./pause_options_clip_select.lua

  1. local Data = { } 
  2.  
  3. local Clip_select_doc_handle 
  4. local Input_tracker 
  5. local Mouse_input_tracker 
  6.  
  7. local Tween_done = true 
  8. local Num_clips = 0 
  9. local Current_clip = 1 
  10.  
  11. function vint_clip_select_get_num_clips(clips) 
  12. 	Num_clips = clips 
  13. end 
  14.  
  15. local Screen_width = 700 
  16.  
  17. function vint_clip_select_get_clip_data(clip_name, clip_info) 
  18. 	local t = { 
  19. 		type = TYPE_BUTTON, 
  20. 		label = clip_name, 
  21. 		tool_tip_text = clip_info 
  22. 	} 
  23. 	Data[Current_clip] = t 
  24. 	Current_clip = Current_clip + 1 
  25. end 
  26.  
  27. function vint_clip_select_get_clips(clip_name, clip_description) 
  28. 	Data[#Data+1] = { 
  29. 			type = TYPE_BUTTON, 
  30. 			label = clip_name, 
  31. 			tool_tip_text = clip_description 
  32. 		} 
  33. end 
  34.  
  35. function options_clip_select_update_build_list() 
  36. 	Data = {} 
  37.  
  38. 	vint_dataresponder_request("vint_clip_select_get_clips_responder", "vint_clip_select_get_clips", 0) 
  39.  
  40. 	-- Remove subscriptions 
  41. 	if Mouse_input_tracker ~= nil then 
  42. 		Mouse_input_tracker:remove_all() 
  43. 	end 
  44. 	 
  45. 	-- Initialize and draw list object 
  46. 	List:draw_items(Data, 1, Screen_width - 15, 10) 
  47. 	 
  48. 	-- Re-add subscriptions 
  49. 	if Mouse_input_tracker ~= nil then 
  50. 		List:add_mouse_inputs("pause_options_clip_select", Mouse_input_tracker) 
  51. 		Menu_hint_bar:add_mouse_inputs("pause_options_clip_select", Mouse_input_tracker) 
  52. 		Mouse_input_tracker:subscribe(true) 
  53. 	end 
  54. end 
  55.  
  56. function pause_options_clip_select_init() 
  57. 	options_clip_select_update_build_list() 
  58.  
  59. 	Clip_select_doc_handle = vint_document_find("pause_options_clip_select") 
  60. 	Input_tracker = Vdo_input_tracker:new() 
  61. 	Input_tracker:add_input("select", "options_clip_select_button_a", 50) 
  62. 	Input_tracker:add_input("back", "options_clip_select_button_b", 50) 
  63. 	if In_pause_menu then 
  64. 		Input_tracker:add_input("pause", "options_clip_select_button_start", 50) 
  65. 	end 
  66. 	Input_tracker:add_input("nav_up", "options_clip_select_nav_up", 50) 
  67. 	Input_tracker:add_input("nav_down", "options_clip_select_nav_down", 50) 
  68. 	Input_tracker:subscribe(false) 
  69. 	 
  70. 	--Set Button hints 
  71. 	local hint_data = { 
  72. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  73. 	} 
  74. 	Menu_hint_bar:set_hints(hint_data)   
  75. 	 
  76. 	--Initialize Header 
  77. 	Header_obj:set_text("MENU_OPTIONS_CLIP_SELECT") 
  78. 	 
  79. 	if First_time then 
  80. 		Screen_in_anim:play(0) 
  81. 		bg_saints_slide_in(Screen_width) 
  82. 		First_time = false 
  83. 	end 
  84. 	 
  85. 	--Store some locals to the pause menu common for screen processing. 
  86. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  87. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim) 
  88. 	 
  89. 	Menu_hint_bar:set_highlight(0) 
  90. 	 
  91. 	Mouse_input_tracker = Vdo_input_tracker:new() 
  92. 	List:add_mouse_inputs("pause_options_clip_select", Mouse_input_tracker) 
  93. 	Menu_hint_bar:add_mouse_inputs("pause_options_clip_select", Mouse_input_tracker) 
  94. 	Mouse_input_tracker:subscribe(true) 
  95. 	 
  96. 	pause_options_clip_select_set_tool_tip(Data[1].tool_tip_text) --("X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X") -- Use this to figure out the correct anchor for In_pause_menu 
  97. end 
  98.  
  99. function pause_options_clip_select_set_tool_tip(new_tip_text) 
  100. 	local tool_tip_h = vint_object_find("tool_tip_text", 0, Clip_select_doc_handle) 
  101. 	vint_set_property(tool_tip_h, "text_tag", new_tip_text) 
  102. end 
  103.  
  104. function pause_options_clip_select_cleanup() 
  105. 	-- Nuke all button subscriptions 
  106. 	Input_tracker:subscribe(false) 
  107. 	if Mouse_input_tracker ~= nil then 
  108. 		Mouse_input_tracker:subscribe(false) 
  109. 	end 
  110. 	List:enable_toggle_input(false) 
  111. end 
  112.  
  113. function options_clip_select_nav_up(event, acceleration) 
  114. 	-- Move highlight up 
  115. 	List:move_cursor(-1) 
  116. 	options_clip_select_update_mouse_inputs() 
  117. 	 
  118. 	-- Set the tool_tip_text 
  119. 	local current_idx = List:get_selection() 
  120. 	local menu_item = Data[current_idx] 
  121. 	pause_options_clip_select_set_tool_tip(menu_item.tool_tip_text) 
  122. end 
  123.  
  124. function options_clip_select_nav_down(event, acceleration) 
  125. 	-- Move highlight down 
  126. 	List:move_cursor(1) 
  127. 	options_clip_select_update_mouse_inputs() 
  128. 	 
  129. 	-- Set the tool_tip_text 
  130. 	local current_idx = List:get_selection() 
  131. 	local menu_item = Data[current_idx] 
  132. 	pause_options_clip_select_set_tool_tip(menu_item.tool_tip_text) 
  133. end 
  134.  
  135. function options_clip_select_button_b(event, acceleration) 
  136. 	--back up a screen 
  137. 	--game_difficulty_select(Data[DIFFICULTY_INDEX].current_value - 1)	-- Difficulties indexed by 0 
  138. 	pause_menu_accept_options() 
  139. 	List:button_b() 
  140.  
  141. 	Input_tracker:subscribe(false) 
  142. 	if Mouse_input_tracker ~= nil then 
  143. 		Mouse_input_tracker:subscribe(false) 
  144. 	end 
  145. 	List:enable_toggle_input(false) 
  146. 	 
  147. 	--Remove current menu from the stack 
  148. 	menu_common_stack_remove() 
  149. 	menu_common_transition_pop(1) 
  150. end 
  151.  
  152. -- Defines for clip options 
  153. local OPTION_EDIT = 0 
  154. local OPTION_CLONE = 1 
  155. local OPTION_DELETE = 2 
  156. local OPTION_CANCEL = 3 
  157.  
  158. local DELETE_CANCEL = 0 
  159. local DELETE_CONFIRM = 1 
  160.  
  161. function options_clip_select_button_a(event, acceleration) 
  162. 	-- Display the options for editing a clip in a dialog box 
  163. 	local options = { 
  164. 		[OPTION_EDIT] = "PC_CA_EDIT_EXPORT", 
  165. 		[OPTION_CLONE] = "PC_CA_CLONE", 
  166. 		[OPTION_DELETE] = "PC_CA_DELETE",	 
  167. 		[OPTION_CANCEL] = "PC_CA_CANCEL",			 
  168. 	} 
  169. 	 
  170. 	local cur_selection = List:get_selection() 
  171. 	dialog_box_open(Data[cur_selection].label, "PC_CLIP_ACTIONS", options, "options_clip_select_dialog_cb", 0, DIALOG_PRIORITY_ACTION) 
  172. end 
  173.  
  174. function options_clip_select_dialog_cb(result, action) 
  175. 	-- TODO: Make these options work (or remove them, particularly CLONE) 
  176. 	if result == OPTION_EDIT then 
  177. 		game_machinima_playback_enter(Data[List:get_selection()].label) 
  178. 		 
  179. 	elseif result == OPTION_CLONE then 
  180. 		game_vkeyboard_input("SAVE_CLIP", "SAVE_CLIP_NAME", 64, "SAVE_CLIP", "options_clip_select_copy_cb", true) 
  181.  
  182. 	elseif result == OPTION_DELETE then 
  183. 		dialog_box_confirmation(Data[List:get_selection()].label, "PC_CLIP_DELETE_CONFIRM", "options_clip_delete_cb", nil, nil, 1) 
  184. 	 
  185. 	elseif result == OPTION_CANCEL then 
  186. 	 
  187. 	end 
  188. end 
  189.  
  190. function options_clip_select_copy_cb(success) 
  191. 	if success == true then 
  192. 		if game_machinima_clip_exists("VKEYBOARD_RESULTS") == true then 
  193. 			dialog_box_confirmation(Data[List:get_selection()].label, "PC_CLIP_OVERWRITE_CONFIRM", "options_clip_overwrite_cb", nil, nil, 1) 
  194. 			 
  195. 		else 
  196. 			game_machinima_copy_clip(Data[List:get_selection()].label, "VKEYBOARD_RESULTS") 
  197. 			options_clip_select_update_build_list() 
  198. 		end 
  199. 	end 
  200. end 
  201.  
  202. function options_clip_overwrite_cb(result, action) 
  203. 	if result == 0 then 
  204. 		game_machinima_overwrite_clip(Data[List:get_selection()].label, "VKEYBOARD_RESULTS") 
  205. 		options_clip_select_update_build_list() 
  206. 	end 
  207. end 
  208.  
  209. function options_clip_delete_cb(result, action) 
  210. 	if result == 0 then 
  211. 		game_machinima_delete_clip(Data[List:get_selection()].label) 
  212. 		options_clip_select_update_build_list() 
  213. 	end 
  214. end 
  215.  
  216. function options_clip_select_button_start(event, acceleration) 
  217. 	menu_common_transition_pop(3) -- options_clip_select, pause_menu_top, menu_common 
  218. end 
  219.  
  220. -- Mouse inputs 
  221. function pause_options_clip_select_mouse_click(event, target_handle, mouse_x, mouse_y) 
  222. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  223. 	if hint_index == 1 then 
  224. 		options_clip_select_button_b() 
  225. 	end 
  226.  
  227. 	local new_index = List:get_button_index(target_handle) 
  228. 	if new_index ~= 0 then 
  229. 		options_clip_select_button_a() 
  230. 	end 
  231. end 
  232.  
  233. function pause_options_clip_select_mouse_move(event, target_handle) 
  234. 	Menu_hint_bar:set_highlight(0) 
  235. 	 
  236. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  237. 	if hint_index ~= 0 then 
  238. 		Menu_hint_bar:set_highlight(hint_index) 
  239. 	end 
  240. 	 
  241. 	local new_index = List:get_button_index(target_handle) 
  242. 	if new_index ~= 0 then 
  243. 		List:set_selection(new_index) 
  244. 		List:move_cursor(0, true) 
  245. 		 
  246. 		-- Set the tool_tip_text 
  247. 		local menu_item = Data[new_index] 
  248. 		pause_options_clip_select_set_tool_tip(menu_item.tool_tip_text) 
  249. 	end 
  250. end 
  251.  
  252. function options_clip_select_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  253. 	if scroll_lines ~= 0 then 
  254. 		if List:get_scroll_region_handle() == target_handle then 
  255. 			List:scroll_list(scroll_lines * -1) 
  256. 			options_clip_select_update_mouse_inputs() 
  257. 		end 
  258. 	end 
  259. end 
  260.  
  261. function options_clip_select_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  262. 	if List.scrollbar.tab_grp.handle == target_handle then 
  263. 		local new_start_index = List.scrollbar:drag_scrolltab(mouse_y, List.num_buttons - (List.max_buttons - 1)) 
  264. 		List:scroll_list(0, new_start_index) 
  265. 	end 
  266. end 
  267.  
  268. -- Updates the mouse inputs for the list and snaps the scrolltab to the closest notch based on the visible index 
  269. -- 
  270. function  options_clip_select_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  271. 	if List.scrollbar.tab_grp.handle == target_handle then 
  272. 		local start_index = List:get_visible_indices() 
  273. 		List.scrollbar:release_scrolltab(start_index, List.num_buttons - (List.max_buttons - 1)) 
  274. 		options_clip_select_update_mouse_inputs() 
  275. 	end 
  276. end 
  277.  
  278. function options_clip_select_update_mouse_inputs() 
  279. 	List:update_mouse_inputs("pause_options_clip_select", Mouse_input_tracker) 
  280. 	Menu_hint_bar:add_mouse_inputs("pause_options_clip_select", Mouse_input_tracker) 
  281. 	Mouse_input_tracker:subscribe(true) 
  282. end 
  283.