./hack_main_editor.lua

  1. local TILE_SPACING = 8 
  2. local TILE_WIDTH = 70 + TILE_SPACING 
  3. local TILE_HEIGHT = 65 + TILE_SPACING 
  4.  
  5. local LIST_MAX_HEIGHT = 0 
  6.  
  7.  
  8. local Hack_grid_data = { 
  9. 	[0] = { 
  10. 		[0] = {type = 0,},[1] = {type = 0,},[2] = {type = 0,},[3] = {type = 0,},[4] = {type = 0,},[5] = {type = 0,},}, 
  11. 	[1] = { 
  12. 		[0] = {type = 0,},[1] = {type = 0,},[2] = {type = 0,},[3] = {type = 0,},[4] = {type = 0,},[5] = {type = 0,},}, 
  13. 	[2] = { 
  14. 		[0] = {type = 0,},[1] = {type = 0,},[2] = {type = 0,},[3] = {type = 0,},[4] = {type = 0,},[5] = {type = 0,},},	 
  15. 	[3] = { 
  16. 		[0] = {type = 0,},[1] = {type = 0,},[2] = {type = 0,},[3] = {type = 0,},[4] = {type = 0,},[5] = {type = 0,},},	 
  17. 	[4] = { 
  18. 		[0] = {type = 0,},[1] = {type = 0,},[2] = {type = 0,},[3] = {type = 0,},[4] = {type = 0,},[5] = {type = 0,},}, 
  19. 	[5] = { 
  20. 		[0] = {type = 0,},[1] = {type = 0,},[2] = {type = 0,},[3] = {type = 0,},[4] = {type = 0,},[5] = {type = 0,},}, 
  21. } 
  22.  
  23. local Hack_grid_solution_data = { 
  24. 	[0] = { 
  25. 		[0] = {type = 1,},[1] = {type = -1,},[2] = {type = -1,},[3] = {type = -1,},[4] = {type = -1,},[5] = {type = -1,},}, 
  26. 	[1] = { 
  27. 		[0] = {type = 6,},[1] = {type = 2,},[2] = {type = 2,},[3] = {type = 2,},[4] = {type = 3,},[5] = {type = -1,},}, 
  28. 	[2] = { 
  29. 		[0] = {type = -1,},[1] = {type = -1,},[2] = {type = -1,},[3] = {type = -1,},[4] = {type = 1,},[5] = {type = -1,},},	 
  30. 	[3] = { 
  31. 		[0] = {type = -1,},[1] = {type = -1,},[2] = {type = -1,},[3] = {type = -1,},[4] = {type = 1,},[5] = {type = -1,},},	 
  32. 	[4] = { 
  33. 		[0] = {type = -1,},[1] = {type = -1,},[2] = {type = -1,},[3] = {type = -1,},[4] = {type = 6,},[5] = {type = 3,},}, 
  34. 	[5] = { 
  35. 		[0] = {type = -1,},[1] = {type = -1,},[2] = {type = -1,},[3] = {type = -1,},[4] = {type = -1,},[5] = {type = 1,},}, 
  36. } 
  37.  
  38. local Hack_list_data = { 
  39. [0] = { 
  40. type = 0, 
  41. max_amount = -1, 
  42. name = "cell_blank", 
  43. }, 
  44. [1] = { 
  45. type = 1, 
  46. max_amount = 0, 
  47. name = "cell_hor", 
  48. }, 
  49. [2] = { 
  50. type = 2, 
  51. max_amount = 0, 
  52. name = "cell_vert", 
  53. }, 
  54. [3] = { 
  55. type = 3, 
  56. max_amount = 0, 
  57. name = "cell_ne", 
  58. }, 
  59. [4] = { 
  60. type = 4, 
  61. max_amount = 0, 
  62. name = "cell_se", 
  63. }, 
  64. [5] = { 
  65. type = 5, 
  66. max_amount = 0, 
  67. name = "cell_sw", 
  68. }, 
  69. [6] = { 
  70. type = 6, 
  71. max_amount = 0, 
  72. name = "cell_nw", 
  73. }, 
  74. [7] = { 
  75. type = -1, 
  76. max_amount = -1, 
  77. name = "cell_dead", 
  78. }, 
  79. } 
  80. local Hack_start = 0 
  81. local Hack_end = 0 
  82.  
  83. local LIST_HEIGHT = #Hack_list_data + 1 
  84. local Grid_width = 6 
  85. local Grid_height = 6 
  86.  
  87. -- 0 = north, 1 = East, 2, 3 
  88. local Hack_list_connections_data = { 
  89. 	[0] = { -1, -1}, 
  90. 	[1] = { 1, 3 }, 
  91. 	[2] = { 0, 2 }, 
  92. 	[3] = { 0, 1 }, 
  93. 	[4] = { 1, 2 }, 
  94. 	[5] = { 2, 3 }, 
  95. 	[6] = { 0, 3 }, 
  96. } 
  97.  
  98. local Hack_list_connection_directions = { 
  99. 	[0] = 2, 
  100. 	[1] = 3, 
  101. 	[2] = 0, 
  102. 	[3] = 1, 
  103. } 
  104.  
  105.  
  106. local Hack_timer_thread 
  107. local Hack_timer_run = true 
  108.  
  109. local Hint_bar 
  110. local List_h 
  111. local List_highlight_h 
  112. local Grid_h 
  113. local Input_tracker 
  114. local Grid_highlight_h 
  115. local Mouse_input_tracker 
  116. local Hack_main_doc_h = -1 
  117. local New_item_idx = 0 
  118. local Current_idx = 0 
  119. local List_idx = 0 
  120. local Grid_x_idx = 0 
  121. local Grid_y_idx = 0 
  122. local Timer_h = 0 
  123. local Hack_timer = 0 
  124.  
  125. local Grid_max_width = 0 
  126. local Grid_max_height = 0 
  127.  
  128. function hack_main_editor_init() 
  129. 	--[[for x = 0, Grid_height - 1 do 
  130. 		Hack_grid_data[ x ] = { } 
  131. 		for y = 0, Grid_width - 1 do 
  132. 			Hack_grid_data[ x ][ y ] = { } 
  133. 		end 
  134. 	end--]] 
  135.  
  136. 	-- unload the full screen map to pillage memory 
  137. 	pause_map_dump() 
  138. 	 
  139. 	-- Find our documents... 
  140. 	Hack_main_doc_h = vint_document_find("hack_main_editor") 
  141. 	 
  142. 	-- Setup input tracker.+ 
  143. 	local priority = 500000 
  144. 	Input_tracker = Vdo_input_tracker:new() 
  145. 	Input_tracker:add_input("select", "hack_main_editor_button_a", priority) 
  146. 	Input_tracker:add_input("back", "hack_main_editor_button_b", priority) 
  147. 	Input_tracker:add_input("alt_select", "hack_main_editor_button_x", 50) 
  148. 	Input_tracker:add_input("nav_up", "hack_main_editor_nav_up", priority) 
  149. 	Input_tracker:add_input("nav_down", "hack_main_editor_nav_down", priority) 
  150. 	Input_tracker:add_input("nav_left", "hack_main_editor_nav_left", priority) 
  151. 	Input_tracker:add_input("nav_right", "hack_main_editor_nav_right", priority) 
  152. 	Input_tracker:add_input("alt_joy_up", "hack_main_editor_list_up", priority) 
  153. 	Input_tracker:add_input("alt_joy_down", "hack_main_editor_list_down", priority) 
  154. 	Input_tracker:add_input("scroll_left", "hack_main_editor_size_down", priority) 
  155. 	Input_tracker:add_input("scroll_right", "hack_main_editor_size_up", priority) 
  156. 	 
  157. 	Input_tracker:subscribe(true) 
  158. 	 
  159. 	Grid_max_width = TILE_WIDTH * (Grid_width - 1) 
  160. 	Grid_max_height = TILE_HEIGHT * (Grid_height - 1) 
  161. 	 
  162. 	LIST_MAX_HEIGHT = TILE_HEIGHT * (LIST_HEIGHT - 1) 
  163. 	 
  164. 	-- Setup Button Hints 
  165. 	Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Hack_main_doc_h) 
  166. 	local hint_data = { 
  167. 		{CTRL_MENU_BUTTON_B, "START/END"}, 
  168. 		{CTRL_BUTTON_LS, "MOVE"}, 
  169. 		{CTRL_BUTTON_X, "RESET"}, 
  170. 	} 
  171. 	Hint_bar:set_hints(hint_data)  
  172. 	 
  173. 	Grid_h = vint_object_find( "cell_grid" ) 
  174. 	Grid_highlight_h = vint_object_find( "cell_highlight" ) 
  175. 	List_h = vint_object_find( "list_main" ) 
  176. 	List_highlight_h = vint_object_find( "list_highlight_grp" ) 
  177. 	Timer_h = vint_object_find( "timer" ) 
  178.  
  179. 	local list_button = Vdo_hint_button:new( "list_button" ) 
  180. 	list_button:set_button( CTRL_BUTTON_RS )	 
  181. 	 
  182. 	if game_get_platform() == "PC" then 
  183. 		Hint_bar:set_visible(true)	 
  184. 		Hint_bar:set_highlight(0) 
  185. 		 
  186. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  187. 		Hint_bar:add_mouse_inputs("hack_main_editor", Mouse_input_tracker) 
  188. 		Mouse_input_tracker:subscribe(false) 
  189. 	end 
  190. 	 
  191. 	local popup_grp_h = vint_object_find( "popup_grp" ) 
  192. 	vint_set_property( popup_grp_h, "visible", false ) 
  193. 	--draw the grid 
  194. 	hack_main_editor_draw_grid() 
  195. 	hack_main_editor_set_list_highlight(0) 
  196. 	 
  197. 	-- position the list 
  198. 	local list_grp_h = vint_object_find("cell_list_grp") 
  199. 	local grid_x,grid_y = vint_get_property(Grid_h, "anchor") 
  200. 	local list_x,list_y = vint_get_property(list_grp_h, "anchor") 
  201. 	vint_set_property(list_grp_h, "anchor", grid_x + 50 + (Grid_width * TILE_WIDTH), grid_y ) 
  202. 	 
  203. 	-- position hintbar 
  204. 	local hint_x,hint_y = Hint_bar:get_property("anchor") 
  205. 	Hint_bar:set_property("anchor", grid_x + 10, grid_y + 30 + (Grid_height * TILE_HEIGHT)) 
  206. 	 
  207. 	Hack_timer_thread = thread_new("hack_main_editor_timer_thread") 
  208. 	 
  209. 	local start_point_anim_h = vint_object_find("start_point_anim") 
  210. 	lua_play_anim( start_point_anim_h, 0 ) 
  211. end 
  212.  
  213. function hack_main_editor_cleanup() 
  214. 	-- reload the full screen map 
  215. 	pause_map_restore() 
  216. 	 
  217. 	thread_kill(Hack_timer_thread) 
  218. 	 
  219. 	-- Nuke all button subscriptions 
  220. 	Input_tracker:subscribe(false) 
  221. 	 
  222. 	if Mouse_input_tracker ~= nil then 
  223. 		Mouse_input_tracker:subscribe(false) 
  224. 	end 
  225. end 
  226.  
  227. function hack_main_editor_validate_cells() 
  228. 	-- the start and end cells could be changed based on the board setup 
  229. 	local current_cell_x = 0 
  230. 	local current_cell_y = Hack_start 
  231. 	local incoming_direction = 3 
  232. 	 
  233. 	local end_cell_x = Grid_width 
  234. 	local end_cell_y = Hack_end 
  235. 	 
  236. 	local hack_title_h = vint_object_find("hack_title") 
  237. 	vint_set_property(hack_title_h,"visible",false) 
  238. 	 
  239. 	-- reset grid tint 
  240. 	for x = 0, Grid_width - 1 do 
  241. 		for y = 0, Grid_height - 1 do 
  242. 			local cell_type = Hack_grid_data[ x ][ y ].type 
  243. 			if cell_type > 0 then 
  244. 				vint_set_property( Hack_grid_data[ x ][ y ].handle, "tint", 0.2, 0.2, 0.2 ) 
  245. 			else 
  246. 				vint_set_property( Hack_grid_data[ x ][ y ].handle, "tint", 1, 1, 1 ) 
  247. 			end 
  248. 		end 
  249. 	end 
  250. 	 
  251. 	while true do 
  252. 		-- validate the current cell 
  253. 		local cell_type = Hack_grid_data[ current_cell_x ][ current_cell_y ].type 
  254. 		 
  255. 		if cell_type == -1 then 
  256. 			return false 
  257. 		end 
  258. 		 
  259. 		local valid = false 
  260. 		local exit_direction = -1 
  261. 		for k, v in pairs( Hack_list_connections_data[ cell_type ] ) do 
  262. 			if v == incoming_direction then 
  263. 				valid = true 
  264. 			else 
  265. 				exit_direction = v 
  266. 			end 
  267. 		end 
  268. 		 
  269. 		if valid == false then 
  270. 			return false 
  271. 		end 
  272. 		 
  273. 		-- update the tint 
  274. 		vint_set_property( Hack_grid_data[ current_cell_x ][ current_cell_y ].handle, "tint", 1, 1, 1 ) 
  275. 		 
  276. 		-- move to the next cell 
  277. 		if exit_direction == 0 then 
  278. 			current_cell_y = current_cell_y - 1 
  279. 		elseif exit_direction == 1 then 
  280. 			current_cell_x = current_cell_x + 1 
  281. 		elseif exit_direction == 2 then 
  282. 			current_cell_y = current_cell_y + 1 
  283. 		elseif exit_direction == 3 then 
  284. 			current_cell_x = current_cell_x  - 1 
  285. 		else 
  286. 			-- hmmmmm 
  287. 			return false 
  288. 		end 
  289. 		 
  290. 		-- did we win? 
  291. 		if current_cell_x == end_cell_x and current_cell_y == end_cell_y then 
  292. 			--launch success popup 
  293. 			--hack_main_editor_launch_popup( true ) 
  294. 			vint_set_property(hack_title_h,"visible",true) 
  295. 			--kill the timer 
  296. 			Hack_timer_run = false 
  297. 			--thread_kill( Hack_timer_thread )  
  298. 			--kill input 
  299. 			--hack_main_editor_lock_controls() 
  300. 			return true 
  301. 		end 
  302. 		 
  303. 		-- did we move out of the grid? 
  304. 		if current_cell_x < 0 or current_cell_x >= Grid_width then 
  305. 			return false 
  306. 		end 
  307. 		 
  308. 		if current_cell_y < 0 or current_cell_y >= Grid_height then 
  309. 			return false 
  310. 		end 
  311. 		 
  312. 		-- update incoming direction 
  313. 		incoming_direction = Hack_list_connection_directions[ exit_direction ] 
  314. 	end 
  315. end 
  316.  
  317. function hack_main_editor_timer_thread() 
  318. 	while Hack_timer_run do 
  319. 		thread_yield() 
  320. 		if Hack_timer < 60 then 
  321. 			Hack_timer = Hack_timer + 1 
  322. 			vint_set_property( Timer_h, "text_tag", Hack_timer ) 
  323. 			delay( 1 ) 
  324. 		else 
  325. 			--we ran out of timer--launch the failure popup 
  326. 			--hack_main_editor_launch_popup( false ) 
  327. 			--kill the timer 
  328. 			Hack_timer_run = false 
  329. 			--thread_kill( Hack_timer_thread )  
  330. 			--kill input 
  331. 			--hack_main_editor_lock_controls() 
  332. 		end 
  333. 	end 
  334. end 
  335.  
  336. function hack_main_editor_nav_up(event, acceleration) 
  337. 	hack_main_editor_set_grid_highlight(-2) 
  338. end 
  339.  
  340. function hack_main_editor_nav_down(event, acceleration) 
  341. 	hack_main_editor_set_grid_highlight(2) 
  342. end 
  343.  
  344. function hack_main_editor_nav_left(event, acceleration) 
  345. 	hack_main_editor_set_grid_highlight(-1) 
  346. end 
  347.  
  348. function hack_main_editor_nav_right(event, acceleration) 
  349. 	hack_main_editor_set_grid_highlight(1) 
  350. end 
  351.  
  352. function hack_main_editor_size_up(event, acceleration) 
  353. 	Grid_width = Grid_width + 1 
  354. 	Grid_height = Grid_height + 1 
  355. 	if Grid_width > 6 then 
  356. 		Grid_width = 6 
  357. 		Grid_height = 6 
  358. 	end 
  359. 	hack_main_editor_nuke_grid() 
  360. end 
  361.  
  362. function hack_main_editor_size_down(event, acceleration) 
  363. 	Grid_width = Grid_width - 1 
  364. 	Grid_height = Grid_height - 1 
  365. 	if Grid_width < 4 then 
  366. 		Grid_width = 4 
  367. 		Grid_height = 4 
  368. 	end 
  369. 	hack_main_editor_nuke_grid() 
  370. end 
  371.  
  372. function hack_main_editor_nuke_grid() 
  373. 	if #Hack_grid_data > 0 then 
  374. 		--nuke the grid 
  375. 		for x = 0, #Hack_grid_data do 
  376. 			for y = 0, #Hack_grid_data do  
  377. 				vint_object_destroy( Hack_grid_data[ x ][ y ].handle ) 
  378. 			end 
  379. 		end 
  380. 		 
  381. 		Hack_grid_data = {} 
  382. 		 
  383. 		for x = 0, Grid_width - 1 do 
  384. 			Hack_grid_data[ x ] = { } 
  385. 			for y = 0, Grid_height - 1 do 
  386. 				Hack_grid_data[ x ][ y ] = { } 
  387. 				Hack_grid_data[ x ][ y ].type = 0 
  388. 			end 
  389. 		end 
  390. 		 
  391. 		Grid_max_width = TILE_WIDTH * (Grid_width - 1) 
  392. 		Grid_max_height = TILE_HEIGHT * (Grid_height - 1) 
  393. 	 
  394. 		hack_main_editor_draw_grid() 
  395. 		hack_main_editor_set_grid_highlight(0) 
  396. 	end 
  397. end 
  398.  
  399. function hack_main_editor_button_b(event, acceleration) 
  400. 	 
  401. 	local cell_start_grp = vint_object_find( "cell_start_grp" ) 
  402. 	local cell_end_grp = vint_object_find( "cell_end_grp" ) 
  403. 	 
  404. 	if Grid_x_idx == 0 then 
  405. 		Hack_start = Grid_y_idx 
  406. 		vint_set_property( cell_start_grp, "anchor", -10, ((Hack_start + 1) * TILE_HEIGHT) - (TILE_HEIGHT * 0.5)) 
  407. 	elseif Grid_x_idx == Grid_width - 1 then 
  408. 		Hack_end = Grid_y_idx 
  409. 		vint_set_property( cell_end_grp, "anchor", Grid_width * TILE_WIDTH, ((Hack_end + 1) * TILE_HEIGHT) - (TILE_HEIGHT * 0.5)) 
  410. 	end 
  411. 	 
  412. 	hack_main_editor_validate_cells() 
  413. end 
  414.  
  415. function hack_main_editor_button_x(event, acceleration) 
  416. 	hack_main_editor_reset_grid() 
  417. end 
  418.  
  419. function hack_main_editor_list_up(event, acceleration) 
  420. 	local current_type = Hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type 
  421. 	--check if cell is open 
  422. 	if current_type >= -1 then 
  423. 		local upper_limit = 0 
  424. 		local bottom_limit = TILE_HEIGHT * (LIST_HEIGHT - 1) 
  425. 		local x ,y = vint_get_property( List_highlight_h, "anchor" ) 
  426. 		y = y - TILE_HEIGHT 
  427. 		 
  428. 		local prev_idx = List_idx 
  429. 		List_idx = List_idx - 1 
  430. 		 
  431. 		if y < upper_limit then 
  432. 			y = bottom_limit 
  433. 			List_idx = LIST_HEIGHT - 1 
  434. 		end 
  435. 		 
  436. 		hack_main_editor_update_amount( prev_idx ) 
  437. 		 
  438. 		vint_set_property( List_highlight_h, "anchor", 0, y ) 
  439.  
  440. 		hack_main_editor_update_cell( Grid_x_idx, Grid_y_idx ) 
  441.  
  442. 	else 
  443. 		--play some error sound 
  444. 	end 
  445. end 
  446.  
  447. function hack_main_editor_list_down(event, acceleration) 
  448. 	local current_type = Hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type 
  449. 	if current_type >= -1 then 
  450. 		local upper_limit = 0 
  451. 		local bottom_limit = TILE_HEIGHT * (LIST_HEIGHT - 1) 
  452. 		local x ,y = vint_get_property( List_highlight_h, "anchor" ) 
  453. 		y = y + TILE_HEIGHT 
  454. 		 
  455. 		local prev_idx = List_idx 
  456. 		List_idx = List_idx + 1 
  457. 		 
  458. 		if y > bottom_limit then 
  459. 			y = upper_limit 
  460. 			List_idx = 0 
  461. 		end 
  462. 		 
  463. 		hack_main_editor_update_amount( prev_idx ) 
  464. 		 
  465. 		vint_set_property( List_highlight_h, "anchor", 0, y ) 
  466. 		 
  467. 		hack_main_editor_update_cell( Grid_x_idx, Grid_y_idx ) 
  468. 		 
  469. 	else 
  470. 		--play some error sound 
  471. 	end 
  472. end 
  473.  
  474. function hack_main_editor_button_a(event, acceleration) 
  475. 		 
  476. 	--TODO: Check to see if tween is done before you move to next screen. 
  477. 	 
  478. 	--local current_id = Menu:get_id() 
  479. 	 
  480. 	--cell_menu_handle_state(current_id) 
  481. 	hack_main_editor_print_list() 
  482. 	 
  483. end 
  484.  
  485. function hack_main_editor_mouse_click(event, target_handle) 
  486. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  487. 	if hint_index == 1 then 
  488. 		hack_main_editor_button_b() 
  489. 	end 
  490. 	 
  491. 	-- If the target_handle matches a button, activate it 
  492. 	--if Menu:select_button(target_handle) == true then 
  493. 		--hack_main_editor_button_a() 
  494. 	--end 
  495. end 
  496.  
  497. function hack_main_editor_mouse_move(event, target_handle)	 
  498. 	Hint_bar:set_highlight(0) 
  499. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  500. 	if hint_index ~= 0 then 
  501. 		Hint_bar:set_highlight(hint_index) 
  502. 		game_UI_audio_play("UI_Cell_Nav") 
  503. 	end 
  504. end 
  505.  
  506. function hack_main_editor_unlock_controls() 
  507. 	Input_tracker:subscribe(true) 
  508. 	if Mouse_input_tracker ~= nil then 
  509. 		Mouse_input_tracker:subscribe(true) 
  510. 	end 
  511. end 
  512.  
  513. function hack_main_editor_lock_controls() 
  514. 	Input_tracker:subscribe(false) 
  515. 	if Mouse_input_tracker ~= nil then 
  516. 		Mouse_input_tracker:subscribe(false) 
  517. 	end 
  518. end 
  519.  
  520. function hack_main_editor_set_list_highlight(new_idx) 
  521. 	local x ,y = vint_get_property(List_highlight_h, "anchor") 
  522. 	 
  523. 	if new_idx == -1 then 
  524. 		new_idx = 7 
  525. 	end 
  526. 	 
  527. 	if new_idx >= 0 then 
  528. 		List_idx = new_idx 
  529. 		if new_idx > 0 then 
  530. 			y = TILE_HEIGHT * new_idx--1 * ( TILE_HEIGHT * new_idx ) 
  531. 		else 
  532. 			y = 0 
  533. 		end 
  534. 		vint_set_property(List_highlight_h, "anchor", 0, y) 
  535. 	else 
  536. 		vint_set_property(List_highlight_h, "anchor", 0, 0) 
  537. 	end 
  538. 	 
  539. end 
  540.  
  541. function hack_main_editor_set_grid_highlight(direction) 
  542. 	local x ,y = vint_get_property(Grid_highlight_h, "anchor") 
  543. 	if direction == 1 then 
  544. 	-- RIGHT 
  545. 		x = x + TILE_WIDTH 
  546. 		Grid_x_idx = Grid_x_idx + 1 
  547. 	elseif direction == -1 then 
  548. 	-- LEFT 
  549. 		x = x - TILE_WIDTH 
  550. 		Grid_x_idx = Grid_x_idx - 1 
  551. 	elseif direction == 2 then 
  552. 	-- DOWN 
  553. 		y = y + TILE_HEIGHT 
  554. 		Grid_y_idx = Grid_y_idx + 1 
  555. 	elseif direction == -2 then 
  556. 	-- UP 
  557. 		y = y - TILE_HEIGHT 
  558. 		Grid_y_idx = Grid_y_idx - 1 
  559. 	else 
  560. 	-- RESET 
  561. 		x = 0 
  562. 		Grid_x_idx = 0 
  563. 		y = 0 
  564. 		Grid_y_idx = 0 
  565. 	end 
  566. 	--check the limits 
  567. 	if x > Grid_max_width then 
  568. 		x = Grid_max_width 
  569. 		Grid_x_idx = Grid_width - 1 
  570. 	elseif x < 0 then 
  571. 		x = 0 
  572. 		Grid_x_idx = 0 
  573. 	end 
  574. 	if y > Grid_max_height then 
  575. 		y = Grid_max_height 
  576. 		Grid_y_idx = Grid_height - 1 
  577. 	elseif y < 0 then 
  578. 		y = 0 
  579. 		Grid_y_idx = 0 
  580. 	end 
  581. 	vint_set_property(Grid_highlight_h, "anchor", x, y) 
  582. 	 
  583. 	local current_type = Hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type 
  584. 	 
  585. 	hack_main_editor_set_list_highlight( current_type ) 
  586. 	 
  587. end 
  588.  
  589. function hack_main_editor_update_cell( cell_x, cell_y ) 
  590. 	--debug_print("vint","cell = "..cell_x..", "..cell_y.."\n") 
  591. 	--debug_print("vint","List_idx = "..List_idx.."\n") 
  592. 	 
  593. 	local current_type = Hack_grid_data[ cell_x ][ cell_y ].type 
  594. 	local list_type = Hack_list_data[ List_idx ].type 
  595. 	 
  596. 	--debug_print("vint","current_type = "..var_to_string(current_type).."\n") 
  597. 	--debug_print("vint","list_type = "..var_to_string(list_type).."\n\n") 
  598. 	if current_type >= -1 then 
  599. 		if current_type ~= list_type then 
  600. 			Hack_grid_data[ cell_x ][ cell_y ].type = list_type 
  601. 			hack_main_editor_set_cell_image( cell_x, cell_y ) 
  602. 			hack_main_editor_validate_cells() 
  603. 		end 
  604. 	end 
  605. end 
  606.  
  607. function hack_main_editor_set_cell_image( cell_x, cell_y ) 
  608. 	local cell_type = Hack_grid_data[ cell_x ][ cell_y ].type 
  609. 	local cell_handle = Hack_grid_data[ cell_x ][ cell_y ].handle 
  610. 	 
  611. 	if cell_type == -1 then 
  612. 		vint_set_property( cell_handle, "image", "ui_hack_grid_lock" ) 
  613. 		vint_set_property( cell_handle, "alpha", 0.33 ) 
  614. 	elseif cell_type == 0 then 
  615. 		vint_set_property( cell_handle, "image", "ui_hack_grid_blank" ) 
  616. 		vint_set_property( cell_handle, "alpha", 0.67 ) 
  617. 	elseif cell_type == 1 then 
  618. 		vint_set_property( cell_handle, "image", "ui_hack_grid_hor" ) 
  619. 		vint_set_property( cell_handle, "alpha", 1.0 ) 
  620. 	elseif cell_type == 2 then 
  621. 		vint_set_property( cell_handle, "image", "ui_hack_grid_vert" ) 
  622. 		vint_set_property( cell_handle, "alpha", 1.0 ) 
  623. 	elseif cell_type == 3 then 
  624. 		vint_set_property( cell_handle, "image", "ui_hack_grid_ne" ) 
  625. 		vint_set_property( cell_handle, "alpha", 1.0 ) 
  626. 	elseif cell_type == 4 then 
  627. 		vint_set_property( cell_handle, "image", "ui_hack_grid_ne" ) 
  628. 		vint_set_property( cell_handle, "alpha", 1.0 ) 
  629. 	elseif cell_type == 5 then 
  630. 		vint_set_property( cell_handle, "image", "ui_hack_grid_sw" ) 
  631. 		vint_set_property( cell_handle, "alpha", 1.0 ) 
  632. 	elseif cell_type == 6 then 
  633. 		vint_set_property( cell_handle, "image", "ui_hack_grid_nw" ) 
  634. 		vint_set_property( cell_handle, "alpha", 1.0 ) 
  635. 	end 
  636. end 
  637.  
  638. function hack_main_editor_draw_list() 
  639. 	--loop through the list of cells and store handles 
  640. 	for i = 0, LIST_HEIGHT - 1 do 
  641. 		--store handles if we have not done so already 
  642. 		if Hack_list_data[ i ].handle == nil then 
  643. 			Hack_list_data[ i ].handle = vint_object_find( Hack_list_data[ i ].name ) 
  644. 			Hack_list_data[ i ].txt = vint_object_find( "cell_txt", Hack_list_data[ i ].handle ) 
  645. 			Hack_list_data[ i ].bg = vint_object_find( "cell_txt_bg", Hack_list_data[ i ].handle ) 
  646. 			Hack_list_data[ i ].image = vint_object_find( "cell_image", Hack_list_data[ i ].handle ) 
  647. 		end 
  648. 		--reset the amount to the max amount you can have 
  649. 		Hack_list_data[ i ].amount_used = Hack_list_data[ i ].max_amount 
  650. 	end 
  651. 	--update the visual state of the cells in the list 
  652. 	hack_main_editor_refresh_list() 
  653. end 
  654.  
  655. function hack_main_editor_refresh_list() 
  656. 	--loop through all the list items 
  657. 	for i = 0, LIST_HEIGHT - 1 do 
  658. 		--grab the amount 
  659. 		local amount_used = Hack_list_data[ i ].amount_used 
  660. 		--if we are not the blank cell then refresh 
  661. 		if amount_used >= 0 then 
  662. 			--set the amount 
  663. 			vint_set_property( Hack_list_data[ i ].txt, "text_tag", Hack_list_data[ i ].amount_used ) 
  664. 			--if we have no pieces and we are not blank then turn us off 
  665. 			if amount_used == 0 and Hack_list_data[ i ].type > 0 then 
  666. 				--vint_set_property( Hack_list_data[ i ].image, "tint", 0.5,0.5,0.5) 
  667. 			else 
  668. 			--if we have pieces and we are not blank then turn us on 
  669. 				vint_set_property( Hack_list_data[ i ].image, "tint", 1, 1, 1 ) 
  670. 			end 
  671. 		else 
  672. 		--we are the blank cell so we have infinite pieces, don't show the amount ever 
  673. 			vint_set_property( Hack_list_data[ i ].txt, "visible", false) 
  674. 			vint_set_property( Hack_list_data[ i ].bg, "visible", false) 
  675. 		end 
  676. 	end 
  677. end 
  678.  
  679. function hack_main_editor_update_amount( prev_idx ) 
  680. 	--if the current tile is not blank then change the amount 
  681. 	if Hack_list_data[ List_idx ].type > 0  then 
  682. 		--take one tile away 
  683. 		--Hack_list_data[ List_idx ].amount = Hack_list_data[ List_idx ].amount - 1 
  684. 		Hack_list_data[ List_idx ].amount_used = Hack_list_data[ List_idx ].amount_used + 1 
  685. 	end 
  686. 	 
  687. 	--if the previous tile was not blank then subtract one 
  688. 	if Hack_list_data[ prev_idx ].type > 0 then 
  689. 		--Hack_list_data[ prev_idx ].amount = Hack_list_data[ prev_idx ].amount - 1 
  690. 		Hack_list_data[ prev_idx ].amount_used = Hack_list_data[ prev_idx ].amount_used - 1 
  691. 		if Hack_list_data[ prev_idx ].amount_used < 0 then 
  692. 			Hack_list_data[ prev_idx ].amount_used = 0  
  693. 		end 
  694. 	end 
  695. 	 
  696. 	hack_main_editor_refresh_list() 
  697. end 
  698. 								 
  699. function hack_main_editor_draw_grid() 
  700. 	local cur_y = 0 
  701. 	local tile_count = 0 
  702. 	--loop through the amount of cells needed 
  703. 	for tile_y = 0, Grid_height - 1 do 
  704. 		for tile_x = 0, Grid_width - 1 do  
  705. 			local bitmap_h = vint_object_create("grid_blank", "bitmap", Grid_h) 
  706. 			--store the handle 
  707. 			Hack_grid_data[ tile_x ][ tile_y ].handle = bitmap_h 
  708. 			debug_print("vint","handle = "..var_to_string(Hack_grid_data[ tile_x ][ tile_y ].handle).."\n\n") 
  709. 			--set the image 
  710. 			hack_main_editor_set_cell_image( tile_x, tile_y ) 
  711. 			 
  712. 			--position... 
  713. 			local x = tile_x * TILE_WIDTH 
  714. 			local y = cur_y 
  715. 			vint_set_property(bitmap_h, "anchor", x, y) 
  716. 			 
  717. 			tile_count = tile_count + 1 
  718. 		end 
  719. 		--Increment y positon... 
  720. 		cur_y = cur_y + TILE_HEIGHT 
  721. 	end 
  722. 	 
  723. 	--set the start point 
  724. 	local cell_start_grp = vint_object_find( "cell_start_grp" ) 
  725. 	vint_set_property( cell_start_grp, "anchor", -10, ((Hack_start + 1) * TILE_HEIGHT) - (TILE_HEIGHT * 0.5)) 
  726. 	 
  727. 	--set the end point(s) 
  728. 	local cell_end_grp = vint_object_find( "cell_end_grp" ) 
  729. 	vint_set_property( cell_end_grp, "anchor", Grid_width * TILE_WIDTH, ((Hack_end + 1) * TILE_HEIGHT) - (TILE_HEIGHT * 0.5)) 
  730. 	 
  731. 	--set up the list handles and tile amounts 
  732. 	hack_main_editor_draw_list() 
  733. end 
  734.  
  735. function hack_main_editor_reset_grid() 
  736. 	--loop through the grid and reset anything that is not invalid or blank 
  737. 	for y = 0, Grid_height - 1 do 
  738. 		for x = 0, Grid_width - 1 do  
  739. 			local type = Hack_grid_data[ x ][ y ].type 
  740. 			--if we are not invalid or blank then set us to blank 
  741. 			if type >= -1 then 
  742. 				Hack_grid_data[ x ][ y ].type = 0 
  743. 				hack_main_editor_set_cell_image( x, y ) 
  744. 			end 
  745. 			--reset all the tints 
  746. 			vint_set_property( Hack_grid_data[ x ][ y ].handle, "tint", 1, 1, 1 ) 
  747. 		end 
  748. 	end 
  749. 	 
  750. 	Hack_start = 0 
  751. 	Hack_end = 0 
  752. 	Hack_timer = 0 
  753. 	Hack_timer_run = true 
  754. 	thread_kill( Hack_timer_thread ) 
  755. 	Hack_timer_thread = thread_new("hack_main_editor_timer_thread") 
  756. 	 
  757. 	--set the start point 
  758. 	local cell_start_grp = vint_object_find( "cell_start_grp" ) 
  759. 	vint_set_property( cell_start_grp, "anchor", -10, ((Hack_start + 1) * TILE_HEIGHT) - (TILE_HEIGHT * 0.5)) 
  760. 	 
  761. 	--set the end point(s) 
  762. 	local cell_end_grp = vint_object_find( "cell_end_grp" ) 
  763. 	vint_set_property( cell_end_grp, "anchor", Grid_width * TILE_WIDTH, ((Hack_end + 1) * TILE_HEIGHT) - (TILE_HEIGHT * 0.5)) 
  764. 	 
  765. 	--refresh all our piece amounts in the list and redraw it 
  766. 	hack_main_editor_draw_list() 
  767. 	hack_main_editor_set_list_highlight(0) 
  768. end 
  769.  
  770. function hack_main_editor_launch_popup( success ) 
  771. 	local popup_grp_h = vint_object_find( "popup_grp" ) 
  772. 	local popup_title_h = vint_object_find( "popup_title" ) 
  773. 	vint_set_property( popup_grp_h, "visible", true ) 
  774. 	if success then 
  775. 		vint_set_property( popup_title_h, "text_tag", "HACK COMPLETE" ) 
  776. 		vint_set_property( popup_title_h, "tint", 6/255, 162/255, 170/255 ) 
  777. 	else 
  778. 		vint_set_property( popup_title_h, "text_tag", "HACK FAILED" ) 
  779. 		vint_set_property( popup_title_h, "tint", 1, 0, 0 ) 
  780. 	end 
  781. end 
  782.  
  783. function hack_main_editor_print_list() 
  784. 	debug_print("vint","[ X ] = {\n") 
  785. 	debug_print("vint","hack_grid_data = {\n") 
  786. 	for y = 0, Grid_height - 1 do 
  787. 		debug_print("vint","["..y.."] = {\n") 
  788. 		for x = 0, Grid_width - 1 do  
  789. 			if Hack_grid_data[y][x].type < 0 then 
  790. 				debug_print("vint","["..x.."] = {type = "..Hack_grid_data[y][x].type..",},") 
  791. 			else 
  792. 				debug_print("vint","["..x.."] = {type = 0,},") 
  793. 			end 
  794. 		end 
  795. 		debug_print("vint","},\n") 
  796. 	end 
  797. 	debug_print("vint","},\n") 
  798. 	 
  799. 	debug_print("vint","hack_list_data = {\n") 
  800. 	for i = 0, LIST_HEIGHT - 2 do 
  801. 		debug_print("vint","["..i.."] = {\n") 
  802. 		debug_print("vint","type = "..Hack_list_data[i].type..",\n") 
  803. 		debug_print("vint","max_amount = "..Hack_list_data[i].amount_used..",\n") 
  804. 		debug_print("vint","name = \""..Hack_list_data[i].name.."\",\n") 
  805. 		debug_print("vint","},\n") 
  806. 	end 
  807. 	debug_print("vint","},\n") 
  808. 	 
  809. 	debug_print("vint","hack_start = "..Hack_start..",\n") 
  810. 	debug_print("vint","hack_end = "..Hack_end..",\n") 
  811. 	debug_print("vint","},\n") 
  812. 	 
  813. end 
  814.