Go to Page... |
Thread Tools | Display Modes |
09-29-18, 06:48 AM | #1 |
[AceConfig] Update options(?) based on selected unit
Hi all ,
I am trying to make an interface options with AceConfig-3.0 and here's what I got so far. Lua Code:
The question is, is it possible to re-use those General, Health and Power tabs, but only change the db entry based on the selected unit? Or should I re-construct all those tabs whenever the unit changes? Last edited by Lyak : 09-29-18 at 07:15 AM. |
|
09-29-18, 09:44 AM | #2 | |
Code:
local ACR = LibStub("AceConfigRegistry-3.0") local ACD = LibStub("AceConfigDialog-3.0") local LSM = LibStub("LibSharedMedia-3.0") local anchorList = { TOPLEFT = "TOPLEFT", TOPRIGHT = "TOPRIGHT", BOTTOMRIGHT = "BOTTOMRIGHT", BOTTOMLEFT = "BOTTOMLEFT", LEFT = "LEFT", TOP = "TOP", RIGHT = "RIGHT", BOTTOM = "BOTTOM", CENTER = "CENTER" } local unitFrame = { Player = PlayerFrame, Pet = PetFrame, Target = TargetFrame, TargetTarget = TargetFrameToT, Focus = FocusFrame } local unitList = { } for unit in pairs(unitFrame) do unitList[unit] = unit end local db = { } for unit in pairs(unitFrame) do db[unit] = { } end local selectedUnit = "Player" local function GetOption(info) return db[selectedUnit][info[#info]] end local function SetOption(info, value) db[selectedUnit][info[#info]] = value end local function UpdatePosition(unit) local frame = unitFrame[unit] frame:ClearAllPoints() local settings = db[unit] frame:SetPoint(settings.point or "CENTER", settings.relativeTo or UIParent, settings.relativePoint or settings.point or "CENTER", tonumber(settings.offsetX) or 0, tonumber(settings.offsetY) or 0) end local function UpdateStatusBar(unit, barKey) local settings = db[unit] local statusBar = unitFrame[unit][barKey] statusBar:SetHeight(tonumber(settings[barKey .. "Height"]) or 12) statusBar:SetStatusBarTexture(LSM:Fetch("statusbar", settings[barKey .. "Texture"])) end local function SetStatusBarOption(info, value) SetOption(info, value) UpdateStatusBar(selectedUnit, info[#info - 1]) end local testOption = { type = "group", childGroups = "tab", name = "TestOption", get = GetOption, args = { selected = { order = 1, type = "select", name = "Selected Unit", values = unitList, get = function(info) return selectedUnit end, set = function(info, value) selectedUnit = value end, }, general = { order = 2, type = "group", name = "General", set = function(info, value) SetOption(info, value) UpdatePosition(selectedUnit) end, args = { point = { order = 1, type = "select", name = "Point", values = anchorList, }, relativeTo = { order = 2, type = "input", name = "Relative To", }, relativePoint = { order = 3, type = "select", name = "Relative Point", values = anchorList, }, offsetX = { order = 4, type = "input", name = "X-Offset", }, offsetY = { order = 5, type = "input", name = "Y-Offset", }, }, }, healthbar = { order = 3, type = "group", name = "Health", set = SetStatusBarOption, args = { healthbarHeight = { order = 1, type = "range", name = "Height", min = 4, max = 32, step = 1, }, healthbarTexture = { order = 2, type = "select", name = "Texture", dialogControl = "LSM30_Statusbar", values = AceGUIWidgetLSMlists.statusbar, }, }, }, manabar = { order = 4, type = "group", name = "Power", set = SetStatusBarOption, args = { manabarHeight = { order = 1, type = "range", name = "Height", min = 4, max = 32, step = 1, }, manabarTexture = { order = 2, type = "select", name = "Texture", dialogControl = "LSM30_Statusbar", values = AceGUIWidgetLSMlists.statusbar, }, }, }, }, } ACR:RegisterOptionsTable("TestOption", testOption) ACD:AddToBlizOptions("TestOption", nil, nil) |
||
09-29-18, 03:37 PM | #3 | |
I really, really and really appreciate your time! So, is the first getter function being the key point which gets called every single time when the selected unit changes? If so, what would be the best way to deal with my db structure? Lua Code:
Like you said it should be the matter of how simply the db is set-up, but I would like to maintain this structure, if possible. Would the best chance be putting IF statements to see which 'point' the option is referring to? Last edited by Lyak : 09-29-18 at 04:27 PM. |
||
09-29-18, 04:33 PM | #4 |
No. The 'get' and 'set' fields are inherited so using a simple save structure allows you to use fewer generic get/set functions. If you insist on a needlessly complex save table then you will have to make more get/set functions for each unique case.
|
|
09-29-18, 05:46 PM | #5 | |
I mean I had those inherited getter and setter for those child options, but it didn't really update the values... Let me have a look first! SO EXCITED EDIT #1 Yeap, you are totally right, Vrul. I was an idiot. It was a logical error and here's what happened. My actual code of getting those general options were like this. Lua Code:
The _selectedUnit was never getting updated to newly selected unit and so, the db was always referrring to player's one even if the selected unit changes. Which should actually be something like Lua Code:
Now it's working perfectly well! Thank you so much for enlightening me Last edited by Lyak : 09-29-18 at 06:04 PM. |
||
WoWInterface » Developer Discussions » Lua/XML Help » [AceConfig] Update options(?) based on selected unit |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|