Skip to content

Commit 3d82222

Browse files
committed
Minor code cleanup
1 parent da583d9 commit 3d82222

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

config.lua

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,12 @@ function Config:Init()
135135
Settings.VarType.String
136136
);
137137
do
138-
local expandInitializer, isExpanded = self:MakeExpandableSection("Displayed Classes")
138+
local expandInitializer, isExpanded = self:MakeExpandableSection(layout, "Displayed Classes")
139139

140140
local function isVisible()
141141
return self.db.showWarbandCatalystInfoModifierKey ~= self.modifierKeyOptions.never;
142142
end
143143
expandInitializer:AddShownPredicate(isVisible);
144-
layout:AddInitializer(expandInitializer);
145144

146145
local tooltip = "If checked, the tooltip will show the Catalyst information for %s for warbound or BoE items."
147146
for classID = 1, GetNumClasses() do
@@ -171,9 +170,9 @@ function Config:Init()
171170
defaults.autoConfirmCatalyst,
172171
"Automatically confirm the popup window when you try to Catalyse an item.",
173172
{
174-
{ text = "Never", label = "Never", tooltip = "Never auto-confirm.", value = self.autoConfirmCatalystOptions.never, },
175-
{ text = "Previous Season", label = "Previous Season", tooltip = "Auto-confirm for items from previous seasons that are free.", value = self.autoConfirmCatalystOptions.previousSeason, },
176-
{ text = "Always", label = "Always", tooltip = "Always auto-confirm, even if there are limited charges.", value = self.autoConfirmCatalystOptions.always, },
173+
{ text = "Never", tooltip = "Never auto-confirm.", value = self.autoConfirmCatalystOptions.never, },
174+
{ text = "Previous Season", tooltip = "Auto-confirm for items from previous seasons that are free.", value = self.autoConfirmCatalystOptions.previousSeason, },
175+
{ text = "Always", tooltip = "Always auto-confirm, even if there are limited charges.", value = self.autoConfirmCatalystOptions.always, },
177176
},
178177
Settings.VarType.String
179178
)
@@ -238,7 +237,7 @@ function Config:MakeCheckbox(category, label, settingKey, defaultValue, tooltip,
238237
return Settings.CreateCheckbox(category, setting, tooltip);
239238
end
240239

241-
--- @alias TUMDropDownOptions { text: string, label: string, tooltip: string, value: any }[]
240+
--- @alias TUMDropDownOptions { text: string, label: string?, tooltip: string?, value: any }[]
242241

243242
--- @param options TUMDropDownOptions|fun(): TUMDropDownOptions
244243
--- @param varType "string"|"number"|"boolean" # one of Settings.VarType
@@ -250,11 +249,19 @@ function Config:MakeDropdown(category, label, settingKey, defaultValue, tooltip,
250249
if type(options) == "table" then
251250
GetOptions = function() return options; end
252251
end
252+
local function wrapper()
253+
local opts = GetOptions();
254+
for _, option in pairs(opts) do
255+
option.label = option.label or option.text;
256+
end
257+
258+
return opts;
259+
end
253260

254261
local setting = Settings.RegisterAddOnSetting(category, variable, settingKey, self.db, varType, label, defaultValue);
255262
setting:SetValueChangedCallback(function(setting, value) self:OnSettingChange(setting:GetVariable(), value) end);
256263

257-
return Settings.CreateDropdown(category, setting, GetOptions, tooltip);
264+
return Settings.CreateDropdown(category, setting, wrapper, tooltip);
258265
end
259266

260267
--- @return SettingsListElementInitializer
@@ -271,10 +278,11 @@ function Config:MakeButton(category, layout, label, onClick, tooltip)
271278
return initializer;
272279
end
273280

281+
--- @param layout SettingsVerticalLayoutMixin
274282
--- @param sectionName string
275283
--- @return SettingsExpandableSectionInitializer initializer
276284
--- @return fun(): boolean isExpanded
277-
function Config:MakeExpandableSection(sectionName)
285+
function Config:MakeExpandableSection(layout, sectionName)
278286
local expandInitializer = CreateSettingsExpandableSectionInitializer(sectionName);
279287
function expandInitializer:GetExtent()
280288
return 25;
@@ -298,6 +306,7 @@ function Config:MakeExpandableSection(sectionName)
298306
return initializer:GetExtent();
299307
end
300308
end);
309+
layout:AddInitializer(expandInitializer);
301310

302311
return expandInitializer, function() return expandInitializer.data.expanded; end;
303312
end
@@ -307,16 +316,10 @@ function Config:OnSettingChange(setting, value)
307316
end
308317

309318
-------------------
310-
--- @class TransmogUpgradeMaster_SettingsButtonControlMixin : SettingsControlMixin
319+
--- @class TransmogUpgradeMaster_SettingsButtonControlMixin : SettingsListElementTemplate, SettingsControlMixin
311320
TransmogUpgradeMaster_SettingsButtonControlMixin = CreateFromMixins(SettingsControlMixin);
312321
do
313322
local mixin = TransmogUpgradeMaster_SettingsButtonControlMixin;
314-
function mixin:OnLoad()
315-
SettingsControlMixin.OnLoad(self);
316-
self.Button = CreateFrame("Button", nil, self, "UIPanelButtonTemplate");
317-
self.Button:SetSize(200, 26);
318-
self.Button:SetPoint("LEFT", self, "CENTER", -80, 0);
319-
end
320323

321324
function mixin:Init(initializer)
322325
SettingsControlMixin.Init(self, initializer);

settingsTemplates.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,13 @@ https://raw.githubusercontent.com/Meorawr/wow-ui-schema/main/UI.xsd">
55
<Scripts>
66
<OnLoad method="OnLoad"/>
77
</Scripts>
8+
<Frames>
9+
<Button parentKey="Button" inherits="UIPanelButtonTemplate">
10+
<Size x="200" y="26"/>
11+
<Anchors>
12+
<Anchor point="LEFT" relativeKey="$parent" relativePoint="CENTER" x="-80" y="0"/>
13+
</Anchors>
14+
</Button>
15+
</Frames>
816
</Frame>
917
</Ui>

types.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@
4444
--- @class SyndicatorCharacterDetails
4545
--- @field class number # classID
4646
--- @field className ClassFile
47+
48+
--- @class TransmogUpgradeMaster_SettingsButtonControlMixin : SettingsListElementTemplate, SettingsControlMixin
49+
--- @field Button UIPanelButtonTemplate
50+

0 commit comments

Comments
 (0)