./hack_main_sticks.lua

  1.  
  2. local TILE_SPACING = 8 
  3. local TILE_WIDTH = 70 + TILE_SPACING 
  4. local TILE_HEIGHT = 65 + TILE_SPACING 
  5.  
  6. local Grid_max_width = 0 
  7. local Grid_max_height = 0 
  8. local LIST_MAX_HEIGHT = 0 
  9.  
  10. local Hack_main_data = {} 
  11.  
  12. local List_height = 0 
  13. local Grid_width = 0 
  14. local Grid_height = 0 
  15.  
  16. --audio 
  17. --[[ 
  18. Event:  UI_SFX 
  19. 1st Switch Group:  UI_SFX 
  20. 1st Switch:  UI_Hacking_SFX 
  21. 2nd Switch Group:  UI_Hacking_SFX 
  22. Switches: 
  23. Background_Loop (trigger this when the minigame starts) 
  24. Tutorial_In 
  25. Tutorial_Out 
  26. Grid_Highlight 
  27. Block_Place 
  28. Block_Delete 
  29. Block_Charge 
  30. List_Highlight (this should only trigger when the player actual moves that cursor, not if it moves on its own) 
  31. Grid_Reset 
  32. Timer_90 (trigger at 95 seconds) 
  33. Timer_60 (trigger at 65 seconds) 
  34. Timer_30 (trigger at 30 seconds) 
  35. Timer_10 (trigger at 15 seconds) 
  36. Hack_Complete 
  37. Hack_Fail 
  38.  
  39. UI_Stop_Hacking_Timer (trigger this anytime you need to stop the 10 second countdown) 
  40. UI_Kill_Hacking SFX (trigger this anytime the player leaves the minigame � quits out, fails, completes) 
  41. --If its failing or completing, be sure not to trigger is until you trigger the UI to fade out and back to the open world) 
  42.  
  43. event_audio_id = audio_object_post_event("UI_Hacking_SFX", "UI_Hacking_SFX", "Background_Loop") 
  44. --]] 
  45.  
  46.  
  47. -- 0 = north, 1 = East, 2, 3 
  48. local Hack_list_connections_data = { 
  49. 	[0] = { -1, -1}, 
  50. 	[1] = { 1, 3 }, 
  51. 	[2] = { 0, 2 }, 
  52. 	[3] = { 0, 1 }, 
  53. 	[4] = { 1, 2 }, 
  54. 	[5] = { 2, 3 }, 
  55. 	[6] = { 0, 3 }, 
  56. } 
  57.  
  58. local Hack_list_connection_directions = { 
  59. 	[0] = 2, 
  60. 	[1] = 3, 
  61. 	[2] = 0, 
  62. 	[3] = 1, 
  63. } 
  64.  
  65. local Hack_timer_thread 
  66. local Hack_timer_run = true 
  67.  
  68. local List_hint_grp_h 
  69. local List_hint_txt_h 
  70. local List_button 
  71. local Hint_bar 
  72. local Popup_hint_bar 
  73. local List_h 
  74. local List_highlight_h 
  75. local Grid_h 
  76. local Grid_pipe_h 
  77. local Input_tracker 
  78. local Grid_highlight_h 
  79. local Grid_highlight_image_h 
  80. local Highlight_anim_h  
  81. local Hack_mouse_input_tracker 
  82. local Hack_popup_mouse_input_tracker 
  83. local Hack_main_sticks_doc_h = -1 
  84. local New_item_idx = 0 
  85. local Prev_idx = 0 
  86. local Current_idx = 0 
  87. local List_idx = 1 
  88. local List_total = 0 
  89. local Grid_x_idx = 0 
  90. local Grid_y_idx = 0 
  91. local Timer_h = 0 
  92. local Hack_timer = 30 
  93. local Hack_puzzle_idx = 0 
  94. local Hack_controls_locked = true 
  95. local Hack_popup_ready = false 
  96. local Is_paused = false 
  97. local Hack_main_paused = false 
  98. local Hack_tutorial_active = false 
  99. local Hack_popup_open = false 
  100. local Grid_pipe_count = 0 
  101. local Hack_complete = false 
  102. local Grid_mouse_lock = false 
  103.  
  104. local Background_loop_audio_id 	= 0 
  105. local Clear_all_audio_id			= 0 
  106. local List_move_audio_id			= 0 
  107. local Grid_move_audio_id			= 0 
  108. local Grid_add_audio_id				= 0 
  109. local Grid_remove_audio_id			= 0 
  110. local Grid_reset_audio_id			= 0 
  111. local Grid_power_audio_id			= 0 
  112. local Timer_audio_id					= 0 
  113. local Tutorial_audio_id				= 0 
  114. local Hack_end_audio_id				= 0 
  115.  
  116. local A_mode = true 
  117.  
  118. local Penalty = false 
  119. local Can_have_penalty = true 
  120.  
  121. local Hack_main_sticks_gamepad_listener = -1 
  122.  
  123. local Popup_defaults_changed = false 
  124. local Popup_footer_grp_x 
  125. local Popup_footer_grp_y  
  126. local Popup_background_width 
  127. local Popup_background_height 
  128. local Popup_background_x 
  129. local Popup_background_y 
  130. local Popup_elements_grp_x 
  131. local Popup_elements_grp_y 
  132.  
  133. function hack_main_sticks_init() 
  134.  
  135. 	-- unload the full screen map to pillage memory 
  136. 	pause_map_dump() 
  137. 	 
  138. 	-- Find our documents... 
  139. 	Hack_main_sticks_doc_h = vint_document_find("hack_main_sticks") 
  140. 	 
  141. 	-- Setup input tracker.+ 
  142. 	local priority = 500000 
  143. 	Input_tracker = Vdo_input_tracker:new() 
  144. 	Input_tracker:add_input( "select", "hack_main_sticks_button_a", priority ) 
  145. 	Input_tracker:add_input( "back", "hack_main_sticks_button_b", priority ) 
  146. 	Input_tracker:add_input( "alt_select", "hack_main_sticks_button_x", priority ) 
  147. 	Input_tracker:add_input( "nav_up", "hack_main_sticks_nav_up", priority ) 
  148. 	Input_tracker:add_input( "nav_down", "hack_main_sticks_nav_down", priority ) 
  149. 	Input_tracker:add_input( "nav_left", "hack_main_sticks_nav_left", priority ) 
  150. 	Input_tracker:add_input( "nav_right", "hack_main_sticks_nav_right", priority ) 
  151. 	Input_tracker:add_input( "alt_joy_up", "hack_main_sticks_list_up", priority ) 
  152. 	Input_tracker:add_input( "alt_joy_down", "hack_main_sticks_list_down", priority ) 
  153. 	--allows for changing puzzles, removing for final code 
  154. 	--Input_tracker:add_input( "scroll_left", "hack_main_sticks_previous_puzzle", priority ) 
  155. 	--Input_tracker:add_input( "scroll_right", "hack_main_sticks_next_puzzle", priority ) 
  156. 	 
  157. 	vint_dataresponder_request( "hacking_screen_populate", "hack_main_sticks_set_puzzle_idx", 0 ) 
  158. 	 
  159. 	if (hacking_use_procedural_generation()) then 
  160. 		Hack_main_data = hacking_procedural_get_puzzle(Hack_puzzle_idx) 
  161. 	else 
  162. 		Hack_main_data = Hack_main_puzzles[ Hack_puzzle_idx ] 
  163. 		 
  164. 		if Hack_main_data == nil then 
  165. 			debug_print( "always_on", "Hack puzzle not found, defaulting" ) 
  166. 			Hack_main_data = Hack_main_puzzles[ 0 ] 
  167. 		end 
  168. 	end 
  169. 	 
  170. 	--flair text 
  171. 	local popup_title_value_h = vint_object_find("popup_title_value", 0, Hack_main_sticks_doc_h) 
  172. 	local popup_title_value_bg_h = vint_object_find("popup_title_value_bg", 0, Hack_main_sticks_doc_h) 
  173. 	local popup_title_value_width, popup_title_value_height = element_get_actual_size(popup_title_value_h) 
  174. 	local popup_title_value_bg_width, popup_title_value_bg_height = element_get_actual_size(popup_title_value_bg_h) 
  175. 	element_set_actual_size(popup_title_value_bg_h, popup_title_value_width + 11, popup_title_value_bg_height) 
  176. 	 
  177. 	local timer_title_h = vint_object_find("timer_title", 0, Hack_main_sticks_doc_h) 
  178. 	local timer_title_bg_h = vint_object_find("timer_title_bg", 0, Hack_main_sticks_doc_h) 
  179. 	local timer_title_width, timer_title_height = element_get_actual_size(timer_title_h) 
  180. 	local timer_title_bg_width, timer_title_bg_height = element_get_actual_size(timer_title_bg_h) 
  181. 	element_set_actual_size(timer_title_bg_h, timer_title_width + 5, timer_title_bg_height) 
  182. 	 
  183. 	local footer_value_h = vint_object_find("footer_value", 0, Hack_main_sticks_doc_h) 
  184. 	local footer_value_bg_h = vint_object_find("footer_value_bg", 0, Hack_main_sticks_doc_h) 
  185. 	local footer_value_width, footer_value_height = element_get_actual_size(footer_value_h) 
  186. 	local footer_value_bg_width, footer_value_bg_height = element_get_actual_size(footer_value_bg_h) 
  187. 	element_set_actual_size(footer_value_bg_h, footer_value_width + 11, footer_value_bg_height) 
  188. 	 
  189. 	 
  190. 	 
  191. 	List_height = #Hack_main_data.hack_list_data + 1 
  192. 	Grid_width = #Hack_main_data.hack_grid_data + 1 
  193. 	Grid_height = #Hack_main_data.hack_grid_data + 1 
  194. 	 
  195. 	Grid_max_width = TILE_WIDTH * (Grid_width - 1) 
  196. 	Grid_max_height = TILE_HEIGHT * (Grid_height - 1) 
  197. 	 
  198. 	LIST_MAX_HEIGHT = TILE_HEIGHT * (List_height - 1) 
  199. 	 
  200. 	-- Setup Button Hints 
  201. 	List_hint_grp_h = vint_object_find("list_hint_grp", 0, Hack_main_sticks_doc_h) 
  202. 	 
  203. 	List_hint_txt_h = vint_object_find("list_hint", 0, Hack_main_sticks_doc_h) 
  204. 	 
  205. 	Hint_bar = Vdo_hint_bar:new( "hint_bar", 0, Hack_main_sticks_doc_h ) 
  206. 	Popup_hint_bar = Vdo_hint_bar:new( "popup_hint_bar", 0, Hack_main_sticks_doc_h ) 
  207. 	List_button = Vdo_hint_button:new( "list_button" ) 
  208.  
  209. 	hack_main_sticks_set_hints() 
  210. 	 
  211. 	Grid_h = vint_object_find( "cell_grid_grp" ) 
  212. 	Grid_highlight_h = vint_object_find( "cell_highlight" ) 
  213. 	Grid_highlight_image_h = vint_object_find( "highlight_image" ) 
  214. 	Grid_pipe_h = vint_object_find( "cell_pipe_grp" ) 
  215. 	List_h = vint_object_find( "list_main" ) 
  216. 	List_highlight_h = vint_object_find( "list_highlight_grp" ) 
  217. 	Timer_h = vint_object_find( "timer" ) 
  218. 	 
  219. 	Highlight_anim_h = vint_object_find( "highlight_anim" ) 
  220. 	 
  221. 	vint_set_property( Grid_highlight_image_h, "visible", true ) 
  222. 	 
  223. 	local highlight_button = Vdo_hint_button:new( "highlight_button" ) 
  224. 	highlight_button:set_button( CTRL_MENU_BUTTON_A ) 
  225. 	 
  226. 	local start_energy_anim_h = vint_object_find( "start_energy_anim" ) 
  227. 	lua_play_anim( start_energy_anim_h, 0 ) 
  228. 	 
  229. 	--draw the grid 
  230. 	hack_main_sticks_draw_grid() 
  231. 	hack_main_sticks_set_list_highlight( 1 ) 
  232. 	 
  233. 	local list_mouse_highlight_h = vint_object_find( "list_mouse_highlight_grp" ) 
  234. 	vint_set_property( list_mouse_highlight_h, "visible", false ) 
  235. 	--setup PC inputs after grid is drawn 
  236. 	if game_get_platform() == "PC" then 
  237. 		Hack_mouse_input_tracker = Vdo_input_tracker:new() 
  238. 		hack_main_sticks_add_mouse_inputs() 
  239. 		Hack_mouse_input_tracker:subscribe(false) 
  240. 		 
  241. 		Hack_popup_mouse_input_tracker = Vdo_input_tracker:new() 
  242. 		Hack_popup_mouse_input_tracker:subscribe(false) 
  243. 		 
  244. 		local popup_grp_h = vint_object_find( "popup_grp" ) 
  245. 		Hack_popup_mouse_input_tracker:add_mouse_input( "mouse_click", "hack_main_sticks_mouse_click", 500000, popup_grp_h ) 
  246. 	end 
  247. 	 
  248. 	--position grid based on grid size 
  249. 	if Grid_width == 4 then 
  250. 		vint_set_property( Grid_h, "anchor", 468, 237 ) 
  251. 	else 
  252. 		vint_set_property( Grid_h, "anchor", 390, 164 ) 
  253. 	end 
  254. 	 
  255. 	hack_main_sticks_draw_side_grids() 
  256. 	 
  257. 	vint_set_property( Timer_h, "text_tag", "--" ) 
  258. 	 
  259. 	vint_set_property( vint_object_find( "label" ), "text_tag", Hack_puzzle_idx ) 
  260. 	 
  261. 	local start_point_anim_h = vint_object_find( "start_point_anim" ) 
  262. 	lua_play_anim( start_point_anim_h, 0 ) 
  263. 	 
  264. 	hack_main_sticks_update_total() 
  265. 	 
  266. 	hack_main_sticks_set_grid_highlight_start() 
  267. 	hack_main_sticks_set_highlight_image() 
  268. 	 
  269. 	vint_dataitem_add_subscription( "game_paused_item", "update", "hack_main_sticks_game_is_paused" ) --to check if game is paused..  
  270. 	 
  271. 	local start_timer_tween_h = vint_object_find( "start_timer_tween" ) 
  272. 	vint_set_property( start_timer_tween_h, "end_event", "hack_main_sticks_intro_done" ) 
  273. 	 
  274. 	local popup_in_tween_h = vint_object_find( "popup_in_tween" ) 
  275. 	vint_set_property( popup_in_tween_h, "end_event", "hack_main_sticks_popup_in_done" ) 
  276. 	 
  277. 	local screen_animate_in_h = vint_object_find( "screen_animate_in" ) 
  278. 	lua_play_anim( screen_animate_in_h, 0 ) 
  279. 	 
  280. 	 
  281. 	local damage_group_h = vint_object_find( "damage_group" ) 
  282. 	vint_set_property( damage_group_h, "alpha", 0 ) 
  283. 	 
  284. 	--audio 
  285. 	Background_loop_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Background_Loop" }, nil, false ) 
  286. 	ui_audio_post_event( "UI_Hacking_On" ) 
  287. 	 
  288. 	Hack_main_sticks_gamepad_listener = vint_scriptevent_listen( "gamepad_active", "hack_main_sticks_update_gamepad_state" ) 
  289. end 
  290.  
  291. function hack_main_sticks_add_mouse_inputs() 
  292. 	local priority = 500000 
  293. 	--clear all mouse inputs 
  294. 	Hack_mouse_input_tracker:remove_all() 
  295. 	--rebuild all mouse inputs 
  296. 	Hint_bar:set_visible(true)	 
  297. 	Hint_bar:set_highlight(0) 
  298. 	 
  299. 	Hint_bar:add_mouse_inputs( "hack_main_sticks", Hack_mouse_input_tracker ) 
  300. 	 
  301. 	local tile_h 
  302. 	for tile_y = 0, Grid_height - 1 do 
  303. 		for tile_x = 0, Grid_width - 1 do  
  304. 			tile_h = Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].handle 
  305. 			Hack_mouse_input_tracker:add_mouse_input( "mouse_click", "hack_main_sticks_mouse_click", priority, tile_h ) 
  306. 			Hack_mouse_input_tracker:add_mouse_input( "mouse_right_click", "hack_main_sticks_mouse_right_click", priority, tile_h ) 
  307. 			Hack_mouse_input_tracker:add_mouse_input( "mouse_move", "hack_main_sticks_mouse_move", priority, tile_h ) 
  308. 		end 
  309. 	end 
  310. 	 
  311. 	for i = 1, List_height - 1 do 
  312. 		Hack_mouse_input_tracker:add_mouse_input( "mouse_click", "hack_main_sticks_mouse_click", priority, Hack_main_data.hack_list_data [ i ].handle ) 
  313. 		Hack_mouse_input_tracker:add_mouse_input( "mouse_move", "hack_main_sticks_mouse_move", priority, Hack_main_data.hack_list_data [ i ].handle ) 
  314. 	end 
  315. 	 
  316. 	Hack_mouse_input_tracker:add_mouse_input("mouse_scroll", "hack_main_sticks_mouse_scroll", priority, Grid_h) 
  317.  
  318. 	Hack_mouse_input_tracker:add_mouse_input( "mouse_click", "hack_main_sticks_mouse_click", priority + 1, Hack_main_sticks_doc_h ) 
  319. end 
  320.  
  321. function hack_main_sticks_set_hints() 
  322. 	local hint_data = {} 
  323. 	if game_get_platform() == "PC" and game_is_active_input_gamepad() == false then 
  324. 		hint_data = { 
  325. 			{HINT_BUTTON_RMB_OVERRIDE, "MENU_CLEAR"}, 
  326. 			{CTRL_MENU_BUTTON_A, "MENU_SELECT"}, 
  327. 			{CTRL_BUTTON_DPAD, "PLAYLIST_MOVE_TRACK"}, 
  328. 			{CTRL_BUTTON_X, "MENU_RESET"}, 
  329. 		} 
  330. 	else 
  331. 		hint_data = { 
  332. 			{CTRL_MENU_BUTTON_B, "MENU_CLEAR"}, 
  333. 			{CTRL_MENU_BUTTON_A, "MENU_SELECT"}, 
  334. 			{CTRL_BUTTON_LS, "PLAYLIST_MOVE_TRACK"}, 
  335. 			{CTRL_BUTTON_X, "MENU_RESET"}, 
  336. 		} 
  337. 	end 
  338. 	Hint_bar:set_hints(hint_data)  
  339.  
  340. 	local ggl = game_get_language() 
  341. 	if ggl == "FR" then 
  342. 		vint_set_property(List_hint_grp_h, "anchor", 0, -26) 
  343. 	elseif ggl == "RU" then 
  344. 		vint_set_property(List_hint_grp_h, "anchor", 0, -26)	 
  345. 	else 
  346. 		vint_set_property(List_hint_grp_h, "anchor", 0, 0) 
  347. 	end 
  348. 	 
  349. 	--override the RS on PC with mouse scroll wheel 
  350. 	if game_get_platform() == "PC" and game_is_active_input_gamepad() == false then 
  351. 		List_button:set_button( CTRL_BUTTON_MOUSE_SCROLL ) 
  352. 	else 
  353. 		List_button:set_button( CTRL_BUTTON_RS ) 
  354. 	end 
  355. 	 
  356. 	-- Move the hint text over so it does not overlap with the hint button 
  357. 	local hint_txt_x, hint_txt_y = vint_get_property(List_hint_txt_h, "anchor") 
  358. 	local list_button_x, list_button_y = vint_get_property(List_button.handle, "anchor") 
  359. 	if hint_txt_x >= list_button_x - (List_button.width/2) then 
  360. 		vint_set_property( List_hint_txt_h, "anchor", list_button_x - (List_button.width/2) - 6, hint_txt_y ) 
  361. 	end 
  362. end 
  363.  
  364. function hack_main_sticks_popup_in_done( tween_h ) 
  365. 	Hack_popup_ready = true 
  366. end 
  367.  
  368. function hack_main_sticks_intro_done( tween_h ) 
  369. 	Input_tracker:subscribe(true) 
  370. 	if Hack_mouse_input_tracker ~= nil then 
  371. 		hack_main_sticks_add_mouse_inputs() 
  372. 		if( not Is_paused )then 
  373. 			Hack_mouse_input_tracker:subscribe(true) 
  374. 		end 
  375. 	end 
  376. 	if Hack_puzzle_idx > 0 then 
  377. 		Hack_timer_thread = thread_new( "hack_main_sticks_timer_thread" ) 
  378. 		Hack_controls_locked = false 
  379. 	else 
  380. 		Hack_tutorial_active = true 
  381. 		Hack_controls_locked = true 
  382. 		if game_get_platform() == "PC" and game_is_active_input_gamepad() == false then 
  383. 			hack_main_sticks_launch_popup( nil, "MENU_HACKING_TUTORIAL_PC" ) 
  384. 		else 
  385. 			hack_main_sticks_launch_popup( nil, "MENU_HACKING_TUTORIAL" ) 
  386. 		end 
  387. 	end 
  388. end 
  389.  
  390. function hack_main_sticks_game_is_paused(di_h) 
  391. 	Is_paused = vint_dataitem_get(di_h) 
  392. 	hack_main_sticks_pause() 
  393. end 
  394.  
  395. function hack_main_sticks_set_puzzle_idx( puzzle_idx, puzzle_time ) 
  396. 	if puzzle_idx ~= nil then 
  397. 		Hack_puzzle_idx = puzzle_idx 
  398. 	end 
  399. 	if puzzle_time ~= nil then 
  400. 		Hack_timer = puzzle_time 
  401. 	end 
  402. end 
  403.  
  404. --we got shot, called directly from C 
  405. function hack_main_sticks_penalty( ) 
  406. 	Penalty = true 
  407. end 
  408.  
  409. function hack_main_sticks_unlock_penalty() 
  410. 	Can_have_penalty = true 
  411. end 
  412.  
  413. function hack_main_sticks_cleanup() 
  414. 	-- reload the full screen map 
  415. 	pause_map_restore() 
  416. 	 
  417. 	if Hack_timer_thread ~= nil then 
  418. 		thread_kill(Hack_timer_thread) 
  419. 		Hack_timer_thread = nil 
  420. 	end 
  421. 	 
  422. 	-- Nuke all button subscriptions 
  423. 	Input_tracker:subscribe(false) 
  424. 	 
  425. 	audio_object_post_event( "UI_Kill_Hacking_SFX" ) 
  426.  
  427. 	if Hack_mouse_input_tracker ~= nil then 
  428. 		Hack_mouse_input_tracker:subscribe(false) 
  429. 	end 
  430. 	 
  431. 	vint_scriptevent_stop_listening( Hack_main_sticks_gamepad_listener ) 
  432. end 
  433.  
  434. function hack_main_sticks_validate_cells() 
  435. 	-- the start and end cells could be changed based on the board setup 
  436. 	local current_cell_x = 0 
  437. 	local current_cell_y = Hack_main_data.hack_start 
  438. 	local incoming_direction = 3 
  439. 	 
  440. 	local pipe_count = 0 
  441. 	 
  442. 	local end_cell_x = Grid_width 
  443. 	local end_cell_y = Hack_main_data.hack_end 
  444. 	 
  445. 	-- reset grid tint 
  446. 	for x = 0, Grid_width - 1 do 
  447. 		for y = 0, Grid_height - 1 do 
  448. 			local cell_type = Hack_main_data.hack_grid_data[ x ][ y ].type 
  449. 			if cell_type > 0 then 
  450. 				vint_set_property( Hack_main_data.hack_grid_data[ x ][ y ].handle, "tint", 0.2, 0.2, 0.2 ) 
  451. 				vint_set_property( Hack_main_data.hack_grid_data[ x ][ y ].pipe, "visible", false ) 
  452. 			else 
  453. 				vint_set_property( Hack_main_data.hack_grid_data[ x ][ y ].handle, "tint", 1, 1, 1 ) 
  454. 				vint_set_property( Hack_main_data.hack_grid_data[ x ][ y ].pipe, "visible", false ) 
  455. 			end 
  456. 		end 
  457. 	end 
  458. 	 
  459. 	while true do 
  460. 		-- validate the current cell 
  461. 		local cell_type = Hack_main_data.hack_grid_data[ current_cell_x ][ current_cell_y ].type 
  462. 		 
  463. 		if cell_type == -1 then 
  464. 			return false 
  465. 		end 
  466. 		 
  467. 		local valid = false 
  468. 		local exit_direction = -1 
  469. 		for k, v in pairs( Hack_list_connections_data[ cell_type ] ) do 
  470. 			if v == incoming_direction then 
  471. 				valid = true 
  472. 			else 
  473. 				exit_direction = v 
  474. 			end 
  475. 		end 
  476. 		 
  477. 		if valid == false then 
  478. 			return false 
  479. 		end 
  480. 		 
  481. 		-- update the tint 
  482. 		vint_set_property( Hack_main_data.hack_grid_data[ current_cell_x ][ current_cell_y ].handle, "tint", 1, 1, 1 ) 
  483. 		vint_set_property( Hack_main_data.hack_grid_data[ current_cell_x ][ current_cell_y ].pipe, "visible", true ) 
  484.  
  485. 		pipe_count = pipe_count + 1 
  486. 		 
  487. 		hack_main_sticks_set_pipe( Hack_main_data.hack_grid_data[ current_cell_x ][ current_cell_y ].pipe, cell_type ) 
  488. 		 
  489. 		-- move to the next cell 
  490. 		if exit_direction == 0 then 
  491. 			current_cell_y = current_cell_y - 1 
  492. 		elseif exit_direction == 1 then 
  493. 			current_cell_x = current_cell_x + 1 
  494. 		elseif exit_direction == 2 then 
  495. 			current_cell_y = current_cell_y + 1 
  496. 		elseif exit_direction == 3 then 
  497. 			current_cell_x = current_cell_x  - 1 
  498. 		else 
  499. 			-- hmmmmm 
  500. 			return false 
  501. 		end 
  502. 		 
  503. 		-- did we win? 
  504. 		if current_cell_x == end_cell_x and current_cell_y == end_cell_y then 
  505. 			--launch success popup 
  506. 			hack_main_sticks_launch_popup( true ) 
  507. 			vint_set_property( Grid_highlight_image_h, "visible", false ) 
  508. 			--kill the timer 
  509. 			Hack_timer_run = false 
  510. 			if Hack_timer_thread ~= nil then 
  511. 				thread_kill( Hack_timer_thread )  
  512. 				Hack_timer_thread = nil 
  513. 			end 
  514. 			--kill input 
  515. 			Hack_controls_locked = true 
  516. 			Hack_complete = true 
  517. 			return true 
  518. 		end 
  519. 		 
  520. 		if Grid_pipe_count < pipe_count then 
  521. 			Grid_power_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_Charge" }, nil, false ) 
  522. 		end 
  523. 		Grid_pipe_count = pipe_count 
  524. 		 
  525. 		-- did we move out of the grid? 
  526. 		if current_cell_x < 0 or current_cell_x >= Grid_width then 
  527. 			return false 
  528. 		end 
  529. 		 
  530. 		if current_cell_y < 0 or current_cell_y >= Grid_height then 
  531. 			return false 
  532. 		end 
  533. 		 
  534. 		-- update incoming direction 
  535. 		incoming_direction = Hack_list_connection_directions[ exit_direction ] 
  536. 	end 
  537. end 
  538.  
  539. function hack_main_sticks_timer_thread() 
  540. 	hacking_begin_player_voice() 
  541. 	while Hack_timer_run do 
  542. 		thread_yield() 
  543. 		if Hack_timer > 0 and Is_paused == false then 
  544. 			Hack_timer = Hack_timer - 1 
  545. 			if Hack_timer > 99 then 
  546. 				vint_set_property( Timer_h, "scale", 0.45, 0.45 ) 
  547. 			else 
  548. 				vint_set_property( Timer_h, "scale", 0.6, 0.6 ) 
  549. 			end 
  550. 			vint_set_property( Timer_h, "text_tag", Hack_timer ) 
  551. 			--audio 
  552. 			if Hack_timer == 95 and Penalty == false then 
  553. 				audio_stop( Timer_audio_id ) 
  554. 				Timer_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Timer_90" }, nil, false ) 
  555. 			elseif Hack_timer == 65 and Penalty == false then 
  556. 				audio_stop( Timer_audio_id ) 
  557. 				Timer_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Timer_60" }, nil, false ) 
  558. 			elseif Hack_timer == 35 and Penalty == false then 
  559. 				audio_stop( Timer_audio_id ) 
  560. 				Timer_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Timer_30" }, nil, false ) 
  561. 			elseif Hack_timer == 15 and Penalty == false then 
  562. 				audio_stop( Timer_audio_id ) 
  563. 				Timer_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Timer_10" }, nil, false ) 
  564. 			end 
  565. 			 
  566. 			--update hints every frame in case input devices changed 
  567. 			--hack_main_sticks_set_hints() 
  568. 			 
  569. 			--show damage stuff, player got shot 
  570. 			if Penalty and Can_have_penalty then 
  571. 				Penalty = false 
  572. 				Can_have_penalty = false 
  573. 				Hack_timer = Hack_timer - 10 
  574. 				if Hack_timer < 0 then 
  575. 					Hack_timer = 0 
  576. 					Hack_complete = true 
  577. 					vint_set_property( Timer_h, "text_tag", Hack_timer ) 
  578. 					audio_stop( Timer_audio_id ) 
  579. 					--we ran out of timer--launch the failure popup 
  580. 					hack_main_sticks_launch_popup( false ) 
  581. 					--kill the timer 
  582. 					Hack_timer_run = false 
  583. 					if Hack_timer_thread ~= nil then 
  584. 						thread_kill( Hack_timer_thread )  
  585. 						Hack_timer_thread = nil 
  586. 					end 
  587. 					--kill input 
  588. 					Hack_controls_locked = true 
  589. 					Hack_complete = true 
  590. 				end 
  591. 				local damage_anim_h = vint_object_find( "damage_anim" ) 
  592. 				local damage_last_tween_h = vint_object_find( "damage_last_tween" ) 
  593. 				vint_set_property( damage_last_tween_h, "end_event", "hack_main_sticks_unlock_penalty" ) 
  594. 				lua_play_anim( damage_anim_h ) 
  595. 			end 
  596. 	 
  597. 			delay( 1 ) 
  598. 		elseif Hack_timer <= 0 then 
  599. 			--we ran out of timer--launch the failure popup 
  600. 			hack_main_sticks_launch_popup( false ) 
  601. 			--kill the timer 
  602. 			Hack_timer_run = false 
  603. 			if Hack_timer_thread ~= nil then 
  604. 				thread_kill( Hack_timer_thread )  
  605. 				Hack_timer_thread = nil 
  606. 			end 
  607. 			--kill input 
  608. 			Hack_controls_locked = true 
  609. 			Hack_complete = true 
  610. 		end 
  611. 	end 
  612. end 
  613.  
  614. function hack_main_sticks_previous_puzzle() 
  615. 	Hack_puzzle_idx = Hack_puzzle_idx - 1 
  616. 	if Hack_puzzle_idx < 0 then 
  617. 		Hack_puzzle_idx = #Hack_main_puzzles 
  618. 	end 
  619. 	hack_main_sticks_redraw_screen() 
  620. end 
  621.  
  622. function hack_main_sticks_next_puzzle() 
  623. 	Hack_puzzle_idx = Hack_puzzle_idx + 1 
  624. 	if Hack_puzzle_idx > #Hack_main_puzzles then 
  625. 		Hack_puzzle_idx = 0 
  626. 	end 
  627. 	hack_main_sticks_redraw_screen() 
  628. end 
  629.  
  630. function hack_main_sticks_redraw_screen() 
  631. 	if #Hack_main_data.hack_grid_data > 0 then 
  632. 		hack_main_sticks_reset_grid() 
  633. 		--nuke the grid 
  634. 		for x = 0, Grid_width - 1 do 
  635. 			for y = 0, Grid_height - 1 do  
  636. 				vint_object_destroy( Hack_main_data.hack_grid_data[ x ][ y ].handle ) 
  637. 				vint_object_destroy( Hack_main_data.hack_grid_data[ x ][ y ].pipe ) 
  638. 				vint_object_destroy( Hack_main_data.hack_grid_data[ x ][ y ].bg_handle ) 
  639. 			end 
  640. 		end 
  641. 		 
  642. 		Hack_main_data = {} 
  643. 		Hack_main_data = Hack_main_puzzles[ Hack_puzzle_idx ] 
  644. 		 
  645. 		Grid_width = #Hack_main_data.hack_grid_data + 1 
  646. 		Grid_height = #Hack_main_data.hack_grid_data + 1 
  647. 		Grid_max_width = TILE_WIDTH * (Grid_width - 1) 
  648. 		Grid_max_height = TILE_HEIGHT * (Grid_height - 1) 
  649. 	 
  650. 		hack_main_sticks_draw_grid() 
  651. 		hack_main_sticks_set_grid_highlight_start() 
  652. 		 
  653. 		hack_main_sticks_update_total() 
  654. 		 
  655. 		local list_grp_h = vint_object_find("cell_list_grp") 
  656. 		local grid_x,grid_y = vint_get_property(Grid_h, "anchor") 
  657. 		local list_x,list_y = vint_get_property(list_grp_h, "anchor") 
  658. 		 
  659. 		--position grid based on grid size 
  660. 		if Grid_width == 4 then 
  661. 			vint_set_property(Grid_h, "anchor", 468, 237 ) 
  662. 		else 
  663. 			vint_set_property(Grid_h, "anchor", 390, 164 ) 
  664. 		end 
  665. 	 
  666. 		Hack_timer = 61 
  667. 		Hack_controls_locked = false 
  668. 		Hack_timer_run = true 
  669. 		 
  670. 		if Hack_timer_thread == nil then 
  671. 			Hack_timer_thread = thread_new("hack_main_sticks_timer_thread") 
  672. 		end 
  673. 		 
  674. 		vint_set_property( vint_object_find( "label" ), "text_tag", Hack_puzzle_idx ) 
  675. 		 
  676. 		hack_main_sticks_launch_popup() 
  677. 	end 
  678. end 
  679.  
  680. function hack_main_sticks_nav_up(event, acceleration) 
  681. 	if not Hack_controls_locked then 
  682. 		hack_main_sticks_set_grid_highlight(-2) 
  683. 	else 
  684. 		if Hack_main_paused then 
  685. 			hack_main_sticks_set_popup_highlight(-1) 
  686. 		end 
  687. 	end 
  688. end 
  689.  
  690. function hack_main_sticks_nav_down(event, acceleration) 
  691. 	if not Hack_controls_locked then 
  692. 		hack_main_sticks_set_grid_highlight(2) 
  693. 	else 
  694. 		if Hack_main_paused then 
  695. 			hack_main_sticks_set_popup_highlight(-1) 
  696. 		end 
  697. 	end 
  698. end 
  699.  
  700. function hack_main_sticks_nav_left(event, acceleration) 
  701. 	if not Hack_controls_locked then 
  702. 		hack_main_sticks_set_grid_highlight(-1) 
  703. 	end 
  704. end 
  705.  
  706. function hack_main_sticks_nav_right(event, acceleration) 
  707. 	if not Hack_controls_locked then 
  708. 		hack_main_sticks_set_grid_highlight(1) 
  709. 	end 
  710. end 
  711.  
  712. function hack_main_sticks_button_x(event, acceleration) 
  713. 	if not Hack_controls_locked then 
  714. 		hack_main_sticks_reset_grid() 
  715. 	end 
  716. end 
  717.  
  718. function hack_main_sticks_list_up(event, acceleration) 
  719. 	if not Hack_controls_locked and List_total > 0 and not Is_paused then 
  720. 		local current_type = Hack_main_data.hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type 
  721. 		--check if cell is open  
  722. 		--if current_type >= 0 then-- or A_mode then 
  723. 			local upper_limit = 1 
  724. 			local bottom_limit = TILE_HEIGHT * 6 
  725. 			local x,y = vint_get_property( List_highlight_h, "anchor" ) 
  726. 			local prev_x,prev_y = vint_get_property( List_highlight_h, "anchor" ) 
  727. 			y = y - TILE_HEIGHT 
  728. 			 
  729. 			Prev_idx = List_idx 
  730. 			List_idx = List_idx - 1 
  731. 			 
  732. 			if y < upper_limit then 
  733. 				y = bottom_limit 
  734. 				List_idx = List_height - 1 
  735. 			end 
  736. 					 
  737. 			local count = 0 
  738. 			local check = true 
  739. 			while check do 
  740. 				if Hack_main_data.hack_list_data [ List_idx ].amount <= 0 then 
  741. 					y = y - TILE_HEIGHT 
  742. 					List_idx = List_idx - 1 
  743. 					 
  744. 					if y < upper_limit then 
  745. 						y = bottom_limit 
  746. 						List_idx = List_height - 1 
  747. 					end 
  748. 				else 
  749. 					check = false 
  750. 				end 
  751. 				count = count + 1 
  752. 				if count > List_height - 1 then 
  753. 					check = false 
  754. 				end 
  755. 			end 
  756. 			 
  757. 			if A_mode == false then 
  758. 				hack_main_sticks_update_amount( Prev_idx ) 
  759. 				hack_main_sticks_update_cell( Grid_x_idx, Grid_y_idx ) 
  760. 			else 
  761. 				hack_main_sticks_set_highlight_image() 
  762. 			end 
  763. 			 
  764. 			if y ~= prev_y then 
  765. 				List_move_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "List_Highlight" }, nil, false ) 
  766. 			end 
  767. 			 
  768. 			vint_set_property( List_highlight_h, "anchor", 0, y ) 
  769.  
  770. 		--else 
  771. 			--play some error sound 
  772. 			--Grid_add_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_X" }, nil, false ) 
  773. 		--end 
  774. 	end 
  775. end 
  776.  
  777. function hack_main_sticks_list_down(event, acceleration) 
  778. 	if not Hack_controls_locked and List_total > 0 and not Is_paused then 
  779. 		debug_print( "vint","List_total = "..var_to_string( List_total ).."\n" ) 
  780. 		local current_type = Hack_main_data.hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type 
  781. 		--if current_type >= 0 then-- or A_mode then 
  782. 			local upper_limit = TILE_HEIGHT 
  783. 			local bottom_limit = TILE_HEIGHT * 6 
  784. 			local x ,y = vint_get_property( List_highlight_h, "anchor" ) 
  785. 			local prev_x,prev_y = vint_get_property( List_highlight_h, "anchor" ) 
  786. 			y = y + TILE_HEIGHT 
  787. 			 
  788. 			Prev_idx = List_idx 
  789. 			List_idx = List_idx + 1 
  790. 			 
  791. 			if y > bottom_limit then 
  792. 				y = upper_limit 
  793. 				List_idx = 1 
  794. 			end 
  795. 			 
  796. 			local count = 0 
  797. 			local check = true 
  798. 			while check do 
  799. 				if Hack_main_data.hack_list_data [ List_idx ].amount <= 0 then 
  800. 					y = y + TILE_HEIGHT 
  801. 					List_idx = List_idx + 1 
  802. 				 
  803. 					if y > bottom_limit then 
  804. 						y = upper_limit 
  805. 						List_idx = 1 
  806. 					end 
  807. 				else 
  808. 					check = false 
  809. 				end 
  810. 				count = count + 1 
  811. 				if count > List_height - 1 then 
  812. 					check = false 
  813. 				end 
  814. 			end 
  815. 			 
  816. 			if A_mode == false then 
  817. 				hack_main_sticks_update_amount( Prev_idx ) 
  818. 				hack_main_sticks_update_cell( Grid_x_idx, Grid_y_idx ) 
  819. 			else 
  820. 				hack_main_sticks_set_highlight_image() 
  821. 			end 
  822. 			 
  823. 			if y ~= prev_y then 
  824. 				List_move_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "List_Highlight" }, nil, false ) 
  825. 			end 
  826. 			 
  827. 			vint_set_property( List_highlight_h, "anchor", 0, y ) 
  828. 			 
  829. 		--else 
  830. 			--play some error sound 
  831. 		--	Grid_add_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_X" }, nil, false ) 
  832. 		--end 
  833. 	end 
  834. end 
  835.  
  836. function hack_main_sticks_button_b(event, acceleration) 
  837. 	if Hack_controls_locked then 
  838. 		if Hack_tutorial_active and Hack_popup_ready then 
  839. 			Hack_controls_locked = false 
  840. 			Hack_tutorial_active = false 
  841. 			hack_main_sticks_launch_popup() 
  842. 			Hack_timer_thread = thread_new( "hack_main_sticks_timer_thread" ) 
  843. 			Input_tracker:subscribe(true) 
  844. 			Tutorial_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Tutorial_Out" }, nil, false ) 
  845. 			--game_UI_audio_play("UI_Cell_Select") 
  846. 			return 
  847. 		elseif Hack_complete then 
  848. 			game_UI_audio_play( "UI_Cell_Select" ) 
  849. 			hacking_screen_exit() 
  850. 		end 
  851. 	end 
  852. 	 
  853. 	if A_mode and Hack_controls_locked == false then 
  854. 		--get the current cell type 
  855. 		local current_type = Hack_main_data.hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type 
  856. 		-- if we are not a blank cell 
  857. 		if current_type > 0 then 
  858. 			--add one back to the list of cell types 
  859. 			Hack_main_data.hack_list_data [ current_type ].amount = Hack_main_data.hack_list_data [ current_type ].amount + 1 
  860. 			--clear out the cell 
  861. 			Hack_main_data.hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type = 0 
  862. 			--set the cell to be blank 
  863. 			hack_main_sticks_set_cell_image( Grid_x_idx, Grid_y_idx ) 
  864. 			--recheck if we are valid 
  865. 			hack_main_sticks_validate_cells() 
  866. 			--update the list of cell types 
  867. 			hack_main_sticks_refresh_list() 
  868. 			hack_main_sticks_update_total() 
  869. 			 
  870. 			local unhighlight_anim_h = vint_object_find( "unhighlight_anim" )  
  871. 			lua_play_anim( unhighlight_anim_h, 0 ) 
  872. 			 
  873. 			Grid_remove_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_Delete" }, nil, false ) 
  874. 			 
  875. 			local list_type = Hack_main_data.hack_list_data[ List_idx ].type 
  876. 			local current_amount = Hack_main_data.hack_list_data [ List_idx ].amount 
  877. 			if current_amount < 1 and list_type > 0 then 
  878. 				local upper_limit = TILE_HEIGHT 
  879. 				local bottom_limit = TILE_HEIGHT * 6 
  880. 				local x ,y = vint_get_property( List_highlight_h, "anchor" ) 
  881. 				local count = 0 
  882. 				local check = true 
  883. 				while check do 
  884. 					if Hack_main_data.hack_list_data [ List_idx ].amount <= 0 then 
  885. 						y = y + TILE_HEIGHT 
  886. 						List_idx = List_idx + 1 
  887. 						if y > bottom_limit then 
  888. 							y = upper_limit 
  889. 							List_idx = 1 
  890. 						end 
  891. 					else 
  892. 						check = false 
  893. 					end 
  894. 					count = count + 1 
  895. 					if count > List_height - 1 then 
  896. 						check = false 
  897. 					end 
  898. 				end 
  899. 				vint_set_property( List_highlight_h, "anchor", 0, y ) 
  900. 			end 
  901. 			hack_main_sticks_set_highlight_image() 
  902. 		else 
  903. 			Grid_add_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_X" }, nil, false ) 
  904. 		end 
  905. 	end 
  906. end 
  907.  
  908. function hack_main_sticks_button_a(event, acceleration) 
  909. 	if Hack_controls_locked then 
  910. 		if Hack_tutorial_active and Hack_popup_ready then 
  911. 			Hack_controls_locked = false 
  912. 			Hack_tutorial_active = false 
  913. 			hack_main_sticks_launch_popup() 
  914. 			Hack_timer_thread = thread_new("hack_main_sticks_timer_thread") 
  915. 			Input_tracker:subscribe(true) 
  916. 			Tutorial_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Tutorial_Out" }, nil, false ) 
  917. 			return 
  918. 		elseif Hack_complete then 
  919. 			game_UI_audio_play("UI_Cell_Select") 
  920. 			hacking_screen_exit() 
  921. 		end 
  922. 	end 
  923. 	 
  924. 	if A_mode and Hack_controls_locked == false then 
  925. 		local grid_type = Hack_main_data.hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type 
  926. 		local list_type = Hack_main_data.hack_list_data[ List_idx ].type 
  927. 		local current_amount = Hack_main_data.hack_list_data [ List_idx ].amount 
  928. 		if grid_type >= 0 then 
  929. 			if grid_type ~= list_type then 
  930. 				if current_amount > 0 or list_type == 0 then 
  931. 					if grid_type > 0 then 
  932. 						Hack_main_data.hack_list_data[ grid_type ].amount = Hack_main_data.hack_list_data[ grid_type ].amount + 1 
  933. 					end 
  934. 					if list_type > 0 then 
  935. 						Hack_main_data.hack_list_data [ List_idx ].amount = Hack_main_data.hack_list_data [ List_idx ].amount - 1 
  936. 					end 
  937. 					 
  938. 					Grid_add_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_Place" }, nil, false ) 
  939.  
  940. 					lua_play_anim( Highlight_anim_h, 0 ) 
  941. 					 
  942. 					hack_main_sticks_update_cell( Grid_x_idx, Grid_y_idx ) 
  943. 					 
  944. 					--recheck if we are valid 
  945. 					hack_main_sticks_validate_cells() 
  946. 					 
  947. 					--update the list of cell types 
  948. 					hack_main_sticks_refresh_list() 
  949. 					 
  950. 					hack_main_sticks_update_total() 
  951. 					 
  952. 					current_amount = Hack_main_data.hack_list_data [ List_idx ].amount 
  953. 					if current_amount < 1 and list_type > 0 then 
  954. 						local upper_limit = TILE_HEIGHT 
  955. 						local bottom_limit = TILE_HEIGHT * 6 
  956. 						local x ,y = vint_get_property( List_highlight_h, "anchor" ) 
  957. 						local count = 0 
  958. 						local check = true 
  959. 						while check do 
  960. 							if Hack_main_data.hack_list_data [ List_idx ].amount <= 0 then 
  961. 								y = y + TILE_HEIGHT 
  962. 								List_idx = List_idx + 1 
  963. 								if y > bottom_limit then 
  964. 									y = upper_limit 
  965. 									List_idx = 1 
  966. 								end 
  967. 							else 
  968. 								check = false 
  969. 							end 
  970. 							count = count + 1 
  971. 							if count > List_height - 1 then 
  972. 								check = false 
  973. 							end 
  974. 						end 
  975. 						hack_main_sticks_set_highlight_image() 
  976. 						vint_set_property( List_highlight_h, "anchor", 0, y ) 
  977. 					end 
  978. 				else 
  979. 					Grid_add_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_X" }, nil, false ) 
  980. 				end 
  981. 			end 
  982. 		else 
  983. 			--play error sound we are on a dead tile 
  984. 			Grid_add_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_X" }, nil, false ) 
  985. 		end 
  986. 	end 
  987. end 
  988.  
  989. function hack_main_sticks_unlock_controls() 
  990. 	Input_tracker:subscribe(true) 
  991. 	if Hack_mouse_input_tracker ~= nil then 
  992. 		hack_main_sticks_add_mouse_inputs() 
  993. 		Hack_mouse_input_tracker:subscribe(true) 
  994. 	end 
  995. end 
  996.  
  997. function hack_main_sticks_lock_controls() 
  998. 	Input_tracker:subscribe(false) 
  999. 	if Hack_mouse_input_tracker ~= nil then 
  1000. 		Hack_mouse_input_tracker:subscribe(false) 
  1001. 	end 
  1002. end 
  1003.  
  1004. function hack_main_sticks_set_list_highlight( new_idx ) 
  1005. 	local x ,y = vint_get_property(List_highlight_h, "anchor") 
  1006. 	if new_idx >= 0 then 
  1007. 		List_idx = new_idx 
  1008. 		if new_idx > 0 then 
  1009. 			y = TILE_HEIGHT * new_idx --1 * ( TILE_HEIGHT * new_idx ) 
  1010. 		else 
  1011. 			y = 0 
  1012. 		end 
  1013. 		vint_set_property(List_highlight_h, "anchor", 0, y) 
  1014. 	else 
  1015. 		vint_set_property(List_highlight_h, "anchor", 0, 0) 
  1016. 	end 
  1017. 	hack_main_sticks_set_highlight_image() 
  1018. end 
  1019.  
  1020. function hack_main_sticks_set_list_mouse_highlight( new_idx ) 
  1021. 	local list_mouse_highlight_h = vint_object_find( "list_mouse_highlight_grp" ) 
  1022. 	local x ,y = vint_get_property(list_mouse_highlight_h, "anchor") 
  1023. 	if new_idx >= 0 then 
  1024. 		--List_idx = new_idx 
  1025. 		if new_idx > 0 then 
  1026. 			y = TILE_HEIGHT * new_idx --1 * ( TILE_HEIGHT * new_idx ) 
  1027. 		else 
  1028. 			y = 0 
  1029. 		end 
  1030. 		vint_set_property(list_mouse_highlight_h, "anchor", 0, y) 
  1031. 	else 
  1032. 		vint_set_property(list_mouse_highlight_h, "anchor", 0, 0) 
  1033. 	end 
  1034. 	--hack_main_sticks_set_highlight_image() 
  1035. end 
  1036.  
  1037. function hack_main_sticks_set_grid_highlight_start() 
  1038. 	local x ,y = vint_get_property(Grid_highlight_h, "anchor") 
  1039. 	vint_set_property( Grid_highlight_h, "anchor", 0, ((Hack_main_data.hack_start) * TILE_HEIGHT) ) 
  1040. 	Grid_x_idx = 0 
  1041. 	Grid_y_idx = Hack_main_data.hack_start 
  1042. end 
  1043.  
  1044. function hack_main_sticks_set_grid_highlight(direction) 
  1045. 	local x ,y = vint_get_property(Grid_highlight_h, "anchor") 
  1046. 	local prev_x,prev_y = vint_get_property(Grid_highlight_h, "anchor") 
  1047. 	if direction == 1 then 
  1048. 	-- RIGHT 
  1049. 		x = x + TILE_WIDTH 
  1050. 		Grid_x_idx = Grid_x_idx + 1 
  1051. 	elseif direction == -1 then 
  1052. 	-- LEFT 
  1053. 		x = x - TILE_WIDTH 
  1054. 		Grid_x_idx = Grid_x_idx - 1 
  1055. 	elseif direction == 2 then 
  1056. 	-- DOWN 
  1057. 		y = y + TILE_HEIGHT 
  1058. 		Grid_y_idx = Grid_y_idx + 1 
  1059. 	elseif direction == -2 then 
  1060. 	-- UP 
  1061. 		y = y - TILE_HEIGHT 
  1062. 		Grid_y_idx = Grid_y_idx - 1 
  1063. 	end 
  1064. 	--check the limits 
  1065. 	if x > Grid_max_width then 
  1066. 		x = Grid_max_width 
  1067. 		Grid_x_idx = Grid_width - 1 
  1068. 	elseif x < 0 then 
  1069. 		x = 0 
  1070. 		Grid_x_idx = 0 
  1071. 	end 
  1072. 	if y > Grid_max_height then 
  1073. 		y = Grid_max_height 
  1074. 		Grid_y_idx = Grid_height - 1 
  1075. 	elseif y < 0 then 
  1076. 		y = 0 
  1077. 		Grid_y_idx = 0 
  1078. 	end 
  1079. 	 
  1080. 	vint_set_property(Grid_highlight_h, "anchor", x, y) 
  1081. 	 
  1082. 	if x ~= prev_x or y ~= prev_y then 
  1083. 		Grid_move_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Grid_Highlight" }, nil, false ) 
  1084. 	end 
  1085. 	 
  1086. 	if A_mode then 
  1087. 		vint_set_property( Grid_highlight_image_h, "scale", 0.9, 0.9 ) 
  1088. 		vint_set_property( Grid_highlight_image_h, "alpha", 0.8 ) 
  1089. 	end 
  1090. 	 
  1091. 	local current_type = Hack_main_data.hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type 
  1092. 	 
  1093. 	if current_type > 0 then 
  1094. 		hack_main_sticks_set_highlight_image() 
  1095. 	end 
  1096. 	 
  1097. end 
  1098.  
  1099. function hack_main_sticks_update_cell( cell_x, cell_y ) 
  1100. 	 
  1101. 	local current_type = Hack_main_data.hack_grid_data[ cell_x ][ cell_y ].type 
  1102. 	local list_type = Hack_main_data.hack_list_data [ List_idx ].type 
  1103. 	 
  1104. 	if current_type >= 0 then 
  1105. 		if current_type ~= list_type then 
  1106. 			Hack_main_data.hack_grid_data[ cell_x ][ cell_y ].type = list_type 
  1107. 			hack_main_sticks_set_cell_image( cell_x, cell_y ) 
  1108. 			hack_main_sticks_validate_cells() 
  1109. 		end 
  1110. 	end 
  1111. end 
  1112.  
  1113. function hack_main_sticks_set_cell_image( cell_x, cell_y ) 
  1114. 	local cell_type = Hack_main_data.hack_grid_data[ cell_x ][ cell_y ].type 
  1115. 	local cell_handle = Hack_main_data.hack_grid_data[ cell_x ][ cell_y ].handle 
  1116. 	 
  1117. 	if cell_type == -1 then 
  1118. 		vint_set_property( cell_handle, "image", "ui_hack_grid_lock" ) 
  1119. 		vint_set_property( cell_handle, "alpha", 0.33 ) 
  1120. 	elseif cell_type == 0 then 
  1121. 		vint_set_property( cell_handle, "image", "ui_hack_grid_blank" ) 
  1122. 		vint_set_property( cell_handle, "alpha", 0.0 ) 
  1123. 	elseif cell_type == 1 then 
  1124. 		vint_set_property( cell_handle, "image", "ui_hack_grid_hor" ) 
  1125. 		vint_set_property( cell_handle, "alpha", 1.0 ) 
  1126. 	elseif cell_type == 2 then 
  1127. 		vint_set_property( cell_handle, "image", "ui_hack_grid_vert" ) 
  1128. 		vint_set_property( cell_handle, "alpha", 1.0 ) 
  1129. 	elseif cell_type == 3 then 
  1130. 		vint_set_property( cell_handle, "image", "ui_hack_grid_ne" ) 
  1131. 		vint_set_property( cell_handle, "alpha", 1.0 ) 
  1132. 	elseif cell_type == 4 then 
  1133. 		vint_set_property( cell_handle, "image", "ui_hack_grid_se" ) 
  1134. 		vint_set_property( cell_handle, "alpha", 1.0 ) 
  1135. 	elseif cell_type == 5 then 
  1136. 		vint_set_property( cell_handle, "image", "ui_hack_grid_sw" ) 
  1137. 		vint_set_property( cell_handle, "alpha", 1.0 ) 
  1138. 	elseif cell_type == 6 then 
  1139. 		vint_set_property( cell_handle, "image", "ui_hack_grid_nw" ) 
  1140. 		vint_set_property( cell_handle, "alpha", 1.0 ) 
  1141. 	end 
  1142. end 
  1143.  
  1144. function hack_main_sticks_set_highlight_image() 
  1145. 	local cell_type = Hack_main_data.hack_list_data [ List_idx ].type 
  1146. 	local cell_amount = Hack_main_data.hack_list_data [ List_idx ].amount 
  1147. 	local cell_handle = Grid_highlight_image_h 
  1148. 	debug_print("vint","cell_type = "..var_to_string( cell_type ).."\n") 
  1149. 	debug_print("vint","cell_amount = "..var_to_string( cell_amount ).."\n") 
  1150. 	debug_print("vint","List_idx = "..var_to_string( List_idx ).."\n\n") 
  1151. 	if cell_amount > 0 then 
  1152. 		vint_set_property( Grid_highlight_image_h, "visible", true ) 
  1153. 	else 
  1154. 		vint_set_property( Grid_highlight_image_h, "visible", false ) 
  1155. 	end 
  1156. 	vint_set_property( Grid_highlight_image_h, "scale", 0.9, 0.9 ) 
  1157. 	local cell_alpha = 0.9 
  1158. 	if cell_type == -1 then 
  1159. 		vint_set_property( cell_handle, "image", "ui_hack_grid_lock" ) 
  1160. 	elseif cell_type == 0 then 
  1161. 		vint_set_property( cell_handle, "image", "ui_blank" ) 
  1162. 		vint_set_property( cell_handle, "alpha", 0) 
  1163. 	elseif cell_type == 1 then 
  1164. 		vint_set_property( cell_handle, "image", "ui_hack_grid_hor" ) 
  1165. 		vint_set_property( cell_handle, "alpha", cell_alpha ) 
  1166. 	elseif cell_type == 2 then 
  1167. 		vint_set_property( cell_handle, "image", "ui_hack_grid_vert" ) 
  1168. 		vint_set_property( cell_handle, "alpha", cell_alpha ) 
  1169. 	elseif cell_type == 3 then 
  1170. 		vint_set_property( cell_handle, "image", "ui_hack_grid_ne" ) 
  1171. 		vint_set_property( cell_handle, "alpha", cell_alpha) 
  1172. 	elseif cell_type == 4 then 
  1173. 		vint_set_property( cell_handle, "image", "ui_hack_grid_se" ) 
  1174. 		vint_set_property( cell_handle, "alpha", cell_alpha ) 
  1175. 	elseif cell_type == 5 then 
  1176. 		vint_set_property( cell_handle, "image", "ui_hack_grid_sw" ) 
  1177. 		vint_set_property( cell_handle, "alpha", cell_alpha ) 
  1178. 	elseif cell_type == 6 then 
  1179. 		vint_set_property( cell_handle, "image", "ui_hack_grid_nw" ) 
  1180. 		vint_set_property( cell_handle, "alpha", cell_alpha ) 
  1181. 	end 
  1182. end 
  1183.  
  1184. function hack_main_sticks_set_pipe( handle, cell_type ) 
  1185. 	if cell_type == -1 then 
  1186. 		vint_set_property( handle, "image", "ui_hack_grid_lock" ) 
  1187. 	elseif cell_type == 0 then 
  1188. 		vint_set_property( handle, "image", "ui_hack_grid_blank" ) 
  1189. 	elseif cell_type == 1 then 
  1190. 		vint_set_property( handle, "image", "ui_hack_grid_pipe_hor" ) 
  1191. 	elseif cell_type == 2 then 
  1192. 		vint_set_property( handle, "image", "ui_hack_grid_pipe_vert" ) 
  1193. 	elseif cell_type == 3 then 
  1194. 		vint_set_property( handle, "image", "ui_hack_grid_pipe_ne" ) 
  1195. 	elseif cell_type == 4 then 
  1196. 		vint_set_property( handle, "image", "ui_hack_grid_pipe_se" ) 
  1197. 	elseif cell_type == 5 then 
  1198. 		vint_set_property( handle, "image", "ui_hack_grid_pipe_sw" ) 
  1199. 	elseif cell_type == 6 then 
  1200. 		vint_set_property( handle, "image", "ui_hack_grid_pipe_nw" ) 
  1201. 	end 
  1202. end 
  1203.  
  1204. function hack_main_sticks_draw_list() 
  1205. 	--loop through the list of cells and store handles 
  1206. 	for i = 0, List_height - 1 do 
  1207. 		--store handles if we have not done so already 
  1208. 		if Hack_main_data.hack_list_data [ i ].handle == nil then 
  1209. 			Hack_main_data.hack_list_data [ i ].handle = vint_object_find( Hack_main_data.hack_list_data [ i ].name ) 
  1210. 			Hack_main_data.hack_list_data [ i ].txt = vint_object_find( "cell_txt", Hack_main_data.hack_list_data [ i ].handle ) 
  1211. 			Hack_main_data.hack_list_data [ i ].bg = vint_object_find( "cell_txt_bg", Hack_main_data.hack_list_data [ i ].handle ) 
  1212. 			Hack_main_data.hack_list_data [ i ].image = vint_object_find( "cell_image", Hack_main_data.hack_list_data [ i ].handle ) 
  1213. 		end 
  1214. 		--reset the amount to the max amount you can have 
  1215. 		Hack_main_data.hack_list_data [ i ].amount = Hack_main_data.hack_list_data [ i ].max_amount 
  1216. 		Hack_main_data.hack_list_data [ i ].amount_used = 0 
  1217. 	end 
  1218. 	--update the visual state of the cells in the list 
  1219. 	hack_main_sticks_refresh_list() 
  1220. end 
  1221.  
  1222. function hack_main_sticks_refresh_list() 
  1223. 	--loop through all the list items 
  1224. 	for i = 0, List_height - 1 do 
  1225. 		--grab the amount 
  1226. 		local amount = Hack_main_data.hack_list_data [ i ].amount 
  1227. 		--if we are not the blank cell then refresh 
  1228. 		if amount >= 0 then 
  1229. 			--set the amount 
  1230. 			vint_set_property( Hack_main_data.hack_list_data [ i ].txt, "text_tag", Hack_main_data.hack_list_data [ i ].amount ) 
  1231. 			--if we have no pieces and we are not blank then turn us off 
  1232. 			if amount == 0 and Hack_main_data.hack_list_data [ i ].type > 0 then 
  1233. 				vint_set_property( Hack_main_data.hack_list_data [ i ].image, "tint", 0.5,0.5,0.5) 
  1234. 			else 
  1235. 			--if we have pieces and we are not blank then turn us on 
  1236. 				vint_set_property( Hack_main_data.hack_list_data [ i ].image, "tint", 1, 1, 1 ) 
  1237. 			end 
  1238. 		else 
  1239. 		--we are the blank cell so we have infinite pieces, don't show the amount ever 
  1240. 			vint_set_property( Hack_main_data.hack_list_data [ i ].txt, "visible", false) 
  1241. 			vint_set_property( Hack_main_data.hack_list_data [ i ].bg, "visible", false) 
  1242. 		end 
  1243. 	end 
  1244. end 
  1245.  
  1246. function hack_main_sticks_update_amount( prev_idx ) 
  1247. 	--if the current tile is not blank then change the amount 
  1248. 	if Hack_main_data.hack_list_data [ List_idx ].type > 0  then 
  1249. 		--take one tile away 
  1250. 		Hack_main_data.hack_list_data [ List_idx ].amount = Hack_main_data.hack_list_data [ List_idx ].amount - 1 
  1251. 		Hack_main_data.hack_list_data [ List_idx ].amount_used = Hack_main_data.hack_list_data [ List_idx ].amount_used + 1 
  1252. 		--check if we are now negative 
  1253. 		if Hack_main_data.hack_list_data [ List_idx ].amount < 0 then 
  1254. 			Hack_main_data.hack_list_data [ List_idx ].amount = 0  
  1255. 		end 
  1256. 	end 
  1257. 	 
  1258. 	--if the previous tile was not blank then add one back 
  1259. 	if Hack_main_data.hack_list_data [ prev_idx ].type > 0 then 
  1260. 		Hack_main_data.hack_list_data [ prev_idx ].amount = Hack_main_data.hack_list_data [ prev_idx ].amount + 1 
  1261. 		Hack_main_data.hack_list_data [ List_idx ].amount_used = Hack_main_data.hack_list_data [ List_idx ].amount_used - 1 
  1262. 	end 
  1263. 	 
  1264. 	hack_main_sticks_refresh_list() 
  1265. end 
  1266. 								 
  1267. function hack_main_sticks_draw_grid() 
  1268. 	local cur_y = 0 
  1269. 	local tile_count = 0 
  1270. 	--loop through the amount of cells needed 
  1271. 	for tile_y = 0, Grid_height - 1 do 
  1272. 		for tile_x = 0, Grid_width - 1 do  
  1273. 			local bitmap_h = vint_object_create( "grid_blank", "bitmap", Grid_h ) 
  1274. 			local pipe_h = vint_object_create( "pipe_blank", "bitmap", Grid_h ) 
  1275. 			--store the handle 
  1276. 			Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].handle = bitmap_h 
  1277. 			Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].pipe = pipe_h 
  1278. 			 
  1279. 			--set the image 
  1280. 			hack_main_sticks_set_cell_image( tile_x, tile_y ) 
  1281. 			vint_set_property( pipe_h, "depth", -100 ) 
  1282. 			vint_set_property( pipe_h, "visible", false ) 
  1283. 			vint_set_property( pipe_h, "image", "ui_hack_grid_pipe_hor" ) 
  1284. 			 
  1285. 			--position... 
  1286. 			local x = (tile_x * TILE_WIDTH) + 6 
  1287. 			local y = 7 + cur_y 
  1288. 			vint_set_property( bitmap_h, "anchor", x, y ) 
  1289. 			 
  1290. 			x = (tile_x * TILE_WIDTH) - 6 
  1291. 			y = cur_y - 2 
  1292. 			vint_set_property( pipe_h, "anchor", x, y ) 
  1293. 			 
  1294. 			tile_count = tile_count + 1 
  1295. 		end 
  1296. 		--Increment y positon... 
  1297. 		cur_y = cur_y + TILE_HEIGHT 
  1298. 	end 
  1299. 	 
  1300. 	cur_y = 0 
  1301. 	tile_count = 0 
  1302. 	for tile_y = 0, Grid_height - 1 do 
  1303. 		for tile_x = 0, Grid_width - 1 do  
  1304. 			local bitmap_h = vint_object_create( "bg_blank", "bitmap", Grid_h ) 
  1305. 			 
  1306. 			Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].bg_handle = bitmap_h 
  1307. 			 
  1308. 			vint_set_property( bitmap_h, "image", "ui_hack_grid_blank" ) 
  1309. 			vint_set_property( bitmap_h, "alpha", 0.40 ) 
  1310. 			vint_set_property( bitmap_h, "depth", 100 ) 
  1311. 			--position... 
  1312. 			local x = tile_x * TILE_WIDTH 
  1313. 			local y = cur_y 
  1314. 			vint_set_property( bitmap_h, "anchor", x, y ) 
  1315. 			 
  1316. 			tile_count = tile_count + 1 
  1317. 		end 
  1318. 		--Increment y positon... 
  1319. 		cur_y = cur_y + TILE_HEIGHT 
  1320. 	end 
  1321. 	 
  1322. 	 
  1323. 	--set the start point 
  1324. 	local cell_start_grp_h = vint_object_find( "cell_start_grp" ) 
  1325. 	vint_set_property( cell_start_grp_h, "anchor", 5, ((Hack_main_data.hack_start + 1) * TILE_HEIGHT) - (TILE_HEIGHT * 0.5)) 
  1326. 	 
  1327. 	--set the end point(s) 
  1328. 	local cell_end_grp_h = vint_object_find( "cell_end_grp" ) 
  1329. 	vint_set_property( cell_end_grp_h, "anchor", (Grid_width * TILE_WIDTH) - 15, ((Hack_main_data.hack_end + 1) * TILE_HEIGHT) - (TILE_HEIGHT * 0.5)) 
  1330. 	 
  1331. 	--set up the list handles and tile amounts 
  1332. 	hack_main_sticks_draw_list() 
  1333. end 
  1334.  
  1335. function hack_main_sticks_reset_grid() 
  1336. 	--loop through the grid and reset anything that is not invalid or blank 
  1337. 	for y = 0, Grid_height - 1 do 
  1338. 		for x = 0, Grid_width - 1 do  
  1339. 			local type = Hack_main_data.hack_grid_data[ x ][ y ].type 
  1340. 			--if we are not invalid or blank then set us to blank 
  1341. 			if type > 0 then 
  1342. 				Hack_main_data.hack_grid_data[ x ][ y ].type = 0 
  1343. 				hack_main_sticks_set_cell_image( x, y ) 
  1344. 				vint_set_property( Hack_main_data.hack_grid_data[ x ][ y ].pipe, "visible", false ) 
  1345. 			end 
  1346. 			--reset all the tints 
  1347. 			vint_set_property( Hack_main_data.hack_grid_data[ x ][ y ].handle, "tint", 1, 1, 1 ) 
  1348. 		end 
  1349. 	end 
  1350. 	--refresh all our piece amounts in the list and redraw it 
  1351. 	hack_main_sticks_draw_list() 
  1352. 	hack_main_sticks_set_list_highlight( 1 ) 
  1353. 	hack_main_sticks_set_highlight_image() 
  1354. 	hack_main_sticks_set_grid_highlight_start() 
  1355. 	hack_main_sticks_update_total() 
  1356. 	Grid_reset_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Grid_Reset" }, nil, false ) 
  1357. 	vint_set_property( List_highlight_h, "visible", true ) 
  1358. end 
  1359.  
  1360. function hack_main_sticks_update_total() 
  1361. 	List_total = 0 
  1362. 	for i = 1, 6 do 
  1363. 		List_total = List_total + Hack_main_data.hack_list_data[ i ].amount 
  1364. 	end 
  1365. 	if List_total > 0 then 
  1366. 		vint_set_property( List_highlight_h, "visible", true ) 
  1367. 	else 
  1368. 		vint_set_property( List_highlight_h, "visible", false ) 
  1369. 	end 
  1370. end 
  1371.  
  1372. function hack_main_sticks_pause() 
  1373. 	local pause_scrim_h = vint_object_find( "pause_scrim" ) 
  1374. 	local pause_scrim_hints_h = vint_object_find( "pause_scrim_hints" ) 
  1375. 	local list_grp_h = vint_object_find( "cell_list_grp" ) 
  1376. 	if Is_paused then 
  1377. 		vint_set_property( pause_scrim_h, "visible", true ) 
  1378. 		vint_set_property( pause_scrim_hints_h, "visible", true ) 
  1379. 		vint_set_property( list_grp_h, "visible", false ) 
  1380. 		if game_get_platform() == "PC" then 
  1381. 			Hack_mouse_input_tracker:subscribe(false) 
  1382. 		end 
  1383. 	else 
  1384. 		vint_set_property( pause_scrim_h, "visible", false ) 
  1385. 		vint_set_property( pause_scrim_hints_h, "visible", false ) 
  1386. 		vint_set_property( list_grp_h, "visible", true ) 
  1387. 		if game_get_platform() == "PC" then 
  1388. 			Hack_mouse_input_tracker:subscribe(true) 
  1389. 		end 
  1390. 	end 
  1391. end 
  1392.  
  1393. function hack_main_sticks_set_popup_highlight( direction ) 
  1394. 	local highlight_grp_h = vint_object_find( "popup_list_highlight_grp" ) 
  1395. 	local button_height = 30 
  1396. 	local highlight_x,highlight_y = vint_get_property( highlight_grp_h, "anchor" ) 
  1397. 	if direction == 1 then 
  1398. 		highlight_y = highlight_y + button_height 
  1399. 	end 
  1400. 	if direction == -1 then 
  1401. 		highlight_y = highlight_y - button_height 
  1402. 	end 
  1403. 	if highlight_y < 0 then 
  1404. 		highlight_y = button_height 
  1405. 	end 
  1406. 	if highlight_y > button_height then 
  1407. 		highlight_y = 0 
  1408. 	end 
  1409. 	vint_set_property( highlight_grp_h, "anchor", highlight_x, highlight_y ) 
  1410. end 
  1411.  
  1412. function hack_main_sticks_launch_popup( success, message ) 
  1413. 	Hack_popup_open = true 
  1414. 	local popup_grp_h = vint_object_find( "popup_grp" ) 
  1415. 	local popup_title_h = vint_object_find( "popup_title" ) 
  1416. 	local popup_message_h = vint_object_find( "popup_text" ) 
  1417. 	local popup_animate_in_h = vint_object_find( "popup_animate_in" ) 
  1418. 	local popup_animate_out_h = vint_object_find( "popup_animate_out" ) 
  1419. 	vint_set_property( popup_message_h, "visible", false ) 
  1420. 	 
  1421. 	local popup_list_grp_h = vint_object_find( "popup_list_grp" ) 
  1422. 	vint_set_property( popup_list_grp_h, "visible", false ) 
  1423. 	 
  1424. 	local popup_footer_grp_h = vint_object_find( "popup_footer_grp" ) 
  1425. 	local popup_background_h = vint_object_find( "popup_background" ) 
  1426. 	local popup_elements_grp_h = vint_object_find( "popup_move_grp" ) 
  1427. 	if Popup_defaults_changed == false then 
  1428. 		Popup_footer_grp_x, Popup_footer_grp_y = vint_get_property( popup_footer_grp_h, "anchor" ) 
  1429. 		 
  1430. 		Popup_background_width, Popup_background_height = element_get_actual_size( popup_background_h) 
  1431. 		Popup_background_x, Popup_background_y = vint_get_property( popup_background_h, "anchor" ) 
  1432. 		 
  1433. 		Popup_elements_grp_x, Popup_elements_grp_y = vint_get_property( popup_elements_grp_h, "anchor" ) 
  1434. 	else 
  1435. 		vint_set_property( popup_footer_grp_h, "anchor", Popup_footer_grp_x, Popup_footer_grp_y ) 
  1436. 		 
  1437. 		element_set_actual_size( popup_background_h, Popup_background_width, Popup_background_height ) 
  1438. 		vint_set_property( popup_background_h, "anchor", Popup_background_x, Popup_background_y ) 
  1439. 		 
  1440. 		vint_set_property( popup_elements_grp_h, "anchor", Popup_elements_grp_x, Popup_elements_grp_y) 
  1441. 	end 
  1442. 	 
  1443. 	 
  1444. 	 
  1445. 	local hint_data = { 
  1446. 		{CTRL_MENU_BUTTON_A, "CONTROL_CONTINUE"}, 
  1447. 	} 
  1448. 	Popup_hint_bar:set_hints(hint_data) 
  1449. 	 
  1450. 	if game_get_platform() == "PC" then 
  1451. 		Hack_mouse_input_tracker:subscribe(false) 
  1452. 		 
  1453. 		Hack_popup_mouse_input_tracker:subscribe(true) 
  1454. 	end 
  1455. 	 
  1456. 	if message ~= nil then 
  1457. 		debug_print("vint","START MESSAGE POPUP\n") 
  1458. 		vint_set_property( popup_title_h, "visible", false ) 
  1459. 		vint_set_property( popup_message_h, "visible", true ) 
  1460. 		vint_set_property( popup_message_h, "text_tag", message ) 
  1461. 		lua_play_anim( popup_animate_in_h ) 
  1462. 		vint_apply_start_values( popup_animate_in_h ) 
  1463. 		Hack_popup_ready = false 
  1464. 		Tutorial_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Tutorial_In" }, nil, false ) 
  1465. 		 
  1466. 		local message_width, message_height = element_get_actual_size(popup_message_h) 
  1467. 		--debug_print("vint", "hack_main_sticks.lua :::: hack_main_sticks_launch_popup :::: message_width = " .. var_to_string(message_width) .. ", message_height = " .. var_to_string(message_height) .. "\n") 
  1468. 		if message_height > 175 then 
  1469. 			 
  1470. 			local height_diff = message_height - 175 						-- Determine the difference in height 
  1471. 			local height_increase_percent = 1 + (height_diff / 175)	-- Determine the percent of how much larger the diff is, ex: 1.5 = 150% larger 
  1472. 			 
  1473. 			 
  1474. 			vint_set_property( popup_footer_grp_h, "anchor", Popup_footer_grp_x, Popup_footer_grp_y + height_diff ) 
  1475. 			 
  1476. 			element_set_actual_size( popup_background_h, Popup_background_width, Popup_background_height * height_increase_percent ) 
  1477. 			vint_set_property( popup_background_h, "anchor", Popup_background_x, Popup_background_y + (height_diff/2) ) 
  1478. 			 
  1479. 			vint_set_property( popup_elements_grp_h, "anchor", Popup_elements_grp_x, Popup_elements_grp_y - height_diff/2 ) 
  1480. 			 
  1481. 			Popup_defaults_changed = true 
  1482. 		end 
  1483. 	else 
  1484. 		if success then 
  1485. 			hacking_screen_report( true ) 
  1486. 			vint_set_property( popup_title_h, "visible", true ) 
  1487. 			vint_set_property( popup_title_h, "text_tag", "MENU_HACK_COMPLETE" ) 
  1488. 			lua_play_anim( popup_animate_in_h ) 
  1489. 			vint_apply_start_values( popup_animate_in_h ) 
  1490. 			Hack_popup_ready = false 
  1491. 			audio_stop( Timer_audio_id ) 
  1492. 			Hack_end_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Hack_Complete" }, nil, false ) 
  1493. 		elseif success == false then 
  1494. 			hacking_screen_report( false ) 
  1495. 			vint_set_property( popup_title_h, "visible", true ) 
  1496. 			vint_set_property( popup_title_h, "text_tag", "MENU_HACK_FAILED" ) 
  1497. 			lua_play_anim( popup_animate_in_h ) 
  1498. 			vint_apply_start_values( popup_animate_in_h ) 
  1499. 			Hack_popup_ready = false 
  1500. 			Hack_end_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Hack_Fail" }, nil, false ) 
  1501. 		else 
  1502. 			lua_play_anim( popup_animate_out_h ) 
  1503. 			 
  1504. 			Hack_popup_open = false 
  1505. 			 
  1506. 			if game_get_platform() == "PC" then 
  1507. 				Hack_mouse_input_tracker:subscribe(true) 
  1508. 				 
  1509. 				Hack_popup_mouse_input_tracker:subscribe(false) 
  1510. 			end 
  1511. 		end 
  1512. 		 
  1513. 		local popup_title_width, popup_title_height = element_get_actual_size( popup_title_h ) 
  1514. 		if popup_title_width >= Popup_background_width - 10 then 
  1515. 			resize_text_element( popup_title_h, Popup_background_width - 10 ) 
  1516. 		end 
  1517. 	end 
  1518. end 
  1519.  
  1520. function hack_main_sticks_print_list() 
  1521. 	debug_print("vint","local Hack_main_data.hack_grid_data = {\n") 
  1522. 	for y = 0, Grid_height - 1 do 
  1523. 		debug_print("vint","["..y.."] = {\n") 
  1524. 		for x = 0, Grid_width - 1 do  
  1525. 			debug_print("vint","["..x.."] = {type = "..Hack_main_data.hack_grid_data[y][x].type..",},")--[1] = {type = 0,},[2] = {type = 0,},[3] = {type = 0,},[4] = {type = 0,},[5] = {type = 0,},}, 
  1526. 		end 
  1527. 		debug_print("vint","},\n") 
  1528. 	end 
  1529. 	debug_print("vint","}\n") 
  1530. 	 
  1531. 	debug_print("vint","\nlocal Hack_main_data.hack_list_data  = {\n") 
  1532. 	for i = 0, List_height - 1 do 
  1533. 		debug_print("vint","["..i.."] = {\n") 
  1534. 		debug_print("vint","type = "..Hack_main_data.hack_list_data [i].type..",\n") 
  1535. 		debug_print("vint","max_amount = "..Hack_main_data.hack_list_data [i].amount_used..",\n") 
  1536. 		debug_print("vint","name = "..Hack_main_data.hack_list_data [i].name..",\n") 
  1537. 		debug_print("vint","},\n") 
  1538. 	end 
  1539. 	debug_print("vint","}\n") 
  1540. end 
  1541.  
  1542. function hack_main_sticks_set_a_mode() 
  1543. 	local highlight_button = Vdo_hint_button:new( "highlight_button" ) 
  1544. 	if A_mode then 
  1545. 		A_mode = false 
  1546. 	else 
  1547. 		A_mode = true 
  1548. 	end 
  1549. 	highlight_button:set_visible( A_mode ) 
  1550. 	vint_set_property( Grid_highlight_image_h, "visible", A_mode ) 
  1551. end 
  1552.  
  1553. function hack_main_sticks_draw_side_grids() 
  1554. 	local cur_y = 0 
  1555. 	local tile_count = 0 
  1556. 	local left_grid_grp_h = vint_object_find( "left_grid_grp" ) 
  1557. 	--loop through the amount of cells needed 
  1558. 	for tile_y = 0, 5 do 
  1559. 		for tile_x = 0, 16 do 
  1560. 			local bitmap_h = vint_object_create("grid_blank", "bitmap", left_grid_grp_h) 
  1561. 			--store the handle 
  1562. 			vint_set_property( bitmap_h, "image", "ui_hack_grid_blank" ) 
  1563. 			--position... 
  1564. 			local x = tile_x * (TILE_WIDTH) 
  1565. 			local y = cur_y 
  1566. 			vint_set_property(bitmap_h, "anchor", x, y) 
  1567. 			 
  1568. 			tile_count = tile_count + 1 
  1569. 		end 
  1570. 		--Increment y positon... 
  1571. 		cur_y = cur_y + TILE_HEIGHT 
  1572. 	end 
  1573. end 
  1574.  
  1575. --PC SPECIFIC FUNCTIONS 
  1576. function hack_main_sticks_mouse_click(event, target_handle) 
  1577. 	if Hack_tutorial_active or Hack_popup_open then 
  1578. 		hack_main_sticks_button_a() 
  1579. 		return 
  1580. 	end 
  1581. 	 
  1582. 	local hint_index = Hint_bar:get_hint_index( target_handle ) 
  1583. 	if hint_index == 4 then 
  1584. 		hack_main_sticks_button_x() 
  1585. 	end 
  1586. 	 
  1587. 	if Grid_mouse_lock then 
  1588. 		Grid_mouse_lock = false 
  1589. 	else 
  1590. 		Grid_mouse_lock = true 
  1591. 	end	 
  1592. 	--handle grid highlight 
  1593. 	local tile_h 
  1594. 	for tile_y = 0, Grid_height - 1 do 
  1595. 		for tile_x = 0, Grid_width - 1 do  
  1596. 			tile_h = Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].handle 
  1597. 			if tile_h == target_handle then 
  1598. 				local x,y = vint_get_property( target_handle, "anchor" ) 
  1599. 				vint_set_property( Grid_highlight_h, "anchor", x - 6, y - 8 ) 
  1600. 				Grid_x_idx = tile_x 
  1601. 				Grid_y_idx = tile_y 
  1602. 				Grid_move_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Grid_Highlight" }, nil, false ) 
  1603. 				hack_main_sticks_button_a() 
  1604. 			end 
  1605. 		end 
  1606. 	end 
  1607. 	 
  1608. 	for i = 0, List_height - 1 do 
  1609. 		if target_handle == Hack_main_data.hack_list_data[ i ].handle then 
  1610. 			if Hack_main_data.hack_list_data[ i ].amount > 0 then 
  1611. 				hack_main_sticks_set_list_highlight( i ) 
  1612. 			end 
  1613. 		end 
  1614. 	end 
  1615. end 
  1616.  
  1617. function hack_main_sticks_mouse_right_click(event, target_handle) 
  1618. 	local tile_h 
  1619. 	for tile_y = 0, Grid_height - 1 do 
  1620. 		for tile_x = 0, Grid_width - 1 do  
  1621. 			tile_h = Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].handle 
  1622. 			if tile_h == target_handle then 
  1623. 				local x,y = vint_get_property( target_handle, "anchor" ) 
  1624. 				vint_set_property( Grid_highlight_h, "anchor", x - 6, y - 8 ) 
  1625. 				Grid_x_idx = tile_x 
  1626. 				Grid_y_idx = tile_y 
  1627. 				Grid_move_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Grid_Highlight" }, nil, false ) 
  1628. 			end 
  1629. 		end 
  1630. 	end 
  1631. 	 
  1632. 	hack_main_sticks_button_b() 
  1633. end 
  1634.  
  1635. function hack_main_sticks_mouse_move(event, target_handle)	 
  1636. 	--handle hintbar highlight 
  1637. 	Hint_bar:set_highlight(0) 
  1638. 	local hint_index = Hint_bar:get_hint_index( target_handle ) 
  1639. 	if hint_index == 4 then 
  1640. 		Hint_bar:set_highlight(hint_index) 
  1641. 	end 
  1642. 	 
  1643. 	local tile_h 
  1644. 	for tile_y = 0, Grid_height - 1 do 
  1645. 		for tile_x = 0, Grid_width - 1 do  
  1646. 			tile_h = Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].handle 
  1647. 			if tile_h == target_handle then 
  1648. 				local x,y = vint_get_property( target_handle, "anchor" ) 
  1649. 				vint_set_property( Grid_highlight_h, "anchor", x - 6, y - 8 ) 
  1650. 				Grid_x_idx = tile_x 
  1651. 				Grid_y_idx = tile_y 
  1652. 				Grid_move_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Grid_Highlight" }, nil, false ) 
  1653. 			end 
  1654. 		end 
  1655. 	end 
  1656. 	 
  1657. 	local list_mouse_highlight_h = vint_object_find( "list_mouse_highlight_grp" ) 
  1658. 	vint_set_property( list_mouse_highlight_h, "visible", false ) 
  1659. 	for i = 0, List_height - 1 do 
  1660. 		if target_handle == Hack_main_data.hack_list_data[ i ].handle then 
  1661. 			if Hack_main_data.hack_list_data[ i ].amount > 0 then 
  1662. 				hack_main_sticks_set_list_mouse_highlight( i ) 
  1663. 				vint_set_property( list_mouse_highlight_h, "visible", true ) 
  1664. 			end 
  1665. 		end 
  1666. 	end 
  1667.  
  1668. end 
  1669.  
  1670. function hack_main_sticks_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines)			 
  1671. 	--scroll lines are inverted for some reason 
  1672. 	scroll_lines = scroll_lines * -1 
  1673. 	if scroll_lines < 0 then 
  1674. 		hack_main_sticks_list_up() 
  1675. 	else 
  1676. 		hack_main_sticks_list_down() 
  1677. 	end 
  1678. end 
  1679.  
  1680. --[[ --------------------------------------------------------------------- 
  1681. -- Function - hack_main_sticks_update_gamepad_state 
  1682. -- Description - Called by code anytime gamepad is plugged or unplugged. 
  1683. -- Parameters - none 
  1684. -- Returns - nil 
  1685. ]]-- --------------------------------------------------------------------- 
  1686. function hack_main_sticks_update_gamepad_state() 
  1687. 	hack_main_sticks_set_hints() 
  1688. end