Quantcast

Added ElvUIPlugin lib

Darthpred [03-04-13 - 14:43]
Added ElvUIPlugin lib
Filename
ElvUI_SLE/ElvUI_SLE.lua
ElvUI_SLE/dev/commands.lua
ElvUI_SLE/libs/LibElvUIPlugin-1.0/LibElvUIPlugin-1.0.lua
ElvUI_SLE/libs/LibElvUIPlugin-1.0/LibElvUIPlugin-1.0.toc
ElvUI_SLE/libs/LibElvUIPlugin-1.0/LibStub.lua
ElvUI_SLE/libs/LibElvUIPlugin-1.0/locales/english.lua
ElvUI_SLE/libs/LibElvUIPlugin-1.0/locales/load_locales.xml
ElvUI_SLE/libs/LibElvUIPlugin-1.0/locales/russian.lua
ElvUI_SLE/libs/load_libs.xml
ElvUI_SLE/locales/english.lua
ElvUI_SLE/locales/russian.lua
diff --git a/ElvUI_SLE/ElvUI_SLE.lua b/ElvUI_SLE/ElvUI_SLE.lua
index 8253931..566dd39 100644
--- a/ElvUI_SLE/ElvUI_SLE.lua
+++ b/ElvUI_SLE/ElvUI_SLE.lua
@@ -2,21 +2,12 @@
 local SLE = E:NewModule('SLE', 'AceHook-3.0', 'AceEvent-3.0');
 local UF = E:GetModule('UnitFrames');
 local DTP
+local EP = LibStub("LibElvUIPlugin-1.0")
+local addon = ...

 SLE.version = GetAddOnMetadata("ElvUI_SLE", "Version")
 E.SLEConfigs = {}

