From 15450b69f8c03a567637c85eff958d855bd457b8 Mon Sep 17 00:00:00 2001 From: harrand Date: Sat, 13 May 2023 04:06:30 +0100 Subject: [PATCH] * Saved variables now kinda seems to work properly. Delay initialisation of everything till the saved vars are loaded basically. Not ideal but works --- HarrandSwingTimer.toc | 1 + src/hst_frame.lua | 12 +++++++++--- src/hst_main.lua | 10 ++++++++-- src/hst_settings.lua | 9 +++++++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/HarrandSwingTimer.toc b/HarrandSwingTimer.toc index 20af793..ca22aba 100644 --- a/HarrandSwingTimer.toc +++ b/HarrandSwingTimer.toc @@ -3,6 +3,7 @@ ## Notes: Modern swing timer for Dragonflight, with a focus on Crusading Strikes (CSAA) ## Version: 0.2.0 ## IconTexture: 135891 +## SavedVariablesPerCharacter: hst_db_t src/hst_settings.lua src/hst_swing.lua diff --git a/src/hst_frame.lua b/src/hst_frame.lua index 17422c5..5b1a77c 100644 --- a/src/hst_frame.lua +++ b/src/hst_frame.lua @@ -51,7 +51,8 @@ local function make_checkbox(parent, title, x, y, on_click_func, initial_val, to end local function impl_hst_options_menu(panel) - local swing_timer_visible = make_checkbox(panel, "Swing Timer Visible", 16, -16, function(self, value) + local swing_timer_visible_checkbox = make_checkbox(panel, "Swing Timer Visible", 16, -16, function(self, value) + hst.settings.swing_timer_visible = value hst.ui.main_frame:SetShown(value) end, hst.ui.main_frame:IsShown(), "Controls whether the swing timer is visible or not. Default: true") local csaa_mode_checkbox = make_checkbox(panel, "CSAA Mode", 16, -40, function(self, value) @@ -69,18 +70,22 @@ local function impl_hst_options_menu(panel) local w = hst.ui.main_frame:GetWidth() local h = hst.ui.main_frame:GetHeight() local slider_x = make_slider(panel, "X Position", 16, -84, function(ui, value) + hst.settings.swingx = value hst.ui.main_frame:SetPoint(p, hst.ui.main_frame:GetParent(), p, value, py) end, -dx/2, dx/2, px, "X Coordinate of the swing timer UI element") local slider_y = make_slider(panel, "Y Position", 16, -128, function(ui, value) + hst.settings.swingy = value hst.ui.main_frame:SetPoint(p, hst.ui.main_frame:GetParent(), p, px, value) end, -dy/2, dy, py, "Y Coordinate of the swing timer UI element") local slider_w = make_slider(panel, "Width", 16, -172, function(ui, value) + hst.settings.swingw = value hst.ui.main_frame:SetWidth(value) end, 0, 500, w, "X Coordinate of the swing timer UI element") local slider_h = make_slider(panel, "Y Position", 16, -216, function(ui, value) + hst.settings.swingh = value hst.ui.main_frame:SetHeight(value) end, 0, 500, h, "Y Coordinate of the swing timer UI element") end @@ -97,8 +102,9 @@ hst.create_frame = function() -- and then a frame to actually represent the swing timer. do hst.ui.main_frame = CreateFrame("Frame", "HarrandSwingTimer Frame", UIParent) - hst.ui.main_frame:SetSize(200, 20) - hst.ui.main_frame:SetPoint("CENTER", 0, -310) + hst.ui.main_frame:SetSize(hst.settings.swingw, hst.settings.swingh) + hst.ui.main_frame:SetPoint("CENTER", hst.settings.swingx, hst.settings.swingy) + hst.ui.main_frame:SetShown(hst.settings.swing_timer_visible) hst.ui.swing = CreateFrame("StatusBar", nil, hst.ui.main_frame) hst.ui.swing_background = CreateFrame("Frame", nil, hst.ui.main_frame) hst.ui.swing_background:SetAllPoints(hst.ui.main_frame) diff --git a/src/hst_main.lua b/src/hst_main.lua index 3c7b477..a310e30 100644 --- a/src/hst_main.lua +++ b/src/hst_main.lua @@ -1,4 +1,10 @@ local an, hst = ... -hst.create_frame() -hst.load_settings() +local f = CreateFrame("Frame") +f:RegisterEvent('ADDON_LOADED') +f:SetScript("OnEvent", function(self, event, arg1) + if(event == 'ADDON_LOADED' and arg1 == an) then + hst.load_settings() + hst.create_frame() + end +end) diff --git a/src/hst_settings.lua b/src/hst_settings.lua index 420adbc..423513f 100644 --- a/src/hst_settings.lua +++ b/src/hst_settings.lua @@ -1,7 +1,12 @@ local an, hst = ... -local hst_db_t = {} -hst_db_t.allow_csaa_override = true +hst_db_t = hst_db_t or {} +hst_db_t.allow_csaa_override = false +hst_db_t.swing_timer_visible = true +hst_db_t.swingx = 0 +hst_db_t.swingy = -310 +hst_db_t.swingw = 200 +hst_db_t.swingh = 20 hst.load_settings = function() -- todo: implement