./cinema_clip_manager.lua

  1. -- Global variables 
  2. local Active_list 
  3. local Cinema_clip_manager_doc_handle = -1 
  4. local Input_tracker 
  5. local Mouse_input_tracker 
  6. local Hint_bar 
  7.  
  8. -- Fake enumerations for clips  
  9. local CLIP1 	= 1 
  10. local CLIP2		= 2 
  11. local CLIP3		= 3 
  12. local CLIP4		= 4 
  13.  
  14. -- Fake data for clips, to be replaced by data from the game (eventually) 
  15. local Data = { 
  16. 	[CLIP1] = { 
  17. 		type = TYPE_BUTTON, 
  18. 		label = "CLIP_1", 
  19. 		id = CLIP1, 
  20. 		clip_date = "!!11/15/11", 
  21. 		location = "!!STEELPORT ACADEMY", 
  22. 		edited = false, 
  23. 		exported = false, 
  24. 		clip_image = "ui_pc_arrow", 
  25. 	},	 
  26. 	[CLIP2] = { 
  27. 		type = TYPE_BUTTON, 
  28. 		label = "CLIP_2", 
  29. 		id = CLIP2, 
  30. 		clip_date = "!!11/14/11", 
  31. 		location = "!!NEW BARANEC", 
  32. 		edited = true, 
  33. 		exported = false,	 
  34. 		clip_image = "ui_homie_gat",		 
  35. 	},	 
  36. 	[CLIP3] = { 
  37. 		type = TYPE_BUTTON, 
  38. 		label = "CLIP_3", 
  39. 		id = CLIP3, 
  40. 		clip_date = "!!11/13/11", 
  41. 		location = "!!PHILIPS TOWER", 
  42. 		edited = true, 
  43. 		exported = true,	 
  44. 		clip_image = "ui_homie_pierce", 
  45. 	},	 
  46. 	[CLIP4] = { 
  47. 		type = TYPE_BUTTON, 
  48. 		label = "CLIP_4", 
  49. 		id = CLIP4, 
  50. 		clip_date = "!!11/13/11", 
  51. 		location = "!!HARRISBURG", 
  52. 		edited = false, 
  53. 		exported = true,	 
  54. 		clip_image = "ui_homie_shaundi", 
  55. 	},	 
  56. } 
  57.  
  58. function cinema_clip_manager_init() 
  59. 	Cinema_clip_manager_doc_handle = vint_document_find("cinema_clip_manager") 
  60. 	 
  61. 	-- Init the visual elements 
  62. 	Active_list = Vdo_mega_list:new("active_list", 0, Cinema_clip_manager_doc_handle) 
  63. 	Active_list:set_highlight_color(COLOR_SAINTS_PURPLE) 
  64. 	 
  65. 	Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Cinema_clip_manager_doc_handle) 
  66. 	local hint_data = {	 
  67. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"},			 
  68. 	} 
  69. 	Hint_bar:set_hints(hint_data)  
  70. 	Hint_bar:set_highlight(0)	-- Mouse-specific 
  71.  
  72. 	cinema_clip_manager_populate_list(Data) 
  73. 	cinema_clip_manager_clip_info_update() 
  74.  
  75. 	-- Keyboard/gamepad controls 
  76. 	Input_tracker = Vdo_input_tracker:new() 
  77. 	Input_tracker:add_input("select", "cinema_clip_manager_nav_a", 50) 
  78. 	Input_tracker:add_input("back", "cinema_clip_manager_nav_b", 50) 
  79. 	Input_tracker:add_input("nav_up", "cinema_clip_manager_nav_up", 50) 
  80. 	Input_tracker:add_input("nav_down", "cinema_clip_manager_nav_down", 50) 
  81. 	--Input_tracker:add_input("nav_left", "cinema_clip_manager_nav_left", 50) 
  82. 	--Input_tracker:add_input("nav_right", "cinema_clip_manager_nav_right", 50)	 
  83. 	Input_tracker:subscribe(true) 
  84. 	 
  85. 	-- Mouse controls 
  86. 	if game_get_platform() == "PC" then 
  87. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  88. 		Active_list:add_mouse_inputs("cinema_clip_manager", Mouse_input_tracker) 
  89. 		Hint_bar:add_mouse_inputs("cinema_clip_manager", Mouse_input_tracker) 
  90. 		Mouse_input_tracker:subscribe(true) 
  91. 	end 
  92. end 
  93.  
  94.  
  95. function cinema_clip_manager_cleanup() 
  96. 	Input_tracker:subscribe(false) 
  97. 	 
  98. 	if Mouse_input_tracker ~= nil then 
  99. 		Mouse_input_tracker:subscribe(false) 
  100. 	end 
  101. end 
  102.  
  103.  
  104. function cinema_clip_manager_populate_list(data) 
  105. 	Active_list:draw_items(data, 1, 660) 
  106. end 
  107.  
  108. -- Defines for clip options 
  109. local OPTION_EDIT = 0 
  110. local OPTION_CLONE = 1 
  111. local OPTION_DELETE = 2 
  112. local OPTION_CANCEL = 3 
  113.  
  114. function cinema_clip_manager_nav_a(event, acceleration) 
  115. 	-- Display the options for editing a clip in a dialog box 
  116. 	local options = { 
  117. 		[OPTION_EDIT] = "PC_CA_EDIT_EXPORT", 
  118. 		[OPTION_CLONE] = "PC_CA_CLONE", 
  119. 		[OPTION_DELETE] = "PC_CA_DELETE",	 
  120. 		[OPTION_CANCEL] = "PC_CA_CANCEL",			 
  121. 	} 
  122. 	 
  123. 	local cur_selection = Active_list:get_selection() 
  124. 	 
  125. 	dialog_box_open("PC_CLIP_ACTIONS", Data[cur_selection].label, options, "cinema_clip_manager_cb", 0, DIALOG_PRIORITY_ACTION) 
  126. 	-- TODO: Remove this if dialog box takes focus from Mouse_input_tracker like it does for Input_tracker 
  127. 	if Mouse_input_tracker ~= nil then 
  128. 		Mouse_input_tracker:subscribe(false) 
  129. 	end 
  130. end 
  131.  
  132. function cinema_clip_manager_cb(result, action) 
  133. 	if result == OPTION_EDIT then 
  134. 	-- TODO: Remove this if dialog box takes focus from Mouse_input_tracker like it does for Input_tracker 
  135. 		if Mouse_input_tracker ~= nil then 
  136. 			Mouse_input_tracker:subscribe(true) 
  137. 		end 
  138. 	elseif result == OPTION_CLONE then 
  139. 	-- TODO: Remove this if dialog box takes focus from Mouse_input_tracker like it does for Input_tracker 
  140. 		if Mouse_input_tracker ~= nil then 
  141. 			Mouse_input_tracker:subscribe(true) 
  142. 		end 
  143. 	elseif result == OPTION_DELETE then 
  144. 	-- TODO: Remove this if dialog box takes focus from Mouse_input_tracker like it does for Input_tracker 
  145. 		if Mouse_input_tracker ~= nil then 
  146. 			Mouse_input_tracker:subscribe(true) 
  147. 		end 
  148. 	elseif result == OPTION_CANCEL then 
  149. 	-- TODO: Remove this if dialog box takes focus from Mouse_input_tracker like it does for Input_tracker 
  150. 		if Mouse_input_tracker ~= nil then 
  151. 			Mouse_input_tracker:subscribe(true) 
  152. 		end 
  153. 	end 
  154. 	 
  155. end 
  156.  
  157. function cinema_clip_manager_nav_b(event, acceleration) 
  158. 	-- Close the screen 
  159. 	pop_screen() 
  160. end 
  161.  
  162.  
  163. function cinema_clip_manager_nav_up(event, acceleration) 
  164. 	-- Move highlight up 
  165. 	Active_list:move_cursor(-1) 
  166. 	 
  167. 	cinema_clip_manager_clip_info_update() 
  168. end 
  169.  
  170. function cinema_clip_manager_nav_down(event, acceleration) 
  171. 	-- Move highlight down 
  172. 	Active_list:move_cursor(1) 
  173. 	 
  174. 	cinema_clip_manager_clip_info_update() 
  175. end 
  176.  
  177. function cinema_clip_manager_nav_left(event, acceleration) 
  178. 	-- Move highlight left 
  179. 	Active_list:move_slider(-1) 
  180. end 
  181.  
  182. function cinema_clip_manager_nav_right(event, acceleration) 
  183. 	-- Move highlight right 
  184. 	Active_list:move_slider(1) 
  185. end 
  186.  
  187. -- Mouse events (auto-generated by add_mouse_inputs) 
  188. function  cinema_clip_manager_mouse_click(event, target_handle) 
  189. 	-- First check if the target_handle is in the hint bar 
  190. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  191. 	if hint_index == 1 then 
  192. 		cinema_clip_manager_nav_b() 
  193. 	end 
  194.  
  195. 	local new_index = Active_list:get_button_index(target_handle) 
  196. 	if new_index ~= 0 then 
  197. 		-- Enter an option if the target_handle is in the Active_list 
  198. 		Active_list:set_selection(new_index) 
  199. 		cinema_clip_manager_nav_a() 
  200. 	end 
  201. end 
  202.  
  203. function  cinema_clip_manager_mouse_move(event, target_handle) 
  204. 	-- Reset highlight for hint bar 
  205. 	Hint_bar:set_highlight(0) 
  206. 	 
  207. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  208. 	if hint_index ~= 0 then 
  209. 		Hint_bar:set_highlight(hint_index) 
  210. 	end 
  211. 	 
  212. 	local new_index = Active_list:get_button_index(target_handle) 
  213. 	if new_index ~= 0 then 
  214. 		-- Set the button as the new selected highlight 
  215. 		Active_list:set_selection(new_index) 
  216. 		Active_list:move_cursor(0, true) 
  217. 	end 
  218. end 
  219.  
  220. function cinema_clip_manager_clip_info_update() 
  221. 	 
  222. 	local cur_selection = Active_list:get_selection() 
  223. 	 
  224. 	-- Get the vint handles for the objects needed 
  225. 	local date_txt_h = vint_object_find("date_txt", 0, Cinema_clip_manager_doc_handle) 
  226. 	local location_txt_h = vint_object_find("location_txt", 0, Cinema_clip_manager_doc_handle) 
  227. 	local edited_txt_h = vint_object_find("edited_txt", 0, Cinema_clip_manager_doc_handle) 
  228. 	local exported_txt_h = vint_object_find("exported_txt", 0, Cinema_clip_manager_doc_handle) 
  229. 	local clip_image_h = vint_object_find("clip_img", 0, Cinema_clip_manager_doc_handle) 
  230. 	 
  231. 	-- Set the date and location 
  232. 	vint_set_property(date_txt_h, "text_tag", Data[cur_selection].clip_date) 
  233. 	vint_set_property(location_txt_h, "text_tag", Data[cur_selection].location) 
  234. 		 
  235. 	-- Set the edited and exported text 
  236. 	if Data[cur_selection].edited then 
  237. 		vint_set_property(edited_txt_h, "text_tag", "OPTION_YES") 
  238. 	else 
  239. 		vint_set_property(edited_txt_h, "text_tag", "OPTION_NO") 
  240. 	end 
  241. 	if Data[cur_selection].exported then 
  242. 		vint_set_property(exported_txt_h, "text_tag", "OPTION_YES") 
  243. 	else 
  244. 		vint_set_property(exported_txt_h, "text_tag", "OPTION_NO") 
  245. 	end 
  246. 	 
  247. 	-- Set the image (Re-enable this once we're saving/loading the data) 
  248. 	-- Make sure it scales correctly too (if it's blank by default, etc) 
  249. 	-- vint_set_property(clip_image, "image", Data[cur_selection].clip_image)		 
  250. 	 
  251. end