Mercurial > wow > buffalo2
comparison ObjectiveTracker/Frame.lua @ 39:92534dc793f2
- restore the previous QuestLogSelection after pulling for selection-restricted quest data; fixes icon mixups while quest map is open
- moved progressbar builders into the schema environment, with all the other Frame.lua functions; prep for configuration access
- relegate the various removal events to a framescript in their corresponding blocks; this takes care of resolving dead frames
| author | Nenue |
|---|---|
| date | Thu, 21 Apr 2016 16:43:37 -0400 |
| parents | 1f8f9cc3d956 |
| children |
comparison
equal
deleted
inserted
replaced
| 38:1f8f9cc3d956 | 39:92534dc793f2 |
|---|---|
| 1 --- ${PACKAGE_NAME} | 1 --- ${PACKAGE_NAME} |
| 2 -- @file-author@ | 2 -- @file-author@ |
| 3 -- @project-revision@ @project-hash@ | 3 -- @project-revision@ @project-hash@ |
| 4 -- @file-revision@ @file-hash@ | 4 -- @file-revision@ @file-hash@ |
| 5 -- Created: 3/30/2016 12:49 AM | 5 -- Created: 3/30/2016 12:49 AM |
| 6 --- Everything that involves directly placing elements on the screen goes here. Sizing, spacing, tiling, etc. | |
| 6 local B = select(2,...).frame | 7 local B = select(2,...).frame |
| 7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') | 8 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') |
| 8 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band | 9 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band |
| 9 local IsResting, UnitXP, UnitXPMax, GetXPExhaustion, tinsert, tremove = IsResting, UnitXP, UnitXPMax, GetXPExhaustion, table.insert, table.remove | 10 local IsResting, UnitXP, UnitXPMax, GetXPExhaustion, tinsert, tremove = IsResting, UnitXP, UnitXPMax, GetXPExhaustion, table.insert, table.remove |
| 10 local UnitLevel, IsQuestWatched, UIParent = UnitLevel, IsQuestWatched, UIParent | 11 local UnitLevel, IsQuestWatched, UIParent = UnitLevel, IsQuestWatched, UIParent |
| 65 local titleFont, titleSize, titleOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 16, 'OUTLINE' | 66 local titleFont, titleSize, titleOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 16, 'OUTLINE' |
| 66 local titleColor = {0,.7,1,1} | 67 local titleColor = {0,.7,1,1} |
| 67 | 68 |
| 68 local textbg = {'HORIZONTAL', 0, 0, 0, 0.4, 0, 0, 0, 0 } | 69 local textbg = {'HORIZONTAL', 0, 0, 0, 0.4, 0, 0, 0, 0 } |
| 69 local textFont, textSize, textOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Regular.ttf]], 16, 'OUTLINE' | 70 local textFont, textSize, textOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Regular.ttf]], 16, 'OUTLINE' |
| 70 local textColor = {1,1,1,1} | 71 local textColor = {1,1,1,1 } |
| 72 | |
| 73 local widgetTextFont, widgetTextSize, widgetTextOutline = [[Interface\Addons\SharedMedia_MyMedia\font\XOIREQE.TTF]], 11, 'OUTLINE' | |
| 74 local widgetTextColor = {1,1,1,1 } | |
| 75 local widgetHeight, widgetBorder = 17, 1 | |
| 76 | |
| 71 | 77 |
| 72 local selectionbg = {'HORIZONTAL', 1, 1, 1, 0, 1, 1, 1, 0.225} | 78 local selectionbg = {'HORIZONTAL', 1, 1, 1, 0, 1, 1, 1, 0.225} |
| 73 local titleSpacing, textSpacing, blockSpacing = 3, 3, 1 | 79 local titleSpacing, textSpacing, blockSpacing = 3, 3, 1 |
| 74 local titleIndent, textIndent,selectionIndent = 2, 5, 50 | 80 local titleIndent, textIndent,selectionIndent = 2, 5, 50 |
| 75 --- END SCHEMA | 81 --- END SCHEMA |
| 123 rewardSize = c.rewardSize | 129 rewardSize = c.rewardSize |
| 124 blockSchema = newSchema | 130 blockSchema = newSchema |
| 125 elseif layer == 'line' then | 131 elseif layer == 'line' then |
| 126 textColor = c.textColor | 132 textColor = c.textColor |
| 127 lineSchema = newSchema | 133 lineSchema = newSchema |
| 134 elseif layer == 'widget' then | |
| 135 widgetTextColor = c.textSpacing | |
| 136 widgetTextFont, widgetTextSize, widgetTextOutline = unpack(c.textFont) | |
| 128 end | 137 end |
| 129 tprint('|cFFFF0088 Schema:|r', layer, lastSchema[layer], '->', newSchema) | 138 tprint('|cFFFF0088 Schema:|r', layer, lastSchema[layer], '->', newSchema) |
| 130 end | 139 end |
| 131 -- todo: figure out why objectives go invisible | 140 -- todo: figure out why objectives go invisible |
| 132 local anchorPoint, anchorFrame | 141 local anchorPoint, anchorFrame |
| 612 Wrapper:Show() | 621 Wrapper:Show() |
| 613 Scroller:Show() | 622 Scroller:Show() |
| 614 Scroll:Show() | 623 Scroll:Show() |
| 615 end | 624 end |
| 616 | 625 |
| 626 | |
| 627 ----------------------------------------- | |
| 628 -- Criteria frames | |
| 629 | |
| 630 --[[ | |
| 631 text = description, | |
| 632 type = type, | |
| 633 finished = completed, | |
| 634 quantity = quantity, | |
| 635 requiredQuantity = requiredQuantity, | |
| 636 characterName = characterName, | |
| 637 flags = flags, | |
| 638 assetID = assetID, | |
| 639 quantityString = quantityString, | |
| 640 criteriaID = criteriaID, | |
| 641 ]] | |
| 642 local newWidgetID = 0 | |
| 643 T.WidgetRegistry = {} | |
| 644 local wr = T.WidgetRegistry | |
| 645 | |
| 646 --- Get a usable widget for the given achievement criteria set. | |
| 647 -- Returns a frame object with dimensioning parameters needed to size the receiving tracker block | |
| 648 T.GetWidget = function(data, objectiveType, objectiveKey) | |
| 649 local print = B.print('ObjectiveWidgets') | |
| 650 local widgetType = objectiveType | |
| 651 local widget | |
| 652 local isNew | |
| 653 if wr[widgetType] and wr[widgetType].used[objectiveKey] then | |
| 654 widget = wr[widgetType].used[objectiveKey] | |
| 655 print('|cFF00FF00Updating ('..objectiveKey..')', widget) | |
| 656 elseif not wr[widgetType] or #wr[widgetType].free == 0 then | |
| 657 -- creating a new frame | |
| 658 isNew = true | |
| 659 widget = CreateFrame(widgetType, 'VeneerObjective' .. widgetType .. (wr[widgetType] and (wr[widgetType].lastn+1) or (1)), VeneerObjectiveScroll, 'VeneerObjectiveCriteria' .. widgetType) | |
| 660 print('|cFFFF0088Creating `'..widget:GetName()..'` id', wr[widgetType].lastn) | |
| 661 T.UpdateSchema(widgetType, data.schema or 'default') | |
| 662 else | |
| 663 -- recycling for a different criteria set | |
| 664 isNew = true | |
| 665 widget = tremove(wr[widgetType].free) | |
| 666 print('|cFFFFFF00Acquiring released widget', widget:GetName()) | |
| 667 end | |
| 668 | |
| 669 | |
| 670 wr[widgetType].used[objectiveKey] = widget | |
| 671 widget.objective = data | |
| 672 widget.key = objectiveKey | |
| 673 T.InitializeWidget(widget, isNew) | |
| 674 return widget | |
| 675 end | |
| 676 | |
| 677 --- WidgetTemplate 'OnLoad' | |
| 678 T.RegisterWidget = function(frame) | |
| 679 local print = B.print('ObjectiveWidgets') | |
| 680 local widgetType = frame.widgetType | |
| 681 if not wr[frame.widgetType] then | |
| 682 print('|cFFFF4400[[WidgetTemplate]]|r', widgetType) | |
| 683 wr[widgetType] = { lastn = 1, free = {}, used = {}, usedIndex = {}, freeIndex = {} } | |
| 684 else | |
| 685 print('|cFF0088FF+ [[WidgetTemplate]]r', widgetType, wr[widgetType].lastn) | |
| 686 wr[widgetType].lastn = wr[widgetType].lastn + 1 | |
| 687 end | |
| 688 end | |
| 689 --- WidgetTemplate 'OnShow' | |
| 690 local wrapperWidth, textIndent | |
| 691 T.InitializeWidget = setmetatable({}, { | |
| 692 __call = function(t, frame, isNew, ...) | |
| 693 -- todo: config pull | |
| 694 if not wrapperWidth then | |
| 695 wrapperWidth = T.Conf.Wrapper.Width | |
| 696 textIndent = T.Conf.Wrapper.TextIndent | |
| 697 end | |
| 698 | |
| 699 tprint('Initialize', frame:GetName(), isNew, ...) | |
| 700 frame:SetWidth(wrapperWidth - textIndent * 2) | |
| 701 frame:SetScript('OnEvent', T.UpdateWidget[frame.widgetType]) | |
| 702 frame:RegisterEvent('QUEST_LOG_UPDATE') | |
| 703 frame:RegisterEvent('TRACKED_ACHIEVEMENT_UPDATE') | |
| 704 frame:RegisterEvent('TRACKED_ACHIEVEMENT_LIST_CHANGED') | |
| 705 frame:RegisterEvent('CRITERIA_UPDATE') | |
| 706 frame:RegisterEvent('CRITERIA_COMPLETE') | |
| 707 frame:RegisterEvent('CRITERIA_EARNED') | |
| 708 t[frame.widgetType](frame, isNew) | |
| 709 T.UpdateWidget[frame.widgetType](frame, isNew) | |
| 710 end, | |
| 711 }) | |
| 712 | |
| 713 --- WidgetTemplate 'OnEvent' | |
| 714 T.UpdateWidget = setmetatable({}, { | |
| 715 __call = function(t, frame, isNew, ...) | |
| 716 tprint('Update', frame:GetName(), isNew, ...) | |
| 717 if not frame.widgetType then | |
| 718 return | |
| 719 end | |
| 720 | |
| 721 return t[frame.widgetType](frame, isNew) | |
| 722 end | |
| 723 }) | |
| 724 | |
| 725 | |
| 726 local progressHeight = 17 | |
| 727 local progressBorder = 1 | |
| 728 local progressFont = _G.VeneerCriteriaFontNormal | |
| 729 | |
| 730 local lprint = B.print('Line') | |
| 731 T.InitializeWidget.StatusBar = function(self, isNew) | |
| 732 local print = lprint | |
| 733 local c = T.Conf.Wrapper | |
| 734 | |
| 735 tprint(self:GetName(), isNew) | |
| 736 if isNew then | |
| 737 self.maxValue = self.maxValue or 1 | |
| 738 self:SetMinMaxValues(0, self.maxValue) | |
| 739 | |
| 740 self:SetHeight(widgetHeight) | |
| 741 self.height = widgetHeight | |
| 742 | |
| 743 self.status:SetFont(widgetTextFont, widgetTextSize, widgetTextOutline) | |
| 744 self.status:SetTextColor(unpack(widgetTextColor)) | |
| 745 end | |
| 746 self.value = self.value or 1 | |
| 747 self:SetValue(self.value) | |
| 748 | |
| 749 self.status:SetText(self.objective.quantityString) | |
| 750 end | |
| 751 | |
| 752 T.UpdateWidget.StatusBar = function (self) | |
| 753 local value, maxValue = self.value, self.maxValue | |
| 754 print('update vals:') | |
| 755 for k,v in pairs(self) do | |
| 756 print(k, v) | |
| 757 end | |
| 758 self.width = self.width or self:GetWidth() | |
| 759 self:SetValue(self.value) | |
| 760 local format = self.format or '%d/%d' | |
| 761 self.status:SetFormattedText(format, value, maxValue) | |
| 762 local progress = (value / maxValue) | |
| 763 if progress > 0 then | |
| 764 print('color:', 1-progress*2 , progress*2 - 1,0,1) | |
| 765 print('width:', (self.width -progressBorder * 2) * progress) | |
| 766 self:SetStatusBarColor(1-progress*2 , progress*2,0,1) | |
| 767 end | |
| 768 end | |
| 769 | |
| 770 | |
| 771 T.InitializeWidget.Hidden = function (self) | |
| 772 self.height = 0 | |
| 773 end | |
| 774 T.UpdateWidget.Hidden = function (self) | |
| 775 self.height= 0 | |
| 776 end | |
| 777 | |
| 778 | |
| 779 --- Queue any active item buttons for update for that frame | |
| 780 local iprint = B.print('ItemButton') | |
| 781 local Quest = T.Quest | |
| 782 local IsQuestWatched, InCombatLockdown = IsQuestWatched, InCombatLockdown | |
| 783 T.UpdateActionButtons = function(updateReason) | |
| 784 local print = iprint | |
| 785 Scroller.snap_upper = 0 | |
| 786 Scroller.snap_lower = 0 | |
| 787 local print = B.print('ItemButton') | |
| 788 if updateReason then | |
| 789 print = B.print('IB_'..updateReason) | |
| 790 end | |
| 791 | |
| 792 local previousItem | |
| 793 for questID, itemButton in pairs(Quest.itemButtons) do | |
| 794 local info= T.Quest.Info[questID] | |
| 795 | |
| 796 print('|cFF00FFFF'.. questID .. '|r', itemButton:GetName()) | |
| 797 local block = T.Quest.QuestBlock[questID] | |
| 798 if block then | |
| 799 -- Dispatch the probe | |
| 800 if IsQuestWatched(info.logIndex) then | |
| 801 itemButton.previousItem = previousItem | |
| 802 print(' |cFFFFFF00probing', block:GetName()) | |
| 803 block:SetScript('OnUpdate', function() | |
| 804 if block:GetBottom() and not InCombatLockdown() then | |
| 805 print(' '..block:GetName()..' |cFF00FF00probe hit!') | |
| 806 T.UpdateBlockAction(block, itemButton, itemButton.previousItem) -- needs to be previousItem from this scope | |
| 807 block:SetScript('OnUpdate', nil) | |
| 808 | |
| 809 end | |
| 810 end) | |
| 811 previousItem = itemButton | |
| 812 else | |
| 813 print('hidden block or unwatched quest') | |
| 814 itemButton.previousItem = nil | |
| 815 itemButton:Hide() | |
| 816 end | |
| 817 elseif itemButton:IsVisible() then | |
| 818 print(' |cFFFF0088hiding unwatched quest button', itemButton:GetName()) | |
| 819 itemButton.previousItem = nil | |
| 820 itemButton:Hide() | |
| 821 else | |
| 822 print(' |cFFBBBBBBignoring hidden log quest button', itemButton:GetName()) | |
| 823 end | |
| 824 end | |
| 825 end |
