From 96e81184b6db8124c113037531bec80804be9c10 Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:56:18 -0700 Subject: [PATCH 01/16] Create startbox combobox --- LuaMenu/widgets/gui_battle_room_window.lua | 557 ++++++++++++--------- 1 file changed, 334 insertions(+), 223 deletions(-) diff --git a/LuaMenu/widgets/gui_battle_room_window.lua b/LuaMenu/widgets/gui_battle_room_window.lua index b30a5e8fc..be7bdf443 100644 --- a/LuaMenu/widgets/gui_battle_room_window.lua +++ b/LuaMenu/widgets/gui_battle_room_window.lua @@ -142,79 +142,66 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs local mapLinkWidth = 150 currentStartRects = {} - local externalFunctions = {} local startBoxPanel = Control:New{ name = 'startBoxPanel', x = 0, - y = 22, + y = 24, width = "100%", height = 25, padding = {0,0,0,0}, parent = rightInfo, } - -- the buttons needed are: - -- splitV , splitH, splitC1_2, splitC2_2, split4, add, remove - local btnSplitV = Button:New{ - name = 'btnSplitV', - x = "0%", + + local btnAddBox = Button:New{ + name = 'btnAddBox', + x = 0, bottom = 0, width = "12%", height = "100%", maxWidth = 50, maxHeight = 50, + parent = startBoxPanel, classname = "button_small", caption = "", noFont = true, padding = {0, 0, 0, 0}, - parent = startBoxPanel, - tooltip = "Split start boxes left vs right", + tooltip = "Add a new start box in the center", OnClick = { function () local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} if battleStatus.isSpectator then return end - WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ - defaultValue = 20, - minValue = 3, - maxValue = 50, - caption = "Change start boxes", - labelCaption = "Split the map start boxes vertically, with X percent of the map going to left and right start boxes.", - imageFile = LUA_DIRNAME .. "images/startboxsplit_v.png", - OnAccepted = function(integervalue) - if battleLobby.name == "singleplayer" then - externalFunctions.RemoveStartRect() - externalFunctions.AddStartRect(0, 0, 0, integervalue *2, 200) - externalFunctions.AddStartRect(1, 200 - integervalue *2, 0, 200, 200) - else - battleLobby:SayBattle("!split v "..tostring(integervalue)) - end - end - }) + if battleLobby.name == "singleplayer" then + externalFunctions.AddStartRect(#currentStartRects,66, 66, 133, 133) + else + battleLobby:SayBattle("!addbox 66 66 133 133") + end end } } - local imSplitV = Image:New { - name = 'imSplitV', + local imAddBox = Image:New { + name = 'imAddBox', x = 0, y = 0, right = 0, bottom = 0, keepAspect = false, - file = LUA_DIRNAME .. "images/startboxsplit_v.png", - parent = btnSplitV, - tooltip = btnSplitV.tooltip, + file = LUA_DIRNAME .. "images/startboxsplit_add.png", + parent = btnAddBox, + tooltip = btnAddBox.tooltip, } - local btnSplitH = Button:New{ - name = 'btnSplitH', - x = "12.5%", + local btnClearBox = Button:New{ + name = 'btnClearBox', + --x = "87.5%", bottom = 0, width = '12%', height = "100%", + right = 0, maxWidth = 50, maxHeight = 50, parent = startBoxPanel, @@ -222,30 +209,321 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs caption = "", noFont = true, padding = {0, 0, 0, 0}, - tooltip = "Split start boxes top vs bottom", + tooltip = "Remove last start box", OnClick = { function () local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} if battleStatus.isSpectator then return end - WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ - defaultValue = 20, - minValue = 3, - maxValue = 50, - caption = "Change start boxes", - labelCaption = "Split the map start boxes horizontally, with X percent of the map going to top and bottom start boxes.", - imageFile = LUA_DIRNAME .. "images/startboxsplit_h.png", - OnAccepted = function(integervalue) - if battleLobby.name == "singleplayer" then - externalFunctions.RemoveStartRect() - externalFunctions.AddStartRect(0, 0, 0, 200, integervalue * 2) - externalFunctions.AddStartRect(1, 0, 200 - integervalue *2, 200, 200) - else - battleLobby:SayBattle("!split h "..tostring(integervalue)) + if battleLobby.name == "singleplayer" then + if #currentStartRects > 0 then + externalFunctions.RemoveStartRect(#currentStartRects -1) + end + else + battleLobby:SayBattle("!clearbox ".. tostring(#currentStartRects)) + end + end + } + } + + local imClearBox = Image:New { + name = 'imClearBox', + x = 0, + y = 0, + right = 0, + bottom = 0, + keepAspect = false, + file = LUA_DIRNAME .. "images/startboxsplit_remove.png", + parent = btnClearBox, + tooltip = btnClearBox.tooltip, + } + + local startBoxImageHolder = Control:New{ + name = 'startBoxImageHolder', + x = "12%", + y = 0, + width = "15%", + height = "100%", + parent = startBoxPanel, + --classname = "combobox_window" + } + + local startBoxImage = Image:New { + name = 'startBoxImage', + x = 0, + y = 0, + width = "100%", + height = "100%", + keepAspect = true, + file = LUA_DIRNAME .. "images/load_img_128.png", + parent = startBoxImageHolder, + tooltip = "Fix Me Baby", + } + +--[[ startBoxComboBox.OnSelectName = { + function(obj, selected, item) + -- Update the image file based on the selected item + + local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + startBoxImage.file = newImageFile + startBoxImage:Invalidate() + end + } ]] + + local boxNames = {"Default Boxes", "East vs West", "North vs South", "NE vs SW", "NW vs SE", "4 Corners", "4 Sides"} + + local startBoxComboBox = ComboBox:New{ + name = 'startBoxComboBox', + x = "13%", + y = 0, + right = "13%", + height = "100%", + maxheight = 50, + items = boxNames, + objectOverrideFont = config:GetFont(2), + selectByName = true, + tooltip = "Change the layout of the start boxes", + OnSelectName = { + function(obj, selected, item) + local imageFileMap = { + ["Default Boxes"] = LUA_DIRNAME .. "images/load_img_128.png", + ["East vs West"] = LUA_DIRNAME .. "images/startboxsplit_v.png", + ["North vs South"] = LUA_DIRNAME .. "images/startboxsplit_h.png", + ["NE vs SW"] = LUA_DIRNAME .. "images/startboxsplit_c1.png", + ["NW vs SE"] = LUA_DIRNAME .. "images/startboxsplit_c2.png", + ["4 Corners"] = LUA_DIRNAME .. "images/startboxsplit_c.png", + ["4 Sides"] = LUA_DIRNAME .. "images/startboxsplit_s.png", + } + if selected == "Default Boxes" then + local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} + if battleStatus.isSpectator then + return + end + WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ + defaultValue = 20, + minValue = 3, + maxValue = 50, + caption = "Change start boxes", + labelCaption = "Restore default start boxes.", + + OnAccepted = function(integervalue) + Spring.Echo("Battle mapname =", battle.mapName) + if battleLobby.name == "singleplayer" then + battleLobby:SelectMap(battle.mapName) + else + Spring.Echo("FIXME") + end + + local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + startBoxImage.file = newImageFile + startBoxImage:Invalidate() end + }) + elseif selected == "East vs West" then + local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} + if battleStatus.isSpectator then + return end - }) + WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ + defaultValue = 20, + minValue = 3, + maxValue = 50, + caption = "Change start boxes", + labelCaption = "Split the map start boxes vertically, with X percent of the map going to left and right start boxes.", + + OnAccepted = function(integervalue) + if battleLobby.name == "singleplayer" then + externalFunctions.RemoveStartRect() + externalFunctions.AddStartRect(0, 0, 0, integervalue *2, 200) + externalFunctions.AddStartRect(1, 200 - integervalue *2, 0, 200, 200) + else + battleLobby:SayBattle("!split v "..tostring(integervalue)) + end + + local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + startBoxImage.file = newImageFile + startBoxImage:Invalidate() + end + }) + elseif selected == "North vs South" then + local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} + if battleStatus.isSpectator then + return + end + WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ + defaultValue = 20, + minValue = 3, + maxValue = 50, + caption = "Change start boxes", + labelCaption = "Split the map start boxes horizontally, with X percent of the map going to top and bottom start boxes.", + + OnAccepted = function(integervalue) + if battleLobby.name == "singleplayer" then + externalFunctions.RemoveStartRect() + externalFunctions.AddStartRect(0, 0, 0, 200, integervalue * 2) + externalFunctions.AddStartRect(1, 0, 200 - integervalue *2, 200, 200) + else + battleLobby:SayBattle("!split h "..tostring(integervalue)) + end + + local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + startBoxImage.file = newImageFile + startBoxImage:Invalidate() + end + }) + elseif selected == "NE vs SW" then + local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} + if battleStatus.isSpectator then + return + end + WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ + defaultValue = 20, + minValue = 3, + maxValue = 50, + caption = "Change start boxes", + labelCaption = "Split the map start boxes along the corners, with X percent of the map going to top left and bottom right start boxes.", + + OnAccepted = function(integervalue) + if battleLobby.name == "singleplayer" then + externalFunctions.RemoveStartRect() + externalFunctions.AddStartRect(0, 0, 0, integervalue *2, integervalue * 2) + externalFunctions.AddStartRect(1, 200 - integervalue *2, 200 - integervalue *2, 200, 200) + else + battleLobby:SayBattle("!split c1 "..tostring(integervalue)) + end + + local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + startBoxImage.file = newImageFile + startBoxImage:Invalidate() + end + }) + elseif selected == "NW vs SE" then + local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} + if battleStatus.isSpectator then + return + end + WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ + defaultValue = 20, + minValue = 3, + maxValue = 50, + caption = "Change start boxes", + labelCaption = "Split the map start boxes along the corners, with X percent of the map going to bottom left and top right start boxes.", + + OnAccepted = function(integervalue) + if battleLobby.name == "singleplayer" then + externalFunctions.RemoveStartRect() + externalFunctions.AddStartRect(0, 0, 200- integervalue*2 , integervalue *2, 200) + externalFunctions.AddStartRect(1, 200-integervalue *2, 0, 200, integervalue *2 ) + else + battleLobby:SayBattle("!split c2 "..tostring(integervalue)) + end + + local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + startBoxImage.file = newImageFile + startBoxImage:Invalidate() + end + }) + elseif selected == "4 Corners" then + local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} + if battleStatus.isSpectator then + return + end + WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ + defaultValue = 20, + minValue = 3, + maxValue = 50, + caption = "Change start boxes", + labelCaption = "Split the map start boxes along the corners, with X percent of the map going to all 4 corners.", + + OnAccepted = function(integervalue) + if battleLobby.name == "singleplayer" then + externalFunctions.RemoveStartRect() + externalFunctions.AddStartRect(0, 0, 200- integervalue*2 , integervalue *2, 200) + externalFunctions.AddStartRect(1, 200-integervalue *2, 0, 200, integervalue *2 ) + externalFunctions.AddStartRect(2, 0, 0, integervalue *2, integervalue * 2) + externalFunctions.AddStartRect(3, 200 - integervalue *2, 200 - integervalue *2, 200, 200) + else + battleLobby:SayBattle("!split c "..tostring(integervalue)) + end + + local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + startBoxImage.file = newImageFile + startBoxImage:Invalidate() + end + }) + elseif selected == "4 Sides" then + local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} + if battleStatus.isSpectator then + return + end + WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ + defaultValue = 20, + minValue = 3, + maxValue = 33, + caption = "Change start boxes", + labelCaption = "Split the map start boxes along the sides, with X percent of the map going to all 4 sides.", + + OnAccepted = function(integervalue) + if battleLobby.name == "singleplayer" then + externalFunctions.RemoveStartRect() + externalFunctions.AddStartRect(0, 0, 100 - integervalue , integervalue *2, 100 + integervalue) + externalFunctions.AddStartRect(1, 200-integervalue *2, 100-integervalue, 200, 100 + integervalue) + externalFunctions.AddStartRect(2, 100 - integervalue , 0, 100 + integervalue, integervalue * 2) + externalFunctions.AddStartRect(3, 100 - integervalue , 200 - integervalue *2, 100+ integervalue, 200) + else + battleLobby:SayBattle("!split s "..tostring(integervalue)) + end + + local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + startBoxImage.file = newImageFile + startBoxImage:Invalidate() + end + }) + end + end + }, + itemKeyToName = boxNames, + parent = startBoxPanel, + } + + -- the buttons needed are: + -- splitV , splitH, splitC1_2, splitC2_2, split4, add, remove + --[[ local btnSplitV = Button:New{ + name = 'btnSplitV', + x = "0%", + bottom = 0, + width = "12%", + height = "100%", + maxWidth = 50, + maxHeight = 50, + classname = "button_small", + caption = "", + noFont = true, + padding = {0, 0, 0, 0}, + parent = startBoxPanel, + tooltip = "Split start boxes left vs right", + OnClick = { + } + } + --]] + --[[ + local btnSplitH = Button:New{ + name = 'btnSplitH', + x = "12.5%", + bottom = 0, + width = '12%', + height = "100%", + maxWidth = 50, + maxHeight = 50, + parent = startBoxPanel, + classname = "button_small", + caption = "", + noFont = true, + padding = {0, 0, 0, 0}, + tooltip = "Split start boxes top vs bottom", + OnClick = { + function () end } } @@ -278,27 +556,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs tooltip = "Split start boxes top left vs bottom right", OnClick = { function () - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end - WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ - defaultValue = 20, - minValue = 3, - maxValue = 50, - caption = "Change start boxes", - labelCaption = "Split the map start boxes along the corners, with X percent of the map going to top left and bottom right start boxes.", - imageFile = LUA_DIRNAME .. "images/startboxsplit_c1.png", - OnAccepted = function(integervalue) - if battleLobby.name == "singleplayer" then - externalFunctions.RemoveStartRect() - externalFunctions.AddStartRect(0, 0, 0, integervalue *2, integervalue * 2) - externalFunctions.AddStartRect(1, 200 - integervalue *2, 200 - integervalue *2, 200, 200) - else - battleLobby:SayBattle("!split c1 "..tostring(integervalue)) - end - end - }) + end } } @@ -331,27 +589,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs tooltip = "Split start boxes bottom left vs top right", OnClick = { function () - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end - WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ - defaultValue = 20, - minValue = 3, - maxValue = 50, - caption = "Change start boxes", - labelCaption = "Split the map start boxes along the corners, with X percent of the map going to bottom left and top right start boxes.", - imageFile = LUA_DIRNAME .. "images/startboxsplit_c2.png", - OnAccepted = function(integervalue) - if battleLobby.name == "singleplayer" then - externalFunctions.RemoveStartRect() - externalFunctions.AddStartRect(0, 0, 200- integervalue*2 , integervalue *2, 200) - externalFunctions.AddStartRect(1, 200-integervalue *2, 0, 200, integervalue *2 ) - else - battleLobby:SayBattle("!split c2 "..tostring(integervalue)) - end - end - }) + end } } @@ -385,29 +623,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs tooltip = "Split start boxes into 4 corners for 4 teams", OnClick = { function () - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end - WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ - defaultValue = 20, - minValue = 3, - maxValue = 50, - caption = "Change start boxes", - labelCaption = "Split the map start boxes along the corners, with X percent of the map going to all 4 corners.", - imageFile = LUA_DIRNAME .. "images/startboxsplit_c.png", - OnAccepted = function(integervalue) - if battleLobby.name == "singleplayer" then - externalFunctions.RemoveStartRect() - externalFunctions.AddStartRect(0, 0, 200- integervalue*2 , integervalue *2, 200) - externalFunctions.AddStartRect(1, 200-integervalue *2, 0, 200, integervalue *2 ) - externalFunctions.AddStartRect(2, 0, 0, integervalue *2, integervalue * 2) - externalFunctions.AddStartRect(3, 200 - integervalue *2, 200 - integervalue *2, 200, 200) - else - battleLobby:SayBattle("!split c "..tostring(integervalue)) - end - end - }) + end } } @@ -441,29 +657,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs tooltip = "Split start boxes into 4 sides for 4 teams", OnClick = { function () - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end - WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ - defaultValue = 20, - minValue = 3, - maxValue = 33, - caption = "Change start boxes", - labelCaption = "Split the map start boxes along the sides, with X percent of the map going to all 4 sides.", - imageFile = LUA_DIRNAME .. "images/startboxsplit_s.png", - OnAccepted = function(integervalue) - if battleLobby.name == "singleplayer" then - externalFunctions.RemoveStartRect() - externalFunctions.AddStartRect(0, 0, 100 - integervalue , integervalue *2, 100 + integervalue) - externalFunctions.AddStartRect(1, 200-integervalue *2, 100-integervalue, 200, 100 + integervalue) - externalFunctions.AddStartRect(2, 100 - integervalue , 0, 100 + integervalue, integervalue * 2) - externalFunctions.AddStartRect(3, 100 - integervalue , 200 - integervalue *2, 100+ integervalue, 200) - else - battleLobby:SayBattle("!split s "..tostring(integervalue)) - end - end - }) + end } } @@ -478,92 +672,9 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs file = LUA_DIRNAME .. "images/startboxsplit_s.png", parent = btnSplitS4, tooltip = btnSplitS4.tooltip, - } - - - local btnAddBox = Button:New{ - name = 'btnAddBox', - x = "75%", - bottom = 0, - width = '12%', - height = "100%", - maxWidth = 50, - maxHeight = 50, - parent = startBoxPanel, - classname = "button_small", - caption = "", - noFont = true, - padding = {0, 0, 0, 0}, - tooltip = "Add a new start box in the center", - OnClick = { - function () - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end - if battleLobby.name == "singleplayer" then - externalFunctions.AddStartRect(#currentStartRects,66, 66, 133, 133) - else - battleLobby:SayBattle("!addbox 66 66 133 133") - end - end - } - } + } ]] - local imAddBox = Image:New { - name = 'imAddBox', - x = 0, - y = 0, - right = 0, - bottom = 0, - keepAspect = false, - file = LUA_DIRNAME .. "images/startboxsplit_add.png", - parent = btnAddBox, - tooltip = btnAddBox.tooltip, - } - local btnClearBox = Button:New{ - name = 'btnClearBox', - x = "87.5%", - bottom = 0, - width = '12%', - height = "100%", - maxWidth = 50, - maxHeight = 50, - parent = startBoxPanel, - classname = "button_small", - caption = "", - noFont = true, - padding = {0, 0, 0, 0}, - tooltip = "Remove last start box", - OnClick = { - function () - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end - if battleLobby.name == "singleplayer" then - if #currentStartRects > 0 then - externalFunctions.RemoveStartRect(#currentStartRects -1) - end - else - battleLobby:SayBattle("!clearbox ".. tostring(#currentStartRects)) - end - end - } - } - - local imClearBox = Image:New { - name = 'imClearBox', - x = 0, - y = 0, - right = 0, - bottom = 0, - keepAspect = false, - file = LUA_DIRNAME .. "images/startboxsplit_remove.png", - parent = btnClearBox, - tooltip = btnClearBox.tooltip, - } local function UpdateStartRectPositionsInMinimap(width) @@ -995,7 +1106,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs rightInfo.OnResize = { function (obj, xSize, ySize) - -- Spring.Utilities.TraceFullEcho(nil,nil,nil,"rightInfo.OnResize", xSize, ySize ) + Spring.Utilities.TraceFullEcho(nil,nil,nil,"rightInfo.OnResize", xSize, ySize ) if xSize + minimapBottomClearance < ySize then minimapPanel._relativeBounds.left = 0 minimapPanel._relativeBounds.right = 0 From 16eb80b30947e02af7a3a4acf497c8d655027865 Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Sat, 14 Dec 2024 12:30:13 -0700 Subject: [PATCH 02/16] Add cancel function support to integer popup --- LuaMenu/widgets/gui_integer_popup_window.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/LuaMenu/widgets/gui_integer_popup_window.lua b/LuaMenu/widgets/gui_integer_popup_window.lua index 2927f43c0..3f3daa74e 100644 --- a/LuaMenu/widgets/gui_integer_popup_window.lua +++ b/LuaMenu/widgets/gui_integer_popup_window.lua @@ -42,6 +42,14 @@ local function CreateIntegerSelectorWindow(opts) IntegerSelectorWindow = nil end + + local function CancelFunction() + if opts.OnCancelled then + opts.OnCancelled() + end + CloseFunction() + end + local lblTitle = TextBox:New { x = "0%", y = "5%", @@ -87,7 +95,7 @@ local function CreateIntegerSelectorWindow(opts) caption = i18n("cancel"), objectOverrideFont = WG.Chobby.Configuration:GetFont(2), classname = "negative_button", - OnClick = { CloseFunction }, + OnClick = { CancelFunction }, parent = IntegerSelectorWindow, } @@ -125,7 +133,7 @@ local function CreateIntegerSelectorWindow(opts) } } - WG.Chobby.PriorityPopup(IntegerSelectorWindow, CloseFunction, CloseFunction, screen0) + WG.Chobby.PriorityPopup(IntegerSelectorWindow, CancelFunction, CloseFunction, screen0) end function widget:Initialize() From d0cbc5de4bc62055980c81aad97ca63175377762 Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Sat, 14 Dec 2024 12:30:25 -0700 Subject: [PATCH 03/16] Second revision of startbox combobox --- LuaMenu/widgets/gui_battle_room_window.lua | 334 ++++++++++----------- 1 file changed, 158 insertions(+), 176 deletions(-) diff --git a/LuaMenu/widgets/gui_battle_room_window.lua b/LuaMenu/widgets/gui_battle_room_window.lua index be7bdf443..e87927922 100644 --- a/LuaMenu/widgets/gui_battle_room_window.lua +++ b/LuaMenu/widgets/gui_battle_room_window.lua @@ -139,6 +139,8 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs local minimapBottomClearance = 160 local currentMapName + local oldSelectedBoxes = 1 + local freezeSettings = true local mapLinkWidth = 150 currentStartRects = {} @@ -154,91 +156,6 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs parent = rightInfo, } - local btnAddBox = Button:New{ - name = 'btnAddBox', - x = 0, - bottom = 0, - width = "12%", - height = "100%", - maxWidth = 50, - maxHeight = 50, - parent = startBoxPanel, - classname = "button_small", - caption = "", - noFont = true, - padding = {0, 0, 0, 0}, - tooltip = "Add a new start box in the center", - OnClick = { - function () - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end - if battleLobby.name == "singleplayer" then - externalFunctions.AddStartRect(#currentStartRects,66, 66, 133, 133) - else - battleLobby:SayBattle("!addbox 66 66 133 133") - end - end - } - } - - local imAddBox = Image:New { - name = 'imAddBox', - x = 0, - y = 0, - right = 0, - bottom = 0, - keepAspect = false, - file = LUA_DIRNAME .. "images/startboxsplit_add.png", - parent = btnAddBox, - tooltip = btnAddBox.tooltip, - } - - local btnClearBox = Button:New{ - name = 'btnClearBox', - --x = "87.5%", - bottom = 0, - width = '12%', - height = "100%", - right = 0, - maxWidth = 50, - maxHeight = 50, - parent = startBoxPanel, - classname = "button_small", - caption = "", - noFont = true, - padding = {0, 0, 0, 0}, - tooltip = "Remove last start box", - OnClick = { - function () - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end - if battleLobby.name == "singleplayer" then - if #currentStartRects > 0 then - externalFunctions.RemoveStartRect(#currentStartRects -1) - end - else - battleLobby:SayBattle("!clearbox ".. tostring(#currentStartRects)) - end - end - } - } - - local imClearBox = Image:New { - name = 'imClearBox', - x = 0, - y = 0, - right = 0, - bottom = 0, - keepAspect = false, - file = LUA_DIRNAME .. "images/startboxsplit_remove.png", - parent = btnClearBox, - tooltip = btnClearBox.tooltip, - } - local startBoxImageHolder = Control:New{ name = 'startBoxImageHolder', x = "12%", @@ -246,7 +163,6 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs width = "15%", height = "100%", parent = startBoxPanel, - --classname = "combobox_window" } local startBoxImage = Image:New { @@ -258,34 +174,35 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs keepAspect = true, file = LUA_DIRNAME .. "images/load_img_128.png", parent = startBoxImageHolder, - tooltip = "Fix Me Baby", } ---[[ startBoxComboBox.OnSelectName = { - function(obj, selected, item) - -- Update the image file based on the selected item - - local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" - startBoxImage.file = newImageFile - startBoxImage:Invalidate() - end - } ]] - local boxNames = {"Default Boxes", "East vs West", "North vs South", "NE vs SW", "NW vs SE", "4 Corners", "4 Sides"} local startBoxComboBox = ComboBox:New{ name = 'startBoxComboBox', - x = "13%", - y = 0, - right = "13%", - height = "100%", - maxheight = 50, + x = "12.25%", + y = 1, + right = "12.45%", + bottom = 1, items = boxNames, objectOverrideFont = config:GetFont(2), selectByName = true, tooltip = "Change the layout of the start boxes", OnSelectName = { function(obj, selected, item) + if freezeSettings then return end -- so these funcs dont run on first init + + NewSelection = selected + Spring.Echo("NewSelection", NewSelection) + + local function cancelFunc() + Spring.Echo("cancelFunc") + Spring.Echo("oldSelectedBoxes",oldSelectedBoxes) + freezeSettings = true + obj:Select(oldSelectedBoxes) + freezeSettings = false + end + local imageFileMap = { ["Default Boxes"] = LUA_DIRNAME .. "images/load_img_128.png", ["East vs West"] = LUA_DIRNAME .. "images/startboxsplit_v.png", @@ -295,43 +212,30 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs ["4 Corners"] = LUA_DIRNAME .. "images/startboxsplit_c.png", ["4 Sides"] = LUA_DIRNAME .. "images/startboxsplit_s.png", } - if selected == "Default Boxes" then - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end - WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ - defaultValue = 20, - minValue = 3, - maxValue = 50, - caption = "Change start boxes", - labelCaption = "Restore default start boxes.", - - OnAccepted = function(integervalue) - Spring.Echo("Battle mapname =", battle.mapName) - if battleLobby.name == "singleplayer" then - battleLobby:SelectMap(battle.mapName) - else - Spring.Echo("FIXME") - end - local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" - startBoxImage.file = newImageFile - startBoxImage:Invalidate() + if selected == "Default Boxes" then + local function defaultBoxes() + if battleLobby.name == "singleplayer" then + battleLobby:SelectMap(battle.mapName) + else + Spring.Echo("FIXME") end - }) - elseif selected == "East vs West" then - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return + + oldSelectedBoxes = NewSelection + + local newImageFile = imageFileMap[selected] + startBoxImage.file = newImageFile + startBoxImage:Invalidate() end + WG.Chobby.ConfirmationPopup(defaultBoxes, "Restore default start boxes.", nil, 330, 230, i18n("ok"),nil, cancelFunc) + return + elseif selected == "East vs West" then WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ defaultValue = 20, minValue = 3, maxValue = 50, caption = "Change start boxes", labelCaption = "Split the map start boxes vertically, with X percent of the map going to left and right start boxes.", - OnAccepted = function(integervalue) if battleLobby.name == "singleplayer" then externalFunctions.RemoveStartRect() @@ -341,23 +245,21 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs battleLobby:SayBattle("!split v "..tostring(integervalue)) end - local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + oldSelectedBoxes = NewSelection + + local newImageFile = imageFileMap[selected] startBoxImage.file = newImageFile startBoxImage:Invalidate() - end + end, + OnCancelled = function () cancelFunc() end }) elseif selected == "North vs South" then - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ defaultValue = 20, minValue = 3, maxValue = 50, caption = "Change start boxes", labelCaption = "Split the map start boxes horizontally, with X percent of the map going to top and bottom start boxes.", - OnAccepted = function(integervalue) if battleLobby.name == "singleplayer" then externalFunctions.RemoveStartRect() @@ -366,24 +268,22 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs else battleLobby:SayBattle("!split h "..tostring(integervalue)) end + + oldSelectedBoxes = NewSelection - local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + local newImageFile = imageFileMap[selected] startBoxImage.file = newImageFile startBoxImage:Invalidate() - end + end, + OnCancelled = function () cancelFunc() end }) elseif selected == "NE vs SW" then - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ defaultValue = 20, minValue = 3, maxValue = 50, caption = "Change start boxes", labelCaption = "Split the map start boxes along the corners, with X percent of the map going to top left and bottom right start boxes.", - OnAccepted = function(integervalue) if battleLobby.name == "singleplayer" then externalFunctions.RemoveStartRect() @@ -393,23 +293,21 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs battleLobby:SayBattle("!split c1 "..tostring(integervalue)) end - local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + oldSelectedBoxes = NewSelection + + local newImageFile = imageFileMap[selected] startBoxImage.file = newImageFile startBoxImage:Invalidate() - end + end, + OnCancelled = function () cancelFunc() end }) elseif selected == "NW vs SE" then - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ defaultValue = 20, minValue = 3, maxValue = 50, caption = "Change start boxes", labelCaption = "Split the map start boxes along the corners, with X percent of the map going to bottom left and top right start boxes.", - OnAccepted = function(integervalue) if battleLobby.name == "singleplayer" then externalFunctions.RemoveStartRect() @@ -419,23 +317,21 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs battleLobby:SayBattle("!split c2 "..tostring(integervalue)) end - local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + oldSelectedBoxes = NewSelection + + local newImageFile = imageFileMap[selected] startBoxImage.file = newImageFile startBoxImage:Invalidate() - end + end, + OnCancelled = function () cancelFunc() end }) elseif selected == "4 Corners" then - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ defaultValue = 20, minValue = 3, maxValue = 50, caption = "Change start boxes", labelCaption = "Split the map start boxes along the corners, with X percent of the map going to all 4 corners.", - OnAccepted = function(integervalue) if battleLobby.name == "singleplayer" then externalFunctions.RemoveStartRect() @@ -447,23 +343,21 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs battleLobby:SayBattle("!split c "..tostring(integervalue)) end - local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + oldSelectedBoxes = NewSelection + + local newImageFile = imageFileMap[selected] startBoxImage.file = newImageFile startBoxImage:Invalidate() - end + end, + OnCancelled = function () cancelFunc() end }) elseif selected == "4 Sides" then - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end - WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ + local integerSelectorWindow = WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ defaultValue = 20, minValue = 3, maxValue = 33, caption = "Change start boxes", labelCaption = "Split the map start boxes along the sides, with X percent of the map going to all 4 sides.", - OnAccepted = function(integervalue) if battleLobby.name == "singleplayer" then externalFunctions.RemoveStartRect() @@ -475,10 +369,13 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs battleLobby:SayBattle("!split s "..tostring(integervalue)) end - local newImageFile = imageFileMap[selected] or LUA_DIRNAME .. "images/load_img_128.png" + oldSelectedBoxes = NewSelection + + local newImageFile = imageFileMap[selected] startBoxImage.file = newImageFile startBoxImage:Invalidate() - end + end, + OnCancelled = function () cancelFunc() end }) end end @@ -487,6 +384,89 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs parent = startBoxPanel, } + local btnAddBox = Button:New{ + name = 'btnAddBox', + x = 0, + y = 1, + width = "12%", + bottom = 1, + maxHeight = 50, + parent = startBoxPanel, + classname = "button_small", + caption = "", + noFont = true, + padding = {0, 0, 0, 0}, + tooltip = "Add a new start box in the center", + OnClick = { + function () + local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} + if battleStatus.isSpectator then + return + end + if battleLobby.name == "singleplayer" then + externalFunctions.AddStartRect(#currentStartRects,66, 66, 133, 133) + else + battleLobby:SayBattle("!addbox 66 66 133 133") + end + end + } + } + + local imAddBox = Image:New { + name = 'imAddBox', + x = 0, + y = 0, + right = 0, + bottom = 0, + keepAspect = true, + file = LUA_DIRNAME .. "images/startboxsplit_add.png", + parent = btnAddBox, + tooltip = btnAddBox.tooltip, + } + + local btnClearBox = Button:New{ + name = 'btnClearBox', + --x = "87.5%", + y = 1, + width = "12%", + bottom = 1, + right = 1, + maxHeight = 50, + parent = startBoxPanel, + classname = "button_small", + caption = "", + noFont = true, + padding = {0, 0, 0, 0}, + tooltip = "Remove last start box", + OnClick = { + function () + local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} + if battleStatus.isSpectator then + return + end + if battleLobby.name == "singleplayer" then + if #currentStartRects > 0 then + externalFunctions.RemoveStartRect(#currentStartRects -1) + end + else + battleLobby:SayBattle("!clearbox ".. tostring(#currentStartRects)) + end + end + } + } + + local imClearBox = Image:New { + name = 'imClearBox', + x = 0, + y = 0, + right = 0, + bottom = 0, + keepAspect = true, + file = LUA_DIRNAME .. "images/startboxsplit_remove.png", + parent = btnClearBox, + tooltip = btnClearBox.tooltip, + } + -- the buttons needed are: -- splitV , splitH, splitC1_2, splitC2_2, split4, add, remove --[[ local btnSplitV = Button:New{ @@ -771,9 +751,9 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs if battleLobby.name == "singleplayer" and config.devMode then local comboboxstartpostype = ComboBox:New{ name = 'comboboxstartpostype', - x = 0, - bottom = 100, - right = 0, + x = "67.15%", + right = 13, + y = 15, height = 30, itemHeight = 22, selectByName = true, @@ -794,7 +774,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs battle.startPosType = nil end }, - parent = rightInfo, + parent = mainWindow, } end @@ -1106,7 +1086,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs rightInfo.OnResize = { function (obj, xSize, ySize) - Spring.Utilities.TraceFullEcho(nil,nil,nil,"rightInfo.OnResize", xSize, ySize ) + -- Spring.Utilities.TraceFullEcho(nil,nil,nil,"rightInfo.OnResize", xSize, ySize ) if xSize + minimapBottomClearance < ySize then minimapPanel._relativeBounds.left = 0 minimapPanel._relativeBounds.right = 0 @@ -1116,7 +1096,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs minimapPanel:UpdateClientArea() lblMapName:SetPos(nil, xSize + 2) - startBoxPanel:SetPos(nil,xSize + 24,nil, xSize / 8) + startBoxPanel:SetPos(nil,xSize + 24,nil, math.min(50, math.round(xSize / 8))) else local horPadding = ((xSize + minimapBottomClearance) - ySize)/2 @@ -1128,7 +1108,8 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs minimapPanel:UpdateClientArea() lblMapName:SetPos(nil, ySize - minimapBottomClearance + 2) - startBoxPanel:SetPos(nil,ySize - minimapBottomClearance + 24,nil, xSize / 8) + startBoxPanel:SetPos(nil,ySize - minimapBottomClearance + 24, nil, math.min(50, math.round(xSize / 8))) + end end @@ -1452,7 +1433,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs -- Lobby interface function externalFunctions.UpdateUserTeamStatus(userName, allyNumber, isSpectator) if userName == myUserName then - if isSpectator then + if isSpectator and battleLobby.name ~= "singleplayer" then -- SetButtonStateSpectating() startBoxPanel:Hide() minimapPanel.disableChildrenHitTest = true --omg this is amazing @@ -1745,6 +1726,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs MaybeDownloadGame(battle) MaybeDownloadMap(battle) UpdateArchiveStatus(true) + freezeSettings = false externalFunctions.rightInfo = rightInfo return externalFunctions From e734f77c060ef9da7ad4e1d5ffcec6f41d8de42e Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Sat, 14 Dec 2024 12:42:24 -0700 Subject: [PATCH 04/16] Don't hide startbox controls when spectator in singleplayer or when boss --- LuaMenu/widgets/gui_battle_room_window.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LuaMenu/widgets/gui_battle_room_window.lua b/LuaMenu/widgets/gui_battle_room_window.lua index e87927922..cbf5302c1 100644 --- a/LuaMenu/widgets/gui_battle_room_window.lua +++ b/LuaMenu/widgets/gui_battle_room_window.lua @@ -1433,7 +1433,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs -- Lobby interface function externalFunctions.UpdateUserTeamStatus(userName, allyNumber, isSpectator) if userName == myUserName then - if isSpectator and battleLobby.name ~= "singleplayer" then + if isSpectator and battleLobby.name ~= "singleplayer" and battle.bossed ~= true then -- SetButtonStateSpectating() startBoxPanel:Hide() minimapPanel.disableChildrenHitTest = true --omg this is amazing From 88e1568d37024db365c030018f20cec9a31b7ec7 Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Sat, 14 Dec 2024 19:10:13 -0700 Subject: [PATCH 05/16] Fix integer popup image --- LuaMenu/widgets/gui_integer_popup_window.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LuaMenu/widgets/gui_integer_popup_window.lua b/LuaMenu/widgets/gui_integer_popup_window.lua index 3f3daa74e..fbb1e54cd 100644 --- a/LuaMenu/widgets/gui_integer_popup_window.lua +++ b/LuaMenu/widgets/gui_integer_popup_window.lua @@ -66,12 +66,12 @@ local function CreateIntegerSelectorWindow(opts) local wideimg = Image:New{ name = "IntegerSelectorWindowImage", x = "5%", - y = "40%", + y = "33%", width = opts.imageWidth or "90%", height = opts.imageHeight or "33%", parent = IntegerSelectorWindow, keepAspect = opts.keepAspect and true, - image = opts.imageFile, + file = opts.imageFile, } end From 99eadf02c81cab636baf32d5b4fec4873bd99447 Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Sat, 14 Dec 2024 19:12:00 -0700 Subject: [PATCH 06/16] Refactor and add tooltips for items --- LuaMenu/widgets/gui_battle_room_window.lua | 274 +++++++++------------ 1 file changed, 112 insertions(+), 162 deletions(-) diff --git a/LuaMenu/widgets/gui_battle_room_window.lua b/LuaMenu/widgets/gui_battle_room_window.lua index cbf5302c1..862c48b66 100644 --- a/LuaMenu/widgets/gui_battle_room_window.lua +++ b/LuaMenu/widgets/gui_battle_room_window.lua @@ -140,6 +140,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs local currentMapName local oldSelectedBoxes = 1 + local startBoxSelect = {} local freezeSettings = true local mapLinkWidth = 150 currentStartRects = {} @@ -176,28 +177,29 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs parent = startBoxImageHolder, } - local boxNames = {"Default Boxes", "East vs West", "North vs South", "NE vs SW", "NW vs SE", "4 Corners", "4 Sides"} + local startBoxSelectorNames = {"Default Boxes", "E vs W", "N vs S", "NE vs SW", "NW vs SE", "4 Corners", "4 Sides"} + local startBoxSelectorTooltips = {"Reset to default", "East vs West", "North vs South", "Northeast vs Southwest", "Northwest vs Southeast", "Southwest vs Northeast vs Northwest vs Southeast", "West vs East vs North vs South"} local startBoxComboBox = ComboBox:New{ name = 'startBoxComboBox', x = "12.25%", y = 1, - right = "12.45%", + right = "12.5%", bottom = 1, - items = boxNames, + items = startBoxSelectorNames, + itemsTooltips = startBoxSelectorTooltips, + itemKeyToName = startBoxSelectorNames, objectOverrideFont = config:GetFont(2), + parent = startBoxPanel, selectByName = true, tooltip = "Change the layout of the start boxes", OnSelectName = { function(obj, selected, item) if freezeSettings then return end -- so these funcs dont run on first init - NewSelection = selected - Spring.Echo("NewSelection", NewSelection) + local newSelectedBoxes = selected local function cancelFunc() - Spring.Echo("cancelFunc") - Spring.Echo("oldSelectedBoxes",oldSelectedBoxes) freezeSettings = true obj:Select(oldSelectedBoxes) freezeSettings = false @@ -205,183 +207,131 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs local imageFileMap = { ["Default Boxes"] = LUA_DIRNAME .. "images/load_img_128.png", - ["East vs West"] = LUA_DIRNAME .. "images/startboxsplit_v.png", - ["North vs South"] = LUA_DIRNAME .. "images/startboxsplit_h.png", + ["E vs W"] = LUA_DIRNAME .. "images/startboxsplit_v.png", + ["N vs S"] = LUA_DIRNAME .. "images/startboxsplit_h.png", ["NE vs SW"] = LUA_DIRNAME .. "images/startboxsplit_c1.png", ["NW vs SE"] = LUA_DIRNAME .. "images/startboxsplit_c2.png", ["4 Corners"] = LUA_DIRNAME .. "images/startboxsplit_c.png", ["4 Sides"] = LUA_DIRNAME .. "images/startboxsplit_s.png", } - if selected == "Default Boxes" then - local function defaultBoxes() - if battleLobby.name == "singleplayer" then - battleLobby:SelectMap(battle.mapName) - else - Spring.Echo("FIXME") - end - - oldSelectedBoxes = NewSelection - - local newImageFile = imageFileMap[selected] - startBoxImage.file = newImageFile - startBoxImage:Invalidate() - end - WG.Chobby.ConfirmationPopup(defaultBoxes, "Restore default start boxes.", nil, 330, 230, i18n("ok"),nil, cancelFunc) - return - elseif selected == "East vs West" then - WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ - defaultValue = 20, - minValue = 3, - maxValue = 50, - caption = "Change start boxes", - labelCaption = "Split the map start boxes vertically, with X percent of the map going to left and right start boxes.", - OnAccepted = function(integervalue) - if battleLobby.name == "singleplayer" then - externalFunctions.RemoveStartRect() - externalFunctions.AddStartRect(0, 0, 0, integervalue *2, 200) - externalFunctions.AddStartRect(1, 200 - integervalue *2, 0, 200, 200) - else - battleLobby:SayBattle("!split v "..tostring(integervalue)) - end - - oldSelectedBoxes = NewSelection - - local newImageFile = imageFileMap[selected] - startBoxImage.file = newImageFile - startBoxImage:Invalidate() - end, - OnCancelled = function () cancelFunc() end - }) - elseif selected == "North vs South" then - WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ - defaultValue = 20, - minValue = 3, - maxValue = 50, - caption = "Change start boxes", - labelCaption = "Split the map start boxes horizontally, with X percent of the map going to top and bottom start boxes.", - OnAccepted = function(integervalue) - if battleLobby.name == "singleplayer" then - externalFunctions.RemoveStartRect() - externalFunctions.AddStartRect(0, 0, 0, 200, integervalue * 2) - externalFunctions.AddStartRect(1, 0, 200 - integervalue *2, 200, 200) - else - battleLobby:SayBattle("!split h "..tostring(integervalue)) - end - - oldSelectedBoxes = NewSelection - - local newImageFile = imageFileMap[selected] - startBoxImage.file = newImageFile - startBoxImage:Invalidate() - end, - OnCancelled = function () cancelFunc() end - }) - elseif selected == "NE vs SW" then - WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ - defaultValue = 20, - minValue = 3, - maxValue = 50, - caption = "Change start boxes", - labelCaption = "Split the map start boxes along the corners, with X percent of the map going to top left and bottom right start boxes.", - OnAccepted = function(integervalue) - if battleLobby.name == "singleplayer" then - externalFunctions.RemoveStartRect() - externalFunctions.AddStartRect(0, 0, 0, integervalue *2, integervalue * 2) - externalFunctions.AddStartRect(1, 200 - integervalue *2, 200 - integervalue *2, 200, 200) - else - battleLobby:SayBattle("!split c1 "..tostring(integervalue)) - end - - oldSelectedBoxes = NewSelection - - local newImageFile = imageFileMap[selected] - startBoxImage.file = newImageFile - startBoxImage:Invalidate() - end, - OnCancelled = function () cancelFunc() end - }) - elseif selected == "NW vs SE" then - WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ - defaultValue = 20, - minValue = 3, - maxValue = 50, - caption = "Change start boxes", - labelCaption = "Split the map start boxes along the corners, with X percent of the map going to bottom left and top right start boxes.", - OnAccepted = function(integervalue) - if battleLobby.name == "singleplayer" then - externalFunctions.RemoveStartRect() - externalFunctions.AddStartRect(0, 0, 200- integervalue*2 , integervalue *2, 200) - externalFunctions.AddStartRect(1, 200-integervalue *2, 0, 200, integervalue *2 ) - else - battleLobby:SayBattle("!split c2 "..tostring(integervalue)) - end + local function UpdateBoxes() + oldSelectedBoxes = newSelectedBoxes - oldSelectedBoxes = NewSelection + local newImageFile = imageFileMap[selected] + startBoxImage.file = newImageFile + startBoxImage:Invalidate() + end - local newImageFile = imageFileMap[selected] - startBoxImage.file = newImageFile - startBoxImage:Invalidate() - end, - OnCancelled = function () cancelFunc() end - }) - elseif selected == "4 Corners" then + local function MakeIntegerSelectorWindow() WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ defaultValue = 20, - minValue = 3, - maxValue = 50, + minValue = startBoxSelect.Min, + maxValue = startBoxSelect.Max, caption = "Change start boxes", - labelCaption = "Split the map start boxes along the corners, with X percent of the map going to all 4 corners.", + imageFile = imageFileMap[selected], + keepAspect = true, + labelCaption = startBoxSelect.Caption, OnAccepted = function(integervalue) if battleLobby.name == "singleplayer" then externalFunctions.RemoveStartRect() - externalFunctions.AddStartRect(0, 0, 200- integervalue*2 , integervalue *2, 200) - externalFunctions.AddStartRect(1, 200-integervalue *2, 0, 200, integervalue *2 ) - externalFunctions.AddStartRect(2, 0, 0, integervalue *2, integervalue * 2) - externalFunctions.AddStartRect(3, 200 - integervalue *2, 200 - integervalue *2, 200, 200) + startBoxSelect.AcceptFuncSingleplayer(integervalue) else - battleLobby:SayBattle("!split c "..tostring(integervalue)) + startBoxSelect.AcceptFunc(integervalue) end - - oldSelectedBoxes = NewSelection - - local newImageFile = imageFileMap[selected] - startBoxImage.file = newImageFile - startBoxImage:Invalidate() + UpdateBoxes() end, OnCancelled = function () cancelFunc() end }) - elseif selected == "4 Sides" then - local integerSelectorWindow = WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({ - defaultValue = 20, - minValue = 3, - maxValue = 33, - caption = "Change start boxes", - labelCaption = "Split the map start boxes along the sides, with X percent of the map going to all 4 sides.", - OnAccepted = function(integervalue) - if battleLobby.name == "singleplayer" then - externalFunctions.RemoveStartRect() - externalFunctions.AddStartRect(0, 0, 100 - integervalue , integervalue *2, 100 + integervalue) - externalFunctions.AddStartRect(1, 200-integervalue *2, 100-integervalue, 200, 100 + integervalue) - externalFunctions.AddStartRect(2, 100 - integervalue , 0, 100 + integervalue, integervalue * 2) - externalFunctions.AddStartRect(3, 100 - integervalue , 200 - integervalue *2, 100+ integervalue, 200) - else - battleLobby:SayBattle("!split s "..tostring(integervalue)) - end - - oldSelectedBoxes = NewSelection + end - local newImageFile = imageFileMap[selected] - startBoxImage.file = newImageFile - startBoxImage:Invalidate() - end, - OnCancelled = function () cancelFunc() end - }) + if selected == "Default Boxes" then + local function defaultBoxes() + if battleLobby.name == "singleplayer" then + battleLobby:SelectMap(battle.mapName) + else + battleLobby:SayBattle("!loadboxes") + end + UpdateBoxes() + end + WG.Chobby.ConfirmationPopup(defaultBoxes, "Restore default start boxes for the current number of teams.", nil, 330, 230, i18n("ok"),nil, cancelFunc) + return + else + if selected == "East vs West" then + startBoxSelect.Min = 3 + startBoxSelect.Max = 50 + startBoxSelect.Caption = "Split the map start boxes vertically, with X percent of the map going to left and right start boxes." + startBoxSelect.AcceptFunc = function(integervalue) + battleLobby:SayBattle("!split v "..tostring(integervalue)) + end + startBoxSelect.AcceptFuncSingleplayer = function(integervalue) + externalFunctions.AddStartRect(0, 0, 0, integervalue *2, 200) + externalFunctions.AddStartRect(1, 200 - integervalue *2, 0, 200, 200) + end + elseif selected == "North vs South" then + startBoxSelect.Min = 3 + startBoxSelect.Max = 50 + startBoxSelect.Caption = "Split the map start boxes horizontally, with X percent of the map going to top and bottom start boxes." + startBoxSelect.AcceptFunc = function(integervalue) + battleLobby:SayBattle("!split h "..tostring(integervalue)) + end + startBoxSelect.AcceptFuncSingleplayer = function(integervalue) + externalFunctions.AddStartRect(0, 0, 0, 200, integervalue * 2) + externalFunctions.AddStartRect(1, 0, 200 - integervalue *2, 200, 200) + end + elseif selected == "NE vs SW" then + startBoxSelect.Min = 3 + startBoxSelect.Max = 50 + startBoxSelect.Caption = "Split the map start boxes along the corners, with X percent of the map going to top left and bottom right start boxes." + startBoxSelect.AcceptFunc = function(integervalue) + battleLobby:SayBattle("!split c1 "..tostring(integervalue)) + end + startBoxSelect.AcceptFuncSingleplayer = function(integervalue) + externalFunctions.AddStartRect(0, 0, 0, integervalue *2, integervalue * 2) + externalFunctions.AddStartRect(1, 200 - integervalue *2, 200 - integervalue *2, 200, 200) + end + elseif selected == "NW vs SE" then + startBoxSelect.Min = 3 + startBoxSelect.Max = 50 + startBoxSelect.Caption = "Split the map start boxes along the corners, with X percent of the map going to bottom left and top right start boxes." + startBoxSelect.AcceptFunc = function(integervalue) + battleLobby:SayBattle("!split c2 "..tostring(integervalue)) + end + startBoxSelect.AcceptFuncSingleplayer = function(integervalue) + externalFunctions.AddStartRect(0, 0, 200- integervalue*2 , integervalue *2, 200) + externalFunctions.AddStartRect(1, 200-integervalue *2, 0, 200, integervalue *2 ) + end + elseif selected == "4 Corners" then + startBoxSelect.Min = 3 + startBoxSelect.Max = 50 + startBoxSelect.Caption = "Split the map start boxes along the corners, with X percent of the map going to all 4 corners." + startBoxSelect.AcceptFunc = function(integervalue) + battleLobby:SayBattle("!split c "..tostring(integervalue)) + end + startBoxSelect.AcceptFuncSingleplayer = function(integervalue) + externalFunctions.AddStartRect(0, 0, 200- integervalue*2 , integervalue *2, 200) + externalFunctions.AddStartRect(1, 200-integervalue *2, 0, 200, integervalue *2 ) + externalFunctions.AddStartRect(2, 0, 0, integervalue *2, integervalue * 2) + externalFunctions.AddStartRect(3, 200 - integervalue *2, 200 - integervalue *2, 200, 200) + end + elseif selected == "4 Sides" then + startBoxSelect.Min = 3 + startBoxSelect.Max = 33 + startBoxSelect.Caption = "Split the map start boxes along the sides, with X percent of the map going to all 4 sides." + startBoxSelect.AcceptFunc = function(integervalue) + battleLobby:SayBattle("!split s "..tostring(integervalue)) + end + startBoxSelect.AcceptFuncSingleplayer = function(integervalue) + externalFunctions.AddStartRect(0, 0, 100 - integervalue , integervalue *2, 100 + integervalue) + externalFunctions.AddStartRect(1, 200-integervalue *2, 100-integervalue, 200, 100 + integervalue) + externalFunctions.AddStartRect(2, 100 - integervalue , 0, 100 + integervalue, integervalue * 2) + externalFunctions.AddStartRect(3, 100 - integervalue , 200 - integervalue *2, 100+ integervalue, 200) + end + end + MakeIntegerSelectorWindow() end end - }, - itemKeyToName = boxNames, - parent = startBoxPanel, + } } local btnAddBox = Button:New{ From d88c8157cfe7c0393ef1cf17e6d8af8aa6cf2287 Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Sat, 14 Dec 2024 19:21:51 -0700 Subject: [PATCH 07/16] ~ --- LuaMenu/widgets/gui_battle_room_window.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LuaMenu/widgets/gui_battle_room_window.lua b/LuaMenu/widgets/gui_battle_room_window.lua index 862c48b66..b8f5c08c4 100644 --- a/LuaMenu/widgets/gui_battle_room_window.lua +++ b/LuaMenu/widgets/gui_battle_room_window.lua @@ -257,7 +257,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs WG.Chobby.ConfirmationPopup(defaultBoxes, "Restore default start boxes for the current number of teams.", nil, 330, 230, i18n("ok"),nil, cancelFunc) return else - if selected == "East vs West" then + if selected == "E vs W" then startBoxSelect.Min = 3 startBoxSelect.Max = 50 startBoxSelect.Caption = "Split the map start boxes vertically, with X percent of the map going to left and right start boxes." @@ -268,7 +268,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs externalFunctions.AddStartRect(0, 0, 0, integervalue *2, 200) externalFunctions.AddStartRect(1, 200 - integervalue *2, 0, 200, 200) end - elseif selected == "North vs South" then + elseif selected == "N vs S" then startBoxSelect.Min = 3 startBoxSelect.Max = 50 startBoxSelect.Caption = "Split the map start boxes horizontally, with X percent of the map going to top and bottom start boxes." From 2fe4329a2555355d8c67bcbda16ad789c40023f3 Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Sat, 14 Dec 2024 19:32:03 -0700 Subject: [PATCH 08/16] ~ --- LuaMenu/widgets/gui_integer_popup_window.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LuaMenu/widgets/gui_integer_popup_window.lua b/LuaMenu/widgets/gui_integer_popup_window.lua index fbb1e54cd..a89c113b3 100644 --- a/LuaMenu/widgets/gui_integer_popup_window.lua +++ b/LuaMenu/widgets/gui_integer_popup_window.lua @@ -115,7 +115,7 @@ local function CreateIntegerSelectorWindow(opts) local integerTrackBar = Trackbar:New { x = 0, - width = IntegerSelectorWindow.width * 0.90, + width = IntegerSelectorWindow.width * 0.88, height = 40, bottom = 45, value = opts.defaultValue or 0, From a5dc9e9c07625baf209c4da551676c0db7f19b88 Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Sun, 15 Dec 2024 17:15:03 -0700 Subject: [PATCH 09/16] Add team count to restore default boxes popup Try to select default boxes when map changes --- LuaMenu/widgets/gui_battle_room_window.lua | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/LuaMenu/widgets/gui_battle_room_window.lua b/LuaMenu/widgets/gui_battle_room_window.lua index b8f5c08c4..296983aba 100644 --- a/LuaMenu/widgets/gui_battle_room_window.lua +++ b/LuaMenu/widgets/gui_battle_room_window.lua @@ -254,7 +254,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs end UpdateBoxes() end - WG.Chobby.ConfirmationPopup(defaultBoxes, "Restore default start boxes for the current number of teams.", nil, 330, 230, i18n("ok"),nil, cancelFunc) + WG.Chobby.ConfirmationPopup(defaultBoxes, "Restore default start boxes for the current number of teams (" .. (battle.nbTeams or emptyTeamIndex or 1) .. ").", nil, 330, 230, i18n("ok"),nil, cancelFunc) return else if selected == "E vs W" then @@ -349,10 +349,6 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs tooltip = "Add a new start box in the center", OnClick = { function () - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end if battleLobby.name == "singleplayer" then externalFunctions.AddStartRect(#currentStartRects,66, 66, 133, 133) else @@ -390,10 +386,6 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs tooltip = "Remove last start box", OnClick = { function () - local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {} - if battleStatus.isSpectator then - return - end if battleLobby.name == "singleplayer" then if #currentStartRects > 0 then externalFunctions.RemoveStartRect(#currentStartRects -1) @@ -666,6 +658,11 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs mapName = battle.mapName:gsub("_", " ") mapName = StringUtilities.GetTruncatedStringWithDotDot(mapName, lblMapName.font, width - 22) lblMapName:SetCaption(mapName) + + startBoxComboBox:Select(1) + oldSelectedBoxes = 1 + startBoxImage.file = LUA_DIRNAME .. "images/load_img_128.png" + startBoxImage:Invalidate() end SetMapName(battle.mapName, mapLinkWidth) @@ -4207,7 +4204,7 @@ end function BattleRoomWindow.SetTeams(numberOfTeams) if battleLobby.name ~= "singleplayer" then -- command to set the teams - battleLobby:SayBattle(string.format("!nbteams %d", numberOfTeams)) + battleLobby:SayBattle(string.format("!nbTeams %d", numberOfTeams)) end end From 38e5fac95b325433ee102599ca52ad9e779b7543 Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Sun, 15 Dec 2024 23:18:07 -0700 Subject: [PATCH 10/16] Make a function for selecting the default position and apply it in a few cases --- LuaMenu/widgets/gui_battle_room_window.lua | 45 ++++++++++++++-------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/LuaMenu/widgets/gui_battle_room_window.lua b/LuaMenu/widgets/gui_battle_room_window.lua index 296983aba..6c8438351 100644 --- a/LuaMenu/widgets/gui_battle_room_window.lua +++ b/LuaMenu/widgets/gui_battle_room_window.lua @@ -141,7 +141,9 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs local currentMapName local oldSelectedBoxes = 1 local startBoxSelect = {} + local startBoxDefaultImage = LUA_DIRNAME .. "images/load_img_128.png" local freezeSettings = true + local mapLinkWidth = 150 currentStartRects = {} @@ -173,11 +175,11 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs width = "100%", height = "100%", keepAspect = true, - file = LUA_DIRNAME .. "images/load_img_128.png", + file = startBoxDefaultImage, parent = startBoxImageHolder, } - local startBoxSelectorNames = {"Default Boxes", "E vs W", "N vs S", "NE vs SW", "NW vs SE", "4 Corners", "4 Sides"} + local startBoxSelectorNames = {"Default Boxes", "East vs West", "North vs South", "NE vs SW", "NW vs SE", "4 Corners", "4 Sides"} local startBoxSelectorTooltips = {"Reset to default", "East vs West", "North vs South", "Northeast vs Southwest", "Northwest vs Southeast", "Southwest vs Northeast vs Northwest vs Southeast", "West vs East vs North vs South"} local startBoxComboBox = ComboBox:New{ @@ -206,9 +208,9 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs end local imageFileMap = { - ["Default Boxes"] = LUA_DIRNAME .. "images/load_img_128.png", - ["E vs W"] = LUA_DIRNAME .. "images/startboxsplit_v.png", - ["N vs S"] = LUA_DIRNAME .. "images/startboxsplit_h.png", + ["Default Boxes"] = startBoxDefaultImage, + ["East vs West"] = LUA_DIRNAME .. "images/startboxsplit_v.png", + ["North vs South"] = LUA_DIRNAME .. "images/startboxsplit_h.png", ["NE vs SW"] = LUA_DIRNAME .. "images/startboxsplit_c1.png", ["NW vs SE"] = LUA_DIRNAME .. "images/startboxsplit_c2.png", ["4 Corners"] = LUA_DIRNAME .. "images/startboxsplit_c.png", @@ -254,10 +256,10 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs end UpdateBoxes() end - WG.Chobby.ConfirmationPopup(defaultBoxes, "Restore default start boxes for the current number of teams (" .. (battle.nbTeams or emptyTeamIndex or 1) .. ").", nil, 330, 230, i18n("ok"),nil, cancelFunc) + WG.Chobby.ConfirmationPopup(defaultBoxes, "Restore default start boxes for the current number of teams: (" .. (battle.nbTeams or emptyTeamIndex or 1) .. ")", nil, 330, 230, i18n("ok"),nil, cancelFunc) return else - if selected == "E vs W" then + if selected == "East vs West" then startBoxSelect.Min = 3 startBoxSelect.Max = 50 startBoxSelect.Caption = "Split the map start boxes vertically, with X percent of the map going to left and right start boxes." @@ -268,7 +270,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs externalFunctions.AddStartRect(0, 0, 0, integervalue *2, 200) externalFunctions.AddStartRect(1, 200 - integervalue *2, 0, 200, 200) end - elseif selected == "N vs S" then + elseif selected == "North vs South" then startBoxSelect.Min = 3 startBoxSelect.Max = 50 startBoxSelect.Caption = "Split the map start boxes horizontally, with X percent of the map going to top and bottom start boxes." @@ -334,6 +336,13 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs } } + StartBoxComboBoxSelectDefault = function() + startBoxComboBox:Select(1) + oldSelectedBoxes = 1 + startBoxImage.file = startBoxDefaultImage + startBoxImage:Invalidate() + end + local btnAddBox = Button:New{ name = 'btnAddBox', x = 0, @@ -658,11 +667,6 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs mapName = battle.mapName:gsub("_", " ") mapName = StringUtilities.GetTruncatedStringWithDotDot(mapName, lblMapName.font, width - 22) lblMapName:SetCaption(mapName) - - startBoxComboBox:Select(1) - oldSelectedBoxes = 1 - startBoxImage.file = LUA_DIRNAME .. "images/load_img_128.png" - startBoxImage:Invalidate() end SetMapName(battle.mapName, mapLinkWidth) @@ -1409,9 +1413,6 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs if battleID ~= updatedBattleID then return end - - -- only on init of single player lobby: - if battleInfo.mapName then SetMapName(battleInfo.mapName, mapLinkWidth) imMinimap.file, imMinimap.checkFileExists = config:GetMinimapImage(battleInfo.mapName) @@ -1455,6 +1456,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs externalFunctions.AddStartRect(1,160,0,200,200) end + StartBoxComboBoxSelectDefault() else Spring.Echo("No map startBoxes found or disabled for map",mapName,"teamcount:",allyTeamCount) end @@ -3565,6 +3567,17 @@ local function InitializeControls(battleID, oldLobby, topPoportion, setupData) local myUserName = battleLobby:GetMyUserName() local iAmMentioned = (string.find(message,myUserName,nil,true) ~= nil) --Spring.Echo("Parsing", userName, message, myUserName,iAmMentioned) + --Preset "tourney" (Tournament 1v1 Game Global Settings) applied by TheMooseIsLoose + + -- Restore default position on startbox selector when map, preset or teamcount changes + if string.match(message, "Global setting changed by .- %((nbTeams=%d+)%)") + or string.match(message, "Loaded boxes of map ") + or string.match(message, "Map changed by .-%: ") + or string.match(message, "Preset .%w+. %(.-%) applied by .+") + then + StartBoxComboBoxSelectDefault() + return false + end if iAmMentioned then return false end From 5ef27daf2466353d73178454b9092c81aae578a5 Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Sun, 15 Dec 2024 23:19:55 -0700 Subject: [PATCH 11/16] ~ --- LuaMenu/widgets/gui_battle_room_window.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/LuaMenu/widgets/gui_battle_room_window.lua b/LuaMenu/widgets/gui_battle_room_window.lua index 6c8438351..faaed74ee 100644 --- a/LuaMenu/widgets/gui_battle_room_window.lua +++ b/LuaMenu/widgets/gui_battle_room_window.lua @@ -3566,8 +3566,6 @@ local function InitializeControls(battleID, oldLobby, topPoportion, setupData) -- should only be called on messages from founder (host) local myUserName = battleLobby:GetMyUserName() local iAmMentioned = (string.find(message,myUserName,nil,true) ~= nil) - --Spring.Echo("Parsing", userName, message, myUserName,iAmMentioned) - --Preset "tourney" (Tournament 1v1 Game Global Settings) applied by TheMooseIsLoose -- Restore default position on startbox selector when map, preset or teamcount changes if string.match(message, "Global setting changed by .- %((nbTeams=%d+)%)") From 8810b1814f8f80da4b326bee00a1c5831fcf43ec Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Sun, 15 Dec 2024 23:23:35 -0700 Subject: [PATCH 12/16] Cleanup --- LuaMenu/widgets/gui_battle_room_window.lua | 190 --------------------- 1 file changed, 190 deletions(-) diff --git a/LuaMenu/widgets/gui_battle_room_window.lua b/LuaMenu/widgets/gui_battle_room_window.lua index faaed74ee..069b4ff82 100644 --- a/LuaMenu/widgets/gui_battle_room_window.lua +++ b/LuaMenu/widgets/gui_battle_room_window.lua @@ -418,196 +418,6 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs tooltip = btnClearBox.tooltip, } - -- the buttons needed are: - -- splitV , splitH, splitC1_2, splitC2_2, split4, add, remove - --[[ local btnSplitV = Button:New{ - name = 'btnSplitV', - x = "0%", - bottom = 0, - width = "12%", - height = "100%", - maxWidth = 50, - maxHeight = 50, - classname = "button_small", - caption = "", - noFont = true, - padding = {0, 0, 0, 0}, - parent = startBoxPanel, - tooltip = "Split start boxes left vs right", - OnClick = { - } - } - --]] - --[[ - local btnSplitH = Button:New{ - name = 'btnSplitH', - x = "12.5%", - bottom = 0, - width = '12%', - height = "100%", - maxWidth = 50, - maxHeight = 50, - parent = startBoxPanel, - classname = "button_small", - caption = "", - noFont = true, - padding = {0, 0, 0, 0}, - tooltip = "Split start boxes top vs bottom", - OnClick = { - function () - end - } - } - - local imSplitH = Image:New { - name = 'imSplitH', - x = 0, - y = 0, - right = 0, - bottom = 0, - keepAspect = false, - file = LUA_DIRNAME .. "images/startboxsplit_h.png", - parent = btnSplitH, - tooltip = btnSplitH.tooltip, - } - - local btnSplitC1 = Button:New{ - name = 'btnSplitC1', - x = "25%", - bottom = 0, - width = '12%', - height = "100%", - maxWidth = 50, - maxHeight = 50, - parent = startBoxPanel, - classname = "button_small", - caption = "", - noFont = true, - padding = {0, 0, 0, 0}, - tooltip = "Split start boxes top left vs bottom right", - OnClick = { - function () - - end - } - } - - local imSplitC1 = Image:New { - name = 'imSplitC1', - x = 0, - y = 0, - right = 0, - bottom = 0, - keepAspect = false, - file = LUA_DIRNAME .. "images/startboxsplit_c1.png", - parent = btnSplitC1, - tooltip = btnSplitC1.tooltip, - } - - local btnSplitC2 = Button:New{ - name = 'btnSplitC2', - x = "37.5%", - bottom = 0, - width = '12%', - height = "100%", - maxWidth = 50, - maxHeight = 50, - parent = startBoxPanel, - classname = "button_small", - caption = "", - noFont = true, - padding = {0, 0, 0, 0}, - tooltip = "Split start boxes bottom left vs top right", - OnClick = { - function () - - end - } - } - - local imSplitC2 = Image:New { - name = 'imSplitC2', - x = 0, - y = 0, - right = 0, - bottom = 0, - keepAspect = false, - file = LUA_DIRNAME .. "images/startboxsplit_c2.png", - parent = btnSplitC2, - tooltip = btnSplitC2.tooltip, - } - - - local btnSplitC4 = Button:New{ - name = 'btnSplitC4', - x = "50%", - bottom = 0, - width = '12%', - height = "100%", - maxWidth = 50, - maxHeight = 50, - parent = startBoxPanel, - classname = "button_small", - caption = "", - noFont = true, - padding = {0, 0, 0, 0}, - tooltip = "Split start boxes into 4 corners for 4 teams", - OnClick = { - function () - - end - } - } - - local imSplitC4 = Image:New { - name = 'imSplitC4', - x = 0, - y = 0, - right = 0, - bottom = 0, - keepAspect = false, - file = LUA_DIRNAME .. "images/startboxsplit_c.png", - parent = btnSplitC4, - tooltip = btnSplitC4.tooltip, - } - - - local btnSplitS4 = Button:New{ - name = 'btnSplitS4', - x = "62.5%", - bottom = 0, - width = '12%', - height = "100%", - maxWidth = 50, - maxHeight = 50, - parent = startBoxPanel, - classname = "button_small", - caption = "", - noFont = true, - padding = {0, 0, 0, 0}, - tooltip = "Split start boxes into 4 sides for 4 teams", - OnClick = { - function () - - end - } - } - - local imSplitS4 = Image:New { - name = 'imSplitS4', - x = 0, - y = 0, - right = 0, - bottom = 0, - keepAspect = false, - file = LUA_DIRNAME .. "images/startboxsplit_s.png", - parent = btnSplitS4, - tooltip = btnSplitS4.tooltip, - } ]] - - - - local function UpdateStartRectPositionsInMinimap(width) for i, rect in pairs(currentStartRects) do From 665312cbf78a94e97f819abc74bf85adcf802eb5 Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Mon, 16 Dec 2024 00:23:33 -0700 Subject: [PATCH 13/16] Reinforce patterns --- LuaMenu/widgets/gui_battle_room_window.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LuaMenu/widgets/gui_battle_room_window.lua b/LuaMenu/widgets/gui_battle_room_window.lua index 069b4ff82..11c82aa8e 100644 --- a/LuaMenu/widgets/gui_battle_room_window.lua +++ b/LuaMenu/widgets/gui_battle_room_window.lua @@ -3378,10 +3378,10 @@ local function InitializeControls(battleID, oldLobby, topPoportion, setupData) local iAmMentioned = (string.find(message,myUserName,nil,true) ~= nil) -- Restore default position on startbox selector when map, preset or teamcount changes - if string.match(message, "Global setting changed by .- %((nbTeams=%d+)%)") - or string.match(message, "Loaded boxes of map ") - or string.match(message, "Map changed by .-%: ") - or string.match(message, "Preset .%w+. %(.-%) applied by .+") + if string.match(message, "Global setting changed by .- %((nbTeams=%d+)%)$") + or string.match(message, "Loaded boxes of map .%w+. ") + or string.match(message, "Map changed by .-%: .+$") + or string.match(message, "Preset .%w+. %(.-%) applied by .+$") then StartBoxComboBoxSelectDefault() return false From 10ce9138edba7b4ff289a72bdb3bd11db76b9fd2 Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:59:19 -0700 Subject: [PATCH 14/16] Add support for small images in the combobox list --- libs/chiliui/chili/controls/combobox.lua | 36 +++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/libs/chiliui/chili/controls/combobox.lua b/libs/chiliui/chili/controls/combobox.lua index 0098af990..cba665901 100644 --- a/libs/chiliui/chili/controls/combobox.lua +++ b/libs/chiliui/chili/controls/combobox.lua @@ -9,6 +9,7 @@ -- @tparam {"item1", "item2", ...} items table of items in the ComboBox, (default {"items"}) -- @int[opt = 1] selected id of the selected item -- @tparam {func1, func2, ...} OnSelect listener functions for selected item changes, (default {}) +-- @tparam {string1, string2, ...} itemImages table of image paths/files for items ComboBox = Button:Inherit{ classname = "combobox", caption = 'combobox', @@ -16,6 +17,7 @@ ComboBox = Button:Inherit{ defaultHeight = 20, items = { "items" }, itemsTooltips = {}, + itemImages = {}, itemHeight = 20, selected = 1, showSelection = true, @@ -113,16 +115,45 @@ function ComboBox:MouseDown(x, y) local width = math.max(self.width, self.minDropDownWidth) local height = self.topHeight + + local imageWidth = self.itemHeight * 0.85 + local imageHeight = self.itemHeight * 0.85 + local imagePadding = (self.itemHeight - imageHeight) / 3 + for i = 1, #self.items do local item = self.items[i] if type(item) == "string" then + local itemContainer = StackPanel:New { + width = '100%', + height = self.itemHeight, + orientation = 'vertical', + padding = {imagePadding, imagePadding, imagePadding, imagePadding}, + itemMargin = {0, 0, 0, 0}, + autosize = false, + resizeItems = false, + centerItems = false, + } + + if self.itemImages[i] then + local imageControl = Image:New { + width = imageWidth, + height = imageHeight, + file = self.itemImages[i], + keepAspect = true, + y = (self.itemHeight - imageHeight) * 0.5, + } + itemContainer:AddChild(imageControl) + end + local newBtn = ComboBoxItem:New { caption = item, width = '100%', height = self.itemHeight, + padding = {3, 0, 3, 0}, fontsize = self.itemFontSize, objectOverrideFont = self.objectOverrideFont, state = {focused = (self.showSelection and i == self.selected), selected = (self.showSelection and i == self.selected)}, + children = { itemContainer }, OnMouseUp = { function() if selectByName then @@ -134,12 +165,15 @@ function ComboBox:MouseDown(x, y) end } } + if self.itemsTooltips[i] then newBtn.tooltip = self.itemsTooltips[i] end + labels[#labels + 1] = newBtn height = height + self.itemHeight - width = math.max(width, self.font:GetTextWidth(item)) + width = math.max(width, self.font:GetTextWidth(item) + + (self.itemImages[i] and (imageWidth + imagePadding + 6) or 0)) else labels[#labels + 1] = item item.OnMouseUp = { function() From 076d2ea4f111bcf6a2eefac611594befa82a5729 Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Mon, 16 Dec 2024 20:00:05 -0700 Subject: [PATCH 15/16] Reorganize the startbox image table --- LuaMenu/widgets/gui_battle_room_window.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/LuaMenu/widgets/gui_battle_room_window.lua b/LuaMenu/widgets/gui_battle_room_window.lua index 11c82aa8e..45d6e8866 100644 --- a/LuaMenu/widgets/gui_battle_room_window.lua +++ b/LuaMenu/widgets/gui_battle_room_window.lua @@ -181,7 +181,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs local startBoxSelectorNames = {"Default Boxes", "East vs West", "North vs South", "NE vs SW", "NW vs SE", "4 Corners", "4 Sides"} local startBoxSelectorTooltips = {"Reset to default", "East vs West", "North vs South", "Northeast vs Southwest", "Northwest vs Southeast", "Southwest vs Northeast vs Northwest vs Southeast", "West vs East vs North vs South"} - + local startBoxSelectorImages = {startBoxDefaultImage, LUA_DIRNAME .. "images/startboxsplit_v.png", LUA_DIRNAME .. "images/startboxsplit_h.png", LUA_DIRNAME .. "images/startboxsplit_c1.png", LUA_DIRNAME .. "images/startboxsplit_c2.png", LUA_DIRNAME .. "images/startboxsplit_c.png", LUA_DIRNAME .. "images/startboxsplit_s.png"} local startBoxComboBox = ComboBox:New{ name = 'startBoxComboBox', x = "12.25%", @@ -190,6 +190,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs bottom = 1, items = startBoxSelectorNames, itemsTooltips = startBoxSelectorTooltips, + itemImages = startBoxSelectorImages, itemKeyToName = startBoxSelectorNames, objectOverrideFont = config:GetFont(2), parent = startBoxPanel, @@ -208,13 +209,13 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs end local imageFileMap = { - ["Default Boxes"] = startBoxDefaultImage, - ["East vs West"] = LUA_DIRNAME .. "images/startboxsplit_v.png", - ["North vs South"] = LUA_DIRNAME .. "images/startboxsplit_h.png", - ["NE vs SW"] = LUA_DIRNAME .. "images/startboxsplit_c1.png", - ["NW vs SE"] = LUA_DIRNAME .. "images/startboxsplit_c2.png", - ["4 Corners"] = LUA_DIRNAME .. "images/startboxsplit_c.png", - ["4 Sides"] = LUA_DIRNAME .. "images/startboxsplit_s.png", + ["Default Boxes"] = startBoxSelectorImages[1], + ["East vs West"] = startBoxSelectorImages[2], + ["North vs South"] = startBoxSelectorImages[3], + ["NE vs SW"] = startBoxSelectorImages[4], + ["NW vs SE"] = startBoxSelectorImages[5], + ["4 Corners"] = startBoxSelectorImages[6], + ["4 Sides"] = startBoxSelectorImages[7], } local function UpdateBoxes() From 048b440d97d6c4aaae59ffb55d54e8e4d09dbf6d Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Mon, 16 Dec 2024 21:19:55 -0700 Subject: [PATCH 16/16] ~ --- LuaMenu/widgets/gui_battle_room_window.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/LuaMenu/widgets/gui_battle_room_window.lua b/LuaMenu/widgets/gui_battle_room_window.lua index 45d6e8866..95f10c903 100644 --- a/LuaMenu/widgets/gui_battle_room_window.lua +++ b/LuaMenu/widgets/gui_battle_room_window.lua @@ -382,7 +382,6 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs local btnClearBox = Button:New{ name = 'btnClearBox', - --x = "87.5%", y = 1, width = "12%", bottom = 1,