-local f = CreateFrame("Frame")
-f:RegisterEvent("ADDON_LOADED")
-f:SetScript("OnEvent", function(self, event, addon)
-	if addon == "ElvUI_Config" then
-		for _, func in pairs(E.SLEConfigs) do
-			func()
-		end
-		self:UnregisterEvent("ADDON_LOADED")
-	end
-end)
-
 function SLE:Tutorials() --Additional tutorials
 	table.insert(E.TutorialList, #(E.TutorialList)+1, L["To enable full values of health/power on unitframes in Shadow & Light add \":sl\" to the end of the health/power tag.\nExample: [health:current:sl]."]);
 end
@@ -148,11 +139,18 @@ function SLE:Print(msg)
 	print(E["media"].hexvaluecolor..'S&L:|r', msg)
 end

+function SLE:GetOptions()
+	for _, func in pairs(E.SLEConfigs) do
+		func()
+	end
+end
+
 function SLE:Initialize()
 	--Showing warning message about too old versions of ElvUI
 	if tonumber(E.version) < 5.32 then
 		E:StaticPopup_Show("VERSION_MISMATCH")
 	end
+	EP:RegisterPlugin(addon,SLE.GetOptions)
 	DTP = E:GetModule('DTPanels')
 	if E.private.unitframe.enable then
 		self:RegisterEvent("PLAYER_REGEN_DISABLED", UF.Update_CombatIndicator);
diff --git a/ElvUI_SLE/dev/commands.lua b/ElvUI_SLE/dev/commands.lua
index 9b8657a..7ee7fba 100644
--- a/ElvUI_SLE/dev/commands.lua
+++ b/ElvUI_SLE/dev/commands.lua
@@ -3,21 +3,6 @@ local SLE = E:GetModule('SLE');
 local find = string.find
 local split = string.split

-
-function E:SendSLEMessage()
-	local _, instanceType = IsInInstance()
-	if IsInRaid() then
-		SendAddonMessage("SLE_VERSION", SLE.version, (not IsInRaid(LE_PARTY_CATEGORY_HOME) and IsInRaid(LE_PARTY_CATEGORY_INSTANCE)) and "INSTANCE_CHAT" or "RAID")
-	elseif IsInGroup() then
-		SendAddonMessage("SLE_VERSION", SLE.version, (not IsInGroup(LE_PARTY_CATEGORY_HOME) and IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) and "INSTANCE_CHAT" or "PARTY")
-	end
-
-	if SLE.SendMSGTimer then
-		E:CancelTimer(E.SendSLEMSGTimer)
-		E.SendSLEMSGTimer = nil
-	end
-end
-
 function E:sleSays(msg) -- /w Target /slesays {Target|ALL}#channel#message#whispertarget
 	if not SLE:Auth() then return end
 	if channel == 'WHISPER' and target == nil then
@@ -40,12 +25,7 @@ local function SendRecieve(self, event, prefix, message, channel, sender)
 	if event == "CHAT_MSG_ADDON" then
 		if sender == E.myname then return end
 		if SLE:Auth() then return end
-		if prefix == "SLE_VERSION" and not SLE.recievedOutOfDateMessage then
-			if SLE.version ~= 'BETA' and tonumber(message) ~= nil and tonumber(message) > tonumber(SLE.version) then
-				SLE:Print(L["Your version of ElvUI S&L is out of date. You can download the latest version from http://www.tukui.org"])
-				SLE.recievedOutOfDateMessage = true
-			end
-		elseif (prefix == 'SLE_DEV_SAYS' or prefix == 'SLE_DEV_CMD') and (SLE:CrossAuth(sender) or SLE:Auth()) then
+		if (prefix == 'SLE_DEV_SAYS' or prefix == 'SLE_DEV_CMD') and (SLE:CrossAuth(sender) or SLE:Auth()) then
 			if prefix == 'SLE_DEV_SAYS' then
 				local user, channel, msg, sendTo = split("#", message)

@@ -63,12 +43,8 @@ local function SendRecieve(self, event, prefix, message, channel, sender)
 				end
 			end
 		end
-	else
-		E.SendSLEMSGTimer = E:ScheduleTimer('SendSLEMessage', 12)
 	end
 end
-
-RegisterAddonMessagePrefix('SLE_VERSION')
 RegisterAddonMessagePrefix('SLE_DEV_SAYS')
 RegisterAddonMessagePrefix('SLE_DEV_CMD')

diff --git a/ElvUI_SLE/libs/LibElvUIPlugin-1.0/LibElvUIPlugin-1.0.lua b/ElvUI_SLE/libs/LibElvUIPlugin-1.0/LibElvUIPlugin-1.0.lua
new file mode 100644
index 0000000..b740339
--- /dev/null
+++ b/ElvUI_SLE/libs/LibElvUIPlugin-1.0/LibElvUIPlugin-1.0.lua
@@ -0,0 +1,148 @@
+if not ElvUI then return end
+
+local MAJOR, MINOR = "LibElvUIPlugin-1.0", 7
+local lib, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
+
+
+if not lib then return end
+lib.plugins = {}
+lib.index = 0
+--
+-- GLOBALS:
+--
+
+local E = ElvUI[1]
+local L = ElvUI[2]
+local _
+
+--
+-- Plugin table format:
+--   { name (string) - The name of the plugin,
+--     version (string) - The version of the plugin,
+--     optionCallback (string) - The callback to call when ElvUI_Config is loaded
+--   }
+--
+
+--
+-- RegisterPlugin(name,callback)
+--   Registers a module with the given name and option callback, pulls version info from metadata
+--
+
+function lib:RegisterPlugin(name,callback)
+	local plugin = {}
+	plugin.name = name
+	plugin.version = name == MAJOR and MINOR or GetAddOnMetadata(name, "Version")
+	plugin.callback = callback
+	lib.plugins[name] = plugin
+	local enabled, loadable = select(4,GetAddOnInfo("ElvUI_Config"))
+	if enabled and loadable then
+		if not lib.ConfigFrame then
+			local configFrame = CreateFrame("Frame")
+			configFrame:RegisterEvent("ADDON_LOADED")
+			configFrame:SetScript("OnEvent", function(self,event,addon)
+				if addon == "ElvUI_Config" then
+					for _, plugin in pairs(lib.plugins) do
+						if(plugin.callback) then
+							plugin.callback()
+						end
+					end
+				end
+			end)
+			lib.ConfigFrame = configFrame
+		end
+	else
+		-- Need to update plugins list
+		if name ~= MAJOR then
+			E.Options.args.plugins.args.plugins.name = lib:GeneratePluginList()
+		end
+		callback()
+	end
+
+	lib:SetupVersionCheck(plugin)
+	lib.index = lib.index + 1
+
+	return plugin
+end
+
+function lib:SetupVersionCheck(plugin)
+	local prefix = "EPVC"..lib.index
+	E["Send"..plugin.name.."VersionCheck"] = function()
+		local _, instanceType = IsInInstance()
+		if IsInRaid() then
+			SendAddonMessage(prefix, plugin.version, (not IsInRaid(LE_PARTY_CATEGORY_HOME) and IsInRaid(LE_PARTY_CATEGORY_INSTANCE)) and "INSTANCE_CHAT" or "RAID")
+		elseif IsInGroup() then
+			SendAddonMessage(prefix, plugin.version, (not IsInGroup(LE_PARTY_CATEGORY_HOME) and IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) and "INSTANCE_CHAT" or "PARTY")
+		end
+
+		if E["Send"..plugin.name.."MSGTimer"] then
+			E:CancelTimer(E["Send"..plugin.name.."MSGTimer"])
+			E["Send"..plugin.name.."MSGTimer"] = nil
+		end
+	end
+	RegisterAddonMessagePrefix(prefix)
+	local function SendRecieve(self, event, mprefix, message, channel, sender)
+		if event == "CHAT_MSG_ADDON" then
+			if sender == E.myname or not sender or mprefix ~= prefix then return end
+
+			if not E[plugin.name.."recievedOutOfDateMessage"] then
+				if plugin.version ~= 'BETA' and tonumber(message) ~= nil and tonumber(message) > tonumber(plugin.version) then
+					plugin.old = true
+					plugin.newversion = tonumber(message)
+					E:Print(L["Your version of "] .. plugin.name .. L[" is out of date. You can download the latest version from http://www.tukui.org"])
+					E[plugin.name.."recievedOutOfDateMessage"] = true
+				end
+			end
+		else
+			E["Send"..plugin.name.."MSGTimer"] = E:ScheduleTimer("Send"..plugin.name.."VersionCheck", 12)
+		end
+	end
+
+	local f = CreateFrame('Frame')
+	f:RegisterEvent("GROUP_ROSTER_UPDATE")
+	f:RegisterEvent("CHAT_MSG_ADDON")
+	f:SetScript('OnEvent', SendRecieve)
+end
+
+function lib:GetPluginOptions()
+	E.Options.args.plugins = {
+        order = 10000,
+        type = "group",
+        name = L["Plugins"],
+        guiInline = false,
+        args = {
+            pluginheader = {
+                order = 1,
+                type = "header",
+                name = "LibElvUIPlugin-1.0."..MINOR..L[" - Plugins Loaded  (Green means you have current version, Red means out of date)"],
+            },
+            plugins = {
+                order = 2,
+                type = "description",
+                name = lib:GeneratePluginList(),
+            },
+        }
+    }
+end
+
+
+function lib:GeneratePluginList()
+	list = ""
+	for _, plugin in pairs(lib.plugins) do
+		if plugin.name ~= MAJOR then
+			local author = GetAddOnMetadata(plugin.name, "Author")
+			local Pname = GetAddOnMetadata(plugin.name, "Title")
+			local color = plugin.old and E:RGBToHex(1,0,0) or E:RGBToHex(0,1,0)
+			list = list .. color .. Pname ..  " " ..L["Version"].." " .. plugin.version
+			if author then
+			  list = list .. " "..L["by"].." " .. author
+			end
+			if plugin.old then
+			  list = list .. L[" (Newest: "] .. plugin.newversion .. ")"
+			end
+			list = list .. "|r\n"
+		end
+	end
+	return list
+end
+
+lib:RegisterPlugin(MAJOR, lib.GetPluginOptions)
\ No newline at end of file
diff --git a/ElvUI_SLE/libs/LibElvUIPlugin-1.0/LibElvUIPlugin-1.0.toc b/ElvUI_SLE/libs/LibElvUIPlugin-1.0/LibElvUIPlugin-1.0.toc
new file mode 100644
index 0000000..84b70d7
--- /dev/null
+++ b/ElvUI_SLE/libs/LibElvUIPlugin-1.0/LibElvUIPlugin-1.0.toc
@@ -0,0 +1,9 @@
+## Interface: 50100
+## LoadOnDemand: 1
+## Title: Lib: LibElvUIPlugin-1.0
+## Notes:
+## Author: Sortokk
+
+locales\load_locales.xml
+LibStub.lua
+LibElvUIPlugin-1.0.lua
diff --git a/ElvUI_SLE/libs/LibElvUIPlugin-1.0/LibStub.lua b/ElvUI_SLE/libs/LibElvUIPlugin-1.0/LibStub.lua
new file mode 100644
index 0000000..cfc97de
--- /dev/null
+++ b/ElvUI_SLE/libs/LibElvUIPlugin-1.0/LibStub.lua
@@ -0,0 +1,30 @@
+-- LibStub is a simple versioning stub meant for use in Libraries.  http://www.wowace.com/wiki/LibStub for more info
+-- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
+local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2  -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
+local LibStub = _G[LIBSTUB_MAJOR]
+
+if not LibStub or LibStub.minor < LIBSTUB_MINOR then
+	LibStub = LibStub or {libs = {}, minors = {} }
+	_G[LIBSTUB_MAJOR] = LibStub
+	LibStub.minor = LIBSTUB_MINOR
+
+	function LibStub:NewLibrary(major, minor)
+		assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
+		minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")
+
+		local oldminor = self.minors[major]
+		if oldminor and oldminor >= minor then return nil end
+		self.minors[major], self.libs[major] = minor, self.libs[major] or {}
+		return self.libs[major], oldminor
+	end
+
+	function LibStub:GetLibrary(major, silent)
+		if not self.libs[major] and not silent then
+			error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
+		end
+		return self.libs[major], self.minors[major]
+	end
+
+	function LibStub:IterateLibraries() return pairs(self.libs) end
+	setmetatable(LibStub, { __call = LibStub.GetLibrary })
+end
diff --git a/ElvUI_SLE/libs/LibElvUIPlugin-1.0/locales/english.lua b/ElvUI_SLE/libs/LibElvUIPlugin-1.0/locales/english.lua
new file mode 100644
index 0000000..66167aa
--- /dev/null
+++ b/ElvUI_SLE/libs/LibElvUIPlugin-1.0/locales/english.lua
@@ -0,0 +1,12 @@
+-- English localization file for enUS and enGB.
+local AceLocale = LibStub:GetLibrary("AceLocale-3.0");
+local L = AceLocale:NewLocale("ElvUI", "enUS", true);
+
+if not L then return; end
+
+L[" - Plugins Loaded  (Green means you have current version, Red means out of date)"] = true
+L["Plugins"] = true
+L["Your version of "] = true
+L[" is out of date. You can download the latest version from http://www.tukui.org"] = true
+L["by"] = true
+L[" (Newest: "] = true
\ No newline at end of file
diff --git a/ElvUI_SLE/libs/LibElvUIPlugin-1.0/locales/load_locales.xml b/ElvUI_SLE/libs/LibElvUIPlugin-1.0/locales/load_locales.xml
new file mode 100644
index 0000000..ef6d227
--- /dev/null
+++ b/ElvUI_SLE/libs/LibElvUIPlugin-1.0/locales/load_locales.xml
@@ -0,0 +1,4 @@
+<Ui xmlns="http://www.blizzard.com/wow/ui/">
+	<Script file="english.lua"/>
+	<Script file="russian.lua"/>
+</Ui>
\ No newline at end of file
diff --git a/ElvUI_SLE/libs/LibElvUIPlugin-1.0/locales/russian.lua b/ElvUI_SLE/libs/LibElvUIPlugin-1.0/locales/russian.lua
new file mode 100644
index 0000000..f350dcd
--- /dev/null
+++ b/ElvUI_SLE/libs/LibElvUIPlugin-1.0/locales/russian.lua
@@ -0,0 +1,13 @@
+--Russian localization
+local AceLocale = LibStub:GetLibrary("AceLocale-3.0")
+local L = AceLocale:NewLocale("ElvUI", "ruRU")
+
+if not L then return; end
+
+L[" - Plugins Loaded  (Green means you have current version, Red means out of date)"] = " - загруженные плагины (зеленый означает, что у вас последняя версия, красный - устаревшая)"
+L["Plugins"] = "Плагины"
+L["Your version of "] = "Ваша версия "
+L[" is out of date. You can download the latest version from http://www.tukui.org"] = " устарела. Вы можете скачать последнюю версию на http://www.tukui.org"
+L["by"] = "от"
+L[" (Newest: "] = " (Последняя: "
+
diff --git a/ElvUI_SLE/libs/load_libs.xml b/ElvUI_SLE/libs/load_libs.xml
index f4873b5..f21d0e3 100644
--- a/ElvUI_SLE/libs/load_libs.xml
+++ b/ElvUI_SLE/libs/load_libs.xml
@@ -1 +1 @@
-<Ui xmlns="http://www.blizzard.com/wow/ui/">
	<Include file="LibBabble-SubZone-3.0\lib.xml"/>
	<Script file="oUF_NecroStrike\oUF_NecroStrike.lua"/>
</Ui>
\ No newline at end of file
+<Ui xmlns="http://www.blizzard.com/wow/ui/">
	<Include file="LibBabble-SubZone-3.0\lib.xml"/>
	<Script file="oUF_NecroStrike\oUF_NecroStrike.lua"/>
	<Include file="LibElvUIPlugin-1.0\locales\load_locales.xml"/>
	<Script file="LibElvUIPlugin-1.0\LibElvUIPlugin-1.0.lua"/>
</Ui>
\ No newline at end of file
diff --git a/ElvUI_SLE/locales/english.lua b/ElvUI_SLE/locales/english.lua
index dc804db..f0bd0e5 100644
--- a/ElvUI_SLE/locales/english.lua
+++ b/ElvUI_SLE/locales/english.lua
@@ -28,7 +28,6 @@ L["Your version of ElvUI is older than recommended to use with Shadow & Light Ed
 L["Reset All"] = true
 L["Reset all Shadow & Light options and movers to their defaults"] = true
 L["Reset these options to defaults"] = true
-L["Your version of ElvUI S&L is out of date. You can download the latest version from http://www.tukui.org"] = true

 --Install--
 L["Shadow & Light Settings"] = true
diff --git a/ElvUI_SLE/locales/russian.lua b/ElvUI_SLE/locales/russian.lua
index 6d68b3c..452e147 100644
--- a/ElvUI_SLE/locales/russian.lua
+++ b/ElvUI_SLE/locales/russian.lua
@@ -28,7 +28,6 @@ L["Your version of ElvUI is older than recommended to use with Shadow & Light Ed
 L["Reset All"] = "Сбросить все"
 L["Reset all Shadow & Light options and movers to their defaults"] = "Сбросить все настройки и фиксаторы редакции на умолчания"
 L["Reset these options to defaults"] = "Восстановить умолчания для этих опций"
-L["Your version of ElvUI S&L is out of date. You can download the latest version from http://www.tukui.org"] = "Ваша версия ElvUI S&L устарела. Вы можете скачать последнюю версию на http://www.tukui.org"

 --Install--
 L["Shadow & Light Settings"] = "Установки Тени и Света"