local Data = { }
Num_items = 0
--Input Trackers...
local Input_tracker = -1
local Input_tracker_garage = -1
local Input_tracker_call = -1
local Mouse_input_tracker = -1
local Mouse_input_tracker_garage = -1
local Mouse_input_tracker_garage_hint = -1
local Mouse_input_tracker_call = -1
local List = nil
local Call_grp
local Cell_phone_handle = -1
local MOUSE_INVALID_HANDLE = -1
local Homie_data = {}
local Homie_data_cur_idx = 1
local HOMIE_MAX_ITEMS = 5
local Book_screen_is_scrolling = false
local Hint_bar = -1
local Garage_hint_bar = -1
local Visible_start_idx = 1
local Visible_end_idx = HOMIE_MAX_ITEMS
local Prev_y = -1
CELL_PHONE_BOOK_MAX_WIDTH_LABEL = 224 --Max label width for the phone
CELL_PHONE_CALL_MAX_WIDTH_LABEL = 259 --Max label width for the calling screen.
-- Enum to define which type of data to retrieve
local CELL_HOMIE_LIST = 0
local CELL_VEHICLE_LIST = 1
--Connection States
local CELL_CALL_INVALID = -1
local CELL_CALL_CONNECTED = 0
local CELL_CALL_GARAGE_SHOW = 1
--Hangup states
local CELL_CALL_HANGUP = 0
local CELL_CALL_RETURN_TO_PHONE = 1
--Transition enums...
local CELL_MENU_TRANS_NONE = 0
local CELL_MENU_TRANS_LEFT = 1
local CELL_MENU_TRANS_RIGHT = 2
-- Enums for pages on the phone...
local CELL_PHONE_MENU_BOOK = 1
local CELL_PHONE_MENU_GARAGE = 2
local CELL_PHONE_MENU_CALL = 3
--Layout constansts
local LIST_COLOR_HIGHLIGHT = COLOR_SAINTS_PURPLE
local LIST_COLOR_UNHIGHLIGHT = {R=80/255,G=80/255,B=80/255} --COLOR_PLAYER_CREATION_TERTIARY
local LIST_COLOR_DISABLED = {R=30/255,G=30/255,B=30/255}
local HOMIE_LIST_SPACING = 74 --Spacing between items
local GARAGE_LIST_WIDTH = 420 --Spacing between items
local Cell_menus = {}
local Menu_active = -1 --Active menu ID...
--Garage stuff
Garage_list = -1 --VDO reference to garage list
local Garage_list_data = {} --Data for garage list...
local GARAGE_LIST_MAX_BUTTONS = 8
local Cell_phone_cash = -1
local Scrollbar = -1
local Screen_start_x
local Screen_start_y
local Game_platform
local Current_menu = -1
local HOMIE_MENU = 0
local GARAGE_MENU = 1
local Highlight_btn = -1
local Cell_phone_gamepad_listener = -1
function cell_phone_init()
Cell_phone_handle = vint_document_find("cell_phone")
--Initialize list...
local contact_highlight_grp_h = vint_object_find("contact_highlight_grp")
local highlight_bg_h = vint_object_find("highlight_bg", contact_highlight_grp_h)
vint_set_property(highlight_bg_h, "tint", LIST_COLOR_HIGHLIGHT.R, LIST_COLOR_HIGHLIGHT.G, LIST_COLOR_HIGHLIGHT.B)
--Set button on contact list...
--if pc then hide ctrl button
Highlight_btn = Vdo_hint_button:new("highlight_btn", contact_highlight_grp_h)
Highlight_btn:set_button(CTRL_MENU_BUTTON_A)
--Set text for vehicle delivery
vint_set_property(vint_object_find("calling_info_txt_1"),"text_tag", "HOMIES_DRIVEUP")
--Set up title
local cell_title_h = Vdo_cell_title:new("cell_title", 0, Cell_phone_handle)
cell_title_h:set_text("MENU_PHONE")
cell_title_h:set_icon("ui_cell_icon_phone")
cell_title_h:play_dots_anim()
--Show screens...
local call_screen_grp_h = vint_object_find("call_screen_grp")
local book_screen_grp_h = vint_object_find("book_screen_grp")
local garage_screen_grp_h = vint_object_find("garage_screen_grp")
vint_set_property(call_screen_grp_h, "visible", false)
--vint_set_property(garage_screen_grp_h, "anchor", 0, -203)
vint_set_property(garage_screen_grp_h, "visible", false)
vint_set_property(book_screen_grp_h, "visible", true)
Screen_start_x, Screen_start_y = vint_get_property(call_screen_grp_h, "anchor")
--Garage list init...
Garage_list = Vdo_mega_list:new("mega_list", 0, Cell_phone_handle, "cell_phone.lua", "Garage_list")
Garage_list:set_properties(LIST_COLOR_HIGHLIGHT, LIST_COLOR_UNHIGHLIGHT, 10, .8, GARAGE_LIST_WIDTH, false, true)
Garage_list:set_highlight_color(LIST_COLOR_HIGHLIGHT, LIST_COLOR_UNHIGHLIGHT)
-- Subscribe to the button presses we need...
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("nav_up", "cell_phone_book_nav_up", 50)
Input_tracker:add_input("nav_down", "cell_phone_book_nav_down", 50)
Input_tracker:add_input("back", "cell_phone_book_button_b", 50)
Input_tracker:add_input("select", "cell_phone_book_button_a", 50)
Input_tracker:add_input("map", "cell_phone_book_button_map", 50)
Input_tracker:subscribe(false)
--Input tracker for garage menu
Input_tracker_garage = Vdo_input_tracker:new()
Input_tracker_garage:add_input("nav_up", "cell_phone_garage_nav_up", 50)
Input_tracker_garage:add_input("nav_down", "cell_phone_garage_nav_down", 50)
Input_tracker_garage:add_input("back", "cell_phone_garage_button_b", 50)
Input_tracker_garage:add_input("select", "cell_phone_garage_button_a", 50)
Input_tracker_garage:add_input("map", "cell_phone_garage_map", 50)
Input_tracker_garage:subscribe(false)
--Input tracker for garage menu
Input_tracker_call = Vdo_input_tracker:new()
Input_tracker_call:add_input("nav_up", "cell_phone_call_input", 50)
Input_tracker_call:add_input("nav_down", "cell_phone_call_input", 50)
Input_tracker_call:add_input("back", "cell_phone_call_input", 50)
Input_tracker_call:add_input("select", "cell_phone_call_input", 50)
Input_tracker_call:add_input("map", "cell_phone_call_input", 50)
Input_tracker_call:subscribe(false)
--Init scrollbar...
Scrollbar = Vdo_scrollbar:new("book_scrollbar")
Scrollbar:set_highlight_color(LIST_COLOR_HIGHLIGHT)
--Hint bar
Hint_bar = Vdo_hint_bar:new("hint_bar")
Garage_hint_bar = Vdo_hint_bar:new("garage_hint_bar")
local hints = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
Hint_bar:set_hints(hints)
Garage_hint_bar:set_hints(hints)
--setup call hintbar...
hints = {
{CTRL_MENU_BUTTON_A, "MENU_CONTINUE"},
}
Game_platform = game_get_platform()
local mouse_area_img_h = vint_object_find("mouse_area_img")
--create mouse input tracker and send it to the scrollbar vdo
if Game_platform == "PC" then
Mouse_input_tracker = Vdo_input_tracker:new()
Mouse_input_tracker_garage = Vdo_input_tracker:new()
Mouse_input_tracker_garage_hint = Vdo_input_tracker:new()
Mouse_input_tracker_call = Vdo_input_tracker:new()
Mouse_input_tracker:add_mouse_input("mouse_scroll", "cell_phone_mouse_scroll", 50, mouse_area_img_h)
Hint_bar:add_mouse_inputs("cell_phone", Mouse_input_tracker, 50)
Scrollbar:add_mouse_inputs("cell_phone",Mouse_input_tracker,50)
Garage_hint_bar:add_mouse_inputs("cell_phone",Mouse_input_tracker_garage_hint,50)
Mouse_input_tracker:subscribe(true)
Mouse_input_tracker_garage:subscribe(false)
Mouse_input_tracker_garage_hint:subscribe(false)
Mouse_input_tracker_call:subscribe(false)
end
--Setup object for our menu functions and handling input...
Cell_menus = {
[CELL_PHONE_MENU_BOOK] = {h = book_screen_grp_h, input_tracker = Input_tracker, mouse_input_tracker = Mouse_input_tracker, hint_input_tracker = nil},
[CELL_PHONE_MENU_GARAGE] = {h = garage_screen_grp_h, input_tracker = Input_tracker_garage, mouse_input_tracker = Mouse_input_tracker_garage, hint_input_tracker = Mouse_input_tracker_garage_hint},
[CELL_PHONE_MENU_CALL] = {h = call_screen_grp_h, input_tracker = Input_tracker_call, mouse_input_tracker = Mouse_input_tracker_call, hint_input_tracker = nil},
}
--Subscribe to player information for cash data
vint_dataitem_add_subscription("sr2_local_player_status_infrequent", "update", "cell_phone_cash_update")
-- Populate homie call list
vint_dataresponder_request("cell_phone_pad_populate", "cell_phone_populate_list", 0, CELL_HOMIE_LIST)
if #Homie_data == 0 then
-- No homie data... we need to abort this screen
debug_print("vint", "no homie data... cannot enter cellphone\n")
cell_phone_exit(false)
local safe_h = vint_object_find("safe_frame")
vint_set_property(safe_h, "visible", false)
return
end
-- Build Phonebook Screen
cell_phone_book_build()
--Transition the screen in...
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_PHONE, CELL_SCREEN_MAIN, cell_phone_menu_trans_in_complete)
if Game_platform == "PC" then
Cell_phone_gamepad_listener = vint_scriptevent_listen( "gamepad_active", "cell_phone_update_gamepad_state" )
end
end
function cell_phone_cleanup()
if Game_platform == "PC" then
vint_scriptevent_stop_listening( Cell_phone_gamepad_listener )
end
if Input_tracker ~= -1 then
Input_tracker:subscribe(false)
Input_tracker:remove_all()
end
if Input_tracker_garage ~= -1 then
Input_tracker_garage:subscribe(false)
Input_tracker_garage:remove_all()
end
if Input_tracker_call ~= -1 then
Input_tracker_call:subscribe(false)
Input_tracker_call:remove_all()
end
if Mouse_input_tracker ~= -1 then
Mouse_input_tracker:subscribe(false)
Mouse_input_tracker:remove_all()
end
if Mouse_input_tracker_garage ~= -1 then
Mouse_input_tracker_garage:subscribe(false)
Mouse_input_tracker_garage:remove_all()
end
if Mouse_input_tracker_garage_hint ~= -1 then
Mouse_input_tracker_garage_hint:subscribe(false)
Mouse_input_tracker_garage_hint:remove_all()
end
if Mouse_input_tracker_call ~= -1 then
Mouse_input_tracker_call:subscribe(false)
Mouse_input_tracker_call:remove_all()
end
end
function cell_phone_menu_trans_in_complete()
--Show homies menu...
cell_phone_menu_show(CELL_PHONE_MENU_BOOK)
end
--Transitions to a specific menu...
function cell_phone_menu_show(menu_id, direction)
--simply show the current menu id...
for i = 1, #Cell_menus do
local h = Cell_menus[i].h
vint_set_property(h, "visible", false)
--Switch to the proper input tracker...
--unsubscribe all menus because we need to wait for transition... and then put subscribe in AFTER the transition callback...
local input_tracker = Cell_menus[i].input_tracker
input_tracker:subscribe(false)
if Game_platform == "PC" then
local mouse_input_tracker = Cell_menus[i].mouse_input_tracker
mouse_input_tracker:subscribe(false)
local hint_input_tracker = Cell_menus[i].hint_input_tracker
if hint_input_tracker ~= nil then
hint_input_tracker:subscribe(false)
end
end
end
if Menu_active == -1 then
--No transition allowed...
--Just do callback..
local input_tracker = Cell_menus[menu_id].input_tracker
input_tracker:subscribe(true)
if Game_platform == "PC" then
local mouse_input_tracker = Cell_menus[menu_id].mouse_input_tracker
mouse_input_tracker:subscribe(true)
local hint_input_tracker = Cell_menus[menu_id].hint_input_tracker
if hint_input_tracker ~= nil then
hint_input_tracker:subscribe(true)
end
end
local h = Cell_menus[menu_id].h
vint_set_property(h, "visible", true)
else
local h = Cell_menus[menu_id].h
local previous_menu_id = Menu_active
local prev_h = Cell_menus[previous_menu_id].h
-- show the two menus we are gonna transition...
vint_set_property(prev_h, "visible", true)
vint_set_property(h, "visible", true)
local menu_width = 365 + 10
--Always transition left for now...
--vint_set_property(prev_h, "anchor", Screen_start_x, Screen_start_y)
--vint_set_property(h, "anchor", menu_width, 0)
local left_h = prev_h
local right_h = h
if direction == CELL_MENU_TRANS_NONE or direction == nil then
vint_set_property(prev_h, "visible", false)
menu_width = 0
elseif direction == CELL_MENU_TRANS_LEFT then
menu_width = - menu_width
elseif direction == CELL_MENU_TRANS_RIGHT then
end
local cell_screen_trans_anim_h = vint_object_find("cell_screen_trans_anim")
local left_twn_h = vint_object_find("trans_left_twn", cell_screen_trans_anim_h)
local right_twn_h = vint_object_find("trans_right_twn", cell_screen_trans_anim_h)
vint_set_property(left_twn_h, "start_value", 1)
vint_set_property(left_twn_h, "end_value", 0)
vint_set_property(right_twn_h, "start_value", 0)
vint_set_property(right_twn_h, "end_value", 1)
--[[
vint_set_property(left_twn_h, "start_value", Screen_start_x , Screen_start_y)
vint_set_property(left_twn_h, "end_value", Screen_start_x - menu_width, Screen_start_y)
vint_set_property(right_twn_h, "start_value", Screen_start_x + menu_width , Screen_start_y)
vint_set_property(right_twn_h, "end_value", Screen_start_x , Screen_start_y)
]]
vint_set_property(right_twn_h, "target_handle", right_h)
vint_set_property(left_twn_h, "target_handle", left_h)
vint_set_property(left_twn_h, "end_event", "cell_phone_menu_trans_cb")
lua_play_anim(cell_screen_trans_anim_h)
end
Menu_active = menu_id
end
-------------------------------------------------------------------------------
-- Gets called after we transition a menu, via tween callback..
-------------------------------------------------------------------------------
function cell_phone_menu_trans_cb()
-- menu is displaying... now subscribe to its input...
local input_tracker = Cell_menus[Menu_active].input_tracker
input_tracker:subscribe(true)
if Game_platform == "PC" then
local mouse_input_tracker = Cell_menus[Menu_active].mouse_input_tracker
mouse_input_tracker:subscribe(true)
end
if Game_platform == "PC" then
local hint_input_tracker = Cell_menus[Menu_active].hint_input_tracker
if hint_input_tracker ~= nil then
hint_input_tracker:subscribe(true)
end
end
end
-------------------------------------------------------------------------------
-- Connection callback...
-- This gets called after we dial...
-- @param success
-------------------------------------------------------------------------------
function cell_phone_dial_connection_cb(success)
debug_print("vint", "cell_phone_dial_connection_cb()\n")
debug_print("vint", "success" .. var_to_string(success) .. "\n")
if success == CELL_CALL_INVALID then
--wrong number
--use invalid number screen
--DON'T DO ANYTHING...
cell_phone_call_build(true)
cell_phone_menu_show(CELL_PHONE_MENU_CALL, CELL_MENU_TRANS_RIGHT)
elseif success == CELL_CALL_CONNECTED then
--Connection has been made, string of store name to display is stored in name
cell_phone_call_build(false)
cell_phone_menu_show(CELL_PHONE_MENU_CALL, CELL_MENU_TRANS_RIGHT)
elseif success == CELL_CALL_GARAGE_SHOW then
--Show garage...
--build garage menu here...
local success = cell_phone_garage_build()
if success == false then
cell_phone_garage_no_vehicles_dialog()
debug_print("vint", "you need vehicles in your garage to access this feature\n")
return
end
--Show it...
cell_phone_menu_show(CELL_PHONE_MENU_GARAGE, CELL_MENU_TRANS_RIGHT)
end
end
-------------------------------------------------------------------------------
-- Builds the phone book
-------------------------------------------------------------------------------
function cell_phone_book_build()
local book_screen_grp_h = vint_object_find("book_screen_grp")
--Base contact handle and hide...
local contact_grp_h = vint_object_find("contact_grp", book_screen_grp_h)
vint_set_property(contact_grp_h, "visible", false)
local homie_count = #Homie_data
for i = 1, homie_count do
--get data out of table...
local homie_index = Homie_data[i].homie_index
local homie_name_crc = Homie_data[i].homie_name_crc
local description_crc = Homie_data[i].description_crc
local image_crc = Homie_data[i].image_crc
local is_available = Homie_data[i].is_available
--clone base item...
local h = vint_object_clone(contact_grp_h)
--Set Text
local name_txt_h = vint_object_find("name_txt", h)
vint_set_property(name_txt_h, "text_tag_crc", homie_name_crc)
resize_text_element(name_txt_h, CELL_PHONE_BOOK_MAX_WIDTH_LABEL)
--Set icon
local homie_icon_h = vint_object_find("homie_icon", h)
vint_set_property(homie_icon_h, "image_crc", image_crc)
--Position Homie in list...
local x, y = vint_get_property(h, "anchor")
y = ( (i - 1) * HOMIE_LIST_SPACING )
vint_set_property(h, "anchor", x, y )
--Show homie in list...
vint_set_property(h, "visible", true)
if is_available == true then
--Reset to normal...
vint_set_property(h, "alpha", 1)
vint_set_property(homie_icon_h, "saturation", 1)
else
--Grey out homie in list...
vint_set_property(h, "alpha", .333)
vint_set_property(homie_icon_h, "saturation", 0)
end
if Game_platform == "PC" then
Mouse_input_tracker:add_mouse_input("mouse_move", "cell_phone_mouse_move", 50, h)
Mouse_input_tracker:add_mouse_input("mouse_click", "cell_phone_mouse_click", 50, h)
end
--Store handle of cloned object into homie table...
Homie_data[i].h = h
end
if Game_platform == "PC" then
Mouse_input_tracker:subscribe(true)
end
--do we need scrollbar?
-- Handle scrolling
if(homie_count > HOMIE_MAX_ITEMS) then
--show the scroll bar
Scrollbar:set_property("visible", true)
local clip_height = HOMIE_LIST_SPACING + ((HOMIE_MAX_ITEMS - 1) * HOMIE_LIST_SPACING)
local total_height = homie_count * HOMIE_LIST_SPACING
Scrollbar:set_size(SCROLLBAR_WIDTH, clip_height, total_height)
else
--show the scroll bar
Scrollbar:set_property("visible", false)
end
--Find first available homie...
local homie_count = #Homie_data
local is_available = Homie_data[Homie_data_cur_idx].is_available
local is_available_count = 0
local is_available_idx = Homie_data_cur_idx
if is_available == false then
local new_index
while not is_available do
is_available = Homie_data[is_available_idx].is_available
if is_available_count > homie_count then
new_index = Homie_data_cur_idx
is_available = true
end
new_index = is_available_idx
is_available_count = is_available_count + 1
is_available_idx = is_available_idx + 1
if is_available_idx > homie_count then
is_available_idx = 1
end
end
Homie_data_cur_idx = new_index
end
--Select item in list...
cell_phone_book_highlight(Homie_data_cur_idx)
Current_menu = HOMIE_MENU
end
------------------------------------------------------------------------------------
-- Sets the current highlighted option on the phone book and resets everything else
-- @param idx index of item to highlight
-- @param is_mouse_input are we using the mouse?
-- @param is_scrollbar are we using the scrollbar with the mouse?
------------------------------------------------------------------------------------
function cell_phone_book_highlight(idx, is_mouse_input, is_scrollbar)
Homie_data_cur_idx = idx
local homie_count = #Homie_data
--if using scrollbar don't update the highlight, just scroll the list
if is_scrollbar ~= true then
local book_screen_grp_h = vint_object_find("book_screen_grp")
--cant select this if its not available...
local is_available = Homie_data[idx].is_available
for i = 1, homie_count do
--Get base group out of homie data...
local h = Homie_data[i].h
local is_available = Homie_data[i].available
local border_grp_h = vint_object_find("border_grp", h)
if i == idx then
--Highlight this option
--Color border purple
--Move the highlight bar to indexed location...
local contact_highlight_grp_h = vint_object_find("contact_highlight_grp", book_screen_grp_h)
vint_set_property(contact_highlight_grp_h, "visible", true)
local x, y = vint_get_property(h, "anchor")
vint_set_property(contact_highlight_grp_h, "anchor", x, y)
--Change text field of item...
local name_txt_h = vint_object_find("name_txt", contact_highlight_grp_h)
local homie_name_crc = Homie_data[i].homie_name_crc
vint_set_property(name_txt_h, "text_tag_crc", homie_name_crc)
vint_set_property(border_grp_h, "tint", LIST_COLOR_HIGHLIGHT.R, LIST_COLOR_HIGHLIGHT.G, LIST_COLOR_HIGHLIGHT.B)
--Make sure it fits in the phone...
resize_text_element(name_txt_h, CELL_PHONE_BOOK_MAX_WIDTH_LABEL)
local highlight_btn_h = vint_object_find("highlight_btn", contact_highlight_grp_h)
local name_x, name_y = vint_get_property(name_txt_h, "anchor")
if game_is_active_input_gamepad() and Homie_data[i].is_available == true then
vint_set_property(name_txt_h, "anchor", 118, name_y)
vint_set_property(highlight_btn_h, "visible", true)
else
vint_set_property(name_txt_h, "anchor", 85, name_y)
vint_set_property(highlight_btn_h, "visible", false)
end
--Update description text
local description_crc = Homie_data[i].description_crc
local description_txt_h = vint_object_find("description_txt")
vint_set_property(description_txt_h, "text_tag_crc", description_crc)
vint_set_property(description_txt_h, "visible", true)
local desc_header_h = vint_object_find("desc_header", 0, Cell_phone_handle)
vint_set_property(desc_header_h, "text_tag_crc", homie_name_crc)
resize_text_element(desc_header_h, 380)
local highlight_bg_h = vint_object_find("highlight_bg", contact_highlight_grp_h)
if Homie_data[i].is_available == false then
vint_set_property(highlight_bg_h, "tint", LIST_COLOR_UNHIGHLIGHT.R, LIST_COLOR_UNHIGHLIGHT.G, LIST_COLOR_UNHIGHLIGHT.B)
vint_set_property(border_grp_h, "tint", LIST_COLOR_UNHIGHLIGHT.R, LIST_COLOR_UNHIGHLIGHT.G, LIST_COLOR_UNHIGHLIGHT.B)
else
vint_set_property(highlight_bg_h, "tint", LIST_COLOR_HIGHLIGHT.R, LIST_COLOR_HIGHLIGHT.G, LIST_COLOR_HIGHLIGHT.B)
end
else
--Color border grey
vint_set_property(border_grp_h, "tint", LIST_COLOR_UNHIGHLIGHT.R, LIST_COLOR_UNHIGHLIGHT.G, LIST_COLOR_UNHIGHLIGHT.B)
end
end
end
local visual_center = ( HOMIE_MAX_ITEMS)
local move_height = HOMIE_LIST_SPACING
local new_y = 0
local list_x, list_y = vint_get_property(vint_object_find("contact_list_grp"), "anchor")
if idx > Visible_end_idx and idx <= homie_count then
Visible_start_idx = idx - (HOMIE_MAX_ITEMS - 1)
elseif idx < Visible_start_idx then
Visible_start_idx = idx
if Visible_start_idx < 1 then
Visible_start_idx = 1
end
end
Visible_end_idx = Visible_start_idx + (HOMIE_MAX_ITEMS - 1)
new_y = -HOMIE_LIST_SPACING * (Visible_start_idx - 1)
local book_scroll_anim_h = vint_object_find("book_scroll_anim")
local book_scroll_twn_h = vint_object_find("book_scroll_twn")
local contact_list_grp_h = vint_object_find("contact_list_grp")
local start_x, start_y = vint_get_property(contact_list_grp_h, "anchor")
local end_x = start_x
local end_y = new_y
vint_set_property(book_scroll_twn_h, "start_value", start_x, start_y)
vint_set_property(book_scroll_twn_h, "end_value", end_x, end_y)
vint_set_property(book_scroll_twn_h, "end_event", "cell_phone_book_scroll_cb")
lua_play_anim(book_scroll_anim_h)
Book_screen_is_scrolling = true
Prev_y = new_y
--Adjust scrollbar
Scrollbar:set_value( homie_count - (HOMIE_MAX_ITEMS - 1), Visible_start_idx, false )
end
-------------------------------------------------------------------------------
-- Select
-------------------------------------------------------------------------------
function cell_phone_book_scroll_cb(event)
Book_screen_is_scrolling = false
end
-------------------------------------------------------------------------
-- Populate cellphone homie list
-------------------------------------------------------------------------------
-- @param index index of homie_icon
-- @param homie_name_crc crc of homie name
-- @param description_crc crc of the description for homie...
-- @param image_crc image of the homie
-- @param is_available is the homie available?
function cell_phone_populate_list(homie_index, homie_name_crc, description_crc, image_crc, is_available)
local idx = #Homie_data + 1
Homie_data[idx] = {
homie_index = homie_index,
homie_name_crc = homie_name_crc,
description_crc = description_crc,
image_crc = image_crc,
is_available = is_available,
}
end
function cell_phone_book_nav_up(event, acceleration)
if Book_screen_is_scrolling == true then
return
end
--move up
local loop_count = 0
local num_items = #Homie_data
local stop_loop = true
while stop_loop do
Homie_data_cur_idx = Homie_data_cur_idx - 1
if Homie_data_cur_idx < 1 then
Homie_data_cur_idx = #Homie_data
end
stop_loop = false
if loop_count > num_items then
--Cannot nav...
return
else
loop_count = loop_count + 1
end
end
--Play sound
game_UI_audio_play("UI_Cell_Nav")
--Highlight current option...
cell_phone_book_highlight(Homie_data_cur_idx)
end
function cell_phone_book_nav_down(event, acceleration)
if Book_screen_is_scrolling == true then
return
end
--move down
local loop_count = 0
local num_items = #Homie_data
local stop_loop = true
while stop_loop do
Homie_data_cur_idx = Homie_data_cur_idx + 1
if Homie_data_cur_idx > #Homie_data then
Homie_data_cur_idx = 1
end
stop_loop = false
if loop_count > num_items then
--Cannot nav...
return
else
loop_count = loop_count + 1
end
end
--Play sound
game_UI_audio_play("UI_Cell_Nav")
--Highlight current option...
cell_phone_book_highlight(Homie_data_cur_idx)
end
function cell_phone_book_button_a(event, acceleration)
if Book_screen_is_scrolling == true then
return
end
--Call homie
local homie_index = Homie_data[Homie_data_cur_idx].homie_index
local is_available = Homie_data[Homie_data_cur_idx].is_available
--Check if homie is available and then call if so...
if is_available == true then
--Lock inputs
Input_tracker:subscribe(false)
if Game_platform == "PC" then
Mouse_input_tracker:subscribe(false)
end
--Call homie
cellphone_dial(homie_index, "cell_phone_dial_connection_cb", "cell_phone_call_hangup_cb")
ui_audio_post_event("ui_call_homie")
end
end
function cell_phone_book_button_b(event, acceleration)
cell_phone_exit(false)
end
function cell_phone_book_button_map(event, acceleration)
cell_phone_exit(true)
end
-------------------------------------------------------------------------------
-- GARAGE
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Builds the garage list
-------------------------------------------------------------------------------
function cell_phone_garage_build()
Garage_list_data = {}
if Game_platform == "PC" then
Mouse_input_tracker_garage:remove_all()
end
--Dataresponder to the garage...
vint_dataresponder_request("cell_phone_pad_populate", "cell_phone_garage_populate", 0, CELL_VEHICLE_LIST)
if #Garage_list_data == 0 then
--no items in list...
return false
end
Garage_list:draw_items(Garage_list_data, 1, GARAGE_LIST_WIDTH, GARAGE_LIST_MAX_BUTTONS)
if Game_platform == "PC" then
Garage_list:add_mouse_inputs("cell_phone", Mouse_input_tracker_garage, 50)
Garage_hint_bar:add_mouse_inputs("cell_phone", Mouse_input_tracker_garage_hint, 50)
Mouse_input_tracker_garage:subscribe(true)
Mouse_input_tracker_garage_hint:subscribe(true)
end
Current_menu = GARAGE_MENU
end
function cell_phone_garage_populate(vehicle_index, vehicle_name, repair_cost)
--Add item to list...
local idx = #Garage_list_data + 1
Garage_list_data[idx] = {
type = TYPE_BUTTON,
label = vehicle_name,
id = vehicle_index,
repair_cost = repair_cost,
}
end
function cell_phone_garage_no_vehicle_cb()
Input_tracker:subscribe(true)
if Game_platform == "PC" then
Mouse_input_tracker:subscribe(true)
end
end
function cell_phone_garage_no_vehicles_dialog()
-- TODO: localize
dialog_box_message("CELL_PHONE_NO_VEHICLES",
"CELL_PHONE_MUST_ADD_VEHICLES",
nil,
nil,
"cell_phone_garage_no_vehicle_cb"
)
end
function cell_phone_garage_map()
-- do nothing
end
function cell_phone_garage_nav_up()
Garage_list:move_cursor(-1)
end
function cell_phone_garage_nav_down()
Garage_list:move_cursor(1)
end
function cell_phone_garage_button_a()
if Garage_list:list_is_playing() == false then
-- Attempt to retrive vehicle
-- Get current selected vehicle data...
local data = Garage_list:return_selected_data()
local repair_cost = data.repair_cost
--Check if player has enough cash
if Cell_phone_cash < repair_cost then
--Not enough cash dialog
dialog_box_message("CELL_VEHICLE_DIALOG_NO_CASH_HEADER","CELL_VEHICLE_DIALOG_NO_CASH_BODY")
return
end
--Repair and Deliver if player has enough cash.
if repair_cost == 0 then
--Deliver if repair price = 0
cellphone_choose_vehicle(data.id)
--Exit phone...
cell_phone_exit(true)
return
end
--Car needs repairs, prepare localized dialog and display
if repair_cost ~= 0 then
local values = {[0] = repair_cost}
local dialog_repairs_body = vint_insert_values_in_string("CELL_VEHICLE_DIALOG_REPAIRS_BODY", values)
dialog_box_confirmation("CELL_VEHICLE_DIALOG_REPAIRS_HEADER", dialog_repairs_body, "cellphone_garage_get_car_dialog_cb")
else
cellphone_choose_vehicle(data.id)
cell_phone_exit(true)
end
end
end
function cell_phone_garage_button_b()
-- Nav back to homie list...
-- Nav back to homie list...
cell_phone_menu_show(CELL_PHONE_MENU_BOOK, CELL_MENU_TRANS_LEFT)
Current_menu = HOMIE_MENU
end
function cell_phone_garage_button_map()
end
-------------------------------------------------------------------------------
-- Dialog response after selecting an option on the repair menu...
-------------------------------------------------------------------------------
function cellphone_garage_get_car_dialog_cb(result, action)
if result == 0 then
--Result is good, retreive the car...
local vehicle_id = Garage_list:get_id()
cellphone_choose_vehicle(vehicle_id)
--Exit back to game...
cell_phone_exit(true)
end
if result == 1 then
-- go back to the menu
return
end
end
-------------------------------------------------------------------------------
-- Called when the game wants to hang up the phone...
-- This gets called after we dial...
-- @param is_busy
------------------------------------------------------------------------------
function cell_phone_call_build(is_busy)
--Get homie data we need...
local homie_name_crc = Homie_data[Homie_data_cur_idx].homie_name_crc
local image_crc = Homie_data[Homie_data_cur_idx].image_crc
local call_contact_grp_h = vint_object_find("call_contact_grp")
--Set text...
local call_name_txt_h = vint_object_find("call_name_txt", call_contact_grp_h)
vint_set_property(call_name_txt_h, "text_tag_crc", homie_name_crc)
--Make sure it fits in the phone...
resize_text_element(call_name_txt_h, CELL_PHONE_CALL_MAX_WIDTH_LABEL)
--Set icon
local call_icon_bmp_h = vint_object_find("call_icon_bmp", call_contact_grp_h)
vint_set_property(call_icon_bmp_h, "image_crc", image_crc)
local calling_info_txt_h = vint_object_find("calling_info_txt")
if is_busy then
vint_set_property(calling_info_txt_h, "text_tag", "CELL_PHONE_BUSY")
else
vint_set_property(calling_info_txt_h, "text_tag", "CELL_PHONE_IN_CALL")
end
end
--------------------------------------------------------------------------
-- Called when the game wants to hang up the phone...
-- This gets called after we dial...
-- @param success (CELL_CALL_HANGUP, CELL_CALL_RETURN_TO_PHONE)
-------------------------------------------------------------------------------
function cell_phone_call_hangup_cb(success)
debug_print("vint", "cell_phone_call_hangup_cb()\n")
if success == CELL_CALL_HANGUP then
--exit back to game....
cell_phone_exit(true)
elseif success == CELL_CALL_RETURN_TO_PHONE then
--Return to phone
cell_phone_menu_show(CELL_PHONE_MENU_BOOK, CELL_MENU_TRANS_LEFT)
else
-- handle any other case exit back to game...
cell_phone_exit(true)
end
end
--------------------------------------------------------------------------------
-- Call screen input..
--------------------------------------------------------------------------------
function cell_phone_call_input(event)
--do something here
if event == "select" or event == "back" or event == "map" then
--exit to game...
cell_phone_exit(true)
end
end
-------------------------------------------------------------------------------
-- Updates player cash for this screen...
-- uses a hud data item and gets the first element from it.
-------------------------------------------------------------------------------
function cell_phone_cash_update(di_h)
local cash = vint_dataitem_get(di_h)
Cell_phone_cash = floor(cash)
end
-------------------------------------------------------------------------------
-- Exits to a menu or back to game...
-------------------------------------------------------------------------------
function cell_phone_exit(exit_to_game)
-- Next time come back to phone main...
vint_dataresponder_post("cell_menu_state_dr", "Set", ID_MAIN)
--Unsubscribe from all controls while we make our transition...
Input_tracker:subscribe(false)
Input_tracker_garage:subscribe(false)
Input_tracker_call:subscribe(false)
if exit_to_game then
--Exit to game...
cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_PHONE, cell_phone_exit_to_game)
ui_audio_post_event("UI_Hub_Menu_Back")
else
--Exit to main...
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_PHONE, cell_phone_exit_to_main)
ui_audio_post_event("UI_Hub_Menu_Back")
end
end
function cell_phone_exit_to_main()
pop_screen()
end
function cell_phone_exit_to_game()
pop_screen() -- cell phone
pop_screen() -- cell main
pop_screen() -- cell fore/background
end
-------------------------------------------------------------------------------
-- resize a specific text element...
-------------------------------------------------------------------------------
function cell_phone_resize_text_element(element_h, max_width)
vint_set_property(element_h, "scale", 1, 1)
local text_width, text_height = element_get_actual_size(element_h)
if text_width > max_width then
local text_scale = max_width/text_width
vint_set_property(element_h, "scale", text_scale, text_scale)
end
end
-------------------------------------------------------------------------------
-- Mouse specific functions...
-------------------------------------------------------------------------------
--Search through active buttons and determine if the mouse is over a valid target
--
function cell_phone_get_valid_handle(target_handle)
for idx, cur_selection in pairs(Homie_data) do
if cur_selection.h ~= nil and cur_selection.h == target_handle then
--if selection is visible then return idx
if idx >= Visible_start_idx and idx <= Visible_end_idx then
return idx
end
end
end
return MOUSE_INVALID_HANDLE
end
function cell_phone_mouse_click(event, target_handle)
local hint_index = Hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
cell_phone_book_button_b()
end
local phone_index = cell_phone_get_valid_handle(target_handle)
if phone_index ~= MOUSE_INVALID_HANDLE then
cell_phone_book_button_a(event, nil)
end
local garage_hint_index = Garage_hint_bar:get_hint_index(target_handle)
if garage_hint_index == 1 then
cell_phone_garage_button_b()
end
local garage_idx = Garage_list:get_button_index(target_handle)
if garage_idx ~= 0 then
Garage_list:set_selection(garage_idx)
cell_phone_garage_button_a(event, nil)
end
end
function cell_phone_mouse_move(event, target_handle)
if Current_menu == HOMIE_MENU then
-- Phone book inputs
Hint_bar:set_highlight(0)
local hint_index = Hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
Hint_bar:set_highlight(hint_index)
game_UI_audio_play("UI_Cell_Nav")
end
local phone_index = cell_phone_get_valid_handle(target_handle)
if phone_index ~= MOUSE_INVALID_HANDLE then
cell_phone_book_highlight(phone_index, true)
game_UI_audio_play("UI_Cell_Nav")
end
elseif Current_menu == GARAGE_MENU then
-- Garage inputs
Garage_hint_bar:set_highlight(0)
local garage_hint_index = Garage_hint_bar:get_hint_index(target_handle)
if garage_hint_index ~= 0 then
Garage_hint_bar:set_highlight(garage_hint_index)
game_UI_audio_play("UI_Cell_Nav")
end
local old_index = Garage_list:get_selection()
local new_index = Garage_list:get_button_index(target_handle)
if new_index ~= 0 and new_index ~= old_index then
Garage_list:set_selection(new_index)
Garage_list:move_cursor(0, true)
-- If the item has a callback for navigation, do it
local data_item = Garage_list:return_selected_data()
if data_item.on_nav ~= nil then
data_item.on_nav(data_item)
end
end
end
end
function cell_phone_mouse_drag(event, target_handle, mouse_x, mouse_y, scroll_lines)
if Scrollbar.tab_grp.handle == target_handle then
local homie_count = #Homie_data
local contact_list_grp_h = vint_object_find("contact_list_grp")
local list_x, list_y = vint_get_property(contact_list_grp_h, "anchor")
Visible_start_idx = Scrollbar:drag_scrolltab(mouse_y, #Homie_data)
Visible_end_idx = Visible_start_idx + (HOMIE_MAX_ITEMS - 1)
if Visible_start_idx < 1 then
Visible_start_idx = 1
elseif Visible_end_idx > homie_count then
Visible_start_idx = homie_count - (HOMIE_MAX_ITEMS - 1)
end
Visible_end_idx = Visible_start_idx + (HOMIE_MAX_ITEMS - 1)
local new_y = 0
new_y = -HOMIE_LIST_SPACING * (Visible_start_idx - 1)
vint_set_property(contact_list_grp_h, "anchor", list_x, new_y)
Prev_y = new_y
Scrollbar:set_value( homie_count - (HOMIE_MAX_ITEMS - 1), Visible_start_idx, false )
end
if Garage_list.scrollbar.tab_grp.handle == target_handle then
local new_start_index = Garage_list.scrollbar:drag_scrolltab(mouse_y, Garage_list.num_buttons - (Garage_list.max_buttons - 1))
--scroll Garage list
Garage_list:scroll_list(0, new_start_index)
end
end
-- Updates the mouse inputs for the list and snaps the scrolltab to the closest notch based on the visible index
--
function cell_phone_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
-- scroll garage list and update mouse inputs
if Garage_list.scrollbar.tab_grp.handle == target_handle then
local start_index = Garage_list:get_visible_indices()
Garage_list.scrollbar:release_scrolltab(start_index, Garage_list.num_buttons - (Garage_list.max_buttons - 1))
Garage_list:update_mouse_inputs("cell_phone",Mouse_input_tracker_garage,50)
end
end
function cell_phone_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines)
--scroll lines are inverted for some reason
scroll_lines = scroll_lines * -1
-- scroll garage list if in garage
if Menu_active == CELL_PHONE_MENU_GARAGE then
if scroll_lines ~= 0 then
Garage_list:scroll_list(scroll_lines)
Garage_list:update_mouse_inputs("cell_phone",Mouse_input_tracker_garage,50)
end
else
local homie_count = #Homie_data
--if list has enough items to scroll then allow mouse wheel
if homie_count > HOMIE_MAX_ITEMS then
local contact_list_grp_h = vint_object_find("contact_list_grp")
local list_x, list_y = vint_get_property(contact_list_grp_h, "anchor")
Visible_start_idx = Visible_start_idx + scroll_lines
Visible_end_idx = Visible_start_idx + (HOMIE_MAX_ITEMS - 1)
if Visible_start_idx < 1 then
Visible_start_idx = 1
elseif Visible_end_idx > homie_count then
Visible_start_idx = homie_count - (HOMIE_MAX_ITEMS - 1)
end
Visible_end_idx = Visible_start_idx + (HOMIE_MAX_ITEMS - 1)
local new_y = 0
new_y = -HOMIE_LIST_SPACING * (Visible_start_idx - 1)
local book_scroll_anim_h = vint_object_find("book_scroll_anim")
local book_scroll_twn_h = vint_object_find("book_scroll_twn")
vint_set_property(book_scroll_twn_h, "start_value", list_x, list_y)
vint_set_property(book_scroll_twn_h, "end_value", list_x, new_y)
vint_set_property(book_scroll_twn_h, "end_event", "cell_phone_book_scroll_cb")
lua_play_anim(book_scroll_anim_h)
Book_screen_is_scrolling = true
Prev_y = new_y
Scrollbar:set_value( homie_count - (HOMIE_MAX_ITEMS - 1), Visible_start_idx, false )
end
end
end
--[[ ---------------------------------------------------------------------
-- Function - cell_phone_update_gamepad_state
-- Description - Called by code anytime input switches between gamepad/mouse & keyboard
-- Parameters - none
-- Returns - nil
]]-- ---------------------------------------------------------------------
function cell_phone_update_gamepad_state()
Highlight_btn:set_button(CTRL_MENU_BUTTON_A)
local book_screen_grp_h = vint_object_find("book_screen_grp")
local contact_highlight_grp_h = vint_object_find("contact_highlight_grp", book_screen_grp_h)
local highlight_btn_h = vint_object_find("highlight_btn", contact_highlight_grp_h)
local name_txt_h = vint_object_find("name_txt", contact_highlight_grp_h)
local name_x, name_y = vint_get_property(name_txt_h, "anchor")
if game_is_active_input_gamepad() then
vint_set_property(name_txt_h, "anchor", 118, name_y)
vint_set_property(highlight_btn_h, "visible", true)
else
vint_set_property(name_txt_h, "anchor", 85, name_y)
vint_set_property(highlight_btn_h, "visible", false)
end
if Current_menu == HOMIE_MENU then
if Input_tracker ~= -1 then
Input_tracker:subscribe(false)
Input_tracker:subscribe(true)
end
if Input_tracker_call ~= -1 then
Input_tracker_call:subscribe(false)
Input_tracker_call:subscribe(true)
end
if Mouse_input_tracker ~= -1 then
Mouse_input_tracker:subscribe(false)
Mouse_input_tracker:subscribe(true)
end
if Mouse_input_tracker_call ~= -1 then
Mouse_input_tracker_call:subscribe(false)
Mouse_input_tracker_call:subscribe(true)
end
elseif Current_menu == GARAGE_MENU then
if Input_tracker_garage ~= -1 then
Input_tracker_garage:subscribe(false)
Input_tracker_garage:subscribe(true)
end
if Mouse_input_tracker_garage ~= -1 then
Mouse_input_tracker_garage:subscribe(false)
Mouse_input_tracker_garage:subscribe(true)
end
if Mouse_input_tracker_garage_hint ~= -1 then
Mouse_input_tracker_garage_hint:subscribe(false)
Mouse_input_tracker_garage_hint:subscribe(true)
end
end
end