diff --git a/KillTrack.lua b/KillTrack.lua index 786314b..66c9d4c 100644 --- a/KillTrack.lua +++ b/KillTrack.lua @@ -39,10 +39,27 @@ local KT = select(2, ...) _G[NAME] = KT +-- Shim C_AddOns for older clients (Vanilla Classic) +if not C_AddOns then + C_AddOns = { + GetAddOnMetadata = GetAddOnMetadata or function() return nil end, + IsAddOnLoaded = IsAddOnLoaded or function() return false end, + } +end + -- Upvalue some functions used in CLEU -local IsGUIDInGroup = IsGUIDInGroup +local IsGUIDInGroup = IsGUIDInGroup or function(guid) + if not guid then return false end + for i = 1, 4 do + if UnitGUID("party" .. i) == guid then return true end + end + for i = 1, 40 do + if UnitGUID("raid" .. i) == guid then return true end + end + return false +end local UnitGUID = UnitGUID -local UnitIsTapDenied = UnitIsTapDenied +local UnitIsTapDenied = UnitIsTapDenied or function() return false end local UnitTokenFromGUID = UnitTokenFromGUID local CombatLogGetCurrentEventInfo = CombatLogGetCurrentEventInfo local GetServerTime = GetServerTime diff --git a/KillTrack.toc b/KillTrack.toc index 532baca..3a3bd45 100644 --- a/KillTrack.toc +++ b/KillTrack.toc @@ -1,7 +1,9 @@ -## Interface: 110105 -## Interface-Vanilla: 11507 +## Interface: 110207 +## Interface-Vanilla: 11508 +## Interface-BCC: 20505 +## Interface-Wrath: 30405 ## Interface-Cata: 40402 -## Version: @project-version@ +## Version: v2.32.0 ## Title: KillTrack ## Notes: Keeps track of how many kills you have per mob and displays them in a list. ## Author: Sharparam @@ -12,14 +14,10 @@ ## X-WoWI-ID: 20509 ## X-Wago-ID: 5bGoqo60 -#@no-lib-strip@ libs\LibStub\LibStub.lua libs\CallbackHandler-1.0\CallbackHandler-1.0.xml -#@end-no-lib-strip@ libs\LibDataBroker-1-1\LibDataBroker-1.1.lua -#@no-lib-strip@ libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua -#@end-no-lib-strip@ Tools.lua KillTrack.lua diff --git a/KillTrack_Cata.toc b/KillTrack_Cata.toc new file mode 100644 index 0000000..50e2b1e --- /dev/null +++ b/KillTrack_Cata.toc @@ -0,0 +1,27 @@ +## Interface: 40402 +## Version: v2.32.0 +## Title: KillTrack +## Notes: Keeps track of how many kills you have per mob and displays them in a list. +## Author: Sharparam +## SavedVariables: KILLTRACK +## SavedVariablesPerCharacter: KILLTRACK_CHAR +## OptionalDeps: LibStub, CallbackHandler-1.0, LibDBIcon-1.0 +## X-Curse-Project-ID: 33976 +## X-WoWI-ID: 20509 +## X-Wago-ID: 5bGoqo60 + +libs\LibStub\LibStub.lua +libs\CallbackHandler-1.0\CallbackHandler-1.0.xml +libs\LibDataBroker-1-1\LibDataBroker-1.1.lua +libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua +Tools.lua +KillTrack.lua +Dialogs.lua +Command.lua +MobList.lua +Timer.lua +TimerFrame.lua +ImmediateFrame.lua +ExpTracker.lua +Broker.lua +Options.lua diff --git a/KillTrack_TBC.toc b/KillTrack_TBC.toc new file mode 100644 index 0000000..ebd1d6e --- /dev/null +++ b/KillTrack_TBC.toc @@ -0,0 +1,27 @@ +## Interface: 20505 +## Version: v2.32.0 +## Title: KillTrack +## Notes: Keeps track of how many kills you have per mob and displays them in a list. +## Author: Sharparam +## SavedVariables: KILLTRACK +## SavedVariablesPerCharacter: KILLTRACK_CHAR +## OptionalDeps: LibStub, CallbackHandler-1.0, LibDBIcon-1.0 +## X-Curse-Project-ID: 33976 +## X-WoWI-ID: 20509 +## X-Wago-ID: 5bGoqo60 + +libs\LibStub\LibStub.lua +libs\CallbackHandler-1.0\CallbackHandler-1.0.xml +libs\LibDataBroker-1-1\LibDataBroker-1.1.lua +libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua +Tools.lua +KillTrack.lua +Dialogs.lua +Command.lua +MobList.lua +Timer.lua +TimerFrame.lua +ImmediateFrame.lua +ExpTracker.lua +Broker.lua +Options.lua diff --git a/KillTrack_Vanilla.toc b/KillTrack_Vanilla.toc new file mode 100644 index 0000000..aaa2768 --- /dev/null +++ b/KillTrack_Vanilla.toc @@ -0,0 +1,27 @@ +## Interface: 11508 +## Version: v2.32.0 +## Title: KillTrack +## Notes: Keeps track of how many kills you have per mob and displays them in a list. +## Author: Sharparam +## SavedVariables: KILLTRACK +## SavedVariablesPerCharacter: KILLTRACK_CHAR +## OptionalDeps: LibStub, CallbackHandler-1.0, LibDBIcon-1.0 +## X-Curse-Project-ID: 33976 +## X-WoWI-ID: 20509 +## X-Wago-ID: 5bGoqo60 + +libs\LibStub\LibStub.lua +libs\CallbackHandler-1.0\CallbackHandler-1.0.xml +libs\LibDataBroker-1-1\LibDataBroker-1.1.lua +libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua +Tools.lua +KillTrack.lua +Dialogs.lua +Command.lua +MobList.lua +Timer.lua +TimerFrame.lua +ImmediateFrame.lua +ExpTracker.lua +Broker.lua +Options.lua diff --git a/KillTrack_Wrath.toc b/KillTrack_Wrath.toc new file mode 100644 index 0000000..febb329 --- /dev/null +++ b/KillTrack_Wrath.toc @@ -0,0 +1,27 @@ +## Interface: 30405 +## Version: v2.32.0 +## Title: KillTrack +## Notes: Keeps track of how many kills you have per mob and displays them in a list. +## Author: Sharparam +## SavedVariables: KILLTRACK +## SavedVariablesPerCharacter: KILLTRACK_CHAR +## OptionalDeps: LibStub, CallbackHandler-1.0, LibDBIcon-1.0 +## X-Curse-Project-ID: 33976 +## X-WoWI-ID: 20509 +## X-Wago-ID: 5bGoqo60 + +libs\LibStub\LibStub.lua +libs\CallbackHandler-1.0\CallbackHandler-1.0.xml +libs\LibDataBroker-1-1\LibDataBroker-1.1.lua +libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua +Tools.lua +KillTrack.lua +Dialogs.lua +Command.lua +MobList.lua +Timer.lua +TimerFrame.lua +ImmediateFrame.lua +ExpTracker.lua +Broker.lua +Options.lua diff --git a/Options.lua b/Options.lua index ee67e18..23613ba 100644 --- a/Options.lua +++ b/Options.lua @@ -1,276 +1,263 @@ ---[[ - * Copyright (c) 2011-2020 by Adam Hellberg. - * - * This file is part of KillTrack. - * - * KillTrack is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * KillTrack is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with KillTrack. If not, see . ---]] - ----@class KillTrack -local KT = select(2, ...) - -local KTT = KT.Tools - ----@class KillTrackOptions -local Opt = { - Panel = CreateFrame("Frame") -} - -KT.Options = Opt - -local panel = Opt.Panel - ----@diagnostic disable-next-line: inject-field -panel.name = "KillTrack" -panel:Hide() - -local category = Settings.RegisterCanvasLayoutCategory(panel, panel.name) -Opt.Category = category - --- Dirty hack to give a name to option checkboxes -local checkCounter = 0 - ----@param label string ----@param description string ----@param onclick function ----@return table|CheckButton -local function checkbox(label, description, onclick) - local check = CreateFrame( - "CheckButton", - "KillTrackOptCheck" .. checkCounter, - panel, - "InterfaceOptionsCheckButtonTemplate") - check:SetScript("OnClick", function(self) - local checked = self:GetChecked() - PlaySound(checked and SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON or SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF) - onclick(self, checked and true or false) - end) - ---@diagnostic disable-next-line: inject-field - check.label = _G[check:GetName() .. "Text"] - check.label:SetText(label) - ---@diagnostic disable-next-line: inject-field - check.tooltipText = label - ---@diagnostic disable-next-line: inject-field - check.tooltipRequirement = description - checkCounter = checkCounter + 1 - return check -end - ----@param text string ----@param tooltip string ----@param onclick function ----@return table|Button -local function button(text, tooltip, onclick) - local btn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate") - btn:SetText(text) - ---@diagnostic disable-next-line: inject-field - btn.tooltipText = tooltip - btn:SetScript("OnClick", function(self) onclick(self) end) - btn:SetHeight(24) - return btn -end - -local function HideBlizzOptions() - HideUIPanel(InterfaceOptionsFrame) - HideUIPanel(GameMenuFrame) -end - -function Opt:Open() - Settings.OpenToCategory(self.Category.ID) -end - ----@param self Frame -function Opt.Show(self) - local title = self:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge") - title:SetPoint("TOPLEFT", 16, -16) - title:SetText("KillTrack") - - local printKills = checkbox("Print kill updates to chat", - "With this enabled, every kill you make is going to be announced locally in the chatbox", - function(_, checked) KT.Global.PRINTKILLS = checked end) - printKills:SetPoint("TOPLEFT", title, "BOTTOMLEFT", -2, -16) - - local tooltipControl = checkbox("Show mob data in tooltip", - "With this enabled, KillTrack will print data about mobs in the tooltip", - function(_, checked) KT.Global.TOOLTIP = checked end) - tooltipControl:SetPoint("LEFT", printKills, "RIGHT", 180, 0) - - local printNew = checkbox("Print new mob entries to chat", - "With this enabled, new mobs added to the database will be announced locally in the chat", - function(_, checked) KT.Global.PRINTNEW = checked end) - printNew:SetPoint("TOPLEFT", printKills, "BOTTOMLEFT", 0, -8) - - local countGroup = checkbox("Count group kills", - "With this disabled, only killing blows made by yourself will count", - function(_, checked) KT.Global.COUNT_GROUP = checked end) - countGroup:SetPoint("TOPLEFT", printNew, "BOTTOMLEFT", 0, -8) - - local thresholdDesc = self:CreateFontString(nil, "ARTWORK", "GameFontNormal") - thresholdDesc:SetPoint("TOPLEFT", countGroup, "BOTTOMLEFT", 0, -8) - thresholdDesc:SetTextColor(1, 1, 1) - thresholdDesc:SetText("Threshold for displaying kill achievements (press enter to apply)") - - local threshold = CreateFrame("EditBox", "KillTrackOptThreshold", panel, "InputBoxTemplate") - threshold:SetHeight(22) - threshold:SetWidth(150) - threshold:SetPoint("LEFT", thresholdDesc, "RIGHT", 8, 0) - threshold:SetAutoFocus(false) - threshold:EnableMouse(true) - threshold:SetScript("OnEditFocusGained", function(box) - box:SetTextColor(0, 1, 0) - box:HighlightText() - end) - local function setThreshold(box, enter) - box:SetTextColor(1, 1, 1) - local value = tonumber(box:GetNumber()) - if value and value > 0 then - KT.Global.ACHIEV_THRESHOLD = value - if not enter then - KT:Msg("Updated threshold value!") - end - box:ClearFocus() - box:SetText(KT.Global.ACHIEV_THRESHOLD) - else - box:SetText(KT.Global.ACHIEV_THRESHOLD) - box:HighlightText() - end - end - threshold:SetScript("OnEditFocusLost", function(box) setThreshold(box) end) - threshold:SetScript("OnEnterPressed", function(box) setThreshold(box, true) end) - - local showTarget = button("Target", "Show information about the currently selected target", - function() - if not UnitExists("target") or UnitIsPlayer("target") then return end - local id = KTT.GUIDToID(UnitGUID("target")) - KT:PrintKills(id) - end) - showTarget:SetWidth(150) - showTarget:SetPoint("TOPLEFT", thresholdDesc, "BOTTOMLEFT", 0, -8) - - local list = button("List", "Open the mob database", - function() - HideBlizzOptions() - KT.MobList:Show() - end) - list:SetWidth(150) - list:SetPoint("TOPLEFT", showTarget, "TOPRIGHT", 8, 0) - - local purge = button("Purge", "Purge mob entries with a kill count below a specified number", - function() KT:ShowPurge() end) - purge:SetWidth(150) - purge:SetPoint("TOPLEFT", showTarget, "BOTTOMLEFT", 0, -8) - - local reset = button("Reset", "Clear the database of ALL mob entries", - function() KT:ShowReset() end) - reset:SetWidth(150) - reset:SetPoint("TOPLEFT", purge, "TOPRIGHT", 8, 0) - - local minimap = checkbox("Show minimap icon", "Adds the KillTrack broker to your minimap", - function(_, checked) KT.Broker:SetMinimap(checked) end) - minimap:SetPoint("TOPLEFT", purge, "BOTTOMLEFT", 0, -8) - - local disableDungeons = checkbox("Disable in dungeons (save CPU)", - "When this is checked, mob kills in dungeons won't be counted.", - function(_, checked) KT.Global.DISABLE_DUNGEONS = checked end) - disableDungeons:SetPoint("TOPLEFT", minimap, "BOTTOMLEFT", 0, -8) - - local disableRaids = checkbox("Disable in raids (save CPU)", - "When this is checked, mob kills in raids won't be counted.", - function(_, checked) KT.Global.DISABLE_RAIDS = checked end) - disableRaids:SetPoint("TOPLEFT", disableDungeons, "BOTTOMLEFT", 0, -8) - - local datetimeFormatDesc = self:CreateFontString(nil, "ARTWORK", "GameFontNormal") - datetimeFormatDesc:SetPoint("TOPLEFT", disableRaids, "BOTTOMLEFT", 0, -8) - datetimeFormatDesc:SetTextColor(1, 1, 1) - datetimeFormatDesc:SetText("Datetime format template (press enter to apply)") - - local datetimeFormat = CreateFrame("EditBox", "KillTrackOptDateTimeFormat", panel, "InputBoxTemplate") - datetimeFormat:SetHeight(22) - datetimeFormat:SetWidth(200) - datetimeFormat:SetPoint("LEFT", datetimeFormatDesc, "RIGHT", 8, 0) - datetimeFormat:SetAutoFocus(false) - datetimeFormat:EnableMouse(true) - local datetimeFormatPreview = self:CreateFontString(nil, "ARTWORK", "GameFontNormal") - datetimeFormatPreview:SetPoint("TOPLEFT", datetimeFormat, "BOTTOMLEFT", 0, -2) - datetimeFormatPreview:SetTextColor(1, 1, 1) - datetimeFormatPreview:SetText("Preview:") - local datetimeFormatPreviewValue = self:CreateFontString(nil, "ARTWORK", "GameFontNormal") - datetimeFormatPreviewValue:SetPoint("LEFT", datetimeFormatPreview, "RIGHT", 8, 0) - datetimeFormatPreviewValue:SetTextColor(1, 1, 1) - datetimeFormatPreviewValue:SetText(KTT:FormatDateTime() --[[@as string]]) - - datetimeFormat:SetScript("OnEditFocusGained", function(box) - box:SetTextColor(0, 1, 0) - box:HighlightText() - end) - local function setDateTimeFormat(box, enter) - box:SetTextColor(1, 1, 1) - local value = box:GetText() - if type(value) ~= "string" then - box:SetText(KT.Global.DATETIME_FORMAT) - box:HighlightText() - return - end - local valid, errMsg = pcall(KTT.FormatDateTime, KTT, nil, value) - if not valid then - KT:Msg("Invalid format string: " .. (errMsg or "unknown error")) - box:HighlightText() - return - end - KT.Global.DATETIME_FORMAT = value - if not enter then - KT:Msg("Updated datetime format!") - end - box:ClearFocus() - box:SetText(KT.Global.DATETIME_FORMAT) - end - datetimeFormat:SetScript("OnEditFocusLost", function(box) setDateTimeFormat(box) end) - datetimeFormat:SetScript("OnEnterPressed", function(box) setDateTimeFormat(box, true) end) - datetimeFormat:SetScript("OnTextChanged", function(box) - local value = box:GetText() - if type(value) ~= "string" then return end - local valid, result = pcall(KTT.FormatDateTime, KTT, nil, value) - if valid then - datetimeFormatPreviewValue:SetText(result --[[@as string]]) - else - datetimeFormatPreviewValue:SetText("invalid format") - end - end) - local datetimeFormatReset = button("Reset", "Reset the datetime format to the default", function() - KT.Global.DATETIME_FORMAT = KT.Defaults.DateTimeFormat - datetimeFormat:SetText(KT.Global.DATETIME_FORMAT) - end) - datetimeFormatReset:SetWidth(80) - datetimeFormatReset:SetPoint("LEFT", datetimeFormat, "RIGHT", 5, 0) - - local function init() - printKills:SetChecked(KT.Global.PRINTKILLS) - tooltipControl:SetChecked(KT.Global.TOOLTIP) - printNew:SetChecked(KT.Global.PRINTNEW) - countGroup:SetChecked(KT.Global.COUNT_GROUP) - threshold:SetText(tostring(KT.Global.ACHIEV_THRESHOLD)) - minimap:SetChecked(not KT.Global.BROKER.MINIMAP.hide) - disableDungeons:SetChecked(KT.Global.DISABLE_DUNGEONS) - disableRaids:SetChecked(KT.Global.DISABLE_RAIDS) - datetimeFormat:SetText(KT.Global.DATETIME_FORMAT) - end - - init() - - self:SetScript("OnShow", init) -end - -panel:SetScript("OnShow", function(self) Opt.Show(self) end) - -Settings.RegisterAddOnCategory(category) +--[[ + * Copyright (c) 2011-2020 by Adam Hellberg. + * + * This file is part of KillTrack. + * + * KillTrack is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KillTrack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KillTrack. If not, see . +--]] + +local _, KT = ... +local KTT = KT.Tools + +KT.Options = { + Panel = CreateFrame("Frame") +} + +local Opt = KT.Options + +local panel = Opt.Panel + +panel.name = "KillTrack" +panel:Hide() + +-- Dirty hack to give a name to option checkboxes +local checkCounter = 0 + +local function checkbox(label, description, onclick) + local check = CreateFrame( + "CheckButton", + "KillTrackOptCheck" .. checkCounter, + panel, + "InterfaceOptionsCheckButtonTemplate") + check:SetScript("OnClick", function(self) + local checked = self:GetChecked() + PlaySound(checked and SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON or SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF) + onclick(self, checked and true or false) + end) + check.label = _G[check:GetName() .. "Text"] + check.label:SetText(label) + check.tooltipText = label + check.tooltipRequirement = description + checkCounter = checkCounter + 1 + return check +end + +local function button(text, tooltip, onclick) + local btn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate") + btn:SetText(text) + btn.tooltipText = tooltip + btn:SetScript("OnClick", function(self) onclick(self) end) + btn:SetHeight(24) + return btn +end + +local function HideBlizzOptions() + HideUIPanel(InterfaceOptionsFrame) + HideUIPanel(GameMenuFrame) +end + +function Opt:Open() + InterfaceOptionsFrame_OpenToCategory(panel) + InterfaceOptionsFrame_OpenToCategory(panel) +end + +function Opt:Show() + local title = self:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge") + title:SetPoint("TOPLEFT", 16, -16) + title:SetText("KillTrack") + + local printKills = checkbox("Print kill updates to chat", + "With this enabled, every kill you make is going to be announced locally in the chatbox", + function(_, checked) KT.Global.PRINT = checked end) + printKills:SetPoint("TOPLEFT", title, "BOTTOMLEFT", -2, -16) + + local tooltipControl = checkbox("Show mob data in tooltip", + "With this enabled, KillTrack will print data about mobs in the tooltip", + function(_, checked) KT.Global.TOOLTIP = checked end) + tooltipControl:SetPoint("LEFT", printKills, "RIGHT", 180, 0) + + local printNew = checkbox("Print new mob entries to chat", + "With this enabled, new mobs added to the database will be announced locally in the chat", + function(_, checked) KT.Global.PRINTNEW = checked end) + printNew:SetPoint("TOPLEFT", printKills, "BOTTOMLEFT", 0, -8) + + local countGroup = checkbox("Count group kills", + "With this disabled, only killing blows made by yourself will count", + function(_, checked) KT.Global.COUNT_GROUP = checked end) + countGroup:SetPoint("TOPLEFT", printNew, "BOTTOMLEFT", 0, -8) + + local thresholdDesc = self:CreateFontString(nil, "ARTWORK", "GameFontNormal") + thresholdDesc:SetPoint("TOPLEFT", countGroup, "BOTTOMLEFT", 0, -8) + thresholdDesc:SetTextColor(1, 1, 1) + thresholdDesc:SetText("Threshold for displaying kill achievements (press enter to apply)") + + local threshold = CreateFrame("EditBox", "KillTrackOptThreshold", panel, "InputBoxTemplate") + threshold:SetHeight(22) + threshold:SetWidth(150) + threshold:SetPoint("LEFT", thresholdDesc, "RIGHT", 8, 0) + threshold:SetAutoFocus(false) + threshold:EnableMouse(true) + threshold:SetScript("OnEditFocusGained", function(box) + box:SetTextColor(0, 1, 0) + box:HighlightText() + end) + local function setThreshold(box, enter) + box:SetTextColor(1, 1, 1) + local value = tonumber(box:GetNumber()) + if value and value > 0 then + KT.Global.ACHIEV_THRESHOLD = value + if not enter then + KT:Msg("Updated threshold value!") + end + box:ClearFocus() + box:SetText(KT.Global.ACHIEV_THRESHOLD) + else + box:SetText(KT.Global.ACHIEV_THRESHOLD) + box:HighlightText() + end + end + threshold:SetScript("OnEditFocusLost", function(box) setThreshold(box) end) + threshold:SetScript("OnEnterPressed", function(box) setThreshold(box, true) end) + + local showTarget = button("Target", "Show information about the currently selected target", + function() + if not UnitExists("target") or UnitIsPlayer("target") then return end + local id = KTT:GUIDToID(UnitGUID("target")) + KT:PrintKills(id) + end) + showTarget:SetWidth(150) + showTarget:SetPoint("TOPLEFT", thresholdDesc, "BOTTOMLEFT", 0, -8) + + local list = button("List", "Open the mob database", + function() + HideBlizzOptions() + KT.MobList:Show() + end) + list:SetWidth(150) + list:SetPoint("TOPLEFT", showTarget, "TOPRIGHT", 8, 0) + + local purge = button("Purge", "Purge mob entries with a kill count below a specified number", + function() KT:ShowPurge() end) + purge:SetWidth(150) + purge:SetPoint("TOPLEFT", showTarget, "BOTTOMLEFT", 0, -8) + + local reset = button("Reset", "Clear the database of ALL mob entries", + function() KT:ShowReset() end) + reset:SetWidth(150) + reset:SetPoint("TOPLEFT", purge, "TOPRIGHT", 8, 0) + + local minimap = checkbox("Show minimap icon", "Adds the KillTrack broker to your minimap", + function(_, checked) KT.Broker:SetMinimap(checked) end) + minimap:SetPoint("TOPLEFT", purge, "BOTTOMLEFT", 0, -8) + + local disableDungeons = checkbox("Disable in dungeons (save CPU)", + "When this is checked, mob kills in dungeons won't be counted.", + function(_, checked) KT.Global.DISABLE_DUNGEONS = checked end) + disableDungeons:SetPoint("TOPLEFT", minimap, "BOTTOMLEFT", 0, -8) + + local disableRaids = checkbox("Disable in raids (save CPU)", + "When this is checked, mob kills in raids won't be counted.", + function(_, checked) KT.Global.DISABLE_RAIDS = checked end) + disableRaids:SetPoint("TOPLEFT", disableDungeons, "BOTTOMLEFT", 0, -8) + + local datetimeFormatDesc = self:CreateFontString(nil, "ARTWORK", "GameFontNormal") + datetimeFormatDesc:SetPoint("TOPLEFT", disableRaids, "BOTTOMLEFT", 0, -8) + datetimeFormatDesc:SetTextColor(1, 1, 1) + datetimeFormatDesc:SetText("Datetime format template (press enter to apply)") + + local datetimeFormat = CreateFrame("EditBox", "KillTrackOptDateTimeFormat", panel, "InputBoxTemplate") + datetimeFormat:SetHeight(22) + datetimeFormat:SetWidth(200) + datetimeFormat:SetPoint("LEFT", datetimeFormatDesc, "RIGHT", 8, 0) + datetimeFormat:SetAutoFocus(false) + datetimeFormat:EnableMouse(true) + local datetimeFormatPreview = self:CreateFontString(nil, "ARTWORK", "GameFontNormal") + datetimeFormatPreview:SetPoint("TOPLEFT", datetimeFormat, "BOTTOMLEFT", 0, -2) + datetimeFormatPreview:SetTextColor(1, 1, 1) + datetimeFormatPreview:SetText("Preview:") + local datetimeFormatPreviewValue = self:CreateFontString(nil, "ARTWORK", "GameFontNormal") + datetimeFormatPreviewValue:SetPoint("LEFT", datetimeFormatPreview, "RIGHT", 8, 0) + datetimeFormatPreviewValue:SetTextColor(1, 1, 1) + datetimeFormatPreviewValue:SetText(KTT:FormatDateTime()) + + datetimeFormat:SetScript("OnEditFocusGained", function(box) + box:SetTextColor(0, 1, 0) + box:HighlightText() + end) + local function setDateTimeFormat(box, enter) + box:SetTextColor(1, 1, 1) + local value = box:GetText() + if type(value) ~= "string" then + box:SetText(KT.Global.DATETIME_FORMAT) + box:HighlightText() + return + end + local valid, errMsg = pcall(KTT.FormatDateTime, KTT, nil, value) + if not valid then + KT:Msg("Invalid format string: " .. (errMsg or "unknown error")) + box:HighlightText() + return + end + KT.Global.DATETIME_FORMAT = value + if not enter then + KT:Msg("Updated datetime format!") + end + box:ClearFocus() + box:SetText(KT.Global.DATETIME_FORMAT) + end + datetimeFormat:SetScript("OnEditFocusLost", function(box) setDateTimeFormat(box) end) + datetimeFormat:SetScript("OnEnterPressed", function(box) setDateTimeFormat(box, true) end) + datetimeFormat:SetScript("OnTextChanged", function(box) + local value = box:GetText() + if type(value) ~= "string" then return end + local valid, result = pcall(KTT.FormatDateTime, KTT, nil, value) + if valid then + datetimeFormatPreviewValue:SetText(result) + else + datetimeFormatPreviewValue:SetText("invalid format") + end + end) + local datetimeFormatReset = button("Reset", "Reset the datetime format to the default", function() + KT.Global.DATETIME_FORMAT = KT.Defaults.DateTimeFormat + datetimeFormat:SetText(KT.Global.DATETIME_FORMAT) + end) + datetimeFormatReset:SetWidth(80) + datetimeFormatReset:SetPoint("LEFT", datetimeFormat, "RIGHT", 5, 0) + + local function init() + printKills:SetChecked(KT.Global.PRINT) + tooltipControl:SetChecked(KT.Global.TOOLTIP) + printNew:SetChecked(KT.Global.PRINTNEW) + countGroup:SetChecked(KT.Global.COUNT_GROUP) + threshold:SetText(KT.Global.ACHIEV_THRESHOLD) + minimap:SetChecked(not KT.Global.BROKER.MINIMAP.hide) + disableDungeons:SetChecked(KT.Global.DISABLE_DUNGEONS) + disableRaids:SetChecked(KT.Global.DISABLE_RAIDS) + datetimeFormat:SetText(KT.Global.DATETIME_FORMAT) + end + + init() + + self:SetScript("OnShow", init) +end + +panel:SetScript("OnShow", function(self) Opt.Show(self) end) + +-- Compatibility: Anniversary realm uses new Settings API +if InterfaceOptions_AddCategory then + InterfaceOptions_AddCategory(panel) +elseif Settings and Settings.RegisterCanvasLayoutCategory then + local category = Settings.RegisterCanvasLayoutCategory(panel, panel.name) + Settings.RegisterAddOnCategory(category) +end