-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.lua
382 lines (358 loc) · 13.8 KB
/
settings.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
local addonName, LithStable = ...
-- Default settings
local defaults = {
profile = {
settings = {
dismountOnly = false,
reoccurring = false,
aquaticBackup = false
}
},
char = {
useSharedSettings = true,
settings = {
dismountOnly = false,
reoccurring = false,
aquaticBackup = false
},
state = {
lastFlyingMount = nil,
lastGroundMount = nil,
lastAquaticMount = nil
},
favorites = {
mounts = {}
}
}
}
local function CreateSettingsToggles(self, parent, order)
local settingsGroup = {
type = "group",
name = "",
inline = true,
order = order,
args = {
sharedSettings = {
type = "toggle",
name = "Shared settings",
desc = "Use settings shared between all characters",
width = "normal",
order = 1,
get = function() return self.db.char.useSharedSettings end,
set = function(_, value)
-- If switching to shared settings, copy current shared settings
if value then
self.db.char.useSharedSettings = true
-- Optionally sync with shared settings immediately
-- self.db.char.settings = CopyTable(self.db.profile.settings)
else
self.db.char.useSharedSettings = false
-- Optionally initialize character settings with current settings
if value == false then
self.db.char.settings = CopyTable(self.db.profile.settings)
end
end
end,
},
characterSettings = {
type = "toggle",
name = "Character specific",
desc = "Use settings specific to this character",
width = "normal",
order = 2,
get = function() return not self.db.char.useSharedSettings end,
set = function(_, value)
self.db.char.useSharedSettings = not value
-- Handle initialization of character settings when switching
if value then
self.db.char.settings = CopyTable(self.db.profile.settings)
end
end,
},
}
}
return settingsGroup
end
function LithStable:InitializeSettings()
-- Create fresh settings if they don't exist
if not LithStableDB then
LithStableDB = {
["profileKeys"] = {},
["profiles"] = {
["Default"] = defaults.profile
},
["char"] = {}
}
end
-- Initialize database with defaults
self.db = LibStub("AceDB-3.0"):New("LithStableDB", defaults, true)
-- Make sure char data exists
local charKey = UnitName("player") .. " - " .. GetRealmName()
LithStableDB.profileKeys[charKey] = "Default"
if not LithStableDB.char[charKey] then
LithStableDB.char[charKey] = CopyTable(defaults.char)
end
-- Register options table
local options = {
name = function()
return "|cFF8000FFLith|r|cffffffffStable|r"
end,
handler = LithStable,
type = "group",
args = {
title = {
order = 0,
type = "description",
name = function()
-- Add padding to center text vertically with logo
return "|TInterface\\AddOns\\LithStable\\images\\lith-logo:50:50:0:0|t"
end,
fontSize = "large",
width = "full",
},
generalHeader = {
type = "header",
name = "General Settings",
order = 1,
},
generalDescription = {
type = "description",
name = "Configure how |cFF8000FFLith|rStable behaves when summoning mounts.",
order = 2,
fontSize = "medium",
},
settingsType = CreateSettingsToggles(self, options, 3), -- (self, parent, order)
spacer = {
type = "description",
name = " ", -- Empty spacer for layout alignment
width = "half",
order = 3.5,
},
mountingHeader = {
type = "header",
name = "Mounting Options",
order = 5,
},
dismountDescription = {
type = "description",
name = "If checked, using the mount command while mounted will only dismount without summoning a new mount.",
order = 6,
fontSize = "medium",
},
dismountOnly = {
type = "toggle",
name = "If mounted just dismount",
desc = "If checked, using the mount command while mounted will only dismount without summoning a new mount.",
width = "full",
order = 6.1,
get = function()
return self.db.char.useSharedSettings
and self.db.profile.settings.dismountOnly
or self.db.char.settings.dismountOnly
end,
set = function(_, value)
if self.db.char.useSharedSettings then
self.db.profile.settings.dismountOnly = value
else
self.db.char.settings.dismountOnly = value
end
end,
},
--[[ --Removed because not all flying mounts can be summoned in water
aquaticDescription = {
type = "description",
name = "If checked, using the mount command while in water will fall back to summon a favorite flying or ground mount if no aquatic mount is available.",
order = 6.2,
fontSize = "medium",
},
aquaticBackup = {
type = "toggle",
name = "Aquatic mount fallback",
desc = "If checked, using the mount command while in water will fall back to summon a favorite flying or ground mount if no aquatic mount is available.",
width = "full",
order = 6.3,
get = function()
return self.db.char.useSharedSettings
and self.db.profile.settings.aquaticBackup
or self.db.char.settings.aquaticBackup
end,
set = function(_, value)
if self.db.char.useSharedSettings then
self.db.profile.settings.aquaticBackup = value
else
self.db.char.settings.aquaticBackup = value
end
self:UpdateAquaticMountBackup()
end,
},]]
spacer1 = {
type = "description",
name = " ", -- Empty spacer for layout alignment
width = "half",
order = 7.5,
},
reoccurringDescription = {
type = "description",
name = "Using the mount command saves the last used mount for both grounded and flying types. If this option is checked, the last summoned mount check is ignored, allowing the same mount to be summoned again at random, even if no other mount has been summoned in between.",
order = 8,
fontSize = "medium",
},
reoccurringAllowed = {
type = "toggle",
name = "Disabled",
desc = "Ignoring the check for last used mount.",
width = "full",
order = 9,
get = function()
return self.db.char.useSharedSettings
and self.db.profile.settings.reoccurring
or self.db.char.settings.reoccurring
end,
set = function(_, value)
if self.db.char.useSharedSettings then
self.db.profile.settings.reoccurring = value
else
self.db.char.settings.reoccurring = value
end
end,
},
reoccurringNOTE = {
type = "description",
name = "|cFFFFFF00NOTE:|r If the mount type you are trying to summon only have one favorite, last mount used in that type is ignored regardless of whether the above option is checked or not",
order = 10,
fontSize = "medium",
},
spacer2 = {
type = "description",
name = " ", -- Empty spacer for layout alignment
width = "half",
order = 10.5,
},
slashCommandsHeader = {
type = "header",
name = "Available Slash Commands",
order = 11,
},
command1 = {
type = "description",
name = "|cFFFFFF00/ls debug|r - Prints a list of your Favorite mounts, and your last used Flying and Ground mount",
order = 12,
fontSize = "medium",
},
command2 = {
type = "description",
name = "|cFFFFFF00/ls last|r - Prints a list of your last used Flying and Ground mount",
order = 13,
fontSize = "medium",
},
command3 = {
type = "description",
name = "|cFFFFFF00/ls config|r - Opens the settings window",
order = 14,
fontSize = "medium",
},
command4 = {
type = "description",
name = "|cFFFFFF00/ls flying|r - Summons a Flying mount",
order = 15,
fontSize = "medium",
},
command5 = {
type = "description",
name = "|cFFFFFF00/ls ground|r - Summons a Ground mount",
order = 16,
fontSize = "medium",
},
command6 = {
type = "description",
name = "|cFFFFFF00/ls|r - Summons a mount by auto-selecting",
order = 17,
fontSize = "medium",
},
command7 = {
type = "description",
name = "|cFFFFFF00/ls help|r - Prints this list",
order = 18,
fontSize = "medium",
},
}
}
-- Register in the Interface Options
local AceConfig = LibStub("AceConfig-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
AceConfig:RegisterOptionsTable(addonName, options)
-- Create the config panel with consistent layout
local dialogFrame = AceConfigDialog:AddToBlizOptions(addonName, "|cFF8000FFLith|rStable")
-- Store reference to the panel
self.optionsFrame = dialogFrame
-- Function to open config
function self:OpenConfig()
LibStub("AceConfigDialog-3.0"):Open(addonName)
--[[if Settings and Settings.OpenToCategory then
Settings.OpenToCategory(self.optionsFrame)
else
-- Fallback for Classic/Cataclysm
ShowUIPanel(InterfaceOptionsFrame)
InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
end]]
end
-- Initialize character favorites if needed
if not self.db.char.favorites.mounts then
self.db.char.favorites.mounts = {}
self:CopyCurrentFavoritesToChar()
end
print("|cFF8000FFLith|r|cffffffffStable|r: |cFFBCCF02loaded")
end
-- Helper function to copy current favorites to character-specific list
function LithStable:CopyCurrentFavoritesToChar()
local favorites = {}
for i = 1, C_MountJournal.GetNumMounts() do
local _, _, _, _, _, _, isFavorite, _, _, _, _, mountID = C_MountJournal.GetMountInfoByID(i)
if mountID and isFavorite then
favorites[mountID] = true
end
end
self.db.char.favorites.mounts = favorites
end
function LithStable:GetCharacterFavorites()
return self.db.char.favorites.mounts or {}
end
-- Function to check if a mount is a favorite
function LithStable:IsFavorite(mountID)
if not mountID then return false end
if self:IsCharacterFavoritesEnabled() then
local favorites = self:GetCharacterFavorites()
return favorites[mountID]
else
local _, _, _, _, _, _, isFavorite = C_MountJournal.GetMountInfoByID(mountID)
return isFavorite
end
end
-- Function to set favorite status
function LithStable:SetFavorite(mountID, isFavorite)
if not mountID then return end
-- Update our character-specific tracking
if not self.db.char.favorites.mounts then
self.db.char.favorites.mounts = {}
end
self.db.char.favorites.mounts[mountID] = isFavorite or nil
-- Update the UI system
local displayIndex
for i = 1, C_MountJournal.GetNumDisplayedMounts() do
local displayedMountID = select(12, C_MountJournal.GetDisplayedMountInfo(i))
if displayedMountID == mountID then
displayIndex = i
break
end
end
if displayIndex then
C_MountJournal.SetIsFavorite(displayIndex, isFavorite)
MountJournal_UpdateMountList()
end
end
function LithStable:ShouldDismountOnly()
if not self.db then return false end
return self.db.char.useSharedSettings
and self.db.profile.settings.dismountOnly
or self.db.char.settings.dismountOnly
end