Skip to content

Commit

Permalink
Add option to resize restricted main bar
Browse files Browse the repository at this point in the history
  • Loading branch information
ls- committed May 7, 2023
1 parent 1e46db7 commit e85c1e1
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 40 deletions.
10 changes: 9 additions & 1 deletion ls_UI/modules/bars/actionbars.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ local isInit = false
local CFG = {
bar1 = {
flyout_dir = "UP",
num = 12,
-- num = 12,
per_row = 12,
width = 32,
height = 0,
Expand Down Expand Up @@ -197,10 +197,18 @@ function bar1_proto:UpdateConfig()
self._config.rightclick_selfcast = C.db.profile.bars.rightclick_selfcast

if MODULE:IsRestricted() then
if C.db.profile.bars.bar1.num < 6 then
C.db.profile.bars.bar1.num = 6
end

self._config.grid = C.db.profile.bars.bar1.grid
self._config.num = C.db.profile.bars.bar1.num
self._config.count = E:CopyTable(C.db.profile.bars.bar1.count, self._config.count)
self._config.hotkey = E:CopyTable(C.db.profile.bars.bar1.hotkey, self._config.hotkey)
self._config.macro = E:CopyTable(C.db.profile.bars.bar1.macro, self._config.macro)

self:SetAttribute("maxbuttons", self._config.num)
MODULE:UpdateMainBarMaxButtons(self._config.num)
end
end

Expand Down
109 changes: 71 additions & 38 deletions ls_UI/modules/bars/controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local unpack = _G.unpack

-- Mine
local isInit = false
local isFinilized = false

local barController
local animController
Expand Down Expand Up @@ -48,7 +49,7 @@ local WIDGETS = {
self:Show()
for i = 7, 12 do
if message == 6 then
if i > message then
buttons[i]:SetAttribute("statehidden", true)
buttons[i]:Hide()
else
Expand All @@ -67,7 +68,7 @@ local WIDGETS = {
frame_level_offset = 3,
point = {"BOTTOM", "LSActionBarControllerBottom", "BOTTOM", 0, 0},
on_play = function(frame, newstate)
frame:UpdateSize(newstate == 6 and 756 / 2 or 1188 / 2, 12)
frame:UpdateSize(756 / 2 + 36 * (newstate - 6), 12)
end,
},
}
Expand All @@ -88,40 +89,6 @@ function MODULE:AddControlledWidget(slot, frame)
end

widget.frame = frame

if not barController.isDriverRegistered and WIDGETS.ACTION_BAR.frame
and WIDGETS.PET_BATTLE_BAR.frame and WIDGETS.XP_BAR.frame then

-- _"childupdate-numbuttons" is executed in barController's environment
for i = 1, 12 do
barController:SetFrameRef("button" .. i, _G["LSActionBar1Button" .. i])
end

barController:Execute([[
top = self:GetFrameRef("top")
bottom = self:GetFrameRef("bottom")
buttons = table.new()
for i = 1, 12 do
table.insert(buttons, self:GetFrameRef("button" .. i))
end
]])

barController:SetAttribute("_onstate-mode", [[
if newstate ~= self:GetAttribute("numbuttons") then
self:SetAttribute("numbuttons", newstate)
self:ChildUpdate("numbuttons", newstate)
self:CallMethod("Update")
top:SetWidth(newstate == 6 and 0.001 or 216)
bottom:SetWidth(newstate == 6 and 0.001 or 216)
end
]])

RegisterStateDriver(barController, "mode", "[vehicleui][petbattle][overridebar][possessbar] 6; 12")

barController.isDriverRegistered = true
end
end
end
end
Expand All @@ -143,6 +110,19 @@ function MODULE:SetupActionBarController()

barController.Shuffle:Play()
end
barController.UpdateSimple = function(_, newstate)
for _, widget in next, WIDGETS do
if widget.frame and widget.on_play then
widget.on_play(widget.frame, newstate)
end
end

animController.Top:SetWidth(newstate == 6 and 0.001 or 36 * (newstate - 6))
animController.Top.Mid:SetTexCoord(233 / 2048, (233 + 72 * (newstate - 6)) / 2048, 1 / 256, 91 / 256)

animController.Bottom:SetWidth(newstate == 6 and 0.001 or 36 * (newstate - 6))
animController.Bottom.Mid:SetTexCoord(569 / 2048, (569 + 72 * (newstate - 6)) / 2048, 92 / 256, 138 / 256)
end

-- These frames are used as anchors/parents for secure/protected frames
local top = CreateFrame("Frame", "$parentTop", barController, "SecureHandlerBaseTemplate")
Expand Down Expand Up @@ -256,8 +236,11 @@ function MODULE:SetupActionBarController()
end)

C_Timer.After(0.4, function()
animController.Top:SetWidth(newstate == 6 and 0.001 or 216)
animController.Bottom:SetWidth(newstate == 6 and 0.001 or 216)
animController.Top:SetWidth(newstate == 6 and 0.001 or 36 * (newstate - 6))
animController.Top.Mid:SetTexCoord(233 / 2048, (233 + 72 * (newstate - 6)) / 2048, 1 / 256, 91 / 256)

animController.Bottom:SetWidth(newstate == 6 and 0.001 or 36 * (newstate - 6))
animController.Bottom.Mid:SetTexCoord(569 / 2048, (569 + 72 * (newstate - 6)) / 2048, 92 / 256, 138 / 256)
end)
end)
ag:SetScript("OnFinished", function()
Expand Down Expand Up @@ -342,6 +325,40 @@ function MODULE:SetupActionBarController()
end
end

function MODULE:FinalizeActionBarController()
if isInit and not isFinilized then
-- "_childupdate-numbuttons" is executed in barController's environment
for i = 1, 12 do
barController:SetFrameRef("button" .. i, _G["LSActionBar1Button" .. i])
end

barController:Execute([[
top = self:GetFrameRef("top")
bottom = self:GetFrameRef("bottom")
buttons = table.new()
for i = 1, 12 do
table.insert(buttons, self:GetFrameRef("button" .. i))
end
]])

barController:SetAttribute("_onstate-mode", [[
if newstate ~= self:GetAttribute("numbuttons") then
self:SetAttribute("numbuttons", newstate)
self:ChildUpdate("numbuttons", newstate)
self:CallMethod("Update")
top:SetWidth(newstate == 6 and 0.001 or 36 * (newstate - 6))
bottom:SetWidth(newstate == 6 and 0.001 or 36 * (newstate - 6))
end
]])

isFinilized = true

self:UpdateMainBarMaxButtons(LSActionBar1:GetAttribute("maxbuttons"))
end
end

function MODULE:UpdateEndcaps()
local endcaps = C.db.profile.bars.endcaps
if endcaps == "BOTH" then
Expand All @@ -365,3 +382,19 @@ function MODULE:UpdateScale()
barController:SetScale(scale)
animController:SetScale(scale)
end

function MODULE:UpdateMainBarMaxButtons(num)
if not isFinilized then return end
if not num then return end

barController:Execute(([[
self:SetAttribute("numbuttons", %1$d)
self:ChildUpdate("numbuttons", %1$d)
self:CallMethod("UpdateSimple", %1$d)
top:SetWidth(%1$d == 6 and 0.001 or 36 * (%1$d - 6))
bottom:SetWidth(%1$d == 6 and 0.001 or 36 * (%1$d - 6))
]]):format(num))

RegisterStateDriver(barController, "mode", "[vehicleui][petbattle][overridebar][possessbar] 6; " .. num)
end
1 change: 1 addition & 0 deletions ls_UI/modules/bars/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ function MODULE:Init()
MODULE:CreateMicroMenu()
MODULE:CreateBag()
MODULE:CreateXPBar()
MODULE:FinalizeActionBarController()
MODULE:CleanUp()
MODULE:UpdateBlizzVehicle()

Expand Down
4 changes: 3 additions & 1 deletion ls_UI_Options/bars/bar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ function CONFIG:CreateBarOptions(order, barID, name)
if barID == "bar1" then
temp.args.reset.disabled = isModuleDisabledOrRestricted
temp.args.visible.disabled = isModuleDisabledOrRestricted
temp.args.num.disabled = isModuleDisabledOrRestricted
if BARS:IsRestricted() then
temp.args.num.min = 6
end
temp.args.per_row.disabled = isModuleDisabledOrRestricted
temp.args.spacing.disabled = isModuleDisabledOrRestricted
temp.args.width.disabled = isModuleDisabledOrRestricted
Expand Down

0 comments on commit e85c1e1

Please sign in to comment.