-------------------------------------------------------------------------------
--Constants
-------------------------------------------------------------------------------
CMP_TEST_MODE = false --Modes for testing...
CMP_TEST_NO_MULTIPLIER = false
--LUT tables...
CMP_LUT_DEFAULT = "none"
CMP_LUT_MISSION = "lut_completion_screen"
--Screen Layout
CMP_SCREEN_LAYOUT_LEFT = 0
CMP_SCREEN_LAYOUT_RIGHT = 1
--Screen types...
CMP_SCREEN_TITLE_INDEX = 1
CMP_SCREEN_CASH_INDEX = 2
CMP_SCREEN_RESPECT_INDEX = 3
CMP_SCREEN_CONTROL_INDEX = 4
CMP_SCREEN_REWARD_INDEX = 5
CMP_SCREEN_COOP_WAIT_INDEX = 6
--Respect Constants...
local RESPECT_START_ANGLE = 2.51
local RESPECT_END_ANGLE = 2.65 -- This is really negative, but entering as positive to make equation work
local RESPECT_METER_UPDATE = 0
local RESPECT_METER_UPDATE_BONUS = 1
local RESPECT_METER_UPDATE_NO_BONUS = 2
-- District Control Constants...
local CONTROL_START_ANGLE = 2.43
local CONTROL_END_ANGLE = 2.27000 -- This is really negative, but entering as positive to make equation work
local RESPECT_METER_UPDATE = 0
local RESPECT_METER_UPDATE_BONUS = 1
local RESPECT_METER_UPDATE_NO_BONUS = 2
-- Cash/Respect Ramp Constants for Animation and Audio...
local CMP_TIME_CASH = 1166 -- 23 frames (766)
local CMP_TIME_CASH_BONUS = 1100 -- 1 sec 3 frames?
local CMP_TIME_CASH_NO_BONUS = 2560 -- 2 sec 9 frames?
local CMP_TIME_RESPECT = 1766 * .001 -- 1 sec 22 frames (1733)
local CMP_TIME_RESPECT_BONUS = 1580 * .001 -- 1 sec 14 frames (1733)
local CMP_TIME_RESPECT_NO_BONUS = 3433 * .001 -- 3 sec 13 frames (3433)
local CMP_TIME_CONTROL = 1580 * .001 -- 1 sec 22 frames (1733)
local CMP_COLOR_TEXT_PURPLE = {R=148/255, G=0/255, B=197/255}
local CMP_COLOR_TEXT_WHITE = {R=220/255, G=220/255, B=220/255}
local CMP_COLOR_TEXT_WHITE_2 = {R=180/255, G=180/255, B=180/255}
-------------------------------------------------------------------------------
-- Globals
-------------------------------------------------------------------------------
Cmp_screen_idx = 0 --Index of the current screen
Cmp_screen_sequence_started = false -- Bool determines if we have started the screen...
Cmp_screen_is_playing = false --Bool determines whether the current screen is in an animation state.
Cmp_screen_base_x = 0 -- Base position x
Cmp_screen_base_y = 0 -- Base position Y
Cmp_common_doc = -1 -- Handle of common document
Cmp_specific_doc = -1 -- Handle of specific completion screen doc(mission, activity, stronghold)
Cmp_image = 0 -- Used to store reference to loaded image for any completion screen format.
Cmp_common_has_image = false -- Used to determine if we have an image or not (cannot use the name because of the way we load the image)
Cmp_common_image_is_visible = true --Used to determine if the completion image is visible or so we don't fade it out twice...
Cmp_common_bg_saints_active = false --used to determine if bg saints is active or not...
Cmp_Input_tracker = -1
local Cmp_mouse_input_tracker
local Cmp_bg_image
Cmp_common_input_is_blocked = true
Cmp_common_input_delay_thread = -1
Cmp_common_coop_dialog_handle = 0 --coop dialog for exiting early...
Cmp_sequence_data = -1 --Data reference for screen, this is set through cmp_common_screen_set_data().
Cmp_hintbar = -1 --Global for the Hintbar VDO used on all the screens.
Cmp_common_audio_ramp_id = -1 --Reference to audio ramp
Cmp_common_audio_music_id = -1 --Reference to completion screen music...
--Stars
local Cmp_stars = {
[1] = "star_01",
[2] = "star_02",
[3] = "star_03",
[4] = "star_04",
[5] = "star_05",
[6] = "star_06",
[7] = "star_07",
[8] = "star_08",
[9] = "star_09",
[10] = "star_10",
[11] = "star_11",
[12] = "star_12",
}
--Cash count
Cmp_screen_cash_start = 0 --When the cash count starts this the starting value...
Cmp_screen_cash_end = 0 --When the cash count ends this is the ending value...
Cmp_screen_cash_total = 0 --The total amount of cash earned...
Cmp_screen_cash_skip_bonus = false --Determines whether or not we skip the multiplier stage...
Cmp_screen_cash_count_is_bonus = false --Determines whether we are doing the bonus stage or not...
Cmp_screen_cash_skip = 0 --Determines if the cash screen should be skipped
Cmp_common_cash_complete_cb = 0 --Callback for function after cash is completed...
--Respect
Cmp_screen_respect_queue = {}
Cmp_screen_respect_level_dif = 0 --Difference to the next level, this gets decremented every fill.
Cmp_screen_respect_target_pct = 0 --Target percentage for final fill, this is what the meter is set to after the last full fill.
Cmp_screen_respect_time_start = 0 --This is the fill time for the percent part of the meter....
Cmp_screen_respect_time_mid = 0
Cmp_screen_respect_time_end = 0
Cmp_screen_respect_level_cur = 0 --This is the current level of the respect, we will increment manually this every time the meter fills up...
Cmp_screen_respect_skip_bonus = false --Determines whether or not we skip the multiplier stage...
--Coop
Cmp_screen_coop_is_waiting = false --Determines whether or not we are on the coop waiting screen.
Cmp_screen_coop_gamer_tag = "PLAYER" --Coop gamer tag... this should get updated by c++ in cmp_common_coop_wait_start()
local continue_hint_data = {
{CTRL_MENU_BUTTON_A, "COMPLETION_CONTINUE"},
}
local coop_hint_data = {
{CTRL_MENU_BUTTON_BACK, "COMPLETION_COOP_DISCONNECT"},
}
function cmp_common_init()
--Set common doc global...
Cmp_common_doc = vint_document_find("cmp_common")
local h = vint_object_find("screen_grp")
Cmp_screen_base_x, Cmp_screen_base_y = vint_get_property(h, "anchor")
--Init Hintbar
Cmp_hintbar = Vdo_hint_bar:new("hint_bar")
Cmp_hintbar:set_hints(continue_hint_data)
Cmp_hintbar:enable_text_shadow(true)
Cmp_hintbar:pulse(1)
Cmp_hintbar:set_alpha(0)
local coop_hintbar = Vdo_hint_bar:new("coop_hint_bar")
coop_hintbar:set_hints(coop_hint_data)
coop_hintbar:enable_text_shadow(true)
--Hide elements
local h = vint_object_find("background_base")
vint_set_property(h, "visible", false)
local h = vint_object_find("title_grp", 0, Cmp_common_doc)
vint_set_property(h, "alpha", 0)
local h = vint_object_find("cash_grp", 0, Cmp_common_doc)
vint_set_property(h, "alpha", 0)
local h = vint_object_find("cash_bonus_txt", 0, Cmp_common_doc)
vint_set_property(h, "alpha", 0)
local h = vint_object_find("respect_grp", 0, Cmp_common_doc)
vint_set_property(h, "alpha", 0)
local h = vint_object_find("control_grp", 0, Cmp_common_doc)
vint_set_property(h, "alpha", 0)
local h = vint_object_find("coop_wait_grp", 0, Cmp_common_doc)
vint_set_property(h, "alpha", 0)
-- Dynamically Replace color on all elements...
local purple_elements = {
"title_txt",
"cash_txt",
"respect_meter",
"respect_txt",
}
local white_elements = {
"complete_txt",
"cash_amount_txt",
"respect_level_text",
}
local white_2_elements = {
"respect_bonus_txt",
"cash_bonus_txt",
}
for idx, val in pairs(purple_elements) do
local h = vint_object_find(val)
vint_set_property(h, "tint", CMP_COLOR_TEXT_PURPLE.R, CMP_COLOR_TEXT_PURPLE.G, CMP_COLOR_TEXT_PURPLE.B)
end
for idx, val in pairs(white_elements) do
local h = vint_object_find(val)
vint_set_property(h, "tint", CMP_COLOR_TEXT_WHITE.R, CMP_COLOR_TEXT_WHITE.G, CMP_COLOR_TEXT_WHITE.B)
end
for idx, val in pairs(white_2_elements) do
local h = vint_object_find(val)
vint_set_property(h, "tint", CMP_COLOR_TEXT_WHITE_2.R, CMP_COLOR_TEXT_WHITE_2.G, CMP_COLOR_TEXT_WHITE_2.B)
end
--bg saints group hide
local bg_saints_grp_h = vint_object_find("bg_saints_grp", 0, Cmp_common_doc)
vint_set_property(bg_saints_grp_h, "alpha", 0)
--Loop BG Saints
local bg_saints_loop_anim_h = vint_object_find("bg_saints_loop_anim", 0, Cmp_common_doc)
lua_play_anim(bg_saints_loop_anim_h)
--Tween Callbacks for ending Screens...
local twn_h = vint_object_find("title_end_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_common_title_end")
local twn_h = vint_object_find("title_in_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_common_title_slam")
--Note: Cash will end on its own because it is run via thread...
--Enable Cash Callback...
cmp_common_cash_callback_enable(true)
--Enable Respect Callback...
cmp_common_respect_cb_enable(true)
--Enable Control Callback...
cmp_common_control_cb_enable(true)
--Enable sound callbacks
cmp_audio_cb_enable()
--Input
Cmp_Input_tracker = Vdo_input_tracker:new()
Cmp_Input_tracker:add_input("select", "cmp_process_input", 50)
Cmp_Input_tracker:add_input("back", "cmp_process_input", 50)
Cmp_Input_tracker:add_input("map", "cmp_process_input", 50)
Cmp_Input_tracker:add_input("pause", "cmp_process_input", 50)
Cmp_Input_tracker:subscribe(false)
if game_get_platform() == "PC" then
Cmp_bg_image = Vdo_base_object:new("background_bmp", 0, Cmp_common_doc)
Cmp_mouse_input_tracker = Vdo_input_tracker:new()
Cmp_mouse_input_tracker:add_mouse_input("mouse_move", "cmp_common_mouse_move", 0, Cmp_bg_image.handle)
Cmp_mouse_input_tracker:add_mouse_input("mouse_click", "cmp_common_mouse_click", 0, Cmp_bg_image.handle)
Cmp_mouse_input_tracker:subscribe(false)
end
vint_dataitem_add_subscription("completion_camera_shake", "update", "cmp_common_camera_shake_update")
end
function cmp_common_cleanup()
--unsubscribe inputs...
if Cmp_Input_tracker ~= nil then
Cmp_Input_tracker:subscribe(false)
end
if Cmp_mouse_input_tracker ~= nil then
Cmp_mouse_input_tracker:subscribe(false)
end
--Unload image if we had one.....
if Cmp_image ~= 0 then
game_peg_unload(Cmp_image)
end
cmp_common_lut_effect(CMP_LUT_DEFAULT)
--Stop music...
game_audio_stop(Cmp_common_audio_music_id)
end
function cmp_common_screen_start(screen_layout)
--Play Intro Animation...(This is screen independant)
local intro_anim_h = vint_object_find("screen_in_anim", 0, Cmp_common_doc)
lua_play_anim(intro_anim_h, 0, Cmp_common_doc)
local use_as_background = true
--determine if we skipped a cutscene or if there is no final screen
local mission_doc_h = vint_document_find("cmp_mission")
local activity_doc_h = vint_document_find("cmp_activity")
local stronghold_doc_h = vint_document_find("cmp_stronghold")
local show_mission_image = false
--check to see if we want to show the image for mission screens...
if mission_doc_h ~= 0 then
--first check if we had an active cutscene...
if completion_cutscene_was_active() then
--now check to see if we skipped the cutscene
if completion_cutscene_was_skipped() then
show_mission_image = true
end
end
if not completion_cutscene_was_active() then
show_mission_image = true
end
--Show black style screen if credits were active...(used in final cutscenes m23_out and m24_out)
if completion_cutscene_was_active() then
if completion_credits_were_active() then
show_mission_image = true
end
end
--Show the image if
if show_mission_image then
--reset screen layout...
screen_layout = CMP_SCREEN_LAYOUT_LEFT
--set image (this is loaded in with cmp_mission)
local image = "ui_cmp_saint"
Cmp_sequence_data[1].image = image
--Set global to image name and set image names to the objects via callback.
Cmp_image = image
cmp_common_image_loaded()
--Clear out the global image name so we don't try to clean it up.
Cmp_image = 0
end
end
--Attemp to activate bg saints...
if activity_doc_h ~= 0 or stronghold_doc_h ~= 0 or show_mission_image == true then
Cmp_common_bg_saints_active = true
cmp_common_bg_saints_show(true)
use_as_background = false
end
if Cmp_sequence_data[1] ~= nil then
if Cmp_sequence_data[1].mission_internal_name == "m06" then
use_as_background = false
end
if Cmp_sequence_data[1].mission_internal_name == "m16" then
if game_get_language() == "NL" then
--resize title for dutch in mission 16
cmp_common_title_resize(.55)
end
end
end
--Show background_base...
local h = vint_object_find("background_base", 0, Cmp_common_doc)
vint_set_property(h, "visible", true)
vint_set_property(h, "background", use_as_background)
--Right Justify screen if needed...
if screen_layout == CMP_SCREEN_LAYOUT_RIGHT then
--Align screen right (screen is default left aligned)
cmp_common_right_justification()
end
-- Advance first screen...
cmp_common_screen_advance(false)
--Set that we have started the sequence...
Cmp_screen_sequence_started = true
-- Unblock input.
Cmp_Input_tracker:subscribe(true)
if Cmp_mouse_input_tracker ~= nil then
Cmp_mouse_input_tracker:subscribe(true)
end
end
function cmp_common_screen_set_data(data)
Cmp_sequence_data = data
end
-- Advances screen to next screen in sequence.
-- @param force_advance bool determines if we force advance to the next screen...
function cmp_common_screen_advance(force_advance)
if force_advance == false or force_advance == nil then
if Cmp_screen_is_playing then
--A current screen is in progress... we should force it to the end...
local screen_data = Cmp_sequence_data[Cmp_screen_idx]
if screen_data ~= nil then
--Call Skip function for that particular screen type...
local screen_type = screen_data.type
Cmp_screens[screen_data.type].skip_func()
end
return
end
end
-- If we aren't force advancing, we will animate it out.
if force_advance == false or force_advance == nil then
--Animate out the previous screen...
local screen_data = Cmp_sequence_data[Cmp_screen_idx]
if screen_data ~= nil then
local screen_type = screen_data.type
Cmp_screens[screen_data.type].out_func()
end
end
--Increment the current screen to next...
Cmp_screen_idx = Cmp_screen_idx + 1
local screen_data = Cmp_sequence_data[Cmp_screen_idx]
--if we are a screen before the final screen we should attemp to hide bg_saints_fade_anim
if screen_data ~= nil then
if screen_data.type == CMP_SCREEN_REWARD_INDEX then
cmp_common_bg_saints_show(false, true)
--Make sure image is faded out...
cmp_common_image_fade_out()
end
if screen_data.type == CMP_SCREEN_COOP_WAIT_INDEX then
--Make sure image is faded out...
cmp_common_image_fade_out()
end
end
--Determine if we start the next screen or exit...
if screen_data ~= nil then
--Call Start function for that particular screen type...
local screen_type = screen_data.type
Cmp_screens[screen_data.type].start_func()
else
-- Do nothing... Final screen is always the coop screen
-- and will bypass itself automatically if not needed to display.
return
end
end
----------------------------------------------------------------
-- Screen based functions
----------------------------------------------------------------
----------------------------------------------------------------
-- Title screen
----------------------------------------------------------------
function cmp_common_title_start()
cmp_common_input_block_delay()
Cmp_screen_is_playing = true
--Set properties from screen data...
local screen_data = Cmp_sequence_data[Cmp_screen_idx]
local title_string = screen_data.title_string
local image = screen_data.image
--local title_string = "THE DUKE IS BACK!"
local title_txt_h = vint_object_find("title_txt", 0, Cmp_common_doc)
vint_set_property(title_txt_h, "text_tag", title_string)
local title_txt_width, title_txt_height = element_get_actual_size(title_txt_h)
local title_txt_x, title_txt_y = vint_get_property(title_txt_h, "anchor")
--Adjust heights and header...
--Get values that we need to calculate position...
local complete_txt_h = vint_object_find("complete_txt", 0, Cmp_common_doc)
local complete_txt_x, complete_txt_y = vint_get_property(complete_txt_h, "anchor")
local complete_txt_width, complete_txt_height = element_get_actual_size(complete_txt_h)
--Calculate new position... for "COMPLETE" text.
local new_y = title_txt_height + title_txt_y + 5
--Set Values...
local complete_txt_slide_twn = vint_object_find("complete_txt_slide_twn", 0, Cmp_common_doc)
local slide_start_x, slide_start_y = vint_get_property(complete_txt_slide_twn, "start_value")
local slide_end_x, slide_end_y = vint_get_property(complete_txt_slide_twn, "end_value")
vint_set_property(complete_txt_slide_twn, "start_value", slide_start_x, new_y)
vint_set_property(complete_txt_slide_twn, "end_value", slide_end_x, new_y)
--determine if we have an image to display or not...
local img_grp_h = vint_object_find("img_grp", 0, Cmp_common_doc)
if image ~= nil or image ~= 0 then
vint_set_property(img_grp_h, "visible", true)
else
vint_set_property(img_grp_h, "visible", false)
end
--Override hintbar position...
Cmp_screens[Cmp_screen_idx].hint_bar_y = new_y + complete_txt_height + 125
local title_anim_h = vint_object_find("title_in_anim", 0, Cmp_common_doc)
lua_play_anim(title_anim_h, 0, Cmp_common_doc)
--Execute on start func if available...
if screen_data.on_start ~= nil and type(screen_data.on_start) == "function" then
screen_data.on_start()
end
end
function cmp_common_title_skip()
--Move animation to end...
local title_anim_h = vint_object_find("title_in_anim", 0, Cmp_common_doc)
lua_play_anim(title_anim_h, -5, Cmp_common_doc)
--Play Star Power...
cmp_common_star_power_start()
--Force end...
cmp_common_title_end()
end
function cmp_common_title_slam()
cmp_common_lut_effect(CMP_LUT_MISSION)
cmp_common_camera_shake()
cmp_common_star_power_start()
game_letterbox_fade_out(true)
end
function cmp_common_title_end()
--Show hints...
cmp_common_hint_bar_show()
Cmp_screen_is_playing = false
end
function cmp_common_title_out()
--Fade out title
local title_anim_h = vint_object_find("title_out_anim", 0, Cmp_common_doc)
lua_play_anim(title_anim_h, 0, Cmp_common_doc)
cmp_common_hint_bar_hide()
end
-------------------------------------------------------------------------------
-- Special case function to change the scale if needed.
--
function cmp_common_title_resize(scale)
local title_txt_h = vint_object_find("title_txt", 0, Cmp_common_doc)
vint_set_property(title_txt_h, "text_scale", scale, scale)
end
----------------------------------------------------------------
-- Cash screen
----------------------------------------------------------------
function cmp_common_cash_start()
--Initialize cash stuff...
Cmp_screen_is_playing = true
--Get properties from screen data...
local screen_data = Cmp_sequence_data[Cmp_screen_idx]
if CMP_TEST_MODE then
screen_data.cash_reward = 2000
screen_data.cash_multiplier = 50
screen_data.cash_reward_inc_multiplier = 5000
if CMP_TEST_NO_MULTIPLIER then
screen_data.cash_multiplier = 0
end
end
if screen_data.cash_reward == 0 then
--skip this screen if no reward granted...
cmp_common_cash_callback_enable(false)
cmp_common_screen_advance(true)
return
end
--delay input...
cmp_common_input_block_delay()
local cash_reward = screen_data.cash_reward
local cash_multiplier = screen_data.cash_multiplier
local cash_reward_inc_multiplier = screen_data.cash_reward_inc_multiplier
Cmp_screen_cash_start = 0
Cmp_screen_cash_end = cash_reward
Cmp_screen_cash_total = cash_reward_inc_multiplier
--Update bonus text...
local bonus_txt_h = vint_object_find("cash_bonus_txt", 0, Cmp_common_doc)
local values = {[0] = cash_multiplier}
local bonus_string = vint_insert_values_in_string("COMPLETION_BONUS", values)
vint_set_property(bonus_txt_h, "text_tag", bonus_string)
--Start cash animation in...
local cash_anim_h = vint_object_find("cash_in_anim", 0, Cmp_common_doc)
lua_play_anim(cash_anim_h, 0, Cmp_common_doc)
--Set callback for cash count complete
if cash_multiplier > 0 then
--Show bonus stage...
Cmp_common_cash_complete_cb = cmp_common_cash_bonus_start
Cmp_screen_cash_skip_bonus = false
else
--Skip bonus stage...
Cmp_common_cash_complete_cb = cmp_common_cash_end
Cmp_screen_cash_skip_bonus = true
end
--Start in the non bonus stage...
Cmp_screen_cash_count_is_bonus = false
--Start counting the cash...
local cash_count_thread = thread_new("cmp_common_cash_count_thread")
end
function cmp_common_cash_skip()
--Destroy callbacks
cmp_common_cash_callback_enable(false)
local cash_anim_h = vint_object_find("cash_in_anim", 0, Cmp_common_doc)
lua_play_anim(cash_anim_h, -5, Cmp_common_doc)
if Cmp_screen_cash_skip_bonus == false then
local cash_anim_h = vint_object_find("cash_bonus_in_anim", 0, Cmp_common_doc)
lua_play_anim(cash_anim_h, -5, Cmp_common_doc)
end
local cash_h = vint_object_find("cash_amount_txt", 0, Cmp_common_doc)
vint_set_property(cash_h, "text_tag", "$" .. format_cash(Cmp_screen_cash_total) .. "\n")
--Play star Power
cmp_common_star_power_start()
--force end of screen(This is a fail safe in case our callbacks don't get called)
cmp_common_cash_end()
--stop ramping audio...
cmp_audio_stop_ramp()
Cmp_screen_cash_skip = true
end
function cmp_common_cash_slam()
if Cmp_screen_is_playing then
cmp_common_camera_shake()
cmp_common_star_power_start()
if Cmp_screen_cash_skip_bonus then
-- skipping bonus... so, start ramp...
-- and of course... no multiplier
cmp_audio_cash_ramp_no_multiplier()
else
--Start ramp with bonus..
cmp_audio_cash_ramp_multiplier()
end
end
end
function cmp_common_cash_end()
--Show hints...
cmp_common_hint_bar_show()
Cmp_screen_is_playing = false
end
function cmp_common_cash_out()
--Fade out Cash
local cash_anim_h = vint_object_find("cash_out_anim", 0, Cmp_common_doc)
lua_play_anim(cash_anim_h, 0, Cmp_common_doc)
cmp_common_hint_bar_hide()
end
function cmp_common_cash_count_thread()
--init stuff
local start_cash = Cmp_screen_cash_start -- $ amount to start cash from...
local cash_this_frame = -1 -- How much cash gets displayed in the current frame...
local is_complete = false -- Is the screen complete?
Cmp_screen_cash_skip = false -- Did we skip the cash?
--get the variables from the global
local cash = Cmp_screen_cash_end - start_cash
local cash_end = Cmp_screen_cash_end
local amt_min = 100
local amt_max = 33000
local time_min = CMP_TIME_CASH
local time_max = CMP_TIME_CASH
if Cmp_screen_cash_count_is_bonus then
time_min = CMP_TIME_CASH_BONUS
time_max = CMP_TIME_CASH_BONUS
elseif Cmp_screen_cash_skip_bonus then
time_min = CMP_TIME_CASH_NO_BONUS
time_max = CMP_TIME_CASH_NO_BONUS
end
local init_time = floor(vint_get_time_index() * 1000)
local cur_time = init_time
local time_to_count = floor(time_min + ((time_max - time_min) * (cash / amt_max)))
if time_to_count > time_max then
time_to_count = time_max
end
if cash > 0 then
while is_complete == false do
local cur_time = floor(vint_get_time_index() * 1000) - init_time
--set my values
cash_this_frame = cash * (cur_time / time_to_count) + start_cash
local cash_h = vint_object_find("cash_amount_txt", 0, Cmp_common_doc)
vint_set_property(cash_h, "text_tag", "$" .. format_cash(cash_this_frame) .. "\n")
--Advance time so we skip...
if Cmp_screen_cash_skip == true then
cur_time = time_to_count
cash_end = Cmp_screen_cash_total
Cmp_common_cash_complete_cb = cmp_common_cash_end
end
if cur_time >= time_to_count then
is_complete = true
--force the values
vint_set_property(cash_h, "text_tag", "$" .. format_cash(cash_end))
Cmp_common_cash_complete_cb()
end
thread_yield()
end
else
-- Start next screen?
cmp_common_cash_end()
end
end
function cmp_common_cash_bonus_start()
-- Start Cash Bonus Screen
local cash_anim_h = vint_object_find("cash_bonus_in_anim", 0, Cmp_common_doc)
lua_play_anim(cash_anim_h, 0, Cmp_common_doc)
--Set callback for cash count complete
Cmp_common_cash_complete_cb = cmp_common_cash_end
end
function cmp_common_cash_bonus_slam()
--Shake camera...
cmp_common_camera_shake()
--Initialize cash stuff...
--Get properties from screen data...
local screen_data = Cmp_sequence_data[Cmp_screen_idx]
local cash_reward = screen_data.cash_reward
local cash_multiplier = screen_data.cash_multiplier
local cash_reward_inc_multiplier = screen_data.cash_reward_inc_multiplier
Cmp_screen_cash_start = cash_reward
Cmp_screen_cash_end = cash_reward_inc_multiplier
--Cash Ramp Bonus
cmp_audio_cash_bonus_ramp()
--Start in the bonus stage...
Cmp_screen_cash_count_is_bonus = true
--Start counting the cash...
local cash_count_thread = thread_new("cmp_common_cash_count_thread")
end
-- Easy way to initialize or clear out the cash callbacks.
function cmp_common_cash_callback_enable(is_enabled)
local cash_slam_cb = "cmp_common_cash_slam"
local cash_bonus_slam_cb = "cmp_common_cash_bonus_slam"
if is_enabled == false then
cash_slam_cb = nil
cash_bonus_slam_cb = nil
end
local twn_h = vint_object_find("cash_slam_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", cash_slam_cb)
local twn_h = vint_object_find("cash_bonus_slam_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", cash_bonus_slam_cb)
end
----------------------------------------------------------------
--Respect screen
----------------------------------------------------------------
function cmp_common_respect_start()
Cmp_screen_is_playing = true
--Get properties from screen data...
local screen_data = Cmp_sequence_data[Cmp_screen_idx]
--respect is always displayed as one level up... (internally respect starts at 0...
screen_data.respect_level_old = screen_data.respect_level_old + 1
screen_data.respect_level_new = screen_data.respect_level_new + 1
screen_data.respect_level_multiplier = screen_data.respect_level_multiplier + 1
if CMP_TEST_MODE then
screen_data.respect_pct_old = .1
screen_data.respect_level_old = 1
screen_data.respect_pct_new = .6
screen_data.respect_level_new = 1
screen_data.respect_multiplier = 40
screen_data.respect_pct_multiplier = .8
screen_data.respect_level_multiplier = 2
end
local respect_pct_old = screen_data.respect_pct_old
local respect_level_old = screen_data.respect_level_old
local respect_pct_new = screen_data.respect_pct_new
local respect_level_new = screen_data.respect_level_new
local respect_multiplier = screen_data.respect_multiplier
local respect_pct_multiplier = screen_data.respect_pct_multiplier
local respect_level_multiplier = screen_data.respect_level_multiplier
if respect_level_old == respect_pct_new and screen_data.respect_level_old == screen_data.respect_level_new then
--Force skip this scren... no respect to ad...
cmp_common_respect_cb_enable(false)
cmp_common_screen_advance(true)
return
end
--Delay input...
cmp_common_input_block_delay()
if respect_multiplier == 0 then
--skip bonus screen if there is no multiplier...
Cmp_screen_respect_skip_bonus = true
--shift respect text to center
local respect_text_shift_grp_h = vint_object_find("respect_text_shift_grp", 0, Cmp_common_doc)
local x, y = vint_get_property(respect_text_shift_grp_h, "anchor")
vint_set_property(respect_text_shift_grp_h, "anchor", x, y + 30)
end
--Set bonus text...
local bonus_txt_h = vint_object_find("respect_bonus_txt", 0, Cmp_common_doc)
local values = {[0] = respect_multiplier}
local bonus_string = vint_insert_values_in_string("COMPLETION_BONUS", values)
vint_set_property(bonus_txt_h, "text_tag", bonus_string)
--figure out how long we are going to process the time...
local base_time = CMP_TIME_RESPECT
if respect_multiplier ~= 0 then
--We have respect Multiplier
base_time = CMP_TIME_RESPECT
--Ramp audio..
cmp_audio_respect_ramp_multiplier()
else
--No multiplier
base_time = CMP_TIME_RESPECT_NO_BONUS
--Ramp audio..
cmp_audio_respect_ramp_no_multiplier()
end
--Start meter fill!
cmp_common_respect_meter_update(respect_pct_old, respect_pct_new, respect_level_old, respect_level_new, base_time)
local respect_anim_h = vint_object_find("respect_in_anim", 0, Cmp_common_doc)
lua_play_anim(respect_anim_h, 0, Cmp_common_doc)
end
function cmp_common_respect_skip()
--Stop any tween callbacks from happening...
cmp_common_respect_cb_enable(false)
local screen_data = Cmp_sequence_data[Cmp_screen_idx]
local respect_pct_multiplier = screen_data.respect_pct_multiplier
local respect_level_multiplier = screen_data.respect_level_multiplier
cmp_common_respect_fill_meter(0, respect_pct_multiplier, false)
--Force meter level
local level = max(screen_data.respect_level_new, screen_data.respect_level_multiplier)
--Force level of respect meter...
local txt_h = vint_object_find("respect_level_text", 0, Cmp_common_doc)
vint_set_property(txt_h, "text_tag", level)
--Play slide in animation to end...
local respect_anim_h = vint_object_find("respect_in_anim", 0, Cmp_common_doc)
lua_play_anim(respect_anim_h, -5, Cmp_common_doc)
if Cmp_screen_respect_skip_bonus == false then
--Play the bonus anim to end...
local respect_bonus_h = vint_object_find("respect_bonus_in_anim", 0, Cmp_common_doc)
lua_play_anim(respect_bonus_h, -5, Cmp_common_doc)
end
--Play star Power
cmp_common_star_power_start()
--stop ramping audio...
cmp_audio_stop_ramp()
--End Screen...
cmp_common_respect_end()
end
function cmp_common_respect_end()
Cmp_screen_is_playing = false
cmp_common_hint_bar_show()
end
function cmp_common_respect_out()
--Fade out Respect
local respect_anim_h = vint_object_find("respect_out_anim", 0, Cmp_common_doc)
lua_play_anim(respect_anim_h, 0, Cmp_common_doc)
cmp_common_hint_bar_hide()
end
--respect_up_level_up_cb_twn
function cmp_common_respect_slam()
if Cmp_screen_is_playing then
cmp_common_camera_shake()
cmp_common_star_power_start()
end
end
--Bonus slam callback...
function cmp_common_respect_slam_bonus()
if Cmp_screen_is_playing then
cmp_common_camera_shake()
--Get properties from screen data...
local screen_data = Cmp_sequence_data[Cmp_screen_idx]
local respect_pct_old = screen_data.respect_pct_old
local respect_level_old = screen_data.respect_level_old
local respect_pct_new = screen_data.respect_pct_new
local respect_level_new = screen_data.respect_level_new
local respect_multiplier = screen_data.respect_multiplier
local respect_pct_multiplier = screen_data.respect_pct_multiplier
local respect_level_multiplier = screen_data.respect_level_multiplier
--Do fillup to multiplier level...
cmp_common_respect_meter_update(respect_pct_new,respect_pct_multiplier, respect_level_new, respect_level_multiplier, CMP_TIME_RESPECT_BONUS)
--Set this flag so we don't play the bonus twice...
Cmp_screen_respect_skip_bonus = true
--Ramp audio...
cmp_audio_respect_bonus_ramp()
end
end
-- Update/animate the respect meter
--
-- @param total_respect current total amount of respect player has
-- @param respect_pct % the player is towards their next rank level
-- @param level: player rank level
-- @param base Base time it should take to fill up the meter from start to finish
function cmp_common_respect_meter_update(old_respect_pct, respect_pct, old_level, new_level, base_time)
--Get differences between the levels
local level_dif = new_level - old_level
Cmp_screen_respect_level_cur = old_level
--Initialize the level of the meter...
local txt_h = vint_object_find("respect_level_text", 0, Cmp_common_doc)
vint_set_property(txt_h, "text_tag", old_level)
--If the difference is greater than 0 then we are going to level up...
if level_dif > 0 then
--Store to global...
Cmp_screen_respect_level_dif = level_dif
--Store target percentage for the meter...
Cmp_screen_respect_target_pct = respect_pct
local first_ramp_pct = 1 - old_respect_pct
local final_ramp_pct = respect_pct
local level_dif = level_dif
--Calculate levels per second (total percentage / times the thing passes 0)
local revolutions_per_ms = base_time / (first_ramp_pct + (level_dif - 1) + final_ramp_pct)
Cmp_screen_respect_time_start = revolutions_per_ms * first_ramp_pct
Cmp_screen_respect_time_mid = revolutions_per_ms * 1
Cmp_screen_respect_time_end = revolutions_per_ms * final_ramp_pct
--Setup callback so it can be filled again and again...
local twn_h = vint_object_find("respect_meter_tween", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_common_respect_fill_cb")
--Modify time to fill...
cmp_common_respect_set_time(Cmp_screen_respect_time_start)
cmp_common_respect_fill_meter(old_respect_pct, 1, true)
else
--No leveling, so do a standard one meter cycle increase.
Cmp_screen_respect_level_dif = 0
--Setup callback for this is the only time its going to be filled...
local twn_h = vint_object_find("respect_meter_tween", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_common_respect_fill_end")
local end_event = vint_get_property(twn_h, "end_event")
--Reset time to fill
cmp_common_respect_set_time(base_time)
--Fill meter anim...
cmp_common_respect_fill_meter(old_respect_pct, respect_pct, true)
end
end
---------------------------------------------------------------------------
-- Fills up the meter and plays added respect animation.
-- After animation is complete it does a callback which checks if we've
-- Increased a level and calls that animation...
--
-- @param old_respect_pct
-- @param respect_pct Percentage to transition too...
-- @param do_animation Text string for header
---------------------------------------------------------------------------
function cmp_common_respect_fill_meter(old_respect_pct, respect_pct, do_animation)
-- min/max for a percentage
respect_pct = limit(respect_pct, 0, 1)
local start_respect_angle = RESPECT_START_ANGLE - ((RESPECT_START_ANGLE + RESPECT_END_ANGLE) * old_respect_pct)
local end_respect_angle = RESPECT_START_ANGLE - ((RESPECT_START_ANGLE + RESPECT_END_ANGLE) * respect_pct)
if do_animation == true then
-- Animate Meter
local respect_up_anim_h = vint_object_find("respect_up_anim", 0, Cmp_common_doc)
local meter_tween_h = vint_object_find("respect_meter_tween", 0, Cmp_common_doc)
local meter_bg_tween_h = vint_object_find("respect_meter_bg_tween", 0, Cmp_common_doc)
-- Animate from previous to new
vint_set_property(meter_tween_h, "start_value", start_respect_angle)
vint_set_property(meter_tween_h, "end_value", end_respect_angle)
vint_set_property(meter_bg_tween_h, "start_value", start_respect_angle - .03)
vint_set_property(meter_bg_tween_h, "end_value", end_respect_angle - .03)
lua_play_anim(respect_up_anim_h, 0, Cmp_common_doc)
else
--Stop Animation...
local respect_up_anim_h = vint_object_find("respect_up_anim", 0, Cmp_common_doc)
vint_set_property(respect_up_anim_h, "is_paused", true)
--Manually set bars...
local respect_meter_h = vint_object_find("respect_meter", 0, Cmp_common_doc)
local respect_meter_bg_h = vint_object_find("respect_meter_bg", 0, Cmp_common_doc)
vint_set_property(respect_meter_h, "end_angle", end_respect_angle)
vint_set_property(respect_meter_bg_h, "end_angle", end_respect_angle - .03)
end
end
function cmp_common_respect_fill_cb()
--Decrement the level difference...
Cmp_screen_respect_level_dif = Cmp_screen_respect_level_dif - 1
--Swap the level
local anim_h = vint_object_find("respect_level_up_anim", 0, Cmp_common_doc)
lua_play_anim(anim_h, 0, Cmp_common_doc)
--Determine if we are going to fill up again?
if Cmp_screen_respect_level_dif <= 0 then
--Setup callback for this is the last time its going to be filled...
local twn_h = vint_object_find("respect_meter_tween", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_common_respect_fill_end")
--Set the the target fill time to something we calculated earlier..
cmp_common_respect_set_time(Cmp_screen_respect_time_end)
--This is the last fill so lets fill it up to the target percent...
cmp_common_respect_fill_meter(0, Cmp_screen_respect_target_pct, true)
else
--reset callback to call this function again after meter fills.
local twn_h = vint_object_find("respect_meter_tween", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_common_respect_fill_cb")
--Set the the target fill time to something we calculated earlier..
cmp_common_respect_set_time(Cmp_screen_respect_time_mid)
--Do normal fill animation to the top...
cmp_common_respect_fill_meter(0, 1, true)
end
end
-- Upgrades the current level of the respect meter.
-- This happens via callback of the respect level up animation...
function cmp_common_respect_next_level()
Cmp_screen_respect_level_cur = Cmp_screen_respect_level_cur + 1
local txt_h = vint_object_find("respect_level_text", 0, Cmp_common_doc)
vint_set_property(txt_h, "text_tag", Cmp_screen_respect_level_cur)
end
function cmp_common_respect_fill_end()
-- Do we go into bonus?
if Cmp_screen_respect_skip_bonus == false then
--Lets not skip the bonus...
local respect_bonus_anim_in_h = vint_object_find("respect_bonus_in_anim", 0, Cmp_common_doc)
lua_play_anim(respect_bonus_anim_in_h, 0, Cmp_common_doc)
else
--End Screen
cmp_common_respect_end()
end
end
---------------------------------------------------------------------------
-- Sets the duration tweens for filling up the meter...
--
-- @param t Time it takes to fill up the meter...
---------------------------------------------------------------------------
function cmp_common_respect_set_time(t)
local meter_tween_h = vint_object_find("respect_meter_tween", 0, Cmp_common_doc)
local meter_bg_tween_h =vint_object_find("respect_meter_bg_tween", 0, Cmp_common_doc)
vint_set_property(meter_tween_h, "duration", t)
vint_set_property(meter_bg_tween_h, "duration", t)
end
-- Easy way to initialize or clear out the respect callbacks.
function cmp_common_respect_cb_enable(is_enabled)
local respect_slam_cb = "cmp_common_respect_slam"
local respect_bonus_cb = "cmp_common_respect_slam_bonus"
local respect_level_cb = "cmp_common_respect_next_level"
if is_enabled == false then
respect_slam_cb = nil
respect_bonus_cb = nil
respect_level_cb = nil
end
--Respect Tween callbacks...
local twn_h = vint_object_find("respect_slam_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", respect_slam_cb)
local twn_h = vint_object_find("respect_bonus_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", respect_bonus_cb)
-- when it is time to update the cash...
local twn_h = vint_object_find("respect_level_up_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", respect_level_cb)
end
----------------------------------------------------------------
-- City Control screen
----------------------------------------------------------------
function cmp_common_control_start()
Cmp_screen_is_playing = true
--Get properties from screen data...
local screen_data = Cmp_sequence_data[Cmp_screen_idx]
if CMP_TEST_MODE then
-- do nothing...
end
local district_pct_old = screen_data.district_pct_old
local district_pct_new = screen_data.district_pct_new
local district_cash_per_day = screen_data.district_cash_per_day
local district_team_name = screen_data.district_team_name
if district_pct_new == 0 or district_pct_new == nil then
--Force skip this scren...
cmp_common_screen_advance(true)
return
end
if district_pct_new == district_pct_old then
-- Skip screen if there is no gained district.
cmp_common_screen_advance(true)
return
end
--Delay input...
cmp_common_input_block_delay()
--Set text...
local control_meter_pct_text_h = vint_object_find("control_meter_pct_text", 0, Cmp_common_doc)
local values_1 = {[0] = floor(district_pct_old * 1000) * .1 }
local control_pct_string = vint_insert_values_in_string("{0}%%%", values_1)
vint_set_property(control_meter_pct_text_h, "text_tag", control_pct_string)
local control_txt = vint_object_find("control_txt", 0, Cmp_common_doc)
local values_2 = {[0] = district_team_name}
local control_string = vint_insert_values_in_string("COMPLETION_CONTROL", values_2)
vint_set_property(control_txt, "text_tag", control_string)
local ctrl_width, ctrl_height = element_get_actual_size(control_txt)
local ctrl_width_max = 383 --HD
if vint_is_std_res() then
ctrl_width_max = 312
end
if ctrl_width > ctrl_width_max then
local scale = ctrl_width_max/ctrl_width
vint_set_property(control_txt, "scale", scale, scale)
end
local control_cash_txt_h = vint_object_find("control_cash_txt", 0, Cmp_common_doc)
local values_3 = {[0] = format_cash(district_cash_per_day)}
local control_cash_string = vint_insert_values_in_string("COMPLETION_CONTROL_PER_DAY", values_3)
vint_set_property(control_cash_txt_h, "text_tag", control_cash_string)
--figure out how long we are going to process the time...
local base_time = CMP_TIME_CONTROL
--Ramp audio..
cmp_audio_control_ramp()
--Start meter fill!
cmp_common_control_meter_update(0, district_pct_new, base_time)
local control_in_anim_h = vint_object_find("control_in_anim", 0, Cmp_common_doc)
lua_play_anim(control_in_anim_h, 0, Cmp_common_doc)
--slam in numbers
local control_level_up_anim_h = vint_object_find("control_level_up_anim", 0, Cmp_common_doc)
lua_play_anim(control_level_up_anim_h, 0, Cmp_common_doc)
end
function cmp_common_control_skip()
if Cmp_screen_is_playing then
--Stop any tween callbacks from happening...
cmp_common_control_cb_enable(false)
local screen_data = Cmp_sequence_data[Cmp_screen_idx]
local district_pct_new = screen_data.district_pct_new
--Force meter level
cmp_common_control_fill_meter(0, district_pct_new, false)
-- Force text into meter...
local control_meter_pct_text_h = vint_object_find("control_meter_pct_text", 0, Cmp_common_doc)
local values_1 = {[0] = floor(district_pct_new * 1000) * .1 }
local control_pct_string = vint_insert_values_in_string("{0}%%%", values_1)
vint_set_property(control_meter_pct_text_h, "text_tag", control_pct_string)
--prevent audio callback from playing twice... I don't like this but its the only way (JMH 8/23/2011)
--Control Cash Slam
local twn_h = vint_object_find("control_cash_audio_slam_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", nil)
--Play slide in animation to end...
local control_in_anim_h = vint_object_find("control_in_anim", 0, Cmp_common_doc)
lua_play_anim(control_in_anim_h, -10, Cmp_common_doc)
--Play star Power
cmp_common_star_power_start()
--stop ramping audio...
cmp_audio_stop_ramp()
--end completion...
cmp_common_control_end()
end
end
function cmp_common_control_end()
Cmp_screen_is_playing = false
cmp_common_hint_bar_show()
end
function cmp_common_control_out()
--Fade out Respect
local control_out_anim_h = vint_object_find("control_out_anim", 0, Cmp_common_doc)
lua_play_anim(control_out_anim_h, 0, Cmp_common_doc)
cmp_common_hint_bar_hide()
end
-- When the meter flys in and stops we do this via tween cb...
function cmp_common_control_slam()
if Cmp_screen_is_playing then
cmp_common_camera_shake()
cmp_common_star_power_start()
end
end
-- Update/animate the respect meter
--
-- @param old_pct current total amount of control player has over district
-- @param new_pct current total amount of control player has over district
-- @param base_time Base time it should take to fill up the meter from start to finish
function cmp_common_control_meter_update(pct_old, pct_new, base_time)
--Reset time to fill
cmp_common_control_set_time(base_time)
--Setup callback for this is the only time its going to be filled...
local twn_h = vint_object_find("control_meter_tween", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_common_control_fill_end")
--Fill meter anim...
cmp_common_control_fill_meter(pct_old, pct_new, true)
end
---------------------------------------------------------------------------
-- Fills up the meter and plays added respect animation.
-- After animation is complete it does a callback which checks if we've
-- Increased a level and calls that animation...
--
-- @param pct_old
-- @param pct_new Percentage to transition too...
-- @param do_animation Text string for header
---------------------------------------------------------------------------
function cmp_common_control_fill_meter(pct_old, pct_new, do_animation)
-- min/max for a percentage
pct_old = limit(pct_old, 0, 1)
pct_new = limit(pct_new, 0, 1)
local start_angle = CONTROL_START_ANGLE - ((CONTROL_START_ANGLE + CONTROL_END_ANGLE) * pct_old)
local end_angle = CONTROL_START_ANGLE - ((CONTROL_START_ANGLE + CONTROL_END_ANGLE) * pct_new)
if do_animation == true then
-- Animate Meter
local control_up_anim_h = vint_object_find("control_up_anim", 0, Cmp_common_doc)
local meter_tween_h = vint_object_find("control_meter_tween", 0, Cmp_common_doc)
local meter_bg_tween_h = vint_object_find("control_meter_bg_tween", 0, Cmp_common_doc)
-- Animate from previous to new
vint_set_property(meter_tween_h, "start_value", start_angle)
vint_set_property(meter_tween_h, "end_value", end_angle)
vint_set_property(meter_bg_tween_h, "start_value", start_angle - .03)
vint_set_property(meter_bg_tween_h, "end_value", end_angle - .03)
lua_play_anim(control_up_anim_h, 0, Cmp_common_doc)
else
--Stop Animation...
local control_up_anim_h = vint_object_find("respect_up_anim", 0, Cmp_common_doc)
vint_set_property(control_up_anim_h, "is_paused", true)
--Manually set bars...
local respect_meter_h = vint_object_find("respect_meter", 0, Cmp_common_doc)
local respect_meter_bg_h = vint_object_find("respect_meter_bg", 0, Cmp_common_doc)
vint_set_property(respect_meter_h, "end_angle", end_angle)
vint_set_property(respect_meter_bg_h, "end_angle", end_angle - .03)
end
-- Force text into meter...
local control_meter_pct_text_h = vint_object_find("control_meter_pct_text", 0, Cmp_common_doc)
local values_1 = {[0] = floor(pct_new * 1000) * .1 }
local control_pct_string = vint_insert_values_in_string("{0}%%%", values_1)
vint_set_property(control_meter_pct_text_h, "text_tag", control_pct_string)
end
function cmp_common_control_fill_end()
--End Screen
if Cmp_screen_is_playing then
cmp_common_control_end()
end
end
---------------------------------------------------------------------------
-- Sets the duration tweens for filling up the meter...
--
-- @param t Time it takes to fill up the meter...
---------------------------------------------------------------------------
function cmp_common_control_set_time(t)
local meter_tween_h = vint_object_find("control_meter_tween", 0, Cmp_common_doc)
local meter_bg_tween_h = vint_object_find("control_meter_bg_tween", 0, Cmp_common_doc)
vint_set_property(meter_tween_h, "duration", t)
vint_set_property(meter_bg_tween_h, "duration", t)
end
-- Easy way to initialize or clear out the control callbacks.
function cmp_common_control_cb_enable(is_enabled)
local control_slam_cb = "cmp_common_control_slam"
if is_enabled == false then
control_slam_cb = nil
end
--Respect Tween callbacks...
local twn_h = vint_object_find("control_slam_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", control_slam_cb)
end
----------------------------------------------------------------
-- Rewards screen
----------------------------------------------------------------
function cmp_common_rewards_start()
--Get properties from screen data...
local screen_data = Cmp_sequence_data[Cmp_screen_idx]
local rewards_count = screen_data.rewards_count
--Set rewards count so it knows how many screens to display...
reward_granted_set_reward_count(rewards_count)
--Set callback on the reward screen, so we know when it is over...
set_reward_granted_end_cb(cmp_common_rewards_end)
--Start reward screen...
reward_granted_start()
Cmp_screen_is_playing = true
end
function cmp_common_rewards_skip()
end
function cmp_common_rewards_end()
--Bring in background full black. so when we exit the reward screen we don't fade anything
--weird uncleaned up...
local h = vint_object_find("background_bmp", 0, Cmp_common_doc)
vint_set_property(h, "alpha", 1)
--Hide everything local to the common screen... afterwards we should always transition back to game,
--So nothing else should display here from the main screen. This cleans up any
--Stars or stuff leftover, this does not fix the player popping back in. (JMH 3/24/2011)
local screen_h = vint_object_find("screen_grp", 0, Cmp_common_doc)
local stars_h = vint_object_find("stars", 0, Cmp_common_doc)
vint_set_property(screen_h, "visible", false)
vint_set_property(stars_h, "visible", false)
Cmp_screen_is_playing = false
cmp_common_screen_advance(false)
end
function cmp_common_rewards_out()
end
----------------------------------------------------------------
-- Unlock screen
----------------------------------------------------------------
----------------------------------------------------------------
-- Coop Wait screen
----------------------------------------------------------------
--Fades in an start coop wait screen...
function cmp_common_coop_wait_start()
Completion_user_is_done_viewing() -- Notify other player that we're ready to move on
if Completion_should_wait_for_coop() then
--Play Fade In anim...
local coop_anim_h = vint_object_find("coop_in_anim", 0, Cmp_common_doc)
lua_play_anim(coop_anim_h, 0, Cmp_common_doc)
--Play Pulse Anim...
local coop_anim_h = vint_object_find("coop_waiting_pulse_anim", 0, Cmp_common_doc)
lua_play_anim(coop_anim_h, 0, Cmp_common_doc)
--Set Coop Player Gamer tag
Cmp_screen_coop_gamer_tag = Completion_get_other_player_name()
local values = {[0] = Cmp_screen_coop_gamer_tag}
local waiting_string = vint_insert_values_in_string("COMPLETION_COOP_WAITING", values)
local waiting_txt_h = vint_object_find("coop_waiting_txt", 0, Cmp_common_doc)
vint_set_property(waiting_txt_h,"text_tag", waiting_string)
Cmp_screen_is_playing = true
Cmp_screen_coop_is_waiting = true
else
-- Do nothing... the game will call cmp_common_exit when we want to leave...
end
end
function cmp_common_coop_wait_skip()
--Does nothing...
end
--Fade out coop wait screen...
function cmp_common_coop_wait_out()
--only fade out if we had the coop screen up...
if Cmp_screen_coop_is_waiting then
local coop_anim_h = vint_object_find("coop_in_anim", 0, Cmp_common_doc)
vint_set_property(coop_anim_h, "is_paused", true)
local coop_anim_h = vint_object_find("coop_out_anim", 0, Cmp_common_doc)
lua_play_anim(coop_anim_h, 0, Cmp_common_doc)
end
end
function cmp_common_coop_wait_dialog()
local options = { [0] = "CONTROL_YES", [1] = "CONTROL_NO" }
Cmp_common_coop_dialog_handle = dialog_box_open("MENU_TITLE_WARNING", "DIALOG_PAUSE_DISCONNECT_PROMPT", options, "cmp_common_coop_disconnect", 1, DIALOG_PRIORITY_SYSTEM_CRITICAL, true, nil, false, false)
end
function cmp_common_coop_disconnect(result, action)
if result == 0 then
dialog_box_disconnect()
--WHAT SHOULD I DO HERE?
cmp_common_exit()
end
Cmp_common_coop_dialog_handle = 0
end
----------------------------------------------------------------
-- Tables for packing screen based functions and constants
----------------------------------------------------------------
Cmp_screens = {
[CMP_SCREEN_TITLE_INDEX] = {
start_func = cmp_common_title_start,
skip_func = cmp_common_title_skip,
out_func = cmp_common_title_out,
hint_bar_y = -1, --set via cmp_common_title_start()...
},
[CMP_SCREEN_CASH_INDEX] = {
start_func = cmp_common_cash_start,
skip_func = cmp_common_cash_skip,
out_func = cmp_common_cash_out,
hint_bar_y = 433,
},
[CMP_SCREEN_RESPECT_INDEX] = {
start_func = cmp_common_respect_start,
skip_func = cmp_common_respect_skip,
out_func = cmp_common_respect_out,
hint_bar_y = 454,
},
[CMP_SCREEN_CONTROL_INDEX] = {
start_func = cmp_common_control_start,
skip_func = cmp_common_control_skip,
out_func = cmp_common_control_out,
hint_bar_y = 454,
},
[CMP_SCREEN_REWARD_INDEX] = {
start_func = cmp_common_rewards_start,
skip_func = cmp_common_rewards_skip,
out_func = cmp_common_rewards_out,
hint_bar_y = nil,
},
[CMP_SCREEN_COOP_WAIT_INDEX] = {
start_func = cmp_common_coop_wait_start,
skip_func = cmp_common_coop_wait_skip,
out_func = cmp_common_coop_wait_out,
hint_bar_y = nil,
},
}
----------------------------------------------------------------
-- Common Screen functions
----------------------------------------------------------------
-- Hint bar
function cmp_common_hint_bar_move(x,y)
Cmp_hintbar:set_anchor(x,y)
end
function cmp_common_hint_bar_show()
--Move hintbar
--Get values from the hintbar and screen type table...
local x, y = Cmp_hintbar:get_anchor()
y = Cmp_screens[Cmp_screen_idx].hint_bar_y
Cmp_hintbar:set_anchor(x,y)
local anim_h = vint_object_find("hint_bar_out_anim", 0, Cmp_common_doc)
vint_set_property(anim_h, "is_paused", true)
local anim_h = vint_object_find("hint_bar_in_anim", 0, Cmp_common_doc)
lua_play_anim(anim_h, 0, Cmp_common_doc)
end
function cmp_common_hint_bar_hide()
local anim_h = vint_object_find("hint_bar_in_anim", 0, Cmp_common_doc)
vint_set_property(anim_h, "is_paused", true)
local anim_h = vint_object_find("hint_bar_out_anim", 0, Cmp_common_doc)
lua_play_anim(anim_h, 0, Cmp_common_doc)
end
--Plays the star power animation...
local Cmp_screen_star_power_screen = -1
function cmp_common_star_power_start()
--Only play the star power if we aren't playing already...
if Cmp_screen_star_power_screen ~= Cmp_screen_idx then
--Check if we aren't already playing for the screen
local anim_h = vint_object_find("star_explode_anim", 0, Cmp_common_doc)
lua_play_anim(anim_h, 0, Cmp_common_doc)
for i = 1, #Cmp_stars do
local h = vint_object_find(Cmp_stars[i], 0, Cmp_common_doc)
local scale = rand_float(0.7, 1.1)
local rotation = rand_float(0.1,0.3)
local rotation_og = vint_get_property(h, "rotation")
vint_set_property(h, "scale", scale, scale)
vint_set_property(h, "rotation", rotation_og)
end
Cmp_screen_star_power_screen = Cmp_screen_idx
end
end
--Exit screen
function cmp_common_exit()
--Tell game that we are done with the completion screen...
completion_screen_finished()
end
----------------------------------------------------------------
-- Input Processing
----------------------------------------------------------------
function cmp_process_input(event, acceleration)
--only allow input if input isn't blocked...
if Cmp_common_input_is_blocked == false then
--Only process input if the screen has started...
if Cmp_screen_sequence_started then
if event == "select" then
cmp_common_screen_advance(false)
elseif event == "map" then
--If we are waiting on the coop screen the bring up the dialog box...
if Cmp_screen_coop_is_waiting then
cmp_common_coop_wait_dialog()
end
elseif event == "back" then
--Do nothing...
--cmp_common_screen_advance()
else
--Do nothing...
end
end
end
end
----------------------------------------------------------------
-- Camera Shake...
--
-- @di_param x Horizontal offset
-- @di_param y Vertical offset
----------------------------------------------------------------
function cmp_common_camera_shake_update(di_h)
local x, y = vint_dataitem_get(di_h)
local screen_h = vint_object_find("screen_grp", 0, Cmp_common_doc)
--Invert parameters and multiply by 2, then add to base position...
x = Cmp_screen_base_x + (x * -1)
y = Cmp_screen_base_y + (y * -1)
vint_set_property(screen_h, "anchor", x, y)
end
----------------------------------------------------------------
-- Wrappers for C Based functions...
----------------------------------------------------------------
--Wrapper for c++ camera shake function...
function cmp_common_camera_shake(shake_type)
completion_camera_shake()
end
--Wrapper for c++ lut swap function...
function cmp_common_lut_effect(lut_table_string)
if lut_table_string ~= CMP_LUT_DEFAULT then
local platform = game_get_platform()
local lut_platform_string = ""
if platform == "PS3" then
lut_platform_string = "_ps3"
elseif platform == "XBOX360" then
lut_platform_string = "_xbox2"
elseif platform == "PC" then
lut_platform_string = "_pc"
end
completion_load_lut(lut_table_string .. lut_platform_string)
else
completion_load_lut(lut_table_string)
end
end
function cmp_common_bitmap_loaded()
end
-------------------------------------------------------------------
-- AUDIO
-------------------------------------------------------------------
--Callbacks for audio placed directly on tweens...
function cmp_audio_cb_enable()
--In order of appearance...
--Title Slam... ("title_in_anim")
local twn_h = vint_object_find("title_slam_audio_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_audio_mission_complete")
--Title music... ("title_in_anim")
local twn_h = vint_object_find("title_slam_music_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "duration", 0.133332 +.03) --force duration to get music timed perfectly with slam...
vint_set_property(twn_h, "end_event", "cmp_audio_music")
--Cash Standard slam...("cash_anim_in")
local twn_h = vint_object_find("cash_audio_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_audio_cash_slam")
--Cash Bonus slam...("cash_bonus_anim_in")
local twn_h = vint_object_find("cash_bonus_audio_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_audio_cash_bonus_slam")
--Respect Slam
local twn_h = vint_object_find("respect_audio_slam_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_audio_respect_slam")
--Respect Bonus Slam
local twn_h = vint_object_find("respect_audio_bonus_slam_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_audio_respect_bonus_slam")
--Control Slam
local twn_h = vint_object_find("control_audio_slam_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_audio_control_slam")
--Control Cash Slam
local twn_h = vint_object_find("control_cash_audio_slam_twn", 0, Cmp_common_doc)
vint_set_property(twn_h, "end_event", "cmp_audio_control_cash_slam")
end
--Slams...
function cmp_audio_mission_complete()
game_UI_audio_play("UI_Completion_Mission_Complete")
end
function cmp_audio_cash_slam()
game_UI_audio_play("UI_Completion_Cash_Slam")
end
function cmp_audio_cash_bonus_slam()
game_UI_audio_play("UI_Completion_Cash_Bonus_Slam")
end
function cmp_audio_respect_slam()
game_UI_audio_play("UI_Completion_Respect_Slam")
end
function cmp_audio_respect_bonus_slam()
game_UI_audio_play("UI_Completion_Respect_Bonus_Slam")
end
function cmp_audio_control_slam()
game_UI_audio_play("UI_Completion_Respect_Slam")
end
function cmp_audio_control_cash_slam()
game_UI_audio_play("UI_Completion_Respect_Bonus_Slam")
end
--Ramps...
function cmp_audio_cash_ramp_no_multiplier()
--CashRamLong 2sec 09 frames...
Cmp_common_audio_ramp_id = game_UI_audio_play("UI_Completion_Cash_Ramp")
end
function cmp_audio_cash_ramp_multiplier()
--short Cash Ramp
Cmp_common_audio_ramp_id = game_UI_audio_play("UI_Completion_Cash_Ramp_Base")
end
function cmp_audio_cash_bonus_ramp()
--Bonus Ramp...
Cmp_common_audio_ramp_id = game_UI_audio_play("UI_Completion_Cash_Ramp_Bonus")
end
function cmp_audio_respect_ramp_no_multiplier()
--respect ramp full 3
Cmp_common_audio_ramp_id = game_UI_audio_play("UI_Completion_Respect_Ramp")
end
function cmp_audio_respect_ramp_multiplier()
--respect ramp base 1sec 22...
Cmp_common_audio_ramp_id = game_UI_audio_play("UI_Completion_Respect_Ramp_Base")
end
function cmp_audio_respect_bonus_ramp()
--respect ramp Bonus 1sec 14...
Cmp_common_audio_ramp_id = game_UI_audio_play("UI_Completion_Respect_Ramp_Bonus")
end
function cmp_audio_control_ramp()
--respect ramp Bonus 1sec 14...
Cmp_common_audio_ramp_id = game_UI_audio_play("UI_Completion_Respect_Ramp_Bonus")
end
function cmp_audio_music()
Cmp_common_audio_music_id = game_audio_play("UI_Music", "UI_Music", "Mission_Completion")
end
function cmp_audio_stop_ramp()
game_audio_stop(Cmp_common_audio_ramp_id)
end
function cmp_common_mouse_click(event, target_handle)
if target_handle == Cmp_bg_image.handle then
if Cmp_screen_coop_is_waiting == true then
cmp_process_input("back")
else
cmp_process_input("select")
end
end
end
function cmp_common_mouse_move(event, target_handle)
end
-------------------------------------------------------------------------------
-- Sets up the screen for right justification
-------------------------------------------------------------------------------
function cmp_common_right_justification()
--Adjust base screen coords
Cmp_screen_base_x = 25
Cmp_screen_base_y = -100
--If standard definition we need to adjust some more even...
if vint_is_std_res() then
Cmp_screen_base_x = -50
Cmp_screen_base_y = -75
end
local global_conversion_table = {
--Screen Group Rotation...
{
name = "screen_grp",
prop = "rotation",
val_1 = 0.13962634, -- 8 degrees.
},
--Shift screen around...
{
name = "screen_grp",
prop = "anchor",
val_1 = Cmp_screen_base_x,
val_2 = Cmp_screen_base_y,
}
}
local title_converstion_table = {
--Title Alignments
{
name = "complete_txt",
prop = "auto_offset",
val_1 = "ne",
},
{
name = "title_txt",
prop = "auto_offset",
val_1 = "ne",
},
{
name = "title_txt",
prop = "horz_align",
val_1 = "right",
},
--Title Tweens
{
name = "title_in_twn",
prop = "start_value_x",
val_1 = -20,
},
{
name = "complete_txt_slide_twn",
prop = "start_value_x",
val_1 = -20,
},
--End position overrides...
{
name = "title_in_twn",
prop = "end_value_x",
val_1 = 647.0,
},
}
local cash_conversion_table = {
--Cash Alignments
{
name = "cash_txt",
prop = "auto_offset",
val_1 = "ne",
},
{
name = "cash_bonus_txt",
prop = "auto_offset",
val_1 = "ne",
},
{
name = "cash_amount_txt",
prop = "auto_offset",
val_1 = "ne",
},
--Cash Tweens
{
name = "cash_amount_slide_twn",
prop = "start_value_x",
val_1 = -20,
},
{
name = "cash_slam_twn",
prop = "start_value_x",
val_1 = -20,
},
{
name = "cash_bonus_slam_twn",
prop = "start_value_x",
val_1 = -20,
},
--End position overrides
{
name = "cash_amount_slide_twn",
prop = "end_value_x",
val_1 = 646,
},
{
name = "cash_slam_twn",
prop = "end_value_x",
val_1 = 646,
},
}
local respect_conversion_table = {
--Respect Alignments
{
name = "respect_bonus_txt",
prop = "auto_offset",
val_1 = "ne",
},
{
name = "respect_txt",
prop = "auto_offset",
val_1 = "ne",
},
--Respect Tweens Start
{
name = "respect_slam_twn",
prop = "start_value_x",
val_1 = -20,
},
{
name = "respect_txt_twn",
prop = "start_value_x",
val_1 = -20,
},
{
name = "respect_bonus_twn",
prop = "start_value_x",
val_1 = -20,
},
--Respect Tweens End
{
name = "respect_slam_twn",
prop = "end_value_x",
val_1 = 600,
},
{
name = "respect_txt_twn",
prop = "end_value_x",
val_1 = 470,
},
{
name = "respect_bonus_twn",
prop = "end_value_x",
val_1 = 472,
},
}
local control_conversion_table = {
--Control Alignments
{
name = "control_cash_txt",
prop = "auto_offset",
val_1 = "ne",
},
{
name = "control_txt",
prop = "horz_align",
val_1 = "right",
},
{
name = "control_txt",
prop = "auto_offset",
val_1 = "ne",
},
--Control Tweens Start
{
name = "control_slam_twn",
prop = "start_value_x",
val_1 = -20,
},
{
name = "control_txt_twn",
prop = "start_value_x",
val_1 = -20,
},
{
name = "control_cash_twn",
prop = "start_value_x",
val_1 = -20,
},
--Control Tweens End
{
name = "control_slam_twn",
prop = "end_value_x",
val_1 = 600,
},
{
name = "control_txt_twn",
prop = "end_value_x",
val_1 = 470,
},
{
name = "control_cash_twn",
prop = "end_value_x",
val_1 = 472,
},
}
local conversion_tables = {
global_conversion_table,
title_converstion_table,
cash_conversion_table,
respect_conversion_table,
control_conversion_table,
}
local h
local value_1, value_2
--Loop through all the conversion tables
for i, conversion_table in pairs(conversion_tables) do
--Get specific conversion table
for idx, val in pairs(conversion_table) do
--Go through each item and start converting properties...
h = vint_object_find(val.name, 0, Cmp_common_doc)
local prop = val.prop
if h ~= 0 then
--Check for "special properties" so we can maintain variables on certain vectors.
if prop == "start_value_x" then
local x, y = vint_get_property(h, "start_value")
vint_set_property(h, "start_value", val.val_1, y)
elseif prop == "end_value_x" then
local x, y = vint_get_property(h, "end_value")
vint_set_property(h, "end_value", val.val_1, y)
elseif prop == "anchor" then
vint_set_property(h, "anchor", val.val_1, val.val_2)
else
vint_set_property(h, val.prop, val.val_1)
end
else
--can't find object...
debug_print("vint", "Item in conversion table is missing\n")
end
end
end
--Shift button hint over...
local x, y = Cmp_hintbar:get_anchor()
local width, height = Cmp_hintbar:get_size()
Cmp_hintbar:set_anchor(x - width - 15, y)
end
function cmp_common_bg_saints_show(is_visible, delay)
if Cmp_common_bg_saints_active ~= true then
--ignore this function if we are not active...
return
end
local delay_time = 0
if delay then
delay_time = .5
end
local bg_saints_fade_anim_h = vint_object_find("bg_saints_fade_anim", 0, Cmp_common_doc)
local bg_saints_fade_twn_h = vint_object_find("bg_saints_fade_twn", 0, Cmp_common_doc)
local start_value, end_value = 1, 0
if is_visible then
start_value = 0
end_value = 1
end
vint_set_property(bg_saints_fade_twn_h, "start_value", start_value)
vint_set_property(bg_saints_fade_twn_h, "end_value", end_value)
lua_play_anim(bg_saints_fade_anim_h, delay_time)
end
-------------------------------------------------------------------------------
-- Callback for when we have our completion image fully loaded...
--
function cmp_common_image_loaded()
--image is loaded...
local img_grp_h = vint_object_find("img_grp", 0, Cmp_common_doc)
--replace all 4 images...
for i = 1, 4 do
local screen_image_h = vint_object_find("screen_image_" .. i, 0, Cmp_common_doc)
vint_set_property(screen_image_h, "image", Cmp_image)
end
Cmp_common_has_image = true
end
function cmp_common_image_fade_out()
if Cmp_common_has_image and Cmp_common_image_is_visible then
local image_fade_out_anim_h = vint_object_find("image_fade_out_anim", 0, Cmp_common_doc)
lua_play_anim(image_fade_out_anim_h, 0, Cmp_common_doc)
Cmp_common_image_is_visible = false
end
end
function cmp_common_input_block_delay()
Cmp_common_input_is_blocked = true
if Cmp_common_input_delay_thread ~= -1 then
thread_kill(Cmp_common_input_delay_thread)
end
if Cmp_common_input_delay_thread == -1 then
Cmp_common_input_delay_thread = thread_new("cmp_common_input_block_thread")
end
end
function cmp_common_input_block_thread()
delay(.75)
Cmp_common_input_is_blocked = false
Cmp_common_input_delay_thread = -1
end
--Debug stuff put in for jon bruer JMH(3/24/2011)
function cmp_bg_hide()
local h = vint_object_find("background_base")
vint_set_property(h, "visible", false)
end