diff --git a/APR-Recorder.toc b/APR-Recorder.toc index 21f692d..dee5423 100644 --- a/APR-Recorder.toc +++ b/APR-Recorder.toc @@ -9,7 +9,7 @@ ## RequiredDeps: APR -## SavedVariables: AprRCData +## SavedVariables: AprRCData, AprRCSettings ## X-License: All Rights Reserved: You are free to fork and modify on GitHub, please ask us about anything else. ## X-Github: https://github.com/Azeroth-Pilot-Reloaded/APR-Route-Recorder diff --git a/Bindings.xml b/Bindings.xml index 2b89940..82e7b68 100644 --- a/Bindings.xml +++ b/Bindings.xml @@ -1,3 +1,3 @@ - + diff --git a/Commands.lua b/Commands.lua index e69de29..7f84019 100644 --- a/Commands.lua +++ b/Commands.lua @@ -0,0 +1,11 @@ +local L = LibStub("AceLocale-3.0"):GetLocale("APR-Route-Recorder") + +AprRC.command = AprRC:NewModule("Command") + +function AprRC.command:SlashCmd(input) + if not AprRC.settings.profile.enableAddon then + AprRC.settings:OpenSettings(AprRC.title) + end + + AprRC.settings:OpenSettings(AprRC.title) +end diff --git a/Config.lua b/Config.lua index e69de29..5cccfe7 100644 --- a/Config.lua +++ b/Config.lua @@ -0,0 +1,240 @@ +local _G = _G + +-- Locale +local L = LibStub("AceLocale-3.0"):GetLocale("APR-Route-Recorder") +local L_APR = LibStub("AceLocale-3.0"):GetLocale("APR") + + +AprRC.settings = AprRC:NewModule("Settings", "AceConsole-3.0") + +-- Ace option config table +local aceConfig = _G.LibStub("AceConfig-3.0") +local aceDialog = _G.LibStub("AceConfigDialog-3.0") + +-- Databroker support -- minimapIcon +local libDataBroker = LibStub("LibDataBroker-1.1") +local libDBIcon = LibStub("LibDBIcon-1.0") + +local function GetProfileOption(info) return AprRC.settings.profile[info[#info]] end + +local function SetProfileOption(info, value) + AprRC.settings.profile[info[#info]] = value +end + +function AprRC.settings:ResetSettings() + SettingsDB:ResetProfile() + self:RefreshProfile() +end + +function AprRC.settings:InitializeBlizOptions() + self:InitializeSettings() + self:createBlizzOptions() + self:CreateMiniMapButton() + + self:RegisterChatCommand("aprrc", self.ChatCommand) +end + +function AprRC.settings:InitializeSettings() + -- Default setting + local settingsDBDefaults = { + profile = { + -- frame + recordBarFrame = {}, + stepOptionBarFrame = {}, + --debug + enableMinimapButton = true, + debug = false, + enableAddon = true, + } + } + + SettingsDB = LibStub("AceDB-3.0"):New("AprRCSettings", settingsDBDefaults) + + SettingsDB.RegisterCallback(self, "OnProfileChanged", "RefreshProfile") + SettingsDB.RegisterCallback(self, "OnProfileCopied", "RefreshProfile") + SettingsDB.RegisterCallback(self, "OnProfileReset", "RefreshProfile") + self.profile = SettingsDB.profile +end + +function AprRC.settings.ChatCommand(input) + AprRC.command:SlashCmd(input) +end + +function AprRC.settings:RefreshProfile() + self.profile = SettingsDB.profile + C_UI.Reload() +end + +function AprRC.settings:createBlizzOptions() + -- Setting definition + local optionsTable = { + name = AprRC.title .. ' - ' .. AprRC.version, + type = "group", + args = { + discordButton = { + order = 1.1, + name = L_APR["JOIN_DISCORD"], + type = "execute", + width = 0.75, + func = function() + AprRC.questionDialog:CreateEditBoxPopup(L_APR["COPY_HELPER"], L["CLOSE"], AprRC.discord) + end + }, + githubButton = { + order = 1.2, + name = "Github", + type = "execute", + width = 0.75, + func = function() + AprRC.questionDialog:CreateEditBoxPopup(L_APR["COPY_HELPER"], L["CLOSE"], AprRC.github) + end + }, + buttonOffset = { + order = 1.3, + name = "", + type = "description", + width = 1.35, + }, + resetButton = { + order = 1.4, + name = L_APR["RESET_SETTINGS"], + type = "execute", + width = 0.75, + func = function() + AprRC.questionDialog:CreateQuestionPopup( + nil, + function() AprRC.settings:ResetSettings() end + ) + end + }, + header_Automation = { + order = 2, + type = "header", + width = "full", + name = "Somthing :)", + }, + somthing = { + order = 3, + type = "group", + name = "What a group", + inline = true, + args = { + enableAddon = { + order = 3.1, + type = "toggle", + name = L_APR["ENABLE_ADDON"], + width = "full", + get = GetProfileOption, + set = function(info, value) + SetProfileOption(info, value) + self:ToggleAddon() + end, + }, + enableMinimapButton = { + name = L_APR["ENABLE_MINIMAP_BUTTON"], + desc = L_APR["ENABLE_MINIMAP_BUTTON_DESC"], + type = "toggle", + width = "full", + order = 9.20, + get = GetProfileOption, + set = function(info, value) + SetProfileOption(info, value) + if value then + libDBIcon:Show(AprRC.title) + else + libDBIcon:Hide(AprRC.title) + end + end + }, + debug = { + order = 3.2, + type = "toggle", + name = L_APR["DEBUG"], + width = "full", + get = GetProfileOption, + set = SetProfileOption, + disabled = function() + return not self.profile.enableAddon + end, + }, + } + }, + } + } + + -- Register setting to the option table + aceConfig:RegisterOptionsTable(AprRC.title, optionsTable) + -- Add settings to bliz option + AprRC.Options = aceDialog:AddToBlizOptions(AprRC.title, AprRC.title) + + -- add profile to bliz option + aceConfig:RegisterOptionsTable(AprRC.title .. "/Profile", _G.LibStub("AceDBOptions-3.0"):GetOptionsTable(SettingsDB)) + aceDialog:AddToBlizOptions(AprRC.title .. "/Profile", L_APR["PROFILES"], AprRC.title) +end + +function AprRC.settings:CreateMiniMapButton() + if not self.profile.enableMinimapButton then return end + + local minimapButton = libDataBroker:NewDataObject(AprRC.title, { + type = "launcher", + icon = "Interface\\AddOns\\assets\\logo", + OnClick = function(_, button) + if button == "RightButton" then + self.profile.enableAddon = not self.profile.enableAddon + self:ToggleAddon() + else + AprRC.settings:OpenSettings(AprRC.title) + end + end, + OnTooltipShow = function(tooltip) + local toggleAddon = '' + if self.profile.enableAddon then + toggleAddon = "|ccce0000f " .. L_APR["DISABLE"] .. "|r" + else + toggleAddon = "|c33ecc00f " .. L_APR["ENABLE"] .. "|r" + end + tooltip:AddLine(APR.title) + tooltip:AddLine(L_APR["LEFT_CLICK"] .. ": |cffeda55f" .. L_APR["SHOW_MENU"] .. "|r", + unpack(AprRC.Color.white)) + tooltip:AddLine(L_APR["RIGHT_CLICK"] .. ": " .. toggleAddon .. "|cffeda55f " .. L_APR["ADDON"] .. "|r", + unpack(AprRC.Color.white)) + end + }) + + libDBIcon:Register(AprRC.title, minimapButton, self.profile.minimap); +end + +function AprRC.settings:ToggleAddon() + AprRC.record:RefreshFrameAnchor() +end + +function AprRC.settings:OpenSettings(name) + if name == AprRC.title then + InterfaceOptionsFrame_OpenToCategory(AprRC.title) + AprRC.settings:OpenSettings(L_APR["PROFILES"]) + end + if AprRC.Options then + if SettingsPanel then + local category = SettingsPanel:GetCategoryList():GetCategory(AprRC.Options.name) + if category then + SettingsPanel:Open() + SettingsPanel:SelectCategory(category) + if AprRC.OptionsRoute and category:HasSubcategories() then + for _, subcategory in pairs(category:GetSubcategories()) do + if subcategory:GetName() == name then + SettingsPanel:SelectCategory(subcategory) + break + end + end + end + end + return + elseif InterfaceOptionsFrame_OpenToCategory then + InterfaceOptionsFrame_OpenToCategory(AprRC.Options) + if AprRC.OptionsRoute then + InterfaceOptionsFrame_OpenToCategory(AprRC.OptionsRoute) + end + return + end + end +end diff --git a/Core.lua b/Core.lua index 90e3195..2638c93 100644 --- a/Core.lua +++ b/Core.lua @@ -5,10 +5,17 @@ AprRC = {} AprRC = _G.LibStub("AceAddon-3.0"):NewAddon(addon, "APR-Route-Recorder", "AceEvent-3.0") function AprRC:OnInitialize() + local GetAddOnMetadata = C_AddOns and C_AddOns.GetAddOnMetadata or _G.GetAddOnMetadata + -- Init on TOC AprRC.title = C_AddOns.GetAddOnMetadata("APR-Route-Recorder", "Title") AprRC.version = C_AddOns.GetAddOnMetadata("APR-Route-Recorder", "Version") - + AprRC.github = GetAddOnMetadata("APR-Route-Recorder", "X-Github") + AprRC.discord = GetAddOnMetadata("APR-Route-Recorder", "X-Discord") + AprRC.Color = { + white = { 1, 1, 1 }, + red = { 1, 0, 0 }, + } -- Init Settings -- APR.settings:InitializeBlizOptions() @@ -90,6 +97,9 @@ end -- - SpellTrigger -- - NoAutoFlightMap -- - DenyNPC +-- - TrigText +-- - Emote +-- - InstanceQuest -- -- only in route check if needed -- - ExtraActionB diff --git a/Event.lua b/Event.lua index 813a94b..e5609fb 100644 --- a/Event.lua +++ b/Event.lua @@ -76,7 +76,7 @@ AprRC.EventFrame:RegisterEvent("ZONE_CHANGED") AprRC.EventFrame:RegisterEvent("ZONE_CHANGED_INDOORS") AprRC.EventFrame:RegisterEvent("ZONE_CHANGED_NEW_AREA") AprRC.EventFrame:SetScript("OnEvent", function(self, event, ...) - if event then - return + if event == "PET_BATTLE_OPENING_START" or event == "PET_BATTLE_CLOSE" then + AprRC.record:RefreshFrameAnchor() end end) diff --git a/RecorderBar.lua b/RecorderBar.lua index e69de29..f122b86 100644 --- a/RecorderBar.lua +++ b/RecorderBar.lua @@ -0,0 +1,109 @@ +local _G = _G +local L = LibStub("AceLocale-3.0"):GetLocale("APR-Route-Recorder") +local LibWindow = LibStub("LibWindow-1.1") + +AprRC.record = AprRC:NewModule('Recorder') + +local isRecording = false +local isPaused = false +local orientation = "HORIZONTAL" + +local FRAME_WIDTH = 250 +local FRAME_HEIGHT = 100 +--------------------------------------------------------------------------------------- +--------------------------------- Recorder Frames ------------------------------------- +--------------------------------------------------------------------------------------- + +local RecordBarFrame = CreateFrame("Frame", "RecordBarFrame", UIParent, "BackdropTemplate") +RecordBarFrame:SetSize(FRAME_WIDTH, FRAME_HEIGHT) +RecordBarFrame:SetFrameStrata("MEDIUM") +RecordBarFrame:SetClampedToScreen(true) + +local function UpdateRecordButton(button) + if isRecording then + button.icon:SetTexture("Interface\\AddOns\\assets\\stop") + else + button.icon:SetTexture("Interface\\AddOns\\assets\\record") + end +end + +local function CreateButton(parent, iconPath, color) + local btn = CreateFrame("Button", nil, parent) + btn:SetSize(32, 32) + btn:SetPoint("TOPLEFT", 0, 0) + btn.icon = btn:CreateTexture(nil, "BACKGROUND") + btn.icon:SetAllPoints(btn) + btn.icon:SetTexture(iconPath) + btn.icon:SetVertexColor(unpack(color)) + return btn +end + +local recordBtn = CreateButton(RecordBarFrame, "Interface\\AddOns\\assets\\record", AprRC.Color.red) +recordBtn:SetScript("OnClick", function() + isRecording = not isRecording + UpdateRecordButton(recordBtn) +end) + +local pauseBtn = CreateButton(RecordBarFrame, "Interface\\AddOns\\assets\\pause", AprRC.Color.white) +pauseBtn:SetScript("OnClick", function() + isPaused = not isPaused +end) + +local updateBtn = CreateButton(RecordBarFrame, "Interface\\AddOns\\assets\\settings", AprRC.Color.white) +updateBtn:SetScript("OnClick", function() + AprRC.settings:OpenSettings(AprRC.title) +end) + +local orientationBtn = CreateButton(RecordBarFrame, "Interface\\AddOns\\assets\\rotation", AprRC.Color.white) +orientationBtn:SetScript("OnClick", function() + orientation = orientation == "HORIZONTAL" and "VERTICAL" or "HORIZONTAL" + AprRc.record:AdjustBarOrientation(RecordBarFrame) +end) +--------------------------------------------------------------------------------------- +----------------------------- Function Recorder Frames -------------------------------- +--------------------------------------------------------------------------------------- + + +function AprRC.record:FrameOnInit() + LibWindow.RegisterConfig(RecordBarFrame, APR.settings.profile.recordBarFrame) + RecordBarFrame.RegisteredForLibWindow = true + LibWindow.MakeDraggable(RecordBarFrame) + RecordBarFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 0) + + self:RefreshPartyFrameAnchor() +end + +function AprRC.record:RefreshFrameAnchor() + if not AprRC.settings.profile.enableAddon or C_PetBattles.IsInBattle() then + RecordBarFrame:Hide() + return + end + RecordBarFrame:EnableMouse(true) + self:AdjustBarOrientation(RecordBarFrame) + UpdateRecordButton(recordBtn) + LibWindow.RestorePosition(RecordBarFrame) + RecordBarFrame:Show() +end + +function AprRc.record:AdjustBarOrientation(bar) + local buttons = { recordBtn, pauseBtn, updateBtn, orientationBtn } + local spacing = 10 + local offsetX, offsetY = 10, -10 + + for i, btn in ipairs(buttons) do + if bar.orientation == "HORIZONTAL" then + btn:SetPoint("TOPLEFT", offsetX, offsetY) + offsetX = offsetX + btn:GetWidth() + spacing + else -- VERTICAL + btn:SetPoint("TOPLEFT", offsetX, offsetY) + offsetY = offsetY - btn:GetHeight() - spacing + end + end + if bar.orientation == "HORIZONTAL" then + bar:SetHeight(FRAME_HEIGHT) + bar:SetWidth(FRAME_WIDTH + (#buttons - 1) * spacing) + else + bar:SetWidth(FRAME_HEIGHT) + bar:SetHeight(FRAME_WIDTH + (#buttons - 1) * spacing) + end +end diff --git a/assets/pause.blp b/assets/pause.blp new file mode 100644 index 0000000..f053d64 Binary files /dev/null and b/assets/pause.blp differ diff --git a/assets/record.blp b/assets/record.blp new file mode 100644 index 0000000..e9eb99e Binary files /dev/null and b/assets/record.blp differ diff --git a/assets/rotation.blp b/assets/rotation.blp new file mode 100644 index 0000000..5cc9518 Binary files /dev/null and b/assets/rotation.blp differ diff --git a/assets/settings.blp b/assets/settings.blp new file mode 100644 index 0000000..524cda7 Binary files /dev/null and b/assets/settings.blp differ diff --git a/assets/stop.blp b/assets/stop.blp new file mode 100644 index 0000000..f6cbb92 Binary files /dev/null and b/assets/stop.blp differ