annotate Loot.lua @ 57:01b63b8ed811 v21

total rewrite to version 21
author yellowfive
date Fri, 05 Jun 2015 11:05:15 -0700
parents
children cf2b6b9a8337
rev   line source
yellowfive@57 1 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
yellowfive@57 2 local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true)
yellowfive@57 3 local AceGUI = LibStub("AceGUI-3.0")
yellowfive@57 4
yellowfive@57 5 local _frameLoot
yellowfive@57 6 local _panelLoot
yellowfive@57 7 local _selectedIndex
yellowfive@57 8 local _disenchant = {}
yellowfive@57 9 local _rankPanels
yellowfive@57 10 local _lootButtons
yellowfive@57 11
yellowfive@57 12 local _widthItemList = 220
yellowfive@57 13 local _widthRankList = 640
yellowfive@57 14 local _widthSpacing = 10
yellowfive@57 15 local _widthRank = 48
yellowfive@57 16 local _widthRankBar = 195
yellowfive@57 17 local _widthRollType = 45
yellowfive@57 18 local _widthColPadding = 8
yellowfive@57 19 local _widthRollExtraSpacing = 4
yellowfive@57 20
yellowfive@57 21 local _rollTypePos = {
yellowfive@57 22 Need = 1,
yellowfive@57 23 Off = 2,
yellowfive@57 24 Greed = 3,
yellowfive@57 25 Pass = 4
yellowfive@57 26 }
yellowfive@57 27
yellowfive@57 28 -- get the index of the loot item that matches up to the specified item
yellowfive@57 29 local function getLootIndex(itemIndex)
yellowfive@57 30
yellowfive@57 31 local ranking = Amr.db.global.TeamOpt.Rankings[itemIndex]
yellowfive@57 32 if not ranking then return nil end
yellowfive@57 33
yellowfive@57 34 local itemUniqueId = Amr.GetItemUniqueId(ranking.item)
yellowfive@57 35 for i = 1, GetNumLootItems() do
yellowfive@57 36 --local texture, item, quantity, quality, locked = GetLootSlotInfo(i)
yellowfive@57 37 local lootType = GetLootSlotType(i)
yellowfive@57 38 if lootType == 1 then
yellowfive@57 39 local link = GetLootSlotLink(i)
yellowfive@57 40 local lootItem = Amr.ParseItemLink(link)
yellowfive@57 41 if Amr.GetItemUniqueId(lootItem) == itemUniqueId then
yellowfive@57 42 return i, link
yellowfive@57 43 end
yellowfive@57 44 end
yellowfive@57 45 end
yellowfive@57 46 end
yellowfive@57 47
yellowfive@57 48 local function getLootCandidateIndex(lootIndex, realm, name)
yellowfive@57 49 -- remove spaces to ensure proper matches, and make all lower
yellowfive@57 50 realm = string.gsub(realm, "%s+", "")
yellowfive@57 51 realm = string.lower(realm)
yellowfive@57 52 name = string.lower(name)
yellowfive@57 53
yellowfive@57 54 local nameMatches = {}
yellowfive@57 55 for i = 1, 40 do
yellowfive@57 56 local candidate = GetMasterLootCandidate(lootIndex, i)
yellowfive@57 57 if candidate then
yellowfive@57 58 local candidateName = candidate
yellowfive@57 59 local candidateRealm = GetRealmName()
yellowfive@57 60
yellowfive@57 61 -- see if realm is in the name
yellowfive@57 62 local splitPos = string.find(candidateName, "-")
yellowfive@57 63 if splitPos ~= nil then
yellowfive@57 64 candidateRealm = string.sub(candidateName, splitPos + 1)
yellowfive@57 65 candidateName = string.sub(candidateName, 1, splitPos - 1)
yellowfive@57 66 end
yellowfive@57 67
yellowfive@57 68 -- remove spaces to ensure proper matches, and make all lower
yellowfive@57 69 candidateRealm = string.gsub(candidateRealm, "%s+", "")
yellowfive@57 70 candidateRealm = string.lower(candidateRealm)
yellowfive@57 71 candidateName = string.lower(candidateName)
yellowfive@57 72
yellowfive@57 73 -- if perfect match then we are done
yellowfive@57 74 if candidateRealm == realm and candidateName == name then
yellowfive@57 75 return i
yellowfive@57 76 end
yellowfive@57 77
yellowfive@57 78 if candidateName == name then
yellowfive@57 79 table.insert(nameMatches, i)
yellowfive@57 80 end
yellowfive@57 81 end
yellowfive@57 82 end
yellowfive@57 83
yellowfive@57 84 -- only one player with same name, must be the player of interest
yellowfive@57 85 if #nameMatches == 1 then
yellowfive@57 86 return nameMatches[1]
yellowfive@57 87 end
yellowfive@57 88
yellowfive@57 89 -- could not be found or ambiguous
yellowfive@57 90 return nil
yellowfive@57 91 end
yellowfive@57 92
yellowfive@57 93 -- helper to send a message telling everyone that an item was just given out
yellowfive@57 94 local function sendGiveLootMessage(itemLink, unitId, isDisenchant)
yellowfive@57 95 -- some display info
yellowfive@57 96 local cls, clsEn = UnitClass(unitId)
yellowfive@57 97 local name = UnitName(unitId)
yellowfive@57 98
yellowfive@57 99 local result = isDisenchant and "Disenchant" or (roll and roll.rollType or nil)
yellowfive@57 100 if result == nil then result = "??" end
yellowfive@57 101
yellowfive@57 102 local msg = string.format("%s\n%d\n%s\n%s\n%s\n%s", Amr.LootMessagePrefixes.Give, _selectedIndex, itemLink, result, clsEn, name)
yellowfive@57 103 Amr:SendAmrCommMessage(msg)
yellowfive@57 104 end
yellowfive@57 105
yellowfive@57 106 local function onGiveLootClick(widget)
yellowfive@57 107 local rollIndex = widget:GetUserData("index")
yellowfive@57 108
yellowfive@57 109 local rankings = Amr.db.global.TeamOpt.Rankings
yellowfive@57 110 local ranking = rankings[_selectedIndex]
yellowfive@57 111 local rank = ranking and ranking.ranks[rollIndex] or nil
yellowfive@57 112 if rank then
yellowfive@57 113 local roll = Amr.db.char.TeamOpt.Rolls[_selectedIndex][rollIndex]
yellowfive@57 114 local isDisenchant = not not _disenchant[_selectedIndex]
yellowfive@57 115
yellowfive@57 116 local unitId = Amr:GetUnitId(rank.realm, rank.name)
yellowfive@57 117 if unitId then
yellowfive@57 118 -- find the item and loot candidate index
yellowfive@57 119 local itemIndex, itemLink = getLootIndex(_selectedIndex)
yellowfive@57 120
yellowfive@57 121 -- for debugging when don't actually have any loot
yellowfive@57 122 --itemLink = Amr.CreateItemLink(ranking.item)
yellowfive@57 123
yellowfive@57 124 local playerIndex = itemIndex and getLootCandidateIndex(itemIndex, rank.realm, rank.name) or nil
yellowfive@57 125 if itemIndex and playerIndex then
yellowfive@57 126 GiveMasterLoot(itemIndex, playerIndex)
yellowfive@57 127 sendGiveLootMessage(itemLink, unitId, isDisenchant)
yellowfive@57 128 return
yellowfive@57 129 end
yellowfive@57 130
yellowfive@57 131 end
yellowfive@57 132 end
yellowfive@57 133
yellowfive@57 134 -- if we make it here, we could not give out the item for some reason
yellowfive@57 135 Amr:Print(L.LootMasterGiveFail)
yellowfive@57 136 end
yellowfive@57 137
yellowfive@57 138 function Amr:OnLootGiveReceived(parts)
yellowfive@57 139 if not parts or #parts < 6 then return end
yellowfive@57 140
yellowfive@57 141 local rankings = Amr.db.global.TeamOpt.Rankings
yellowfive@57 142
yellowfive@57 143 -- index of the item that was given, flag it to hide it from the ui now
yellowfive@57 144 local index = tonumber(parts[2])
yellowfive@57 145 local ranking = rankings[index]
yellowfive@57 146 if ranking then
yellowfive@57 147 ranking.given = true
yellowfive@57 148 end
yellowfive@57 149
yellowfive@57 150 -- change the selected item index to the next ungiven item
yellowfive@57 151 for i, obj in ipairs(rankings) do
yellowfive@57 152 if not obj.given then
yellowfive@57 153 _selectedIndex = i
yellowfive@57 154 break
yellowfive@57 155 end
yellowfive@57 156 end
yellowfive@57 157
yellowfive@57 158 -- add a loot history entry
yellowfive@57 159 local entry = {
yellowfive@57 160 link = parts[3],
yellowfive@57 161 result = parts[4],
yellowfive@57 162 class = parts[5],
yellowfive@57 163 name = parts[6]
yellowfive@57 164 }
yellowfive@57 165 table.insert(Amr.db.char.TeamOpt.History, entry)
yellowfive@57 166
yellowfive@57 167 -- redraw any open windows
yellowfive@57 168 Amr:RefreshTeamUi()
yellowfive@57 169 Amr:RefreshLootWindow()
yellowfive@57 170 Amr:RefreshLootRolls()
yellowfive@57 171
yellowfive@57 172 -- if this is the master looter, check if all items have been given out
yellowfive@57 173 if IsMasterLooter() then
yellowfive@57 174 local allDone = true
yellowfive@57 175 for i, ranking in ipairs(rankings) do
yellowfive@57 176 if not ranking.given then
yellowfive@57 177 allDone = false
yellowfive@57 178 break
yellowfive@57 179 end
yellowfive@57 180 end
yellowfive@57 181
yellowfive@57 182 if allDone then
yellowfive@57 183 -- send a message indicating that looting is done
yellowfive@57 184 Amr:SendAmrCommMessage(Amr.LootMessagePrefixes.Finish)
yellowfive@57 185 end
yellowfive@57 186 end
yellowfive@57 187
yellowfive@57 188 end
yellowfive@57 189
yellowfive@57 190 local function onDisenchantClick()
yellowfive@57 191 local val = not _disenchant[_selectedIndex]
yellowfive@57 192 _disenchant[_selectedIndex] = val
yellowfive@57 193
yellowfive@57 194 Amr:RefreshLootWindow()
yellowfive@57 195 Amr:RefreshLootRolls()
yellowfive@57 196 end
yellowfive@57 197
yellowfive@57 198 local function onRollClick()
yellowfive@57 199 -- generate a roll for everyone on the current item
yellowfive@57 200 local rands = {}
yellowfive@57 201
yellowfive@57 202 local ranking = Amr.db.global.TeamOpt.Rankings[_selectedIndex]
yellowfive@57 203 for i, rank in ipairs(ranking.ranks) do
yellowfive@57 204 local r = math.random(100)
yellowfive@57 205 rands[i] = r
yellowfive@57 206 end
yellowfive@57 207
yellowfive@57 208 -- transmit the roll data to all group members
yellowfive@57 209 local msg = string.format("%s\n%d\n%s", Amr.LootMessagePrefixes.Rand, _selectedIndex, Amr:Serialize(rands))
yellowfive@57 210 Amr:SendAmrCommMessage(msg)
yellowfive@57 211 end
yellowfive@57 212
yellowfive@57 213 function Amr:OnLootRandReceived(parts)
yellowfive@57 214 if not parts or #parts < 3 then return end
yellowfive@57 215
yellowfive@57 216 local index = tonumber(parts[2])
yellowfive@57 217 local success, rands = Amr:Deserialize(parts[3])
yellowfive@57 218 if not index or not success then return end
yellowfive@57 219
yellowfive@57 220 local rolls = Amr.db.char.TeamOpt.Rolls[index]
yellowfive@57 221 for i, r in pairs(rands) do
yellowfive@57 222 local roll = rolls[i]
yellowfive@57 223 if not roll then
yellowfive@57 224 roll = {}
yellowfive@57 225 rolls[i] = roll
yellowfive@57 226 end
yellowfive@57 227
yellowfive@57 228 roll.rand = r
yellowfive@57 229 end
yellowfive@57 230
yellowfive@57 231 Amr:RefreshLootRolls()
yellowfive@57 232 end
yellowfive@57 233
yellowfive@57 234 local function onVetoClick(widget)
yellowfive@57 235 local rollIndex = widget:GetUserData("rollIndex")
yellowfive@57 236 local rollType = widget:GetUserData("rollType")
yellowfive@57 237
yellowfive@57 238 -- acts like a toggle
yellowfive@57 239 local roll = Amr.db.char.TeamOpt.Rolls[_selectedIndex][rollIndex]
yellowfive@57 240 local veto = not roll or not roll.vetoes or not roll.vetoes[rollType]
yellowfive@57 241
yellowfive@57 242 -- send a message that a veto has been changed
yellowfive@57 243 local msg = string.format("%s\n%d\n%d\n%s\n%s", Amr.LootMessagePrefixes.Veto, _selectedIndex, rollIndex, rollType, veto and "t" or "f")
yellowfive@57 244 Amr:SendAmrCommMessage(msg)
yellowfive@57 245 end
yellowfive@57 246
yellowfive@57 247 function Amr:OnLootVetoReceived(parts)
yellowfive@57 248 if not parts or #parts < 5 then return end
yellowfive@57 249
yellowfive@57 250 local itemIndex = tonumber(parts[2])
yellowfive@57 251 local rollIndex = tonumber(parts[3])
yellowfive@57 252 local rollType = parts[4]
yellowfive@57 253 local veto = parts[5] == "t"
yellowfive@57 254
yellowfive@57 255 if itemIndex and rollIndex then
yellowfive@57 256 local roll = Amr.db.char.TeamOpt.Rolls[itemIndex][rollIndex]
yellowfive@57 257 if not roll then
yellowfive@57 258 roll = {}
yellowfive@57 259 Amr.db.char.TeamOpt.Rolls[itemIndex][rollIndex] = roll
yellowfive@57 260 end
yellowfive@57 261
yellowfive@57 262 if not roll.vetoes then
yellowfive@57 263 roll.vetoes = {}
yellowfive@57 264 end
yellowfive@57 265
yellowfive@57 266 roll.vetoes[rollType] = veto
yellowfive@57 267
yellowfive@57 268 -- if the player chose this option, have to remove it because it has been vetoed
yellowfive@57 269 if veto and roll.rollType == rollType then
yellowfive@57 270 roll.rollType = nil
yellowfive@57 271 end
yellowfive@57 272
yellowfive@57 273 Amr:RefreshLootRolls()
yellowfive@57 274 end
yellowfive@57 275 end
yellowfive@57 276
yellowfive@57 277 -- a user choice for what they want to do on an item
yellowfive@57 278 local function doRoll(rollType)
yellowfive@57 279
yellowfive@57 280 local msg = string.format("%s\n%d\n%s\n%s\n%s", Amr.LootMessagePrefixes.Roll, _selectedIndex, rollType, GetRealmName(), UnitName("player"))
yellowfive@57 281 Amr:SendAmrCommMessage(msg)
yellowfive@57 282 end
yellowfive@57 283
yellowfive@57 284 function Amr:OnLootRollReceived(parts)
yellowfive@57 285 local index = tonumber(parts[2])
yellowfive@57 286 local rollType = parts[3]
yellowfive@57 287 local realm = parts[4]
yellowfive@57 288 local name = parts[5]
yellowfive@57 289
yellowfive@57 290 -- for now, this code matches up name/realm to one in the rankings
yellowfive@57 291 -- TODO: more robust handling of players with same name but different realms in the same group on non-english clients
yellowfive@57 292 local nameMatches = {}
yellowfive@57 293 local ranking = Amr.db.global.TeamOpt.Rankings[index]
yellowfive@57 294 for i, rank in ipairs(ranking.ranks) do
yellowfive@57 295 if name == rank.name and realm == rank.realm then
yellowfive@57 296 nameMatches = {}
yellowfive@57 297 break
yellowfive@57 298 end
yellowfive@57 299
yellowfive@57 300 if name == rank.name then
yellowfive@57 301 table.insert(nameMatches, rank)
yellowfive@57 302 end
yellowfive@57 303 end
yellowfive@57 304 if #nameMatches == 1 then
yellowfive@57 305 realm = nameMatches[1].realm
yellowfive@57 306 name = nameMatches[1].name
yellowfive@57 307 end
yellowfive@57 308
yellowfive@57 309 -- find index of the ranking
yellowfive@57 310 local rankIndex = nil
yellowfive@57 311 for i, rank in ipairs(ranking.ranks) do
yellowfive@57 312 if name == rank.name and realm == rank.realm then
yellowfive@57 313 rankIndex = i
yellowfive@57 314 break
yellowfive@57 315 end
yellowfive@57 316 end
yellowfive@57 317
yellowfive@57 318 if rankIndex then
yellowfive@57 319 local obj = Amr.db.char.TeamOpt.Rolls[index][rankIndex]
yellowfive@57 320 if not obj then
yellowfive@57 321 obj = {}
yellowfive@57 322 Amr.db.char.TeamOpt.Rolls[index][rankIndex] = obj
yellowfive@57 323 end
yellowfive@57 324 obj.rollType = rollType
yellowfive@57 325 end
yellowfive@57 326
yellowfive@57 327 Amr:RefreshLootRolls()
yellowfive@57 328 end
yellowfive@57 329
yellowfive@57 330 local function renderRollType(rp, rollType, roll, index)
yellowfive@57 331
yellowfive@57 332 local icon = rp:GetUserData(rollType)
yellowfive@57 333 if not icon and roll then
yellowfive@57 334 -- create icon if we need one
yellowfive@57 335 icon = AceGUI:Create("AmrUiTextButton")
yellowfive@57 336 icon:SetWidth(16)
yellowfive@57 337 icon:SetHeight(16)
yellowfive@57 338 local pos = _rollTypePos[rollType]
yellowfive@57 339 local left = _widthRank + _widthColPadding + _widthRankBar + (pos * _widthColPadding) + ((pos - 1) * _widthRollType) + ((_widthRollType - 16) / 2)
yellowfive@57 340 icon:SetPoint("LEFT", rp.content, "LEFT", left, 0)
yellowfive@57 341 rp:AddChild(icon)
yellowfive@57 342 rp:SetUserData(rollType, icon)
yellowfive@57 343
yellowfive@57 344 icon:SetUserData("rollType", rollType)
yellowfive@57 345 icon:SetUserData("rollIndex", index)
yellowfive@57 346 icon:SetVisible(false)
yellowfive@57 347
yellowfive@57 348 icon:SetCallback("OnClick", onVetoClick)
yellowfive@57 349 end
yellowfive@57 350
yellowfive@57 351 if icon then
yellowfive@57 352 if roll and roll.rollType == rollType then
yellowfive@57 353 icon:SetVisible(true)
yellowfive@57 354 icon:SetBackgroundImage("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\IconCheck")
yellowfive@57 355 icon:SetHoverBackgroundImage("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\IconCheck")
yellowfive@57 356 elseif roll and roll.vetoes and roll.vetoes[rollType] then
yellowfive@57 357 icon:SetVisible(true)
yellowfive@57 358 icon:SetBackgroundImage("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\IconX")
yellowfive@57 359 icon:SetHoverBackgroundImage("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\IconX")
yellowfive@57 360 else
yellowfive@57 361 icon:SetVisible(false)
yellowfive@57 362 end
yellowfive@57 363
yellowfive@57 364 icon:SetDisabled(not IsMasterLooter())
yellowfive@57 365 end
yellowfive@57 366
yellowfive@57 367 -- update button state for this roll type
yellowfive@57 368 if _lootButtons and _lootButtons[rollType] then
yellowfive@57 369 _lootButtons[rollType]:SetDisabled(roll and roll.vetoes and roll.vetoes[rollType])
yellowfive@57 370 end
yellowfive@57 371 end
yellowfive@57 372
yellowfive@57 373 -- gets the current winner based on rolls and currently selected roll type for each user (returns index into rankings for item, or -1 if no winner yet)
yellowfive@57 374 local function getWinner(itemIndex)
yellowfive@57 375
yellowfive@57 376 local rolls = Amr.db.char.TeamOpt.Rolls[itemIndex]
yellowfive@57 377 if not rolls then return -1 end
yellowfive@57 378
yellowfive@57 379 -- go through and find the highest priority roll type
yellowfive@57 380 local bestRollType
yellowfive@57 381 local bestTypePos = 100
yellowfive@57 382 for i, roll in pairs(rolls) do
yellowfive@57 383 if roll.rollType then
yellowfive@57 384 local rollPos = _rollTypePos[roll.rollType]
yellowfive@57 385 if rollPos < bestTypePos and rollPos < _rollTypePos["Pass"] then
yellowfive@57 386 bestRollType = roll.rollType
yellowfive@57 387 bestTypePos = rollPos
yellowfive@57 388 end
yellowfive@57 389 end
yellowfive@57 390 end
yellowfive@57 391
yellowfive@57 392 -- nobody has chosen anything yet
yellowfive@57 393 if not bestRollType then return -1 end
yellowfive@57 394
yellowfive@57 395 -- find highest roll in the highest priority roll type
yellowfive@57 396 local maxRoll = -1
yellowfive@57 397 local bestRoll = -1
yellowfive@57 398 for i, roll in pairs(rolls) do
yellowfive@57 399 if roll.rollType == bestRollType and roll.rand and roll.rand > maxRoll then
yellowfive@57 400 bestRoll = i
yellowfive@57 401 maxRoll = roll.rand
yellowfive@57 402 end
yellowfive@57 403 end
yellowfive@57 404
yellowfive@57 405 return bestRoll
yellowfive@57 406 end
yellowfive@57 407
yellowfive@57 408 function Amr:RefreshLootRolls()
yellowfive@57 409 if not _rankPanels then return end
yellowfive@57 410
yellowfive@57 411 local ranking = Amr.db.global.TeamOpt.Rankings[_selectedIndex]
yellowfive@57 412 local rolls = Amr.db.char.TeamOpt.Rolls[_selectedIndex]
yellowfive@57 413 local isDisenchant = _disenchant[_selectedIndex]
yellowfive@57 414
yellowfive@57 415 local winnerIndex = getWinner(_selectedIndex)
yellowfive@57 416
yellowfive@57 417 for i, rp in pairs(_rankPanels) do
yellowfive@57 418 local rank = ranking.ranks[i]
yellowfive@57 419 local roll = rolls[i]
yellowfive@57 420 if isDisenchant then roll = nil end
yellowfive@57 421
yellowfive@57 422 -- clear or set the value of each roll column
yellowfive@57 423 renderRollType(rp, "Need", roll, i)
yellowfive@57 424 renderRollType(rp, "Off", roll, i)
yellowfive@57 425 renderRollType(rp, "Greed", roll, i)
yellowfive@57 426 renderRollType(rp, "Pass", roll, i)
yellowfive@57 427
yellowfive@57 428 -- render the random roll
yellowfive@57 429 local lbl = rp:GetUserData("randLabel")
yellowfive@57 430 if roll and roll.rand then
yellowfive@57 431 if not lbl then
yellowfive@57 432 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 433 lbl:SetJustifyH("RIGHT")
yellowfive@57 434
yellowfive@57 435 local left = _widthRank + _widthColPadding + _widthRankBar + (5 * _widthColPadding) + (5 * _widthRollType)
yellowfive@57 436 lbl:SetPoint("RIGHT", rp.content, "LEFT", left, 0)
yellowfive@57 437 rp:AddChild(lbl)
yellowfive@57 438 rp:SetUserData("randLabel", lbl)
yellowfive@57 439 end
yellowfive@57 440
yellowfive@57 441 -- highlight this roll if winner, otherwise unhighlight
yellowfive@57 442 if i == winnerIndex then
yellowfive@57 443 lbl:SetFont(Amr.CreateFont("Bold", 18, Amr.Colors.BrightGreen))
yellowfive@57 444 else
yellowfive@57 445 lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White))
yellowfive@57 446 end
yellowfive@57 447
yellowfive@57 448 lbl:SetText(roll.rand)
yellowfive@57 449 else
yellowfive@57 450 if lbl then
yellowfive@57 451 lbl:SetVisible(false)
yellowfive@57 452 end
yellowfive@57 453 end
yellowfive@57 454
yellowfive@57 455 -- if this person does not have the addon, show a message (except in DE mode)
yellowfive@57 456 local hasAddon = true
yellowfive@57 457 local unitId = Amr:GetUnitId(rank.realm, rank.name)
yellowfive@57 458 if unitId then
yellowfive@57 459 local realm, name = Amr:GetRealmAndName(unitId)
yellowfive@57 460 if realm then
yellowfive@57 461 local ver = Amr:GetAddonVersion(realm, name)
yellowfive@57 462 hasAddon = ver >= Amr.MIN_ADDON_VERSION
yellowfive@57 463 end
yellowfive@57 464 end
yellowfive@57 465
yellowfive@57 466 lbl = rp:GetUserData("noaddonLabel")
yellowfive@57 467 if not hasAddon and not isDisenchant then
yellowfive@57 468 if not lbl then
yellowfive@57 469 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 470 lbl:SetFont(Amr.CreateFont("Italic", 14, Amr.Colors.Red))
yellowfive@57 471 lbl:SetText(L.LootRankLabelNoAddon)
yellowfive@57 472 lbl:SetPoint("LEFT", rp.content, "LEFT", _widthRank + _widthColPadding + _widthRankBar + _widthColPadding + 5, 0)
yellowfive@57 473 rp:AddChild(lbl)
yellowfive@57 474 rp:SetUserData("noaddonLabel", lbl)
yellowfive@57 475 end
yellowfive@57 476 else
yellowfive@57 477 if lbl then
yellowfive@57 478 lbl:SetVisible(false)
yellowfive@57 479 end
yellowfive@57 480 end
yellowfive@57 481
yellowfive@57 482 end
yellowfive@57 483 end
yellowfive@57 484
yellowfive@57 485 -- helper to create the column bg and header for rank list
yellowfive@57 486 local function createLootRankColumn(container, prevColumn, width, txt, txtAlign, extraPadding)
yellowfive@57 487 extraPadding = extraPadding and extraPadding or 0
yellowfive@57 488
yellowfive@57 489 local panel = AceGUI:Create("AmrUiPanel")
yellowfive@57 490 panel:SetBackgroundColor(Amr.Colors.Black, 0.3)
yellowfive@57 491 container:AddChild(panel)
yellowfive@57 492
yellowfive@57 493 if prevColumn then
yellowfive@57 494 -- pad a bit to right of previous column
yellowfive@57 495 panel:SetPoint("TOPLEFT", prevColumn.content, "TOPRIGHT", _widthColPadding + extraPadding, 0)
yellowfive@57 496 panel:SetPoint("BOTTOMRIGHT", prevColumn.content, "BOTTOMRIGHT", _widthColPadding + extraPadding + width, 0)
yellowfive@57 497 else
yellowfive@57 498 -- first column abs position in the main ranking panel
yellowfive@57 499 panel:SetPoint("TOPLEFT", container.content, "TOPLEFT", _widthItemList + _widthSpacing, -115)
yellowfive@57 500 panel:SetPoint("BOTTOMRIGHT", container.content, "BOTTOMLEFT", _widthItemList + _widthSpacing + width, 0)
yellowfive@57 501 end
yellowfive@57 502
yellowfive@57 503 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 504 lbl:SetWordWrap(false)
yellowfive@57 505 lbl:SetFont(Amr.CreateFont("Regular", 12, Amr.Colors.TextHeaderDisabled))
yellowfive@57 506 lbl:SetText(txt)
yellowfive@57 507 lbl:SetJustifyH(txtAlign)
yellowfive@57 508 lbl:SetWidth(width)
yellowfive@57 509 lbl:SetPoint("BOTTOMLEFT", panel.content, "TOPLEFT", 0, 5)
yellowfive@57 510 container:AddChild(lbl)
yellowfive@57 511
yellowfive@57 512 return panel, lbl
yellowfive@57 513 end
yellowfive@57 514
yellowfive@57 515 function Amr:RefreshLootWindow()
yellowfive@57 516 if not _panelLoot then return end
yellowfive@57 517
yellowfive@57 518 -- clear out any children of the main loot frame and re-render
yellowfive@57 519 _panelLoot:ReleaseChildren()
yellowfive@57 520 _rankPanels = {}
yellowfive@57 521 _lootButtons = {}
yellowfive@57 522
yellowfive@57 523 local ml = IsMasterLooter()
yellowfive@57 524 local myUnitId = Amr:GetUnitId(GetRealmName(), UnitName("player"))
yellowfive@57 525
yellowfive@57 526 local rankings = Amr.db.global.TeamOpt.Rankings
yellowfive@57 527 if rankings and #rankings > 0 then
yellowfive@57 528
yellowfive@57 529 -- make sure that an item is selected
yellowfive@57 530 if not _selectedIndex then
yellowfive@57 531 for i, ranking in ipairs(rankings) do
yellowfive@57 532 if not ranking.given then
yellowfive@57 533 _selectedIndex = i
yellowfive@57 534 break
yellowfive@57 535 end
yellowfive@57 536 end
yellowfive@57 537 end
yellowfive@57 538
yellowfive@57 539 -- render list of items
yellowfive@57 540 local panelItems = AceGUI:Create("AmrUiPanel")
yellowfive@57 541 panelItems:SetLayout("Fill")
yellowfive@57 542 panelItems:SetWidth(_widthItemList)
yellowfive@57 543 panelItems:SetBackgroundColor(Amr.Colors.Black, 0)
yellowfive@57 544 panelItems:SetPoint("TOPLEFT", _panelLoot.content, "TOPLEFT", 0, 0)
yellowfive@57 545 panelItems:SetPoint("BOTTOMLEFT", _panelLoot.content, "BOTTOMLEFT")
yellowfive@57 546 _panelLoot:AddChild(panelItems)
yellowfive@57 547
yellowfive@57 548 local scrollItems = AceGUI:Create("AmrUiScrollFrame")
yellowfive@57 549 scrollItems:SetLayout("List")
yellowfive@57 550 panelItems:AddChild(scrollItems)
yellowfive@57 551
yellowfive@57 552 -- render the divider between items and ranks
yellowfive@57 553 local divider = AceGUI:Create("AmrUiPanel")
yellowfive@57 554 divider:SetBackgroundColor(Amr.Colors.Black, 0.5)
yellowfive@57 555 divider:SetPoint("TOPLEFT", _panelLoot.content, "TOPLEFT", _widthItemList, 0)
yellowfive@57 556 divider:SetPoint("BOTTOMRIGHT", _panelLoot.content, "BOTTOMLEFT", _widthItemList + 5, 0)
yellowfive@57 557 _panelLoot:AddChild(divider)
yellowfive@57 558
yellowfive@57 559 local btn, btn2, lbl, lbl2, panel, panel2, chk
yellowfive@57 560
yellowfive@57 561 local remainingItems = {}
yellowfive@57 562 for i, ranking in ipairs(rankings) do
yellowfive@57 563 if not ranking.given then
yellowfive@57 564 remainingItems[i] = ranking
yellowfive@57 565 end
yellowfive@57 566 end
yellowfive@57 567
yellowfive@57 568 for i, ranking in pairs(remainingItems) do
yellowfive@57 569 btn = AceGUI:Create("AmrUiTextButton")
yellowfive@57 570 btn:SetWidth(_widthItemList)
yellowfive@57 571 btn:SetHeight(50)
yellowfive@57 572 btn:SetJustifyH("LEFT")
yellowfive@57 573 btn:SetJustifyV("TOP")
yellowfive@57 574 btn:SetTextPadding(9, nil, nil, 2)
yellowfive@57 575 btn:SetWordWrap(false)
yellowfive@57 576 btn:SetUserData("index", i)
yellowfive@57 577
yellowfive@57 578 local f
yellowfive@57 579 if _selectedIndex == i then
yellowfive@57 580 f = Amr.CreateFont("Bold", 16, Amr.Colors.Text)
yellowfive@57 581 btn:SetBackgroundColor(Amr.Colors.Black, 0.5)
yellowfive@57 582 btn:SetHoverBackgroundColor(Amr.Colors.Black, 0.5)
yellowfive@57 583 else
yellowfive@57 584 f = Amr.CreateFont("Regular", 14, Amr.Colors.Text)
yellowfive@57 585 btn:SetHoverBackgroundColor(Amr.Colors.Black, 0.2)
yellowfive@57 586 end
yellowfive@57 587
yellowfive@57 588 btn:SetFont(f)
yellowfive@57 589 btn:SetHoverFont(f)
yellowfive@57 590
yellowfive@57 591 scrollItems:AddChild(btn)
yellowfive@57 592
yellowfive@57 593 btn:SetCallback("OnClick", function(widget)
yellowfive@57 594 Amr:SelectLootItem(widget:GetUserData("index"))
yellowfive@57 595 end)
yellowfive@57 596
yellowfive@57 597 local rankLink = Amr.CreateItemLink(ranking.item)
yellowfive@57 598 Amr.GetItemInfo(rankLink, function(obj, name, link)
yellowfive@57 599 -- set item name, tooltip
yellowfive@57 600 obj:SetText(" " .. link:gsub("%[", ""):gsub("%]", ""))
yellowfive@57 601 Amr:SetItemTooltip(obj, link, "ANCHOR_BOTTOMLEFT", 0, obj.frame:GetHeight())
yellowfive@57 602 end, btn)
yellowfive@57 603
yellowfive@57 604 -- add a label for slot, armor type
yellowfive@57 605 local slotText = Amr.SlotEnumDisplayText[ranking.itemInfo.slot]
yellowfive@57 606 if ranking.itemInfo.slot == 'MainHand' then
yellowfive@57 607 slotText = ranking.itemInfo.subclass == 'TwoHand' and L.TwoHand or L.OneHand
yellowfive@57 608 elseif ranking.itemInfo.slot == 'OffHand' then
yellowfive@57 609 slotText = L.OffHand
yellowfive@57 610 end
yellowfive@57 611
yellowfive@57 612 if ranking.itemInfo.armorType == 'None' and ranking.itemInfo.weaponType ~= 'None' then
yellowfive@57 613 if ranking.itemInfo.weaponType ~= 'OffHand' then
yellowfive@57 614 slotText = slotText .. ", " .. L.WeaponTypes[ranking.itemInfo.weaponType]
yellowfive@57 615 end
yellowfive@57 616 elseif ranking.itemInfo.armorType ~= 'None' then
yellowfive@57 617 slotText = slotText .. ", " .. L.ArmorTypes[ranking.itemInfo.armorType]
yellowfive@57 618 end
yellowfive@57 619
yellowfive@57 620 btn:SetSubtextFont(Amr.CreateFont("Regular", 13, Amr.Colors.TextGray))
yellowfive@57 621 btn:SetSubtextJustifyH("LEFT")
yellowfive@57 622 btn:SetSubtextJustifyV("BOTTOM")
yellowfive@57 623 btn:SetSubtextPadding(nil, nil, 9, 7)
yellowfive@57 624 btn:SetSubtextWordWrap(false)
yellowfive@57 625 btn:SetSubtext(slotText)
yellowfive@57 626
yellowfive@57 627
yellowfive@57 628 local isDisenchant = not not _disenchant[i]
yellowfive@57 629
yellowfive@57 630 if _selectedIndex == i then
yellowfive@57 631
yellowfive@57 632 -- see if I am in the list
yellowfive@57 633 local canLoot = false
yellowfive@57 634 for j, rank in ipairs(ranking.ranks) do
yellowfive@57 635 local unitId = Amr:GetUnitId(rank.realm, rank.name)
yellowfive@57 636 if unitId == myUnitId then
yellowfive@57 637 canLoot = not rank.notRanked or rank.offspec
yellowfive@57 638 break
yellowfive@57 639 end
yellowfive@57 640 end
yellowfive@57 641
yellowfive@57 642 -- render loot options
yellowfive@57 643 if canLoot then
yellowfive@57 644 btn = AceGUI:Create("AmrUiButton")
yellowfive@57 645 btn:SetWidth(120)
yellowfive@57 646 btn:SetHeight(26)
yellowfive@57 647 btn:SetFont(Amr.CreateFont("Bold", 15, Amr.Colors.White))
yellowfive@57 648 btn:SetBackgroundColor(Amr.Colors.Green)
yellowfive@57 649 btn:SetText(L.TeamLootOptionNeed)
yellowfive@57 650 btn:SetPoint("TOPLEFT", _panelLoot.content, "TOPLEFT", _widthItemList + _widthSpacing, -7)
yellowfive@57 651 btn:SetCallback("OnClick", function(widget) doRoll("Need") end)
yellowfive@57 652 _panelLoot:AddChild(btn)
yellowfive@57 653 _lootButtons["Need"] = btn
yellowfive@57 654
yellowfive@57 655 btn2 = AceGUI:Create("AmrUiButton")
yellowfive@57 656 btn2:SetWidth(120)
yellowfive@57 657 btn2:SetHeight(26)
yellowfive@57 658 btn2:SetFont(Amr.CreateFont("Bold", 15, Amr.Colors.White))
yellowfive@57 659 btn2:SetBackgroundColor(Amr.Colors.Orange)
yellowfive@57 660 btn2:SetText(L.TeamLootOptionPass)
yellowfive@57 661 btn2:SetPoint("TOPLEFT", btn.frame, "BOTTOMLEFT", 0, -15)
yellowfive@57 662 btn2:SetCallback("OnClick", function(widget) doRoll("Pass") end)
yellowfive@57 663 _panelLoot:AddChild(btn2)
yellowfive@57 664 _lootButtons["Pass"] = btn2
yellowfive@57 665
yellowfive@57 666 btn = AceGUI:Create("AmrUiButton")
yellowfive@57 667 btn:SetWidth(120)
yellowfive@57 668 btn:SetHeight(26)
yellowfive@57 669 btn:SetFont(Amr.CreateFont("Bold", 15, Amr.Colors.White))
yellowfive@57 670 btn:SetBackgroundColor(Amr.Colors.Blue)
yellowfive@57 671 btn:SetText(L.TeamLootOptionOff)
yellowfive@57 672 btn:SetPoint("BOTTOMLEFT", btn2.frame, "TOPRIGHT", 15, 15)
yellowfive@57 673 btn:SetCallback("OnClick", function(widget) doRoll("Off") end)
yellowfive@57 674 _panelLoot:AddChild(btn)
yellowfive@57 675 _lootButtons["Off"] = btn
yellowfive@57 676
yellowfive@57 677 btn2 = AceGUI:Create("AmrUiButton")
yellowfive@57 678 btn2:SetWidth(120)
yellowfive@57 679 btn2:SetHeight(26)
yellowfive@57 680 btn2:SetFont(Amr.CreateFont("Bold", 15, Amr.Colors.White))
yellowfive@57 681 btn2:SetBackgroundColor(Amr.Colors.Blue)
yellowfive@57 682 btn2:SetText(L.TeamLootOptionGreed)
yellowfive@57 683 btn2:SetPoint("TOPLEFT", btn.frame, "BOTTOMLEFT", 0, -15)
yellowfive@57 684 btn2:SetCallback("OnClick", function(widget) doRoll("Greed") end)
yellowfive@57 685 _panelLoot:AddChild(btn2)
yellowfive@57 686 _lootButtons["Greed"] = btn2
yellowfive@57 687 else
yellowfive@57 688 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 689 lbl:SetFont(Amr.CreateFont("Italic", 14, Amr.Colors.TextTan))
yellowfive@57 690 lbl:SetText(L.LootIneligible)
yellowfive@57 691 lbl:SetWidth(255)
yellowfive@57 692 lbl:SetPoint("TOPLEFT", _panelLoot.content, "TOPLEFT", _widthItemList + _widthSpacing, -7)
yellowfive@57 693 _panelLoot:AddChild(lbl)
yellowfive@57 694 end
yellowfive@57 695
yellowfive@57 696 -- master loot options
yellowfive@57 697 if ml then
yellowfive@57 698 chk = AceGUI:Create("AmrUiCheckBox")
yellowfive@57 699 chk:SetText(L.LootMasterDisenchantText)
yellowfive@57 700 chk:SetPoint("TOPRIGHT", _panelLoot.content, "TOPRIGHT", -18, -12)
yellowfive@57 701 chk:SetCallback("OnClick", onDisenchantClick)
yellowfive@57 702 chk:SetChecked(_disenchant[i])
yellowfive@57 703 _panelLoot:AddChild(chk)
yellowfive@57 704
yellowfive@57 705 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 706 lbl:SetWidth(120)
yellowfive@57 707 lbl:SetJustifyH("CENTER")
yellowfive@57 708 lbl:SetText(L.LootMasterDisenchantLabel)
yellowfive@57 709 lbl:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.TextTan))
yellowfive@57 710 lbl:SetPoint("TOP", chk.frame, "BOTTOM", 0, -5)
yellowfive@57 711 _panelLoot:AddChild(lbl)
yellowfive@57 712
yellowfive@57 713 btn2 = AceGUI:Create("AmrUiButton")
yellowfive@57 714 btn2:SetWidth(120)
yellowfive@57 715 btn2:SetHeight(26)
yellowfive@57 716 btn2:SetFont(Amr.CreateFont("Bold", 15, Amr.Colors.White))
yellowfive@57 717 btn2:SetBackgroundColor(Amr.Colors.Green)
yellowfive@57 718 btn2:SetText(L.LootMasterRollText)
yellowfive@57 719 btn2:SetPoint("RIGHT", chk.frame, "LEFT", -50, 0)
yellowfive@57 720 btn2:SetCallback("OnClick", onRollClick)
yellowfive@57 721 _panelLoot:AddChild(btn2)
yellowfive@57 722
yellowfive@57 723 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 724 lbl:SetWidth(120)
yellowfive@57 725 lbl:SetJustifyH("CENTER")
yellowfive@57 726 lbl:SetText(L.LootMasterRollLabel)
yellowfive@57 727 lbl:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.TextTan))
yellowfive@57 728 lbl:SetPoint("TOP", btn2.frame, "BOTTOM", 0, -5)
yellowfive@57 729 _panelLoot:AddChild(lbl)
yellowfive@57 730
yellowfive@57 731 end
yellowfive@57 732
yellowfive@57 733 -- backgrounds for the rank list and headers
yellowfive@57 734 panel = createLootRankColumn(_panelLoot, nil, _widthRank, isDisenchant and "" or L.LootRankHeaderRank, "RIGHT")
yellowfive@57 735 panel = createLootRankColumn(_panelLoot, panel, _widthRankBar, isDisenchant and L.LootRankHeaderScoreDisenchant or L.LootRankHeaderScore, "LEFT")
yellowfive@57 736
yellowfive@57 737 if not isDisenchant then
yellowfive@57 738 panel = createLootRankColumn(_panelLoot, panel, _widthRollType, L.LootRankHeaderNeed, "CENTER")
yellowfive@57 739 panel = createLootRankColumn(_panelLoot, panel, _widthRollType, L.LootRankHeaderOff, "CENTER")
yellowfive@57 740 panel = createLootRankColumn(_panelLoot, panel, _widthRollType, L.LootRankHeaderGreed, "CENTER")
yellowfive@57 741 panel = createLootRankColumn(_panelLoot, panel, _widthRollType, L.LootRankHeaderPass, "CENTER")
yellowfive@57 742 panel = createLootRankColumn(_panelLoot, panel, _widthRollType, L.LootRankHeaderRoll, "RIGHT", _widthRollExtraSpacing)
yellowfive@57 743 end
yellowfive@57 744
yellowfive@57 745 -- rank list for selected item
yellowfive@57 746 panel = AceGUI:Create("AmrUiPanel")
yellowfive@57 747 panel:SetLayout("Fill")
yellowfive@57 748 panel:SetBackgroundColor(Amr.Colors.Black, 0)
yellowfive@57 749 panel:SetPoint("TOPLEFT", _panelLoot.content, "TOPLEFT", _widthItemList + _widthSpacing, -115)
yellowfive@57 750 panel:SetPoint("BOTTOMRIGHT", _panelLoot.content, "BOTTOMRIGHT")
yellowfive@57 751 _panelLoot:AddChild(panel)
yellowfive@57 752
yellowfive@57 753 local scrollRanks = AceGUI:Create("AmrUiScrollFrame")
yellowfive@57 754 scrollRanks:SetLayout("List")
yellowfive@57 755 panel:AddChild(scrollRanks)
yellowfive@57 756
yellowfive@57 757 -- find min and max value, used for sizing the bars
yellowfive@57 758 local rankMin = -0.02
yellowfive@57 759 local rankMax = 0.02
yellowfive@57 760 for j, rank in ipairs(ranking.ranks) do
yellowfive@57 761 if rank.score < rankMin then
yellowfive@57 762 rankMin = rank.score
yellowfive@57 763 end
yellowfive@57 764 if rank.score > rankMax then
yellowfive@57 765 rankMax = rank.score
yellowfive@57 766 end
yellowfive@57 767 end
yellowfive@57 768
yellowfive@57 769 -- just make min less than max if they are the same, doesn't really matter what it is, would be a wacky case
yellowfive@57 770 if rankMin == rankMax then
yellowfive@57 771 rankMin = rankMax - 1
yellowfive@57 772 end
yellowfive@57 773
yellowfive@57 774 local minWidth = 10
yellowfive@57 775 local maxWidth = _widthRankBar - 36 - 65 - 2 -- reserve 36 for icon, 65 for bar label, and 2 for a border around the bar
yellowfive@57 776 local rankCount = 0
yellowfive@57 777
yellowfive@57 778 for j, rank in ipairs(ranking.ranks) do
yellowfive@57 779 local unitId = Amr:GetUnitId(rank.realm, rank.name)
yellowfive@57 780 if unitId then
yellowfive@57 781 local skip = false
yellowfive@57 782 if isDisenchant then
yellowfive@57 783 skip = true
yellowfive@57 784 if rank.isMasterLooter or (rank.enchantingSkill and rank.enchantingSkill > 0) then
yellowfive@57 785 skip = false
yellowfive@57 786 end
yellowfive@57 787 end
yellowfive@57 788
yellowfive@57 789 if not skip then
yellowfive@57 790 rankCount = rankCount + 1
yellowfive@57 791
yellowfive@57 792 local rp = AceGUI:Create("AmrUiPanel")
yellowfive@57 793 rp:SetLayout("None")
yellowfive@57 794 rp:SetBackgroundColor(Amr.Colors.Black, 0)
yellowfive@57 795 rp:SetWidth(_widthRankList)
yellowfive@57 796 rp:SetHeight(45)
yellowfive@57 797 scrollRanks:AddChild(rp)
yellowfive@57 798 _rankPanels[j] = rp
yellowfive@57 799
yellowfive@57 800 if not isDisenchant then
yellowfive@57 801 panel = AceGUI:Create("AmrUiPanel")
yellowfive@57 802 panel:SetBackgroundColor(Amr.Colors.Black, 1)
yellowfive@57 803 panel:SetPoint("TOPLEFT", rp.content, "BOTTOMLEFT", 0, 0)
yellowfive@57 804 panel:SetPoint("BOTTOMRIGHT", rp.content, "BOTTOMRIGHT", -120, -1)
yellowfive@57 805 rp:AddChild(panel)
yellowfive@57 806 end
yellowfive@57 807
yellowfive@57 808 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 809 lbl:SetFont(Amr.CreateFont("Bold", 32, Amr.Colors.White))
yellowfive@57 810 lbl:SetText(rankCount)
yellowfive@57 811 lbl:SetWidth(_widthRank - 6)
yellowfive@57 812 lbl:SetJustifyH("RIGHT")
yellowfive@57 813 lbl:SetPoint("BOTTOMLEFT", rp.content, "BOTTOMLEFT", 0, 3)
yellowfive@57 814 rp:AddChild(lbl)
yellowfive@57 815
yellowfive@57 816 local cls, clsEn = UnitClass(unitId)
yellowfive@57 817 local color = clsEn and Amr.Colors.Classes[clsEn] or Amr.Colors.TextHeaderDisabled
yellowfive@57 818
yellowfive@57 819 local icon = AceGUI:Create("AmrUiIcon")
yellowfive@57 820 icon:SetIconBorderColor(color)
yellowfive@57 821 icon:SetWidth(36)
yellowfive@57 822 icon:SetHeight(36)
yellowfive@57 823 icon:SetIcon("Interface\\Icons\\" .. Amr.SpecIcons[rank.specId])
yellowfive@57 824 icon:SetPoint("BOTTOMLEFT", rp.content, "BOTTOMLEFT", 48 + 8, 0)
yellowfive@57 825 rp:AddChild(icon)
yellowfive@57 826
yellowfive@57 827 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 828 lbl:SetFont(Amr.CreateFont("Bold", 16, color))
yellowfive@57 829 lbl:SetText(UnitName(unitId))
yellowfive@57 830 lbl:SetWidth(_widthRankBar - 36 - 8) -- 4px on left and right side
yellowfive@57 831 lbl:SetPoint("TOPLEFT", icon.frame, "TOPRIGHT", 4, -2)
yellowfive@57 832 rp:AddChild(lbl)
yellowfive@57 833
yellowfive@57 834 if isDisenchant or rank.notRanked then
yellowfive@57 835 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 836 lbl:SetFont(Amr.CreateFont("Italic", 13, Amr.Colors.TextHeaderDisabled))
yellowfive@57 837 lbl:SetWidth(_widthRankBar - 36 - 4) -- 4px on left side
yellowfive@57 838 lbl:SetWordWrap(false)
yellowfive@57 839 lbl:SetPoint("BOTTOMLEFT", icon.frame, "BOTTOMRIGHT", 4, 2)
yellowfive@57 840 rp:AddChild(lbl)
yellowfive@57 841
yellowfive@57 842 if isDisenchant then
yellowfive@57 843 -- will be disenchanter or ML if we are DEing the item
yellowfive@57 844 lbl:SetText((rank.enchantingSkill and rank.enchantingSkill > 0) and string.format(L.LootRankLabelDisenchant .. " (%d)", rank.enchantingSkill) or L.LootRankLabelMasterLooter)
yellowfive@57 845 else
yellowfive@57 846 -- if this is off spec or just a disenchanter, no score bar just description text
yellowfive@57 847 lbl:SetText(rank.offspec and L.LootRankLabelOff or ((rank.enchantingSkill and rank.enchantingSkill > 0) and string.format(L.LootRankLabelDisenchant .. " (%d)", rank.enchantingSkill) or L.LootRankLabelMasterLooter))
yellowfive@57 848 end
yellowfive@57 849 else
yellowfive@57 850 local scoreText = rank.score .. "%"
yellowfive@57 851 local val = rank.score;
yellowfive@57 852 if rank.isEquipped then
yellowfive@57 853 scoreText = "E"
yellowfive@57 854 val = 0
yellowfive@57 855 elseif val >= 0 then
yellowfive@57 856 scoreText = "+" .. scoreText
yellowfive@57 857 end
yellowfive@57 858
yellowfive@57 859 local per = (val - rankMin) / (rankMax - rankMin);
yellowfive@57 860 local w = minWidth + (per * (maxWidth - minWidth));
yellowfive@57 861 color = val > 0 and Amr.Colors.BarHigh or (val == 0 and Amr.Colors.BarMed or Amr.Colors.BarLow)
yellowfive@57 862
yellowfive@57 863 panel = AceGUI:Create("AmrUiPanel")
yellowfive@57 864 panel:SetLayout("None")
yellowfive@57 865 panel:SetWidth(w + 2)
yellowfive@57 866 panel:SetHeight(16)
yellowfive@57 867 panel:SetBackgroundColor(Amr.Colors.Black, 1)
yellowfive@57 868 panel:SetPoint("BOTTOMLEFT", icon.frame, "BOTTOMRIGHT", 0, -1)
yellowfive@57 869 rp:AddChild(panel)
yellowfive@57 870
yellowfive@57 871 panel2 = AceGUI:Create("AmrUiPanel")
yellowfive@57 872 panel2:SetLayout("None")
yellowfive@57 873 panel2:SetWidth(w)
yellowfive@57 874 panel2:SetHeight(14)
yellowfive@57 875 panel2:SetBackgroundColor(color, 1)
yellowfive@57 876 panel2:SetPoint("TOPLEFT", panel.content, "TOPLEFT", 1, -1)
yellowfive@57 877 panel:AddChild(panel2)
yellowfive@57 878
yellowfive@57 879 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 880 lbl:SetFont(Amr.CreateFont("Bold", 13, color))
yellowfive@57 881 lbl:SetText(scoreText)
yellowfive@57 882 lbl:SetWidth(63)
yellowfive@57 883 lbl:SetWordWrap(false)
yellowfive@57 884 lbl:SetPoint("LEFT", panel.content, "RIGHT", 2, 0)
yellowfive@57 885 rp:AddChild(lbl)
yellowfive@57 886 end
yellowfive@57 887
yellowfive@57 888 if ml then
yellowfive@57 889 btn2 = AceGUI:Create("AmrUiButton")
yellowfive@57 890 btn2:SetHeight(24)
yellowfive@57 891 btn2:SetFont(Amr.CreateFont("Regular", 13, Amr.Colors.White))
yellowfive@57 892 btn2:SetBackgroundColor(Amr.Colors.Green)
yellowfive@57 893
yellowfive@57 894 if isDisenchant then
yellowfive@57 895 btn2:SetWidth(200)
yellowfive@57 896 btn2:SetText(L.LootMasterGiveDisenchant)
yellowfive@57 897 btn2:SetPoint("LEFT", rp.content, "LEFT", _widthRank + _widthRankBar + (3 * _widthColPadding), 0)
yellowfive@57 898 else
yellowfive@57 899 btn2:SetWidth(85)
yellowfive@57 900 btn2:SetText(L.LootMasterGiveLoot)
yellowfive@57 901 btn2:SetPoint("RIGHT", rp.content, "RIGHT", -30, 0)
yellowfive@57 902 end
yellowfive@57 903
yellowfive@57 904 btn2:SetUserData("index", j)
yellowfive@57 905 btn2:SetCallback("OnClick", onGiveLootClick)
yellowfive@57 906 rp:AddChild(btn2)
yellowfive@57 907 end
yellowfive@57 908 end
yellowfive@57 909
yellowfive@57 910 end
yellowfive@57 911 end
yellowfive@57 912
yellowfive@57 913 end
yellowfive@57 914
yellowfive@57 915 end
yellowfive@57 916
yellowfive@57 917 else
yellowfive@57 918 local lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 919 lbl:SetFont(Amr.CreateFont("Italic", 16, Amr.Colors.TextTan))
yellowfive@57 920 lbl:SetWidth(800)
yellowfive@57 921 lbl:SetText(L.LootEmpty)
yellowfive@57 922 lbl:SetPoint("CENTER", _panelLoot.content, "CENTER")
yellowfive@57 923 _panelLoot:AddChild(lbl)
yellowfive@57 924 end
yellowfive@57 925
yellowfive@57 926 end
yellowfive@57 927
yellowfive@57 928 -- select a particular loot item to display
yellowfive@57 929 function Amr:SelectLootItem(index)
yellowfive@57 930 _selectedIndex = index
yellowfive@57 931 self:RefreshLootWindow()
yellowfive@57 932 self:RefreshLootRolls()
yellowfive@57 933 end
yellowfive@57 934
yellowfive@57 935 local function onLootFrameClose(widget)
yellowfive@57 936 AceGUI:Release(widget)
yellowfive@57 937 _frameLoot = nil
yellowfive@57 938 _panelLoot = nil
yellowfive@57 939 _rankPanels = nil
yellowfive@57 940 _lootButtons = nil
yellowfive@57 941 end
yellowfive@57 942
yellowfive@57 943 function Amr:HideLootWindow()
yellowfive@57 944 if not _frameLoot then return end
yellowfive@57 945 _frameLoot:Hide()
yellowfive@57 946 end
yellowfive@57 947
yellowfive@57 948 function Amr:ShowLootWindow()
yellowfive@57 949 if not _frameLoot then
yellowfive@57 950 _frameLoot = AceGUI:Create("AmrUiFrame")
yellowfive@57 951 _frameLoot:SetStatusTable(Amr.db.profile.lootWindow) -- window position is remembered in db
yellowfive@57 952 _frameLoot:SetCallback("OnClose", onLootFrameClose)
yellowfive@57 953 _frameLoot:SetLayout("None")
yellowfive@57 954 _frameLoot:SetWidth(900)
yellowfive@57 955 _frameLoot:SetHeight(600)
yellowfive@57 956 _frameLoot:SetBorderColor(Amr.Colors.BorderBlue)
yellowfive@57 957 _frameLoot:SetBackgroundColor(Amr.Colors.Bg)
yellowfive@57 958
yellowfive@57 959 local lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 960 lbl:SetWidth(600)
yellowfive@57 961 lbl:SetFont(Amr.CreateFont("Bold", 28, Amr.Colors.White))
yellowfive@57 962 lbl:SetText(L.LootTitle)
yellowfive@57 963 lbl:SetWordWrap(false)
yellowfive@57 964 lbl:SetJustifyH("CENTER")
yellowfive@57 965 lbl:SetPoint("TOP", _frameLoot.content, "TOP", 0, 30)
yellowfive@57 966 _frameLoot:AddChild(lbl)
yellowfive@57 967
yellowfive@57 968 lbl:SetCallback("OnMouseDown", function(widget) _frameLoot:StartMove() end)
yellowfive@57 969 lbl:SetCallback("OnMouseUp", function(widget) _frameLoot:EndMove() end)
yellowfive@57 970
yellowfive@57 971 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 972 lbl:SetWidth(_widthItemList)
yellowfive@57 973 lbl:SetFont(Amr.CreateFont("Regular", 18, Amr.Colors.TextHeaderActive))
yellowfive@57 974 lbl:SetText(L.LootHelpItems)
yellowfive@57 975 lbl:SetPoint("TOPLEFT", _frameLoot.content, "TOPLEFT", 0, -10)
yellowfive@57 976 _frameLoot:AddChild(lbl)
yellowfive@57 977
yellowfive@57 978 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 979 lbl:SetWidth(_widthItemList)
yellowfive@57 980 lbl:SetFont(Amr.CreateFont("Regular", 18, Amr.Colors.TextHeaderActive))
yellowfive@57 981 lbl:SetText(L.LootHelpRanks)
yellowfive@57 982 lbl:SetPoint("TOPLEFT", _frameLoot.content, "TOPLEFT", _widthItemList + _widthSpacing, -10)
yellowfive@57 983 _frameLoot:AddChild(lbl)
yellowfive@57 984
yellowfive@57 985 if IsMasterLooter() then
yellowfive@57 986 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 987 lbl:SetWidth(_widthItemList)
yellowfive@57 988 lbl:SetFont(Amr.CreateFont("Regular", 18, Amr.Colors.TextHeaderActive))
yellowfive@57 989 lbl:SetText(L.LootHelpMaster)
yellowfive@57 990 lbl:SetPoint("TOPLEFT", _frameLoot.content, "TOPLEFT", _widthItemList + _widthSpacing + _widthRank + _widthRankBar + _widthRollType + (_widthColPadding * 3), -10)
yellowfive@57 991 _frameLoot:AddChild(lbl)
yellowfive@57 992 end
yellowfive@57 993
yellowfive@57 994 _panelLoot = AceGUI:Create("AmrUiPanel")
yellowfive@57 995 _panelLoot:SetLayout("None")
yellowfive@57 996 _panelLoot:SetBackgroundColor(Amr.Colors.Black, 0)
yellowfive@57 997 _panelLoot:SetPoint("TOPLEFT", _frameLoot.content, "TOPLEFT", 0, -40)
yellowfive@57 998 _panelLoot:SetPoint("BOTTOMRIGHT", _frameLoot.content, "BOTTOMRIGHT", 0, 0)
yellowfive@57 999 _frameLoot:AddChild(_panelLoot)
yellowfive@57 1000 else
yellowfive@57 1001 _frameLoot:Show()
yellowfive@57 1002 end
yellowfive@57 1003
yellowfive@57 1004 _frameLoot:Raise()
yellowfive@57 1005 end
yellowfive@57 1006
yellowfive@57 1007 function Amr:OnStartLootReceived(parts)
yellowfive@57 1008 local data = {}
yellowfive@57 1009 for i = 2, #parts do
yellowfive@57 1010 table.insert(data, parts[i])
yellowfive@57 1011 end
yellowfive@57 1012 data = table.concat(data, "\n")
yellowfive@57 1013
yellowfive@57 1014 -- reset rankings to the new data sent out by person in control
yellowfive@57 1015 local rankings = Amr:ParseRankingString(data)
yellowfive@57 1016 Amr.db.global.TeamOpt.Rankings = rankings
yellowfive@57 1017
yellowfive@57 1018 -- reset disenchant state
yellowfive@57 1019 _disenchant = {}
yellowfive@57 1020
yellowfive@57 1021 -- reset roll information when loot is started
yellowfive@57 1022 local rolls = {}
yellowfive@57 1023 for i = 1, #rankings do
yellowfive@57 1024 table.insert(rolls, {})
yellowfive@57 1025 end
yellowfive@57 1026 Amr.db.char.TeamOpt.Rolls = rolls
yellowfive@57 1027
yellowfive@57 1028 -- select first item by default
yellowfive@57 1029 _selectedIndex = #rankings > 0 and 1 or nil
yellowfive@57 1030
yellowfive@57 1031 -- begin looting
yellowfive@57 1032 Amr.db.char.TeamOpt.LootInProgress = true
yellowfive@57 1033
yellowfive@57 1034 Amr:RefreshTeamUi()
yellowfive@57 1035 Amr:ShowLootWindow()
yellowfive@57 1036 Amr:RefreshLootWindow()
yellowfive@57 1037 end