comparison classes/MultiCastButton.lua @ 163:ab5c37989986

- totem bar now stores which page was selected across sessions - totem bar shouldn't be messed up if resized around on non-shaman toons now
author Flick <flickerstreak@gmail.com>
date Sat, 22 Aug 2009 00:12:44 +0000
parents fc08372f0c7a
children 8241be11dcc0
comparison
equal deleted inserted replaced
162:fc08372f0c7a 163:ab5c37989986
102 -- set up some globals in the secure environment 102 -- set up some globals in the secure environment
103 flyout = self:GetFrameRef("flyout") 103 flyout = self:GetFrameRef("flyout")
104 flyoutChildren = newtable() 104 flyoutChildren = newtable()
105 nMultiCastSlots = self:GetAttribute("nMultiCastSlots") 105 nMultiCastSlots = self:GetAttribute("nMultiCastSlots")
106 baseActionID = self:GetAttribute("baseActionID") 106 baseActionID = self:GetAttribute("baseActionID")
107 currentMultiCastPage = currentMultiCastPage or 1 107 currentMultiCastPage = currentMultiCastPage or self:GetAttribute("lastSummon") or 1
108 multiCastSpellList = newtable() 108 multiCastSpellList = newtable()
109 for i = 1, nMultiCastSlots do 109 for i = 1, nMultiCastSlots do
110 tinsert(multiCastSpellList, newtable()) 110 tinsert(multiCastSpellList, newtable())
111 end 111 end
112 ]] 112 ]]
113 113
114 local _onstate_multispellpage = -- function(self, stateid, newstate) 114 local _onstate_multispellpage = -- function(self, stateid, newstate)
115 [[ 115 [[
116 currentMultiCastPage = tonumber(newstate) 116 currentMultiCastPage = tonumber(newstate)
117 control:CallMethod("UpdateLastSummon",currentMultiCastPage)
117 control:ChildUpdate() 118 control:ChildUpdate()
118 ]] 119 ]]
119 120
120 121
121 -- buttons 122 -- buttons
259 function MultiCast:New( idx, btnConfig, bar ) 260 function MultiCast:New( idx, btnConfig, bar )
260 if idx < 1 or idx > NUM_MULTI_CAST_BUTTONS_PER_PAGE + 2 then 261 if idx < 1 or idx > NUM_MULTI_CAST_BUTTONS_PER_PAGE + 2 then
261 error("Multicast button index out of range") 262 error("Multicast button index out of range")
262 end 263 end
263 264
265 if idx > bar.nMultiCastSlots then
266 return false
267 end
268
264 local name = format("ReAction_%s_Action_%d",bar:GetName(),idx) 269 local name = format("ReAction_%s_Action_%d",bar:GetName(),idx)
265 270
266 self = Super.New(self, name, btnConfig, bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" ) 271 self = Super.New(self, name, btnConfig, bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" )
267 272
268 local barFrame = bar:GetFrame() 273 local barFrame = bar:GetFrame()
269 local f = self:GetFrame() 274 local f = self:GetFrame()
270 275
271 -- attributes 276 -- attributes
277 local page = (idx == NUM_MULTI_CAST_BUTTONS_PER_PAGE + 2) and 1 or (bar:GetConfig().lastSummon or 1)
272 if idx == 1 or idx == NUM_MULTI_CAST_BUTTONS_PER_PAGE + 2 then 278 if idx == 1 or idx == NUM_MULTI_CAST_BUTTONS_PER_PAGE + 2 then
273 f:SetAttribute("type","spell") 279 f:SetAttribute("type","spell")
274 local spells = idx == 1 and TOTEM_MULTI_CAST_SUMMON_SPELLS or TOTEM_MULTI_CAST_RECALL_SPELLS 280 local spells = idx == 1 and TOTEM_MULTI_CAST_SUMMON_SPELLS or TOTEM_MULTI_CAST_RECALL_SPELLS
281 f:SetAttribute("spell",spells[page])
275 for i, spell in ipairs(spells) do 282 for i, spell in ipairs(spells) do
276 if spell and IsSpellKnown(spell) then 283 if spell and IsSpellKnown(spell) then
277 f:SetAttribute("spell-page"..i, spell) 284 f:SetAttribute("spell-page"..i, spell)
278 if i == 1 then
279 -- TODO: store/restore last used summon
280 f:SetAttribute("spell",spell)
281 end
282 end 285 end
283 end 286 end
284 else 287 else
285 local baseAction = barFrame:GetAttribute("baseActionID") + TOTEM_PRIORITIES[idx-1] 288 local baseAction = barFrame:GetAttribute("baseActionID") + TOTEM_PRIORITIES[idx-1]
286 f:SetAttribute("type","action") 289 f:SetAttribute("type","action")
287 f:SetAttribute("action", baseAction) 290 f:SetAttribute("action", baseAction + (page - 1) * NUM_MULTI_CAST_BUTTONS_PER_PAGE)
288 for i = 1, NUM_MULTI_CAST_PAGES do 291 for i = 1, NUM_MULTI_CAST_PAGES do
289 f:SetAttribute("action-page"..i, baseAction + (i-1) * NUM_MULTI_CAST_BUTTONS_PER_PAGE) 292 f:SetAttribute("action-page"..i, baseAction + (i-1) * NUM_MULTI_CAST_BUTTONS_PER_PAGE)
290 end 293 end
291 end 294 end
292 f:SetAttribute("bar-idx",idx) 295 f:SetAttribute("bar-idx",idx)
535 maxIdx = max(idx,maxIdx) 538 maxIdx = max(idx,maxIdx)
536 end 539 end
537 end 540 end
538 541
539 if #summon == 0 and #recall == 0 then 542 if #summon == 0 and #recall == 0 then
540 return 0 -- no multicast capability 543 bar.nMultiCastSlots = 0 -- no multicast capability
544 return
541 end 545 end
542 546
543 local slots = { } 547 local slots = { }
544 548
545 tinsert(slots, summon) 549 tinsert(slots, summon)
553 tinsert(slots, recall) 557 tinsert(slots, recall)
554 558
555 local barFrame = bar:GetFrame() 559 local barFrame = bar:GetFrame()
556 560
557 -- init bar secure environment 561 -- init bar secure environment
562 barFrame:SetAttribute("lastSummon",bar:GetConfig().lastSummon)
558 barFrame:SetAttribute("nMultiCastSlots",#slots) 563 barFrame:SetAttribute("nMultiCastSlots",#slots)
559 barFrame:SetAttribute("baseActionID", (NUM_ACTIONBAR_PAGES + GetMultiCastBarOffset() - 1)*NUM_ACTIONBAR_BUTTONS) 564 barFrame:SetAttribute("baseActionID", (NUM_ACTIONBAR_PAGES + GetMultiCastBarOffset() - 1)*NUM_ACTIONBAR_BUTTONS)
560 barFrame:SetAttribute("_onstate-multispellpage", _onstate_multispellpage) 565 barFrame:SetAttribute("_onstate-multispellpage", _onstate_multispellpage)
561 barFrame:Execute(_bar_init) 566 barFrame:Execute(_bar_init)
567
568 function barFrame:UpdateLastSummon(value)
569 bar:GetConfig().lastSummon = value
570 end
562 571
563 for i, p in ipairs(TOTEM_PRIORITIES) do 572 for i, p in ipairs(TOTEM_PRIORITIES) do
564 barFrame:SetAttribute("TOTEM_PRIORITY_"..i,p) 573 barFrame:SetAttribute("TOTEM_PRIORITY_"..i,p)
565 end 574 end
566 575
627 multiCastSpellList[self:GetAttribute("spell-slot")][self:GetAttribute("spell-index")] = self:GetAttribute("spell-id") 636 multiCastSpellList[self:GetAttribute("spell-slot")][self:GetAttribute("spell-index")] = self:GetAttribute("spell-id")
628 ]]) 637 ]])
629 end 638 end
630 end 639 end
631 640
632 return #slots 641 bar.nMultiCastSlots = #slots
633 end 642 end
634 643