./cell_camera.lua

  1. local Input_tracker 
  2. local Mouse_input_tracker 
  3. local Hint_bar  
  4.  
  5. local Camera_menu_data = { 
  6. 	[1] = { label = "CELL_CAMERA_MODE_TITLE", type = TYPE_TOGGLE, id = 1, current_value = 1, options = {"CELL_CAMERA_MODE_ENABLED", "CELL_CAMERA_MODE_DISABLED"} },	 
  7. } 
  8.  
  9. Camera_list = 0 
  10. Cell_camera_doc_handle = -1 
  11. local CHEATS_LIST_WIDTH 
  12.  
  13. function cell_camera_init() 
  14. 	--Get our document handle... 
  15. 	Cell_camera_doc_handle = vint_document_find("cell_camera") 
  16. 	 
  17. 	--Ask c++ if our camera is enabled... 
  18. 	local camera_enabled = cell_camera_is_enabled() 
  19. 	 
  20. 	--Set our menu to reflect game data... 
  21. 	if camera_enabled == true then 
  22. 		Camera_menu_data[1].current_value = 1 
  23. 	else 
  24. 		Camera_menu_data[1].current_value = 2 
  25. 	end 
  26. 	 
  27. 	--Format our screen... 
  28.  
  29. 	--Align web info... 
  30. 	local data = { 
  31. 		{h = vint_object_find("web_title_txt"), 	type = VINT_OBJECT_TEXT, space = 0}, 
  32. 		{h = vint_object_find("web_desc_txt"), 	type = VINT_OBJECT_TEXT, space = 0}, 
  33. 	} 
  34. 	local width, height = vint_align_elements(data, true) 
  35. 		 
  36. 	local web_info_bg_h = vint_object_find("web_info_bg") 
  37. 	local bg_width, bg_height = element_get_actual_size(web_info_bg_h) 
  38. 	height = height + 15 --(add padding for height) 
  39. 	element_set_actual_size(web_info_bg_h, bg_width, height) 
  40. 	 
  41. 	local web_info_grp_h = vint_object_find("web_info_grp") 
  42. 	local x, y = vint_get_property(web_info_grp_h, "anchor") 
  43. 	 
  44. 	local bottom_y = 370	--bottom of the screen 
  45. 	y = bottom_y - height	--subtract up to place... 
  46. 	vint_set_property(web_info_grp_h, "anchor", x, y) 
  47.  
  48. 	--Align description/how to... 
  49. 	local description_1_txt_h = vint_object_find("description_1_txt") 
  50. 	local description_x, description_y = vint_get_property(description_1_txt_h, "anchor") 
  51. 	local description_width, description_height = element_get_actual_size(description_1_txt_h) 
  52. 	 
  53. 	local camera_hint_grp_h = vint_object_find("camera_hint_grp") 
  54. 	local camera_hint_x, camera_hint_y = vint_get_property(camera_hint_grp_h, "anchor") 
  55. 	 
  56. 	local camera_hint_y = description_y + description_height + ((y - (description_y + description_height))*.4)  
  57. 	 
  58. 	vint_set_property(camera_hint_grp_h, "anchor", camera_hint_x, camera_hint_y) 
  59. 	 
  60. 	--set control image... 
  61. 	local camera_hint_icon_vdo = Vdo_hint_button:new( "camera_hint_icon" ) 
  62. 	camera_hint_icon_vdo:set_button( CTRL_BUTTON_DPAD_DOWN, game_get_key_name_for_action( "CBA_GAC_TAKE_SCREENSHOT" ), false, false) 
  63. 	 
  64. 	local hint_icon_w,hint_icon_h = camera_hint_icon_vdo:get_property( "screen_size" ) 
  65. 	local adjusted_hint_x = hint_icon_w * 0.5 
  66. 	 
  67. 	camera_hint_icon_vdo:set_property( "anchor", adjusted_hint_x, 0 ) 
  68. 	 
  69. 	local camera_hint_icon_bmp_h = vint_object_find( "camera_hint_icon_bmp" ) 
  70. 	vint_set_property( camera_hint_icon_bmp_h, "anchor", hint_icon_w + 6, 0 ) 
  71. 	 
  72. 	--Build our megalist...	 
  73. 	Camera_list = Vdo_mega_list:new("camera_list", 0, Cell_camera_doc_handle, "cell_camera.lua", "Camera_list") 
  74. 	Camera_list:set_properties(COLOR_CHEATS_PRIMARY, COLOR_CHEATS_SECONDARY, 10, .8, 364, false, false)	 
  75. 	Camera_list:draw_items(Camera_menu_data, 1) 
  76.  
  77. 	-- Subscribe to the button presses we need 
  78. 	Input_tracker = Vdo_input_tracker:new() 
  79. 	Input_tracker:add_input("map", "cell_camera_button_map", 50) 
  80. 	Input_tracker:add_input("back", "cell_camera_button_b", 50) 
  81. 	Input_tracker:add_input("nav_up", "cell_camera_nav", 50) 
  82. 	Input_tracker:add_input("nav_down", "cell_camera_nav", 50) 
  83. 	Input_tracker:add_input("nav_left", "cell_camera_nav_left_right", 50) 
  84. 	Input_tracker:add_input("nav_right", "cell_camera_nav_left_right", 50) 
  85. 	Input_tracker:subscribe(true) 
  86. 	 
  87. 	--[[ 
  88. 	local action_hint_data = { 
  89. 		{CTRL_BUTTON_DPAD_DOWN, "CELL_CAMERA_MODE_TAKE_SNAPSHOT"}, 
  90. 	} 
  91. 	local action_hint_bar = Vdo_hint_bar:new("action_hint") 
  92. 	action_hint_bar:set_hints(action_hint_data) 
  93. 	]] 
  94. 	 
  95. 	local hint_data = { 
  96. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  97. 	} 
  98. 	Hint_bar = Vdo_hint_bar:new("hint_bar") 
  99. 	Hint_bar:set_hints(hint_data) 
  100. 	 
  101. 	if game_get_platform() == "PC" then 
  102. 		Hint_bar:set_highlight(0) 
  103. 		 
  104. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  105. 		Camera_list:add_mouse_inputs("cell_camera", Mouse_input_tracker) 
  106. 		Hint_bar:add_mouse_inputs("cell_camera", Mouse_input_tracker) 
  107. 		Mouse_input_tracker:subscribe(true) 
  108. 	end 
  109. 	 
  110. 	--Transition the screen in... 
  111. 	cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_CAMERA, CELL_SCREEN_MAIN, nil) 
  112. end 
  113.  
  114. function cell_camera_nav(event) 
  115. 	if event == "nav_up" then 
  116. 		Camera_list:move_cursor(-1) 
  117. 	elseif event == "nav_down" then 
  118. 		Camera_list:move_cursor(1) 
  119. 	end 
  120. end 
  121.  
  122. function cell_camera_nav_left_right(event) 
  123. 	if event == "nav_left" then 
  124. 		Camera_list:move_slider(1) 
  125. 	elseif event == "nav_right" then 
  126. 		Camera_list:move_slider(-1) 
  127. 	end 
  128. 	 
  129. 	local toggle_selection = Camera_list:get_toggle_selection() 
  130. 	 
  131. 	if toggle_selection == 1 then 
  132. 		--enabled 
  133. 		cell_camera_enable(true) 
  134. 	elseif toggle_selection == 2 then 
  135. 		--disabled 
  136. 		cell_camera_enable(false) 
  137. 	end 
  138. end 
  139.  
  140. function cell_camera_button_b(event, acceleration) 
  141. 	cell_camera_lock_controls() 
  142. 	game_UI_audio_play("UI_Cell_Nav_Back") 
  143. 	 
  144. 	--Transition the screen in... 
  145. 	cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_CAMERA, cell_camera_exit_to_main) 
  146. end 
  147.  
  148. function cell_camera_button_map(event, acceleration) 
  149. 	--Exit phone... 
  150. 	cell_camera_lock_controls() 
  151.  
  152. 	vint_dataresponder_post("cell_menu_state_dr", "Set", ID_MAIN) 
  153. 	game_UI_audio_play("UI_Cell_Close") 
  154.  
  155. 	--Transition the screen in... 
  156. 	cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_CAMERA, cell_camera_exit_to_game) 
  157. end 
  158.  
  159. function cell_camera_exit_to_main() 
  160. 	pop_screen() 
  161. end 
  162.  
  163. function cell_camera_exit_to_game() 
  164. 	pop_screen()	--camera 
  165. 	pop_screen()	--main menu 
  166. 	pop_screen()	--cellphone frame 
  167. end 
  168.  
  169. ------------------------------------------------------------------------------- 
  170. -- Controls Unlock  
  171. -- 
  172. function cell_camera_unlock_controls() 
  173. 	Input_tracker:subscribe(true) 
  174. 	if Mouse_input_tracker ~= nil then 
  175. 		Mouse_input_tracker:subscribe(true) 
  176. 	end 
  177. end 
  178.  
  179. ------------------------------------------------------------------------------- 
  180. -- Controls Lock 
  181. -- 
  182. function cell_camera_lock_controls() 
  183. 	Input_tracker:subscribe(false) 
  184. 	if Mouse_input_tracker ~= nil then 
  185. 		Mouse_input_tracker:subscribe(false) 
  186. 	end 
  187. end 
  188.  
  189. -- Mouse inputs 
  190. function cell_camera_mouse_click(event, target_handle, mouse_x, mouse_y) 
  191. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  192. 	if hint_index == 1 then 
  193. 		cell_camera_button_b() 
  194. 	end 
  195.  
  196. 	local new_index = Camera_list:get_button_index(target_handle) 
  197. 	if new_index ~= 0 then 
  198. 		Camera_list:set_selection(new_index) 
  199. 		cell_camera_nav_left_right("nav_right") 
  200. 	end 
  201. 	 
  202. 	if Camera_list:is_left_arrow(target_handle) then 
  203. 		cell_camera_nav_left_right("nav_left") 
  204. 	end 
  205. end 
  206.  
  207. function cell_camera_mouse_move(event, target_handle) 
  208. 	Hint_bar:set_highlight(0) 
  209. 	 
  210. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  211. 	if hint_index ~= 0 then 
  212. 		Hint_bar:set_highlight(hint_index) 
  213. 	end 
  214. 	 
  215. 	local new_index = Camera_list:get_button_index(target_handle) 
  216. 	if new_index ~= 0 then 
  217. 		Camera_list:set_selection(new_index) 
  218. 		Camera_list:move_cursor(0, true) 
  219. 	end 
  220. end 
  221.  
  222.