- added music/sfc subsystem\n- added basic audio\n- added music/sound test screen\n- added some basic vscode tasks
This commit is contained in:
85
inc/window/window.audiotest.lua
Normal file
85
inc/window/window.audiotest.lua
Normal file
@@ -0,0 +1,85 @@
|
||||
AudioTestWindow = {
|
||||
index_menu = 1,
|
||||
index_func = 1,
|
||||
list_func = {},
|
||||
menuitems = {},
|
||||
last_pressed = false
|
||||
}
|
||||
|
||||
function AudioTestWindow.generate_menuitems(list_func, index_func)
|
||||
return {
|
||||
{
|
||||
label = "Play music/sound: " .. (list_func[index_func] or "?"),
|
||||
action = function()
|
||||
local current_func = Audio[list_func[index_func]]
|
||||
if current_func then
|
||||
current_func()
|
||||
else
|
||||
trace("Invalid Audio function: " .. list_func[index_menu])
|
||||
end
|
||||
end
|
||||
},
|
||||
{
|
||||
label = "Stop playing music",
|
||||
action = function()
|
||||
Audio.music_stop()
|
||||
end
|
||||
},
|
||||
{
|
||||
label = "Back",
|
||||
action = function()
|
||||
AudioTestWindow.back()
|
||||
end
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
function AudioTestWindow.generate_listfunc()
|
||||
local result = {}
|
||||
|
||||
for k, v in pairs(Audio) do
|
||||
if type(v) == "function" then
|
||||
result[#result + 1] = k
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(result)
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
function AudioTestWindow.back()
|
||||
Audio.sfx_deselect()
|
||||
GameWindow.set_state(WINDOW_MENU)
|
||||
end
|
||||
|
||||
function AudioTestWindow.init()
|
||||
AudioTestWindow.last_pressed = false
|
||||
AudioTestWindow.index_menu = 1
|
||||
AudioTestWindow.index_func = 1
|
||||
AudioTestWindow.list_func = AudioTestWindow.generate_listfunc()
|
||||
AudioTestWindow.menuitems = AudioTestWindow.generate_menuitems(AudioTestWindow.list_func, AudioTestWindow.index_func)
|
||||
end
|
||||
|
||||
function AudioTestWindow.draw()
|
||||
UI.draw_top_bar("Audio test")
|
||||
UI.draw_menu(AudioTestWindow.menuitems, AudioTestWindow.index_menu, 20, 50)
|
||||
end
|
||||
|
||||
function AudioTestWindow.update()
|
||||
if Input.up() then
|
||||
AudioTestWindow.index_menu = Util.safeindex(AudioTestWindow.menuitems, AudioTestWindow.index_menu - 1)
|
||||
elseif Input.down() then
|
||||
AudioTestWindow.index_menu = Util.safeindex(AudioTestWindow.menuitems, AudioTestWindow.index_menu + 1)
|
||||
elseif Input.left() then
|
||||
AudioTestWindow.index_func = Util.safeindex(AudioTestWindow.list_func, AudioTestWindow.index_func - 1)
|
||||
AudioTestWindow.menuitems = AudioTestWindow.generate_menuitems(AudioTestWindow.list_func, AudioTestWindow.index_func)
|
||||
elseif Input.right() then
|
||||
AudioTestWindow.index_func = Util.safeindex(AudioTestWindow.list_func, AudioTestWindow.index_func + 1)
|
||||
AudioTestWindow.menuitems = AudioTestWindow.generate_menuitems(AudioTestWindow.list_func, AudioTestWindow.index_func)
|
||||
elseif Input.menu_confirm() then
|
||||
AudioTestWindow.menuitems[AudioTestWindow.index_menu].action()
|
||||
elseif Input.menu_back() then
|
||||
AudioTestWindow.back()
|
||||
end
|
||||
end
|
||||
@@ -9,6 +9,7 @@ function MenuWindow.update()
|
||||
if Input.menu_confirm() then
|
||||
local selected_item = Context.menu_items[Context.selected_menu_item]
|
||||
if selected_item and selected_item.action then
|
||||
Audio.sfx_select()
|
||||
selected_item.action()
|
||||
end
|
||||
end
|
||||
@@ -41,6 +42,11 @@ function MenuWindow.configuration()
|
||||
GameWindow.set_state(WINDOW_CONFIGURATION)
|
||||
end
|
||||
|
||||
function MenuWindow.audio_test()
|
||||
AudioTestWindow.init()
|
||||
GameWindow.set_state(WINDOW_AUDIOTEST)
|
||||
end
|
||||
|
||||
function MenuWindow.refresh_menu_items()
|
||||
Context.menu_items = {} -- Start with an empty table
|
||||
|
||||
@@ -52,9 +58,8 @@ function MenuWindow.refresh_menu_items()
|
||||
table.insert(Context.menu_items, {label = "New Game", action = MenuWindow.new_game})
|
||||
table.insert(Context.menu_items, {label = "Load Game", action = MenuWindow.load_game})
|
||||
table.insert(Context.menu_items, {label = "Configuration", action = MenuWindow.configuration})
|
||||
table.insert(Context.menu_items, {label = "Audio Test", action = MenuWindow.audio_test})
|
||||
table.insert(Context.menu_items, {label = "Exit", action = MenuWindow.exit})
|
||||
|
||||
|
||||
Context.selected_menu_item = 1 -- Reset selection after refreshing
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user