Skip to content

Commit 2adfd96

Browse files
committed
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
1 parent cc4f85f commit 2adfd96

File tree

5 files changed

+258
-2
lines changed

5 files changed

+258
-2
lines changed

LuaMenu/images/vol.png

689 Bytes
Loading

LuaMenu/images/vol_music.png

648 Bytes
Loading

LuaMenu/widgets/chobby/components/interface_root.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,18 @@ function GetInterfaceRoot(optionsParent, mainWindowParent, fontFunction)
181181
children = {}
182182
}
183183

184+
local status_volumePanel = Panel:New {
185+
y = 5,
186+
height = 36,
187+
width = 205,
188+
right = userStatusWidth + 10,
189+
padding = {0, 0, 0, 0},
190+
parent = holder_status,
191+
children = {
192+
WG.VolumePanel.GetControl(),
193+
}
194+
}
195+
184196
local status_userWindow = Control:New {
185197
y = 0,
186198
right = 0,
@@ -619,6 +631,8 @@ function GetInterfaceRoot(optionsParent, mainWindowParent, fontFunction)
619631
holder_status._relativeBounds.right = 0
620632
holder_status:UpdateClientArea()
621633

634+
status_volumePanel._relativeBounds.bottom = panelButtonsHeight
635+
status_volumePanel:UpdateClientArea()
622636
status_userWindow._relativeBounds.bottom = panelButtonsHeight
623637
status_userWindow:UpdateClientArea()
624638

@@ -676,6 +690,8 @@ function GetInterfaceRoot(optionsParent, mainWindowParent, fontFunction)
676690
holder_status._relativeBounds.right = 0
677691
holder_status:UpdateClientArea()
678692

693+
status_volumePanel._relativeBounds.bottom = 0
694+
status_volumePanel:UpdateClientArea()
679695
status_userWindow._relativeBounds.bottom = 0
680696
status_userWindow:UpdateClientArea()
681697

LuaMenu/widgets/gui_settings_window.lua

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ end
1818
--------------------------------------------------------------------------------
1919
-- Local Variables
2020
local spSetConfigInt = Spring.SetConfigInt
21+
local spGetConfigInt = Spring.GetConfigInt
2122

2223
local battleStartDisplay = 1
2324
local lobbyFullscreen = 1
@@ -40,6 +41,9 @@ local TEXT_OFFSET = 6
4041

4142
local settingsWindowHandler
4243

44+
local trackbarLobbyMusicVolume
45+
local trackbarMasterVolume
46+
4347
--------------------------------------------------------------------------------
4448
--------------------------------------------------------------------------------
4549
-- Utilities
@@ -799,8 +803,26 @@ local function GetLobbyTabControls()
799803
}
800804
offset = offset + ITEM_OFFSET
801805

