vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- Constants |
2 | TITAN_PANEL_UPDATE_BUTTON = 1; |
||
3 | TITAN_PANEL_UDPATE_TOOLTIP = 2; |
||
4 | TITAN_PANEL_UPDATE_ALL = 3; |
||
5 | TITAN_PANEL_LABEL_SEPARATOR = " " |
||
6 | |||
7 | TITAN_PANEL_BUTTON_TYPE_TEXT = 1; |
||
8 | TITAN_PANEL_BUTTON_TYPE_ICON = 2; |
||
9 | TITAN_PANEL_BUTTON_TYPE_COMBO = 3; |
||
10 | TITAN_PANEL_BUTTON_TYPE_CUSTOM = 4; |
||
11 | |||
12 | TITAN_RIDER_ID = "Rider"; |
||
13 | TITAN_RIDER_FREQUENCY = 1; |
||
14 | TITAN_RIDER_ATTACKBUTTON = 0; |
||
15 | |||
16 | TITAN_RIDER_IS_MOUNTED = false; |
||
17 | TITAN_DOUBLE_CHECK = false; |
||
18 | |||
19 | TITAN_RIDER_LOCALE = { |
||
20 | menu = "Rider", |
||
21 | tooltip = "Rider", |
||
22 | button = "Rider" |
||
23 | }; |
||
24 | |||
25 | CURRENTSTATE = TitanGetVar(TITAN_RIDER_ID,"PlayerState"); |
||
26 | |||
27 | function TitanPanelRiderButton_OnLoad() |
||
28 | -- register plugin |
||
29 | this.registry = { |
||
30 | id = TITAN_RIDER_ID, |
||
31 | builtIn = 1, |
||
32 | menuText = TITAN_RIDER_LOCALE["menu"], |
||
33 | buttonTextFunction = "TitanPanelRiderButton_GetButtonText", |
||
34 | tooltipTitle = TITAN_RIDER_LOCALE["tooltip"], |
||
35 | tooltipTextFunction = "TitanPanelRiderButton_GetTooltipText", |
||
36 | frequency = TITAN_RIDER_FREQUENCY, |
||
37 | icon = "Interface\\AddOns\\Titan\\Artwork\\TitanRider", |
||
38 | iconWidth = 16, |
||
39 | savedVariables = { |
||
40 | ShowIcon = 1, |
||
41 | ShowLabelText = 1, |
||
42 | ShowColoredText = TITAN_NIL, |
||
43 | ShowState = 1, |
||
44 | PlayerState = 1, |
||
45 | EquipItems = 1, |
||
46 | RiderItems = {"FeetSlot","Trinket0Slot","HandsSlot"} |
||
47 | } |
||
48 | }; |
||
49 | this:RegisterEvent("VARIABLES_LOADED") -- configuration loading |
||
50 | this:RegisterEvent("PLAYER_AURAS_CHANGED") -- mount buff check |
||
51 | this:RegisterEvent("ACTIONBAR_UPDATE_USABLE") -- flight path check |
||
52 | this:RegisterEvent("PLAYER_REGEN_DISABLED") -- combat check |
||
53 | this:RegisterEvent("PLAYER_REGEN_ENABLED") -- combat check |
||
54 | this:RegisterEvent("DELETE_ITEM_CONFIRM") -- delete check |
||
55 | this:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
56 | this:RegisterEvent("PLAYER_UNGHOST"); |
||
57 | |||
58 | end |
||
59 | |||
60 | function TitanPanelRiderButton_GetButtonText(id) |
||
61 | local retstr = ""; |
||
62 | |||
63 | -- Check for inflight option |
||
64 | if UnitOnTaxi("player") == 1 then |
||
65 | TitanSetVar(TITAN_RIDER_ID,"PlayerState",3); |
||
66 | if CURRENTSTATE ~= TitanGetVar(TITAN_RIDER_ID,"PlayerState") then |
||
67 | CURRENTSTATE = TitanGetVar(TITAN_RIDER_ID,"PlayerState"); |
||
68 | end |
||
69 | end |
||
70 | |||
71 | -- supports turning off labels |
||
72 | if (TitanGetVar(TITAN_RIDER_ID, "ShowLabelText")) then |
||
73 | retstr = TITAN_RIDER_LOCALE["button"]; |
||
74 | if TitanGetVar(TITAN_RIDER_ID,"ShowState") then |
||
75 | retstr = retstr .. ": "; |
||
76 | end |
||
77 | end |
||
78 | |||
79 | if TitanGetVar(TITAN_RIDER_ID,"ShowState") then |
||
80 | if (TitanGetVar(TITAN_RIDER_ID, "ShowColoredText")) then |
||
81 | retstr = retstr .. TitanUtils_GetGreenText(TITAN_RIDER_STATES[TitanGetVar(TITAN_RIDER_ID,"PlayerState")]); |
||
82 | else |
||
83 | retstr = retstr .. TitanUtils_GetNormalText(TITAN_RIDER_STATES[TitanGetVar(TITAN_RIDER_ID,"PlayerState")]); |
||
84 | end |
||
85 | end |
||
86 | |||
87 | -- This is a double check to ENSURE all riding equipment is removed as there are cases it will skip or miss the equip swap |
||
88 | local EquipGear = 0; |
||
89 | if TITAN_RIDER_IS_MOUNTED == false and combat_flag == false and TITAN_DOUBLE_CHECK == true then |
||
90 | TitanRider_SwitchGear() |
||
91 | end |
||
92 | |||
93 | return retstr; |
||
94 | end |
||
95 | |||
96 | function TitanPanelRiderButton_GetTooltipText() |
||
97 | local retstr = ""; |
||
98 | retstr = retstr .. TitanUtils_GetGreenText(TITAN_RIDER_HINT..TITAN_RIDER_STATES[TitanGetVar(TITAN_RIDER_ID,"PlayerState")]); |
||
99 | return retstr; |
||
100 | end |
||
101 | |||
102 | function TitanPanelRightClickMenu_PrepareRiderMenu() |
||
103 | TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_RIDER_ID].menuText); |
||
104 | |||
105 | TitanPanelRightClickMenu_AddSpacer(); |
||
106 | |||
107 | TitanPanelRightClickMenu_AddToggleIcon(TITAN_RIDER_ID); |
||
108 | TitanPanelRightClickMenu_AddToggleLabelText(TITAN_RIDER_ID); |
||
109 | TitanPanelRightClickMenu_AddToggleColoredText(TITAN_RIDER_ID); |
||
110 | |||
111 | info = {}; |
||
112 | info.text = TITAN_RIDER_OPTIONS_SHOWSTATE; |
||
113 | info.func = TitanRider_StateToggle; |
||
114 | info.value = TITAN_RIDER_OPTIONS_SHOWSTATE; |
||
115 | info.checked = TitanGetVar(TITAN_RIDER_ID,"ShowState"); |
||
116 | UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL); |
||
117 | |||
118 | info = {}; |
||
119 | info.text = TITAN_RIDER_OPTIONS_EQUIP; |
||
120 | info.func = TitanRider_EquipToggle; |
||
121 | info.value = TITAN_RIDER_OPTIONS_EQUIP; |
||
122 | info.checked = TitanGetVar(TITAN_RIDER_ID,"EquipItems"); |
||
123 | UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL); |
||
124 | |||
125 | info = {}; |
||
126 | TitanPanelRightClickMenu_AddSpacer(); |
||
127 | TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_RIDER_ID, TITAN_PANEL_MENU_FUNC_HIDE); |
||
128 | end |
||
129 | |||
130 | function TitalPanelRiderButton_OnClick(button) |
||
131 | if ( button == "LeftButton" ) then |
||
132 | --Nothing so far |
||
133 | end |
||
134 | end |
||
135 | |||
136 | function TitanPanelRiderButton_OnEvent() |
||
137 | local shown = TitanPanel_IsPluginShown(TITAN_RIDER_ID); |
||
138 | |||
139 | if shown == nil then |
||
140 | shown = 0; |
||
141 | end |
||
142 | |||
143 | |||
144 | if(event == "VARIABLES_LOADED") then |
||
145 | combat_flag = false; |
||
146 | end |
||
147 | |||
148 | if event == "PLAYER_REGEN_DISABLED" then |
||
149 | combat_flag = true |
||
150 | end |
||
151 | |||
152 | if event == "PLAYER_REGEN_ENABLED" then |
||
153 | combat_flag = false |
||
154 | end |
||
155 | |||
156 | if event == "PLAYER_ENTERING_WORLD" then |
||
157 | combat_flag = false |
||
158 | end |
||
159 | |||
160 | if event == "PLAYER_UNGHOST" then |
||
161 | combat_flag = false |
||
162 | end |
||
163 | |||
164 | if shown > 0 and TitanGetVar(TITAN_RIDER_ID,"EquipItems") then |
||
165 | if combat_flag == false then |
||
166 | TitanSetVar(TITAN_RIDER_ID,"PlayerState",TitanRider_PlayerMounted()); |
||
167 | if CURRENTSTATE ~= TitanGetVar(TITAN_RIDER_ID,"PlayerState") then |
||
168 | CURRENTSTATE = TitanGetVar(TITAN_RIDER_ID,"PlayerState"); |
||
169 | if TitanGetVar(TITAN_RIDER_ID,"PlayerState") ~= 3 then |
||
170 | TitanRider_SwitchGear(); |
||
171 | end |
||
172 | end |
||
173 | end |
||
174 | end |
||
175 | end |
||
176 | |||
177 | function TitanRider_StateToggle() |
||
178 | TitanToggleVar(TITAN_RIDER_ID, "ShowState"); |
||
179 | end |
||
180 | |||
181 | function TitanRider_EquipToggle() |
||
182 | TitanToggleVar(TITAN_RIDER_ID, "EquipItems"); |
||
183 | end |
||
184 | |||
185 | function TitanRider_PlayerMounted() |
||
186 | local playerClass = UnitClass("player"); |
||
187 | TITAN_DOUBLE_CHECK = false; |
||
188 | |||
189 | for i = 1,16 do |
||
190 | local buff_texture = UnitBuff("player", i) |
||
191 | local debuff_texture = UnitDebuff("player", i) |
||
192 | if debuff_texture and string.find(debuff_texture, "Polymorph") then |
||
193 | TITAN_RIDER_IS_MOUNTED = false; |
||
194 | return 4; |
||
195 | end |
||
196 | if playerClass == "Paladin" or playerClass == "Warlock" then |
||
197 | if buff_texture and string.find(buff_texture, "Spell_Nature_Swiftness") then |
||
198 | TITAN_RIDER_IS_MOUNTED = true; |
||
199 | TITAN_DOUBLE_CHECK = true; |
||
200 | return 2; |
||
201 | end |
||
202 | end |
||
203 | if buff_texture and ( string.find(buff_texture, "Mount") or string.find(buff_texture, "Foot_Kodo") or ( detectedIcon ~= nil and string.find(buff_texture, detectedIcon) ) ) then |
||
204 | -- Make sure it isn't "Aspect of the xxx" or "Tiger's Fury" |
||
205 | local BuffName = TitanRider_GetBuffName(i); |
||
206 | local Skip = false; |
||
207 | if BuffName and ( string.find(BuffName, "Aspect") or string.find(BuffName, "Aspekt") or string.find(BuffName, "Tiger's Fury") ) then |
||
208 | Skip = true |
||
209 | end |
||
210 | if Skip == false then |
||
211 | TITAN_RIDER_IS_MOUNTED = true; |
||
212 | TITAN_DOUBLE_CHECK = true; |
||
213 | return 2; |
||
214 | end |
||
215 | end |
||
216 | end |
||
217 | |||
218 | TITAN_RIDER_IS_MOUNTED = false; |
||
219 | return 1; |
||
220 | |||
221 | end |
||
222 | |||
223 | function TitanRider_GetBuffName(buffIndex) |
||
224 | local x, y = GetPlayerBuff(buffIndex, "HELPFUL"); |
||
225 | TitanRiderTooltip:SetUnitBuff("player", buffIndex); |
||
226 | local Bname = TitanRiderTooltipTextLeft1:GetText(); |
||
227 | |||
228 | if ( Bname ~= nil ) then |
||
229 | return Bname; |
||
230 | end |
||
231 | return nil; |
||
232 | end |
||
233 | |||
234 | function TitanRider_SwitchGear() |
||
235 | if (TITAN_RIDER_IS_MOUNTED) then |
||
236 | TitanRider_EquipRidingGear(); |
||
237 | else |
||
238 | if (UnitHealth ("player") > 1) then |
||
239 | TitanRider_RemoveRidingGear(); |
||
240 | end |
||
241 | end |
||
242 | end |
||
243 | |||
244 | function TitanRider_EquipRidingGear() |
||
245 | local EquipGear = 0; |
||
246 | for EquipGear = 1, TITAN_RIDER_ITEMS do |
||
247 | --if (TitanGetVarTable(TITAN_RIDER_ID,"RiderItems",EquipGear) == TITAN_RIDER_ITEM_SLOTS[EquipGear] or TitanGetVarTable(TITAN_RIDER_ID,"RiderItems",EquipGear) == "-none-") then |
||
248 | local bagNum, itemInBagNum = TitanRider_FindInventoryItemWithText(TITAN_RIDER_ITEM_NAMES[EquipGear], TITAN_RIDER_ITEM_DESCS[EquipGear]); |
||
249 | |||
250 | if (bagNum ~= nil) then |
||
251 | local newItemLink = GetContainerItemLink (bagNum, itemInBagNum); |
||
252 | local normalItemLink = GetInventoryItemLink("player", GetInventorySlotInfo(TITAN_RIDER_ITEM_SLOTS[EquipGear])); |
||
253 | |||
254 | if (normalItemLink ~= nil) then |
||
255 | local gearBagNum, gearItemInBagNum, tempstr; |
||
256 | |||
257 | _, _, tempstr = string.find (normalItemLink, "%[(.+)%]"); |
||
258 | TitanSetVarTable(TITAN_RIDER_ID,"RiderItems", EquipGear, tempstr); |
||
259 | else |
||
260 | TitanSetVarTable(TITAN_RIDER_ID,"RiderItems", EquipGear, "-none-"); |
||
261 | end |
||
262 | if (CursorHasItem()) then PickupSpell(1, "spell"); end |
||
263 | PickupContainerItem (bagNum, itemInBagNum); |
||
264 | AutoEquipCursorItem(); |
||
265 | else |
||
266 | TitanSetVarTable(TITAN_RIDER_ID,"RiderItems",EquipGear,"-none-"); |
||
267 | end |
||
268 | --end |
||
269 | end |
||
270 | end |
||
271 | |||
272 | function TitanRider_RemoveRidingGear() |
||
273 | local EquipGear = 0; |
||
274 | for EquipGear = 1, TITAN_RIDER_ITEMS do |
||
275 | if (TitanGetVarTable(TITAN_RIDER_ID,"RiderItems",EquipGear) ~= TITAN_RIDER_ITEM_SLOTS[EquipGear]) then |
||
276 | local bagNum, itemInBagNum = TitanRider_FindInventoryItemWithText(TitanGetVarTable(TITAN_RIDER_ID,"RiderItems",EquipGear)); |
||
277 | |||
278 | if (bagNum ~= nil) then |
||
279 | local normalItemLink = GetContainerItemLink(bagNum, itemInBagNum); |
||
280 | if (CursorHasItem()) then PickupSpell(1, "spell"); end |
||
281 | PickupContainerItem (bagNum, itemInBagNum); |
||
282 | AutoEquipCursorItem(); |
||
283 | end |
||
284 | local newItemLink = GetInventoryItemLink("player", GetInventorySlotInfo(TITAN_RIDER_ITEM_SLOTS[EquipGear])); |
||
285 | if newItemLink == normalItemLink then |
||
286 | TitanSetVarTable(TITAN_RIDER_ID,"RiderItems",EquipGear,TITAN_RIDER_ITEM_SLOTS[EquipGear]); |
||
287 | TITAN_DOUBLE_CHECK = false; |
||
288 | end |
||
289 | end |
||
290 | end |
||
291 | end |
||
292 | |||
293 | function TitanRider_FindInventoryItemWithText(name, description) |
||
294 | local bagNum; |
||
295 | |||
296 | TitanRiderTooltip:SetOwner(UIParent, "ANCHOR_NONE"); |
||
297 | for bagNum = 0, 4 do |
||
298 | local itemInBagNum; |
||
299 | for itemInBagNum = 1, GetContainerNumSlots (bagNum) do |
||
300 | local i; |
||
301 | local text = TitanRider_GetItemName(bagNum, itemInBagNum); |
||
302 | --Loop through tooltip |
||
303 | for i = 1, 15, 1 do |
||
304 | local field = getglobal("TitanRiderTooltipTextLeft" .. i); |
||
305 | if (field ~= nil) then |
||
306 | local text = field:GetText(); |
||
307 | if (i == 1) then |
||
308 | if ((name ~= nil) and (text ~= name)) then |
||
309 | break; |
||
310 | else |
||
311 | if (description == nil) then |
||
312 | return bagNum, itemInBagNum; |
||
313 | end |
||
314 | end |
||
315 | else |
||
316 | if (text == description) then |
||
317 | return bagNum, itemInBagNum; |
||
318 | end |
||
319 | end |
||
320 | end |
||
321 | end |
||
322 | end |
||
323 | end |
||
324 | return nil; |
||
325 | end |
||
326 | |||
327 | function TitanRider_GetItemName(bag, slot) |
||
328 | local bagNumber = bag; |
||
329 | local name = ""; |
||
330 | if ( type(bagNumber) ~= "number" ) then |
||
331 | bagNumber = tonumber(bag); |
||
332 | end |
||
333 | TitanRiderTooltip:SetBagItem(bag, slot); |
||
334 | name = TitanRiderTooltipTextLeft1:GetText(); |
||
335 | if name == nil then |
||
336 | name = ""; |
||
337 | end |
||
338 | return name; |
||
339 | end |