adam@0: local _, AskMrRobot = ... yellowfive@11: local L = AskMrRobot.L; adam@0: adam@0: AskMrRobot.AmrUI = AskMrRobot.inheritsFrom(AskMrRobot.Frame) adam@0: adam@17: local _menuIds = { adam@17: export = 1, adam@17: gear = 2, TuhMuffinMan>@51: settings = 3, TuhMuffinMan>@51: combatLog = 4, TuhMuffinMan>@51: help = 5 adam@17: } adam@0: adam@17: function AskMrRobot.AmrUI:new() adam@17: local o = AskMrRobot.Frame:new("AskMrRobot_Dialog", nil, "BasicFrameTemplateWithInset") adam@0: adam@17: -- use the AmrUI class adam@17: setmetatable(o, { __index = AskMrRobot.AmrUI }) adam@0: adam@17: o:RegisterForDrag("LeftButton"); adam@17: o:SetWidth(615) adam@17: o:SetHeight(550) adam@17: o.InsetBg:SetPoint("TOPLEFT", 140, -24) adam@0: adam@17: o:SetParent("UIParent") adam@17: o:SetPoint("CENTER") adam@17: o:Hide() adam@17: o:EnableMouse(true) adam@17: o:EnableKeyboard(true) adam@17: o.hideOnEscape = 1 adam@17: o:SetMovable(true) adam@17: o:SetToplevel(true) adam@0: adam@17: o:SetScript("OnDragStart", AskMrRobot.AmrUI.OnDragStart) adam@17: o:SetScript("OnDragStop", AskMrRobot.AmrUI.OnDragStop) adam@17: o:SetScript("OnHide", AskMrRobot.AmrUI.OnHide) adam@17: o:SetScript("OnShow", AskMrRobot.AmrUI.OnShow) adam@0: adam@17: o:RegisterEvent("AUCTION_HOUSE_CLOSED") adam@17: o:RegisterEvent("AUCTION_HOUSE_SHOW") adam@17: o:RegisterEvent("SOCKET_INFO_UPDATE") adam@17: o:RegisterEvent("SOCKET_INFO_CLOSE") adam@17: adam@17: o:SetScript("OnEvent", function(...) adam@17: o:OnEvent(...) adam@17: end) adam@17: adam@17: tinsert(UISpecialFrames, o:GetName()) adam@17: adam@17: -- initialize some fields adam@17: o.initialized = false adam@17: o.visible = false adam@17: adam@17: -- title adam@17: o.TitleText:SetText("--BETA-- Ask Mr. Robot v" .. GetAddOnMetadata(AskMrRobot.AddonName, "Version")) adam@17: adam@17: -- create the main menu adam@17: o.menu = o:createMainMenu() adam@17: adam@17: local tabArea = AskMrRobot.Frame:new(nil, o) adam@17: tabArea:SetPoint("TOPLEFT", 155, -30) adam@17: tabArea:SetPoint("BOTTOMRIGHT") adam@17: adam@17: o.exportTab = AskMrRobot.ExportTab:new(tabArea) adam@17: o.menu[_menuIds["export"]].element = o.exportTab adam@17: adam@17: o.gearComparisonTab = AskMrRobot.GearComparisonTab:new(tabArea) adam@17: o.menu[_menuIds["gear"]].element = o.gearComparisonTab adam@17: TuhMuffinMan>@51: o.settingsTab = AskMrRobot.SettingsTab:new(tabArea) TuhMuffinMan>@51: o.menu[_menuIds["settings"]].element = o.settingsTab TuhMuffinMan>@51: adam@17: o.combatLogTab = AskMrRobot.CombatLogTab:new(tabArea) adam@17: o.menu[_menuIds["combatLog"]].element = o.combatLogTab adam@17: adam@17: o.helpTab = AskMrRobot.HelpTab:new(tabArea) adam@17: o.menu[_menuIds["help"]].element = o.helpTab adam@17: adam@17: o:Hide() adam@17: o:ShowMenu("export") adam@17: adam@17: return o adam@0: end adam@0: adam@17: function AskMrRobot.AmrUI:createMainMenu() adam@0: local buttons = {} adam@0: adam@0: local function onTabButtonClick(clickedButton, event, ...) adam@0: for i = 1, #buttons do adam@0: local button = buttons[i] adam@0: if clickedButton == button then adam@0: button.highlight:SetVertexColor(1, 1, 0) adam@0: button:LockHighlight() adam@17: if button.element then adam@17: button.element:Show() adam@17: end adam@0: else adam@0: button.highlight:SetVertexColor(.196, .388, .8) adam@0: button:UnlockHighlight() adam@0: if button.element then adam@0: button.element:Hide() adam@0: end adam@0: end adam@0: end adam@0: end adam@0: adam@17: local function createButton(text, spacing) adam@0: local lastButton = #buttons adam@0: local i = lastButton + 1 adam@0: local tabButton = CreateFrame("Button", "AmrTabButton" .. i, self, "OptionsListButtonTemplate") adam@0: tabButton:SetText(text) adam@0: tabText = tabButton:GetFontString() adam@0: tabText:SetPoint("LEFT", 6, 0) adam@0: if i == 1 then adam@0: tabButton:SetPoint("TOPLEFT", 2, spacing) adam@0: else adam@0: tabButton:SetPoint("TOPLEFT", "AmrTabButton" .. lastButton, "BOTTOMLEFT", 0, spacing) adam@0: end adam@17: tabButton:SetWidth(140) adam@0: tabButton:SetHeight(20) adam@0: tinsert(buttons, tabButton) adam@0: tabButton:SetScript("OnClick", onTabButtonClick) adam@0: end adam@0: adam@17: createButton(L.AMR_UI_MENU_EXPORT, -35) adam@17: createButton(L.AMR_UI_MENU_GEAR, -20) TuhMuffinMan>@51: createButton(L.AMR_UI_MENU_SETTINGS, 0) adam@17: createButton(L.AMR_UI_MENU_COMBAT_LOG, 0) adam@17: createButton(L.AMR_UI_MENU_HELP, 0) adam@0: adam@0: return buttons adam@0: end adam@0: adam@17: function AskMrRobot.AmrUI:ShowMenu(menu) adam@17: local id = _menuIds[menu] adam@17: if id then adam@17: self.menu[id]:Click() adam@17: end adam@0: end adam@0: adam@17: function AskMrRobot.AmrUI:Toggle() adam@17: if self.visible then adam@17: self:Hide() adam@17: else adam@17: self.visible = true adam@17: self:Show() adam@0: end adam@0: end adam@0: adam@0: function AskMrRobot.AmrUI:OnShow() adam@0: adam@0: end adam@0: adam@0: function AskMrRobot.AmrUI:OnDragStart() adam@0: if not self.isLocked then adam@0: self:StartMoving(); adam@0: end adam@0: end adam@0: adam@0: function AskMrRobot.AmrUI:OnDragStop() adam@0: self:StopMovingOrSizing() adam@0: end adam@0: adam@0: function AskMrRobot.AmrUI:OnHide() adam@0: self.visible = false adam@0: self:StopMovingOrSizing() adam@0: end adam@0: adam@0: function AskMrRobot.AmrUI:OnEvent(frame, event, ...) adam@0: local handler = self["On_" .. event] adam@0: if handler then adam@0: handler(self, ...) adam@0: end adam@0: end