vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | TITAN_XP_ID = "XP"; |
2 | TITAN_XP_FREQUENCY = 1; |
||
3 | |||
4 | function TitanPanelXPButton_OnLoad() |
||
5 | this.registry = { |
||
6 | id = TITAN_XP_ID, |
||
7 | builtIn = 1, |
||
8 | version = TITAN_VERSION, |
||
9 | menuText = TITAN_XP_MENU_TEXT, |
||
10 | buttonTextFunction = "TitanPanelXPButton_GetButtonText", |
||
11 | tooltipTitle = TITAN_XP_TOOLTIP, |
||
12 | tooltipTextFunction = "TitanPanelXPButton_GetTooltipText", |
||
13 | frequency = TITAN_XP_FREQUENCY, |
||
14 | iconWidth = 16, |
||
15 | savedVariables = { |
||
16 | ShowXPPerHourSession = 1, |
||
17 | ShowIcon = 1, |
||
18 | ShowLabelText = 1, |
||
19 | } |
||
20 | }; |
||
21 | |||
22 | this:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
23 | this:RegisterEvent("PLAYER_XP_UPDATE"); |
||
24 | this:RegisterEvent("PLAYER_LEVEL_UP"); |
||
25 | end |
||
26 | |||
27 | function TitanPanelXPButton_OnShow() |
||
28 | TitanPanelXPButton_SetIcon(); |
||
29 | end |
||
30 | |||
31 | function TitanPanelXPButton_OnEvent(arg1, arg2) |
||
32 | if (event == "PLAYER_ENTERING_WORLD") then |
||
33 | if (not this.initXP) then |
||
34 | this.initXP = UnitXP("player"); |
||
35 | this.accumXP = 0; |
||
36 | this.sessionXP = 0; |
||
37 | this.startSessionTime = 0; |
||
38 | end |
||
39 | elseif (event == "PLAYER_XP_UPDATE") then |
||
40 | if (not this.initXP) then |
||
41 | this.initXP = UnitXP("player"); |
||
42 | this.accumXP = 0; |
||
43 | this.sessionXP = 0; |
||
44 | this.startSessionTime = 0; |
||
45 | end |
||
46 | this.sessionXP = UnitXP("player") - this.initXP + this.accumXP; |
||
47 | elseif (event == "PLAYER_LEVEL_UP") then |
||
48 | this.accumXP = this.accumXP + UnitXPMax("player") - this.initXP; |
||
49 | this.initXP = 0; |
||
50 | end |
||
51 | end |
||
52 | |||
53 | function TitanPanelXPButton_GetButtonText(id) |
||
54 | local button, id = TitanUtils_GetButton(id, true); |
||
55 | local totalXP = UnitXPMax("player"); |
||
56 | local currentXP = UnitXP("player"); |
||
57 | local toLevelXP = totalXP - currentXP; |
||
58 | local sessionXP = button.sessionXP; |
||
59 | local xpPerHour, xpPerHourText, timeToLevel, timeToLevelText; |
||
60 | local sessionTime = TitanUtils_GetSessionTime() - button.startSessionTime; |
||
61 | local levelTime = TitanUtils_GetLevelTime(); |
||
62 | |||
63 | if (levelTime) then |
||
64 | if (TitanGetVar(TITAN_XP_ID, "ShowXPPerHourSession")) then |
||
65 | xpPerHour = sessionXP / sessionTime * 3600; |
||
66 | timeToLevel = TitanUtils_Ternary((sessionXP == 0), -1, toLevelXP / sessionXP * sessionTime); |
||
67 | |||
68 | xpPerHourText = format(TITAN_XP_FORMAT, xpPerHour); |
||
69 | timeToLevelText = TitanUtils_GetEstTimeText(timeToLevel) |
||
70 | |||
71 | return TITAN_XP_BUTTON_LABEL_XPHR_SESSION, TitanUtils_GetHighlightText(xpPerHourText), |
||
72 | TITAN_XP_BUTTON_LABEL_TOLEVEL_TIME_SESSION, TitanUtils_GetHighlightText(timeToLevelText); |
||
73 | else |
||
74 | xpPerHour = currentXP / levelTime * 3600; |
||
75 | timeToLevel = TitanUtils_Ternary((currentXP == 0), -1, toLevelXP / currentXP * levelTime); |
||
76 | |||
77 | xpPerHourText = format(TITAN_XP_FORMAT, xpPerHour); |
||
78 | timeToLevelText = TitanUtils_GetEstTimeText(timeToLevel); |
||
79 | |||
80 | return TITAN_XP_BUTTON_LABEL_XPHR_LEVEL, TitanUtils_GetHighlightText(xpPerHourText), |
||
81 | TITAN_XP_BUTTON_LABEL_TOLEVEL_TIME_LEVEL, TitanUtils_GetHighlightText(timeToLevelText); |
||
82 | end |
||
83 | end |
||
84 | end |
||
85 | |||
86 | function TitanPanelXPButton_GetTooltipText() |
||
87 | local totalTime = TitanUtils_GetTotalTime(); |
||
88 | local sessionTime = TitanUtils_GetSessionTime() - this.startSessionTime; |
||
89 | local levelTime = TitanUtils_GetLevelTime(); |
||
90 | local totalXP = UnitXPMax("player"); |
||
91 | local currentXP = UnitXP("player"); |
||
92 | local toLevelXP = totalXP - currentXP; |
||
93 | local currentXPPercent = currentXP / totalXP * 100; |
||
94 | local toLevelXPPercent = toLevelXP / totalXP * 100; |
||
95 | local xpPerHourThisLevel = currentXP / levelTime * 3600; |
||
96 | local xpPerHourThisSession = this.sessionXP / sessionTime * 3600; |
||
97 | local estTimeToLevelThisLevel = TitanUtils_Ternary((currentXP == 0), -1, toLevelXP / currentXP * levelTime); |
||
98 | local estTimeToLevelThisSession = TitanUtils_Ternary((this.sessionXP == 0), -1, toLevelXP / this.sessionXP * sessionTime); |
||
99 | |||
100 | return "".. |
||
101 | TITAN_XP_TOOLTIP_TOTAL_TIME.."\t"..TitanUtils_GetHighlightText(TitanUtils_GetAbbrTimeText(totalTime)).."\n".. |
||
102 | TITAN_XP_TOOLTIP_LEVEL_TIME.."\t"..TitanUtils_GetHighlightText(TitanUtils_GetAbbrTimeText(levelTime)).."\n".. |
||
103 | TITAN_XP_TOOLTIP_SESSION_TIME.."\t"..TitanUtils_GetHighlightText(TitanUtils_GetAbbrTimeText(sessionTime)).."\n".. |
||
104 | "\n".. |
||
105 | TITAN_XP_TOOLTIP_TOTAL_XP.."\t"..TitanUtils_GetHighlightText(totalXP).."\n".. |
||
106 | TITAN_XP_TOOLTIP_LEVEL_XP.."\t"..TitanUtils_GetHighlightText(format(TITAN_XP_PERCENT_FORMAT, currentXP, currentXPPercent)).."\n".. |
||
107 | TITAN_XP_TOOLTIP_TOLEVEL_XP.."\t"..TitanUtils_GetHighlightText(format(TITAN_XP_PERCENT_FORMAT, toLevelXP, toLevelXPPercent)).."\n".. |
||
108 | TITAN_XP_TOOLTIP_SESSION_XP.."\t"..TitanUtils_GetHighlightText(this.sessionXP).."\n".. |
||
109 | "\n".. |
||
110 | TITAN_XP_TOOLTIP_XPHR_LEVEL.."\t"..TitanUtils_GetHighlightText(format(TITAN_XP_FORMAT, xpPerHourThisLevel)).."\n".. |
||
111 | TITAN_XP_TOOLTIP_XPHR_SESSION.."\t"..TitanUtils_GetHighlightText(format(TITAN_XP_FORMAT, xpPerHourThisSession)).."\n".. |
||
112 | TITAN_XP_TOOLTIP_TOLEVEL_LEVEL.."\t"..TitanUtils_GetHighlightText(TitanUtils_GetAbbrTimeText(estTimeToLevelThisLevel)).."\n".. |
||
113 | TITAN_XP_TOOLTIP_TOLEVEL_SESSION.."\t"..TitanUtils_GetHighlightText(TitanUtils_GetAbbrTimeText(estTimeToLevelThisSession)); |
||
114 | end |
||
115 | |||
116 | function TitanPanelXPButton_SetIcon() |
||
117 | local icon = TitanPanelXPButtonIcon; |
||
118 | local factionGroup, factionName = UnitFactionGroup("player"); |
||
119 | |||
120 | if ( factionGroup == "Alliance" ) then |
||
121 | icon:SetTexture("Interface\\TargetingFrame\\UI-PVP-Alliance"); |
||
122 | icon:SetTexCoord(0.046875, 0.609375, 0.03125, 0.59375); |
||
123 | elseif ( factionGroup == "Horde" ) then |
||
124 | icon:SetTexture("Interface\\TargetingFrame\\UI-PVP-Horde"); |
||
125 | icon:SetTexCoord(0.046875, 0.609375, 0.015625, 0.578125); |
||
126 | else |
||
127 | icon:SetTexture("Interface\\TargetingFrame\\UI-PVP-FFA"); |
||
128 | icon:SetTexCoord(0.046875, 0.609375, 0.03125, 0.59375); |
||
129 | end |
||
130 | end |
||
131 | |||
132 | function TitanPanelRightClickMenu_PrepareXPMenu() |
||
133 | TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_XP_ID].menuText); |
||
134 | |||
135 | local info = {}; |
||
136 | info.text = TITAN_XP_MENU_SHOW_XPHR_THIS_SESSION; |
||
137 | info.func = TitanPanelXPButton_ShowXPPerHourSession; |
||
138 | info.checked = TitanGetVar(TITAN_XP_ID, "ShowXPPerHourSession"); |
||
139 | UIDropDownMenu_AddButton(info); |
||
140 | |||
141 | info = {}; |
||
142 | info.text = TITAN_XP_MENU_SHOW_XPHR_THIS_LEVEL; |
||
143 | info.func = TitanPanelXPButton_ShowXPPerHourLevel |
||
144 | info.checked = TitanUtils_Toggle(TitanGetVar(TITAN_XP_ID, "ShowXPPerHourSession")); |
||
145 | UIDropDownMenu_AddButton(info); |
||
146 | |||
147 | TitanPanelRightClickMenu_AddSpacer(); |
||
148 | TitanPanelRightClickMenu_AddCommand(TITAN_XP_MENU_RESET_SESSION, TITAN_XP_ID, "TitanPanelXPButton_ResetSession"); |
||
149 | |||
150 | TitanPanelRightClickMenu_AddSpacer(); |
||
151 | TitanPanelRightClickMenu_AddToggleIcon(TITAN_XP_ID); |
||
152 | TitanPanelRightClickMenu_AddToggleLabelText(TITAN_XP_ID); |
||
153 | |||
154 | TitanPanelRightClickMenu_AddSpacer(); |
||
155 | TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_XP_ID, TITAN_PANEL_MENU_FUNC_HIDE); |
||
156 | end |
||
157 | |||
158 | function TitanPanelXPButton_ShowXPPerHourSession() |
||
159 | TitanSetVar(TITAN_XP_ID, "ShowXPPerHourSession", 1); |
||
160 | TitanPanelButton_UpdateButton(TITAN_XP_ID); |
||
161 | end |
||
162 | |||
163 | function TitanPanelXPButton_ShowXPPerHourLevel() |
||
164 | TitanSetVar(TITAN_XP_ID, "ShowXPPerHourSession", nil); |
||
165 | TitanPanelButton_UpdateButton(TITAN_XP_ID); |
||
166 | end |
||
167 | |||
168 | function TitanPanelXPButton_ResetSession() |
||
169 | TitanPanelXPButton.initXP = UnitXP("player"); |
||
170 | TitanPanelXPButton.accumXP = 0; |
||
171 | TitanPanelXPButton.sessionXP = 0; |
||
172 | TitanPanelXPButton.startSessionTime = TitanUtils_GetSessionTime(); |
||
173 | end |