From 4bf79adda50450efed386cbb134708726ae737e2 Mon Sep 17 00:00:00 2001 From: Parnic Date: Sun, 26 Sep 2010 00:31:12 +0000 Subject: [PATCH] - added the ability to duplicate an existing custom bar --- IceCore.lua | 4 ++- IceHUD.lua | 58 ++++++++++++++++++++++------------------ modules/CustomBar.lua | 10 +++++++ modules/CustomCDBar.lua | 10 +++++++ modules/CustomCount.lua | 10 +++++++ modules/CustomHealth.lua | 10 +++++++ modules/CustomMana.lua | 10 +++++++ 7 files changed, 85 insertions(+), 27 deletions(-) diff --git a/IceCore.lua b/IceCore.lua index df2a369..c9a9d75 100644 --- a/IceCore.lua +++ b/IceCore.lua @@ -195,11 +195,13 @@ end function IceCore.prototype:AddNewDynamicModule(module, hasSettings) if not hasSettings then self.settings.modules[module.elementName] = module:GetDefaultSettings() + elseif type(hasSettings) == "table" then + self.settings.modules[module.elementName] = IceHUD.deepcopy(hasSettings) end module:SetDatabase(self.settings) - if not hasSettings then + if not hasSettings or type(hasSettings) == "table" then local numExisting = self:GetNumCustomModules(module, module:GetDefaultSettings().customBarType) self:RenameDynamicModule(module, "MyCustom"..module:GetDefaultSettings().customBarType..(numExisting+1)) end diff --git a/IceHUD.lua b/IceHUD.lua index 4a830cd..4694347 100644 --- a/IceHUD.lua +++ b/IceHUD.lua @@ -9,7 +9,7 @@ local AceSerializer = LibStub("AceSerializer-3.0", 1) local pendingModuleLoads = {} local bReadyToRegisterModules = false -local lastCustomModule = 1 +local lastCustomModule = "Bar" IceHUD.CurrTagVersion = 3 IceHUD.debugging = false @@ -17,7 +17,7 @@ IceHUD.debugging = false IceHUD.WowVer = select(4, GetBuildInfo()) IceHUD.validBarList = { "Bar", "HiBar", "RoundBar", "ColorBar", "RivetBar", "RivetBar2", "CleanCurves", "GlowArc", "BloodGlaives", "ArcHUD", "FangRune" } -IceHUD.validCustomModules = {"Buff/Debuff watcher", "Buff/Debuff stack counter", "Ability cooldown bar", "Health bar", "Mana bar"} +IceHUD.validCustomModules = {Bar="Buff/Debuff watcher", Counter="Buff/Debuff stack counter", CD="Ability cooldown bar", Health="Health bar", Mana="Mana bar"} local function deepcopy(object) local lookup_table = {} @@ -37,6 +37,8 @@ local function deepcopy(object) return _copy(object) end +IceHUD.deepcopy = deepcopy + IceHUD.Location = "Interface\\AddOns\\IceHUD" IceHUD.options = { @@ -599,30 +601,7 @@ Expand "|cffffdc42Module Settings|r", expand PlayerInfo (or TargetInfo for targe name = "Create", desc = "Creates the selected custom module", func = function() - local v = lastCustomModule - local newMod = nil - local popupMsg - if v == 1 then -- custom bar - newMod = IceCustomBar:new() - popupMsg = "ICEHUD_CUSTOM_BAR_CREATED" - elseif v == 2 then -- custom counter - newMod = IceCustomCount:new() - popupMsg = "ICEHUD_CUSTOM_COUNTER_CREATED" - elseif v == 3 then -- cooldown bar - newMod = IceCustomCDBar:new() - popupMsg = "ICEHUD_CUSTOM_CD_CREATED" - elseif v == 4 then -- custom health bar - newMod = IceCustomHealth:new() - popupMsg = "ICEHUD_CUSTOM_HEALTH_CREATED" - elseif v == 5 then -- custom mana bar - newMod = IceCustomMana:new() - popupMsg = "ICEHUD_CUSTOM_MANA_CREATED" - end - if newMod ~= nil then - IceHUD.IceCore:AddNewDynamicModule(newMod) - ConfigDialog:SelectGroup("IceHUD", "modules", newMod.elementName) - StaticPopup_Show(popupMsg) - end + IceHUD:CreateCustomModuleAndNotify(lastCustomModule) end, order = 94.6, }, @@ -1292,3 +1271,30 @@ function IceHUD:UpdateMedia(event, mediatype, key) end end end + +function IceHUD:CreateCustomModuleAndNotify(moduleKey, settings) + local newMod = nil + local popupMsg + if moduleKey == "Bar" then -- custom bar + newMod = IceCustomBar:new() + popupMsg = "ICEHUD_CUSTOM_BAR_CREATED" + elseif moduleKey == "Counter" then -- custom counter + newMod = IceCustomCount:new() + popupMsg = "ICEHUD_CUSTOM_COUNTER_CREATED" + elseif moduleKey == "CD" then -- cooldown bar + newMod = IceCustomCDBar:new() + popupMsg = "ICEHUD_CUSTOM_CD_CREATED" + elseif moduleKey == "Health" then -- custom health bar + newMod = IceCustomHealth:new() + popupMsg = "ICEHUD_CUSTOM_HEALTH_CREATED" + elseif moduleKey == "Mana" then -- custom mana bar + newMod = IceCustomMana:new() + popupMsg = "ICEHUD_CUSTOM_MANA_CREATED" + end + + if newMod ~= nil then + IceHUD.IceCore:AddNewDynamicModule(newMod, settings) + ConfigDialog:SelectGroup("IceHUD", "modules", newMod.elementName) + StaticPopup_Show(popupMsg) + end +end diff --git a/modules/CustomBar.lua b/modules/CustomBar.lua index 52b1d67..679bacb 100644 --- a/modules/CustomBar.lua +++ b/modules/CustomBar.lua @@ -161,6 +161,16 @@ function IceCustomBar.prototype:GetOptions() order = 20.1, } + opts["duplicateme"] = { + type = 'execute', + name = 'Duplicate me', + desc = 'Creates a new module of this same type and with all the same settings.', + func = function() + IceHUD:CreateCustomModuleAndNotify(self.moduleSettings.customBarType, self.moduleSettings) + end, + order = 20.2, + } + opts["name"] = { type = 'input', name = 'Bar name', diff --git a/modules/CustomCDBar.lua b/modules/CustomCDBar.lua index f8262ca..7cb4bbc 100644 --- a/modules/CustomCDBar.lua +++ b/modules/CustomCDBar.lua @@ -148,6 +148,16 @@ function IceCustomCDBar.prototype:GetOptions() order = 20.1, } + opts["duplicateme"] = { + type = 'execute', + name = 'Duplicate me', + desc = 'Creates a new module of this same type and with all the same settings.', + func = function() + IceHUD:CreateCustomModuleAndNotify(self.moduleSettings.customBarType, self.moduleSettings) + end, + order = 20.2, + } + opts["name"] = { type = 'input', name = 'Bar name', diff --git a/modules/CustomCount.lua b/modules/CustomCount.lua index 233fe7a..b0f92cd 100644 --- a/modules/CustomCount.lua +++ b/modules/CustomCount.lua @@ -37,6 +37,16 @@ function IceCustomCount.prototype:GetOptions() order = 20.1, } + opts["duplicateme"] = { + type = 'execute', + name = 'Duplicate me', + desc = 'Creates a new module of this same type and with all the same settings.', + func = function() + IceHUD:CreateCustomModuleAndNotify(self.moduleSettings.customBarType, self.moduleSettings) + end, + order = 20.2, + } + opts["name"] = { type = 'input', name = 'Counter name', diff --git a/modules/CustomHealth.lua b/modules/CustomHealth.lua index 41fa85e..0f28ada 100644 --- a/modules/CustomHealth.lua +++ b/modules/CustomHealth.lua @@ -52,6 +52,16 @@ function IceCustomHealth.prototype:GetOptions() order = 20.1, } + opts["duplicateme"] = { + type = 'execute', + name = 'Duplicate me', + desc = 'Creates a new module of this same type and with all the same settings.', + func = function() + IceHUD:CreateCustomModuleAndNotify(self.moduleSettings.customBarType, self.moduleSettings) + end, + order = 20.2, + } + opts["name"] = { type = 'input', name = 'Bar name', diff --git a/modules/CustomMana.lua b/modules/CustomMana.lua index 07fba55..db85b9d 100644 --- a/modules/CustomMana.lua +++ b/modules/CustomMana.lua @@ -53,6 +53,16 @@ function IceCustomMana.prototype:GetOptions() order = 20.1, } + opts["duplicateme"] = { + type = 'execute', + name = 'Duplicate me', + desc = 'Creates a new module of this same type and with all the same settings.', + func = function() + IceHUD:CreateCustomModuleAndNotify(self.moduleSettings.customBarType, self.moduleSettings) + end, + order = 20.2, + } + opts["name"] = { type = 'input', name = 'Bar name',