yellowfive@57: local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot") yellowfive@57: local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true) yellowfive@57: local AceGUI = LibStub("AceGUI-3.0") yellowfive@57: yellowfive@57: local _frameLoot yellowfive@57: local _panelLoot yellowfive@57: local _selectedIndex yellowfive@57: local _disenchant = {} yellowfive@57: local _rankPanels yellowfive@57: local _lootButtons yellowfive@57: yellowfive@57: local _widthItemList = 220 yellowfive@57: local _widthRankList = 640 yellowfive@57: local _widthSpacing = 10 yellowfive@57: local _widthRank = 48 yellowfive@57: local _widthRankBar = 195 yellowfive@57: local _widthRollType = 45 yellowfive@57: local _widthColPadding = 8 yellowfive@57: local _widthRollExtraSpacing = 4 yellowfive@57: yellowfive@57: local _rollTypePos = { yellowfive@57: Need = 1, yellowfive@57: Off = 2, yellowfive@57: Greed = 3, yellowfive@57: Pass = 4 yellowfive@57: } yellowfive@57: yellowfive@57: -- get the index of the loot item that matches up to the specified item yellowfive@57: local function getLootIndex(itemIndex) yellowfive@57: yellowfive@57: local ranking = Amr.db.global.TeamOpt.Rankings[itemIndex] yellowfive@57: if not ranking then return nil end yellowfive@57: yellowfive@57: local itemUniqueId = Amr.GetItemUniqueId(ranking.item) yellowfive@57: for i = 1, GetNumLootItems() do yellowfive@57: --local texture, item, quantity, quality, locked = GetLootSlotInfo(i) yellowfive@57: local lootType = GetLootSlotType(i) yellowfive@57: if lootType == 1 then yellowfive@57: local link = GetLootSlotLink(i) yellowfive@57: local lootItem = Amr.ParseItemLink(link) yellowfive@57: if Amr.GetItemUniqueId(lootItem) == itemUniqueId then yellowfive@57: return i, link yellowfive@57: end yellowfive@57: end yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: local function getLootCandidateIndex(lootIndex, realm, name) yellowfive@57: -- remove spaces to ensure proper matches, and make all lower yellowfive@57: realm = string.gsub(realm, "%s+", "") yellowfive@57: realm = string.lower(realm) yellowfive@57: name = string.lower(name) yellowfive@57: yellowfive@57: local nameMatches = {} yellowfive@57: for i = 1, 40 do yellowfive@57: local candidate = GetMasterLootCandidate(lootIndex, i) yellowfive@57: if candidate then yellowfive@57: local candidateName = candidate yellowfive@57: local candidateRealm = GetRealmName() yellowfive@57: yellowfive@57: -- see if realm is in the name yellowfive@57: local splitPos = string.find(candidateName, "-") yellowfive@57: if splitPos ~= nil then yellowfive@57: candidateRealm = string.sub(candidateName, splitPos + 1) yellowfive@57: candidateName = string.sub(candidateName, 1, splitPos - 1) yellowfive@57: end yellowfive@57: yellowfive@57: -- remove spaces to ensure proper matches, and make all lower yellowfive@57: candidateRealm = string.gsub(candidateRealm, "%s+", "") yellowfive@57: candidateRealm = string.lower(candidateRealm) yellowfive@57: candidateName = string.lower(candidateName) yellowfive@57: yellowfive@57: -- if perfect match then we are done yellowfive@57: if candidateRealm == realm and candidateName == name then yellowfive@57: return i yellowfive@57: end yellowfive@57: yellowfive@57: if candidateName == name then yellowfive@57: table.insert(nameMatches, i) yellowfive@57: end yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: -- only one player with same name, must be the player of interest yellowfive@57: if #nameMatches == 1 then yellowfive@57: return nameMatches[1] yellowfive@57: end yellowfive@57: yellowfive@57: -- could not be found or ambiguous yellowfive@57: return nil yellowfive@57: end yellowfive@57: yellowfive@57: -- helper to send a message telling everyone that an item was just given out yellowfive@57: local function sendGiveLootMessage(itemLink, unitId, isDisenchant) yellowfive@57: -- some display info yellowfive@57: local cls, clsEn = UnitClass(unitId) yellowfive@57: local name = UnitName(unitId) yellowfive@57: yellowfive@57: local result = isDisenchant and "Disenchant" or (roll and roll.rollType or nil) yellowfive@57: if result == nil then result = "??" end yellowfive@57: yellowfive@57: 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: Amr:SendAmrCommMessage(msg) yellowfive@57: end yellowfive@57: yellowfive@57: local function onGiveLootClick(widget) yellowfive@57: local rollIndex = widget:GetUserData("index") yellowfive@57: yellowfive@57: local rankings = Amr.db.global.TeamOpt.Rankings yellowfive@57: local ranking = rankings[_selectedIndex] yellowfive@57: local rank = ranking and ranking.ranks[rollIndex] or nil yellowfive@57: if rank then yellowfive@57: local roll = Amr.db.char.TeamOpt.Rolls[_selectedIndex][rollIndex] yellowfive@57: local isDisenchant = not not _disenchant[_selectedIndex] yellowfive@57: yellowfive@57: local unitId = Amr:GetUnitId(rank.realm, rank.name) yellowfive@57: if unitId then yellowfive@57: -- find the item and loot candidate index yellowfive@57: local itemIndex, itemLink = getLootIndex(_selectedIndex) yellowfive@57: yellowfive@57: -- for debugging when don't actually have any loot yellowfive@57: --itemLink = Amr.CreateItemLink(ranking.item) yellowfive@57: yellowfive@57: local playerIndex = itemIndex and getLootCandidateIndex(itemIndex, rank.realm, rank.name) or nil yellowfive@57: if itemIndex and playerIndex then yellowfive@57: GiveMasterLoot(itemIndex, playerIndex) yellowfive@57: sendGiveLootMessage(itemLink, unitId, isDisenchant) yellowfive@57: return yellowfive@57: end yellowfive@57: yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: -- if we make it here, we could not give out the item for some reason yellowfive@57: Amr:Print(L.LootMasterGiveFail) yellowfive@57: end yellowfive@57: yellowfive@57: function Amr:OnLootGiveReceived(parts) yellowfive@57: if not parts or #parts < 6 then return end yellowfive@57: yellowfive@57: local rankings = Amr.db.global.TeamOpt.Rankings yellowfive@57: yellowfive@57: -- index of the item that was given, flag it to hide it from the ui now yellowfive@57: local index = tonumber(parts[2]) yellowfive@57: local ranking = rankings[index] yellowfive@57: if ranking then yellowfive@57: ranking.given = true yellowfive@57: end yellowfive@57: yellowfive@57: -- change the selected item index to the next ungiven item yellowfive@57: for i, obj in ipairs(rankings) do yellowfive@57: if not obj.given then yellowfive@57: _selectedIndex = i yellowfive@57: break yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: -- add a loot history entry yellowfive@57: local entry = { yellowfive@57: link = parts[3], yellowfive@57: result = parts[4], yellowfive@57: class = parts[5], yellowfive@57: name = parts[6] yellowfive@57: } yellowfive@57: table.insert(Amr.db.char.TeamOpt.History, entry) yellowfive@57: yellowfive@57: -- redraw any open windows yellowfive@57: Amr:RefreshTeamUi() yellowfive@57: Amr:RefreshLootWindow() yellowfive@57: Amr:RefreshLootRolls() yellowfive@57: yellowfive@57: -- if this is the master looter, check if all items have been given out yellowfive@57: if IsMasterLooter() then yellowfive@57: local allDone = true yellowfive@57: for i, ranking in ipairs(rankings) do yellowfive@57: if not ranking.given then yellowfive@57: allDone = false yellowfive@57: break yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: if allDone then yellowfive@57: -- send a message indicating that looting is done yellowfive@57: Amr:SendAmrCommMessage(Amr.LootMessagePrefixes.Finish) yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: end yellowfive@57: yellowfive@57: local function onDisenchantClick() yellowfive@57: local val = not _disenchant[_selectedIndex] yellowfive@57: _disenchant[_selectedIndex] = val yellowfive@57: yellowfive@57: Amr:RefreshLootWindow() yellowfive@57: Amr:RefreshLootRolls() yellowfive@57: end yellowfive@57: yellowfive@57: local function onRollClick() yellowfive@57: -- generate a roll for everyone on the current item yellowfive@57: local rands = {} yellowfive@57: yellowfive@57: local ranking = Amr.db.global.TeamOpt.Rankings[_selectedIndex] yellowfive@57: for i, rank in ipairs(ranking.ranks) do yellowfive@57: local r = math.random(100) yellowfive@57: rands[i] = r yellowfive@57: end yellowfive@57: yellowfive@57: -- transmit the roll data to all group members yellowfive@57: local msg = string.format("%s\n%d\n%s", Amr.LootMessagePrefixes.Rand, _selectedIndex, Amr:Serialize(rands)) yellowfive@57: Amr:SendAmrCommMessage(msg) yellowfive@57: end yellowfive@57: yellowfive@57: function Amr:OnLootRandReceived(parts) yellowfive@57: if not parts or #parts < 3 then return end yellowfive@57: yellowfive@57: local index = tonumber(parts[2]) yellowfive@57: local success, rands = Amr:Deserialize(parts[3]) yellowfive@57: if not index or not success then return end yellowfive@57: yellowfive@57: local rolls = Amr.db.char.TeamOpt.Rolls[index] yellowfive@57: for i, r in pairs(rands) do yellowfive@57: local roll = rolls[i] yellowfive@57: if not roll then yellowfive@57: roll = {} yellowfive@57: rolls[i] = roll yellowfive@57: end yellowfive@57: yellowfive@57: roll.rand = r yellowfive@57: end yellowfive@57: yellowfive@57: Amr:RefreshLootRolls() yellowfive@57: end yellowfive@57: yellowfive@57: local function onVetoClick(widget) yellowfive@57: local rollIndex = widget:GetUserData("rollIndex") yellowfive@57: local rollType = widget:GetUserData("rollType") yellowfive@57: yellowfive@57: -- acts like a toggle yellowfive@57: local roll = Amr.db.char.TeamOpt.Rolls[_selectedIndex][rollIndex] yellowfive@57: local veto = not roll or not roll.vetoes or not roll.vetoes[rollType] yellowfive@57: yellowfive@57: -- send a message that a veto has been changed yellowfive@57: 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: Amr:SendAmrCommMessage(msg) yellowfive@57: end yellowfive@57: yellowfive@57: function Amr:OnLootVetoReceived(parts) yellowfive@57: if not parts or #parts < 5 then return end yellowfive@57: yellowfive@57: local itemIndex = tonumber(parts[2]) yellowfive@57: local rollIndex = tonumber(parts[3]) yellowfive@57: local rollType = parts[4] yellowfive@57: local veto = parts[5] == "t" yellowfive@57: yellowfive@57: if itemIndex and rollIndex then yellowfive@57: local roll = Amr.db.char.TeamOpt.Rolls[itemIndex][rollIndex] yellowfive@57: if not roll then yellowfive@57: roll = {} yellowfive@57: Amr.db.char.TeamOpt.Rolls[itemIndex][rollIndex] = roll yellowfive@57: end yellowfive@57: yellowfive@57: if not roll.vetoes then yellowfive@57: roll.vetoes = {} yellowfive@57: end yellowfive@57: yellowfive@57: roll.vetoes[rollType] = veto yellowfive@57: yellowfive@57: -- if the player chose this option, have to remove it because it has been vetoed yellowfive@57: if veto and roll.rollType == rollType then yellowfive@57: roll.rollType = nil yellowfive@57: end yellowfive@57: yellowfive@57: Amr:RefreshLootRolls() yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: -- a user choice for what they want to do on an item yellowfive@57: local function doRoll(rollType) yellowfive@57: yellowfive@57: local msg = string.format("%s\n%d\n%s\n%s\n%s", Amr.LootMessagePrefixes.Roll, _selectedIndex, rollType, GetRealmName(), UnitName("player")) yellowfive@57: Amr:SendAmrCommMessage(msg) yellowfive@57: end yellowfive@57: yellowfive@57: function Amr:OnLootRollReceived(parts) yellowfive@57: local index = tonumber(parts[2]) yellowfive@57: local rollType = parts[3] yellowfive@57: local realm = parts[4] yellowfive@57: local name = parts[5] yellowfive@57: yellowfive@57: -- for now, this code matches up name/realm to one in the rankings yellowfive@57: -- TODO: more robust handling of players with same name but different realms in the same group on non-english clients yellowfive@57: local nameMatches = {} yellowfive@57: local ranking = Amr.db.global.TeamOpt.Rankings[index] yellowfive@57: for i, rank in ipairs(ranking.ranks) do yellowfive@57: if name == rank.name and realm == rank.realm then yellowfive@57: nameMatches = {} yellowfive@57: break yellowfive@57: end yellowfive@57: yellowfive@57: if name == rank.name then yellowfive@57: table.insert(nameMatches, rank) yellowfive@57: end yellowfive@57: end yellowfive@57: if #nameMatches == 1 then yellowfive@57: realm = nameMatches[1].realm yellowfive@57: name = nameMatches[1].name yellowfive@57: end yellowfive@57: yellowfive@57: -- find index of the ranking yellowfive@57: local rankIndex = nil yellowfive@57: for i, rank in ipairs(ranking.ranks) do yellowfive@57: if name == rank.name and realm == rank.realm then yellowfive@57: rankIndex = i yellowfive@57: break yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: if rankIndex then yellowfive@57: local obj = Amr.db.char.TeamOpt.Rolls[index][rankIndex] yellowfive@57: if not obj then yellowfive@57: obj = {} yellowfive@57: Amr.db.char.TeamOpt.Rolls[index][rankIndex] = obj yellowfive@57: end yellowfive@57: obj.rollType = rollType yellowfive@57: end yellowfive@57: yellowfive@57: Amr:RefreshLootRolls() yellowfive@57: end yellowfive@57: yellowfive@57: local function renderRollType(rp, rollType, roll, index) yellowfive@57: yellowfive@57: local icon = rp:GetUserData(rollType) yellowfive@57: if not icon and roll then yellowfive@57: -- create icon if we need one yellowfive@57: icon = AceGUI:Create("AmrUiTextButton") yellowfive@57: icon:SetWidth(16) yellowfive@57: icon:SetHeight(16) yellowfive@57: local pos = _rollTypePos[rollType] yellowfive@57: local left = _widthRank + _widthColPadding + _widthRankBar + (pos * _widthColPadding) + ((pos - 1) * _widthRollType) + ((_widthRollType - 16) / 2) yellowfive@57: icon:SetPoint("LEFT", rp.content, "LEFT", left, 0) yellowfive@57: rp:AddChild(icon) yellowfive@57: rp:SetUserData(rollType, icon) yellowfive@57: yellowfive@57: icon:SetUserData("rollType", rollType) yellowfive@57: icon:SetUserData("rollIndex", index) yellowfive@57: icon:SetVisible(false) yellowfive@57: yellowfive@57: icon:SetCallback("OnClick", onVetoClick) yellowfive@57: end yellowfive@57: yellowfive@57: if icon then yellowfive@57: if roll and roll.rollType == rollType then yellowfive@57: icon:SetVisible(true) yellowfive@57: icon:SetBackgroundImage("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\IconCheck") yellowfive@57: icon:SetHoverBackgroundImage("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\IconCheck") yellowfive@57: elseif roll and roll.vetoes and roll.vetoes[rollType] then yellowfive@57: icon:SetVisible(true) yellowfive@57: icon:SetBackgroundImage("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\IconX") yellowfive@57: icon:SetHoverBackgroundImage("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\IconX") yellowfive@57: else yellowfive@57: icon:SetVisible(false) yellowfive@57: end yellowfive@57: yellowfive@57: icon:SetDisabled(not IsMasterLooter()) yellowfive@57: end yellowfive@57: yellowfive@57: -- update button state for this roll type yellowfive@57: if _lootButtons and _lootButtons[rollType] then yellowfive@57: _lootButtons[rollType]:SetDisabled(roll and roll.vetoes and roll.vetoes[rollType]) yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: -- 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: local function getWinner(itemIndex) yellowfive@57: yellowfive@57: local rolls = Amr.db.char.TeamOpt.Rolls[itemIndex] yellowfive@57: if not rolls then return -1 end yellowfive@57: yellowfive@57: -- go through and find the highest priority roll type yellowfive@57: local bestRollType yellowfive@57: local bestTypePos = 100 yellowfive@57: for i, roll in pairs(rolls) do yellowfive@57: if roll.rollType then yellowfive@57: local rollPos = _rollTypePos[roll.rollType] yellowfive@57: if rollPos < bestTypePos and rollPos < _rollTypePos["Pass"] then yellowfive@57: bestRollType = roll.rollType yellowfive@57: bestTypePos = rollPos yellowfive@57: end yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: -- nobody has chosen anything yet yellowfive@57: if not bestRollType then return -1 end yellowfive@57: yellowfive@57: -- find highest roll in the highest priority roll type yellowfive@57: local maxRoll = -1 yellowfive@57: local bestRoll = -1 yellowfive@57: for i, roll in pairs(rolls) do yellowfive@57: if roll.rollType == bestRollType and roll.rand and roll.rand > maxRoll then yellowfive@57: bestRoll = i yellowfive@57: maxRoll = roll.rand yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: return bestRoll yellowfive@57: end yellowfive@57: yellowfive@57: function Amr:RefreshLootRolls() yellowfive@57: if not _rankPanels then return end yellowfive@57: yellowfive@57: local ranking = Amr.db.global.TeamOpt.Rankings[_selectedIndex] yellowfive@57: local rolls = Amr.db.char.TeamOpt.Rolls[_selectedIndex] yellowfive@57: local isDisenchant = _disenchant[_selectedIndex] yellowfive@57: yellowfive@57: local winnerIndex = getWinner(_selectedIndex) yellowfive@57: yellowfive@57: for i, rp in pairs(_rankPanels) do yellowfive@57: local rank = ranking.ranks[i] yellowfive@57: local roll = rolls[i] yellowfive@57: if isDisenchant then roll = nil end yellowfive@57: yellowfive@57: -- clear or set the value of each roll column yellowfive@57: renderRollType(rp, "Need", roll, i) yellowfive@57: renderRollType(rp, "Off", roll, i) yellowfive@57: renderRollType(rp, "Greed", roll, i) yellowfive@57: renderRollType(rp, "Pass", roll, i) yellowfive@57: yellowfive@57: -- render the random roll yellowfive@57: local lbl = rp:GetUserData("randLabel") yellowfive@57: if roll and roll.rand then yellowfive@57: if not lbl then yellowfive@57: lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetJustifyH("RIGHT") yellowfive@57: yellowfive@57: local left = _widthRank + _widthColPadding + _widthRankBar + (5 * _widthColPadding) + (5 * _widthRollType) yellowfive@57: lbl:SetPoint("RIGHT", rp.content, "LEFT", left, 0) yellowfive@57: rp:AddChild(lbl) yellowfive@57: rp:SetUserData("randLabel", lbl) yellowfive@57: end yellowfive@57: yellowfive@57: -- highlight this roll if winner, otherwise unhighlight yellowfive@57: if i == winnerIndex then yellowfive@57: lbl:SetFont(Amr.CreateFont("Bold", 18, Amr.Colors.BrightGreen)) yellowfive@57: else yellowfive@57: lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White)) yellowfive@57: end yellowfive@57: yellowfive@57: lbl:SetText(roll.rand) yellowfive@57: else yellowfive@57: if lbl then yellowfive@57: lbl:SetVisible(false) yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: -- if this person does not have the addon, show a message (except in DE mode) yellowfive@57: local hasAddon = true yellowfive@57: local unitId = Amr:GetUnitId(rank.realm, rank.name) yellowfive@57: if unitId then yellowfive@57: local realm, name = Amr:GetRealmAndName(unitId) yellowfive@57: if realm then yellowfive@57: local ver = Amr:GetAddonVersion(realm, name) yellowfive@57: hasAddon = ver >= Amr.MIN_ADDON_VERSION yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: lbl = rp:GetUserData("noaddonLabel") yellowfive@57: if not hasAddon and not isDisenchant then yellowfive@57: if not lbl then yellowfive@57: lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetFont(Amr.CreateFont("Italic", 14, Amr.Colors.Red)) yellowfive@57: lbl:SetText(L.LootRankLabelNoAddon) yellowfive@57: lbl:SetPoint("LEFT", rp.content, "LEFT", _widthRank + _widthColPadding + _widthRankBar + _widthColPadding + 5, 0) yellowfive@57: rp:AddChild(lbl) yellowfive@57: rp:SetUserData("noaddonLabel", lbl) yellowfive@57: end yellowfive@57: else yellowfive@57: if lbl then yellowfive@57: lbl:SetVisible(false) yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: -- helper to create the column bg and header for rank list yellowfive@57: local function createLootRankColumn(container, prevColumn, width, txt, txtAlign, extraPadding) yellowfive@57: extraPadding = extraPadding and extraPadding or 0 yellowfive@57: yellowfive@57: local panel = AceGUI:Create("AmrUiPanel") yellowfive@57: panel:SetBackgroundColor(Amr.Colors.Black, 0.3) yellowfive@57: container:AddChild(panel) yellowfive@57: yellowfive@57: if prevColumn then yellowfive@57: -- pad a bit to right of previous column yellowfive@57: panel:SetPoint("TOPLEFT", prevColumn.content, "TOPRIGHT", _widthColPadding + extraPadding, 0) yellowfive@57: panel:SetPoint("BOTTOMRIGHT", prevColumn.content, "BOTTOMRIGHT", _widthColPadding + extraPadding + width, 0) yellowfive@57: else yellowfive@57: -- first column abs position in the main ranking panel yellowfive@57: panel:SetPoint("TOPLEFT", container.content, "TOPLEFT", _widthItemList + _widthSpacing, -115) yellowfive@57: panel:SetPoint("BOTTOMRIGHT", container.content, "BOTTOMLEFT", _widthItemList + _widthSpacing + width, 0) yellowfive@57: end yellowfive@57: yellowfive@57: lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetWordWrap(false) yellowfive@57: lbl:SetFont(Amr.CreateFont("Regular", 12, Amr.Colors.TextHeaderDisabled)) yellowfive@57: lbl:SetText(txt) yellowfive@57: lbl:SetJustifyH(txtAlign) yellowfive@57: lbl:SetWidth(width) yellowfive@57: lbl:SetPoint("BOTTOMLEFT", panel.content, "TOPLEFT", 0, 5) yellowfive@57: container:AddChild(lbl) yellowfive@57: yellowfive@57: return panel, lbl yellowfive@57: end yellowfive@57: yellowfive@57: function Amr:RefreshLootWindow() yellowfive@57: if not _panelLoot then return end yellowfive@57: yellowfive@57: -- clear out any children of the main loot frame and re-render yellowfive@57: _panelLoot:ReleaseChildren() yellowfive@57: _rankPanels = {} yellowfive@57: _lootButtons = {} yellowfive@57: yellowfive@57: local ml = IsMasterLooter() yellowfive@57: local myUnitId = Amr:GetUnitId(GetRealmName(), UnitName("player")) yellowfive@57: yellowfive@57: local rankings = Amr.db.global.TeamOpt.Rankings yellowfive@57: if rankings and #rankings > 0 then yellowfive@57: yellowfive@57: -- make sure that an item is selected yellowfive@57: if not _selectedIndex then yellowfive@57: for i, ranking in ipairs(rankings) do yellowfive@57: if not ranking.given then yellowfive@57: _selectedIndex = i yellowfive@57: break yellowfive@57: end yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: -- render list of items yellowfive@57: local panelItems = AceGUI:Create("AmrUiPanel") yellowfive@57: panelItems:SetLayout("Fill") yellowfive@57: panelItems:SetWidth(_widthItemList) yellowfive@57: panelItems:SetBackgroundColor(Amr.Colors.Black, 0) yellowfive@57: panelItems:SetPoint("TOPLEFT", _panelLoot.content, "TOPLEFT", 0, 0) yellowfive@57: panelItems:SetPoint("BOTTOMLEFT", _panelLoot.content, "BOTTOMLEFT") yellowfive@57: _panelLoot:AddChild(panelItems) yellowfive@57: yellowfive@57: local scrollItems = AceGUI:Create("AmrUiScrollFrame") yellowfive@57: scrollItems:SetLayout("List") yellowfive@57: panelItems:AddChild(scrollItems) yellowfive@57: yellowfive@57: -- render the divider between items and ranks yellowfive@57: local divider = AceGUI:Create("AmrUiPanel") yellowfive@57: divider:SetBackgroundColor(Amr.Colors.Black, 0.5) yellowfive@57: divider:SetPoint("TOPLEFT", _panelLoot.content, "TOPLEFT", _widthItemList, 0) yellowfive@57: divider:SetPoint("BOTTOMRIGHT", _panelLoot.content, "BOTTOMLEFT", _widthItemList + 5, 0) yellowfive@57: _panelLoot:AddChild(divider) yellowfive@57: yellowfive@57: local btn, btn2, lbl, lbl2, panel, panel2, chk yellowfive@57: yellowfive@57: local remainingItems = {} yellowfive@57: for i, ranking in ipairs(rankings) do yellowfive@57: if not ranking.given then yellowfive@57: remainingItems[i] = ranking yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: for i, ranking in pairs(remainingItems) do yellowfive@57: btn = AceGUI:Create("AmrUiTextButton") yellowfive@57: btn:SetWidth(_widthItemList) yellowfive@57: btn:SetHeight(50) yellowfive@57: btn:SetJustifyH("LEFT") yellowfive@57: btn:SetJustifyV("TOP") yellowfive@57: btn:SetTextPadding(9, nil, nil, 2) yellowfive@57: btn:SetWordWrap(false) yellowfive@57: btn:SetUserData("index", i) yellowfive@57: yellowfive@57: local f yellowfive@57: if _selectedIndex == i then yellowfive@57: f = Amr.CreateFont("Bold", 16, Amr.Colors.Text) yellowfive@57: btn:SetBackgroundColor(Amr.Colors.Black, 0.5) yellowfive@57: btn:SetHoverBackgroundColor(Amr.Colors.Black, 0.5) yellowfive@57: else yellowfive@57: f = Amr.CreateFont("Regular", 14, Amr.Colors.Text) yellowfive@57: btn:SetHoverBackgroundColor(Amr.Colors.Black, 0.2) yellowfive@57: end yellowfive@57: yellowfive@57: btn:SetFont(f) yellowfive@57: btn:SetHoverFont(f) yellowfive@57: yellowfive@57: scrollItems:AddChild(btn) yellowfive@57: yellowfive@57: btn:SetCallback("OnClick", function(widget) yellowfive@57: Amr:SelectLootItem(widget:GetUserData("index")) yellowfive@57: end) yellowfive@57: yellowfive@57: local rankLink = Amr.CreateItemLink(ranking.item) yellowfive@57: Amr.GetItemInfo(rankLink, function(obj, name, link) yellowfive@57: -- set item name, tooltip yellowfive@57: obj:SetText(" " .. link:gsub("%[", ""):gsub("%]", "")) yellowfive@57: Amr:SetItemTooltip(obj, link, "ANCHOR_BOTTOMLEFT", 0, obj.frame:GetHeight()) yellowfive@57: end, btn) yellowfive@57: yellowfive@57: -- add a label for slot, armor type yellowfive@57: local slotText = Amr.SlotEnumDisplayText[ranking.itemInfo.slot] yellowfive@57: if ranking.itemInfo.slot == 'MainHand' then yellowfive@57: slotText = ranking.itemInfo.subclass == 'TwoHand' and L.TwoHand or L.OneHand yellowfive@57: elseif ranking.itemInfo.slot == 'OffHand' then yellowfive@57: slotText = L.OffHand yellowfive@57: end yellowfive@57: yellowfive@57: if ranking.itemInfo.armorType == 'None' and ranking.itemInfo.weaponType ~= 'None' then yellowfive@57: if ranking.itemInfo.weaponType ~= 'OffHand' then yellowfive@57: slotText = slotText .. ", " .. L.WeaponTypes[ranking.itemInfo.weaponType] yellowfive@57: end yellowfive@57: elseif ranking.itemInfo.armorType ~= 'None' then yellowfive@57: slotText = slotText .. ", " .. L.ArmorTypes[ranking.itemInfo.armorType] yellowfive@57: end yellowfive@57: yellowfive@57: btn:SetSubtextFont(Amr.CreateFont("Regular", 13, Amr.Colors.TextGray)) yellowfive@57: btn:SetSubtextJustifyH("LEFT") yellowfive@57: btn:SetSubtextJustifyV("BOTTOM") yellowfive@57: btn:SetSubtextPadding(nil, nil, 9, 7) yellowfive@57: btn:SetSubtextWordWrap(false) yellowfive@57: btn:SetSubtext(slotText) yellowfive@57: yellowfive@57: yellowfive@57: local isDisenchant = not not _disenchant[i] yellowfive@57: yellowfive@57: if _selectedIndex == i then yellowfive@57: yellowfive@57: -- see if I am in the list yellowfive@57: local canLoot = false yellowfive@57: for j, rank in ipairs(ranking.ranks) do yellowfive@57: local unitId = Amr:GetUnitId(rank.realm, rank.name) yellowfive@57: if unitId == myUnitId then yellowfive@57: canLoot = not rank.notRanked or rank.offspec yellowfive@57: break yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: -- render loot options yellowfive@57: if canLoot then yellowfive@57: btn = AceGUI:Create("AmrUiButton") yellowfive@57: btn:SetWidth(120) yellowfive@57: btn:SetHeight(26) yellowfive@57: btn:SetFont(Amr.CreateFont("Bold", 15, Amr.Colors.White)) yellowfive@57: btn:SetBackgroundColor(Amr.Colors.Green) yellowfive@57: btn:SetText(L.TeamLootOptionNeed) yellowfive@57: btn:SetPoint("TOPLEFT", _panelLoot.content, "TOPLEFT", _widthItemList + _widthSpacing, -7) yellowfive@57: btn:SetCallback("OnClick", function(widget) doRoll("Need") end) yellowfive@57: _panelLoot:AddChild(btn) yellowfive@57: _lootButtons["Need"] = btn yellowfive@57: yellowfive@57: btn2 = AceGUI:Create("AmrUiButton") yellowfive@57: btn2:SetWidth(120) yellowfive@57: btn2:SetHeight(26) yellowfive@57: btn2:SetFont(Amr.CreateFont("Bold", 15, Amr.Colors.White)) yellowfive@57: btn2:SetBackgroundColor(Amr.Colors.Orange) yellowfive@57: btn2:SetText(L.TeamLootOptionPass) yellowfive@57: btn2:SetPoint("TOPLEFT", btn.frame, "BOTTOMLEFT", 0, -15) yellowfive@57: btn2:SetCallback("OnClick", function(widget) doRoll("Pass") end) yellowfive@57: _panelLoot:AddChild(btn2) yellowfive@57: _lootButtons["Pass"] = btn2 yellowfive@57: yellowfive@57: btn = AceGUI:Create("AmrUiButton") yellowfive@57: btn:SetWidth(120) yellowfive@57: btn:SetHeight(26) yellowfive@57: btn:SetFont(Amr.CreateFont("Bold", 15, Amr.Colors.White)) yellowfive@57: btn:SetBackgroundColor(Amr.Colors.Blue) yellowfive@57: btn:SetText(L.TeamLootOptionOff) yellowfive@57: btn:SetPoint("BOTTOMLEFT", btn2.frame, "TOPRIGHT", 15, 15) yellowfive@57: btn:SetCallback("OnClick", function(widget) doRoll("Off") end) yellowfive@57: _panelLoot:AddChild(btn) yellowfive@57: _lootButtons["Off"] = btn yellowfive@57: yellowfive@57: btn2 = AceGUI:Create("AmrUiButton") yellowfive@57: btn2:SetWidth(120) yellowfive@57: btn2:SetHeight(26) yellowfive@57: btn2:SetFont(Amr.CreateFont("Bold", 15, Amr.Colors.White)) yellowfive@57: btn2:SetBackgroundColor(Amr.Colors.Blue) yellowfive@57: btn2:SetText(L.TeamLootOptionGreed) yellowfive@57: btn2:SetPoint("TOPLEFT", btn.frame, "BOTTOMLEFT", 0, -15) yellowfive@57: btn2:SetCallback("OnClick", function(widget) doRoll("Greed") end) yellowfive@57: _panelLoot:AddChild(btn2) yellowfive@57: _lootButtons["Greed"] = btn2 yellowfive@57: else yellowfive@57: lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetFont(Amr.CreateFont("Italic", 14, Amr.Colors.TextTan)) yellowfive@57: lbl:SetText(L.LootIneligible) yellowfive@57: lbl:SetWidth(255) yellowfive@57: lbl:SetPoint("TOPLEFT", _panelLoot.content, "TOPLEFT", _widthItemList + _widthSpacing, -7) yellowfive@57: _panelLoot:AddChild(lbl) yellowfive@57: end yellowfive@57: yellowfive@57: -- master loot options yellowfive@57: if ml then yellowfive@57: chk = AceGUI:Create("AmrUiCheckBox") yellowfive@57: chk:SetText(L.LootMasterDisenchantText) yellowfive@57: chk:SetPoint("TOPRIGHT", _panelLoot.content, "TOPRIGHT", -18, -12) yellowfive@57: chk:SetCallback("OnClick", onDisenchantClick) yellowfive@57: chk:SetChecked(_disenchant[i]) yellowfive@57: _panelLoot:AddChild(chk) yellowfive@57: yellowfive@57: lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetWidth(120) yellowfive@57: lbl:SetJustifyH("CENTER") yellowfive@57: lbl:SetText(L.LootMasterDisenchantLabel) yellowfive@57: lbl:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.TextTan)) yellowfive@57: lbl:SetPoint("TOP", chk.frame, "BOTTOM", 0, -5) yellowfive@57: _panelLoot:AddChild(lbl) yellowfive@57: yellowfive@57: btn2 = AceGUI:Create("AmrUiButton") yellowfive@57: btn2:SetWidth(120) yellowfive@57: btn2:SetHeight(26) yellowfive@57: btn2:SetFont(Amr.CreateFont("Bold", 15, Amr.Colors.White)) yellowfive@57: btn2:SetBackgroundColor(Amr.Colors.Green) yellowfive@57: btn2:SetText(L.LootMasterRollText) yellowfive@57: btn2:SetPoint("RIGHT", chk.frame, "LEFT", -50, 0) yellowfive@57: btn2:SetCallback("OnClick", onRollClick) yellowfive@57: _panelLoot:AddChild(btn2) yellowfive@57: yellowfive@57: lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetWidth(120) yellowfive@57: lbl:SetJustifyH("CENTER") yellowfive@57: lbl:SetText(L.LootMasterRollLabel) yellowfive@57: lbl:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.TextTan)) yellowfive@57: lbl:SetPoint("TOP", btn2.frame, "BOTTOM", 0, -5) yellowfive@57: _panelLoot:AddChild(lbl) yellowfive@57: yellowfive@57: end yellowfive@57: yellowfive@57: -- backgrounds for the rank list and headers yellowfive@57: panel = createLootRankColumn(_panelLoot, nil, _widthRank, isDisenchant and "" or L.LootRankHeaderRank, "RIGHT") yellowfive@57: panel = createLootRankColumn(_panelLoot, panel, _widthRankBar, isDisenchant and L.LootRankHeaderScoreDisenchant or L.LootRankHeaderScore, "LEFT") yellowfive@57: yellowfive@57: if not isDisenchant then yellowfive@57: panel = createLootRankColumn(_panelLoot, panel, _widthRollType, L.LootRankHeaderNeed, "CENTER") yellowfive@57: panel = createLootRankColumn(_panelLoot, panel, _widthRollType, L.LootRankHeaderOff, "CENTER") yellowfive@57: panel = createLootRankColumn(_panelLoot, panel, _widthRollType, L.LootRankHeaderGreed, "CENTER") yellowfive@57: panel = createLootRankColumn(_panelLoot, panel, _widthRollType, L.LootRankHeaderPass, "CENTER") yellowfive@57: panel = createLootRankColumn(_panelLoot, panel, _widthRollType, L.LootRankHeaderRoll, "RIGHT", _widthRollExtraSpacing) yellowfive@57: end yellowfive@57: yellowfive@57: -- rank list for selected item yellowfive@57: panel = AceGUI:Create("AmrUiPanel") yellowfive@57: panel:SetLayout("Fill") yellowfive@57: panel:SetBackgroundColor(Amr.Colors.Black, 0) yellowfive@57: panel:SetPoint("TOPLEFT", _panelLoot.content, "TOPLEFT", _widthItemList + _widthSpacing, -115) yellowfive@57: panel:SetPoint("BOTTOMRIGHT", _panelLoot.content, "BOTTOMRIGHT") yellowfive@57: _panelLoot:AddChild(panel) yellowfive@57: yellowfive@57: local scrollRanks = AceGUI:Create("AmrUiScrollFrame") yellowfive@57: scrollRanks:SetLayout("List") yellowfive@57: panel:AddChild(scrollRanks) yellowfive@57: yellowfive@57: -- find min and max value, used for sizing the bars yellowfive@57: local rankMin = -0.02 yellowfive@57: local rankMax = 0.02 yellowfive@57: for j, rank in ipairs(ranking.ranks) do yellowfive@57: if rank.score < rankMin then yellowfive@57: rankMin = rank.score yellowfive@57: end yellowfive@57: if rank.score > rankMax then yellowfive@57: rankMax = rank.score yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: -- 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: if rankMin == rankMax then yellowfive@57: rankMin = rankMax - 1 yellowfive@57: end yellowfive@57: yellowfive@57: local minWidth = 10 yellowfive@57: local maxWidth = _widthRankBar - 36 - 65 - 2 -- reserve 36 for icon, 65 for bar label, and 2 for a border around the bar yellowfive@57: local rankCount = 0 yellowfive@57: yellowfive@57: for j, rank in ipairs(ranking.ranks) do yellowfive@57: local unitId = Amr:GetUnitId(rank.realm, rank.name) yellowfive@57: if unitId then yellowfive@57: local skip = false yellowfive@57: if isDisenchant then yellowfive@57: skip = true yellowfive@57: if rank.isMasterLooter or (rank.enchantingSkill and rank.enchantingSkill > 0) then yellowfive@57: skip = false yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: if not skip then yellowfive@57: rankCount = rankCount + 1 yellowfive@57: yellowfive@57: local rp = AceGUI:Create("AmrUiPanel") yellowfive@57: rp:SetLayout("None") yellowfive@57: rp:SetBackgroundColor(Amr.Colors.Black, 0) yellowfive@57: rp:SetWidth(_widthRankList) yellowfive@57: rp:SetHeight(45) yellowfive@57: scrollRanks:AddChild(rp) yellowfive@57: _rankPanels[j] = rp yellowfive@57: yellowfive@57: if not isDisenchant then yellowfive@57: panel = AceGUI:Create("AmrUiPanel") yellowfive@57: panel:SetBackgroundColor(Amr.Colors.Black, 1) yellowfive@57: panel:SetPoint("TOPLEFT", rp.content, "BOTTOMLEFT", 0, 0) yellowfive@57: panel:SetPoint("BOTTOMRIGHT", rp.content, "BOTTOMRIGHT", -120, -1) yellowfive@57: rp:AddChild(panel) yellowfive@57: end yellowfive@57: yellowfive@57: lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetFont(Amr.CreateFont("Bold", 32, Amr.Colors.White)) yellowfive@57: lbl:SetText(rankCount) yellowfive@57: lbl:SetWidth(_widthRank - 6) yellowfive@57: lbl:SetJustifyH("RIGHT") yellowfive@57: lbl:SetPoint("BOTTOMLEFT", rp.content, "BOTTOMLEFT", 0, 3) yellowfive@57: rp:AddChild(lbl) yellowfive@57: yellowfive@57: local cls, clsEn = UnitClass(unitId) yellowfive@57: local color = clsEn and Amr.Colors.Classes[clsEn] or Amr.Colors.TextHeaderDisabled yellowfive@57: yellowfive@57: local icon = AceGUI:Create("AmrUiIcon") yellowfive@57: icon:SetIconBorderColor(color) yellowfive@57: icon:SetWidth(36) yellowfive@57: icon:SetHeight(36) yellowfive@57: icon:SetIcon("Interface\\Icons\\" .. Amr.SpecIcons[rank.specId]) yellowfive@57: icon:SetPoint("BOTTOMLEFT", rp.content, "BOTTOMLEFT", 48 + 8, 0) yellowfive@57: rp:AddChild(icon) yellowfive@57: yellowfive@57: lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetFont(Amr.CreateFont("Bold", 16, color)) yellowfive@57: lbl:SetText(UnitName(unitId)) yellowfive@57: lbl:SetWidth(_widthRankBar - 36 - 8) -- 4px on left and right side yellowfive@57: lbl:SetPoint("TOPLEFT", icon.frame, "TOPRIGHT", 4, -2) yellowfive@57: rp:AddChild(lbl) yellowfive@57: yellowfive@57: if isDisenchant or rank.notRanked then yellowfive@57: lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetFont(Amr.CreateFont("Italic", 13, Amr.Colors.TextHeaderDisabled)) yellowfive@57: lbl:SetWidth(_widthRankBar - 36 - 4) -- 4px on left side yellowfive@57: lbl:SetWordWrap(false) yellowfive@57: lbl:SetPoint("BOTTOMLEFT", icon.frame, "BOTTOMRIGHT", 4, 2) yellowfive@57: rp:AddChild(lbl) yellowfive@57: yellowfive@57: if isDisenchant then yellowfive@57: -- will be disenchanter or ML if we are DEing the item yellowfive@57: lbl:SetText((rank.enchantingSkill and rank.enchantingSkill > 0) and string.format(L.LootRankLabelDisenchant .. " (%d)", rank.enchantingSkill) or L.LootRankLabelMasterLooter) yellowfive@57: else yellowfive@57: -- if this is off spec or just a disenchanter, no score bar just description text yellowfive@57: 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: end yellowfive@57: else yellowfive@57: local scoreText = rank.score .. "%" yellowfive@57: local val = rank.score; yellowfive@57: if rank.isEquipped then yellowfive@57: scoreText = "E" yellowfive@57: val = 0 yellowfive@57: elseif val >= 0 then yellowfive@57: scoreText = "+" .. scoreText yellowfive@57: end yellowfive@57: yellowfive@57: local per = (val - rankMin) / (rankMax - rankMin); yellowfive@57: local w = minWidth + (per * (maxWidth - minWidth)); yellowfive@57: color = val > 0 and Amr.Colors.BarHigh or (val == 0 and Amr.Colors.BarMed or Amr.Colors.BarLow) yellowfive@57: yellowfive@57: panel = AceGUI:Create("AmrUiPanel") yellowfive@57: panel:SetLayout("None") yellowfive@57: panel:SetWidth(w + 2) yellowfive@57: panel:SetHeight(16) yellowfive@57: panel:SetBackgroundColor(Amr.Colors.Black, 1) yellowfive@57: panel:SetPoint("BOTTOMLEFT", icon.frame, "BOTTOMRIGHT", 0, -1) yellowfive@57: rp:AddChild(panel) yellowfive@57: yellowfive@57: panel2 = AceGUI:Create("AmrUiPanel") yellowfive@57: panel2:SetLayout("None") yellowfive@57: panel2:SetWidth(w) yellowfive@57: panel2:SetHeight(14) yellowfive@57: panel2:SetBackgroundColor(color, 1) yellowfive@57: panel2:SetPoint("TOPLEFT", panel.content, "TOPLEFT", 1, -1) yellowfive@57: panel:AddChild(panel2) yellowfive@57: yellowfive@57: lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetFont(Amr.CreateFont("Bold", 13, color)) yellowfive@57: lbl:SetText(scoreText) yellowfive@57: lbl:SetWidth(63) yellowfive@57: lbl:SetWordWrap(false) yellowfive@57: lbl:SetPoint("LEFT", panel.content, "RIGHT", 2, 0) yellowfive@57: rp:AddChild(lbl) yellowfive@57: end yellowfive@57: yellowfive@57: if ml then yellowfive@57: btn2 = AceGUI:Create("AmrUiButton") yellowfive@57: btn2:SetHeight(24) yellowfive@57: btn2:SetFont(Amr.CreateFont("Regular", 13, Amr.Colors.White)) yellowfive@57: btn2:SetBackgroundColor(Amr.Colors.Green) yellowfive@57: yellowfive@57: if isDisenchant then yellowfive@57: btn2:SetWidth(200) yellowfive@57: btn2:SetText(L.LootMasterGiveDisenchant) yellowfive@57: btn2:SetPoint("LEFT", rp.content, "LEFT", _widthRank + _widthRankBar + (3 * _widthColPadding), 0) yellowfive@57: else yellowfive@57: btn2:SetWidth(85) yellowfive@57: btn2:SetText(L.LootMasterGiveLoot) yellowfive@57: btn2:SetPoint("RIGHT", rp.content, "RIGHT", -30, 0) yellowfive@57: end yellowfive@57: yellowfive@57: btn2:SetUserData("index", j) yellowfive@57: btn2:SetCallback("OnClick", onGiveLootClick) yellowfive@57: rp:AddChild(btn2) yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: end yellowfive@57: yellowfive@57: end yellowfive@57: yellowfive@57: else yellowfive@57: local lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetFont(Amr.CreateFont("Italic", 16, Amr.Colors.TextTan)) yellowfive@57: lbl:SetWidth(800) yellowfive@57: lbl:SetText(L.LootEmpty) yellowfive@57: lbl:SetPoint("CENTER", _panelLoot.content, "CENTER") yellowfive@57: _panelLoot:AddChild(lbl) yellowfive@57: end yellowfive@57: yellowfive@57: end yellowfive@57: yellowfive@57: -- select a particular loot item to display yellowfive@57: function Amr:SelectLootItem(index) yellowfive@57: _selectedIndex = index yellowfive@57: self:RefreshLootWindow() yellowfive@57: self:RefreshLootRolls() yellowfive@57: end yellowfive@57: yellowfive@57: local function onLootFrameClose(widget) yellowfive@57: AceGUI:Release(widget) yellowfive@57: _frameLoot = nil yellowfive@57: _panelLoot = nil yellowfive@57: _rankPanels = nil yellowfive@57: _lootButtons = nil yellowfive@57: end yellowfive@57: yellowfive@57: function Amr:HideLootWindow() yellowfive@57: if not _frameLoot then return end yellowfive@57: _frameLoot:Hide() yellowfive@57: end yellowfive@57: yellowfive@57: function Amr:ShowLootWindow() yellowfive@57: if not _frameLoot then yellowfive@57: _frameLoot = AceGUI:Create("AmrUiFrame") yellowfive@57: _frameLoot:SetStatusTable(Amr.db.profile.lootWindow) -- window position is remembered in db yellowfive@57: _frameLoot:SetCallback("OnClose", onLootFrameClose) yellowfive@57: _frameLoot:SetLayout("None") yellowfive@57: _frameLoot:SetWidth(900) yellowfive@57: _frameLoot:SetHeight(600) yellowfive@57: _frameLoot:SetBorderColor(Amr.Colors.BorderBlue) yellowfive@57: _frameLoot:SetBackgroundColor(Amr.Colors.Bg) yellowfive@57: yellowfive@57: local lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetWidth(600) yellowfive@57: lbl:SetFont(Amr.CreateFont("Bold", 28, Amr.Colors.White)) yellowfive@57: lbl:SetText(L.LootTitle) yellowfive@57: lbl:SetWordWrap(false) yellowfive@57: lbl:SetJustifyH("CENTER") yellowfive@57: lbl:SetPoint("TOP", _frameLoot.content, "TOP", 0, 30) yellowfive@57: _frameLoot:AddChild(lbl) yellowfive@57: yellowfive@57: lbl:SetCallback("OnMouseDown", function(widget) _frameLoot:StartMove() end) yellowfive@57: lbl:SetCallback("OnMouseUp", function(widget) _frameLoot:EndMove() end) yellowfive@57: yellowfive@57: lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetWidth(_widthItemList) yellowfive@57: lbl:SetFont(Amr.CreateFont("Regular", 18, Amr.Colors.TextHeaderActive)) yellowfive@57: lbl:SetText(L.LootHelpItems) yellowfive@57: lbl:SetPoint("TOPLEFT", _frameLoot.content, "TOPLEFT", 0, -10) yellowfive@57: _frameLoot:AddChild(lbl) yellowfive@57: yellowfive@57: lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetWidth(_widthItemList) yellowfive@57: lbl:SetFont(Amr.CreateFont("Regular", 18, Amr.Colors.TextHeaderActive)) yellowfive@57: lbl:SetText(L.LootHelpRanks) yellowfive@57: lbl:SetPoint("TOPLEFT", _frameLoot.content, "TOPLEFT", _widthItemList + _widthSpacing, -10) yellowfive@57: _frameLoot:AddChild(lbl) yellowfive@57: yellowfive@57: if IsMasterLooter() then yellowfive@57: lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetWidth(_widthItemList) yellowfive@57: lbl:SetFont(Amr.CreateFont("Regular", 18, Amr.Colors.TextHeaderActive)) yellowfive@57: lbl:SetText(L.LootHelpMaster) yellowfive@57: lbl:SetPoint("TOPLEFT", _frameLoot.content, "TOPLEFT", _widthItemList + _widthSpacing + _widthRank + _widthRankBar + _widthRollType + (_widthColPadding * 3), -10) yellowfive@57: _frameLoot:AddChild(lbl) yellowfive@57: end yellowfive@57: yellowfive@57: _panelLoot = AceGUI:Create("AmrUiPanel") yellowfive@57: _panelLoot:SetLayout("None") yellowfive@57: _panelLoot:SetBackgroundColor(Amr.Colors.Black, 0) yellowfive@57: _panelLoot:SetPoint("TOPLEFT", _frameLoot.content, "TOPLEFT", 0, -40) yellowfive@57: _panelLoot:SetPoint("BOTTOMRIGHT", _frameLoot.content, "BOTTOMRIGHT", 0, 0) yellowfive@57: _frameLoot:AddChild(_panelLoot) yellowfive@57: else yellowfive@57: _frameLoot:Show() yellowfive@57: end yellowfive@57: yellowfive@57: _frameLoot:Raise() yellowfive@57: end yellowfive@57: yellowfive@57: function Amr:OnStartLootReceived(parts) yellowfive@57: local data = {} yellowfive@57: for i = 2, #parts do yellowfive@57: table.insert(data, parts[i]) yellowfive@57: end yellowfive@57: data = table.concat(data, "\n") yellowfive@57: yellowfive@57: -- reset rankings to the new data sent out by person in control yellowfive@57: local rankings = Amr:ParseRankingString(data) yellowfive@57: Amr.db.global.TeamOpt.Rankings = rankings yellowfive@57: yellowfive@57: -- reset disenchant state yellowfive@57: _disenchant = {} yellowfive@57: yellowfive@57: -- reset roll information when loot is started yellowfive@57: local rolls = {} yellowfive@57: for i = 1, #rankings do yellowfive@57: table.insert(rolls, {}) yellowfive@57: end yellowfive@57: Amr.db.char.TeamOpt.Rolls = rolls yellowfive@57: yellowfive@57: -- select first item by default yellowfive@57: _selectedIndex = #rankings > 0 and 1 or nil yellowfive@57: yellowfive@57: -- begin looting yellowfive@57: Amr.db.char.TeamOpt.LootInProgress = true yellowfive@57: yellowfive@57: Amr:RefreshTeamUi() yellowfive@57: Amr:ShowLootWindow() yellowfive@57: Amr:RefreshLootWindow() yellowfive@57: end