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_STANCESETS_ID = "StanceSets"; |
||
13 | TITAN_STANCESETS_FREQUENCY = 1; |
||
14 | |||
15 | STANCESET_INDEX = 0; |
||
16 | STANCESET_MAX_STANCES = 5 |
||
17 | |||
18 | BINDING_HEADER_STANCESETS = "Stance Sets" |
||
19 | BINDING_NAME_TOGGLESTANCESETSDLG = "Toggle Configuration Pane"; |
||
20 | BINDING_NAME_STANCESETNEXT = "Equip Next Weapon Set"; |
||
21 | |||
22 | StanceSetsOptions = {}; |
||
23 | |||
24 | --UIPanelWindows["StanceSetsFrame"] = { area = "left", pushable = 5 }; |
||
25 | |||
26 | function TitanOptionSlider_TooltipText(text, value) |
||
27 | return text .. GREEN_FONT_COLOR_CODE .. value .. FONT_COLOR_CODE_CLOSE; |
||
28 | end |
||
29 | |||
30 | function TitanPanelStanceSetsButton_OnLoad() |
||
31 | this:RegisterEvent("VARIABLES_LOADED"); |
||
32 | -- register plugin |
||
33 | this.registry = { |
||
34 | id = TITAN_STANCESETS_ID, |
||
35 | menuText = STANCESETS_LOCALE["menu"], |
||
36 | buttonTextFunction = "TitanPanelStanceSetsButton_GetButtonText", |
||
37 | tooltipTitle = STANCESETS_LOCALE["tooltip"], |
||
38 | tooltipTextFunction = "TitanPanelStanceSetsButton_GetTooltipText", |
||
39 | frequency = TITAN_STANCESETS_FREQUENCY, |
||
40 | icon = "Interface\\Icons\\Ability_Warrior_ShieldWall", |
||
41 | iconWidth = 16, |
||
42 | savedVariables = { |
||
43 | ShowIcon = 1, |
||
44 | ShowLabelText = 1, |
||
45 | ShowColoredText = TITAN_NIL |
||
46 | } |
||
47 | }; |
||
48 | |||
49 | end |
||
50 | |||
51 | function TitanPanelStanceSetsButton_OnEvent() |
||
52 | if(event == "VARIABLES_LOADED") then |
||
53 | if (StanceSetsOptions.StanceSetsLocked == nil) then |
||
54 | StanceSetsOptions.StanceSetsLocked = false; |
||
55 | end |
||
56 | if (StanceSetsOptions.ShowStance == nil) then |
||
57 | StanceSetsOptions.ShowStance = true; |
||
58 | end |
||
59 | end |
||
60 | end |
||
61 | |||
62 | function TitanPanelStanceSetsButton_GetButtonText(id) |
||
63 | local retstr = ""; |
||
64 | |||
65 | -- supports turning off labels |
||
66 | if (TitanGetVar(TITAN_STANCESETS_ID, "ShowLabelText")) then |
||
67 | if (StanceSetsOptions.ShowStance) then |
||
68 | retstr = STANCESETS_LOCALE["button"]; |
||
69 | else |
||
70 | retstr = STANCESETS_LOCALE["cbutton"]; |
||
71 | end |
||
72 | end |
||
73 | |||
74 | if (StanceSetsOptions.ShowStance) then |
||
75 | if (TitanGetVar(TITAN_STANCESETS_ID, "ShowColoredText")) then |
||
76 | retstr = retstr .. TitanUtils_GetGreenText(StanceSets_GetCurrentForm()); |
||
77 | else |
||
78 | retstr = retstr .. TitanUtils_GetNormalText(StanceSets_GetCurrentForm()); |
||
79 | end |
||
80 | end |
||
81 | |||
82 | return retstr; |
||
83 | end |
||
84 | |||
85 | function TitanPanelStanceSetsButton_GetTooltipText() |
||
86 | local retstr = TitanUtils_GetGreenText("Hint: Left click to open Stance Sets"); |
||
87 | return retstr; |
||
88 | end |
||
89 | |||
90 | function TitanPanelRightClickMenu_PrepareStanceSetsMenu() |
||
91 | TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_STANCESETS_ID].menuText); |
||
92 | info = {}; |
||
93 | info.text = ATLAS_OPTIONS_SHOWSTANCE; |
||
94 | info.func = StanceSetOptions_ShowStanceToggle; |
||
95 | info.value = ATLAS_OPTIONS_SHOWSTANCE; |
||
96 | info.checked = StanceSetsOptions.ShowStance; |
||
97 | UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL); |
||
98 | |||
99 | info = {}; |
||
100 | |||
101 | TitanPanelRightClickMenu_AddSpacer(); |
||
102 | TitanPanelRightClickMenu_AddToggleIcon(TITAN_STANCESETS_ID); |
||
103 | TitanPanelRightClickMenu_AddToggleLabelText(TITAN_STANCESETS_ID); |
||
104 | TitanPanelRightClickMenu_AddToggleColoredText(TITAN_STANCESETS_ID); |
||
105 | |||
106 | TitanPanelRightClickMenu_AddSpacer(); |
||
107 | TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_STANCESETS_ID, TITAN_PANEL_MENU_FUNC_HIDE); |
||
108 | end |
||
109 | |||
110 | function TitalPanelStanceSetsButton_OnClick(button) |
||
111 | if ( button == "LeftButton" ) then |
||
112 | StanceSets_Toggle(); |
||
113 | end |
||
114 | end |
||
115 | |||
116 | function StanceSetOptions_ShowStanceToggle() |
||
117 | if(StanceSetsOptions.ShowStance) then |
||
118 | StanceSetsOptions.ShowStance = false; |
||
119 | else |
||
120 | StanceSetsOptions.ShowStance = true; |
||
121 | end |
||
122 | end |
||
123 | |||
124 | function StanceSets_StartMoving() |
||
125 | if(not StanceSetsOptions.StanceSetsLocked) then |
||
126 | StanceSetsFrame:StartMoving(); |
||
127 | end |
||
128 | end |
||
129 | |||
130 | function StanceSets_ToggleLock() |
||
131 | if(StanceSetsOptions.StanceSetsLocked) then |
||
132 | StanceSetsOptions.StanceSetsLocked = false; |
||
133 | StanceSets_UpdateLock(); |
||
134 | else |
||
135 | StanceSetsOptions.StanceSetsLocked = true; |
||
136 | StanceSets_UpdateLock(); |
||
137 | end |
||
138 | end |
||
139 | |||
140 | function StanceSets_UpdateLock() |
||
141 | if(StanceSetsOptions.StanceSetsLocked) then |
||
142 | StanceSetsLockNorm:SetTexture("Interface\\AddOns\\Titan\\TitanStanceSets\\Images\\LockButton-Locked-Up"); |
||
143 | StanceSetsLockPush:SetTexture("Interface\\AddOns\\Titan\\TitanStanceSets\\Images\\LockButton-Locked-Down"); |
||
144 | else |
||
145 | StanceSetsLockNorm:SetTexture("Interface\\AddOns\\Titan\\TitanStanceSets\\Images\\LockButton-Unlocked-Up"); |
||
146 | StanceSetsLockPush:SetTexture("Interface\\AddOns\\Titan\\TitanStanceSets\\Images\\LockButton-Unlocked-Down"); |
||
147 | end |
||
148 | end |
||
149 | |||
150 | function StanceSets_OnLoad() |
||
151 | this:RegisterEvent("UPDATE_BONUS_ACTIONBAR"); |
||
152 | this:RegisterEvent("SPELLS_CHANGED"); |
||
153 | this:RegisterEvent("VARIABLES_LOADED"); |
||
154 | |||
155 | tinsert(UISpecialFrames, "StanceSetsFrame"); |
||
156 | UIPanelWindows["StanceSetsFrame"] = nil; |
||
157 | StanceSetsFrame:RegisterForDrag("LeftButton"); |
||
158 | SlashCmdList["STANCESETS"] = StanceSets_SlashCmd; |
||
159 | SLASH_STANCESETS1 = "/stancesets"; |
||
160 | |||
161 | StanceSets = { }; |
||
162 | end |
||
163 | |||
164 | function StanceSets_OnShow() |
||
165 | return StanceSets_UpdateAllStances(); |
||
166 | end |
||
167 | |||
168 | function StanceSets_OnEvent(event, arg1) |
||
169 | if event == "UPDATE_BONUS_ACTIONBAR" then |
||
170 | return StanceSets_FormChanged(); |
||
171 | elseif event == "SPELLS_CHANGED" then |
||
172 | return StanceSets_SpellsChanged(); |
||
173 | elseif event == "VARIABLES_LOADED" then |
||
174 | StanceSets_UpdateLock(); |
||
175 | end |
||
176 | end |
||
177 | |||
178 | function StanceSets_SlashCmd(cmd) |
||
179 | if cmd and cmd == "next" then |
||
180 | return StanceSets_Next(); |
||
181 | end |
||
182 | |||
183 | return StanceSets_Toggle(); |
||
184 | end |
||
185 | |||
186 | function StanceSets_Toggle() |
||
187 | if StanceSetsFrame:IsVisible() then |
||
188 | HideUIPanel(StanceSetsFrame); |
||
189 | else |
||
190 | ShowUIPanel(StanceSetsFrame); |
||
191 | end |
||
192 | end |
||
193 | |||
194 | function StanceSets_SpellsChanged() |
||
195 | -- Spells have changed, this may mean that we've got a new shapeshift form |
||
196 | if StanceSetsFrame:IsVisible() then |
||
197 | return StanceSets_UpdateAllStances(); |
||
198 | end |
||
199 | end |
||
200 | |||
201 | function StanceSet_SetButtonTextureAndName(suffix,texture,itemName) |
||
202 | local btn = getglobal("StanceSetsFrameSet"..suffix); |
||
203 | if btn then |
||
204 | SetItemButtonTexture(btn, texture); |
||
205 | btn.itemName = itemName; |
||
206 | end |
||
207 | end |
||
208 | |||
209 | function StanceSet_FindAndSetButtonTexture(suffix, itemName) |
||
210 | if itemName and itemName ~= "" then |
||
211 | local bag, slot = WeaponQuickSwap_FindItem(itemName); |
||
212 | if bag and slot then |
||
213 | local texture; |
||
214 | if bag == -1 then |
||
215 | texture = GetInventoryItemTexture("player", slot); |
||
216 | else |
||
217 | texture = GetContainerItemInfo(bag, slot); |
||
218 | end |
||
219 | StanceSet_SetButtonTextureAndName(suffix, texture, itemName); |
||
220 | else |
||
221 | -- if not found, just use a generic icon |
||
222 | StanceSet_SetButtonTextureAndName(suffix, "Interface\\Icons\\INV_Misc_Gift_01", itemName); |
||
223 | end |
||
224 | else |
||
225 | -- no item name, no icon |
||
226 | StanceSet_SetButtonTextureAndName(suffix, nil, itemName); |
||
227 | end |
||
228 | end |
||
229 | |||
230 | function StanceSets_UpdateAllStances() |
||
231 | local allstances = StanceSets_GetAllForms(); |
||
232 | |||
233 | for i=1,STANCESET_MAX_STANCES do |
||
234 | local stanceName = allstances[i]; |
||
235 | local frameStance = getglobal("StanceSetsFrameSet"..i); |
||
236 | local frameLabel = getglobal("StanceSetsFrameSet"..i.."Title"); |
||
237 | |||
238 | if frameStance then |
||
239 | local chkForceFirst = getglobal(frameStance:GetName().."ForceFirst"); |
||
240 | |||
241 | if stanceName then |
||
242 | frameStance.StanceName = stanceName; |
||
243 | |||
244 | frameStance:Show(); |
||
245 | if frameLabel then frameLabel:SetText(stanceName); end |
||
246 | |||
247 | local playerName = UnitName("player"); |
||
248 | local setName = playerName.."_"..stanceName; |
||
249 | local stanceSet = StanceSets[setName]; |
||
250 | |||
251 | if StanceSets[setName.."_ForceFirst"] then |
||
252 | chkForceFirst:SetChecked(1); |
||
253 | else |
||
254 | chkForceFirst:SetChecked(nil); |
||
255 | end |
||
256 | |||
257 | if stanceSet then |
||
258 | StanceSet_FindAndSetButtonTexture(i.."MainHand1", stanceSet[1]); |
||
259 | StanceSet_FindAndSetButtonTexture(i.."OffHand1", stanceSet[2]); |
||
260 | StanceSet_FindAndSetButtonTexture(i.."MainHand2", stanceSet[3]); |
||
261 | StanceSet_FindAndSetButtonTexture(i.."OffHand2", stanceSet[4]); |
||
262 | StanceSet_FindAndSetButtonTexture(i.."MainHand3", stanceSet[5]); |
||
263 | StanceSet_FindAndSetButtonTexture(i.."OffHand3", stanceSet[6]); |
||
264 | else |
||
265 | StanceSet_SetButtonTextureAndName(i.."MainHand1", nil, nil); |
||
266 | StanceSet_SetButtonTextureAndName(i.."OffHand1", nil, nil); |
||
267 | StanceSet_SetButtonTextureAndName(i.."MainHand2", nil, nil); |
||
268 | StanceSet_SetButtonTextureAndName(i.."OffHand2", nil, nil); |
||
269 | StanceSet_SetButtonTextureAndName(i.."MainHand3", nil, nil); |
||
270 | StanceSet_SetButtonTextureAndName(i.."OffHand3", nil, nil); |
||
271 | end |
||
272 | else |
||
273 | frameStance:Hide(); |
||
274 | end |
||
275 | end -- if frame found |
||
276 | end -- for i 1,MAX |
||
277 | end |
||
278 | |||
279 | function StanceSets_GetCurrentStanceSet() |
||
280 | if not StanceSets then return end |
||
281 | |||
282 | local currentForm = StanceSets_GetCurrentForm(); |
||
283 | local playerName = UnitName("player"); |
||
284 | |||
285 | if not playerName then return; end -- player name might not be defined if not logged yet |
||
286 | |||
287 | local setName = playerName.."_"..currentForm; |
||
288 | return StanceSets[setName], setName; |
||
289 | end |
||
290 | |||
291 | function StanceSets_Next() |
||
292 | local playerFormSet = StanceSets_GetCurrentStanceSet(); |
||
293 | if playerFormSet then |
||
294 | for i = 1,6 do |
||
295 | if not playerFormSet[i] and playerFormSet[i+1] then |
||
296 | playerFormSet[i] = ""; |
||
297 | end |
||
298 | end |
||
299 | |||
300 | return WeaponSwap(unpack(playerFormSet)); |
||
301 | end |
||
302 | end |
||
303 | |||
304 | function StanceSets_FormChanged() |
||
305 | local playerFormSet, setName = StanceSets_GetCurrentStanceSet(); |
||
306 | if playerFormSet then |
||
307 | if StanceSets[setName.."_ForceFirst"] then |
||
308 | -- must have at least one thing to do a swap |
||
309 | if playerFormSet[1] or playerFormSet[2] then |
||
310 | return WeaponSwap(playerFormSet[1], playerFormSet[2]); |
||
311 | end |
||
312 | elseif table.getn(playerFormSet) > 0 then |
||
313 | -- If not forcing a set, only swap if we don't already a known set currently engaged |
||
314 | local matchingsetidx = WeaponQuickSwap_FindCurrentSetIndex(16, 17, 1, playerFormSet); |
||
315 | if not matchingsetidx then |
||
316 | return WeaponSwap(unpack(playerFormSet)); |
||
317 | end |
||
318 | end |
||
319 | end |
||
320 | end |
||
321 | |||
322 | function StanceSets_GetCurrentForm() |
||
323 | for i=1,GetNumShapeshiftForms(),1 do |
||
324 | local _, name, isActive = GetShapeshiftFormInfo(i); |
||
325 | if isActive then |
||
326 | return name; |
||
327 | end |
||
328 | end |
||
329 | |||
330 | return "Default"; |
||
331 | end |
||
332 | |||
333 | function StanceSets_GetAllForms() |
||
334 | local retVal = { }; |
||
335 | table.insert(retVal, "Default"); |
||
336 | for i=1,GetNumShapeshiftForms() do |
||
337 | local _, name = GetShapeshiftFormInfo(i); |
||
338 | table.insert(retVal, name); |
||
339 | end |
||
340 | |||
341 | return retVal; |
||
342 | end |
||
343 | |||
344 | function StanceSetSlot_OnEnter() |
||
345 | if this.itemName and this.itemName ~= "" then |
||
346 | GameTooltip:SetOwner(this, "ANCHOR_RIGHT"); |
||
347 | |||
348 | local bag,slot = WeaponQuickSwap_FindItem(this.itemName); |
||
349 | if bag and slot then |
||
350 | if bag == -1 then |
||
351 | GameTooltip:SetInventoryItem("player", slot); |
||
352 | else |
||
353 | GameTooltip:SetBagItem(bag,slot); |
||
354 | end |
||
355 | else |
||
356 | GameTooltip:SetText(this.itemName, 1.0, 1.0, 1.0); |
||
357 | end |
||
358 | |||
359 | GameTooltip:Show(); |
||
360 | end |
||
361 | end |
||
362 | |||
363 | function StanceSetSlot_IDToSlotID(id) |
||
364 | if id == 1 or id == 3 or id == 5 then |
||
365 | return 16; |
||
366 | else |
||
367 | return 17; |
||
368 | end |
||
369 | end |
||
370 | |||
371 | function StanceSetSlot_OnDragStart() |
||
372 | local frmParent = this:GetParent(); |
||
373 | local playerName = UnitName("player"); |
||
374 | local setName = playerName.."_"..frmParent.StanceName; |
||
375 | |||
376 | local stanceSet = StanceSets[setName]; |
||
377 | if stanceSet then |
||
378 | stanceSet[this:GetID()] = nil; |
||
379 | ResetCursor(); |
||
380 | StanceSets_UpdateAllStances(); |
||
381 | end |
||
382 | end |
||
383 | |||
384 | function StanceSetSlot_TakeItemOffCursor(srcBag, srcSlot) |
||
385 | if srcBag == -1 then |
||
386 | PickupInventoryItem(srcSlot); |
||
387 | else |
||
388 | PickupContainerItem(srcBag, srcSlot); |
||
389 | end |
||
390 | end |
||
391 | |||
392 | function StanceSetSlot_OnReceiveDrag() |
||
393 | StanceSetSlot_OnClick("LeftButton"); |
||
394 | end |
||
395 | |||
396 | function StanceSetSlot_OnClick(arg1) |
||
397 | local slotID = StanceSetSlot_IDToSlotID(this:GetID()); |
||
398 | |||
399 | arg1 = arg1 or ""; |
||
400 | if arg1 == "LeftButton" then |
||
401 | if CursorHasItem() and StanceSets_PickedupItem then |
||
402 | local itemName = WeaponQuickSwap_GetItemName(StanceSets_PickedupItem.bag, |
||
403 | StanceSets_PickedupItem.slot); |
||
404 | |||
405 | if CursorCanGoInSlot(slotID) then |
||
406 | local frmParent = this:GetParent(); |
||
407 | local playerName = UnitName("player"); |
||
408 | local setName = playerName.."_"..frmParent.StanceName; |
||
409 | |||
410 | local stanceSet = StanceSets[setName]; |
||
411 | if not stanceSet then stanceSet = {}; end |
||
412 | stanceSet[this:GetID()] = itemName; |
||
413 | StanceSets[setName] = stanceSet; |
||
414 | |||
415 | StanceSets_UpdateAllStances(); |
||
416 | else |
||
417 | Print(itemName.." can not go in that slot!"); |
||
418 | end |
||
419 | |||
420 | ResetCursor(); |
||
421 | StanceSetSlot_TakeItemOffCursor(StanceSets_PickedupItem.bag,StanceSets_PickedupItem.slot); |
||
422 | end -- if has item and we know where it came from |
||
423 | |||
424 | StanceSets_PickedupItem = nil; |
||
425 | end -- if left button |
||
426 | end |
||
427 | |||
428 | local StanceSets_Save_PickupContainerItem = PickupContainerItem; |
||
429 | PickupContainerItem = function (bag,slot) |
||
430 | StanceSets_PickedupItem = { }; |
||
431 | StanceSets_PickedupItem.bag = bag; |
||
432 | StanceSets_PickedupItem.slot = slot; |
||
433 | return StanceSets_Save_PickupContainerItem(bag,slot); |
||
434 | end |
||
435 | |||
436 | local StanceSets_Save_PickupInventoryItem = PickupInventoryItem; |
||
437 | PickupInventoryItem = function (slot) |
||
438 | StanceSets_PickedupItem = { }; |
||
439 | StanceSets_PickedupItem.bag = -1; |
||
440 | StanceSets_PickedupItem.slot = slot; |
||
441 | return StanceSets_Save_PickupInventoryItem(slot); |
||
442 | end |
||
443 | |||
444 | function StanceSetsForceCheck_OnClick() |
||
445 | local frmParent = this:GetParent(); |
||
446 | local playerName = UnitName("player"); |
||
447 | local setName = playerName.."_"..frmParent.StanceName.."_ForceFirst"; |
||
448 | |||
449 | if not StanceSets then StanceSets = { }; end |
||
450 | |||
451 | if (this:GetChecked()) then |
||
452 | StanceSets[setName] = true; |
||
453 | PlaySound("igMainMenuOptionCheckBoxOff"); |
||
454 | else |
||
455 | StanceSets[setName] = nil; |
||
456 | PlaySound("igMainMenuOptionCheckBoxOn"); |
||
457 | end |
||
458 | end |
||
459 | |||
460 | function DebugReport(msg, color, bSecondChatWindow) |
||
461 | local r = 0.50; |
||
462 | local g = 0.50; |
||
463 | local b = 1.00; |
||
464 | |||
465 | if (color) then |
||
466 | r = color.r; |
||
467 | g = color.g; |
||
468 | b = color.b; |
||
469 | end |
||
470 | |||
471 | local frame = DEFAULT_CHAT_FRAME; |
||
472 | if (bSecondChatWindow) then |
||
473 | frame = ChatFrame2; |
||
474 | end |
||
475 | |||
476 | if (frame) then |
||
477 | frame:AddMessage(msg,r,g,b); |
||
478 | end |
||
479 | end |