Quantcast

- Make "RightClickMenu" a constant

urnati [04-18-23 - 18:29]
- Make "RightClickMenu" a constant
Filename
Titan/Titan.lua
Titan/Titan.xml
Titan/TitanPanel.xml
Titan/TitanTemplate.lua
Titan/TitanUtils.lua
Titan/TitanVariables.lua
diff --git a/Titan/Titan.lua b/Titan/Titan.lua
index 4ea033c..344d9f8 100644
--- a/Titan/Titan.lua
+++ b/Titan/Titan.lua
@@ -1824,15 +1824,10 @@ local function BuildServerProfilesMenu()
 end

 --[[ local
-NAME: TitanPanel_PlayerSettingsMenu
-DESC: Show list of toons submenu off Profiles/Manage/<server or custom> from the Titan right click menu.
+NAME: BuildPluginMenu
+DESC: Show list of plugin defined options from the Titan right click menu.
 VAR:  None
 OUT:  None
-NOTE:
-- There are 2 level 3 menus possible
-  1) Under profiles, then value could be the server of a saved toon
-  2) Under plugins value could be the options of a plugin
-:NOTE
 --]]
 local function BuildPluginMenu()
 	--
@@ -1842,10 +1837,8 @@ local function BuildPluginMenu()

 	for index, id in pairs(TitanPluginsIndex) do
 		local plugin = TitanUtils_GetPlugin(id)
---		local _, _, menu_plugin = string.find(TitanPanelRightClickMenu_GetDropdMenuValue(), R_PLUGIN.."(.-)")
 		local par_val = TitanPanelRightClickMenu_GetDropdMenuValue()
 		local menu_plugin = string.gsub(par_val, R_PLUGIN, "")
---		if plugin.id and plugin.id == TitanPanelRightClickMenu_GetDropdMenuValue() then
 		if plugin.id and plugin.id == menu_plugin then
 			--title
 			info = {};
@@ -1935,6 +1928,12 @@ local function BuildPluginMenu()
 	end
 end

+--[[ local
+NAME: BuildPluginMenu
+DESC: Show alphabetical list of toons submenu off Profiles/Manage/<server or custom> from the Titan right click menu.
+VAR:  None
+OUT:  None
+--]]
 local function BuildProfileMenu()
 	--
 	local info = {};
@@ -1943,7 +1942,6 @@ local function BuildProfileMenu()
 	--
 	-- Handle the profiles
 	--
---	for index, id in pairs(TitanSettings.Players) do
 	for idx = 1, #TitanVars.players do
 		local index = TitanVars.players[idx]
 		local player, server = TitanUtils_ParseName(index)
@@ -2095,15 +2093,17 @@ end

 --[[ Titan
 NAME: TitanPanelRightClickMenu_PrepareBarMenu
-DESC: This is the controller to show the proper level of the Titan (right click) menu.
-VAR: self - expected to be the Tian bar that was right clicked
+DESC: This is the controller of the Titan (right click) menu.
+VAR: self - expected to be the Titan bar that was right clicked
 OUT: None
+NOTE:
+- Frame name used is <Titan bar name>RightClickMenu
+:NOTE
 --]]
 function TitanPanelRightClickMenu_PrepareBarMenu(self)
 	-- Determine which bar was clicked on
