diff --git a/Era/Talented/Talented.toc b/Era/Talented/Talented.toc index 1314427..6edb2ba 100644 --- a/Era/Talented/Talented.toc +++ b/Era/Talented/Talented.toc @@ -1,4 +1,4 @@ -## Interface: 11504 +## Interface: 11508 ## Title: Talented ## Name: Talented ## Notes: The Talent Template Editor diff --git a/Era/Talented/core.lua b/Era/Talented/core.lua index 88ea2c0..8556168 100644 --- a/Era/Talented/core.lua +++ b/Era/Talented/core.lua @@ -1,373 +1,421 @@ -local Talented = LibStub("AceAddon-3.0"):NewAddon("Talented", - "AceConsole-3.0", "AceComm-3.0", "AceHook-3.0", "AceEvent-3.0", "AceSerializer-3.0") +local Talented = + LibStub("AceAddon-3.0"):NewAddon( + "Talented", + "AceConsole-3.0", + "AceComm-3.0", + "AceHook-3.0", + "AceEvent-3.0", + "AceSerializer-3.0" +) local L = LibStub("AceLocale-3.0"):GetLocale("Talented") -local classes = {'DRUID','HUNTER','MAGE','PALADIN','PRIEST','ROGUE','SHAMAN','WARLOCK','WARRIOR'} +local classes = {"DRUID", "HUNTER", "MAGE", "PALADIN", "PRIEST", "ROGUE", "SHAMAN", "WARLOCK", "WARRIOR"} Talented.prev_Print = Talented.Print function Talented:Print(s, ...) - if type(s) == "string" and s:find("%", nil, true) then - self:prev_Print(s:format(...)) - else - self:prev_Print(s, ...) - end + if type(s) == "string" and s:find("%", nil, true) then + self:prev_Print(s:format(...)) + else + self:prev_Print(s, ...) + end end function Talented:Debug(...) - if not self.db or self.db.profile.debug then - self:Print(...) - end + if not self.db or self.db.profile.debug then + self:Print(...) + end end function Talented:MakeTarget(targetName) - local tar = self.db.char.targets[targetName] - local name = nil; local class = nil + local tar = self.db.char.targets[targetName] + local name = nil + local class = nil if tar then name = tar.name class = tar.class end - local src = tar and self.db.global.templates[class] and self.db.global.templates[class][name] - if not src then - if tar then - self.db.char.targets[targetName] = nil - end - return - end - - local target = self.target - if not target then - target = {} - self.target = target - end - self:CopyPackedTemplate(src, target) - - if not self:ValidateTemplate(target) or target.class ~= select(2, UnitClass"player") - then - self.db.char.targets[targetName] = nil - return nil - end - target.name = name - target.class = class - return target + local src = tar and self.db.global.templates[class] and self.db.global.templates[class][name] + if not src then + if tar then + self.db.char.targets[targetName] = nil + end + return + end + + local target = self.target + if not target then + target = {} + self.target = target + end + self:CopyPackedTemplate(src, target) + + if not self:ValidateTemplate(target) or target.class ~= select(2, UnitClass "player") then + self.db.char.targets[targetName] = nil + return nil + end + target.name = name + target.class = class + return target end function Talented:GetMode() - return self.mode + return self.mode end function Talented:SetMode(mode) - if self.mode ~= mode then - self.mode = mode - if mode == "apply" then - self:ApplyCurrentTemplate() - elseif self.base and self.base.view then - self.base.view:SetViewMode(mode) - end - end - local cb = self.base and self.base.checkbox - if cb then - cb:SetChecked(mode == "edit") - end + if self.mode ~= mode then + self.mode = mode + if mode == "apply" then + self:ApplyCurrentTemplate() + elseif self.base and self.base.view then + self.base.view:SetViewMode(mode) + end + end + local cb = self.base and self.base.checkbox + if cb then + cb:SetChecked(mode == "edit") + end end -- Hook this function if you wanna change the way Talented loads its modules function Talented:LoadAddOn(name) - LoadAddOn(name) + LoadAddOn(name) end function Talented:OnInitialize() - self.db = LibStub("AceDB-3.0"):New("TalentedDB", self.defaults) - self:UpgradeOptions() - self:LoadTemplates() - - local AceDBOptions = LibStub("AceDBOptions-3.0", true) - if AceDBOptions then - self.options.args.profiles = AceDBOptions:GetOptionsTable(self.db) - self.options.args.profiles.order = 200 - end - - LibStub("AceConfig-3.0"):RegisterOptionsTable("Talented", self.options) - self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Talented", "Talented") - self:RegisterChatCommand("talented", "OnChatCommand") - - self:RegisterComm("Talented") - if IsLoggedIn() then - self:LoadAddOn"Talented_SpecTabs" - else - self.PLAYER_LOGIN = function (self) - self:LoadAddOn"Talented_SpecTabs" - self:UnregisterEvent"PLAYER_LOGIN" - self.PLAYER_LOGIN = nil - end - self:RegisterEvent"PLAYER_LOGIN" - end - self.OnInitialize = nil + self.db = LibStub("AceDB-3.0"):New("TalentedDB", self.defaults) + self:UpgradeOptions() + self:LoadTemplates() + + local AceDBOptions = LibStub("AceDBOptions-3.0", true) + if AceDBOptions then + self.options.args.profiles = AceDBOptions:GetOptionsTable(self.db) + self.options.args.profiles.order = 200 + end + + LibStub("AceConfig-3.0"):RegisterOptionsTable("Talented", self.options) + self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Talented", "Talented") + self:RegisterChatCommand("talented", "OnChatCommand") + + self:RegisterComm("Talented") + if IsLoggedIn() then + self:LoadAddOn "Talented_SpecTabs" + else + self.PLAYER_LOGIN = function(self) + self:LoadAddOn "Talented_SpecTabs" + self:UnregisterEvent "PLAYER_LOGIN" + self.PLAYER_LOGIN = nil + end + self:RegisterEvent "PLAYER_LOGIN" + end + self.OnInitialize = nil end function Talented:OnChatCommand(input) - if not input or input:trim() == "" then - self:OpenOptionsFrame() - else - LibStub("AceConfigCmd-3.0").HandleCommand(self, "talented", "Talented", input) - end + if not input or input:trim() == "" then + self:OpenOptionsFrame() + else + LibStub("AceConfigCmd-3.0").HandleCommand(self, "talented", "Talented", input) + end end function Talented:DeleteCurrentTemplate() - local template = self.template - if template == self.current then return end - local templates = self.db.global.templates - templates[template.class][template.name] = nil - self:SetTemplate() + local template = self.template + if template.talentGroup then + return + end + local templates = self.db.global.templates + templates[template.class][template.name] = nil + self:SetTemplate() end function Talented:UpdateTemplateName(template, newname) - local class = template.class - if self.db.global.templates[class][newname] or - self.current == template or - type(newname) ~= "string" or newname == "" then - return - end - - local oldname = template.name - template.name = newname - local t = self.db.global.templates - t[class][newname] = template - t[class][oldname] = nil + local class = template.class + if self.db.global.templates[class][newname] or template.talentGroup or type(newname) ~= "string" or newname == "" then + return + end + + local oldname = template.name + template.name = newname + local t = self.db.global.templates + t[class][newname] = template + t[class][oldname] = nil end do - local function new(templates, name, class) - local count = 0 - local template = { - name = name, - class = class - } - while templates[template.class][template.name] do - count = count + 1 - template.name = format(L["%s (%d)"], name, count) - end - templates[template.class][template.name] = template - return template - end - - local function copy(dst, src) - dst.class = src.class - if src.code then - dst.code = src.code - return - else - for tab, tree in ipairs(Talented:GetTalentInfo(src.class)) do - local s, d = src[tab], {} - dst[tab] = d - for index = 1, #tree.talents do - d[index] = s[index] - end - end - end - end - - function Talented:ImportFromOther(name, src) - if not self:GetTalentInfo(src.class) then return end - - local dst = new(self.db.global.templates, name, src.class) - - copy(dst, src) - - self:OpenTemplate(dst) - - return dst - end - - function Talented:CopyTemplate(src) - local dst = new(self.db.global.templates, format(L["Copy of %s"], src.name), src.class) - - copy(dst, src) - - return dst - end - - function Talented:CreateEmptyTemplate(class) - class = class or select(2, UnitClass"player") - - local template = new(self.db.global.templates, L["Empty"], class) - local info = self:GetTalentInfo(class) - if not info then return end - - for tab, tree in ipairs(info) do - local t = {} - template[tab] = t - for index = 1, #tree.talents do - t[index] = 0 - end - end - - return template - end - - Talented.importers = {} - Talented.exporters = {} - function Talented:ImportTemplate(url) - --Get class - for pattern, method in pairs(self.importers) do - if url:find(pattern) then - class = method(self, url) - if class then break end - end - end - assert(class) - - --Decode the template - local dst, result = new(self.db.global.templates, L["Imported"], class) - for pattern, method in pairs(self.importers) do - if url:find(pattern) then - result = method(self, url, dst) - assert(dst.class == class) - if result then break end - end - end - - --Error-check - if result then - if not self:ValidateTemplate(dst) then - self:Print(L["The given template is not a valid one!"]) - self.db.global.templates[dst.class][dst.name] = nil - else - return dst - end - else - self:Print(L["\"%s\" does not appear to be a valid URL!"], url) - self.db.global.templates[dst.class][dst.name] = nil - end - end + local function new(templates, name, class) + -- [Fix] Safety check: Ensure class is valid and Uppercase + if not class then + return nil + end + class = class:upper() + + if not templates[class] then + -- If we can't find the class in the DB, we can't create the template + return nil + end + + local count = 0 + local template = { + name = name, + class = class + } + + -- Safe lookup + while templates[template.class][template.name] do + count = count + 1 + template.name = format(L["%s (%d)"], name, count) + end + templates[template.class][template.name] = template + return template + end + + local function copy(dst, src) + dst.class = src.class + if src.code then + dst.code = src.code + return + else + for tab, tree in ipairs(Talented:GetTalentInfo(src.class)) do + local s, d = src[tab], {} + dst[tab] = d + for index = 1, #tree.talents do + d[index] = s[index] + end + end + end + end + + function Talented:ImportFromOther(name, src) + if not self:GetTalentInfo(src.class) then + return + end + + local dst = new(self.db.global.templates, name, src.class) + if not dst then + return + end -- Safety check + + copy(dst, src) + + self:OpenTemplate(dst) + + return dst + end + + function Talented:CopyTemplate(src) + local dst = new(self.db.global.templates, format(L["Copy of %s"], src.name), src.class) + if not dst then + return + end -- Safety check + + copy(dst, src) + + return dst + end + + function Talented:CreateEmptyTemplate(class) + class = class or select(2, UnitClass "player") + + local template = new(self.db.global.templates, L["Empty"], class) + if not template then + return + end -- Safety check + + local info = self:GetTalentInfo(class) + if not info then + return + end + + for tab, tree in ipairs(info) do + local t = {} + template[tab] = t + for index = 1, #tree.talents do + t[index] = 0 + end + end + + return template + end + + Talented.importers = {} + Talented.exporters = {} + function Talented:ImportTemplate(url) + local class + --Get class + for pattern, method in pairs(self.importers) do + if url:find(pattern) then + class = method(self, url) + if class then + class = class:upper() -- [Fix] Force uppercase + break + end + end + end + + -- [Fix] Replaced assert() with user friendly error + if not class then + self:Print(L['"%s" does not appear to be a valid URL!'], url) + return + end + + --Decode the template + local dst, result = new(self.db.global.templates, L["Imported"], class) + if not dst then + self:Print("Error creating template for class: %s", class) + return + end + + for pattern, method in pairs(self.importers) do + if url:find(pattern) then + result = method(self, url, dst) + if result then + break + end + end + end + + --Error-check + if result then + if not self:ValidateTemplate(dst) then + self:Print(L["The given template is not a valid one!"]) + self.db.global.templates[dst.class][dst.name] = nil + else + return dst + end + else + self:Print(L['"%s" does not appear to be a valid URL!'], url) + self.db.global.templates[dst.class][dst.name] = nil + end + end end function Talented:OpenTemplate(template) - self:UnpackTemplate(template) - if not self:ValidateTemplate(template, true) then - local name = template.name - local class = template.class - self.db.global.templates[class][name] = nil - self:Print(L["The template '%s' is no longer valid and has been removed."], name) - return - end - local base = self:CreateBaseFrame() - if not self.current then - self:UpdateCurrentTemplate() - end - self:SetTemplate(template) - if not base:IsVisible() then - -- ShowUIPanel(base) - base:Show() - end + self:UnpackTemplate(template) + if not self:ValidateTemplate(template, true) then + local name = template.name + local class = template.class + self.db.global.templates[class][name] = nil + self:Print(L["The template '%s' is no longer valid and has been removed."], name) + return + end + local base = self:CreateBaseFrame() + if not self.alternates then + self:UpdatePlayerSpecs() + end + self:SetTemplate(template) + if not base:IsVisible() then + -- ShowUIPanel(base) + base:Show() + end end function Talented:SetTemplate(template) - if not template then template = self.current end - local view = self:CreateBaseFrame().view - local old = view.template - if template ~= old then - if self.current == template then - local target = self:MakeTarget(1) - view:SetTemplate(template, target) - else - view:SetTemplate(template) - end - self.template = template - end - if template and self.current ~= template then - self.db.profile.last_template = template.name - end - self:SetMode(self:GetDefaultMode()) - - -- self:UpdateView() --TODO: Why is this commented out? + if not template then + template = self:GetActiveSpec() + end + local view = self:CreateBaseFrame().view + local old = view.template + if template ~= old then + if template.talentGroup then + view:SetTemplate(template, self:MakeTarget(template.talentGroup)) + else + view:SetTemplate(template) + end + self.template = template + end + if not template or not template.talentGroup then + self.db.profile.last_template = template.name + end + self:SetMode(self:GetDefaultMode()) + + -- self:UpdateView() --TODO: Why is this commented out? end function Talented:GetDefaultMode() - return self.db.profile.always_edit and "edit" or "view" + return self.db.profile.always_edit and "edit" or "view" end function Talented:OnEnable() - self:createNew2OldIdx() - self:RawHook("ToggleTalentFrame", true) - --Non-taint option that loads Talented's frame IN ADDITION to Blizzard's frame: self:SecureHook("ToggleTalentFrame") - self:SecureHook("UpdateMicroButtons") - - UIParent:UnregisterEvent("CONFIRM_TALENT_WIPE") - self:RegisterEvent("CONFIRM_TALENT_WIPE") - self:RegisterEvent("CHARACTER_POINTS_CHANGED") - TalentMicroButton:SetScript("OnClick", ToggleTalentFrame) + self:createNew2OldIdx() + self:RawHook("ToggleTalentFrame", true) + --Non-taint option that loads Talented's frame IN ADDITION to Blizzard's frame: self:SecureHook("ToggleTalentFrame") + self:SecureHook("UpdateMicroButtons") + + UIParent:UnregisterEvent("CONFIRM_TALENT_WIPE") + self:RegisterEvent("CONFIRM_TALENT_WIPE") + self:RegisterEvent("CHARACTER_POINTS_CHANGED") + TalentMicroButton:SetScript("OnClick", ToggleTalentFrame) end function Talented:OnDisable() - -- self:UnhookInspectUI() - UIParent:RegisterEvent("CONFIRM_TALENT_WIPE") + -- self:UnhookInspectUI() + UIParent:RegisterEvent("CONFIRM_TALENT_WIPE") end function Talented:PLAYER_TALENT_UPDATE() - self:UpdateCurrentTemplate() + self:UpdatePlayerSpecs() end function Talented:CONFIRM_TALENT_WIPE(_, cost) - StaticPopupDialogs["CONFIRM_TALENT_WIPE"].text = L['CONFIRM_TALENT_WIPE_TEXT'] --the problem: text for CONFIRM_TALENT_WIPE are nil, eventualy in conjunction of unregisterevent from uiparent??? now let us set the text manually... - local dialog = StaticPopup_Show("CONFIRM_TALENT_WIPE") - if dialog then - MoneyFrame_Update(dialog:GetName().."MoneyFrame", cost) - local frame = self.base + StaticPopupDialogs["CONFIRM_TALENT_WIPE"].text = L["CONFIRM_TALENT_WIPE_TEXT"] --the problem: text for CONFIRM_TALENT_WIPE are nil, eventualy in conjunction of unregisterevent from uiparent??? now let us set the text manually... + local dialog = StaticPopup_Show("CONFIRM_TALENT_WIPE") + if dialog then + MoneyFrame_Update(dialog:GetName() .. "MoneyFrame", cost) + local frame = self.base if not frame or not frame:IsVisible() then - self:Update() - -- ShowUIPanel(self.base) - self.base:Show() - end + self:Update() + -- ShowUIPanel(self.base) + self.base:Show() + end --dialog:SetFrameLevel(self.base:GetFrameLevel() + 5) frame level dosn't work, so let's us set the frame strata - dialog:SetFrameStrata('FULLSCREEN_DIALOG') - end + dialog:SetFrameStrata("FULLSCREEN_DIALOG") + end end - function Talented:CHARACTER_POINTS_CHANGED() - self:UpdateCurrentTemplate() - self:UpdateView() - if self.mode == "apply" then - self:ApplyNextTalentPoint() - end + self:UpdatePlayerSpecs() + self:UpdateView() + if self.mode == "apply" then + self:ApplyNextTalentPoint() + end end - function Talented:UpdateMicroButtons() - local button = TalentMicroButton - if self.db.profile.donthide and UnitLevel"player" < button.minLevel then - button:Enable() - end - if self.base and self.base:IsShown() then - button:SetButtonState("PUSHED", 1) - else - button:SetButtonState"NORMAL" - end + local button = TalentMicroButton + if self.db.profile.donthide and UnitLevel "player" < button.minLevel then + button:Enable() + end + if self.base and self.base:IsShown() then + button:SetButtonState("PUSHED", 1) + else + button:SetButtonState "NORMAL" + end end function Talented:ToggleTalentFrame() - local frame = self.base - if not frame or not frame:IsVisible() then - self:Update() - if self.template then - -- reset editing mode to the default every time we open the panel after the initial open - self:SetMode(self:GetDefaultMode()) - end - -- ShowUIPanel(self.base) - self.base:Show() - else - -- HideUIPanel(frame) - frame:Hide() - end + local frame = self.base + if not frame or not frame:IsVisible() then + self:Update() + if self.template then + -- reset editing mode to the default every time we open the panel after the initial open + self:SetMode(self:GetDefaultMode()) + end + -- ShowUIPanel(self.base) + self.base:Show() + else + -- HideUIPanel(frame) + frame:Hide() + end end function Talented:Update() - self:CreateBaseFrame() - self:UpdateCurrentTemplate() - if not self.template then - self:SetTemplate() - end - self:UpdateView() + self:CreateBaseFrame() + self:UpdatePlayerSpecs() + if not self.template then + self:SetTemplate() + end + self:UpdateView() end function Talented:is_class(class) @@ -380,13 +428,12 @@ function Talented:is_class(class) end function Talented:MakeSubArrays(db) - local madeArrays = 0 + local madeArrays = 0 for index, class in ipairs(classes) do if db[class] == nil then - db[class] = {} - madeArrays = 1 - - --If there is an existing template named after the class... + --If there is an existing template named after the class... + db[class] = {} + madeArrays = 1 elseif type(db[class]) == "string" then --rename the template local count = 1 @@ -399,108 +446,110 @@ function Talented:MakeSubArrays(db) --THEN make the class sub-array db[name] = db[class] - db[class] = {} - madeArrays = 1 + db[class] = {} + madeArrays = 1 end - end - - return madeArrays -end + end + return madeArrays +end function Talented:LoadOldTemplates(db) - local invalid = {} - local converted = {} - - --Load old template and place it into the db by class - for name, code in pairs(db) do - if not self:is_class(name) then - if type(code) == "string" then - local class = self:GetTemplateStringClass(code) - if class then - db[class][name] = { - name = name, - code = code, - class = class, - } - converted[#converted +1] = name - else - invalid[#invalid +1] = name - end - - elseif not self:ValidateTemplate(code) then - invalid[#invalid +1] = name - end - - --Erase this old template - db[name] = nil - end - end - - if next(converted) then - table.sort(converted) - self:Print(L["The following templates were converted from a previous version of the addon. Ensure that none are 'invalid' (below); retrieve the backup of your config file from the WTF folder if so."]) - self:Print(table.concat(converted, ", ")) - end - - if next(invalid) then - table.sort(invalid) - self:Print(L["The following templates are no longer valid and have been removed:"]) - self:Print(table.concat(invalid, ", ")) - return 1 --indicates bad things - end - - return 0 + local invalid = {} + local converted = {} + + --Load old template and place it into the db by class + for name, code in pairs(db) do + if not self:is_class(name) then + if type(code) == "string" then + local class = self:GetTemplateStringClass(code) + if class then + db[class][name] = { + name = name, + code = code, + class = class + } + converted[#converted + 1] = name + else + invalid[#invalid + 1] = name + end + elseif not self:ValidateTemplate(code) then + invalid[#invalid + 1] = name + end + + --Erase this old template + db[name] = nil + end + end + + if next(converted) then + table.sort(converted) + self:Print( + L[ + "The following templates were converted from a previous version of the addon. Ensure that none are 'invalid' (below); retrieve the backup of your config file from the WTF folder if so." + ] + ) + self:Print(table.concat(converted, ", ")) + end + + if next(invalid) then + table.sort(invalid) + self:Print(L["The following templates are no longer valid and have been removed:"]) + self:Print(table.concat(invalid, ", ")) + return 1 --indicates bad things + end + + return 0 end function Talented:LoadTemplates() - local db = self.db.global.templates - if Talented:MakeSubArrays(db)==1 then - --If we had to make the sub arrays, either the database was empty or it has templates as defined in an older version of the addon (arranged by name, not by class) - self:LoadOldTemplates(db) - else - --If we have the nice new layout for templates - local returnValue = 0 - local invalid = {} - for class, classdb in pairs(db) do - assert(self:is_class(class)) - - for name, code in pairs(classdb) do - if type(code) == "string" then - db[class][name] = { - name = name, - code = code, - class = class, - } - elseif not self:ValidateTemplate(code) then - db[class][name] = nil - invalid[#invalid + 1] = name - end - end - end - - if next(invalid) then - table.sort(invalid) - self:Print(L["The following templates are no longer valid and have been removed:"]) - self:Print(table.concat(invalid, ", ")) - end - end - - self.OnDatabaseShutdown = function (self, event, db) - local db = db.global.templates - for class, classdb in pairs(db) do - for name, template in pairs(classdb) do - template.current = nil - Talented:PackTemplate(template) - if template.code then - db[class][name] = template.code - end - end - end - self.db = nil - end - self.db.RegisterCallback(self, "OnDatabaseShutdown") - self.LoadTemplates = nil + local db = self.db.global.templates + if Talented:MakeSubArrays(db) == 1 then + --If we had to make the sub arrays, either the database was empty or it has templates as defined in an older version of the addon (arranged by name, not by class) + self:LoadOldTemplates(db) + else + --If we have the nice new layout for templates + local returnValue = 0 + local invalid = {} + for class, classdb in pairs(db) do + assert(self:is_class(class)) + + for name, code in pairs(classdb) do + if type(code) == "string" then + db[class][name] = { + name = name, + code = code, + class = class + } + elseif not self:ValidateTemplate(code) then + db[class][name] = nil + invalid[#invalid + 1] = name + end + end + end + + if next(invalid) then + table.sort(invalid) + self:Print(L["The following templates are no longer valid and have been removed:"]) + self:Print(table.concat(invalid, ", ")) + end + end + + self.OnDatabaseShutdown = function(self, event, db) + local db = db.global.templates + for class, classdb in pairs(db) do + for name, template in pairs(classdb) do + template.current = nil + Talented:PackTemplate(template) + if template.code then + db[class][name] = template.code + end + end + end + self.db = nil + end + self.db.RegisterCallback(self, "OnDatabaseShutdown") + self.LoadTemplates = nil end _G.Talented = Talented diff --git a/Era/Talented/tips.lua b/Era/Talented/tips.lua index f4b0184..5385724 100644 --- a/Era/Talented/tips.lua +++ b/Era/Talented/tips.lua @@ -11,139 +11,160 @@ local RED_FONT_COLOR = RED_FONT_COLOR local L = LibStub("AceLocale-3.0"):GetLocale("Talented") local function addline(line, color, split) - GameTooltip:AddLine(line, color.r, color.g, color.b, split) + GameTooltip:AddLine(line, color.r, color.g, color.b, split) end local function gettipline(tip, tipValues, rank) - -- ─── CHECK FOR MISSING TOOLTIPS OR RANKS ──────────────────────────────────────── - --TipValues doesn't exist. Maybe tip was called using data straight from the WoW client? - if not tipValues then - return tip --If we have no data on what to do with ranks, just return the tooltip. - --This might be unformatted, - --or it might be the rank 1 tooltip extracted from the client without parsing - we don't know. - -- tipRank = {} --this would yield no arguments for format, to make %% -> %. Dangerous if single % exists. - - --Format values for requested rank are missing. - --Three cases: Talented_Data is incorrect; called rank is incorrect; talent only has one rank. - elseif not tipValues[rank] then - if rank==1 then - tipRank = {} --It is likely this talent has a single rank -> no formatting needed - else - self:Print(string.format( - "Error: tooltip found for \"%s\" but rank %d is missing. Size of rank array: %d. %s", - tip, rank, #tipValues, "Yielding rank 1 instead." - )) - tipRank = tipValues[1] - end - - --Rank requested for exists and all is well - else - tipRank = tipValues[rank] - end + -- ─── CHECK FOR MISSING TOOLTIPS OR RANKS ──────────────────────────────────────── + --TipValues doesn't exist. Maybe tip was called using data straight from the WoW client? + if not tipValues then + --This might be unformatted, + --or it might be the rank 1 tooltip extracted from the client without parsing - we don't know. + -- tipRank = {} --this would yield no arguments for format, to make %% -> %. Dangerous if single % exists. + --Format values for requested rank are missing. + --Three cases: Talented_Data is incorrect; called rank is incorrect; talent only has one rank. + return tip --If we have no data on what to do with ranks, just return the tooltip. + elseif not tipValues[rank] then + if rank == 1 then + tipRank = {} --It is likely this talent has a single rank -> no formatting needed + else + self:Print( + string.format( + 'Error: tooltip found for "%s" but rank %d is missing. Size of rank array: %d. %s', + tip, + rank, + #tipValues, + "Yielding rank 1 instead." + ) + ) + tipRank = tipValues[1] + end + else + tipRank = tipValues[rank] + end - return string.format(tip, unpack(tipRank)) + if not tipValues or #tipValues == 0 then + return tip + end + + if not tipValues[rank] then + return tip + end + + return tip:format(unpack(tipValues[rank])) end local function addtipline(tip) - local color = HIGHLIGHT_FONT_COLOR - tip = tip or "" - if type(tip) == "string" then - addline(tip, NORMAL_FONT_COLOR, true) - else - for _, i in ipairs(tip) do - if (_ == #tip) then color = NORMAL_FONT_COLOR end - if i.right then - GameTooltip:AddDoubleLine(i.left, i.right, color.r, color.g, color.b, color.r, color.g, color.b) - else - addline(i.left, color, true) - end - end - end + local color = HIGHLIGHT_FONT_COLOR + tip = tip or "" + if type(tip) == "string" then + addline(tip, NORMAL_FONT_COLOR, true) + else + for _, i in ipairs(tip) do + if (_ == #tip) then + color = NORMAL_FONT_COLOR + end + if i.right then + GameTooltip:AddDoubleLine(i.left, i.right, color.r, color.g, color.b, color.r, color.g, color.b) + else + addline(i.left, color, true) + end + end + end end local lastTooltipInfo = {} function Talented:SetTooltipInfo(frame, class, tab, index) - lastTooltipInfo[1] = frame - lastTooltipInfo[2] = class - lastTooltipInfo[3] = tab - lastTooltipInfo[4] = index - if not GameTooltip:IsOwned(frame) then - GameTooltip:SetOwner(frame, "ANCHOR_RIGHT") - end + lastTooltipInfo[1] = frame + lastTooltipInfo[2] = class + lastTooltipInfo[3] = tab + lastTooltipInfo[4] = index + if not GameTooltip:IsOwned(frame) then + GameTooltip:SetOwner(frame, "ANCHOR_RIGHT") + end - local tree = self.talents[class][tab] - local info = tree.talents[index].info - GameTooltip:ClearLines() - local tier = (info.row - 1) * self:GetSkillPointsPerTier(class) - local template = frame:GetParent().view.template + local tree = self.talents[class][tab] + local info = tree.talents[index].info + GameTooltip:ClearLines() + local tier = (info.row - 1) * self:GetSkillPointsPerTier(class) + local template = frame:GetParent().view.template - self:UnpackTemplate(template) - local rank = template[tab][index] - local ranks, req = info.ranks, info.prereqs - addline(info.name, HIGHLIGHT_FONT_COLOR) - addline(TOOLTIP_TALENT_RANK:format(rank, ranks), HIGHLIGHT_FONT_COLOR) - if req then - reqSource = req[1].source - local oranks = tree.talents[reqSource].info.ranks - if template[tab][reqSource] < oranks then - addline(TOOLTIP_TALENT_PREREQ:format(oranks, self:GetTalentName(class, tab, reqSource)), RED_FONT_COLOR) - end - end - if tier >= 1 and self:GetTalentTabCount(template, tab) < tier then - addline(TOOLTIP_TALENT_TIER_POINTS:format(tier, self.tabdata[class][tab].name), RED_FONT_COLOR) - end - if IsAltKeyDown() then - for i = 1, info.ranks do - -- addtipline(info.tips) - addtipline(gettipline(info.tips, info.tipValues, i), i == rank and HIGHLIGHT_FONT_COLOR or NORMAL_FONT_COLOR) - end - else - if rank > 0 then - -- addtipline(info.tips) - addtipline(gettipline(info.tips, info.tipValues, rank)) - end - if rank < ranks then - if rank > 0 then - addline("|n"..TOOLTIP_TALENT_NEXT_RANK, HIGHLIGHT_FONT_COLOR) - end - -- addtipline(info.tips) - -- addtipline(self:GetTalentDesc(class, tab, index, rank + 1)) - addtipline(gettipline(info.tips, info.tipValues, rank + 1)) - end - end - local s = self:GetTalentState(template, tab, index) - if self.mode == "edit" then - if template == self.current then - if s == "available" or s == "empty" then - addline(TOOLTIP_TALENT_LEARN, GREEN_FONT_COLOR) - end - elseif s == "full" then - addline(TALENT_TOOLTIP_REMOVEPREVIEWPOINT, GREEN_FONT_COLOR) - elseif s == "available" then - GameTooltip:AddDoubleLine( - TALENT_TOOLTIP_ADDPREVIEWPOINT, TALENT_TOOLTIP_REMOVEPREVIEWPOINT, - GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b, - GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b) - elseif s == "empty" then - addline(TALENT_TOOLTIP_ADDPREVIEWPOINT, GREEN_FONT_COLOR) - end - end - GameTooltip:Show() + self:UnpackTemplate(template) + local rank = template[tab][index] + local ranks, req = info.ranks, info.prereqs + addline(info.name, HIGHLIGHT_FONT_COLOR) + addline(TOOLTIP_TALENT_RANK:format(rank, ranks), HIGHLIGHT_FONT_COLOR) + if req then + reqSource = req[1].source + local oranks = tree.talents[reqSource].info.ranks + if template[tab][reqSource] < oranks then + addline(TOOLTIP_TALENT_PREREQ:format(oranks, self:GetTalentName(class, tab, reqSource)), RED_FONT_COLOR) + end + end + if tier >= 1 and self:GetTalentTabCount(template, tab) < tier then + addline(TOOLTIP_TALENT_TIER_POINTS:format(tier, self.tabdata[class][tab].name), RED_FONT_COLOR) + end + if IsAltKeyDown() then + for i = 1, info.ranks do + -- addtipline(info.tips) + addtipline( + gettipline(info.tips, info.tipValues, i), + i == rank and HIGHLIGHT_FONT_COLOR or NORMAL_FONT_COLOR + ) + end + else + if rank > 0 then + -- addtipline(info.tips) + addtipline(gettipline(info.tips, info.tipValues, rank)) + end + if rank < ranks then + if rank > 0 then + addline("|n" .. TOOLTIP_TALENT_NEXT_RANK, HIGHLIGHT_FONT_COLOR) + end + -- addtipline(info.tips) + -- addtipline(self:GetTalentDesc(class, tab, index, rank + 1)) + addtipline(gettipline(info.tips, info.tipValues, rank + 1)) + end + end + local s = self:GetTalentState(template, tab, index) + if self.mode == "edit" then + if template == self.template then + if s == "available" or s == "empty" then + addline(TOOLTIP_TALENT_LEARN, GREEN_FONT_COLOR) + end + elseif s == "full" then + addline(TALENT_TOOLTIP_REMOVEPREVIEWPOINT, GREEN_FONT_COLOR) + elseif s == "available" then + GameTooltip:AddDoubleLine( + TALENT_TOOLTIP_ADDPREVIEWPOINT, + TALENT_TOOLTIP_REMOVEPREVIEWPOINT, + GREEN_FONT_COLOR.r, + GREEN_FONT_COLOR.g, + GREEN_FONT_COLOR.b, + GREEN_FONT_COLOR.r, + GREEN_FONT_COLOR.g, + GREEN_FONT_COLOR.b + ) + elseif s == "empty" then + addline(TALENT_TOOLTIP_ADDPREVIEWPOINT, GREEN_FONT_COLOR) + end + end + GameTooltip:Show() end function Talented:HideTooltipInfo() - GameTooltip:Hide() - wipe(lastTooltipInfo) + GameTooltip:Hide() + wipe(lastTooltipInfo) end function Talented:UpdateTooltip() - if next(lastTooltipInfo) then - self:SetTooltipInfo(unpack(lastTooltipInfo)) - end + if next(lastTooltipInfo) then + self:SetTooltipInfo(unpack(lastTooltipInfo)) + end end function Talented:MODIFIER_STATE_CHANGED(_, mod) - if mod:sub(-3) == "ALT" then - self:UpdateTooltip() - end + if mod:sub(-3) == "ALT" then + self:UpdateTooltip() + end end diff --git a/Era/Talented/ui/base.lua b/Era/Talented/ui/base.lua index adb418e..0e488c9 100644 --- a/Era/Talented/ui/base.lua +++ b/Era/Talented/ui/base.lua @@ -14,394 +14,437 @@ Talented.uielements = {} -- :OnMouse{Up|Down}(). local BUTTON_TEXTURES = { - NORMAL = "Interface\\Buttons\\UI-Panel-Button-Up", - PUSHED = "Interface\\Buttons\\UI-Panel-Button-Down", - DISABLED = "Interface\\Buttons\\UI-Panel-Button-Disabled", - PUSHED_DISABLED = "Interface\\Buttons\\UI-Panel-Button-Disabled-Down", + NORMAL = "Interface\\Buttons\\UI-Panel-Button-Up", + PUSHED = "Interface\\Buttons\\UI-Panel-Button-Down", + DISABLED = "Interface\\Buttons\\UI-Panel-Button-Disabled", + PUSHED_DISABLED = "Interface\\Buttons\\UI-Panel-Button-Disabled-Down" } local DefaultButton_Enable = GameMenuButtonOptions.Enable local DefaultButton_Disable = GameMenuButtonOptions.Disable local DefaultButton_SetButtonState = GameMenuButtonOptions.SetButtonState local function Button_SetState(self, state) - if not state then - if self:IsEnabled() == 0 then - state = "DISABLED" - else - state = self:GetButtonState() - end - end - if state == "DISABLED" and self.locked_state == "PUSHED" then - state = "PUSHED_DISABLED" - end - local texture = BUTTON_TEXTURES[state] - self.left:SetTexture(texture) - self.middle:SetTexture(texture) - self.right:SetTexture(texture) + if not state then + if self:IsEnabled() == 0 then + state = "DISABLED" + else + state = self:GetButtonState() + end + end + if state == "DISABLED" and self.locked_state == "PUSHED" then + state = "PUSHED_DISABLED" + end + local texture = BUTTON_TEXTURES[state] + self.left:SetTexture(texture) + self.middle:SetTexture(texture) + self.right:SetTexture(texture) end local function Button_SetButtonState(self, state, locked) - self.locked_state = locked and state - if self:IsEnabled() ~= 0 then - DefaultButton_SetButtonState(self, state, locked) - end - Button_SetState(self) + self.locked_state = locked and state + if self:IsEnabled() ~= 0 then + DefaultButton_SetButtonState(self, state, locked) + end + Button_SetState(self) end local function Button_OnMouseDown(self) - Button_SetState(self, self:IsEnabled() == 0 and "DISABLED" or "PUSHED") + Button_SetState(self, self:IsEnabled() == 0 and "DISABLED" or "PUSHED") end local function Button_OnMouseUp(self) - Button_SetState(self, self:IsEnabled() == 0 and "DISABLED" or "NORMAL") + Button_SetState(self, self:IsEnabled() == 0 and "DISABLED" or "NORMAL") end local function Button_Enable(self) - DefaultButton_Enable(self) - if self.locked_state then - Button_SetButtonState(self, self.locked_state, true) - else - Button_SetState(self) - end + DefaultButton_Enable(self) + if self.locked_state then + Button_SetButtonState(self, self.locked_state, true) + else + Button_SetState(self) + end end local function Button_Disable(self) - DefaultButton_Disable(self) - Button_SetState(self) + DefaultButton_Disable(self) + Button_SetState(self) end local function MakeButton(parent) - local button = CreateFrame("Button", nil, parent) - button:SetNormalFontObject(GameFontNormal) - button:SetHighlightFontObject(GameFontHighlight) - button:SetDisabledFontObject(GameFontDisable) - - local texture = button:CreateTexture() - texture:SetTexCoord(0, 0.09375, 0, 0.6875) - texture:SetPoint"LEFT" - texture:SetSize(12, 22) - button.left = texture - - texture = button:CreateTexture() - texture:SetTexCoord(0.53125, 0.625, 0, 0.6875) - texture:SetPoint"RIGHT" - texture:SetSize(12, 22) - button.right = texture - - texture = button:CreateTexture() - texture:SetTexCoord(0.09375, 0.53125, 0, 0.6875) - texture:SetPoint("LEFT", button.left, "RIGHT") - texture:SetPoint("RIGHT", button.right, "LEFT") - texture:SetHeight(22) - button.middle = texture - - texture = button:CreateTexture() - texture:SetTexture"Interface\\Buttons\\UI-Panel-Button-Highlight" - texture:SetBlendMode"ADD" - texture:SetTexCoord(0, 0.625, 0, 0.6875) - texture:SetAllPoints(button) - button:SetHighlightTexture(texture) - - button:SetScript("OnMouseDown", Button_OnMouseDown) - button:SetScript("OnMouseUp", Button_OnMouseUp) - button:SetScript("OnShow", Button_SetState) - button.Enable = Button_Enable - button.Disable = Button_Disable - button.SetButtonState = Button_SetButtonState - - table.insert(Talented.uielements, button) - return button + local button = CreateFrame("Button", nil, parent) + button:SetNormalFontObject(GameFontNormal) + button:SetHighlightFontObject(GameFontHighlight) + button:SetDisabledFontObject(GameFontDisable) + + local texture = button:CreateTexture() + texture:SetTexCoord(0, 0.09375, 0, 0.6875) + texture:SetPoint "LEFT" + texture:SetSize(12, 22) + button.left = texture + + texture = button:CreateTexture() + texture:SetTexCoord(0.53125, 0.625, 0, 0.6875) + texture:SetPoint "RIGHT" + texture:SetSize(12, 22) + button.right = texture + + texture = button:CreateTexture() + texture:SetTexCoord(0.09375, 0.53125, 0, 0.6875) + texture:SetPoint("LEFT", button.left, "RIGHT") + texture:SetPoint("RIGHT", button.right, "LEFT") + texture:SetHeight(22) + button.middle = texture + + texture = button:CreateTexture() + texture:SetTexture "Interface\\Buttons\\UI-Panel-Button-Highlight" + texture:SetBlendMode "ADD" + texture:SetTexCoord(0, 0.625, 0, 0.6875) + texture:SetAllPoints(button) + button:SetHighlightTexture(texture) + + button:SetScript("OnMouseDown", Button_OnMouseDown) + button:SetScript("OnMouseUp", Button_OnMouseUp) + button:SetScript("OnShow", Button_SetState) + button.Enable = Button_Enable + button.Disable = Button_Disable + button.SetButtonState = Button_SetButtonState + + table.insert(Talented.uielements, button) + return button end local function CreateBaseButtons(parent) - local function Frame_OnEnter(self) - if self.tooltip then - GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT") - GameTooltip:SetText(self.tooltip, nil, nil, nil, nil, 1) - end - end - - local function Frame_OnLeave(self) - if GameTooltip:IsOwned(self) then - GameTooltip:Hide() - end - end - - local b = MakeButton(parent) - parent.bactions = b - b:SetText(L["Actions"]) - b:SetSize(max(110, b:GetTextWidth() + 22), 22) - b:SetScript("OnClick", function (self) - Talented:OpenActionMenu(self) - end) - b:SetPoint("TOPLEFT", 14, -4) - - b = MakeButton(parent) - parent.bmode = b - b:SetText(L["Templates"]) - b:SetSize(max(110, b:GetTextWidth() + 22), 22) - b:SetScript("OnClick", function (self) - Talented:OpenTemplateMenu(self) - end) - b:SetPoint("LEFT", parent.bactions, "RIGHT", 14, 0) - - local e = CreateFrame("EditBox", nil, parent, "InputBoxTemplate") - parent.editname = e - e:SetFontObject(ChatFontNormal) - e:SetTextColor(GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b) - e:SetSize(200, 13) - e:SetAutoFocus(false) - e:SetScript("OnEscapePressed", function (this) - this:ClearFocus() - end) - e:SetScript("OnEditFocusLost", function (this) - this:SetText(Talented.template.name) - end) - e:SetScript("OnEnterPressed", function (this) - Talented:UpdateTemplateName(Talented.template, this:GetText()) - Talented:UpdateView() - this:ClearFocus() - end) - e:SetScript("OnEnter", Frame_OnEnter) - e:SetScript("OnLeave", Frame_OnLeave) - e:SetPoint("LEFT", parent.bmode, "RIGHT", 14, 1) - e.tooltip = L["You can edit the name of the template here. You must press the Enter key to save your changes."] - - local fs = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal") - fs:SetJustifyH("LEFT") - fs:SetSize(200, 13) - fs:SetPoint("LEFT", parent.bmode, "RIGHT", 14, 0) - parent.targetname = fs - - do - local f = CreateFrame("Frame", nil, parent) - local fs = f:CreateFontString(nil, "OVERLAY", "GameFontNormal") - fs:SetJustifyH("RIGHT") - fs:SetPoint("BOTTOMRIGHT", parent, "BOTTOMRIGHT", -14, 8) - f:SetPoint("BOTTOMRIGHT") - f:SetFrameLevel(parent:GetFrameLevel()+2) - f.text = fs - parent.pointsleft = f - end - - local cb = CreateFrame("Checkbutton", nil, parent) - parent.checkbox = cb - - local makeTexture = function (path, blend) - local t = cb:CreateTexture() - t:SetTexture(path) - t:SetAllPoints(cb) - if blend then - t:SetBlendMode(blend) - end - return t - end - - cb:SetSize(20, 20) - - local fs = cb:CreateFontString(nil, "BACKGROUND", "GameFontNormal") - cb.label = fs - fs:SetJustifyH("LEFT") - fs:SetSize(400, 20) - fs:SetPoint("LEFT", cb, "RIGHT", 1, 1) - cb:SetNormalTexture(makeTexture("Interface\\Buttons\\UI-CheckBox-Up")) - cb:SetPushedTexture(makeTexture("Interface\\Buttons\\UI-CheckBox-Down")) - cb:SetDisabledTexture(makeTexture("Interface\\Buttons\\UI-CheckBox-Check-Disabled")) - cb:SetCheckedTexture(makeTexture("Interface\\Buttons\\UI-CheckBox-Check")) - cb:SetHighlightTexture(makeTexture("Interface\\Buttons\\UI-CheckBox-Highlight", "ADD")) - cb:SetScript("OnClick", function () - if Talented.mode == "edit" then - Talented:SetMode("view") - else - Talented:SetMode("edit") - end - end) - cb:SetScript("OnEnter", Frame_OnEnter) - cb:SetScript("OnLeave", Frame_OnLeave) - cb:SetPoint("BOTTOMLEFT", parent, "BOTTOMLEFT", 14, 8) - cb:SetFrameLevel(parent:GetFrameLevel() + 2) - - local points = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal") - parent.points = points - points:SetJustifyH("RIGHT") - points:SetSize(80, 14) - points:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -40, -6) - - -- local b = MakeButton(parent) - -- parent.bactivate = b - - -- b:SetText(TALENT_SPEC_ACTIVATE) - -- b:SetSize(b:GetTextWidth() + 40, 22) - -- b:SetScript("OnClick", function (self) - -- if self.talentGroup then - -- SetActiveTalentGroup(self.talentGroup) - -- end - -- end) - -- b:SetPoint("BOTTOM", 0, 6) - -- b:SetFrameLevel(parent:GetFrameLevel() + 2) + local function Frame_OnEnter(self) + if self.tooltip then + GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT") + GameTooltip:SetText(self.tooltip, nil, nil, nil, nil, 1) + end + end + + local function Frame_OnLeave(self) + if GameTooltip:IsOwned(self) then + GameTooltip:Hide() + end + end + + local b = MakeButton(parent) + parent.bactions = b + b:SetText(L["Actions"]) + b:SetSize(max(110, b:GetTextWidth() + 22), 22) + b:SetScript( + "OnClick", + function(self) + Talented:OpenActionMenu(self) + end + ) + b:SetPoint("TOPLEFT", 14, -4) + + b = MakeButton(parent) + parent.bmode = b + b:SetText(L["Templates"]) + b:SetSize(max(110, b:GetTextWidth() + 22), 22) + b:SetScript( + "OnClick", + function(self) + Talented:OpenTemplateMenu(self) + end + ) + b:SetPoint("LEFT", parent.bactions, "RIGHT", 14, 0) + + local e = CreateFrame("EditBox", nil, parent, "InputBoxTemplate") + parent.editname = e + e:SetFontObject(ChatFontNormal) + e:SetTextColor(GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b) + e:SetSize(200, 13) + e:SetAutoFocus(false) + e:SetScript( + "OnEscapePressed", + function(this) + this:ClearFocus() + end + ) + e:SetScript( + "OnEditFocusLost", + function(this) + this:SetText(Talented.template.name) + end + ) + e:SetScript( + "OnEnterPressed", + function(this) + Talented:UpdateTemplateName(Talented.template, this:GetText()) + Talented:UpdateView() + this:ClearFocus() + end + ) + e:SetScript("OnEnter", Frame_OnEnter) + e:SetScript("OnLeave", Frame_OnLeave) + e:SetPoint("LEFT", parent.bmode, "RIGHT", 14, 1) + e.tooltip = L["You can edit the name of the template here. You must press the Enter key to save your changes."] + + local fs = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal") + fs:SetJustifyH("LEFT") + fs:SetSize(200, 13) + fs:SetPoint("LEFT", parent.bmode, "RIGHT", 14, 0) + parent.targetname = fs + + do + local f = CreateFrame("Frame", nil, parent) + local fs = f:CreateFontString(nil, "OVERLAY", "GameFontNormal") + fs:SetJustifyH("RIGHT") + fs:SetPoint("BOTTOMRIGHT", parent, "BOTTOMRIGHT", -14, 8) + f:SetPoint("BOTTOMRIGHT") + f:SetFrameLevel(parent:GetFrameLevel() + 2) + f.text = fs + parent.pointsleft = f + end + + local cb = CreateFrame("Checkbutton", nil, parent) + parent.checkbox = cb + + local makeTexture = function(path, blend) + local t = cb:CreateTexture() + t:SetTexture(path) + t:SetAllPoints(cb) + if blend then + t:SetBlendMode(blend) + end + return t + end + + cb:SetSize(20, 20) + + local fs = cb:CreateFontString(nil, "BACKGROUND", "GameFontNormal") + cb.label = fs + fs:SetJustifyH("LEFT") + fs:SetSize(400, 20) + fs:SetPoint("LEFT", cb, "RIGHT", 1, 1) + cb:SetNormalTexture(makeTexture("Interface\\Buttons\\UI-CheckBox-Up")) + cb:SetPushedTexture(makeTexture("Interface\\Buttons\\UI-CheckBox-Down")) + cb:SetDisabledTexture(makeTexture("Interface\\Buttons\\UI-CheckBox-Check-Disabled")) + cb:SetCheckedTexture(makeTexture("Interface\\Buttons\\UI-CheckBox-Check")) + cb:SetHighlightTexture(makeTexture("Interface\\Buttons\\UI-CheckBox-Highlight", "ADD")) + cb:SetScript( + "OnClick", + function() + if Talented.mode == "edit" then + Talented:SetMode("view") + else + Talented:SetMode("edit") + end + end + ) + cb:SetScript("OnEnter", Frame_OnEnter) + cb:SetScript("OnLeave", Frame_OnLeave) + cb:SetPoint("BOTTOMLEFT", parent, "BOTTOMLEFT", 14, 8) + cb:SetFrameLevel(parent:GetFrameLevel() + 2) + + local points = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal") + parent.points = points + points:SetJustifyH("RIGHT") + points:SetSize(80, 14) + points:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -40, -6) + + local b = MakeButton(parent) + parent.bactivate = b + b:SetText(TALENT_SPEC_ACTIVATE) + b:SetSize(b:GetTextWidth() + 40, 22) + b:SetScript( + "OnClick", + function(self) + if self.talentGroup then + if C_SpecializationInfo and C_SpecializationInfo.SetActiveSpecGroup then + C_SpecializationInfo.SetActiveSpecGroup(self.talentGroup) + else + SetActiveTalentGroup(self.talentGroup) + end + end + end + ) + b:SetPoint("BOTTOM", 0, 6) + b:SetFrameLevel(parent:GetFrameLevel() + 2) end local function BaseFrame_SetTabSize(self, tabs) - local tabs = tabs or 3 - local bmode, editname, targetname, points = self.bmode, self.editname, self.targetname, self.points - editname:ClearAllPoints() - targetname:ClearAllPoints() - points:ClearAllPoints() - if tabs == 1 then - editname:SetPoint("TOPLEFT", bmode, "BOTTOMLEFT", 0, -4) - targetname:SetPoint("TOPLEFT", bmode, "BOTTOMLEFT", 0, -5) - points:SetPoint("TOPRIGHT", self, "TOPRIGHT", -8, -56) - elseif tabs == 2 then - editname:SetPoint("TOPLEFT", bmode, "BOTTOMLEFT", 0, -4) - targetname:SetPoint("TOPLEFT", bmode, "BOTTOMLEFT", 0, -5) - points:SetPoint("TOPRIGHT", self, "TOPRIGHT", -8, -31) - elseif tabs == 3 then - editname:SetPoint("LEFT", bmode, "RIGHT", 14, 1) - targetname:SetPoint("LEFT", bmode, "RIGHT", 14, 0) - points:SetPoint("TOPRIGHT", self, "TOPRIGHT", -40, -6) - end + local tabs = tabs or 3 + local bmode, editname, targetname, points = self.bmode, self.editname, self.targetname, self.points + editname:ClearAllPoints() + targetname:ClearAllPoints() + points:ClearAllPoints() + if tabs == 1 then + editname:SetPoint("TOPLEFT", bmode, "BOTTOMLEFT", 0, -4) + targetname:SetPoint("TOPLEFT", bmode, "BOTTOMLEFT", 0, -5) + points:SetPoint("TOPRIGHT", self, "TOPRIGHT", -8, -56) + elseif tabs == 2 then + editname:SetPoint("TOPLEFT", bmode, "BOTTOMLEFT", 0, -4) + targetname:SetPoint("TOPLEFT", bmode, "BOTTOMLEFT", 0, -5) + points:SetPoint("TOPRIGHT", self, "TOPRIGHT", -8, -31) + elseif tabs == 3 then + editname:SetPoint("LEFT", bmode, "RIGHT", 14, 1) + targetname:SetPoint("LEFT", bmode, "RIGHT", 14, 0) + points:SetPoint("TOPRIGHT", self, "TOPRIGHT", -40, -6) + end end local function CloseButton_OnClick(self, button) - if button == "LeftButton" then - if self.OnClick then - self:OnClick(button) - else - self:GetParent():Hide() - end - else - Talented:OpenLockMenu(self, self:GetParent()) - end + if button == "LeftButton" then + if self.OnClick then + self:OnClick(button) + else + self:GetParent():Hide() + end + else + Talented:OpenLockMenu(self, self:GetParent()) + end end function Talented:CreateCloseButton(parent, OnClickHandler) - local close = CreateFrame("Button", nil, parent) - - local makeTexture = function (path, blend) - local t = close:CreateTexture() - t:SetAllPoints(close) - t:SetTexture(path) - if blend then - t:SetBlendMode(blend) - end - return t - end - - close:SetNormalTexture(makeTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Up")) - close:SetPushedTexture(makeTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Down")) - close:SetHighlightTexture(makeTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight", "ADD")) - close:RegisterForClicks("LeftButtonUp", "RightButtonUp") - close:SetScript("OnClick", CloseButton_OnClick) - close.OnClick = OnClickHandler - - close:SetSize(32, 32) - close:SetPoint("TOPRIGHT", 1, 0) - - return close + local close = CreateFrame("Button", nil, parent) + + local makeTexture = function(path, blend) + local t = close:CreateTexture() + t:SetAllPoints(close) + t:SetTexture(path) + if blend then + t:SetBlendMode(blend) + end + return t + end + + close:SetNormalTexture(makeTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Up")) + close:SetPushedTexture(makeTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Down")) + close:SetHighlightTexture(makeTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight", "ADD")) + close:RegisterForClicks("LeftButtonUp", "RightButtonUp") + close:SetScript("OnClick", CloseButton_OnClick) + close.OnClick = OnClickHandler + + close:SetSize(32, 32) + close:SetPoint("TOPRIGHT", 1, 0) + + return close end function Talented:CreateBaseFrame() - local frame = TalentedFrame or CreateFrame("Frame", "TalentedFrame", UIParent, "BackdropTemplate") - frame:Hide() - - frame:SetFrameStrata("DIALOG") - frame:EnableMouse(true) - frame:SetToplevel(true) - frame:SetSize(50, 50) - frame:SetBackdrop({ - bgFile = "Interface\\TutorialFrame\\TutorialFrameBackground", - edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", - tile = true, - edgeSize = 16, - tileSize = 32, - insets = { - left = 5, - right = 5, - top = 5, - bottom = 5 - } - }) - - - local close = self:CreateCloseButton(frame, function (self) - -- HideUIPanel(self:GetParent()) - self:GetParent():Hide() - end) - frame.close = close - table.insert(Talented.uielements, close) - - CreateBaseButtons(frame) - - UISpecialFrames[#UISpecialFrames + 1] = "TalentedFrame" - - frame:SetScript("OnShow", function () - Talented:RegisterEvent"MODIFIER_STATE_CHANGED" - SetButtonPulse(TalentMicroButton, 0, 1) - PlaySound(6144) --ID for TalentScreenOpen https://www.wowhead.com/sound=6144/unknown-sound - Talented:UpdateMicroButtons() - end) - frame:SetScript("OnHide", function() - PlaySound(6145) --ID for TalentScreenClose - if Talented.mode == "apply" then - Talented:SetMode(Talented:GetDefaultMode()) - Talented:Print(L["Error! Talented window has been closed during template application. Please reapply later."]) - Talented:EnableUI(true) - end - Talented:CloseMenu() - Talented:UpdateMicroButtons() - Talented:UnregisterEvent"MODIFIER_STATE_CHANGED" - end) - frame.SetTabSize = BaseFrame_SetTabSize - frame.view = self.TalentView:new(frame, "base") - self:LoadFramePosition(frame) - self:SetFrameLock(frame) - - self.base = frame - self.CreateBaseFrame = function (self) return self.base end - return frame + local frame = TalentedFrame or CreateFrame("Frame", "TalentedFrame", UIParent, "BackdropTemplate") + frame:Hide() + + frame:SetFrameStrata("DIALOG") + frame:EnableMouse(true) + frame:SetToplevel(true) + frame:SetSize(50, 50) + frame:SetBackdrop( + { + bgFile = "Interface\\TutorialFrame\\TutorialFrameBackground", + edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", + tile = true, + edgeSize = 16, + tileSize = 32, + insets = { + left = 5, + right = 5, + top = 5, + bottom = 5 + } + } + ) + + local close = + self:CreateCloseButton( + frame, + function(self) + -- HideUIPanel(self:GetParent()) + self:GetParent():Hide() + end + ) + frame.close = close + table.insert(Talented.uielements, close) + + CreateBaseButtons(frame) + + UISpecialFrames[#UISpecialFrames + 1] = "TalentedFrame" + + frame:SetScript( + "OnShow", + function() + Talented:RegisterEvent "MODIFIER_STATE_CHANGED" + SetButtonPulse(TalentMicroButton, 0, 1) + PlaySound(6144) --ID for TalentScreenOpen https://www.wowhead.com/sound=6144/unknown-sound + Talented:UpdateMicroButtons() + end + ) + frame:SetScript( + "OnHide", + function() + PlaySound(6145) --ID for TalentScreenClose + if Talented.mode == "apply" then + Talented:SetMode(Talented:GetDefaultMode()) + Talented:Print( + L["Error! Talented window has been closed during template application. Please reapply later."] + ) + Talented:EnableUI(true) + end + Talented:CloseMenu() + Talented:UpdateMicroButtons() + Talented:UnregisterEvent "MODIFIER_STATE_CHANGED" + end + ) + frame.SetTabSize = BaseFrame_SetTabSize + frame.view = self.TalentView:new(frame, "base") + self:LoadFramePosition(frame) + self:SetFrameLock(frame) + + self.base = frame + self.CreateBaseFrame = function(self) + return self.base + end + return frame end function Talented:EnableUI(enable) - if enable then - for _, element in ipairs(self.uielements) do - element:Enable() - end - else - for _, element in ipairs(self.uielements) do - element:Disable() - end - end + if enable then + for _, element in ipairs(self.uielements) do + element:Enable() + end + else + for _, element in ipairs(self.uielements) do + element:Disable() + end + end end function Talented:MakeAlternateView() - local frame = CreateFrame("Frame", "TalentedAltFrame", UIParent, "BackdropTemplate") - - frame:SetFrameStrata("DIALOG") - if TalentedFrame then - frame:SetFrameLevel(TalentedFrame:GetFrameLevel() + 5) - end - frame:EnableMouse(true) - frame:SetToplevel(true) - frame:SetSize(50, 50) - frame:SetBackdrop({ - bgFile = "Interface\\TutorialFrame\\TutorialFrameBackground", - edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", - tile = true, - edgeSize = 16, - tileSize = 32, - insets = { - left = 5, - right = 5, - top = 5, - bottom = 5 - } - }) - - frame.close = self:CreateCloseButton(frame) - frame.view = self.TalentView:new(frame, "alt") - self:LoadFramePosition(frame) - self:SetFrameLock(frame) - - self.altView = frame - self.MakeAlternateView = function (self) return self.altView end - return frame + local frame = CreateFrame("Frame", "TalentedAltFrame", UIParent, "BackdropTemplate") + + frame:SetFrameStrata("DIALOG") + if TalentedFrame then + frame:SetFrameLevel(TalentedFrame:GetFrameLevel() + 5) + end + frame:EnableMouse(true) + frame:SetToplevel(true) + frame:SetSize(50, 50) + frame:SetBackdrop( + { + bgFile = "Interface\\TutorialFrame\\TutorialFrameBackground", + edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", + tile = true, + edgeSize = 16, + tileSize = 32, + insets = { + left = 5, + right = 5, + top = 5, + bottom = 5 + } + } + ) + + frame.close = self:CreateCloseButton(frame) + frame.view = self.TalentView:new(frame, "alt") + self:LoadFramePosition(frame) + self:SetFrameLock(frame) + + self.altView = frame + self.MakeAlternateView = function(self) + return self.altView + end + return frame end diff --git a/Era/Talented/ui/menu.lua b/Era/Talented/ui/menu.lua index 64161df..17f3cc9 100644 --- a/Era/Talented/ui/menu.lua +++ b/Era/Talented/ui/menu.lua @@ -9,477 +9,501 @@ FillLocalizedClassList(classNames, false) local menuColorCodes = {} local function fill_menuColorCodes() - for name, default in pairs(RAID_CLASS_COLORS) do - local color = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[name] or default - menuColorCodes[name] = string.format("|cff%2x%2x%2x", color.r * 255, color.g * 255, color.b * 255) - end - -- menuColorCodes["Ferocity"] = "|cffe0a040" - -- menuColorCodes["Tenacity"] = "|cffe0a040" - -- menuColorCodes["Cunning"] = "|cffe0a040" + for name, default in pairs(RAID_CLASS_COLORS) do + local color = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[name] or default + menuColorCodes[name] = string.format("|cff%2x%2x%2x", color.r * 255, color.g * 255, color.b * 255) + end + -- menuColorCodes["Ferocity"] = "|cffe0a040" + -- menuColorCodes["Tenacity"] = "|cffe0a040" + -- menuColorCodes["Cunning"] = "|cffe0a040" end fill_menuColorCodes() if CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS.RegisterCallback then - CUSTOM_CLASS_COLORS:RegisterCallback(fill_menuColorCodes) + CUSTOM_CLASS_COLORS:RegisterCallback(fill_menuColorCodes) end function Talented:OpenOptionsFrame() - LibStub("AceConfigDialog-3.0"):Open("Talented") + LibStub("AceConfigDialog-3.0"):Open("Talented") end function Talented:GetNamedMenu(name) - local menus = self.menus - if not menus then - menus = {} - self.menus = menus - end - local menu = menus[name] - if not menu then - menu = {} - menus[name] = menu - end - return menu + local menus = self.menus + if not menus then + menus = {} + self.menus = menus + end + local menu = menus[name] + if not menu then + menu = {} + menus[name] = menu + end + return menu end local function Menu_SetTemplate(entry, template) - if IsShiftKeyDown() then - local frame = Talented:MakeAlternateView() - frame.view:SetTemplate(template) - frame.view:SetViewMode"view" - frame:Show() - else - Talented:OpenTemplate(template) - end - Talented:CloseMenu() + if IsShiftKeyDown() then + local frame = Talented:MakeAlternateView() + frame.view:SetTemplate(template) + frame.view:SetViewMode "view" + frame:Show() + else + Talented:OpenTemplate(template) + end + Talented:CloseMenu() end local function Menu_IsTemplatePlayerClass() - return Talented.template.class == select(2, UnitClass("player")) + return Talented.template.class == select(2, UnitClass("player")) end local function Menu_NewTemplate(entry, class) - Talented:OpenTemplate(Talented:CreateEmptyTemplate(class)) - Talented:CloseMenu() + Talented:OpenTemplate(Talented:CreateEmptyTemplate(class)) + Talented:CloseMenu() end function Talented:CreateTemplateMenu() - local menu = self:GetNamedMenu("Template") - - local entry = self:GetNamedMenu("primary") - entry.text = TALENT_SPEC_PRIMARY - entry.func = Menu_SetTemplate - entry.arg1 = self.current - menu[#menu + 1] = entry - - entry = self:GetNamedMenu("separator") - if not entry.text then - entry.text = "" - entry.disabled = true - entry.separator = true - end - menu[#menu + 1] = entry - - local list = {} - for index, name in ipairs(CLASS_SORT_ORDER) do - list[index] = name - end - - for _, name in ipairs(list) do - entry = self:GetNamedMenu(name) - entry.text = classNames[name] - entry.colorCode = menuColorCodes[name] - entry.hasArrow = true - entry.menuList = self:GetNamedMenu(name.."List") - menu[#menu + 1] = entry - end - - -- menu[#menu + 1] = self:GetNamedMenu("separator") - - -- entry = self:GetNamedMenu("Inspected") - -- entry.text = L["Inspected Characters"] - -- entry.hasArrow = true - -- entry.menuList = self:GetNamedMenu("InspectedList") - -- menu[#menu + 1] = entry - - self.CreateTemplateMenu = function (self) return self:GetNamedMenu("Template") end - return menu + local menu = self:GetNamedMenu("Template") + + local entry = self:GetNamedMenu("primary") + entry.text = TALENT_SPEC_PRIMARY + entry.func = Menu_SetTemplate + menu[#menu + 1] = entry + + entry = self:GetNamedMenu("secondary") + entry.text = TALENT_SPEC_SECONDARY + entry.disabled = true + entry.func = Menu_SetTemplate + menu[#menu + 1] = entry + + entry = self:GetNamedMenu("separator") + if not entry.text then + entry.text = "" + entry.disabled = true + entry.separator = true + end + menu[#menu + 1] = entry + + local list = {} + for index, name in ipairs(CLASS_SORT_ORDER) do + list[index] = name + end + + for _, name in ipairs(list) do + entry = self:GetNamedMenu(name) + entry.text = classNames[name] + entry.colorCode = menuColorCodes[name] + entry.hasArrow = true + entry.menuList = self:GetNamedMenu(name .. "List") + menu[#menu + 1] = entry + end + + -- menu[#menu + 1] = self:GetNamedMenu("separator") + + -- entry = self:GetNamedMenu("Inspected") + -- entry.text = L["Inspected Characters"] + -- entry.hasArrow = true + -- entry.menuList = self:GetNamedMenu("InspectedList") + -- menu[#menu + 1] = entry + + self.CreateTemplateMenu = function(self) + return self:GetNamedMenu("Template") + end + return menu end local function Sort_Template_Menu_Entry(a, b) - a, b = a.text, b.text - if not a then return false end - if not b then return true end - return a < b + a, b = a.text, b.text + if not a then + return false + end + if not b then + return true + end + return a < b end local function update_template_entry(entry, name, template) - local points = template.points - if not points then - points = Talented:GetTemplateInfo(template) - template.points = points - end - entry.text = name..points + local points = template.points + if not points then + points = Talented:GetTemplateInfo(template) + template.points = points + end + entry.text = name .. points end function Talented:MakeTemplateMenu() - local menu = self:CreateTemplateMenu() - - - for cindex, class in pairs(CLASS_SORT_ORDER) do - color = menuColorCodes[class] --Looping through menuColorCodes would give us Death Knight, etc, which aren't in classic - local menuList = self:GetNamedMenu(class.."List") - local index = 1 - classdb = self.db.global.templates[class] - if classdb ~= nil then - for name, template in pairs(classdb) do - if template.class == class then - local entry = menuList[index] - if not entry then - entry = {} - menuList[index] = entry - end - index = index + 1 - update_template_entry(entry, name, template) - entry.func = Menu_SetTemplate - entry.checked = (self.template == template) - entry.arg1 = template - entry.colorCode = color - end - end - end - for i = index, #menuList do - menuList[i].text = nil - end - table.sort(menuList, Sort_Template_Menu_Entry) - local menu = self:GetNamedMenu(class) - menu.text = classNames[class] - if index == 1 then - menu.disabled = true - else - menu.disabled = nil - menu.colorCode = color - end - end - - -- if not self.inspections then - -- self:GetNamedMenu("Inspected").disabled = true - -- else - -- self:GetNamedMenu("Inspected").disabled = nil - -- local menuList = self:GetNamedMenu("InspectedList") - -- local index = 1 - -- for name, template in pairs(self.inspections) do - -- local entry = menuList[index] - -- if not entry then - -- entry = {} - -- menuList[index] = entry - -- end - -- index = index + 1 - -- update_template_entry(entry, name, template) - -- entry.func = Menu_SetTemplate - -- entry.checked = (self.template == template) - -- entry.arg1 = template - -- entry.colorCode = menuColorCodes[template.class] - -- end - -- table.sort(menuList, Sort_Template_Menu_Entry) - -- end - -- local talentGroup = GetActiveTalentGroup() - -- local entry = self:GetNamedMenu("primary") - -- local current = self.alternates[1] - -- update_template_entry(entry, TALENT_SPEC_PRIMARY, current) - -- entry.arg1 = current - -- entry.checked = (self.template == current) - -- if #self.alternates > 1 then - -- local alt = self.alternates[2] - -- local entry = self:GetNamedMenu("secondary") - -- entry.disabled = false - -- update_template_entry(entry, TALENT_SPEC_SECONDARY, alt) - -- entry.arg1 = alt - -- entry.checked = (self.template == alt) - -- end - - return menu + local menu = self:CreateTemplateMenu() + + for cindex, class in pairs(CLASS_SORT_ORDER) do + color = menuColorCodes[class] --Looping through menuColorCodes would give us Death Knight, etc, which aren't in classic + local menuList = self:GetNamedMenu(class .. "List") + local index = 1 + classdb = self.db.global.templates[class] + if classdb ~= nil then + for name, template in pairs(classdb) do + if template.class == class then + local entry = menuList[index] + if not entry then + entry = {} + menuList[index] = entry + end + index = index + 1 + update_template_entry(entry, name, template) + entry.func = Menu_SetTemplate + entry.checked = (self.template == template) + entry.arg1 = template + entry.colorCode = color + end + end + end + for i = index, #menuList do + menuList[i].text = nil + end + table.sort(menuList, Sort_Template_Menu_Entry) + local menu = self:GetNamedMenu(class) + menu.text = classNames[class] + if index == 1 then + menu.disabled = true + else + menu.disabled = nil + menu.colorCode = color + end + end + + -- if not self.inspections then + -- self:GetNamedMenu("Inspected").disabled = true + -- else + -- self:GetNamedMenu("Inspected").disabled = nil + -- local menuList = self:GetNamedMenu("InspectedList") + -- local index = 1 + -- for name, template in pairs(self.inspections) do + -- local entry = menuList[index] + -- if not entry then + -- entry = {} + -- menuList[index] = entry + -- end + -- index = index + 1 + -- update_template_entry(entry, name, template) + -- entry.func = Menu_SetTemplate + -- entry.checked = (self.template == template) + -- entry.arg1 = template + -- entry.colorCode = menuColorCodes[template.class] + -- end + -- table.sort(menuList, Sort_Template_Menu_Entry) + -- end + -- Old: local talentGroup = GetActiveTalentGroup() + local talentGroup = C_SpecializationInfo and C_SpecializationInfo.GetActiveSpecGroup() or GetActiveTalentGroup() + local entry = self:GetNamedMenu("primary") + local current = self.alternates[1] + update_template_entry(entry, TALENT_SPEC_PRIMARY, current) + entry.arg1 = current + entry.checked = (self.template == current) + if #self.alternates > 1 then + local alt = self.alternates[2] + local entry = self:GetNamedMenu("secondary") + entry.disabled = false + update_template_entry(entry, TALENT_SPEC_SECONDARY, alt) + entry.arg1 = alt + entry.checked = (self.template == alt) + end + + return menu end StaticPopupDialogs["TALENTED_IMPORT_URL"] = { - text = L["Enter the complete URL of a template from Blizzard talent calculator or wowhead."], - button1 = ACCEPT, - button2 = CANCEL, - hasEditBox = 1, - hasWideEditBox = 1, - maxLetters = 256, - whileDead = 1, - OnShow = function (self) - self.editBox:SetText"" - end, - OnAccept = function(self) - local url = self.editBox:GetText() - self:Hide() - local template = Talented:ImportTemplate(url) - if template then Talented:OpenTemplate(template) end - end, - timeout = 0, - EditBoxOnEnterPressed = function(self) - local parent = self:GetParent() - StaticPopupDialogs[parent.which].OnAccept(parent) - self:GetParent():Hide() - end, - EditBoxOnEscapePressed = function(self) - self:GetParent():Hide(); - end, - hideOnEscape = 1 - + text = L["Enter the complete URL of a template from Blizzard talent calculator or wowhead."], + button1 = ACCEPT, + button2 = CANCEL, + hasEditBox = 1, + hasWideEditBox = 1, + maxLetters = 256, + whileDead = 1, + OnShow = function(self) + self.EditBox:SetText "" + end, + OnAccept = function(self) + local url = self.EditBox:GetText() + self:Hide() + local template = Talented:ImportTemplate(url) + if template then + Talented:OpenTemplate(template) + end + end, + timeout = 0, + EditBoxOnEnterPressed = function(self) + local parent = self:GetParent() + StaticPopupDialogs[parent.which].OnAccept(parent) + self:GetParent():Hide() + end, + EditBoxOnEscapePressed = function(self) + self:GetParent():Hide() + end, + hideOnEscape = 1 } StaticPopupDialogs["TALENTED_EXPORT_TO"] = { - text = L["Enter the name of the character you want to send the template to."], - button1 = ACCEPT, - button2 = CANCEL, - hasEditBox = 1, - maxLetters = 256, - whileDead = 1, - autoCompleteParams = AUTOCOMPLETE_LIST.WHISPER, - OnAccept = function(self) - local name = self.editBox:GetText() - self:Hide() - Talented:ExportTemplateToUser(name) - end, - timeout = 0, - EditBoxOnEnterPressed = - StaticPopupDialogs.TALENTED_IMPORT_URL.EditBoxOnEnterPressed, - EditBoxOnEscapePressed = - StaticPopupDialogs.TALENTED_IMPORT_URL.EditBoxOnEscapePressed, - hideOnEscape = 1 + text = L["Enter the name of the character you want to send the template to."], + button1 = ACCEPT, + button2 = CANCEL, + hasEditBox = 1, + maxLetters = 256, + whileDead = 1, + autoCompleteParams = AUTOCOMPLETE_LIST.WHISPER, + OnAccept = function(self) + local name = self.EditBox:GetText() + self:Hide() + Talented:ExportTemplateToUser(name) + end, + timeout = 0, + EditBoxOnEnterPressed = StaticPopupDialogs.TALENTED_IMPORT_URL.EditBoxOnEnterPressed, + EditBoxOnEscapePressed = StaticPopupDialogs.TALENTED_IMPORT_URL.EditBoxOnEscapePressed, + hideOnEscape = 1 } function Talented:CreateActionMenu() - local menu = self:GetNamedMenu("Action") - - local menuList = self:GetNamedMenu("NewTemplates") - - local list = {} - for index, name in ipairs(CLASS_SORT_ORDER) do - list[index] = name - end - -- list[#list + 1] = "Ferocity" - -- list[#list + 1] = "Tenacity" - -- list[#list + 1] = "Cunning" - - for _, name in ipairs(list) do - local s = { - text = classNames[name], - colorCode = menuColorCodes[name], - func = Menu_NewTemplate, - arg1 = name - } - menuList[#menuList + 1] = s - end - - menu[#menu + 1] = { - text = L["New Template"], - hasArrow = true, - menuList = menuList, - } - local entry = self:GetNamedMenu("separator") - if not entry.text then - entry.text = "" - entry.disabled = true - entry.separator = true - end - menu[#menu + 1] = entry - - entry = self:GetNamedMenu("Apply") - entry.text = L["Apply template"] - entry.func = function () Talented:SetMode("apply") end - menu[#menu + 1] = entry - - -- entry = self:GetNamedMenu("SwitchTalentGroup") - -- entry.text = L["Switch to this Spec"] - -- entry.func = function (entry, talentGroup) SetActiveTalentGroup(talentGroup) end - -- menu[#menu + 1] = entry - - entry = self:GetNamedMenu("Delete") - entry.text = L["Delete template"] - entry.func = function () Talented:DeleteCurrentTemplate() end - menu[#menu + 1] = entry - - entry = self:GetNamedMenu("Copy") - entry.text = L["Copy template"] - entry.func = function () Talented:OpenTemplate(Talented:CopyTemplate(Talented.template)) end - menu[#menu + 1] = entry - - entry = self:GetNamedMenu("Target") - entry.text = L["Set as target"] - entry.func = function (entry, targetName, template) - if entry.checked then - Talented.db.char.targets[targetName] = nil - Talented.base.view:ClearTarget() - else - if not template then - Talented.base.view:ClearTarget() - else - Talented.db.char.targets[targetName] = {name = template.name, class = template.class} - end - end - end - entry.arg2 = self.template - menu[#menu + 1] = entry - - menu[#menu + 1] = self:GetNamedMenu("separator") - menu[#menu + 1] = { - text = L["Import template ..."], - func = function () - StaticPopup_Show"TALENTED_IMPORT_URL" - end, - } - - menu[#menu + 1] = { - text = L["Export template"], - hasArrow = true, - menuList = self:GetNamedMenu("exporters"), - } - - menu[#menu + 1] = { - text = L["Send to ..."], - func = function () - StaticPopup_Show"TALENTED_EXPORT_TO" - end, - } - - menu[#menu + 1] = { - text = L["Options ..."], - func = function () - Talented:OpenOptionsFrame() - end, - } - - self.CreateActionMenu = function (self) return self:GetNamedMenu("Action") end - return menu + local menu = self:GetNamedMenu("Action") + + local menuList = self:GetNamedMenu("NewTemplates") + + local list = {} + for index, name in ipairs(CLASS_SORT_ORDER) do + list[index] = name + end + -- list[#list + 1] = "Ferocity" + -- list[#list + 1] = "Tenacity" + -- list[#list + 1] = "Cunning" + + for _, name in ipairs(list) do + local s = { + text = classNames[name], + colorCode = menuColorCodes[name], + func = Menu_NewTemplate, + arg1 = name + } + menuList[#menuList + 1] = s + end + + menu[#menu + 1] = { + text = L["New Template"], + hasArrow = true, + menuList = menuList + } + local entry = self:GetNamedMenu("separator") + if not entry.text then + entry.text = "" + entry.disabled = true + entry.separator = true + end + menu[#menu + 1] = entry + + entry = self:GetNamedMenu("Apply") + entry.text = L["Apply template"] + entry.func = function() + Talented:SetMode("apply") + end + menu[#menu + 1] = entry + + entry = self:GetNamedMenu("SwitchTalentGroup") + entry.text = L["Switch to this Spec"] + entry.func = function(entry, talentGroup) + SetActiveTalentGroup(talentGroup) + end + menu[#menu + 1] = entry + + entry = self:GetNamedMenu("Delete") + entry.text = L["Delete template"] + entry.func = function() + Talented:DeleteCurrentTemplate() + end + menu[#menu + 1] = entry + + entry = self:GetNamedMenu("Copy") + entry.text = L["Copy template"] + entry.func = function() + Talented:OpenTemplate(Talented:CopyTemplate(Talented.template)) + end + menu[#menu + 1] = entry + + entry = self:GetNamedMenu("Target") + entry.text = L["Set as target"] + entry.func = function(entry, targetName, template) + if entry.checked then + Talented.db.char.targets[targetName] = nil + Talented.base.view:ClearTarget() + else + if not template then + Talented.base.view:ClearTarget() + else + Talented.db.char.targets[targetName] = {name = template.name, class = template.class} + end + end + end + entry.arg2 = self.template + menu[#menu + 1] = entry + + menu[#menu + 1] = self:GetNamedMenu("separator") + menu[#menu + 1] = { + text = L["Import template ..."], + func = function() + StaticPopup_Show "TALENTED_IMPORT_URL" + end + } + + menu[#menu + 1] = { + text = L["Export template"], + hasArrow = true, + menuList = self:GetNamedMenu("exporters") + } + + menu[#menu + 1] = { + text = L["Send to ..."], + func = function() + StaticPopup_Show "TALENTED_EXPORT_TO" + end + } + + menu[#menu + 1] = { + text = L["Options ..."], + func = function() + Talented:OpenOptionsFrame() + end + } + + self.CreateActionMenu = function(self) + return self:GetNamedMenu("Action") + end + return menu end local function Export_Template(entry, handler) - local url = handler(Talented, Talented.template) - if url then - if Talented.db.profile.show_url_in_chat then - Talented:WriteToChat(url) - else - Talented:ShowInDialog(url) - end - end + local url = handler(Talented, Talented.template) + if url then + if Talented.db.profile.show_url_in_chat then + Talented:WriteToChat(url) + else + Talented:ShowInDialog(url) + end + end end function Talented:MakeActionMenu() - local menu = self:CreateActionMenu() - -- local templateTalentGroup, activeTalentGroup = self.template.talentGroup, GetActiveTalentGroup() - local template, current = self.template, self.current - local restricted = (self.template.class ~= select(2, UnitClass("player"))) - local targetName - if not restricted then - targetName = 1 --Primary talents, the only talent group ion calssic. Formerly targetName = templateTalentGroup or activeTalentGroup - end - - self:GetNamedMenu("Apply").disabled = self.template==self.current or restricted - self:GetNamedMenu("Delete").disabled = self.template==self.current or not self.db.global.templates[self.template.class][self.template.name] - -- local switch = self:GetNamedMenu("SwitchTalentGroup") - -- switch.disabled = (restricted or not templateTalentGroup or templateTalentGroup == activeTalentGroup) - -- switch.arg1 = templateTalentGroup - - local target = self:GetNamedMenu("Target") - if template == self.current then - target.text = L["Clear target"] - target.arg1 = targetName - target.arg2 = nil - target.disabled = not self.db.char.targets[targetName] - target.checked = nil - else - target.text = L["Set as target"] - target.arg1 = targetName - target.arg2 = self.template - target.disabled = not targetName - - target.checked = (self.db.char.targets[targetName] and self.db.char.targets[targetName].name == self.template.name) - end - - for _, entry in ipairs(self:GetNamedMenu("NewTemplates")) do - local class = entry.arg1 - entry.colorCode = menuColorCodes[class] - end - - local exporters = self:GetNamedMenu("exporters") - local index = 1 - for name, handler in pairs(self.exporters) do - exporters[index] = exporters[index] or {} - exporters[index].text = name - exporters[index].func = Export_Template - exporters[index].arg1 = handler - index = index + 1 - end - for i = index, #exporters do - exporters[i].text = nil - end - - return menu + local menu = self:CreateActionMenu() + -- Old: local templateTalentGroup, activeTalentGroup = self.template.talentGroup, GetActiveTalentGroup() + local templateTalentGroup = self.template.talentGroup + local activeTalentGroup = + C_SpecializationInfo and C_SpecializationInfo.GetActiveSpecGroup() or GetActiveTalentGroup() + local restricted = (self.template.class ~= select(2, UnitClass("player"))) + local targetName + if not restricted then + targetName = templateTalentGroup or activeTalentGroup + end + + self:GetNamedMenu("Apply").disabled = templateTalentGroup or restricted + self:GetNamedMenu("Delete").disabled = + templateTalentGroup or not self.db.global.templates[self.template.class][self.template.name] + local switch = self:GetNamedMenu("SwitchTalentGroup") + switch.disabled = (restricted or not templateTalentGroup or templateTalentGroup == activeTalentGroup) + switch.arg1 = templateTalentGroup + + local target = self:GetNamedMenu("Target") + if templateTalentGroup then + target.text = L["Clear target"] + target.arg1 = targetName + target.arg2 = nil + target.disabled = not self.db.char.targets[targetName] + target.checked = nil + else + target.text = L["Set as target"] + target.arg1 = targetName + target.arg2 = self.template + target.disabled = not targetName + + target.checked = + (self.db.char.targets[targetName] and self.db.char.targets[targetName].name == self.template.name) + end + + for _, entry in ipairs(self:GetNamedMenu("NewTemplates")) do + local class = entry.arg1 + entry.colorCode = menuColorCodes[class] + end + + local exporters = self:GetNamedMenu("exporters") + local index = 1 + for name, handler in pairs(self.exporters) do + exporters[index] = exporters[index] or {} + exporters[index].text = name + exporters[index].func = Export_Template + exporters[index].arg1 = handler + index = index + 1 + end + for i = index, #exporters do + exporters[i].text = nil + end + + return menu end function Talented:CloseMenu() - HideDropDownMenu(1) + HideDropDownMenu(1) end function Talented:GetDropdownFrame(frame) - local dropdown = CreateFrame("Frame", "TalentedDropDown", nil, "UIDropDownMenuTemplate") - dropdown.point = "TOPLEFT" - dropdown.relativePoint = "BOTTOMLEFT" - dropdown.displayMode = "MENU" - dropdown.xOffset = 2 - dropdown.yOffset = 2 - dropdown.relativeTo = frame - self.dropdown = dropdown - self.GetDropdownFrame = function (self, frame) - local dropdown = self.dropdown - dropdown.relativeTo = frame - return dropdown - end - return dropdown + local dropdown = CreateFrame("Frame", "TalentedDropDown", nil, "UIDropDownMenuTemplate") + dropdown.point = "TOPLEFT" + dropdown.relativePoint = "BOTTOMLEFT" + dropdown.displayMode = "MENU" + dropdown.xOffset = 2 + dropdown.yOffset = 2 + dropdown.relativeTo = frame + self.dropdown = dropdown + self.GetDropdownFrame = function(self, frame) + local dropdown = self.dropdown + dropdown.relativeTo = frame + return dropdown + end + return dropdown end -local function EasyMenu_Initialize( frame, level, menuList ) - for index = 1, #menuList do - local value = menuList[index] - if (value.text) then - value.index = index; - UIDropDownMenu_AddButton( value, level ); - end - end +local function EasyMenu_Initialize(frame, level, menuList) + for index = 1, #menuList do + local value = menuList[index] + if (value.text) then + value.index = index + UIDropDownMenu_AddButton(value, level) + end + end end -local function EasyMenu(menuList, menuFrame, anchor, x, y, displayMode, autoHideDelay ) - if ( displayMode == "MENU" ) then - menuFrame.displayMode = displayMode; - end - UIDropDownMenu_Initialize(menuFrame, EasyMenu_Initialize, displayMode, nil, menuList); - ToggleDropDownMenu(1, nil, menuFrame, anchor, x, y, menuList, nil, autoHideDelay); +local function EasyMenu(menuList, menuFrame, anchor, x, y, displayMode, autoHideDelay) + if (displayMode == "MENU") then + menuFrame.displayMode = displayMode + end + UIDropDownMenu_Initialize(menuFrame, EasyMenu_Initialize, displayMode, nil, menuList) + ToggleDropDownMenu(1, nil, menuFrame, anchor, x, y, menuList, nil, autoHideDelay) end function Talented:OpenTemplateMenu(frame) - EasyMenu(self:MakeTemplateMenu(), self:GetDropdownFrame(frame)) + EasyMenu(self:MakeTemplateMenu(), self:GetDropdownFrame(frame)) end function Talented:OpenActionMenu(frame) - EasyMenu(self:MakeActionMenu(), self:GetDropdownFrame(frame)) + EasyMenu(self:MakeActionMenu(), self:GetDropdownFrame(frame)) end function Talented:OpenLockMenu(frame, parent) - local menu = self:GetNamedMenu("LockFrame") - local entry = menu[1] - if not entry then - entry = { - text = L["Lock frame"], - func = function (entry, frame) - Talented:SetFrameLock(frame, not entry.checked) - end, - } - menu[1] = entry - end - entry.arg1 = parent - entry.checked = self:GetFrameLock(parent) - EasyMenu(menu, self:GetDropdownFrame(frame)) + local menu = self:GetNamedMenu("LockFrame") + local entry = menu[1] + if not entry then + entry = { + text = L["Lock frame"], + func = function(entry, frame) + Talented:SetFrameLock(frame, not entry.checked) + end + } + menu[1] = entry + end + entry.arg1 = parent + entry.checked = self:GetFrameLock(parent) + EasyMenu(menu, self:GetDropdownFrame(frame)) end