This repository has been archived by the owner on Aug 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDejaCharacterStats.lua
273 lines (240 loc) · 9.78 KB
/
DejaCharacterStats.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
local ADDON_NAME, namespace = ... --localization
local L = namespace.L --localization
local version = GetAddOnMetadata(ADDON_NAME, "Version")
local addoninfo = 'v'..version
--------------------------
-- SavedVariables Setup --
--------------------------
local DejaCharacterStats, gdbprivate = ...
gdbprivate.gdbdefaults = {
}
gdbprivate.gdbdefaults.gdbdefaults = {
}
----------------------------
-- Saved Variables Loader --
----------------------------
local loader = CreateFrame("Frame")
loader:RegisterEvent("ADDON_LOADED")
loader:SetScript("OnEvent", function(self, event, arg1)
if event == "ADDON_LOADED" and arg1 == "DejaCharacterStats" then
local function initDB(gdb, gdbdefaults)
if type(gdb) ~= "table" then gdb = {} end
if type(gdbdefaults) ~= "table" then return gdb end
for k, v in pairs(gdbdefaults) do
if type(v) == "table" then
gdb[k] = initDB(gdb[k], v)
elseif type(v) ~= type(gdb[k]) then
gdb[k] = v
end
end
return gdb
end
DejaCharacterStatsDB = initDB(DejaCharacterStatsDB, gdbprivate.gdbdefaults) --the first per account saved variable. The second per-account variable DCS_ClassSpecDB is handled in DCS_Layouts.lua
gdbprivate.gdb = DejaCharacterStatsDB --fast access for checkbox states
self:UnregisterEvent("ADDON_LOADED")
end
end)
local DejaCharacterStats, private = ...
private.defaults = {
}
private.defaults.dcsdefaults = {
}
DejaCharacterStats = {};
----------------------------
-- Saved Variables Loader --
----------------------------
local loader = CreateFrame("Frame")
loader:RegisterEvent("ADDON_LOADED")
loader:SetScript("OnEvent", function(self, event, arg1)
if event == "ADDON_LOADED" and arg1 == "DejaCharacterStats" then
local function initDB(db, defaults)
if type(db) ~= "table" then db = {} end
if type(defaults) ~= "table" then return db end
for k, v in pairs(defaults) do
if type(v) == "table" then
db[k] = initDB(db[k], v)
elseif type(v) ~= type(db[k]) then
db[k] = v
end
end
return db
end
DejaCharacterStatsDBPC = initDB(DejaCharacterStatsDBPC, private.defaults) --saved variable per character, currently not used.
private.db = DejaCharacterStatsDBPC
self:UnregisterEvent("ADDON_LOADED")
end
end)
-- Uncomment below the following three database saved variables setup lines for DejaView integration.
-- SavedVariables Setup
-- local DejaCharacterStats, private = ...
-- private.defaults = {}
-- DejaCharacterStats = {};
---------------------
-- DCS Slash Setup --
---------------------
local RegisteredEvents = {};
local dcsslash = CreateFrame("Frame", "DejaCharacterStatsSlash", UIParent)
dcsslash:SetScript("OnEvent", function (self, event, ...)
if (RegisteredEvents[event]) then
return RegisteredEvents[event](self, event, ...)
end
end)
function RegisteredEvents:ADDON_LOADED(event, addon, ...)
if (addon == "DejaCharacterStats") then
--SLASH_DEJACHARACTERSTATS1 = (L["/dcstats"])
SLASH_DEJACHARACTERSTATS1 = "/dcstats"
SlashCmdList["DEJACHARACTERSTATS"] = function (msg, editbox)
DejaCharacterStats.SlashCmdHandler(msg, editbox)
end
-- DEFAULT_CHAT_FRAME:AddMessage("DejaCharacterStats loaded successfully. For options: Esc>Interface>AddOns or type /dcstats.",0,192,255)
end
end
for k, v in pairs(RegisteredEvents) do
dcsslash:RegisterEvent(k)
end
function DejaCharacterStats.ShowHelp()
print(addoninfo)
print(L["DejaCharacterStats Slash commands (/dcstats):"])
print(L[" /dcstats config: Opens the DejaCharacterStats addon config menu."])
print(L[" /dcstats reset: Resets DejaCharacterStats options to default."])
end
--[[
function DejaCharacterStats.SetConfigToDefaults()
print(L["Resetting config to defaults"])
DejaCharacterStatsDBPC = private.db --DBPC not used, when (and if) will, DefaultConfig should be replaced with private.db
RELOADUI()
end
--]]
--[[
function DejaCharacterStats.GetConfigValue(key)
return DejaCharacterStatsDBPC[key] --I think here a loop is required -- Called in the dumpconfig loop in the DejaCharacterStats.SlashCmdHandler function.
end
--]]
--[[
function DejaCharacterStats.PrintPerformanceData()
UpdateAddOnMemoryUsage()
local mem = GetAddOnMemoryUsage("DejaCharacterStats")
print(L["DejaCharacterStats is currently using "] .. mem .. L[" kbytes of memory"])
collectgarbage("collect")
UpdateAddOnMemoryUsage()
mem = GetAddOnMemoryUsage("DejaCharacterStats")
print(L["DejaCharacterStats is currently using "] .. mem .. L[" kbytes of memory after garbage collection"])
end
--]]
function DejaCharacterStats.SlashCmdHandler(msg, editbox)
msg = string.lower(msg)
--print("command is " .. msg .. "\n")
--if (string.lower(msg) == L["config"]) then --I think string.lowermight not work for Russian letters
if (msg == "config") then
InterfaceOptionsFrame_OpenToCategory("DejaCharacterStats");
InterfaceOptionsFrame_OpenToCategory("DejaCharacterStats");
InterfaceOptionsFrame_OpenToCategory("DejaCharacterStats");
--[[
elseif (string.lower(msg) == L["dumpconfig"]) then
print(L["With defaults"])
for k,v in pairs(private.db) do --produces error
print(k,DejaCharacterStats.GetConfigValue(k))
end
print(L["Direct table"])
for k,v in pairs(private.db) do
print(k,v)
end
--]]
--elseif (string.lower(msg) == L["reset"]) then
elseif (msg == "reset") then
--DejaCharacterStatsDBPC = private.defaults;
gdbprivate.gdb.gdbdefaults = gdbprivate.gdbdefaults.gdbdefaults
ReloadUI();
--[[
elseif (string.lower(msg) == L["perf"]) then
DejaCharacterStats.PrintPerformanceData()
--]]
else
DejaCharacterStats.ShowHelp()
end
end
SlashCmdList["DEJACHARACTERSTATS"] = DejaCharacterStats.SlashCmdHandler;
-----------------------
-- DCS Options Panel --
-----------------------
DejaCharacterStats.panel = CreateFrame( "Frame", "DejaCharacterStatsPanel", UIParent );
DejaCharacterStats.panel.name = "DejaCharacterStats";
InterfaceOptions_AddCategory(DejaCharacterStats.panel);
-- DCS, DejaView Child Panel
-- DejaViewPanel.DejaCharacterStatsPanel = CreateFrame( "Frame", "DejaCharacterStatsPanel", DejaViewPanel);
-- DejaViewPanel.DejaCharacterStatsPanel.name = "DejaCharacterStats";
-- Specify childness of this panel (this puts it under the little red [+], instead of giving it a normal AddOn category)
-- DejaViewPanel.DejaCharacterStatsPanel.parent = DejaViewPanel.name;
-- Add the child to the Interface Options
-- InterfaceOptions_AddCategory(DejaViewPanel.DejaCharacterStatsPanel);
local dcstitle=CreateFrame("Frame", "DCSTitle", DejaCharacterStatsPanel)
dcstitle:SetPoint("TOPLEFT", 10, -10)
--dcstitle:SetScale(2.0)
dcstitle:SetWidth(300)
dcstitle:SetHeight(100)
dcstitle:Show()
local dcstitleFS = dcstitle:CreateFontString(nil, "OVERLAY", "GameFontNormal")
dcstitleFS:SetText('|cff00c0ffDejaCharacterStats|r')
dcstitleFS:SetPoint("TOPLEFT", 0, 0)
dcstitleFS:SetFont("Fonts\\FRIZQT__.TTF", 20)
local dcsversionFS = DejaCharacterStatsPanel:CreateFontString(nil, "OVERLAY", "GameFontNormal")
dcsversionFS:SetText('|cff00c0ff' .. addoninfo .. '|r')
dcsversionFS:SetPoint("BOTTOMRIGHT", -10, 10)
dcsversionFS:SetFont("Fonts\\FRIZQT__.TTF", 12)
local dcsresetcheck = CreateFrame("Button", "DCSResetButton", DejaCharacterStatsPanel, "UIPanelButtonTemplate")
dcsresetcheck:ClearAllPoints()
dcsresetcheck:SetPoint("BOTTOMLEFT", 5, 5)
dcsresetcheck:SetScale(1.25)
--local LOCALE = GetLocale()
local LOCALE = namespace.locale
--print (LOCALE)
local sometable = {
["ptBR"] = {},
["frFR"] = {},
["deDE"] = {},
}
if sometable[LOCALE] then
LOCALE = 175
else
--print ("enUS = 125")
LOCALE = 125
end
--[[
if (LOCALE == "ptBR" or LOCALE == "frFR" or LOCALE == "deDE") then
--print ("ptBR, frFR, deDE = 175")
LOCALE = 175
else
--print ("enUS = 125")
LOCALE = 125
end
--]]
dcsresetcheck:SetWidth(LOCALE)
dcsresetcheck:SetHeight(30)
_G[dcsresetcheck:GetName() .. "Text"]:SetText(L["Reset to Default"])
dcsresetcheck:SetScript("OnClick", function(self, button, down)
gdbprivate.gdb.gdbdefaults = gdbprivate.gdbdefaults.gdbdefaults;
ReloadUI();
end)
----------------------
-- Panel Categories --
----------------------
--Average Item Level
local dcsILvlPanelCategoryFS = DejaCharacterStatsPanel:CreateFontString("dcsILvlPanelCategoryFS", "OVERLAY", "GameFontNormal")
dcsILvlPanelCategoryFS:SetText('|cffffffff' .. L["Average Item Level:"] .. '|r') --wouldn't be more efficient through format?
dcsILvlPanelCategoryFS:SetPoint("TOPLEFT", 25, -40)
dcsILvlPanelCategoryFS:SetFontObject("GameFontNormalLarge") --Use instead of SetFont("Fonts\\FRIZQT__.TTF", 15) or Russian, Korean and Chinese characters won't work.
--Character Stats
local dcsStatsPanelcategoryFS = DejaCharacterStatsPanel:CreateFontString("dcsStatsPanelcategoryFS", "OVERLAY", "GameFontNormal")
dcsStatsPanelcategoryFS:SetText('|cffffffff' .. L["Character Stats:"] .. '|r')
dcsStatsPanelcategoryFS:SetPoint("TOPLEFT", 25, -150)
dcsStatsPanelcategoryFS:SetFontObject("GameFontNormalLarge") --Use instead of SetFont("Fonts\\FRIZQT__.TTF", 15) or Russian, Korean and Chinese characters won't work.
--Item Slots
local dcsItemsPanelCategoryFS = DejaCharacterStatsPanel:CreateFontString("dcsItemsPanelCategoryFS", "OVERLAY", "GameFontNormal")
dcsItemsPanelCategoryFS:SetText('|cffffffff' .. L["Item Slots:"] .. '|r')
dcsItemsPanelCategoryFS:SetPoint("TOPLEFT", 25, -240)
dcsItemsPanelCategoryFS:SetFontObject("GameFontNormalLarge") --Use instead of SetFont("Fonts\\FRIZQT__.TTF", 15) or Russian, Korean and Chinese characters won't work.
--Miscellaneous
local dcsMiscPanelCategoryFS = DejaCharacterStatsPanel:CreateFontString("dcsMiscPanelCategoryFS", "OVERLAY", "GameFontNormal")
dcsMiscPanelCategoryFS:SetText('|cffffffff' .. L["Miscellaneous:"] .. '|r')
dcsMiscPanelCategoryFS:SetPoint("LEFT", 25, -165)
dcsMiscPanelCategoryFS:SetFontObject("GameFontNormalLarge") --Use instead of SetFont("Fonts\\FRIZQT__.TTF", 15) or Russian, Korean and Chinese characters won't work.