(1.1.0) New major release
This commit is contained in:
3
Event/Load_Events.xml
Normal file
3
Event/Load_Events.xml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<Ui xmlns="http://www.blizzard.com/wow/ui/">
|
||||||
|
<Script file="PLAYER_MONEY.lua"/>
|
||||||
|
</Ui>
|
||||||
24
Event/PLAYER_MONEY.lua
Normal file
24
Event/PLAYER_MONEY.lua
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
local MX = LibStub("AceAddon-3.0"):GetAddon("MxW.Farm");
|
||||||
|
local L = LibStub("AceLocale-3.0"):GetLocale("MxW.Farm");
|
||||||
|
|
||||||
|
local PLAYER_MONEY_Frame = CreateFrame("Frame")
|
||||||
|
PLAYER_MONEY_Frame:RegisterEvent("PLAYER_MONEY")
|
||||||
|
PLAYER_MONEY_Frame:SetScript("OnEvent", function(self, event, arg1)
|
||||||
|
if event == "PLAYER_MONEY" then
|
||||||
|
local DiffGold = 0
|
||||||
|
local NewGold = GetMoney() -- Get the player gold after the event
|
||||||
|
DiffGold = NewGold - CurrentGold -- Get the gold difference
|
||||||
|
if (DiffGold > 0) then -- Gold gain
|
||||||
|
-- Write to SavedVariables
|
||||||
|
MxW_MonthlyGlobal = MxW_MonthlyGlobal + DiffGold;
|
||||||
|
MxW_DailyGlobal = MxW_DailyGlobal + DiffGold;
|
||||||
|
MX:RefreshDisplay()
|
||||||
|
|
||||||
|
elseif (DiffGold <= 0) then -- Gold lost
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
CurrentGold = GetMoney()
|
||||||
|
DiffGold = 0
|
||||||
|
end
|
||||||
|
end)
|
||||||
3
Function/Load_Functions.xml
Normal file
3
Function/Load_Functions.xml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<Ui xmlns="http://www.blizzard.com/wow/ui/">
|
||||||
|
<Script file="Money.lua"/>
|
||||||
|
</Ui>
|
||||||
61
Function/Money.lua
Normal file
61
Function/Money.lua
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
local MX = LibStub("AceAddon-3.0"):GetAddon("MxW.Farm");
|
||||||
|
local L = LibStub("AceLocale-3.0"):GetLocale("MxW.Farm");
|
||||||
|
|
||||||
|
local COLOR_COPPER = "|cffeda55f"
|
||||||
|
local COLOR_SILVER = "|cffc7c7cf"
|
||||||
|
local COLOR_GOLD = "|cffffd700"
|
||||||
|
local COLOR_WHITE = "|cffffffff"
|
||||||
|
|
||||||
|
function MX:FormatMoney(money)
|
||||||
|
local ret = ""
|
||||||
|
local gold = floor(money / (COPPER_PER_SILVER * SILVER_PER_GOLD));
|
||||||
|
local silver = floor((money - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER);
|
||||||
|
local copper = mod(money, COPPER_PER_SILVER);
|
||||||
|
|
||||||
|
if (gold == 0) then
|
||||||
|
return format("%s%02ds|r %s%02dc|r", COLOR_SILVER, silver, COLOR_COPPER, copper)
|
||||||
|
end
|
||||||
|
if (gold > 0) then
|
||||||
|
return format("%s%02dg|r %s%02ds|r %s%02dc|r", COLOR_GOLD, gold, COLOR_SILVER, silver, COLOR_COPPER, copper)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function MX:FormatMoneyGoldOnly(money)
|
||||||
|
local ret = ""
|
||||||
|
local gold = floor(money / (COPPER_PER_SILVER * SILVER_PER_GOLD));
|
||||||
|
local silver = floor((money - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER);
|
||||||
|
local copper = mod(money, COPPER_PER_SILVER);
|
||||||
|
|
||||||
|
if (gold == 0) then
|
||||||
|
return "0g"
|
||||||
|
end
|
||||||
|
if (gold > 0) then
|
||||||
|
return format("%s%dg|r", COLOR_GOLD, gold)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function MX:FormatMoneyShort(money)
|
||||||
|
local ret = ""
|
||||||
|
local gold = floor(money / (COPPER_PER_SILVER * SILVER_PER_GOLD));
|
||||||
|
local silver = floor((money - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER);
|
||||||
|
local copper = mod(money, COPPER_PER_SILVER);
|
||||||
|
|
||||||
|
if (gold == 0) then
|
||||||
|
return format("%s%02ds|r %s%02dc|r", COLOR_SILVER, silver, COLOR_COPPER, copper)
|
||||||
|
end
|
||||||
|
if (gold > 0) then
|
||||||
|
return format("%s%sg%s", COLOR_GOLD, gold, COLOR_WHITE)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function MX:FormatMoneyNoColor(money)
|
||||||
|
local gold = floor(money / (COPPER_PER_SILVER * SILVER_PER_GOLD));
|
||||||
|
local silver = floor((money - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER);
|
||||||
|
local copper = mod(money, COPPER_PER_SILVER);
|
||||||
|
if (gold == 0) then
|
||||||
|
return format("%ss %sc", silver, copper)
|
||||||
|
end
|
||||||
|
if (gold > 0) then
|
||||||
|
return format("%sg %ss %sc", gold, silver, copper)
|
||||||
|
end
|
||||||
|
end
|
||||||
674
Libraries/AceAddon-3.0/AceAddon-3.0.lua
Normal file
674
Libraries/AceAddon-3.0/AceAddon-3.0.lua
Normal file
@@ -0,0 +1,674 @@
|
|||||||
|
--- **AceAddon-3.0** provides a template for creating addon objects.
|
||||||
|
-- It'll provide you with a set of callback functions that allow you to simplify the loading
|
||||||
|
-- process of your addon.\\
|
||||||
|
-- Callbacks provided are:\\
|
||||||
|
-- * **OnInitialize**, which is called directly after the addon is fully loaded.
|
||||||
|
-- * **OnEnable** which gets called during the PLAYER_LOGIN event, when most of the data provided by the game is already present.
|
||||||
|
-- * **OnDisable**, which is only called when your addon is manually being disabled.
|
||||||
|
-- @usage
|
||||||
|
-- -- A small (but complete) addon, that doesn't do anything,
|
||||||
|
-- -- but shows usage of the callbacks.
|
||||||
|
-- local MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
|
||||||
|
--
|
||||||
|
-- function MyAddon:OnInitialize()
|
||||||
|
-- -- do init tasks here, like loading the Saved Variables,
|
||||||
|
-- -- or setting up slash commands.
|
||||||
|
-- end
|
||||||
|
--
|
||||||
|
-- function MyAddon:OnEnable()
|
||||||
|
-- -- Do more initialization here, that really enables the use of your addon.
|
||||||
|
-- -- Register Events, Hook functions, Create Frames, Get information from
|
||||||
|
-- -- the game that wasn't available in OnInitialize
|
||||||
|
-- end
|
||||||
|
--
|
||||||
|
-- function MyAddon:OnDisable()
|
||||||
|
-- -- Unhook, Unregister Events, Hide frames that you created.
|
||||||
|
-- -- You would probably only use an OnDisable if you want to
|
||||||
|
-- -- build a "standby" mode, or be able to toggle modules on/off.
|
||||||
|
-- end
|
||||||
|
-- @class file
|
||||||
|
-- @name AceAddon-3.0.lua
|
||||||
|
-- @release $Id: AceAddon-3.0.lua 1084 2013-04-27 20:14:11Z nevcairiel $
|
||||||
|
|
||||||
|
local MAJOR, MINOR = "AceAddon-3.0", 12
|
||||||
|
local AceAddon, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||||
|
|
||||||
|
if not AceAddon then return end -- No Upgrade needed.
|
||||||
|
|
||||||
|
AceAddon.frame = AceAddon.frame or CreateFrame("Frame", "AceAddon30Frame") -- Our very own frame
|
||||||
|
AceAddon.addons = AceAddon.addons or {} -- addons in general
|
||||||
|
AceAddon.statuses = AceAddon.statuses or {} -- statuses of addon.
|
||||||
|
AceAddon.initializequeue = AceAddon.initializequeue or {} -- addons that are new and not initialized
|
||||||
|
AceAddon.enablequeue = AceAddon.enablequeue or {} -- addons that are initialized and waiting to be enabled
|
||||||
|
AceAddon.embeds = AceAddon.embeds or setmetatable({}, {__index = function(tbl, key) tbl[key] = {} return tbl[key] end }) -- contains a list of libraries embedded in an addon
|
||||||
|
|
||||||
|
-- Lua APIs
|
||||||
|
local tinsert, tconcat, tremove = table.insert, table.concat, table.remove
|
||||||
|
local fmt, tostring = string.format, tostring
|
||||||
|
local select, pairs, next, type, unpack = select, pairs, next, type, unpack
|
||||||
|
local loadstring, assert, error = loadstring, assert, error
|
||||||
|
local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget
|
||||||
|
|
||||||
|
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||||
|
-- List them here for Mikk's FindGlobals script
|
||||||
|
-- GLOBALS: LibStub, IsLoggedIn, geterrorhandler
|
||||||
|
|
||||||
|
--[[
|
||||||
|
xpcall safecall implementation
|
||||||
|
]]
|
||||||
|
local xpcall = xpcall
|
||||||
|
|
||||||
|
local function errorhandler(err)
|
||||||
|
return geterrorhandler()(err)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function CreateDispatcher(argCount)
|
||||||
|
local code = [[
|
||||||
|
local xpcall, eh = ...
|
||||||
|
local method, ARGS
|
||||||
|
local function call() return method(ARGS) end
|
||||||
|
|
||||||
|
local function dispatch(func, ...)
|
||||||
|
method = func
|
||||||
|
if not method then return end
|
||||||
|
ARGS = ...
|
||||||
|
return xpcall(call, eh)
|
||||||
|
end
|
||||||
|
|
||||||
|
return dispatch
|
||||||
|
]]
|
||||||
|
|
||||||
|
local ARGS = {}
|
||||||
|
for i = 1, argCount do ARGS[i] = "arg"..i end
|
||||||
|
code = code:gsub("ARGS", tconcat(ARGS, ", "))
|
||||||
|
return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler)
|
||||||
|
end
|
||||||
|
|
||||||
|
local Dispatchers = setmetatable({}, {__index=function(self, argCount)
|
||||||
|
local dispatcher = CreateDispatcher(argCount)
|
||||||
|
rawset(self, argCount, dispatcher)
|
||||||
|
return dispatcher
|
||||||
|
end})
|
||||||
|
Dispatchers[0] = function(func)
|
||||||
|
return xpcall(func, errorhandler)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function safecall(func, ...)
|
||||||
|
-- we check to see if the func is passed is actually a function here and don't error when it isn't
|
||||||
|
-- this safecall is used for optional functions like OnInitialize OnEnable etc. When they are not
|
||||||
|
-- present execution should continue without hinderance
|
||||||
|
if type(func) == "function" then
|
||||||
|
return Dispatchers[select('#', ...)](func, ...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- local functions that will be implemented further down
|
||||||
|
local Enable, Disable, EnableModule, DisableModule, Embed, NewModule, GetModule, GetName, SetDefaultModuleState, SetDefaultModuleLibraries, SetEnabledState, SetDefaultModulePrototype
|
||||||
|
|
||||||
|
-- used in the addon metatable
|
||||||
|
local function addontostring( self ) return self.name end
|
||||||
|
|
||||||
|
-- Check if the addon is queued for initialization
|
||||||
|
local function queuedForInitialization(addon)
|
||||||
|
for i = 1, #AceAddon.initializequeue do
|
||||||
|
if AceAddon.initializequeue[i] == addon then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Create a new AceAddon-3.0 addon.
|
||||||
|
-- Any libraries you specified will be embeded, and the addon will be scheduled for
|
||||||
|
-- its OnInitialize and OnEnable callbacks.
|
||||||
|
-- The final addon object, with all libraries embeded, will be returned.
|
||||||
|
-- @paramsig [object ,]name[, lib, ...]
|
||||||
|
-- @param object Table to use as a base for the addon (optional)
|
||||||
|
-- @param name Name of the addon object to create
|
||||||
|
-- @param lib List of libraries to embed into the addon
|
||||||
|
-- @usage
|
||||||
|
-- -- Create a simple addon object
|
||||||
|
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceEvent-3.0")
|
||||||
|
--
|
||||||
|
-- -- Create a Addon object based on the table of a frame
|
||||||
|
-- local MyFrame = CreateFrame("Frame")
|
||||||
|
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon(MyFrame, "MyAddon", "AceEvent-3.0")
|
||||||
|
function AceAddon:NewAddon(objectorname, ...)
|
||||||
|
local object,name
|
||||||
|
local i=1
|
||||||
|
if type(objectorname)=="table" then
|
||||||
|
object=objectorname
|
||||||
|
name=...
|
||||||
|
i=2
|
||||||
|
else
|
||||||
|
name=objectorname
|
||||||
|
end
|
||||||
|
if type(name)~="string" then
|
||||||
|
error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2)
|
||||||
|
end
|
||||||
|
if self.addons[name] then
|
||||||
|
error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon '%s' already exists."):format(name), 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
object = object or {}
|
||||||
|
object.name = name
|
||||||
|
|
||||||
|
local addonmeta = {}
|
||||||
|
local oldmeta = getmetatable(object)
|
||||||
|
if oldmeta then
|
||||||
|
for k, v in pairs(oldmeta) do addonmeta[k] = v end
|
||||||
|
end
|
||||||
|
addonmeta.__tostring = addontostring
|
||||||
|
|
||||||
|
setmetatable( object, addonmeta )
|
||||||
|
self.addons[name] = object
|
||||||
|
object.modules = {}
|
||||||
|
object.orderedModules = {}
|
||||||
|
object.defaultModuleLibraries = {}
|
||||||
|
Embed( object ) -- embed NewModule, GetModule methods
|
||||||
|
self:EmbedLibraries(object, select(i,...))
|
||||||
|
|
||||||
|
-- add to queue of addons to be initialized upon ADDON_LOADED
|
||||||
|
tinsert(self.initializequeue, object)
|
||||||
|
return object
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Get the addon object by its name from the internal AceAddon registry.
|
||||||
|
-- Throws an error if the addon object cannot be found (except if silent is set).
|
||||||
|
-- @param name unique name of the addon object
|
||||||
|
-- @param silent if true, the addon is optional, silently return nil if its not found
|
||||||
|
-- @usage
|
||||||
|
-- -- Get the Addon
|
||||||
|
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||||
|
function AceAddon:GetAddon(name, silent)
|
||||||
|
if not silent and not self.addons[name] then
|
||||||
|
error(("Usage: GetAddon(name): 'name' - Cannot find an AceAddon '%s'."):format(tostring(name)), 2)
|
||||||
|
end
|
||||||
|
return self.addons[name]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- - Embed a list of libraries into the specified addon.
|
||||||
|
-- This function will try to embed all of the listed libraries into the addon
|
||||||
|
-- and error if a single one fails.
|
||||||
|
--
|
||||||
|
-- **Note:** This function is for internal use by :NewAddon/:NewModule
|
||||||
|
-- @paramsig addon, [lib, ...]
|
||||||
|
-- @param addon addon object to embed the libs in
|
||||||
|
-- @param lib List of libraries to embed into the addon
|
||||||
|
function AceAddon:EmbedLibraries(addon, ...)
|
||||||
|
for i=1,select("#", ... ) do
|
||||||
|
local libname = select(i, ...)
|
||||||
|
self:EmbedLibrary(addon, libname, false, 4)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- - Embed a library into the addon object.
|
||||||
|
-- This function will check if the specified library is registered with LibStub
|
||||||
|
-- and if it has a :Embed function to call. It'll error if any of those conditions
|
||||||
|
-- fails.
|
||||||
|
--
|
||||||
|
-- **Note:** This function is for internal use by :EmbedLibraries
|
||||||
|
-- @paramsig addon, libname[, silent[, offset]]
|
||||||
|
-- @param addon addon object to embed the library in
|
||||||
|
-- @param libname name of the library to embed
|
||||||
|
-- @param silent marks an embed to fail silently if the library doesn't exist (optional)
|
||||||
|
-- @param offset will push the error messages back to said offset, defaults to 2 (optional)
|
||||||
|
function AceAddon:EmbedLibrary(addon, libname, silent, offset)
|
||||||
|
local lib = LibStub:GetLibrary(libname, true)
|
||||||
|
if not lib and not silent then
|
||||||
|
error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Cannot find a library instance of %q."):format(tostring(libname)), offset or 2)
|
||||||
|
elseif lib and type(lib.Embed) == "function" then
|
||||||
|
lib:Embed(addon)
|
||||||
|
tinsert(self.embeds[addon], libname)
|
||||||
|
return true
|
||||||
|
elseif lib then
|
||||||
|
error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Library '%s' is not Embed capable"):format(libname), offset or 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Return the specified module from an addon object.
|
||||||
|
-- Throws an error if the addon object cannot be found (except if silent is set)
|
||||||
|
-- @name //addon//:GetModule
|
||||||
|
-- @paramsig name[, silent]
|
||||||
|
-- @param name unique name of the module
|
||||||
|
-- @param silent if true, the module is optional, silently return nil if its not found (optional)
|
||||||
|
-- @usage
|
||||||
|
-- -- Get the Addon
|
||||||
|
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||||
|
-- -- Get the Module
|
||||||
|
-- MyModule = MyAddon:GetModule("MyModule")
|
||||||
|
function GetModule(self, name, silent)
|
||||||
|
if not self.modules[name] and not silent then
|
||||||
|
error(("Usage: GetModule(name, silent): 'name' - Cannot find module '%s'."):format(tostring(name)), 2)
|
||||||
|
end
|
||||||
|
return self.modules[name]
|
||||||
|
end
|
||||||
|
|
||||||
|
local function IsModuleTrue(self) return true end
|
||||||
|
|
||||||
|
--- Create a new module for the addon.
|
||||||
|
-- The new module can have its own embeded libraries and/or use a module prototype to be mixed into the module.\\
|
||||||
|
-- A module has the same functionality as a real addon, it can have modules of its own, and has the same API as
|
||||||
|
-- an addon object.
|
||||||
|
-- @name //addon//:NewModule
|
||||||
|
-- @paramsig name[, prototype|lib[, lib, ...]]
|
||||||
|
-- @param name unique name of the module
|
||||||
|
-- @param prototype object to derive this module from, methods and values from this table will be mixed into the module (optional)
|
||||||
|
-- @param lib List of libraries to embed into the addon
|
||||||
|
-- @usage
|
||||||
|
-- -- Create a module with some embeded libraries
|
||||||
|
-- MyModule = MyAddon:NewModule("MyModule", "AceEvent-3.0", "AceHook-3.0")
|
||||||
|
--
|
||||||
|
-- -- Create a module with a prototype
|
||||||
|
-- local prototype = { OnEnable = function(self) print("OnEnable called!") end }
|
||||||
|
-- MyModule = MyAddon:NewModule("MyModule", prototype, "AceEvent-3.0", "AceHook-3.0")
|
||||||
|
function NewModule(self, name, prototype, ...)
|
||||||
|
if type(name) ~= "string" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2) end
|
||||||
|
if type(prototype) ~= "string" and type(prototype) ~= "table" and type(prototype) ~= "nil" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'prototype' - table (prototype), string (lib) or nil expected got '%s'."):format(type(prototype)), 2) end
|
||||||
|
|
||||||
|
if self.modules[name] then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - Module '%s' already exists."):format(name), 2) end
|
||||||
|
|
||||||
|
-- modules are basically addons. We treat them as such. They will be added to the initializequeue properly as well.
|
||||||
|
-- NewModule can only be called after the parent addon is present thus the modules will be initialized after their parent is.
|
||||||
|
local module = AceAddon:NewAddon(fmt("%s_%s", self.name or tostring(self), name))
|
||||||
|
|
||||||
|
module.IsModule = IsModuleTrue
|
||||||
|
module:SetEnabledState(self.defaultModuleState)
|
||||||
|
module.moduleName = name
|
||||||
|
|
||||||
|
if type(prototype) == "string" then
|
||||||
|
AceAddon:EmbedLibraries(module, prototype, ...)
|
||||||
|
else
|
||||||
|
AceAddon:EmbedLibraries(module, ...)
|
||||||
|
end
|
||||||
|
AceAddon:EmbedLibraries(module, unpack(self.defaultModuleLibraries))
|
||||||
|
|
||||||
|
if not prototype or type(prototype) == "string" then
|
||||||
|
prototype = self.defaultModulePrototype or nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(prototype) == "table" then
|
||||||
|
local mt = getmetatable(module)
|
||||||
|
mt.__index = prototype
|
||||||
|
setmetatable(module, mt) -- More of a Base class type feel.
|
||||||
|
end
|
||||||
|
|
||||||
|
safecall(self.OnModuleCreated, self, module) -- Was in Ace2 and I think it could be a cool thing to have handy.
|
||||||
|
self.modules[name] = module
|
||||||
|
tinsert(self.orderedModules, module)
|
||||||
|
|
||||||
|
return module
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Returns the real name of the addon or module, without any prefix.
|
||||||
|
-- @name //addon//:GetName
|
||||||
|
-- @paramsig
|
||||||
|
-- @usage
|
||||||
|
-- print(MyAddon:GetName())
|
||||||
|
-- -- prints "MyAddon"
|
||||||
|
function GetName(self)
|
||||||
|
return self.moduleName or self.name
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Enables the Addon, if possible, return true or false depending on success.
|
||||||
|
-- This internally calls AceAddon:EnableAddon(), thus dispatching a OnEnable callback
|
||||||
|
-- and enabling all modules of the addon (unless explicitly disabled).\\
|
||||||
|
-- :Enable() also sets the internal `enableState` variable to true
|
||||||
|
-- @name //addon//:Enable
|
||||||
|
-- @paramsig
|
||||||
|
-- @usage
|
||||||
|
-- -- Enable MyModule
|
||||||
|
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||||
|
-- MyModule = MyAddon:GetModule("MyModule")
|
||||||
|
-- MyModule:Enable()
|
||||||
|
function Enable(self)
|
||||||
|
self:SetEnabledState(true)
|
||||||
|
|
||||||
|
-- nevcairiel 2013-04-27: don't enable an addon/module if its queued for init still
|
||||||
|
-- it'll be enabled after the init process
|
||||||
|
if not queuedForInitialization(self) then
|
||||||
|
return AceAddon:EnableAddon(self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Disables the Addon, if possible, return true or false depending on success.
|
||||||
|
-- This internally calls AceAddon:DisableAddon(), thus dispatching a OnDisable callback
|
||||||
|
-- and disabling all modules of the addon.\\
|
||||||
|
-- :Disable() also sets the internal `enableState` variable to false
|
||||||
|
-- @name //addon//:Disable
|
||||||
|
-- @paramsig
|
||||||
|
-- @usage
|
||||||
|
-- -- Disable MyAddon
|
||||||
|
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||||
|
-- MyAddon:Disable()
|
||||||
|
function Disable(self)
|
||||||
|
self:SetEnabledState(false)
|
||||||
|
return AceAddon:DisableAddon(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Enables the Module, if possible, return true or false depending on success.
|
||||||
|
-- Short-hand function that retrieves the module via `:GetModule` and calls `:Enable` on the module object.
|
||||||
|
-- @name //addon//:EnableModule
|
||||||
|
-- @paramsig name
|
||||||
|
-- @usage
|
||||||
|
-- -- Enable MyModule using :GetModule
|
||||||
|
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||||
|
-- MyModule = MyAddon:GetModule("MyModule")
|
||||||
|
-- MyModule:Enable()
|
||||||
|
--
|
||||||
|
-- -- Enable MyModule using the short-hand
|
||||||
|
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||||
|
-- MyAddon:EnableModule("MyModule")
|
||||||
|
function EnableModule(self, name)
|
||||||
|
local module = self:GetModule( name )
|
||||||
|
return module:Enable()
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Disables the Module, if possible, return true or false depending on success.
|
||||||
|
-- Short-hand function that retrieves the module via `:GetModule` and calls `:Disable` on the module object.
|
||||||
|
-- @name //addon//:DisableModule
|
||||||
|
-- @paramsig name
|
||||||
|
-- @usage
|
||||||
|
-- -- Disable MyModule using :GetModule
|
||||||
|
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||||
|
-- MyModule = MyAddon:GetModule("MyModule")
|
||||||
|
-- MyModule:Disable()
|
||||||
|
--
|
||||||
|
-- -- Disable MyModule using the short-hand
|
||||||
|
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||||
|
-- MyAddon:DisableModule("MyModule")
|
||||||
|
function DisableModule(self, name)
|
||||||
|
local module = self:GetModule( name )
|
||||||
|
return module:Disable()
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Set the default libraries to be mixed into all modules created by this object.
|
||||||
|
-- Note that you can only change the default module libraries before any module is created.
|
||||||
|
-- @name //addon//:SetDefaultModuleLibraries
|
||||||
|
-- @paramsig lib[, lib, ...]
|
||||||
|
-- @param lib List of libraries to embed into the addon
|
||||||
|
-- @usage
|
||||||
|
-- -- Create the addon object
|
||||||
|
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
|
||||||
|
-- -- Configure default libraries for modules (all modules need AceEvent-3.0)
|
||||||
|
-- MyAddon:SetDefaultModuleLibraries("AceEvent-3.0")
|
||||||
|
-- -- Create a module
|
||||||
|
-- MyModule = MyAddon:NewModule("MyModule")
|
||||||
|
function SetDefaultModuleLibraries(self, ...)
|
||||||
|
if next(self.modules) then
|
||||||
|
error("Usage: SetDefaultModuleLibraries(...): cannot change the module defaults after a module has been registered.", 2)
|
||||||
|
end
|
||||||
|
self.defaultModuleLibraries = {...}
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Set the default state in which new modules are being created.
|
||||||
|
-- Note that you can only change the default state before any module is created.
|
||||||
|
-- @name //addon//:SetDefaultModuleState
|
||||||
|
-- @paramsig state
|
||||||
|
-- @param state Default state for new modules, true for enabled, false for disabled
|
||||||
|
-- @usage
|
||||||
|
-- -- Create the addon object
|
||||||
|
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
|
||||||
|
-- -- Set the default state to "disabled"
|
||||||
|
-- MyAddon:SetDefaultModuleState(false)
|
||||||
|
-- -- Create a module and explicilty enable it
|
||||||
|
-- MyModule = MyAddon:NewModule("MyModule")
|
||||||
|
-- MyModule:Enable()
|
||||||
|
function SetDefaultModuleState(self, state)
|
||||||
|
if next(self.modules) then
|
||||||
|
error("Usage: SetDefaultModuleState(state): cannot change the module defaults after a module has been registered.", 2)
|
||||||
|
end
|
||||||
|
self.defaultModuleState = state
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Set the default prototype to use for new modules on creation.
|
||||||
|
-- Note that you can only change the default prototype before any module is created.
|
||||||
|
-- @name //addon//:SetDefaultModulePrototype
|
||||||
|
-- @paramsig prototype
|
||||||
|
-- @param prototype Default prototype for the new modules (table)
|
||||||
|
-- @usage
|
||||||
|
-- -- Define a prototype
|
||||||
|
-- local prototype = { OnEnable = function(self) print("OnEnable called!") end }
|
||||||
|
-- -- Set the default prototype
|
||||||
|
-- MyAddon:SetDefaultModulePrototype(prototype)
|
||||||
|
-- -- Create a module and explicitly Enable it
|
||||||
|
-- MyModule = MyAddon:NewModule("MyModule")
|
||||||
|
-- MyModule:Enable()
|
||||||
|
-- -- should print "OnEnable called!" now
|
||||||
|
-- @see NewModule
|
||||||
|
function SetDefaultModulePrototype(self, prototype)
|
||||||
|
if next(self.modules) then
|
||||||
|
error("Usage: SetDefaultModulePrototype(prototype): cannot change the module defaults after a module has been registered.", 2)
|
||||||
|
end
|
||||||
|
if type(prototype) ~= "table" then
|
||||||
|
error(("Usage: SetDefaultModulePrototype(prototype): 'prototype' - table expected got '%s'."):format(type(prototype)), 2)
|
||||||
|
end
|
||||||
|
self.defaultModulePrototype = prototype
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Set the state of an addon or module
|
||||||
|
-- This should only be called before any enabling actually happend, e.g. in/before OnInitialize.
|
||||||
|
-- @name //addon//:SetEnabledState
|
||||||
|
-- @paramsig state
|
||||||
|
-- @param state the state of an addon or module (enabled=true, disabled=false)
|
||||||
|
function SetEnabledState(self, state)
|
||||||
|
self.enabledState = state
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Return an iterator of all modules associated to the addon.
|
||||||
|
-- @name //addon//:IterateModules
|
||||||
|
-- @paramsig
|
||||||
|
-- @usage
|
||||||
|
-- -- Enable all modules
|
||||||
|
-- for name, module in MyAddon:IterateModules() do
|
||||||
|
-- module:Enable()
|
||||||
|
-- end
|
||||||
|
local function IterateModules(self) return pairs(self.modules) end
|
||||||
|
|
||||||
|
-- Returns an iterator of all embeds in the addon
|
||||||
|
-- @name //addon//:IterateEmbeds
|
||||||
|
-- @paramsig
|
||||||
|
local function IterateEmbeds(self) return pairs(AceAddon.embeds[self]) end
|
||||||
|
|
||||||
|
--- Query the enabledState of an addon.
|
||||||
|
-- @name //addon//:IsEnabled
|
||||||
|
-- @paramsig
|
||||||
|
-- @usage
|
||||||
|
-- if MyAddon:IsEnabled() then
|
||||||
|
-- MyAddon:Disable()
|
||||||
|
-- end
|
||||||
|
local function IsEnabled(self) return self.enabledState end
|
||||||
|
local mixins = {
|
||||||
|
NewModule = NewModule,
|
||||||
|
GetModule = GetModule,
|
||||||
|
Enable = Enable,
|
||||||
|
Disable = Disable,
|
||||||
|
EnableModule = EnableModule,
|
||||||
|
DisableModule = DisableModule,
|
||||||
|
IsEnabled = IsEnabled,
|
||||||
|
SetDefaultModuleLibraries = SetDefaultModuleLibraries,
|
||||||
|
SetDefaultModuleState = SetDefaultModuleState,
|
||||||
|
SetDefaultModulePrototype = SetDefaultModulePrototype,
|
||||||
|
SetEnabledState = SetEnabledState,
|
||||||
|
IterateModules = IterateModules,
|
||||||
|
IterateEmbeds = IterateEmbeds,
|
||||||
|
GetName = GetName,
|
||||||
|
}
|
||||||
|
local function IsModule(self) return false end
|
||||||
|
local pmixins = {
|
||||||
|
defaultModuleState = true,
|
||||||
|
enabledState = true,
|
||||||
|
IsModule = IsModule,
|
||||||
|
}
|
||||||
|
-- Embed( target )
|
||||||
|
-- target (object) - target object to embed aceaddon in
|
||||||
|
--
|
||||||
|
-- this is a local function specifically since it's meant to be only called internally
|
||||||
|
function Embed(target, skipPMixins)
|
||||||
|
for k, v in pairs(mixins) do
|
||||||
|
target[k] = v
|
||||||
|
end
|
||||||
|
if not skipPMixins then
|
||||||
|
for k, v in pairs(pmixins) do
|
||||||
|
target[k] = target[k] or v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- - Initialize the addon after creation.
|
||||||
|
-- This function is only used internally during the ADDON_LOADED event
|
||||||
|
-- It will call the **OnInitialize** function on the addon object (if present),
|
||||||
|
-- and the **OnEmbedInitialize** function on all embeded libraries.
|
||||||
|
--
|
||||||
|
-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing.
|
||||||
|
-- @param addon addon object to intialize
|
||||||
|
function AceAddon:InitializeAddon(addon)
|
||||||
|
safecall(addon.OnInitialize, addon)
|
||||||
|
|
||||||
|
local embeds = self.embeds[addon]
|
||||||
|
for i = 1, #embeds do
|
||||||
|
local lib = LibStub:GetLibrary(embeds[i], true)
|
||||||
|
if lib then safecall(lib.OnEmbedInitialize, lib, addon) end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- we don't call InitializeAddon on modules specifically, this is handled
|
||||||
|
-- from the event handler and only done _once_
|
||||||
|
end
|
||||||
|
|
||||||
|
-- - Enable the addon after creation.
|
||||||
|
-- Note: This function is only used internally during the PLAYER_LOGIN event, or during ADDON_LOADED,
|
||||||
|
-- if IsLoggedIn() already returns true at that point, e.g. for LoD Addons.
|
||||||
|
-- It will call the **OnEnable** function on the addon object (if present),
|
||||||
|
-- and the **OnEmbedEnable** function on all embeded libraries.\\
|
||||||
|
-- This function does not toggle the enable state of the addon itself, and will return early if the addon is disabled.
|
||||||
|
--
|
||||||
|
-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing.
|
||||||
|
-- Use :Enable on the addon itself instead.
|
||||||
|
-- @param addon addon object to enable
|
||||||
|
function AceAddon:EnableAddon(addon)
|
||||||
|
if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end
|
||||||
|
if self.statuses[addon.name] or not addon.enabledState then return false end
|
||||||
|
|
||||||
|
-- set the statuses first, before calling the OnEnable. this allows for Disabling of the addon in OnEnable.
|
||||||
|
self.statuses[addon.name] = true
|
||||||
|
|
||||||
|
safecall(addon.OnEnable, addon)
|
||||||
|
|
||||||
|
-- make sure we're still enabled before continueing
|
||||||
|
if self.statuses[addon.name] then
|
||||||
|
local embeds = self.embeds[addon]
|
||||||
|
for i = 1, #embeds do
|
||||||
|
local lib = LibStub:GetLibrary(embeds[i], true)
|
||||||
|
if lib then safecall(lib.OnEmbedEnable, lib, addon) end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- enable possible modules.
|
||||||
|
local modules = addon.orderedModules
|
||||||
|
for i = 1, #modules do
|
||||||
|
self:EnableAddon(modules[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self.statuses[addon.name] -- return true if we're disabled
|
||||||
|
end
|
||||||
|
|
||||||
|
-- - Disable the addon
|
||||||
|
-- Note: This function is only used internally.
|
||||||
|
-- It will call the **OnDisable** function on the addon object (if present),
|
||||||
|
-- and the **OnEmbedDisable** function on all embeded libraries.\\
|
||||||
|
-- This function does not toggle the enable state of the addon itself, and will return early if the addon is still enabled.
|
||||||
|
--
|
||||||
|
-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing.
|
||||||
|
-- Use :Disable on the addon itself instead.
|
||||||
|
-- @param addon addon object to enable
|
||||||
|
function AceAddon:DisableAddon(addon)
|
||||||
|
if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end
|
||||||
|
if not self.statuses[addon.name] then return false end
|
||||||
|
|
||||||
|
-- set statuses first before calling OnDisable, this allows for aborting the disable in OnDisable.
|
||||||
|
self.statuses[addon.name] = false
|
||||||
|
|
||||||
|
safecall( addon.OnDisable, addon )
|
||||||
|
|
||||||
|
-- make sure we're still disabling...
|
||||||
|
if not self.statuses[addon.name] then
|
||||||
|
local embeds = self.embeds[addon]
|
||||||
|
for i = 1, #embeds do
|
||||||
|
local lib = LibStub:GetLibrary(embeds[i], true)
|
||||||
|
if lib then safecall(lib.OnEmbedDisable, lib, addon) end
|
||||||
|
end
|
||||||
|
-- disable possible modules.
|
||||||
|
local modules = addon.orderedModules
|
||||||
|
for i = 1, #modules do
|
||||||
|
self:DisableAddon(modules[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return not self.statuses[addon.name] -- return true if we're disabled
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Get an iterator over all registered addons.
|
||||||
|
-- @usage
|
||||||
|
-- -- Print a list of all installed AceAddon's
|
||||||
|
-- for name, addon in AceAddon:IterateAddons() do
|
||||||
|
-- print("Addon: " .. name)
|
||||||
|
-- end
|
||||||
|
function AceAddon:IterateAddons() return pairs(self.addons) end
|
||||||
|
|
||||||
|
--- Get an iterator over the internal status registry.
|
||||||
|
-- @usage
|
||||||
|
-- -- Print a list of all enabled addons
|
||||||
|
-- for name, status in AceAddon:IterateAddonStatus() do
|
||||||
|
-- if status then
|
||||||
|
-- print("EnabledAddon: " .. name)
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
function AceAddon:IterateAddonStatus() return pairs(self.statuses) end
|
||||||
|
|
||||||
|
-- Following Iterators are deprecated, and their addon specific versions should be used
|
||||||
|
-- e.g. addon:IterateEmbeds() instead of :IterateEmbedsOnAddon(addon)
|
||||||
|
function AceAddon:IterateEmbedsOnAddon(addon) return pairs(self.embeds[addon]) end
|
||||||
|
function AceAddon:IterateModulesOfAddon(addon) return pairs(addon.modules) end
|
||||||
|
|
||||||
|
-- Event Handling
|
||||||
|
local function onEvent(this, event, arg1)
|
||||||
|
-- 2011-08-17 nevcairiel - ignore the load event of Blizzard_DebugTools, so a potential startup error isn't swallowed up
|
||||||
|
if (event == "ADDON_LOADED" and arg1 ~= "Blizzard_DebugTools") or event == "PLAYER_LOGIN" then
|
||||||
|
-- if a addon loads another addon, recursion could happen here, so we need to validate the table on every iteration
|
||||||
|
while(#AceAddon.initializequeue > 0) do
|
||||||
|
local addon = tremove(AceAddon.initializequeue, 1)
|
||||||
|
-- this might be an issue with recursion - TODO: validate
|
||||||
|
if event == "ADDON_LOADED" then addon.baseName = arg1 end
|
||||||
|
AceAddon:InitializeAddon(addon)
|
||||||
|
tinsert(AceAddon.enablequeue, addon)
|
||||||
|
end
|
||||||
|
|
||||||
|
if IsLoggedIn() then
|
||||||
|
while(#AceAddon.enablequeue > 0) do
|
||||||
|
local addon = tremove(AceAddon.enablequeue, 1)
|
||||||
|
AceAddon:EnableAddon(addon)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
AceAddon.frame:RegisterEvent("ADDON_LOADED")
|
||||||
|
AceAddon.frame:RegisterEvent("PLAYER_LOGIN")
|
||||||
|
AceAddon.frame:SetScript("OnEvent", onEvent)
|
||||||
|
|
||||||
|
-- upgrade embeded
|
||||||
|
for name, addon in pairs(AceAddon.addons) do
|
||||||
|
Embed(addon, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 2010-10-27 nevcairiel - add new "orderedModules" table
|
||||||
|
if oldminor and oldminor < 10 then
|
||||||
|
for name, addon in pairs(AceAddon.addons) do
|
||||||
|
addon.orderedModules = {}
|
||||||
|
for module_name, module in pairs(addon.modules) do
|
||||||
|
tinsert(addon.orderedModules, module)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
4
Libraries/AceAddon-3.0/AceAddon-3.0.xml
Normal file
4
Libraries/AceAddon-3.0/AceAddon-3.0.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||||
|
..\FrameXML\UI.xsd">
|
||||||
|
<Script file="AceAddon-3.0.lua"/>
|
||||||
|
</Ui>
|
||||||
137
Libraries/AceLocale-3.0/AceLocale-3.0.lua
Normal file
137
Libraries/AceLocale-3.0/AceLocale-3.0.lua
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
--- **AceLocale-3.0** manages localization in addons, allowing for multiple locale to be registered with fallback to the base locale for untranslated strings.
|
||||||
|
-- @class file
|
||||||
|
-- @name AceLocale-3.0
|
||||||
|
-- @release $Id: AceLocale-3.0.lua 1035 2011-07-09 03:20:13Z kaelten $
|
||||||
|
local MAJOR,MINOR = "AceLocale-3.0", 6
|
||||||
|
|
||||||
|
local AceLocale, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||||
|
|
||||||
|
if not AceLocale then return end -- no upgrade needed
|
||||||
|
|
||||||
|
-- Lua APIs
|
||||||
|
local assert, tostring, error = assert, tostring, error
|
||||||
|
local getmetatable, setmetatable, rawset, rawget = getmetatable, setmetatable, rawset, rawget
|
||||||
|
|
||||||
|
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||||
|
-- List them here for Mikk's FindGlobals script
|
||||||
|
-- GLOBALS: GAME_LOCALE, geterrorhandler
|
||||||
|
|
||||||
|
local gameLocale = GetLocale()
|
||||||
|
if gameLocale == "enGB" then
|
||||||
|
gameLocale = "enUS"
|
||||||
|
end
|
||||||
|
|
||||||
|
AceLocale.apps = AceLocale.apps or {} -- array of ["AppName"]=localetableref
|
||||||
|
AceLocale.appnames = AceLocale.appnames or {} -- array of [localetableref]="AppName"
|
||||||
|
|
||||||
|
-- This metatable is used on all tables returned from GetLocale
|
||||||
|
local readmeta = {
|
||||||
|
__index = function(self, key) -- requesting totally unknown entries: fire off a nonbreaking error and return key
|
||||||
|
rawset(self, key, key) -- only need to see the warning once, really
|
||||||
|
geterrorhandler()(MAJOR..": "..tostring(AceLocale.appnames[self])..": Missing entry for '"..tostring(key).."'")
|
||||||
|
return key
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
-- This metatable is used on all tables returned from GetLocale if the silent flag is true, it does not issue a warning on unknown keys
|
||||||
|
local readmetasilent = {
|
||||||
|
__index = function(self, key) -- requesting totally unknown entries: return key
|
||||||
|
rawset(self, key, key) -- only need to invoke this function once
|
||||||
|
return key
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Remember the locale table being registered right now (it gets set by :NewLocale())
|
||||||
|
-- NOTE: Do never try to register 2 locale tables at once and mix their definition.
|
||||||
|
local registering
|
||||||
|
|
||||||
|
-- local assert false function
|
||||||
|
local assertfalse = function() assert(false) end
|
||||||
|
|
||||||
|
-- This metatable proxy is used when registering nondefault locales
|
||||||
|
local writeproxy = setmetatable({}, {
|
||||||
|
__newindex = function(self, key, value)
|
||||||
|
rawset(registering, key, value == true and key or value) -- assigning values: replace 'true' with key string
|
||||||
|
end,
|
||||||
|
__index = assertfalse
|
||||||
|
})
|
||||||
|
|
||||||
|
-- This metatable proxy is used when registering the default locale.
|
||||||
|
-- It refuses to overwrite existing values
|
||||||
|
-- Reason 1: Allows loading locales in any order
|
||||||
|
-- Reason 2: If 2 modules have the same string, but only the first one to be
|
||||||
|
-- loaded has a translation for the current locale, the translation
|
||||||
|
-- doesn't get overwritten.
|
||||||
|
--
|
||||||
|
local writedefaultproxy = setmetatable({}, {
|
||||||
|
__newindex = function(self, key, value)
|
||||||
|
if not rawget(registering, key) then
|
||||||
|
rawset(registering, key, value == true and key or value)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
__index = assertfalse
|
||||||
|
})
|
||||||
|
|
||||||
|
--- Register a new locale (or extend an existing one) for the specified application.
|
||||||
|
-- :NewLocale will return a table you can fill your locale into, or nil if the locale isn't needed for the players
|
||||||
|
-- game locale.
|
||||||
|
-- @paramsig application, locale[, isDefault[, silent]]
|
||||||
|
-- @param application Unique name of addon / module
|
||||||
|
-- @param locale Name of the locale to register, e.g. "enUS", "deDE", etc.
|
||||||
|
-- @param isDefault If this is the default locale being registered (your addon is written in this language, generally enUS)
|
||||||
|
-- @param silent If true, the locale will not issue warnings for missing keys. Must be set on the first locale registered. If set to "raw", nils will be returned for unknown keys (no metatable used).
|
||||||
|
-- @usage
|
||||||
|
-- -- enUS.lua
|
||||||
|
-- local L = LibStub("AceLocale-3.0"):NewLocale("TestLocale", "enUS", true)
|
||||||
|
-- L["string1"] = true
|
||||||
|
--
|
||||||
|
-- -- deDE.lua
|
||||||
|
-- local L = LibStub("AceLocale-3.0"):NewLocale("TestLocale", "deDE")
|
||||||
|
-- if not L then return end
|
||||||
|
-- L["string1"] = "Zeichenkette1"
|
||||||
|
-- @return Locale Table to add localizations to, or nil if the current locale is not required.
|
||||||
|
function AceLocale:NewLocale(application, locale, isDefault, silent)
|
||||||
|
|
||||||
|
-- GAME_LOCALE allows translators to test translations of addons without having that wow client installed
|
||||||
|
local gameLocale = GAME_LOCALE or gameLocale
|
||||||
|
|
||||||
|
local app = AceLocale.apps[application]
|
||||||
|
|
||||||
|
if silent and app and getmetatable(app) ~= readmetasilent then
|
||||||
|
geterrorhandler()("Usage: NewLocale(application, locale[, isDefault[, silent]]): 'silent' must be specified for the first locale registered")
|
||||||
|
end
|
||||||
|
|
||||||
|
if not app then
|
||||||
|
if silent=="raw" then
|
||||||
|
app = {}
|
||||||
|
else
|
||||||
|
app = setmetatable({}, silent and readmetasilent or readmeta)
|
||||||
|
end
|
||||||
|
AceLocale.apps[application] = app
|
||||||
|
AceLocale.appnames[app] = application
|
||||||
|
end
|
||||||
|
|
||||||
|
if locale ~= gameLocale and not isDefault then
|
||||||
|
return -- nop, we don't need these translations
|
||||||
|
end
|
||||||
|
|
||||||
|
registering = app -- remember globally for writeproxy and writedefaultproxy
|
||||||
|
|
||||||
|
if isDefault then
|
||||||
|
return writedefaultproxy
|
||||||
|
end
|
||||||
|
|
||||||
|
return writeproxy
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Returns localizations for the current locale (or default locale if translations are missing).
|
||||||
|
-- Errors if nothing is registered (spank developer, not just a missing translation)
|
||||||
|
-- @param application Unique name of addon / module
|
||||||
|
-- @param silent If true, the locale is optional, silently return nil if it's not found (defaults to false, optional)
|
||||||
|
-- @return The locale table for the current language.
|
||||||
|
function AceLocale:GetLocale(application, silent)
|
||||||
|
if not silent and not AceLocale.apps[application] then
|
||||||
|
error("Usage: GetLocale(application[, silent]): 'application' - No locales registered for '"..tostring(application).."'", 2)
|
||||||
|
end
|
||||||
|
return AceLocale.apps[application]
|
||||||
|
end
|
||||||
4
Libraries/AceLocale-3.0/AceLocale-3.0.xml
Normal file
4
Libraries/AceLocale-3.0/AceLocale-3.0.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||||
|
..\FrameXML\UI.xsd">
|
||||||
|
<Script file="AceLocale-3.0.lua"/>
|
||||||
|
</Ui>
|
||||||
4
Libraries/Load_Libraries.xml
Normal file
4
Libraries/Load_Libraries.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<Ui xmlns="http://www.blizzard.com/wow/ui/">
|
||||||
|
<Include file="AceAddon-3.0\AceAddon-3.0.xml"/>
|
||||||
|
<Include file="AceLocale-3.0\AceLocale-3.0.xml"/>
|
||||||
|
</Ui>
|
||||||
4
Locale/Load_Locales.xml
Normal file
4
Locale/Load_Locales.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<Ui xmlns="http://www.blizzard.com/wow/ui/">
|
||||||
|
<Script file="frFR.lua"/>
|
||||||
|
<Script file="usEN.lua"/>
|
||||||
|
</Ui>
|
||||||
9
Locale/frFR.lua
Normal file
9
Locale/frFR.lua
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
local AceLocale = LibStub:GetLibrary("AceLocale-3.0");
|
||||||
|
local L = AceLocale:NewLocale("MxW.Farm", "frFR");
|
||||||
|
if not L then return; end
|
||||||
|
|
||||||
|
-- MainForm
|
||||||
|
L["MxW_MainForm_Live"] = "|cFF00FF00Actu: %.2fg|r (|cFFFFD100%.1f/h|r) |cFF888888%s|r"
|
||||||
|
L["MxW_MainForm_Bag"] = "|cFF00FFFFSac: %.2fg|r (|cffffd700%dg|r)"
|
||||||
|
L["MxW_MainForm_Day"] = "Jour %s"
|
||||||
|
L["MxW_MainForm_Month"] = "Mois %s"
|
||||||
9
Locale/usEN.lua
Normal file
9
Locale/usEN.lua
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
local AceLocale = LibStub:GetLibrary("AceLocale-3.0");
|
||||||
|
local L = AceLocale:NewLocale("MxW.Farm", "enUS");
|
||||||
|
if not L then return; end
|
||||||
|
|
||||||
|
-- MainForm
|
||||||
|
L["MxW_MainForm_Live"] = "|cFF00FF00Live: %.2fg|r (|cFFFFD100%.1f/h|r) |cFF888888%s|r"
|
||||||
|
L["MxW_MainForm_Bag"] = "|cFF00FFFFSac: %.2fg|r (|cffffd700%dg|r)"
|
||||||
|
L["MxW_MainForm_Day"] = "Day %s"
|
||||||
|
L["MxW_MainForm_Month"] = "Month %s"
|
||||||
832
Main.lua
832
Main.lua
@@ -1,41 +1,62 @@
|
|||||||
-- 1. Persistent Data & Session Initialization
|
local MX = LibStub("AceAddon-3.0"):NewAddon("MxW.Farm");
|
||||||
FarmTrackerDB = FarmTrackerDB or {
|
local L = LibStub("AceLocale-3.0"):GetLocale("MxW.Farm");
|
||||||
items = {2840, 2841, 2770},
|
|
||||||
locked = false,
|
|
||||||
goal = 0,
|
|
||||||
pos = nil,
|
|
||||||
scale = 1.0
|
|
||||||
}
|
|
||||||
local sessionStartCounts = {}
|
|
||||||
local startTime = GetTime()
|
|
||||||
local isInitialized = false
|
|
||||||
local hoverButtons = {}
|
|
||||||
local goalReachedSoundPlayed = false
|
|
||||||
|
|
||||||
-- 2. Create the Main Tracker Frame
|
local date = C_DateAndTime.GetCurrentCalendarTime();
|
||||||
local f = CreateFrame("Frame", "FarmTrackerFrame", UIParent, "BackdropTemplate")
|
local weekday, month, day, year = date.weekday, date.month, date.monthDay, date.year;
|
||||||
f:SetSize(280, 100)
|
|
||||||
f:SetFrameStrata("MEDIUM")
|
|
||||||
f:SetMovable(true)
|
|
||||||
f:EnableMouse(true)
|
|
||||||
f:RegisterForDrag("LeftButton")
|
|
||||||
|
|
||||||
local function SavePosition(self)
|
function MX:OnInitialize()
|
||||||
local point, _, relativePoint, xOfs, yOfs = self:GetPoint()
|
if (LogicDay == nil) then
|
||||||
FarmTrackerDB.pos = {
|
LogicDay = day;
|
||||||
point = point,
|
end
|
||||||
relativePoint = relativePoint,
|
|
||||||
x = xOfs,
|
|
||||||
y = yOfs
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
f:SetScript("OnDragStart", f.StartMoving)
|
-- 1. Data & Initialization
|
||||||
f:SetScript("OnDragStop", function(self)
|
FarmTrackerDB = FarmTrackerDB or {
|
||||||
self:StopMovingOrSizing()
|
items = {2840, 2841, 2770},
|
||||||
SavePosition(self)
|
milestone = 100,
|
||||||
end)
|
autoAdd = true,
|
||||||
|
minValue = 1,
|
||||||
|
goal = 0,
|
||||||
|
minimzed = false,
|
||||||
|
locked = false,
|
||||||
|
scale = 1.0,
|
||||||
|
pos = {
|
||||||
|
y = 0,
|
||||||
|
x = 0,
|
||||||
|
point = "BOTTOMLEFT",
|
||||||
|
relativePoint = "BOTTOMLEFT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
local sessionStartCounts, itemRows = {}, {}
|
||||||
|
local startTime = GetTime()
|
||||||
|
local isInitialized, lastMilestoneReached, lastGoldValue = false, 0, 0
|
||||||
|
local currentGold = GetMoney() -- Initializing for tracking
|
||||||
|
local CUSTOM_FONT = "Interface\\Addons\\MxW.Farm\\Media\\Font\\Consola.ttf"
|
||||||
|
local mxwVersion = C_AddOns.GetAddOnMetadata("MxW.Farm", "Version")
|
||||||
|
|
||||||
|
-- Ensure these are NOT nil
|
||||||
|
local isPaused = false
|
||||||
|
local sessionAccumulatedTime = 0
|
||||||
|
local pauseStartTime = 0
|
||||||
|
|
||||||
|
local function ApplyCustomFont(fs, size, style)
|
||||||
|
if not fs or not fs.SetFont then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local success = style and style ~= "" and pcall(fs.SetFont, fs, CUSTOM_FONT, size or 14, style) or
|
||||||
|
pcall(fs.SetFont, fs, CUSTOM_FONT, size or 14)
|
||||||
|
if not success then
|
||||||
|
fs:SetFontObject("GameFontHighlightSmall")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 2. Main Tracker Frame (Updated Styling)
|
||||||
|
local f = CreateFrame("Frame", "FarmTrackerFrame", UIParent, "BackdropTemplate")
|
||||||
|
f:SetSize(280, 120);
|
||||||
|
f:SetFrameStrata("MEDIUM");
|
||||||
|
f:SetMovable(true);
|
||||||
|
f:EnableMouse(true);
|
||||||
|
f:RegisterForDrag("LeftButton")
|
||||||
f:SetBackdrop({
|
f:SetBackdrop({
|
||||||
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
||||||
edgeFile = "Interface/Buttons/WHITE8x8",
|
edgeFile = "Interface/Buttons/WHITE8x8",
|
||||||
@@ -49,346 +70,557 @@ f:SetBackdrop({
|
|||||||
bottom = 2
|
bottom = 2
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
f:SetBackdropColor(0.20,0.20,0.20,1);
|
f:SetBackdropColor(0.20, 0.20, 0.20, 1)
|
||||||
|
f:SetScript("OnDragStart", f.StartMoving)
|
||||||
f.title = f:CreateFontString(nil, "OVERLAY")
|
f:SetScript("OnDragStop", function(self)
|
||||||
f.title:SetFont("Interface\\Addons\\MxW\\Media\\Font\\Consola.ttf", 14);
|
self:StopMovingOrSizing()
|
||||||
f.title:SetPoint("TOP", f, "TOP", 0, -10)
|
local p, _, rp, x, y = self:GetPoint()
|
||||||
f.title:SetTextColor(1.00,0.49,0.04);
|
FarmTrackerDB.pos = {
|
||||||
f.title:SetText("MxW.Farm")
|
point = p,
|
||||||
|
relativePoint = rp,
|
||||||
f.statsText = f:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
|
x = x,
|
||||||
f.statsText:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 12, 12)
|
y = y
|
||||||
f.statsText:SetJustifyH("LEFT")
|
}
|
||||||
|
|
||||||
f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
|
|
||||||
f.text:SetPoint("BOTTOMLEFT", f.statsText, "TOPLEFT", 0, 10)
|
|
||||||
f.text:SetJustifyH("LEFT")
|
|
||||||
|
|
||||||
-- Buttons: Reset & Manager Toggle
|
|
||||||
f.resetBtn = CreateFrame("Button", nil, f)
|
|
||||||
f.resetBtn:SetSize(18, 18)
|
|
||||||
f.resetBtn:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -10, 10)
|
|
||||||
f.resetBtn:SetNormalTexture("Interface\\Buttons\\UI-RefreshButton")
|
|
||||||
f.resetBtn:SetScript("OnClick", function()
|
|
||||||
for _, id in ipairs(FarmTrackerDB.items) do
|
|
||||||
sessionStartCounts[id] = GetItemCount(id, true)
|
|
||||||
end
|
|
||||||
startTime = GetTime()
|
|
||||||
goalReachedSoundPlayed = false
|
|
||||||
RefreshDisplay()
|
|
||||||
print("|cFF00FF00MxW.Farm:|r Session reset for " .. UnitName("player"))
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
f.configBtn = CreateFrame("Button", nil, f)
|
-- Label - Titleersion
|
||||||
f.configBtn:SetSize(18, 18)
|
f.title = f:CreateFontString(nil, "ARTWORK");
|
||||||
f.configBtn:SetPoint("TOPRIGHT", f, "TOPRIGHT", -8, -8)
|
f.title:SetFont("Interface\\Addons\\MxW\\Media\\Font\\Consola.ttf", 20);
|
||||||
f.configBtn:SetNormalTexture("Interface\\Buttons\\UI-OptionsButton")
|
f.title:SetPoint("TOP", 0, -5);
|
||||||
f.configBtn:SetScript("OnClick", function()
|
f.title:SetTextColor(1.00, 0.49, 0.04);
|
||||||
if FarmTrackerManager:IsShown() then
|
f.title:SetText("MxW");
|
||||||
FarmTrackerManager:Hide()
|
|
||||||
|
-- Label - Version
|
||||||
|
f.version = f:CreateFontString(nil, "ARTWORK");
|
||||||
|
f.version:SetFont("Interface\\Addons\\MxW\\Media\\Font\\Consola.ttf", 12);
|
||||||
|
f.version:SetPoint("TOP", 0, -22);
|
||||||
|
f.version:SetTextColor(1.00, 0.49, 0.04);
|
||||||
|
f.version:SetText(mxwVersion);
|
||||||
|
|
||||||
|
-- f.title = f:CreateFontString(nil, "OVERLAY"); f.title:SetPoint("TOP", 0, -10); ApplyCustomFont(f.title, 14, "OUTLINE"); f.title:SetText("MxW")
|
||||||
|
f.text = f:CreateFontString(nil, "OVERLAY");
|
||||||
|
f.text:SetPoint("TOPLEFT", 12, -35);
|
||||||
|
f.text:SetJustifyH("LEFT");
|
||||||
|
ApplyCustomFont(f.text, 14)
|
||||||
|
|
||||||
|
f.barBG = f:CreateTexture(nil, "BACKGROUND");
|
||||||
|
f.barBG:SetHeight(4);
|
||||||
|
f.barBG:SetPoint("BOTTOMLEFT", 12, 75);
|
||||||
|
f.barBG:SetPoint("BOTTOMRIGHT", -12, 75);
|
||||||
|
f.barBG:SetColorTexture(0.1, 0.1, 0.1, 0.8)
|
||||||
|
f.barFill = f:CreateTexture(nil, "ARTWORK");
|
||||||
|
f.barFill:SetHeight(4);
|
||||||
|
f.barFill:SetPoint("LEFT", f.barBG, "LEFT")
|
||||||
|
|
||||||
|
f.statsText = f:CreateFontString(nil, "OVERLAY");
|
||||||
|
f.statsText:SetPoint("BOTTOMLEFT", 12, 58);
|
||||||
|
ApplyCustomFont(f.statsText, 13)
|
||||||
|
f.invText = f:CreateFontString(nil, "OVERLAY");
|
||||||
|
f.invText:SetPoint("BOTTOMLEFT", 12, 42);
|
||||||
|
ApplyCustomFont(f.invText, 13)
|
||||||
|
|
||||||
|
-- New: MXW Style Global Tracking Section
|
||||||
|
f.line = f:CreateTexture(nil, "ARTWORK");
|
||||||
|
f.line:SetHeight(1);
|
||||||
|
f.line:SetPoint("BOTTOMLEFT", 10, 38);
|
||||||
|
f.line:SetPoint("BOTTOMRIGHT", -10, 38);
|
||||||
|
f.line:SetColorTexture(1, 1, 1, 0.2)
|
||||||
|
f.dailyText = f:CreateFontString(nil, "OVERLAY");
|
||||||
|
f.dailyText:SetPoint("BOTTOMLEFT", 12, 22);
|
||||||
|
ApplyCustomFont(f.dailyText, 14)
|
||||||
|
f.monthlyText = f:CreateFontString(nil, "OVERLAY");
|
||||||
|
f.monthlyText:SetPoint("BOTTOMLEFT", 12, 8);
|
||||||
|
ApplyCustomFont(f.monthlyText, 14)
|
||||||
|
|
||||||
|
-- Pause/Play Button
|
||||||
|
f.pauseBtn = CreateFrame("Button", nil, f)
|
||||||
|
f.pauseBtn:SetSize(16, 16)
|
||||||
|
f.pauseBtn:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Up") -- Default Play look
|
||||||
|
f.pauseBtn:GetNormalTexture():SetVertexColor(0, 1, 0) -- Green for Play
|
||||||
|
|
||||||
|
f.pauseBtn:SetScript("OnClick", function()
|
||||||
|
isPaused = not isPaused
|
||||||
|
if isPaused then
|
||||||
|
pauseStartTime = GetTime()
|
||||||
|
f.pauseBtn:GetNormalTexture():SetVertexColor(1, 0, 0) -- Red for Paused
|
||||||
|
f.pauseBtn:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up")
|
||||||
else
|
else
|
||||||
FarmTrackerManager:Show()
|
-- Add the duration of the pause to the accumulated time
|
||||||
|
sessionAccumulatedTime = sessionAccumulatedTime + (GetTime() - startTime)
|
||||||
|
startTime = GetTime() -- Reset start reference to "now"
|
||||||
|
f.pauseBtn:GetNormalTexture():SetVertexColor(0, 1, 0) -- Green for Play
|
||||||
|
f.pauseBtn:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Up")
|
||||||
end
|
end
|
||||||
|
MX:RefreshDisplay()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- 3. The SCROLLABLE Management UI (Drag & Drop)
|
-- Flash Animation
|
||||||
local m = CreateFrame("Frame", "FarmTrackerManager", UIParent, "BackdropTemplate")
|
f.flash = f:CreateAnimationGroup()
|
||||||
m:SetSize(320, 420)
|
local alpha1 = f.flash:CreateAnimation("Alpha")
|
||||||
m:SetPoint("CENTER")
|
alpha1:SetFromAlpha(1);
|
||||||
m:SetFrameStrata("HIGH")
|
alpha1:SetToAlpha(0.5);
|
||||||
m:SetMovable(true)
|
alpha1:SetDuration(0.2);
|
||||||
m:EnableMouse(true)
|
alpha1:SetOrder(1)
|
||||||
m:RegisterForDrag("LeftButton")
|
local alpha2 = f.flash:CreateAnimation("Alpha")
|
||||||
m:SetScript("OnDragStart", m.StartMoving)
|
alpha2:SetFromAlpha(0.5);
|
||||||
m:SetScript("OnDragStop", m.StopMovingOrSizing)
|
alpha2:SetToAlpha(1);
|
||||||
m:SetBackdrop(f:GetBackdrop())
|
alpha2:SetDuration(0.4);
|
||||||
m:SetBackdropColor(0, 0, 0, 1)
|
alpha2:SetOrder(2)
|
||||||
m:Hide()
|
|
||||||
|
|
||||||
local function AddItemToList(id)
|
local function FlashGreen()
|
||||||
if not id then
|
f:SetBackdropColor(0, 0.5, 0, 1)
|
||||||
return
|
f.flash:Play()
|
||||||
end
|
C_Timer.After(0.6, function()
|
||||||
local found = false
|
f:SetBackdropColor(0.20, 0.20, 0.20, 1)
|
||||||
for _, existing in ipairs(FarmTrackerDB.items) do
|
end)
|
||||||
if existing == id then
|
|
||||||
found = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not found then
|
|
||||||
table.insert(FarmTrackerDB.items, id)
|
|
||||||
sessionStartCounts[id] = GetItemCount(id, true)
|
|
||||||
C_Item.RequestLoadItemDataByID(id)
|
|
||||||
UpdateManagerList()
|
|
||||||
RefreshDisplay()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
m:SetScript("OnReceiveDrag", function()
|
-- 3. Management UI (Matching Styles)
|
||||||
|
local m = CreateFrame("Frame", "FarmTrackerManager", UIParent, "BackdropTemplate")
|
||||||
|
m:SetSize(340, 560);
|
||||||
|
m:SetPoint("CENTER");
|
||||||
|
m:Hide();
|
||||||
|
m:SetMovable(true);
|
||||||
|
m:EnableMouse(true);
|
||||||
|
m:RegisterForDrag("LeftButton")
|
||||||
|
m:SetBackdrop(f:GetBackdrop())
|
||||||
|
m:SetBackdropColor(0.1, 0.1, 0.1, 1)
|
||||||
|
m:SetBackdropBorderColor(0, 0, 0, 1)
|
||||||
|
m:SetScript("OnDragStart", m.StartMoving);
|
||||||
|
m:SetScript("OnDragStop", m.StopMovingOrSizing)
|
||||||
|
|
||||||
|
local function OnReceiveDragItem()
|
||||||
local infoType, itemID = GetCursorInfo()
|
local infoType, itemID = GetCursorInfo()
|
||||||
if infoType == "item" then
|
if infoType == "item" then
|
||||||
AddItemToList(itemID)
|
local id = tonumber(itemID)
|
||||||
|
if id then
|
||||||
|
local exists = false
|
||||||
|
for _, v in ipairs(FarmTrackerDB.items) do
|
||||||
|
if v == id then
|
||||||
|
exists = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not exists then
|
||||||
|
table.insert(FarmTrackerDB.items, id)
|
||||||
|
sessionStartCounts[id] = GetItemCount(id, false)
|
||||||
|
UpdateManagerList();
|
||||||
|
MX:RefreshDisplay()
|
||||||
|
end
|
||||||
|
end
|
||||||
ClearCursor()
|
ClearCursor()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
m:SetScript("OnReceiveDrag", OnReceiveDragItem)
|
||||||
|
|
||||||
|
m.title = m:CreateFontString(nil, "OVERLAY");
|
||||||
|
m.title:SetPoint("TOPLEFT", 15, -15);
|
||||||
|
ApplyCustomFont(m.title, 16, "OUTLINE");
|
||||||
|
m.title:SetText("Manager")
|
||||||
|
m.close = CreateFrame("Button", nil, m, "UIPanelCloseButton");
|
||||||
|
m.close:SetPoint("TOPRIGHT", -5, -5)
|
||||||
|
|
||||||
|
m.mileLabel = m:CreateFontString(nil, "OVERLAY");
|
||||||
|
m.mileLabel:SetPoint("TOPLEFT", 15, -45);
|
||||||
|
ApplyCustomFont(m.mileLabel, 12);
|
||||||
|
m.mileLabel:SetText("Milestone (Gold):")
|
||||||
|
m.mileEdit = CreateFrame("EditBox", nil, m, "InputBoxTemplate")
|
||||||
|
m.mileEdit:SetSize(60, 20);
|
||||||
|
m.mileEdit:SetPoint("LEFT", m.mileLabel, "RIGHT", 10, 0);
|
||||||
|
m.mileEdit:SetAutoFocus(false)
|
||||||
|
m.mileEdit:SetScript("OnEnterPressed", function(self)
|
||||||
|
FarmTrackerDB.milestone = tonumber(self:GetText()) or 100;
|
||||||
|
self:ClearFocus();
|
||||||
|
MX:RefreshDisplay()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
m:SetScript("OnUpdate", function(self)
|
m.autoAddCheck = CreateFrame("CheckButton", "FTAutoAddCheck", m, "UICheckButtonTemplate")
|
||||||
if GetCursorInfo() == "item" and MouseIsOver(self) then
|
m.autoAddCheck:SetPoint("TOPLEFT", m.mileLabel, "BOTTOMLEFT", -5, -15)
|
||||||
self:SetBackdropBorderColor(0, 1, 0, 1)
|
m.autoAddCheck.text = m:CreateFontString(nil, "OVERLAY");
|
||||||
else
|
m.autoAddCheck.text:SetPoint("LEFT", m.autoAddCheck, "RIGHT", 5, 0)
|
||||||
self:SetBackdropBorderColor(1, 1, 1, 1)
|
ApplyCustomFont(m.autoAddCheck.text, 12);
|
||||||
end
|
m.autoAddCheck.text:SetText("Auto-Add Materials")
|
||||||
|
m.autoAddCheck:SetScript("OnClick", function(self)
|
||||||
|
FarmTrackerDB.autoAdd = self:GetChecked()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
m.title = m:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
|
m.minValLabel = m:CreateFontString(nil, "OVERLAY");
|
||||||
m.title:SetPoint("TOPLEFT", m, "TOPLEFT", 15, -15)
|
m.minValLabel:SetPoint("LEFT", m.autoAddCheck.text, "RIGHT", 15, 0);
|
||||||
m.title:SetText("Manage Materials")
|
ApplyCustomFont(m.minValLabel, 12);
|
||||||
|
m.minValLabel:SetText("Min Gold:")
|
||||||
|
m.minValEdit = CreateFrame("EditBox", nil, m, "InputBoxTemplate")
|
||||||
|
m.minValEdit:SetSize(40, 20);
|
||||||
|
m.minValEdit:SetPoint("LEFT", m.minValLabel, "RIGHT", 8, 0);
|
||||||
|
m.minValEdit:SetAutoFocus(false)
|
||||||
|
m.minValEdit:SetScript("OnEnterPressed", function(self)
|
||||||
|
FarmTrackerDB.minValue = tonumber(self:GetText()) or 0;
|
||||||
|
self:ClearFocus()
|
||||||
|
end)
|
||||||
|
|
||||||
m.desc = m:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
|
m.summary = m:CreateFontString(nil, "OVERLAY");
|
||||||
m.desc:SetPoint("TOPLEFT", m.title, "BOTTOMLEFT", 0, -2)
|
m.summary:SetPoint("TOPLEFT", m.autoAddCheck, "BOTTOMLEFT", 5, -5);
|
||||||
m.desc:SetText("Drag & drop items here to add them")
|
ApplyCustomFont(m.summary, 12)
|
||||||
|
|
||||||
m.close = CreateFrame("Button", nil, m, "UIPanelCloseButton")
|
local scrollFrame = CreateFrame("ScrollFrame", "FTScroll", m, "UIPanelScrollFrameTemplate")
|
||||||
m.close:SetPoint("TOPRIGHT", m, "TOPRIGHT", -5, -5)
|
scrollFrame:SetPoint("TOPLEFT", 10, -140);
|
||||||
|
scrollFrame:SetPoint("BOTTOMRIGHT", -30, 20)
|
||||||
local scrollFrame = CreateFrame("ScrollFrame", "FTManagerScrollFrame", m, "UIPanelScrollFrameTemplate")
|
local scrollChild = CreateFrame("Frame");
|
||||||
scrollFrame:SetPoint("TOPLEFT", m, "TOPLEFT", 10, -60)
|
scrollChild:SetSize(280, 1) -- Height updated in UpdateManagerList
|
||||||
scrollFrame:SetPoint("BOTTOMRIGHT", m, "BOTTOMRIGHT", -30, 60)
|
|
||||||
|
|
||||||
local scrollChild = CreateFrame("Frame")
|
|
||||||
scrollChild:SetSize(270, 1)
|
|
||||||
scrollFrame:SetScrollChild(scrollChild)
|
scrollFrame:SetScrollChild(scrollChild)
|
||||||
|
|
||||||
local itemRows = {}
|
|
||||||
|
|
||||||
function UpdateManagerList()
|
function UpdateManagerList()
|
||||||
for _, row in ipairs(itemRows) do
|
for _, row in ipairs(itemRows) do
|
||||||
row:Hide()
|
row:Hide()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local listCount = #FarmTrackerDB.items
|
||||||
|
scrollChild:SetHeight(math.max(1, listCount * 28))
|
||||||
|
|
||||||
for i, id in ipairs(FarmTrackerDB.items) do
|
for i, id in ipairs(FarmTrackerDB.items or {}) do
|
||||||
if not itemRows[i] then
|
if not itemRows[i] then
|
||||||
local row = CreateFrame("Frame", nil, scrollChild)
|
local row = CreateFrame("Frame", nil, scrollChild);
|
||||||
row:SetSize(270, 26)
|
row:SetSize(280, 28)
|
||||||
|
|
||||||
-- Item Text
|
-- Item Name Text
|
||||||
row.text = row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
|
row.text = row:CreateFontString(nil, "OVERLAY");
|
||||||
row.text:SetPoint("LEFT", row, "LEFT", 45, 0) -- Pushed right to fit arrows
|
row.text:SetPoint("LEFT", 5, 0);
|
||||||
row.text:SetWidth(180)
|
row.text:SetWidth(170); -- Slightly narrowed to make room for buttons
|
||||||
row.text:SetJustifyH("LEFT")
|
row.text:SetJustifyH("LEFT");
|
||||||
|
ApplyCustomFont(row.text, 11)
|
||||||
-- Remove Button
|
|
||||||
row.remove = CreateFrame("Button", nil, row)
|
-- Delete Button
|
||||||
row.remove:SetSize(16, 16)
|
row.del = CreateFrame("Button", nil, row);
|
||||||
row.remove:SetPoint("RIGHT", row, "RIGHT", -2, 0)
|
row.del:SetSize(16, 16);
|
||||||
row.remove:SetNormalTexture("Interface\\Buttons\\UI-GroupLoot-Pass-Up")
|
row.del:SetPoint("RIGHT", -5, 0);
|
||||||
|
row.del:SetNormalTexture("Interface\\Buttons\\UI-GroupLoot-Pass-Up")
|
||||||
-- UP Arrow
|
|
||||||
row.up = CreateFrame("Button", nil, row)
|
-- Down Button
|
||||||
row.up:SetSize(16, 16)
|
row.down = CreateFrame("Button", nil, row);
|
||||||
row.up:SetPoint("LEFT", row, "LEFT", 5, 0)
|
row.down:SetSize(16, 16);
|
||||||
row.up:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Up")
|
row.down:SetPoint("RIGHT", row.del, "LEFT", -4, 0);
|
||||||
|
|
||||||
-- DOWN Arrow
|
|
||||||
row.down = CreateFrame("Button", nil, row)
|
|
||||||
row.down:SetSize(16, 16)
|
|
||||||
row.down:SetPoint("LEFT", row.up, "RIGHT", 2, 0)
|
|
||||||
row.down:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up")
|
row.down:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up")
|
||||||
|
|
||||||
|
-- Up Button
|
||||||
|
row.up = CreateFrame("Button", nil, row);
|
||||||
|
row.up:SetSize(16, 16);
|
||||||
|
row.up:SetPoint("RIGHT", row.down, "LEFT", -4, 0);
|
||||||
|
row.up:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Up")
|
||||||
|
|
||||||
itemRows[i] = row
|
itemRows[i] = row
|
||||||
end
|
end
|
||||||
|
|
||||||
local _, link = GetItemInfo(id)
|
local _, link = GetItemInfo(id);
|
||||||
local row = itemRows[i]
|
local row = itemRows[i]
|
||||||
row.text:SetText(link or "Loading ID: " .. id)
|
row.text:SetText(link or "Loading...")
|
||||||
|
|
||||||
|
-- Logic for Delete
|
||||||
|
row.del:SetScript("OnClick", function()
|
||||||
|
table.remove(FarmTrackerDB.items, i);
|
||||||
|
UpdateManagerList();
|
||||||
|
MX:RefreshDisplay()
|
||||||
|
end)
|
||||||
|
|
||||||
-- Logic: Move Up
|
-- Logic for Move Up
|
||||||
|
row.up:SetEnabled(i > 1)
|
||||||
|
row.up:GetNormalTexture():SetDesaturated(i == 1)
|
||||||
row.up:SetScript("OnClick", function()
|
row.up:SetScript("OnClick", function()
|
||||||
if i > 1 then
|
if i > 1 then
|
||||||
local temp = FarmTrackerDB.items[i - 1]
|
local temp = FarmTrackerDB.items[i-1]
|
||||||
FarmTrackerDB.items[i - 1] = FarmTrackerDB.items[i]
|
FarmTrackerDB.items[i-1] = FarmTrackerDB.items[i]
|
||||||
FarmTrackerDB.items[i] = temp
|
FarmTrackerDB.items[i] = temp
|
||||||
UpdateManagerList()
|
UpdateManagerList();
|
||||||
RefreshDisplay()
|
MX:RefreshDisplay()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Logic: Move Down
|
-- Logic for Move Down
|
||||||
|
row.down:SetEnabled(i < listCount)
|
||||||
|
row.down:GetNormalTexture():SetDesaturated(i == listCount)
|
||||||
row.down:SetScript("OnClick", function()
|
row.down:SetScript("OnClick", function()
|
||||||
if i < #FarmTrackerDB.items then
|
if i < listCount then
|
||||||
local temp = FarmTrackerDB.items[i + 1]
|
local temp = FarmTrackerDB.items[i+1]
|
||||||
FarmTrackerDB.items[i + 1] = FarmTrackerDB.items[i]
|
FarmTrackerDB.items[i+1] = FarmTrackerDB.items[i]
|
||||||
FarmTrackerDB.items[i] = temp
|
FarmTrackerDB.items[i] = temp
|
||||||
UpdateManagerList()
|
UpdateManagerList();
|
||||||
RefreshDisplay()
|
MX:RefreshDisplay()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Logic: Remove
|
row:SetPoint("TOPLEFT", 0, -(i - 1) * 28);
|
||||||
row.remove:SetScript("OnClick", function()
|
|
||||||
table.remove(FarmTrackerDB.items, i)
|
|
||||||
UpdateManagerList()
|
|
||||||
RefreshDisplay()
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Visibility of arrows (disable first up and last down)
|
|
||||||
row.up:SetAlpha(i == 1 and 0.3 or 1)
|
|
||||||
row.down:SetAlpha(i == #FarmTrackerDB.items and 0.3 or 1)
|
|
||||||
|
|
||||||
row:SetPoint("TOPLEFT", scrollChild, "TOPLEFT", 0, -(i - 1) * 26)
|
|
||||||
row:Show()
|
row:Show()
|
||||||
end
|
end
|
||||||
scrollChild:SetHeight(#FarmTrackerDB.items * 26)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
m.editBox = CreateFrame("EditBox", nil, m, "InputBoxTemplate")
|
-- 4. Logic: Refresh Display & Dynamic Height
|
||||||
m.editBox:SetSize(180, 20)
|
function MX:RefreshDisplay()
|
||||||
m.editBox:SetPoint("BOTTOMLEFT", m, "BOTTOMLEFT", 20, 20)
|
if not isInitialized then
|
||||||
m.editBox:SetAutoFocus(false)
|
|
||||||
m.editBox:SetText("Paste link/ID here...")
|
|
||||||
m.editBox:SetScript("OnEditFocusGained", function(self)
|
|
||||||
if self:GetText() == "Paste link/ID here..." then
|
|
||||||
self:SetText("")
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
m.addBtn = CreateFrame("Button", nil, m, "UIPanelButtonTemplate")
|
|
||||||
m.addBtn:SetSize(80, 22)
|
|
||||||
m.addBtn:SetPoint("LEFT", m.editBox, "RIGHT", 5, 0)
|
|
||||||
m.addBtn:SetText("Add Item")
|
|
||||||
m.addBtn:SetScript("OnClick", function()
|
|
||||||
local text = m.editBox:GetText()
|
|
||||||
local id = tonumber(text) or tonumber(text:match("item:(%d+)"))
|
|
||||||
if id then
|
|
||||||
AddItemToList(id)
|
|
||||||
m.editBox:SetText("")
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
m:SetScript("OnShow", UpdateManagerList)
|
|
||||||
|
|
||||||
-- 4. Logic: Refresh Display
|
|
||||||
local function GetOrCreateButton(index)
|
|
||||||
if not hoverButtons[index] then
|
|
||||||
local b = CreateFrame("Button", nil, f)
|
|
||||||
b:SetHeight(28)
|
|
||||||
b:SetScript("OnEnter", function(self)
|
|
||||||
if self.itemID and not FarmTrackerDB.locked then
|
|
||||||
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
|
|
||||||
GameTooltip:SetItemByID(self.itemID)
|
|
||||||
GameTooltip:Show()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
b:SetScript("OnLeave", function()
|
|
||||||
GameTooltip:Hide()
|
|
||||||
end)
|
|
||||||
hoverButtons[index] = b
|
|
||||||
end
|
|
||||||
return hoverButtons[index]
|
|
||||||
end
|
|
||||||
|
|
||||||
function RefreshDisplay()
|
|
||||||
if not FarmTrackerDB then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local displayString, totalInv, totalSess, activeIndex = "", 0, 0, 0
|
local displayString, totalSess, totalInv, itemCount = "", 0, 0, 0
|
||||||
local elapsed = (GetTime() - startTime) / 3600
|
local maxWidth = 260
|
||||||
for _, btn in ipairs(hoverButtons) do
|
|
||||||
btn:Hide()
|
|
||||||
end
|
|
||||||
|
|
||||||
for _, id in ipairs(FarmTrackerDB.items) do
|
for _, id in ipairs(FarmTrackerDB.items or {}) do
|
||||||
local name, link, _, _, _, _, _, _, _, icon = GetItemInfo(id)
|
local name, link, _, _, _, _, _, _, _, icon = GetItemInfo(id)
|
||||||
local count = GetItemCount(id, true)
|
if name and link then
|
||||||
local gain = count - (sessionStartCounts[id] or count)
|
local truncatedName = link:sub(1, 25)
|
||||||
|
local quality = C_TradeSkillUI.GetItemReagentQualityByItemInfo(link)
|
||||||
if count > 0 or gain > 0 then
|
local qualityIcon = ""
|
||||||
activeIndex = activeIndex + 1
|
if quality then
|
||||||
local price = (_G.TSM_API and TSM_API.GetCustomPriceValue("dbmarket", "i:" .. id)) or 0
|
qualityIcon = CreateAtlasMarkup("Professions-Icon-Quality-Tier" .. quality, 14, 14)
|
||||||
totalInv = totalInv + (count * price / 10000)
|
else
|
||||||
totalSess = totalSess + (gain * price / 10000)
|
qualityIcon = "|TInterface\\Buttons\\UI-EmptySlot-White:14:14:0:0:64:64:0:0:0:0|t";
|
||||||
|
end
|
||||||
local rank = ""
|
local count = GetItemCount(id, false)
|
||||||
if link then
|
local countString = ""
|
||||||
local q = C_TradeSkillUI.GetItemReagentQualityByItemInfo(link)
|
local gain = count - (sessionStartCounts[id] or count)
|
||||||
if q and q > 0 then
|
local gainString = ""
|
||||||
rank = " " .. CreateAtlasMarkup(("Professions-Icon-Quality-Tier%d-Small"):format(q), 14, 14)
|
local price = ((_G.TSM_API and TSM_API.GetCustomPriceValue("DBMinBuyout", "i:" .. id)) or 0) / 10000
|
||||||
|
local priceCopper = ((_G.TSM_API and TSM_API.GetCustomPriceValue("DBMinBuyout", "i:" .. id)) or 0)
|
||||||
|
totalSess, totalInv = totalSess + (gain * price), totalInv + (count * price)
|
||||||
|
if count > 0 or gain > 0 then
|
||||||
|
-- displayString = displayString .. string.format("|T%s:16:16:0:0|t %s: %d |cFF00FF00(+%d)|r\n", icon or "", name or "...", count, gain)
|
||||||
|
-- displayString = displayString .. string.format("|T%s:16:16:0:0|t %s: %d |cFF00FF00(+%d)|r\n", icon or "", name or "...", count, gain)
|
||||||
|
if count < 10 then
|
||||||
|
countString = string.format(" %d", count)
|
||||||
|
elseif count >= 10 and count < 100 then
|
||||||
|
countString = string.format(" %d", count)
|
||||||
|
elseif count >= 100 then
|
||||||
|
countString = string.format("%d", count)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
displayString = string.format(
|
if gain < 10 then
|
||||||
"|T%s:14:14:0:0|t |cFFFFD100%s%s:|r %d |cFF00FF00(+%d)|r\n|cFF808080Inv: %.2fg|r\n\n", icon or "",
|
gainString = string.format(" %d", gain)
|
||||||
name or "Loading...", rank, count, gain, (count * price / 10000)) .. displayString
|
elseif gain > 10 and gain < 100 then
|
||||||
|
gainString = string.format(" %d", gain)
|
||||||
|
elseif gain > 100 then
|
||||||
|
gainString = string.format("%d", gain)
|
||||||
|
end
|
||||||
|
|
||||||
local btn = GetOrCreateButton(activeIndex)
|
local unitDiv = priceCopper / 1000
|
||||||
btn.itemID = id
|
local unitString = ""
|
||||||
btn:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 10,
|
if unitDiv < 10 then
|
||||||
55 + (activeIndex - 1) * 32 + (FarmTrackerDB.goal > 0 and 15 or 0))
|
unitString = string.format(" %s", MX:FormatMoneyGoldOnly(priceCopper))
|
||||||
btn:SetWidth(f:GetWidth() - 20)
|
elseif unitDiv >= 10 and unitDiv < 100 then
|
||||||
if not FarmTrackerDB.locked then
|
unitString = string.format(" %s", MX:FormatMoneyGoldOnly(priceCopper))
|
||||||
btn:Show()
|
elseif unitDiv >= 100 and unitDiv < 1000 then
|
||||||
|
unitString = string.format(" %s", MX:FormatMoneyGoldOnly(priceCopper))
|
||||||
|
elseif unitDiv >= 1000 and unitDiv < 10000 then
|
||||||
|
unitString = string.format(" %s", MX:FormatMoneyGoldOnly(priceCopper))
|
||||||
|
elseif unitDiv >= 10000 and unitDiv < 100000 then
|
||||||
|
unitString = string.format(" %s", MX:FormatMoneyGoldOnly(priceCopper))
|
||||||
|
elseif unitDiv >= 100000 then
|
||||||
|
unitString = string.format("%s", MX:FormatMoneyGoldOnly(priceCopper))
|
||||||
|
end
|
||||||
|
|
||||||
|
local totalDiv = (count * priceCopper) / 1000
|
||||||
|
local totalString = ""
|
||||||
|
if totalDiv < 10 then
|
||||||
|
totalString = string.format(" %s", MX:FormatMoneyGoldOnly(count * priceCopper))
|
||||||
|
elseif totalDiv >= 10 and totalDiv < 100 then
|
||||||
|
totalString = string.format(" %s", MX:FormatMoneyGoldOnly(count * priceCopper))
|
||||||
|
elseif totalDiv >= 100 and totalDiv < 1000 then
|
||||||
|
totalString = string.format(" %s", MX:FormatMoneyGoldOnly(count * priceCopper))
|
||||||
|
elseif totalDiv >= 1000 and totalDiv < 10000 then
|
||||||
|
totalString = string.format(" %s", MX:FormatMoneyGoldOnly(count * priceCopper))
|
||||||
|
elseif totalDiv >= 10000 and totalDiv < 100000 then
|
||||||
|
totalString = string.format(" %s", MX:FormatMoneyGoldOnly(count * priceCopper))
|
||||||
|
elseif totalDiv >= 100000 then
|
||||||
|
totalString = string.format("%s", MX:FormatMoneyGoldOnly(count * priceCopper))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- displayString = displayString .. string.format("|T%s:14:14:0:0|t |cFF00FFFFB%s|r |cFF00FF00S%s|r %s/u %s/t %s %s\n", icon or "", countString, gainString, MX:FormatMoneyGoldOnly(priceCopper), MX:FormatMoneyGoldOnly(count * priceCopper), qualityIcon or "n", name or "...")
|
||||||
|
displayString = displayString ..
|
||||||
|
string.format("|T%s:14:14:0:0|t |cFF00FFFF%s|r |cFF00FF00%s|r %s/u %s/t %s\n",
|
||||||
|
icon or "", countString, gainString, unitString, totalString, link or "...")
|
||||||
|
itemCount = itemCount + 1
|
||||||
|
maxWidth = math.max(maxWidth, f.text:GetStringWidth() + 40)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local gph = elapsed > 0 and (totalSess / elapsed) or 0
|
local ms = math.max(1, FarmTrackerDB.milestone or 100)
|
||||||
local goalBar = ""
|
local progress = (totalSess % ms) / ms
|
||||||
if FarmTrackerDB.goal > 0 then
|
-- Calculate active time
|
||||||
local p = math.min(totalSess / FarmTrackerDB.goal, 1)
|
local currentActiveSession = isPaused and 0 or (GetTime() - startTime)
|
||||||
goalBar = string.format("\nGoal: |cFF00FF00%s|r|cFF555555%s|r %.1f%%", string.rep("■", math.floor(p * 20)),
|
local totalActiveSeconds = sessionAccumulatedTime + currentActiveSession
|
||||||
string.rep("■", 20 - math.floor(p * 20)), p * 100)
|
|
||||||
if p >= 1 and not goalReachedSoundPlayed then
|
|
||||||
PlaySound(888, "Master")
|
|
||||||
goalReachedSoundPlayed = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
f.statsText:SetText(string.format("|cFF00FF00Sess: %.2fg|r |cFFFFFF00Total: %.2fg|r\n|cFF55AAFFGPH: %.2fg/hr|r%s",
|
local elapsedHours = totalActiveSeconds / 3600
|
||||||
totalSess, totalInv, gph, goalBar))
|
local gph = elapsedHours > 0.005 and (totalSess / elapsedHours) or 0
|
||||||
f.text:SetText(displayString)
|
local timerStr = string.format("[%02d:%02d]", math.floor(totalActiveSeconds / 60),
|
||||||
f:SetHeight(f.text:GetStringHeight() + f.statsText:GetStringHeight() + 60)
|
math.floor(totalActiveSeconds % 60))
|
||||||
|
|
||||||
|
if FarmTrackerDB.minimized then
|
||||||
|
f:SetSize(200, 55);
|
||||||
|
f.text:SetText("");
|
||||||
|
f.line:Hide();
|
||||||
|
f.dailyText:Hide();
|
||||||
|
f.monthlyText:Hide();
|
||||||
|
f.barBG:Hide()
|
||||||
|
f.statsText:SetPoint("BOTTOMLEFT", 12, 22);
|
||||||
|
f.statsText:SetText(string.format("|cFF00FF00S: %.2fg|r %s", totalSess, timerStr))
|
||||||
|
f.invText:SetPoint("BOTTOMLEFT", 12, 8);
|
||||||
|
f.invText:SetText(string.format("|cFF00FFFFI: %.2fg|r", totalInv))
|
||||||
|
else
|
||||||
|
f.text:SetText(displayString)
|
||||||
|
if displayString then
|
||||||
|
f.barBG:Show()
|
||||||
|
end
|
||||||
|
f.line:Show();
|
||||||
|
f.dailyText:Show();
|
||||||
|
f.monthlyText:Show();
|
||||||
|
|
||||||
|
-- Anchor elements from the bottom up to prevent overlapping
|
||||||
|
f.dailyText:SetText(string.format(L["MxW_MainForm_Day"], MX:FormatMoneyGoldOnly(MxW_DailyGlobal)))
|
||||||
|
f.monthlyText:SetText(string.format(L["MxW_MainForm_Month"], MX:FormatMoneyGoldOnly(MxW_MonthlyGlobal)))
|
||||||
|
f.line:SetPoint("BOTTOMLEFT", 10, 44);
|
||||||
|
f.line:SetPoint("BOTTOMRIGHT", -10, 44)
|
||||||
|
f.invText:SetPoint("BOTTOMLEFT", 12, 50);
|
||||||
|
f.invText:SetText(string.format(L["MxW_MainForm_Bag"], totalInv, totalInv - (totalInv * 0.05)))
|
||||||
|
f.statsText:SetPoint("BOTTOMLEFT", 12, 66);
|
||||||
|
f.statsText:SetText(string.format(L["MxW_MainForm_Live"], totalSess, gph, timerStr))
|
||||||
|
f.barBG:SetPoint("BOTTOMLEFT", 12, 84);
|
||||||
|
f.barBG:SetPoint("BOTTOMRIGHT", -12, 84)
|
||||||
|
f.barFill:SetWidth(math.max(1, f.barBG:GetWidth() * progress))
|
||||||
|
f.barFill:SetColorTexture(progress < 0.5 and 1 or (progress < 0.8 and 1 or 0), progress < 0.5 and 0 or 1, 0)
|
||||||
|
f.pauseBtn:SetPoint("LEFT", f.statsText, "RIGHT", 5, 0);
|
||||||
|
f.pauseBtn:Show()
|
||||||
|
|
||||||
|
f:SetSize(maxWidth, 120 + (itemCount * 20)) -- Dynamic Height calculation
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 5. Init & Events
|
-- 5. Buttons & Tickers
|
||||||
f:RegisterEvent("ADDON_LOADED")
|
f.minBtn = CreateFrame("Button", nil, f);
|
||||||
f:RegisterEvent("BAG_UPDATE")
|
f.minBtn:SetSize(18, 18);
|
||||||
f:RegisterEvent("PLAYER_LOGIN")
|
f.minBtn:SetPoint("TOPRIGHT", -8, -8);
|
||||||
|
f.minBtn:SetNormalTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Up")
|
||||||
|
f.minBtn:SetScript("OnClick", function()
|
||||||
|
FarmTrackerDB.minimized = not FarmTrackerDB.minimized;
|
||||||
|
RefreshDisplay()
|
||||||
|
end)
|
||||||
|
f.configBtn = CreateFrame("Button", nil, f);
|
||||||
|
f.configBtn:SetSize(18, 18);
|
||||||
|
f.configBtn:SetPoint("TOPRIGHT", f.minBtn, "TOPLEFT", -2, 0);
|
||||||
|
f.configBtn:SetNormalTexture("Interface\\Buttons\\UI-OptionsButton")
|
||||||
|
f.configBtn:SetScript("OnClick", function()
|
||||||
|
if m:IsShown() then
|
||||||
|
m:Hide()
|
||||||
|
else
|
||||||
|
m.mileEdit:SetText(tostring(FarmTrackerDB.milestone or 100))
|
||||||
|
m.minValEdit:SetText(tostring(FarmTrackerDB.minValue or 1))
|
||||||
|
m.autoAddCheck:SetChecked(FarmTrackerDB.autoAdd)
|
||||||
|
UpdateManagerList();
|
||||||
|
m:Show()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
f.resetBtn = CreateFrame("Button", nil, f);
|
||||||
|
f.resetBtn:SetSize(18, 18);
|
||||||
|
f.resetBtn:SetPoint("BOTTOMRIGHT", -10, 10);
|
||||||
|
f.resetBtn:SetNormalTexture("Interface\\Buttons\\UI-RefreshButton")
|
||||||
|
f.resetBtn:SetScript("OnClick", function()
|
||||||
|
StaticPopup_Show("FARMTRACKER_RESET")
|
||||||
|
end)
|
||||||
|
|
||||||
|
StaticPopupDialogs["FARMTRACKER_RESET"] = {
|
||||||
|
text = "Reset session?",
|
||||||
|
button1 = "Yes",
|
||||||
|
button2 = "No",
|
||||||
|
OnAccept = function()
|
||||||
|
for _, id in ipairs(FarmTrackerDB.items) do
|
||||||
|
sessionStartCounts[id] = GetItemCount(id, false)
|
||||||
|
end
|
||||||
|
startTime, lastMilestoneReached, lastGoldValue = GetTime(), 0, 0
|
||||||
|
MX:RefreshDisplay()
|
||||||
|
end,
|
||||||
|
timeout = 0,
|
||||||
|
whileDead = true,
|
||||||
|
hideOnEscape = true
|
||||||
|
}
|
||||||
|
|
||||||
|
-- 6. Events
|
||||||
|
f:RegisterEvent("ADDON_LOADED");
|
||||||
|
f:RegisterEvent("PLAYER_LOGIN");
|
||||||
|
f:RegisterEvent("CHAT_MSG_LOOT");
|
||||||
|
f:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||||
f:SetScript("OnEvent", function(self, event, arg1)
|
f:SetScript("OnEvent", function(self, event, arg1)
|
||||||
if event == "ADDON_LOADED" and (arg1 == "MxW.Farm" or arg1 == "FarmTracker") then
|
if event == "ADDON_LOADED" and arg1 == "MxW.Farm" then
|
||||||
FarmTrackerDB = FarmTrackerDB or {}
|
FarmTrackerDB = FarmTrackerDB or {
|
||||||
FarmTrackerDB.items = FarmTrackerDB.items or {2840, 2841, 2770}
|
items = {2840, 2841, 2770},
|
||||||
FarmTrackerDB.scale = FarmTrackerDB.scale or 1.0
|
milestone = 100,
|
||||||
f:SetScale(FarmTrackerDB.scale)
|
autoAdd = true,
|
||||||
|
minValue = 1
|
||||||
|
}
|
||||||
if FarmTrackerDB.pos then
|
if FarmTrackerDB.pos then
|
||||||
f:ClearAllPoints()
|
f:ClearAllPoints();
|
||||||
f:SetPoint(FarmTrackerDB.pos.point, UIParent, FarmTrackerDB.pos.relativePoint, FarmTrackerDB.pos.x,
|
f:SetPoint(FarmTrackerDB.pos.point, UIParent, FarmTrackerDB.pos.relativePoint, FarmTrackerDB.pos.x,
|
||||||
FarmTrackerDB.pos.y)
|
FarmTrackerDB.pos.y)
|
||||||
else
|
|
||||||
f:SetPoint("BOTTOM", UIParent, "CENTER")
|
|
||||||
end
|
|
||||||
if FarmTrackerDB.locked then
|
|
||||||
f:EnableMouse(false)
|
|
||||||
f:SetMovable(false)
|
|
||||||
f.resetBtn:Hide()
|
|
||||||
end
|
end
|
||||||
elseif event == "PLAYER_LOGIN" then
|
elseif event == "PLAYER_LOGIN" then
|
||||||
C_Timer.After(2, function()
|
-- nothing
|
||||||
for _, id in ipairs(FarmTrackerDB.items) do
|
elseif event == "CHAT_MSG_LOOT" and isInitialized and FarmTrackerDB.autoAdd then
|
||||||
sessionStartCounts[id] = GetItemCount(id, true)
|
local itemLink = arg1:match("|H(item:%d+:.-)|h")
|
||||||
C_Item.RequestLoadItemDataByID(id)
|
if itemLink then
|
||||||
|
-- Use a ItemMixin to ensure data is loaded before processing
|
||||||
|
local item = Item:CreateFromItemLink(itemLink)
|
||||||
|
item:ContinueOnItemLoad(function()
|
||||||
|
local id = item:GetItemID()
|
||||||
|
local _, _, _, _, _, _, classID = GetItemInfo(id)
|
||||||
|
|
||||||
|
-- Check if it's a Crafting Material (Class 7)
|
||||||
|
if classID == 7 then
|
||||||
|
-- Get price from TSM
|
||||||
|
local priceCopper = (_G.TSM_API and TSM_API.GetCustomPriceValue("DBMinBuyout", "i:" .. id)) or 0
|
||||||
|
local priceGold = priceCopper / 10000
|
||||||
|
|
||||||
|
-- Check threshold
|
||||||
|
if priceGold >= (FarmTrackerDB.minValue or 0) then
|
||||||
|
local exists = false
|
||||||
|
for _, v in ipairs(FarmTrackerDB.items) do
|
||||||
|
if v == id then
|
||||||
|
exists = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not exists then
|
||||||
|
table.insert(FarmTrackerDB.items, id)
|
||||||
|
-- Set start count to current - 1 so the (+1) shows immediately
|
||||||
|
sessionStartCounts[id] = GetItemCount(id, false) - 1
|
||||||
|
|
||||||
|
-- Call the correct function name
|
||||||
|
MX:RefreshDisplay()
|
||||||
|
if m:IsShown() then
|
||||||
|
UpdateManagerList()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
elseif event == "PLAYER_ENTERING_WORLD" then
|
||||||
|
if (day ~= 0 and LogicDay ~= day) then
|
||||||
|
MxW_DailyGlobal = 0;
|
||||||
|
LogicDay = day;
|
||||||
|
end
|
||||||
|
C_Timer.After(5, function()
|
||||||
|
for _, id in ipairs(FarmTrackerDB.items or {}) do
|
||||||
|
sessionStartCounts[id] = GetItemCount(id, false)
|
||||||
end
|
end
|
||||||
isInitialized = true
|
isInitialized = true;
|
||||||
f:Show()
|
f:Show();
|
||||||
RefreshDisplay()
|
MX:RefreshDisplay()
|
||||||
end)
|
end)
|
||||||
elseif event == "BAG_UPDATE" and isInitialized then
|
CurrentGold = GetMoney()
|
||||||
RefreshDisplay()
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- 6. Slash Commands
|
C_Timer.NewTicker(1, function()
|
||||||
|
if isInitialized then
|
||||||
|
MX:RefreshDisplay()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- 7. Slash Commands
|
||||||
SLASH_FARMTRACKER1 = "/ft"
|
SLASH_FARMTRACKER1 = "/ft"
|
||||||
SlashCmdList["FARMTRACKER"] = function(msg)
|
SlashCmdList["FARMTRACKER"] = function(msg)
|
||||||
local cmd, arg = msg:match("^(%S*)%s*(.-)$")
|
local cmd, arg = msg:match("^(%S*)%s*(.-)$")
|
||||||
@@ -415,6 +647,6 @@ SlashCmdList["FARMTRACKER"] = function(msg)
|
|||||||
elseif cmd == "manage" then
|
elseif cmd == "manage" then
|
||||||
m:Show()
|
m:Show()
|
||||||
else
|
else
|
||||||
m:Show() -- Default to showing manager if no command
|
f:Show() -- Default to showing manager if no command
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
BIN
Media/Font/Consola.ttf
Normal file
BIN
Media/Font/Consola.ttf
Normal file
Binary file not shown.
BIN
Media/Font/Homespun.ttf
Normal file
BIN
Media/Font/Homespun.ttf
Normal file
Binary file not shown.
BIN
Media/Font/Verdana.ttf
Normal file
BIN
Media/Font/Verdana.ttf
Normal file
Binary file not shown.
BIN
Media/Sound/register.mp3
Normal file
BIN
Media/Sound/register.mp3
Normal file
Binary file not shown.
BIN
Media/Texture/Black8x8.tga
Normal file
BIN
Media/Texture/Black8x8.tga
Normal file
Binary file not shown.
BIN
Media/Texture/MainForm.tga
Normal file
BIN
Media/Texture/MainForm.tga
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 200 KiB |
13
MxW.Farm.toc
13
MxW.Farm.toc
@@ -1,10 +1,19 @@
|
|||||||
## Interface: 120001
|
## Interface: 120001
|
||||||
## Title: |cff1784d1MxW.Farm|r
|
## Title: |cff1784d1MxW.Farm|r
|
||||||
## IconTexture: Interface\Icons\inv_misc_coin_01
|
## IconTexture: Interface\Icons\inv_misc_coin_01
|
||||||
## Version: 1.0.0
|
## Version: 1.1.0
|
||||||
## Author: mikx
|
## Author: mikx
|
||||||
## Notes: MxW Farming Addon
|
## Notes: MxW Farming Addon
|
||||||
## RequiredDeps: TradeSkillMaster
|
## RequiredDeps: TradeSkillMaster
|
||||||
|
## SavedVariables: MxW_DailyGlobal,MxW_MonthlyGlobal,CurrentGold,LogicDay
|
||||||
## SavedVariablesPerCharacter: FarmTrackerDB
|
## SavedVariablesPerCharacter: FarmTrackerDB
|
||||||
|
|
||||||
Main.lua
|
# Libraries and third-parties code
|
||||||
|
Libraries\Load_Libraries.xml
|
||||||
|
# Localization
|
||||||
|
Locale\Load_Locales.xml
|
||||||
|
# Main Logic
|
||||||
|
Main.lua
|
||||||
|
# Logics
|
||||||
|
Function\Load_Functions.xml
|
||||||
|
Event\Load_Events.xml
|
||||||
Reference in New Issue
Block a user