802-
children[#children + 1] = AddLabel(offset, "Menu Music Volume")
803-
children[#children + 1] = Trackbar:New {
806+
trackbarMasterVolume = Trackbar:New {
807+
x = COMBO_X,
808+
y = offset,
809+
width = COMBO_WIDTH,
810+
height = 30,
811+
value = spGetConfigInt("snd_volmaster", 50),
812+
OnChange = {
813+
function(obj, value)
814+
if freezeSettings then
815+
return
816+
end
817+
spSetConfigInt("snd_volmaster", value)
818+
end
819+
}
820+
}
821+
children[#children + 1] = AddLabel(offset, "Master Volume")
822+
children[#children + 1] = trackbarMasterVolume
823+
offset = offset + ITEM_OFFSET
824+
825+
trackbarLobbyMusicVolume = Trackbar:New {
804826
x = COMBO_X,
805827
y = offset,
806828
width = COMBO_WIDTH,
@@ -818,6 +840,8 @@ local function GetLobbyTabControls()
818840
end
819841
}
820842
}
843+
children[#children + 1] = AddLabel(offset, "Menu Music Volume")
844+
children[#children + 1] = trackbarLobbyMusicVolume
821845
offset = offset + ITEM_OFFSET
822846

823847
children[#children + 1] = AddLabel(offset, "Notification Volume")
@@ -1619,6 +1643,7 @@ local function MakeTab(name, children)
16191643
}
16201644
end
16211645

1646+
local initialized = false
16221647
local function InitializeControls(window)
16231648
window.OnParent = nil
16241649

@@ -1672,6 +1697,7 @@ local function InitializeControls(window)
16721697
tabPanel.tabBar:Select(tabName)
16731698
end
16741699

1700+
initialized = true
16751701
return externalFunctions
16761702
end
16771703

@@ -1846,6 +1872,22 @@ function widget:ActivateMenu()
18461872
SetLobbyFullscreenMode(WG.Chobby.Configuration.lobby_fullscreen)
18471873
end
18481874

1875+
local dLastSync = 0
1876+
function widget:Update()
1877+
dLastSync = dLastSync + 1
1878+
if dLastSync < 10 then -- Only run this stuff every 10 updates
1879+
return
1880+
end
1881+
dLastSync = 0
1882+
1883+
if not (initialized and WG.Chobby and WG.Chobby.Configuration) then
1884+
return
1885+
end
1886+
1887+
trackbarMasterVolume.value = spGetConfigInt("snd_volmaster", trackbarMasterVolume.value)
1888+
trackbarLobbyMusicVolume.value = WG.Chobby.Configuration.menuMusicVolume
1889+
end
1890+
18491891
--local oldWidth, oldHeight, oldX, oldY
18501892
--function widget:Update()
18511893
-- if not ((currentMode == 2 or not currentMode) and lobbyFullscreen == 2) then
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
--------------------------------------------------------------------------------
2+
--------------------------------------------------------------------------------
3+
4+
function widget:GetInfo()
5+
return {
6+
name = "Chobby Volume Panel",
7+
desc = "Ports the EpicMenu volume/clock panel to chobby",
8+
author = "Birdulon",
9+
date = "2020-10-07",
10+
license = "GNU GPL, v2 or later",
11+
layer = 0,
12+
-- handler = true,
13+
enabled = true,
14+
}
15+
end
16+
17+
--------------------------------------------------------------------------------
18+
--------------------------------------------------------------------------------
19+
local IMAGE_DIR = LUA_DIRNAME .. "images/"
20+
local IMAGE_VOLUME = IMAGE_DIR .. "vol.png"
21+
local IMAGE_VOL_MUSIC = IMAGE_DIR .. "vol_music.png"
22+
local IMAGE_CLOCK = IMAGE_DIR .. "clock.png"
23+
24+
local INVISIBLE_COLOR = {0, 0, 0, 0}
25+
local TEXT_COLOR = {1, 1, 1, 1}
26+
27+
local spGetConfigInt = Spring.GetConfigInt
28+
local spSetConfigInt = Spring.SetConfigInt
29+
local spEcho = Spring.Echo
30+
local Configuration
31+
32+
local VolumePanel = {}
33+
local trackbarVolume
34+
local trackbarMusic
35+
local lblClock
36+
37+
38+
local function InitializeControls(window)
39+
local sliderWidth = 96
40+
41+
--------------------------------------------------------------------------------
42+
-- Make Widgets
43+
local imageVolume = Image:New{tooltip = 'Volume', file = IMAGE_VOLUME, width = 16, height = 16}
44+
local imageMusic = Image:New{tooltip = 'Music', file = IMAGE_VOL_MUSIC, width = 16, height = 16}
45+
local imageClock = Image:New{file = IMAGE_CLOCK, width = 20, height = 26}
46+
47+
lblClock = Label:New{name = 'lblClock', caption = 'Clock', width = 45, height = 26, textColor = TEXT_COLOR}
48+
trackbarVolume = Trackbar:New{
49+
tooltip = 'Volume',
50+
height = 16,
51+
width = sliderWidth,
52+
trackColor = TEXT_COLOR,
53+
value = spGetConfigInt("snd_volmaster", 50),
54+
OnChange = {
55+
function(self)
56+
spSetConfigInt("snd_volmaster", self.value)
57+
end
58+
},
59+
}
60+
trackbarMusic = Trackbar:New{
61+
tooltip = 'Music',
62+
height = 16,
63+
width = sliderWidth,
64+
min = 0,
65+
max = 1,
66+
step = 0.01,
67+
trackColor = TEXT_COLOR,
68+
value = WG.Chobby.Configuration.menuMusicVolume or 0.0,
69+
OnChange = {
70+
function(self)
71+
WG.Chobby.Configuration:SetConfigValue("menuMusicVolume", self.value)
72+
end
73+
},
74+
}
75+
76+
--------------------------------------------------------------------------------
77+
-- Make Sublayouts
78+
local stackClock = StackPanel:New{
79+
orientation = 'horizontal',
80+
width = 62,
81+
height = '100%',
82+
resizeItems = false,
83+
autoArrangeV = false,
84+
autoArrangeH = false,
85+
padding = {0, 2, 0, 0},
86+
itemMargin = {1, 0, 0, 0},
87+
children = {imageClock, lblClock},
88+
-- parent = window,
89+
}
90+
local gridVolume = Grid:New{
91+
height = '100%',
92+
width = sliderWidth + 25,
93+
columns = 2,
94+
rows = 2,
95+
resizeItems = false,
96+
margin = {0, 0, 0, 0},
97+
padding = {0, 0, 0, 0},
98+
itemPadding = {0, 0, 0, 0},
99+
itemMargin = {0, 0, 0, 0},
100+
children = {imageVolume, trackbarVolume, imageMusic, trackbarMusic},
101+
-- parent = window,
102+
}
103+
104+
--------------------------------------------------------------------------------
105+
-- Make Layout
106+
local stackFull = StackPanel:New{
107+
orientation = 'horizontal',
108+
width = '100%',
109+
height = 32,
110+
resizeItems = false,
111+
autoArrangeV = false,
112+
autoArrangeH = false,
113+
padding = {0, 0, 0, 0},
114+
itemMargin = {0, 0, 0, 0},
115+
children = {gridVolume, stackClock},
116+
parent = window,
117+
}
118+
end
119+
120+
121+
function VolumePanel.GetControl()
122+
local window = Control:New {
123+
x = 0,
124+
y = 0,
125+
right = 0,
126+
bottom = 0,
127+
padding = {0, 0, 0, 0},
128+
OnParent = {
129+
function(obj)
130+
if obj:IsEmpty() then
131+
InitializeControls(obj)
132+
end
133+
end
134+
},
135+
}
136+
-- Other setup that we can only do once Chobby has loaded stuff
137+
--Configuration = WG.Chobby.Configuration
138+
--Configuration:AddListener("OnConfigurationChange", onConfigurationChange)
139+
return window
140+
end
141+
142+
--------------------------------------------------------------------------------
143+
--------------------------------------------------------------------------------
144+
-- Widget Updates
145+
local function updateTrackbarVolume(value)
146+
if value then
147+
trackbarVolume.value = value
148+
trackbarVolume.tooltip = string.format("Volume (%d%%)", value)
149+
end
150+
end
151+
152+
local function updateTrackbarMusic(value)
153+
if value then
154+
trackbarMusic.value = value
155+
trackbarMusic.tooltip = string.format("Music (%d%%)", math.floor(value*100))
156+
end
157+
end
158+
159+
-- local function onConfigurationChange(listener, key, value)
160+
-- if key == "menuMusicVolume" then
161+
-- updateTrackbarMusic(value)
162+
-- end
163+
-- end
164+
165+
--------------------------------------------------------------------------------
166+
--------------------------------------------------------------------------------
167+
-- Widget Interface
168+
local dLastSync = 0
169+
function widget:Update()
170+
dLastSync = dLastSync + 1
171+
if dLastSync < 10 then -- Only run this stuff every 10 updates
172+
return
173+
end
174+
dLastSync = 0
175+
176+
if lblClock then
177+
lblClock:SetCaption(os.date("%H:%M"))
178+
end
179+
180+
updateTrackbarVolume(spGetConfigInt("snd_volmaster"))
181+
updateTrackbarMusic(WG.Chobby.Configuration.menuMusicVolume)
182+
end
183+
184+
function widget:Initialize()
185+
-- Very limited initialization as many things aren't available until GetControl()
186+
VFS.Include(LUA_DIRNAME .. "widgets/chobby/headers/exports.lua", nil, VFS.RAW_FIRST)
187+
WG.VolumePanel = VolumePanel
188+
end
189+
190+
function widget:Shutdown()
191+
-- if Configuration then
192+
-- Configuration:RemoveListener("OnConfigurationChange", onConfigurationChange)
193+
-- end
194+
end
195+
196+
197+
--------------------------------------------------------------------------------
198+
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)