From 30b296bc6264d12a12739822fe93414dc8bce8ff Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Fri, 29 Mar 2013 01:57:34 +0000 Subject: [PATCH] Back out changes in r842 and restore damage meter registration. OvaleFuture needs to send out messages to all of the registered damage meters when a scored spell has been cast. Improve the implementation of the registration so that it only requires a function or a method name instead of the module itself. This makes it easier for other damage meters to implement a small function to receive score information from Ovale instead of implementing a full-blown Ovale module. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@855 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- Ovale.lua | 97 ++++++++++++++++++++++++++++++++++++++++++++---------- OvaleRecount.lua | 39 ++++++++++------------ OvaleSkada.lua | 55 +++++++++++++++---------------- 3 files changed, 123 insertions(+), 68 deletions(-) diff --git a/Ovale.lua b/Ovale.lua index 1ae4afc..2c71364 100644 --- a/Ovale.lua +++ b/Ovale.lua @@ -19,11 +19,14 @@ local format = string.format local pairs = pairs local wipe = table.wipe local API_GetTime = GetTime +local API_RegisterAddonMessagePrefix = RegisterAddonMessagePrefix local API_SendAddonMessage = SendAddonMessage local API_UnitCanAttack = UnitCanAttack local API_UnitExists = UnitExists local API_UnitHasVehicleUI = UnitHasVehicleUI local API_UnitIsDead = UnitIsDead + +local self_damageMeterMethods = {} -- -- @@ -62,14 +65,32 @@ BINDING_NAME_OVALE_CHECKBOX2 = L["Inverser la boîte à cocher "].."(3)" BINDING_NAME_OVALE_CHECKBOX3 = L["Inverser la boîte à cocher "].."(4)" BINDING_NAME_OVALE_CHECKBOX4 = L["Inverser la boîte à cocher "].."(5)" +-- +local function OnCheckBoxValueChanged(widget) + OvaleOptions:GetProfile().check[widget.userdata.k] = widget:GetValue() + if Ovale.casesACocher[widget.userdata.k].compile then + Ovale:SendMessage("Ovale_CheckBoxValueChanged") + end +end + +local function OnDropDownValueChanged(widget) + OvaleOptions:GetProfile().list[widget.userdata.k] = widget.value + if Ovale.listes[widget.userdata.k].compile then + Ovale:SendMessage("Ovale_ListValueChanged") + end +end +-- + -- function Ovale:OnEnable() -- Called when the addon is enabled - OvaleGUID = Ovale:GetModule("OvaleGUID") - OvaleOptions = Ovale:GetModule("OvaleOptions") + OvaleGUID = self:GetModule("OvaleGUID") + OvaleOptions = self:GetModule("OvaleOptions") - self:RegisterEvent("PLAYER_REGEN_ENABLED"); - self:RegisterEvent("PLAYER_REGEN_DISABLED"); + API_RegisterAddonMessagePrefix("Ovale") + self:RegisterEvent("CHAT_MSG_ADDON") + self:RegisterEvent("PLAYER_REGEN_ENABLED") + self:RegisterEvent("PLAYER_REGEN_DISABLED") self:RegisterEvent("PLAYER_TARGET_CHANGED") self.frame = LibStub("AceGUI-3.0"):Create("OvaleFrame") @@ -78,12 +99,23 @@ end function Ovale:OnDisable() -- Called when the addon is disabled + self:UnregisterEvent("CHAT_MSG_ADDON") self:UnregisterEvent("PLAYER_REGEN_ENABLED") self:UnregisterEvent("PLAYER_REGEN_DISABLED") self:UnregisterEvent("PLAYER_TARGET_CHANGED") self.frame:Hide() end +-- Receive scores for damage meters from other Ovale addons in the raid. +function Ovale:CHAT_MSG_ADDON(event, ...) + local prefix, message, channel, sender = ... + if prefix ~= "Ovale" then return end + if channel ~= "RAID" and channel ~= "PARTY" then return end + + local scored, scoreMax, guid = strsplit(";", message) + self:SendScoreToDamageMeter(sender, guid, scored, scoreMax) +end + --Called when the player target change --Used to update the visibility e.g. if the user chose --to hide Ovale if a friendly unit is targeted @@ -102,6 +134,7 @@ end function Ovale:PLAYER_REGEN_DISABLED() if self.maxScore > 0 then + -- Broadcast the player's own score for damage meters when combat ends. -- Broadcast message is "score;maxScore;playerGUID" local message = self.score .. ";" .. self.maxScore .. ";" .. OvaleGUID:GetGUID("player") API_SendAddonMessage("Ovale", message, "RAID") @@ -113,20 +146,6 @@ function Ovale:PLAYER_REGEN_DISABLED() self:UpdateVisibility() end -local function OnCheckBoxValueChanged(widget) - OvaleOptions:GetProfile().check[widget.userdata.k] = widget:GetValue() - if Ovale.casesACocher[widget.userdata.k].compile then - Ovale:SendMessage("Ovale_CheckBoxValueChanged") - end -end - -local function OnDropDownValueChanged(widget) - OvaleOptions:GetProfile().list[widget.userdata.k] = widget.value - if Ovale.listes[widget.userdata.k].compile then - Ovale:SendMessage("Ovale_ListValueChanged") - end -end - function Ovale:ToggleOptions() self.frame:ToggleOptions() end @@ -232,6 +251,48 @@ function Ovale:ToggleCheckBox(v) end end +--[[ + Damage meter addons that want to receive Ovale scores should implement + and register a function that has the following signature: + + ReceiveScore(name, guid, scored, scoreMax) + + Parameters: + name - the name of the unit + guid - GUID of the named unit + scored - current score + scoreMax - current maximum score + + Returns: + none + + The function should be registered with Ovale using the RegisterDamageMeter + method, which needs a unique name for the meter and either the function itself + or a method name for the module with the given name. +]]-- + +function Ovale:RegisterDamageMeter(name, method) + self_damageMeterMethods[name] = method +end + +function Ovale:UnregisterDamageMeter(name) + self_damageMeterMethods[name] = nil +end + +function Ovale:SendScoreToDamageMeter(name, guid, scored, scoreMax) + for _, method in pairs(self_damageMeterMethods) do + if type(method) == "string" then + local module = self:GetModule(name) or LibStub("AceAddon-3.0"):GetAddon(name) + if module and type(module[method]) == "function" then + return module[method](module, name, guid, scored, scoreMax) + end + elseif type(method) == "function" then + return method(name, guid, scored, scoreMax) + end + end +end + +-- Debugging methods. function Ovale:DebugPrint(flag, ...) local profile = OvaleOptions:GetProfile() if profile and profile.debug and profile.debug[flag] then diff --git a/OvaleRecount.lua b/OvaleRecount.lua index 61e37aa..5f4ce37 100644 --- a/OvaleRecount.lua +++ b/OvaleRecount.lua @@ -1,6 +1,7 @@ --[[-------------------------------------------------------------------- Ovale Spell Priority Copyright (C) 2009 Sidoine + Copyright (C) 2012, 2013 Johnny C. Lam This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License in the LICENSE @@ -8,7 +9,7 @@ ----------------------------------------------------------------------]] local _, Ovale = ... -local OvaleRecount = Ovale:NewModule("OvaleRecount", "AceEvent-3.0") +local OvaleRecount = Ovale:NewModule("OvaleRecount") Ovale.OvaleRecount = OvaleRecount -- @@ -17,9 +18,6 @@ local L = LibStub("AceLocale-3.0"):GetLocale("Recount", true) if not L then L = setmetatable({}, { __index = function(t, k) t[k] = k; return k; end }) end - -local strsplit = string.split -local API_RegisterAddonMessagePrefix = RegisterAddonMessagePrefix -- -- @@ -51,31 +49,30 @@ end -- function OvaleRecount:OnInitialize() - if not Recount then return end - Recount:AddModeTooltip("Ovale", DataModes, TooltipFuncs, nil, nil, nil, nil) + if Recount then + Recount:AddModeTooltip("Ovale", DataModes, TooltipFuncs, nil, nil, nil, nil) + end end function OvaleRecount:OnEnable() - if not Recount then return end - self:RegisterEvent("CHAT_MSG_ADDON") - API_RegisterAddonMessagePrefix("Ovale") + if Recount then + Ovale:RegisterDamageMeter("OvaleRecount", "ReceiveScore") + end end function OvaleRecount:OnDisable() - if not Recount then return end - self:UnregisterEvent("CHAT_MSG_ADDON") + if Recount then + Ovale:UnregisterDamageMeter("OvaleRecount") + end end -function OvaleRecount:CHAT_MSG_ADDON(event, ...) - local prefix, message, channel, sender = ... - if prefix ~= "Ovale" then return end - if channel ~= "RAID" and channel ~= "PARTY" then return end - - local scored, scoreMax, guid = strsplit(";", message) - local source = Recount.db2.combatants[sender] - if source then - Recount:AddAmount(source, "Ovale", scored) - Recount:AddAmount(source, "OvaleMax", scoreMax) +function OvaleRecount:ReceiveScore(name, guid, scored, scoreMax) + if Recount then + local source = Recount.db2.combatants[name] + if source then + Recount:AddAmount(source, "Ovale", scored) + Recount:AddAmount(source, "OvaleMax", scoreMax) + end end end -- diff --git a/OvaleSkada.lua b/OvaleSkada.lua index 393d9f3..ef7fec8 100644 --- a/OvaleSkada.lua +++ b/OvaleSkada.lua @@ -1,6 +1,7 @@ --[[-------------------------------------------------------------------- Ovale Spell Priority Copyright (C) 2010 Sidoine + Copyright (C) 2012, 2013 Johnny C. Lam This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License in the LICENSE @@ -8,7 +9,7 @@ ----------------------------------------------------------------------]] local _, Ovale = ... -local OvaleSkada = Ovale:NewModule("OvaleSkada", "AceEvent-3.0") +local OvaleSkada = Ovale:NewModule("OvaleSkada") Ovale.OvaleSkada = OvaleSkada -- @@ -17,9 +18,7 @@ local SkadaModule = Skada and Skada:NewModule("Ovale Spell Priority") or { noSka local ipairs = ipairs local math = math -local strsplit = string.split local tostring = tostring -local API_RegisterAddonMessagePrefix = RegisterAddonMessagePrefix -- -- @@ -94,38 +93,36 @@ function SkadaModule:GetSetSummary(set) end function OvaleSkada:OnEnable() - if SkadaModule.noSkada then return end - if not SkadaModule:IsEnabled() then - SkadaModule:Enable() + if not SkadaModule.noSkada then + if not SkadaModule:IsEnabled() then + SkadaModule:Enable() + end + Ovale:RegisterDamageMeter("OvaleSkada", "ReceiveScore") end - self:RegisterEvent("CHAT_MSG_ADDON") - API_RegisterAddonMessagePrefix("Ovale") end function OvaleSkada:OnDisable() - if SkadaModule.noSkada then return end - self:UnregisterEvent("CHAT_MSG_ADDON") - if SkadaModule:IsEnabled() then - SkadaModule:Disable() + if not SkadaModule.noSkada then + Ovale:UnregisterDamageMeter("OvaleSkada") + if SkadaModule:IsEnabled() then + SkadaModule:Disable() + end end end -function OvaleSkada:CHAT_MSG_ADDON(event, ...) - local prefix, message, channel, sender = ... - if prefix ~= "Ovale" then return end - if channel ~= "RAID" and channel ~= "PARTY" then return end - - local scored, scoreMax, guid = strsplit(";", message) - if not guid or not Skada.current or not Skada.total then return end - - local player = Skada:get_player(Skada.current, guid, nil) - if not player then return end - - SkadaModule:AddPlayerAttributes(player) - player.ovale = player.ovale + scored - player.ovaleMax = player.ovaleMax + scoreMax - player = Skada:get_player(Skada.total, guid, nil) - player.ovale = player.ovale + scored - player.ovaleMax = player.ovaleMax + scoreMax +function OvaleSkada:ReceiveScore(name, guid, scored, scoreMax) + if not SkadaModule.noSkada then + if not guid or not Skada.current or not Skada.total then return end + + local player = Skada:get_player(Skada.current, guid, nil) + if player then + SkadaModule:AddPlayerAttributes(player) + player.ovale = player.ovale + scored + player.ovaleMax = player.ovaleMax + scoreMax + player = Skada:get_player(Skada.total, guid, nil) + player.ovale = player.ovale + scored + player.ovaleMax = player.ovaleMax + scoreMax + end + end end -- -- 1.7.9.5