local Remap_doc_handle
-- This is used by vdo_button_remap, so must be global
Remap_category_index = 1
local Data = { }
local Category_names = { "MENU_CATEGORY_GENERAL", "MENU_CATEGORY_ONFOOT", "MENU_CATEGORY_CAR", "MENU_CATEGORY_HELI", "MENU_CATEGORY_PLANE", "MENU_CATEGORY_TANK" }
local Input_tracker
local Mouse_input_tracker
local Tween_done = true
local Overall_action = 1
local Num_categories = 1
local Num_actions = 0
local Screen_width = 700
local STATE_CATEGORIES = 1
local STATE_SUBMENU = 2
local Current_state = STATE_CATEGORIES
local MAX_VISIBLE = 15
function vint_options_remap_get_num_actions(actions)
Num_actions = actions
end
function vint_remap_get_action_binding(action_name, key1, key2)
local t = {
type = TYPE_REMAP,
label = action_name,
value1 = key1,
value2 = key2,
}
if key1 == "" then
t.value1 = nil
end
if key2 == "" then
t.value2 = nil
end
Data[Overall_action] = t
Overall_action = Overall_action + 1
end
function vint_remap_update_display(sel)
if Current_state ~= STATE_SUBMENU then
return
end
Data = { }
-- Always add the category first
--[[Data[1] = {
type = TYPE_TOGGLE,
label = "MENU_CATEGORY",
options = Category_names,
current_value = Remap_category_index,
is_special = true
}]]
local cur_cat = Remap_category_index
Num_categories = 7 --vint_options_remap_get_num_categories()
Overall_action = 1
vint_dataresponder_request("vint_options_remap_get_num_actions", "vint_options_remap_get_num_actions", 1, cur_cat)
local action
for action = 1, Num_actions do
vint_dataresponder_request("vint_remap_get_action_binding", "vint_remap_get_action_binding", 2, cur_cat, action)
end
-- Remove subscriptions
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
end
-- Initialize and draw list object
List:set_properties(nil, nil, nil, nil, nil, nil, true)
List:draw_items(Data, sel, Screen_width, MAX_VISIBLE)
-- Re-add subscriptions
if Mouse_input_tracker ~= nil then
List:add_mouse_inputs("options_remap", Mouse_input_tracker)
Menu_hint_bar:add_mouse_inputs("options_remap", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
function pause_options_remap_set_tool_tip(new_tip_text)
local tool_tip_h = vint_object_find("tool_tip_text", 0, Remap_doc_handle)
vint_set_property(tool_tip_h, "text_tag", new_tip_text)
end
function pause_options_remap_show_categories()
Data = { }
local cat
for cat = 1, #Category_names do
Data[cat] = {
type = TYPE_BUTTON,
label = Category_names[cat],
current_value = 0,
id = cat
}
end
-- Remove subscriptions
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
end
-- Initialize and draw list object
List:set_properties(nil, nil, nil, nil, nil, nil, true)
List:draw_items(Data, 1, Screen_width, MAX_VISIBLE)
-- Re-add subscriptions
if Mouse_input_tracker ~= nil then
List:add_mouse_inputs("options_remap", Mouse_input_tracker)
Menu_hint_bar:add_mouse_inputs("options_remap", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
function pause_options_remap_init()
Remap_doc_handle = vint_document_find("pause_options_remap")
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("select", "options_remap_button_a", 50)
Input_tracker:add_input("back", "options_remap_button_b", 50)
Input_tracker:add_input("alt_select", "options_remap_button_x", 50)
if In_pause_menu then
Input_tracker:add_input("pause", "options_remap_button_start", 50)
end
Input_tracker:add_input("nav_up", "options_remap_nav_up", 50)
Input_tracker:add_input("nav_down", "options_remap_nav_down", 50)
Input_tracker:add_input("nav_left", "options_remap_nav_left", 50)
Input_tracker:add_input("nav_right", "options_remap_nav_right", 50)
Input_tracker:subscribe(false)
--Set Button hints
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_X, "MENU_RESTORE_ALL_DEFAULTS"},
}
Menu_hint_bar:set_hints(hint_data)
if game_get_language() == "FR" then
Screen_width = 850
end
--Initialize Header
Header_obj:set_text("MENU_OPTIONS_REMAP",Screen_width)
--Data[DIFFICULTY_INDEX].current_value = get_current_difficulty() + 1 -- Difficulties start at 0
pause_options_remap_show_categories()
--vint_remap_update_display(0)
--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", 1000, 120)
header_back_in:set_property("start_value", 1000, 80)
list_back_in:set_property("end_value", 100, 120)
header_back_in:set_property("end_value", 130, 80)
--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)
Menu_hint_bar:set_highlight(0)
Mouse_input_tracker = Vdo_input_tracker:new()
List:add_mouse_inputs("options_remap", Mouse_input_tracker)
Menu_hint_bar:add_mouse_inputs("options_remap", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
local tool_tip_h = vint_object_find("tool_tip_text", 0, Remap_doc_handle)
vint_set_property(tool_tip_h, "alpha", 0)
-- Align the tooltip to the list
if In_pause_menu then
local anchor_in_h = vint_object_find("new_tween2")
local anchor_out_h = vint_object_find("new_tween4")
local anchor_in_x,anchor_in_y = vint_get_property(anchor_in_h, "start_value")
local anchor_out_x,anchor_out_y = vint_get_property(anchor_out_h, "start_value")
if vint_is_std_res() then
vint_set_property(anchor_in_h, "start_value", 282, anchor_in_y)
vint_set_property(anchor_in_h, "end_value", 282, anchor_out_y)
vint_set_property(anchor_out_h, "start_value", 282, anchor_out_y)
vint_set_property(anchor_out_h, "end_value", 282, anchor_in_y)
else
vint_set_property(anchor_in_h, "start_value", 448, anchor_in_y)
vint_set_property(anchor_in_h, "end_value", 448, anchor_out_y)
vint_set_property(anchor_out_h, "start_value", 448, anchor_out_y)
vint_set_property(anchor_out_h, "end_value", 448, anchor_in_y)
end
end
pause_options_remap_set_tool_tip("MENU_PRIMARY_ASSIGNMENT") --("X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X") -- Use this to figure out the correct anchor for In_pause_menu
end
function pause_options_remap_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 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", 1000, 267)
header_back_in:set_property("start_value", 1000, 230)
list_back_in:set_property("end_value", 100, 267)
header_back_in:set_property("end_value", 130, 230)
--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, 267)
header_slide_out:set_property("start_value", 130, 230)
list_slide_out:set_property("end_value", 1000, 267)
header_slide_out:set_property("end_value", 1000, 230)
end
function options_remap_nav_up(event, acceleration)
-- Move highlight up
List:move_cursor(-1)
options_remap_update_mouse_inputs()
end
function options_remap_nav_down(event, acceleration)
-- Move highlight down
List:move_cursor(1)
options_remap_update_mouse_inputs()
end
function options_remap_nav_left(event, acceleration)
local current_idx = List:get_selection()
local menu_item = Data[current_idx]
if menu_item.type == TYPE_TOGGLE then
List:move_slider(-1)
-- This assumes there's only 1 toggle (for the category)
options_remap_update_category(menu_item.current_value)
pause_options_remap_set_tool_tip("MENU_PRIMARY_ASSIGNMENT")
elseif Current_state == STATE_SUBMENU then
List:move_cursor(0, true)
List.buttons[current_idx].remap:set_highlight_column(1)
List.remap_column = 1
pause_options_remap_set_tool_tip("MENU_PRIMARY_ASSIGNMENT")
end
end
function options_remap_nav_right(event, acceleration)
local current_idx = List:get_selection()
local menu_item = Data[current_idx]
if menu_item.type == TYPE_TOGGLE then
List:move_slider(1)
-- This assumes there's only 1 toggle (for the category)
options_remap_update_category(menu_item.current_value)
pause_options_remap_set_tool_tip("MENU_PRIMARY_ASSIGNMENT")
elseif Current_state == STATE_SUBMENU then
List:move_cursor(0, true)
List.buttons[current_idx].remap:set_highlight_column(2)
List.remap_column = 2
pause_options_remap_set_tool_tip("MENU_SECONDARY_ASSIGNMENT")
end
end
function options_remap_update_category(new_index)
Remap_category_index = new_index
vint_remap_update_display(0)
end
function options_remap_button_b(event, acceleration)
-- If we're in a sub menu, just back out to the category list.
if Current_state == STATE_SUBMENU then
Current_state = STATE_CATEGORIES
pause_options_remap_show_categories()
-- animate tooltip out
local anim_h = vint_object_find("animate_out", 0, Remap_doc_handle)
lua_play_anim(anim_h, 0, Remap_doc_handle)
return
end
--back up a screen
--game_difficulty_select(Data[DIFFICULTY_INDEX].current_value - 1) -- Difficulties indexed by 0
pause_menu_accept_options()
List:button_b()
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)
list_slide_out:set_property("start_value", 100, 120)
header_slide_out:set_property("start_value", 130, 80)
list_slide_out:set_property("end_value", 1000, 120)
header_slide_out:set_property("end_value", 1000, 80)
--Remove current menu from the stack
menu_common_stack_remove()
menu_common_transition_pop(1)
end
function options_remap_button_x(event, acceleration)
dialog_box_confirmation("OPTIONS_MENU_DEFAULTS_TITLE", "OPTIONS_MENU_DEFAULTS_DESC", "options_remap_revert", true, true)
end
function options_remap_revert(result, action)
if result == 0 then
vint_options_remap_reset_bindings()
vint_remap_update_display(1)
end
end
function options_remap_button_a(event, acceleration)
local current_idx = List:get_selection()
local menu_item = Data[current_idx]
if menu_item.type == TYPE_TOGGLE then
options_remap_nav_right()
else
--pass off the input to the list
List:button_a()
if menu_item.type == TYPE_BUTTON and Current_state == STATE_CATEGORIES then
Current_state = STATE_SUBMENU
Remap_category_index = menu_item.id
vint_remap_update_display(1)
-- animate tooltip in
local anim_h = vint_object_find("animate_in", 0, Remap_doc_handle)
lua_play_anim(anim_h, 0, Remap_doc_handle)
end
end
end
function options_remap_button_start(event, acceleration)
menu_common_transition_pop(4) -- options_remap, options, pause_menu_top, menu_common
end
-- Mouse inputs
function options_remap_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_remap_button_b()
elseif hint_index == 2 then
options_remap_button_x()
end
local new_index = List:get_button_index(target_handle)
if new_index ~= 0 then
List:set_selection(new_index)
options_remap_button_a()
end
local index, button, column = List:get_remap_index(target_handle)
if column ~= 0 then
List:set_selection(index)
List:move_cursor(0, true)
button:set_highlight_column(column)
if column == 1 then
pause_options_remap_set_tool_tip("MENU_PRIMARY_ASSIGNMENT")
else
pause_options_remap_set_tool_tip("MENU_SECONDARY_ASSIGNMENT")
end
options_remap_button_a()
end
if List:is_left_arrow(target_handle) then
options_remap_nav_left()
end
end
function options_remap_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
local index, button, column = List:get_remap_index(target_handle)
if column ~= 0 then
List:set_selection(index)
List:move_cursor(0, true)
button:set_highlight_column(column)
if column == 1 then
pause_options_remap_set_tool_tip("MENU_PRIMARY_ASSIGNMENT")
else
pause_options_remap_set_tool_tip("MENU_SECONDARY_ASSIGNMENT")
end
-- Activate remapping
end
end
function options_remap_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines)
if scroll_lines ~= 0 then
if List:get_scroll_region_handle() == target_handle then
List:scroll_list(scroll_lines * -1)
options_remap_update_mouse_inputs()
end
end
end
function options_remap_mouse_drag(event, target_handle, mouse_x, mouse_y)
if List.scrollbar.tab.handle == target_handle then
local new_start_index = List.scrollbar:drag_scrolltab(mouse_y, List.num_buttons - (List.max_buttons - 1))
List:scroll_list(0, new_start_index)
end
end
-- Updates the mouse inputs for the list and snaps the scrolltab to the closest notch based on the visible index
--
function options_remap_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
if List.scrollbar.tab.handle == target_handle then
local start_index = List:get_visible_indices()
List.scrollbar:release_scrolltab(start_index, List.num_buttons - (List.max_buttons - 1))
options_remap_update_mouse_inputs()
end
end
function options_remap_update_mouse_inputs()
List:update_mouse_inputs("options_remap", Mouse_input_tracker)
Menu_hint_bar:add_mouse_inputs("options_remap", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end