-	-- This MUST match the convention used in TitanPanel.xml to declare
-	-- the dropdown menu. ($parentRightClickMenu)
-	local s, e, frame = string.find(self:GetName(), "(.*)RightClickMenu");
+--	local s, e, frame = string.find(self:GetName(), "(.*)RightClickMenu");
+	local s, e, frame = string.find(self:GetName(), "(.*)"..TITAN_PANEL_CLICK_MENU_SUFFIX);
 	local lev = (TitanPanelRightClickMenu_GetDropdownLevel() or 1)
 --[[
 print("_prep R click"
@@ -2118,6 +2118,9 @@ print("_prep R click"
 	end

 	-- Level 2
+	-- Plugin Categories => Plugins in that category
+	-- OR
+	-- Profiles => Server / Realm list
 	if ( lev == 2 ) then
 		if string.find(TitanPanelRightClickMenu_GetDropdMenuValue(), R_ADDONS) then
 			BuildPluginCategoryMenu(frame)
@@ -2130,6 +2133,9 @@ print("_prep R click"
 	end

 	-- Level 3
+	-- Plugin Categories => Plugins in that category => Plugin defined options
+	-- OR
+	-- Profiles => Server / Realm list => Character on realm list
 	if ( lev == 3 ) then
 		if string.find(TitanPanelRightClickMenu_GetDropdMenuValue(), R_PLUGIN) then
 			BuildPluginMenu()
@@ -2141,8 +2147,9 @@ print("_prep R click"
 	end

 	-- Level 4
+	-- Profiles => Server / Realm list => Character on realm list => load / delete
 	if ( lev == 4 ) then
-		BuildAProfileMenu() -- only load / delete profiles for now
+		BuildAProfileMenu()
 		return;
 	end

@@ -2173,3 +2180,341 @@ function TitanPanel_GetPluginSide(id)
 		return TITAN_LEFT;
 	end
 end
+
+--
+--==========================
+-- Routines to handle moving and sizing of short bars
+--
+
+--[[ local
+NAME: TitanPanel_SetScale
+DESC: Set the scale of each plugin and each Titan bar.
+VAR:  None
+OUT:  None
+--]]
+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
+	local escale = UIParent:GetEffectiveScale()
+
+	if TitanBarData[f_name].user_move
+	and TitanBarDataVars[f_name].show
+	then
+		local tscale = TitanPanelGetVar("Scale")
+--		local tscale = self:GetEffectiveScale()
+		local screen = TitanUtils_ScreenSize()
+		local screen_right_scaled = screen.scaled_x
+		local screen_top_scaled = screen.scaled_y
+		local screen_right = screen.x
+		local screen_top = screen.y
+
+		-- 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
+
+		--- Back out the Titan scaling to get 'real' position within unscaled WoW window
+		-- Use floor to trunc decimal places where the side could be right on the edge of the screen.
+		local orig_w = self:GetWidth()
+		local l_off = math.floor(self:GetLeft() * tscale)
+		local r_off = math.floor(self:GetRight() * tscale)
+		local t_off = math.floor(self:GetTop() * tscale)
+		local b_off = math.floor(self:GetBottom() * tscale)
+
+		local w = 0
+		local x_off = 0
+		local y_off = 0
+		local w_off = 0
+
+		-- Assume all ok :)
+		x_off = l_off
+		y_off = b_off
+
+local show_errs = false
+		if (width == 0) then -- drag and drop
+			-- Keep the width
+			w_off = orig_w
+			res = "Ok"
+
+			if l_off < 0 then
+				x_off = 0
+				err = "Off left of screen, leaving on the edge."
+				res = "Off L"
+			elseif (r_off) > screen_right then
+--				x_off = math.floor(l_off - math.abs((r_off - screen_right)))
+				x_off = math.floor(screen_right - (r_off - l_off))
+				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
+			err = ""
+			if (t_off) > screen_top then
+--				y_off = math.floor(b_off - ((t_off) - screen_top))
+				y_off = math.floor(screen_top - (t_off - b_off))
+				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
+			w_new = orig_w + width
+
+			if w_new < min_w then
+				-- do nothing - too small
+				w_off = min_w
+				err = "Width too small. Set to min width."
+				res = "Too small"
+			elseif w_new > max_w then
+				w_off = max_w
+				err = "Width too big. Set to max width." -- too wide
+				res = "Too big"
+			elseif x_off + w_new > screen_right then
+				w_off = orig_w
+				err = "Off right of screen, leaving on the edge."
+				res = "Off R"
+			else
+				w_off = w_new
+				res = "Ok"
+			end
+
+			self:SetSize(w_off, TITAN_PANEL_BAR_HEIGHT)
+--			self:SetWidth(w_off)
+			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
+
+		-- Offsets are saved in without scale
+		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
+
+	return result
+end
+
+--[[ local
+NAME: OnMoveStart
+DESC: Start the grap of a Short Titan bar if Shift and left mouse are held.
+VAR:  self - the bar frame
+OUT:  None
+--]]
+local function OnMoveStart(self)
+	if IsShiftKeyDown() then
+		if self:IsMovable() then
+			self.isMoving = true
+			self:StartMoving()
+			_G.GameTooltip:Hide()
+		end
+	else
+		-- Do not move
+	end
+end
+
+--[[
+print("OnMoveStart"
+.." "..tostring(self:GetName())..""
+.." "..tostring(IsShiftKeyDown())..""
+.." "..tostring(IsAltKeyDown())..""
+.."\n"
+.." x "..tostring(format("%0.1f", self:GetLeft()))..""
+.." y "..tostring(format("%0.1f", self:GetTop()))..""
+)
+--]]
+
+--[[ local
+NAME: OnMovingStop
+DESC: When a Short Titan bar drag is stopped.
+VAR:  self - the bar frame
+OUT:  None
+--]]
+local function OnMovingStop(self)
+
+	self:StopMovingOrSizing()
+	self.isMoving = nil
+
+	local res = CheckBarBounds(self, 0)
+	if res.ok then
+	else
+	end
+	-- Seems overkill - this will recalc all bars...
+	TitanPanel_InitPanelBarButton("OnMovingStop")
+end
+
+--[[ local
+NAME: OnMouseWheel
+DESC: Change the width of a Short Titan bar when mouse is over the bar and Shift is held when the mouse wheel is used.
+VAR:  self - the bar frame
+VAR:  d - mouse wheel direction; assuming a 1 'click' is a pixel
+OUT:  None
+NOTE:
+- Can get noisy, "Initializes" all bars at each click to ensure the bar is drawn.
+:NOTE
+--]]
+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(self:GetName())..""
+.." "..tostring(d)..""
+.." old: "..tostring(format("%0.1f", old_w))..""
+.." new: "..tostring(format("%0.1f", self:GetWidth()))..""
+.." ok: "..tostring(res.ok)..""
+)
+--]]
+		-- Seems overkill - this will recalc all bars but recalc of textures could be needed...
+		TitanPanel_InitPanelBarButton("OnMouseWheel")
+	end
+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
+		CheckBarBounds(_G[idx], 0)
+		TitanPanel_SetBarTexture(idx)
+	end
+
+	TitanPanelBarButton_DisplayBarsWanted("InitPanelBarButton")
+end
+
+--
+--==========================
+-- Routines to handle creation of Titan bars
+--
+--[[ Titan
+NAME: TitanPanelButton_CreateBar(frame_str)
+DESC: Create a Titan bar that can show plugins.
+VAR: frame_str - name of the frame
+NOTE:
+- This assumes ...
+:NOTE
+--]]
+function TitanPanelButton_CreateBar(frame_str)
+	local this_bar = frame_str
+	local a_bar = CreateFrame("Button", this_bar, UIParent, "Titan_Bar__Display_Template")
+
+	local bar_data = TitanBarData[this_bar]
+
+	-- ======
+	-- Scripts
+	a_bar:SetScript("OnEnter", function(self) TitanPanelBarButton_OnEnter(self) end)
+	a_bar:SetScript("OnLeave", function(self) TitanPanelBarButton_OnLeave(self) end)
+	a_bar:SetFrameStrata("DIALOG")
+
+	local x, y, w = TitanVariables_GetBarPos(frame_str)
+	local tscale = TitanPanelGetVar("Scale")
+--[[
+print("_Create bar"
+.." "..tostring(bar_data.name)..""
+.."\n "
+.." "..tostring(bar_data.name)..""
+.." "..tostring(bar_data.show.pt)..""
+.." "..tostring(bar_data.show.rel_fr)..""
+.." "..tostring(bar_data.show.rel_pt)..""
+.."\n "
+.." "..tostring(bar_data.name)..""
+.." "..tostring(format("%0.1f", x))..""
+.." "..tostring(format("%0.1f", y))..""
+.." "..tostring(format("%0.1f", w))..""
+)
+--]]
+	if bar_data.user_move then
+		a_bar:SetPoint(bar_data.show.pt, bar_data.show.rel_fr, bar_data.show.rel_pt, x, y)
+		a_bar:SetMovable(true)
+		a_bar:SetResizable(true)
+		a_bar:EnableMouse(true)
+		a_bar:RegisterForDrag("LeftButton")
+		a_bar:SetScript("OnDragStart", OnMoveStart)
+		a_bar:SetScript("OnDragStop", OnMovingStop)
+		a_bar:SetScript("OnMouseWheel", OnMouseWheel)
+		a_bar:SetSize(w / tscale, TITAN_PANEL_BAR_HEIGHT)
+	else
+		-- Static full width bar
+		a_bar:SetPoint(bar_data.show.pt, bar_data.show.rel_fr, bar_data.show.rel_pt, x, y)
+		a_bar:SetPoint(bar_data.show.pt, bar_data.show.rel_fr, bar_data.show.rel_pt, x, y - TITAN_PANEL_BAR_HEIGHT)
+	end
+
+	-- ======
+	-- Bounds only effective on Short bars for now
+	-- Min : No smaller than the padding & one icon
+	-- Max : No wider than the screen
+	-- does not seem to work to restrict size automatically...
+	local screen = TitanUtils_ScreenSize()
+	a_bar:SetResizeBounds(TitanBarData[this_bar].plugin_x_offset + 16, TITAN_PANEL_BAR_HEIGHT, screen.x, TITAN_PANEL_BAR_HEIGHT)
+
+	a_bar:RegisterForClicks("LeftButtonUp", "RightButtonUp");
+	a_bar:SetScript("OnClick", function(self, button) TitanPanelBarButton_OnClick(self, button) end)
+
+	-- ======
+	-- Frame for right clicks
+	f = CreateFrame("Frame", this_bar..TITAN_PANEL_CLICK_MENU_SUFFIX, UIParent, "UIDropDownMenuTemplate")
+
+	-- ======
+	-- Hider for auto hide feature
+	local hide_bar_name = TITAN_PANEL_HIDE_PREFIX..bar_data.name
+	if bar_data.hider then
+--[[
+print("_Create hide bar"
+.." "..tostring(bar_data.name)..""
+.." "..tostring(hide_bar_name)..""
+)
+--]]
+
+		local hide_bar = CreateFrame("Button", hide_bar_name, UIParent, "TitanPanelBarButtonHiderTemplate")
+		hide_bar:SetFrameStrata("DIALOG")
+		hide_bar:SetPoint(bar_data.show.pt, bar_data.show.rel_fr, bar_data.show.rel_pt, x, -y)
+
+		-- Set script handlers for display
+		hide_bar:RegisterForClicks("LeftButtonUp", "RightButtonUp");
+		hide_bar:SetScript("OnEnter", function(self) TitanPanelBarButtonHider_OnEnter(self) end)
+		hide_bar:SetScript("OnLeave", function(self) TitanPanelBarButtonHider_OnLeave(self) end)
+		hide_bar:SetScript("OnClick", function(self, button) TitanPanelBarButton_OnClick(self, button) end)
+
+		hide_bar:SetFrameStrata("BACKGROUND")
+		hide_bar:SetSize(screen.x / tscale, TITAN_PANEL_BAR_HEIGHT)
+	else
+		-- Not allowed for this bar
+	end
+end
+
diff --git a/Titan/Titan.xml b/Titan/Titan.xml
new file mode 100644
index 0000000..a761d2a
--- /dev/null
+++ b/Titan/Titan.xml
@@ -0,0 +1,20 @@
+<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
+..\FrameXML\UI.xsd">
+
+	<!--
+	These two frames are placed at the bottom of the top bar(s)
+	and top of the bottom bar(s) to give addons a notion of what
+	space Titan is using.
+	A non zero size is needed for the anchors to respond properly.
+	-->
+	<Button name="TitanPanelTopAnchor" frameStrata="DIALOG" parent="UIParent" >
+		<Size>
+			<AbsDimension x="1" y="1" />
+		</Size>
+	</Button>
+	<Button name="TitanPanelBottomAnchor" frameStrata="DIALOG" parent="UIParent" >
+		<Size>
+			<AbsDimension x="1" y="1" />
+		</Size>
+	</Button>
+</Ui>
diff --git a/Titan/TitanPanel.xml b/Titan/TitanPanel.xml
deleted file mode 100644
index eb6f9e6..0000000
--- a/Titan/TitanPanel.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
-..\FrameXML\UI.xsd">
-
-	<!--
-	These two frames are placed at the bottom of the top bar(s)
-	and top of the bottom bar(s) to give addons a notion of what
-	space Titan is using.
-	A non zero size is needed for the anchors to respond properly.
-	-->
-	<Button name="TitanPanelTopAnchor" frameStrata="DIALOG" parent="UIParent" >
-		<Size>
-			<AbsDimension x="1" y="1" />
-		</Size>
-	</Button>
-	<Button name="TitanPanelBottomAnchor" frameStrata="DIALOG" parent="UIParent" >
-		<Size>
-			<AbsDimension x="1" y="1" />
-		</Size>
-	</Button>
-</Ui>
diff --git a/Titan/TitanTemplate.lua b/Titan/TitanTemplate.lua
index 881e206..3021b6d 100644
--- a/Titan/TitanTemplate.lua
+++ b/Titan/TitanTemplate.lua
@@ -1548,7 +1548,7 @@ print("_Create bar"

 	-- ======
 	-- Frame for right clicks
-	f = CreateFrame("Frame", this_bar.."RightClickMenu", UIParent, "UIDropDownMenuTemplate")
+	f = CreateFrame("Frame", this_bar..TITAN_PANEL_CLICK_MENU_SUFFIX, UIParent, "UIDropDownMenuTemplate")

 	-- ======
 	-- Hider for auto hide feature
diff --git a/Titan/TitanUtils.lua b/Titan/TitanUtils.lua
index 4562475..2f80c7d 100644
--- a/Titan/TitanUtils.lua
+++ b/Titan/TitanUtils.lua
@@ -1363,9 +1363,8 @@ function TitanUtils_PluginToRegister(self, isChildButton)

 	--[[ For updated menu lib (Dec 2018)
 	Old way was to use the XML file to declare the frame, now it needs to be in Lua
-	<Frame name="$parentRightClickMenu" inherits="L_UIDropDownMenuTemplate" id="1" hidden="true"></Frame>
 	--]]
-	local f = CreateFrame("Frame", self:GetName().."RightClickMenu", self or nil, "UIDropDownMenuTemplate")
+	local f = CreateFrame("Frame", self:GetName()..TITAN_PANEL_CLICK_MENU_SUFFIX, self or nil, "UIDropDownMenuTemplate")
 end

 --[[ Titan
@@ -1730,7 +1729,7 @@ function TitanPanelRightClickMenu_Toggle(self)
 	-- 1) Titan bar - creates same menu
 	-- 2) Plugin creation via the .registry
 	local frame = self:GetName()
-	local menu = _G[self:GetName().."RightClickMenu"]
+	local menu = _G[self:GetName()..TITAN_PANEL_CLICK_MENU_SUFFIX]
 --[[
 print("_ toggle R menu"
 .." "..tostring(frame)..""
diff --git a/Titan/TitanVariables.lua b/Titan/TitanVariables.lua
index 53cbef3..cad06b5 100644
--- a/Titan/TitanVariables.lua
+++ b/Titan/TitanVariables.lua
@@ -82,6 +82,7 @@ TITAN_PANEL_HIDE_PREFIX = "Titan_Bar__Hider_"
 TITAN_PANEL_DISPLAY_PREFIX = "Titan_Bar__Display_"
 TITAN_PANEL_DISPLAY_MENU = "Menu_"
 TITAN_PANEL_BACKGROUND_PREFIX = "TitanPanelBackground_"
+TITAN_PANEL_CLICK_MENU_SUFFIX = "RightClickMenu"
 TITAN_PANEL_TEXT = "Text"
 TITAN_PANEL_TEXTURE_VAR = "Texture"
 TITAN_PANEL_BUTTON_TEXT = "Button"..TITAN_PANEL_TEXT