comparison WorldPlan.lua @ 7:34d9fbf7af20

beginning of reflecting code path isolation in file structure
author Nenue
date Sat, 22 Oct 2016 15:36:25 -0400
parents 232617b8bcd5
children 802abb8a10ea
comparison
equal deleted inserted replaced
6:48001b6a9496 7:34d9fbf7af20
21 local QuestPOI = WorldPlanPOIMixin 21 local QuestPOI = WorldPlanPOIMixin
22 local FilterPin = WorldPlanFilterPinMixin 22 local FilterPin = WorldPlanFilterPinMixin
23 local WP_VERSION = "1.0" 23 local WP_VERSION = "1.0"
24 24
25 local print = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end 25 local print = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end
26 local qprint = DEVIAN_WORKSPACE and function(...) _G.print('POI', ...) end or function() end
27 local iprint = DEVIAN_WORKSPACE and function(...) _G.print('ItemScan', ...) end or function() end
28
26 local wipe, tremove, tinsert, pairs, floor, tContains = table.wipe, table.remove, table.insert, pairs, floor, tContains 29 local wipe, tremove, tinsert, pairs, floor, tContains = table.wipe, table.remove, table.insert, pairs, floor, tContains
27 local TQ_GetQuestInfoByQuestID = C_TaskQuest.GetQuestInfoByQuestID -- Return the name of a quest with a given ID 30 local TQ_GetQuestInfoByQuestID = C_TaskQuest.GetQuestInfoByQuestID -- Return the name of a quest with a given ID
28 local TQ_GetQuestsForPlayerByMapID = C_TaskQuest.GetQuestsForPlayerByMapID -- This function is not yet documented 31 local TQ_GetQuestsForPlayerByMapID = C_TaskQuest.GetQuestsForPlayerByMapID -- This function is not yet documented
29 local TQ_GetQuestTimeLeftMinutes = C_TaskQuest.GetQuestTimeLeftMinutes 32 local TQ_GetQuestTimeLeftMinutes = C_TaskQuest.GetQuestTimeLeftMinutes
30 local TQ_RequestPreloadRewardData = C_TaskQuest.RequestPreloadRewardData 33 local TQ_RequestPreloadRewardData = C_TaskQuest.RequestPreloadRewardData
43 local GetQuestLogRewardInfo, GetQuestLogRewardCurrencyInfo, GetMoneyString = GetQuestLogRewardInfo, GetQuestLogRewardCurrencyInfo, GetMoneyString 46 local GetQuestLogRewardInfo, GetQuestLogRewardCurrencyInfo, GetMoneyString = GetQuestLogRewardInfo, GetQuestLogRewardCurrencyInfo, GetMoneyString
44 47
45 local GetCurrentMapAreaID, GetMapNameByID, GetSuperTrackedQuestID = GetCurrentMapAreaID, GetMapNameByID, GetSuperTrackedQuestID 48 local GetCurrentMapAreaID, GetMapNameByID, GetSuperTrackedQuestID = GetCurrentMapAreaID, GetMapNameByID, GetSuperTrackedQuestID
46 local MC_GetNumZones, MC_GetZoneInfo = C_MapCanvas.GetNumZones, C_MapCanvas.GetZoneInfo 49 local MC_GetNumZones, MC_GetZoneInfo = C_MapCanvas.GetNumZones, C_MapCanvas.GetZoneInfo
47 50
48 local qprint = DEVIAN_WORKSPACE and function(...) _G.print('POI', ...) end or function() end
49 local iprint = DEVIAN_WORKSPACE and function(...) _G.print('ItemScan', ...) end or function() end
50 51
51 local SearchFaction 52 local SearchFaction
52 local PinBaseIndex = 1600 53 local PinBaseIndex = 1600
53 local ShowAllProfessionQuests = false 54 local ShowAllProfessionQuests = false
54 local DisplayContinentSummary = true 55 local DisplayContinentSummary = true
175 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PVP, label = 'PvP', texture = "Interface\\Icons\\Ability_PVP_GladiatorMedallion", spacing = 10 }, 176 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PVP, label = 'PvP', texture = "Interface\\Icons\\Ability_PVP_GladiatorMedallion", spacing = 10 },
176 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PET_BATTLE, label = 'Pet Battle', texture = "Interface\\Icons\\PetJournalPortrait", }, 177 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PET_BATTLE, label = 'Pet Battle', texture = "Interface\\Icons\\PetJournalPortrait", },
177 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_DUNGEON, label = 'Dungeon', texture = "Interface\\LFGFRAME\\UI-LFR-PORTRAIT", }, 178 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_DUNGEON, label = 'Dungeon', texture = "Interface\\LFGFRAME\\UI-LFR-PORTRAIT", },
178 } 179 }
179 180
180 local PIN_TIME_CONTEXT = {
181 {max = 60,
182 r=1, g=0.25, b =0, format = function (minutes) return '|cFFFF4400'.. minutes .. 'm' end,
183 continentAlpha = 1, swipeTime = 1440,
184 },
185 {max = 240,
186 r=1, g=.5, b=0, format = function(minutes) return '|cFFFF4400'.. floor(minutes/60) .. 'h' end,
187 continentAlpha = 1, swipeTime = 1440,
188 },
189 {max = 1440,
190 r=1, g=1, b=0, format = function(minutes) return '|cFFFFFF00'.. floor(minutes/60) .. 'h' end,
191 continentAlpha = .55, swipeTime = 1440
192 },
193 {max = 10081,
194 r=0, g=1, b=0,
195 continentAlpha = .3,
196 }, -- 7 days + 1 minute
197 }
198
199 local numPins = 0 181 local numPins = 0
200 local QuestsByZone = {} 182 local QuestsByZone = {}
201 local QuestsByFaction = {} 183 local QuestsByFaction = {}
202 local QuestsByReward = {} 184 local QuestsByReward = {}
203 local QuestsByTag = {} 185 local QuestsByTag = {}
497 else 479 else
498 local name = 'WorldPlanQuestMarker' .. NumPinFrames 480 local name = 'WorldPlanQuestMarker' .. NumPinFrames
499 --print('|cFF00FF00Creating', name) 481 --print('|cFF00FF00Creating', name)
500 pin = CreateFrame('Frame', name, WorldMapPOIFrame, 'WorldPlanQuestPin') 482 pin = CreateFrame('Frame', name, WorldMapPOIFrame, 'WorldPlanQuestPin')
501 pin:SetFrameStrata('HIGH') 483 pin:SetFrameStrata('HIGH')
502 pin:SetScript('OnEnter', function(self)
503 TaskPOI_OnEnter(self)
504 end)
505 pin:SetScript('OnLeave', function(self)
506 TaskPOI_OnLeave(self)
507 end)
508 pin:SetScript('OnMouseDown', TaskPOI_OnClick)
509 484
510 NumPinFrames = NumPinFrames + 1 485 NumPinFrames = NumPinFrames + 1
511 486
512 --pin.iconBorder:SetVertexColor(0,0,0,1) 487 --pin.iconBorder:SetVertexColor(0,0,0,1)
513 488
517 pin.currentWidth = nil 492 pin.currentWidth = nil
518 493
519 -- used by TaskPOI_x scripts 494 -- used by TaskPOI_x scripts
520 pin.questID = questID 495 pin.questID = questID
521 pin.worldQuest = true 496 pin.worldQuest = true
497
498 pin.Reset = function(self)
499 WorldQuests:GetPinByQuestID(questID)
500 end
522 else 501 else
523 --print('|cFF00FF00Using', pin:GetName()) 502 --print('|cFF00FF00Using', pin:GetName())
524 end 503 end
525 504
526 -- set display flags accordingly 505 -- set display flags accordingly
881 local tooltip = CreateFrame ("GameTooltip", "VeneerWorldQuestsScanner", nil, "GameTooltipTemplate") 860 local tooltip = CreateFrame ("GameTooltip", "VeneerWorldQuestsScanner", nil, "GameTooltipTemplate")
882 local tooltipLine1 = _G['VeneerWorldQuestsScannerTextLeft1'] 861 local tooltipLine1 = _G['VeneerWorldQuestsScannerTextLeft1']
883 local tooltipLine3 = _G['VeneerWorldQuestsScannerTextLeft3'] 862 local tooltipLine3 = _G['VeneerWorldQuestsScannerTextLeft3']
884 local GetTime, mod = GetTime, mod 863 local GetTime, mod = GetTime, mod
885 864
886 function QuestPOI:OnLoad() 865
887 self:RegisterEvent('SUPER_TRACKED_QUEST_CHANGED') 866
888 end 867
889
890 function QuestPOI:OnEvent(event, ...)
891 if event == 'SUPER_TRACKED_QUEST_CHANGED' then
892 if self:IsVisible() then
893 self:Refresh()
894 end
895 end
896 end
897
898 local PIN_UPDATE_DELAY = .016
899 local TOP_PIN_ID
900 function QuestPOI:OnUpdate (sinceLast)
901 -- control update check intervals
902 self.throttle = (self.throttle or PIN_UPDATE_DELAY) - sinceLast
903 if self.throttle <= 0 then
904 -- factor overtime into the throttle timer
905 self.throttle = PIN_UPDATE_DELAY - self.throttle
906 else
907 return
908 end
909
910 -- query for reward data if it wasn't found in the original scan
911 local questID = self.questID
912 if self.isPending then
913 WorldQuests:GetPinByQuestID(questID)
914 if not (self.PendingFade:IsPlaying() or self.isAnimating) then
915 self.PendingFade:Play()
916 end
917 return
918 else
919 if self.PendingFade:IsPlaying() then
920 self.PendingFade:Stop()
921 end
922 end
923
924 if self.hasUpdate then
925 self:Refresh()
926 self.hasUpdate = nil
927 end
928
929 -- update time elements
930 local tl = self.timeThreschold
931 local timeLeft = TQ_GetQuestTimeLeftMinutes(questID)
932 if timeLeft > 0 then
933 for i, context in ipairs(PIN_TIME_CONTEXT) do
934 if i > self.TimeleftStage then
935 self.timeLabel:SetText(nil)
936 break
937 end
938
939
940 if timeLeft <= context.max then
941 if tl ~= i then
942 tl = i
943 end
944
945 if context.format then
946 self.timeLabel:SetText(context.format(timeLeft))
947 else
948 self.timeLabel:SetText(nil)
949 end
950 break
951 end
952 end
953 else
954 -- remove self in a timely manner
955 if not self.isPending then
956 self:Hide()
957 end
958 end
959 self.timeThreschold = tl
960
961 if self:IsMouseOver() then
962 self.MouseGlow:Show()
963 else
964 self.MouseGlow:Hide()
965 end
966 end
967
968 function QuestPOI:OnShow ()
969 qprint('|cFFFFFF00["'..tostring(self.title)..'"]|r:OnShow()')
970 -- pop this on principle
971 self:Refresh()
972 end
973 function QuestPOI:OnHide()
974 --qprint('|cFFFFFF00["'..tostring(self.title)..'"]|r:OnHide()')
975 end
976 function QuestPOI:Refresh () 868 function QuestPOI:Refresh ()
977 print('|cFF00FF88["'..tostring(self.title)..'"]|r:Refresh()', tostring(self.title), "|T"..tostring(self.itemTexture)..":12:12|t", tostring(self.itemName)) 869 print('|cFF00FF88["'..tostring(self.title)..'"]|r:Refresh()', tostring(self.title), "|T"..tostring(self.itemTexture)..":12:12|t", tostring(self.itemName))
978 qprint(self.style) 870 qprint(self.style)
979 871
980 local questID = self.questId 872 local questID = self.questId
1033 self.label:SetText(nil) 925 self.label:SetText(nil)
1034 end 926 end
1035 qprint('|cFF88FF00updated', questID, self.title, self.rewardType, (style.showNumber and self.itemNumber) or '') 927 qprint('|cFF88FF00updated', questID, self.title, self.rewardType, (style.showNumber and self.itemNumber) or '')
1036 end 928 end
1037 929
1038 function QuestPOI:SetAnchor(frame, mapID, mapWidth, mapHeight) 930
1039 self:ClearAllPoints()
1040 local dX, dY = TQ_GetQuestLocation(self.questID, mapID)
1041 if not dX or dX == 0 then
1042 local _, x, y = QuestPOIGetIconInfo(self.questID)
1043 if x and floor(x) ~= 0 then
1044 dX, dY = x, y
1045 else
1046 dX, dY = self.x, self.y
1047 end
1048 end
1049 self.x = dX
1050 self.y = dY
1051
1052 print(' |cFF00FF00'..self.questID..':|r', format("%0.2f %0.2f", dX, dY))
1053
1054 local pX = (dX * mapWidth)
1055 local pY = (-dY * mapHeight)
1056
1057 self:SetParent(WorldMapPOIFrame)
1058 self:SetPoint('CENTER', frame, 'TOPLEFT', pX, pY)
1059 end
1060 931
1061 932
1062 function QuestPOI:IsShowable (ignoreFilters) 933 function QuestPOI:IsShowable (ignoreFilters)
1063 local qType = self.worldQuestType 934 local qType = self.worldQuestType
1064 local rType = self.rewardType 935 local rType = self.rewardType
1157 else 1028 else
1158 self.icon:Show() 1029 self.icon:Show()
1159 end 1030 end
1160 1031
1161 end 1032 end
1162
1163 1033
1164 1034
1165 function FilterBar:OnEvent(event) 1035 function FilterBar:OnEvent(event)
1166 if event == 'QUEST_LOG_UPDATE' then 1036 if event == 'QUEST_LOG_UPDATE' then
1167 self:Refresh() 1037 self:Refresh()