Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Controller goodness #504

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions Controller/EditMode.lua
Original file line number Diff line number Diff line change
@@ -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
64 changes: 29 additions & 35 deletions GUI/BarEditTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)

-------------------------------
Expand Down Expand Up @@ -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)

-------------------------------
Expand Down Expand Up @@ -106,48 +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)
local registeredGUIData = Neuron:RegisterGUI()
---@param bar Bar
---@param tabFrame Frame
---@param value "general"|"states"|"visibility"
function NeuronGUI:SelectInnerBarTab(bar, tabFrame, value)
tabFrame:ReleaseChildren()
if value == "general" then
NeuronGUI:GeneralConfigPanel(tabFrame, registeredGUIData)
NeuronGUI:GeneralConfigPanel(bar, tabFrame)
currentTab = "general"
elseif value == "states" then
NeuronGUI:BarStatesPanel(tabFrame)
NeuronGUI:BarStatesPanel(bar, tabFrame)
currentTab = "states"
elseif value == "visibility" then
NeuronGUI:BarVisibilityPanel(tabFrame)
NeuronGUI:BarVisibilityPanel(bar, tabFrame)
currentTab = "visibility"
end
end
23 changes: 13 additions & 10 deletions GUI/BarEditTab_BarStatesPanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -75,26 +77,27 @@ 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

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
13 changes: 8 additions & 5 deletions GUI/BarEditTab_BarVisibilityPanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -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
Loading