Compare with Previous | Blame | View Log
--[[ ]] ---------------------------------- -- Create plugin local RW = LibStub("AceAddon-3.0"):GetAddon("Raid Watch") local plugin = RW:Plugin("Stats") if not plugin then return end ---------------------------------- -- Locals local L = LibStub("AceLocale-3.0"):GetLocale("RW2-Plugin-Stats") local LB = LibStub("AceLocale-3.0"):GetLocale("RW2-Plugin-Base") local LSM = LibStub("LibSharedMedia-3.0") local AceGUI = LibStub("AceGUI-3.0") local UIF local db local Utils = RW.Utils local mods = {} local startedDifficulties = {} local modTypes = {} local selectedDiffs = {} local diffLists = { raid = { {value = 10, text = "10"}, {value = 25, text = "25"}, }, party = { {value = 5, text = 5}, } } local defaults = { global = { PluginEnabled = true, Announce = true, LastSelectedChar = UnitName("player"), Chars = { ["**"] = { Stats = { ["**"] = { ["**"] = { heroic = { kills = 0, wipes = 0, best = "---", }, normal = { kills = 0, wipes = 0, best = "---", }, }, } }, } }, } } ---------------------------------- -- Init function plugin:OnRegister() self.db = LibStub("AceDB-3.0"):New("RaidWatch2StatsDB", defaults, "Default") db = self.db.global self.db.RegisterCallback(self, "OnProfileChanged", "Reset") self.db.RegisterCallback(self, "OnProfileCopied", "Reset") self.db.RegisterCallback(self, "OnProfileReset", "Reset") end function plugin:PluginEnable() if not db.PluginEnabled then self:Disable() return end self:RegisterCallback("BossEngaged") self:RegisterCallback("BossDisengaged") db.Chars[UnitName("player")] = db.Chars[UnitName("player")] or {} end function plugin:PluginDisable() end function plugin:Reset() db = self.db.profile end function plugin:BossEngaged(message, boss, trigger) if trigger and not boss.TrashMod then startedDifficulties[boss] = {size = boss:InstanceSize(), heroic = boss:IsHeroic(), pullTime = GetTime()} end end function plugin:BossDisengaged(event, boss, wipe, trigger) if not boss.TrashMod then if trigger and trigger ~= "Debug" then local pullData = startedDifficulties[boss] local timeTaken if pullData.pullTime then timeTaken = GetTime() - pullData.pullTime else timeTaken = 0 end local stats = db.Chars[UnitName("player")].Stats[boss:GetName()][pullData.size][pullData.heroic and "heroic" or "normal"] -- Did not wipe if not wipe then stats.kills = stats.kills + 1 if stats.best == "---" then if db.Announce then self:Msg(L.BOSS_FIRST_KILL) end stats.best = timeTaken elseif timeTaken < stats.best then if db.Announce then self:Msg(L.BOSS_NEW_BEST:format(Utils:TimeToStr(stats.best))) end stats.best = timeTaken else if db.Announce then self:Msg(L.BOSS_NOT_BEST:format(Utils:TimeToStr(stats.best))) end end -- Wipe else stats.wipes = stats.wipes + 1 end end end startedDifficulties[boss] = nil end function plugin:BuildList() for modName in RW:IterateBossPacks() do for index, boss in RW:IterateBossesByPack(modName) do mods[boss.modPack] = mods[boss.modPack] or {} if not Utils:InTable(mods[boss.modPack], boss) then tinsert(mods[boss.modPack], boss) modTypes[boss.modPack] = modTypes[boss.modPack] or boss.type end end end end ------------------------------------- -- Options function plugin:GetOptions() return { {LB.PLUGINS, L.NAME, self.GetGUI1, [[Interface\PAPERDOLLINFOFRAME\UI-GearManager-ItemIntoBag]]}, {LB.PLUGINS, L.NAME, 1, "Boss Mods", self.GetGUI2}, } end function plugin:GetGUI1() return plugin:GetTheGUI(true) end function plugin:GetGUI2() return plugin:GetTheGUI() end local cats = {} local listFontSize = 15 local col1, col2, col3, col4, col5 = 0.3, 0.15, 0.15, 0.15, 0.15 local color1 = {1, 0.6, 0.16} local color2 = {1, 1, 1} local function tabSelectDiff(widget, event, group) widget:ReleaseChildren() selectedDiffs[widget:GetUserData("mod")] = group wipe(cats) label = UIF:Title2("Boss", nil, listFontSize + 3) label:SetRelativeWidth(col1) widget:AddChild(label) label = UIF:Title2("Kills", nil, listFontSize + 3) label:SetRelativeWidth(col2) widget:AddChild(label) label = UIF:Title2("Wipes", nil, listFontSize + 3) label:SetRelativeWidth(col3) widget:AddChild(label) label = UIF:Title2("Total", nil, listFontSize + 3) label:SetRelativeWidth(col4) widget:AddChild(label) label = UIF:Title2("Best", nil, listFontSize + 3) label:SetRelativeWidth(col5) widget:AddChild(label) label = UIF:Title2("Reset", nil, listFontSize + 3) label:SetRelativeWidth(0.09) widget:AddChild(label) for i, boss in pairs(mods[widget:GetUserData("mod")]) do if not boss.TrashMod then local color if i % 2 == 0 then color = color1 else color = color2 end local tgroup local stats = db.Chars[db.LastSelectedChar].Stats[boss:GetName()][selectedDiffs[boss.modPack]] if boss.subGroup then if not cats[boss.subGroup] then local simpleG = AceGUI:Create("SimpleGroup") simpleG:SetLayout("Flow") simpleG:SetFullWidth(true) widget:AddChild(simpleG) local labelCat = UIF:Title2(boss.subGroup, nil, listFontSize + 2, nil, "OUTLINE") simpleG:AddChild(labelCat) cats[boss.subGroup] = simpleG end tgroup = cats[boss.subGroup] else tgroup = widget end local bossName = RW.LBB[boss:GetName()] or boss:GetName() label = UIF:NormalText(bossName, color, listFontSize) label:SetRelativeWidth(col1) tgroup:AddChild(label) label = UIF:NormalText(stats.heroic.kills.."/"..stats.normal.kills, color, listFontSize) label:SetRelativeWidth(col2) tgroup:AddChild(label) label = UIF:NormalText(stats.heroic.wipes.."/"..stats.normal.wipes, color, listFontSize) label:SetRelativeWidth(col3) tgroup:AddChild(label) label = UIF:NormalText((stats.heroic.kills + stats.heroic.wipes).."/"..(stats.normal.kills + stats.normal.wipes), color, listFontSize) label:SetRelativeWidth(col4) tgroup:AddChild(label) label = UIF:NormalText(Utils:TimeToStringShort(stats.heroic.best).."/"..Utils:TimeToStringShort(stats.normal.best), color, listFontSize) label:SetRelativeWidth(col5) tgroup:AddChild(label) button = UIF:Button("", function() for diff, data in pairs(stats) do data.kills = 0 data.wipes = 0 data.best = "---" end end) button:SetUserData("confirm", true) button:SetUserData("TriggerGlobalUpdate", true) button:SetWidth(25) button:SetHeight(18) tgroup:AddChild(button) end end end local function changedCallback(widget, event, ...) RW.Callbacks:Fire("RefreshOptions") end local charList = {} local function buildCharList() wipe(charList) for char, charData in pairs(db.Chars) do charList[char] = {text = char, value = char} end end function plugin:GetTheGUI(withOptions) self = self or plugin UIF = LibStub("LibGUIFactory-1.0"):GetFactory("RW") self:BuildList() local label, select, group, sgroup, button, igroup group = AceGUI:Create("ScrollFrame") group:SetLayout("Flow") label = UIF:MainTitleLabel(L.NAME) group:AddChild(label) sgroup = UIF:InlineGroup("") group:AddChild(sgroup) if withOptions then label = UIF:NormalText(L.STATS_DESC) label:SetImage([[Interface\PAPERDOLLINFOFRAME\UI-GearManager-ItemIntoBag]]) sgroup:AddChild(label) label = UIF:NormalText(" ") sgroup:AddChild(label) check = UIF:CheckBox(LB.ENABLED, db, "PluginEnabled", function() if not db.PluginEnabled then self:Disable() else self:Enable() end end) check:SetFullWidth(true) sgroup:AddChild(check) check = UIF:CheckBox(L.ANNOUNCE, db, "Announce") check:SetDescription(L.ANNOUNCE_DESC) sgroup:AddChild(check) else buildCharList() select = UIF:Dropdown(LB.CHARACTER, db, "LastSelectedChar", changedCallback) select:SetList(charList) select:SetValue(UnitName("player")) sgroup:AddChild(select) button = UIF:Button(L.RESET_CHARACTER, function() wipe(db.Chars[db.LastSelectedChar].Stats) end) button:SetUserData("confirm", true) button:SetUserData("TriggerGlobalUpdate", true) sgroup:AddChild(button) sgroup = UIF:InlineGroup("") group:AddChild(sgroup) for modName, data in pairs(mods) do print("Loading data for "..modName) local modgroup = AceGUI:Create("SimpleGroup") modgroup:SetLayout("Flow") modgroup:SetFullWidth(true) sgroup:AddChild(modgroup) igroup = UIF:TabGroup2(modName) igroup:SetTabs(diffLists[modTypes[modName]]) igroup:SetUserData("mod", modName) igroup:SetCallback("OnGroupSelected", tabSelectDiff) igroup:SelectTab(selectedDiffs[modName] or (modTypes[modName] == "party" and 5 or 10)) modgroup:AddChild(igroup) end end return group end