Mercurial > wow > reaction
comparison BagButton.lua @ 298:d1a56601267b
Fix bag buttons and remove keyring
| author | Flick |
|---|---|
| date | Wed, 14 Nov 2012 16:35:18 -0800 |
| parents | 4e325f1ea6e1 |
| children |
comparison
equal
deleted
inserted
replaced
| 297:f7a5676c9517 | 298:d1a56601267b |
|---|---|
| 23 defaultBarConfig = { | 23 defaultBarConfig = { |
| 24 type = buttonTypeID, | 24 type = buttonTypeID, |
| 25 btnWidth = 30, | 25 btnWidth = 30, |
| 26 btnHeight = 30, | 26 btnHeight = 30, |
| 27 btnRows = 1, | 27 btnRows = 1, |
| 28 btnColumns = 6, | 28 btnColumns = 5, |
| 29 spacing = 4, | 29 spacing = 4, |
| 30 buttons = { } | 30 buttons = { } |
| 31 }, | 31 }, |
| 32 | 32 |
| 33 barType = L["Bag Bar"], | 33 barType = L["Bag Bar"], |
| 37 }, | 37 }, |
| 38 { __index = Super } ) | 38 { __index = Super } ) |
| 39 | 39 |
| 40 local Bag = setmetatable( { }, { __index = BagBase } ) | 40 local Bag = setmetatable( { }, { __index = BagBase } ) |
| 41 local Backpack = setmetatable( { }, { __index = BagBase } ) | 41 local Backpack = setmetatable( { }, { __index = BagBase } ) |
| 42 local Keyring = setmetatable( { }, { __index = BagBase } ) | |
| 43 | 42 |
| 44 ReAction.Button.Bag = BagBase | 43 ReAction.Button.Bag = BagBase |
| 45 ReAction:RegisterBarType(BagBase) | 44 ReAction:RegisterBarType(BagBase) |
| 46 | 45 |
| 47 -- | 46 -- |
| 53 -- unlike traditional OO programming, we can initialize the leaf | 52 -- unlike traditional OO programming, we can initialize the leaf |
| 54 -- class before initializing its parent | 53 -- class before initializing its parent |
| 55 local class = Bag | 54 local class = Bag |
| 56 if idx == 1 then | 55 if idx == 1 then |
| 57 class = Backpack | 56 class = Backpack |
| 58 elseif idx == 6 then | |
| 59 class = Keyring | |
| 60 end | 57 end |
| 61 self = class:New(btnCfg, bar, idx) | 58 self = class:New(btnCfg, bar, idx) |
| 62 | 59 |
| 63 local f = self:GetFrame() | 60 local f = self:GetFrame() |
| 64 local config = self:GetConfig() | 61 local config = self:GetConfig() |
| 65 | 62 |
| 66 -- set up the bag ID pool | 63 -- set up the bag ID pool |
| 67 self:SetActionIDPool("bag",6) | 64 self:SetActionIDPool("bag",5) |
| 68 config.bagID = self:AcquireActionID(config.bagID, idHint, true) | 65 config.bagID = self:AcquireActionID(config.bagID, idHint, true) |
| 69 | 66 |
| 70 -- non secure scripts | 67 -- non secure scripts |
| 71 f:SetScript("OnEvent", function(frame, ...) self:OnEvent(...) end) | 68 f:SetScript("OnEvent", function(frame, ...) self:OnEvent(...) end) |
| 72 f:SetScript("OnEnter", function(frame) self:OnEnter() end) | 69 f:SetScript("OnEnter", function(frame) self:OnEnter() end) |
| 82 | 79 |
| 83 -- frame setup | 80 -- frame setup |
| 84 f:SetID(self:GetBagID()) | 81 f:SetID(self:GetBagID()) |
| 85 | 82 |
| 86 if not f.hotkey then | 83 if not f.hotkey then |
| 87 local h = f:CreateFontString(name.."HotKey","ARTWORK","NumberFontNormalSmallGray") | 84 local h = f:CreateFontString(self:GetName().."HotKey","ARTWORK","NumberFontNormalSmallGray") |
| 88 h:SetWidth(30) | 85 h:SetWidth(30) |
| 89 h:SetHeight(10) | 86 h:SetHeight(10) |
| 90 h:SetJustifyH("RIGHT") | 87 h:SetJustifyH("RIGHT") |
| 91 h:SetPoint("TOPLEFT",f,"TOPLEFT",-2,-2) | 88 h:SetPoint("TOPLEFT",f,"TOPLEFT",-2,-2) |
| 92 h:Show() | 89 h:Show() |
| 93 f.hotkey = h | 90 f.hotkey = h |
| 94 end | 91 end |
| 95 | 92 |
| 96 if not _G[name.."ItemAnim"] then | 93 if not _G[self:GetName().."ItemAnim"] then |
| 97 local anim = CreateFrame("Model",name.."ItemAnim",f,"ItemAnimTemplate") | 94 local anim = CreateFrame("Model",self:GetName().."ItemAnim",f,"ItemAnimTemplate") |
| 98 anim:SetPoint("BOTTOMRIGHT",f,"BOTTOMRIGHT",-10,0) | 95 anim:SetPoint("BOTTOMRIGHT",f,"BOTTOMRIGHT",-10,0) |
| 99 anim:Hide() | 96 anim:Hide() |
| 100 end | 97 end |
| 101 | 98 |
| 102 if not f.border then | 99 if not f.border then |
| 103 local b = f:CreateTexture(name.."Border","OVERLAY") | 100 local b = f:CreateTexture(self:GetName().."Border","OVERLAY") |
| 104 b:SetAllPoints() | 101 b:SetAllPoints() |
| 105 b:SetWidth(f:GetWidth()*(62/36)) | 102 b:SetWidth(f:GetWidth()*(62/36)) |
| 106 b:SetHeight(f:GetHeight()*(62/36)) | 103 b:SetHeight(f:GetHeight()*(62/36)) |
| 107 b:SetTexture("Interface\\Buttons\UI-ActionButton-Border") | 104 b:SetTexture("Interface\\Buttons\UI-ActionButton-Border") |
| 108 b:SetBlendMode("ADD") | 105 b:SetBlendMode("ADD") |
| 111 end | 108 end |
| 112 | 109 |
| 113 self.frames.count:SetDrawLayer("ARTWORK") | 110 self.frames.count:SetDrawLayer("ARTWORK") |
| 114 | 111 |
| 115 self.frames.hotkey = f.hotkey | 112 self.frames.hotkey = f.hotkey |
| 116 self.frames.border = _G[name.."Border"] | 113 self.frames.border = _G[self:GetName().."Border"] |
| 117 self.frames.icon = _G[name.."IconTexture"] | 114 self.frames.icon = _G[self:GetName().."IconTexture"] |
| 118 self.frames.anim = _G[name.."ItemAnim"] | 115 self.frames.anim = _G[self:GetName().."ItemAnim"] |
| 119 | 116 |
| 120 -- initial display | 117 -- initial display |
| 121 if ReAction:GetConfigMode() then | 118 if ReAction:GetConfigMode() then |
| 122 self:GetFrame():Show() | 119 self:GetFrame():Show() |
| 123 end | 120 end |
| 191 | 188 |
| 192 | 189 |
| 193 -- | 190 -- |
| 194 -- Bag Button class | 191 -- Bag Button class |
| 195 -- | 192 -- |
| 196 function Bag:New(name, cfg, bar, idx) | 193 function Bag:New(cfg, bar, idx) |
| 197 self = Super.New(self, name, cfg, bar, idx, "ItemButtonTemplate" ) | 194 self = Super.New(self, cfg, bar, idx, "ItemButtonTemplate" ) |
| 198 | 195 |
| 199 local f = self:GetFrame() | 196 local f = self:GetFrame() |
| 200 | 197 |
| 201 f:SetCheckedTexture("Interface\\Buttons\\CheckButtonHilight") | 198 f:SetCheckedTexture("Interface\\Buttons\\CheckButtonHilight") |
| 202 | 199 |
| 207 f:RegisterForDrag("LeftButton") | 204 f:RegisterForDrag("LeftButton") |
| 208 | 205 |
| 209 -- attach to skinner | 206 -- attach to skinner |
| 210 bar:SkinButton(self, | 207 bar:SkinButton(self, |
| 211 { | 208 { |
| 212 Icon = _G[name.."IconTexture"] | 209 Icon = _G[self:GetName().."IconTexture"] |
| 213 } | 210 } |
| 214 ) | 211 ) |
| 215 | 212 |
| 216 return self | 213 return self |
| 217 end | 214 end |
| 289 | 286 |
| 290 | 287 |
| 291 -- | 288 -- |
| 292 -- Backpack Button class | 289 -- Backpack Button class |
| 293 -- | 290 -- |
| 294 function Backpack:New(name, cfg, bar, idx) | 291 function Backpack:New(cfg, bar, idx) |
| 295 self = Super.New(self, name, cfg, bar, idx, "ItemButtonTemplate" ) | 292 self = Super.New(self, cfg, bar, idx, "ItemButtonTemplate" ) |
| 296 | 293 |
| 297 local f = self:GetFrame() | 294 local f = self:GetFrame() |
| 298 local icon = _G[name.."IconTexture"] | 295 local icon = _G[self:GetName().."IconTexture"] |
| 299 icon:SetTexture("Interface\\Buttons\\Button-Backpack-Up") | 296 icon:SetTexture("Interface\\Buttons\\Button-Backpack-Up") |
| 300 icon:Show() | 297 icon:Show() |
| 301 f:SetCheckedTexture("Interface\\Buttons\\CheckButtonHilight") | 298 f:SetCheckedTexture("Interface\\Buttons\\CheckButtonHilight") |
| 302 f:RegisterEvent("PLAYER_ENTERING_WORLD"); | 299 f:RegisterEvent("PLAYER_ENTERING_WORLD"); |
| 303 f:RegisterEvent("CVAR_UPDATE"); | 300 f:RegisterEvent("CVAR_UPDATE"); |
| 304 f:SetScript("OnShow", function(frame, ...) self:OnShow(...) end) | 301 f:SetScript("OnShow", function(frame, ...) self:OnShow(...) end) |
| 305 | 302 |
| 306 -- attach to skinner | 303 -- attach to skinner |
| 307 bar:SkinButton(self, | 304 bar:SkinButton(self, |
| 308 { | 305 { |
| 309 Icon = _G[name.."IconTexture"] | 306 Icon = _G[self:GetName().."IconTexture"] |
| 310 } | 307 } |
| 311 ) | 308 ) |
| 312 | 309 |
| 313 return self | 310 return self |
| 314 end | 311 end |
| 384 self:UpdateFreeSlots() | 381 self:UpdateFreeSlots() |
| 385 end | 382 end |
| 386 end | 383 end |
| 387 | 384 |
| 388 | 385 |
| 389 -- | |
| 390 -- Keyring Button class | |
| 391 -- | |
| 392 function Keyring:New(name, cfg, bar, idx) | |
| 393 self = Super.New(self, name, cfg, bar, idx, "ItemButtonTemplate" ) | |
| 394 | |
| 395 local f = self:GetFrame() | |
| 396 | |
| 397 f:SetWidth(18) | |
| 398 f:SetHeight(39) | |
| 399 | |
| 400 local tex = f:GetNormalTexture() | |
| 401 tex:ClearAllPoints() | |
| 402 tex:SetAllPoints() | |
| 403 | |
| 404 f:SetNormalTexture("Interface\\Buttons\\UI-Button-KeyRing") | |
| 405 f:SetHighlightTexture("Interface\\Buttons\\UI-Button-KeyRing-Highlight") | |
| 406 f:SetPushedTexture("Interface\\Buttons\\UI-Button-KeyRing-Down") | |
| 407 f:GetNormalTexture():SetTexCoord(0,0.5625,0,0.609375) | |
| 408 f:GetHighlightTexture():SetTexCoord(0,0.5625,0,0.609375) | |
| 409 f:GetPushedTexture():SetTexCoord(0,0.5625,0,0.609375) | |
| 410 | |
| 411 if not HasKey() then | |
| 412 f:Hide() | |
| 413 end | |
| 414 | |
| 415 -- DO NOT attach to skinner | |
| 416 | |
| 417 return self | |
| 418 end | |
| 419 | |
| 420 function Keyring:GetBagID() | |
| 421 return KEYRING_CONTAINER | |
| 422 end | |
| 423 | |
| 424 function Keyring:Refresh() | |
| 425 local f = self:GetFrame() | |
| 426 self.bar:PlaceButton( self, f:GetHeight(), f:GetHeight() ) -- use height x height since it's an odd size | |
| 427 self:UpdateHotkey() | |
| 428 self:Update() | |
| 429 end | |
| 430 | |
| 431 function Keyring:SetTooltip() | |
| 432 GameTooltip:SetOwner(self:GetFrame(), "ANCHOR_RIGHT"); | |
| 433 GameTooltip:SetText(KEYRING, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b); | |
| 434 GameTooltip:AddLine(); | |
| 435 end | |
| 436 | |
| 437 function Keyring:OnReceiveDrag() | |
| 438 if CursorHasItem() then | |
| 439 PutKeyInKeyRing() | |
| 440 end | |
| 441 end | |
| 442 | |
| 443 function Keyring:OnClick() | |
| 444 if CursorHasItem() then | |
| 445 PutKeyInKeyRing() | |
| 446 else | |
| 447 ToggleKeyRing() | |
| 448 end | |
| 449 self:UpdateChecked() | |
| 450 end | |
| 451 | |
| 452 function Keyring:ShowGridTemp(show) | |
| 453 if not HasKey() then | |
| 454 if show then | |
| 455 self:GetFrame():Show() | |
| 456 else | |
| 457 self:GetFrame():Hide() | |
| 458 end | |
| 459 end | |
| 460 end | |
| 461 | 386 |
| 462 | 387 |
| 463 | 388 |
| 464 -- hook some functions to propagate to our bag buttons | 389 -- hook some functions to propagate to our bag buttons |
| 465 hooksecurefunc("Disable_BagButtons", | 390 hooksecurefunc("Disable_BagButtons", |
