Skip to content

Commit

Permalink
System - Additional Toggle/Setting Bug Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteOne committed Oct 6, 2024
1 parent 62ae3c7 commit 11219ae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
4 changes: 3 additions & 1 deletion System/Functions/Misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,9 @@ local function findOption(Value, Page, Type)
end
elseif reportFindings[option] ~= nil and reportFindings[option].Findings ~= nil and #reportFindings[option].Findings == 1 then
local thisOption = reportFindings[option].Findings[1]
return settings[thisOption.page][thisOption.option]
if settings and settings[thisOption.page] and settings[thisOption.page][thisOption.option] then
return settings[thisOption.page][thisOption.option]
end
end
end
end
Expand Down
38 changes: 21 additions & 17 deletions System/UI/Toggles/ToggleFunctions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ function br.ui:createToggle(table, name, col, row)
br._G.print("Invaild type " .. type(name) .. " detected for table " .. name .. ". Please let devs know!")
else
br[name .. "Modes"] = table
br["CreateButton"](name, col, row)
br.CreateButton(name, col, row)
-- br.ui:RefreshButton(name)
end
end

function br.ui:RefreshButton(name)
local index = br[name .. "Modes"] and br[name .. "Modes"].value or 1
br.changeButton(name, index)
end

-- when we find a match, we reset tooltip
function br.ResetTip(toggleValue, thisValue)
br._G.GameTooltip:SetOwner(br["button" .. toggleValue], br.mainButton, 0, 0)
Expand Down Expand Up @@ -253,11 +259,9 @@ function br.CreateButton(Name, x, y)
local Icon
-- local Name = string.upper(Name)
-- todo: extend to use spec + profile specific variable; ATM it shares between profile AND spec, -> global for char
if
br.data.settings[br.selectedSpec].toggles[Name] == nil or
br.data.settings[br.selectedSpec].toggles[Name] > #br[Name .. "Modes"]
then
br.data.settings[br.selectedSpec].toggles[Name] = 1
local toggleIndex = br.data.settings[br.selectedSpec].toggles[Name]
if toggleIndex == nil or toggleIndex > #br[Name .. "Modes"] or toggleIndex == 0 then
toggleIndex = 1
end
if br.buttonsTable then
br._G.tinsert(br.buttonsTable, { name = Name, bx = x, by = y })
Expand All @@ -271,14 +275,15 @@ function br.CreateButton(Name, x, y)
y * (br.data.settings["buttonSize"]) + (y * 2)
)
br["button" .. Name]:RegisterForClicks("AnyUp")
local toggleIcon = br[Name .. "Modes"][br.data.settings[br.selectedSpec].toggles[Name]].icon
local toggleIcon = br[Name .. "Modes"][toggleIndex].icon
if toggleIcon ~= nil and type(toggleIcon) == "number" then
Icon = toggleIcon
else
Icon = br.emptyIcon
end
local spellInfo = br._G.GetSpellInfo(Icon)
Icon = spellInfo.iconID or br.emptyIcon
local _, _, spellIcon = br._G.GetSpellInfo(Icon)
Icon = spellIcon or br.emptyIcon
print(tostring(Icon))
br["button" .. Name]:SetNormalTexture(Icon)
--CreateBorder(br["button"..Name], 8, 0.6, 0.6, 0.6)
br["text" .. Name] = br["button" .. Name]:CreateFontString(nil, "OVERLAY")
Expand All @@ -304,11 +309,11 @@ function br.CreateButton(Name, x, y)
br[Name .. "Modes"] = br[Name .. "Modes"] or ""
end
local modeValue
if br.data.settings[br.selectedSpec].toggles[tostring(Name)] == nil then
br.data.settings[br.selectedSpec].toggles[tostring(Name)] = 1
if toggleIndex == nil then
toggleIndex = 1
modeValue = 1
else
modeValue = br.data.settings[br.selectedSpec].toggles[tostring(Name)]
modeValue = toggleIndex
end
br["button" .. Name]:SetScript(
"OnClick",
Expand All @@ -324,14 +329,13 @@ function br.CreateButton(Name, x, y)
"OnMouseWheel",
function(_, delta)
local Go = false
if delta < 0 and br.data.settings[br.selectedSpec].toggles[tostring(Name)] > 1 then
if delta < 0 and toggleIndex > 1 then
Go = true
elseif delta > 0 and br.data.settings[br.selectedSpec].toggles[tostring(Name)] < #br[Name .. "Modes"] then
elseif delta > 0 and toggleIndex < #br[Name .. "Modes"] then
Go = true
end
if Go == true then
br.data.settings[br.selectedSpec].toggles[tostring(Name)] =
br.data.settings[br.selectedSpec].toggles[tostring(Name)] + delta
toggleIndex = toggleIndex + delta
end
end
)
Expand All @@ -340,7 +344,7 @@ function br.CreateButton(Name, x, y)
function()
br._G.GameTooltip:SetOwner(br["button" .. Name], br._G.UIParent, 0, 0)
br._G.GameTooltip:SetText(
br[Name .. "Modes"][br.data.settings[br.selectedSpec].toggles[Name]].tip,
br[Name .. "Modes"][toggleIndex].tip,
225 / 255,
225 / 255,
225 / 255,
Expand Down

0 comments on commit 11219ae

Please sign in to comment.