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