From c4624da87e4b1f137d7da121b2b784df13aa0179 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Fri, 5 May 2023 22:52:16 +0930 Subject: [PATCH 1/5] [settings] Add label helper function --- LuaMenu/widgets/gui_settings_window.lua | 174 +++++------------------- 1 file changed, 37 insertions(+), 137 deletions(-) diff --git a/LuaMenu/widgets/gui_settings_window.lua b/LuaMenu/widgets/gui_settings_window.lua index dd428594a..98de8a237 100644 --- a/LuaMenu/widgets/gui_settings_window.lua +++ b/LuaMenu/widgets/gui_settings_window.lua @@ -692,6 +692,21 @@ local function AddNumberSetting(offset, caption, desc, key, default, minVal, max return label, numberInput, offset + ITEM_OFFSET end +local function AddLabel(offset, caption, tooltip) + local Configuration = WG.Chobby.Configuration + return Label:New { + x = 20, + y = offset + TEXT_OFFSET, + width = 90, + height = 40, + valign = "top", + align = "left", + font = Configuration:GetFont(2), + caption = caption, + tooltip = tooltip, + } +end + local function GetLobbyTabControls() local freezeSettings = true @@ -718,16 +733,7 @@ local function GetLobbyTabControls() langNum = langNum + 1 end - children[#children + 1] = Label:New { - x = 20, - y = offset + TEXT_OFFSET, - width = 90, - height = 40, - valign = "top", - align = "left", - objectOverrideFont = Configuration:GetFont(2), - caption = "Language", - } + children[#children + 1] = AddLabel(offset, "Language") children[#children + 1] = ComboBox:New { x = COMBO_X, y = offset, @@ -748,16 +754,7 @@ local function GetLobbyTabControls() } offset = offset + ITEM_OFFSET - children[#children + 1] = Label:New { - x = 20, - y = offset + TEXT_OFFSET, - width = 90, - height = 40, - valign = "top", - align = "left", - objectOverrideFont = Configuration:GetFont(2), - caption = "Split Panel Mode", - } + children[#children + 1] = AddLabel(offset, "Split Panel Mode") children[#children + 1] = ComboBox:New { x = COMBO_X, y = offset, @@ -780,16 +777,7 @@ local function GetLobbyTabControls() children[#children + 1], children[#children + 2], offset = AddNumberSetting(offset, "Lobby Interface Scale", "Increase or decrease interface size, for accessibility and 4k screens.", "uiScale", Configuration.uiScale, Configuration.minUiScale*100, Configuration.maxUiScale*100, true) - children[#children + 1] = Label:New { - x = 20, - y = offset + TEXT_OFFSET, - width = 90, - height = 40, - valign = "top", - align = "left", - objectOverrideFont = Configuration:GetFont(2), - caption = "Chat Font Size", - } + children[#children + 1] = AddLabel(offset, "Chat Font Size") children[#children + 1] = Trackbar:New { x = COMBO_X, y = offset, @@ -810,16 +798,7 @@ local function GetLobbyTabControls() } offset = offset + ITEM_OFFSET - children[#children + 1] = Label:New { - x = 20, - y = offset + TEXT_OFFSET, - width = 90, - height = 40, - valign = "top", - align = "left", - objectOverrideFont = Configuration:GetFont(2), - caption = "Menu Music Volume", - } + children[#children + 1] = AddLabel(offset, "Menu Music Volume") children[#children + 1] = Trackbar:New { x = COMBO_X, y = offset, @@ -840,16 +819,7 @@ local function GetLobbyTabControls() } offset = offset + ITEM_OFFSET - children[#children + 1] = Label:New { - x = 20, - y = offset + TEXT_OFFSET, - width = 90, - height = 40, - valign = "top", - align = "left", - objectOverrideFont = Configuration:GetFont(2), - caption = "Notification Volume", - } + children[#children + 1] = AddLabel(offset, "Notification Volume") children[#children + 1] = Trackbar:New { x = COMBO_X, y = offset, @@ -870,16 +840,7 @@ local function GetLobbyTabControls() } offset = offset + ITEM_OFFSET - children[#children + 1] = Label:New { - x = 20, - y = offset + TEXT_OFFSET, - width = 90, - height = 40, - valign = "top", - align = "left", - objectOverrideFont = Configuration:GetFont(2), - caption = "Background Brightness", - } + children[#children + 1] = AddLabel(offset, "Background Brightness") children[#children + 1] = Trackbar:New { x = COMBO_X, y = offset, @@ -900,16 +861,7 @@ local function GetLobbyTabControls() } offset = offset + ITEM_OFFSET - children[#children + 1] = Label:New { - x = 20, - y = offset + TEXT_OFFSET, - width = 90, - height = 40, - valign = "top", - align = "left", - objectOverrideFont = Configuration:GetFont(2), - caption = "Game Overlay Opacity", - } + children[#children + 1] = AddLabel(offset, "Game Overlay Opacity") children[#children + 1] = Trackbar:New { x = COMBO_X, y = offset, @@ -930,17 +882,10 @@ local function GetLobbyTabControls() } offset = offset + ITEM_OFFSET - children[#children + 1] = Label:New { - x = 20, - y = offset + TEXT_OFFSET, - width = 90, - height = 40, - valign = "top", - align = "left", - objectOverrideFont = Configuration:GetFont(2), - caption = "Coop Connection Delay", - tooltip = "Hosts with poor internet may require their clients to add a delay in order to connect.", - } + children[#children + 1] = AddLabel(offset, + "Coop Connection Delay", + "Hosts with poor internet may require their clients to add a delay in order to connect." + ) children[#children + 1] = Trackbar:New { x = COMBO_X, y = offset, @@ -988,7 +933,7 @@ local function GetLobbyTabControls() if not Configuration.gameConfig.disablePlanetwars then children[#children + 1], offset = AddCheckboxSetting(offset, i18n("planetwars_notifications"), "planetwarsNotifications", false) end - + children[#children + 1], offset = AddCheckboxSetting(offset, "Autosave SP on matchmaker", "autosaveOnMatchmaker", true) children[#children + 1], offset = AddCheckboxSetting(offset, i18n("ingame_notifcations"), "ingameNotifcations", true) children[#children + 1], offset = AddCheckboxSetting(offset, i18n("non_friend_notifications"), "nonFriendNotifications", true) @@ -1000,20 +945,11 @@ local function GetLobbyTabControls() children[#children + 1], offset = AddCheckboxSetting(offset, i18n("animate_lobby"), "animate_lobby", true) children[#children + 1], offset = AddCheckboxSetting(offset, i18n("drawFullSpeed"), "drawAtFullSpeed", false) children[#children + 1], offset = AddCheckboxSetting(offset, "Minimize lobby updates", "lobbyIdleSleep", true) - + -- Not needed as it happens automatically for spectating and singleplayer. --children[#children + 1], offset = AddCheckboxSetting(offset, i18n("keep_queues"), "rememberQueuesOnStart2", false, nil, "Stay in the matchmaker when you launch a singleplayer game or replay, as well as when watching a multiplayer game.") - children[#children + 1] = Label:New { - x = 20, - y = offset + TEXT_OFFSET, - width = 90, - height = 40, - valign = "top", - align = "left", - objectOverrideFont = Configuration:GetFont(2), - caption = "Clear Channel History", - } + children[#children + 1] = AddLabel(offset, "Clear Channel History") children[#children + 1] = Button:New { x = COMBO_X, y = offset, @@ -1031,16 +967,7 @@ local function GetLobbyTabControls() } offset = offset + ITEM_OFFSET - children[#children + 1] = Label:New { - x = 20, - y = offset + TEXT_OFFSET, - width = 90, - height = 40, - valign = "top", - align = "left", - objectOverrideFont = Configuration:GetFont(2), - caption = "Delete Path Cache", - } + children[#children + 1] = AddLabel(offset, "Delete Path Cache") children[#children + 1] = Button:New { x = COMBO_X, y = offset, @@ -1116,16 +1043,7 @@ local function GetVoidTabControls() children[#children + 1], offset = AddCheckboxSetting(offset, "Use wrong engine", "useWrongEngine", false) children[#children + 1], offset = AddCheckboxSetting(offset, "Show old AI versions", "showOldAiVersions", false) - children[#children + 1] = Label:New { - x = 20, - y = offset + TEXT_OFFSET, - width = 90, - height = 40, - valign = "top", - align = "left", - objectOverrideFont = Configuration:GetFont(2), - caption = "Disable Lobby", - } + children[#children + 1] = AddLabel(offset, "Disable Lobby") children[#children + 1] = Button:New { x = COMBO_X, y = offset, @@ -1142,16 +1060,7 @@ local function GetVoidTabControls() } offset = offset + ITEM_OFFSET - children[#children + 1] = Label:New { - x = 20, - y = offset + TEXT_OFFSET, - width = 90, - height = 40, - valign = "top", - align = "left", - objectOverrideFont = Configuration:GetFont(2), - caption = "Server Address (zero-k.info or test.zero-k.info for testing)", - } + children[#children + 1] = AddLabel(offset, "Server Address (zero-k.info or test.zero-k.info for testing)") children[#children + 1] = EditBox:New { x = COMBO_X, y = offset, @@ -1174,16 +1083,7 @@ local function GetVoidTabControls() } offset = offset + ITEM_OFFSET - children[#children + 1] = Label:New { - x = 20, - y = offset + TEXT_OFFSET, - width = 90, - height = 40, - valign = "top", - align = "left", - objectOverrideFont = Configuration:GetFont(2), - caption = "Server Port (8200 or 8202 for testing)", - } + children[#children + 1] = AddLabel(offset, "Server Port (8200 or 8202 for testing)") children[#children + 1] = EditBox:New { x = COMBO_X, y = offset, @@ -1324,7 +1224,7 @@ local function MakeRestartWarning(offset) objectOverrideFont = Configuration:GetFont(2), caption = "Warning: Most changes do not affect battles in progress.", } - + return warningLabel, offset + ITEM_OFFSET end @@ -1671,7 +1571,7 @@ local function PopulateTab(settingPresets, settingOptions, settingsDefault) label, list, customSettingsSwitch, offset = MakePresetsControl(settingPresets, offset) children[#children + 1] = label children[#children + 1] = list - + label, offset = MakeRestartWarning(offset) children[#children + 1] = label end @@ -1856,7 +1756,7 @@ function SettingsWindow.WriteGameSpringsettings(fileName) WriteToFile("WindowBorderless", 0) WriteToFile("Fullscreen", 1) end - + settingsFile:close() end @@ -1981,7 +1881,7 @@ function widget:Initialize() -- Settings which rely on io local gameSettings = Configuration.game_settings - + if lobbyFullscreen ~= battleStartDisplay or battleStartDisplay >= 4 then SetLobbyFullscreenMode(battleStartDisplay) From 8191bde14ee504a5c723e2676d2be599892afc4a Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Fri, 5 May 2023 22:54:30 +0930 Subject: [PATCH 2/5] Move nil check on WG.Chobby.Configuration --- LuaMenu/widgets/gui_settings_window.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/LuaMenu/widgets/gui_settings_window.lua b/LuaMenu/widgets/gui_settings_window.lua index 98de8a237..50c9c4e1b 100644 --- a/LuaMenu/widgets/gui_settings_window.lua +++ b/LuaMenu/widgets/gui_settings_window.lua @@ -1829,6 +1829,9 @@ end local firstCall = true function widget:ActivateMenu() + if not (WG.Chobby and WG.Chobby.Configuration) then + return + end if firstCall then local gameSettings = WG.Chobby.Configuration.game_settings for key, value in pairs(gameSettings) do @@ -1838,9 +1841,6 @@ function widget:ActivateMenu() firstCall = false return end - if not (WG.Chobby and WG.Chobby.Configuration) then - return - end inLobby = true SetLobbyFullscreenMode(WG.Chobby.Configuration.lobby_fullscreen) end From 17678780f94310fbde35232224d60dfae6912139 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Fri, 5 May 2023 22:55:51 +0930 Subject: [PATCH 3/5] [settings] Localize Spring.SetConfigInt --- LuaMenu/widgets/gui_settings_window.lua | 71 +++++++++++++------------ 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/LuaMenu/widgets/gui_settings_window.lua b/LuaMenu/widgets/gui_settings_window.lua index 50c9c4e1b..332e0eb22 100644 --- a/LuaMenu/widgets/gui_settings_window.lua +++ b/LuaMenu/widgets/gui_settings_window.lua @@ -17,6 +17,7 @@ end -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- Local Variables +local spSetConfigInt = Spring.SetConfigInt local battleStartDisplay = 1 local lobbyFullscreen = 1 @@ -87,7 +88,7 @@ local function SaveWindowPos(width, height, x, y) end -- WindowState is not saved by Spring. See https://springrts.com/mantis/view.php?id=5624 - Spring.SetConfigInt("WindowState", (x == 0 and 1) or 0, false) + spSetConfigInt("WindowState", (x == 0 and 1) or 0, false) end local function EnableProfilerFunc(newState) @@ -230,22 +231,22 @@ local function SetLobbyFullscreenMode(mode, borderOverride) -- Required to remove FUDGE currentManualBorderless = false - Spring.SetConfigInt("Fullscreen", 1) + spSetConfigInt("Fullscreen", 1) - Spring.SetConfigInt("XResolutionWindowed", screenX - FUDGE*2, false) - Spring.SetConfigInt("YResolutionWindowed", screenY - FUDGE*2, false) - Spring.SetConfigInt("WindowPosX", FUDGE, false) - Spring.SetConfigInt("WindowPosY", FUDGE, false) + spSetConfigInt("XResolutionWindowed", screenX - FUDGE*2, false) + spSetConfigInt("YResolutionWindowed", screenY - FUDGE*2, false) + spSetConfigInt("WindowPosX", FUDGE, false) + spSetConfigInt("WindowPosY", FUDGE, false) - Spring.SetConfigInt("WindowBorderless", 1, false) - Spring.SetConfigInt("Fullscreen", 0, false) + spSetConfigInt("WindowBorderless", 1, false) + spSetConfigInt("Fullscreen", 0, false) elseif mode == 2 then -- Windowed local winSizeX, winSizeY, winPosX, winPosY = Spring.GetViewGeometry() winPosX = Configuration.window_WindowPosX or winPosX winSizeX = Configuration.window_XResolutionWindowed or winSizeX winSizeY = Configuration.window_YResolutionWindowed or winSizeY - Spring.SetConfigInt("WindowBorderless", 0, false) - Spring.SetConfigInt("Fullscreen", 0) + spSetConfigInt("WindowBorderless", 0, false) + spSetConfigInt("Fullscreen", 0) if Configuration.window_WindowPosY then winPosY = Configuration.window_WindowPosY @@ -255,23 +256,23 @@ local function SetLobbyFullscreenMode(mode, borderOverride) if winPosY > 10 then -- Window is not stuck at the top of the screen - Spring.SetConfigInt("WindowPosX", math.min(winPosX, screenX - 50), false) - Spring.SetConfigInt("WindowPosY", math.min(winPosY, screenY - 50), false) - Spring.SetConfigInt("XResolutionWindowed", math.min(winSizeX, screenX), false) - Spring.SetConfigInt("YResolutionWindowed", math.min(winSizeY, screenY - 50), false) + spSetConfigInt("WindowPosX", math.min(winPosX, screenX - 50), false) + spSetConfigInt("WindowPosY", math.min(winPosY, screenY - 50), false) + spSetConfigInt("XResolutionWindowed", math.min(winSizeX, screenX), false) + spSetConfigInt("YResolutionWindowed", math.min(winSizeY, screenY - 50), false) else -- Reset window to screen centre - Spring.SetConfigInt("WindowPosX", screenX/4, false) - Spring.SetConfigInt("WindowPosY", screenY/8, false) - Spring.SetConfigInt("XResolutionWindowed", screenX/2, false) - Spring.SetConfigInt("YResolutionWindowed", screenY*3/4, false) + spSetConfigInt("WindowPosX", screenX/4, false) + spSetConfigInt("WindowPosY", screenY/8, false) + spSetConfigInt("XResolutionWindowed", screenX/2, false) + spSetConfigInt("YResolutionWindowed", screenY*3/4, false) end - Spring.SetConfigInt("WindowBorderless", 0, false) - Spring.SetConfigInt("Fullscreen", 0) + spSetConfigInt("WindowBorderless", 0, false) + spSetConfigInt("Fullscreen", 0) elseif mode == 3 then -- Fullscreen - Spring.SetConfigInt("XResolution", screenX, false) - Spring.SetConfigInt("YResolution", screenY, false) - Spring.SetConfigInt("Fullscreen", 1, false) + spSetConfigInt("XResolution", screenX, false) + spSetConfigInt("YResolution", screenY, false) + spSetConfigInt("Fullscreen", 1, false) elseif mode == 4 or mode == 6 then -- Manual Borderless and windowed local borders = borderOverride if not borders then @@ -284,16 +285,16 @@ local function SetLobbyFullscreenMode(mode, borderOverride) end currentManualBorderless = Spring.Utilities.CopyTable(borders) - Spring.SetConfigInt("Fullscreen", (mode == 4 and 1) or 0) + spSetConfigInt("Fullscreen", (mode == 4 and 1) or 0) - Spring.SetConfigInt("XResolutionWindowed", borders.width or (screenX - FUDGE*2), false) - Spring.SetConfigInt("YResolutionWindowed", borders.height or (screenY - FUDGE*2), false) - Spring.SetConfigInt("WindowPosX", borders.x or FUDGE, false) - Spring.SetConfigInt("WindowPosY", borders.y or FUDGE, false) + spSetConfigInt("XResolutionWindowed", borders.width or (screenX - FUDGE*2), false) + spSetConfigInt("YResolutionWindowed", borders.height or (screenY - FUDGE*2), false) + spSetConfigInt("WindowPosX", borders.x or FUDGE, false) + spSetConfigInt("WindowPosY", borders.y or FUDGE, false) - Spring.SetConfigInt("WindowBorderless", (mode == 4 and 1) or 0, false) + spSetConfigInt("WindowBorderless", (mode == 4 and 1) or 0, false) - Spring.SetConfigInt("Fullscreen", 0, false) + spSetConfigInt("Fullscreen", 0, false) elseif mode == 5 then -- Manual Fullscreen local resolution if inLobby then @@ -301,9 +302,9 @@ local function SetLobbyFullscreenMode(mode, borderOverride) else resolution = WG.Chobby.Configuration.manualFullscreen.game or {} end - Spring.SetConfigInt("XResolution", resolution.width or screenX, false) - Spring.SetConfigInt("YResolution", resolution.height or screenY, false) - Spring.SetConfigInt("Fullscreen", 1, false) + spSetConfigInt("XResolution", resolution.width or screenX, false) + spSetConfigInt("YResolution", resolution.height or screenY, false) + spSetConfigInt("Fullscreen", 1, false) end if delayedModeSet == mode and delayedBorderOverride then @@ -313,8 +314,8 @@ local function SetLobbyFullscreenMode(mode, borderOverride) delayedModeSet = mode delayedBorderOverride = borderOverride currentMode = 2 - Spring.SetConfigInt("WindowBorderless", 0, false) - Spring.SetConfigInt("Fullscreen", 0) + spSetConfigInt("WindowBorderless", 0, false) + spSetConfigInt("Fullscreen", 0) WG.Delay(SetLobbyFullscreenMode, 0.8) end end From cc4f85f551c2cf363a6fccd63924c718886db187 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Thu, 8 Oct 2020 18:35:03 +1030 Subject: [PATCH 4/5] [music] Prevent SetTrackVolume from propagating nil to Spring.SetSoundStreamVolume --- LuaMenu/widgets/snd_music_lite.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LuaMenu/widgets/snd_music_lite.lua b/LuaMenu/widgets/snd_music_lite.lua index e369ab9fa..f9b7b48f6 100644 --- a/LuaMenu/widgets/snd_music_lite.lua +++ b/LuaMenu/widgets/snd_music_lite.lua @@ -74,7 +74,7 @@ end -------------------------------------------------------------------------------- local function SetTrackVolume(volume) - if volume == 0 then + if not volume or volume == 0 then StopTrack() return end @@ -183,7 +183,7 @@ function widget:Initialize() WG.LibLobby.lobby:AddListener("OnBattleAboutToStart", OnBattleAboutToStart) WG.MusicHandler = MusicHandler - + WG.Delay(DelayedInitialize, 0.1) WG.Delay(DelayedInitialize, 1) end From 2adfd96c4d1605982431a23a7f92d8d3f7b304ed Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Thu, 8 Oct 2020 19:50:46 +1030 Subject: [PATCH 5/5] Added volume sliders and a clock. Layout probably needs work. [settings] Make Lobby Music Volume trackbar update periodically [settings] Added Master Volume trackbar Moving panels around --- LuaMenu/images/vol.png | Bin 0 -> 689 bytes LuaMenu/images/vol_music.png | Bin 0 -> 648 bytes .../chobby/components/interface_root.lua | 16 ++ LuaMenu/widgets/gui_settings_window.lua | 46 +++- LuaMenu/widgets/gui_volume_panel.lua | 198 ++++++++++++++++++ 5 files changed, 258 insertions(+), 2 deletions(-) create mode 100644 LuaMenu/images/vol.png create mode 100644 LuaMenu/images/vol_music.png create mode 100644 LuaMenu/widgets/gui_volume_panel.lua diff --git a/LuaMenu/images/vol.png b/LuaMenu/images/vol.png new file mode 100644 index 0000000000000000000000000000000000000000..b0624332fad89adc712cdbb984a9746745e4708d GIT binary patch literal 689 zcmV;i0#5yjP)2WjmV(pA7HYiGQIP@ z%WfAa2=fOb;=LCmVz~QY-gO~3>_T?EK{D6C3lUw%7__7nJ3D84y67m!a{0n@^?pBJ zp67kOuM!bD9i@~4t^)Uf8gL{cmRqA;0$&4$GMUWs$jHb`z^{}#&xpuB1t`D=#Aaq@ zQq^iz^7;H8@D%7jr~Mxsi9`~*t}hjf#jl28NHUpx58Maz3k}@x`uh6EVzF55?(SY1 z8ykCfaByIk%jG)o0_Zzs&gOB=90eW^3=G^21OkDzwY6uPo14dnhliEk-rm09;o*nC zm2;2ihF4ct-{`vTkH_O5L`0&|Xarz?fB)FFZAM2&hkzc3IqRSYc(Ay*_QSLksMYKBUw*&e53sYdb7b2#;cz$%^aEXP0}aqU9*@_uENZoy>1;?@mUSAGF3YlL zHk&O#oI-al8$cpvG37A8&8B$vy51_%a&LDMwJX0v&~6lZOx9UvlYrBn?l*tSijQmHf= zjn?e!Y;Iy=;*QVfyLEDM@_l!AcMq^TCei8YI`BLc3e9`H-sO#rjc?oA+Y*n*(?FzS zkS;Qro}SKZZEZ;^mHGrcafhg*!QUn;D=XPhDD(=r0cdWWy5u`+PQb!|0UV2n?biGT X>wIDM@veby00000NkvXXu0mjf90NA* literal 0 HcmV?d00001 diff --git a/LuaMenu/images/vol_music.png b/LuaMenu/images/vol_music.png new file mode 100644 index 0000000000000000000000000000000000000000..ed8da6f8f33033249eb7af4cd9b8de02e58e5db1 GIT binary patch literal 648 zcmV;30(bq1P)6D>U1{Vh_+>Rk_wZ=4R#p^v^2hS~%l=Q$^K6sz=e((1k zB_iBDN+}mu1)c-X00Z>w9Rsmgq4N*10un&x&=}_kc~{5#XwXat}oLzV9>|jjq<( zJ32Z#0A2!5tiyW&044|my4~*gVzKxslgX@?N~JeT0Ox-WBnSefl)5&?^jodg*J`y| z0v-bTjsrUZ$M)|6%JV!0+yK3HyZuE(CO`xTAbLrh2z?vUV_;P&rHnDZfgh)*rJq;I literal 0 HcmV?d00001 diff --git a/LuaMenu/widgets/chobby/components/interface_root.lua b/LuaMenu/widgets/chobby/components/interface_root.lua index 838e552f6..faa9fcb71 100644 --- a/LuaMenu/widgets/chobby/components/interface_root.lua +++ b/LuaMenu/widgets/chobby/components/interface_root.lua @@ -181,6 +181,18 @@ function GetInterfaceRoot(optionsParent, mainWindowParent, fontFunction) children = {} } + local status_volumePanel = Panel:New { + y = 5, + height = 36, + width = 205, + right = userStatusWidth + 10, + padding = {0, 0, 0, 0}, + parent = holder_status, + children = { + WG.VolumePanel.GetControl(), + } + } + local status_userWindow = Control:New { y = 0, right = 0, @@ -619,6 +631,8 @@ function GetInterfaceRoot(optionsParent, mainWindowParent, fontFunction) holder_status._relativeBounds.right = 0 holder_status:UpdateClientArea() + status_volumePanel._relativeBounds.bottom = panelButtonsHeight + status_volumePanel:UpdateClientArea() status_userWindow._relativeBounds.bottom = panelButtonsHeight status_userWindow:UpdateClientArea() @@ -676,6 +690,8 @@ function GetInterfaceRoot(optionsParent, mainWindowParent, fontFunction) holder_status._relativeBounds.right = 0 holder_status:UpdateClientArea() + status_volumePanel._relativeBounds.bottom = 0 + status_volumePanel:UpdateClientArea() status_userWindow._relativeBounds.bottom = 0 status_userWindow:UpdateClientArea() diff --git a/LuaMenu/widgets/gui_settings_window.lua b/LuaMenu/widgets/gui_settings_window.lua index 332e0eb22..801e35a8f 100644 --- a/LuaMenu/widgets/gui_settings_window.lua +++ b/LuaMenu/widgets/gui_settings_window.lua @@ -18,6 +18,7 @@ end -------------------------------------------------------------------------------- -- Local Variables local spSetConfigInt = Spring.SetConfigInt +local spGetConfigInt = Spring.GetConfigInt local battleStartDisplay = 1 local lobbyFullscreen = 1 @@ -40,6 +41,9 @@ local TEXT_OFFSET = 6 local settingsWindowHandler +local trackbarLobbyMusicVolume +local trackbarMasterVolume + -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- Utilities @@ -799,8 +803,26 @@ local function GetLobbyTabControls() } offset = offset + ITEM_OFFSET - children[#children + 1] = AddLabel(offset, "Menu Music Volume") - children[#children + 1] = Trackbar:New { + trackbarMasterVolume = Trackbar:New { + x = COMBO_X, + y = offset, + width = COMBO_WIDTH, + height = 30, + value = spGetConfigInt("snd_volmaster", 50), + OnChange = { + function(obj, value) + if freezeSettings then + return + end + spSetConfigInt("snd_volmaster", value) + end + } + } + children[#children + 1] = AddLabel(offset, "Master Volume") + children[#children + 1] = trackbarMasterVolume + offset = offset + ITEM_OFFSET + + trackbarLobbyMusicVolume = Trackbar:New { x = COMBO_X, y = offset, width = COMBO_WIDTH, @@ -818,6 +840,8 @@ local function GetLobbyTabControls() end } } + children[#children + 1] = AddLabel(offset, "Menu Music Volume") + children[#children + 1] = trackbarLobbyMusicVolume offset = offset + ITEM_OFFSET children[#children + 1] = AddLabel(offset, "Notification Volume") @@ -1619,6 +1643,7 @@ local function MakeTab(name, children) } end +local initialized = false local function InitializeControls(window) window.OnParent = nil @@ -1672,6 +1697,7 @@ local function InitializeControls(window) tabPanel.tabBar:Select(tabName) end + initialized = true return externalFunctions end @@ -1846,6 +1872,22 @@ function widget:ActivateMenu() SetLobbyFullscreenMode(WG.Chobby.Configuration.lobby_fullscreen) end +local dLastSync = 0 +function widget:Update() + dLastSync = dLastSync + 1 + if dLastSync < 10 then -- Only run this stuff every 10 updates + return + end + dLastSync = 0 + + if not (initialized and WG.Chobby and WG.Chobby.Configuration) then + return + end + + trackbarMasterVolume.value = spGetConfigInt("snd_volmaster", trackbarMasterVolume.value) + trackbarLobbyMusicVolume.value = WG.Chobby.Configuration.menuMusicVolume +end + --local oldWidth, oldHeight, oldX, oldY --function widget:Update() -- if not ((currentMode == 2 or not currentMode) and lobbyFullscreen == 2) then diff --git a/LuaMenu/widgets/gui_volume_panel.lua b/LuaMenu/widgets/gui_volume_panel.lua new file mode 100644 index 000000000..8e6f5573e --- /dev/null +++ b/LuaMenu/widgets/gui_volume_panel.lua @@ -0,0 +1,198 @@ +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +function widget:GetInfo() + return { + name = "Chobby Volume Panel", + desc = "Ports the EpicMenu volume/clock panel to chobby", + author = "Birdulon", + date = "2020-10-07", + license = "GNU GPL, v2 or later", + layer = 0, +-- handler = true, + enabled = true, + } +end + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +local IMAGE_DIR = LUA_DIRNAME .. "images/" +local IMAGE_VOLUME = IMAGE_DIR .. "vol.png" +local IMAGE_VOL_MUSIC = IMAGE_DIR .. "vol_music.png" +local IMAGE_CLOCK = IMAGE_DIR .. "clock.png" + +local INVISIBLE_COLOR = {0, 0, 0, 0} +local TEXT_COLOR = {1, 1, 1, 1} + +local spGetConfigInt = Spring.GetConfigInt +local spSetConfigInt = Spring.SetConfigInt +local spEcho = Spring.Echo +local Configuration + +local VolumePanel = {} +local trackbarVolume +local trackbarMusic +local lblClock + + +local function InitializeControls(window) + local sliderWidth = 96 + + -------------------------------------------------------------------------------- + -- Make Widgets + local imageVolume = Image:New{tooltip = 'Volume', file = IMAGE_VOLUME, width = 16, height = 16} + local imageMusic = Image:New{tooltip = 'Music', file = IMAGE_VOL_MUSIC, width = 16, height = 16} + local imageClock = Image:New{file = IMAGE_CLOCK, width = 20, height = 26} + + lblClock = Label:New{name = 'lblClock', caption = 'Clock', width = 45, height = 26, textColor = TEXT_COLOR} + trackbarVolume = Trackbar:New{ + tooltip = 'Volume', + height = 16, + width = sliderWidth, + trackColor = TEXT_COLOR, + value = spGetConfigInt("snd_volmaster", 50), + OnChange = { + function(self) + spSetConfigInt("snd_volmaster", self.value) + end + }, + } + trackbarMusic = Trackbar:New{ + tooltip = 'Music', + height = 16, + width = sliderWidth, + min = 0, + max = 1, + step = 0.01, + trackColor = TEXT_COLOR, + value = WG.Chobby.Configuration.menuMusicVolume or 0.0, + OnChange = { + function(self) + WG.Chobby.Configuration:SetConfigValue("menuMusicVolume", self.value) + end + }, + } + + -------------------------------------------------------------------------------- + -- Make Sublayouts + local stackClock = StackPanel:New{ + orientation = 'horizontal', + width = 62, + height = '100%', + resizeItems = false, + autoArrangeV = false, + autoArrangeH = false, + padding = {0, 2, 0, 0}, + itemMargin = {1, 0, 0, 0}, + children = {imageClock, lblClock}, +-- parent = window, + } + local gridVolume = Grid:New{ + height = '100%', + width = sliderWidth + 25, + columns = 2, + rows = 2, + resizeItems = false, + margin = {0, 0, 0, 0}, + padding = {0, 0, 0, 0}, + itemPadding = {0, 0, 0, 0}, + itemMargin = {0, 0, 0, 0}, + children = {imageVolume, trackbarVolume, imageMusic, trackbarMusic}, +-- parent = window, + } + + -------------------------------------------------------------------------------- + -- Make Layout + local stackFull = StackPanel:New{ + orientation = 'horizontal', + width = '100%', + height = 32, + resizeItems = false, + autoArrangeV = false, + autoArrangeH = false, + padding = {0, 0, 0, 0}, + itemMargin = {0, 0, 0, 0}, + children = {gridVolume, stackClock}, + parent = window, + } +end + + +function VolumePanel.GetControl() + local window = Control:New { + x = 0, + y = 0, + right = 0, + bottom = 0, + padding = {0, 0, 0, 0}, + OnParent = { + function(obj) + if obj:IsEmpty() then + InitializeControls(obj) + end + end + }, + } + -- Other setup that we can only do once Chobby has loaded stuff + --Configuration = WG.Chobby.Configuration + --Configuration:AddListener("OnConfigurationChange", onConfigurationChange) + return window +end + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-- Widget Updates +local function updateTrackbarVolume(value) + if value then + trackbarVolume.value = value + trackbarVolume.tooltip = string.format("Volume (%d%%)", value) + end +end + +local function updateTrackbarMusic(value) + if value then + trackbarMusic.value = value + trackbarMusic.tooltip = string.format("Music (%d%%)", math.floor(value*100)) + end +end + +-- local function onConfigurationChange(listener, key, value) +-- if key == "menuMusicVolume" then +-- updateTrackbarMusic(value) +-- end +-- end + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-- Widget Interface +local dLastSync = 0 +function widget:Update() + dLastSync = dLastSync + 1 + if dLastSync < 10 then -- Only run this stuff every 10 updates + return + end + dLastSync = 0 + + if lblClock then + lblClock:SetCaption(os.date("%H:%M")) + end + + updateTrackbarVolume(spGetConfigInt("snd_volmaster")) + updateTrackbarMusic(WG.Chobby.Configuration.menuMusicVolume) +end + +function widget:Initialize() + -- Very limited initialization as many things aren't available until GetControl() + VFS.Include(LUA_DIRNAME .. "widgets/chobby/headers/exports.lua", nil, VFS.RAW_FIRST) + WG.VolumePanel = VolumePanel +end + +function widget:Shutdown() +-- if Configuration then +-- Configuration:RemoveListener("OnConfigurationChange", onConfigurationChange) +-- end +end + + +-------------------------------------------------------------------------------- +--------------------------------------------------------------------------------