forked from raptormama/GuildTithe-Reincarnated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuildTitheFrameScripts.lua
343 lines (298 loc) · 11 KB
/
GuildTitheFrameScripts.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
--[[
------------------------------------------------------------------------
Project: GuildTithe
File: Frame scripts rev. 118
Date: 2014-10-17T00:50:40Z
Purpose: Miscellaneous Frame Scripts.
Credits: Code written by Vandesdelca32
Copyright (C) 2011 Vandesdelca32
This version made in 2023-later by Miragosa.
Released to public domain.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------
]]
local E, L = unpack(select(2, ...))
-- Skin the frames to look like ElvUI's frames, if it's available
function E:SkinFrames()
if not ElvUI or not GuildTithe_SavedDB.SkinElvUI then return end
local ElvEngine, ElvLocale, ElvProfile, ElvGlobal = unpack(ElvUI)
local S = ElvEngine:GetModule("Skins")
local fList = {
"GT_MiniTitheFrame",
"GT_OptionsFrame",
--"GT_OptionsFrame_Title",
"GT_OptionsFrame_Seperator",
}
local chbList = {
"GT_OptionsFrame_QuestOptions_Check",
"GT_OptionsFrame_LootOptions_Check",
"GT_OptionsFrame_MerchantOptions_Check",
"GT_OptionsFrame_MailOptions_Check",
"GT_OptionsFrame_TradeOptions_Check",
"GT_OptionsFrame_Seperator_ExtraOption1",
"GT_OptionsFrame_Seperator_ExtraOption2",
"GT_OptionsFrame_Seperator_ExtraOption3",
"GT_OptionsFrame_Seperator_ExtraOption4",
}
local sbList = {
"GT_OptionsFrame_QuestOptions_Slider",
"GT_OptionsFrame_LootOptions_Slider",
"GT_OptionsFrame_MerchantOptions_Slider",
"GT_OptionsFrame_MailOptions_Slider",
"GT_OptionsFrame_TradeOptions_Slider",
}
local ebList = {
"GT_OptionsFrame_QuestOptions_Text",
"GT_OptionsFrame_LootOptions_Text",
"GT_OptionsFrame_MerchantOptions_Text",
"GT_OptionsFrame_MailOptions_Text",
"GT_OptionsFrame_TradeOptions_Text",
}
-- Here's where the magic happens
for _, v in pairs(fList) do
_G[v]:SetTemplate("Transparent")
end
-- Tweak the frames
GT_OptionsFrame_Title:StripTextures()
GT_OptionsFrame:SetHeight(292)
GT_OptionsFrame:SetWidth(420)
GT_MiniTitheFrame.CurrentTithe:Point("BOTTOM", GT_MiniTitheFrame, "BOTTOM", 0, -1)
-- Close button
S:HandleCloseButton(GT_OptionsFrame_CloseButton, GT_OptionsFrame)
S:HandleCloseButton(GT_MiniTitheFrame_Close, GT_MiniTitheFrame)
-- Check Buttons
for _, v in pairs(chbList) do
S:HandleCheckBox(_G[v])
_G[v]:SetSize(24, 24)
end
-- Sliders. These need special handling, they need the thumbs resized or else it will make them HUUUUGE
for _, v in pairs(sbList) do
S:HandleSliderFrame(_G[v])
_G[v]:SetHeight(12)
_G[v]:GetThumbTexture():SetSize(10, 14)
_G[v .. "Low"]:Point("TOPLEFT", _G[v], "BOTTOMLEFT", 0, -2)
_G[v .. "High"]:Point("TOPRIGHT", _G[v], "BOTTOMRIGHT", 0, -2)
end
-- EditBoxes:
for _, v in pairs(ebList) do
S:HandleEditBox(_G[v])
_G[v]:SetHeight(20)
end
-- Mark the addon as skinned
E.ElvSkinned = true
end
-- The script called by the template, used to keep the edit box in check
function E.FrameScript_EditBoxOnEnterPressed(self)
-- Get the text
local num = self:GetText()
-- Check to see if the user put a % sign in, because the field implies it is there.
if strfind(num, "%%") then return end
num = tonumber(num)
if not num then return end
if num < 1 then
num = 1
self:SetText("1")
elseif num > 100 then
num = 100
self:SetText("100")
end
self:GetParent().Slider:SetValue(num)
self:ClearFocus()
end
function E.FrameScript_UpdateOptionRow(self)
if not self:GetChecked() then
self:GetParent().Text:Disable();
self:GetParent().Slider:Disable();
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF)
else
self:GetParent().Slider:Enable();
self:GetParent().Text:Enable();
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
end
end
function E.FrameScript_OptionRowChangeState(self, state)
if not E.ElvSkinned then
if state == "DISABLE" then
self:GetThumbTexture():SetVertexColor(0.5, 0.5, 0.5)
_G[self:GetName() .. "Low"]:SetFontObject(GameFontDisableSmall)
_G[self:GetName() .. "High"]:SetFontObject(GameFontDisableSmall)
elseif state == "ENABLE" then
self:GetThumbTexture():SetVertexColor(1, 1, 1)
_G[self:GetName() .. "Low"]:SetFontObject(GameFontHighlightSmall)
_G[self:GetName() .. "High"]:SetFontObject(GameFontHighlightSmall)
else
return
end
else
-- Need a different method for this if we're skinning it through ElvUI
if state == "DISABLE" then
self:GetThumbTexture():Hide()
_G[self:GetName() .. "Low"]:SetFontObject(GameFontDisableSmall)
_G[self:GetName() .. "High"]:SetFontObject(GameFontDisableSmall)
elseif state == "ENABLE" then
self:GetThumbTexture():Show()
_G[self:GetName() .. "Low"]:SetFontObject(GameFontHighlightSmall)
_G[self:GetName() .. "High"]:SetFontObject(GameFontHighlightSmall)
end
end
end
function E.FrameScript_MiniTitheFrameOnLoad(self)
self:RegisterForDrag("LeftButton")
self.Label1:SetText(L.MiniFrameCurrentTitheText)
end
function E.FrameScript_MiniTitheFrameOnClick(self, button)
E:PrintDebug("MiniFrame OnClick()")
if (C_AddOns.IsAddOnLoaded("Blizzard_GuildBankUI") and GuildBankFrame:IsVisible()) or
(C_AddOns.IsAddOnLoaded("Arkinventory") and ARKINV_Frame4TitleArkBorder:IsVisible()) then
E:DepositTithe(1)
elseif SendMailFrame:IsVisible() then
E:DepositTithe(1,1)
else
if GuildTithe_SavedDB.Spammy then
E:PrintMessage(L.ChatNoValidDeposits, true)
end
end
end
-- Load the localization-specific strings
function E.LoadOptionsFrame(self)
-- Set the strings
self.Title.Text:SetText(L.OptionsTitle)
self.Info.text:SetText(L.OptionsExtraText)
self.Version.text:SetText(format(L.OptionsVersionText, E:GetVerString()))
--Set the row's text here.
self.QuestOptions.Check.text:SetText(L.OptionsQuestText)
self.LootOptions.Check.text:SetText(L.OptionsLootText)
self.MerchantOptions.Check.text:SetText(L.OptionsMerchantText)
self.MailOptions.Check.text:SetText(L.OptionsMailText)
self.TradeOptions.Check.text:SetText(L.OptionsTradeText)
-- Extra Options
self.Extra.AutoDeposit.text:SetText(L.OptionsAutoDeposit)
self.Extra.AutoDeposit.text:SetFontObject(GameFontHighlight)
self.Extra.Spammy.text:SetText(L.OptionsSpammy)
self.Extra.Spammy.text:SetFontObject(GameFontHighlight)
self.Extra.Debug.text:SetText(L.OptionsDebug)
if ElvUI then
self.Extra.SkinElv:Show()
self.Extra.SkinElv.text:SetText(L.OptionsElvSkin)
self.Extra.SkinElv.text:SetFontObject(GameFontHighlight)
else
self.Extra.SkinElv:Hide()
end
end
-- Show the user thier options when they open the form.
function E.UpdateOptions(self)
-- load options
-- Quests?
if (GuildTithe_SavedDB.CollectSource.Quest
and GuildTithe_SavedDB.CollectSource.Quest ~= -1) then
self.QuestOptions.Check:SetChecked(1)
self.QuestOptions.Slider:SetValue(GuildTithe_SavedDB.CollectSource.Quest)
else
self.QuestOptions.Check:SetChecked(false)
self.QuestOptions.Slider:SetValue(20)
end
-- Loot?
if (GuildTithe_SavedDB.CollectSource.Loot
and GuildTithe_SavedDB.CollectSource.Loot ~= -1) then
self.LootOptions.Check:SetChecked(true)
self.LootOptions.Slider:SetValue(GuildTithe_SavedDB.CollectSource.Loot)
else
self.LootOptions.Check:SetChecked(false)
self.LootOptions.Slider:SetValue(20)
end
-- Merchant?
if (GuildTithe_SavedDB.CollectSource.Merchant
and GuildTithe_SavedDB.CollectSource.Merchant ~= -1) then
self.MerchantOptions.Check:SetChecked(true)
self.MerchantOptions.Slider:SetValue(GuildTithe_SavedDB.CollectSource.Merchant)
else
self.MerchantOptions.Check:SetChecked(false)
self.MerchantOptions.Slider:SetValue(20)
end
-- Mail?
if (GuildTithe_SavedDB.CollectSource.Mail
and GuildTithe_SavedDB.CollectSource.Mail ~= -1) then
self.MailOptions.Check:SetChecked(true)
self.MailOptions.Slider:SetValue(GuildTithe_SavedDB.CollectSource.Mail)
else
self.MailOptions.Check:SetChecked(false)
self.MailOptions.Slider:SetValue(20)
end
-- Trade?
if (GuildTithe_SavedDB.CollectSource.Trade
and GuildTithe_SavedDB.CollectSource.Trade ~= -1) then
self.TradeOptions.Check:SetChecked(true)
self.TradeOptions.Slider:SetValue(GuildTithe_SavedDB.CollectSource.Trade)
else
self.TradeOptions.Check:SetChecked(false)
self.TradeOptions.Slider:SetValue(20)
end
-- Misc options
self.Extra.AutoDeposit:SetChecked(GuildTithe_SavedDB.AutoDeposit)
self.Extra.Spammy:SetChecked(GuildTithe_SavedDB.Spammy)
self.Extra.Debug:SetChecked(E._DebugMode)
self.Extra.SkinElv:SetChecked(GuildTithe_SavedDB.SkinElvUI)
-- Total Tithe
self.TotalTithe.text:SetFormattedText(L.OptionsTotalTitheText, C_CurrencyInfo.GetCoinTextureString(GuildTithe_SavedDB.TotalTithe))
-- Force the frame to properly update state.
E.FrameScript_UpdateOptionRow(self.QuestOptions.Check)
E.FrameScript_UpdateOptionRow(self.LootOptions.Check)
E.FrameScript_UpdateOptionRow(self.MerchantOptions.Check)
E.FrameScript_UpdateOptionRow(self.MailOptions.Check)
E.FrameScript_UpdateOptionRow(self.TradeOptions.Check)
PlaySound(SOUNDKIT.IG_MAINMENU_OPEN)
end
-- Save the config when the user closes the form.
function E.SaveOptions(self)
local GuildTithe_SavedDB = GuildTithe_SavedDB
-- Inc tedium, we're setting the option to the value, or -1 if the check isn't set.
-- Quest
if self.QuestOptions.Check:GetChecked() then
GuildTithe_SavedDB["CollectSource"]["Quest"] = self.QuestOptions.Slider:GetValue()
else
GuildTithe_SavedDB["CollectSource"]["Quest"] = -1
end
-- Loot
if self.LootOptions.Check:GetChecked() then
GuildTithe_SavedDB["CollectSource"]["Loot"] = self.LootOptions.Slider:GetValue()
else
GuildTithe_SavedDB["CollectSource"]["Loot"] = -1
end
-- Mail
if self.MailOptions.Check:GetChecked() then
GuildTithe_SavedDB["CollectSource"]["Mail"] = self.MailOptions.Slider:GetValue()
else
GuildTithe_SavedDB["CollectSource"]["Mail"] = -1
end
-- Merchant
if self.MerchantOptions.Check:GetChecked() then
GuildTithe_SavedDB["CollectSource"]["Merchant"] = self.MerchantOptions.Slider:GetValue()
else
GuildTithe_SavedDB["CollectSource"]["Merchant"] = -1
end
-- Trade
if self.TradeOptions.Check:GetChecked() then
GuildTithe_SavedDB["CollectSource"]["Trade"] = self.TradeOptions.Slider:GetValue()
else
GuildTithe_SavedDB["CollectSource"]["Trade"] = -1
end
GuildTithe_SavedDB["AutoDeposit"] = self.Extra.AutoDeposit:GetChecked()
GuildTithe_SavedDB["Spammy"] = self.Extra.Spammy:GetChecked()
GuildTithe_SavedDB["SkinElvUI"] = self.Extra.SkinElv:GetChecked()
-- DebugMode is never saved, but update the user's choice:
if self.Extra.Debug:GetChecked() then
E._DebugMode = true
else
E._DebugMode = false
end
PlaySound(SOUNDKIT.IG_MAINMENU_CLOSE)
end