local PM_MENU_CONTROL_OPTIONS = 1
local CONTROL_SCHEME_BUTTON_ID = -1
local Data = { }
local Anims = {}
local Input_tracker
local Mouse_input_tracker
local Max_list_items = 11
local Screen_width = 840
local Tween_done = true
function pause_options_controls_init()
-- Subscribe to the button presses we need
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("select", "options_controls_button_a", 50)
Input_tracker:add_input("back", "options_controls_button_b", 50)
if In_pause_menu then
Input_tracker:add_input("pause", "options_controls_button_start", 50)
end
Input_tracker:add_input("alt_select", "options_controls_button_x", 50)
Input_tracker:add_input("nav_up", "options_controls_nav_up", 50)
Input_tracker:add_input("nav_down", "options_controls_nav_down", 50)
Input_tracker:add_input("nav_left", "options_controls_nav_left", 50)
Input_tracker:add_input("nav_right", "options_controls_nav_right", 50)
Input_tracker:subscribe(false)
if vint_is_std_res() then
Screen_width = 750
else
Screen_width = 840
end
--Initialize Header
if game_get_platform() == "PC" then
Header_obj:set_text("MENU_CONTROLLER_OPTIONS_TITLE", Screen_width)
else
Header_obj:set_text("CONTROLS_TITLE", Screen_width)
end
--Shift screen up we don't have to scroll for one additional option.
--Newsticker gets in the way in the main menu.
--set up the list in twns
local list_back_in = Vdo_tween_object:new("back_in_twn2", Screen_back_in_anim.handle)
local header_back_in = Vdo_tween_object:new("back_in_twn3", Screen_back_in_anim.handle)
list_back_in:set_property("start_value", 100, 140)
header_back_in:set_property("start_value", 130, 83)
list_back_in:set_property("end_value", 100, 140)
header_back_in:set_property("end_value", 130, 83)
--set up the list out twns
local list_slide_out = Vdo_tween_object:new("screen_slide_out_twn2", Screen_slide_out_anim.handle)
local header_slide_out = Vdo_tween_object:new("screen_slide_out_twn3", Screen_slide_out_anim.handle)
list_slide_out:set_property("start_value", 100, 140)
header_slide_out:set_property("start_value", 130, 83)
list_slide_out:set_property("end_value", 100, 140)
header_slide_out:set_property("end_value", 130, 83)
local list_slide_in = Vdo_tween_object:new("screen_slide_in_twn2", Screen_slide_in_anim.handle)
local header_slide_in = Vdo_tween_object:new("screen_slide_in_twn3", Screen_slide_in_anim.handle)
list_slide_in:set_property("start_value", 100, 140)
header_slide_in:set_property("start_value", 130, 83)
list_slide_in:set_property("end_value", 100, 140)
header_slide_in:set_property("end_value", 130, 83)
--Get the selection option from when the menu was last loaded
local last_option_selected = menu_common_stack_get_index()
--Setup button hints
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_X, "MENU_RESTORE_DEFAULTS"},
}
Menu_hint_bar:set_hints(hint_data)
-- Initialize and draw list object
vint_dataresponder_request("pause_menu_options", "options_controls_populate", 0, PM_MENU_CONTROL_OPTIONS)
List:set_input_tracker(Input_tracker)
List:draw_items(Data, last_option_selected, Screen_width, Max_list_items)
--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)
-- 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("pause_options_controls", Mouse_input_tracker)
Menu_hint_bar:add_mouse_inputs("pause_options_controls", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
--menu_common_set_mouse_tracker(Mouse_input_tracker)
end
end
function pause_options_controls_cleanup()
-- 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)
--set up the list out twns
local list_slide_out = Vdo_tween_object:new("screen_slide_out_twn2", Screen_slide_out_anim.handle)
local header_slide_out = Vdo_tween_object:new("screen_slide_out_twn3", Screen_slide_out_anim.handle)
local list_slide_in = Vdo_tween_object:new("screen_slide_in_twn2", Screen_slide_in_anim.handle)
local header_slide_in = Vdo_tween_object:new("screen_slide_in_twn3", Screen_slide_in_anim.handle)
local list_back_out = Vdo_tween_object:new("back_out_twn3", Screen_back_out_anim.handle)
local header_back_out = Vdo_tween_object:new("back_out_twn2", Screen_back_out_anim.handle)
local list_back_in = Vdo_tween_object:new("back_in_twn2", Screen_back_in_anim.handle)
local header_back_in = Vdo_tween_object:new("back_in_twn3", Screen_back_in_anim.handle)
list_back_in:set_property("start_value", 100, 267)
header_back_in:set_property("start_value", 130, 210)
list_back_in:set_property("end_value", 100, 267)
header_back_in:set_property("end_value", 130, 210)
list_slide_out:set_property("start_value", 100, 267)
header_slide_out:set_property("start_value", 130, 210)
list_slide_out:set_property("end_value", 100, 267)
header_slide_out:set_property("end_value", 130, 210)
list_slide_in:set_property("start_value", 100, 267)
header_slide_in:set_property("start_value", 130, 210)
list_slide_in:set_property("end_value", 100, 267)
header_slide_in:set_property("end_value", 130, 210)
end
function options_controls_populate(invert_y, invert_rotation, veh_camera_snap, airplane_controls, vertical_sens, horz_sens, vibration, toggle_crouch, fine_auto_aim, invert_aircraft_pitch, qte_touch_pad)
Data = { }
if game_get_platform() == "PC" then
Data[#Data + 1] = {
type = TYPE_BUTTON,
label = "MENU_CONTROL_SCHEMES",
id = CONTROL_SCHEME_BUTTON_ID,
current_value = 0
}
end
Data[#Data + 1] = {
type = TYPE_TOGGLE,
label = "MENU_CONTROLS_INVERT_Y",
options = {"OPTION_NO", "OPTION_YES"},
id = 1,
current_value = 1
}
if invert_y == 1 then
Data[#Data].current_value = 2
else
Data[#Data].current_value = 1
end
Data[#Data + 1] = {
type = TYPE_TOGGLE,
label = "MENU_CONTROLS_INVERT_ROTATION",
options = {"OPTION_NO", "OPTION_YES"},
id = 2,
current_value = 1
}
if invert_rotation == 1 then
Data[#Data].current_value = 2
else
Data[#Data].current_value = 1
end
if game_get_platform() ~= "PC" then
Data[#Data + 1] = {
type = TYPE_TOGGLE,
label = "CONTROLS_INVERT_AIRCRAFT_PITCH",
options = {"OPTION_NO", "OPTION_YES"},
id = 10,
current_value = 1
}
if invert_aircraft_pitch == 1 then
Data[#Data].current_value = 2
else
Data[#Data].current_value = 1
end
end
local vehicle_snap_option = {
type = TYPE_TOGGLE,
label = "MENU_VEHICLE_CAMERA_SNAP",
options = {"MENU_INSTANT", "MENU_DELAYED"},
id = 3,
current_value = 1
}
if veh_camera_snap == 1 then
vehicle_snap_option.current_value = 2
else
vehicle_snap_option.current_value = 1
end
--[[
if game_get_platform() ~= "PC" then
Data[#Data + 1] = vehicle_snap_option
Data[#Data + 1] = {
type = TYPE_TOGGLE,
label = "MENU_AIRPLANE_CONTROLS",
options = {"MENU_ADVANCED", "MENU_NORMAL"},
id = 4,
current_value = 1
}
if airplane_controls == 1 then
Data[#Data].current_value = 2
else
Data[#Data].current_value = 1
end
end
--]]
Data[#Data + 1] = {
type = TYPE_SLIDER,
label = "CONTROLS_SENSE_V",
min = 0,
max = 100,
step = 1,
id = 5,
current_value = floor(vertical_sens * 100)
}
Data[#Data + 1] = {
type = TYPE_SLIDER,
label = "CONTROLS_SENSE_H",
min = 0,
max = 100,
step = 1,
id = 6,
current_value = floor(horz_sens * 100)
}
Data[#Data + 1] = {
type = TYPE_TOGGLE,
label = "CONTROLS_FORCE_FEED",
options = {"OPTION_NO", "OPTION_YES"},
id = 7,
current_value = 1
}
if vibration == 1 or vibration == true then
Data[#Data].current_value = 2
else
Data[#Data].current_value = 1
end
Data[#Data + 1] = {
type = TYPE_TOGGLE,
label = "CONTROLS_CROUCH_TOGGLE",
options = {"OPTION_NO", "OPTION_YES"},
id = 8,
current_value = 1
}
if toggle_crouch == 1 then
Data[#Data].current_value = 2
else
Data[#Data].current_value = 1
end
Data[#Data + 1] = {
type = TYPE_TOGGLE,
label = "CONTROLS_FINE_AUTO_AIM",
options = {"OPTION_NO", "OPTION_YES"},
id = 9,
current_value = 1
}
if fine_auto_aim == 1 then
Data[#Data].current_value = 2
else
Data[#Data].current_value = 1
end
if game_get_platform() == "PC" then
Data[#Data + 1] = vehicle_snap_option
end
-- HVS_JPM [KING ONLY] 10/21/2014 - HS 11166 - there are no QTEs in King so we removed the touchpad option
--[[
if game_get_platform() == "PS4" then --HVS_JRP[PRINCE] 4/1/2014 PS4 touch pad for quick time events.
Data[#Data + 1] = {
type = TYPE_TOGGLE,
label = "CONTROLS_QTE_TOUCH_PAD",
options = {"OPTION_NO", "OPTION_YES"},
id = 11,
current_value = 1
}
if qte_touch_pad == 1 then
Data[#Data].current_value = 2
else
Data[#Data].current_value = 1
end
end
--]]
end
function options_controls_nav_up(event, acceleration)
-- Move highlight up
List:move_cursor(-1)
end
function options_controls_nav_down(event, acceleration)
-- Move highlight down
List:move_cursor(1)
end
function options_controls_nav_left(event, acceleration)
-- Move highlight left
List:move_slider(-1)
options_controls_update_option_value()
end
function options_controls_nav_right(event, acceleration)
-- Move highlight right
List:move_slider(1)
options_controls_update_option_value()
end
function options_controls_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
-- 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
pause_menu_update_option(PM_MENU_CONTROL_OPTIONS, menu_item.id, bool_val, converted_float)
end
function options_controls_button_a(event, acceleration)
options_controls_nav_right()
if Tween_done == true then
--set the screen data to the list data
Data = List:return_data()
--Add current selection to the stack to store the selected position on the menu
local current_id = List:get_id()
--pass off the input to the list
List:button_a()
if current_id == CONTROL_SCHEME_BUTTON_ID then
menu_common_stack_add(List:get_selection())
local list_back_out = Vdo_tween_object:new("back_out_twn3", Screen_back_out_anim.handle)
local header_back_out = Vdo_tween_object:new("back_out_twn2", Screen_back_out_anim.handle)
list_back_out:set_property("start_value", 100, 140)
header_back_out:set_property("start_value", 130, 83)
list_back_out:set_property("end_value", 100, 140)
header_back_out:set_property("end_value", 130, 83)
menu_common_transition_push("pause_ctrl_scheme")
pause_options_controls_cleanup()
return
end
end
end
function options_controls_button_b(event, acceleration)
if Tween_done == true then
List:button_b()
-- save options to the profile
pause_menu_accept_options()
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
List:enable_toggle_input(false)
--Remove current menu from the stack
menu_common_stack_remove()
menu_common_transition_pop(1)
end
end
function options_controls_button_x(event, acceleration)
dialog_box_confirmation("OPTIONS_MENU_DEFAULTS_TITLE", "OPTIONS_MENU_DEFAULTS_DESC", "options_controls_revert", true, true,1)
end
function options_controls_revert(result, action)
if result == 0 then
pause_menu_restore_defaults(PM_MENU_CONTROL_OPTIONS)
vint_dataresponder_request("pause_menu_options", "options_controls_populate", 0, PM_MENU_CONTROL_OPTIONS)
List:draw_items(Data, List:get_selection(), Screen_width, Max_list_items)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("pause_options_controls", Mouse_input_tracker)
Menu_hint_bar:add_mouse_inputs("pause_options_controls", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
end
function options_controls_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)
if game_get_platform() == "PC" then
menu_common_transition_pop(5) --controls, mouse_controls, options, pause menu top, pause menu common
else
menu_common_transition_pop(4) --controls, options, pause menu top, pause menu common
end
bg_saints_slide_out()
end
-- Mouse inputs
function pause_options_controls_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_controls_button_b()
elseif hint_index == 2 then
options_controls_button_x()
end
local new_index = List:get_button_index(target_handle)
if new_index ~= 0 then
List:set_selection(new_index)
options_controls_button_a()
end
if List:is_left_arrow(target_handle) then
List:move_slider(-1)
options_controls_update_option_value()
elseif List:is_right_arrow(target_handle) then
List:move_slider(1)
options_controls_update_option_value()
end
if List:is_slider(target_handle) then
List:move_slider(0, mouse_x)
options_controls_update_option_value()
end
end
function pause_options_controls_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 pause_options_controls_mouse_drag(event, target_handle, mouse_x, mouse_y)
if List:is_slider(target_handle) then
List:move_slider(0, mouse_x)
end
local scrollbar = List.scrollbar
--Max items is number of buttons in the list minus the max buttons that can be displayed.
local max_items = List.num_buttons - (List.max_buttons - 1)
if List:list_is_playing() == false then
if scrollbar.tab_grp.handle == target_handle then
--Get new start index from scroll tab
local new_start_index = scrollbar:drag_scrolltab(mouse_y, max_items)
--Scroll Mission list
List:scroll_list(0, new_start_index)
end
end
end
function pause_options_controls_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
if List:is_slider(target_handle) then
List:move_slider(0, mouse_x)
options_controls_button_a()
end
local scrollbar = List.scrollbar
if List:list_is_playing() == false then
if scrollbar.tab_grp.handle == target_handle then
local start_index, end_index = List:get_visible_indices()
--Max items is number of buttons in the list minus the max buttons that can be displayed.
local max_items = List.num_buttons - (List.max_buttons - 1)
--Set scrolltab position...
scrollbar:release_scrolltab(start_index, max_items)
end
end
end
function pause_options_controls_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines)
--scroll lines are inverted for some reason
scroll_lines = scroll_lines * -1
if scroll_lines ~= 0 then
List:scroll_list(scroll_lines)
end
end