-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleGold.lua
More file actions
executable file
·414 lines (311 loc) · 10.9 KB
/
SimpleGold.lua
File metadata and controls
executable file
·414 lines (311 loc) · 10.9 KB
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
-- Globals:
-- ========
SimpleGold_variablesLoaded = false;
SimpleGold_firstRun = true;
SimpleGold_UpdateInterval = 5; -- shouldn't need to update often.
SimpleGold_UpdateTimer = 0;
-- Globals
-- Locals:
-- =======
local myPlayerRealm=GetRealmName();
local myPlayerName=UnitName("player");
local myPlayerID=myPlayerName.."**"..myPlayerRealm;
local myPlayerClassText, myPlayerClassType = UnitClass("player");
local lastWindowState = false;
-- preset color options:
local colorPresetList ={
{1,1,1,0},
{0,0,0,1},
{0,0,0,.6},
{.5,.5,.5,.6},
{.5,0,0,.6},
{.5,0,0,1},
{1,0,0,1},
{0,.5,0,.6},
{0,.5,0,1},
{0,1,0,1},
{0,0,.5,.6},
{.5,0,.5,1},
{0,0,1,1},
{.5,.5,0,.6},
{.5,.5,0,1},
{1,1,0,1},
{.5,0,.5,.6},
{.5,0,.5,1},
{1,0,1,1},
{0,.5,.5,.6},
{0,.5,.5,1},
{0,1,1,1}
}
-- save last version to detect if client has changed
local prevVersion=1;
if (nil ~= SimpleGoldSavedVars) then
if (nil ~= SimpleGoldSavedVars["clientBuild"]) then
prevVersion=SimpleGoldSavedVars["clientBuild"];
end
end
-- My local functions:
-- ====================
function DrawBG()
-------- ---------------
FixVars();
local tColor=SimpleGoldSavedVars["color"];
SimpleGold_BackgroundTexture:SetVertexColor(tColor[1],tColor[2],tColor[3],tColor[4]);
end
function UpdateGlobalGold()
-------- ---------------
if (SimpleGoldGlobals == nil) then
SimpleGoldGlobals = {};
end
if (SimpleGoldGlobals[myPlayerRealm]==nil) then
SimpleGoldGlobals[myPlayerRealm]={};
end
SimpleGoldGlobals[myPlayerRealm][myPlayerName]=GetMoney();
end
function FixVars()
-------- ---------------
local version, build, date, tocversion = GetBuildInfo();
-- initialize our saved variables if needed
if (SimpleGoldSavedVars == nil) then
SimpleGoldSavedVars={
xPos=0,
yPos=0,
lastPreset=1,
color={0,0,0,1},
borderStyle=1,
viz=true,
locked=false,
clientBuild=tocversion
};
end
if SimpleGoldSavedVars["viz"] == nil then
SimpleGoldSavedVars["viz"]=true;
end
if SimpleGoldSavedVars["locked"] == nil then
SimpleGoldSavedVars["locked"]=false;
end
if SimpleGoldSavedVars["clientBuild"] == nil then
SimpleGoldSavedVars["clientBuild"]=tocversion;
end
end
function SimpleGold_OnLoad(self)
-- Register the slash command
-- --------------------------
SLASH_SimpleGold1 = "/simplegold";
SlashCmdList["SimpleGold"] = SimpleGold_CommandLine;
-- Register the event handlers:
-- =============================
self:RegisterEvent("VARIABLES_LOADED");
self:RegisterEvent("PLAYER_MONEY");
self:RegisterEvent("PLAYER_ENTERING_WORLD");
-- new event: CURRENCY_DISPLAY_UPDATE ?
if (not myPlayerName) then
myPlayerName = UnitName("player");
myPlayerID=myPlayerName.."**"..myPlayerRealm;
end
DEFAULT_CHAT_FRAME:AddMessage(SGOLDTEXT.WELCOME, 0.5, 1.0, 0.5, 1);
UpdateGlobalGold();
end -- OnLoad
function SimpleGold_Event(self, event, ...)
local eventHandled = false;
-- VARIABLES_LOADED
-- ================
if ( event == "VARIABLES_LOADED" ) then
-- record that we have been loaded:
SimpleGold_variablesLoaded = true;
FixVars();
lastWindowState= not(SimpleGoldSavedVars["viz"]); -- guarantee initial draw
eventHandled = true;
end -- ( event == "VARIABLES_LOADED" )
-- Money events:
if (eventHandled == false and event == "PLAYER_MONEY") then
SimpleGoldUpdate(self);
eventHandled = true;
end
if (eventHandled == false and event == "PLAYER_ENTERING_WORLD") then
SimpleGoldUpdate(self); -- show the frame if necessary
eventHandled = true;
end
end -- SimpleGold_Event
-- command line parameters: (slash command handler)
function SimpleGold_CommandLine(msg)
local tName;
local normalizedName;
local normalizedIndex;
local foundIndex = nil;
local oStr, toss;
cmd=string.lower(msg);
-- display the help mesage:
if ( msg=="" or cmd=="help") then
local p="/simplegold ";
DEFAULT_CHAT_FRAME:AddMessage(SASSTEXT_TITLE, 0.5, 1.0, 0.5, 1);
DEFAULT_CHAT_FRAME:AddMessage(SGOLDTEXT.HELP, 0.8, 0.8, 0.8, 1);
DEFAULT_CHAT_FRAME:AddMessage(p..SGOLDTEXT.SHOW .. " - " .. SGOLDTEXT.SHOW_DESCRIPTION, 0.8, 0.8, 0.8, 1);
DEFAULT_CHAT_FRAME:AddMessage(p..SGOLDTEXT.HIDE .. " - " .. SGOLDTEXT.HIDE_DESCRIPTION, 0.8, 0.8, 0.8, 1);
DEFAULT_CHAT_FRAME:AddMessage(p..SGOLDTEXT.LOCK .. " - " .. SGOLDTEXT.LOCK_DESCRIPTION, 0.8, 0.8, 0.8, 1);
DEFAULT_CHAT_FRAME:AddMessage(p..SGOLDTEXT.UNLOCK .. " - " .. SGOLDTEXT.UNLOCK_DESCRIPTION, 0.8, 0.8, 0.8, 1);
DEFAULT_CHAT_FRAME:AddMessage(p..SGOLDTEXT.CENTER .. " - " .. SGOLDTEXT.CENTER_DESCRIPTION, 0.8, 0.8, 0.8, 1);
DEFAULT_CHAT_FRAME:AddMessage(p..SGOLDTEXT.DELETE .. " {character name} - " .. SGOLDTEXT.DELETE_DESCRIPTION, 0.8, 0.8, 0.8, 1);
end
local delStart, delEnd = string.find(cmd,"delete ",1);
if (delStart) then
tName=(string.sub(msg,delEnd+1));
-- CONFIRM_DELETE="Character &CHARNAME removed from list."
local tList=SimpleGoldGlobals[myPlayerRealm];
normalizedName=SimpleGold_NormalizeString(tName);
if (strlenutf8(normalizedName)>0) then
-- look for the name in this realm:
for k, v in pairs (tList) do
normalizedIndex=SimpleGold_NormalizeString(k);
if (normalizedIndex == normalizedName) then
foundIndex=k
end
end -- loop through the names
if (foundIndex ~= nil) then
SimpleGoldGlobals[myPlayerRealm][foundIndex]=nil;
oStr, toss= string.gsub(SGOLDTEXT.CONFIRM_DELETE, "_CHARNAME_", tName);
else
oStr, toss= string.gsub(SGOLDTEXT.NOTOON, "_CHARNAME_", tName);
end
DEFAULT_CHAT_FRAME:AddMessage(oStr, 0.8, 0.8, 0.8, 1);
end -- able to parse a name
end
if ( cmd == SGOLDTEXT.SHOW) then
SimpleGoldDisplayFrame:Show();
DEFAULT_CHAT_FRAME:AddMessage(SGOLDTEXT.CONFIRM_SHOWING, 0.8, 0.8, 0.8, 1);
end
if ( cmd == SGOLDTEXT.HIDE) then
SimpleGoldDisplayFrame:Hide();
SimpleGoldSavedVars["viz"]=false;
DEFAULT_CHAT_FRAME:AddMessage(SGOLDTEXT.CONFIRM_HIDING, 0.8, 0.8, 0.8, 1);
end
if ( cmd == SGOLDTEXT.LOCK) then
SimpleGoldSavedVars["locked"]=true;
DEFAULT_CHAT_FRAME:AddMessage(SGOLDTEXT.CONFIRM_LOCKED, 0.8, 0.8, 0.8, 1);
end
if ( cmd == SGOLDTEXT.UNLOCK) then
SimpleGoldSavedVars["locked"]=false;
DEFAULT_CHAT_FRAME:AddMessage(SGOLDTEXT.CONFIRM_UNLOCKED, 0.8, 0.8, 0.8, 1);
end
if ( cmd == SGOLDTEXT.CENTER) then
SimpleGoldSavedVars["locked"]=false;
SimpleGoldPrefsCenter()
DEFAULT_CHAT_FRAME:AddMessage(SGOLDTEXT.CONFIRM_UNLOCKED, 0.8, 0.8, 0.8, 1);
DEFAULT_CHAT_FRAME:AddMessage(SGOLDTEXT.CONFIRM_CENTER, 0.8, 0.8, 0.8, 1);
end
end
function SimpleGoldUpdate(self)
if (lastWindowState == SimpleGoldSavedVars["viz"]) then
-- we don't really need to update do we?
else
lastWindowState = SimpleGoldSavedVars["viz"];
if (lastWindowState) then
SimpleGoldDisplayFrame:Show();
else
SimpleGoldDisplayFrame:Hide();
end
end
local money = GetMoney();
UpdateGlobalGold();
MoneyFrame_Update("SimpleGoldMoney", money); --"SimpleGoldMoney", money
DrawBG();
end
function SimpleGoldServiceUpdate(elapsed)
SimpleGold_UpdateTimer = SimpleGold_UpdateTimer + elapsed;
if (SimpleGold_UpdateTimer > SimpleGold_UpdateInterval) then
-- DEFAULT_CHAT_FRAME:AddMessage("tick", 0.5, 1.0, 0.5, 1);
SimpleGoldUpdate();
SimpleGold_UpdateTimer = 0;
end
end
-- GUI Handlers:
-- =============================
-- prefs:
-- function SimpleGold_Options_OnClick(arg1)
-- id = this:GetID()
-- local buttonName=this:GetName()
-- SimpleGoldDefaults[buttonName] =getglobal(buttonName):GetChecked();
-- SimpleGoldSavedVars[buttonName] =getglobal(buttonName):GetChecked();
-- end
function SimpleGoldPrefsCenter()
--
SimpleGoldSavedVars["xPos"]=0;
SimpleGoldSavedVars["yPos"]=0;
SimpleGoldDisplayFrame:ClearAllPoints();
SimpleGoldDisplayFrame:SetPoint("CENTER", "UIParent", "CENTER", 0, 0);
end
-- OnShow
function SimpleGoldPrefsFrameOnShow()
-- see if we need to position this frame:
if (nil == SimpleGoldSavedVars["xPos"]) then -- No value? Set one
SimpleGoldPrefsCenter();
else
if (-6666 == SimpleGoldSavedVars["xPos"]) then -- Uninitialized value? Set it
SimpleGoldPrefsCenter();
end
end
DrawBG();
SimpleGoldSavedVars["viz"]=true;
-- SimpleGoldUpdate();
end
function SimpleGoldPrefsFrameOnHide()
SimpleGoldSavedVars["viz"]=false;
end
function SimpleGold_StepBackground()
FixVars();
local currentStep=SimpleGoldSavedVars["lastPreset"];
local presetCount=#(colorPresetList);
currentStep=currentStep+1;
if (currentStep > presetCount) then
currentStep=1;
end
local tColor=colorPresetList[currentStep];
SimpleGold_BackgroundTexture:SetVertexColor(tColor[1],tColor[2],tColor[3],tColor[4]);
SimpleGoldSavedVars["lastPreset"]=currentStep;
SimpleGoldSavedVars["color"]=tColor;
-- SimpleGold_BackgroundTexture:SetTexture(1,1,1,0);
-- Frame:SetBackdrop([backdropTable]) - Set the backdrop of the frame according to the specification provided.
-- Frame:SetBackdropBorderColor(r,g,b[,a]) - Set the frame's backdrop's border's color.
-- Frame:SetBackdropColor(r,g,b[,a]) - Set the frame's backdrop color.
end
function SimpleGold_ShowTooltip()
local tooltipList ={};
local totalGold=0;
-- GameTooltip_SetDefaultAnchor(GameTooltip, SimpleGoldDisplayFrame);
GameTooltip:SetOwner(getglobal("SimpleGoldDisplayFrame") , "ANCHOR_CURSOR", -5, 5);
-- GameTooltip:SetOwner(owner, "anchor"[, +x, +y]);
--GameTooltip:AddLine("test", .6,1.0,.8); -- GameTooltip:AddLine(name, GameTooltip_UnitColor("player"));\
-- add up the gold for this realm:
if (SimpleGoldGlobals==nil) then
table.insert(tooltipList,"Gold Data Unavailable");
else
local thisRealmList=SimpleGoldGlobals[myPlayerRealm];
for k,v in pairs(thisRealmList) do
-- table.insert(tooltipList,k..' '..string.format("%.4f",v/10000));
table.insert(tooltipList,{k,string.format("%.2f",v/10000)});
totalGold=totalGold+v;
end --thisRealmList
end
if (#(tooltipList))>0 then
GameTooltip:AddLine("Total: "..string.format("%.2f",totalGold/10000), .8, .8, 1.8);
for i = 1, #(tooltipList) do
-- GameTooltip:AddLine(tooltipList[i], .8, .8, 1.8);
GameTooltip:AddLine(tooltipList[i][1]..': '..tooltipList[i][2], .8, .8, 1.8);
end -- for fieldCount
end
GameTooltip:Show();
end
function SimpleGold_HideTooltip()
GameTooltip:Hide();
end
function SimpleGold_NormalizeString(s)
-- makes a string lower case and trims whitespace
s=string.lower(s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
function SimpleGoldSaveLastPosition()
local point, relativeTo, relativePoint, xOff, yOff;
point, relativeTo, relativePoint, xOff, yOff = SimpleGoldDisplayFrame:GetPoint();
SimpleGoldSavedVars["xPos"]=xOff;
SimpleGoldSavedVars["yPos"]=yOff;
end