diff --git a/Localization/enUS.lua b/Localization/enUS.lua index 2ea9b49..c5f388e 100644 --- a/Localization/enUS.lua +++ b/Localization/enUS.lua @@ -2,8 +2,30 @@ local AceLocale = LibStub:GetLibrary("AceLocale-3.0") local L = AceLocale:NewLocale("Omen", "enUS", true) if not L then return end +-- Main Omen window L["Unknown"] = true +-- Config module titles +L["General Settings"] = true +L["Profiles"] = true +L["Slash Command"] = true + +-- Config strings, general settings section +L["OMEN_DESC"] = "Omen is a lightweight threat meter that shows you the threat of mobs you are engaged in combat with. You can change how Omen looks and behaves, and configure different profiles for every of your characters." +L["Alpha"] = true +L["Controls the transparency of the main Omen window."] = true +L["Scale"] = true +L["Controls the scaling of the main Omen window."] = true + +-- Config strings, slash command section +L["OMEN_SLASH_DESC"] = "These buttons execute the same functions as the ones in the slash command /omen" +L["Toggle Omen"] = true +L["Center Omen"] = true +L["Configure"] = true +L["Open the configuration dialog"] = true + +-- Slash command + BINDING_HEADER_OMEN = "Omen" BINDING_NAME_OMENTOGGLE = "Toggle Omen" diff --git a/Omen.lua b/Omen.lua index db13ef7..47bde1f 100644 --- a/Omen.lua +++ b/Omen.lua @@ -26,7 +26,8 @@ local GetNumRaidMembers, GetNumPartyMembers = GetNumRaidMembers, GetNumPartyMemb local db local defaults = { profile = { - Scale = 100, + Alpha = 1, + Scale = 1, GrowUp = false, Autocollapse = false, NumBars = 10, @@ -122,14 +123,7 @@ local function sizing() Omen:UpdateBars() end -function Omen:OnInitialize() - -- Create savedvariables - self.db = LibStub("AceDB-3.0"):New("Omen3DB", defaults) - self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged") - self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileChanged") - self.db.RegisterCallback(self, "OnProfileReset", "OnProfileChanged") - db = self.db.profile - +function Omen:CreateFrames() -- Create anchor self.Anchor = CreateFrame("Frame", "OmenAnchor", UIParent) self.Anchor:SetResizable(true) @@ -200,7 +194,19 @@ function Omen:OnInitialize() self:SetAnchors() end) self.Grip:SetScript("OnHide", self.Grip:GetScript("OnHide")) - +end + +function Omen:OnInitialize() + -- Create savedvariables + self.db = LibStub("AceDB-3.0"):New("Omen3DB", defaults) + self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged") + self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileChanged") + self.db.RegisterCallback(self, "OnProfileReset", "OnProfileChanged") + db = self.db.profile + + self:CreateFrames() + self:SetupOptions() + -- Register events that are "always on". The rest are in :OnEnable() self:RegisterEvent("PLAYER_LOGIN") self:RegisterEvent("PLAYER_ENTERING_WORLD") @@ -269,7 +275,7 @@ function Omen:SetAnchors(useDB) local x, y, w, h -- Set the scale, since the scaling affects the position - self.Anchor:SetScale(db.Scale / 100) + self.Anchor:SetScale(db.Scale) -- Get position if useDB then @@ -582,6 +588,7 @@ function Omen:UpdateBars() end if #sortTable == 0 then self:ClearAll() + self.TitleText:SetText(guidNameLookup[mobGUID]) return end sort(sortTable, sortfunction) @@ -638,3 +645,123 @@ function Omen:ResizeBars() end end + +----------------------------------------------------------------------------- +-- Omen config stuff + +local options = { + type = "group", + name = "Omen", + get = function(info) + local key = info[#info] + return Omen.db.profile[key] + end, + set = function(info, value) + local key = info[#info] + Omen.db.profile[key] = value + end, + args = { + general = { + order = 1, + type = "group", + name = L["General Settings"], + args = { + intro = { + order = 1, + type = "description", + name = L["OMEN_DESC"], + cmdHidden = true, + }, + Alpha = { + order = 3, + name = L["Alpha"], + type = "range", + min = 0, max = 1, step = 0.01, + isPercent = true, + desc = L["Controls the transparency of the main Omen window."], + set = function(info, value) + local key = info[#info] + Omen.db.profile[key] = value + Omen.Anchor:SetAlpha(value) + end, + }, + Scale = { + order = 5, + name = L["Scale"], + type = "range", + min = 0.50, max = 1.50, step = 0.01, + isPercent = true, + desc = L["Controls the scaling of the main Omen window."], + set = function(info, value) + local key = info[#info] + Omen.db.profile[key] = value + Omen:SetAnchors() + end, + }, + }, + }, + }, +} + +local optionsSlash = { + type = "group", + name = L["Slash Command"], + args = { + intro = { + order = 1, + type = "description", + name = L["OMEN_SLASH_DESC"], + cmdHidden = true, + }, + toggle = { + type = "execute", + name = L["Toggle Omen"], + desc = L["Toggle Omen"].." ( /omen toggle )", + func = function() + Omen:Toggle() + end, + }, + center = { + type = "execute", + name = L["Center Omen"], + desc = L["Center Omen"].." ( /omen center )", + func = function() + Omen.Anchor:ClearAllPoints() + Omen.Anchor:SetPoint("CENTER", UIParent, "CENTER") + Omen:SetAnchors() + end, + }, + config = { + type = "execute", + name = L["Configure"], + desc = L["Open the configuration dialog"].." ( /omen config )", + func = function() + Omen:ShowConfig() + end, + guiHidden = true, + } + }, +} + +function Omen:SetupOptions() + self.optionsFrames = {} + + -- setup options table + LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("Omen", options) + LibStub("AceConfig-3.0"):RegisterOptionsTable("OmenSlashCommand", optionsSlash, "omen") + self.optionsFrames.Omen = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Omen", nil, nil, "general") + + self:RegisterModuleOptions("Profiles", LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db), L["Profiles"]) + self:RegisterModuleOptions("OmenSlashCommand", optionsSlash, L["Slash Command"]) +end + +function Omen:RegisterModuleOptions(name, optionTbl, displayName) + options.args[name] = (type(optionTbl) == "function") and optionTbl() or optionTbl + self.optionsFrames[name] = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Omen", displayName, "Omen", name) +end + +function Omen:ShowConfig() + -- Open the profiles tab before, so the menu expands + InterfaceOptionsFrame_OpenToCategory(self.optionsFrames.Profiles) + InterfaceOptionsFrame_OpenToCategory(self.optionsFrames.Omen) +end