Mercurial > wow > hotcorners
comparison HotCorners.lua @ 2:a6fb0ff113b1
- Added inventory items.
- Added alpha animation.
author | tercio |
---|---|
date | Sat, 23 Aug 2014 18:56:28 -0300 |
parents | 018fc9f0c471 |
children | be6f5d3e0a95 |
comparison
equal
deleted
inserted
replaced
1:018fc9f0c471 | 2:a6fb0ff113b1 |
---|---|
1 | |
2 -- fazer ele fechar apenas com o HotCornersBackgroundFrame. | |
3 -- assim vai dar + estabilidade sabendo exatamente quando ele esta aberto ou fechado. | |
1 | 4 |
2 LibHotCorners = LibStub ("AceAddon-3.0"):NewAddon ("HotCorners", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0") | 5 LibHotCorners = LibStub ("AceAddon-3.0"):NewAddon ("HotCorners", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0") |
3 _G.HotCorners = LibHotCorners | 6 _G.HotCorners = LibHotCorners |
4 local LibHotCorners = LibHotCorners | 7 local LibHotCorners = LibHotCorners |
5 | 8 |
26 end | 29 end |
27 | 30 |
28 function LibHotCorners:OnDisable() | 31 function LibHotCorners:OnDisable() |
29 | 32 |
30 end | 33 end |
34 | |
35 LibHotCorners.ItemButtons = {} | |
36 LibHotCorners.ItemOnInventory = {} | |
31 | 37 |
32 local refresh_topleft = function() | 38 local refresh_topleft = function() |
33 LibHotCorners ["topleft"].is_enabled = LibHotCorners.db.profile.topleft_enabled | 39 LibHotCorners ["topleft"].is_enabled = LibHotCorners.db.profile.topleft_enabled |
34 end | 40 end |
35 | 41 |
287 | 293 |
288 --> background (window mode fix) | 294 --> background (window mode fix) |
289 function HotCornersBackgroundOnEnter (self) | 295 function HotCornersBackgroundOnEnter (self) |
290 if (LibHotCornersTopLeft and LibHotCornersTopLeft:IsShown()) then | 296 if (LibHotCornersTopLeft and LibHotCornersTopLeft:IsShown()) then |
291 if (LibHotCornersTopLeft:GetWidth() > 2) then | 297 if (LibHotCornersTopLeft:GetWidth() > 2) then |
292 HotCornersOnLeave (LibHotCornersTopLeft) | 298 HotCornersOnLeave (LibHotCornersTopLeft, true) |
293 end | 299 end |
294 end | 300 end |
295 self:EnableMouse (false) | 301 self:EnableMouse (false) |
296 end | 302 end |
297 | 303 |
304 end | 310 end |
305 end | 311 end |
306 | 312 |
307 --> show tooltip | 313 --> show tooltip |
308 local show_tooltip = function (self) | 314 local show_tooltip = function (self) |
309 if (self.table.tooltip) then | 315 if (self.table and self.table.tooltip) then |
310 if (type (self.table.tooltip) == "function") then | 316 if (type (self.table.tooltip) == "function") then |
311 GameTooltip:SetOwner (self, "ANCHOR_RIGHT") | 317 GameTooltip:SetOwner (self, "ANCHOR_RIGHT") |
312 self.table.tooltip (GameTooltip) | 318 self.table.tooltip (GameTooltip) |
313 GameTooltip:Show() | 319 GameTooltip:Show() |
314 elseif (type (self.table.tooltip) == "string") then | 320 elseif (type (self.table.tooltip) == "string") then |
315 GameTooltip:SetOwner (self, "ANCHOR_RIGHT") | 321 GameTooltip:SetOwner (self, "ANCHOR_RIGHT") |
316 GameTooltip:AddLine (self.table.tooltip) | 322 GameTooltip:AddLine (self.table.tooltip) |
317 GameTooltip:Show() | 323 GameTooltip:Show() |
318 end | 324 end |
319 elseif (self.table.onenter) then | 325 elseif (self.table and self.table.onenter) then |
320 self.table.onenter (self) | 326 self.table.onenter (self) |
327 elseif (self.isItem) then | |
328 GameTooltip:SetOwner (self, "ANCHOR_BOTTOMRIGHT") | |
329 GameTooltip:SetHyperlink (self.itemtable[4]) | |
330 GameTooltip:Show() | |
321 end | 331 end |
322 end | 332 end |
323 | 333 |
324 --> corner frame on enter | 334 --> corner frame on enter |
325 local more_clicked = function (t1, t2) | 335 local more_clicked = function (t1, t2) |
326 return t1[1] > t2[1] | 336 return t1[1] > t2[1] |
327 end | 337 end |
328 | 338 |
339 LibHotCorners.BackPackItemList = { | |
340 | |
341 --> alchemy | |
342 [76086] = true, -- Flask of Falling Leaves | |
343 [76084] = true, -- Flask of Spring Blossoms | |
344 [76085] = true, -- Flask of the Warm Sun | |
345 [76087] = true, -- Flask of the Earth | |
346 [76088] = true, -- Flask of Winter's Bite | |
347 | |
348 [76081] = true, -- Elixir of Mirrors | |
349 [76079] = true, -- Elixir of Peace | |
350 [76080] = true, -- Elixir of Perfection | |
351 [76078] = true, -- Elixir of the Rapids | |
352 [76077] = true, -- Elixir of Weaponry | |
353 [70676] = true, -- Mad Hozen Elixir | |
354 [76075] = true, -- Mantid Elixir | |
355 [76083] = true, -- Monk's Elixir | |
356 | |
357 [76094] = true, -- Alchemist's Rejuvenation | |
358 [96096] = true, -- Darkwater Potion | |
359 [75218] = true, -- Electrified Oil | |
360 [76097] = true, -- Master Healing Potion | |
361 [76098] = true, -- Master Mana Potion | |
362 [76092] = true, -- Potion of Focus | |
363 [76093] = true, -- Potion of the Jade Serpent | |
364 [76095] = true, -- Potion of Mogu Power | |
365 [76090] = true, -- Potion of the Mountains | |
366 [76091] = true, -- Greater Potion of Luck | |
367 [76089] = true, -- Virmen's Bite | |
368 | |
369 --> cooking | |
370 | |
371 --Way of the Grill: Strength | |
372 [74642] = true, -- Charbroiled Tiger Steak | |
373 [74645] = true, -- Eternal Blossom Fish | |
374 [74646] = true, -- Black Pepper Ribs and Shrimp | |
375 | |
376 --Way of the Oven: Stamina | |
377 [74654] = true, -- Wildfowl Roast | |
378 [74655] = true, -- Twin Fish Platter | |
379 [74656] = true, -- Chun Tian Spring Rolls | |
380 | |
381 --Way of the Pot: Intellect | |
382 | |
383 [74644] = true, -- Swirling Mist Soup | |
384 [74649] = true, -- Braised Turtle | |
385 [74650] = true, -- Mogu Fish Stew | |
386 | |
387 --Way of the Steamer: Spirit | |
388 | |
389 [74651] = true, -- Shrimp Dumplings | |
390 [74652] = true, -- Fire Spirit Salmon | |
391 [74653] = true, -- Steamed Crab Surprise | |
392 | |
393 --Way of the Wok: Agility | |
394 | |
395 [74643] = true, -- Sauteed Carrots | |
396 [74647] = true, -- Valley Stir Fry | |
397 [74648] = true, -- Sea Mist Rice Noodles | |
398 | |
399 --Way of the Brew: Headaches and Grandeur | |
400 | |
401 [74626] = true, -- Ginseng Tea | |
402 [74637] = true, -- Jade Witch Brew | |
403 [74638] = true, -- Mad Brewer's Breakfast | |
404 | |
405 --General Cooking | |
406 | |
407 [74641] = true, -- Fish Cake | |
408 [74636] = true, -- Golden Carp Consomme | |
409 [86070] = true, -- Wildfowl Ginseng Soup | |
410 [86069] = true, -- Rice Pudding | |
411 [86074] = true, -- Spicy Vegetable Chips | |
412 [86073] = true, -- Spicy Salmon | |
413 | |
414 --5.4 Recipes | |
415 | |
416 [145308] = true, -- Mango Ice | |
417 [145309] = true, -- Farmer's Delight | |
418 [145311] = true, -- Fluffy Silkfeather Omelet | |
419 [145310] = true, -- Stuffed Lushrooms | |
420 [145307] = true, -- Spiced Blossom Soup | |
421 [145305] = true, -- Seasoned Pomfruit Slices | |
422 | |
423 --Cart Kits | |
424 [101630] = true, -- Noodle Cart Kit | |
425 [101661] = true, -- Deluxe Noodle Cart Kit | |
426 [101662] = true, -- Pandaren Treasure Noodle Cart Kit | |
427 | |
428 [101618] = true, -- Pandaren Treasure Noodle Soup | |
429 [101617] = true, -- Deluxe Noodle Soup | |
430 [101616] = true, -- Noodle Soup | |
431 } | |
432 | |
329 function HotCornersOnEnter (self) | 433 function HotCornersOnEnter (self) |
330 | 434 |
331 if (not LibHotCorners.db.profile.is_enabled) then | 435 if (not LibHotCorners.db.profile.is_enabled) then |
332 return | 436 return |
333 end | 437 end |
334 | 438 |
335 if (not LibHotCorners.db.profile [self.position .. "_enabled"]) then | 439 if (not LibHotCorners.db.profile [self.position .. "_enabled"]) then |
336 return | 440 return |
337 end | 441 end |
338 | 442 |
443 if (self:GetWidth() < 1.1 and self:GetHeight() < 1.1) then | |
444 --print ("abrindo...") | |
445 end | |
446 | |
339 set_size (self) | 447 set_size (self) |
340 | 448 |
341 HotCornersBackgroundFrame:EnableMouse (true) | 449 HotCornersBackgroundFrame:EnableMouse (true) |
450 self.item_frame:Show() | |
342 | 451 |
343 local i = 1 | 452 local i = 1 |
344 | 453 |
345 local sort = {} | 454 local sort = {} |
346 local clicks = LibHotCorners.db.profile.clicks | 455 local clicks = LibHotCorners.db.profile.clicks |
361 | 470 |
362 button_table.widget:ClearAllPoints() | 471 button_table.widget:ClearAllPoints() |
363 | 472 |
364 if (not disabled [button_table.name] and not button_table.optionstable.hide) then | 473 if (not disabled [button_table.name] and not button_table.optionstable.hide) then |
365 if (self.position == "topleft" or self.position == "topright") then | 474 if (self.position == "topleft" or self.position == "topright") then |
475 | |
366 local y = i * 35 * -1 | 476 local y = i * 35 * -1 |
367 button_table.widget:SetPoint ("topleft", self, "topleft", 4, y) | 477 --button_table.widget:SetPoint ("topleft", self, "topleft", 4, y) |
368 button_table.widget.y = y | 478 button_table.widget.y = y |
369 else | 479 HotCornersStartAnimOnShow (button_table.widget, "y") |
480 | |
481 else --bottom left / bottom right | |
370 local x = i * 35 | 482 local x = i * 35 |
371 button_table.widget:SetPoint ("topleft", self, "topleft", x, -4) | 483 button_table.widget:SetPoint ("topleft", self, "topleft", x, -4) |
372 button_table.widget.x = x | 484 button_table.widget.x = x |
373 end | 485 end |
374 | 486 |
384 local OptionsButton = LibHotCorners [self.position].optionsbutton | 496 local OptionsButton = LibHotCorners [self.position].optionsbutton |
385 local y = i * 35 * -1 | 497 local y = i * 35 * -1 |
386 OptionsButton:SetPoint ("top", self, "top", 0, y) | 498 OptionsButton:SetPoint ("top", self, "top", 0, y) |
387 OptionsButton:Show() | 499 OptionsButton:Show() |
388 | 500 |
389 end | 501 --item frame |
390 | 502 LibHotCorners:RefereshItems (self) |
503 | |
504 end | |
505 | |
506 function LibHotCorners:RefereshItems (self) | |
507 | |
508 if (not self) then | |
509 return LibHotCorners:ScheduleTimer ("RefereshItems", 1, LibHotCornersTopLeft) | |
510 end | |
511 | |
512 if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then | |
513 for itemId, itemTable in pairs (LibHotCorners.ItemOnInventory) do | |
514 itemTable [1] = 0 | |
515 end | |
516 | |
517 for bagID = 0, 4 do | |
518 local numItems = GetContainerNumSlots (bagID) | |
519 for slot = 1, numItems do | |
520 local itemId = GetContainerItemID (bagID, slot) | |
521 if (LibHotCorners.BackPackItemList [itemId]) then | |
522 local texture, itemCount, locked, quality, readable, lootable, itemLink = GetContainerItemInfo (bagID, slot) | |
523 if (not LibHotCorners.ItemOnInventory [itemId]) then | |
524 LibHotCorners.ItemOnInventory [itemId] = {itemCount, texture, quality, itemLink, itemId} | |
525 else | |
526 LibHotCorners.ItemOnInventory [itemId] [1] = LibHotCorners.ItemOnInventory [itemId] [1] + itemCount | |
527 end | |
528 end | |
529 end | |
530 end | |
531 | |
532 local index = 1 | |
533 for itemId, itemTable in pairs (LibHotCorners.ItemOnInventory) do | |
534 local itemCount, texture, quality, itemLink = unpack (itemTable) | |
535 | |
536 local item_button = LibHotCorners:GetItemButton (index, self) | |
537 if (item_button) then | |
538 item_button:SetNormalTexture (texture) | |
539 item_button:SetHighlightTexture (texture) | |
540 item_button:SetPushedTexture (texture) | |
541 | |
542 item_button.item_count:SetText (itemCount or 0) | |
543 item_button:SetAttribute ("macrotext", "/use " .. GetItemInfo (itemId) .. ";\n/script HotCorners:RefereshItems()") | |
544 | |
545 item_button.itemtable = itemTable | |
546 | |
547 if (not item_button:IsShown() or item_button:GetAlpha() < 1) then | |
548 HotCornersStartAnimOnShow (item_button, "item_topleft") | |
549 end | |
550 end | |
551 index = index + 1 | |
552 end | |
553 | |
554 end | |
555 | |
556 --/run local itemid=GetContainerItemID (0, 1);print (itemid) | |
557 --UseContainerItem(bagID, slot[, onSelf]) | |
558 end | |
559 | |
560 function LibHotCorners:GetItemButton (index, parent) | |
561 local button = LibHotCorners.ItemButtons [index] | |
562 if (not button) then | |
563 button = CreateFrame ("button", "HotCornersItemButton" .. index, parent.item_frame, "HotCornersUseItemButtonTemplate") | |
564 button.isItem = true | |
565 | |
566 if (parent.position == "topleft") then | |
567 local x = (index-1) * 33 | |
568 button:SetPoint ("topleft", parent.item_frame, "topleft", x, -2) | |
569 button.x = x | |
570 elseif (parent.position == "topright") then | |
571 local x = (index-1) * 33 | |
572 button:SetPoint ("topright", parent.item_frame, "topright", -x, -2) | |
573 end | |
574 | |
575 LibHotCorners.ItemButtons [index] = button | |
576 end | |
577 return button | |
578 end | |
579 | |
391 --> corner frame on leave | 580 --> corner frame on leave |
392 function HotCornersOnLeave (self) | 581 function HotCornersOnLeave (self, from_background) |
582 if (not from_background) then | |
583 return | |
584 end | |
585 | |
393 self:SetSize (1, 1) | 586 self:SetSize (1, 1) |
394 for index, button_table in ipairs (LibHotCorners [self.position]) do | 587 for index, button_table in ipairs (LibHotCorners [self.position]) do |
395 if (button_table.widget) then | 588 if (button_table.widget) then |
396 button_table.widget:Hide() | 589 button_table.widget:Hide() |
397 end | 590 end |
398 end | 591 end |
592 for _, button in pairs (LibHotCorners.ItemButtons) do | |
593 button:Hide() | |
594 end | |
595 | |
399 local OptionsButton = LibHotCorners [self.position].optionsbutton | 596 local OptionsButton = LibHotCorners [self.position].optionsbutton |
400 OptionsButton:Hide() | 597 OptionsButton:Hide() |
598 | |
599 self.item_frame:Hide() | |
401 end | 600 end |
402 | 601 |
403 --> quick corner on click | 602 --> quick corner on click |
404 function HotCornersOnQuickClick (self, button) | 603 function HotCornersOnQuickClick (self, button) |
405 local parent_position = self:GetParent().position | 604 local parent_position = self:GetParent().position |
434 self:GetParent():GetScript("OnLeave")(self:GetParent()) | 633 self:GetParent():GetScript("OnLeave")(self:GetParent()) |
435 end | 634 end |
436 | 635 |
437 --> button onenter | 636 --> button onenter |
438 function HotCornersButtonOnEnter (self) | 637 function HotCornersButtonOnEnter (self) |
439 set_size (self:GetParent()) | 638 --set_size (self:GetParent()) |
440 for index, button_table in ipairs (LibHotCorners [self:GetParent().position]) do | 639 --for index, button_table in ipairs (LibHotCorners [self:GetParent().position]) do |
441 if (not LibHotCorners.db.profile.disabled [button_table.name]) then | 640 -- if (not LibHotCorners.db.profile.disabled [button_table.name] and button_table.widget) then |
442 button_table.widget:Show() | 641 -- button_table.widget:Show() |
443 end | 642 -- end |
444 end | 643 --end |
445 show_tooltip (self) | 644 show_tooltip (self) |
446 local OptionsButton = LibHotCorners [self:GetParent().position].optionsbutton | 645 --local OptionsButton = LibHotCorners [self:GetParent().position].optionsbutton |
447 OptionsButton:Show() | 646 --OptionsButton:Show() |
448 end | 647 end |
449 | 648 |
450 --> button onleave | 649 --> button onleave |
451 function HotCornersButtonOnLeave (self) | 650 function HotCornersButtonOnLeave (self) |
452 GameTooltip:Hide() | 651 GameTooltip:Hide() |
453 if (self.table.onleave) then | 652 if (self.table and self.table.onleave) then |
454 self.table.onleave (self) | 653 self.table.onleave (self) |
455 end | 654 end |
456 self:GetParent():GetScript("OnLeave")(self:GetParent()) | 655 --self:GetParent():GetScript("OnLeave")(self:GetParent()) |
457 local OptionsButton = LibHotCorners [self:GetParent().position].optionsbutton | 656 --local OptionsButton = LibHotCorners [self:GetParent().position].optionsbutton |
458 OptionsButton:Hide() | 657 --OptionsButton:Hide() |
459 end | 658 end |
460 | 659 |
461 --> button onmousedown | 660 --> button onmousedown |
462 function HotCornersButtonOnMouseDown (self, button) | 661 function HotCornersButtonOnMouseDown (self, button) |
463 if (self:GetParent().position == "topleft" or self:GetParent().position == "topright") then | 662 if (self.isItem) then |
464 self:SetPoint ("topleft", self:GetParent(), "topleft", 5, self.y - 1) | 663 if (self:GetParent():GetParent().position == "topleft") then |
664 self:SetPoint ("topleft", self:GetParent(), "topleft", self.x+1, -3) | |
665 end | |
465 else | 666 else |
466 self:SetPoint ("topleft", self:GetParent(), "topleft", self.x+1, -6) | 667 if (self:GetParent().position == "topleft" or self:GetParent().position == "topright") then |
668 self:SetPoint ("topleft", self:GetParent(), "topleft", 5, self.y - 1) | |
669 else | |
670 self:SetPoint ("topleft", self:GetParent(), "topleft", self.x+1, -6) | |
671 end | |
467 end | 672 end |
468 end | 673 end |
469 | 674 |
470 --> button onmouseup | 675 --> button onmouseup |
471 function HotCornersButtonOnMouseUp (self, button) | 676 function HotCornersButtonOnMouseUp (self, button) |
472 if (self:GetParent().position == "topleft" or self:GetParent().position == "topright") then | 677 if (self.isItem) then |
473 self:SetPoint ("topleft", self:GetParent(), "topleft", 4, self.y) | 678 if (self:GetParent():GetParent().position == "topleft") then |
679 self:SetPoint ("topleft", self:GetParent(), "topleft", self.x, -2) | |
680 end | |
474 else | 681 else |
475 self:SetPoint ("topleft", self:GetParent(), "topleft", self.x, -4) | 682 if (self:GetParent().position == "topleft" or self:GetParent().position == "topright") then |
476 end | 683 self:SetPoint ("topleft", self:GetParent(), "topleft", 4, self.y) |
477 if (self.table.click) then | 684 else |
478 local clicks = LibHotCorners.db.profile.clicks | 685 self:SetPoint ("topleft", self:GetParent(), "topleft", self.x, -4) |
479 clicks [self.table.name] = clicks [self.table.name] or 0 | 686 end |
480 clicks [self.table.name] = clicks [self.table.name] + 1 | 687 if (self.table.click) then |
481 self.table.click (self, button) | 688 local clicks = LibHotCorners.db.profile.clicks |
482 end | 689 clicks [self.table.name] = clicks [self.table.name] or 0 |
690 clicks [self.table.name] = clicks [self.table.name] + 1 | |
691 self.table.click (self, button) | |
692 end | |
693 end | |
694 end | |
695 | |
696 --> start show animation | |
697 function HotCornersStartAnimOnShow (button, axis) | |
698 if (axis == "y") then | |
699 --button:SetPoint ("topleft", button:GetParent(), "topleft", -32, button.y) | |
700 button:SetPoint ("topleft", button:GetParent(), "topleft", 4, button.y) | |
701 button.AnimOnShow:Play() | |
702 | |
703 elseif (axis == "item_topleft") then | |
704 button:Show() | |
705 button.AnimOnShow:Play() | |
706 | |
707 end | |
708 end | |
709 | |
710 --> on start / finish show animation | |
711 function HotCornersAnimOnShowStarted (button) | |
712 | |
713 end | |
714 function HotCornersAnimOnShowFinished (button) | |
715 --button:SetPoint ("topleft", button:GetParent(), "topleft", 4, button.y) | |
716 button:Show() | |
717 --button:SetPoint ("topleft", button:GetParent(), "topleft", -4, button.y) | |
483 end | 718 end |
484 | 719 |
485 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | 720 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
486 --> create top left corner | 721 --> create top left corner |
487 | 722 |