--Globals...
local TILE_WIDTH = 126
local TILE_HEIGHT = 126
local Character_select_doc_h
local Character_select_screen_grp_h
local Grid_highlight_h
local Grid_glow_h
local Character_image_h
local Character_image_mask_h
local Character_select_out_anim_h
local Grid_button
local Character_select_input_tracker
local Character_select_mouse_Character_select_input_tracker
local Grid_data = {}
local Store_character_select_img_update_thread = -1
local Store_character_select_loading_img = nil
local Store_character_select_unload_img = nil
local Store_character_select_current_img = nil
local Character_select_image_idx = 1
Store_character_select_anim_done = false
local Character_select_mouse_input_tracker = nil
local Character_cell_handles = { "cell_1_1","cell_1_2","cell_1_3",
"cell_2_1","cell_2_2","cell_2_3",
"cell_3_1","cell_3_2","cell_3_3",}
local Zinyak_image_string = "ui_store_lineup_mugshot_10"
local Grid_col_idx = 1
local Grid_row_idx = 1
local Grid_width = 3
local Grid_height = 3
local Grid_max_width = ( TILE_WIDTH * Grid_width ) - TILE_WIDTH
local Grid_max_height = ( TILE_HEIGHT * Grid_height ) - TILE_HEIGHT
function store_character_select_init()
-- Find our documents...
Character_select_doc_h = vint_document_find( "store_character_select" )
Character_select_screen_grp_h = vint_object_find( "screen_grp" )
vint_set_property( Character_select_screen_grp_h, "alpha", 0.0 )
Character_select_input_tracker = Input_tracker:new()
Character_select_input_tracker:add_input( "select", "store_character_select_button_a", 50 )
Character_select_input_tracker:add_input( "nav_up", "store_character_select_nav_up", 50 )
Character_select_input_tracker:add_input( "nav_down", "store_character_select_nav_down", 50 )
Character_select_input_tracker:add_input( "nav_left", "store_character_select_nav_left", 50 )
Character_select_input_tracker:add_input( "nav_right", "store_character_select_nav_right", 50 )
Character_select_input_tracker:subscribe( false )
Grid_highlight_h = vint_object_find( "grid_highlight_grp" )
Grid_glow_h = vint_object_find( "grid_glow" )
Grid_button = Vdo_hint_button:new( "highlight_button", 0, Character_select_doc_h )
Grid_button:set_button( CTRL_MENU_BUTTON_A )
Character_image_h = vint_object_find( "player_image" )
Character_image_mask_h = vint_object_find( "player_image_mask" )
-- build the grid data
local image_idx = 0
for x = 1, 3 do
Grid_data[ x ] = { }
for y = 1, 3 do
Grid_data[ x ][ y ] = { }
Grid_data[ x ][ y ].handle = vint_object_find( "cell_"..x.."_"..y )
image_idx = ( x - 1 ) * Grid_width + y
Grid_data[ x ][ y ].image = "ui_store_lineup_mugshot_0"..image_idx
end
end
local highlight_anim_h = vint_object_find( "highlight_anim" )
lua_play_anim( highlight_anim_h, 0, Character_select_doc_h )
local player_glow_anim_h = vint_object_find( "player_glow_anim" )
lua_play_anim( player_glow_anim_h, 0, Character_select_doc_h )
local zinyak_glow_anim_h = vint_object_find( "zinyak_glow_anim" )
lua_play_anim( zinyak_glow_anim_h, 0, Character_select_doc_h )
-- make fire
local fire_h = vint_object_find( "fire" )
local fire_frames_table = { "ui_hud_diversion_fire1", "ui_hud_diversion_fire2", "ui_hud_diversion_fire3", "ui_hud_diversion_fire4", "ui_hud_diversion_fire5","ui_hud_diversion_fire6", "ui_hud_diversion_fire7",
"ui_hud_diversion_fire8", "ui_hud_diversion_fire9", "ui_hud_diversion_fire10", "ui_hud_diversion_fire11", "ui_hud_diversion_fire12", "ui_hud_diversion_fire13", "ui_hud_diversion_fire14"}
vint_bitmap_animator_register_animation(--[[target handle]]fire_h, --[[loop type see game_ui_globals.lua]]ANIMATED_BITMAP_PLAYBACK_TYPE_LOOPING, --[[playback reverse]] false,
--[[frametime]]1/18, --[[duration (negative means forever)]]-1.0, --[[start paused]]false, --[[starting frame]] 1, --[[frames table]]fire_frames_table, --[[end event]] "")
local char_sel_in_anim_h = vint_object_find( "char_sel_in_anim", 0, Character_select_doc_h )
Character_select_out_anim_h = vint_object_clone( char_sel_in_anim_h )
lua_reverse_anim( Character_select_out_anim_h )
if game_get_platform() == "PC" then
Character_select_mouse_input_tracker = Vdo_input_tracker:new()
for x = 1, 3 do
for y = 1, 3 do
Character_select_mouse_input_tracker:add_mouse_input("mouse_click", "store_character_select_mouse_click", 25, Grid_data[ x ][ y ].handle )
Character_select_mouse_input_tracker:add_mouse_input("mouse_move", "store_character_select_mouse_move", 100, Grid_data[ x ][ y ].handle )
end
end
Character_select_mouse_input_tracker:subscribe(true)
end
local player_name = game_lobby_get_local_player_name()
store_character_select_set_player_name( player_name )
if pcr_is_plastic_surgeon() == false then
--Load initial pegs...
thread_new( "store_character_select_load_initial_pegs" )
end
end
function store_character_select_load_initial_pegs()
--Dump the pause map.
game_peg_unload( "ui_map_world_city" )
thread_yield()
-- Pre-load top level images
game_peg_load_with_cb( "store_character_select_zinyak_loaded", 2, "ui_store_lineup_mugshot_01", Zinyak_image_string )
end
function store_character_select_zinyak_loaded()
--show screen stuff
local zinyak_image = vint_object_find( "zinyak_image" )
vint_set_property( zinyak_image, "image", Zinyak_image_string )
vint_set_property( Character_image_h, "image", "ui_store_lineup_mugshot_01" )
vint_set_property( Character_image_mask_h, "image", "ui_store_lineup_mugshot_01" )
vint_set_property( Character_image_mask_h, "visible", false )
store_character_line_up_is_loaded()
--store_character_select_set_grid_highlight( 0 )
end
function store_character_select_close()
-- Unscubscribe from inputs...
Character_select_input_tracker:subscribe(false)
--play loading animation...
--local loading_anim_h = vint_object_find("loading_anim")
--lua_play_anim(loading_anim_h)
--delay while we we transition out...
delay(.25)
store_character_select_unload_pegs()
thread_yield()
--Load pause map on callback we will do the final exit and transition out as planned.
game_peg_load_with_cb("store_character_select_close_final", 1, "ui_map_world_city")
end
function store_character_select_unload_pegs()
game_peg_unload( Zinyak_image_string )
for i = 1, 9 do
game_peg_unload( "ui_store_lineup_mugshot_0"..i )
end
if Store_character_select_unload_img ~= nil then
game_peg_unload( Store_character_select_unload_img )
end
if Store_character_select_loading_img ~= nil then
game_peg_unload( Store_character_select_loading_img )
end
game_peg_unload( "ui_store_lineup_mugshot_01" )
end
function store_character_select_close_final()
end
function store_character_select_nothing()
end
function store_character_select_cleanup()
store_character_select_unload_pegs()
end
-------------------------------------------------------------------------------
-- Called by C++ via data responder
--
-- cash_from_bank how much the bank is paying the player
-- player_cash how much cash the player has before withdrawl
-- daily_cash how much cash the player earns per day...
-- transfer_cap How much cash the bank can max out on.
-------------------------------------------------------------------------------
function store_character_select_populate(cash_from_bank, player_cash, daily_cash, transfer_cap, next_transfer_percent)
end
-------------------------------------------------------------------------------
-- Process input
-------------------------------------------------------------------------------
function store_character_select_button_a()
store_character_lineup_select()
end
function store_character_select_nav_up(event, acceleration)
store_character_select_set_grid_highlight(-2)
end
function store_character_select_nav_down(event, acceleration)
store_character_select_set_grid_highlight(2)
end
function store_character_select_nav_left(event, acceleration)
store_character_select_set_grid_highlight(-1)
end
function store_character_select_nav_right(event, acceleration)
store_character_select_set_grid_highlight(1)
end
function store_character_select_set_grid_highlight(direction)
local x ,y = vint_get_property(Grid_highlight_h, "anchor")
if direction == 1 then
-- RIGHT
x = x + TILE_WIDTH
Grid_col_idx = Grid_col_idx + 1
elseif direction == -1 then
-- LEFT
x = x - TILE_WIDTH
Grid_col_idx = Grid_col_idx - 1
elseif direction == 2 then
-- DOWN
y = y + TILE_HEIGHT
Grid_row_idx = Grid_row_idx + 1
elseif direction == -2 then
-- UP
y = y - TILE_HEIGHT
Grid_row_idx = Grid_row_idx - 1
else
x = 0
Grid_col_idx = 1
y = 0
Grid_row_idx = 1
end
--check the limits
if x > Grid_max_width then
x = 0
Grid_col_idx = 1
end
if x < 0 then
x = Grid_max_width
Grid_col_idx = Grid_width
end
if y > Grid_max_height then
y = 0
Grid_row_idx = 1
end
if y < 0 then
y = Grid_max_height
Grid_row_idx = Grid_height
end
vint_set_property( Grid_highlight_h, "anchor", x, y )
vint_set_property( Grid_glow_h, "anchor", x, y )
for x = 1, 3 do
for y = 1, 3 do
vint_set_property( Grid_data[ x ][ y ].handle, "scale", 0.9, 0.9 )
vint_set_property( Grid_data[ x ][ y ].handle, "tint", 80/255, 80/255, 80/255 )
end
end
Character_select_image_idx = ( Grid_row_idx - 1 ) * Grid_width + Grid_col_idx
vint_set_property( Grid_data[ Grid_row_idx ][ Grid_col_idx ].handle, "scale", 1.0, 1.0 )
vint_set_property( Grid_data[ Grid_row_idx ][ Grid_col_idx ].handle, "tint", 1.0, 1.0, 1.0 )
vint_set_property( Character_image_h, "visible", false )
local player_flash_h = vint_object_find( "player_flash" )
vint_set_property( player_flash_h, "visible", false )
if Character_select_image_idx == 9 then
store_character_select_show_text( "LINEUP_DOWNLOAD_CHARACTER", "LINEUP_DOWNLOAD_CHARACTER_DESC", true )
else
store_character_select_show_text( nil, nil, false )
end
if Store_character_select_loading_img == nil then
local new_image = Grid_data[ Grid_row_idx ][ Grid_col_idx ].image
--local Store_character_select_current_img = vint_get_property( Character_image_h, "image_crc" )
if Store_character_select_current_img ~= nil then
game_peg_unload( Store_character_select_current_img )
end
if new_image ~= nil then
-- must set Store_character_select_loading_img before calling game_peg_load_with_cb(), which could fire the callback right away
Store_character_select_loading_img = new_image
game_peg_load_with_cb( "store_character_select_show_image", 1, new_image )
end
end
end
-- Called in a thread to delay the image updating.
-- This is done for 2 reasons: to slow down rapid scrolling updates done too quickly,
-- and because the streaming system didn't always co-operate with the images being released
-- from the callback context that was executed when another stream load completed.
--
function store_character_select_image_update()
delay( 0.2 )
game_peg_unload( Store_character_select_unload_img )
game_peg_load_with_cb( "store_character_select_show_image", 1, Store_character_select_loading_img )
Store_character_select_img_update_thread = -1
end
-- Callback for when an image is done loading.
-- SEH: It might make sense to roll this into vdo_bitmap_viewer...
--
function store_character_select_show_image()
local new_image = Grid_data[ Grid_row_idx ][ Grid_col_idx ].image
if Store_character_select_loading_img == new_image then
vint_set_property( Character_image_h, "image", new_image )
vint_set_property( Character_image_h, "visible", true )
vint_set_property( Character_image_mask_h, "image", new_image )
vint_set_property( Character_image_mask_h, "visible", true )
if Store_character_select_current_img ~= new_image then
local player_flash_h = vint_object_find( "player_flash", 0, Character_select_doc_h )
vint_set_property( player_flash_h, "visible", true )
local player_anim_h = vint_object_find( "player_anim", 0, Character_select_doc_h )
lua_play_anim( player_anim_h, 0, Character_select_doc_h )
end
Store_character_select_current_img = new_image
Store_character_select_loading_img = nil
else
-- a new image was picked while we were loading - load this now, and unload the one we just loaded
if new_image ~= nil then
Store_character_select_unload_img = Store_character_select_loading_img
Store_character_select_loading_img = new_image
Store_character_select_img_update_thread = thread_new( "store_character_select_image_update" )
else
game_peg_unload( Store_character_select_loading_img )
Store_character_select_loading_img = nil
end
end
end
function store_character_select_show_screen()
vint_set_property( Character_select_screen_grp_h, "alpha", 1.0 )
end
function store_character_select_hide_screen()
vint_set_property( Character_select_screen_grp_h, "alpha", 0 )
end
function store_character_select_get_index()
return Character_select_image_idx
end
function store_character_select_lock_input()
Character_select_input_tracker:subscribe( false )
end
function store_character_select_unlock_input()
Character_select_input_tracker:subscribe( true )
end
function store_character_select_play_intro()
local char_sel_in_anim_h = vint_object_find( "char_sel_in_anim", 0, Character_select_doc_h )
local end_tween_h = vint_object_find( "char_in_last_tween", char_sel_in_anim_h )
vint_set_property( end_tween_h, "end_event", "store_character_select_anim_in_done" )
lua_play_anim( char_sel_in_anim_h, 0, Character_select_doc_h )
if Character_select_mouse_input_tracker ~= nil then
Character_select_mouse_input_tracker:subscribe(true)
end
end
function store_character_select_play_outro()
--local char_sel_in_anim_h = vint_object_find( "char_sel_in_anim", 0, Character_select_doc_h )
lua_play_anim( Character_select_out_anim_h, 0, Character_select_doc_h )
vint_apply_start_values( Character_select_out_anim_h )
if Character_select_mouse_input_tracker ~= nil then
Character_select_mouse_input_tracker:subscribe(false)
end
end
function store_character_select_anim_in_done()
Store_character_select_anim_done = true
store_character_select_unlock_input()
end
function store_character_select_show_text( title, desc, is_visible )
local title_txt_h = vint_object_find( "title_txt_1", 0, Character_select_doc_h )
local desc_txt_h = vint_object_find( "desc_txt", 0, Character_select_doc_h )
if title ~= nil then
vint_set_property( title_txt_h, "text_tag", title )
end
if desc ~= nil then
vint_set_property( desc_txt_h, "text_tag", desc )
end
vint_set_property( title_txt_h, "visible", is_visible )
vint_set_property( desc_txt_h, "visible", is_visible )
end
function store_character_select_set_player_name( new_name )
local player_name_h = vint_object_find( "label_name" )
vint_set_property( player_name_h, "text_tag", new_name )
if vint_is_std_res() then
--resize player name to fit
vint_set_property( player_name_h, "scale", 1, 1 )
local MAX_WIDTH_TITLE = 265
local text_width_label, text_height_label = element_get_actual_size( player_name_h )
if text_width_label > MAX_WIDTH_TITLE then
local text_scale_label = MAX_WIDTH_TITLE/text_width_label
vint_set_property( player_name_h, "scale", text_scale_label, 1 )
end
end
end
-- =====================================
-- Mouse Specific Functions
-- =====================================
function store_character_select_mouse_click( event, target_handle )
store_character_lineup_select(event)
end
function store_character_select_mouse_move(event, target_handle)
for x = 1, 3 do
for y = 1, 3 do
vint_set_property( Grid_data[ x ][ y ].handle, "scale", 0.9, 0.9 )
vint_set_property( Grid_data[ x ][ y ].handle, "tint", 80/255, 80/255, 80/255 )
if Grid_data[ x ][ y ].handle == target_handle then
Grid_row_idx = x
Grid_col_idx = y
end
end
end
Character_select_image_idx = ( Grid_row_idx - 1 ) * Grid_width + Grid_col_idx
vint_set_property( Grid_data[ Grid_row_idx ][ Grid_col_idx ].handle, "scale", 1.0, 1.0 )
vint_set_property( Grid_data[ Grid_row_idx ][ Grid_col_idx ].handle, "tint", 1.0, 1.0, 1.0 )
local cell_x, cell_y = vint_get_property( Grid_data[ Grid_row_idx ][ Grid_col_idx ].handle, "anchor" )
cell_x = cell_x - 64
cell_y = cell_y - 64
vint_set_property( Grid_highlight_h, "anchor", cell_x, cell_y )
vint_set_property( Grid_glow_h, "anchor", cell_x, cell_y )
vint_set_property( Character_image_h, "visible", false )
local player_flash_h = vint_object_find( "player_flash", 0, Character_select_doc_h )
vint_set_property( player_flash_h, "visible", false )
if Character_select_image_idx == 9 then
store_character_select_show_text( "LINEUP_DOWNLOAD_CHARACTER", "LINEUP_DOWNLOAD_CHARACTER_DESC", true )
else
store_character_select_show_text( nil, nil, false )
end
if Store_character_select_loading_img == nil then
local new_image = Grid_data[ Grid_row_idx ][ Grid_col_idx ].image
if Store_character_select_current_img ~= nil then
game_peg_unload( Store_character_select_current_img )
end
if new_image ~= nil then
-- must set Store_character_select_loading_img before calling game_peg_load_with_cb(), which could fire the callback right away
Store_character_select_loading_img = new_image
game_peg_load_with_cb( "store_character_select_show_image", 1, new_image )
end
end
end