diff --git a/LuaMenu/images/vol.png b/LuaMenu/images/vol.png new file mode 100644 index 000000000..b0624332f Binary files /dev/null and b/LuaMenu/images/vol.png differ diff --git a/LuaMenu/images/vol_music.png b/LuaMenu/images/vol_music.png new file mode 100644 index 000000000..ed8da6f8f Binary files /dev/null and b/LuaMenu/images/vol_music.png differ 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 dd428594a..801e35a8f 100644 --- a/LuaMenu/widgets/gui_settings_window.lua +++ b/LuaMenu/widgets/gui_settings_window.lua @@ -17,6 +17,8 @@ end -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- Local Variables +local spSetConfigInt = Spring.SetConfigInt +local spGetConfigInt = Spring.GetConfigInt local battleStartDisplay = 1 local lobbyFullscreen = 1 @@ -39,6 +41,9 @@ local TEXT_OFFSET = 6 local settingsWindowHandler +local trackbarLobbyMusicVolume +local trackbarMasterVolume + -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- Utilities @@ -87,7 +92,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 +235,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 +260,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 +289,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 +306,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 +318,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 @@ -692,6 +697,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 +738,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 +759,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 +782,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,17 +803,26 @@ 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", + 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] = Trackbar:New { + 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, @@ -838,18 +840,11 @@ local function GetLobbyTabControls() end } } + children[#children + 1] = AddLabel(offset, "Menu Music Volume") + children[#children + 1] = trackbarLobbyMusicVolume 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 +865,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 +886,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 +907,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 +958,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 +970,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 +992,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 +1068,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 +1085,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 +1108,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 +1249,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 +1596,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 @@ -1718,6 +1643,7 @@ local function MakeTab(name, children) } end +local initialized = false local function InitializeControls(window) window.OnParent = nil @@ -1771,6 +1697,7 @@ local function InitializeControls(window) tabPanel.tabBar:Select(tabName) end + initialized = true return externalFunctions end @@ -1856,7 +1783,7 @@ function SettingsWindow.WriteGameSpringsettings(fileName) WriteToFile("WindowBorderless", 0) WriteToFile("Fullscreen", 1) end - + settingsFile:close() end @@ -1929,6 +1856,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 @@ -1938,13 +1868,26 @@ 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 +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 @@ -1981,7 +1924,7 @@ function widget:Initialize() -- Settings which rely on io local gameSettings = Configuration.game_settings - + if lobbyFullscreen ~= battleStartDisplay or battleStartDisplay >= 4 then SetLobbyFullscreenMode(battleStartDisplay) 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 + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- 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