forked from getov/CharacterStatsClassic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacterStatsClassicUI.lua
244 lines (206 loc) · 10.6 KB
/
CharacterStatsClassicUI.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
-- Namespaces
-- core - table (namespace) shared between every lua file
local addonName, core = ...;
core.UIConfig = {};
-- Defaults
local UISettingsGlobal = {
useBlizzardBlockValue = false;
}
local UISettingsCharacter = {
selectedLeftStatsCategory = 1;
selectedRightStatsCategory = 2;
}
-- for easier referencing the core config
local UIConfig = core.UIConfig;
local CSC_UIFrame = core.UIConfig;
local CSC_ConfigFrame = { };
local statsDropdownList = {
PLAYERSTAT_BASE_STATS,
PLAYERSTAT_MELEE_COMBAT,
PLAYERSTAT_RANGED_COMBAT,
PLAYERSTAT_SPELL_COMBAT,
PLAYERSTAT_DEFENSES
}
local NUM_STATS_TO_SHOW = 5;
local LeftStatsTable = { }
local RightStatsTable = { }
local function CSC_ResetStatFrames(statFrames)
for i=1, NUM_STATS_TO_SHOW, 1 do
statFrames[i]:Hide();
statFrames[i]:SetScript("OnEnter", statFrames[i].OnEnterCallback);
statFrames[i].tooltip = nil;
statFrames[i].tooltip2 = nil;
statFrames[i].tooltip3 = nil;
end
end
function UIConfig:InitializeStatsFrames(leftParentFrame, rightParentFrame)
local offsetStepY = 15;
local accumulatedOffsetY = 0;
for i = 1, NUM_STATS_TO_SHOW do
accumulatedOffsetY = accumulatedOffsetY + offsetStepY;
local actualOffset = accumulatedOffsetY;
if i == 1 then
actualOffset = 32;
accumulatedOffsetY = 32;
end
LeftStatsTable[i] = CreateFrame("Frame", nil, leftParentFrame, "CharacterStatFrameTemplate");
LeftStatsTable[i]:SetPoint("LEFT", leftParentFrame, "TOPLEFT", 10, -actualOffset);
LeftStatsTable[i]:SetWidth(130);
LeftStatsTable[i].OnEnterCallback = LeftStatsTable[i]:GetScript("OnEnter");
RightStatsTable[i] = CreateFrame("Frame", nil, rightParentFrame, "CharacterStatFrameTemplate");
RightStatsTable[i]:SetPoint("LEFT", rightParentFrame, "TOPLEFT", 10, -actualOffset);
RightStatsTable[i]:SetWidth(130);
RightStatsTable[i].OnEnterCallback = RightStatsTable[i]:GetScript("OnEnter");
end
end
function UIConfig:SetCharacterStats(statsTable, category)
CSC_ResetStatFrames(statsTable);
if category == PLAYERSTAT_BASE_STATS then
-- str, agility, stamina, intelect, spirit
CSC_PaperDollFrame_SetPrimaryStats(statsTable, "player");
elseif category == PLAYERSTAT_DEFENSES then
-- armor, defense, dodge, parry, block
CSC_PaperDollFrame_SetArmor(statsTable[1], "player");
CSC_PaperDollFrame_SetDefense(statsTable[2], "player");
CSC_PaperDollFrame_SetDodge(statsTable[3], "player");
CSC_PaperDollFrame_SetParry(statsTable[4], "player");
CSC_PaperDollFrame_SetBlock(statsTable[5], "player");
elseif category == PLAYERSTAT_MELEE_COMBAT then
-- damage, Att Power, speed, hit raiting, crit chance
CSC_PaperDollFrame_SetDamage(statsTable[1], "player", category);
CSC_PaperDollFrame_SetMeleeAttackPower(statsTable[2], "player");
CSC_PaperDollFrame_SetAttackSpeed(statsTable[3], "player");
CSC_PaperDollFrame_SetCritChance(statsTable[4], "player", category);
CSC_PaperDollFrame_SetHitChance(statsTable[5], "player");
elseif category == PLAYERSTAT_RANGED_COMBAT then
CSC_PaperDollFrame_SetDamage(statsTable[1], "player", category);
CSC_PaperDollFrame_SetRangedAttackPower(statsTable[2], "player");
CSC_PaperDollFrame_SetRangedAttackSpeed(statsTable[3], "player");
CSC_PaperDollFrame_SetCritChance(statsTable[4], "player", category);
CSC_PaperDollFrame_SetRangedHitChance(statsTable[5], "player");
elseif category == PLAYERSTAT_SPELL_COMBAT then
-- bonus dmg, bonus healing, crit chance, mana regen, hit
CSC_PaperDollFrame_SetSpellPower(statsTable[1], "player");
CSC_PaperDollFrame_SetHealing(statsTable[2], "player");
CSC_PaperDollFrame_SetManaRegen(statsTable[3], "player");
CSC_PaperDollFrame_SetSpellCritChance(statsTable[4], "player");
CSC_PaperDollFrame_SetSpellHitChance(statsTable[5], "player");
end
end
function UIConfig:CreateMenu()
-- Hide the default stats
CharacterAttributesFrame:Hide();
CSC_UIFrame.CharacterStatsPanel = CreateFrame("Frame", nil, CharacterFrame); --CharacterFrameInsetRight
CSC_UIFrame.CharacterStatsPanel:SetPoint("LEFT", CharacterFrame, "BOTTOMLEFT", 50, 75); --85 for 6 stats
CSC_UIFrame.CharacterStatsPanel:SetHeight(320);
CSC_UIFrame.CharacterStatsPanel:SetWidth(200);
UIConfig:SetupDropdown();
UIConfig:SetupConfigInterface();
UIConfig:InitializeStatsFrames(CSC_UIFrame.CharacterStatsPanel.leftStatsDropDown, CSC_UIFrame.CharacterStatsPanel.rightStatsDropDown);
UIConfig:UpdateStats();
end
function UIConfig:UpdateStats()
UIConfig:SetCharacterStats(LeftStatsTable, statsDropdownList[UISettingsCharacter.selectedLeftStatsCategory]);
UIConfig:SetCharacterStats(RightStatsTable, statsDropdownList[UISettingsCharacter.selectedRightStatsCategory]);
end
local function OnClickLeftStatsDropdown(self)
UISettingsCharacter.selectedLeftStatsCategory = self:GetID();
UIDropDownMenu_SetSelectedID(CSC_UIFrame.CharacterStatsPanel.leftStatsDropDown, UISettingsCharacter.selectedLeftStatsCategory);
UIConfig:SetCharacterStats(LeftStatsTable, statsDropdownList[UISettingsCharacter.selectedLeftStatsCategory]);
end
local function OnClickRightStatsDropdown(self)
UISettingsCharacter.selectedRightStatsCategory = self:GetID();
UIDropDownMenu_SetSelectedID(CSC_UIFrame.CharacterStatsPanel.rightStatsDropDown, UISettingsCharacter.selectedRightStatsCategory);
UIConfig:SetCharacterStats(RightStatsTable, statsDropdownList[UISettingsCharacter.selectedRightStatsCategory]);
end
function UIConfig:InitializeLeftStatsDropdown(self, level)
local info = UIDropDownMenu_CreateInfo();
for k,v in pairs(statsDropdownList) do
info.text = v;
info.func = OnClickLeftStatsDropdown;
info.checked = false;
UIDropDownMenu_AddButton(info, level);
end
end
function UIConfig:InitializeRightStatsDropdown(self, level)
local info = UIDropDownMenu_CreateInfo();
for k,v in pairs(statsDropdownList) do
info.text = v;
info.func = OnClickRightStatsDropdown;
info.checked = false;
UIDropDownMenu_AddButton(info, level);
end
end
function UIConfig:SetupDropdown()
CSC_UIFrame.CharacterStatsPanel.leftStatsDropDown = CreateFrame("Frame", nil, CSC_UIFrame.CharacterStatsPanel, "UIDropDownMenuTemplate");
CSC_UIFrame.CharacterStatsPanel.leftStatsDropDown:SetPoint("TOPLEFT", CSC_UIFrame.CharacterStatsPanel, "TOPLEFT", 0, 0);
CSC_UIFrame.CharacterStatsPanel.rightStatsDropDown = CreateFrame("Frame", nil, CSC_UIFrame.CharacterStatsPanel, "UIDropDownMenuTemplate");
CSC_UIFrame.CharacterStatsPanel.rightStatsDropDown:SetPoint("TOPLEFT", CSC_UIFrame.CharacterStatsPanel, "TOPLEFT", 115, 0);
UIDropDownMenu_Initialize(CSC_UIFrame.CharacterStatsPanel.leftStatsDropDown, UIConfig.InitializeLeftStatsDropdown);
UIDropDownMenu_SetSelectedID(CSC_UIFrame.CharacterStatsPanel.leftStatsDropDown, UISettingsCharacter.selectedLeftStatsCategory);
UIDropDownMenu_SetWidth(CSC_UIFrame.CharacterStatsPanel.leftStatsDropDown, 99);
UIDropDownMenu_JustifyText(CSC_UIFrame.CharacterStatsPanel.leftStatsDropDown, "LEFT");
UIDropDownMenu_Initialize(CSC_UIFrame.CharacterStatsPanel.rightStatsDropDown, UIConfig.InitializeRightStatsDropdown);
UIDropDownMenu_SetSelectedID(CSC_UIFrame.CharacterStatsPanel.rightStatsDropDown, UISettingsCharacter.selectedRightStatsCategory);
UIDropDownMenu_SetWidth(CSC_UIFrame.CharacterStatsPanel.rightStatsDropDown, 99);
UIDropDownMenu_JustifyText(CSC_UIFrame.CharacterStatsPanel.rightStatsDropDown, "LEFT");
end
function UIConfig:SetupConfigInterface()
CSC_ConfigFrame = CreateFrame("Frame", "CSC_InterfaceOptionsPanel", UIParent);
CSC_ConfigFrame.name = "CharacterStatsClassic";
InterfaceOptions_AddCategory(CSC_ConfigFrame);
-- Title and font
CSC_ConfigFrame.title = CreateFrame("Frame", "CharacterStatsClassic", CSC_ConfigFrame);
CSC_ConfigFrame.title:SetPoint("TOPLEFT", CSC_ConfigFrame, "TOPLEFT", 10, -10);
CSC_ConfigFrame.title:SetWidth(300);
CSC_ConfigFrame.titleString = CSC_ConfigFrame.title:CreateFontString(nil, "OVERLAY", "GameFontNormal");
CSC_ConfigFrame.titleString:SetPoint("TOPLEFT", CSC_ConfigFrame, "TOPLEFT", 10, -10);
CSC_ConfigFrame.titleString:SetText('|cff00c0ffCharacterStatsClassic|r');
CSC_ConfigFrame.titleString:SetFont("Fonts\\FRIZQT__.tff", 20, "OUTLINE");
-- Checkboxes
CSC_ConfigFrame.chkBtnUseBlizzardBlockValue = CreateFrame("CheckButton", "default", CSC_ConfigFrame, "UICheckButtonTemplate");
CSC_ConfigFrame.chkBtnUseBlizzardBlockValue:SetPoint("TOPLEFT", 20, -30);
CSC_ConfigFrame.chkBtnUseBlizzardBlockValue.text:SetText("Use alternative Block Value calculation (Blizzard function)");
CSC_ConfigFrame.chkBtnUseBlizzardBlockValue:SetChecked(UISettingsGlobal.useBlizzardBlockValue);
CSC_ConfigFrame.chkBtnUseBlizzardBlockValue:SetScript("OnClick",
function()
UISettingsGlobal.useBlizzardBlockValue = not UISettingsGlobal.useBlizzardBlockValue;
end);
end
-- Hook a custom function in order to extend the functionality of the default ToggleCharacter function
local function CSC_ToggleCharacterPostHook(tab, onlyShow)
if (tab == "PaperDollFrame") then
CSC_UIFrame.CharacterStatsPanel:Show();
CSC_UIFrame:UpdateStats();
else
CSC_UIFrame.CharacterStatsPanel:Hide();
end
end
hooksecurefunc("ToggleCharacter", CSC_ToggleCharacterPostHook);
-- Serializing the DB
local dbLoader = CreateFrame("Frame");
dbLoader:RegisterEvent("ADDON_LOADED");
dbLoader:RegisterEvent("PLAYER_LOGOUT");
-- ADDON_LOADED is called after the code of the addon is being executed
-- Therefore I have to call any setup-functions dependent on the DB after the event (UIConfig:SetupDropdown())
function dbLoader:OnEvent(event, arg1)
if (event == "ADDON_LOADED" and arg1 == "CharacterStatsClassic") then
-- Global DB
if (CharacterStatsClassicDB == nil) then
CharacterStatsClassicDB = UISettingsGlobal;
else
UISettingsGlobal = CharacterStatsClassicDB;
end
-- Character DB
if (CharacterStatsClassicCharacterDB == nil) then
CharacterStatsClassicCharacterDB = UISettingsCharacter;
else
UISettingsCharacter = CharacterStatsClassicCharacterDB;
end
UIConfig:CreateMenu();
elseif (event == "PLAYER_LOGOUT") then
CharacterStatsClassicDB = UISettingsGlobal;
CharacterStatsClassicCharacterDB = UISettingsCharacter;
end
end
dbLoader:SetScript("OnEvent", dbLoader.OnEvent);