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