local ON_FOOT_INDEX = 1
local VEHICLE_INDEX = 2
local Anims = {}
local Screen_width = 840
local Input_tracker
local Mouse_input_tracker
Control_list = -1
local Ctrl_scheme_doc = -1
Pause_menu_controller = -1
Pause_menu_controller_thread_h = -1
local PAUSE_MENU_CONTROL_SCHEME_ID = 14
local Tween_done = true
local pad_anchor_x, pad_anchor_y
function pause_ctrl_scheme_init()
Ctrl_scheme_doc = vint_document_find("pause_ctrl_scheme")
-- Subscribe to the button presses we need
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("select", "pause_ctrl_scheme_button_a", 50)
Input_tracker:add_input("back", "pause_ctrl_scheme_button_b", 50)
Input_tracker:add_input("nav_up", "pause_ctrl_scheme_nav_up", 50)
Input_tracker:add_input("nav_down", "pause_ctrl_scheme_nav_down", 50)
Input_tracker:add_input("nav_left", "pause_ctrl_scheme_nav_left", 50)
Input_tracker:add_input("nav_right", "pause_ctrl_scheme_nav_right", 50)
if In_pause_menu then
Input_tracker:add_input("pause", "pause_ctrl_scheme_button_start", 50)
end
if vint_is_std_res() then
Screen_width = 750
else
Screen_width = 840
end
Input_tracker:subscribe(false)
--Initialize Header
local ctrl_header_obj = Vdo_pause_header:new("header",0,Ctrl_scheme_doc)
ctrl_header_obj:set_text("MENU_CONTROL_SCHEMES", Screen_width)
Control_list = Vdo_mega_list:new("list", 0, Ctrl_scheme_doc, "pause_ctril_scheme.lua", "Control_list")
Control_list:set_highlight_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY)
--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"},
}
Menu_hint_bar:set_hints(hint_data)
--Change controller image based on platform...
local controller_h = vint_object_find("controller")
local platform = game_get_platform()
if platform == "PS3" then
vint_set_property(controller_h, "image", "ui_menu_ctrl_ps3")
elseif platform == "PS4" then -- HVS_JRP[PRINCE] 3/18/2014
vint_set_property(controller_h, "image", "ui_menu_ctrl_ps4")
elseif platform == "XBOX3" then -- HVS_JRP[PRINCE] 3/18/2014
vint_set_property(controller_h, "image", "ui_menu_ctrl_xbox3")
else
vint_set_property(controller_h, "image", "ui_menu_ctrl_xbox2")
end
local grp_h = vint_object_find("ctrls", 0, Ctrl_scheme_doc)
local h = vint_object_find("19_btn", grp_h)
pad_anchor_x, pad_anchor_y = vint_get_property(h, "anchor")
--Get control schemes and populate stuff
-- On foot Controls
local which_controller, which_scheme, num_buttons = pause_menu_control_scheme_init(true, 0)
--Options_Controls_Data[1].current_value = which_scheme + 1
-- Vehicle Controls
local which_controller, which_scheme, num_buttons = pause_menu_control_scheme_init(true, 1)
--Options_Controls_Data[2].current_value = which_scheme + 1
-- Aircraft Controls
-- local which_controller, which_scheme, num_buttons = pause_menu_control_scheme_init(true, 2)
--Reset Controls Menu...
pause_ctrl_scheme_reset(0)
-- Draw the list for the first time
Control_list:draw_items(Options_Controls_Data, 1, Screen_width, nil, nil, nil, false)
--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 platform == "PC" then
Menu_hint_bar:set_highlight(0)
Mouse_input_tracker = Vdo_input_tracker:new()
Control_list:add_mouse_inputs("pause_ctrl_scheme", Mouse_input_tracker)
Menu_hint_bar:add_mouse_inputs("pause_ctrl_scheme", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
--menu_common_set_mouse_tracker(Mouse_input_tracker)
end
List:set_visible(false)
Header_obj:set_visible(false)
if not In_pause_menu then
--get the list x and y
local new_x
local middle_x
if vint_is_std_res() == false then
middle_x = 640
else
middle_x = 320 * 1.5
end
new_x = middle_x - (Screen_width * 0.5)
bg_saints_set_type(BG_TYPE_PAUSE, true, Screen_width)
else
end
local screen_in_anim = Vdo_anim_object:new("ctrl_back_in_anim", 0, Ctrl_scheme_doc)
screen_in_anim:play(0)
vdo_mega_list_enable_listener(false)
end
function pause_ctrl_scheme_cleanup()
--Kill menu cycle thread...
thread_kill(Pause_menu_controller_thread_h)
Pause_menu_controller_thread_h = -1
--Free up Memory...
pause_menu_control_scheme_init(false)
-- 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)
vdo_mega_list_enable_listener(true)
end
function pause_ctrl_scheme_nav_up(event, acceleration)
end
function pause_ctrl_scheme_nav_down(event, acceleration)
end
function pause_ctrl_scheme_nav_left(event, acceleration)
-- Move highlight left
Control_list:move_slider(-1)
--Update control menu...
pause_ctrl_scheme_reset(Control_list:get_toggle_selection() - 1)
end
function pause_ctrl_scheme_nav_right(event, acceleration)
-- Move highlight right
Control_list:move_slider(1)
--Update control menu...
pause_ctrl_scheme_reset(Control_list:get_toggle_selection() - 1)
end
function pause_ctrl_scheme_button_a(event, acceleration)
if Tween_done == true then
--pass off the input to the list
--Control_list:button_a()
pause_ctrl_scheme_nav_right(event, acceleration)
end
end
function pause_ctrl_scheme_button_b(event, acceleration)
if Tween_done == true then
--slide the screen out
local screen_out_anim = Vdo_anim_object:new("ctrl_slide_out_anim",0,Ctrl_scheme_doc)
screen_out_anim:play(0)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
List:enable_toggle_input(false)
-- Save options
pause_menu_accept_options()
--Remove from internal stack for button tracking and pop screen.
menu_common_stack_remove()
Control_list:button_b()
menu_common_transition_pop(1)
--List:set_visible(true)
--Header_obj:set_visible(true)
end
end
--------------------------------------------------
-- SR2 Stuff...
--------------------------------------------------
function pause_ctrl_scheme_reset(scheme_id)
local which_controller, which_scheme, num_buttons = pause_menu_control_scheme_init(true, scheme_id)
local grp_h = vint_object_find("ctrls", 0, Ctrl_scheme_doc)
Pause_menu_controller = {}
if which_controller == 0 then
--XBOX2
else
--PS3/PS4
local h = vint_object_find("dpad", grp_h)
vint_set_property(h, "anchor", 0, -109 )
local h = vint_object_find("left_sticks", grp_h)
vint_set_property(h, "anchor", 0, 190)
local h = vint_object_find("start", grp_h)
vint_set_property(h, "anchor", 20, 0)
end
if which_controller == 2 then
--PS4
local h = vint_object_find("19_btn", grp_h)
vint_set_property(h, "anchor", pad_anchor_x, pad_anchor_y+6)
end
--Left Side buttons
local btn_lt_h = vint_object_find("0_btn", grp_h)
vint_set_property(btn_lt_h, "image", CTRL_BUTTON_LT)
local btn_lb_h = vint_object_find("1_btn", grp_h)
vint_set_property(btn_lb_h, "image", CTRL_BUTTON_LB)
local btn_ls_h = vint_object_find("3_btn", grp_h)
vint_set_property(btn_ls_h, "image", CTRL_BUTTON_LS)
local btn_ls_press_h = vint_object_find("4_btn", grp_h)
vint_set_property(btn_ls_press_h, "image", CTRL_BUTTON_LS_PRESS)
local btn_dpad_up_h = vint_object_find("6_btn", grp_h)
vint_set_property(btn_dpad_up_h, "image", CTRL_BUTTON_DPAD_UP)
local btn_dpad_left_h = vint_object_find("7_btn", grp_h)
vint_set_property(btn_dpad_left_h, "image", CTRL_BUTTON_DPAD_LEFT)
local btn_dpad_down_h = vint_object_find("8_btn", grp_h)
vint_set_property(btn_dpad_down_h, "image", CTRL_BUTTON_DPAD_DOWN)
local btn_dpad_right_h = vint_object_find("9_btn", grp_h)
vint_set_property(btn_dpad_right_h, "image", CTRL_BUTTON_DPAD_RIGHT)
--Right Side Button...
local btn_rt_h = vint_object_find("10_btn", grp_h)
vint_set_property(btn_rt_h, "image", CTRL_BUTTON_RT)
local btn_rb_h = vint_object_find("11_btn", grp_h)
vint_set_property(btn_rb_h, "image", CTRL_BUTTON_RB)
local btn_y_h = vint_object_find("12_btn", grp_h)
vint_set_property(btn_y_h, "image", CTRL_BUTTON_Y)
local btn_b_h = vint_object_find("13_btn", grp_h)
vint_set_property(btn_b_h, "image", get_actual_b_button())
local btn_a_h = vint_object_find("14_btn", grp_h)
vint_set_property(btn_a_h, "image", CTRL_BUTTON_X)
local btn_x_h = vint_object_find("15_btn", grp_h)
vint_set_property(btn_x_h, "image", get_actual_a_button())
local btn_rs_h = vint_object_find("16_btn", grp_h)
vint_set_property(btn_rs_h, "image", CTRL_BUTTON_RS)
local btn_rs_press_h = vint_object_find("17_btn", grp_h)
vint_set_property(btn_rs_press_h, "image", CTRL_BUTTON_RS_PRESS)
--Middle Buttons
local btn_start_h = vint_object_find("18_btn", grp_h)
vint_set_property(btn_start_h, "image", CTRL_BUTTON_START)
local btn_back_h = vint_object_find("19_btn", grp_h)
vint_set_property(btn_back_h, "image", CTRL_MENU_BUTTON_BACK)
Pause_menu_controller = {
["L1"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("1_txt", grp_h), label_h = btn_lb_h } },
["L2"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("0_txt", grp_h), label_h = btn_lt_h } },
["analog left"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("3_txt", grp_h), label_h = btn_ls_h } },
["analog left click 1"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("4_txt", grp_h), label_h = btn_ls_press_h } },
-- ["analog left click 2"] = { labels = { }, num_buttons = 0, cur_button = 0,
-- handles = { button_h = 0, label_h = 0 } },
["dpad up"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("6_txt", grp_h), label_h = btn_dpad_up_h } },
["dpad left"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("7_txt", grp_h), label_h = btn_dpad_left_h } },
["dpad down"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("8_txt", grp_h), label_h = btn_dpad_down_h } },
["dpad right"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("9_txt", grp_h), label_h = btn_dpad_right_h } },
["R2"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("10_txt", grp_h), label_h = btn_rt_h } },
["R1"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("11_txt", grp_h), label_h = btn_rb_h } },
["button y"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("12_txt", grp_h), label_h = btn_y_h } },
["button b"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("13_txt", grp_h), label_h = btn_b_h } },
["button a"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("14_txt", grp_h), label_h = btn_a_h } },
["button x"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("15_txt", grp_h), label_h = btn_x_h } },
["analog right"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("16_txt", grp_h), label_h = btn_rs_h } },
["analog right click"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("17_txt", grp_h), label_h = btn_rs_press_h } },
["back"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("19_txt", grp_h), label_h = btn_back_h } },
["start"] = { labels = { }, num_buttons = 0, cur_button = 0,
handles = { button_h = vint_object_find("18_txt", grp_h), label_h = btn_start_h } },
}
for idx, val in pairs(Pause_menu_controller) do
vint_set_property(val.handles.button_h, "visible", false)
vint_set_property(val.handles.label_h, "visible", false)
val.num_buttons = 0
val.cur_button = 0
end
vint_dataresponder_request("pause_menu_control_scheme", "pause_ctrl_scheme_populate", 0, scheme_id)
if Pause_menu_controller_thread_h ~= -1 then
thread_kill(Pause_menu_controller_thread_h)
Pause_menu_controller_thread_h = -1
end
Pause_menu_controller_thread_h = thread_new("pause_ctrl_scheme_cycle")
end
function pause_ctrl_scheme_cycle()
while true do
delay(2)
for i, val in pairs(Pause_menu_controller) do
local num_buttons = val.num_buttons
local cur_button = val.cur_button
cur_button = cur_button + 1
if cur_button >= num_buttons then
cur_button = 0
end
if cur_button ~= val.cur_button then
val.cur_button = cur_button
vint_set_property(val.handles.button_h, "text_tag", val.labels[cur_button])
end
end
end
end
--Populates the control scheme with propert text..
--This gets called by a dataresponder...
--
--@param button_name This is the ID sent from game to change text for a certain button...
--@param button this is the text that gets used on the button.
function pause_ctrl_scheme_populate(button_name, button)
local num_buttons = Pause_menu_controller[button_name].num_buttons
Pause_menu_controller[button_name].labels[num_buttons] = button
if num_buttons == 0 then
vint_set_property(Pause_menu_controller[button_name].handles.button_h, "visible", true)
vint_set_property(Pause_menu_controller[button_name].handles.button_h, "text_tag", button)
if Pause_menu_controller[button_name].handles.label_h ~= 0 then
vint_set_property(Pause_menu_controller[button_name].handles.label_h, "visible", true)
end
end
Pause_menu_controller[button_name].num_buttons = num_buttons + 1
end
-- This gets called after naving or pressing a button...
-- Changes the Controlscheme internally and updates the menu.
--
-- @param button_data Table of button data...
function pause_ctrl_scheme_update_scheme(button_data)
--This gets called after naving...
pause_menu_change_control_scheme(0) --always use first control scheme in list...
pause_ctrl_scheme_reset(button_data.current_value - 1)
end
function pause_ctrl_scheme_button_start(event, acceleration)
if Tween_done == true then
local screen_grp_h = vint_object_find("screen_grp", 0, Ctrl_scheme_doc)
local screen_out_anim_h = vint_object_find("screen_out_anim", 0, Ctrl_scheme_doc)
lua_play_anim(screen_out_anim_h, 0, Ctrl_scheme_doc)
menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim, pause_menu_top_anim_in_done)
bg_saints_slide_out()
-- stack is part of common, which is getting popped, so we don't update it.
if game_get_platform() ~= "PC" then
menu_common_transition_pop(5) -- pause_ctrl_scheme, options_control, options, pause menu top, pause_menu common
else
menu_common_transition_pop(6)
end
end
end
Options_Controls_Data = {
[1] = {
type = TYPE_TOGGLE,
label = "CONTROL_SCHEME",
options = {"CONTROLS_SETUP_FOOT", "CONTROLS_SETUP_DRIVING", "CONTROLS_SETUP_AIRCRAFT"},
current_value = 1,
on_nav = pause_ctrl_scheme_update_scheme,
on_select = pause_ctrl_scheme_update_scheme,
},
}
function pause_ctrl_scheme_mask_morph( screen_type, size_end_x, anchor_end_x )
end
function pause_ctrl_scheme_set_slide_in_values( new_x )
local ctrl_anchor_twn_h = vint_object_find("ctrl_ctrls_back_anchor", 0, Ctrl_scheme_doc)
local header_anchor_twn_h = vint_object_find("ctrl_header_back_anchor", 0, Ctrl_scheme_doc)
local list_anchor_twn_h = vint_object_find("ctrl_list_back_anchor", 0, Ctrl_scheme_doc)
local ctrl_x,ctrl_y = vint_get_property(ctrl_anchor_twn_h, "end_value")
local header_x,header_y = vint_get_property(header_anchor_twn_h, "end_value")
local list_x,list_y = vint_get_property(list_anchor_twn_h, "end_value")
local ctrl_offset = 46
local header_offset = 30
local list_offset = 0
if vint_is_std_res() == true then
ctrl_offset = 75
header_offset = 60
list_offset = 28
end
--vint_set_property(ctrl_anchor_twn_h, "end_value", new_x + ctrl_offset, ctrl_y)
--vint_set_property(header_anchor_twn_h, "end_value", new_x + header_offset, header_y)
--vint_set_property(list_anchor_twn_h, "end_value", new_x + list_offset, list_y)
end
-- Mouse inputs
function pause_ctrl_scheme_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
pause_ctrl_scheme_button_b()
end
local new_index = Control_list:get_button_index(target_handle)
if new_index ~= 0 then
Control_list:set_selection(new_index)
pause_ctrl_scheme_nav_right()
end
if Control_list:is_left_arrow(target_handle) then
pause_ctrl_scheme_nav_left()
end
end
function pause_ctrl_scheme_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 = Control_list:get_button_index(target_handle)
if new_index ~= 0 then
Control_list:set_selection(new_index)
Control_list:move_cursor(0, true)
end
end