Skip to content

Commit 463d616

Browse files
committed
Added volume sliders and a clock. Layout probably needs work.
1 parent 6ccc99a commit 463d616

4 files changed

Lines changed: 255 additions & 0 deletions

File tree

LuaMenu/images/vol.png

689 Bytes
Loading

LuaMenu/images/vol_music.png

648 Bytes
Loading

LuaMenu/widgets/chobby/components/interface_root.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,19 @@ function GetInterfaceRoot(optionsParent, mainWindowParent, fontFunction)
178178
children = {}
179179
}
180180

181+
local status_volumePanel = Control:New {
182+
--y = 0,
183+
height = 32,
184+
width = 180,
185+
right = 225, --?????
186+
top = panelButtonsHeight,
187+
padding = {0, 0, 0, 0},
188+
parent = holder_status,
189+
children = {
190+
WG.VolumePanel.GetControl(),
191+
}
192+
}
193+
181194
local status_userWindow = Control:New {
182195
y = 0,
183196
right = 0,
@@ -614,6 +627,8 @@ function GetInterfaceRoot(optionsParent, mainWindowParent, fontFunction)
614627
holder_status._relativeBounds.right = 0
615628
holder_status:UpdateClientArea()
616629

630+
status_volumePanel._relativeBounds.bottom = panelButtonsHeight
631+
status_volumePanel:UpdateClientArea()
617632
status_userWindow._relativeBounds.bottom = panelButtonsHeight
618633
status_userWindow:UpdateClientArea()
619634

@@ -667,6 +682,8 @@ function GetInterfaceRoot(optionsParent, mainWindowParent, fontFunction)
667682
holder_status._relativeBounds.right = 0
668683
holder_status:UpdateClientArea()
669684

685+
status_volumePanel._relativeBounds.bottom = 0
686+
status_volumePanel:UpdateClientArea()
670687
status_userWindow._relativeBounds.bottom = 0
671688
status_userWindow:UpdateClientArea()
672689

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
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, --12,
51+
width = sliderWidth - 25,
52+
trackColor = TEXT_COLOR,
53+
value = spGetConfigInt("snd_volmaster", 50),
54+
OnChange = {
55+
function(self)
56+
spSetConfigInt("snd_volmaster", self.value)
57+
-- spSendCommands{"set snd_volmaster " .. self.value}
58+
end
59+
},
60+
}
61+
trackbarMusic = Trackbar:New{
62+
tooltip = 'Music',
63+
height = 16, --12,
64+
width = sliderWidth - 25,
65+
min = 0,
66+
max = 1,
67+
step = 0.01,
68+
trackColor = TEXT_COLOR,
69+
value = WG.Chobby.Configuration.menuMusicVolume or 0.0,
70+
OnChange = {
71+
function(self)
72+
WG.Chobby.Configuration:SetConfigValue("menuMusicVolume", self.value)
73+
end
74+
},
75+
}
76+
77+
--------------------------------------------------------------------------------
78+
-- Make Sublayouts
79+
local stackClock = StackPanel:New{
80+
orientation = 'horizontal',
81+
width = 62,
82+
height = '100%',
83+
resizeItems = false,
84+
autoArrangeV = false,
85+
autoArrangeH = false,
86+
padding = {0, 2, 0, 0},
87+
itemMargin = {1, 0, 0, 0},
88+
children = {imageClock, lblClock},
89+
-- parent = window,
90+
}
91+
local gridVolume = Grid:New{
92+
height = 32, --24,
93+
width = sliderWidth, -- - 25,
94+
columns = 2,
95+
rows = 2,
96+
resizeItems = false,
97+
margin = {0, 0, 0, 0},
98+
padding = {0, 0, 0, 0}, --{0, -2, 0, 0},
99+
itemPadding = {0, 0, 0, 0},
100+
itemMargin = {0, 0, 0, 0},
101+
children = {imageVolume, trackbarVolume, imageMusic, trackbarMusic},
102+
-- parent = window,
103+
}
104+
105+
--------------------------------------------------------------------------------
106+
-- Make Layout
107+
local stackFull = StackPanel:New{
108+
orientation = 'horizontal',
109+
width = '100%',
110+
height = 32,
111+
resizeItems = false,
112+
autoArrangeV = false,
113+
autoArrangeH = false,
114+
padding = {0, 2, 0, 0},
115+
itemMargin = {1, 0, 0, 0},
116+
children = {stackClock, gridVolume},
117+
parent = window,
118+
}
119+
-- local stackChildren = {}
120+
-- local holderWidth = 6
121+
-- if width > 435 then
122+
-- stackChildren[#stackChildren + 1] = stackClock
123+
-- holderWidth = holderWidth + 64
124+
-- end
125+
---- stackChildren[#stackChildren + 1] = imageVolume
126+
-- stackChildren[#stackChildren + 1] = gridVolume
127+
-- holderWidth = holderWidth + sliderWidth + 2
128+
--
129+
-- local mainPanel = Panel:New{
130+
-- y = 0,
131+
-- right = 0,
132+
-- bottom = 0,
133+
---- clientWidth = holderWidth,
134+
-- backgroundColor = INVISIBLE_COLOR,
135+
-- color = INVISIBLE_COLOR,
136+
-- margin = {0, 0, 0, 0},
137+
-- padding = {0, 0, 3, 6},
138+
-- parent = window,
139+
--
140+
-- children = {
141+
-- StackPanel:New{
142+
-- name = 'stack_main',
143+
-- orientation = 'horizontal',
144+
-- width = '100%',
145+
-- height = '100%',
146+
-- resizeItems = false,
147+
-- padding = {0, 0, 0, 0},
148+
-- itemPadding = {1, 1, 1, 1},
149+
-- itemMargin = {1, 1, 1, 1},
150+
-- autoArrangeV = false,
151+
-- autoArrangeH = false,
152+
--
153+
-- children = stackChildren,
154+
---- children = {stackClock, gridVolume},
155+
-- }
156+
-- }
157+
-- }
158+
end
159+
160+
161+
function VolumePanel.GetControl()
162+
local window = Control:New {
163+
x = 0,
164+
y = 0,
165+
right = 0,
166+
bottom = 0,
167+
padding = {0, 0, 0, 0},
168+
OnParent = {
169+
function(obj)
170+
if obj:IsEmpty() then
171+
InitializeControls(obj)
172+
end
173+
end
174+
},
175+
}
176+
-- Other setup that we can only do once Chobby has loaded stuff
177+
--Configuration = WG.Chobby.Configuration
178+
--Configuration:AddListener("OnConfigurationChange", onConfigurationChange)
179+
return window
180+
end
181+
182+
--------------------------------------------------------------------------------
183+
--------------------------------------------------------------------------------
184+
-- Widget Updates
185+
local function updateTrackbarVolume(value)
186+
if value then
187+
trackbarVolume.value = value
188+
trackbarVolume.tooltip = string.format("Volume (%d%%)", value)
189+
end
190+
end
191+
192+
local function updateTrackbarMusic(value)
193+
if value then
194+
trackbarMusic.value = value
195+
trackbarMusic.tooltip = string.format("Music (%d%%)", math.floor(value*100))
196+
end
197+
end
198+
199+
-- local function onConfigurationChange(listener, key, value)
200+
-- if key == "menuMusicVolume" then
201+
-- updateTrackbarMusic(value)
202+
-- end
203+
-- end
204+
205+
--------------------------------------------------------------------------------
206+
--------------------------------------------------------------------------------
207+
-- Widget Interface
208+
local dLastSync = 0
209+
function widget:Update()
210+
dLastSync = dLastSync + 1
211+
if dLastSync < 10 then -- Only run this stuff every 10 updates
212+
return
213+
end
214+
dLastSync = 0
215+
216+
if lblClock then
217+
lblClock:SetCaption(os.date("%H:%M"))
218+
end
219+
220+
updateTrackbarVolume(spGetConfigInt("snd_volmaster"))
221+
updateTrackbarMusic(WG.Chobby.Configuration.menuMusicVolume)
222+
end
223+
224+
function widget:Initialize()
225+
-- Very limited initialization as many things aren't available until GetControl()
226+
VFS.Include(LUA_DIRNAME .. "widgets/chobby/headers/exports.lua", nil, VFS.RAW_FIRST)
227+
WG.VolumePanel = VolumePanel
228+
end
229+
230+
function widget:Shutdown()
231+
-- if Configuration then
232+
-- Configuration:RemoveListener("OnConfigurationChange", onConfigurationChange)
233+
-- end
234+
end
235+
236+
237+
--------------------------------------------------------------------------------
238+
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)