annotate AskMrRobotUi.lua @ 17:e77e01abce98

Warlords of Draenor pre-patch
author Adam tegen <adam.tegen@gmail.com>
date Mon, 13 Oct 2014 21:28:32 -0500
parents ece9167c0d1c
children 6f1bb8fcf64d
rev   line source
adam@0 1 local _, AskMrRobot = ...
yellowfive@11 2 local L = AskMrRobot.L;
adam@0 3
adam@0 4 AskMrRobot.AmrUI = AskMrRobot.inheritsFrom(AskMrRobot.Frame)
adam@0 5
adam@17 6 local _menuIds = {
adam@17 7 export = 1,
adam@17 8 gear = 2,
adam@17 9 combatLog = 3,
adam@17 10 help = 4
adam@17 11 }
adam@0 12
adam@17 13 function AskMrRobot.AmrUI:new()
adam@17 14 local o = AskMrRobot.Frame:new("AskMrRobot_Dialog", nil, "BasicFrameTemplateWithInset")
adam@0 15
adam@17 16 -- use the AmrUI class
adam@17 17 setmetatable(o, { __index = AskMrRobot.AmrUI })
adam@0 18
adam@17 19 o:RegisterForDrag("LeftButton");
adam@17 20 o:SetWidth(615)
adam@17 21 o:SetHeight(550)
adam@17 22 o.InsetBg:SetPoint("TOPLEFT", 140, -24)
adam@0 23
adam@17 24 o:SetParent("UIParent")
adam@17 25 o:SetPoint("CENTER")
adam@17 26 o:Hide()
adam@17 27 o:EnableMouse(true)
adam@17 28 o:EnableKeyboard(true)
adam@17 29 o.hideOnEscape = 1
adam@17 30 o:SetMovable(true)
adam@17 31 o:SetToplevel(true)
adam@0 32
adam@17 33 o:SetScript("OnDragStart", AskMrRobot.AmrUI.OnDragStart)
adam@17 34 o:SetScript("OnDragStop", AskMrRobot.AmrUI.OnDragStop)
adam@17 35 o:SetScript("OnHide", AskMrRobot.AmrUI.OnHide)
adam@17 36 o:SetScript("OnShow", AskMrRobot.AmrUI.OnShow)
adam@0 37
adam@17 38 o:RegisterEvent("AUCTION_HOUSE_CLOSED")
adam@17 39 o:RegisterEvent("AUCTION_HOUSE_SHOW")
adam@17 40 o:RegisterEvent("SOCKET_INFO_UPDATE")
adam@17 41 o:RegisterEvent("SOCKET_INFO_CLOSE")
adam@17 42
adam@17 43 o:SetScript("OnEvent", function(...)
adam@17 44 o:OnEvent(...)
adam@17 45 end)
adam@17 46
adam@17 47 tinsert(UISpecialFrames, o:GetName())
adam@17 48
adam@17 49 -- initialize some fields
adam@17 50 o.initialized = false
adam@17 51 o.visible = false
adam@17 52
adam@17 53 -- title
adam@17 54 o.TitleText:SetText("--BETA-- Ask Mr. Robot v" .. GetAddOnMetadata(AskMrRobot.AddonName, "Version"))
adam@17 55
adam@17 56 -- create the main menu
adam@17 57 o.menu = o:createMainMenu()
adam@17 58
adam@17 59 local tabArea = AskMrRobot.Frame:new(nil, o)
adam@17 60 tabArea:SetPoint("TOPLEFT", 155, -30)
adam@17 61 tabArea:SetPoint("BOTTOMRIGHT")
adam@17 62
adam@17 63 o.exportTab = AskMrRobot.ExportTab:new(tabArea)
adam@17 64 o.menu[_menuIds["export"]].element = o.exportTab
adam@17 65
adam@17 66 o.gearComparisonTab = AskMrRobot.GearComparisonTab:new(tabArea)
adam@17 67 o.menu[_menuIds["gear"]].element = o.gearComparisonTab
adam@17 68
adam@17 69 o.combatLogTab = AskMrRobot.CombatLogTab:new(tabArea)
adam@17 70 o.menu[_menuIds["combatLog"]].element = o.combatLogTab
adam@17 71
adam@17 72 o.helpTab = AskMrRobot.HelpTab:new(tabArea)
adam@17 73 o.menu[_menuIds["help"]].element = o.helpTab
adam@17 74
adam@17 75 o:Hide()
adam@17 76 o:ShowMenu("export")
adam@17 77
adam@17 78 return o
adam@0 79 end
adam@0 80
adam@17 81 function AskMrRobot.AmrUI:createMainMenu()
adam@0 82 local buttons = {}
adam@0 83
adam@0 84 local function onTabButtonClick(clickedButton, event, ...)
adam@0 85 for i = 1, #buttons do
adam@0 86 local button = buttons[i]
adam@0 87 if clickedButton == button then
adam@0 88 button.highlight:SetVertexColor(1, 1, 0)
adam@0 89 button:LockHighlight()
adam@17 90 if button.element then
adam@17 91 button.element:Show()
adam@17 92 end
adam@0 93 else
adam@0 94 button.highlight:SetVertexColor(.196, .388, .8)
adam@0 95 button:UnlockHighlight()
adam@0 96 if button.element then
adam@0 97 button.element:Hide()
adam@0 98 end
adam@0 99 end
adam@0 100 end
adam@0 101 end
adam@0 102
adam@17 103 local function createButton(text, spacing)
adam@0 104 local lastButton = #buttons
adam@0 105 local i = lastButton + 1
adam@0 106 local tabButton = CreateFrame("Button", "AmrTabButton" .. i, self, "OptionsListButtonTemplate")
adam@0 107 tabButton:SetText(text)
adam@0 108 tabText = tabButton:GetFontString()
adam@0 109 tabText:SetPoint("LEFT", 6, 0)
adam@0 110 if i == 1 then
adam@0 111 tabButton:SetPoint("TOPLEFT", 2, spacing)
adam@0 112 else
adam@0 113 tabButton:SetPoint("TOPLEFT", "AmrTabButton" .. lastButton, "BOTTOMLEFT", 0, spacing)
adam@0 114 end
adam@17 115 tabButton:SetWidth(140)
adam@0 116 tabButton:SetHeight(20)
adam@0 117 tinsert(buttons, tabButton)
adam@0 118 tabButton:SetScript("OnClick", onTabButtonClick)
adam@0 119 end
adam@0 120
adam@17 121 createButton(L.AMR_UI_MENU_EXPORT, -35)
adam@17 122 createButton(L.AMR_UI_MENU_GEAR, -20)
adam@17 123 createButton(L.AMR_UI_MENU_COMBAT_LOG, 0)
adam@17 124 createButton(L.AMR_UI_MENU_HELP, 0)
adam@0 125
adam@0 126 return buttons
adam@0 127 end
adam@0 128
adam@17 129 function AskMrRobot.AmrUI:ShowMenu(menu)
adam@17 130 local id = _menuIds[menu]
adam@17 131 if id then
adam@17 132 self.menu[id]:Click()
adam@17 133 end
adam@0 134 end
adam@0 135
adam@17 136 function AskMrRobot.AmrUI:Toggle()
adam@17 137 if self.visible then
adam@17 138 self:Hide()
adam@17 139 else
adam@17 140 self.visible = true
adam@17 141 self:Show()
adam@0 142 end
adam@0 143 end
adam@0 144
adam@0 145 function AskMrRobot.AmrUI:OnShow()
adam@0 146
adam@0 147 end
adam@0 148
adam@0 149 function AskMrRobot.AmrUI:OnDragStart()
adam@0 150 if not self.isLocked then
adam@0 151 self:StartMoving();
adam@0 152 end
adam@0 153 end
adam@0 154
adam@0 155 function AskMrRobot.AmrUI:OnDragStop()
adam@0 156 self:StopMovingOrSizing()
adam@0 157 end
adam@0 158
adam@0 159 function AskMrRobot.AmrUI:OnHide()
adam@0 160 self.visible = false
adam@0 161 self:StopMovingOrSizing()
adam@0 162 end
adam@0 163
adam@0 164 function AskMrRobot.AmrUI:OnEvent(frame, event, ...)
adam@0 165 local handler = self["On_" .. event]
adam@0 166 if handler then
adam@0 167 handler(self, ...)
adam@0 168 end
adam@0 169 end