./pause_options_remap.lua

  1. local Remap_doc_handle 
  2.  
  3. -- This is used by vdo_button_remap, so must be global 
  4. Remap_category_index = 1 
  5.  
  6. local Data = { } 
  7. local Category_names = { "MENU_CATEGORY_GENERAL", "MENU_CATEGORY_ONFOOT", "MENU_CATEGORY_CAR", "MENU_CATEGORY_TANK" } --, "MENU_CATEGORY_HELI", "MENU_CATEGORY_PLANE" 
  8.  
  9. local Input_tracker 
  10. local Mouse_input_tracker 
  11.  
  12. local Tween_done = true 
  13. local Overall_action = 1 
  14. local Num_categories = 1 
  15. local Num_actions = 0 
  16.  
  17. local Screen_width 
  18. if vint_is_std_res() then 
  19. 	Screen_width = 750 
  20. else 
  21. 	Screen_width = 840 
  22. end 
  23.  
  24. local STATE_CATEGORIES = 1 
  25. local STATE_SUBMENU = 2 
  26. local Current_state = STATE_CATEGORIES 
  27.  
  28. local MAX_VISIBLE = 10 
  29.  
  30. function vint_options_remap_get_num_actions(actions) 
  31. 	Num_actions = actions 
  32. end 
  33.  
  34. function vint_remap_get_action_binding(action_name, key1, key2) 
  35. 	local t = { 
  36. 		type = TYPE_REMAP, 
  37. 		label = action_name, 
  38. 		value1 = key1, 
  39. 		value2 = key2, 
  40. 	} 
  41. 	if key1 == "" then 
  42. 		t.value1 = nil 
  43. 	end 
  44. 	if key2 == "" then 
  45. 		t.value2 = nil 
  46. 	end 
  47. 	Data[Overall_action] = t 
  48. 	Overall_action = Overall_action + 1 
  49. end 
  50.  
  51. function vint_remap_update_display(sel) 
  52. 	if Current_state ~= STATE_SUBMENU then 
  53. 		return 
  54. 	end 
  55.  
  56. 	Data = { } 
  57. 	-- Always add the category first 
  58. 	--[[Data[1] = { 
  59. 		type = TYPE_TOGGLE, 
  60. 		label = "MENU_CATEGORY", 
  61. 		options = Category_names, 
  62. 		current_value = Remap_category_index, 
  63. 		is_special = true 
  64. 	}]] 
  65. 	local cur_cat = Remap_category_index 
  66.  
  67. 	Num_categories = 7 --vint_options_remap_get_num_categories() 
  68. 	Overall_action = 1 
  69. 	vint_dataresponder_request("vint_options_remap_get_num_actions", "vint_options_remap_get_num_actions", 1, cur_cat) 
  70. 	local action 
  71. 	for action = 1, Num_actions do 
  72. 		vint_dataresponder_request("vint_remap_get_action_binding", "vint_remap_get_action_binding", 2, cur_cat, action) 
  73. 	end 
  74.  
  75. 	-- Remove subscriptions 
  76. 	if Mouse_input_tracker ~= nil then 
  77. 		Mouse_input_tracker:remove_all() 
  78. 	end 
  79.  
  80. 	-- Initialize and draw list object 
  81. 	List:set_properties(nil, nil, nil, nil, nil, nil, true) 
  82. 	List:draw_items(Data, sel, Screen_width, MAX_VISIBLE) 
  83. 	 
  84. 	--Set Button hints 
  85. 	local hint_data = { 
  86. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  87. 		{CTRL_BUTTON_X, "MENU_RESTORE_ALL_DEFAULTS"}, 
  88. 		{CTRL_BUTTON_Y, "OPTIONS_MENU_CLEAR_KEY_TITLE", game_get_key_name(211)}, 
  89. 	} 
  90. 	Menu_hint_bar:set_hints(hint_data) 
  91. 	 
  92. 	-- Re-add subscriptions 
  93. 	if Mouse_input_tracker ~= nil then 
  94. 		List:add_mouse_inputs("options_remap", Mouse_input_tracker) 
  95. 		Menu_hint_bar:add_mouse_inputs("options_remap", Mouse_input_tracker) 
  96. 		Mouse_input_tracker:subscribe(true) 
  97. 	end 
  98. end 
  99.  
  100. function pause_options_remap_set_tool_tip(new_tip_text) 
  101. 	local tool_tip_h = vint_object_find("tool_tip_text", 0, Remap_doc_handle) 
  102. 	vint_set_property(tool_tip_h, "text_tag", new_tip_text) 
  103. end 
  104.  
  105. function pause_options_remap_show_categories() 
  106. 	Data = { } 
  107.  
  108. 	local cat 
  109. 	for cat = 1, #Category_names do 
  110. 		Data[cat] = { 
  111. 			type = TYPE_BUTTON, 
  112. 			label = Category_names[cat], 
  113. 			current_value = 0, 
  114. 			id = cat 
  115. 		} 
  116. 	end 
  117.  
  118. 	-- Remove subscriptions 
  119. 	if Mouse_input_tracker ~= nil then 
  120. 		Mouse_input_tracker:remove_all() 
  121. 	end 
  122.  
  123. 	-- Initialize and draw list object 
  124. 	List:set_properties(nil, nil, nil, nil, nil, nil, true) 
  125. 	List:draw_items(Data, 1, Screen_width, MAX_VISIBLE)	 
  126. 	 
  127. 	--Set Button hints 
  128. 	local hint_data = { 
  129. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  130. 		{CTRL_BUTTON_X, "MENU_RESTORE_ALL_DEFAULTS"}, 
  131. 	} 
  132. 	Menu_hint_bar:set_hints(hint_data) 
  133. 	 
  134. 	-- Re-add subscriptions 
  135. 	if Mouse_input_tracker ~= nil then 
  136. 		List:add_mouse_inputs("options_remap", Mouse_input_tracker) 
  137. 		Menu_hint_bar:add_mouse_inputs("options_remap", Mouse_input_tracker) 
  138. 		Mouse_input_tracker:subscribe(true) 
  139. 	end 
  140. end 
  141.  
  142. function pause_options_remap_init() 
  143. 	Remap_doc_handle = vint_document_find("pause_options_remap") 
  144.  
  145. 	Input_tracker = Vdo_input_tracker:new() 
  146. 	Input_tracker:add_input("select", "options_remap_button_a", 50) 
  147. 	Input_tracker:add_input("back", "options_remap_button_b", 50) 
  148. 	Input_tracker:add_input("alt_select", "options_remap_button_x", 50) 
  149. 	if In_pause_menu then 
  150. 		Input_tracker:add_input("pause", "options_remap_button_start", 50) 
  151. 	end 
  152. 	Input_tracker:add_input("nav_up", "options_remap_nav_up", 50) 
  153. 	Input_tracker:add_input("nav_down", "options_remap_nav_down", 50) 
  154. 	Input_tracker:add_input("nav_left", "options_remap_nav_left", 50) 
  155. 	Input_tracker:add_input("nav_right", "options_remap_nav_right", 50) 
  156. 	Input_tracker:add_input("scancode", "options_remap_button_del", 50, false, 211) 
  157. 	Input_tracker:subscribe(false) 
  158.  
  159. 	--Set Button hints 
  160. 	local hint_data = { 
  161. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  162. 		{CTRL_BUTTON_X, "MENU_RESTORE_ALL_DEFAULTS"}, 
  163. 		{CTRL_BUTTON_Y, "OPTIONS_MENU_CLEAR_KEY_TITLE", game_get_key_name(211)}, 
  164. 	} 
  165. 	Menu_hint_bar:set_hints(hint_data) 
  166.  
  167. 	--Initialize Header 
  168. 	Header_obj:set_text("MENU_OPTIONS_REMAP",Screen_width) 
  169.  
  170. 	--Data[DIFFICULTY_INDEX].current_value = get_current_difficulty() + 1	-- Difficulties start at 0 
  171.  
  172. 	pause_options_remap_show_categories() 
  173. 	--vint_remap_update_display(0) 
  174.  
  175. 	--set up the list in twns 
  176. 	local list_back_in = Vdo_tween_object:new("back_in_twn2", Screen_back_in_anim.handle) 
  177. 	local header_back_in = Vdo_tween_object:new("back_in_twn3", Screen_back_in_anim.handle) 
  178.  
  179. 	list_back_in:set_property("start_value", 100, 140) 
  180. 	header_back_in:set_property("start_value", 130, 83) 
  181.  
  182. 	list_back_in:set_property("end_value", 100, 140) 
  183. 	header_back_in:set_property("end_value", 130, 83) 
  184.  
  185. 	--Store some locals to the pause menu common for screen processing. 
  186. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  187. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim) 
  188.  
  189. 	Menu_hint_bar:set_highlight(0) 
  190.  
  191. 	Mouse_input_tracker = Vdo_input_tracker:new() 
  192. 	List:add_mouse_inputs("options_remap", Mouse_input_tracker) 
  193. 	Menu_hint_bar:add_mouse_inputs("options_remap", Mouse_input_tracker) 
  194. 	Mouse_input_tracker:subscribe(true) 
  195.  
  196. 	local tool_tip_h = vint_object_find("tool_tip_text", 0, Remap_doc_handle) 
  197. 	vint_set_property(tool_tip_h, "alpha", 0) 
  198.  
  199. 	-- Align the tooltip to the list 
  200. 	--[[ 
  201. 	if In_pause_menu then 
  202. 		local anchor_in_h = vint_object_find("new_tween2") 
  203. 		local anchor_out_h = vint_object_find("new_tween4") 
  204. 		local anchor_in_x,anchor_in_y = vint_get_property(anchor_in_h, "start_value") 
  205. 		local anchor_out_x,anchor_out_y = vint_get_property(anchor_out_h, "start_value") 
  206.  
  207. 		if vint_is_std_res() then 
  208. 			vint_set_property(anchor_in_h, "start_value", 282, anchor_in_y) 
  209. 			vint_set_property(anchor_in_h, "end_value", 282, anchor_out_y) 
  210.  
  211. 			vint_set_property(anchor_out_h, "start_value", 282, anchor_out_y) 
  212. 			vint_set_property(anchor_out_h, "end_value", 282, anchor_in_y) 
  213. 		else 
  214. 			vint_set_property(anchor_in_h, "start_value", 448, anchor_in_y) 
  215. 			vint_set_property(anchor_in_h, "end_value", 448, anchor_out_y) 
  216.  
  217. 			vint_set_property(anchor_out_h, "start_value", 448, anchor_out_y) 
  218. 			vint_set_property(anchor_out_h, "end_value", 448, anchor_in_y) 
  219. 		end 
  220. 	end 
  221. 	]] 
  222. 	pause_options_remap_set_tool_tip("MENU_PRIMARY_ASSIGNMENT") --("X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X") -- Use this to figure out the correct anchor for In_pause_menu 
  223. end 
  224.  
  225. function pause_options_remap_cleanup() 
  226. 	-- Nuke all button subscriptions 
  227. 	Input_tracker:subscribe(false) 
  228. 	if Mouse_input_tracker ~= nil then 
  229. 		Mouse_input_tracker:subscribe(false) 
  230. 	end 
  231. 	List:enable_toggle_input(false) 
  232.  
  233. 	--set up the list in twns 
  234. 	local list_back_in = Vdo_tween_object:new("back_in_twn2", Screen_back_in_anim.handle) 
  235. 	local header_back_in = Vdo_tween_object:new("back_in_twn3", Screen_back_in_anim.handle) 
  236.  
  237. 	list_back_in:set_property("start_value", 100, 267) 
  238. 	header_back_in:set_property("start_value", 130, 210) 
  239.  
  240. 	list_back_in:set_property("end_value", 100, 267) 
  241. 	header_back_in:set_property("end_value", 130, 210) 
  242.  
  243. 	--set up the list out twns 
  244. 	local list_slide_out = Vdo_tween_object:new("screen_slide_out_twn2", Screen_slide_out_anim.handle) 
  245. 	local header_slide_out = Vdo_tween_object:new("screen_slide_out_twn3", Screen_slide_out_anim.handle) 
  246.  
  247. 	list_slide_out:set_property("start_value", 100, 267) 
  248. 	header_slide_out:set_property("start_value", 130, 210) 
  249.  
  250. 	list_slide_out:set_property("end_value", 100, 267) 
  251. 	header_slide_out:set_property("end_value", 130, 210) 
  252. end 
  253.  
  254. function options_remap_nav_up(event, acceleration) 
  255. 	-- Move highlight up 
  256. 	List:move_cursor(-1) 
  257. 	options_remap_update_mouse_inputs() 
  258. end 
  259.  
  260. function options_remap_nav_down(event, acceleration) 
  261. 	-- Move highlight down 
  262. 	List:move_cursor(1) 
  263. 	options_remap_update_mouse_inputs() 
  264. end 
  265.  
  266. function options_remap_nav_left(event, acceleration) 
  267. 	local current_idx = List:get_selection() 
  268. 	local menu_item = Data[current_idx] 
  269.  
  270. 	if menu_item.type == TYPE_TOGGLE then 
  271. 		List:move_slider(-1) 
  272.  
  273. 		-- This assumes there's only 1 toggle (for the category) 
  274. 		options_remap_update_category(menu_item.current_value) 
  275. 		pause_options_remap_set_tool_tip("MENU_PRIMARY_ASSIGNMENT") 
  276.  
  277. 	elseif Current_state == STATE_SUBMENU then 
  278. 		List:move_cursor(0, true) 
  279. 		List.buttons[current_idx].remap:set_highlight_column(1) 
  280. 		List.remap_column = 1 
  281. 		pause_options_remap_set_tool_tip("MENU_PRIMARY_ASSIGNMENT") 
  282. 	end 
  283. end 
  284.  
  285. function options_remap_nav_right(event, acceleration) 
  286. 	local current_idx = List:get_selection() 
  287. 	local menu_item = Data[current_idx] 
  288.  
  289. 	if menu_item.type == TYPE_TOGGLE then 
  290. 		List:move_slider(1) 
  291.  
  292. 		-- This assumes there's only 1 toggle (for the category) 
  293. 		options_remap_update_category(menu_item.current_value) 
  294. 		pause_options_remap_set_tool_tip("MENU_PRIMARY_ASSIGNMENT") 
  295. 	elseif Current_state == STATE_SUBMENU then 
  296. 		List:move_cursor(0, true) 
  297. 		List.buttons[current_idx].remap:set_highlight_column(2) 
  298. 		List.remap_column = 2 
  299. 		pause_options_remap_set_tool_tip("MENU_SECONDARY_ASSIGNMENT") 
  300. 	end 
  301. end 
  302.  
  303. function options_remap_update_category(new_index) 
  304. 	Remap_category_index = new_index 
  305. 	vint_remap_update_display(0) 
  306. end 
  307.  
  308. function options_remap_button_b(event, acceleration) 
  309. 	-- If we're in a sub menu, just back out to the category list. 
  310. 	if Current_state == STATE_SUBMENU then 
  311. 		Current_state = STATE_CATEGORIES 
  312. 		pause_options_remap_show_categories() 
  313.  
  314. 		-- animate tooltip out 
  315. 		local anim_h = vint_object_find("animate_out", 0, Remap_doc_handle) 
  316. 		lua_play_anim(anim_h, 0, Remap_doc_handle) 
  317.  
  318. 		return 
  319. 	end 
  320.  
  321. 	--back up a screen 
  322. 	--game_difficulty_select(Data[DIFFICULTY_INDEX].current_value - 1)	-- Difficulties indexed by 0 
  323. 	pause_menu_accept_options() 
  324. 	List:button_b() 
  325.  
  326. 	Input_tracker:subscribe(false) 
  327. 	if Mouse_input_tracker ~= nil then 
  328. 		Mouse_input_tracker:subscribe(false) 
  329. 	end 
  330. 	List:enable_toggle_input(false) 
  331.  
  332. 	--set up the list out twns 
  333. 	local list_slide_out = Vdo_tween_object:new("screen_slide_out_twn2", Screen_slide_out_anim.handle) 
  334. 	local header_slide_out = Vdo_tween_object:new("screen_slide_out_twn3", Screen_slide_out_anim.handle) 
  335.  
  336. 	list_slide_out:set_property("start_value", 100, 140) 
  337. 	header_slide_out:set_property("start_value", 130, 83) 
  338.  
  339. 	list_slide_out:set_property("end_value", 100, 140) 
  340. 	header_slide_out:set_property("end_value", 130, 83) 
  341.  
  342. 	--Remove current menu from the stack 
  343. 	menu_common_stack_remove() 
  344. 	menu_common_transition_pop(1) 
  345.  
  346. end 
  347.  
  348. function options_remap_button_x(event, acceleration) 
  349. 	dialog_box_confirmation("OPTIONS_MENU_DEFAULTS_TITLE", "OPTIONS_MENU_DEFAULTS_DESC", "options_remap_revert", true, true) 
  350. end 
  351.  
  352. function options_remap_revert(result, action) 
  353. 	if result == 0 then 
  354. 		vint_options_remap_reset_bindings() 
  355. 		vint_remap_update_display(1) 
  356. 	end 
  357. end 
  358.  
  359. function options_remap_button_a(event, acceleration) 
  360. 	local current_idx = List:get_selection() 
  361. 	local menu_item = Data[current_idx] 
  362.  
  363. 	if menu_item.type == TYPE_TOGGLE then 
  364. 		options_remap_nav_right() 
  365. 	else 
  366. 		--pass off the input to the list 
  367. 		List:button_a() 
  368.  
  369. 		if menu_item.type == TYPE_BUTTON and Current_state == STATE_CATEGORIES then 
  370. 			Current_state = STATE_SUBMENU 
  371. 			Remap_category_index = menu_item.id 
  372. 			vint_remap_update_display(1) 
  373.  
  374. 			-- animate tooltip in 
  375. 			local anim_h = vint_object_find("animate_in", 0, Remap_doc_handle) 
  376. 			lua_play_anim(anim_h, 0, Remap_doc_handle) 
  377.  
  378. 		end 
  379. 	end 
  380. end 
  381.  
  382. function options_remap_clear_confirm( result ) 
  383. 	if result ~= 0 then 
  384. 		return 
  385. 	end 
  386.  
  387. 	local current_idx = List:get_selection() 
  388. 	local menu_item = Data[current_idx] 
  389.  
  390. 	if menu_item.type == TYPE_REMAP then 
  391. 		vint_options_remap_clear_key_binding(Remap_category_index, current_idx - 1) 
  392.  
  393. 		local button = List.buttons[ current_idx ].remap 
  394.  
  395. 		button.value_text[1]:set_text("--") 
  396. 		button.value_text[1]:set_visible(true) 
  397. 		button.value_button[1]:set_visible(false) 
  398.  
  399. 		button.value_text[2]:set_text("--") 
  400. 		button.value_text[2]:set_visible(true) 
  401. 		button.value_button[2]:set_visible(false) 
  402. 	end 
  403. end 
  404.  
  405. function options_remap_button_del() 
  406. 	local current_idx = List:get_selection() 
  407. 	local menu_item = Data[current_idx] 
  408.  
  409. 	if menu_item.type == TYPE_REMAP then 
  410. 		local body = vint_insert_values_in_string("OPTIONS_MENU_CLEAR_KEY_BODY", { [0] = menu_item.label }) 
  411.  
  412. 		dialog_box_confirmation("OPTIONS_MENU_CLEAR_KEY_TITLE", body, "options_remap_clear_confirm", true, true) 
  413. 	end 
  414. end 
  415.  
  416. function options_remap_button_start(event, acceleration) 
  417. 	menu_common_transition_pop(4) -- options_remap, options, pause_menu_top, menu_common 
  418. end 
  419.  
  420. -- Mouse inputs 
  421. function options_remap_mouse_click(event, target_handle, mouse_x, mouse_y) 
  422. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  423. 	if hint_index == 1 then 
  424. 		options_remap_button_b() 
  425. 	elseif hint_index == 2 then 
  426. 		options_remap_button_x() 
  427. 	end 
  428.  
  429. 	local new_index = List:get_button_index(target_handle) 
  430. 	if new_index ~= 0 then 
  431. 		List:set_selection(new_index) 
  432. 		options_remap_button_a() 
  433. 	end 
  434.  
  435. 	local index, button, column = List:get_remap_index(target_handle) 
  436. 	if column ~= 0 then 
  437. 		List:set_selection(index) 
  438. 		List:move_cursor(0, true) 
  439. 		button:set_highlight_column(column) 
  440. 		if column == 1 then 
  441. 			pause_options_remap_set_tool_tip("MENU_PRIMARY_ASSIGNMENT") 
  442. 		else 
  443. 			pause_options_remap_set_tool_tip("MENU_SECONDARY_ASSIGNMENT") 
  444. 		end 
  445. 		options_remap_button_a() 
  446. 	end 
  447. 	if List:is_left_arrow(target_handle) then 
  448. 		options_remap_nav_left() 
  449. 	end 
  450. end 
  451.  
  452. function options_remap_mouse_move(event, target_handle) 
  453. 	Menu_hint_bar:set_highlight(0) 
  454.  
  455. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  456. 	if hint_index ~= 0 and Menu_hint_bar.hint_data[hint_index][2] ~= "OPTIONS_MENU_CLEAR_KEY_TITLE" then 
  457. 		Menu_hint_bar:set_highlight(hint_index) 
  458. 	end 
  459.  
  460. 	local new_index = List:get_button_index(target_handle) 
  461. 	if new_index ~= 0 then 
  462. 		List:set_selection(new_index) 
  463. 		List:move_cursor(0, true) 
  464. 	end 
  465.  
  466. 	local index, button, column = List:get_remap_index(target_handle) 
  467. 	if column ~= 0 then 
  468. 		List:set_selection(index) 
  469. 		List:move_cursor(0, true) 
  470. 		button:set_highlight_column(column) 
  471. 		if column == 1 then 
  472. 			pause_options_remap_set_tool_tip("MENU_PRIMARY_ASSIGNMENT") 
  473. 		else 
  474. 			pause_options_remap_set_tool_tip("MENU_SECONDARY_ASSIGNMENT") 
  475. 		end 
  476. 		-- Activate remapping 
  477. 	end 
  478. end 
  479.  
  480. function options_remap_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  481. 	if scroll_lines ~= 0 then 
  482. 		if List:get_scroll_region_handle() == target_handle then 
  483. 			List:scroll_list(scroll_lines * -1) 
  484. 			options_remap_update_mouse_inputs() 
  485. 		end 
  486. 	end 
  487. end 
  488.  
  489. function options_remap_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  490. 	if List.scrollbar.tab_grp.handle == target_handle then 
  491. 		local new_start_index = List.scrollbar:drag_scrolltab(mouse_y, List.num_buttons - (List.max_buttons - 1)) 
  492. 		List:scroll_list(0, new_start_index) 
  493. 	end 
  494. end 
  495.  
  496. -- Updates the mouse inputs for the list and snaps the scrolltab to the closest notch based on the visible index 
  497. -- 
  498. function  options_remap_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  499. 	if List.scrollbar.tab_grp.handle == target_handle then 
  500. 		local start_index = List:get_visible_indices() 
  501. 		List.scrollbar:release_scrolltab(start_index, List.num_buttons - (List.max_buttons - 1)) 
  502. 		options_remap_update_mouse_inputs() 
  503. 	end 
  504. end 
  505.  
  506. function options_remap_update_mouse_inputs() 
  507. 	List:update_mouse_inputs("options_remap", Mouse_input_tracker) 
  508. 	Menu_hint_bar:add_mouse_inputs("options_remap", Mouse_input_tracker) 
  509. 	Mouse_input_tracker:subscribe(true) 
  510. end 
  511.