From d2730f0d918a9ba796f1596afbd608fe42c89413 Mon Sep 17 00:00:00 2001 From: urnati Date: Fri, 7 Apr 2023 21:37:23 -0400 Subject: [PATCH] - More Profile fixes to ensure copy is correct - Internal code cleanup --- Titan/TitanConfig.lua | 17 +- Titan/TitanPanel.lua | 59 +---- Titan/TitanPanelTemplate.lua | 516 ++++++++++++++++++++++++------------------ Titan/TitanUtils.lua | 6 +- 4 files changed, 309 insertions(+), 289 deletions(-) diff --git a/Titan/TitanConfig.lua b/Titan/TitanConfig.lua index 30b62f5..42a72b3 100644 --- a/Titan/TitanConfig.lua +++ b/Titan/TitanConfig.lua @@ -50,6 +50,7 @@ changes = changes .."- Configuration > Skins shows available skins.\n" .."- Remove adjustment of XP & status bars and Bag & Menu buttons.\n" .."- Remove unused timers; only LDB timer left.\n" + .."- Internal code cleanup.\n" .."- Update TOC\n" ) .."\n\n" @@ -149,19 +150,6 @@ local function TitanPanel_GetLicense() return GetAddOnMetadata(TITAN_ID, "X-License") or L["TITAN_NA"]; end ---[[ local -NAME: TitanAdjustPanelScale -DESC: Set the Titan bars and plugins to the selected scale then adjust other frames as needed. -VAR: scale - the scale the user has selected for Titan -OUT: None ---]] -local function TitanAdjustPanelScale(scale) --- TitanPanel_InitPanelBarButton("Config scale change "..scale) --- TitanPanelBarButton_DisplayBarsWanted("Config scale change "..scale) - TitanPanel_SetScale() --- TitanPanel_AdjustFrames(true, "AdjustPanelScale") -end - -- helper functions ------------- @@ -617,7 +605,7 @@ local optionsUIScale = { set = function(_, a) if not InCombatLockdown() then TitanPanelSetVar("Scale", a) - TitanAdjustPanelScale(a) + TitanPanel_InitPanelBarButton("Config scale change "..scale) end end, disabled = function() @@ -863,7 +851,6 @@ local function TitanUpdateConfigBars(t, pos) -- Justify button position TitanPanelButton_Justify(); - --TitanPanelBarButton_ToggleAlign(v.name.."_Align"); end, } position = position + 1 -- Combat hide toggle diff --git a/Titan/TitanPanel.lua b/Titan/TitanPanel.lua index b69a18b..3e07e3a 100644 --- a/Titan/TitanPanel.lua +++ b/Titan/TitanPanel.lua @@ -333,7 +333,6 @@ function TitanPanel_PlayerEnteringWorld() for idx, v in pairs (TitanBarData) do TitanPanelButton_CreateBar(idx) end --- TitanPanel_InitPanelBarButton() Titan_AutoHide_Create_Frames() local realmName = GetRealmName() @@ -507,7 +506,7 @@ function TitanPanelBarButton:CVAR_UPDATE(cvarname, cvarvalue) or cvarname == "WINDOWED_MODE" or cvarname == "uiScale" then if TitanPlayerSettings and TitanPanelGetVar("Scale") then - TitanPanel_SetScale() + TitanPanel_InitPanelBarButton() -- TitanPanel_SetScale() end end end @@ -703,7 +702,7 @@ local function handle_reset_cmds(cmd_list) elseif p1 == "panelscale" then if not InCombatLockdown() then TitanPanelSetVar("Scale", 1); - TitanPanel_SetScale() + TitanPanel_InitPanelBarButton() -- TitanPanel_SetScale() TitanPrint(L["TITAN_PANEL_SLASH_RESP3"], "info") else TitanPrint(L["TITAN_PANEL_MENU_IN_COMBAT_LOCKDOWN"], "warning") @@ -1108,23 +1107,6 @@ end -------------------------------------------------------------- -- -- Titan features ---[[ Titan -NAME: TitanPanelBarButton_ToggleAlign -DESC: Align the buttons per the user's new choice. -VAR: align - left or center -OUT: None ---]] -function TitanPanelBarButton_ToggleAlign(align) - -- toggle between left or center - if ( TitanPanelGetVar(align) == TITAN_PANEL_BUTTONS_ALIGN_CENTER ) then - TitanPanelSetVar(align, TITAN_PANEL_BUTTONS_ALIGN_LEFT); - else - TitanPanelSetVar(align, TITAN_PANEL_BUTTONS_ALIGN_CENTER); - end - - -- Justify button position - TitanPanelButton_Justify(); -end --[[ Titan NAME: TitanPanelBarButton_ForceLDBLaunchersRight @@ -1392,21 +1374,6 @@ print("_Hide" end --[[ Titan -NAME: TitanPanel_InitPanelBarButton -DESC: Set the scale, texture (graphic), and transparancy of all the Titan bars based on the user selection. -VAR: None -OUT: None ---]] -function TitanPanel_InitPanelBarButton() - -- Set initial Panel Scale - TitanPanel_SetScale(); - - for idx,v in pairs (TitanBarData) do - TitanPanel_SetBarTexture(idx) - end -end - ---[[ Titan NAME: TitanPanel_InitPanelButtons DESC: Show all user selected plugins on the Titan bar(s) then justify per the user selection. VAR: None @@ -1664,28 +1631,6 @@ function TitanPanelButton_Justify() end end ---[[ Titan -NAME: TitanPanel_SetScale -DESC: Set the scale of each plugin and each Titan bar. -VAR: None -OUT: None ---]] -function TitanPanel_SetScale() - local scale = TitanPanelGetVar("Scale"); - - -- Set all the Titan bars - for idx,v in pairs (TitanBarData) do - local bar_name = TITAN_PANEL_DISPLAY_PREFIX..TitanBarData[idx].name - _G[bar_name]:SetScale(scale) - end - -- Set all the registered plugins - for index, value in pairs(TitanPlugins) do - if index then - TitanUtils_GetButton(index):SetScale(scale); - end - end -end - -------------------------------------------------------------- -- -- Local routines for Titan menu creation diff --git a/Titan/TitanPanelTemplate.lua b/Titan/TitanPanelTemplate.lua index 7080f6a..61a2491 100644 --- a/Titan/TitanPanelTemplate.lua +++ b/Titan/TitanPanelTemplate.lua @@ -59,6 +59,270 @@ local _G = getfenv(0); local InCombatLockdown = _G.InCombatLockdown; local media = LibStub("LibSharedMedia-3.0") +-- +--========================== +-- Routines to handle moving and sizing of short bars +-- + +local function CheckBarBounds(self, width) + local result = {} + local err = "" + local res = "" + + local f_name = self:GetName() + local bar_name = TitanBarData[f_name].name + local locale_name = TitanBarData[f_name].locale_name + + if TitanBarData[f_name].user_move + and TitanBarDataVars[f_name].show + then + local tscale = TitanPanelGetVar("Scale") +--[===[ +print("CheckBounds" +.." '"..tostring(bar_name).."'" +.." "..(width == 0 and "drag" or "width").."" +.." T "..tostring(format("%0.1f", tscale)).."" +.." UI "..tostring(format("%0.1f", UIParent:GetEffectiveScale())).."" +) +--]===] + -- Assumes BOTTOMLEFT of screen per Short bar defaults. + -- Top and right adjust an addition pixel, + -- if resolution is not 'pixel perfect' rounding could cause algorithm to think bar is off screen + local orig_w = self:GetWidth() + local l_off = self:GetLeft() + local r_off = self:GetRight() + local t_off = self:GetTop() + local b_off = self:GetBottom() + local screen_right, screen_top = TitanUtils_ScreenSize() + + local w = 0 + local x_off = 0 + local y_off = 0 + local w_off = 0 +local show_errs = true + if (width == 0) then -- drag and drop + -- Keep the width + w_off = orig_w +--[===[ +print(">>CheckBounds" +.." '"..tostring(bar_name).."'" +.." l "..tostring(format("%0.1f", l_off)).."" +.." r "..tostring(format("%0.1f", r_off)).."" +.." t "..tostring(format("%0.1f", t_off)).."" +.." b "..tostring(format("%0.1f", b_off)).."" +.." et "..tostring(format("%0.1f", (t_off * tscale))).."" +) +--]===] + -- Assume all ok :) + x_off = l_off + y_off = b_off + res = "Ok" + if l_off < 0 then + x_off = 0 + err = "Off left side of screen, leaving on the edge." + res = "Off L" + elseif r_off > screen_right then + x_off = (screen_right - orig_w) - 1 + err = "Off right side of screen, leaving on the edge." + res = "Off R" + end + if show_errs and err ~= "" then + TitanPrint(locale_name.." "..err.."!!!!" + .." ["..tostring(format("%0.1f", x_off)).."]" + .." ["..tostring(format("%0.1f", y_off)).."]" + , "warning") + end + if (t_off * tscale) > screen_top then + y_off = b_off - ((t_off * tscale) - screen_top) - 1 + err = "Off top of screen, leaving on the edge." + res = "Off T" + elseif b_off < 0 then + y_off = 0 + err = "Off bottom of screen, leaving on the edge." + res = "Off B" + end + if show_errs and err ~= "" then + TitanPrint(locale_name.." "..err.."!!!!" + .." ["..tostring(format("%0.1f", x_off)).."]" + .." ["..tostring(format("%0.1f", y_off)).."]" + , "warning") + end + else -- width change + local min_w, min_h, max_w, max_h = self:GetResizeBounds() + -- Keep the X and Y + x_off = l_off + y_off = b_off + + w = orig_w + width + if w < min_w then + -- do nothing - too small + w_off = min_w + err = "Width too small. Set to min width." + res = "Too small" + elseif w > max_w then + w_off = max_w + err = "Width too big. Set to max width." -- too wide + res = "Too big" + elseif x_off + w > screen_right then + w_off = orig_w + err = "Off right side of screen, leaving on the edge." + res = "Off R" + else + w_off = w + res = "Ok" + end + self:SetSize(w_off, TITAN_PANEL_BAR_HEIGHT) + if show_errs and err ~= "" then + TitanPrint(locale_name.." "..err.."!!!!" + .." ["..tostring(format("%0.1f", orig_w)).."]" + .." ["..tostring(format("%0.1f", w_off)).."]" + , "warning") + end + end + +--[===[ +---[[ +print(">>CheckBounds" +.." '"..tostring(bar_name).."'" +.." '"..tostring(res).."'" +.."\n" +.." x "..tostring(format("%0.1f", l_off)).."" +.." => "..tostring(format("%0.1f", x_off)).."" +.."\n" +.." y "..tostring(format("%0.1f", b_off)).."" +.." => "..tostring(format("%0.1f", y_off)).."" +.."\n" +.." w "..tostring(format("%0.1f", orig_w)).."" +.." + "..tostring(format("%0.1f", width)).."" +.." = "..tostring(format("%0.1f", w_off)).."" +.."\n" +.." s "..tostring(format("%0.1f", screen_right)).."w" +.." x "..tostring(format("%0.1f", screen_top)).."h" +) +--]] +--]===] + +-- TitanVariables_SetBarPos(self, false, x_off, y_off, w_off) + else + -- Controlled with anchor points; cannot move so no check is needed + end + + if err == "" then + -- all is good + result.ok = true + else + result.ok = false + end + +--[[ +print("CheckBounds" +.." '"..tostring(locale_name).."'" +.." w "..tostring(format("%0.1f", orig_w)).."" +.." + "..tostring(format("%0.1f", w)).."" +.." = "..tostring(format("%0.1f", self:GetWidth())).."" +) +print(">>" +.." x "..tostring(format("%0.1f", x_off)).."" +.." => "..tostring(format("%0.1f", result.x)).."" +) +print(">>" +.." y "..tostring(format("%0.1f", y_off)).."" +.." => "..tostring(format("%0.1f", result.y)).."" +) +print(">>" +.." w "..tostring(format("%0.1f", self:GetWidth())).."" +.." s "..tostring(format("%0.1f", screen_edge)).."" +) +--]] + return result +end + +local function OnMoveStart(self) + if IsShiftKeyDown() then + if self:IsMovable() then + self.isMoving = true +--[[ +print("OnMoveStart" +.." "..tostring(self:GetName()).."" +.." "..tostring(IsShiftKeyDown()).."" +.." "..tostring(IsAltKeyDown()).."" +.."\n" +.." x "..tostring(format("%0.1f", self:GetLeft())).."" +.." y "..tostring(format("%0.1f", self:GetTop())).."" +) +--]] + self:StartMoving() + _G.GameTooltip:Hide() + end + else + -- Do not move + end +end + +local function OnMovingStop(self) + + self:StopMovingOrSizing() + self.isMoving = nil + + local res = CheckBarBounds(self, 0) +--[[ +print("OnMovingStop" +.." "..tostring(self:GetName()).."" +.." x: "..tostring(res.x).."" +.." y: "..tostring(res.y).."" +.." ok: "..tostring(res.ok).."" +) +--]] + if res.ok then + else + end + -- Seems overkill - this will recalc all bars but recalc of textures could be needed... + TitanPanel_InitPanelBarButton("Check bounds") +end + +local function OnMouseWheel(self, d) + if IsShiftKeyDown() then + local old_w = self:GetWidth() + local res = CheckBarBounds(self, d) + if res.ok then + end +--[[ +print("wheel" +.." "..tostring(f_name).."" +.." old: "..tostring(old_w).."" +.." new: "..tostring(self:GetWidth()).."" +.." ok: "..tostring(res.ok).."" +) +--]] + -- Seems overkill - this will recalc all bars but recalc of textures could be needed... + TitanPanel_InitPanelBarButton("Check bounds") + end +end + +--========================== + +--[[ local +NAME: TitanPanel_SetScale +DESC: Set the scale of each plugin and each Titan bar. +VAR: None +OUT: None +--]] +function TitanPanel_SetScale() + local scale = TitanPanelGetVar("Scale"); + + -- Set all the Titan bars + for idx,v in pairs (TitanBarData) do + local bar_name = TITAN_PANEL_DISPLAY_PREFIX..TitanBarData[idx].name + _G[bar_name]:SetScale(scale) + end + -- Set all the registered plugins + for index, value in pairs(TitanPlugins) do + if index then + TitanUtils_GetButton(index):SetScale(scale); + end + end +end + --[[ local NAME: TitanTooltip_AddTooltipText DESC: Helper to add a line of tooltip text to the tooltip. @@ -675,7 +939,6 @@ end TitanPanelRightClickMenu_Close(); local position = TitanUtils_GetWhichBar(id) - local scale = TitanPanelGetVar("Scale"); if (isControlFrameShown) then -- Note: This uses anchor points to place the control frame relative to the plugin on the screen. @@ -1039,6 +1302,7 @@ function TitanPanelButton_UpdateButton(id, setButtonWidth) -- Used by plugins end end + --[[ API NAME: TitanPanelButton_UpdateTooltip DESC: Update the tooltip of the given Titan plugin. @@ -1124,6 +1388,29 @@ function TitanPanelButton_GetType(id) end --[[ Titan +NAME: TitanPanelButton_ApplyBarPos +DESC: Apply saved Bar position to the Bar frame. +VAR: frame_str - string name of the Bar frame +OUT: None +NOTE: +- Bit of a sledge hammer; used when loading a profile over the current one so the Bars ready to be placed. +:NOTE +--]] +function TitanPanelButton_ApplyBarPos(frame_str) + local frame = _G[frame_str] + local bdata = TitanBarData[frame] + local fdata = TitanBarDataVars[frame_str] + if frame and bdata and fdata then + frame:ClearAllPoints(); + if bdata.user_move then + frame:SetPoint(bdata.show.pt, bdata.show.rel_fr, bdata.show.rel_pt, fdata.off_x, fdata.off_y) + else + -- Set bar, ignore + end + end +end + +--[[ Titan NAME: TitanOptionsSliderTemplate_OnLoad DESC: Loads the Backdrop for TitanOptionsSliderTemplate with new 9.0 API VAR: self - The frame @@ -1144,223 +1431,22 @@ function TitanOptionsSliderTemplate_OnLoad(self) }) end --- ---========================== --- Routines to handle moving and sizing of short bars --- - -local function CheckBounds(self, width) - local result = {} - local err = "" - local res = "" - - local f_name = self:GetName() - local bar_name = TitanBarData[f_name].name - local locale_name = TitanBarData[f_name].locale_name - - if TitanBarData[f_name].user_move then - -- Assumes BOTTOMLEFT of screen per Short bar defaults. ---[===[ -print("CheckBounds" -.." '"..tostring(bar_name).."'" -.." '"..tostring(width).."'" -.." "..(width == 0 and "drag" or "width").."" -) ---]===] - local min_w, min_h, max_w, max_h = self:GetResizeBounds() - local orig_w = self:GetWidth() --/ UIParent:GetEffectiveScale() -- take out scaling to get 'real' width - local l_off = self:GetLeft() -- * UIParent:GetEffectiveScale() - local r_off = self:GetRight() -- * UIParent:GetEffectiveScale() - local t_off = self:GetTop() -- * UIParent:GetEffectiveScale() - local b_off = self:GetBottom() -- * UIParent:GetEffectiveScale() - local screen_right, screen_top = TitanUtils_ScreenSize() - - local w = 0 - local x_off = 0 - local y_off = 0 - local w_off = 0 - if TitanBarData[f_name] then - if (width == 0) then -- drag and drop - -- Keep the width - w_off = orig_w - - if l_off < 0 then - err = "Off left side of screen, leaving on the edge." - x_off = 0 - y_off = b_off - res = "Off L" - elseif r_off > screen_right then - err = "Off right side of screen, leaving on the edge." - x_off = screen_right - orig_w - y_off = b_off - res = "Off R" - elseif t_off > screen_top then - err = "Off top of screen, leaving on the edge." - x_off = l_off - y_off = screen_top - TITAN_PANEL_BAR_HEIGHT - res = "Off T" - elseif b_off < 0 then - err = "Off bottom of screen, leaving on the edge." - x_off = l_off - y_off = 0 - res = "Off B" - else - -- all seems ok - x_off = l_off - y_off = b_off - res = "Ok" - end - else -- width change - -- Keep the X and Y - x_off = l_off - y_off = b_off - - w = orig_w + width - if w < min_w then - -- do nothing - too small - err = "Width too small. Set to min width." - w_off = min_w - res = "Too small" - elseif w > max_w then - err = "Width too big. Set to max width." -- too wide - w_off = max_w - res = "Too big" - elseif x_off + w > screen_right then - err = "Off right side of screen, leaving on the edge." - w_off = orig_w - res = "Off R" - else - w_off = w - res = "Ok" - end - self:SetSize(w_off, TITAN_PANEL_BAR_HEIGHT) - end - end - ---[===[ ----[[ -print(">>CheckBounds" -.." '"..tostring(bar_name).."'" -.." '"..tostring(res).."'" -.."\n" -.." x "..tostring(format("%0.1f", l_off)).."" -.." => "..tostring(format("%0.1f", x_off)).."" -.."\n" -.." y "..tostring(format("%0.1f", b_off)).."" -.." => "..tostring(format("%0.1f", y_off)).."" -.."\n" -.." w "..tostring(format("%0.1f", orig_w)).."" -.." + "..tostring(format("%0.1f", width)).."" -.." = "..tostring(format("%0.1f", w_off)).."" -.."\n" -.." s "..tostring(format("%0.1f", screen_right)).."w" -.." x "..tostring(format("%0.1f", screen_top)).."h" -) ---]] ---]===] - - TitanVariables_SetBarPos(self, false, - x_off, y_off, w_off) --- x_off / UIParent:GetEffectiveScale(), y_off / UIParent:GetEffectiveScale(), w_off) - else - -- Controlled with anchor points so no check is needed - end - - if err == "" then - -- all is good - result.ok = true - else - result.ok = false - TitanPrint(locale_name.." "..err.."!!!!", "error") - end - ---[[ -print("CheckBounds" -.." '"..tostring(locale_name).."'" -.." w "..tostring(format("%0.1f", orig_w)).."" -.." + "..tostring(format("%0.1f", w)).."" -.." = "..tostring(format("%0.1f", self:GetWidth())).."" -) -print(">>" -.." x "..tostring(format("%0.1f", x_off)).."" -.." => "..tostring(format("%0.1f", result.x)).."" -) -print(">>" -.." y "..tostring(format("%0.1f", y_off)).."" -.." => "..tostring(format("%0.1f", result.y)).."" -) -print(">>" -.." w "..tostring(format("%0.1f", self:GetWidth())).."" -.." s "..tostring(format("%0.1f", screen_edge)).."" -) ---]] - return result -end - -local function OnMoveStart(self) - if IsShiftKeyDown() then - if self:IsMovable() then - self.isMoving = true ---[[ -print("OnMoveStart" -.." "..tostring(self:GetName()).."" -.." "..tostring(IsShiftKeyDown()).."" -.." "..tostring(IsAltKeyDown()).."" -.."\n" -.." x "..tostring(format("%0.1f", self:GetLeft())).."" -.." y "..tostring(format("%0.1f", self:GetTop())).."" -) ---]] - self:StartMoving() - _G.GameTooltip:Hide() - end - else - -- Do not move - end -end - -local function OnMovingStop(self) - - self:StopMovingOrSizing() - self.isMoving = nil - - local res = CheckBounds(self, 0) ---[[ -print("OnMovingStop" -.." "..tostring(self:GetName()).."" -.." x: "..tostring(res.x).."" -.." y: "..tostring(res.y).."" -.." ok: "..tostring(res.ok).."" -) +--[[ Titan +NAME: TitanPanel_InitPanelBarButton +DESC: Set the scale, texture (graphic), and transparancy of all the Titan bars based on the user selection. +VAR: None +OUT: None --]] - if res.ok then - else - end - -- Seems overkill - this will recalc all bars but recalc of textures could be needed... - TitanPanel_InitPanelBarButton("Check bounds") - -- The drag or width change occrred on screen but may need adjusting from user drop if bounds condition. - TitanPanelBarButton_DisplayBarsWanted("Short Bar change - "..(width == o and "width" or "drag").." - "..tostring(f_name)) -end +function TitanPanel_InitPanelBarButton() + -- Set initial Panel Scale + TitanPanel_SetScale(); -local function OnMouseWheel(self, d) - if IsShiftKeyDown() then - local old_w = self:GetWidth() - local res = CheckBounds(self, d) - if res.ok then - end ---[[ -print("wheel" -.." "..tostring(f_name).."" -.." old: "..tostring(old_w).."" -.." new: "..tostring(self:GetWidth()).."" -.." ok: "..tostring(res.ok).."" -) ---]] - -- Seems overkill - this will recalc all bars but recalc of textures could be needed... - TitanPanel_InitPanelBarButton("Check bounds") - -- The drag or width change occrred on screen but may need adjusting from user drop if bounds condition. - TitanPanelBarButton_DisplayBarsWanted("Short Bar change - "..(width == o and "width" or "drag").." - "..tostring(f_name)) + for idx,v in pairs (TitanBarData) do + CheckBarBounds(_G[idx], 0) + TitanPanel_SetBarTexture(idx) end + + TitanPanelBarButton_DisplayBarsWanted("InitPanelBarButton") end -- diff --git a/Titan/TitanUtils.lua b/Titan/TitanUtils.lua index bc3243b..76aa62d 100644 --- a/Titan/TitanUtils.lua +++ b/Titan/TitanUtils.lua @@ -1980,12 +1980,14 @@ function TitanUtils_ScreenSize(output) .."\n" .." UI - x:"..tostring(format("%0.1f", x)).."" .." X y:"..tostring(format("%0.1f", y)).."" - .." scale:"..tostring(format("%0.6f", s)).."" .."\n" .." UI scaled - x:"..tostring(format("%0.1f", screen_x * UIParent:GetEffectiveScale())).."" .." X y:"..tostring(format("%0.1f", screen_y * UIParent:GetEffectiveScale())).."" .."\n" - .." screen - x:"..tostring(format("%0.1f",px)).."" + .." Scale: UI"..tostring(format("%0.6f", s)).."" + .." Titan "..tostring(format("%0.1f", TitanPanelGetVar("Scale"))).."" + .."\n" + .." screen - x:"..tostring(format("%0.1f", px)).."" .." X y:"..tostring(format("%0.1f", py)).."" ) end -- 1.7.9.5