- changed the custom bar creation code to name each bar as the highest-numbered bar +1. e.g. if a bar "MyCustomBar4" exists and the user creates a new bar, the new bar will be called MyCustomBar5 (even if 1-3 don't exist any more, just to avoid complications). This way, each custom bar gets a unique name and users can't stomp an old custom bar by creating a new one without changing the old one's name first

This commit is contained in:
Parnic
2009-04-05 19:24:08 +00:00
parent 56fc146f56
commit eb905a92b7
2 changed files with 26 additions and 1 deletions

View File

@ -115,12 +115,18 @@ end
function IceCore.prototype:AddNewDynamicModule(module, hasSettings)
self:Register(module)
if not hasSettings then
self.settings.modules[module.elementName] = module:GetDefaultSettings()
end
module:SetDatabase(self.settings)
if not hasSettings then
local numExisting = self:GetNumCustomModules(module, true)
self:RenameDynamicModule(module, "MyCustomBar"..(numExisting+1))
end
module:Create(self.IceHUDFrame)
if (module:IsEnabled()) then
module:Enable(true)
@ -130,6 +136,25 @@ function IceCore.prototype:AddNewDynamicModule(module, hasSettings)
end
function IceCore.prototype:GetNumCustomModules(exceptMe)
local num = 0
local foundNum = 0
for i=0,table.getn(self.elements) do
if (self.elements[i] and self.elements[i] ~= exceptMe and self.elements[i].moduleSettings.isCustomBar) then
local str = self.elements[i].elementName:match("MyCustomBar%d+")
if str then
foundNum = str:match("%d+")
end
num = max(num, foundNum)
end
end
return num
end
function IceCore.prototype:DeleteDynamicModule(module)
if module:IsEnabled() then
module:Disable()