mirror of
https://github.com/parnic/ice-hud.git
synced 2025-06-16 06:40:13 -05:00
- 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:
25
IceCore.lua
25
IceCore.lua
@ -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()
|
||||
|
Reference in New Issue
Block a user