Mercurial > wow > worldplan
comparison ClassPlan.lua @ 4:4c7e9efec4b5
fix order of operations regarding frame visibility checking
| author | Nenue |
|---|---|
| date | Mon, 17 Oct 2016 12:59:24 -0400 |
| parents | c006ce87a147 |
| children | 4e1883842abf |
comparison
equal
deleted
inserted
replaced
| 3:c006ce87a147 | 4:4c7e9efec4b5 |
|---|---|
| 1 local wipe = table.wipe | 1 local wipe, tinsert, sort = table.wipe, tinsert, table.sort |
| 2 local pairs, ipairs = pairs, ipairs | 2 local pairs, ipairs = pairs, ipairs |
| 3 local floor, mod, time = floor, mod, time | |
| 3 local GetTime = GetTime | 4 local GetTime = GetTime |
| 4 local GI_currentTime = time() | 5 local GI_currentTime = time() |
| 5 | 6 |
| 6 | 7 local BOUND_FRAMES = {} |
| 7 local blockTemplate = { | 8 local blockTemplate = { |
| 8 point = 'TOPLEFT', | 9 point = 'TOPLEFT', |
| 9 relativePoint ='TOPLEFT', | 10 relativePoint ='TOPLEFT', |
| 10 } | 11 } |
| 11 | 12 |
| 25 playerFirst = false, | 26 playerFirst = false, |
| 26 prototypes = {} | 27 prototypes = {} |
| 27 } | 28 } |
| 28 ClassPlanBlockMixin = { | 29 ClassPlanBlockMixin = { |
| 29 templateName = 'ClassPlanBlock', | 30 templateName = 'ClassPlanBlock', |
| 30 events = {'GARRISON_MISSION_LIST_UPDATE', 'GARRISON_MISSION_FINISHED', 'GARRISON_MISSION_FINISHED'},} | 31 events = {'GARRISON_MISSION_LIST_UPDATE', 'GARRISON_MISSION_STARTED', 'GARRISON_MISSION_FINISHED'},} |
| 31 ClassPlanShipmentMixin = { | 32 ClassPlanShipmentMixin = { |
| 32 templateName = 'ClassPlanShipment', | 33 templateName = 'ClassPlanShipment', |
| 33 parent = false, | 34 parent = false, |
| 34 point = 'TOPRIGHT', | 35 point = 'TOPRIGHT', |
| 35 relativePoint ='TOPRIGHT', | 36 relativePoint ='TOPRIGHT', |
| 36 events = {'GARRISON_LANDINGPAGE_SHIPMENTS', 'GARRISON_TALENT_UPDATE', "GARRISON_TALENT_COMPLETE", 'GARRISON_TALENT_COMPLETE', 'GARRISON_SHIPMENT_RECEIVED', "GARRISON_SHIPMENT_RECEIVED"}, | 37 events = {'GARRISON_LANDINGPAGE_SHIPMENTS', 'GARRISON_TALENT_UPDATE', "GARRISON_TALENT_COMPLETE", "GARRISON_SHIPMENT_RECEIVED"}, |
| 37 } | 38 } |
| 38 setmetatable(ClassPlanShipmentMixin, {__index = ClassPlanBlockMixin}) | 39 setmetatable(ClassPlanShipmentMixin, {__index = ClassPlanBlockMixin}) |
| 39 local core, MissionsHandler, ShipmentsHandler = ClassOrderPlanCore, ClassPlanBlockMixin, ClassPlanShipmentMixin | 40 local core, MissionsHandler, ShipmentsHandler = ClassOrderPlanCore, ClassPlanBlockMixin, ClassPlanShipmentMixin |
| 40 local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop | 41 local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop |
| 41 | 42 |
| 42 | 43 local GetTimeLeftString = function(timeLeft) |
| 44 local days = floor(timeLeft/(24*3600)) | |
| 45 local hours = floor(mod(timeLeft, (24*3600)) / 3600) | |
| 46 local minutes = floor(mod(timeLeft, 3600) / 60) | |
| 47 local seconds = mod(timeLeft, 60) | |
| 48 if days >= 1 then | |
| 49 return (days .. 'd' .. ' ') .. ((hours > 0) and (hours .. 'h ') or '') | |
| 50 else | |
| 51 return ((hours > 0) and (hours .. 'h ') or '') .. ((minutes > 0) and (minutes .. ' min') or '') | |
| 52 end | |
| 53 end | |
| 43 | 54 |
| 44 MissionsHandler.GetPlayerData = function(self) | 55 MissionsHandler.GetPlayerData = function(self) |
| 45 if not self.profile then | 56 if not self.profile then |
| 46 return | 57 return |
| 47 end | 58 end |
| 48 self.items = C_Garrison.GetLandingPageItems(LE_GARRISON_TYPE_7_0) | 59 self.items = C_Garrison.GetLandingPageItems(LE_GARRISON_TYPE_7_0) |
| 49 | 60 |
| 50 if #self.items >= 1 then | 61 wipe(self.profile.missions) |
| 51 wipe(self.profile.missions) | 62 for index, data in ipairs(self.items) do |
| 52 for index, data in ipairs(self.items) do | 63 print(' ',data.name, '|cFF00FF00'.. data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime)) |
| 53 print(' ',data.name, '|cFF00FF00'.. data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime)) | 64 tinsert(self.profile.missions, data) |
| 54 tinsert(self.profile.missions, data) | 65 end |
| 55 end | 66 print('items update pending') |
| 56 print('items update pending') | 67 self.isStale = true |
| 57 self.isStale = true | |
| 58 end | |
| 59 | 68 |
| 60 if self:IsVisible() then | 69 if self:IsVisible() then |
| 61 self:Refresh() | 70 self:Refresh() |
| 62 end | 71 end |
| 63 end | 72 end |
| 64 | 73 |
| 74 MissionsHandler.FreeBlock = function(self, block) | |
| 75 end | |
| 76 | |
| 65 MissionsHandler.SortHandler = function (a,b) | 77 MissionsHandler.SortHandler = function (a,b) |
| 66 local result = false | 78 local result = false |
| 67 if not a or not b then | 79 --if not a or not b then |
| 68 result = true | 80 -- return true |
| 69 else | 81 --else |
| 70 if (a.isMine ~= b.isMine) then | 82 --if (a.isMine ~= b.isMine) then |
| 71 result = a.isMine | 83 -- result = a.isMine |
| 72 else | 84 --else |
| 73 if (not b.missionEndTime) or (not a.missionEndTime) then | 85 --if (not b.missionEndTime) or (not a.missionEndTime) then |
| 74 print('missing article', b.missionEndTime, a.missionEndTime) | 86 -- print('missing article', b.missionEndTime, a.missionEndTime) |
| 75 end | 87 --end |
| 76 result = ( b.missionEndTime > a.missionEndTime) | 88 return ( b.missionEndTime > a.missionEndTime) |
| 77 end | 89 --end |
| 78 end | 90 --end |
| 79 return result | |
| 80 end | 91 end |
| 81 | 92 |
| 82 | 93 |
| 83 ShipmentsHandler.OnGetItem = function(data) | 94 ShipmentsHandler.OnGetItem = function(data) |
| 84 if data.shipmentsTotal then | 95 if data.shipmentsTotal then |
| 97 end | 108 end |
| 98 | 109 |
| 99 ShipmentsHandler.SortHandler = function(a, b) | 110 ShipmentsHandler.SortHandler = function(a, b) |
| 100 if b.isComplete ~= a.isComplete then | 111 if b.isComplete ~= a.isComplete then |
| 101 return a.isComplete and true or false | 112 return a.isComplete and true or false |
| 102 end | 113 elseif a.shipmentsReady or b.shipmentsReady then |
| 103 return (a.creationTime) < (b.creationTime) | 114 return (a.shipmentsReady or 0) > (b.shipmentsReady or 0) |
| 104 end | 115 else |
| 105 | 116 return (a.creationTime) < (b.creationTime) |
| 117 end | |
| 118 end | |
| 119 | |
| 120 local AddShipmentInfo = function(self, shipmentType, name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID, followerID) | |
| 121 -- early login queries may return empty tables, causing the sorter to compare nil | |
| 122 if not creationTime then | |
| 123 return | |
| 124 end | |
| 125 print(shipmentType, name, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString) | |
| 126 tinsert(self.shipments, | |
| 127 { | |
| 128 shipmentType = shipmentType, | |
| 129 name = name, | |
| 130 icon = texture, | |
| 131 shipmentCapacity = shipmentCapacity, | |
| 132 shipmentsReady = shipmentsReady, | |
| 133 shipmentsTotal = shipmentsTotal, | |
| 134 creationTime = creationTime, | |
| 135 duration = duration, | |
| 136 timeleftString = timeleftString, | |
| 137 itemName = itemName, | |
| 138 itemIcon = itemIcon, | |
| 139 itemQuality = itemQuality, | |
| 140 itemID = itemID, | |
| 141 followerID = followerID, | |
| 142 }) | |
| 143 end | |
| 106 ShipmentsHandler.GetPlayerData = function (self) | 144 ShipmentsHandler.GetPlayerData = function (self) |
| 107 if not self.profile then | 145 if not self.profile then |
| 108 return | 146 return |
| 109 end | 147 end |
| 110 wipe(self.shipments) | 148 wipe(self.shipments) |
| 114 local buildings = C_Garrison.GetBuildings(garrisonType); | 152 local buildings = C_Garrison.GetBuildings(garrisonType); |
| 115 local shipmentIndex = 0 | 153 local shipmentIndex = 0 |
| 116 --print('Buildings:') | 154 --print('Buildings:') |
| 117 for i = 1, #buildings do | 155 for i = 1, #buildings do |
| 118 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID = C_Garrison.GetLandingPageShipmentInfo(buildingID); | 156 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID = C_Garrison.GetLandingPageShipmentInfo(buildingID); |
| 119 tinsert(self.shipments, | 157 AddShipmentInfo(self, 'Building', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID) |
| 120 { | |
| 121 shipmentType = 'Work Order', | |
| 122 name = name, | |
| 123 icon = texture, | |
| 124 shipmentCapacity = shipmentCapacity, | |
| 125 shipmentsReady = shipmentsReady, | |
| 126 shipmentsTotal = shipmentsTotal, | |
| 127 creationTime = creationTime, | |
| 128 duration = duration, | |
| 129 timeleftString = timeleftString, | |
| 130 itemName = itemName, | |
| 131 itemIcon = itemIcon, | |
| 132 itemQuality = itemQuality, | |
| 133 itemID = itemID | |
| 134 }) | |
| 135 end | 158 end |
| 136 | 159 |
| 137 --print('Follower:') | 160 --print('Follower:') |
| 138 local followerShipments = C_Garrison.GetFollowerShipments(garrisonType); | 161 local followerShipments = C_Garrison.GetFollowerShipments(garrisonType); |
| 139 for i = 1, #followerShipments do | 162 for i = 1, #followerShipments do |
| 140 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, _, _, _, _, followerID = C_Garrison.GetLandingPageShipmentInfoByContainerID(followerShipments[i]); | 163 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, _, _, _, _, followerID = C_Garrison.GetLandingPageShipmentInfoByContainerID(followerShipments[i]); |
| 141 tinsert(self.shipments, | 164 AddShipmentInfo(self, 'Follower', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, nil, nil, nil, nil, followerID) |
| 142 { | |
| 143 shipmentType = '', | |
| 144 name = name, | |
| 145 icon = texture, | |
| 146 shipmentCapacity = shipmentCapacity, | |
| 147 shipmentsReady = shipmentsReady, | |
| 148 shipmentsTotal = shipmentsTotal, | |
| 149 creationTime = creationTime, | |
| 150 duration = duration, | |
| 151 timeleftString = timeleftString, | |
| 152 followerID = followerID, | |
| 153 }) | |
| 154 end | 165 end |
| 155 | 166 |
| 156 --print('Loose:') | 167 --print('Loose:') |
| 157 local looseShipments = C_Garrison.GetLooseShipments(garrisonType) | 168 local looseShipments = C_Garrison.GetLooseShipments(garrisonType) |
| 158 for i = 1, #looseShipments do | 169 for i = 1, #looseShipments do |
| 159 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString = C_Garrison.GetLandingPageShipmentInfoByContainerID(looseShipments[i]); | 170 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString = C_Garrison.GetLandingPageShipmentInfoByContainerID(looseShipments[i]); |
| 160 tinsert(self.shipments, | 171 AddShipmentInfo(self, 'Follower', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString) |
| 161 { | |
| 162 shipmentType = '', | |
| 163 name = name, | |
| 164 icon = texture, | |
| 165 shipmentCapacity = shipmentCapacity, | |
| 166 shipmentsReady = shipmentsReady, | |
| 167 shipmentsTotal = shipmentsTotal, | |
| 168 creationTime = creationTime, | |
| 169 duration = duration, | |
| 170 timeleftString = timeleftString, | |
| 171 }) | |
| 172 end | 172 end |
| 173 | 173 |
| 174 local talentTrees = C_Garrison.GetTalentTrees(garrisonType, select(3, UnitClass("player"))); | 174 local talentTrees = C_Garrison.GetTalentTrees(garrisonType, select(3, UnitClass("player"))); |
| 175 -- this is a talent that has completed, but has not been seen in the talent UI yet. | 175 -- this is a talent that has completed, but has not been seen in the talent UI yet. |
| 176 local completeTalentID = C_Garrison.GetCompleteTalent(garrisonType); | 176 local completeTalentID = C_Garrison.GetCompleteTalent(garrisonType); |
| 177 --print('Talents:') | 177 --print('Talents:') |
| 178 if (talentTrees) then | 178 if (talentTrees) then |
| 179 for treeIndex, tree in ipairs(talentTrees) do | 179 for treeIndex, tree in ipairs(talentTrees) do |
| 180 for talentIndex, talent in ipairs(tree) do | 180 for talentIndex, talent in ipairs(tree) do |
| 181 local showTalent = false; | 181 local showTalent = false; |
| 182 if (talent.isBeingResearched) then | 182 if (talent.isBeingResearched) or (talent.id == completeTalentID) then |
| 183 showTalent = true; | 183 AddShipmentInfo(self, 'Talent', talent.name, talent.icon, 1, (talent.isBeingResearched and 0 or 1), 1, talent.researchStartTime, talent.researchDuration, talent.timeleftString) |
| 184 end | |
| 185 if (talent.id == completeTalentID) then | |
| 186 showTalent = true; | |
| 187 end | |
| 188 if (showTalent) then | |
| 189 print(talent.name) | |
| 190 talent.creationTime = talent.researchStartTime | |
| 191 talent.duration = talent.researchDuration | |
| 192 talent.shipmentType = 'Talent: ' | |
| 193 tinsert(self.shipments, talent) | |
| 194 end | 184 end |
| 195 end | 185 end |
| 196 end | 186 end |
| 197 end | 187 end |
| 198 | 188 |
| 199 self.profile.shipments = self.profile.shipments or {} | 189 self.profile.shipments = self.profile.shipments or {} |
| 200 if #self.shipments >= 1 then | 190 if #self.shipments >= 1 then |
| 201 | |
| 202 | |
| 203 wipe(self.profile.shipments) | 191 wipe(self.profile.shipments) |
| 204 for index, data in ipairs(self.shipments) do | 192 for index, data in ipairs(self.shipments) do |
| 205 print(' ', data.shipmentType .. data.name, data.creationTime, data.duration) | 193 |
| 194 --DEFAULT_CHAT_FRAME:AddMessage(data.shipmentType ..' '.. tostring(data.name) ..' '.. tostring(data.creationTime) ..' '.. tostring(data.duration)) | |
| 206 tinsert(self.profile.shipments, data) | 195 tinsert(self.profile.shipments, data) |
| 207 end | 196 end |
| 208 self.isStale = true | 197 self.isStale = true |
| 209 end | 198 end |
| 210 | 199 |
| 217 self:RegisterUnitEvent('UNIT_PORTRAIT_UPDATE', 'player') | 206 self:RegisterUnitEvent('UNIT_PORTRAIT_UPDATE', 'player') |
| 218 self:RegisterEvent('PLAYER_LOGIN') | 207 self:RegisterEvent('PLAYER_LOGIN') |
| 219 self:RegisterEvent('PLAYER_ENTERING_WORLD') | 208 self:RegisterEvent('PLAYER_ENTERING_WORLD') |
| 220 self:RegisterEvent('ADDON_LOADED') | 209 self:RegisterEvent('ADDON_LOADED') |
| 221 self:RegisterEvent('PLAYER_REGEN_ENABLED') | 210 self:RegisterEvent('PLAYER_REGEN_ENABLED') |
| 211 -- Blizzard_GarrisonUI already fires a shipment data request for GARRISON_SHIPMENT_RECEIVED; this is unlikely to | |
| 212 | |
| 222 | 213 |
| 223 self:AddHandler('missions', MissionsHandler) | 214 self:AddHandler('missions', MissionsHandler) |
| 224 self:AddHandler('shipments', ShipmentsHandler) | 215 self:AddHandler('shipments', ShipmentsHandler) |
| 216 | |
| 217 | |
| 218 self:Reanchor() | |
| 219 end | |
| 220 local parentFrames = {'VeneerWorldState', 'OrderHallCommandBar'} | |
| 221 function core:Reanchor() | |
| 222 | |
| 223 | |
| 224 self:ClearAllPoints() | |
| 225 | |
| 226 self.anchorParent = UIParent | |
| 227 for i, name in ipairs(parentFrames) do | |
| 228 local frame = _G[name] | |
| 229 if frame then | |
| 230 if not BOUND_FRAMES[frame] then | |
| 231 BOUND_FRAMES[frame] = {visible = frame:IsVisible()} | |
| 232 hooksecurefunc(frame, 'Show', function() | |
| 233 BOUND_FRAMES[frame].visible = true | |
| 234 print(frame:GetName(), 'Show', 'reanchor trigger') | |
| 235 self:Reanchor() | |
| 236 end) | |
| 237 hooksecurefunc(frame, 'Hide', function() | |
| 238 BOUND_FRAMES[frame].visible = false | |
| 239 print(frame:GetName(), 'Hide', 'reanchor trigger') | |
| 240 self:Reanchor() | |
| 241 end) | |
| 242 end | |
| 243 print('f:', frame:GetName(), frame:IsVisible()) | |
| 244 if BOUND_FRAMES[frame].visible then | |
| 245 self.anchorParent = frame | |
| 246 break | |
| 247 end | |
| 248 end | |
| 249 end | |
| 250 print('|cFFFF8800Using ' .. tostring(self.anchorParent:GetName()) .. ' as anchor point') | |
| 251 | |
| 252 if self:IsVisible() then | |
| 253 self:SetPoint('TOP', ClassPlanButton, 'BOTTOM', 0, 0) | |
| 254 ClassPlanButton.Background:Show() | |
| 255 ClassPlanButton:SetWidth(600) | |
| 256 else | |
| 257 ClassPlanButton.Background:Hide() | |
| 258 ClassPlanButton:SetWidth(200) | |
| 259 end | |
| 260 | |
| 261 ClassPlanButton:SetPoint('TOP', self.anchorParent, (self.anchorPoint == UIParent) and 'TOP' or 'BOTTOM', 0, 0) | |
| 262 | |
| 225 end | 263 end |
| 226 | 264 |
| 227 function core:AddHandler(name, prototype) | 265 function core:AddHandler(name, prototype) |
| 228 self.prototypes[name] = setmetatable(prototype, { | 266 self.prototypes[name] = setmetatable(prototype, { |
| 229 __index = blockTemplate, | 267 __index = blockTemplate, |
| 242 print('adding', name, 'to', event) | 280 print('adding', name, 'to', event) |
| 243 self.events[event][name] = prototype.GetPlayerData | 281 self.events[event][name] = prototype.GetPlayerData |
| 244 end | 282 end |
| 245 end | 283 end |
| 246 self.sortedItems[name] = {} | 284 self.sortedItems[name] = {} |
| 285 end | |
| 286 | |
| 287 function core:Setup() | |
| 288 if IsLoggedIn() then | |
| 289 WorldPlanData.OrderHall = WorldPlanData.OrderHall or {} | |
| 290 self.data = WorldPlanData.OrderHall | |
| 291 self.data.characters = self.data.characters or {} | |
| 292 | |
| 293 local name, realm = UnitName('player') | |
| 294 realm = realm or GetRealmName() | |
| 295 self.profileKey = name .. '-' .. realm | |
| 296 if not self.data.characters[self.profileKey] then | |
| 297 self.data.characters[self.profileKey] = {} | |
| 298 end | |
| 299 self.profile = self.data.characters[self.profileKey] | |
| 300 | |
| 301 self.profile.shipments = self.profile.shipments or {} | |
| 302 self.profile.missions = self.profile.missions or {} | |
| 303 self.profile.classColor = RAID_CLASS_COLORS[select(2, UnitClass('player'))] | |
| 304 | |
| 305 if self.data.IsShown then | |
| 306 self:Show() | |
| 307 end | |
| 308 self.initialized = true | |
| 309 end | |
| 247 end | 310 end |
| 248 | 311 |
| 249 function core:OnEvent (event, ...) | 312 function core:OnEvent (event, ...) |
| 250 print(event) | 313 print(event) |
| 251 if event == 'UNIT_PORTRAIT_UPDATE' then | 314 if event == 'UNIT_PORTRAIT_UPDATE' then |
| 252 SetPortraitTexture(self.portrait, 'player') | 315 SetPortraitTexture(self.portrait, 'player') |
| 253 elseif event == 'PLAYER_LOGIN' then | 316 elseif event == 'PLAYER_LOGIN' then |
| 254 if not self.initialized then | 317 if not self.initialized then |
| 255 if IsLoggedIn() then | 318 self:Setup() |
| 256 WorldPlanData.OrderHall = WorldPlanData.OrderHall or {} | 319 end |
| 257 self.data = WorldPlanData.OrderHall | 320 elseif self.initialized and self.events[event] then |
| 258 | 321 local numCalls = 0 |
| 259 | |
| 260 local name, realm = UnitName('player') | |
| 261 realm = realm or GetRealmName() | |
| 262 self.profileKey = name .. '-' .. realm | |
| 263 if not self.data[self.profileKey] then | |
| 264 self.data[self.profileKey] = {} | |
| 265 end | |
| 266 self.profile = self.data[self.profileKey] | |
| 267 | |
| 268 self.profile.shipments = self.profile.shipments or {} | |
| 269 self.profile.missions = self.profile.missions or {} | |
| 270 self.profile.classColor = RAID_CLASS_COLORS[select(2, UnitClass('player'))] | |
| 271 | |
| 272 C_Garrison.RequestLandingPageShipmentInfo(); | |
| 273 | |
| 274 if self.data.IsShown then | |
| 275 self:Show() | |
| 276 end | |
| 277 self.initialized = true | |
| 278 end | |
| 279 end | |
| 280 elseif self.events[event] then | |
| 281 for ptype, eventFunc in pairs(self.events[event]) do | 322 for ptype, eventFunc in pairs(self.events[event]) do |
| 282 print('|cFF88FF00' .. tostring(ptype) .. '|r:GetPlayerData()') | 323 numCalls = numCalls + 1 |
| 324 print('|cFF88FF00' .. tostring(ptype) .. '|r:GetPlayerData() --', numCalls) | |
| 283 eventFunc(self, event) | 325 eventFunc(self, event) |
| 284 end | 326 end |
| 285 end | 327 end |
| 286 end | 328 end |
| 287 | 329 |
| 288 function core:UpdateNotifications() | 330 function core:UpdateNotifications() |
| 331 end | |
| 332 | |
| 333 | |
| 334 local SetOwnerData = function(self, data) | |
| 335 local name, realm = string.match(data.profileKey, "(.+)%-(.+)") | |
| 336 local ownerText = '|c'.. data.classColor.colorStr .. name .. '|r' | |
| 337 if realm ~= GI_currentRealm then | |
| 338 ownerText = ownerText .. ' (' .. realm .. ')' | |
| 339 end | |
| 340 self.Owner:SetText(ownerText) | |
| 341 self.Background:SetColorTexture(data.classColor.r, data.classColor.g, data.classColor.b) | |
| 289 end | 342 end |
| 290 | 343 |
| 291 function core:RefreshItems(configKey, prototype) | 344 function core:RefreshItems(configKey, prototype) |
| 292 local sortedItems = self.sortedItems[configKey] | 345 local sortedItems = self.sortedItems[configKey] |
| 293 | 346 |
| 301 local block = blocks[i] | 354 local block = blocks[i] |
| 302 | 355 |
| 303 if not block then | 356 if not block then |
| 304 block = CreateFrame('Button', nil, self, prototype.templateName) | 357 block = CreateFrame('Button', nil, self, prototype.templateName) |
| 305 block:SetID(i) | 358 block:SetID(i) |
| 359 block.handler = prototype | |
| 306 prototype.numBlocks = prototype.numBlocks + 1 | 360 prototype.numBlocks = prototype.numBlocks + 1 |
| 307 | 361 |
| 308 if prototype.lastBlock then | 362 if prototype.lastBlock then |
| 309 block:SetPoint('TOPLEFT', prototype.lastBlock, 'BOTTOMLEFT', 0, 0) | 363 block:SetPoint('TOPLEFT', prototype.lastBlock, 'BOTTOMLEFT', 0, 0) |
| 310 else | 364 else |
| 314 blocks[i] = block | 368 blocks[i] = block |
| 315 end | 369 end |
| 316 | 370 |
| 317 totalHeight = totalHeight + block:GetHeight() | 371 totalHeight = totalHeight + block:GetHeight() |
| 318 block.lastProfile = lastProfile | 372 block.lastProfile = lastProfile |
| 373 for k,v in pairs(data) do | |
| 374 if type(block[k]) ~= 'function' then | |
| 375 block[k] = v | |
| 376 end | |
| 377 end | |
| 319 block:Refresh(data) | 378 block:Refresh(data) |
| 379 SetOwnerData(block, data) | |
| 380 | |
| 320 block:Show() | 381 block:Show() |
| 321 lastProfile = data.profileKey | 382 lastProfile = data.profileKey |
| 322 end | 383 end |
| 323 | 384 |
| 324 for i = numItems + 1, prototype.numBlocks do | 385 for i = numItems + 1, prototype.numBlocks do |
| 340 for name, info in pairs(self.prototypes) do | 401 for name, info in pairs(self.prototypes) do |
| 341 local itemsHeight = self:RefreshItems(name, info) | 402 local itemsHeight = self:RefreshItems(name, info) |
| 342 self.currentHeight = max(itemsHeight, self.currentHeight) | 403 self.currentHeight = max(itemsHeight, self.currentHeight) |
| 343 end | 404 end |
| 344 | 405 |
| 345 if OrderHallCommandBar and OrderHallCommandBar:IsVisible() then | 406 self:Reanchor() |
| 346 self:ClearAllPoints() | |
| 347 self:SetPoint('TOP', OrderHallCommandBar, 'BOTTOM') | |
| 348 else | |
| 349 | |
| 350 local posX = self.data.posX or 0 | |
| 351 local posY = self.data.posY or -24 | |
| 352 local point = self.point or 'TOP' | |
| 353 local relativePoint = self.point or 'TOP' | |
| 354 self:SetPoint(point, UIParent, relativePoint, posX, posY) | |
| 355 end | |
| 356 | |
| 357 self:SetHeight(self.currentHeight) | 407 self:SetHeight(self.currentHeight) |
| 358 end | 408 end |
| 359 | 409 |
| 360 function core:Toggle() | 410 function core:Toggle() |
| 361 if self:IsVisible() then | 411 if self:IsVisible() then |
| 378 function core:OnShow() | 428 function core:OnShow() |
| 379 if self.isStale then | 429 if self.isStale then |
| 380 print('updating items on show') | 430 print('updating items on show') |
| 381 self:Refresh() | 431 self:Refresh() |
| 382 end | 432 end |
| 383 ClassPlanButton:SetPoint('TOP', self, 'TOP', 0, 0) | 433 -- grab this at least once |
| 434 C_Garrison.RequestLandingPageShipmentInfo(); | |
| 435 ClassPlanButton.Background:Show() | |
| 436 ClassPlanButton.Grip:SetShown(true) | |
| 384 end | 437 end |
| 385 function core:OnHide() | 438 function core:OnHide() |
| 386 ClassPlanButton:SetPoint('TOP', UIParent, 'TOP', 0, 0) | 439 ClassPlanButton.Background:Hide() |
| 440 ClassPlanButton.Grip:SetShown(false) | |
| 387 end | 441 end |
| 388 | 442 |
| 389 local GI_profileKey, GI_profile, GI_isMine | 443 local GI_profileKey, GI_profile, GI_isMine |
| 390 local GetItemList = function (source, dest, onGetItem) | 444 local defaultClassColor = {r = 0.7, g = 0.7, b =0.7, colorStr = "ffffffff"} |
| 445 local DoItemList = function (source, dest, onGetItem) | |
| 391 if not source then | 446 if not source then |
| 392 return | 447 return |
| 393 end | 448 end |
| 394 local numItems = 0 | 449 local numItems = 0 |
| 395 for index, data in ipairs(source) do | 450 for index, data in ipairs(source) do |
| 396 data.classColor = GI_profile.classColor or {r = 0.7, g = 0.7, b =0.7} | 451 data.classColor = GI_profile.classColor or defaultClassColor |
| 397 data.profileKey = GI_profileKey | 452 data.profileKey = GI_profileKey |
| 398 data.isMine = GI_isMine | 453 data.isMine = GI_isMine |
| 399 if onGetItem then | 454 if onGetItem then |
| 400 onGetItem(data) | 455 onGetItem(data) |
| 401 end | 456 end |
| 410 GI_currentTime = time() | 465 GI_currentTime = time() |
| 411 | 466 |
| 412 for key, sortedItems in pairs(self.sortedItems) do | 467 for key, sortedItems in pairs(self.sortedItems) do |
| 413 wipe(sortedItems) | 468 wipe(sortedItems) |
| 414 local ptype = self.prototypes[key] | 469 local ptype = self.prototypes[key] |
| 415 print( 'object:', ptype) | 470 --print( 'object:', ptype) |
| 416 for name, profile in pairs(self.data.characters) do | 471 for name, profile in pairs(self.data.characters) do |
| 417 GI_profileKey = name | 472 GI_profileKey = name |
| 418 GI_profile = profile | 473 GI_profile = profile |
| 419 GI_isMine = (profile == self.profile) | 474 GI_isMine = (profile == self.profile) |
| 420 | 475 local results = DoItemList(profile[key], sortedItems, ptype.OnGetItem) |
| 421 local results = GetItemList(profile[key], sortedItems, ptype.OnGetItem) | 476 --print(' - ', name, results, 'items') |
| 422 print(' - ', name, results, 'items') | |
| 423 | |
| 424 end | 477 end |
| 425 | 478 |
| 426 if ptype.SortHandler then | 479 if ptype.SortHandler then |
| 427 print(' sorting', key, #sortedItems) | 480 sort(sortedItems, ptype.SortHandler) |
| 428 table.sort(sortedItems, ptype.SortHandler) | 481 end |
| 429 end | 482 end |
| 430 end | |
| 431 end | |
| 432 | |
| 433 | |
| 434 | |
| 435 function core:UpdateItems () | |
| 436 end | 483 end |
| 437 | 484 |
| 438 function MissionsHandler:OnComplete() | 485 function MissionsHandler:OnComplete() |
| 439 self.data.isComplete = true | 486 self.isComplete = true |
| 440 self:Refresh() | 487 self:Refresh() |
| 441 end | 488 end |
| 442 | 489 |
| 443 local GetTimeLeftString = function(timeLeft) | |
| 444 | |
| 445 local days = floor(timeLeft/(24*3600)) | |
| 446 local hours = floor(mod(timeLeft, (24*3600)) / 3600) | |
| 447 local minutes = floor(mod(timeLeft, 3600) / 60) | |
| 448 local seconds = mod(timeLeft, 60) | |
| 449 if days >= 1 then | |
| 450 return (days .. 'd' .. ' ') .. ((hours > 0) and (hours .. 'h ') or '') | |
| 451 else | |
| 452 return ((hours > 0) and (hours .. 'h ') or '') .. ((minutes > 0) and (minutes .. ' min') or '') | |
| 453 end | |
| 454 end | |
| 455 | |
| 456 function MissionsHandler:OnUpdate() | 490 function MissionsHandler:OnUpdate() |
| 457 if self.data.isComplete then | 491 if self.isComplete then |
| 458 return | 492 return |
| 459 end | 493 end |
| 460 | 494 |
| 461 if self.missionEndTime then | 495 if self.missionEndTime then |
| 462 local timeLeft = self.missionEndTime - time() | 496 local timeLeft = self.missionEndTime - time() |
| 475 else | 509 else |
| 476 self.TimeLeft:SetText(self.missionEndTime) | 510 self.TimeLeft:SetText(self.missionEndTime) |
| 477 end | 511 end |
| 478 end | 512 end |
| 479 | 513 |
| 480 local SetClassColors = function(self, data) | 514 function MissionsHandler:Refresh() |
| 481 | 515 |
| 482 if self.lastProfile ~= data.profileKey then | |
| 483 self.Owner:SetText(data.profileKey) | |
| 484 self.Owner:SetTextColor(data.classColor.r, data.classColor.g, data.classColor.b) | |
| 485 else | |
| 486 self.Owner:SetText(nil) | |
| 487 end | |
| 488 self.Background:SetColorTexture(data.classColor.r, data.classColor.g, data.classColor.b, | |
| 489 (data.isComplete and 0.5 or 0.1)) | |
| 490 end | |
| 491 | |
| 492 function MissionsHandler:Refresh(data) | |
| 493 data = data or self.data | |
| 494 self.data = data | |
| 495 | |
| 496 self.isComplete = data.isComplete | |
| 497 self.missionEndTime = data.missionEndTime | |
| 498 | 516 |
| 499 local r,g,b = 1, 1, 1 | 517 local r,g,b = 1, 1, 1 |
| 500 if data.isRare then | 518 if self.isRare then |
| 501 r,g,b = 0.1, 0.4, 1 | 519 r,g,b = 0.1, 0.4, 1 |
| 502 end | 520 end |
| 503 | 521 |
| 504 | 522 |
| 505 --self.missionData = data | 523 --self.missionData = data |
| 506 self.Label:SetText(data.name) | 524 self.Label:SetText(self.name) |
| 507 self.Label:SetTextColor(r, g, b) | 525 self.Label:SetTextColor(r, g, b) |
| 508 | 526 |
| 509 if #data.rewards >= 1 then | 527 if #self.rewards >= 1 then |
| 510 self.Icon:SetTexture(data.rewards[1].icon or GetItemIcon(data.rewards[1].itemID)) | 528 self.Icon:SetTexture(self.rewards[1].icon or GetItemIcon(self.rewards[1].itemID)) |
| 511 self.rewardInfo = data.rewards[1] | 529 self.rewardInfo = self.rewards[1] |
| 512 else | 530 else |
| 513 self.Icon:SetAtlas(data.typeAtlas, false) | 531 self.Icon:SetAtlas(self.typeAtlas, false) |
| 514 end | 532 end |
| 515 if self.isComplete then | 533 if self.isComplete then |
| 516 self.TimeLeft:SetText('Complete!') | 534 self.TimeLeft:SetText('Complete!') |
| 517 end | 535 end |
| 518 SetClassColors(self, data) | 536 |
| 537 self.Background:SetAlpha(self.isComplete and 1 or 0.1) | |
| 519 end | 538 end |
| 520 | 539 |
| 521 | 540 |
| 522 function MissionsHandler:OnEnter() | 541 function MissionsHandler:OnEnter() |
| 523 if self.rewardInfo and self.rewardInfo.itemID then | 542 if self.rewardInfo and self.rewardInfo.itemID then |
| 532 end | 551 end |
| 533 end | 552 end |
| 534 | 553 |
| 535 | 554 |
| 536 | 555 |
| 537 function ShipmentsHandler:Refresh(data) | 556 function ShipmentsHandler:Refresh() |
| 538 data = data or self.data | |
| 539 | 557 |
| 540 --[[ | 558 --[[ |
| 541 self.icon = data.icon | 559 self.icon = data.icon |
| 542 self.shipmentCapacity = data.shipmentCapacity | 560 self.shipmentCapacity = data.shipmentCapacity |
| 543 self.shipmentsReady = data.shipmentsReady | 561 self.shipmentsReady = data.shipmentsReady |
| 558 itemQuality = itemQuality, | 576 itemQuality = itemQuality, |
| 559 itemID = itemID | 577 itemID = itemID |
| 560 | 578 |
| 561 --]] | 579 --]] |
| 562 | 580 |
| 563 self.Icon:SetTexture(data.icon) | 581 self.Icon:SetTexture(self.icon) |
| 564 self.data = data | 582 |
| 565 | 583 self.Name:SetText(self.name) |
| 566 | 584 self.Count:SetText(self.shipmentsReady) |
| 567 local isComplete = data.isComplete | 585 self.Done:SetShown(self.shipmentsReady and (self.shipmentsReady >= 1)) |
| 568 | |
| 569 | |
| 570 | |
| 571 self.Name:SetText(data.shipmentType .. data.name) | |
| 572 self.Count:SetText(data.shipmentsReady) | |
| 573 self.Done:SetShown(data.shipmentsReady and (data.shipmentsReady >= 1)) | |
| 574 | 586 |
| 575 | 587 |
| 576 -- flag as complete | 588 -- flag as complete |
| 577 if ( data.shipmentsReady == data.shipmentsTotal ) and (not data.isBeingResearched) then | 589 if ( self.shipmentsReady == self.shipmentsTotal ) and (not self.isBeingResearched) then |
| 578 self.Swipe:SetCooldownUNIX(0, 0); | 590 self.Swipe:SetCooldownUNIX(0, 0); |
| 579 self.Done:Show(); | 591 self.Done:Show(); |
| 580 isComplete = true | 592 self.isComplete = true |
| 581 else | 593 else |
| 582 self.Swipe:SetCooldownUNIX(data.creationTime or 0 , data.duration or 0); | 594 self.Swipe:SetCooldownUNIX(self.creationTime or 0 , self.duration or 0); |
| 583 end | 595 end |
| 584 | 596 |
| 585 data.isComplete = isComplete | 597 local hasPickups = (self.isComplete or (self.shipmentsTotal and (self.shipmentsReady > 0))) |
| 586 | 598 self.Background:SetAlpha(hasPickups and 1 or 0.1) |
| 587 SetClassColors(self, data) | 599 end |
| 588 end | 600 local time = time |
| 589 function ShipmentsHandler:OnUpdate() | 601 function ShipmentsHandler:OnUpdate() |
| 590 local data = self.data | 602 |
| 591 if (data.shipmentsReady and data.shipmentsTotal) and (data.shipmentsReady ~= data.shipmentsTotal) then | 603 if (self.shipmentsReady and self.shipmentsTotal) and (self.shipmentsReady ~= self.shipmentsTotal) then |
| 592 local timeLeft = data.creationTime + data.duration - time() | 604 local timeLeft = self.creationTime + self.duration - time() |
| 593 self.TimeLeft:SetText('Next: '.. GetTimeLeftString(timeLeft) .. ' |cFFFFFF00'..data.shipmentsTotal..' orders|r') | 605 self.TimeLeft:SetText('Next: '.. GetTimeLeftString(timeLeft) .. ' |cFFFFFF00'..self.shipmentsTotal..' orders|r') |
| 594 elseif data.isStale then | 606 elseif self.isStale then |
| 595 self.TimeLeft:SetText('|cFFFF0000Needs refresh|r') | 607 self.TimeLeft:SetText('|cFFFF0000Needs refresh|r') |
| 596 elseif data.isBeingResearched then | 608 elseif self.isBeingResearched then |
| 597 self.TimeLeft:SetText(GetTimeLeftString(data.researchStartTime + data.researchDuration - time())) | 609 self.TimeLeft:SetText(GetTimeLeftString(self.researchStartTime + self.researchDuration - time())) |
| 598 else | 610 else |
| 599 self.TimeLeft:SetText('Complete!') | 611 self.TimeLeft:SetText('Complete!') |
| 600 end | 612 end |
| 601 | 613 |
| 602 end | 614 end |
| 603 | 615 |
| 604 function ShipmentsHandler:OnEnter() | 616 function ShipmentsHandler:OnEnter() |
| 605 local data = self.data | 617 |
| 606 if ( data.shipmentsReady and data.shipmentsTotal ) then | 618 if ( self.shipmentsReady and self.shipmentsTotal ) then |
| 607 GameTooltip:SetOwner(self, 'ANCHOR_LEFT') | 619 GameTooltip:SetOwner(self, 'ANCHOR_LEFT') |
| 608 GameTooltip:AddLine(data.shipmentsReady .. ' of '.. data.shipmentsTotal) | 620 |
| 621 GameTooltip:AddLine(self.Owner:GetText(), self.Owner:GetTextColor()) | |
| 622 GameTooltip:AddLine(self.shipmentType) | |
| 623 GameTooltip:AddLine(self.shipmentsReady .. ' of '.. self.shipmentsTotal) | |
| 609 GameTooltip:Show() | 624 GameTooltip:Show() |
| 610 end | 625 end |
| 611 end | 626 end |
| 612 | 627 |
| 613 function ShipmentsHandler:OnLeave() | 628 function ShipmentsHandler:OnLeave() |
| 616 end | 631 end |
| 617 end | 632 end |
| 618 | 633 |
| 619 function ShipmentsHandler:OnClick(button) | 634 function ShipmentsHandler:OnClick(button) |
| 620 if button == 'RightButton' then | 635 if button == 'RightButton' then |
| 621 for name, profile in pairs(ClassOrderPlan.data) do | 636 self.handler:FreeBlock(self) |
| 622 for index, shipment in pairs(profile.shipments) do | 637 end |
| 623 if shipment == self.data then | 638 end |
| 624 profile.shipments[index] = nil | |
| 625 ClassOrderPlan:Refresh() | |
| 626 end | |
| 627 end | |
| 628 end | |
| 629 end | |
| 630 end |
