From eb177d30465bef0f9c6980868f08636c54b13290 Mon Sep 17 00:00:00 2001 From: Jon Allen Date: Tue, 27 Dec 2022 01:13:38 -0600 Subject: [PATCH 1/7] first draft bar data type declaration --- Neuron-DB-Defaults.lua | 86 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/Neuron-DB-Defaults.lua b/Neuron-DB-Defaults.lua index 7c96ff2..4957e5a 100644 --- a/Neuron-DB-Defaults.lua +++ b/Neuron-DB-Defaults.lua @@ -7,6 +7,10 @@ local _, addonTable = ... ---**NOTE** values assigned with empty quotes, i.e. name = "", basically don't exist. Lua treats them as nil +---@class GenericButtonData +---@field btnType "macro" + +---@type GenericButtonData local genericButtonData = { btnType = "macro", } @@ -162,6 +166,12 @@ local genericMirrorBtnData= { } +---@class GenericKeyData +---@field hotKeyLock boolean +---@field hotKeyPri boolean +---@field hotKeys string + +---@type GenericKeyData local genericKeyData = { hotKeyLock = false, hotKeyPri = false, @@ -169,6 +179,82 @@ local genericKeyData = { } +---@class GenericBarData +---@field actionID number|false|nil +---@field name string +---@field buttons {config: GenericButtonData, keys: GenericKeyData, data: any}[], +---@field hidestates string +---@field point string +---@field x number +---@field y number +---@field scale number +---@field shape "linear"|"circle"|"circle + one" +---@field columns number +---@field alpha number +---@field alphaUp "off"|"mouseover"|"combat"|"combat + mouseover" +---@field alphaMax number +---@field fadeSpeed number +---@field strata number +---@field padH number +---@field padV number +---@field arcStart number +---@field arcLength number +---@field snapTo boolean +---@field snapToPad number +---@field snapToPoint boolean +---@field snapToFrame boolean +---@field autoHide boolean +---@field showGrid boolean +---@field bindColor {[1]:number,[2]:number,[3]:number} +---@field macroColor {[1]:number,[2]:number,[3]:number} +---@field countColor {[1]:number,[2]:number,[3]:number} +---@field cdcolor1 {[1]:number,[2]:number,[3]:number} +---@field cdcolor2 {[1]:number,[2]:number,[3]:number} +---@field rangecolor {[1]:number,[2]:number,[3]:number} +---@field manacolor {[1]:number,[2]:number,[3]:number} +---@field border boolean +---@field clickMode "UpClick"|"DownClick" +---@field conceal boolean +---@field multiSpec boolean +---@field spellGlow "default"|"alternate"|false +---@field barLock boolean +---@field tooltips "normal"|"minimal"|"off" +---@field tooltipsCombat boolean +---@field bindText boolean +---@field buttonText boolean +---@field countText boolean +---@field rangeInd boolean +---@field cdText boolean +---@field cdAlpha boolean +---@field showBorderStyle boolean +---@field homestate boolean +---@field paged boolean +---@field stance boolean +---@field stealth boolean +---@field reaction boolean +---@field combat boolean +---@field group boolean +---@field pet boolean +---@field fishing boolean +---@field vehicle boolean +---@field possess boolean +---@field dragonriding boolean +---@field override boolean +---@field extrabar boolean +---@field alt boolean +---@field ctrl boolean +---@field shift boolean +---@field target boolean +---@field selfCast boolean +---@field focusCast boolean +---@field rightClickTarget boolean +---@field mouseOverCast boolean +---@field custom boolean +---@field customRange boolean +---@field customNames boolean +---@field remap boolean + +---@type GenericBarData local genericBarData = { name = ":", From 06853141999b4ecd957b2a9b0973bbcf69db76a5 Mon Sep 17 00:00:00 2001 From: Jon Allen Date: Tue, 27 Dec 2022 01:52:35 -0600 Subject: [PATCH 2/7] walk back global state from the button edit panel --- GUI/ButtonEditTab.lua | 43 ++++++++++++++++++++-------------------- GUI/MainWindow.lua | 6 +++--- Objects/ActionButton.lua | 18 ++++++++--------- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/GUI/ButtonEditTab.lua b/GUI/ButtonEditTab.lua index e0c206c..f3438bf 100644 --- a/GUI/ButtonEditTab.lua +++ b/GUI/ButtonEditTab.lua @@ -18,9 +18,12 @@ local Array = addonTable.utilities.Array --------------------------Button Editor-------------------------------------- ----------------------------------------------------------------------------- +--- @param frame Frame @the icon preview frame +--- @param data GenericSpecData +--- @return nil local function refreshIconPreview(frame, data) --try to get the texture currently on the button itself - local texture = Neuron.currentButton:GetAppearance(data) + local texture = Neuron.ActionButton.GetAppearance(data) if texture then frame:SetImage(texture) else --fallback to question mark icon if nothing is found @@ -55,9 +58,9 @@ end --our states come from the VISIBILITY_STATES but we only show the states that --are enabled for the bar _and_ that are in the states field of the --corresponding MANAGED_BAR_STATES entry -local function getStateList() - local barData = Neuron.currentButton.bar.data - +---@param barData GenericBarData +---@return string[] +local function getStateList(barData) local barStates = Array.filter(function(state) return barData[state] end, Array.map(function(state) return state[1] end, @@ -162,29 +165,27 @@ local function buttonEditPanel(specData, update) return settingContainer end -function NeuronGUI:ButtonsEditPanel(topContainer) +---@param button ActionButton +---@param topContainer Frame +function NeuronGUI:ButtonsEditPanel(button, topContainer) Neuron:ToggleButtonEditMode(true) - if not Neuron.currentButton then - return - end - topContainer = makeScrollFrame(topContainer) - local multiSpec = Neuron.currentButton.bar:GetMultiSpec() + local multiSpec = button.bar:GetMultiSpec() local specs = Spec.names(multiSpec) specs[5] = L["No Spec"] for specIndex, specName in pairs(specs) do - local specData = Neuron.currentButton.DB[specIndex] + local specData = button.DB[specIndex] local buttonTree = { value = "homestate", text = specName, children = Array.map( function(state) return {value=state, text=Neuron.STATES[state]} end, - getStateList() + getStateList(button.bar.data) ), } @@ -205,17 +206,15 @@ function NeuronGUI:ButtonsEditPanel(topContainer) specData[state][k] = v end - if Spec.active(multiSpec) ~= specIndex then - -- don't update the button if the modified spec isn't active - return + -- don't update the button if the modified spec isn't active + if Spec.active(multiSpec) == specIndex then + -- for some reason we need to do a full bar load or the buttons don't + -- update. we can investigate further, but note that switching specs + -- probably needs the same fix + button.bar:Load() + --button:LoadDataFromDatabase(specIndex, state) + --button:UpdateAll() end - - -- for some reason we need to do a full bar load or the buttons don't - -- update. we can investigate further, but note that switching specs - -- probably needs the same fix - Neuron.currentButton.bar:Load() - --Neuron.currentButton:LoadDataFromDatabase(specIndex, state) - --Neuron.currentButton:UpdateAll() end) container:AddChild(buttonEditor) end) diff --git a/GUI/MainWindow.lua b/GUI/MainWindow.lua index af070d6..909d7be 100644 --- a/GUI/MainWindow.lua +++ b/GUI/MainWindow.lua @@ -119,14 +119,14 @@ function NeuronGUI:SelectTab(tabFrame, _, value) tabFrame:ReleaseChildren() if value == "bar" then NeuronGUI:BarEditPanel(tabFrame) - elseif value == "button" then + elseif value == "button" and Neuron.currentButton then -- whenever we change a button, RefreshEditor is called upstream -- so we don't need to keep track of updating currentButton here - NeuronGUI:ButtonsEditPanel(tabFrame) + NeuronGUI:ButtonsEditPanel(Neuron.currentButton, tabFrame) elseif value == "status" then NeuronGUI:ButtonStatusEditPanel(tabFrame) else - return -- if we get here we forgot to add a tab! + return -- if we get here we forgot to add a tab! (or a global state is borked) end currentTab = value end diff --git a/Objects/ActionButton.lua b/Objects/ActionButton.lua index 97eb47c..eeaaaf3 100644 --- a/Objects/ActionButton.lua +++ b/Objects/ActionButton.lua @@ -75,7 +75,7 @@ function ActionButton:InitializeButton() end self:SetAttribute("type", "macro") - self:SetAttribute("*macrotext*", self.SanitizedMacro(self:GetMacroText())) + self:SetAttribute("*macrotext*", ActionButton.SanitizedMacro(self:GetMacroText())) self:SetAttribute("hotkeypri", self.keys.hotKeyPri) self:SetAttribute("hotkeys", self.keys.hotKeys) @@ -811,8 +811,8 @@ function ActionButton:UpdateData() return end - local cleanMacro = self.SanitizedMacro(self:GetMacroText()) - local spellItemUnit = self.ExtractMacroData(cleanMacro) + local cleanMacro = ActionButton.SanitizedMacro(self:GetMacroText()) + local spellItemUnit = ActionButton.ExtractMacroData(cleanMacro) self.spell = spellItemUnit.spell self.spellID = spellItemUnit.spellID self.item = spellItemUnit.item @@ -865,7 +865,7 @@ function ActionButton:UpdateIcon() ) data.actionID = self.actionID -- this is for vehicle, possession, etc - self:ApplyAppearance(self:GetAppearance(data)) + self:ApplyAppearance(ActionButton.GetAppearance(data)) --make sure our button gets the correct Normal texture if we're not using a Masque skin self:UpdateNormalTexture() @@ -876,17 +876,17 @@ end --- @param data GenericSpecData --- @return TextureRef, Border an icon texture, and an rgb tuple, both nilable -function ActionButton:GetAppearance(data) - local spellItem = self.ExtractMacroData(self.SanitizedMacro(data.macro_Text)) +function ActionButton.GetAppearance(data) + local spellItem = ActionButton.ExtractMacroData(ActionButton.SanitizedMacro(data.macro_Text)) local spell, item = spellItem.spell, spellItem.item local texture, border if data.actionID then - return self.GetActionAppearance(data.actionID) + return ActionButton.GetActionAppearance(data.actionID) elseif spell then - texture, border = self.GetSpellAppearance(spell) + texture, border = ActionButton.GetSpellAppearance(spell) elseif item then - texture, border = self.GetItemAppearance(item) + texture, border = ActionButton.GetItemAppearance(item) -- macro must go after spells and items, for blizz macro #showtooltip to work elseif data.macro_Icon then texture, border = data.macro_Icon, nil From c48c3f337b23a40fea2d83873eafd844e89168e4 Mon Sep 17 00:00:00 2001 From: Jon Allen Date: Tue, 27 Dec 2022 02:13:40 -0600 Subject: [PATCH 3/7] get rid of currentbar/button in button status form --- GUI/ButtonStatusEditTab.lua | 14 +++++++------- GUI/MainWindow.lua | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/GUI/ButtonStatusEditTab.lua b/GUI/ButtonStatusEditTab.lua index 7d6377c..df3ab6a 100644 --- a/GUI/ButtonStatusEditTab.lua +++ b/GUI/ButtonStatusEditTab.lua @@ -162,11 +162,11 @@ local function castButtonOptions(button) return castContainer end -function NeuronGUI:ButtonStatusEditPanel(tabFrame) + +---@param button CastButton|ExpButton|MirrorButton|RepButton +---@param tabFrame Frame +function NeuronGUI:ButtonStatusEditPanel(button, tabFrame) Neuron.ToggleButtonEditMode(true) - if not Neuron.currentButton then - return - end -- weird stuff happens if we don't wrap this in a group -- like dropdowns showing at the bottom of the screen and stuff @@ -189,9 +189,9 @@ function NeuronGUI:ButtonStatusEditPanel(tabFrame) reloadButton:SetCallback("OnClick", ReloadUI) reloadButtonContainer:AddChild(reloadButton) - settingContainer:AddChild(statusButtonOptions(Neuron.currentButton)) - if Neuron.currentBar.barType == "CastBar" then - settingContainer:AddChild(castButtonOptions(Neuron.currentButton)) + settingContainer:AddChild(statusButtonOptions(button)) + if button.bar.barType == "CastBar" then + settingContainer:AddChild(castButtonOptions(button)) end settingContainer:AddChild(reloadButtonContainer) tabFrame:AddChild(settingContainer) diff --git a/GUI/MainWindow.lua b/GUI/MainWindow.lua index 909d7be..c69b47d 100644 --- a/GUI/MainWindow.lua +++ b/GUI/MainWindow.lua @@ -123,8 +123,8 @@ function NeuronGUI:SelectTab(tabFrame, _, value) -- whenever we change a button, RefreshEditor is called upstream -- so we don't need to keep track of updating currentButton here NeuronGUI:ButtonsEditPanel(Neuron.currentButton, tabFrame) - elseif value == "status" then - NeuronGUI:ButtonStatusEditPanel(tabFrame) + elseif value == "status" and Neuron.currentButton then + NeuronGUI:ButtonStatusEditPanel(Neuron.currentButton, tabFrame) else return -- if we get here we forgot to add a tab! (or a global state is borked) end From 26a9e129015a823a53881127090b5d138f98de91 Mon Sep 17 00:00:00 2001 From: Jon Allen Date: Fri, 30 Dec 2022 00:32:43 -0600 Subject: [PATCH 4/7] remove globals from the bar gui --- GUI/BarEditTab.lua | 11 +- GUI/BarEditTab_BarStatesPanel.lua | 23 +- GUI/BarEditTab_BarVisibilityPanel.lua | 13 +- GUI/BarEditTab_GeneralConfigPanel.lua | 375 +++++++++++++------------- Neuron-DB-Defaults.lua | 2 +- Objects/Bar.lua | 5 +- 6 files changed, 219 insertions(+), 210 deletions(-) diff --git a/GUI/BarEditTab.lua b/GUI/BarEditTab.lua index 85cbbd9..340509d 100644 --- a/GUI/BarEditTab.lua +++ b/GUI/BarEditTab.lua @@ -138,16 +138,17 @@ end ----------------------------------------------------------------------------- function NeuronGUI:SelectInnerBarTab(tabFrame, _, value) - local registeredGUIData = Neuron:RegisterGUI() tabFrame:ReleaseChildren() - if value == "general" then - NeuronGUI:GeneralConfigPanel(tabFrame, registeredGUIData) + if not Neuron.currentBar then + return + elseif value == "general" then + NeuronGUI:GeneralConfigPanel(Neuron.currentBar, tabFrame) currentTab = "general" elseif value == "states" then - NeuronGUI:BarStatesPanel(tabFrame) + NeuronGUI:BarStatesPanel(Neuron.currentBar, tabFrame) currentTab = "states" elseif value == "visibility" then - NeuronGUI:BarVisibilityPanel(tabFrame) + NeuronGUI:BarVisibilityPanel(Neuron.currentBar, tabFrame) currentTab = "visibility" end end diff --git a/GUI/BarEditTab_BarStatesPanel.lua b/GUI/BarEditTab_BarStatesPanel.lua index 47ee9c4..e7073d4 100644 --- a/GUI/BarEditTab_BarStatesPanel.lua +++ b/GUI/BarEditTab_BarStatesPanel.lua @@ -13,15 +13,16 @@ local AceGUI = LibStub("AceGUI-3.0") local Array = addonTable.utilities.Array +---@param bar Bar ---@return Frame @a dropdown widget -local function actionPrimaryBarKindOptions() +local function actionPrimaryBarKindOptions(bar) local barKinds = Array.map( function(state) return state[1] end, Array.fromIterator(pairs(Neuron.MANAGED_HOME_STATES))) local currentKind = Array.foldl( function (kind, candidate) - return Neuron.currentBar.data[candidate] and candidate or kind + return bar.data[candidate] and candidate or kind end, "none", barKinds @@ -44,18 +45,19 @@ local function actionPrimaryBarKindOptions() barKindDropdown:SetCallback("OnValueChanged", function(_, _, key) if key == "none" then for _,kind in ipairs(barKinds) do - Neuron.currentBar:SetState(kind, true, false) + bar:SetState(kind, true, false) end else - Neuron.currentBar:SetState(key, true, true) + bar:SetState(key, true, true) end end) return barKindDropdown end +---@param bar Bar ---@return Frame @a group containing checkboxes -local function actionSecondaryStateOptions() +local function actionSecondaryStateOptions(bar) local stateList = Array.map( function(state) return state[1] end, @@ -75,9 +77,9 @@ local function actionSecondaryStateOptions() for _,state in ipairs(stateList) do local checkbox = AceGUI:Create("CheckBox") checkbox:SetLabel(Neuron.MANAGED_SECONDARY_STATES[state].localizedName) - checkbox:SetValue(Neuron.currentBar.data[state]) + checkbox:SetValue(bar.data[state]) checkbox:SetCallback("OnValueChanged", function(_,_,value) - Neuron.currentBar:SetState(state, true, value) + bar:SetState(state, true, value) end) secondaryStatesContainer:AddChild(checkbox) end @@ -85,16 +87,17 @@ local function actionSecondaryStateOptions() return secondaryStatesContainer end +---@param bar Bar ---@param tabFrame Frame -function NeuronGUI:BarStatesPanel(tabFrame) +function NeuronGUI:BarStatesPanel(bar, tabFrame) -- weird stuff happens if we don't wrap this in a group -- like dropdowns showing at the bottom of the screen and stuff local settingContainer = AceGUI:Create("SimpleGroup") settingContainer:SetFullWidth(true) settingContainer:SetLayout("Flow") - settingContainer:AddChild(actionPrimaryBarKindOptions()) - settingContainer:AddChild(actionSecondaryStateOptions()) + settingContainer:AddChild(actionPrimaryBarKindOptions(bar)) + settingContainer:AddChild(actionSecondaryStateOptions(bar)) tabFrame:AddChild(settingContainer) end diff --git a/GUI/BarEditTab_BarVisibilityPanel.lua b/GUI/BarEditTab_BarVisibilityPanel.lua index 2d4c450..3981840 100644 --- a/GUI/BarEditTab_BarVisibilityPanel.lua +++ b/GUI/BarEditTab_BarVisibilityPanel.lua @@ -13,7 +13,8 @@ local AceGUI = LibStub("AceGUI-3.0") local Array = addonTable.utilities.Array -local function barVisibilityOptions() +---@param bar Bar +local function barVisibilityOptions(bar) local stateList = Array.map( function (state) @@ -36,16 +37,18 @@ local function barVisibilityOptions() for _,state in ipairs(stateList) do local checkbox = AceGUI:Create("CheckBox") checkbox:SetLabel(Neuron.VISIBILITY_STATES[state]) - checkbox:SetValue(not Neuron.currentBar.data.hidestates:find(state)) + checkbox:SetValue(not bar.data.hidestates:find(state)) checkbox:SetCallback("OnValueChanged", function(_,_,value) - Neuron.currentBar:SetVisibility(state, value) + bar:SetVisibility(state, value) end) visibilityStatesContainer:AddChild(checkbox) end return visibilityStatesContainer end -function NeuronGUI:BarVisibilityPanel(tabFrame) + +---@param bar Bar +function NeuronGUI:BarVisibilityPanel(bar, tabFrame) -- weird stuff happens if we don't wrap this in a group -- like dropdowns showing at the bottom of the screen and stuff local settingContainer = AceGUI:Create("SimpleGroup") @@ -67,7 +70,7 @@ function NeuronGUI:BarVisibilityPanel(tabFrame) reloadButton:SetCallback("OnClick", ReloadUI) reloadButtonContainer:AddChild(reloadButton) - settingContainer:AddChild(barVisibilityOptions()) + settingContainer:AddChild(barVisibilityOptions(bar)) settingContainer:AddChild(reloadButtonContainer) tabFrame:AddChild(settingContainer) end diff --git a/GUI/BarEditTab_GeneralConfigPanel.lua b/GUI/BarEditTab_GeneralConfigPanel.lua index 6f6db50..f916f06 100644 --- a/GUI/BarEditTab_GeneralConfigPanel.lua +++ b/GUI/BarEditTab_GeneralConfigPanel.lua @@ -17,100 +17,18 @@ local WIDGET_GRID_HEIGHT = 45 local INNER_WIDGET_RATIO = 0.95 -function NeuronGUI:GeneralConfigPanel(tabFrame, registeredGUIData) - - local scrollFrame = AceGUI:Create("ScrollFrame") - scrollFrame:SetLayout("Flow") - tabFrame:AddChild(scrollFrame) - - -------------------------------------------------- - -------------------- Rename Bar ------------------ - -------------------------------------------------- - local renameBoxContainer = AceGUI:Create("SimpleGroup") - renameBoxContainer:SetWidth(WIDGET_GRID_WIDTH*1.5) - renameBoxContainer:SetHeight(WIDGET_GRID_HEIGHT) - scrollFrame:AddChild(renameBoxContainer) - - local renameBox = AceGUI:Create("EditBox") - renameBox:SetRelativeWidth(INNER_WIDGET_RATIO) - renameBox:SetLabel("Rename selected bar:") - if Neuron.currentBar then - renameBox:SetText(Neuron.currentBar:GetBarName()) - end - renameBox:SetCallback("OnEnterPressed", function(self) NeuronGUI:updateBarName(self) end) - renameBoxContainer:AddChild(renameBox) - - ------------------------------------------------ - ------------------------------------------------ - --General Options Heading - local heading1 = AceGUI:Create("Heading") - heading1:SetHeight(WIDGET_GRID_HEIGHT) - heading1:SetFullWidth(true) - heading1:SetText(L["General Options"]) - scrollFrame:AddChild(heading1) - - NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) - - ------------------------------------------------ - ------------------------------------------------ - --Layout Heading - local heading2 = AceGUI:Create("Heading") - heading2:SetHeight(WIDGET_GRID_HEIGHT) - heading2:SetFullWidth(true) - heading2:SetText(L["Size and Shape"]) - scrollFrame:AddChild(heading2) - - NeuronGUI:PopulateLayoutBarOptions(scrollFrame) - - ------------------------------------------------ - ------------------------------------------------ - if registeredGUIData[Neuron.currentBar.class].visualOptions then - --Visual Heading - local heading3 = AceGUI:Create("Heading") - heading3:SetHeight(WIDGET_GRID_HEIGHT) - heading3:SetFullWidth(true) - heading3:SetText(L["Visuals"]) - scrollFrame:AddChild(heading3) - - NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) - end - - -------------------------------------------------- - -------------------------------------------------- - --Dangerous Heading - local heading4 = AceGUI:Create("Heading") - heading4:SetHeight(WIDGET_GRID_HEIGHT) - heading4:SetFullWidth(true) - heading4:SetText("Dangerous") - scrollFrame:AddChild(heading4) - - -------------------------------------------------- - ------------------ Delete Bar -------------------- - -------------------------------------------------- - local deleteBarButtonContainer = AceGUI:Create("SimpleGroup") - deleteBarButtonContainer:SetWidth(WIDGET_GRID_WIDTH*1.5) - deleteBarButtonContainer:SetHeight(WIDGET_GRID_HEIGHT) - scrollFrame:AddChild(deleteBarButtonContainer) - - local deleteBarButton = AceGUI:Create("Button") - deleteBarButton:SetRelativeWidth(INNER_WIDGET_RATIO) - deleteBarButton:SetText("Delete Current Bar") - deleteBarButton:SetCallback("OnClick", function() if Neuron.currentBar then NeuronGUI:DeleteBarPopup() end end) - if not Neuron.currentBar then - deleteBarButton:SetDisabled(true) - end - deleteBarButtonContainer:AddChild(deleteBarButton) -end - -------------------------------------------------- -------------------------------------------------- -function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) +---@param bar Bar +---@param scrollFrame Frame +---@param registeredGUIData any +local function generalBarOptions(bar, scrollFrame, registeredGUIData) -------------------------------------------------- -------------------- AutoHide -------------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].generalOptions.AUTOHIDE then + if registeredGUIData[bar.class].generalOptions.AUTOHIDE then local autoHideCheckboxContainer = AceGUI:Create("SimpleGroup") autoHideCheckboxContainer:SetWidth(WIDGET_GRID_WIDTH) autoHideCheckboxContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -119,9 +37,9 @@ function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) local autoHideCheckbox = AceGUI:Create("CheckBox") autoHideCheckbox:SetLabel(L["Auto-Hide"]) autoHideCheckbox:SetRelativeWidth(INNER_WIDGET_RATIO) - autoHideCheckbox:SetValue(Neuron.currentBar:GetAutoHide()) + autoHideCheckbox:SetValue(bar:GetAutoHide()) autoHideCheckbox:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetAutoHide(self:GetValue()) + bar:SetAutoHide(self:GetValue()) end) autoHideCheckboxContainer:AddChild(autoHideCheckbox) end @@ -129,7 +47,7 @@ function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- -------------------- ShowGrid -------------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].generalOptions.SHOWGRID then + if registeredGUIData[bar.class].generalOptions.SHOWGRID then local showGridCheckboxContainer = AceGUI:Create("SimpleGroup") showGridCheckboxContainer:SetWidth(WIDGET_GRID_WIDTH) showGridCheckboxContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -138,9 +56,9 @@ function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) local showGridCheckbox = AceGUI:Create("CheckBox") showGridCheckbox:SetLabel(L["Show Grid"]) showGridCheckbox:SetRelativeWidth(INNER_WIDGET_RATIO) - showGridCheckbox:SetValue(Neuron.currentBar:GetShowGrid()) + showGridCheckbox:SetValue(bar:GetShowGrid()) showGridCheckbox:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetShowGrid(self:GetValue()) + bar:SetShowGrid(self:GetValue()) end) showGridCheckboxContainer:AddChild(showGridCheckbox) end @@ -148,7 +66,7 @@ function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- -------------------- SnapTo ---------------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].generalOptions.SNAPTO then + if registeredGUIData[bar.class].generalOptions.SNAPTO then local snapToCheckboxContainer = AceGUI:Create("SimpleGroup") snapToCheckboxContainer:SetWidth(WIDGET_GRID_WIDTH) snapToCheckboxContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -157,9 +75,9 @@ function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) local snapToCheckbox = AceGUI:Create("CheckBox") snapToCheckbox:SetLabel(L["SnapTo"]) snapToCheckbox:SetRelativeWidth(INNER_WIDGET_RATIO) - snapToCheckbox:SetValue(Neuron.currentBar:GetSnapTo()) + snapToCheckbox:SetValue(bar:GetSnapTo()) snapToCheckbox:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetSnapTo(self:GetValue()) + bar:SetSnapTo(self:GetValue()) end) snapToCheckboxContainer:AddChild(snapToCheckbox) end @@ -167,7 +85,7 @@ function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- -------------------- MultiSpec ------------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].generalOptions.MULTISPEC then + if registeredGUIData[bar.class].generalOptions.MULTISPEC then local multiSpecCheckboxContainer = AceGUI:Create("SimpleGroup") multiSpecCheckboxContainer:SetWidth(WIDGET_GRID_WIDTH) multiSpecCheckboxContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -176,9 +94,9 @@ function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) local multiSpecCheckbox = AceGUI:Create("CheckBox") multiSpecCheckbox:SetLabel(L["Multi Spec"]) multiSpecCheckbox:SetRelativeWidth(INNER_WIDGET_RATIO) - multiSpecCheckbox:SetValue(Neuron.currentBar:GetMultiSpec()) + multiSpecCheckbox:SetValue(bar:GetMultiSpec()) multiSpecCheckbox:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetMultiSpec(self:GetValue()) + bar:SetMultiSpec(self:GetValue()) end) multiSpecCheckboxContainer:AddChild(multiSpecCheckbox) end @@ -186,7 +104,7 @@ function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- -------------------- Hide Bar -------------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].generalOptions.HIDDEN then + if registeredGUIData[bar.class].generalOptions.HIDDEN then local barConcealCheckboxContainer = AceGUI:Create("SimpleGroup") barConcealCheckboxContainer:SetWidth(WIDGET_GRID_WIDTH) barConcealCheckboxContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -195,9 +113,9 @@ function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) local barConcealCheckbox = AceGUI:Create("CheckBox") barConcealCheckbox:SetLabel(L["Hidden"]) barConcealCheckbox:SetRelativeWidth(INNER_WIDGET_RATIO) - barConcealCheckbox:SetValue(Neuron.currentBar:GetBarConceal()) + barConcealCheckbox:SetValue(bar:GetBarConceal()) barConcealCheckbox:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetBarConceal(self:GetValue()) + bar:SetBarConceal(self:GetValue()) end) barConcealCheckboxContainer:AddChild(barConcealCheckbox) end @@ -205,16 +123,13 @@ function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- -------------------- Bar Lock -------------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].generalOptions.LOCKBAR then + if registeredGUIData[bar.class].generalOptions.LOCKBAR then local spellAlertDropdownContainer = AceGUI:Create("SimpleGroup") spellAlertDropdownContainer:SetWidth(WIDGET_GRID_WIDTH) spellAlertDropdownContainer:SetHeight(WIDGET_GRID_HEIGHT) scrollFrame:AddChild(spellAlertDropdownContainer) - local currentLock = Neuron.currentBar:GetBarLock() - if not currentLock then - currentLock = "none" - end + local currentLock = bar:GetBarLock() or "none" local spellAlertDropdown = AceGUI:Create("Dropdown") spellAlertDropdown:SetLabel(L["Lock Actions"]) @@ -223,7 +138,7 @@ function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) {[1] = "none", [2] = "shift", [3] = "ctrl", [4] = "alt"}) spellAlertDropdown:SetValue(currentLock) spellAlertDropdown:SetCallback("OnValueChanged", function(_, _, key) - Neuron.currentBar:SetBarLock(key) + bar:SetBarLock(key) end) spellAlertDropdownContainer:AddChild(spellAlertDropdown) end @@ -231,7 +146,7 @@ function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- -------------------- Click Mode ------------------ -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].generalOptions.CLICKMODE then + if registeredGUIData[bar.class].generalOptions.CLICKMODE then local clickModeDropdownContainer = AceGUI:Create("SimpleGroup") clickModeDropdownContainer:SetWidth(WIDGET_GRID_WIDTH) clickModeDropdownContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -242,16 +157,18 @@ function NeuronGUI:PopulateGeneralBarOptions(scrollFrame, registeredGUIData) clickModeDropdown:SetRelativeWidth(INNER_WIDGET_RATIO) clickModeDropdown:SetList({["UpClick"] = L["On Release"], ["DownClick"] = L["On Click"]}, {[1] = "UpClick", [2] = "DownClick"}) - clickModeDropdown:SetValue(Neuron.currentBar:GetClickMode()) + clickModeDropdown:SetValue(bar:GetClickMode()) clickModeDropdown:SetCallback("OnValueChanged", function(_, _, key) - Neuron.currentBar:SetClickMode(key) + bar:SetClickMode(key) end) clickModeDropdownContainer:AddChild(clickModeDropdown) end end -function NeuronGUI:PopulateLayoutBarOptions(scrollFrame) +---@param bar Bar +---@param scrollFrame Frame +local function layoutBarOptions(bar, scrollFrame) -------------------------------------------------- --------------- Add/Remove Button ---------------- -------------------------------------------------- @@ -262,7 +179,7 @@ function NeuronGUI:PopulateLayoutBarOptions(scrollFrame) addOrRemoveButtonContainer:SetTitle(L["Buttons"]) scrollFrame:AddChild(addOrRemoveButtonContainer) - local currentText = Neuron.currentBar:GetNumObjects() --hack to try to keep the number centered between the buttons + local currentText = bar:GetNumObjects() --hack to try to keep the number centered between the buttons if currentText > 9 then currentText = " "..currentText --one space leading two-digit numbers else @@ -273,7 +190,7 @@ function NeuronGUI:PopulateLayoutBarOptions(scrollFrame) subtractObjectButton:SetText("|TInterface\\Buttons\\Arrow-Down-Up:15:15:2:-5|t") --this is an escape sequence that gives us a down arrow centered on the button subtractObjectButton:SetRelativeWidth(.35) subtractObjectButton:SetCallback("OnClick", function() - Neuron.currentBar:RemoveObjectFromBar() + bar:RemoveObjectFromBar() NeuronGUI:RefreshEditor() end) addOrRemoveButtonContainer:AddChild(subtractObjectButton) @@ -288,7 +205,7 @@ function NeuronGUI:PopulateLayoutBarOptions(scrollFrame) addObjectButton:SetText("|TInterface\\Buttons\\Arrow-Up-Up:15:15:2:2|t") --this is an escape sequence that gives us an up arrow centered on the button addObjectButton:SetRelativeWidth(.35) addObjectButton:SetCallback("OnClick", function() - Neuron.currentBar:AddObjectToBar() + bar:AddObjectToBar() NeuronGUI:RefreshEditor() end) addOrRemoveButtonContainer:AddChild(addObjectButton) @@ -303,11 +220,11 @@ function NeuronGUI:PopulateLayoutBarOptions(scrollFrame) local columnSlider = AceGUI:Create("Slider") columnSlider:SetRelativeWidth(INNER_WIDGET_RATIO) - columnSlider:SetSliderValues(0,Neuron.currentBar:GetNumObjects(),1) + columnSlider:SetSliderValues(0,bar:GetNumObjects(),1) columnSlider:SetLabel(L["Columns"]) - columnSlider:SetValue(Neuron.currentBar:GetColumns()) + columnSlider:SetValue(bar:GetColumns()) columnSlider:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetColumns(self:GetValue()) + bar:SetColumns(self:GetValue()) end) currentNumColumnsContainer:AddChild(columnSlider) @@ -324,9 +241,9 @@ function NeuronGUI:PopulateLayoutBarOptions(scrollFrame) scaleSlider:SetSliderValues(0.1,2,0.05) scaleSlider:SetIsPercent(true) scaleSlider:SetLabel(L["Scale"]) - scaleSlider:SetValue(Neuron.currentBar:GetBarScale()) + scaleSlider:SetValue(bar:GetBarScale()) scaleSlider:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetBarScale(self:GetValue()) + bar:SetBarScale(self:GetValue()) end) setScaleContainer:AddChild(scaleSlider) @@ -343,9 +260,9 @@ function NeuronGUI:PopulateLayoutBarOptions(scrollFrame) barShapeDropdown:SetRelativeWidth(INNER_WIDGET_RATIO) barShapeDropdown:SetList({["linear"] = L["Linear"], ["circle"] = L["Circle"], ["circle + one"] = L["Circle + One"]}, {[1] = "linear", [2] = "circle", [3] = "circle + one"}) - barShapeDropdown:SetValue(Neuron.currentBar:GetBarShape()) + barShapeDropdown:SetValue(bar:GetBarShape()) barShapeDropdown:SetCallback("OnValueChanged", function(_, _, key) - Neuron.currentBar:SetBarShape(key) + bar:SetBarShape(key) end) barShapeDropdownContainer:AddChild(barShapeDropdown) @@ -361,9 +278,9 @@ function NeuronGUI:PopulateLayoutBarOptions(scrollFrame) horizPadSlider:SetRelativeWidth(INNER_WIDGET_RATIO) horizPadSlider:SetSliderValues(-200,200,1) horizPadSlider:SetLabel(L["Horizontal Padding"]) - horizPadSlider:SetValue(Neuron.currentBar:GetHorizontalPad()) + horizPadSlider:SetValue(bar:GetHorizontalPad()) horizPadSlider:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetHorizontalPad(self:GetValue()) + bar:SetHorizontalPad(self:GetValue()) end) horizPadContainer:AddChild(horizPadSlider) @@ -379,9 +296,9 @@ function NeuronGUI:PopulateLayoutBarOptions(scrollFrame) vertPadSlider:SetRelativeWidth(INNER_WIDGET_RATIO) vertPadSlider:SetSliderValues(-200,200,1) vertPadSlider:SetLabel(L["Vertical Padding"]) - vertPadSlider:SetValue(Neuron.currentBar:GetVerticalPad()) + vertPadSlider:SetValue(bar:GetVerticalPad()) vertPadSlider:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetVerticalPad(self:GetValue()) + bar:SetVerticalPad(self:GetValue()) end) vertPadContainer:AddChild(vertPadSlider) @@ -398,9 +315,9 @@ function NeuronGUI:PopulateLayoutBarOptions(scrollFrame) alphaSlider:SetSliderValues(.01,1,.01) alphaSlider:SetIsPercent(true) alphaSlider:SetLabel(L["Alpha"]) - alphaSlider:SetValue(Neuron.currentBar:GetBarAlpha()) + alphaSlider:SetValue(bar:GetBarAlpha()) alphaSlider:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetBarAlpha(self:GetValue()) + bar:SetBarAlpha(self:GetValue()) end) alphaContainer:AddChild(alphaSlider) @@ -417,9 +334,9 @@ function NeuronGUI:PopulateLayoutBarOptions(scrollFrame) alphaUpDropdown:SetRelativeWidth(INNER_WIDGET_RATIO) alphaUpDropdown:SetList({["off"] = L["Off"], ["mouseover"] = L["Mouseover"], ["combat"] = L["Combat"], ["combat + mouseover"] = L["Combat + Mouseover"]}, {[1] = "off", [2] = "mouseover", [3] = "combat", [4] = "combat + mouseover"}) - alphaUpDropdown:SetValue(Neuron.currentBar:GetAlphaUp()) + alphaUpDropdown:SetValue(bar:GetAlphaUp()) alphaUpDropdown:SetCallback("OnValueChanged", function(_, _, key) - Neuron.currentBar:SetAlphaUp(key) + bar:SetAlphaUp(key) end) AlphaUpDropdownContainer:AddChild(alphaUpDropdown) @@ -436,9 +353,9 @@ function NeuronGUI:PopulateLayoutBarOptions(scrollFrame) alphaSpeedSlider:SetSliderValues(.01,1,.01) alphaSpeedSlider:SetIsPercent(true) alphaSpeedSlider:SetLabel(L["AlphaUp Speed"]) - alphaSpeedSlider:SetValue(Neuron.currentBar:GetAlphaUpSpeed()) + alphaSpeedSlider:SetValue(bar:GetAlphaUpSpeed()) alphaSpeedSlider:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetAlphaUpSpeed(self:GetValue()) + bar:SetAlphaUpSpeed(self:GetValue()) end) alphaSpeedContainer:AddChild(alphaSpeedSlider) @@ -455,19 +372,22 @@ function NeuronGUI:PopulateLayoutBarOptions(scrollFrame) strataDropdown:SetRelativeWidth(INNER_WIDGET_RATIO) strataDropdown:SetList({[2] = L["Low"], [3] = L["Medium"], [4] = L["High"], [5] = L["Dialog"], [6] = L["Tooltip"]}, {[1] = 2, [2] = 3, [3] = 4, [4] = 5, [5] = 6}) - strataDropdown:SetValue(Neuron.currentBar:GetStrata()) + strataDropdown:SetValue(bar:GetStrata()) strataDropdown:SetCallback("OnValueChanged", function(_, _, key) - Neuron.currentBar:SetStrata(key) + bar:SetStrata(key) end) strataDropdownContainer:AddChild(strataDropdown) end -function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) +---@param bar Bar +---@param scrollFrame Frame +---@param registeredGUIData any +local function visualBarOptions(bar, scrollFrame, registeredGUIData) -------------------------------------------------- -------------------- Bind Text ------------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].visualOptions.BINDTEXT then + if registeredGUIData[bar.class].visualOptions.BINDTEXT then local bindTextContainer = AceGUI:Create("SimpleGroup") bindTextContainer:SetWidth(WIDGET_GRID_WIDTH) bindTextContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -477,17 +397,17 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) local bindTextCheckbox = AceGUI:Create("CheckBox") bindTextCheckbox:SetLabel(L["Keybind Label"]) bindTextCheckbox:SetRelativeWidth(.70) - bindTextCheckbox:SetValue(Neuron.currentBar:GetShowBindText()) + bindTextCheckbox:SetValue(bar:GetShowBindText()) bindTextCheckbox:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetShowBindText(self:GetValue()) + bar:SetShowBindText(self:GetValue()) end) bindTextContainer:AddChild(bindTextCheckbox) local bindTextColorPicker = AceGUI:Create("ColorPicker") bindTextColorPicker:SetRelativeWidth(.15) - bindTextColorPicker:SetColor(Neuron.currentBar:GetBindColor()[1],Neuron.currentBar:GetBindColor()[2],Neuron.currentBar:GetBindColor()[3]) + bindTextColorPicker:SetColor(bar:GetBindColor()[1],bar:GetBindColor()[2],bar:GetBindColor()[3]) bindTextColorPicker:SetCallback("OnValueConfirmed", function(_,_, r,g,b,a) - Neuron.currentBar:SetBindColor({r,g,b,a}) + bar:SetBindColor({r,g,b,a}) end) bindTextContainer:AddChild(bindTextColorPicker) end @@ -495,7 +415,7 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- ------------------- Macro Text ------------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].visualOptions.BUTTONTEXT then + if registeredGUIData[bar.class].visualOptions.BUTTONTEXT then local macroTextContainer = AceGUI:Create("SimpleGroup") macroTextContainer:SetWidth(WIDGET_GRID_WIDTH) macroTextContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -505,17 +425,17 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) local macroTextCheckbox = AceGUI:Create("CheckBox") macroTextCheckbox:SetLabel(L["Button Name"]) macroTextCheckbox:SetRelativeWidth(.70) - macroTextCheckbox:SetValue(Neuron.currentBar:GetShowButtonText()) + macroTextCheckbox:SetValue(bar:GetShowButtonText()) macroTextCheckbox:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetShowButtonText(self:GetValue()) + bar:SetShowButtonText(self:GetValue()) end) macroTextContainer:AddChild(macroTextCheckbox) local macroTextColorPicker = AceGUI:Create("ColorPicker") macroTextColorPicker:SetRelativeWidth(.15) - macroTextColorPicker:SetColor(Neuron.currentBar:GetMacroColor()[1],Neuron.currentBar:GetMacroColor()[2],Neuron.currentBar:GetMacroColor()[3]) + macroTextColorPicker:SetColor(bar:GetMacroColor()[1],bar:GetMacroColor()[2],bar:GetMacroColor()[3]) macroTextColorPicker:SetCallback("OnValueConfirmed", function(_,_, r,g,b,a) - Neuron.currentBar:SetMacroColor({r,g,b,a}) + bar:SetMacroColor({r,g,b,a}) end) macroTextContainer:AddChild(macroTextColorPicker) end @@ -523,7 +443,7 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- -------------------- Count Text ------------------ -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].visualOptions.COUNTTEXT then + if registeredGUIData[bar.class].visualOptions.COUNTTEXT then local countTextContainer = AceGUI:Create("SimpleGroup") countTextContainer:SetWidth(WIDGET_GRID_WIDTH) countTextContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -533,17 +453,17 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) local countTextCheckbox = AceGUI:Create("CheckBox") countTextCheckbox:SetLabel(L["Stack/Charge"]) countTextCheckbox:SetRelativeWidth(.70) - countTextCheckbox:SetValue(Neuron.currentBar:GetShowCountText()) + countTextCheckbox:SetValue(bar:GetShowCountText()) countTextCheckbox:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetShowCountText(self:GetValue()) + bar:SetShowCountText(self:GetValue()) end) countTextContainer:AddChild(countTextCheckbox) local countTextColorPicker = AceGUI:Create("ColorPicker") countTextColorPicker:SetRelativeWidth(.15) - countTextColorPicker:SetColor(Neuron.currentBar:GetCountColor()[1],Neuron.currentBar:GetCountColor()[2],Neuron.currentBar:GetCountColor()[3]) + countTextColorPicker:SetColor(bar:GetCountColor()[1],bar:GetCountColor()[2],bar:GetCountColor()[3]) countTextColorPicker:SetCallback("OnValueConfirmed", function(_,_, r,g,b,a) - Neuron.currentBar:SetCountColor({r,g,b,a}) + bar:SetCountColor({r,g,b,a}) end) countTextContainer:AddChild(countTextColorPicker) end @@ -551,7 +471,7 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- ------------------ Range Indicator --------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].visualOptions.RANGEIND then + if registeredGUIData[bar.class].visualOptions.RANGEIND then local rangeIndContainer = AceGUI:Create("SimpleGroup") rangeIndContainer:SetWidth(WIDGET_GRID_WIDTH) rangeIndContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -561,17 +481,17 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) local rangeIndCheckbox = AceGUI:Create("CheckBox") rangeIndCheckbox:SetLabel(L["Out-of-Range"]) rangeIndCheckbox:SetRelativeWidth(.70) - rangeIndCheckbox:SetValue(Neuron.currentBar:GetShowRangeIndicator()) + rangeIndCheckbox:SetValue(bar:GetShowRangeIndicator()) rangeIndCheckbox:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetShowRangeIndicator(self:GetValue()) + bar:SetShowRangeIndicator(self:GetValue()) end) rangeIndContainer:AddChild(rangeIndCheckbox) local rangIndColorPicker = AceGUI:Create("ColorPicker") rangIndColorPicker:SetRelativeWidth(.15) - rangIndColorPicker:SetColor(Neuron.currentBar:GetRangeColor()[1],Neuron.currentBar:GetRangeColor()[2],Neuron.currentBar:GetRangeColor()[3]) + rangIndColorPicker:SetColor(bar:GetRangeColor()[1],bar:GetRangeColor()[2],bar:GetRangeColor()[3]) rangIndColorPicker:SetCallback("OnValueConfirmed", function(_,_, r,g,b,a) - Neuron.currentBar:SetRangeColor({r,g,b,a}) + bar:SetRangeColor({r,g,b,a}) end) rangeIndContainer:AddChild(rangIndColorPicker) end @@ -579,7 +499,7 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- ------------------ Cooldown Text ----------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].visualOptions.CDTEXT then + if registeredGUIData[bar.class].visualOptions.CDTEXT then local cooldownCounterContainer = AceGUI:Create("SimpleGroup") cooldownCounterContainer:SetWidth(WIDGET_GRID_WIDTH) cooldownCounterContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -589,25 +509,25 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) local cooldownCounterCheckbox = AceGUI:Create("CheckBox") cooldownCounterCheckbox:SetLabel(L["CD Counter"]) cooldownCounterCheckbox:SetRelativeWidth(.70) - cooldownCounterCheckbox:SetValue(Neuron.currentBar:GetShowCooldownText()) + cooldownCounterCheckbox:SetValue(bar:GetShowCooldownText()) cooldownCounterCheckbox:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetShowCooldownText(self:GetValue()) + bar:SetShowCooldownText(self:GetValue()) end) cooldownCounterContainer:AddChild(cooldownCounterCheckbox) local cooldownCounterColorPicker1 = AceGUI:Create("ColorPicker") cooldownCounterColorPicker1:SetRelativeWidth(.15) - cooldownCounterColorPicker1:SetColor(Neuron.currentBar:GetCooldownColor1()[1],Neuron.currentBar:GetCooldownColor1()[2],Neuron.currentBar:GetCooldownColor1()[3]) + cooldownCounterColorPicker1:SetColor(bar:GetCooldownColor1()[1],bar:GetCooldownColor1()[2],bar:GetCooldownColor1()[3]) cooldownCounterColorPicker1:SetCallback("OnValueConfirmed", function(_,_, r,g,b) - Neuron.currentBar:SetCooldownColor1({r,g,b}) + bar:SetCooldownColor1({r,g,b}) end) cooldownCounterContainer:AddChild(cooldownCounterColorPicker1) local cooldownCounterColorPicker2 = AceGUI:Create("ColorPicker") cooldownCounterColorPicker2:SetRelativeWidth(.15) - cooldownCounterColorPicker2:SetColor(Neuron.currentBar:GetCooldownColor2()[1],Neuron.currentBar:GetCooldownColor2()[2],Neuron.currentBar:GetCooldownColor2()[3]) + cooldownCounterColorPicker2:SetColor(bar:GetCooldownColor2()[1],bar:GetCooldownColor2()[2],bar:GetCooldownColor2()[3]) cooldownCounterColorPicker2:SetCallback("OnValueConfirmed", function(_,_, r,g,b) - Neuron.currentBar:SetCooldownColor2({r,g,b}) + bar:SetCooldownColor2({r,g,b}) end) cooldownCounterContainer:AddChild(cooldownCounterColorPicker2) end @@ -615,7 +535,7 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- ------------------ Cooldown Alpha ---------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].visualOptions.CDALPHA then + if registeredGUIData[bar.class].visualOptions.CDALPHA then local cooldownAlphaContainer = AceGUI:Create("SimpleGroup") cooldownAlphaContainer:SetWidth(WIDGET_GRID_WIDTH) cooldownAlphaContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -624,9 +544,9 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) local cooldownAlphaCheckbox = AceGUI:Create("CheckBox") cooldownAlphaCheckbox:SetLabel(L["Cooldown Alpha"]) - cooldownAlphaCheckbox:SetValue(Neuron.currentBar:GetShowCooldownAlpha()) + cooldownAlphaCheckbox:SetValue(bar:GetShowCooldownAlpha()) cooldownAlphaCheckbox:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetShowCooldownAlpha(self:GetValue()) + bar:SetShowCooldownAlpha(self:GetValue()) end) cooldownAlphaContainer:AddChild(cooldownAlphaCheckbox) @@ -635,16 +555,13 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- ------------------ SpellGlow --------------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].visualOptions.SPELLGLOW then + if registeredGUIData[bar.class].visualOptions.SPELLGLOW then local spellAlertDropdownContainer = AceGUI:Create("SimpleGroup") spellAlertDropdownContainer:SetWidth(WIDGET_GRID_WIDTH) spellAlertDropdownContainer:SetHeight(WIDGET_GRID_HEIGHT) scrollFrame:AddChild(spellAlertDropdownContainer) - local currentGlow = Neuron.currentBar:GetSpellGlow() - if not currentGlow then - currentGlow = "none" - end + local currentGlow = bar:GetSpellGlow() or "none" local spellAlertDropdown = AceGUI:Create("Dropdown") spellAlertDropdown:SetLabel(L["Spell Alerts"]) @@ -653,7 +570,7 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) {[1] = "none", [2] = "alternate", [3] = "default"}) spellAlertDropdown:SetValue(currentGlow) spellAlertDropdown:SetCallback("OnValueChanged", function(_, _, key) - Neuron.currentBar:SetSpellGlow(key) + bar:SetSpellGlow(key) end) spellAlertDropdownContainer:AddChild(spellAlertDropdown) end @@ -661,16 +578,13 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- -------------------- Tooltips -------------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].visualOptions.TOOLTIPS then + if registeredGUIData[bar.class].visualOptions.TOOLTIPS then local tooltipDropdownContainer = AceGUI:Create("SimpleGroup") tooltipDropdownContainer:SetWidth(WIDGET_GRID_WIDTH) tooltipDropdownContainer:SetHeight(WIDGET_GRID_HEIGHT) scrollFrame:AddChild(tooltipDropdownContainer) - local currentTooltipOption = Neuron.currentBar:GetTooltipOption() - if not currentTooltipOption then - currentTooltipOption = "none" - end + local currentTooltipOption = bar:GetTooltipOption() local tooltipDropdown = AceGUI:Create("Dropdown") tooltipDropdown:SetLabel(L["Enable Tooltips"]) @@ -679,7 +593,7 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) {[1] = "off", [2] = "minimal", [3] = "normal"}) tooltipDropdown:SetValue(currentTooltipOption) tooltipDropdown:SetCallback("OnValueChanged", function(_, _, key) - Neuron.currentBar:SetTooltipOption(key) + bar:SetTooltipOption(key) end) tooltipDropdownContainer:AddChild(tooltipDropdown) @@ -688,7 +602,7 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- ------------------Tooltips in Combat ------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].visualOptions.TOOLTIPS then + if registeredGUIData[bar.class].visualOptions.TOOLTIPS then local combatTooltipsCheckboxContainer = AceGUI:Create("SimpleGroup") combatTooltipsCheckboxContainer:SetWidth(WIDGET_GRID_WIDTH) combatTooltipsCheckboxContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -697,9 +611,9 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) local combatTooltipsCheckbox = AceGUI:Create("CheckBox") combatTooltipsCheckbox:SetLabel(L["Tooltips in Combat"]) combatTooltipsCheckbox:SetRelativeWidth(INNER_WIDGET_RATIO) - combatTooltipsCheckbox:SetValue(Neuron.currentBar:GetTooltipCombat()) + combatTooltipsCheckbox:SetValue(bar:GetTooltipCombat()) combatTooltipsCheckbox:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetTooltipCombat(self:GetValue()) + bar:SetTooltipCombat(self:GetValue()) end) combatTooltipsCheckboxContainer:AddChild(combatTooltipsCheckbox) end @@ -707,7 +621,7 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) -------------------------------------------------- ------------------- Border Style ----------------- -------------------------------------------------- - if registeredGUIData[Neuron.currentBar.class].visualOptions.BORDERSTYLE then + if registeredGUIData[bar.class].visualOptions.BORDERSTYLE then local borderStyleCheckboxContainer = AceGUI:Create("SimpleGroup") borderStyleCheckboxContainer:SetWidth(WIDGET_GRID_WIDTH) borderStyleCheckboxContainer:SetHeight(WIDGET_GRID_HEIGHT) @@ -716,9 +630,9 @@ function NeuronGUI:PopulateVisualBarOptions(scrollFrame, registeredGUIData) local borderStyleCheckbox = AceGUI:Create("CheckBox") borderStyleCheckbox:SetLabel(L["Show Border Style"]) borderStyleCheckbox:SetRelativeWidth(INNER_WIDGET_RATIO) - borderStyleCheckbox:SetValue(Neuron.currentBar:GetShowBorderStyle()) + borderStyleCheckbox:SetValue(bar:GetShowBorderStyle()) borderStyleCheckbox:SetCallback("OnValueChanged", function(self) - Neuron.currentBar:SetShowBorderStyle(self:GetValue()) + bar:SetShowBorderStyle(self:GetValue()) end) borderStyleCheckboxContainer:AddChild(borderStyleCheckbox) end @@ -728,23 +642,24 @@ end -------------------------------------------------- --Delete bar popup menu -function NeuronGUI:DeleteBarPopup() +---@param bar Bar +local function deleteBarPopup(bar) StaticPopupDialogs["Delete_Bar_Popup"] = { - text = "Do you really wish to delete "..Neuron.currentBar:GetBarName().."?", + text = "Do you really wish to delete "..bar:GetBarName().."?", button1 = ACCEPT, button2 = CANCEL, timeout = 0, whileDead = true, - OnAccept = function() Neuron.currentBar:DeleteBar(); NeuronGUI:RefreshEditor() end, + OnAccept = function() bar:DeleteBar(); NeuronGUI:RefreshEditor() end, OnCancel = function() NeuronGUI:RefreshEditor() end, } StaticPopup_Show("Delete_Bar_Popup") end --Bar Rename -function NeuronGUI:updateBarName(editBox) - local bar = Neuron.currentBar - +---@param bar Bar +---@param editBox any +local function updateBarName(bar, editBox) if bar then bar:SetBarName(editBox:GetText()) @@ -752,3 +667,87 @@ function NeuronGUI:updateBarName(editBox) NeuronGUI:RefreshEditor() end end + +---@param bar Bar +---@param tabFrame Frame +function NeuronGUI:GeneralConfigPanel(bar, tabFrame) + local registeredGUIData = Neuron:RegisterGUI() + + local scrollFrame = AceGUI:Create("ScrollFrame") + scrollFrame:SetLayout("Flow") + tabFrame:AddChild(scrollFrame) + + -------------------------------------------------- + -------------------- Rename Bar ------------------ + -------------------------------------------------- + local renameBoxContainer = AceGUI:Create("SimpleGroup") + renameBoxContainer:SetWidth(WIDGET_GRID_WIDTH*1.5) + renameBoxContainer:SetHeight(WIDGET_GRID_HEIGHT) + scrollFrame:AddChild(renameBoxContainer) + + local renameBox = AceGUI:Create("EditBox") + renameBox:SetRelativeWidth(INNER_WIDGET_RATIO) + renameBox:SetLabel("Rename selected bar:") + renameBox:SetText(bar:GetBarName()) + renameBox:SetCallback("OnEnterPressed", function(editBox) updateBarName(bar, editBox) end) + renameBoxContainer:AddChild(renameBox) + + ------------------------------------------------ + ------------------------------------------------ + --General Options Heading + local heading1 = AceGUI:Create("Heading") + heading1:SetHeight(WIDGET_GRID_HEIGHT) + heading1:SetFullWidth(true) + heading1:SetText(L["General Options"]) + scrollFrame:AddChild(heading1) + + generalBarOptions(bar, scrollFrame, registeredGUIData) + + ------------------------------------------------ + ------------------------------------------------ + --Layout Heading + local heading2 = AceGUI:Create("Heading") + heading2:SetHeight(WIDGET_GRID_HEIGHT) + heading2:SetFullWidth(true) + heading2:SetText(L["Size and Shape"]) + scrollFrame:AddChild(heading2) + + layoutBarOptions(bar, scrollFrame) + + ------------------------------------------------ + ------------------------------------------------ + if registeredGUIData[bar.class].visualOptions then + --Visual Heading + local heading3 = AceGUI:Create("Heading") + heading3:SetHeight(WIDGET_GRID_HEIGHT) + heading3:SetFullWidth(true) + heading3:SetText(L["Visuals"]) + scrollFrame:AddChild(heading3) + + visualBarOptions(bar, scrollFrame, registeredGUIData) + end + + -------------------------------------------------- + -------------------------------------------------- + --Dangerous Heading + local heading4 = AceGUI:Create("Heading") + heading4:SetHeight(WIDGET_GRID_HEIGHT) + heading4:SetFullWidth(true) + heading4:SetText("Dangerous") + scrollFrame:AddChild(heading4) + + -------------------------------------------------- + ------------------ Delete Bar -------------------- + -------------------------------------------------- + local deleteBarButtonContainer = AceGUI:Create("SimpleGroup") + deleteBarButtonContainer:SetWidth(WIDGET_GRID_WIDTH*1.5) + deleteBarButtonContainer:SetHeight(WIDGET_GRID_HEIGHT) + scrollFrame:AddChild(deleteBarButtonContainer) + + local deleteBarButton = AceGUI:Create("Button") + deleteBarButton:SetRelativeWidth(INNER_WIDGET_RATIO) + deleteBarButton:SetText("Delete Current Bar") + deleteBarButton:SetCallback("OnClick", function() deleteBarPopup(bar) end) + deleteBarButtonContainer:AddChild(deleteBarButton) +end + diff --git a/Neuron-DB-Defaults.lua b/Neuron-DB-Defaults.lua index 4957e5a..94c7608 100644 --- a/Neuron-DB-Defaults.lua +++ b/Neuron-DB-Defaults.lua @@ -217,7 +217,7 @@ local genericKeyData = { ---@field conceal boolean ---@field multiSpec boolean ---@field spellGlow "default"|"alternate"|false ----@field barLock boolean +---@field barLock "shift"|"ctrl"|"alt"|false ---@field tooltips "normal"|"minimal"|"off" ---@field tooltipsCombat boolean ---@field bindText boolean diff --git a/Objects/Bar.lua b/Objects/Bar.lua index 716ef30..7f713fe 100644 --- a/Objects/Bar.lua +++ b/Objects/Bar.lua @@ -10,6 +10,8 @@ local Spec = addonTable.utilities.Spec local BarEditor = addonTable.overlay.BarEditor ---@class Bar : CheckButton @This is our bar object that serves as the container for all of our button objects +---@field data GenericBarData +---@field class "ActionBar"|"BagBar"|"MenuBar"|"PetBar"|"XPBar"|"RepBar"|"CastBar"|"MirrorBar"|"ZoneAbilityBar"|"ExtraBar"|"ExitBar" local Bar = setmetatable({}, {__index = CreateFrame("CheckButton")}) --this is the metatable for our button object Neuron.Bar = Bar @@ -1655,7 +1657,8 @@ function Bar:SetTooltipOption(option) end function Bar:GetTooltipOption() - return self.data.tooltips + -- fallback to "off" in case there is some falsey value of this in the db somewhere + return self.data.tooltips or "off" end function Bar:SetTooltipCombat(checked) From bb932ddb8a1c0808d72a6d1f7466c3e922012ba4 Mon Sep 17 00:00:00 2001 From: Jon Allen Date: Mon, 2 Jan 2023 00:00:50 -0600 Subject: [PATCH 5/7] more globals --- GUI/BarEditTab.lua | 67 +++++++++++++++++++++------------------------- GUI/MainWindow.lua | 6 ++--- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/GUI/BarEditTab.lua b/GUI/BarEditTab.lua index 340509d..9d66258 100644 --- a/GUI/BarEditTab.lua +++ b/GUI/BarEditTab.lua @@ -17,10 +17,9 @@ local selectedBarType --remember which bar type was selected for creating new ba ----------------------------------------------------------------------------- --------------------------Bar Editor----------------------------------------- ----------------------------------------------------------------------------- -function NeuronGUI:BarEditPanel(tabFrame) - - Neuron:ToggleBarEditMode(true) - +---@param currentBar Bar +---@param tabFrame Frame +function NeuronGUI:BarEditPanel(currentBar, tabFrame) ------------------------------- --Container for the top Row local topRow = AceGUI:Create("SimpleGroup") @@ -47,9 +46,9 @@ function NeuronGUI:BarEditPanel(tabFrame) local barListDropdown = AceGUI:Create("Dropdown") barListDropdown:SetWidth(180) barListDropdown:SetLabel("Switch selected bar:") - barListDropdown:SetText(Neuron.currentBar:GetBarName() or "") + barListDropdown:SetText(currentBar:GetBarName() or "") barListDropdown:SetList(barList) --assign the bar type table to the dropdown menu - barListDropdown:SetCallback("OnValueChanged", function(self, callBackType, key) Neuron.Bar.ChangeSelectedBar(key); NeuronGUI:RefreshEditor() end) + barListDropdown:SetCallback("OnValueChanged", function(_, _, key) Neuron.Bar.ChangeSelectedBar(key); NeuronGUI:RefreshEditor() end) topRow:AddChild(barListDropdown) ------------------------------- @@ -78,7 +77,7 @@ function NeuronGUI:BarEditPanel(tabFrame) barTypeDropdown:SetText("- select a bar type -") end barTypeDropdown:SetList(barTypes) --assign the bar type table to the dropdown menu - barTypeDropdown:SetCallback("OnValueChanged", function(self, callBackType, key) selectedBarType = key; newBarButton:SetDisabled(false) end) + barTypeDropdown:SetCallback("OnValueChanged", function(_, _, key) selectedBarType = key; newBarButton:SetDisabled(false) end) topRow:AddChild(barTypeDropdown) ------------------------------- @@ -106,49 +105,43 @@ function NeuronGUI:BarEditPanel(tabFrame) ------ Settings Tab Group ------- --------------------------------- - if Neuron.currentBar then - --Tab group that will contain all of our settings to configure - local innerTabFrame = AceGUI:Create("TabGroup") - innerTabFrame:SetLayout("Fill") - innerTabFrame:SetFullHeight(true) - innerTabFrame:SetFullWidth(true) - --only show the states tab if the bar is an ActionBar - if Neuron.currentBar.class=="ActionBar" then - innerTabFrame:SetTabs({{text="General Configuration", value="general"}, {text="Bar States", value="states"}, {text="Bar Visibility", value="visibility"}}) - else - innerTabFrame:SetTabs({{text="General Configuration", value="general"}, {text="Bar Visibility", value="visibility"}}) - if currentTab == "states" then - currentTab = "general" - end - end - innerTabFrame:SetCallback("OnGroupSelected", function(self, _, value) NeuronGUI:SelectInnerBarTab(self, _, value) end) - tabFrame:AddChild(innerTabFrame) - - innerTabFrame:SelectTab(currentTab) + --Tab group that will contain all of our settings to configure + local innerTabFrame = AceGUI:Create("TabGroup") + innerTabFrame:SetLayout("Fill") + innerTabFrame:SetFullHeight(true) + innerTabFrame:SetFullWidth(true) + --only show the states tab if the bar is an ActionBar + if currentBar.class=="ActionBar" then + innerTabFrame:SetTabs({{text="General Configuration", value="general"}, {text="Bar States", value="states"}, {text="Bar Visibility", value="visibility"}}) else - local selectBarMessage = AceGUI:Create("Label") - selectBarMessage:SetText("Please select a bar to continue") - selectBarMessage:SetFont("Fonts\\FRIZQT__.TTF", 30) - tabFrame:AddChild(selectBarMessage) + innerTabFrame:SetTabs({{text="General Configuration", value="general"}, {text="Bar Visibility", value="visibility"}}) + if currentTab == "states" then + currentTab = "general" + end end + innerTabFrame:SetCallback("OnGroupSelected", function(callbackFrame, _, value) NeuronGUI:SelectInnerBarTab(currentBar, callbackFrame, value) end) + tabFrame:AddChild(innerTabFrame) + + innerTabFrame:SelectTab(currentTab) end ----------------------------------------------------------------------------- ----------------------Inner Tab Frame---------------------------------------- ----------------------------------------------------------------------------- -function NeuronGUI:SelectInnerBarTab(tabFrame, _, value) +---@param bar Bar +---@param tabFrame Frame +---@param value "general"|"states"|"visibility" +function NeuronGUI:SelectInnerBarTab(bar, tabFrame, value) tabFrame:ReleaseChildren() - if not Neuron.currentBar then - return - elseif value == "general" then - NeuronGUI:GeneralConfigPanel(Neuron.currentBar, tabFrame) + if value == "general" then + NeuronGUI:GeneralConfigPanel(bar, tabFrame) currentTab = "general" elseif value == "states" then - NeuronGUI:BarStatesPanel(Neuron.currentBar, tabFrame) + NeuronGUI:BarStatesPanel(bar, tabFrame) currentTab = "states" elseif value == "visibility" then - NeuronGUI:BarVisibilityPanel(Neuron.currentBar, tabFrame) + NeuronGUI:BarVisibilityPanel(bar, tabFrame) currentTab = "visibility" end end diff --git a/GUI/MainWindow.lua b/GUI/MainWindow.lua index c69b47d..c7387a8 100644 --- a/GUI/MainWindow.lua +++ b/GUI/MainWindow.lua @@ -20,6 +20,7 @@ local currentTab = "bar" --remember which tab we were using between refreshes --------------------------Main Window---------------------------------------- ----------------------------------------------------------------------------- +---@param defaultTab "bar"|"button"|"status" function NeuronGUI:RefreshEditor(defaultTab) addonTable.NeuronEditor:ReleaseChildren() @@ -76,7 +77,6 @@ function NeuronGUI:DestroyEditor() addonTable.NeuronEditor = nil end - Neuron:ToggleBarEditMode() Neuron:ToggleButtonEditMode() end @@ -117,8 +117,8 @@ end function NeuronGUI:SelectTab(tabFrame, _, value) tabFrame:ReleaseChildren() - if value == "bar" then - NeuronGUI:BarEditPanel(tabFrame) + if value == "bar" and Neuron.currentBar then + NeuronGUI:BarEditPanel(Neuron.currentBar, tabFrame) elseif value == "button" and Neuron.currentButton then -- whenever we change a button, RefreshEditor is called upstream -- so we don't need to keep track of updating currentButton here From 68489654a40f11c2cc704487ec2bc4a697613ebc Mon Sep 17 00:00:00 2001 From: Jon Allen Date: Mon, 2 Jan 2023 00:04:45 -0600 Subject: [PATCH 6/7] wire up a controller also used some alternative syntax that seems to help the lsp correlate --- Neuron-Console.lua | 2 +- Neuron-MinimapIcon.lua | 67 ++++++-------- Neuron.lua | 82 +++-------------- Neuron.toc | 2 + Objects/ActionButton.lua | 2 +- Objects/Bar.lua | 20 +---- Objects/Button.lua | 2 +- Objects/CastButton.lua | 8 +- Objects/MirrorButton.lua | 6 +- Objects/StatusButton.lua | 4 +- Overlay/BarEditor.lua | 184 ++++++++++++++++++++------------------- 11 files changed, 148 insertions(+), 231 deletions(-) diff --git a/Neuron-Console.lua b/Neuron-Console.lua index 8caef10..2fd239d 100644 --- a/Neuron-Console.lua +++ b/Neuron-Console.lua @@ -72,7 +72,7 @@ function Neuron:slashHandler(input) end --somewhat of a hack to insert a "true" as an arg if trying to toggle the edit modes - if command == "config" and Neuron.barEditMode == false then + if command == "config" and Neuron.state.kind ~= "bar" then args[1] = true end if command == "edit" and Neuron.buttonEditMode == false then diff --git a/Neuron-MinimapIcon.lua b/Neuron-MinimapIcon.lua index 5d5cc2c..637b657 100644 --- a/Neuron-MinimapIcon.lua +++ b/Neuron-MinimapIcon.lua @@ -6,6 +6,9 @@ local _, addonTable = ... local Neuron = addonTable.Neuron +---@type EditMode +local EditMode = addonTable.controller.EditMode + --Neuron MinimapIcon makes use of LibDBIcon and LibDataBroker to make sure we play --nicely with LDB addons and to simplify dramatically the minimap button @@ -42,50 +45,34 @@ function Neuron:Minimap_OnClickHandler(button) PlaySound(SOUNDKIT.IG_CHAT_SCROLL_DOWN) - if button == "LeftButton" then - if IsShiftKeyDown() then - if not Neuron.bindingMode then - Neuron:ToggleBindingMode(true) - else - Neuron:ToggleBindingMode(false) - end + if button == "LeftButton" and IsShiftKeyDown() then + if not Neuron.bindingMode then + Neuron:ToggleBindingMode(true) else - if not Neuron.barEditMode then - Neuron:ToggleBarEditMode(true) - if not addonTable.NeuronEditor then - Neuron.NeuronGUI:CreateEditor("bar") - else - Neuron.NeuronGUI:RefreshEditor("bar") - end - else - Neuron:ToggleBarEditMode(false) - if addonTable.NeuronEditor then - Neuron.NeuronGUI:DestroyEditor() - end - end + Neuron:ToggleBindingMode(false) end - elseif button == "RightButton" then - if IsShiftKeyDown() then - if SettingsPanel and SettingsPanel:IsShown() then - SettingsPanel:Hide() - elseif InterfaceOptionsFrame and InterfaceOptionsFrame:IsShown() then --this is for pre-dragonflight compatibility - InterfaceOptionsFrame:Hide(); + elseif button == "LeftButton" and not IsShiftKeyDown() then + Neuron.state = EditMode.enterBarMode(Neuron.state, false, false) + elseif button == "RightButton" and IsShiftKeyDown() then + if SettingsPanel and SettingsPanel:IsShown() then + SettingsPanel:Hide() + elseif InterfaceOptionsFrame and InterfaceOptionsFrame:IsShown() then --this is for pre-dragonflight compatibility + InterfaceOptionsFrame:Hide(); + else + Neuron:ToggleMainMenu() + end + elseif button == "RightButton" and not IsShiftKeyDown() then + if not Neuron.buttonEditMode then + Neuron:ToggleButtonEditMode(true) + if not addonTable.NeuronEditor then + Neuron.NeuronGUI:CreateEditor("button") else - Neuron:ToggleMainMenu() + Neuron.NeuronGUI:RefreshEditor("button") end else - if not Neuron.buttonEditMode then - Neuron:ToggleButtonEditMode(true) - if not addonTable.NeuronEditor then - Neuron.NeuronGUI:CreateEditor("button") - else - Neuron.NeuronGUI:RefreshEditor("button") - end - else - Neuron:ToggleButtonEditMode(false) - if addonTable.NeuronEditor then - Neuron.NeuronGUI:DestroyEditor() - end + Neuron:ToggleButtonEditMode(false) + if addonTable.NeuronEditor then + Neuron.NeuronGUI:DestroyEditor() end end end @@ -111,4 +98,4 @@ function Neuron:Minimap_ToggleIcon() icon:Show("Neuron") DB.NeuronIcon.hide = false end -end \ No newline at end of file +end diff --git a/Neuron.lua b/Neuron.lua index a90188a..e06753d 100644 --- a/Neuron.lua +++ b/Neuron.lua @@ -11,7 +11,9 @@ local DBFixer = addonTable.utilities.DBFixer local Array = addonTable.utilities.Array local ButtonBinder = addonTable.overlay.ButtonBinder local ButtonEditor = addonTable.overlay.ButtonEditor -local BarEditor = addonTable.overlay.BarEditor + +---@type EditMode +local EditMode = addonTable.controller.EditMode ---@class Neuron : AceAddon-3.0 @define The main addon object for the Neuron Action Bar addon addonTable.Neuron = LibStub("AceAddon-3.0"):NewAddon(CreateFrame("Frame", nil, UIParent), "Neuron", "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0", "AceSerializer-3.0") @@ -33,7 +35,6 @@ Neuron.registeredBarData = {} Neuron.itemCache = {} --Stores a cache of all items that have been seen by a Neuron button Neuron.spellCache = {} --Stores a cache of all spells that have been seen by a Neuron button -Neuron.barEditMode = false Neuron.buttonEditMode = false Neuron.bindingMode = false @@ -55,6 +56,11 @@ Neuron.SNAPTO_TOLERANCE = 28 Neuron.DEBUG = true +---@type EditModeState +Neuron.state = { + guiState = { kind = "off" }, +} + ------------------------------------------------------------------------- --------------------Start of Functions----------------------------------- ------------------------------------------------------------------------- @@ -121,29 +127,6 @@ function Neuron:OnEnable() Neuron:UpdateStanceStrings() - --this allows for the "Esc" key to disable the Edit Mode instead of bringing up the game menu, but only if an edit mode is activated. - - if not Neuron:IsHooked(GameMenuFrame, "OnUpdate") then - Neuron:HookScript(GameMenuFrame, "OnUpdate", function(self) - - if Neuron.barEditMode then - HideUIPanel(self) - Neuron:ToggleBarEditMode(false) - end - - if Neuron.buttonEditMode then - HideUIPanel(self) - Neuron:ToggleButtonEditMode(false) - end - - if Neuron.bindingMode then - HideUIPanel(self) - Neuron:ToggleBindingMode(false) - end - - end) - end - Neuron:LoginMessage() --Load all bars and buttons @@ -169,7 +152,9 @@ end ------------------------------------------------- +--entering combat function Neuron:PLAYER_REGEN_DISABLED() + Neuron.state = EditMode.exit(Neuron.state) if Neuron.buttonEditMode then Neuron:ToggleButtonEditMode(false) end @@ -177,10 +162,6 @@ function Neuron:PLAYER_REGEN_DISABLED() if Neuron.bindingMode then Neuron:ToggleBindingMode(false) end - - if Neuron.barEditMode then - Neuron:ToggleBarEditMode(false) - end end @@ -372,47 +353,6 @@ function Neuron:ToggleMainMenu() InterfaceOptionsFrame_OpenToCategory("Neuron"); end -function Neuron:ToggleBarEditMode(show) - if show then - Neuron.barEditMode = true - Neuron:ToggleButtonEditMode(false) - Neuron:ToggleBindingMode(false) - - for _, bar in pairs(Neuron.bars) do - bar.editFrame = - bar.editFrame or - BarEditor.allocate(bar, function(overlay, button, down) - overlay.bar:OnClick(button, down) - end) - - bar:UpdateObjectVisibility(true) - bar:UpdateBarStatus(true) - bar:UpdateObjectStatus() - end - - --if there is no bar selected, default to the first in the BarList - --TODO: This logic may be unintuitive. Should probably be fixed - if not Neuron.currentBar and #Neuron.bars then - Neuron.Bar.ChangeSelectedBar(Neuron.bars[1]) - elseif Neuron.currentBar then - BarEditor.activate(Neuron.currentBar.editFrame) - end - else - Neuron.barEditMode = false - for _, bar in pairs(Neuron.bars) do - local overlay = bar.editFrame - bar.editFrame = nil - if overlay then - BarEditor.free(overlay) - end - - bar:UpdateObjectVisibility() - bar:UpdateBarStatus() - bar:UpdateObjectStatus() - end - end -end - function Neuron:ToggleButtonEditMode(show) local isActionBar = function(bar) return bar and bar.class == "ActionBar" @@ -436,7 +376,6 @@ function Neuron:ToggleButtonEditMode(show) if show then Neuron.buttonEditMode = true - Neuron:ToggleBarEditMode(false) Neuron:ToggleBindingMode(false) local currentButton = @@ -566,7 +505,6 @@ function Neuron:ToggleBindingMode(show) if show then Neuron.bindingMode = true Neuron:ToggleButtonEditMode(false) - Neuron:ToggleBarEditMode(false) for _, bar in pairs(bars) do for _, button in pairs(bar.buttons) do diff --git a/Neuron.toc b/Neuron.toc index 5e0ccfb..d89ccd5 100644 --- a/Neuron.toc +++ b/Neuron.toc @@ -29,6 +29,8 @@ Overlay\ButtonBinder.lua Overlay\ButtonEditor.lua Overlay\BarEditor.lua +Controller\EditMode.lua + Neuron-DB-Defaults.lua Neuron.lua Neuron-States.lua diff --git a/Objects/ActionButton.lua b/Objects/ActionButton.lua index eeaaaf3..4e15de5 100644 --- a/Objects/ActionButton.lua +++ b/Objects/ActionButton.lua @@ -821,7 +821,7 @@ end --overwrite function in parent class Button function ActionButton:UpdateVisibility(show) - if self:HasAction() or Neuron.dragging or show or self.bar:GetShowGrid() or Neuron.buttonEditMode or Neuron.barEditMode or Neuron.bindingMode then + if self:HasAction() or Neuron.dragging or show or self.bar:GetShowGrid() or Neuron.buttonEditMode or Neuron.state.kind == "bar" or Neuron.bindingMode then self.isShown = true else self.isShown = false diff --git a/Objects/Bar.lua b/Objects/Bar.lua index 7f713fe..a5ba8ec 100644 --- a/Objects/Bar.lua +++ b/Objects/Bar.lua @@ -343,7 +343,7 @@ end ---this function is set via a repeating scheduled timer in SetAutoHide() function Bar:AutoHideUpdate() if self:GetAutoHide() and self.handler~=nil then - if not Neuron.buttonEditMode and not Neuron.barEditMode and not Neuron.bindingMode then + if not Neuron.buttonEditMode and Neuron.state.kind ~= "bar" and not Neuron.bindingMode then if self:IsShown() then self.handler:SetAlpha(1) else @@ -1198,24 +1198,6 @@ end ------------------------OnEvent Functions----------------------------- ---------------------------------------------------------------------- -function Bar:OnClick(click, down) - if not down then - Bar.ChangeSelectedBar(self) - end - - if IsShiftKeyDown() and not down then - BarEditor.microadjust(self.editFrame) - elseif click == "RightButton" and not down then - if not addonTable.NeuronEditor then - Neuron.NeuronGUI:CreateEditor() - end - end - - if addonTable.NeuronEditor then - Neuron.NeuronGUI:RefreshEditor() - end -end - function Bar:OnShow() self.handler:SetAttribute("editmode", true) self.handler:Show() diff --git a/Objects/Button.lua b/Objects/Button.lua index 8fece07..78850e7 100644 --- a/Objects/Button.lua +++ b/Objects/Button.lua @@ -427,7 +427,7 @@ function Button:UpdateNormalTexture() end function Button:UpdateVisibility() - if self.isShown or Neuron.barEditMode or (Neuron.buttonEditMode and self.editFrame) or (Neuron.bindingMode and self.keybindFrame) then + if self.isShown or Neuron.state.kind == "bar" or (Neuron.buttonEditMode and self.editFrame) or (Neuron.bindingMode and self.keybindFrame) then self.isShown = true else self.isShown = false diff --git a/Objects/CastButton.lua b/Objects/CastButton.lua index 71f8834..f65bc19 100644 --- a/Objects/CastButton.lua +++ b/Objects/CastButton.lua @@ -239,7 +239,7 @@ function CastButton:OnEvent(event,...) self.StatusBar.Shield:Show() end - if not Neuron.barEditMode and not Neuron.buttonEditMode then + if Neuron.state.kind ~= "bar" and not Neuron.buttonEditMode then self.StatusBar.CenterText:SetText(self:cFunc()) self.StatusBar.LeftText:SetText(self:lFunc()) self.StatusBar.RightText:SetText(self:rFunc()) @@ -315,7 +315,7 @@ function CastButton:OnUpdate(elapsed) self.flash = nil end - elseif self.fadeout and (not Neuron.barEditMode and not Neuron.buttonEditMode) then + elseif self.fadeout and (Neuron.state.kind ~= "bar" and not Neuron.buttonEditMode) then local alpha = self.StatusBar:GetAlpha() - CASTING_BAR_ALPHA_STEP if alpha > 0 then self.StatusBar:SetAlpha(alpha) @@ -326,7 +326,7 @@ function CastButton:OnUpdate(elapsed) self:Reset() end - if not Neuron.barEditMode and not Neuron.buttonEditMode then + if Neuron.state.kind ~= "bar" and not Neuron.buttonEditMode then self.StatusBar.CenterText:SetText(self:cFunc()) self.StatusBar.LeftText:SetText(self:lFunc()) self.StatusBar.RightText:SetText(self:rFunc()) @@ -350,7 +350,7 @@ function CastButton:Reset() self.channeling = nil self.StatusBar:SetStatusBarColor(self.config.castColor[1], self.config.castColor[2], self.config.castColor[3]) - if not Neuron.barEditMode and not Neuron.buttonEditMode then + if Neuron.state.kind ~= "bar" and not Neuron.buttonEditMode then self.StatusBar:Hide() end end diff --git a/Objects/MirrorButton.lua b/Objects/MirrorButton.lua index 15ca496..0a4f6fc 100644 --- a/Objects/MirrorButton.lua +++ b/Objects/MirrorButton.lua @@ -152,7 +152,7 @@ function MirrorButton:OnUpdate() mirrorWatch[self.mirror].timer = self.value end - elseif not Neuron.barEditMode and not Neuron.buttonEditMode then + elseif Neuron.state.kind ~= "bar" and not Neuron.buttonEditMode then self.alpha = self.StatusBar:GetAlpha() - CASTING_BAR_ALPHA_STEP if self.alpha > 0 then self.StatusBar:SetAlpha(self.alpha) @@ -161,10 +161,10 @@ function MirrorButton:OnUpdate() end end - if not Neuron.barEditMode and not Neuron.buttonEditMode then + if Neuron.state.kind ~= "bar" and not Neuron.buttonEditMode then self.StatusBar.CenterText:SetText(self:cFunc()) self.StatusBar.LeftText:SetText(self:lFunc()) self.StatusBar.RightText:SetText(self:rFunc()) self.StatusBar.MouseoverText:SetText(self:mFunc()) end -end \ No newline at end of file +end diff --git a/Objects/StatusButton.lua b/Objects/StatusButton.lua index cdc510e..1659685 100644 --- a/Objects/StatusButton.lua +++ b/Objects/StatusButton.lua @@ -320,7 +320,7 @@ end --overwrite function in parent class Button function StatusButton:UpdateVisibility() - if Neuron.barEditMode or Neuron.buttonEditMode then + if Neuron.state.kind == "bar" or Neuron.buttonEditMode then self.StatusBar:Show() self.StatusBar:SetAlpha(1) end @@ -328,7 +328,7 @@ end --overwrite function in parent class Button function StatusButton:UpdateStatus() - if Neuron.barEditMode or Neuron.buttonEditMode then + if Neuron.state.kind == "bar" or Neuron.buttonEditMode then self.StatusBar.CenterText:SetText("") self.StatusBar.LeftText:SetText(self.typeString) self.StatusBar.RightText:SetText("") diff --git a/Overlay/BarEditor.lua b/Overlay/BarEditor.lua index d619ad1..3b4af6c 100644 --- a/Overlay/BarEditor.lua +++ b/Overlay/BarEditor.lua @@ -21,6 +21,7 @@ local L = LibStub("AceLocale-3.0"):GetLocale("Neuron") ---@field frame NeuronBarFrame ---@field microadjust number ---@field onClick fun(overlay: BarOverlay, button:string, down: boolean):nil +---@field onExit fun(overlay: BarOverlay):nil ---@type NeuronBarFrame[] local framePool = {} @@ -63,7 +64,8 @@ local function updateAppearance(overlay) end -- forward declare it so the event handlers can use it -local BarEditor +---@class BarEditor +local BarEditor = {} ---@param overlay BarOverlay local function onEnter(overlay) @@ -127,6 +129,12 @@ end ---@param overlay BarOverlay ---@param key string local function onKeyDown(overlay, key) + --this allows for the "Esc" key to disable the Edit Mode instead of bringing up the game menu + if key == "ESCAPE" then + overlay.onExit(overlay) + return + end + if overlay.microadjust == 0 then return end @@ -169,100 +177,100 @@ local function onClick(overlay, button, down) overlay.onClick(overlay, button, down) end -BarEditor = { - ---@param bar Bar - ---@param onClickCallback fun(overlay: BarOverlay, button: string, down: boolean): nil - ---@return BarOverlay - allocate = function (bar, onClickCallback) - ---@type BarOverlay - local overlay = { - active = false, - bar = bar, - frame = -- try to pop a frame off the stack, otherwise make a new one - table.remove(framePool) or - CreateFrame("CheckButton", nil, UIParent, "NeuronBarTemplate") --[[@as NeuronBarFrame]], - microadjust = 0, - onClick = onClickCallback, - } - overlay.frame:SetBackdrop({ - bgFile = "Interface/Tooltips/UI-Tooltip-Background", - tile = true, - tileSize = 16, - insets = {left = 4, right = 4, top = 4, bottom = 4} - }) - - overlay.frame.Text:SetText(bar:GetBarName()) +---@param bar Bar +---@param onClickCallback fun(overlay: BarOverlay, button: string, down: boolean): nil +---@param onExitCallback fun(overlay: BarOverlay): nil +---@return BarOverlay +BarEditor.allocate = function (bar, onClickCallback, onExitCallback) + ---@type BarOverlay + local overlay = { + active = false, + bar = bar, + frame = -- try to pop a frame off the stack, otherwise make a new one + table.remove(framePool) or + CreateFrame("CheckButton", nil, UIParent, "NeuronBarTemplate") --[[@as NeuronBarFrame]], + microadjust = 0, + onClick = onClickCallback, + onExit = onExitCallback + } + overlay.frame:SetBackdrop({ + bgFile = "Interface/Tooltips/UI-Tooltip-Background", + tile = true, + tileSize = 16, + insets = {left = 4, right = 4, top = 4, bottom = 4} + }) + + overlay.frame.Text:SetText(bar:GetBarName()) + + overlay.frame:EnableKeyboard(false) + overlay.frame:RegisterForClicks("AnyUp", "AnyDown") + overlay.frame:RegisterForDrag("LeftButton") + overlay.frame:SetScript("OnDragStart", function(_, button) onDragStart(overlay, button) end) + overlay.frame:SetScript("OnDragStop", function(_) onDragStop(overlay) end) + overlay.frame:SetScript("OnKeyDown", function(_, key) onKeyDown(overlay, key) end) + overlay.frame:SetScript("OnEnter", function() onEnter(overlay) end) + overlay.frame:SetScript("OnLeave", function() onLeave(overlay) end) + overlay.frame:SetScript("OnClick", function(_, button, down) onClick(overlay, button, down) end) + + overlay.frame.Text:Show() + overlay.frame:Show() + updateAppearance(overlay) - overlay.frame:EnableKeyboard(false) - overlay.frame:RegisterForClicks("AnyUp", "AnyDown") - overlay.frame:RegisterForDrag("LeftButton") - overlay.frame:SetScript("OnDragStart", function(_, button) onDragStart(overlay, button) end) - overlay.frame:SetScript("OnDragStop", function(_) onDragStop(overlay) end) - overlay.frame:SetScript("OnKeyDown", function(_, key) onKeyDown(overlay, key) end) - overlay.frame:SetScript("OnEnter", function() onEnter(overlay) end) - overlay.frame:SetScript("OnLeave", function() onLeave(overlay) end) - overlay.frame:SetScript("OnClick", function(_, button, down) onClick(overlay, button, down) end) + return overlay +end - overlay.frame.Text:Show() - overlay.frame:Show() - updateAppearance(overlay) +---@param overlay BarOverlay +BarEditor.activate = function(overlay) + overlay.active = true + BarEditor.microadjust(overlay, overlay.microadjust) + updateAppearance(overlay) +end + +---@param overlay BarOverlay +BarEditor.deactivate = function(overlay) + overlay.active = false + BarEditor.microadjust(overlay, 0) - return overlay - end, + updateAppearance(overlay) +end - ---@param overlay BarOverlay - activate = function(overlay) - overlay.active = true - BarEditor.microadjust(overlay, overlay.microadjust) - updateAppearance(overlay) - end, +---@param overlay BarOverlay +BarEditor.free = function (overlay) + overlay.frame:SetScript("OnDragStart", nil) + overlay.frame:SetScript("OnDragStop", nil) + overlay.frame:SetScript("OnEnter", nil) + overlay.frame:SetScript("OnLeave", nil) + overlay.frame:SetScript("OnClick", nil) + overlay.frame:EnableKeyboard(false) + overlay.frame:RegisterForDrag() + overlay.frame:RegisterForClicks() + overlay.frame:Hide() + table.insert(framePool, overlay.frame) + + -- just for good measure to make sure nothing else can mess with + -- the frame after we put it back into the pool + overlay.frame = nil +end - ---@param overlay BarOverlay - deactivate = function(overlay) - overlay.active = false - BarEditor.microadjust(overlay, 0) +---if no value is passed in for microadjust then make it a toggle +---@param overlay BarOverlay +---@param microadjust number|nil +BarEditor.microadjust = function(overlay, microadjust) + if microadjust ~= nil then + overlay.microadjust = microadjust + elseif overlay.microadjust == 0 then + overlay.microadjust = 1 + else + overlay.microadjust = 0 + end - updateAppearance(overlay) - end, - - ---@param overlay BarOverlay - free = function (overlay) - overlay.frame:SetScript("OnDragStart", nil) - overlay.frame:SetScript("OnDragStop", nil) - overlay.frame:SetScript("OnEnter", nil) - overlay.frame:SetScript("OnLeave", nil) - overlay.frame:SetScript("OnClick", nil) + if microadjust == 0 then overlay.frame:EnableKeyboard(false) - overlay.frame:RegisterForDrag() - overlay.frame:RegisterForClicks() - overlay.frame:Hide() - table.insert(framePool, overlay.frame) - - -- just for good measure to make sure nothing else can mess with - -- the frame after we put it back into the pool - overlay.frame = nil - end, - - ---if no value is passed in for microadjust then make it a toggle - ---@param overlay BarOverlay - ---@param microadjust number|nil - microadjust = function(overlay, microadjust) - if microadjust ~= nil then - overlay.microadjust = microadjust - elseif overlay.microadjust == 0 then - overlay.microadjust = 1 - else - overlay.microadjust = 0 - end - - if microadjust == 0 then - overlay.frame:EnableKeyboard(false) - else - overlay.frame:EnableKeyboard(true) - end + else + overlay.frame:EnableKeyboard(true) + end - updateAppearance(overlay) - end, -} + updateAppearance(overlay) +end addonTable.overlay.BarEditor = BarEditor From cac0ddbfb3e3dc942405fac9bd4552469fe23e62 Mon Sep 17 00:00:00 2001 From: Jon Allen Date: Sat, 4 Feb 2023 15:48:27 -0600 Subject: [PATCH 7/7] editmode controller --- Controller/EditMode.lua | 166 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 Controller/EditMode.lua diff --git a/Controller/EditMode.lua b/Controller/EditMode.lua new file mode 100644 index 0000000..af1c3e4 --- /dev/null +++ b/Controller/EditMode.lua @@ -0,0 +1,166 @@ +-- Neuron is a World of Warcraft® user interface addon. +-- Copyright (c) 2017-2021 Britt W. Yazel +-- Copyright (c) 2006-2014 Connor H. Chenoweth +-- This code is licensed under the MIT license (see LICENSE for details) + +local _, addonTable = ... + +addonTable.controller = addonTable.controller or {} + +---@type BarEditor +local BarEditor = addonTable.overlay.BarEditor +local ButtonBinder = addonTable.overlay.ButtonBinder +local ButtonEditor = addonTable.overlay.ButtonEditor +local Array = addonTable.utilities.Array + +---@class EditModeFrames +---@field binderOverlays BinderOverlay[] +---@field barOverlays BarOverlay[] +---@field buttonOverlays ButtonOverlay[] + +---@class EditModeState +---@field guiState GuiBarState|GuiButtonState|GuiOffState + +---@class GuiBarState +---@field kind "bar" +---@field bar Bar|false +---@field microadjust boolean + +---@class GuiBindState +---@field kind "bind" + +---@class GuiButtonState +---@field kind "button" +---@field button Button|false + +---@class GuiStatusButtonState +---@field kind "status" +---@field button StatusButton|false + +---@class GuiOffState +---@field kind "off" + +---@type EditModeFrames +local views = { + barOverlays = {}, + binderOverlays = {}, + buttonOverlays = {}, +} + +---@class EditMode +local EditMode = {} + +local function cleanOverlays() + for _,overlay in pairs(views.barOverlays) do + BarEditor.free(overlay) + + overlay.bar:UpdateObjectVisibility() + overlay.bar:UpdateBarStatus() + overlay.bar:UpdateObjectStatus() + end + for _,overlay in pairs(views.buttonOverlays) do + ButtonEditor.free(overlay) + end + for _,overlay in pairs(views.binderOverlays) do + ButtonBinder.free(overlay) + end + + views = { + barOverlays = {}, + binderOverlays = {}, + buttonOverlays = {}, + } +end + +---@param state GuiBarState +local function renderBarOverlays(state) + views.barOverlays = Array.map( + function(bar) + local overlay = BarEditor.allocate( + bar, + function(overlay, button, down) + if down then + return + end + + if IsShiftKeyDown() then + addonTable.Neuron.state = EditMode.enterBarMode(state, bar, true) + else + addonTable.Neuron.state = EditMode.enterBarMode(state, bar, false) + end + --TODO: this should hit the controller, not the bar + --[[ + elseif click == "RightButton" and not down then + if not addonTable.NeuronEditor then + Neuron.NeuronGUI:CreateEditor() + end + end + + if addonTable.NeuronEditor then + Neuron.NeuronGUI:RefreshEditor() + end + --]] + end, + function(_) + addonTable.Neuron.state = EditMode.exit(addonTable.Neuron.state) + end + ) + if state.bar == bar then + BarEditor.activate(overlay) + end + if state.bar == bar and state.microadjust then + BarEditor.microadjust(overlay) + end + + bar:UpdateObjectVisibility(true) + bar:UpdateBarStatus(true) + bar:UpdateObjectStatus() + + return overlay + end, + Neuron.bars + ) +end + +---@param state EditModeState +local function renderOverlays(state) + cleanOverlays() + + if state.guiState.kind == "bar" then + renderBarOverlays(state.guiState --[[ @as GuiBarState]]) + end +end + +---@param state EditModeState +---@param bar Bar|false +---@param microadjust boolean +---@return EditModeState +EditMode.enterBarMode = function (state, bar, microadjust) + local newState = CopyTable(state, true) + MergeTable(newState, { + guiState={ + kind="bar", + microadjust=microadjust, + bar=bar, + } + }) + + renderOverlays(newState) + return newState +end + +---@param state EditModeState +---@return EditModeState +EditMode.exit = function (state) + local newState = CopyTable(state, true) + MergeTable(newState, { + guiState={ + kind="off", + } + }) + + renderOverlays(newState) + return newState +end + +addonTable.controller.EditMode = EditMode