local TILE_SPACING = 8
local TILE_WIDTH = 70 + TILE_SPACING
local TILE_HEIGHT = 65 + TILE_SPACING
local Grid_max_width = 0
local Grid_max_height = 0
local LIST_MAX_HEIGHT = 0
local Hack_main_data = {}
local List_height = 0
local Grid_width = 0
local Grid_height = 0
--audio
--[[
Event: UI_SFX
1st Switch Group: UI_SFX
1st Switch: UI_Hacking_SFX
2nd Switch Group: UI_Hacking_SFX
Switches:
Background_Loop (trigger this when the minigame starts)
Tutorial_In
Tutorial_Out
Grid_Highlight
Block_Place
Block_Delete
Block_Charge
List_Highlight (this should only trigger when the player actual moves that cursor, not if it moves on its own)
Grid_Reset
Timer_90 (trigger at 95 seconds)
Timer_60 (trigger at 65 seconds)
Timer_30 (trigger at 30 seconds)
Timer_10 (trigger at 15 seconds)
Hack_Complete
Hack_Fail
UI_Stop_Hacking_Timer (trigger this anytime you need to stop the 10 second countdown)
UI_Kill_Hacking SFX (trigger this anytime the player leaves the minigame � quits out, fails, completes)
--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)
event_audio_id = audio_object_post_event("UI_Hacking_SFX", "UI_Hacking_SFX", "Background_Loop")
--]]
-- 0 = north, 1 = East, 2, 3
local Hack_list_connections_data = {
[0] = { -1, -1},
[1] = { 1, 3 },
[2] = { 0, 2 },
[3] = { 0, 1 },
[4] = { 1, 2 },
[5] = { 2, 3 },
[6] = { 0, 3 },
}
local Hack_list_connection_directions = {
[0] = 2,
[1] = 3,
[2] = 0,
[3] = 1,
}
local Hack_timer_thread
local Hack_timer_run = true
local List_hint_grp_h
local List_hint_txt_h
local List_button
local Hint_bar
local Popup_hint_bar
local List_h
local List_highlight_h
local Grid_h
local Grid_pipe_h
local Input_tracker
local Grid_highlight_h
local Grid_highlight_image_h
local Highlight_anim_h
local Hack_mouse_input_tracker
local Hack_popup_mouse_input_tracker
local Hack_main_sticks_doc_h = -1
local New_item_idx = 0
local Prev_idx = 0
local Current_idx = 0
local List_idx = 1
local List_total = 0
local Grid_x_idx = 0
local Grid_y_idx = 0
local Timer_h = 0
local Hack_timer = 30
local Hack_puzzle_idx = 0
local Hack_controls_locked = true
local Hack_popup_ready = false
local Is_paused = false
local Hack_main_paused = false
local Hack_tutorial_active = false
local Hack_popup_open = false
local Grid_pipe_count = 0
local Hack_complete = false
local Grid_mouse_lock = false
local Background_loop_audio_id = 0
local Clear_all_audio_id = 0
local List_move_audio_id = 0
local Grid_move_audio_id = 0
local Grid_add_audio_id = 0
local Grid_remove_audio_id = 0
local Grid_reset_audio_id = 0
local Grid_power_audio_id = 0
local Timer_audio_id = 0
local Tutorial_audio_id = 0
local Hack_end_audio_id = 0
local A_mode = true
local Penalty = false
local Can_have_penalty = true
local Hack_main_sticks_gamepad_listener = -1
local Popup_defaults_changed = false
local Popup_footer_grp_x
local Popup_footer_grp_y
local Popup_background_width
local Popup_background_height
local Popup_background_x
local Popup_background_y
local Popup_elements_grp_x
local Popup_elements_grp_y
function hack_main_sticks_init()
-- unload the full screen map to pillage memory
pause_map_dump()
-- Find our documents...
Hack_main_sticks_doc_h = vint_document_find("hack_main_sticks")
-- Setup input tracker.+
local priority = 500000
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input( "select", "hack_main_sticks_button_a", priority )
Input_tracker:add_input( "back", "hack_main_sticks_button_b", priority )
Input_tracker:add_input( "alt_select", "hack_main_sticks_button_x", priority )
Input_tracker:add_input( "nav_up", "hack_main_sticks_nav_up", priority )
Input_tracker:add_input( "nav_down", "hack_main_sticks_nav_down", priority )
Input_tracker:add_input( "nav_left", "hack_main_sticks_nav_left", priority )
Input_tracker:add_input( "nav_right", "hack_main_sticks_nav_right", priority )
Input_tracker:add_input( "alt_joy_up", "hack_main_sticks_list_up", priority )
Input_tracker:add_input( "alt_joy_down", "hack_main_sticks_list_down", priority )
--allows for changing puzzles, removing for final code
--Input_tracker:add_input( "scroll_left", "hack_main_sticks_previous_puzzle", priority )
--Input_tracker:add_input( "scroll_right", "hack_main_sticks_next_puzzle", priority )
vint_dataresponder_request( "hacking_screen_populate", "hack_main_sticks_set_puzzle_idx", 0 )
if (hacking_use_procedural_generation()) then
Hack_main_data = hacking_procedural_get_puzzle(Hack_puzzle_idx)
else
Hack_main_data = Hack_main_puzzles[ Hack_puzzle_idx ]
if Hack_main_data == nil then
debug_print( "always_on", "Hack puzzle not found, defaulting" )
Hack_main_data = Hack_main_puzzles[ 0 ]
end
end
--flair text
local popup_title_value_h = vint_object_find("popup_title_value", 0, Hack_main_sticks_doc_h)
local popup_title_value_bg_h = vint_object_find("popup_title_value_bg", 0, Hack_main_sticks_doc_h)
local popup_title_value_width, popup_title_value_height = element_get_actual_size(popup_title_value_h)
local popup_title_value_bg_width, popup_title_value_bg_height = element_get_actual_size(popup_title_value_bg_h)
element_set_actual_size(popup_title_value_bg_h, popup_title_value_width + 11, popup_title_value_bg_height)
local timer_title_h = vint_object_find("timer_title", 0, Hack_main_sticks_doc_h)
local timer_title_bg_h = vint_object_find("timer_title_bg", 0, Hack_main_sticks_doc_h)
local timer_title_width, timer_title_height = element_get_actual_size(timer_title_h)
local timer_title_bg_width, timer_title_bg_height = element_get_actual_size(timer_title_bg_h)
element_set_actual_size(timer_title_bg_h, timer_title_width + 5, timer_title_bg_height)
local footer_value_h = vint_object_find("footer_value", 0, Hack_main_sticks_doc_h)
local footer_value_bg_h = vint_object_find("footer_value_bg", 0, Hack_main_sticks_doc_h)
local footer_value_width, footer_value_height = element_get_actual_size(footer_value_h)
local footer_value_bg_width, footer_value_bg_height = element_get_actual_size(footer_value_bg_h)
element_set_actual_size(footer_value_bg_h, footer_value_width + 11, footer_value_bg_height)
List_height = #Hack_main_data.hack_list_data + 1
Grid_width = #Hack_main_data.hack_grid_data + 1
Grid_height = #Hack_main_data.hack_grid_data + 1
Grid_max_width = TILE_WIDTH * (Grid_width - 1)
Grid_max_height = TILE_HEIGHT * (Grid_height - 1)
LIST_MAX_HEIGHT = TILE_HEIGHT * (List_height - 1)
-- Setup Button Hints
List_hint_grp_h = vint_object_find("list_hint_grp", 0, Hack_main_sticks_doc_h)
List_hint_txt_h = vint_object_find("list_hint", 0, Hack_main_sticks_doc_h)
Hint_bar = Vdo_hint_bar:new( "hint_bar", 0, Hack_main_sticks_doc_h )
Popup_hint_bar = Vdo_hint_bar:new( "popup_hint_bar", 0, Hack_main_sticks_doc_h )
List_button = Vdo_hint_button:new( "list_button" )
hack_main_sticks_set_hints()
Grid_h = vint_object_find( "cell_grid_grp" )
Grid_highlight_h = vint_object_find( "cell_highlight" )
Grid_highlight_image_h = vint_object_find( "highlight_image" )
Grid_pipe_h = vint_object_find( "cell_pipe_grp" )
List_h = vint_object_find( "list_main" )
List_highlight_h = vint_object_find( "list_highlight_grp" )
Timer_h = vint_object_find( "timer" )
Highlight_anim_h = vint_object_find( "highlight_anim" )
vint_set_property( Grid_highlight_image_h, "visible", true )
local highlight_button = Vdo_hint_button:new( "highlight_button" )
highlight_button:set_button( CTRL_MENU_BUTTON_A )
local start_energy_anim_h = vint_object_find( "start_energy_anim" )
lua_play_anim( start_energy_anim_h, 0 )
--draw the grid
hack_main_sticks_draw_grid()
hack_main_sticks_set_list_highlight( 1 )
local list_mouse_highlight_h = vint_object_find( "list_mouse_highlight_grp" )
vint_set_property( list_mouse_highlight_h, "visible", false )
--setup PC inputs after grid is drawn
if game_get_platform() == "PC" then
Hack_mouse_input_tracker = Vdo_input_tracker:new()
hack_main_sticks_add_mouse_inputs()
Hack_mouse_input_tracker:subscribe(false)
Hack_popup_mouse_input_tracker = Vdo_input_tracker:new()
Hack_popup_mouse_input_tracker:subscribe(false)
local popup_grp_h = vint_object_find( "popup_grp" )
Hack_popup_mouse_input_tracker:add_mouse_input( "mouse_click", "hack_main_sticks_mouse_click", 500000, popup_grp_h )
end
--position grid based on grid size
if Grid_width == 4 then
vint_set_property( Grid_h, "anchor", 468, 237 )
else
vint_set_property( Grid_h, "anchor", 390, 164 )
end
hack_main_sticks_draw_side_grids()
vint_set_property( Timer_h, "text_tag", "--" )
vint_set_property( vint_object_find( "label" ), "text_tag", Hack_puzzle_idx )
local start_point_anim_h = vint_object_find( "start_point_anim" )
lua_play_anim( start_point_anim_h, 0 )
hack_main_sticks_update_total()
hack_main_sticks_set_grid_highlight_start()
hack_main_sticks_set_highlight_image()
vint_dataitem_add_subscription( "game_paused_item", "update", "hack_main_sticks_game_is_paused" ) --to check if game is paused..
local start_timer_tween_h = vint_object_find( "start_timer_tween" )
vint_set_property( start_timer_tween_h, "end_event", "hack_main_sticks_intro_done" )
local popup_in_tween_h = vint_object_find( "popup_in_tween" )
vint_set_property( popup_in_tween_h, "end_event", "hack_main_sticks_popup_in_done" )
local screen_animate_in_h = vint_object_find( "screen_animate_in" )
lua_play_anim( screen_animate_in_h, 0 )
local damage_group_h = vint_object_find( "damage_group" )
vint_set_property( damage_group_h, "alpha", 0 )
--audio
Background_loop_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Background_Loop" }, nil, false )
ui_audio_post_event( "UI_Hacking_On" )
Hack_main_sticks_gamepad_listener = vint_scriptevent_listen( "gamepad_active", "hack_main_sticks_update_gamepad_state" )
end
function hack_main_sticks_add_mouse_inputs()
local priority = 500000
--clear all mouse inputs
Hack_mouse_input_tracker:remove_all()
--rebuild all mouse inputs
Hint_bar:set_visible(true)
Hint_bar:set_highlight(0)
Hint_bar:add_mouse_inputs( "hack_main_sticks", Hack_mouse_input_tracker )
local tile_h
for tile_y = 0, Grid_height - 1 do
for tile_x = 0, Grid_width - 1 do
tile_h = Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].handle
Hack_mouse_input_tracker:add_mouse_input( "mouse_click", "hack_main_sticks_mouse_click", priority, tile_h )
Hack_mouse_input_tracker:add_mouse_input( "mouse_right_click", "hack_main_sticks_mouse_right_click", priority, tile_h )
Hack_mouse_input_tracker:add_mouse_input( "mouse_move", "hack_main_sticks_mouse_move", priority, tile_h )
end
end
for i = 1, List_height - 1 do
Hack_mouse_input_tracker:add_mouse_input( "mouse_click", "hack_main_sticks_mouse_click", priority, Hack_main_data.hack_list_data [ i ].handle )
Hack_mouse_input_tracker:add_mouse_input( "mouse_move", "hack_main_sticks_mouse_move", priority, Hack_main_data.hack_list_data [ i ].handle )
end
Hack_mouse_input_tracker:add_mouse_input("mouse_scroll", "hack_main_sticks_mouse_scroll", priority, Grid_h)
Hack_mouse_input_tracker:add_mouse_input( "mouse_click", "hack_main_sticks_mouse_click", priority + 1, Hack_main_sticks_doc_h )
end
function hack_main_sticks_set_hints()
local hint_data = {}
if game_get_platform() == "PC" and game_is_active_input_gamepad() == false then
hint_data = {
{HINT_BUTTON_RMB_OVERRIDE, "MENU_CLEAR"},
{CTRL_MENU_BUTTON_A, "MENU_SELECT"},
{CTRL_BUTTON_DPAD, "PLAYLIST_MOVE_TRACK"},
{CTRL_BUTTON_X, "MENU_RESET"},
}
else
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_CLEAR"},
{CTRL_MENU_BUTTON_A, "MENU_SELECT"},
{CTRL_BUTTON_LS, "PLAYLIST_MOVE_TRACK"},
{CTRL_BUTTON_X, "MENU_RESET"},
}
end
Hint_bar:set_hints(hint_data)
local ggl = game_get_language()
if ggl == "FR" then
vint_set_property(List_hint_grp_h, "anchor", 0, -26)
elseif ggl == "RU" then
vint_set_property(List_hint_grp_h, "anchor", 0, -26)
else
vint_set_property(List_hint_grp_h, "anchor", 0, 0)
end
--override the RS on PC with mouse scroll wheel
if game_get_platform() == "PC" and game_is_active_input_gamepad() == false then
List_button:set_button( CTRL_BUTTON_MOUSE_SCROLL )
else
List_button:set_button( CTRL_BUTTON_RS )
end
-- Move the hint text over so it does not overlap with the hint button
local hint_txt_x, hint_txt_y = vint_get_property(List_hint_txt_h, "anchor")
local list_button_x, list_button_y = vint_get_property(List_button.handle, "anchor")
if hint_txt_x >= list_button_x - (List_button.width/2) then
vint_set_property( List_hint_txt_h, "anchor", list_button_x - (List_button.width/2) - 6, hint_txt_y )
end
end
function hack_main_sticks_popup_in_done( tween_h )
Hack_popup_ready = true
end
function hack_main_sticks_intro_done( tween_h )
Input_tracker:subscribe(true)
if Hack_mouse_input_tracker ~= nil then
hack_main_sticks_add_mouse_inputs()
if( not Is_paused )then
Hack_mouse_input_tracker:subscribe(true)
end
end
if Hack_puzzle_idx > 0 then
Hack_timer_thread = thread_new( "hack_main_sticks_timer_thread" )
Hack_controls_locked = false
else
Hack_tutorial_active = true
Hack_controls_locked = true
if game_get_platform() == "PC" and game_is_active_input_gamepad() == false then
hack_main_sticks_launch_popup( nil, "MENU_HACKING_TUTORIAL_PC" )
else
hack_main_sticks_launch_popup( nil, "MENU_HACKING_TUTORIAL" )
end
end
end
function hack_main_sticks_game_is_paused(di_h)
Is_paused = vint_dataitem_get(di_h)
hack_main_sticks_pause()
end
function hack_main_sticks_set_puzzle_idx( puzzle_idx, puzzle_time )
if puzzle_idx ~= nil then
Hack_puzzle_idx = puzzle_idx
end
if puzzle_time ~= nil then
Hack_timer = puzzle_time
end
end
--we got shot, called directly from C
function hack_main_sticks_penalty( )
Penalty = true
end
function hack_main_sticks_unlock_penalty()
Can_have_penalty = true
end
function hack_main_sticks_cleanup()
-- reload the full screen map
pause_map_restore()
if Hack_timer_thread ~= nil then
thread_kill(Hack_timer_thread)
Hack_timer_thread = nil
end
-- Nuke all button subscriptions
Input_tracker:subscribe(false)
audio_object_post_event( "UI_Kill_Hacking_SFX" )
if Hack_mouse_input_tracker ~= nil then
Hack_mouse_input_tracker:subscribe(false)
end
vint_scriptevent_stop_listening( Hack_main_sticks_gamepad_listener )
end
function hack_main_sticks_validate_cells()
-- the start and end cells could be changed based on the board setup
local current_cell_x = 0
local current_cell_y = Hack_main_data.hack_start
local incoming_direction = 3
local pipe_count = 0
local end_cell_x = Grid_width
local end_cell_y = Hack_main_data.hack_end
-- reset grid tint
for x = 0, Grid_width - 1 do
for y = 0, Grid_height - 1 do
local cell_type = Hack_main_data.hack_grid_data[ x ][ y ].type
if cell_type > 0 then
vint_set_property( Hack_main_data.hack_grid_data[ x ][ y ].handle, "tint", 0.2, 0.2, 0.2 )
vint_set_property( Hack_main_data.hack_grid_data[ x ][ y ].pipe, "visible", false )
else
vint_set_property( Hack_main_data.hack_grid_data[ x ][ y ].handle, "tint", 1, 1, 1 )
vint_set_property( Hack_main_data.hack_grid_data[ x ][ y ].pipe, "visible", false )
end
end
end
while true do
-- validate the current cell
local cell_type = Hack_main_data.hack_grid_data[ current_cell_x ][ current_cell_y ].type
if cell_type == -1 then
return false
end
local valid = false
local exit_direction = -1
for k, v in pairs( Hack_list_connections_data[ cell_type ] ) do
if v == incoming_direction then
valid = true
else
exit_direction = v
end
end
if valid == false then
return false
end
-- update the tint
vint_set_property( Hack_main_data.hack_grid_data[ current_cell_x ][ current_cell_y ].handle, "tint", 1, 1, 1 )
vint_set_property( Hack_main_data.hack_grid_data[ current_cell_x ][ current_cell_y ].pipe, "visible", true )
pipe_count = pipe_count + 1
hack_main_sticks_set_pipe( Hack_main_data.hack_grid_data[ current_cell_x ][ current_cell_y ].pipe, cell_type )
-- move to the next cell
if exit_direction == 0 then
current_cell_y = current_cell_y - 1
elseif exit_direction == 1 then
current_cell_x = current_cell_x + 1
elseif exit_direction == 2 then
current_cell_y = current_cell_y + 1
elseif exit_direction == 3 then
current_cell_x = current_cell_x - 1
else
-- hmmmmm
return false
end
-- did we win?
if current_cell_x == end_cell_x and current_cell_y == end_cell_y then
--launch success popup
hack_main_sticks_launch_popup( true )
vint_set_property( Grid_highlight_image_h, "visible", false )
--kill the timer
Hack_timer_run = false
if Hack_timer_thread ~= nil then
thread_kill( Hack_timer_thread )
Hack_timer_thread = nil
end
--kill input
Hack_controls_locked = true
Hack_complete = true
return true
end
if Grid_pipe_count < pipe_count then
Grid_power_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_Charge" }, nil, false )
end
Grid_pipe_count = pipe_count
-- did we move out of the grid?
if current_cell_x < 0 or current_cell_x >= Grid_width then
return false
end
if current_cell_y < 0 or current_cell_y >= Grid_height then
return false
end
-- update incoming direction
incoming_direction = Hack_list_connection_directions[ exit_direction ]
end
end
function hack_main_sticks_timer_thread()
hacking_begin_player_voice()
while Hack_timer_run do
thread_yield()
if Hack_timer > 0 and Is_paused == false then
Hack_timer = Hack_timer - 1
if Hack_timer > 99 then
vint_set_property( Timer_h, "scale", 0.45, 0.45 )
else
vint_set_property( Timer_h, "scale", 0.6, 0.6 )
end
vint_set_property( Timer_h, "text_tag", Hack_timer )
--audio
if Hack_timer == 95 and Penalty == false then
audio_stop( Timer_audio_id )
Timer_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Timer_90" }, nil, false )
elseif Hack_timer == 65 and Penalty == false then
audio_stop( Timer_audio_id )
Timer_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Timer_60" }, nil, false )
elseif Hack_timer == 35 and Penalty == false then
audio_stop( Timer_audio_id )
Timer_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Timer_30" }, nil, false )
elseif Hack_timer == 15 and Penalty == false then
audio_stop( Timer_audio_id )
Timer_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Timer_10" }, nil, false )
end
--update hints every frame in case input devices changed
--hack_main_sticks_set_hints()
--show damage stuff, player got shot
if Penalty and Can_have_penalty then
Penalty = false
Can_have_penalty = false
Hack_timer = Hack_timer - 10
if Hack_timer < 0 then
Hack_timer = 0
Hack_complete = true
vint_set_property( Timer_h, "text_tag", Hack_timer )
audio_stop( Timer_audio_id )
--we ran out of timer--launch the failure popup
hack_main_sticks_launch_popup( false )
--kill the timer
Hack_timer_run = false
if Hack_timer_thread ~= nil then
thread_kill( Hack_timer_thread )
Hack_timer_thread = nil
end
--kill input
Hack_controls_locked = true
Hack_complete = true
end
local damage_anim_h = vint_object_find( "damage_anim" )
local damage_last_tween_h = vint_object_find( "damage_last_tween" )
vint_set_property( damage_last_tween_h, "end_event", "hack_main_sticks_unlock_penalty" )
lua_play_anim( damage_anim_h )
end
delay( 1 )
elseif Hack_timer <= 0 then
--we ran out of timer--launch the failure popup
hack_main_sticks_launch_popup( false )
--kill the timer
Hack_timer_run = false
if Hack_timer_thread ~= nil then
thread_kill( Hack_timer_thread )
Hack_timer_thread = nil
end
--kill input
Hack_controls_locked = true
Hack_complete = true
end
end
end
function hack_main_sticks_previous_puzzle()
Hack_puzzle_idx = Hack_puzzle_idx - 1
if Hack_puzzle_idx < 0 then
Hack_puzzle_idx = #Hack_main_puzzles
end
hack_main_sticks_redraw_screen()
end
function hack_main_sticks_next_puzzle()
Hack_puzzle_idx = Hack_puzzle_idx + 1
if Hack_puzzle_idx > #Hack_main_puzzles then
Hack_puzzle_idx = 0
end
hack_main_sticks_redraw_screen()
end
function hack_main_sticks_redraw_screen()
if #Hack_main_data.hack_grid_data > 0 then
hack_main_sticks_reset_grid()
--nuke the grid
for x = 0, Grid_width - 1 do
for y = 0, Grid_height - 1 do
vint_object_destroy( Hack_main_data.hack_grid_data[ x ][ y ].handle )
vint_object_destroy( Hack_main_data.hack_grid_data[ x ][ y ].pipe )
vint_object_destroy( Hack_main_data.hack_grid_data[ x ][ y ].bg_handle )
end
end
Hack_main_data = {}
Hack_main_data = Hack_main_puzzles[ Hack_puzzle_idx ]
Grid_width = #Hack_main_data.hack_grid_data + 1
Grid_height = #Hack_main_data.hack_grid_data + 1
Grid_max_width = TILE_WIDTH * (Grid_width - 1)
Grid_max_height = TILE_HEIGHT * (Grid_height - 1)
hack_main_sticks_draw_grid()
hack_main_sticks_set_grid_highlight_start()
hack_main_sticks_update_total()
local list_grp_h = vint_object_find("cell_list_grp")
local grid_x,grid_y = vint_get_property(Grid_h, "anchor")
local list_x,list_y = vint_get_property(list_grp_h, "anchor")
--position grid based on grid size
if Grid_width == 4 then
vint_set_property(Grid_h, "anchor", 468, 237 )
else
vint_set_property(Grid_h, "anchor", 390, 164 )
end
Hack_timer = 61
Hack_controls_locked = false
Hack_timer_run = true
if Hack_timer_thread == nil then
Hack_timer_thread = thread_new("hack_main_sticks_timer_thread")
end
vint_set_property( vint_object_find( "label" ), "text_tag", Hack_puzzle_idx )
hack_main_sticks_launch_popup()
end
end
function hack_main_sticks_nav_up(event, acceleration)
if not Hack_controls_locked then
hack_main_sticks_set_grid_highlight(-2)
else
if Hack_main_paused then
hack_main_sticks_set_popup_highlight(-1)
end
end
end
function hack_main_sticks_nav_down(event, acceleration)
if not Hack_controls_locked then
hack_main_sticks_set_grid_highlight(2)
else
if Hack_main_paused then
hack_main_sticks_set_popup_highlight(-1)
end
end
end
function hack_main_sticks_nav_left(event, acceleration)
if not Hack_controls_locked then
hack_main_sticks_set_grid_highlight(-1)
end
end
function hack_main_sticks_nav_right(event, acceleration)
if not Hack_controls_locked then
hack_main_sticks_set_grid_highlight(1)
end
end
function hack_main_sticks_button_x(event, acceleration)
if not Hack_controls_locked then
hack_main_sticks_reset_grid()
end
end
function hack_main_sticks_list_up(event, acceleration)
if not Hack_controls_locked and List_total > 0 and not Is_paused then
local current_type = Hack_main_data.hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type
--check if cell is open
--if current_type >= 0 then-- or A_mode then
local upper_limit = 1
local bottom_limit = TILE_HEIGHT * 6
local x,y = vint_get_property( List_highlight_h, "anchor" )
local prev_x,prev_y = vint_get_property( List_highlight_h, "anchor" )
y = y - TILE_HEIGHT
Prev_idx = List_idx
List_idx = List_idx - 1
if y < upper_limit then
y = bottom_limit
List_idx = List_height - 1
end
local count = 0
local check = true
while check do
if Hack_main_data.hack_list_data [ List_idx ].amount <= 0 then
y = y - TILE_HEIGHT
List_idx = List_idx - 1
if y < upper_limit then
y = bottom_limit
List_idx = List_height - 1
end
else
check = false
end
count = count + 1
if count > List_height - 1 then
check = false
end
end
if A_mode == false then
hack_main_sticks_update_amount( Prev_idx )
hack_main_sticks_update_cell( Grid_x_idx, Grid_y_idx )
else
hack_main_sticks_set_highlight_image()
end
if y ~= prev_y then
List_move_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "List_Highlight" }, nil, false )
end
vint_set_property( List_highlight_h, "anchor", 0, y )
--else
--play some error sound
--Grid_add_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_X" }, nil, false )
--end
end
end
function hack_main_sticks_list_down(event, acceleration)
if not Hack_controls_locked and List_total > 0 and not Is_paused then
debug_print( "vint","List_total = "..var_to_string( List_total ).."\n" )
local current_type = Hack_main_data.hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type
--if current_type >= 0 then-- or A_mode then
local upper_limit = TILE_HEIGHT
local bottom_limit = TILE_HEIGHT * 6
local x ,y = vint_get_property( List_highlight_h, "anchor" )
local prev_x,prev_y = vint_get_property( List_highlight_h, "anchor" )
y = y + TILE_HEIGHT
Prev_idx = List_idx
List_idx = List_idx + 1
if y > bottom_limit then
y = upper_limit
List_idx = 1
end
local count = 0
local check = true
while check do
if Hack_main_data.hack_list_data [ List_idx ].amount <= 0 then
y = y + TILE_HEIGHT
List_idx = List_idx + 1
if y > bottom_limit then
y = upper_limit
List_idx = 1
end
else
check = false
end
count = count + 1
if count > List_height - 1 then
check = false
end
end
if A_mode == false then
hack_main_sticks_update_amount( Prev_idx )
hack_main_sticks_update_cell( Grid_x_idx, Grid_y_idx )
else
hack_main_sticks_set_highlight_image()
end
if y ~= prev_y then
List_move_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "List_Highlight" }, nil, false )
end
vint_set_property( List_highlight_h, "anchor", 0, y )
--else
--play some error sound
-- Grid_add_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_X" }, nil, false )
--end
end
end
function hack_main_sticks_button_b(event, acceleration)
if Hack_controls_locked then
if Hack_tutorial_active and Hack_popup_ready then
Hack_controls_locked = false
Hack_tutorial_active = false
hack_main_sticks_launch_popup()
Hack_timer_thread = thread_new( "hack_main_sticks_timer_thread" )
Input_tracker:subscribe(true)
Tutorial_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Tutorial_Out" }, nil, false )
--game_UI_audio_play("UI_Cell_Select")
return
elseif Hack_complete then
game_UI_audio_play( "UI_Cell_Select" )
hacking_screen_exit()
end
end
if A_mode and Hack_controls_locked == false then
--get the current cell type
local current_type = Hack_main_data.hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type
-- if we are not a blank cell
if current_type > 0 then
--add one back to the list of cell types
Hack_main_data.hack_list_data [ current_type ].amount = Hack_main_data.hack_list_data [ current_type ].amount + 1
--clear out the cell
Hack_main_data.hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type = 0
--set the cell to be blank
hack_main_sticks_set_cell_image( Grid_x_idx, Grid_y_idx )
--recheck if we are valid
hack_main_sticks_validate_cells()
--update the list of cell types
hack_main_sticks_refresh_list()
hack_main_sticks_update_total()
local unhighlight_anim_h = vint_object_find( "unhighlight_anim" )
lua_play_anim( unhighlight_anim_h, 0 )
Grid_remove_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_Delete" }, nil, false )
local list_type = Hack_main_data.hack_list_data[ List_idx ].type
local current_amount = Hack_main_data.hack_list_data [ List_idx ].amount
if current_amount < 1 and list_type > 0 then
local upper_limit = TILE_HEIGHT
local bottom_limit = TILE_HEIGHT * 6
local x ,y = vint_get_property( List_highlight_h, "anchor" )
local count = 0
local check = true
while check do
if Hack_main_data.hack_list_data [ List_idx ].amount <= 0 then
y = y + TILE_HEIGHT
List_idx = List_idx + 1
if y > bottom_limit then
y = upper_limit
List_idx = 1
end
else
check = false
end
count = count + 1
if count > List_height - 1 then
check = false
end
end
vint_set_property( List_highlight_h, "anchor", 0, y )
end
hack_main_sticks_set_highlight_image()
else
Grid_add_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_X" }, nil, false )
end
end
end
function hack_main_sticks_button_a(event, acceleration)
if Hack_controls_locked then
if Hack_tutorial_active and Hack_popup_ready then
Hack_controls_locked = false
Hack_tutorial_active = false
hack_main_sticks_launch_popup()
Hack_timer_thread = thread_new("hack_main_sticks_timer_thread")
Input_tracker:subscribe(true)
Tutorial_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Tutorial_Out" }, nil, false )
return
elseif Hack_complete then
game_UI_audio_play("UI_Cell_Select")
hacking_screen_exit()
end
end
if A_mode and Hack_controls_locked == false then
local grid_type = Hack_main_data.hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type
local list_type = Hack_main_data.hack_list_data[ List_idx ].type
local current_amount = Hack_main_data.hack_list_data [ List_idx ].amount
if grid_type >= 0 then
if grid_type ~= list_type then
if current_amount > 0 or list_type == 0 then
if grid_type > 0 then
Hack_main_data.hack_list_data[ grid_type ].amount = Hack_main_data.hack_list_data[ grid_type ].amount + 1
end
if list_type > 0 then
Hack_main_data.hack_list_data [ List_idx ].amount = Hack_main_data.hack_list_data [ List_idx ].amount - 1
end
Grid_add_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_Place" }, nil, false )
lua_play_anim( Highlight_anim_h, 0 )
hack_main_sticks_update_cell( Grid_x_idx, Grid_y_idx )
--recheck if we are valid
hack_main_sticks_validate_cells()
--update the list of cell types
hack_main_sticks_refresh_list()
hack_main_sticks_update_total()
current_amount = Hack_main_data.hack_list_data [ List_idx ].amount
if current_amount < 1 and list_type > 0 then
local upper_limit = TILE_HEIGHT
local bottom_limit = TILE_HEIGHT * 6
local x ,y = vint_get_property( List_highlight_h, "anchor" )
local count = 0
local check = true
while check do
if Hack_main_data.hack_list_data [ List_idx ].amount <= 0 then
y = y + TILE_HEIGHT
List_idx = List_idx + 1
if y > bottom_limit then
y = upper_limit
List_idx = 1
end
else
check = false
end
count = count + 1
if count > List_height - 1 then
check = false
end
end
hack_main_sticks_set_highlight_image()
vint_set_property( List_highlight_h, "anchor", 0, y )
end
else
Grid_add_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_X" }, nil, false )
end
end
else
--play error sound we are on a dead tile
Grid_add_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Block_X" }, nil, false )
end
end
end
function hack_main_sticks_unlock_controls()
Input_tracker:subscribe(true)
if Hack_mouse_input_tracker ~= nil then
hack_main_sticks_add_mouse_inputs()
Hack_mouse_input_tracker:subscribe(true)
end
end
function hack_main_sticks_lock_controls()
Input_tracker:subscribe(false)
if Hack_mouse_input_tracker ~= nil then
Hack_mouse_input_tracker:subscribe(false)
end
end
function hack_main_sticks_set_list_highlight( new_idx )
local x ,y = vint_get_property(List_highlight_h, "anchor")
if new_idx >= 0 then
List_idx = new_idx
if new_idx > 0 then
y = TILE_HEIGHT * new_idx --1 * ( TILE_HEIGHT * new_idx )
else
y = 0
end
vint_set_property(List_highlight_h, "anchor", 0, y)
else
vint_set_property(List_highlight_h, "anchor", 0, 0)
end
hack_main_sticks_set_highlight_image()
end
function hack_main_sticks_set_list_mouse_highlight( new_idx )
local list_mouse_highlight_h = vint_object_find( "list_mouse_highlight_grp" )
local x ,y = vint_get_property(list_mouse_highlight_h, "anchor")
if new_idx >= 0 then
--List_idx = new_idx
if new_idx > 0 then
y = TILE_HEIGHT * new_idx --1 * ( TILE_HEIGHT * new_idx )
else
y = 0
end
vint_set_property(list_mouse_highlight_h, "anchor", 0, y)
else
vint_set_property(list_mouse_highlight_h, "anchor", 0, 0)
end
--hack_main_sticks_set_highlight_image()
end
function hack_main_sticks_set_grid_highlight_start()
local x ,y = vint_get_property(Grid_highlight_h, "anchor")
vint_set_property( Grid_highlight_h, "anchor", 0, ((Hack_main_data.hack_start) * TILE_HEIGHT) )
Grid_x_idx = 0
Grid_y_idx = Hack_main_data.hack_start
end
function hack_main_sticks_set_grid_highlight(direction)
local x ,y = vint_get_property(Grid_highlight_h, "anchor")
local prev_x,prev_y = vint_get_property(Grid_highlight_h, "anchor")
if direction == 1 then
-- RIGHT
x = x + TILE_WIDTH
Grid_x_idx = Grid_x_idx + 1
elseif direction == -1 then
-- LEFT
x = x - TILE_WIDTH
Grid_x_idx = Grid_x_idx - 1
elseif direction == 2 then
-- DOWN
y = y + TILE_HEIGHT
Grid_y_idx = Grid_y_idx + 1
elseif direction == -2 then
-- UP
y = y - TILE_HEIGHT
Grid_y_idx = Grid_y_idx - 1
end
--check the limits
if x > Grid_max_width then
x = Grid_max_width
Grid_x_idx = Grid_width - 1
elseif x < 0 then
x = 0
Grid_x_idx = 0
end
if y > Grid_max_height then
y = Grid_max_height
Grid_y_idx = Grid_height - 1
elseif y < 0 then
y = 0
Grid_y_idx = 0
end
vint_set_property(Grid_highlight_h, "anchor", x, y)
if x ~= prev_x or y ~= prev_y then
Grid_move_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Grid_Highlight" }, nil, false )
end
if A_mode then
vint_set_property( Grid_highlight_image_h, "scale", 0.9, 0.9 )
vint_set_property( Grid_highlight_image_h, "alpha", 0.8 )
end
local current_type = Hack_main_data.hack_grid_data[ Grid_x_idx ][ Grid_y_idx ].type
if current_type > 0 then
hack_main_sticks_set_highlight_image()
end
end
function hack_main_sticks_update_cell( cell_x, cell_y )
local current_type = Hack_main_data.hack_grid_data[ cell_x ][ cell_y ].type
local list_type = Hack_main_data.hack_list_data [ List_idx ].type
if current_type >= 0 then
if current_type ~= list_type then
Hack_main_data.hack_grid_data[ cell_x ][ cell_y ].type = list_type
hack_main_sticks_set_cell_image( cell_x, cell_y )
hack_main_sticks_validate_cells()
end
end
end
function hack_main_sticks_set_cell_image( cell_x, cell_y )
local cell_type = Hack_main_data.hack_grid_data[ cell_x ][ cell_y ].type
local cell_handle = Hack_main_data.hack_grid_data[ cell_x ][ cell_y ].handle
if cell_type == -1 then
vint_set_property( cell_handle, "image", "ui_hack_grid_lock" )
vint_set_property( cell_handle, "alpha", 0.33 )
elseif cell_type == 0 then
vint_set_property( cell_handle, "image", "ui_hack_grid_blank" )
vint_set_property( cell_handle, "alpha", 0.0 )
elseif cell_type == 1 then
vint_set_property( cell_handle, "image", "ui_hack_grid_hor" )
vint_set_property( cell_handle, "alpha", 1.0 )
elseif cell_type == 2 then
vint_set_property( cell_handle, "image", "ui_hack_grid_vert" )
vint_set_property( cell_handle, "alpha", 1.0 )
elseif cell_type == 3 then
vint_set_property( cell_handle, "image", "ui_hack_grid_ne" )
vint_set_property( cell_handle, "alpha", 1.0 )
elseif cell_type == 4 then
vint_set_property( cell_handle, "image", "ui_hack_grid_se" )
vint_set_property( cell_handle, "alpha", 1.0 )
elseif cell_type == 5 then
vint_set_property( cell_handle, "image", "ui_hack_grid_sw" )
vint_set_property( cell_handle, "alpha", 1.0 )
elseif cell_type == 6 then
vint_set_property( cell_handle, "image", "ui_hack_grid_nw" )
vint_set_property( cell_handle, "alpha", 1.0 )
end
end
function hack_main_sticks_set_highlight_image()
local cell_type = Hack_main_data.hack_list_data [ List_idx ].type
local cell_amount = Hack_main_data.hack_list_data [ List_idx ].amount
local cell_handle = Grid_highlight_image_h
debug_print("vint","cell_type = "..var_to_string( cell_type ).."\n")
debug_print("vint","cell_amount = "..var_to_string( cell_amount ).."\n")
debug_print("vint","List_idx = "..var_to_string( List_idx ).."\n\n")
if cell_amount > 0 then
vint_set_property( Grid_highlight_image_h, "visible", true )
else
vint_set_property( Grid_highlight_image_h, "visible", false )
end
vint_set_property( Grid_highlight_image_h, "scale", 0.9, 0.9 )
local cell_alpha = 0.9
if cell_type == -1 then
vint_set_property( cell_handle, "image", "ui_hack_grid_lock" )
elseif cell_type == 0 then
vint_set_property( cell_handle, "image", "ui_blank" )
vint_set_property( cell_handle, "alpha", 0)
elseif cell_type == 1 then
vint_set_property( cell_handle, "image", "ui_hack_grid_hor" )
vint_set_property( cell_handle, "alpha", cell_alpha )
elseif cell_type == 2 then
vint_set_property( cell_handle, "image", "ui_hack_grid_vert" )
vint_set_property( cell_handle, "alpha", cell_alpha )
elseif cell_type == 3 then
vint_set_property( cell_handle, "image", "ui_hack_grid_ne" )
vint_set_property( cell_handle, "alpha", cell_alpha)
elseif cell_type == 4 then
vint_set_property( cell_handle, "image", "ui_hack_grid_se" )
vint_set_property( cell_handle, "alpha", cell_alpha )
elseif cell_type == 5 then
vint_set_property( cell_handle, "image", "ui_hack_grid_sw" )
vint_set_property( cell_handle, "alpha", cell_alpha )
elseif cell_type == 6 then
vint_set_property( cell_handle, "image", "ui_hack_grid_nw" )
vint_set_property( cell_handle, "alpha", cell_alpha )
end
end
function hack_main_sticks_set_pipe( handle, cell_type )
if cell_type == -1 then
vint_set_property( handle, "image", "ui_hack_grid_lock" )
elseif cell_type == 0 then
vint_set_property( handle, "image", "ui_hack_grid_blank" )
elseif cell_type == 1 then
vint_set_property( handle, "image", "ui_hack_grid_pipe_hor" )
elseif cell_type == 2 then
vint_set_property( handle, "image", "ui_hack_grid_pipe_vert" )
elseif cell_type == 3 then
vint_set_property( handle, "image", "ui_hack_grid_pipe_ne" )
elseif cell_type == 4 then
vint_set_property( handle, "image", "ui_hack_grid_pipe_se" )
elseif cell_type == 5 then
vint_set_property( handle, "image", "ui_hack_grid_pipe_sw" )
elseif cell_type == 6 then
vint_set_property( handle, "image", "ui_hack_grid_pipe_nw" )
end
end
function hack_main_sticks_draw_list()
--loop through the list of cells and store handles
for i = 0, List_height - 1 do
--store handles if we have not done so already
if Hack_main_data.hack_list_data [ i ].handle == nil then
Hack_main_data.hack_list_data [ i ].handle = vint_object_find( Hack_main_data.hack_list_data [ i ].name )
Hack_main_data.hack_list_data [ i ].txt = vint_object_find( "cell_txt", Hack_main_data.hack_list_data [ i ].handle )
Hack_main_data.hack_list_data [ i ].bg = vint_object_find( "cell_txt_bg", Hack_main_data.hack_list_data [ i ].handle )
Hack_main_data.hack_list_data [ i ].image = vint_object_find( "cell_image", Hack_main_data.hack_list_data [ i ].handle )
end
--reset the amount to the max amount you can have
Hack_main_data.hack_list_data [ i ].amount = Hack_main_data.hack_list_data [ i ].max_amount
Hack_main_data.hack_list_data [ i ].amount_used = 0
end
--update the visual state of the cells in the list
hack_main_sticks_refresh_list()
end
function hack_main_sticks_refresh_list()
--loop through all the list items
for i = 0, List_height - 1 do
--grab the amount
local amount = Hack_main_data.hack_list_data [ i ].amount
--if we are not the blank cell then refresh
if amount >= 0 then
--set the amount
vint_set_property( Hack_main_data.hack_list_data [ i ].txt, "text_tag", Hack_main_data.hack_list_data [ i ].amount )
--if we have no pieces and we are not blank then turn us off
if amount == 0 and Hack_main_data.hack_list_data [ i ].type > 0 then
vint_set_property( Hack_main_data.hack_list_data [ i ].image, "tint", 0.5,0.5,0.5)
else
--if we have pieces and we are not blank then turn us on
vint_set_property( Hack_main_data.hack_list_data [ i ].image, "tint", 1, 1, 1 )
end
else
--we are the blank cell so we have infinite pieces, don't show the amount ever
vint_set_property( Hack_main_data.hack_list_data [ i ].txt, "visible", false)
vint_set_property( Hack_main_data.hack_list_data [ i ].bg, "visible", false)
end
end
end
function hack_main_sticks_update_amount( prev_idx )
--if the current tile is not blank then change the amount
if Hack_main_data.hack_list_data [ List_idx ].type > 0 then
--take one tile away
Hack_main_data.hack_list_data [ List_idx ].amount = Hack_main_data.hack_list_data [ List_idx ].amount - 1
Hack_main_data.hack_list_data [ List_idx ].amount_used = Hack_main_data.hack_list_data [ List_idx ].amount_used + 1
--check if we are now negative
if Hack_main_data.hack_list_data [ List_idx ].amount < 0 then
Hack_main_data.hack_list_data [ List_idx ].amount = 0
end
end
--if the previous tile was not blank then add one back
if Hack_main_data.hack_list_data [ prev_idx ].type > 0 then
Hack_main_data.hack_list_data [ prev_idx ].amount = Hack_main_data.hack_list_data [ prev_idx ].amount + 1
Hack_main_data.hack_list_data [ List_idx ].amount_used = Hack_main_data.hack_list_data [ List_idx ].amount_used - 1
end
hack_main_sticks_refresh_list()
end
function hack_main_sticks_draw_grid()
local cur_y = 0
local tile_count = 0
--loop through the amount of cells needed
for tile_y = 0, Grid_height - 1 do
for tile_x = 0, Grid_width - 1 do
local bitmap_h = vint_object_create( "grid_blank", "bitmap", Grid_h )
local pipe_h = vint_object_create( "pipe_blank", "bitmap", Grid_h )
--store the handle
Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].handle = bitmap_h
Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].pipe = pipe_h
--set the image
hack_main_sticks_set_cell_image( tile_x, tile_y )
vint_set_property( pipe_h, "depth", -100 )
vint_set_property( pipe_h, "visible", false )
vint_set_property( pipe_h, "image", "ui_hack_grid_pipe_hor" )
--position...
local x = (tile_x * TILE_WIDTH) + 6
local y = 7 + cur_y
vint_set_property( bitmap_h, "anchor", x, y )
x = (tile_x * TILE_WIDTH) - 6
y = cur_y - 2
vint_set_property( pipe_h, "anchor", x, y )
tile_count = tile_count + 1
end
--Increment y positon...
cur_y = cur_y + TILE_HEIGHT
end
cur_y = 0
tile_count = 0
for tile_y = 0, Grid_height - 1 do
for tile_x = 0, Grid_width - 1 do
local bitmap_h = vint_object_create( "bg_blank", "bitmap", Grid_h )
Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].bg_handle = bitmap_h
vint_set_property( bitmap_h, "image", "ui_hack_grid_blank" )
vint_set_property( bitmap_h, "alpha", 0.40 )
vint_set_property( bitmap_h, "depth", 100 )
--position...
local x = tile_x * TILE_WIDTH
local y = cur_y
vint_set_property( bitmap_h, "anchor", x, y )
tile_count = tile_count + 1
end
--Increment y positon...
cur_y = cur_y + TILE_HEIGHT
end
--set the start point
local cell_start_grp_h = vint_object_find( "cell_start_grp" )
vint_set_property( cell_start_grp_h, "anchor", 5, ((Hack_main_data.hack_start + 1) * TILE_HEIGHT) - (TILE_HEIGHT * 0.5))
--set the end point(s)
local cell_end_grp_h = vint_object_find( "cell_end_grp" )
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))
--set up the list handles and tile amounts
hack_main_sticks_draw_list()
end
function hack_main_sticks_reset_grid()
--loop through the grid and reset anything that is not invalid or blank
for y = 0, Grid_height - 1 do
for x = 0, Grid_width - 1 do
local type = Hack_main_data.hack_grid_data[ x ][ y ].type
--if we are not invalid or blank then set us to blank
if type > 0 then
Hack_main_data.hack_grid_data[ x ][ y ].type = 0
hack_main_sticks_set_cell_image( x, y )
vint_set_property( Hack_main_data.hack_grid_data[ x ][ y ].pipe, "visible", false )
end
--reset all the tints
vint_set_property( Hack_main_data.hack_grid_data[ x ][ y ].handle, "tint", 1, 1, 1 )
end
end
--refresh all our piece amounts in the list and redraw it
hack_main_sticks_draw_list()
hack_main_sticks_set_list_highlight( 1 )
hack_main_sticks_set_highlight_image()
hack_main_sticks_set_grid_highlight_start()
hack_main_sticks_update_total()
Grid_reset_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Grid_Reset" }, nil, false )
vint_set_property( List_highlight_h, "visible", true )
end
function hack_main_sticks_update_total()
List_total = 0
for i = 1, 6 do
List_total = List_total + Hack_main_data.hack_list_data[ i ].amount
end
if List_total > 0 then
vint_set_property( List_highlight_h, "visible", true )
else
vint_set_property( List_highlight_h, "visible", false )
end
end
function hack_main_sticks_pause()
local pause_scrim_h = vint_object_find( "pause_scrim" )
local pause_scrim_hints_h = vint_object_find( "pause_scrim_hints" )
local list_grp_h = vint_object_find( "cell_list_grp" )
if Is_paused then
vint_set_property( pause_scrim_h, "visible", true )
vint_set_property( pause_scrim_hints_h, "visible", true )
vint_set_property( list_grp_h, "visible", false )
if game_get_platform() == "PC" then
Hack_mouse_input_tracker:subscribe(false)
end
else
vint_set_property( pause_scrim_h, "visible", false )
vint_set_property( pause_scrim_hints_h, "visible", false )
vint_set_property( list_grp_h, "visible", true )
if game_get_platform() == "PC" then
Hack_mouse_input_tracker:subscribe(true)
end
end
end
function hack_main_sticks_set_popup_highlight( direction )
local highlight_grp_h = vint_object_find( "popup_list_highlight_grp" )
local button_height = 30
local highlight_x,highlight_y = vint_get_property( highlight_grp_h, "anchor" )
if direction == 1 then
highlight_y = highlight_y + button_height
end
if direction == -1 then
highlight_y = highlight_y - button_height
end
if highlight_y < 0 then
highlight_y = button_height
end
if highlight_y > button_height then
highlight_y = 0
end
vint_set_property( highlight_grp_h, "anchor", highlight_x, highlight_y )
end
function hack_main_sticks_launch_popup( success, message )
Hack_popup_open = true
local popup_grp_h = vint_object_find( "popup_grp" )
local popup_title_h = vint_object_find( "popup_title" )
local popup_message_h = vint_object_find( "popup_text" )
local popup_animate_in_h = vint_object_find( "popup_animate_in" )
local popup_animate_out_h = vint_object_find( "popup_animate_out" )
vint_set_property( popup_message_h, "visible", false )
local popup_list_grp_h = vint_object_find( "popup_list_grp" )
vint_set_property( popup_list_grp_h, "visible", false )
local popup_footer_grp_h = vint_object_find( "popup_footer_grp" )
local popup_background_h = vint_object_find( "popup_background" )
local popup_elements_grp_h = vint_object_find( "popup_move_grp" )
if Popup_defaults_changed == false then
Popup_footer_grp_x, Popup_footer_grp_y = vint_get_property( popup_footer_grp_h, "anchor" )
Popup_background_width, Popup_background_height = element_get_actual_size( popup_background_h)
Popup_background_x, Popup_background_y = vint_get_property( popup_background_h, "anchor" )
Popup_elements_grp_x, Popup_elements_grp_y = vint_get_property( popup_elements_grp_h, "anchor" )
else
vint_set_property( popup_footer_grp_h, "anchor", Popup_footer_grp_x, Popup_footer_grp_y )
element_set_actual_size( popup_background_h, Popup_background_width, Popup_background_height )
vint_set_property( popup_background_h, "anchor", Popup_background_x, Popup_background_y )
vint_set_property( popup_elements_grp_h, "anchor", Popup_elements_grp_x, Popup_elements_grp_y)
end
local hint_data = {
{CTRL_MENU_BUTTON_A, "CONTROL_CONTINUE"},
}
Popup_hint_bar:set_hints(hint_data)
if game_get_platform() == "PC" then
Hack_mouse_input_tracker:subscribe(false)
Hack_popup_mouse_input_tracker:subscribe(true)
end
if message ~= nil then
debug_print("vint","START MESSAGE POPUP\n")
vint_set_property( popup_title_h, "visible", false )
vint_set_property( popup_message_h, "visible", true )
vint_set_property( popup_message_h, "text_tag", message )
lua_play_anim( popup_animate_in_h )
vint_apply_start_values( popup_animate_in_h )
Hack_popup_ready = false
Tutorial_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Tutorial_In" }, nil, false )
local message_width, message_height = element_get_actual_size(popup_message_h)
--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")
if message_height > 175 then
local height_diff = message_height - 175 -- Determine the difference in height
local height_increase_percent = 1 + (height_diff / 175) -- Determine the percent of how much larger the diff is, ex: 1.5 = 150% larger
vint_set_property( popup_footer_grp_h, "anchor", Popup_footer_grp_x, Popup_footer_grp_y + height_diff )
element_set_actual_size( popup_background_h, Popup_background_width, Popup_background_height * height_increase_percent )
vint_set_property( popup_background_h, "anchor", Popup_background_x, Popup_background_y + (height_diff/2) )
vint_set_property( popup_elements_grp_h, "anchor", Popup_elements_grp_x, Popup_elements_grp_y - height_diff/2 )
Popup_defaults_changed = true
end
else
if success then
hacking_screen_report( true )
vint_set_property( popup_title_h, "visible", true )
vint_set_property( popup_title_h, "text_tag", "MENU_HACK_COMPLETE" )
lua_play_anim( popup_animate_in_h )
vint_apply_start_values( popup_animate_in_h )
Hack_popup_ready = false
audio_stop( Timer_audio_id )
Hack_end_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Hack_Complete" }, nil, false )
elseif success == false then
hacking_screen_report( false )
vint_set_property( popup_title_h, "visible", true )
vint_set_property( popup_title_h, "text_tag", "MENU_HACK_FAILED" )
lua_play_anim( popup_animate_in_h )
vint_apply_start_values( popup_animate_in_h )
Hack_popup_ready = false
Hack_end_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Hack_Fail" }, nil, false )
else
lua_play_anim( popup_animate_out_h )
Hack_popup_open = false
if game_get_platform() == "PC" then
Hack_mouse_input_tracker:subscribe(true)
Hack_popup_mouse_input_tracker:subscribe(false)
end
end
local popup_title_width, popup_title_height = element_get_actual_size( popup_title_h )
if popup_title_width >= Popup_background_width - 10 then
resize_text_element( popup_title_h, Popup_background_width - 10 )
end
end
end
function hack_main_sticks_print_list()
debug_print("vint","local Hack_main_data.hack_grid_data = {\n")
for y = 0, Grid_height - 1 do
debug_print("vint","["..y.."] = {\n")
for x = 0, Grid_width - 1 do
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,},},
end
debug_print("vint","},\n")
end
debug_print("vint","}\n")
debug_print("vint","\nlocal Hack_main_data.hack_list_data = {\n")
for i = 0, List_height - 1 do
debug_print("vint","["..i.."] = {\n")
debug_print("vint","type = "..Hack_main_data.hack_list_data [i].type..",\n")
debug_print("vint","max_amount = "..Hack_main_data.hack_list_data [i].amount_used..",\n")
debug_print("vint","name = "..Hack_main_data.hack_list_data [i].name..",\n")
debug_print("vint","},\n")
end
debug_print("vint","}\n")
end
function hack_main_sticks_set_a_mode()
local highlight_button = Vdo_hint_button:new( "highlight_button" )
if A_mode then
A_mode = false
else
A_mode = true
end
highlight_button:set_visible( A_mode )
vint_set_property( Grid_highlight_image_h, "visible", A_mode )
end
function hack_main_sticks_draw_side_grids()
local cur_y = 0
local tile_count = 0
local left_grid_grp_h = vint_object_find( "left_grid_grp" )
--loop through the amount of cells needed
for tile_y = 0, 5 do
for tile_x = 0, 16 do
local bitmap_h = vint_object_create("grid_blank", "bitmap", left_grid_grp_h)
--store the handle
vint_set_property( bitmap_h, "image", "ui_hack_grid_blank" )
--position...
local x = tile_x * (TILE_WIDTH)
local y = cur_y
vint_set_property(bitmap_h, "anchor", x, y)
tile_count = tile_count + 1
end
--Increment y positon...
cur_y = cur_y + TILE_HEIGHT
end
end
--PC SPECIFIC FUNCTIONS
function hack_main_sticks_mouse_click(event, target_handle)
if Hack_tutorial_active or Hack_popup_open then
hack_main_sticks_button_a()
return
end
local hint_index = Hint_bar:get_hint_index( target_handle )
if hint_index == 4 then
hack_main_sticks_button_x()
end
if Grid_mouse_lock then
Grid_mouse_lock = false
else
Grid_mouse_lock = true
end
--handle grid highlight
local tile_h
for tile_y = 0, Grid_height - 1 do
for tile_x = 0, Grid_width - 1 do
tile_h = Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].handle
if tile_h == target_handle then
local x,y = vint_get_property( target_handle, "anchor" )
vint_set_property( Grid_highlight_h, "anchor", x - 6, y - 8 )
Grid_x_idx = tile_x
Grid_y_idx = tile_y
Grid_move_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Grid_Highlight" }, nil, false )
hack_main_sticks_button_a()
end
end
end
for i = 0, List_height - 1 do
if target_handle == Hack_main_data.hack_list_data[ i ].handle then
if Hack_main_data.hack_list_data[ i ].amount > 0 then
hack_main_sticks_set_list_highlight( i )
end
end
end
end
function hack_main_sticks_mouse_right_click(event, target_handle)
local tile_h
for tile_y = 0, Grid_height - 1 do
for tile_x = 0, Grid_width - 1 do
tile_h = Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].handle
if tile_h == target_handle then
local x,y = vint_get_property( target_handle, "anchor" )
vint_set_property( Grid_highlight_h, "anchor", x - 6, y - 8 )
Grid_x_idx = tile_x
Grid_y_idx = tile_y
Grid_move_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Grid_Highlight" }, nil, false )
end
end
end
hack_main_sticks_button_b()
end
function hack_main_sticks_mouse_move(event, target_handle)
--handle hintbar highlight
Hint_bar:set_highlight(0)
local hint_index = Hint_bar:get_hint_index( target_handle )
if hint_index == 4 then
Hint_bar:set_highlight(hint_index)
end
local tile_h
for tile_y = 0, Grid_height - 1 do
for tile_x = 0, Grid_width - 1 do
tile_h = Hack_main_data.hack_grid_data[ tile_x ][ tile_y ].handle
if tile_h == target_handle then
local x,y = vint_get_property( target_handle, "anchor" )
vint_set_property( Grid_highlight_h, "anchor", x - 6, y - 8 )
Grid_x_idx = tile_x
Grid_y_idx = tile_y
Grid_move_audio_id = audio_object_post_event( "UI_SFX", { "UI_SFX", "UI_Hacking_SFX" }, { "UI_Hacking_SFX", "Grid_Highlight" }, nil, false )
end
end
end
local list_mouse_highlight_h = vint_object_find( "list_mouse_highlight_grp" )
vint_set_property( list_mouse_highlight_h, "visible", false )
for i = 0, List_height - 1 do
if target_handle == Hack_main_data.hack_list_data[ i ].handle then
if Hack_main_data.hack_list_data[ i ].amount > 0 then
hack_main_sticks_set_list_mouse_highlight( i )
vint_set_property( list_mouse_highlight_h, "visible", true )
end
end
end
end
function hack_main_sticks_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines)
--scroll lines are inverted for some reason
scroll_lines = scroll_lines * -1
if scroll_lines < 0 then
hack_main_sticks_list_up()
else
hack_main_sticks_list_down()
end
end
--[[ ---------------------------------------------------------------------
-- Function - hack_main_sticks_update_gamepad_state
-- Description - Called by code anytime gamepad is plugged or unplugged.
-- Parameters - none
-- Returns - nil
]]-- ---------------------------------------------------------------------
function hack_main_sticks_update_gamepad_state()
hack_main_sticks_set_hints()
end