annotate ObjectiveFrame.lua @ 5:e9b61fd5f607

- use IsQuestWatched as the determinant for setting action button updates - check for block match-up in deferred action button updates
author Nenue
date Thu, 31 Mar 2016 15:58:08 -0400
parents 18eee961038e
children 589de8ea05b9
rev   line source
Nenue@1 1 --- ${PACKAGE_NAME}
Nenue@1 2 -- @file-author@
Nenue@1 3 -- @project-revision@ @project-hash@
Nenue@1 4 -- @file-revision@ @file-hash@
Nenue@1 5 -- Created: 3/30/2016 12:49 AM
Nenue@1 6 local B = select(2,...).frame
Nenue@2 7 local ipairs, max, min, unpack, floor, pairs, tostring, type = ipairs, max, min, unpack, floor, pairs, tostring, type
Nenue@2 8 local IsResting, UnitXP, UnitXPMax, GetXPExhaustion = IsResting, UnitXP, UnitXPMax, GetXPExhaustion
Nenue@2 9 local UnitLevel, IsQuestWatched, UIParent = UnitLevel, IsQuestWatched, UIParent
Nenue@1 10 local CreateFrame = CreateFrame
Nenue@1 11 local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@1 12 local print = B.print('Objectives')
Nenue@1 13 --------------------------------------------------------------------
Nenue@1 14 --- Global frame layout
Nenue@1 15 --------------------------------------------------------------------
Nenue@1 16
Nenue@1 17 --- Upvalues
Nenue@2 18 local Wrapper = VeneerObjectiveWrapper
Nenue@1 19 local Scroller = Wrapper.scrollArea
Nenue@2 20 local Scroll = VeneerObjectiveScroll
Nenue@1 21 local orderedHandlers = mod.orderedHandlers
Nenue@1 22 local orderedNames = mod.orderedNames
Nenue@1 23
Nenue@1 24 --- Temp values set during updates
Nenue@1 25 local wrapperWidth, wrapperHeight
Nenue@1 26 local scrollWidth, scrollHeight
Nenue@1 27 local previousBlock
Nenue@1 28 local currentBlock
Nenue@1 29 --- todo: map these into config table when its sorted out
Nenue@1 30 local titleFont, textFont = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Regular.ttf]]
Nenue@1 31 local titleSize, textSize = 15, 15
Nenue@1 32 local titleOutline, textOutline = "OUTLINE", "OUTLINE"
Nenue@1 33 local titleSpacing, textSpacing = 4, 3
Nenue@1 34 local textIndent = 5
Nenue@1 35 local wrapperMaxWidth, wrapperMaxHeight = 280, 490 -- these are the hard bounds, actual *Height variables are changed
Nenue@2 36 local wrapperHeadFont, wrapperHeadSize, wrapperHeadOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 16, 'NONE'
Nenue@1 37 local headerFont, headerSize, headerHeight = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 18, 24
Nenue@2 38 local headerOutline, headerColor, headerSpacing = 'OUTLINE', {1,1,1,1}, 2
Nenue@1 39 local wrapperPosition = {'RIGHT', UIParent, 'RIGHT', -84, 0}
Nenue@1 40
Nenue@2 41 --- These are mostly aesthetic choices so it lives here
Nenue@1 42 mod.defaults = {
Nenue@1 43 ObjectiveTrackerAnchor = {'BOTTOM', 'RIGHT'},
Nenue@1 44 ObjectiveTrackerParent = 'DebuffButton',
Nenue@1 45 ObjectiveTrackerSize = {250, 600},
Nenue@1 46 ObjectiveWrapperParent = '',
Nenue@2 47 WrapperStyle = {
Nenue@2 48 Header = {
Nenue@2 49 Background = {Left = [[Objective-Header]], Right = [[Objective-Header]], Tile = [[Objective-Header]]},
Nenue@2 50 BackgroundCrop = {Left = {0, 0.4, 0,1}, Right={0.6,1,0,1}, Tile = {0.4,.6,0,1,}},
Nenue@2 51 BackgroundScale = {Left = 100, Right = 100},
Nenue@2 52 Font = {wrapperHeadFont, wrapperHeadSize, wrapperHeadOutline}
Nenue@2 53 }
Nenue@2 54 },
Nenue@2 55 ObjectiveHeaderStyle = {
Nenue@2 56 Normal = {
Nenue@3 57 Gradient = {MinColor = {0,0,0,0.5}, MaxColor = {0,0,0,.25}},
Nenue@2 58 Font = {headerFont, headerSize, headerOutline}, Spacing = headerSpacing,
Nenue@2 59 }
Nenue@2 60 },
Nenue@1 61 ObjectiveTrackerStyle = {
Nenue@1 62 Normal = {
Nenue@1 63 Title = {
Nenue@1 64 Gradient = { MinColor = {0.2, .4, 1, 0.45}, MaxColor = {.7, 0, 0.9, 0}},
Nenue@1 65 Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing,
Nenue@1 66 },
Nenue@1 67 Text = {
Nenue@1 68 Gradient = { MinColor = {0.2, .4, 1, 0.25}, MaxColor = {.7, 0, 0.9, 0}},
Nenue@1 69 Font = {textFont, textSize, textOutline}, Spacing = textSpacing,
Nenue@1 70 },
Nenue@1 71 },
Nenue@1 72 Super = {
Nenue@1 73 Title = {
Nenue@1 74 Gradient = { MinColor = {0, .7, .6, .8}, MaxColor = {0, .7, .6, 0.2}},
Nenue@1 75 Font = {titleFont, titleSize, titleOutline},
Nenue@1 76 Spacing = titleSpacing, BackgroundFullWidth = true
Nenue@1 77 },
Nenue@1 78 Text = {
Nenue@1 79 Gradient = { MinColor = {0, .7, .6, 0.5}, MaxColor = {0, .7, .6, 0.1} },
Nenue@1 80 Font = {textFont, textSize, textOutline}, Spacing = textSpacing,
Nenue@1 81 },
Nenue@1 82 },
Nenue@1 83 Active = {
Nenue@1 84 Title = {
Nenue@1 85 Gradient = { MinColor = {0.2, .4, 1, 1}, MaxColor = {0.2, .4, 1, 1}, },
Nenue@1 86 Font = {titleFont, titleSize, titleOutline},
Nenue@1 87 Spacing = titleSpacing,
Nenue@1 88 BackgroundFullWidth = true
Nenue@1 89 },
Nenue@1 90 Text = {
Nenue@1 91 Gradient = { MinColor = {0.2, .4, 1, 1}, MaxColor = {0.2, .4, 1, 1}, },
Nenue@1 92 Font = {textFont, textSize, textOutline},
Nenue@1 93 Spacing = textSpacing,
Nenue@1 94 BackgroundFullWidth = true
Nenue@1 95 }
Nenue@1 96 },
Nenue@1 97 Complete = {
Nenue@1 98 Title = {
Nenue@1 99 Gradient = { MinColor = {0, 1, 0, 0.34}, MaxColor = {0, 1, 0, .17}, },
Nenue@1 100 Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing,
Nenue@1 101 BackgroundFullWidth = true
Nenue@1 102 },
Nenue@1 103 Text = {
Nenue@1 104 Gradient = { MinColor = {0, 1, 0, .25}, MaxColor = {0, 1, 0, 0.12}, },
Nenue@1 105 Font = {textFont, textSize, textOutline}, Spacing = textSpacing,
Nenue@1 106 BackgroundFullWidth = true
Nenue@1 107 }
Nenue@1 108 },
Nenue@1 109 }
Nenue@1 110 }
Nenue@1 111
Nenue@3 112 local FontBank = {
Nenue@3 113 ['Normal'] = VeneerCriteriaFontNormal,
Nenue@3 114 ['Progress'] = VeneerCriteriaFontProgress,
Nenue@3 115 ['Complete'] = VeneerCriteriaFontComplete,
Nenue@3 116 ['Failed'] = VeneerCriteriaFontFailed,
Nenue@3 117 }
Nenue@3 118
Nenue@2 119 local Scroller_OnShow = function()
Nenue@2 120 Wrapper.watchMoneyReasons = 0;
Nenue@2 121 mod.UpdateWrapper()
Nenue@2 122 mod.SetEvents()
Nenue@2 123 for i, region in ipairs(Wrapper.header) do
Nenue@2 124 region:Show()
Nenue@2 125 end
Nenue@2 126 end
Nenue@2 127
Nenue@2 128 local Scroller_OnHide = function()
Nenue@2 129 local self = Wrapper
Nenue@2 130 Wrapper:UnregisterAllEvents()
Nenue@2 131 Wrapper:SetScript('OnEvent', nil)
Nenue@2 132 for i, region in ipairs(Wrapper.header) do
Nenue@2 133 region:Hide()
Nenue@2 134 end
Nenue@2 135 end
Nenue@2 136
Nenue@2 137 local Scroller_OnMouseWheel = function(self, delta)
Nenue@2 138 local r = Scroll:GetHeight() - Scroller:GetHeight()
Nenue@2 139 local s = self:GetVerticalScroll() - delta * floor(r/5+.5)
Nenue@2 140 if r == 0 then return end
Nenue@2 141 if s >= r then
Nenue@2 142 s = r
Nenue@2 143 elseif s < 1 then
Nenue@2 144 s = 0
Nenue@2 145 end
Nenue@2 146 self:SetVerticalScroll(s)
Nenue@2 147 print(s, r, self:GetVerticalScroll())
Nenue@2 148
Nenue@2 149 mod.UpdateActionButtons()
Nenue@2 150 end
Nenue@2 151
Nenue@2 152 local WrapperCloseButton_OnClick = function(self)
Nenue@2 153 if Scroller:IsVisible() then
Nenue@2 154 Scroller:Hide()
Nenue@2 155 else
Nenue@2 156 Scroller:Show()
Nenue@2 157 end
Nenue@2 158 end
Nenue@2 159
Nenue@2 160 mod.InitializeTrackers = function()
Nenue@2 161
Nenue@2 162 local c = mod.defaults.ObjectiveHeaderStyle.Normal
Nenue@2 163 local g1, g2, g3, g4 = unpack(c.Gradient.MinColor)
Nenue@2 164 local h1, h2, h3, h4 = unpack(c.Gradient.MaxColor)
Nenue@2 165
Nenue@2 166 for i, name in ipairs(orderedNames) do
Nenue@2 167 if not mod.orderedHandlers[i] then
Nenue@2 168 if mod.Tracker(name, i) then
Nenue@2 169 local handler = mod[name]
Nenue@2 170
Nenue@2 171 local tracker = CreateFrame('Frame', 'Veneer'..name..'Tracker', Scroll, 'VeneerTrackerTemplate')
Nenue@2 172 tracker.header:SetText(handler.name)
Nenue@2 173 tracker.header:SetHeight(headerHeight)
Nenue@2 174 tracker.header:SetFont(unpack(c.Font))
Nenue@2 175 tracker.header:SetTextColor(unpack(headerColor))
Nenue@2 176
Nenue@2 177 tracker.headerbg:SetGradientAlpha('HORIZONTAL', g1, g2 ,g3, g4, h1, h2, h3, h4)
Nenue@2 178 tracker.headerbg:SetHeight(headerHeight)
Nenue@2 179
Nenue@2 180 handler.Tracker = tracker
Nenue@2 181 mod.orderedTrackers[i] = tracker
Nenue@2 182 mod.namedTrackers[name] = tracker
Nenue@2 183 mod.indexedTrackers[handler] = tracker
Nenue@2 184 print('created new tracker frames for new handler')
Nenue@2 185 end
Nenue@2 186 end
Nenue@2 187 end
Nenue@2 188
Nenue@2 189 Scroller:SetScrollChild(Scroll)
Nenue@2 190 Scroller:SetScript('OnMouseWheel', Scroller_OnMouseWheel)
Nenue@2 191 Scroller:SetScript('OnShow', Scroller_OnShow)
Nenue@2 192 Scroller:SetScript('OnHide', Scroller_OnHide)
Nenue@2 193 Wrapper.close:SetScript('OnClick', WrapperCloseButton_OnClick)
Nenue@2 194 Wrapper:SetPoint(unpack(wrapperPosition))
Nenue@2 195 Scroller_OnShow(Scroller)
Nenue@2 196
Nenue@2 197 mod.UpdateWrapperStyle()
Nenue@2 198 end
Nenue@2 199
Nenue@2 200 mod.InitializeXPTracker = function()
Nenue@2 201 local XPBar = Wrapper.XPBar
Nenue@2 202 if UnitLevel('player') == 100 then
Nenue@2 203 XPBar:Hide()
Nenue@2 204 return
Nenue@2 205 end
Nenue@2 206
Nenue@2 207 --- xp bar
Nenue@2 208 XPBar:Show()
Nenue@2 209 XPBar.rested:SetTexture(2,.6,1,1)
Nenue@2 210 XPBar.fg:SetTexture(.3,.1,.95,1)
Nenue@2 211 XPBar.bg:SetTexture(0,0,0,.25)
Nenue@2 212 XPBar:RegisterEvent('PLAYER_XP_UPDATE')
Nenue@2 213 XPBar:RegisterEvent('PLAYER_LEVEL_UP')
Nenue@2 214 XPBar:RegisterEvent('PLAYER_UPDATE_RESTING')
Nenue@2 215 XPBar:SetScript('OnEvent', mod.UpdateXP)
Nenue@2 216 mod.UpdateXP(Wrapper.xpBar)
Nenue@2 217 end
Nenue@2 218
Nenue@2 219 mod.UpdateXP = function()
Nenue@2 220 local XPBar = Wrapper.XPBar
Nenue@2 221 local xp = UnitXP('player')
Nenue@2 222 local xpmax = UnitXPMax('player')
Nenue@2 223 local rest = GetXPExhaustion()
Nenue@2 224
Nenue@2 225 XPBar.bg:SetAllPoints(XPBar)
Nenue@2 226 XPBar.fg:SetWidth((xp/xpmax) * XPBar:GetWidth())
Nenue@2 227
Nenue@2 228 if IsResting() then
Nenue@2 229 XPBar.bg:SetTexture(.2,.8,.2,.5)
Nenue@2 230 else
Nenue@2 231 XPBar.bg:SetTexture(0,0,0,.25)
Nenue@2 232 end
Nenue@2 233
Nenue@2 234 if rest then
Nenue@2 235 XPBar.rested:ClearAllPoints()
Nenue@2 236 if xp == 0 then
Nenue@3 237 XPBar.rested:SetPoint('TOPLEFT', XPBar, 'TOPLEFT', 0, 0)
Nenue@2 238 else
Nenue@3 239 XPBar.rested:SetPoint('TOPLEFT', XPBar.fg, 'TOPRIGHT', 0, 0)
Nenue@2 240 end
Nenue@2 241
Nenue@2 242 if (xp + rest) > xpmax then
Nenue@3 243 XPBar.rested:SetPoint('BOTTOMRIGHT', XPBar, 'BOTTOMRIGHT', 0, 0)
Nenue@2 244 else
Nenue@3 245 XPBar.rested:SetWidth((rest/xpmax) * XPBar:GetWidth())
Nenue@2 246 end
Nenue@3 247 XPBar.rested:SetPoint('BOTTOM', XPBar, 'BOTTOM')
Nenue@2 248 XPBar.rested:Show()
Nenue@2 249 else
Nenue@2 250 XPBar.rested:Hide()
Nenue@2 251 end
Nenue@2 252
Nenue@2 253 XPBar.xpText:SetText(xp .. '/'.. xpmax .. (rest and (' ('..tostring(rest)..')') or ''))
Nenue@2 254 end
Nenue@2 255
Nenue@2 256 mod.UpdateReputation = function(self)
Nenue@2 257 end
Nenue@1 258
Nenue@1 259 --- Argument containers
Nenue@1 260 local a1, a2, a3, a4, b1, b2, b3, b4, f1, f2, f3, w1, w2
Nenue@1 261 mod.SetBlockStyle = function(block, name)
Nenue@1 262 -- var names intended to reflect argument order
Nenue@2 263 --@debug@
Nenue@1 264 local c = mod.defaults.ObjectiveTrackerStyle[name]
Nenue@2 265 --@end-debug@
Nenue@2 266 --[===[@non-debug
Nenue@2 267 local c = mod.Conf
Nenue@2 268 --@end-non-debug]===]
Nenue@1 269 a1, a2, a3, a4 = unpack(c.Title.Gradient.MinColor)
Nenue@1 270 b1, b2, b3, b4 = unpack(c.Title.Gradient.MaxColor)
Nenue@1 271 block.titlebg:SetGradientAlpha('HORIZONTAL', a1, a2, a3, a4, b1, b2, b3, b4)
Nenue@1 272
Nenue@1 273 a1, a2, a3, a4 = unpack(c.Text.Gradient.MinColor)
Nenue@1 274 b1, b2, b3, b4 = unpack(c.Text.Gradient.MaxColor)
Nenue@1 275 block.bg:SetGradientAlpha('HORIZONTAL', a1, a2, a3, a4, b1, b2, b3, b4)
Nenue@1 276
Nenue@1 277 f1, f2, f3 = unpack(c.Title.Font)
Nenue@1 278 block.title:SetFont(f1, f2, f3)
Nenue@1 279
Nenue@1 280 f1, f2 ,f3 = unpack(c.Text.Font)
Nenue@1 281 block.objectives:SetFont(f1,f2,f3)
Nenue@1 282
Nenue@1 283 w1 = Wrapper:GetWidth()
Nenue@1 284 w2 = (c.Title.BackgroundFullWidth and w1 or block.title:GetStringWidth())
Nenue@1 285
Nenue@1 286 local titleSpacing, titleSpacing2 = c.Title.Spacing, (c.Title.Spacing * 2)
Nenue@1 287 local textSpacing, textSpacing2 = c.Text.Spacing, (c.Text.Spacing * 2)
Nenue@1 288
Nenue@1 289 if block.info.isTrivial then
Nenue@1 290 block.title:SetTextColor(0.7, 0.7, 0.7, 1)
Nenue@1 291 elseif block.info.isComplete then
Nenue@1 292 block.title:SetTextColor(1,1,1,1)
Nenue@1 293 else
Nenue@1 294 block.title:SetTextColor(0,.7,1,1)
Nenue@1 295 end
Nenue@1 296 block.title:SetSpacing(titleSpacing)
Nenue@1 297 block.objectives:SetSpacing(textSpacing)
Nenue@1 298 block.objectives:SetWordWrap(true)
Nenue@1 299
Nenue@1 300 local titleHeight, textHeight = block.title:GetStringHeight(), block.objectives:GetStringHeight()
Nenue@1 301 local blockHeight = titleHeight + titleSpacing2 + textHeight + textSpacing2
Nenue@1 302 local blockWidth = wrapperMaxWidth
Nenue@1 303
Nenue@1 304 block.titlebg:SetSize(min(w1, w2), titleHeight + titleSpacing2)
Nenue@1 305 block.bg:SetSize(w1, textHeight + textSpacing2)
Nenue@1 306 block:SetSize(blockWidth, blockHeight)
Nenue@1 307
Nenue@1 308 block.title:SetPoint('TOPLEFT', block.titlebg, 'TOPLEFT', 0, -titleSpacing)
Nenue@1 309 block.objectives:SetPoint('TOPLEFT', block.titlebg, 'BOTTOMLEFT', textIndent, -textSpacing)
Nenue@1 310
Nenue@1 311 -- store
Nenue@1 312 block.titleHeight = titleHeight
Nenue@1 313 block.textHeight = textHeight
Nenue@1 314 block.width = blockWidth
Nenue@1 315 block.height = blockHeight
Nenue@1 316
Nenue@2 317 print(' |cFF00FFFF'..block:GetName()..'|r:|cFF0088FFSetStyle|r(', blockWidth, 'x', blockHeight, '(textH', textHeight,', titleH', titleHeight, ')')
Nenue@2 318 end
Nenue@2 319
Nenue@2 320 local segments = {'Left', 'Right', 'Tile'}
Nenue@2 321 mod.UpdateWrapperStyle = function()
Nenue@2 322 local c = mod.defaults.WrapperStyle
Nenue@2 323 for _, segment in ipairs(segments) do
Nenue@2 324 Wrapper['Background'..segment]:SetAtlas(c.Header.Background[segment])
Nenue@2 325 Wrapper['Background'..segment]:SetTexCoord(unpack(c.Header.BackgroundCrop[segment]))
Nenue@2 326 if c.Header.BackgroundScale[segment] then
Nenue@2 327 Wrapper['Background'..segment]:SetWidth(c.Header.BackgroundScale[segment])
Nenue@2 328 end
Nenue@2 329 end
Nenue@1 330 end
Nenue@1 331
Nenue@1 332 --- Updates the selected block frame to display the given info batch
Nenue@1 333 -- If `previousBlock` is set, it will attempt to anchor to that
Nenue@1 334 -- @param blockNum the ordered block to be updated, not a watchIndex value
Nenue@1 335 -- @param info the reference returned by the GetXInfo functions
Nenue@1 336 -- REMEMBER: t.info and questData[questID] are the same table
Nenue@1 337 mod.UpdateTrackerBlock = function (handler, blockIndex, info)
Nenue@2 338 print(' |cFF00FFFFUpdateTrackerBlock('..blockIndex..'|r')
Nenue@1 339 if not blockIndex or not info then
Nenue@1 340 return
Nenue@1 341 end
Nenue@1 342
Nenue@1 343 local tracker = handler.Tracker
Nenue@1 344
Nenue@1 345 local t = handler:GetBlock(blockIndex)
Nenue@1 346 if previousBlock then
Nenue@1 347 if blockIndex == 1 then
Nenue@1 348 t:SetPoint('TOPLEFT', previousBlock, 'TOPLEFT', 0, -headerHeight)
Nenue@1 349 else
Nenue@1 350 t:SetPoint('TOPLEFT', previousBlock, 'BOTTOMLEFT', 0, 0)
Nenue@1 351 end
Nenue@1 352 t:SetPoint('RIGHT', tracker,'RIGHT', 0, 0)
Nenue@1 353 end
Nenue@2 354 --print(t:GetName(), t:GetSize())
Nenue@2 355 --print(t:GetPoint(1))
Nenue@1 356
Nenue@1 357 t.info = info
Nenue@1 358
Nenue@5 359 if info.questID then handler.QuestBlock[info.questID] = t end
Nenue@1 360 if info.questLogIndex then handler.LogBlock[info.questLogIndex] = t end
Nenue@1 361 if info.watchIndex then handler.WatchBlock[info.watchIndex] = t end
Nenue@1 362
Nenue@1 363 info.blockIndex = blockIndex
Nenue@1 364 handler.BlockInfo[blockIndex] = info
Nenue@1 365 t.Select = handler.Select
Nenue@1 366 t.Open = handler.Open
Nenue@1 367 t.Remove = handler.Remove
Nenue@1 368 t.Link = handler.Link
Nenue@1 369 t:SetScript('OnMouseUp', handler.OnMouseUp)
Nenue@1 370 t:SetScript('OnMouseDown', handler.OnMouseDown)
Nenue@1 371 t.title:SetText(info.title)
Nenue@1 372
Nenue@1 373 if info.isComplete then
Nenue@1 374 t.objectives:Show()
Nenue@1 375 t.objectives:SetText(info.completionText)
Nenue@1 376 elseif info.numObjectives >= 1 then
Nenue@1 377 t.objectives:Show()
Nenue@2 378 print(' - objective lines:', info.numObjectives, 'can wrap:', t.objectives:CanWordWrap())
Nenue@3 379
Nenue@1 380 local text = ''
Nenue@3 381 if info.description then
Nenue@3 382 print(' -- has description text:', select('#', info.description), info.description)
Nenue@3 383 text = info.description
Nenue@3 384 end
Nenue@3 385
Nenue@3 386 --- todo: implement objective displays
Nenue@3 387 -- in an accumulator loop, call upon handler for the appropriate display frame, each defining:
Nenue@3 388 -- * height of whatever display widget is involved in conveying the task
Nenue@3 389 -- * number of non-wrapped text lines to account for line space; may be discarded depending on things
Nenue@3 390 -- * boolean that determines listening for money events or not
Nenue@4 391 t.attachmentHeight, text = mod.UpdateObjectives(t, info, text)
Nenue@3 392
Nenue@1 393 t.objectives:SetText(text)
Nenue@3 394 t.objectives:SetWordWrap(true)
Nenue@1 395
Nenue@1 396
Nenue@1 397
Nenue@1 398 elseif info.description then
Nenue@1 399 t.objectives:SetText(info.description)
Nenue@1 400 t.objectives:SetWordWrap(true)
Nenue@1 401 else
Nenue@1 402 t.objectives:SetText(nil)
Nenue@1 403 end
Nenue@1 404 local style = 'Normal'
Nenue@1 405 if info.isComplete then
Nenue@1 406 style = 'Complete'
Nenue@1 407 elseif info.superTracked then
Nenue@1 408 style = 'Super'
Nenue@1 409 end
Nenue@1 410
Nenue@5 411 if info.specialItem and not info.itemButton then
Nenue@5 412 print(' - |cFF00FFFFgenerating item button for info set')
Nenue@4 413 info.itemButton = mod.SetItemButton(t, info)
Nenue@4 414 else
Nenue@4 415 --info.itemButton = nil
Nenue@4 416 end
Nenue@4 417
Nenue@3 418 --- metrics are calculated in SetStyle
Nenue@1 419 t:SetStyle(style)
Nenue@3 420 t:Show()
Nenue@1 421
Nenue@3 422 print(' |cFF00FFFF)|r -> ', t, t:GetHeight())
Nenue@1 423 return t
Nenue@1 424 end
Nenue@1 425
Nenue@4 426 mod.UpdateObjectives = function(block, info, text)
Nenue@4 427 local attachmentHeight = 0
Nenue@4 428 for o, obj in ipairs(info.objectives) do
Nenue@4 429 --- achievement criteria
Nenue@4 430 if obj.flags then
Nenue@4 431
Nenue@4 432
Nenue@4 433 if bit.band(obj.flags, 0x00000001) > 0 then
Nenue@4 434 obj.type = 'ProgressBar'
Nenue@4 435 obj.widget = mod.SetWidget(obj, info)
Nenue@4 436 elseif bit.band(obj.flags, 0x00000002) then
Nenue@4 437 obj.type = 'Hidden'
Nenue@4 438 obj.widget = nil
Nenue@4 439 else
Nenue@4 440 obj.type = 'Text'
Nenue@4 441 obj.widget = nil
Nenue@4 442 text = text .. ((text == '') and "" or "\n") .. obj.text
Nenue@4 443 end
Nenue@4 444
Nenue@4 445 print(obj.type, obj.text, obj.quantityString)
Nenue@4 446 --- none of the above (most quests)
Nenue@4 447 else
Nenue@4 448 local line = obj.text
Nenue@4 449 local color = '00FFFF'
Nenue@4 450 if obj.finished then
Nenue@4 451 color = 'FFFFFF'
Nenue@4 452 elseif obj.type == 'monster' then
Nenue@4 453 color = 'FFFF00'
Nenue@4 454 elseif obj.type == 'item' then
Nenue@4 455 color = '44DDFF'
Nenue@4 456 elseif obj.type == 'object' then
Nenue@4 457 color = 'FF44DD'
Nenue@4 458 end
Nenue@4 459 text = text .. ((text == '') and "" or "\n") .. '|cFF'..color.. line .. '|r'
Nenue@4 460 end
Nenue@4 461
Nenue@4 462 if obj.widget then
Nenue@4 463 attachmentHeight = attachmentHeight + obj.widget.height
Nenue@4 464 end
Nenue@4 465
Nenue@4 466 end
Nenue@4 467 return attachmentHeight, text
Nenue@4 468 end
Nenue@4 469
Nenue@1 470 mod.UpdateTracker = function(handler)
Nenue@1 471 print('|cFF00FF88UpdateTracker(|r|cFFFF4400' .. type(handler) .. '|r :: |cFF88FFFF' .. tostring(handler) .. '|r')
Nenue@1 472 local tracker = handler.Tracker
Nenue@1 473 local blockIndex = 0
Nenue@1 474 local trackerHeight = headerHeight
Nenue@1 475 local w = 300
Nenue@1 476
Nenue@1 477 previousBlock = handler.Tracker
Nenue@1 478 local numWatched = handler.GetNumWatched()
Nenue@1 479 local numBlocks = handler.numBlocks
Nenue@1 480 local actualBlocks = handler.actualBlocks
Nenue@1 481 for watchIndex = 1, 25 do
Nenue@1 482 blockIndex = blockIndex + 1
Nenue@1 483 if watchIndex <= numWatched then
Nenue@1 484 local info = handler:GetInfo(watchIndex)
Nenue@1 485 if info then
Nenue@1 486 local currentBlock = mod.UpdateTrackerBlock(handler, blockIndex, info)
Nenue@1 487 previousBlock = currentBlock
Nenue@1 488 trackerHeight = trackerHeight + currentBlock.height
Nenue@1 489 numBlocks = max(numBlocks, watchIndex)
Nenue@1 490 actualBlocks = actualBlocks + 1
Nenue@1 491 else
Nenue@1 492 print('|cFFFF0000Failed to draw info for index #'..watchIndex)
Nenue@1 493 end
Nenue@1 494
Nenue@1 495 elseif watchIndex <= numBlocks then
Nenue@1 496 local used = handler.usedBlocks
Nenue@1 497 local free = handler.freeBlocks
Nenue@1 498 print('clean up dead quest block')
Nenue@1 499 if used[blockIndex] then
Nenue@1 500 used[blockIndex]:Hide()
Nenue@1 501 used[blockIndex]:ClearAllPoints()
Nenue@1 502 free[#free+1]= used[blockIndex]
Nenue@1 503 used[blockIndex] = nil
Nenue@1 504 end
Nenue@1 505 else
Nenue@1 506 print('Stopping scan at', blockIndex)
Nenue@1 507 break -- done with quest stuff
Nenue@1 508 end
Nenue@1 509 end
Nenue@1 510 handler.numWatched = numWatched
Nenue@1 511 handler.numBlocks = numBlocks
Nenue@1 512 handler.actualBlocks = actualBlocks
Nenue@1 513 handler:Report()
Nenue@1 514 previousBlock = nil
Nenue@1 515 if numBlocks > 0 then
Nenue@1 516 tracker.height = trackerHeight
Nenue@1 517 else
Nenue@1 518 tracker.height = 0
Nenue@1 519 end
Nenue@1 520
Nenue@1 521 print('|cFF00FF88)|r ->', numBlocks, 'blocks; height', tracker.height, 'last block: ')
Nenue@1 522 end
Nenue@1 523
Nenue@1 524 mod.Quest.numButtons = 0
Nenue@1 525 local usedButtons = mod.Quest.itemButtons
Nenue@1 526 local freeButtons = mod.Quest.freeButtons
Nenue@1 527 mod.UpdateWrapper = function()
Nenue@1 528 wrapperWidth = wrapperMaxWidth
Nenue@1 529 scrollWidth = wrapperWidth
Nenue@1 530 local wrapperBlocks = 0
Nenue@1 531 -- Update scroll child vertical size
Nenue@1 532 scrollHeight = 0
Nenue@1 533 for i, handler in ipairs(orderedHandlers) do
Nenue@1 534 mod.UpdateTracker(handler)
Nenue@1 535 if handler.actualBlocks >= 1 then
Nenue@1 536 local tracker = handler.Tracker
Nenue@1 537 print('setting', handler.Tracker, 'to anchor to offset', -scrollHeight)
Nenue@1 538 tracker:SetParent(Scroll) -- this doesn't do anything that relativeTo doesn't
Nenue@1 539 tracker:SetPoint('TOPLEFT', Scroll, 'TOPLEFT', 0, - scrollHeight)
Nenue@1 540 tracker:SetSize(wrapperWidth, tracker.height)
Nenue@1 541 print('adding ', tracker.height)
Nenue@1 542 scrollHeight = scrollHeight + tracker.height
Nenue@1 543 end
Nenue@1 544 wrapperBlocks = wrapperBlocks + handler.actualBlocks
Nenue@1 545 end
Nenue@1 546 print('final scrollHeight:', scrollHeight)
Nenue@1 547
Nenue@1 548
Nenue@1 549
Nenue@1 550 -- Update frame dimensions
Nenue@1 551 if scrollHeight > wrapperMaxHeight then
Nenue@1 552 print(' is larger than', wrapperMaxHeight)
Nenue@1 553 --ScrollBar:Show()
Nenue@1 554 --scrollWidth = wrapperMaxWidth - scrollBarWidth
Nenue@1 555 wrapperHeight = wrapperMaxHeight
Nenue@1 556 -- Make ThumbTexture reflect the viewing scale (smaller for longer scroll, bigger for shorter)
Nenue@1 557 --ScrollBar:GetThumbTexture():SetHeight((wrapperMaxHeight/scrollHeight) * (wrapperMaxHeight))
Nenue@1 558 --ScrollBar:SetWidth(scrollBarWidth)
Nenue@1 559 --ScrollBar:SetPoint('TOPRIGHT', Scroller, 'TOPRIGHT', 0, 0)
Nenue@1 560 --ScrollBar:SetPoint('BOTTOMLEFT', Scroller, 'BOTTOMRIGHT', -scrollBarWidth, 0)
Nenue@1 561 --ScrollBar:SetMinMaxValues(1, scrollHeight - wrapperMaxHeight)
Nenue@1 562 else
Nenue@1 563 --ScrollBar:Hide()
Nenue@1 564 wrapperHeight = scrollHeight
Nenue@1 565 end
Nenue@1 566 scrollWidth = floor(scrollWidth+.5)
Nenue@1 567 scrollHeight = floor(scrollHeight+.5)
Nenue@1 568 wrapperWidth = floor(wrapperWidth+.5)
Nenue@1 569 wrapperHeight = floor(wrapperHeight+.5)
Nenue@1 570 headerHeight = floor(headerHeight+.5)
Nenue@1 571
Nenue@1 572 if wrapperBlocks >= 1 then
Nenue@2 573 for i, region in ipairs(Wrapper.header) do
Nenue@2 574 region:Show()
Nenue@2 575 end
Nenue@1 576 else
Nenue@2 577 for i, region in ipairs(Wrapper.header) do
Nenue@2 578 region:Hide()
Nenue@2 579 end
Nenue@1 580 return
Nenue@1 581 end
Nenue@1 582 --wrapperHeight = scrollHeight
Nenue@1 583
Nenue@1 584 print('|cFFFFFF00params:|r scroller:', scrollWidth, 'x', scrollHeight)
Nenue@1 585 print('|cFFFFFF00params:|r scroll:', scrollWidth, 'x', scrollHeight)
Nenue@1 586 print('|cFFFFFF00params:|r wrapper:', wrapperWidth, 'x', wrapperHeight)
Nenue@1 587 print('|cFFFFFF00params:|r header:', headerHeight)
Nenue@1 588
Nenue@1 589 Scroller:SetSize(wrapperWidth, wrapperHeight)
Nenue@1 590 Scroller:SetPoint('TOPLEFT', Wrapper, 'TOPLEFT', 0, -headerHeight)
Nenue@1 591 Scroller:SetPoint('BOTTOMRIGHT', Wrapper, 'BOTTOMRIGHT')
Nenue@1 592
Nenue@1 593 Scroll:SetSize(scrollWidth, scrollHeight)
Nenue@1 594 Scroll:SetPoint('TOPLEFT', Scroller, 'TOPLEFT', 0, 0)
Nenue@1 595 Scroll:SetPoint('RIGHT', Scroller, 'RIGHT')
Nenue@1 596
Nenue@1 597 --Scroller:UpdateScrollChildRect()
Nenue@1 598 Wrapper:SetSize(wrapperWidth, wrapperHeight + headerHeight)
Nenue@1 599
Nenue@1 600 -- update action buttons
Nenue@1 601
Nenue@1 602
Nenue@1 603 print('scroll size:', Scroll:GetSize())
Nenue@1 604 print('scroller size:',Scroller:GetSize())
Nenue@1 605 print('wrapper size:', Wrapper:GetSize())
Nenue@1 606 print('scroll range :', floor(Scroller:GetVerticalScrollRange()+.5))
Nenue@1 607
Nenue@1 608
Nenue@1 609 mod.UpdateActionButtons()
Nenue@1 610 end
Nenue@1 611
Nenue@1 612 --- Queue any active item buttons for update for that frame
Nenue@1 613 mod.UpdateActionButtons = function()
Nenue@1 614 local previousItem
Nenue@2 615 for questID, itemButton in pairs(usedButtons) do
Nenue@2 616 local questIndex = mod.Quest.Info[questID].questLogIndex
Nenue@5 617 print('|cFF00FFFF'.. questID .. '|r', itemButton:GetName())
Nenue@5 618 local block = mod.Quest.QuestBlock[questID]
Nenue@1 619 if block then
Nenue@5 620 -- Dispatch the probe
Nenue@1 621 if IsQuestWatched(questIndex) then
Nenue@5 622
Nenue@5 623 print(' |cFFFFFF00probing', block:GetName())
Nenue@1 624 block:SetScript('OnUpdate', function()
Nenue@5 625 if block:GetBottom() and not InCombatLockdown() then
Nenue@5 626 print(' '..block:GetName()..' |cFF00FF00probe hit!')
Nenue@5 627 mod.UpdateBlockAction(block, itemButton, previousItem)
Nenue@5 628 block:SetScript('OnUpdate', nil)
Nenue@5 629 end
Nenue@5 630 end)
Nenue@1 631 else
Nenue@5 632 print('hidden block or unwatched quest')
Nenue@5 633 itemButton:Hide()
Nenue@1 634 end
Nenue@5 635 else
Nenue@5 636 print(' |cFFFF0088missing block data', itemButton:GetName())
Nenue@1 637 end
Nenue@1 638 end
Nenue@1 639 end
Nenue@1 640
Nenue@1 641 mod.UpdateBlockAction = function (block, itemButton, previousItem)
Nenue@5 642 print('**|cFF0088FF'..itemButton:GetName(), '|r:Update()')
Nenue@5 643 if itemButton.questID ~= block.info.questID then
Nenue@5 644 print('** |cFFFF0088mismatched block assignment', itemButton.questID,'<~>', block.info.questID)
Nenue@5 645
Nenue@5 646 return mod.UpdateActionButtons()
Nenue@2 647 end
Nenue@2 648
Nenue@1 649 if block:GetBottom() < Scroller:GetBottom() then
Nenue@5 650 print('** ',block:GetName() ,'|cFFFFFF00bottom not fully visible')
Nenue@1 651 if previousItem then
Nenue@1 652 previousItem:ClearAllPoints()
Nenue@1 653 previousItem:SetPoint('BOTTOM', itemButton, 'TOP', 0, 4)
Nenue@1 654 end
Nenue@1 655 itemButton:ClearAllPoints()
Nenue@1 656 itemButton:SetPoint('BOTTOMRIGHT', UIParent, 'BOTTOMLEFT', Wrapper:GetLeft(), Wrapper:GetBottom())
Nenue@1 657 itemButton:Show()
Nenue@1 658 else
Nenue@5 659 print('** ',block:GetName() ,'|cFF00FF00visible positions')
Nenue@1 660 itemButton:ClearAllPoints()
Nenue@1 661 itemButton:SetPoint('TOPRIGHT', UIParent, 'BOTTOMLEFT', block:GetLeft(), block:GetTop())
Nenue@1 662 itemButton:Show()
Nenue@1 663 end
Nenue@1 664 end
Nenue@1 665
Nenue@1 666 mod.UpdateItemButtonCooldown = function(button)
Nenue@1 667
Nenue@1 668 end