local SCREEN_FADE_STYLE_LEFT_TO_RIGHT = 0
local SCREEN_FADE_STYLE_ALPHA = 1
local SCREEN_FADE_TYPE_IN = 0
local SCREEN_FADE_TYPE_OUT = 1
local SCREEN_FADE_DEFAULT_DURATION = 1000 -- only used for classic in out fades..
local SCREEN_FADE_LEFT = 1
local SCREEN_FADE_RIGHT = -1
local Screen_fade_doc_handle = -1
local Screen_fade_state = -1 --The state of the last called fade...
local Screen_fades = {
[SCREEN_FADE_STYLE_LEFT_TO_RIGHT] = {
[SCREEN_FADE_TYPE_OUT] = {
anim_name = "left_to_right_black_anim",
grp_name = "screen_left_to_right_grp",
},
[SCREEN_FADE_TYPE_IN] = {
anim_name = "left_to_right_none_anim",
grp_name = "screen_left_to_right_grp",
},
},
[SCREEN_FADE_STYLE_ALPHA] = {
[SCREEN_FADE_TYPE_OUT] = {
anim_name = "fade_none_to_black_anim",
grp_name = "screen_fade_grp"
},
[SCREEN_FADE_TYPE_IN] = {
anim_name = "fade_black_to_none_anim",
grp_name = "screen_fade_grp"
},
},
}
local Screen_fade_logo_is_visible = false -- determines if our logo is visible or not.
local Screen_fade_images_is_visible = false -- deterimes if our images are visible or not...
local Screen_fade_images_grp_h = 0
local Screen_fade_images_trans_anim_h = 0
local Screen_fade_images_fade_anim_h = 0
local Screen_fade_images_fade_twn_h = 0
--Screen fade images globals...
Screen_fade_images = {
"ui_mainmenu_load_06",
"ui_mainmenu_load_07",
"ui_mainmenu_load_08",
"ui_mainmenu_load_09",
"ui_mainmenu_load_10",
"ui_mainmenu_load_11",
}
Screen_fade_image_1_h = 0
Screen_fade_image_2_h = 0
Screen_fade_loaded_images = {}
Screen_fade_use_load_images = false
Screen_fade_autosave_grp_h = 0
Screen_fade_autosave_grp_x, Screen_fade_autosave_grp_y = 0, 0
Screen_fade_hide_ref_count = 0
local Screen_fade_force_white_load = false
function screen_fade_init()
Screen_fade_doc_handle = vint_document_find("screen_fade")
--Hide all groups
local safe_frame_h = vint_object_find("screen_grp")
vint_hide_children(safe_frame_h)
--Setup tween callbacks....
local tween_names_for_cb = {
"left_to_right_black_twn",
"fade_black_to_none_twn",
"fade_none_to_black_twn",
"left_to_right_none_twn",
}
for idx, val in pairs(tween_names_for_cb) do
local h = vint_object_find(val)
vint_set_property(h, "end_event", "screen_fade_complete_cb")
end
--hide loading
local loading_grp_h = vint_object_find("loading_grp")
local mem_loading_grp_h = vint_object_find("mem_loading_grp")
vint_set_property(loading_grp_h, "alpha", 0)
vint_set_property(mem_loading_grp_h, "alpha", 0)
local loading_fade_out_twn_h = vint_object_find("loading_fade_out_twn")
vint_set_property(loading_fade_out_twn_h, "end_event", "screen_fade_logo_out_cb")
--loop animation that plays over everythinng...
--local loading_anim_h = vint_object_find("loading_anim")
--local loading_twn_h = vint_object_find("loading_twn", loading_anim_h)
--vint_set_property(loading_twn_h, "end_event", "vint_anim_loop_callback")
--Initialize Image Stuff
screen_fade_images_init()
--Initialize auto save text...
screen_fade_auto_save_init()
--Hide auto save by default
screen_fade_auto_save_hide()
end
function screen_fade_cleanup()
screen_fade_images_cleanup()
end
-------------------------------------------------------------------------------
-- Fades the screen. This should be called directly from c++
-- @param style style of fade(left to right, right to left, fade) SCREEN_FADE_STYLE_LEFT_TO_RIGHT, SCREEN_FADE_STYLE_RIGHT_TO_LEFT, SCREEN_FADE_STYLE_ALPHA)
-- @param type In or out? out = show black, in = show what is behind. (SCREEN_FADE_TYPE_IN, SCREEN_FADE_TYPE_OUT)
-- @param duration only for SCREEN_FADE_STYLE_ALPHA stuff. defaults to .25 seconds. Units passed in are in milleseconds.
-------------------------------------------------------------------------------
function screen_fade_do(style, type, duration, special_type, red, green, blue, fade_silently)
-- Force Hide all groups
if red == 1 and green == 1 and blue == 1 then
Screen_fade_force_white_load = true
special_type = 1
else
Screen_fade_force_white_load = false
end
local _red = 0
if red ~= nil then
_red = red
end
local _green = 0
if green ~= nil then
_green = green
end
local _blue = 0
if blue ~= nil then
_blue = blue
end
local safe_frame_h = vint_object_find("screen_grp")
vint_hide_children(safe_frame_h)
if fade_silently == false then
if type == SCREEN_FADE_TYPE_IN then
game_audio_play( "ui_screen_trans_in" )
elseif type == SCREEN_FADE_TYPE_OUT then
game_audio_play( "ui_screen_trans_out" )
end
end
-- Force Pause all animations...
for key, val in pairs(Screen_fades) do
for k, v in pairs(val) do
local anim_h = vint_object_find(v.anim_name)
vint_set_property(anim_h, "is_paused", true)
end
end
local screen_fade_data = Screen_fades[style][type]
if screen_fade_data == nil then
return
end
-- Normal screen fades can accept a duration...
if style == SCREEN_FADE_STYLE_ALPHA then
local fade_1_h = vint_object_find("fade_black_to_none_twn")
local fade_2_h = vint_object_find("fade_none_to_black_twn")
if duration == nil or duration < 0 then
duration = SCREEN_FADE_DEFAULT_DURATION
end
-- convert to seconds
duration = duration * 0.001
vint_set_property(fade_1_h, "duration", duration)
vint_set_property(fade_2_h, "duration", duration)
end
--check to see if we need to hide the logo
if Screen_fade_logo_is_visible and type == SCREEN_FADE_TYPE_IN then
screen_fade_logo_hide()
end
local fade_out_delay = 0
if Screen_fade_images_is_visible and type == SCREEN_FADE_TYPE_IN then
--fade_out_delay = 1
screen_fade_images_hide()
end
local anim_h = vint_object_find(screen_fade_data.anim_name)
local grp_h = vint_object_find(screen_fade_data.grp_name)
vint_set_property(grp_h, "visible", true)
--if memory then straight fade to white instead of black
--local special_type = 1
local black_fade_h = vint_object_find("black_fade")
if special_type == 1 then
vint_set_property(black_fade_h, "tint", 220/255,220/255,220/255)
else
vint_set_property(black_fade_h, "tint", _red, _green, _blue)
end
lua_play_anim(anim_h, fade_out_delay)
--hide white bg once fade in starts
if type == SCREEN_FADE_TYPE_IN then
local mem_white_bg_h = vint_object_find("mem_white_bg")
local mem_loading_grp_h = vint_object_find("mem_loading_grp")
vint_set_property(mem_white_bg_h, "alpha", 0)
vint_set_property(mem_loading_grp_h, "alpha", 0)
end
Screen_fade_state = type
end
--This is called when the transition is finished
function screen_fade_complete_cb(tween_h)
--Let C know we are done fading out the screen...
Screen_fade_transition_complete()
--If we are fading back into game hide the bitmaps...
if Screen_fade_state == SCREEN_FADE_TYPE_IN then
-- Force Hide all groups
local safe_frame_h = vint_object_find("screen_grp")
vint_hide_children(safe_frame_h)
end
end
-------------------------------------------------------------------------------
-- C determines if we are going to show a logo during this transition...
--
function screen_fade_logo_show(special_type)
if Screen_fade_force_white_load == true then
special_type = 1
Screen_fade_force_white_load = false
end
if Screen_fade_state == SCREEN_FADE_TYPE_IN then
--Do not show the logo if we are faded in...
return
end
local loading_pulse_anim_h = -1
local loading_pulse_twn_h = -1
local loading_fade_in_anim_h = -1
--Check if its a memory fade
--1 = Memory Fade
if special_type == 1 then
loading_fade_in_anim_h = vint_object_find("mem_loading_fade_in_anim")
else
loading_pulse_anim_h = vint_object_find("loading_pulse_anim")
loading_fade_in_anim_h = vint_object_find("loading_fade_in_anim")
lua_play_anim(loading_pulse_anim_h)
end
--Play fade out of logo
local loading_fade_out_anim_h = vint_object_find("loading_fade_out_anim")
vint_set_property(loading_fade_out_anim_h, "is_paused", true)
--Fade in logo
lua_play_anim(loading_fade_in_anim_h)
Screen_fade_logo_is_visible = true
end
-------------------------------------------------------------------------------
-- This is called to fade out the logo...
--
function screen_fade_logo_hide()
--Check if its a memory fade
local loading_fade_in_anim_h = vint_object_find("loading_fade_in_anim")
local mem_loading_fade_in_anim_h = vint_object_find("mem_loading_fade_in_anim")
local loading_fade_out_anim_h = vint_object_find("loading_fade_out_anim")
-- Pause fade in of logo...
vint_set_property(loading_fade_in_anim_h, "is_paused", true)
vint_set_property(mem_loading_fade_in_anim_h, "is_paused", true)
--Play fade out of logo
lua_play_anim(loading_fade_out_anim_h)
end
--------------------------------------------------------------------------------
-- Called when logo is completely faded out
--
function screen_fade_logo_out_cb()
--Start highlight on logo...
--local loading_anim_h = vint_object_find("loading_anim")
--vint_set_property(loading_anim_h, "is_paused", true)
--Pulse center of logo...
local loading_pulse_anim_h = vint_object_find("loading_pulse_anim")
local mem_loading_pulse_anim_h = vint_object_find("mem_loading_pulse_anim")
vint_set_property(loading_pulse_anim_h, "is_paused", true)
vint_set_property(mem_loading_pulse_anim_h, "is_paused", true)
Screen_fade_logo_is_visible = false
end
--------------------------------------------------------------------------------
-- Shows "Saving..." text and displays rotating spinner
--
function screen_fade_auto_save_show()
vint_set_property(Screen_fade_autosave_grp_h, "visible", true)
local autosave_loop_anim_h = vint_object_find("autosave_loop_anim")
lua_play_anim(autosave_loop_anim_h)
local hud_doc_h = vint_document_find("hud")
local move_y = 0
if hud_doc_h ~= 0 and Hud_gsi ~= -1 then
--check if hud gsi is active
if Hud_gsi:is_active_get() then
--Move it
local width, height = Hud_gsi:get_size()
move_y = Screen_fade_autosave_grp_y + height + 5
end
end
screen_fade_auto_save_move(move_y)
end
--------------------------------------------------------------------------------
-- Hides "Saving..." text
--
function screen_fade_auto_save_hide()
local autosave_grp_h = vint_object_find("autosave_grp")
vint_set_property(autosave_grp_h, "visible", false)
local autosave_loop_anim_h = vint_object_find("autosave_loop_anim")
vint_set_property(autosave_loop_anim_h, "is_paused", true)
end
-------------------------------------------------------------------------------
-- Initialize screen fades
-- Setup text boxes
--
function screen_fade_auto_save_init()
Screen_fade_autosave_grp_h = vint_object_find("autosave_grp")
local saving_content_text_1_h = vint_object_find("saving_content_text_1")
local saving_content_bg_h = vint_object_find("saving_content_bg")
vint_set_property(saving_content_text_1_h, "text_tag", "SAVE_WARNING_GAME") --Saving Content
local bg_width, bg_height = element_get_actual_size(saving_content_bg_h)
local text_1_width, text_1_height = element_get_actual_size(saving_content_text_1_h)
local text_1_x, text_1_y = vint_get_property(saving_content_text_1_h, "anchor")
local BG_PADDING = 10
local max_width = 340
if text_1_width > max_width then
local scale = max_width / text_1_width
vint_set_property(saving_content_text_1_h, "scale", scale, scale)
end
local text_1_width, text_1_height = element_get_actual_size(saving_content_text_1_h)
bg_width = text_1_x + text_1_width + BG_PADDING
element_set_actual_size(saving_content_bg_h, bg_width, bg_height)
Screen_fade_autosave_grp_x, Screen_fade_autosave_grp_y = vint_get_property(Screen_fade_autosave_grp_h, "anchor")
end
function screen_fade_auto_save_move(y_position)
if y_position ~= 0 then
vint_set_property(Screen_fade_autosave_grp_h, "anchor", Screen_fade_autosave_grp_x, y_position)
else
vint_set_property(Screen_fade_autosave_grp_h, "anchor", Screen_fade_autosave_grp_x, Screen_fade_autosave_grp_y)
end
end
-------------------------------------------------------------------------------
-- Initialize screen fade images (called from init)
--
function screen_fade_images_init()
Screen_fade_images_grp_h = vint_object_find("images_grp")
Screen_fade_images_fade_anim_h = vint_object_find("images_fade_anim")
Screen_fade_images_fade_twn_h = vint_object_find("images_fade_twn", Screen_fade_images_fade_anim_h)
Screen_fade_images_trans_anim_h = vint_object_find("images_transition_anim")
--Setup callback for fading in/out
vint_set_property(Screen_fade_images_fade_twn_h, "end_event", "screen_fade_images_fade_cb")
--Set up loop for images...
local bmp1_fade_in_twn_h = vint_object_find("bmp1_fade_in_twn", Screen_fade_images_trans_anim_h)
vint_set_property(bmp1_fade_in_twn_h, "end_event", "vint_anim_loop_callback")
--Hide images...
vint_set_property(Screen_fade_images_grp_h, "alpha", 0)
--Store paths to images...
Screen_fade_image_1_h = vint_object_find("bmp1", Screen_fade_images_grp_h)
Screen_fade_image_2_h = vint_object_find("bmp2", Screen_fade_images_grp_h)
if sfx_use_load_images() then
local loading_images = {}
local random_num_values = {}
local random_num_count = 1
local screen_fade_images_num = #Screen_fade_images
while #random_num_values < 2 do
local found_match = false
local random_num = rand_int(1, screen_fade_images_num)
for i = 1, 3 do
if random_num == random_num_values[i] then
found_match = true
end
end
if found_match == false then
random_num_values[random_num_count] = random_num
random_num_count = random_num_count + 1
end
end
local platform_file_ext = ""
if game_get_platform() == "PC" then
platform_file_ext = "_pc"
elseif game_get_platform() == "XBOX3" then
platform_file_ext = "_xbox3"
elseif game_get_platform() == "PS4" then
platform_file_ext = "_ps4"
end
for i = 1, #random_num_values do
loading_images[i] = Screen_fade_images[random_num_values[i]] .. platform_file_ext
end
Screen_fade_loaded_images = loading_images
game_peg_load_with_cb("screen_fade_images_loaded", 2, loading_images[1], loading_images[2])
Screen_fade_use_load_images = true
end
end
-------------------------------------------------------------------------------
-- Cleanup any loaded images... (called from cleanup)
--
function screen_fade_images_cleanup()
if Screen_fade_use_load_images then
--Free up memory...
for i, v in pairs(Screen_fade_loaded_images) do
game_peg_unload(v)
end
Screen_fade_loaded_images = {}
end
end
-------------------------------------------------------------------------------
-- Shows the screen fade images... (called from c++)
--
function screen_fade_images_show()
--Fade in group based and fade it in with transition animation...
local images_alpha = vint_get_property(Screen_fade_images_grp_h, "alpha")
vint_set_property(Screen_fade_images_fade_twn_h, "start_value", images_alpha)
vint_set_property(Screen_fade_images_fade_twn_h, "end_value", 1)
local screenshot_anim_h = vint_object_find("screenshot_anim")
--Apply start values of animations
vint_apply_start_values(Screen_fade_images_fade_anim_h)
vint_apply_start_values(Screen_fade_images_trans_anim_h)
--Start animations
lua_play_anim(Screen_fade_images_fade_anim_h)
vint_set_property(Screen_fade_images_grp_h, "alpha", 1)
lua_play_anim(Screen_fade_images_trans_anim_h)
lua_play_anim(screenshot_anim_h)
Screen_fade_images_is_visible = true
end
-------------------------------------------------------------------------------
-- Hides the screen fade images... (called from c++)
--
function screen_fade_images_hide()
--Fade in group based and fade it in with transition animation...
local images_alpha = vint_get_property(Screen_fade_images_grp_h, "alpha")
vint_set_property(Screen_fade_images_fade_twn_h, "start_value", images_alpha)
vint_set_property(Screen_fade_images_fade_twn_h, "end_value", 0)
--lua_play_anim(Screen_fade_images_fade_anim_h)
vint_set_property(Screen_fade_images_grp_h, "alpha", 0)
Screen_fade_images_is_visible = false
--vint_set_property(Screen_fade_images_fade_anim_h, "is_paused", true)
end
-------------------------------------------------------------------------------
-- Sets screen background to render in the background or foreground (called from C++)
--
function screen_fade_set_to_background(is_background)
local base_grp_h = vint_object_find("base_grp")
vint_set_property(base_grp_h, "background", is_background)
end
-------------------------------------------------------------------------------
-- Callback for when the images are done fading...
--
function screen_fade_images_fade_cb()
if Screen_fade_images_is_visible == false then
--stop transition animation if we are paused...
vint_set_property(Screen_fade_images_trans_anim_h, "is_paused", true)
end
end
-------------------------------------------------------------------------------
-- Callabck to set the images that are loaded
--
function screen_fade_images_loaded()
--Replace image names with loaded images
vint_set_property(Screen_fade_image_1_h, "image", Screen_fade_loaded_images[1])
vint_set_property(Screen_fade_image_2_h, "image", Screen_fade_loaded_images[2])
end
-------------------------------------------------------------------------------
-- These are test functions to test the fades...
-------------------------------------------------------------------------------
function screen_fade_1()
screen_fade_do(SCREEN_FADE_STYLE_LEFT_TO_RIGHT, SCREEN_FADE_TYPE_IN)
end
function screen_fade_2()
screen_fade_do(SCREEN_FADE_STYLE_LEFT_TO_RIGHT, SCREEN_FADE_TYPE_OUT)
end
function screen_fade_3()
screen_fade_do(SCREEN_FADE_STYLE_ALPHA, SCREEN_FADE_TYPE_IN)
end
function screen_fade_4()
screen_fade_do(SCREEN_FADE_STYLE_ALPHA, SCREEN_FADE_TYPE_OUT)
end
function screen_fade_5()
screen_fade_do(SCREEN_FADE_STYLE_ALPHA, SCREEN_FADE_TYPE_IN, 5000)
end
function screen_fade_6()
screen_fade_do(SCREEN_FADE_STYLE_ALPHA, SCREEN_FADE_TYPE_OUT, 5000)
end
function screen_fade_hide()
if Screen_fade_hide_ref_count == 0 then
local d = vint_document_find( "screen_fade" )
local h = vint_object_find( "safe_frame", nil, d )
vint_set_property( h, "visible", false )
end
Screen_fade_hide_ref_count = Screen_fade_hide_ref_count + 1
end
function screen_fade_unhide()
if Screen_fade_hide_ref_count < 1 then
assert_msg( false, "screen_fade_unhide(): ref count is already 0" )
return
end
if Screen_fade_hide_ref_count == 1 then
local d = vint_document_find( "screen_fade" )
local h = vint_object_find( "safe_frame", nil, d )
vint_set_property( h, "visible", true )
end
Screen_fade_hide_ref_count = Screen_fade_hide_ref_count - 1
end
--[[ ---------------------------------------------------------------------
-- Function - screen_fade_reset
-- Description - called whenever the screen is reset
-- Parameters - none
-- Returns - nil
]]-- ---------------------------------------------------------------------
function screen_fade_reset()
if game_get_platform() == "PC" then
if vint_is_std_res() then
vint_set_property(Screen_fade_autosave_grp_h, "anchor", 48, 36)
Screen_fade_autosave_grp_x = 48
Screen_fade_autosave_grp_y = 36
vint_set_property(Screen_fade_autosave_grp_h, "scale", 0.667, 0.667)
else
vint_set_property(Screen_fade_autosave_grp_h, "anchor", 96, 54)
Screen_fade_autosave_grp_x = 96
Screen_fade_autosave_grp_y = 54
vint_set_property(Screen_fade_autosave_grp_h, "scale", 1, 1)
end
end
end