local PM_MENU_MOUSE_OPTIONS = 6
local REMAP_BUTTON_ID = -1
local GAMEPAD_OPTIONS_BUTTON_ID = -2
local Data = {}
local Anims = {}
local Input_tracker
local Mouse_input_tracker
local Screen_width = 800
local Tween_done = true
function pause_options_mouse_init()
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("select", "options_mouse_button_a", 50)
Input_tracker:add_input("back", "options_mouse_button_b", 50)
if In_pause_menu then
Input_tracker:add_input("pause", "options_mouse_button_start", 50)
end
Input_tracker:add_input("alt_select", "options_mouse_button_x", 50)
Input_tracker:add_input("nav_up", "options_mouse_nav_up", 50)
Input_tracker:add_input("nav_down", "options_mouse_nav_down", 50)
Input_tracker:add_input("nav_left", "options_mouse_nav_left", 50)
Input_tracker:add_input("nav_right", "options_mouse_nav_right", 50)
Input_tracker:subscribe(false)
--Initialize Header
Header_obj:set_text("MOUSE_TITLE", Screen_width)
--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_mouse_populate", 0, PM_MENU_MOUSE_OPTIONS)
List:set_input_tracker(Input_tracker)
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)
-- 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_mouse", Mouse_input_tracker)
Menu_hint_bar:add_mouse_inputs("options_mouse", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
--menu_common_set_mouse_tracker(Mouse_input_tracker)
end
end
function pause_options_mouse_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)
end
function options_mouse_populate(invert_x, invert_y, sensitivity_x, sensitivity_y, vehicle_camera_snap)
Data = {}
Data[#Data + 1] = {
type = TYPE_BUTTON,
label = "MENU_OPTIONS_REMAP",
current_value = 0,
id = REMAP_BUTTON_ID
}
Data[#Data + 1] = {
type = TYPE_TOGGLE,
label = "MENU_MOUSE_CONTROLS_INVERT_Y",
options = {"OPTION_NO", "OPTION_YES"},
current_value = 1,
id = 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_MOUSE_CONTROLS_INVERT_X",
options = {"OPTION_NO", "OPTION_YES"},
current_value = 1,
id = 2
}
if invert_x == 1 then
Data[#Data].current_value = 2
else
Data[#Data].current_value = 1
end
Data[#Data + 1] = {
type = TYPE_SLIDER,
label = "MENU_MOUSE_CONTROLS_VERT_SENS",
min = 0,
max = 100,
step = 1,
current_value = floor(sensitivity_y * 100),
id = 3
}
Data[#Data + 1] = {
type = TYPE_SLIDER,
label = "MENU_MOUSE_CONTROLS_HORIZ_SENS",
min = 0,
max = 100,
step = 1,
current_value = floor(sensitivity_x * 100),
id = 4
}
Data[#Data + 1] = {
type = TYPE_TOGGLE,
label = "MENU_VEHICLE_CAMERA_SNAP",
options = {"MENU_INSTANT", "MENU_DELAYED", "MENU_CAMERA_SMART"},
current_value = vehicle_camera_snap + 1,
id = 5
}
Data[#Data + 1] = {
type = TYPE_BUTTON,
label = "MENU_CONTROLLER_OPTIONS",
current_value = 0,
id = GAMEPAD_OPTIONS_BUTTON_ID
}
end
function options_mouse_nav_up(event, acceleration)
-- Move highlight up
List:move_cursor(-1)
end
function options_mouse_nav_down(event, acceleration)
-- Move highlight down
List:move_cursor(1)
end
function options_mouse_nav_left(event, acceleration)
-- Move highlight left
List:move_slider(-1)
options_mouse_update_option_value()
end
function options_mouse_nav_right(event, acceleration)
-- Move highlight right
List:move_slider(1)
options_mouse_update_option_value()
end
function options_mouse_update_option_value()
local current_idx = List:get_selection()
local menu_item = Data[current_idx]
if menu_item.type == TYPE_BUTTON then
return
end
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
if menu_item.type == TYPE_TOGGLE then
converted_float = menu_item.current_value - 1 -- 0-based
end
pause_menu_update_option(PM_MENU_MOUSE_OPTIONS, menu_item.id, bool_val, converted_float)
end
function options_mouse_button_a(event, acceleration)
options_mouse_nav_right()
if Tween_done == true then
--set the screen data to the list data
Data = List:return_data()
local current_id = List:get_id()
List:button_a()
if current_id == REMAP_BUTTON_ID then
menu_common_transition_push("pause_options_remap")
pause_options_mouse_cleanup()
-- save options to the profile
pause_menu_accept_options()
return
end
if current_id == GAMEPAD_OPTIONS_BUTTON_ID then
menu_common_transition_push("pause_options_controls")
pause_options_mouse_cleanup()
-- save options to the profile
pause_menu_accept_options()
return
end
end
end
function options_mouse_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_mouse_button_x(event, acceleration)
dialog_box_confirmation("OPTIONS_MENU_DEFAULTS_TITLE", "OPTIONS_MENU_DEFAULTS_DESC", "options_mouse_revert", true, true,1)
end
function options_mouse_revert(result, action)
if result == 0 then
pause_menu_restore_defaults(PM_MENU_MOUSE_OPTIONS)
vint_dataresponder_request("pause_menu_options", "options_mouse_populate", 0, PM_MENU_MOUSE_OPTIONS)
List:draw_items(Data, List:get_selection(), Screen_width)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("options_mouse", Mouse_input_tracker)
Menu_hint_bar:add_mouse_inputs("options_mouse", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
end
function options_mouse_button_start(event, acceleration)
menu_common_transition_pop(4) --controls, options, pause menu top, pause menu common
end
-- Mouse inputs
function options_mouse_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_mouse_button_b()
elseif hint_index == 2 then
options_mouse_button_x()
end
local new_index = List:get_button_index(target_handle)
if new_index ~= 0 then
List:set_selection(new_index)
options_mouse_button_a()
end
if List:is_left_arrow(target_handle) then
List:move_slider(-1)
options_mouse_update_option_value()
elseif List:is_right_arrow(target_handle) then
List:move_slider(1)
options_mouse_update_option_value()
end
if List:is_slider(target_handle) then
List:move_slider(0, mouse_x)
options_mouse_update_option_value()
end
end
function options_mouse_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_mouse_mouse_drag(event, target_handle, mouse_x, mouse_y)
if List:is_slider(target_handle) then
List:move_slider(0, mouse_x)
end
end
function options_mouse_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
if List:is_slider(target_handle) then
List:move_slider(0, mouse_x)
options_mouse_button_a()
end
end