--Item Type Enum
SAINTSBOOK_ITEM_TYPE_ALL = 0 --Note all is not used on v2 of the saints book screen.
SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS = 1
SAINTSBOOK_ITEM_TYPE_CHOPSHOP = 2
SAINTSBOOK_ITEM_TYPE_CHALLENGE = 3
--Screen types
local SCREEN_TYPE_UNUSED = 0
local SCREEN_TYPE_MAIN = 1
local SCREEN_TYPE_SUB = 2
local Active_screen = {}
local Active_screen_type = -1
--Local Globals
local SAINTSBOOK_COLOR_TOP_BG_SELECTED = {R = 148/255, G = 0/255, B = 197/255}
local SAINTSBOOK_COLOR_TOP_BG_UNSELECTED = {R = 51/255, G = 51/255, B = 51/255}
local SAINTSBOOK_COLOR_TOP_TEXT_SELECTED = {R = 0/255, G = 0/255, B = 0/255}
local SAINTSBOOK_COLOR_TOP_TEXT_UNSELECTED = {R = 156/255, G = 156/255, B = 156/255}
local SAINTSBOOK_COLOR_ICON_SELECTED = {R = 220/255, G = 220/255, B = 220/255}
local SAINTSBOOK_COLOR_ICON_UNSELECTED = {R = 120/255, G = 120/255, B = 120/255}
local SAINTSBOOK_PAGE_WIDTH = 850 --size of entire page (used to space and transition the pages...
--VDO
local Input_tracker_main
local Hint_bar
local Clip_region
local Mouse_input_tracker
local Scrollbar_mouse_input_tracker
local Cell_saintsbook_main_scrollbar
local Cell_saintsbook_sub_scrollbar
local Cell_saintsbook_contact_image = -1 --Reference to streamed in saintsbook image...
local Cell_saintsbook_target_image = -1 --Reference to streamed in saintsbook image...
local Cell_saintsbook_exit_phone = false --Determine if we go back to cellphone main or exit the phone all together.
local Cell_saintsbook_scroll_tween_done = true
Cell_saintsbook_first_transition = false --flag to determine if we finished the first transition (determines when to unlock input)
Cell_saintsbook_top_is_ready = false --flag to determine that we've loaded into saintsbook... (determines when to unlock input)
--Icons per item type....
local Cell_saintsbook_icons = {
[SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS] = "ui_saintsbook_hitman",
[SAINTSBOOK_ITEM_TYPE_CHOPSHOP] = "ui_saintsbook_vehicle",
[SAINTSBOOK_ITEM_TYPE_CHALLENGE] = "ui_saintsbook_challenge",
}
--Icons per item type....
local Cell_saintsbook_main_pegs = {
[SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS] = "ui_bms_sb_hitman",
[SAINTSBOOK_ITEM_TYPE_CHOPSHOP] = "ui_bms_sb_chopshop",
[SAINTSBOOK_ITEM_TYPE_CHALLENGE] = "ui_bms_sb_challenges",
}
--Icons per item type....
local Cell_saintsbook_top_pegs = {
[SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS] = "ui_sb_main_hitman",
[SAINTSBOOK_ITEM_TYPE_CHOPSHOP] = "ui_sb_main_chopshop",
[SAINTSBOOK_ITEM_TYPE_CHALLENGE] = "ui_sb_main_challenges",
}
--Top level descriptions of items
local Cell_saintsbook_top_descriptions = {
[SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS] = "SB_ASSASSINATION_DESC",
[SAINTSBOOK_ITEM_TYPE_CHOPSHOP] = "SB_CHOP_SHOP_DESC",
[SAINTSBOOK_ITEM_TYPE_CHALLENGE] = "SB_CHALLENGES_DESC",
}
-- Table to translate contact images that are normally homie heads...
-- Use cell_saintsbook_contact_image_get(image_name)
-- This will attempt to pull the image from this table.
--
local Cell_saintsbook_contact_images = {
["ui_homie_pierce"] = "ui_sb_ct_pierce",
["ui_homie_shaundi"] = "ui_sb_ct_shaundi",
["ui_homie_zimos"] = "ui_sb_ct_zimos",
["ui_homie_kinzie"] = "ui_sb_ct_kinzie",
["ui_homie_angel_wmask"] = "ui_sb_ct_angel",
["ui_homie_angel_womask"] = "ui_sb_ct_angel",
["ui_hud_act_ico_saints"] = "ui_sb_ct_kinzie",
["ui_homie_oleg"] = "ui_sb_ct_oleg",
["ui_homie_viola"] = "ui_sb_ct_viola",
}
--Top level menu stuff
Cell_saintsbook_top_items = {}
Cell_saintsbook_items = {} -- Items in the list...
Cell_saintsbook_display_items = {} -- Items that are currently displayed
Cell_saintsbook_item_count = 0 -- # of items in the list...
Cell_saintsbook_main_selected_idx = 0 -- Currently selected inded...
Cell_saintsbook_main_max_items = 0 -- max items
Cell_saintsbook_selected_target = -1
local Cell_old_mouse_index = -1
--Main menu stuff
SAINTSBOOK_MAIN_MAX_ITEMS = 4
SAINTSBOOK_MAIN_ITEM_SPACING = 115 --Spacing between items...
-------------------------------------------------------------------------------
-- Initialize saintsbook
--
function cell_saintsbook_init()
local h = vint_object_find("safe_frame")
vint_set_property(h, "visible", false)
--hide loading symbol (this is used on exit)
local loading_grp_h = vint_object_find("loading_grp")
vint_set_property(loading_grp_h, "alpha", 0)
--Initailize Input tracker...
Input_tracker_main = Vdo_input_tracker:new()
Input_tracker_main:add_input("nav_up", "cell_saintsbook_input", 50)
Input_tracker_main:add_input("nav_down", "cell_saintsbook_input", 50)
Input_tracker_main:add_input("map", "cell_saintsbook_input", 50)
Input_tracker_main:add_input("back", "cell_saintsbook_input", 50)
Input_tracker_main:add_input("pause", "cell_saintsbook_input", 50)
Input_tracker_main:add_input("select", "cell_saintsbook_input", 50)
--hintbar...
local hint_data = { {CTRL_MENU_BUTTON_B, "BACK"}, }
Hint_bar = Vdo_hint_bar:new("hint_bar")
Hint_bar:set_hints(hint_data)
Clip_region = Vdo_base_object:new("content_clip")
if game_get_platform() == "PC" then
Mouse_input_tracker = Vdo_input_tracker:new()
Mouse_input_tracker:subscribe(false)
Scrollbar_mouse_input_tracker = Vdo_input_tracker:new()
Scrollbar_mouse_input_tracker:subscribe(false)
Scrollbar_mouse_input_tracker.enabled = false
end
Cell_saintsbook_main_selected_idx = 0
Cell_saintsbook_main_scrollbar = Vdo_scrollbar:new("main_scroll_bar")
Cell_saintsbook_sub_scrollbar = Vdo_scrollbar:new("task_scroll_bar")
Cell_saintsbook_main_scrollbar:set_property("visible", false)
Cell_saintsbook_sub_scrollbar:set_property("visible", false)
Cell_saintsbook_main_scrollbar:set_highlight_color(COLOR_STORE_REWARDS_PRIMARY)
Cell_saintsbook_sub_scrollbar:set_highlight_color(COLOR_STORE_REWARDS_PRIMARY)
--Position Pages in the slide.
local main_grp_h = vint_object_find("main_grp")
local subpage_grp_h = vint_object_find("subpage_grp")
local top_grp_h = vint_object_find("top_grp")
vint_set_property(top_grp_h, "anchor", 0, 0)
vint_set_property(main_grp_h, "anchor", SAINTSBOOK_PAGE_WIDTH, 0)
vint_set_property(subpage_grp_h, "anchor", SAINTSBOOK_PAGE_WIDTH * 2, 0)
--Hint bar
local hint_data = {
{CTRL_MENU_BUTTON_B, "CONTROL_BACK"},
}
Hint_bar = Vdo_hint_bar:new("hint_bar")
Hint_bar:set_hints(hint_data)
--Specific screen setup...
--Set button image for main screen.
local gps_btn = Vdo_hint_button:new("gps_btn")
gps_btn:set_button(CTRL_MENU_BUTTON_A)
--Load initial pegs...
thread_new("cell_saintsbook_load_initial_pegs")
end
function cell_saintsbook_load_initial_pegs()
--Dump the pause map.
game_peg_unload("ui_map_world_city")
thread_yield()
--force challenges peg to load
local thumbnail_peg = Cell_saintsbook_main_pegs[SAINTSBOOK_ITEM_TYPE_CHALLENGE]
game_peg_load_with_cb("cell_saintsbook_all_pegs_loaded", 1, thumbnail_peg)
end
function cell_saintsbook_all_pegs_loaded()
--Transition the screen in...
cell_transition_screen(CELL_STATE_LANDSCAPE, CELL_SCREEN_SAINTSBOOK, CELL_SCREEN_MAIN, cell_saintsbook_top_ready)
--lock controls
cell_saintsbook_controls_lock()
cell_saintsbook_active_screen_set(SCREEN_TYPE_MAIN, true)
-- go straight into challenges and main screen
cell_saintsbook_main_open_stage_1(SAINTSBOOK_ITEM_TYPE_CHALLENGE)
-- Show the safe and transition the screen
local h = vint_object_find("safe_frame")
vint_set_property(h, "visible", true)
local h = vint_object_find("saintsbook_grp")
vint_set_property(h, "alpha", 0)
end
-------------------------------------------------------------------------------
-- Cleanup saintsbook.
--
function cell_saintsbook_cleanup()
--unload the pegs again on cleanup to guaranteed cleanup...
cell_saintsbook_unload_pegs()
end
--------------------------------------------------------------------------------
-- Unloads pegs and queues up the pause map to load.
--
function cell_saintsbook_close()
-- Unscubscribe from inputs...
Input_tracker_main:subscribe(false)
--play loading animation...
local loading_anim_h = vint_object_find("loading_anim")
lua_play_anim(loading_anim_h)
--delay while we we transition out...
delay(.25)
cell_saintsbook_unload_pegs()
thread_yield()
--Load pause map on callback we will do the final exit and transition out as planned.
game_peg_load_with_cb("cell_phone_saintsbook_close_final", 1, "ui_map_world_city")
end
function cell_saintsbook_unload_pegs()
--Unload a peg if we have it loaded...
if Cell_saintsbook_contact_image ~= -1 then
game_peg_unload(Cell_saintsbook_contact_image)
Cell_saintsbook_contact_image = -1
end
if Cell_saintsbook_target_image ~= -1 then
game_peg_unload(Cell_saintsbook_target_image)
Cell_saintsbook_target_image = -1
end
--Unload any main image pegs
for i = 1, #Cell_saintsbook_main_pegs do
game_peg_unload(Cell_saintsbook_main_pegs[i])
end
end
-----------------------------------------------
-- Closes Saintsbook and does the transition.
--
function cell_phone_saintsbook_close_final()
-- Next time come back to phone main...
vint_dataresponder_post("cell_menu_state_dr", "Set", ID_MAIN)
if Cell_saintsbook_exit_phone then
--Exit to game...
cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_SAINTSBOOK, cell_saintsbook_exit_final_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_SAINTSBOOK, cell_saintsbook_exit_final_to_menu)
ui_audio_post_event("UI_Hub_Menu_Back")
end
end
----------------------------------------------------------------------------------------
function cell_saintsbook_exit_to_game()
Cell_saintsbook_exit_phone = true
thread_new("cell_saintsbook_close")
end
function cell_saintsbook_exit_to_menu()
Cell_saintsbook_exit_phone = false
thread_new("cell_saintsbook_close")
end
function cell_saintsbook_exit_final_to_menu()
pop_screen()
end
function cell_saintsbook_exit_final_to_game()
pop_screen() --saintsbook
pop_screen() --cellphone main
pop_screen() --cellphone foreground/background
end
-------------------------------------------------------------------------------
-- Controls Unlock
--
function cell_saintsbook_controls_unlock()
Input_tracker_main:subscribe(true)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(true)
Scrollbar_mouse_input_tracker:subscribe(true)
Scrollbar_mouse_input_tracker.enabled = false -- Inentional: Will reset mouse inputs if necessary
end
end
-------------------------------------------------------------------------------
-- Controls lock
--
function cell_saintsbook_controls_lock()
Input_tracker_main:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
Scrollbar_mouse_input_tracker:subscribe(false)
Scrollbar_mouse_input_tracker.enabled = false
end
end
-------------------------------------------------------------------------------
-- Sets the active screen for nav callbacks.
--
function cell_saintsbook_active_screen_set(screen_type, cancel_transition)
if Saintsbook_screens[screen_type] ~= nil then
Active_screen = Saintsbook_screens[screen_type]
Active_screen_type = screen_type
end
--transition to page
cell_saintsbook_transition(screen_type, cancel_transition)
end
-------------------------------------------------------------------------------
-- Transitions to specific screen type, essentially first, second, third levels
--
-- @screen_type SCREEN_TYPE_TOP, SCREEN_TYPE_MAIN, SCREEN_TYPE_SUB
--
function cell_saintsbook_transition(screen_type, cancel_transition)
local transition_page_anim_h = vint_object_find("transition_page_anim")
local transition_twn_h = vint_object_find("transition_twn")
local content_h = vint_object_find("content")
local new_x = -SAINTSBOOK_PAGE_WIDTH * screen_type
local old_x, old_y = vint_get_property(content_h, "anchor")
if cancel_transition == true then
vint_set_property(content_h, "anchor", new_x, old_y)
cell_saintsbook_transition_complete()
else
vint_set_property(transition_twn_h, "end_event", "cell_saintsbook_transition_complete")
local new_x = -SAINTSBOOK_PAGE_WIDTH * screen_type
local old_x, old_y = vint_get_property(content_h, "anchor")
vint_set_property(transition_twn_h, "start_value", old_x, old_y)
vint_set_property(transition_twn_h, "end_value", new_x, old_y)
lua_play_anim(transition_page_anim_h)
end
end
function cell_saintsbook_transition_complete()
--unlock controls
Cell_saintsbook_first_transition = true
if Cell_saintsbook_top_is_ready == true then
cell_saintsbook_controls_unlock()
end
if game_get_platform() == "PC" then
if Active_screen_type == SCREEN_TYPE_MAIN then
cell_saintsbook_main_activate_mouse()
end
end
end
-------------------------------------------------------------------------------
-- Handles input callbacks for the Active_screen
--
function cell_saintsbook_input(event, accelleration)
if event == "nav_up" then --or event == "dpad_up" then
if Active_screen.nav ~= nil then
Active_screen.nav(-1)
end
elseif event == "nav_down" then -- or event == "dpad_down" then
if Active_screen.nav ~= nil then
Active_screen.nav(1)
end
elseif event == "select" then
if Active_screen.select ~= nil then
Active_screen.select(Active_screen.selected_idx)
end
elseif event == "back" then
if Active_screen.back ~= nil then
game_UI_audio_play("UI_Cell_Nav_Back")
Active_screen.back()
end
elseif event == "map" then
if Active_screen.exit ~= nil then
Active_screen.exit()
end
end
end
-------------------------------------------------------------------------------
-- Top
-------------------------------------------------------------------------------
function cell_saintsbook_top_ready()
--attemp to unlock controls
Cell_saintsbook_top_is_ready = true
if Cell_saintsbook_first_transition == true then
cell_saintsbook_controls_unlock()
end
end
function cell_saintsbook_mouse_click(event, target_handle)
-- Check if the user is over the hint bar
local hint_index = Hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
cell_saintsbook_input("back")
end
if Active_screen_type == SCREEN_TYPE_SUB then
cell_saintsbook_sub_mouse_click(event, target_handle)
end
end
function cell_saintsbook_mouse_move(event, target_handle)
-- Reset highlights
Hint_bar:set_highlight(0)
-- Check if the user is over the hint bar
local hint_index = Hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
Hint_bar:set_highlight(hint_index) --COLOR_PLAYER_CREATION_PRIMARY)
end
if Active_screen_type == SCREEN_TYPE_SUB then
cell_saintsbook_sub_mouse_move(event, target_handle)
end
end
function cell_saintsbook_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines)
if scroll_lines ~= 0 then
if Active_screen_type == SCREEN_TYPE_MAIN then
if scroll_lines < 0 and Cell_saintsbook_main_first_item < Cell_saintsbook_item_count - 4 then
cell_saintsbook_main_show_items(Cell_saintsbook_main_first_item + 1, Cell_saintsbook_main_first_item)
elseif scroll_lines > 0 and Cell_saintsbook_main_first_item > 0 then
cell_saintsbook_main_show_items(Cell_saintsbook_main_first_item - 1, Cell_saintsbook_main_first_item)
end
end
end
end
-------------------------------------------------------------------------------
-- Builds the section main menu.
-- @item_type SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS, SAINTSBOOK_ITEM_TYPE_CHOPSHOP, SAINTSBOOK_ITEM_TYPE_CHALLENGE
--
function cell_saintsbook_main_open_stage_1(item_type)
--Remove items from list...
for idx, val in pairs(Cell_saintsbook_items) do
if val.item_h ~= nil then
vint_object_destroy(val.item_h)
end
end
--Reset list...
Cell_saintsbook_item_count = 0
Cell_saintsbook_items = {}
--Populate list...
vint_dataresponder_request("saintsbook_categories", "cell_saintsbook_populate", 0, item_type)
--Sort List, puts completed items at the back of the list...
cell_saintsbook_sort()
--stage 2 go!
cell_saintsbook_main_open_stage_2()
end
--This is called via callback after we load our stuff...
function cell_saintsbook_main_open_stage_2()
--reset list position...
local h = vint_object_find("main_sub_grp")
vint_set_property(h, "anchor", 0,0)
local scroll_anim_h = vint_object_find("main_scroll_anim")
local twn_h = vint_object_find("main_scroll_twn", scroll_anim_h)
vint_set_property(twn_h, "start_value", 0, 0)
-- Show items in list...
cell_saintsbook_main_show_items(0)
cell_saintsbook_main_highlight_item(0)
if Cell_saintsbook_item_count > 4 then
local h = vint_object_find("content_clip")
local width, height = vint_get_property(h, "clip_size")
--show the scroll bar
Cell_saintsbook_main_scrollbar:set_property("visible", true)
Cell_saintsbook_main_scrollbar:set_size(SCROLLBAR_WIDTH, height)
else
-- hide the scroll bar
Cell_saintsbook_main_scrollbar:set_property("visible", false)
end
--Show the main screen....
cell_saintsbook_active_screen_set(SCREEN_TYPE_MAIN, true)
end
--TODO: organize these...
Cell_saintsbook_main_first_item = 0
Cell_saintsbook_main_last_item = 0
local main_first_mouse_item = 0
local main_last_mouse_item = 0
-------------------------------------------------------------------------------
-- Clears our current items in list and rebuilds them from the first to last...
--
-- @param first_item # of the first item you want to draw...
--
function cell_saintsbook_main_show_items(first_item, old_item)
if game_get_platform() == "PC" and Cell_saintsbook_scroll_tween_done == false then
return
end
--Remove any existing items...
for i, item in pairs(Cell_saintsbook_items) do
if item.item_h ~= nil then
vint_object_destroy(item.item_h)
item.item_h = nil
end
end
--Loop through items and build list
local main_item_h = vint_object_find("main_item")
vint_set_property(main_item_h, "visible", false)
if first_item < 0 then
first_item = 0
end
Cell_saintsbook_main_first_item = first_item
Cell_saintsbook_main_last_item = first_item + SAINTSBOOK_MAIN_MAX_ITEMS + 1
-- Set the range of the mouse inputs
main_first_mouse_item = first_item
main_last_mouse_item = main_first_mouse_item + 3
-- If scrolling down, offset by 1 item
if old_item ~= nil then
if first_item > old_item then
first_item = first_item - 1
end
end
for i = first_item, Cell_saintsbook_main_last_item do
if i >= Cell_saintsbook_item_count then
if game_get_platform() == "PC" then
cell_saintsbook_main_pc_scroll(Cell_saintsbook_main_first_item, false, old_item)
cell_saintsbook_main_activate_mouse()
end
return
end
--Do common stuff...
local item = Cell_saintsbook_items[i]
local item_clone_h = vint_object_clone(main_item_h)
vint_set_property(item_clone_h, "name", "main_item_clone")
vint_set_property(item_clone_h, "visible", true)
--Set button image...
local hint_btn = Vdo_hint_button:new("main_btn", item_clone_h)
hint_btn:set_button(CTRL_MENU_BUTTON_A)
--Set target name
local target_name_txt_h = vint_object_find("target_name_txt", item_clone_h)
if type(item.target_name) == "number" then
vint_set_property(target_name_txt_h, "text_tag_crc", item.target_name)
else
vint_set_property(target_name_txt_h, "text_tag", item.target_name)
end
--Set target image...
local target_img_h = vint_object_find("target_img", item_clone_h)
vint_set_property(target_img_h, "image", item.target_image .. "_t")
--Details...
local challenge_grp_h = vint_object_find("challenge_grp", item_clone_h)
local task_grp_h = vint_object_find("task_grp", item_clone_h)
--is the item selected... we set this to hide at first and then show it later if needed.
local contact_target_bmp_h = vint_object_find("contact_target_bmp", item_clone_h)
vint_set_property(contact_target_bmp_h, "visible", false)
--Fill out details...
if item.item_type == SAINTSBOOK_ITEM_TYPE_CHALLENGE then
--Challenge type... fill out data...
-- Contact Name
--local challenge_contact_txt_h = vint_object_find("challenge_contact_txt", item_clone_h)
--vint_set_property(challenge_contact_txt_h, "text_tag", item.contact_name)
--challenge_x_y
local x_y_h = vint_object_find("challenge_x_y", item_clone_h)
if item.units_crc ~= 0 then
local insert = { [0] = floor(item.units_completed),[1] = floor(item.units_total), [2] = item.units_crc }
local x_y_str = vint_insert_values_in_string("DIVERSION_CHALLENGES_UNITS", insert)
vint_set_property(x_y_h, "text_tag", x_y_str)
else
vint_set_property(x_y_h, "text_tag", floor(item.units_completed).. "/" ..floor(item.units_total))
end
--meter
local meter_bg_h = vint_object_find("meter_bg", item_clone_h)
local meter_fill_h = vint_object_find("meter_fill", item_clone_h)
local meter_max_width, meter_max_height = element_get_actual_size(meter_bg_h)
local pct = 0
if item.units_total ~= 0 then
pct = item.units_completed/item.units_total
end
local meter_target_width = meter_max_width * pct
element_set_actual_size(meter_fill_h, meter_target_width, meter_max_height)
--Remove unneeded item...
vint_object_destroy(task_grp_h)
else
--Hitman/chopshop type...
--local contact_name_txt_h = vint_object_find("contact_name_txt", item_clone_h)
--vint_set_property(contact_name_txt_h, "text_tag", item.contact_name)
--task_description
local task_description_h = vint_object_find("task_description", item_clone_h)
vint_set_property(task_description_h, "text_tag_crc", item.blurb_condensed)
--If selected item we need to show the icon
if item.is_selected == true then
--Show icon
vint_set_property(contact_target_bmp_h, "visible", true)
--Get icon name from type...
local icon_image = Cell_saintsbook_icons[item.item_type]
vint_set_property(contact_target_bmp_h, "image", icon_image)
end
--Remove unneeded item...
vint_object_destroy(challenge_grp_h)
end
--Reposition elements according to their index...
local x, y = vint_get_property(main_item_h, "anchor")
local target_x = x
local target_y = y + (SAINTSBOOK_MAIN_ITEM_SPACING * i)
vint_set_property(item_clone_h, "anchor", target_x, target_y)
local highlight_bg_h = vint_object_find("highlight_bg", item_clone_h)
local highlight_mouse_bg_h = vint_object_find("background", item_clone_h)
if game_get_platform() == "PC" then
item.highlight_h = highlight_mouse_bg_h
end
if Cell_saintsbook_main_selected_idx == i then
--Item is selected...
vint_set_property(highlight_bg_h, "visible", true)
vint_set_property(target_name_txt_h, "tint", SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.R, SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.G, SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.B)
-- Hide the button if not using the gamepad
if game_is_active_input_gamepad() == false then
local x, y = vint_get_property(target_name_txt_h, "anchor")
x = x - 38
vint_set_property(target_name_txt_h, "anchor", x,y)
hint_btn:set_visible(false)
end
else
--item is not selected...
hint_btn:set_visible(false)
--Item is selected...
vint_set_property(highlight_bg_h, "visible", false)
local x, y = vint_get_property(target_name_txt_h, "anchor")
x = x - 38
vint_set_property(target_name_txt_h, "anchor", x,y)
--delete border frame...
local contact_highlight_h = vint_object_find("contact_highlight", item_clone_h)
vint_object_destroy(contact_highlight_h)
end
--set disabled or not...
if item.is_completed == true then
vint_set_property(item_clone_h, "alpha", .3)
end
--store clone to item table...
item.item_h = item_clone_h
item.hint_btn = hint_btn
end
if game_get_platform() == "PC" then
cell_saintsbook_main_pc_scroll(Cell_saintsbook_main_first_item, false, old_item)
cell_saintsbook_main_activate_mouse()
end
end
function cell_saintsbook_main_activate_mouse()
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
for i = main_first_mouse_item, main_last_mouse_item do
if Cell_saintsbook_items[i] ~= nil and Cell_saintsbook_items[i].highlight_h ~= nil then
Mouse_input_tracker:add_mouse_input("mouse_move", "cell_saintsbook_main_mouse_move", 0, Cell_saintsbook_items[i].highlight_h)
Mouse_input_tracker:add_mouse_input("mouse_click", "cell_saintsbook_main_mouse_click", 0, Cell_saintsbook_items[i].highlight_h)
end
end
Hint_bar:add_mouse_inputs("cell_saintsbook", Mouse_input_tracker)
Mouse_input_tracker:add_mouse_input("mouse_scroll", "cell_saintsbook_mouse_scroll", 0, Clip_region.handle)
Mouse_input_tracker:subscribe(true)
if Scrollbar_mouse_input_tracker.enabled == false then
Scrollbar_mouse_input_tracker:remove_all()
Cell_saintsbook_main_scrollbar:add_mouse_inputs("cell_saintsbook_main", Scrollbar_mouse_input_tracker, 0)
end
-- Only want to call :subscribe when switching to this screen, not when updating the mouse
if Scrollbar_mouse_input_tracker.enabled == false then
Scrollbar_mouse_input_tracker:subscribe(true)
Scrollbar_mouse_input_tracker.enabled = true
end
end
end
function cell_saintsbook_main_mouse_click(event, target_handle)
local new_index = -1
for i = 0, Cell_saintsbook_item_count do
if Cell_saintsbook_items[i] ~= nil and Cell_saintsbook_items[i].highlight_h ~= nil then
if target_handle == Cell_saintsbook_items[i].highlight_h then
new_index = i
end
end
end
if new_index > -1 then
Cell_saintsbook_main_selected_idx = new_index
cell_saintsbook_main_select()
game_UI_audio_play("UI_Cell_Nav")
end
end
function cell_saintsbook_main_mouse_move(event, target_handle)
local new_index = -1
for i = 0, Cell_saintsbook_item_count do
if Cell_saintsbook_items[i] ~= nil and Cell_saintsbook_items[i].highlight_h ~= nil then
if target_handle == Cell_saintsbook_items[i].highlight_h then
new_index = i
end
end
end
if new_index > -1 then
if new_index ~= Cell_saintsbook_main_selected_idx then
Cell_saintsbook_main_selected_idx = new_index
cell_saintsbook_main_show_items(Cell_saintsbook_main_first_item)
game_UI_audio_play("UI_Cell_Nav")
end
end
end
function cell_saintsbook_main_mouse_drag(event, target_handle, mouse_x, mouse_y)
if Active_screen_type == SCREEN_TYPE_MAIN then
if Cell_saintsbook_main_scrollbar.tab_grp.handle == target_handle then
local new_start_index = Cell_saintsbook_main_scrollbar:drag_scrolltab(mouse_y, Cell_saintsbook_item_count - 3)
new_start_index = new_start_index - 1
cell_saintsbook_main_show_items(new_start_index, Cell_saintsbook_main_first_item)
end
end
end
-- Updates the mouse inputs for the list and snaps the scrolltab to the closest notch based on the visible index
--
function cell_saintsbook_main_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
if Active_screen_type == SCREEN_TYPE_MAIN then
if Cell_saintsbook_main_scrollbar.tab_grp.handle == target_handle then
Cell_saintsbook_main_scrollbar:release_scrolltab(Cell_saintsbook_main_first_item + 1, Cell_saintsbook_item_count - 3)
end
end
end
function cell_saintsbook_main_nav(direction, index_to_set)
if Cell_saintsbook_scroll_tween_done == false then
return
end
local instant_set = false
local item_to_select = Cell_saintsbook_main_selected_idx + direction
if direction == 0 then
item_to_select = index_to_set
end
if item_to_select >= Cell_saintsbook_item_count then
item_to_select = 0
instant_set = true
elseif item_to_select < 0 then
item_to_select = Cell_saintsbook_item_count - 1
instant_set = true
end
--This is where we should probably send the index and rebuild the list...
if game_get_platform() == "PC" then
-- Select the item
Cell_saintsbook_main_selected_idx = item_to_select
-- Maybe scroll
local scroll_item = Cell_saintsbook_main_first_item
if Cell_saintsbook_main_selected_idx < main_first_mouse_item then
scroll_item = Cell_saintsbook_main_selected_idx
elseif Cell_saintsbook_main_selected_idx > main_last_mouse_item then
scroll_item = Cell_saintsbook_main_selected_idx - 3
end
cell_saintsbook_main_show_items(scroll_item, Cell_saintsbook_main_first_item)
else
cell_saintsbook_main_highlight_item(item_to_select, instant_set)
end
game_UI_audio_play("UI_Cell_Nav")
end
-------------------------------------------------------------------------------
-- Navigates back to the top menu
--
function cell_saintsbook_main_back()
--lock controls
cell_saintsbook_controls_lock()
end
function cell_saintsbook_main_select()
--lock controls
cell_saintsbook_controls_lock()
cell_saintsbook_sub_open_stage_1()
game_UI_audio_play("UI_Cell_Select")
end
function cell_saintsbook_main_pc_scroll(first_item, instant_set, old_item)
if instant_set == true then
local new_y = 0
if first_item + 2 >= Cell_saintsbook_item_count then
new_y = -(Cell_saintsbook_item_count - 3) * SAINTSBOOK_MAIN_ITEM_SPACING
else
new_y = -first_item * SAINTSBOOK_MAIN_ITEM_SPACING
end
local h = vint_object_find("main_sub_grp")
vint_set_property(h, "anchor", 0, new_y)
h = vint_object_find("root_animation")
local scroll_anim_h = vint_object_find("main_scroll_anim", h)
local twn_h = vint_object_find("main_scroll_twn", scroll_anim_h)
vint_set_property(twn_h, "start_value", 0, new_y)
else
if first_item + 1 == old_item then
cell_saintsbook_main_animate_scroll(false)
elseif first_item - 1 == old_item then
cell_saintsbook_main_animate_scroll(true)
else
cell_saintsbook_main_pc_scroll(first_item, true)
end
end
Cell_saintsbook_main_scrollbar:set_value(Cell_saintsbook_item_count - 3, first_item + 1, false)
end
-------------------------------------------------------------------------------
-- Highlights a specific item and scrolls to it.
--
function cell_saintsbook_main_highlight_item(item_index, instant_set)
local nav_down = Cell_saintsbook_main_selected_idx < item_index
local old_index = Cell_saintsbook_main_selected_idx
Cell_saintsbook_main_selected_idx = item_index
if game_get_platform() ~= "PC" then
Cell_saintsbook_main_scrollbar:set_value(Cell_saintsbook_item_count , Cell_saintsbook_main_selected_idx + 1, false)
if instant_set == true then
local new_y = 0
if (nav_down == true and item_index + 2 >= Cell_saintsbook_item_count) or
(nav_down == false and item_index + 3 >= Cell_saintsbook_item_count) then
cell_saintsbook_main_show_items(Cell_saintsbook_item_count - 4 - 1)
new_y = -(Cell_saintsbook_item_count - 4) * SAINTSBOOK_MAIN_ITEM_SPACING
else
new_y = -item_index * SAINTSBOOK_MAIN_ITEM_SPACING
cell_saintsbook_main_show_items(max(item_index - 2, 0))
end
local h = vint_object_find("main_sub_grp")
vint_set_property(h, "anchor", 0, new_y)
h = vint_object_find("root_animation")
local scroll_anim_h = vint_object_find("main_scroll_anim", h)
local twn_h = vint_object_find("main_scroll_twn", scroll_anim_h)
vint_set_property(twn_h, "start_value", 0, new_y)
return
end
local animate = true
-- step 1 - rebuild new list
if nav_down == true and item_index - 2 < 0 then
cell_saintsbook_main_show_items(0)
animate = false
end
if nav_down == false and item_index == 0 then
cell_saintsbook_main_show_items(0)
animate = false
end
if (nav_down == true and item_index + 2 >= Cell_saintsbook_item_count) or
(nav_down == false and item_index + 3 >= Cell_saintsbook_item_count) then
cell_saintsbook_main_show_items(Cell_saintsbook_item_count - 4 - 1)
animate = false
end
-- step 3 - animate
if animate then
cell_saintsbook_main_show_items(Cell_saintsbook_main_selected_idx - 2)
cell_saintsbook_main_animate_scroll(nav_down)
end
end
end
function cell_saintsbook_main_animate_scroll(nav_down)
local h = vint_object_find("root_animation")
local scroll_anim_h = vint_object_find("main_scroll_anim", h)
local twn_h = vint_object_find("main_scroll_twn", scroll_anim_h)
local x, y = vint_get_property(twn_h, "start_value")
vint_set_property(twn_h, "duration", 0.2)
if nav_down == true then
vint_set_property(twn_h, "end_value", x, y - SAINTSBOOK_MAIN_ITEM_SPACING)
else
vint_set_property(twn_h, "end_value", x, y + SAINTSBOOK_MAIN_ITEM_SPACING)
end
vint_set_property(twn_h, "end_event", "cell_saintsbook_finish_scroll")
lua_play_anim(scroll_anim_h, 0)
Cell_saintsbook_scroll_tween_done = false
end
function cell_saintsbook_finish_scroll()
local h = vint_object_find("root_animation")
local scroll_anim_h = vint_object_find("main_scroll_anim", h)
local twn_h = vint_object_find("main_scroll_twn", scroll_anim_h)
local new_x, new_y = vint_get_property(twn_h, "end_value")
vint_set_property(twn_h, "start_value", new_x, new_y)
Cell_saintsbook_scroll_tween_done = true
end
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Sub page display.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Cell_saintsbook_sub_task_mask_height = 0
Cell_saintsbook_sub_task_height = 0
Cell_saintsbook_scroll_direction = 0
Cell_saintsbook_scroll_enabled = false
Cell_saintsbook_sub_scrollbar_thread = 0
CELL_SAINTSBOOK_SUB_PIXEL_RATE = 20
CELL_SAINTSBOOK_SUB_DURATION = 0.05
-------------------------------------------------------------------------------
-- Opens sub page from currently selected main index...
--
function cell_saintsbook_sub_open_stage_1()
if Cell_saintsbook_item_count == 0 then
return
end
-- Populate sub page with selected data from main page...
local item = Cell_saintsbook_items[Cell_saintsbook_main_selected_idx]
-- Unload old image if exists...
if Cell_saintsbook_contact_image ~= -1 then
game_peg_unload(Cell_saintsbook_contact_image)
end
if Cell_saintsbook_target_image ~= -1 then
game_peg_unload(Cell_saintsbook_target_image)
end
-- Stream the image and wait...
Cell_saintsbook_contact_image = cell_saintsbook_contact_image_get(item.contact_image)
Cell_saintsbook_target_image = item.target_image
game_peg_load_with_cb("cell_saintsbook_sub_open_stage_2", 2, Cell_saintsbook_contact_image, Cell_saintsbook_target_image)
end
function cell_saintsbook_sub_open_stage_2()
-- Populate sub page with selected data from main page...
local item = Cell_saintsbook_items[Cell_saintsbook_main_selected_idx]
local subpage_grp_h = vint_object_find("subpage_grp")
local mask_h = vint_object_find("mask", subpage_grp_h)
local mask_width, mask_height = element_get_actual_size(mask_h)
Cell_saintsbook_sub_task_mask_height = mask_height
--Find challenge and location groups
local challenge_grp_h = vint_object_find("challenge_grp", subpage_grp_h)
local location_grp_h = vint_object_find("location_grp", subpage_grp_h)
local gps_grp_h = vint_object_find("gps_grp", subpage_grp_h)
local selected_grp_h = vint_object_find("selected_grp", subpage_grp_h)
local task_icon_grp_h = vint_object_find("task_icon_grp", subpage_grp_h)
local completed_txt_h = vint_object_find("completed_txt", subpage_grp_h)
--Hide challenge and location groups, will show these depending on which mode we are in.
vint_set_property(challenge_grp_h, "visible", false)
vint_set_property(location_grp_h, "visible", false)
vint_set_property(gps_grp_h, "visible", false)
vint_set_property(task_icon_grp_h, "visible", false)
vint_set_property(selected_grp_h, "visible", false)
vint_set_property(completed_txt_h, "visible", false)
--Set Completed or not...
if item.is_completed == true then
vint_set_property(subpage_grp_h, "alpha", .3)
vint_set_property(completed_txt_h, "visible", true)
else
vint_set_property(subpage_grp_h, "alpha", 1)
end
--Common elements....
local target_name_txt_h = vint_object_find("target_name_txt", subpage_grp_h)
local target_img_h = vint_object_find("target_img", subpage_grp_h)
local location_desc_txt_h = vint_object_find("location_desc_txt", subpage_grp_h)
local cash_desc_txt_h = vint_object_find("cash_desc_txt", subpage_grp_h)
local respect_desc_txt_h = vint_object_find("respect_desc_txt", subpage_grp_h)
--local contact_name_h = vint_object_find("contact_name", subpage_grp_h)
--local contact_image_h = vint_object_find("contact_img", subpage_grp_h)
local task_condensed_h = vint_object_find("task_condensed", subpage_grp_h)
local task_icon_desc_h = vint_object_find("task_icon_desc", subpage_grp_h)
local task_long_h = vint_object_find("task_long", subpage_grp_h)
--Set our target name...
if type(item.target_name) == "number" then
vint_set_property(target_name_txt_h, "text_tag_crc", item.target_name)
else
vint_set_property(target_name_txt_h, "text_tag", item.target_name)
end
--Make sure russian fits here...
--Check widths against max size...
local max_width = 510
vint_set_property(target_name_txt_h, "scale", 1, 1)
local width, height = element_get_actual_size(target_name_txt_h)
if width > max_width then
local scale = max_width / width
width = width * scale
element_set_actual_size(target_name_txt_h, width, height)
end
--Target image
vint_set_property(target_img_h, "image", item.target_image)
--Cash and Respect
vint_set_property(cash_desc_txt_h, "text_tag", "{GAME_CASH}" .. format_cash(item.cash))
vint_set_property(respect_desc_txt_h, "text_tag", item.respect)
--Contact Name
--vint_set_property(contact_name_h, "text_tag", item.contact_name)
--Contact Image
local contact_image = cell_saintsbook_contact_image_get(item.contact_image)
--vint_set_property(contact_image_h, "image", contact_image)
--Setup scrollbox
--Condensed Blurb
if type(item.blurb_condensed) == "number" then
vint_set_property(task_condensed_h, "text_tag_crc", item.blurb_condensed)
else
vint_set_property(task_condensed_h, "text_tag", item.blurb_condensed)
end
--Long Blurb
if type(item.blurb_long) == "number" then
vint_set_property(task_long_h, "text_tag_crc", item.blurb_long)
else
vint_set_property(task_long_h, "text_tag", item.blurb_long)
end
--Arrange task descriptions
local task_condensed_x, task_condensed_y = vint_get_property(task_condensed_h, "anchor")
local task_long_x, task_long_y = vint_get_property(task_long_h, "anchor")
local task_condensed_width, task_condensed_height = element_get_actual_size(task_condensed_h)
local task_long_width, task_long_height = element_get_actual_size(task_long_h)
if item.blurb_condensed == 0 then
-- Hide condensed blurb
vint_set_property(task_condensed_h, "visible", false)
-- Reposition because we don't have a condensed blurb
task_long_y = task_condensed_y
vint_set_property(task_long_h, "anchor", task_long_x, task_long_y)
else
--Show condensed blurb
vint_set_property(task_condensed_h, "visible", true)
task_long_y = task_condensed_y + task_condensed_height
vint_set_property(task_long_h, "anchor", task_long_x, task_condensed_y + task_condensed_height + 20)
end
Cell_saintsbook_sub_task_height = task_long_y + task_long_height
if Cell_saintsbook_sub_task_mask_height < Cell_saintsbook_sub_task_height then
Cell_saintsbook_sub_scrollbar:set_property("visible", true)
Cell_saintsbook_sub_scrollbar:set_size(SCROLLBAR_WIDTH, Cell_saintsbook_sub_task_mask_height)
cell_saintsbook_sub_scrollbar_set()
Cell_saintsbook_scroll_enabled = true
else
Cell_saintsbook_sub_scrollbar:set_property("visible", false)
Cell_saintsbook_scroll_enabled = false
end
local gps_txt_h = vint_object_find("gps_to_target_txt", gps_grp_h)
-- Specific stuff pertaining to each type...
if item.item_type == SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS or item.item_type == SAINTSBOOK_ITEM_TYPE_CHOPSHOP then
-- Show location info...
vint_set_property(location_grp_h, "visible", true)
--show GPS info
vint_set_property(gps_grp_h, "visible", true)
-- Set target location...
if item.target_location == 0 then
-- no target location so hide the field...
vint_set_property(location_desc_txt_h, "visible", false)
else
vint_set_property(location_desc_txt_h, "visible", true)
vint_set_property(location_desc_txt_h, "text_tag_crc", item.target_location)
end
-- Determine what icon to show for map finding...
local task_icon_h = vint_object_find("task_icon", subpage_grp_h)
if item.item_type == SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS then
--Show assassination Icons...
vint_set_property(task_icon_h, "image", "ui_saintsbook_hitman")
elseif item.item_type == SAINTSBOOK_ITEM_TYPE_CHOPSHOP then
--Show chopshop icons...
vint_set_property(task_icon_h, "image", "ui_saintsbook_vehicle")
end
--Check if item is selected, then set it to selected target...
if item.is_selected == true then
Cell_saintsbook_selected_target = Cell_saintsbook_main_selected_idx
else
--not selected so we reset the selected target index.
Cell_saintsbook_selected_target = -1
end
--Set selected target, this determines if the target is selected.
cell_saintsbook_sub_set_selected()
else
-- Show challenge page...
vint_set_property(challenge_grp_h, "visible", true)
-- Find all objects first...
local x_y_h = vint_object_find("challenge_x_y", challenge_grp_h)
local meter_bg_h = vint_object_find("meter_bg", challenge_grp_h)
local meter_fill_h = vint_object_find("meter_fill", challenge_grp_h)
--challenge_x_y
if item.units_crc ~= 0 then
local insert = { [0] = floor(item.units_completed),[1] = floor(item.units_total), [2] = item.units_crc }
local x_y_str = vint_insert_values_in_string("DIVERSION_CHALLENGES_UNITS", insert)
vint_set_property(x_y_h, "text_tag", x_y_str)
else
vint_set_property(x_y_h, "text_tag", floor(item.units_completed).."/"..floor(item.units_total))
end
-- Set Meter
local meter_max_width, meter_max_height = element_get_actual_size(meter_bg_h)
local pct = 0
if item.units_total ~= 0 then
pct = item.units_completed/item.units_total
end
local meter_target_width = meter_max_width * pct
element_set_actual_size(meter_fill_h, meter_target_width, meter_max_height)
end
--Reset Scrollbar...
cell_saintsbook_sub_scrollbar_reset()
--Navigate to sub screen...
cell_saintsbook_active_screen_set(SCREEN_TYPE_SUB)
cell_saintsbook_sub_activate_mouse()
end
function cell_saintsbook_sub_activate_mouse()
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
-- Select/deselect button
local item = Cell_saintsbook_items[Cell_saintsbook_main_selected_idx]
if item.item_type == SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS or item.item_type == SAINTSBOOK_ITEM_TYPE_CHOPSHOP then
local subpage_grp_h = vint_object_find("subpage_grp")
local gps_grp_h = vint_object_find("gps_grp", subpage_grp_h)
Mouse_input_tracker:add_mouse_input("mouse_move", "cell_saintsbook_mouse_move", 0, gps_grp_h)
Mouse_input_tracker:add_mouse_input("mouse_click", "cell_saintsbook_mouse_click", 0, gps_grp_h)
end
Hint_bar:add_mouse_inputs("cell_saintsbook", Mouse_input_tracker)
Mouse_input_tracker:add_mouse_input("mouse_scroll", "cell_saintsbook_mouse_scroll", 0, Clip_region.handle)
Mouse_input_tracker:subscribe(true)
Scrollbar_mouse_input_tracker:subscribe(false)
Scrollbar_mouse_input_tracker.enabled = false
end
end
function cell_saintsbook_sub_mouse_click(event, target_handle)
local subpage_grp_h = vint_object_find("subpage_grp")
local gps_grp_h = vint_object_find("gps_grp", subpage_grp_h)
if target_handle == gps_grp_h then
cell_saintsbook_sub_select()
end
end
function cell_saintsbook_sub_mouse_move(event, target_handle)
local subpage_grp_h = vint_object_find("subpage_grp")
local gps_txt_h = vint_object_find("gps_to_target_txt", subpage_grp_h)
vint_set_property(gps_txt_h, "tint", SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.R, SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.G, SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.B)
local gps_grp_h = vint_object_find("gps_grp", subpage_grp_h)
if target_handle == gps_grp_h then
vint_set_property(gps_txt_h, "tint", SAINTSBOOK_COLOR_ICON_SELECTED.R, SAINTSBOOK_COLOR_ICON_SELECTED.G, SAINTSBOOK_COLOR_ICON_SELECTED.B)
end
end
function cell_saintsbook_sub_nav(event, value)
if Cell_saintsbook_scroll_enabled == false then
return
end
local h = vint_object_find("root_animation")
local scroll_anim_h = vint_object_find("sub_scroll_anim", h)
-- First check if the stick is pointed in any direction
if abs(value) < 0.5 then
-- Stop scrolling if it's not
if Cell_saintsbook_scroll_direction ~= 0 then
-- Kill the thread for scrolling
if Cell_saintsbook_sub_scrollbar_thread ~= 0 then
thread_kill(Cell_saintsbook_sub_scrollbar_thread)
Cell_saintsbook_sub_scrollbar_thread = 0
end
-- Pause the animation
vint_set_property(scroll_anim_h, "is_paused", true)
Cell_saintsbook_scroll_direction = 0
cell_saintsbook_sub_scrollbar_set()
end
else
-- Just continue tweening if we're still going in the same direction
if (Cell_saintsbook_scroll_direction > 0 and value > 0) or
(Cell_saintsbook_scroll_direction < 0 and value < 0) then
return
elseif Cell_saintsbook_scroll_direction ~= 0 then
-- Stop the animation if we're changing direction
vint_set_property(scroll_anim_h, "is_paused", true)
end
-- Kill the thread if it exists, and reset the scrollbar
if Cell_saintsbook_sub_scrollbar_thread ~= 0 then
thread_kill(Cell_saintsbook_sub_scrollbar_thread)
Cell_saintsbook_sub_scrollbar_thread = 0
cell_saintsbook_sub_scrollbar_set()
end
-- If the value is negative, we're naving down
local nav_down = (value < 0)
local movement = 0
local pixel_per_duration = 0
local subpage_grp_h = vint_object_find("subpage_grp")
local task_long_h = vint_object_find("task_desc_scroll", subpage_grp_h)
local task_x, task_y = vint_get_property(task_long_h, "anchor")
-- Find the bottom of the text
local task_bottom = task_y + Cell_saintsbook_sub_task_height
-- Prepare for movement
if nav_down == false then
-- Move to the top
if task_y < 0 then
movement = -(task_y)
end
else
-- Move to the bottom
movement = -(task_bottom - Cell_saintsbook_sub_task_mask_height)
end
-- If we're going to be moving, then start the tween
if movement ~= 0 then
local twn_h = vint_object_find("sub_scroll_twn", scroll_anim_h)
-- Calculate the duration of the tween, this is the amount of time it should take to scroll from the current position to bottom
-- This speed should be consistent no matter how much movement is left
local duration = CELL_SAINTSBOOK_SUB_DURATION * (abs(movement) / CELL_SAINTSBOOK_SUB_PIXEL_RATE)
-- Create the tween, its told to scroll until it gets all the way to the top or the bottom, but will be killed when the
-- stick is released
vint_set_property(twn_h, "duration", duration)
vint_set_property(twn_h, "start_value", task_x, task_y)
vint_set_property(twn_h, "end_value", task_x, task_y + movement)
vint_set_property(twn_h, "end_event", "cell_saintsbook_sub_finish_scroll")
lua_play_anim(scroll_anim_h, 0)
-- Start the thread for scrolling
Cell_saintsbook_sub_scrollbar_thread = thread_new("cell_saintsbook_scroll_thread")
-- Store our scroll direction
if nav_down == true then
Cell_saintsbook_scroll_direction = -1
else
Cell_saintsbook_scroll_direction = 1
end
end
end
end
function cell_saintsbook_scroll_thread()
while true do
-- Set the scrollbar position based on where the text currently is (should be tweening)
cell_saintsbook_sub_scrollbar_set()
thread_yield()
end
end
-------------------------------------------------------------------------------
-- Resets the scrollbar for the subscreens...
-------------------------------------------------------------------------------
function cell_saintsbook_sub_scrollbar_reset()
--Reset Tween
local scroll_anim_h = vint_object_find("sub_scroll_anim")
local twn_h = vint_object_find("sub_scroll_twn", scroll_anim_h)
vint_set_property(twn_h, "start_value", 0, 0)
--Reset Object we are scrolling...
local subpage_grp_h = vint_object_find("subpage_grp")
local task_desc_scroll_h = vint_object_find("task_desc_scroll", subpage_grp_h)
vint_set_property(task_desc_scroll_h, "anchor", 0, 0)
--Recalculate scrollbar...
cell_saintsbook_sub_scrollbar_set()
end
function cell_saintsbook_sub_scrollbar_set()
local subpage_grp_h = vint_object_find("subpage_grp")
local task_long_h = vint_object_find("task_desc_scroll", subpage_grp_h)
local task_x, task_y = vint_get_property(task_long_h, "anchor")
local task_bottom = task_y + Cell_saintsbook_sub_task_height
-- Create the 'indices' to reference with the scroll bar.. we do this in pixel amoutns
-- Our current index is how far the task_bottom is from the entire height of the text
local index = floor(Cell_saintsbook_sub_task_height - task_bottom) + 1-- not sure about this +1
-- The max index is the height of the task, minus the visible area of the text
local max_index = floor(Cell_saintsbook_sub_task_height - Cell_saintsbook_sub_task_mask_height) + 1
if index > max_index then
index = max_index
end
Cell_saintsbook_sub_scrollbar:set_value(max_index, index, true)
end
function cell_saintsbook_sub_finish_scroll()
-- Reset the start values for the tween when the scroll is no longer occuring
local h = vint_object_find("root_animation")
local scroll_anim_h = vint_object_find("sub_scroll_anim", h)
local twn_h = vint_object_find("sub_scroll_twn", scroll_anim_h)
local new_x, new_y = vint_get_property(twn_h, "end_value")
vint_set_property(twn_h, "start_value", new_x, new_y)
-- Kill the thread that runs while the button is held
if Cell_saintsbook_sub_scrollbar_thread ~= 0 then
thread_kill(Cell_saintsbook_sub_scrollbar_thread)
Cell_saintsbook_sub_scrollbar_thread = 0
cell_saintsbook_sub_scrollbar_set()
end
Cell_saintsbook_scroll_direction = 0
end
function cell_saintsbook_sub_select()
local item = Cell_saintsbook_items[Cell_saintsbook_main_selected_idx]
if item.is_completed == true then
return
end
if item.item_type == SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS then
--unselect all targets matching assassinations
for i, item in pairs(Cell_saintsbook_items) do
if item.item_type == SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS then
item.is_selected = false
end
end
--select the current target.
item.is_selected = sb_select_hitman_target(item.group_index, item.target_index)
game_UI_audio_play("UI_Cell_Select")
elseif item.item_type == SAINTSBOOK_ITEM_TYPE_CHOPSHOP then
--unselect all targets matching assassinations
for i, item in pairs(Cell_saintsbook_items) do
if item.item_type == SAINTSBOOK_ITEM_TYPE_CHOPSHOP then
item.is_selected = false
end
end
--select the current target.
item.is_selected = sb_select_chop_shop_vehicle(item.group_index, item.target_index)
game_UI_audio_play("UI_Cell_Select")
end
Cell_saintsbook_items[Cell_saintsbook_main_selected_idx].is_selected = item.is_selected
if item.is_selected == true then
Cell_saintsbook_selected_target = Cell_saintsbook_main_selected_idx
else
Cell_saintsbook_selected_target = -1
end
cell_saintsbook_sub_set_selected()
end
-------------------------------------------------------------------------------
-- If our target is selected this sets it up in the proper state.
--
function cell_saintsbook_sub_set_selected()
local subpage_grp_h = vint_object_find("subpage_grp")
local gps_grp_h = vint_object_find("gps_grp", subpage_grp_h)
local gps_txt_h = vint_object_find("gps_to_target_txt", gps_grp_h)
local selected_grp_h = vint_object_find("selected_grp", subpage_grp_h)
local task_icon_grp_h = vint_object_find("task_icon_grp", subpage_grp_h)
if Cell_saintsbook_selected_target == Cell_saintsbook_main_selected_idx then
vint_set_property(gps_txt_h, "text_tag", "SB_DESELECT_TARGET")
vint_set_property(selected_grp_h, "visible", true)
vint_set_property(task_icon_grp_h, "visible", true)
else
vint_set_property(gps_txt_h, "text_tag", "SB_SELECT_TARGET")
vint_set_property(selected_grp_h, "visible", false)
vint_set_property(task_icon_grp_h, "visible", false)
end
--align button
local center_x = 263 --this is the center of the button
local gps_btn_grp_h = vint_object_find("gps_btn_grp", gps_grp_h)
local text_x, text_y = vint_get_property(gps_txt_h, "anchor")
local text_width, text_height = element_get_actual_size(gps_txt_h)
local width = text_x + text_width
local x, y = vint_get_property(gps_btn_grp_h, "anchor")
x = center_x - (width * 0.5)
vint_set_property(gps_btn_grp_h, "anchor", x, y)
local gps_btn_h = vint_object_find("gps_btn", gps_btn_grp_h)
if game_is_active_input_gamepad() == false then
vint_set_property(gps_btn_h, "visible", false)
else
vint_set_property(gps_btn_h, "visible", true)
end
end
function cell_saintsbook_sub_back()
--lock controls
cell_saintsbook_controls_lock()
cell_saintsbook_main_show_items(Cell_saintsbook_main_first_item)
--Navigate to main screen...
cell_saintsbook_active_screen_set(SCREEN_TYPE_MAIN)
end
-------------------------------------------------------------------------------
-- Common functions for all screens.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Populate function via responder for saintsbook.
-- This is a generic responder used for both challenges, hitman and diversion
-- the additional parameters are determined by the item type.
--
function cell_saintsbook_populate(item_type, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13 )
if item_type == SAINTSBOOK_ITEM_TYPE_CHALLENGE then
--Its a challenge...
param9 = 0 --No use for acheivement
if param11 == nil then
param11 = ""
end
Cell_saintsbook_items[Cell_saintsbook_item_count] = {
item_h = -1,
item_type = item_type,
contact_name = param1,
contact_image = param2,
target_image = param11, --get target image...
target_name = param3, -- Target name is also the challenge name.
blurb_condensed = 0, --no blurb condensed for challenges.
blurb_long = param12, --This is a CRC.
units_completed = param4,
units_total = param5,
units_crc = param6,
cash = param7,
respect = param8,
achievement_value = param9,
is_completed = param10,
}
else
--Its hitman or chopshop...
Cell_saintsbook_items[Cell_saintsbook_item_count] = {
item_h = -1,
item_type = item_type,
contact_name = param1,
contact_image = param2,
blurb_condensed = param3,
blurb_long = param4,
target_name = param5,
target_image = param6,
target_location = param7,
cash = param8,
respect = param9,
is_completed = param10,
group_index = param11,
target_index = param12,
is_selected = param13,
}
end
if Cell_saintsbook_items[Cell_saintsbook_item_count].is_selected == true then
Cell_saintsbook_selected_target = Cell_saintsbook_item_count
end
Cell_saintsbook_item_count = Cell_saintsbook_item_count + 1
end
-------------------------------------------------------------------------------
-- Sorts saintsbook main menu...
-- For now it just puts the completed items at the back of the list...
--
function cell_saintsbook_sort()
local front_list = {}
local back_list = {}
local front_list_count = 0
local back_list_count = 0
--split list...
for key, val in pairs(Cell_saintsbook_items) do
if val.is_completed == false then
front_list[front_list_count] = val
front_list_count = front_list_count + 1
else
back_list[back_list_count] = val
back_list_count = back_list_count + 1
end
end
--combine lists back into saintsbook items... first front then back..
Cell_saintsbook_items = {}
Cell_saintsbook_item_count = 0
for key, val in pairs(front_list) do
Cell_saintsbook_items[Cell_saintsbook_item_count] = val
Cell_saintsbook_item_count = Cell_saintsbook_item_count + 1
end
for key, val in pairs(back_list) do
Cell_saintsbook_items[Cell_saintsbook_item_count] = val
Cell_saintsbook_item_count = Cell_saintsbook_item_count + 1
end
end
function cell_saintsbook_map_restored()
end
-------------------------------------------------------------------------------
-- Handles dummy callbacks.
--
function saints_book_empty_func()
end
-------------------------------------------------------------------------------
-- Returns an alternate contact image based on what we have in the contacts
-- table. This is because saintsbook and missions use the same contact table
-- but different images. So we translate them this way...
--
function cell_saintsbook_contact_image_get(image)
local image_test = Cell_saintsbook_contact_images[image]
if image_test ~= nil then
return image_test
end
return image
end
-------------------------------------------------------------------------------
-- Data saintsbook to maintain navigation callbacks
-- and other data between screens.
--
Saintsbook_screens = {
[SCREEN_TYPE_MAIN] = {
nav = cell_saintsbook_main_nav,
select = cell_saintsbook_main_select,
back = cell_saintsbook_exit_to_menu,
exit = cell_saintsbook_exit_to_game,
selected_idx = 1,
},
[SCREEN_TYPE_SUB] = {
nav = saints_book_empty_func,
select = cell_saintsbook_sub_select,
back = cell_saintsbook_sub_back,
exit = cell_saintsbook_exit_to_game,
selected_idx = 1
}
}