-- These are for the 9 buttons on the cellphone.
ID_INVALID = -2
ID_MAIN = -1
ID_MAP = 0
ID_MISSIONS = 1
ID_SAINTSBOOK = 2
ID_REWARDS = 3
ID_MUSIC = 4
ID_CAMERA = 5
ID_PHONE = 6
ID_CASH = 7
ID_EXTRAS = 8
PING_RED = 300
PING_GREEN = 150
Cell_foreground_doc = -1
Cell_background_doc = -1
Cell_foreground_h = 0
Cell_background_h = 0
Pause_map_from_menu = false --Are we coming from the cell_menu_main or directly from game?
Rewards_from_menu = false --Are we coming from the cell_menu_main or directly from game?
Missions_from_menu = false --Are we coming from the cell_menu_main or directly from game?
--Transtition Enums...
CELL_TRANSITION_INVALID = 0
CELL_TRANSITION_IN_PORTRAIT = 1 --set to portrait
CELL_TRANSITION_IN_LANDSCAPE = 2 --set to landscape
CELL_TRANSITION_OUT_PORTRAIT = 3 --transition out to portrait
CELL_TRANSITION_OUT_LANDSCAPE = 4 --transition out to landscape
CELL_STATE_INVALID = 0
CELL_STATE_START = 1
CELL_STATE_OUT = 2
CELL_STATE_PORTRAIT = 3
CELL_STATE_LANDSCAPE = 4
CELL_STATE_START_PORTRAIT = 5
CELL_STATE_START_LANDSCAPE = 6
CELL_STATE_OUT_PORTRAIT = 7
CELL_STATE_OUT_LANDSCAPE = 8
CELL_TYPE_LANDSCAPE = 1
CELL_TYPE_PORTRAIT = 2
local Ping_thread_h = 0
local Cell_current_state = CELL_STATE_START
Cell_transition_cb_func = -1
--This is a seperate enum because the ID_* enums does not have every screen in the phone...
CELL_SCREEN_NONE = 0
CELL_SCREEN_MAIN = 1
CELL_SCREEN_MAP = 2
CELL_SCREEN_MISSIONS = 3
CELL_SCREEN_SAINTSBOOK = 4
CELL_SCREEN_REWARDS = 5
CELL_SCREEN_MUSIC = 6
CELL_SCREEN_MUSIC_SUB = 7
CELL_SCREEN_PLAYLIST = 8
CELL_SCREEN_CAMERA = 9
CELL_SCREEN_PHONE = 10
CELL_SCREEN_EXTRAS = 11
CELL_SCREEN_CHEATS = 12
CELL_SCREEN_STATS = 13
CELL_SCREEN_CASH =14
-- Table is used to define screen types.
-- Allows us to store the type of screen it is, document name and target element.
-- This allows us to make any kind of transtion to a particular screen.
-- Screen type is either CELL_TYPE_LANDSCAPE (screens designed to be wide) or CELL_TYPE_PORTRAIT (screens in vertical orientation.
local Cell_menu_types = {
--Screen ID defined above Screen Type Document Name First element of the group
[CELL_SCREEN_NONE] = {nil, nil, nil}, --This is used so we can transition to nothing...
[CELL_SCREEN_MAIN] = {CELL_TYPE_PORTRAIT, "cell_menu_main", "cell_menu_grp"},
[CELL_SCREEN_MAP] = {CELL_TYPE_LANDSCAPE, "pause_map", "map_all_grp"},
[CELL_SCREEN_MISSIONS] = {CELL_TYPE_PORTRAIT, "cell_missions", "missions_grp"},
[CELL_SCREEN_SAINTSBOOK] = {CELL_TYPE_LANDSCAPE, "cell_saintsbook", "saintsbook_grp"},
[CELL_SCREEN_REWARDS] = {CELL_TYPE_LANDSCAPE, "cell_rewards", "rewards_base_grp"},
[CELL_SCREEN_MUSIC_SUB] = {CELL_TYPE_PORTRAIT, "cell_music_sub", "cell_menu_grp"},
[CELL_SCREEN_MUSIC] = {CELL_TYPE_LANDSCAPE, "cell_music_menu", "station_group"},
[CELL_SCREEN_PLAYLIST] = {CELL_TYPE_LANDSCAPE, "cell_playlist", "playlist_grp"},
[CELL_SCREEN_CAMERA] = {CELL_TYPE_PORTRAIT, "cell_camera", "camera_grp"},
[CELL_SCREEN_PHONE] = {CELL_TYPE_PORTRAIT, "cell_phone", "phone_grp"},
[CELL_SCREEN_EXTRAS] = {CELL_TYPE_PORTRAIT, "cell_extras", "cell_menu_grp"},
[CELL_SCREEN_CHEATS] = {CELL_TYPE_PORTRAIT, "cell_cheats", "cheats_grp"},
[CELL_SCREEN_STATS] = {CELL_TYPE_LANDSCAPE, "cell_stats", "stats_grp"},
[CELL_SCREEN_CASH] = {CELL_TYPE_PORTRAIT, "store_crib_cash", "cell_bonus_grp"},
}
-- Positions, rotation and scale values for screens in HD
local Cell_states = {
[CELL_TYPE_PORTRAIT] = {
[CELL_STATE_START_PORTRAIT] = {x = 1000, y = 1300, r = (45 * DEG_TO_RAD), s = 1.0},
[CELL_STATE_START_LANDSCAPE] = {x = 1000, y = 1300, r = (-45 * DEG_TO_RAD), s = 1.5},
[CELL_STATE_PORTRAIT] = {x = 640, y = 360, r = (0 * DEG_TO_RAD), s = 1.0},
[CELL_STATE_LANDSCAPE] = {x = 640, y = 360, r = (-90 * DEG_TO_RAD), s = 1.5},
[CELL_STATE_OUT_PORTRAIT] = {x = 1000, y = 1300, r = (45 * DEG_TO_RAD), s = 1.0},
[CELL_STATE_OUT_LANDSCAPE] = {x = 1000, y = 1300, r = (-45 * DEG_TO_RAD), s = 1.5},
},
[CELL_TYPE_LANDSCAPE] = {
[CELL_STATE_START_PORTRAIT] = {x = 1000, y = 1300, r = (135 * DEG_TO_RAD), s = .65},
[CELL_STATE_START_LANDSCAPE] = {x = 1000, y = 1300, r = (45 * DEG_TO_RAD), s = 1.0},
[CELL_STATE_PORTRAIT] = {x = 640, y = 360, r = (90 * DEG_TO_RAD), s = .65},
[CELL_STATE_LANDSCAPE] = {x = 640, y = 360, r = (0 * DEG_TO_RAD), s = 1.0},
[CELL_STATE_OUT_PORTRAIT] = {x = 1000, y = 1300, r = (135 * DEG_TO_RAD), s = .65},
[CELL_STATE_OUT_LANDSCAPE] = {x = 1000, y = 1300, r = (45 * DEG_TO_RAD), s = 1.0},
},
}
--Initialize
function cell_foreground_init()
if vint_is_std_res() then
-- Positions, rotation and scale values for screens in SD
for idx, val in pairs(Cell_states) do
for idx2, val2 in pairs(val) do
if val2.x == 640 then
val2.x = 320
elseif val2.x == 1000 then
val2.x = 700
end
if val2.y == 360 then
val2.y = 240
elseif val2.y == 1300 then
val2.y = 900
end
val2.s = val2.s *.667 *.9
end
end
end
Cell_foreground_doc = vint_document_find("cell_foreground")
Cell_background_doc = vint_document_find("cell_background")
Cell_foreground_h = vint_object_find("screen_grp", 0, Cell_foreground_doc)
Cell_background_h = vint_object_find("screen_grp", 0, Cell_background_doc)
local ping_grp_h = vint_object_find("ping_grp", 0, Cell_foreground_doc)
local top_icons_h = vint_object_find("top_icons", 0, Cell_foreground_doc)
vint_set_property(ping_grp_h, "visible", false)
if game_get_platform() == "PC" then
if coop_is_active() == true then
vint_set_property(top_icons_h, "visible", false)
vint_set_property(ping_grp_h, "visible", true)
-- poll the ping every 2 seconds until the cell phone is closed
Ping_thread_h = thread_new("cell_foreground_ping_thread")
end
end
--Hide all elements to start out with...
vint_set_property(Cell_foreground_h, "visible", false)
vint_set_property(Cell_background_h, "visible", false)
local bg_loop = Vdo_anim_object:new("bg_loop", 0, Cell_background_doc)
bg_loop:play(0)
-- set up data items for player status
vint_dataitem_add_subscription("sr2_local_player_respect", "update", "cell_foreground_respect_update")
vint_dataitem_add_subscription("sr2_local_player_status_infrequent", "update", "cell_foreground_cash_update")
end
--Cleanup
function cell_foreground_cleanup()
thread_kill(Ping_thread_h)
Ping_thread_h = 0
end
--DELETE THIS..
function cell_foreground_set_state()
end
-------------------------------------------------------------------------------
-- Transitions the cellphone screen to next
--
-- @transition_type transition type... (CELL_TRANSITION_IN_LANDSCAPE)
-- @doc_name "document name"
-- @doc_name "base_name"
--
-- transition_type, "pause_map", "map_all_grp",
--cell_transition_screen(CELL_TYPE_LANDSCAPE, CELL_STATE_LANDSCAPE, "pause_map", "map_all_grp", pause_map_trans_in_complete)
function cell_transition_screen(target_state, screen1, screen2, callback_func)
local screen_1_data = Cell_menu_types[screen1]
local screen_2_data = Cell_menu_types[screen2]
local transition_screens = {
[1] = {screen_type = screen_1_data[1], doc_name = screen_1_data[2], base_name = screen_1_data[3]},
[2] = {screen_type = CELL_TYPE_LANDSCAPE, doc_name = "cell_foreground", base_name = "cell_frame_grp"},
[3] = {screen_type = CELL_TYPE_PORTRAIT, doc_name = "cell_background", base_name = "cell_bg_grp"},
[4] = {screen_type = screen_2_data[1], doc_name = screen_2_data[2], base_name = screen_2_data[3]}
}
if screen1 == nil or screen2 == nil then
--ABORT: attempt to do whack transition...
debug_print("vint", "No valid screen set for cell_transition_screen(). screen1 or screen2: " .. var_to_string(screen1) .. "\n")
return
end
--Special case for cell rewards... needs to have an extra document transition...
if screen1 == CELL_SCREEN_REWARDS or screen2 == CELL_SCREEN_REWARDS then
transition_screens[5] = {screen_type = CELL_TYPE_LANDSCAPE, doc_name = "store_common", base_name = "cell_rotate_grp"}
--Also needs to reset scale of store common because it gets overriden.
local store_common_doc_h = vint_document_find("store_common")
local h = vint_object_find("screen_grp", 0, store_common_doc_h)
vint_set_property(h, "scale", 1,1)
end
local twn_h
--This is used to ensure our callbacks context is called to the appropriate document.
local transition_callback_idx = 1
if screen1 == CELL_SCREEN_NONE then
-- If screen is none this means we are exiting the phone,
-- Our function callback should happen in the context of the screen we are exiting from...
transition_callback_idx = 2
end
for idx, screen in pairs(transition_screens) do
if screen.screen_type ~= nil then
--Screen transitions...
local doc_h = vint_document_find(screen.doc_name)
local target_h = vint_object_find(screen.base_name, 0, doc_h)
--Animation we use as the base(anchor, rotation, scale)
local anim_h = vint_object_find("transition_element_anim", 0, Cell_background_doc)
local anim_clone_h = vint_object_clone(anim_h)
local root_anim_h = vint_object_find("root_animation", 0, doc_h)
vint_object_set_parent(anim_clone_h, root_anim_h)
local anchor_twn_h = vint_object_find("anchor_twn", anim_clone_h)
local rotation_twn_h = vint_object_find("rotation_twn", anim_clone_h)
local scale_twn_h = vint_object_find("scale_twn", anim_clone_h)
local start_state = Cell_current_state --start state is the last state saved...
local end_state = target_state --end state is the target state...
-- Do some translations for the start and end states...
-- If our state is starting then we need to figure out what type we should transition from.
-- This is to keep the size ratios the same all the way through...
if start_state == CELL_STATE_START then
if end_state == CELL_STATE_PORTRAIT then
start_state = CELL_STATE_START_PORTRAIT
else
start_state = CELL_STATE_START_LANDSCAPE
end
end
--We do the same for when we are transitioning out...
if end_state == CELL_STATE_OUT then
if start_state == CELL_STATE_PORTRAIT then
end_state = CELL_STATE_OUT_PORTRAIT
else
end_state = CELL_STATE_OUT_LANDSCAPE
end
end
local start_data = table_clone(Cell_states[screen.screen_type][start_state])
local end_data = table_clone(Cell_states[screen.screen_type][end_state])
--Check to make sure we have valid states...
if start_data == nil or end_data == nil then
debug_print("vint", "invalid target_state: " .. var_to_string(target_state) .. "\n")
debug_print("vint", "invalid screen_type: " .. var_to_string(screen.screen_type) .. "\n")
return
end
--Set target handle of our cloned tweens.
vint_set_property(anchor_twn_h, "target_handle", target_h)
vint_set_property(rotation_twn_h,"target_handle", target_h)
vint_set_property(scale_twn_h, "target_handle", target_h)
--Set callback so we know we are completed and can cleanup the tweens.
--Additionally, the callback will call our sent in callback function.
if idx == transition_callback_idx then
-- only setup the action callback for the screen we are transitioning to...
-- this is to maintain vint context of the lua function call to that document.
vint_set_property(anchor_twn_h, "end_event", "cell_transition_action_cb")
else
--callback to make sure we cleanup the animation when we are finished.
vint_set_property(anchor_twn_h, "end_event", "cell_transition_delete_cb")
end
--Get and set properties based on our start/end data.
vint_set_property(anchor_twn_h, "start_value", start_data.x, start_data.y)
vint_set_property(anchor_twn_h, "end_value", end_data.x, end_data.y)
vint_set_property(rotation_twn_h, "start_value", start_data.r)
vint_set_property(rotation_twn_h, "end_value", end_data.r)
vint_set_property(scale_twn_h, "start_value", start_data.s, start_data.s)
vint_set_property(scale_twn_h, "end_value", end_data.s, end_data.s)
if end_state == CELL_STATE_OUT_PORTRAIT or end_state == CELL_STATE_OUT_LANDSCAPE then
vint_set_property(anchor_twn_h, "algorithm", "ease_out_quart")
vint_set_property(rotation_twn_h,"algorithm", "ease_out_quart")
vint_set_property(scale_twn_h, "algorithm", "ease_out_quart")
end
-- Play animation...
vint_apply_start_values(anim_clone_h)
lua_play_anim(anim_clone_h, 0, doc_h)
--Play incomming screens transition animation
if idx == 1 then
--Pause out animation
local trans_out_anim_h = vint_object_find("trans_out_anim", 0, doc_h)
if trans_out_anim_h ~= 0 then
vint_set_property(trans_out_anim_h, "is_paused", true)
end
--Play in animation...
local trans_in_anim_h = vint_object_find("trans_in_anim", 0, doc_h)
if trans_in_anim_h ~= 0 then
lua_play_anim(trans_in_anim_h, 0, doc_h)
end
if screen1 == CELL_SCREEN_MAIN or screen1 == CELL_SCREEN_EXTRAS or screen1 == CELL_SCREEN_MUSIC_SUB then
--need to play hide top bar anim...
if start_state ~= end_state then
if end_state == CELL_STATE_PORTRAIT then
--fade in header
cell_foreground_fade_in_header()
else
--fade out header
cell_foreground_fade_out_header()
end
end
end
end
if idx == 3 then
local bg_rotate_h = vint_object_find("bg_rotate",0,Cell_background_doc)
--bg rotation over ride
if start_state ~= end_state then
if (start_state == CELL_STATE_LANDSCAPE or start_state == CELL_STATE_START_PORTRAIT) and end_state == CELL_STATE_PORTRAIT then
vint_set_property(bg_rotate_h, "rotation", (-35 * DEG_TO_RAD))
elseif (start_state == CELL_STATE_PORTRAIT or start_state == CELL_STATE_START_LANDSCAPE) and end_state == CELL_STATE_LANDSCAPE then
vint_set_property(bg_rotate_h, "rotation", (55 * DEG_TO_RAD))
end
end
end
--Play outgoing screens transition animation
if idx == 4 then
--Pause in animation
local trans_in_anim_h = vint_object_find("trans_in_anim", 0, doc_h)
if trans_in_anim_h ~= 0 then
vint_set_property(trans_in_anim_h, "is_paused", true)
end
--Play out animation
local trans_out_anim_h = vint_object_find("trans_out_anim", 0, doc_h)
if trans_out_anim_h ~= 0 then
lua_play_anim(trans_out_anim_h, 0, doc_h)
end
if screen2 == CELL_SCREEN_MAIN or screen2 == CELL_SCREEN_EXTRAS or screen2 == CELL_SCREEN_MUSIC_SUB then
--need to play hide top bar anim...
if start_state ~= end_state then
if screen.end_state == CELL_STATE_PORTRAIT then
--fade in header
cell_foreground_fade_in_header()
else
--fade out header
cell_foreground_fade_out_header()
end
end
end
end
--PLAY AUDIO
if idx == 1 then
if start_state == CELL_STATE_LANDSCAPE and end_state == CELL_STATE_PORTRAIT then
game_UI_audio_play("UI_Cell_Switch_Horizontal")
elseif start_state == CELL_STATE_PORTRAIT and end_state == CELL_STATE_LANDSCAPE then
game_UI_audio_play("UI_Cell_Switch_Vertical")
end
end
end
end
--Store callback function to global
if callback_func ~= nil then
Cell_transition_cb_func = callback_func
else
Cell_transition_cb_func = -1
end
--Store current state.
Cell_current_state = target_state
end
function cell_foreground_cash_update(di_h)
local cash = vint_dataitem_get(di_h)
local cash_txt = Vdo_base_object:new("cash",0, Cell_foreground_doc)
cash_txt:set_text("$" .. format_cash(cash))
end
function cell_foreground_respect_update(di_h)
local respect_total, respect_needed, respect_level, show_upgrades = vint_dataitem_get(di_h)
local respect_txt = Vdo_base_object:new("respect",0, Cell_foreground_doc)
respect_txt:set_text(respect_level + 1)
end
-------------------------------------------------------------------------------
-- Callback functions for tweens.
-- 1. Destroys its parent anim.
--
function cell_transition_delete_cb(tween_h)
vint_object_destroy(vint_object_parent(tween_h))
end
-- Callback functions for tweens.
-- 1. Destroys its parent anim.
-- 2. Does callback that was stored in the global from our last transition.
-- 3. Wipes the callback out so other tweens don't call it.
function cell_transition_action_cb(tween_h)
vint_object_destroy(vint_object_parent(tween_h))
--Do cell transition callback if it exists the reset it.
if Cell_transition_cb_func ~= -1 then
Cell_transition_cb_func()
Cell_transition_cb_func = -1
end
end
-------------------------------------------------------------------------------
-- Fades in the header(battery, power)
--
function cell_foreground_fade_in_header()
lua_play_anim(vint_object_find("in_header_anim", 0, Cell_foreground_doc), 0, Cell_foreground_doc)
end
-------------------------------------------------------------------------------
-- Fades out the header(battery, power)
--
function cell_foreground_fade_out_header()
lua_play_anim(vint_object_find("out_header_anim", 0, Cell_foreground_doc), 0, Cell_foreground_doc)
end
function cell_show_frame()
vint_set_property(Cell_foreground_h, "visible", true)
vint_set_property(Cell_background_h, "visible", true)
end
-------------------------------------------------------------------------------
-- Get ping every 2 seconds until cell phone is closed
--
function cell_foreground_ping_thread()
while true do
cell_forground_set_ping(game_get_coop_ping())
delay(2)
end
end
-------------------------------------------------------------------------------
-- Sets connection strength for coop PC
--
function cell_forground_set_ping(ping)
local ping_grp_h = vint_object_find("ping_grp", 0 , Cell_foreground_doc)
local ping_txt_h = vint_object_find("ping_txt", 0, Cell_foreground_doc)
local bars = {}
local num_bars = 0
local color = COLOR_PING_GREY
vint_set_property(ping_txt_h, "text_tag", ping.." ms ")
-- turn all bars "off"
for i = 1, 5 do
local h = vint_object_find("bar_img_"..i, ping_grp_h, Cell_foreground_doc)
vint_set_property(h, "alpha", .33)
bars[i] = h
end
-- determing how many bars and what color to show
if ping <= PING_GREEN then
if ping < 100 then
num_bars = 5
else
num_bars = 4
end
color = COLOR_PING_GREEN
elseif ping > PING_GREEN and ping < PING_RED then
num_bars = 3
color = COLOR_PING_YELLOW
else
if ping < 400 then
num_bars = 2
else
num_bars = 1
end
color = COLOR_PING_RED
if ping > 999 then
vint_set_property(ping_txt_h, "text_tag", "999 ms ")
end
end
-- turn bars "on"
for i = 1, num_bars do
vint_set_property(bars[i], "alpha", 1)
end
--set color and show grp
vint_set_property(ping_grp_h,"tint", color.R, color.G, color.B)
vint_set_property(ping_grp_h,"visible", true)
end