local PM_MENU_AUDIO_OPTIONS = 4
-- These IDs correspond to values in the Pause_menu_audio_options enum in code.
local OVERALL_ID = 1
local SOUND_EFFECTS_ID = 2
local MUSIC_ID = 3
local VOICE_ID = 4
local RADIO_CONTROLS_ID = 5
local SUBTITLES_ID = 6
local VOICE_CHAT_ENABLED_ID = 7
local OVERALL_INDEX = -1
local SOUND_EFFECTS_INDEX = 1
local MUSIC_INDEX = 2
local VOICE_INDEX = 3
local RADIO_CONTROLS_INDEX = 4
local SUBTITLES_INDEX = 5
local VOICE_CHAT_ENABLED_INDEX = -1
local SETUP_MIC_INDEX = -1
local Music_inst = -1
local Screen_width = 700
local Data = {}
function pause_options_audio_get_list_data()
if game_get_platform() == "PC" then
OVERALL_INDEX = 1
SOUND_EFFECTS_INDEX = 2
MUSIC_INDEX = 3
VOICE_INDEX = 4
RADIO_CONTROLS_INDEX = -1
SUBTITLES_INDEX = -1
VOICE_CHAT_ENABLED_INDEX = 5
SETUP_MIC_INDEX = 6
end
Data = {
[SOUND_EFFECTS_INDEX] = {
type = TYPE_SLIDER,
label = "MENU_AUDIO_SFX",
min = 0,
max = 100,
step = 10,
current_value = 100,
id = SOUND_EFFECTS_ID
},
[MUSIC_INDEX] = {
type = TYPE_SLIDER,
label = "MENU_AUDIO_MUSIC",
min = 0,
max = 100,
step = 10,
current_value = 100,
id = MUSIC_ID,
},
[VOICE_INDEX] = {
type = TYPE_SLIDER,
label = "MENU_AUDIO_VOICE",
min = 0,
max = 100,
step = 10,
current_value = 100,
id = VOICE_ID
},
[RADIO_CONTROLS_INDEX] = {
type = TYPE_TOGGLE,
label = "MENU_AUDIO_RADIO",
options = {"RADIO_ALWAYS_ON", "RADIO_HIJACK_ON", "RADIO_LIFE_LIKE" },
current_value = 1,
id = RADIO_CONTROLS_ID
},
[SUBTITLES_INDEX] = {
type = TYPE_TOGGLE,
label = "MENU_CONTROLS_SUBTITLES",
options = {"OPTION_NO", "OPTION_YES"},
current_value = 1,
id = SUBTITLES_ID
},
}
if game_get_platform() == "PC" then
Data[OVERALL_INDEX] = {
type = TYPE_SLIDER,
label = "MENU_AUDIO_OVERALL",
min = 0,
max = 100,
step = 10,
current_value = 100,
id = OVERALL_ID
}
Data[VOICE_CHAT_ENABLED_INDEX] = {
type = TYPE_TOGGLE,
label = "PLT_MENU_AUDIO_VOICE_ENABLE",
options = {"PLT_MENU_VOICE_DISABLED", "PLT_MENU_VOICE_ALWAYS_ON", "PLT_MENU_VOICE_PUSH_TO_TALK"},
current_value = 2,
id = VOICE_CHAT_ENABLED_ID
}
Data[SETUP_MIC_INDEX] = {
type = TYPE_BUTTON,
label = "PLT_MENU_SETUP_MIC",
}
end
end
local Anims = {}
local Input_tracker
local Mouse_input_tracker
local Tween_done = true
function pause_options_audio_init()
pause_options_audio_get_list_data()
-- Subscribe to the button presses we need
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("select", "options_audio_button_a", 50)
Input_tracker:add_input("back", "options_audio_button_b", 50)
Input_tracker:add_input("alt_select", "options_audio_button_x", 50)
if In_pause_menu then
Input_tracker:add_input("pause", "options_audio_button_start", 50)
end
Input_tracker:add_input("nav_up", "options_audio_nav_up", 50)
Input_tracker:add_input("nav_down", "options_audio_nav_down", 50)
Input_tracker:add_input("nav_left", "options_audio_nav_left", 50)
Input_tracker:add_input("nav_right", "options_audio_nav_right", 50)
Input_tracker:subscribe(false)
--Set Button hints
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_X, "MENU_RESTORE_DEFAULTS"},
}
Menu_hint_bar:set_hints(hint_data)
Header_obj:set_text("MENU_OPTIONS_AUDIO", Screen_width)
--Get the selection option from when the menu was last loaded
local last_option_selected = menu_common_stack_get_index()
vint_dataresponder_request("pause_menu_options", "options_audio_populate", 0, PM_MENU_AUDIO_OPTIONS)
List:draw_items(Data, last_option_selected, Screen_width)
--Store some locals to the pause menu common for screen processing.
menu_common_set_list_style(List, Header_obj, Screen_width)
menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim)
ui_audio_post_event("Main_Menu_Music_Mute")
-- Add mouse inputs for the PC
if game_get_platform() == "PC" then
Menu_hint_bar:set_highlight(0)
Mouse_input_tracker = Vdo_input_tracker:new()
List:add_mouse_inputs("options_audio", Mouse_input_tracker)
Menu_hint_bar:add_mouse_inputs("options_audio", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
--menu_common_set_mouse_tracker(Mouse_input_tracker)
end
end
function pause_options_audio_cleanup()
if Music_inst ~= -1 then
game_audio_stop(Music_inst)
Music_inst = -1
end
ui_audio_post_event("Main_Menu_Music_Unmute")
-- Nuke all button subscriptions
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
List:enable_toggle_input(false)
end
function options_audio_populate(overall, sfx, music, voice, radio_state, subtitles, voice_chat_state)
if OVERALL_INDEX ~= -1 then
Data[OVERALL_INDEX].current_value = floor(overall * 100)
Data[OVERALL_INDEX].previous_value = Data[OVERALL_INDEX].current_value
end
Data[SOUND_EFFECTS_INDEX].current_value = floor(sfx * 100)
Data[SOUND_EFFECTS_INDEX].previous_value = Data[SOUND_EFFECTS_INDEX].current_value
Data[MUSIC_INDEX].current_value = floor(music * 100)
Data[MUSIC_INDEX].previous_value = Data[MUSIC_INDEX].current_value
-- SEH: music is not allowed while recording
if game_record_mode_is_active() then
Data[MUSIC_INDEX].disabled = true
end
Data[VOICE_INDEX].current_value = floor(voice * 100)
Data[VOICE_INDEX].previous_value = Data[VOICE_INDEX].current_value
if RADIO_CONTROLS_INDEX ~= -1 then
Data[RADIO_CONTROLS_INDEX].current_value = radio_state + 1
Data[RADIO_CONTROLS_INDEX].previous_value = Data[RADIO_CONTROLS_INDEX].current_value
end
if SUBTITLES_INDEX ~= -1 then
Data[SUBTITLES_INDEX].current_value = subtitles and 2 or 1
Data[SUBTITLES_INDEX].previous_value = Data[SUBTITLES_INDEX].current_value
end
if VOICE_CHAT_ENABLED_INDEX ~= -1 then
Data[VOICE_CHAT_ENABLED_INDEX].current_value = voice_chat_state + 1
Data[VOICE_CHAT_ENABLED_INDEX].previous_value = Data[VOICE_CHAT_ENABLED_INDEX].current_value
end
end
function options_audio_nav_up(event, acceleration)
-- Move highlight up
List:move_cursor(-1)
if List:get_selection() == MUSIC_INDEX then
if Music_inst == -1 then
Music_inst = game_UI_audio_play("UI_Volume_Music")
end
elseif Music_inst ~= -1 then
game_audio_stop(Music_inst)
Music_inst = -1
end
end
function options_audio_nav_down(event, acceleration)
-- Move highlight down
List:move_cursor(1)
if List:get_selection() == MUSIC_INDEX then
if Music_inst == -1 then
Music_inst = game_UI_audio_play("UI_Volume_Music")
end
elseif Music_inst ~= -1 then
game_audio_stop(Music_inst)
Music_inst = -1
end
end
function options_audio_nav_left(event, acceleration)
-- Move highlight left
List:move_slider(-1,nil,true)
options_audio_update_option_value()
end
function options_audio_nav_right(event, acceleration)
-- Move highlight right
List:move_slider(1,nil,true)
options_audio_update_option_value()
end
function options_audio_update_option_value()
local current_idx = List:get_selection()
local menu_item = Data[current_idx]
local bool_val = true
if menu_item.current_value == 1 then
bool_val = false
end
-- Keep us from updating the value more often than is needed. (Useful for PC).
if menu_item.current_value == menu_item.previous_value then
return
end
menu_item.previous_value = menu_item.current_value
-- Convert the value to [0.0 - 1.0]
local converted_float = menu_item.current_value
if converted_float ~= 0 then
converted_float = menu_item.current_value / 100
end
if menu_item.type == TYPE_TOGGLE then
converted_float = menu_item.current_value - 1 -- 0-based in the radio system
end
pause_menu_update_option(PM_MENU_AUDIO_OPTIONS, menu_item.id, bool_val, converted_float)
if current_idx == SOUND_EFFECTS_INDEX or current_idx == OVERALL_INDEX then
game_UI_audio_play("UI_Volume_SFX")
elseif current_idx == VOICE_INDEX then
game_UI_audio_play("UI_Volume_Voice")
elseif current_idx == RADIO_CONTROLS_INDEX then
end
end
function options_audio_button_a(event, acceleration)
local current_idx = List:get_selection()
if current_idx == SETUP_MIC_INDEX then
game_steam_open_overlay("voicesettings")
else
options_audio_nav_right()
if Tween_done == true then
--set the screen data to the list data
Data = List:return_data()
end
end
end
function options_audio_button_b(event, acceleration)
if Tween_done == true then
List:button_b()
-- Accept the options
pause_menu_accept_options()
--Remove current menu from the stack
menu_common_stack_remove()
--Pop Screen off the list
menu_common_transition_pop(1)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
end
end
function options_audio_button_x(event, acceleration)
dialog_box_confirmation("OPTIONS_MENU_DEFAULTS_TITLE", "OPTIONS_MENU_DEFAULTS_DESC", "options_audio_revert", true, true,1)
end
function options_audio_revert(result, action)
if result == 0 then
pause_menu_restore_defaults(PM_MENU_AUDIO_OPTIONS)
vint_dataresponder_request("pause_menu_options", "options_audio_populate", 0, PM_MENU_AUDIO_OPTIONS)
List:draw_items(Data, List:get_selection(), 700)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("options_audio", Mouse_input_tracker)
Menu_hint_bar:add_mouse_inputs("options_audio", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
end
function options_audio_button_start(event, acceleration)
menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim)
Input_tracker:subscribe(false)
menu_common_transition_pop(4) -- options_audio, options, pause menu top, pause_menu common
bg_saints_slide_out()
end
-- Mouse inputs
function options_audio_mouse_click(event, target_handle, mouse_x, mouse_y)
local hint_index = Menu_hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
options_audio_button_b()
elseif hint_index == 2 then
options_audio_button_x()
end
local new_index = List:get_button_index(target_handle)
if new_index ~= 0 then
List:set_selection(new_index)
options_audio_button_a()
end
if List:is_left_arrow(target_handle) then
List:move_slider(-1)
options_audio_update_option_value()
elseif List:is_right_arrow(target_handle) then
List:move_slider(1)
options_audio_update_option_value()
end
if List:is_slider(target_handle) then
List:move_slider(0, mouse_x)
options_audio_update_option_value()
end
end
function options_audio_mouse_move(event, target_handle)
Menu_hint_bar:set_highlight(0)
local hint_index = Menu_hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
Menu_hint_bar:set_highlight(hint_index)
end
local new_index = List:get_button_index(target_handle)
if new_index ~= 0 then
List:set_selection(new_index)
List:move_cursor(0, true)
end
end
function options_audio_mouse_drag(event, target_handle, mouse_x, mouse_y)
if List:is_slider(target_handle) then
List:move_slider(0, mouse_x)
options_audio_update_option_value()
end
end
function options_audio_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
end