diff --git a/.gitmodules b/.gitmodules
new file mode 100755
index 0000000..027388f
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,6 @@
+[submodule "Libs/RavenousUtils"]
+ path = Libs/RavenousUtils
+ url = https://github.com/RavenousAddons/RavenousUtils
+[submodule "Libs/RavenousOptions"]
+ path = Libs/RavenousOptions
+ url = https://github.com/RavenousAddons/RavenousOptions
diff --git a/HonorableKillsTracker.toc b/HonorableKillsTracker.toc
index e1f2f9a..f94bd68 100755
--- a/HonorableKillsTracker.toc
+++ b/HonorableKillsTracker.toc
@@ -1,9 +1,5 @@
-## Interface: 110005
-## Version: 1.0.5
-
-## TODO
-## Add HKs to Addon Compartment
-## Reinvestigate bar / broker addons display
+## Interface: 110100
+## Version: 1.0.6
## Name: Honorable Kills Tracker
## Title: Honorable Kills Tracker
@@ -11,6 +7,18 @@
## Author: RavenousAddons
## IconAtlas: BattleMaster
+## Category-enUS: Data Broker
+## Category-deDE: Datenbroker
+## Category-esES: Intermediario de Datos
+## Category-esMX: Intermediario de Datos
+## Category-frFR: Courtier de Données
+## Category-itIT:
+## Category-koKR:
+## Category-ptBR: Corretor de Dados
+## Category-ruRU: Посредник данных
+## Category-zhCN: 数据管理
+## Category-zhTW: 資料管理
+
## SavedVariables: HKT_version
## SavedVariablesPerCharacter: HKT_data, HKT_options
@@ -18,4 +26,6 @@
## X-Website: https://github.com/RavenousAddons/HonorableKillsTracker
## X-Curse-Project-ID: 1099637
+Libs/RavenousUtils/RavenousUtils.xml
+Libs/RavenousOptions/RavenousOptions.xml
HonorableKillsTracker.xml
diff --git a/HonorableKillsTracker.xml b/HonorableKillsTracker.xml
index 81207ac..177ed06 100755
--- a/HonorableKillsTracker.xml
+++ b/HonorableKillsTracker.xml
@@ -2,7 +2,6 @@
-
diff --git a/Libs/RavenousOptions b/Libs/RavenousOptions
new file mode 160000
index 0000000..e7bde9d
--- /dev/null
+++ b/Libs/RavenousOptions
@@ -0,0 +1 @@
+Subproject commit e7bde9d8f55d1c12623e85f14f9216e4473b92af
diff --git a/Libs/RavenousUtils b/Libs/RavenousUtils
new file mode 160000
index 0000000..e06f6dd
--- /dev/null
+++ b/Libs/RavenousUtils
@@ -0,0 +1 @@
+Subproject commit e06f6dd885be847d6e49c2d8a61d8797a04bad44
diff --git a/core.lua b/core.lua
index 364f3bb..1f26cce 100755
--- a/core.lua
+++ b/core.lua
@@ -5,8 +5,6 @@ local characterID = UnitGUID("player")
local CT = C_Timer
-local criteriaUpdateAllowed = false
-
-- Load the Addon
function HonorableKillTracker_OnLoad(self)
@@ -22,8 +20,8 @@ function HonorableKillTracker_OnEvent(self, event, ...)
if event == "PLAYER_ENTERING_WORLD" then
local isInitialLogin, isReloadingUi = ...
ns:SetPlayerState()
- ns:SetDefaultOptions()
- ns:CreateSettingsPanel()
+ ns:SetOptionDefaults()
+ ns:CreateSettingsPanel(HKT_options, ns.data.defaults, L.Settings, ns.name, ns.prefix, ns.version)
if not HKT_version then
ns:PrettyPrint(L.Install:format(ns.color, ns.version))
elseif HKT_version ~= ns.version then
@@ -31,22 +29,21 @@ function HonorableKillTracker_OnEvent(self, event, ...)
end
HKT_version = ns.version
if isInitialLogin then
- if ns:OptionValue("displayOnLogin") then
+ if ns:OptionValue(HKT_options, "displayOnLogin") then
C_Timer.After(3, function()
ns:Alert(true)
end)
end
end
- criteriaUpdateAllowed = true
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
elseif event == "LOADING_SCREEN_ENABLED" then
- criteriaUpdateAllowed = false
+ self:UnregisterEvent("CRITERIA_UPDATE")
elseif event == "LOADING_SCREEN_DISABLED" then
- criteriaUpdateAllowed = true
+ self:RegisterEvent("CRITERIA_UPDATE")
elseif event == "CRITERIA_UPDATE" then
- if criteriaUpdateAllowed then
+ C_Timer.After(1, function()
ns:Alert()
- end
+ end)
end
end
@@ -87,10 +84,8 @@ SlashCmdList["HONORABLEKILLTRACKER"] = function(message)
elseif message == "c" or message:match("con") or message == "o" or message:match("opt") or message == "s" or message:match("sett") or message:match("togg") then
-- Open settings window
ns:OpenSettings()
- elseif message == "a" then
- ns:Alert()
else
- -- Print the timer
+ -- Print HK count
ns:Alert(true)
end
end
diff --git a/data.lua b/data.lua
index b9d583f..30dd4a3 100755
--- a/data.lua
+++ b/data.lua
@@ -2,14 +2,13 @@ local _, ns = ...
ns.data = {
defaults = {
+ trackAchievements = true,
characterSpecific = false,
- thousandsSeparator = 1,
- displayDivision = 3,
displayOnLogin = true,
- trackAchievements = true,
+ displayDivision = 3,
+ thousandsSeparator = 1,
},
divisions = {
- [0] = 0,
[1] = 1,
[2] = 5,
[3] = 10,
@@ -21,16 +20,15 @@ ns.data = {
[9] = 1000,
},
achievements = {
- [1] = 238,
- [100] = 513,
- [500] = 515,
- [1000] = 516,
- [5000] = 512,
- [10000] = 509,
- [25000] = 539,
- [50000] = 869,
- [100000] = 870,
- [250000] = 5363,
+ [1] = 513, -- 100
+ [2] = 515, -- 500
+ [3] = 516, -- 1000
+ [4] = 512, -- 5000
+ [5] = 509, -- 10000
+ [6] = 239, -- 25000
+ [7] = 869, -- 50000
+ [8] = 870, -- 100000
+ [9] = 5363, -- 250000
},
statistic = 588,
classColors = {
diff --git a/functions.lua b/functions.lua
index cca96e0..56008e6 100755
--- a/functions.lua
+++ b/functions.lua
@@ -4,7 +4,7 @@ local L = ns.L
ns.data.warbandFormatted = "|cff01e2ff" .. L.WarbandWide .. "|r"
local achievements = ns.data.achievements
-local achievementsCount = #achievements
+local achievementsSize = #achievements
local CT = C_Timer
local CQL = C_QuestLog
@@ -13,22 +13,8 @@ local CQL = C_QuestLog
-- Local Functions
---
--- Set default values for options which are not yet set.
--- @param {string} option
--- @param {any} default
-local function RegisterDefaultOption(option, default)
- if HKT_options[ns.prefix .. option] == nil then
- if HKT_options[option] ~= nil then
- HKT_options[ns.prefix .. option] = HKT_options[option]
- HKT_options[option] = nil
- else
- HKT_options[ns.prefix .. option] = default
- end
- end
-end
-
local function FormatNumber(number)
- local thousandsSeparator = ns:OptionValue("thousandsSeparator") == 2 and "." or ","
+ local thousandsSeparator = ns:OptionValue(HKT_options, "thousandsSeparator") == 2 and "." or ","
local formatted = tostring(number)
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", "%1" .. thousandsSeparator .. "%2")
@@ -39,67 +25,31 @@ local function FormatNumber(number)
return formatted
end
-local function HighestAchievementIndex()
- if ns.data.highestAchievementIndex ~= nil then
- return ns.data.highestAchievementIndex
- end
- local index
- for total, _ in pairs(achievements) do
- if index == nil or index < total then
- index = total
- end
- end
- ns.data.highestAchievementIndex = tonumber(index)
- return tonumber(index)
-end
-
-local function HighestAchievementID()
- if ns.data.highestAchievementID ~= nil then
- return ns.data.highestAchievementID
- end
- local id = tonumber(achievements[HighestAchievementIndex()])
- ns.data.highestAchievementID = id
- return id
-end
+local function GetAchievementData()
+ -- if ns.data.achievementData ~= nil then
+ -- return ns.data.achievementData
+ -- end
-local function CurrentAchievementIndex(warbandHKs)
- if ns.data.currentAchievementIndex ~= nil and warbandHKs < ns.data.currentAchievementIndex then
- return ns.data.currentAchievementIndex
- end
- local max = HighestAchievementIndex()
- if warbandHKs >= max then
- return max
- end
+ local data = {}
- local index
- for total, _ in pairs(achievements) do
- if warbandHKs < total and total < (index or max) then
- index = tonumber(total)
+ local previousReqQuantity = 0
+ for i = 1, achievementsSize do
+ local _, _, _, quantity, reqQuantity = GetAchievementCriteriaInfo(achievements[i], 1)
+ if quantity < reqQuantity and quantity > previousReqQuantity then
+ data.id = achievements[i]
+ data.quantity = quantity
+ data.reqQuantity = reqQuantity
+ previousReqQuantity = reqQuantity
end
end
- ns.data.currentAchievementIndex = index
- return index
-end
-
-local function CurrentAchievementID(warbandHKs)
- if ns.data.currentAchievementID ~= nil and ns.data.currentAchievementIndex ~= nil and warbandHKs < ns.data.currentAchievementIndex then
- return ns.data.currentAchievementID
- end
- local id = tonumber(achievements[CurrentAchievementIndex(warbandHKs)])
- ns.data.currentAchievementID = id
- return id
-end
-local function AchievementLink(warbandHKs)
- return "|cffffffaa|Hachievement:" .. CurrentAchievementID(warbandHKs) .. ":" .. ns.data.characterID .. ":0:0:0:0:0:0:0:0|h[" .. L.HKs:format(CurrentAchievementIndex(warbandHKs)) .. "]|h|r"
+ ns.data.achievementData = data
+ return data
end
-local function ShouldTrackCharacterSpecific(warbandHKs)
- return ns:OptionValue("characterSpecific") or HighestAchievementIndex() < warbandHKs
-end
-
-local function DisplayDivision()
- return ns.data.divisions[ns:OptionValue("displayDivision")]
+local function ShouldTrackCharacterSpecific()
+ local achievementData = GetAchievementData()
+ return ns:OptionValue(HKT_options, "characterSpecific") or achievementData.id == nil
end
local function GetChangeIndex(old, new)
@@ -125,22 +75,22 @@ local function FormatChange(old, new)
return left .. "|cff44ff44" .. right .. "|r"
end
+local function PrintStats(trackingType, key, honorableKills, forced)
+ print(L.HKs:format(trackingType) .. ": " .. (forced and FormatNumber(honorableKills) or FormatChange(FormatNumber(HKT_data[key] or "0"), FormatNumber(honorableKills))))
+end
+
local function CharacterHKs()
local value = GetStatistic(ns.data.statistic)
return value and tonumber(value) or 0
end
local function WarbandHKs()
- local _, _, _, _, _, _, _, _, quantityString = GetAchievementCriteriaInfo(HighestAchievementID(), 1)
- return tonumber(quantityString:match("%d+"))
-end
-
-local function PrintStats(trackingType, key, honorableKills, forced)
- print(L.HKs:format(trackingType) .. ": " .. (forced and FormatNumber(honorableKills) or FormatChange(FormatNumber(HKT_data[key] or "0"), FormatNumber(honorableKills))))
+ local achievementData = GetAchievementData()
+ return achievementData.quantity
end
-local function EqualDivision(characterHKs, warbandHKs, characterSpecific)
- local displayDivision = DisplayDivision()
+local function MatchesDivision(characterHKs, warbandHKs, characterSpecific)
+ local displayDivision = ns.data.divisions[ns:OptionValue(HKT_options, "displayDivision")]
if displayDivision == 0 then
return false
elseif displayDivision == 1 then
@@ -150,40 +100,64 @@ local function EqualDivision(characterHKs, warbandHKs, characterSpecific)
return x == 0
end
+local function AchievementLink()
+ local achievementData = GetAchievementData()
+ return "|cffffffaa|Hachievement:" .. achievementData.id .. ":" .. ns.data.characterID .. ":0:0:0:0:0:0:0:0|h[" .. L.HKs:format(achievementData.reqQuantity) .. "]|h|r"
+end
+
local displayLocked = false
local function DisplayStats(characterHKs, warbandHKs, characterSpecific, forced)
- if forced or not displayLocked then
- displayLocked = true
- -- Print stats based on character-specific parameter
- local trackingType = characterSpecific and ns.data.characterNameFormatted or ns.data.warbandFormatted
- local key = characterSpecific and "honorableKillsCharacter" or "honorableKills"
- local honorableKills = characterSpecific and characterHKs or warbandHKs
+ if displayLocked and not forced then
+ return
+ end
+ displayLocked = true
+
+ -- Print stats based on character-specific parameter
+ local trackingType = characterSpecific and ns.data.characterNameFormatted or ns.data.warbandFormatted
+ local key = characterSpecific and "honorableKillsCharacter" or "honorableKills"
+ local honorableKills = characterSpecific and characterHKs or warbandHKs
+ PrintStats(trackingType, key, honorableKills, forced)
+
+ -- Print stats based on opposite of character-specific parameter
+ if forced and ns.data.achievementData.quantity then
+ trackingType = characterSpecific and ns.data.warbandFormatted or ns.data.characterNameFormatted
+ key = characterSpecific and "honorableKills" or "honorableKillsCharacter"
+ honorableKills = characterSpecific and warbandHKs or characterHKs
PrintStats(trackingType, key, honorableKills, forced)
+ end
- -- Print stats based on opposite of character-specific parameter
- if forced then
- trackingType = characterSpecific and ns.data.warbandFormatted or ns.data.characterNameFormatted
- key = characterSpecific and "honorableKills" or "honorableKillsCharacter"
- honorableKills = characterSpecific and warbandHKs or characterHKs
- PrintStats(trackingType, key, honorableKills, forced)
- end
-
- local remaining = CurrentAchievementIndex(warbandHKs) - warbandHKs
- if ns:OptionValue("trackAchievements") and warbandHKs < HighestAchievementIndex() then
- print(AchievementLink(warbandHKs) .. " " .. L.Remaining:format(FormatNumber(remaining or "0")))
- end
-
- HKT_data.remaining = remaining
- C_Timer.After(1, function()
- displayLocked = false
- end)
+ local achievementData = GetAchievementData()
+ if ns:OptionValue(HKT_options, "trackAchievements") and achievementData.reqQuantity and warbandHKs < achievementData.reqQuantity then
+ local remaining = achievementData.reqQuantity - warbandHKs
+ print(AchievementLink() .. " " .. L.Remaining:format(FormatNumber(remaining or "0")))
end
+
+ C_Timer.After(1, function()
+ displayLocked = false
+ end)
end
---
-- Namespaced Functions
---
+--- Returns an option from the options table
+-- @param {boolean} forced
+function ns:Alert(forced)
+ C_Timer.After(0, function()
+ local characterSpecific = ShouldTrackCharacterSpecific()
+ local characterHKs = CharacterHKs()
+ local warbandHKs = WarbandHKs()
+
+ if forced or (MatchesDivision(characterHKs, warbandHKs, characterSpecific) and HKT_data.honorableKillsCharacter < characterHKs) then
+ DisplayStats(characterHKs, warbandHKs, characterSpecific, forced)
+ end
+
+ HKT_data.honorableKills = warbandHKs
+ HKT_data.honorableKillsCharacter = characterHKs
+ end)
+end
+
--- Set some data about the player
function ns:SetPlayerState()
ns.data.characterID = UnitGUID("player")
@@ -193,39 +167,11 @@ function ns:SetPlayerState()
ns.data.characterNameFormatted = "|cff" .. ns.data.classColors[ns.data.className:lower()] .. ns.data.characterName .. "|r"
end
---- Returns an option from the options table
-function ns:OptionValue(option)
- return HKT_options[ns.prefix .. option]
-end
-
--- Sets default options if they are not already set
-function ns:SetDefaultOptions()
+function ns:SetOptionDefaults()
HKT_data = HKT_data or {}
HKT_options = HKT_options or {}
for option, default in pairs(ns.data.defaults) do
- RegisterDefaultOption(option, default)
+ ns:SetOptionDefault(HKT_options, option, default)
end
end
-
---- Prints a formatted message to the chat
--- @param {string} message
-function ns:PrettyPrint(message)
- DEFAULT_CHAT_FRAME:AddMessage("|cff" .. ns.color .. ns.name .. "|r " .. message)
-end
-
---- Opens the Addon settings menu and plays a sound
-function ns:OpenSettings()
- PlaySound(SOUNDKIT.IG_MAINMENU_OPEN)
- Settings.OpenToCategory(ns.Settings:GetID())
-end
-
-function ns:Alert(forced)
- local characterHKs = CharacterHKs()
- local warbandHKs = WarbandHKs()
- local characterSpecific = ShouldTrackCharacterSpecific(warbandHKs)
- if forced or (EqualDivision(characterHKs, warbandHKs, characterSpecific) and HKT_data.honorableKillsCharacter < characterHKs) then
- DisplayStats(characterHKs, warbandHKs, characterSpecific, forced)
- end
- HKT_data.honorableKills = warbandHKs
- HKT_data.honorableKillsCharacter = characterHKs
-end
\ No newline at end of file
diff --git a/locales.lua b/locales.lua
index 18fd0ee..6ac6f5a 100755
--- a/locales.lua
+++ b/locales.lua
@@ -20,53 +20,58 @@ L.Version = "%s is the current version." -- ns.version
L.Install = "Thanks for installing version |cff%1$s%2$s|r!" -- ns.color, ns.version
L.AddonCompartmentTooltip1 = "|cff" .. ns.color .. "Left-Click:|r Check " .. L.HonorableKills
L.AddonCompartmentTooltip2 = "|cff" .. ns.color .. "Right-Click:|r Open Settings"
-L.OptionsTitle1 = "General options:"
-L.OptionsGeneral = {
- [1] = {
- key = "trackAchievements",
- name = "Track Achievements",
- tooltip = "Track progress on the various achievements for increasing numbers of " .. L.HonorableKills .. " across your Warband.",
- },
- [2] = {
- key = "characterSpecific",
- name = "Prioritize character-specific stats",
- tooltip = "Instead of displaying alerts for " .. L.HonorableKills .. " progress across your Warband, display Character-specific " .. L.HonorableKills .. ".",
- },
-}
-L.OptionsTitle2 = "How often do you want to see your progress?"
-L.OptionsStats = {
+
+L.Settings = {
[1] = {
- key = "displayOnLogin",
- name = "Display stats on login",
- tooltip = "Prints your " .. L.HonorableKills .. " stats in the chat box when you log in.",
+ title = "General options:",
+ options = {
+ [1] = {
+ key = "trackAchievements",
+ name = "Track Achievements",
+ tooltip = "Track progress on the various achievements for increasing numbers of " .. L.HonorableKills .. " across your Warband.",
+ },
+ [2] = {
+ key = "characterSpecific",
+ name = "Prioritize character-specific stats",
+ tooltip = "Instead of displaying alerts for " .. L.HonorableKills .. " progress across your Warband, display Character-specific " .. L.HonorableKills .. ".",
+ },
+ },
},
[2] = {
- key = "displayDivision",
- name = "Display stats every",
- tooltip = "Change how often you will be alerted to progress in the number of your " .. L.HonorableKills .. ".",
- fn = function()
- local container = Settings.CreateControlTextContainer()
- container:Add(0, L.Never)
- for index = 1, #ns.data.divisions do
- local value = ns.data.divisions[index]
- container:Add(index, value .. " " .. L.HonorableKills)
- end
- return container:GetData()
- end,
+ title = "How often do you want to see your progress?",
+ options = {
+ [1] = {
+ key = "displayOnLogin",
+ name = "Display stats on login",
+ tooltip = "Prints your " .. L.HonorableKills .. " stats in the chat box when you log in.",
+ },
+ [2] = {
+ key = "displayDivision",
+ name = "Display stats every",
+ tooltip = "Change how often you will be alerted to progress in the number of your " .. L.HonorableKills .. ".",
+ choices = function(container)
+ container:Add(0, L.Never)
+ for index = 1, #ns.data.divisions do
+ local value = ns.data.divisions[index]
+ container:Add(index, value .. " " .. L.HonorableKills)
+ end
+ end,
+ },
+ },
},
-}
-L.OptionsTitle3 = "Extra Options:"
-L.OptionsExtra = {
- [1] = {
- key = "thousandsSeparator",
- name = "Thousands Separator",
- tooltip = "Choose a character to separate thousands.",
- fn = function()
- local container = Settings.CreateControlTextContainer()
- container:Add(1, "1,000")
- container:Add(2, "1.000")
- return container:GetData()
- end,
+ [3] = {
+ title = "Extra Options:",
+ options = {
+ [1] = {
+ key = "thousandsSeparator",
+ name = "Thousands Separator",
+ tooltip = "Choose a character to separate thousands.",
+ choices = {
+ [1] = "1,000",
+ [2] = "1.000",
+ },
+ },
+ },
},
}
@@ -75,5 +80,5 @@ local CURRENT_LOCALE = GetLocale()
-- British English
if CURRENT_LOCALE == "enGB" then
- L.OptionsGeneral[1].name = "Prioritise character-specific stats"
+ L.Settings[1].options[2].name = "Prioritise character-specific stats"
end
diff --git a/options.lua b/options.lua
deleted file mode 100755
index 14f0abc..0000000
--- a/options.lua
+++ /dev/null
@@ -1,54 +0,0 @@
-local ADDON_NAME, ns = ...
-local L = ns.L
-
-local defaults = ns.data.defaults
-
-local function CreateCheckBox(category, variable, name, tooltip)
- local setting = Settings.RegisterAddOnSetting(category, ns.prefix .. variable, ns.prefix .. variable, HKT_options, type(defaults[variable]), name, defaults[variable])
- Settings.CreateCheckbox(category, setting, tooltip)
-end
-
-local function CreateDropDown(category, variable, name, options, tooltip)
- local setting = Settings.RegisterAddOnSetting(category, ns.prefix .. variable, ns.prefix .. variable, HKT_options, type(defaults[variable]), name, defaults[variable])
- Settings.CreateDropdown(category, setting, options, tooltip)
-end
-
-function ns:CreateSettingsPanel()
- local category, layout = Settings.RegisterVerticalLayoutCategory(ns.name)
- Settings.RegisterAddOnCategory(category)
-
- layout:AddInitializer(CreateSettingsListSectionHeaderInitializer(L.OptionsTitle1))
-
- for index = 1, #L.OptionsGeneral do
- local option = L.OptionsGeneral[index]
- if option.fn then
- CreateDropDown(category, option.key, option.name, option.fn, option.tooltip)
- else
- CreateCheckBox(category, option.key, option.name, option.tooltip)
- end
- end
-
- layout:AddInitializer(CreateSettingsListSectionHeaderInitializer(L.OptionsTitle2))
-
- for index = 1, #L.OptionsStats do
- local option = L.OptionsStats[index]
- if option.fn then
- CreateDropDown(category, option.key, option.name, option.fn, option.tooltip)
- else
- CreateCheckBox(category, option.key, option.name, option.tooltip)
- end
- end
-
- layout:AddInitializer(CreateSettingsListSectionHeaderInitializer(L.OptionsTitle3))
-
- for index = 1, #L.OptionsExtra do
- local option = L.OptionsExtra[index]
- if option.fn then
- CreateDropDown(category, option.key, option.name, option.fn, option.tooltip)
- else
- CreateCheckBox(category, option.key, option.name, option.tooltip)
- end
- end
-
- ns.Settings = category
-end