SCALE_FONT_STORE_CRIB_LIST = 0.8
STORE_CRIB_POPUP_X = 132
STORE_CRIB_POPUP_Y = 267
Store_common_screen_grp_x = -640
Store_crib_doc_handle = -1
Crib_title = -1
Store_crib_top_menu = {}
Store_crib_title_in_anim = -1
-- Hint bar and store header vdo's.
local Store_logo1
local Store_logo2
local Not_popup_grp
local Reward_image
local GVT_CARS = 0
local GVT_HELICOPTERS = 1
local GVT_AIRPLANES = 2
local GVT_WATERCRAFT = 3
local Previous_screen
-- We used this as a reference to the current submenu we are building.
local Store_crib_building_menu = {}
-- keeps track of which selection we were on when leaving to a sub-document
local Store_crib_current_menu_selection = 1
local Store_crib_screen_to_push = -1
local Hint_bar_mouse_input_tracker
local Game_platform
local Transition_to_garage_type = -1
local Wait_for_fade_thread_id = -1
---------------------------------------------------------------------------
-- Initialize crib Store (Customization)
---------------------------------------------------------------------------
function store_crib_build_top_menu()
Store_crib_top_menu = {}
local always_valid = true
-- cash MOVED TO CELL PHONE, MAYBE IT WILL COME BACK?
--[[if always_valid then
local index = #Store_crib_top_menu + 1
Store_crib_top_menu[index] = { label = "COMPLETION_CASH", type = TYPE_BUTTON, on_select = store_crib_open_cash, screen = "store_crib_cash", id = index }
end]]
-- wardrobe
if always_valid then
local index = #Store_crib_top_menu + 1
Store_crib_top_menu[index] = { label = "MENU_SWAP_WARDROBE", type = TYPE_BUTTON, on_select = store_crib_open_screen, screen = "store_clothing", id = index}
end
local disable_garage = crib_is_garage_disabled()
if disable_garage ~= true then
-- garage GVT_CARS
if crib_has_garage_with_vehicles_of_type(GVT_CARS) then
local index = #Store_crib_top_menu + 1
Store_crib_top_menu[index] = { label = "GARAGE_CRIB_NAME", type = TYPE_BUTTON, on_select = store_crib_open_garage, screen = "store_vehicle", id = index, garage_type = GVT_CARS }
end
-- garage GVT_HELICOPTERS
if crib_has_garage_with_vehicles_of_type(GVT_HELICOPTERS) then
local index = #Store_crib_top_menu + 1
Store_crib_top_menu[index] = { label = "GARAGE_HELIPORT", type = TYPE_BUTTON, on_select = store_crib_open_garage, screen = "store_vehicle", id = index, garage_type = GVT_HELICOPTERS }
end
-- garage GVT_AIRPLANES
if crib_has_garage_with_vehicles_of_type(GVT_AIRPLANES) then
local index = #Store_crib_top_menu + 1
Store_crib_top_menu[index] = { label = "GARAGE_HANGAR", type = TYPE_BUTTON, on_select = store_crib_open_garage, screen = "store_vehicle", id = index, garage_type = GVT_AIRPLANES }
end
-- garage GVT_WATERCRAFT
if crib_has_garage_with_vehicles_of_type(GVT_WATERCRAFT) then
local index = #Store_crib_top_menu + 1
Store_crib_top_menu[index] = { label = "GARAGE_DOCK", type = TYPE_BUTTON, on_select = store_crib_open_garage, screen = "store_vehicle", id = index, garage_type = GVT_WATERCRAFT }
end
end
-- weapons
if always_valid then
local index = #Store_crib_top_menu + 1
Store_crib_top_menu[index] = { label = "WPNSTOR_TITLE_WEAPON_CACHE", type = TYPE_BUTTON, on_select = store_crib_open_screen, screen = "store_weapon", id = index }
end
-- Check to see if we've unlocked the gang customization menu...
if store_gang_is_unlocked() then
local index = #Store_crib_top_menu + 1
Store_crib_top_menu[index] = { label = "GANG_CUST_TITLE", type = TYPE_BUTTON, on_select = store_crib_open_screen, screen = "store_gang", id = index }
end
-- Check if this is an upgradeable "stronghold" crib...
if crib_is_stronghold() and Completion_is_client() == false then
local index = #Store_crib_top_menu + 1
Store_crib_top_menu[index] = { label = "MENU_STRONGHOLD_CUSTOMIZATION", type = TYPE_BUTTON, on_select = store_crib_open_screen, screen = "store_stronghold", id = index }
end
--add the exit option
local index = #Store_crib_top_menu + 1
Store_crib_top_menu[index] = { label = "STORE_EXIT", type = TYPE_BUTTON, on_select = store_crib_exit, screen = "", id = index }
end
function store_crib_init()
Store_common_current_highlight_color = COLOR_STORE_REWARDS_PRIMARY
Wait_for_fade_thread_id = -1
-- unload the full screen map to pillage memory
pause_map_dump()
Game_platform = game_get_platform()
Store_crib_doc_handle = vint_document_find("store_crib")
Store_crib_title_in_anim = Vdo_anim_object:new("crib_title_anim", 0, Store_crib_doc_handle)
local store_group = vint_object_find("screen_grp",0,Store_common_doc_handle)
vint_set_property(store_group,"visible",false)
-- Set up some callbacks for the common store script
Store_common_populate_list_cb = store_crib_populate_list
Store_common_exit_cb = store_crib_exit
-- Subscribe to the button presses we need, Input_tracker is created in store_common.lua
Input_tracker:subscribe(false)
bg_saints_set_type(BG_TYPE_STRONGHOLD)
--Set Mask
local cell_mask = Vdo_base_object:new("cell_mask", 0, Store_common_doc_handle)
cell_mask:set_visible(true)
cell_mask:set_property("mask", true)
cell_mask:set_property("screen_size",488,720)
--cell_mask:set_anchor(344,360)
if vint_is_std_res() then
Store_common_screen_grp_x = -320
end
--Setup Button Hints
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
Store_common_hint_bar:set_hints(hint_data)
Store_common_hint_bar:set_visible(true)
if game_is_active_input_gamepad() then
local hint_rotate_data = {
{CTRL_BUTTON_RS, "STORE_ZOOM_ROTATE"},
}
Store_common_rotate_hint:set_hints(hint_rotate_data)
end
if Game_platform == "PC" then
Mouse_input_tracker:subscribe(false)
Hint_bar_mouse_input_tracker = Vdo_input_tracker:new()
Store_common_hint_bar:add_mouse_inputs("store_crib", Hint_bar_mouse_input_tracker)
Hint_bar_mouse_input_tracker:subscribe(true)
end
local store_megalist_grp_h = vint_object_find("store_megalist_grp",0,Store_common_doc_handle)
vint_set_property(store_megalist_grp_h, "anchor", 0, 0)
-- Set Store Header colors
Store_header:set_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY, COLOR_STORE_REWARDS_TERTIARY)
Store_header:set_visible(true)
Active_list:set_highlight_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY)
-- Everything that is not in the popup so we can fade it when the popup is active
Not_popup_grp = Vdo_base_object:new("not_popup_grp", 0, Store_common_doc_handle)
-- Setup purchase popup
Store_common_popup:set_visible(false)
Store_common_popup:set_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY, COLOR_STORE_REWARDS_TERTIARY)
Store_common_popup:set_size(STORE_COMMON_LIST_SIZE, (LIST_BUTTON_HEIGHT * 5) + (LIST_BUTTON_SPACE * 5))
Store_common_popup:set_anchor(STORE_CRIB_POPUP_X,STORE_CRIB_POPUP_Y)
Crib_title = vint_object_find("store_title_grp",0,Store_crib_doc_handle)
store_crib_build_top_menu()
-- Pass the table data to the megalist vdo.
Menu_data = Store_crib_top_menu
-- Pass the table data to the megalist vdo.
store_crib_populate_list(Menu_data, 1)
ui_audio_post_event("Enter_Crib")
--play background anim...
store_crib_bg_anim()
store_unlock_controls()
character_enable_mouse_drag(false)
end
-- Cleanup function called on document unload.
--
function store_crib_cleanup()
if Wait_for_fade_thread_id ~= -1 then
thread_kill(Wait_for_fade_thread_id)
end
-- Nuke all button subscriptions
Input_tracker:subscribe(false)
store_crib_enable_mouse(false)
-- reload the full screen map
pause_map_restore()
-- Some things need to be cleaned up right away when a store doc is unloading, particular disabled inputs which have
-- callbacks to the script that is unloading.
store_common_cleanup_current_store()
end
-- Called when this interface becomes the top one on the stack again.
--
function store_crib_gained_focus()
Store_common_current_highlight_color = COLOR_STORE_REWARDS_PRIMARY
Wait_for_fade_thread_id = thread_new("store_crib_waiting_for_fade")
end
function store_crib_waiting_for_fade()
while not sfx_faded_in() do
thread_yield()
end
-- Reset our header
Store_header:clear_titles()
-- Store_header:enable_price_respect(true)
Store_header:reformat_and_resize(false)
Store_header:set_price(nil)
Store_common_popup:set_anchor(STORE_CRIB_POPUP_X,STORE_CRIB_POPUP_Y)
--clear the rotate hint out
Store_common_rotate_hint:set_visible(false)
-- make background so it covers up the world
Input_tracker:subscribe(true)
vint_set_property(Crib_title,"visible",true)
-- Need to clear out menu and menu stacks
store_common_stack_clear_menu()
store_common_stack_clear_id()
store_common_stack_clear_index()
--reset the exit cb
Store_common_exit_cb = store_crib_exit
-- Pass the table data to the megalist vdo.
Menu_data = Store_crib_top_menu
--reset the bg to a strip
bg_saints_set_type(BG_TYPE_STRONGHOLD,true)
local cell_mask = Vdo_base_object:new("cell_mask", 0, Store_common_doc_handle)
cell_mask:set_visible(true)
cell_mask:set_property("mask", true)
local store_crib_in_anim = Vdo_anim_object:new("store_crib_in_anim", 0, Store_common_doc_handle)
local crib_in_mask_twn_h = Vdo_tween_object:new("crib_in_mask_twn", store_crib_in_anim.handle)
local mask_end_x,mask_end_y = crib_in_mask_twn_h:get_property("end_value")
crib_in_mask_twn_h:set_property("start_value", mask_end_x, mask_end_y)
local store_common_screen_grp_h = vint_object_find("screen_grp", 0, Store_common_doc_handle)
local screen_x,screen_y = vint_get_property(store_common_screen_grp_h, "anchor")
vint_set_property(store_common_screen_grp_h, "anchor", Store_common_screen_grp_x, screen_y)
if Previous_screen == "store_stronghold" then
store_crib_build_top_menu()
store_crib_populate_list(Store_crib_top_menu, Store_crib_current_menu_selection)
if Hint_bar_mouse_input_tracker ~= nil then
Store_common_hint_bar:add_mouse_inputs("store_crib", Hint_bar_mouse_input_tracker)
Hint_bar_mouse_input_tracker:subscribe(true)
end
end
if Previous_screen == "store_stronghold" or Previous_screen == "store_vehicle" then
local title_twn = Vdo_tween_object:new("title_twn", 0, Store_crib_doc_handle)
title_twn:set_property("start_value",-800,0)
title_twn:set_property("end_value",0,0)
title_twn:set_end_event("store_crib_anim_complete")
local mask_twn = Vdo_tween_object:new("mask_twn", 0, Store_crib_doc_handle)
local new_x = 104
if vint_is_std_res() then
new_x = 50
end
mask_twn:set_property("start_value", new_x, -52)
mask_twn:set_property("end_value", new_x, -52)
vint_apply_start_values(Store_crib_title_in_anim.handle)
Store_crib_title_in_anim:play()
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:subscribe(true)
end
end
vint_apply_start_values(store_crib_in_anim.handle)
store_crib_in_anim:play()
Not_popup_grp:set_alpha(1)
--reset the hints
local hint_data = {}
hint_data = { {CTRL_MENU_BUTTON_B, "MENU_BACK"}, }
Store_common_hint_bar:set_hints(hint_data)
-- Pass the table data to the megalist vdo.
store_crib_populate_list(Menu_data, Store_crib_current_menu_selection)
store_crib_enable_mouse(true)
Wait_for_fade_thread_id = -1
end
function store_crib_bg_anim()
local store_crib_in_anim = Vdo_anim_object:new("store_crib_in_anim", 0, Store_common_doc_handle)
store_crib_in_anim:play()
vint_apply_start_values(store_crib_in_anim.handle)
vint_apply_start_values(Store_crib_title_in_anim.handle)
Store_crib_title_in_anim:play()
local store_group = vint_object_find("screen_grp",0,Store_common_doc_handle)
vint_set_property(store_group,"visible",true)
bg_saints_show(true)
bg_saints_slide_in()
end
function store_crib_back_out_anim( animate_title )
local back_out_anim = Vdo_anim_object:new("store_crib_out_anim", 0, Store_common_doc_handle)
local back_out_end_twn = Vdo_tween_object:new("common_anchor_out_twn", back_out_anim.handle)
back_out_end_twn:set_end_event("store_crib_back_out_anim_complete")
if animate_title then
local title_twn = Vdo_tween_object:new("title_twn", 0, Store_crib_doc_handle)
title_twn:set_property("start_value",0,0)
title_twn:set_property("end_value",-800,0)
Store_crib_title_in_anim:play()
end
bg_saints_set_background(false)
back_out_anim:play()
end
function store_crib_anim_complete()
end
function store_crib_back_out_anim_complete(tween_h, event)
-- if we are not going to the stronghold screen, kill the mask
if Store_crib_screen_to_push ~= "store_stronghold" then
local cell_mask = Vdo_base_object:new("cell_mask", 0, Store_common_doc_handle)
cell_mask:set_visible(false)
cell_mask:set_property("mask", false)
end
if Transition_to_garage_type ~= -1 then
-- Set up going to garage
store_crib_init_crib_garage(Transition_to_garage_type)
Transition_to_garage_type = -1
end
if Previous_screen == "store_vehicle" then
bg_saints_set_type(BG_TYPE_CENTER, true, 1280)
return
end
-- attempt to push screen. If something bad happens kick the user back to game.
local success = push_screen(Store_crib_screen_to_push)
if success == false then
pop_screen()
end
end
function store_lock_controls()
Input_tracker:subscribe(false)
store_crib_enable_mouse(false)
end
function store_unlock_controls()
debug_print("vint","THIS IS REALLY BAD\n")
Input_tracker:subscribe(true)
store_crib_enable_mouse(true)
end
-- Called when player requests exiting store.
--
function store_crib_exit()
Store_common_popup:populate_list(Yes_no_choices, 2, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("MENU_TITLE_WARNING")
Store_common_popup:set_text("MENU_EXIT_CRIB")
Store_common_popup:nav_enable(true, "store_crib_exit_final", "store_crib_popup_nav")
Not_popup_grp:set_alpha(.5)
store_crib_enable_mouse(false)
end
-- Called when player has responded to store exit confirmation dialog.
--
-- event: input response from the player
--
function store_crib_exit_final(event)
Store_common_popup:nav_enable(false, nil, nil)
-- The user hit the B button and is exiting
-- This is redundant to selecting "No" in the list
if event == "back" then
game_UI_audio_play("UI_Main_Menu_Nav_Back")
Not_popup_grp:set_alpha(1)
store_crib_enable_mouse(true)
return
end
game_UI_audio_play("UI_Main_Menu_Select")
-- Did we select yes? This assumes yes is the first item
if Store_common_popup:get_selected_data() ~= 1 then
Not_popup_grp:set_alpha(1)
store_crib_enable_mouse(true)
return
end
Not_popup_grp:set_alpha(0)
-- exit the interface
pop_screen()
end
-- Populate the active megalist menu, and hide the previous menu
--
-- list_data: this table contains the data to populate the megalist
-- current_index: the current index in the menu that's selected
--
function store_crib_populate_list(list_data, current_index)
Active_list:draw_items(list_data, current_index, STORE_COMMON_LIST_SIZE, 10, SCALE_FONT_STORE_CRIB_LIST)
Active_list:set_visible(true)
if Game_platform == "PC" then
Mouse_input_tracker:remove_all()
Active_list:set_store("store_crib")
Active_list:add_mouse_inputs("store_common", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
-- Clears the price and respect values from the store header.
--
function store_crib_header_revert(menu_data)
Store_header:set_price(nil)
Store_header:set_respect(nil)
end
-- Handles navigation of any popups
function store_crib_popup_nav(event, value)
if event == "nav_up" then
Store_common_popup.list:move_cursor(-1)
elseif event == "nav_down" then
Store_common_popup.list:move_cursor(1)
elseif event == "mouse_move" then
-- value contains the target_handle in this case
local new_index = Store_common_popup.list:get_button_index(value)
if new_index ~= 0 then
Store_common_popup.list:set_selection(new_index)
Store_common_popup.list:move_cursor(0, true)
end
else
--do nothing
end
end
-- Pushes a new UI screen on the stack based on the "screen" parameter in menu_data.
--
function store_crib_open_screen(menu_data)
Previous_screen = menu_data.screen
Store_crib_current_menu_selection = menu_data.id
Store_crib_screen_to_push = menu_data.screen
--LOCK INPUT
store_lock_controls()
--local cell_mask = Vdo_base_object:new("cell_mask", 0, Store_common_doc_handle)
if menu_data.screen == "store_stronghold" then
bg_saints_set_type(BG_TYPE_STRONGHOLD,true)
store_crib_back_out_anim(true)
Hint_bar_mouse_input_tracker:subscribe(false)
Hint_bar_mouse_input_tracker:remove_all()
elseif menu_data.screen == "store_weapon" or menu_data.screen == "store_gang" or menu_data.screen == "store_clothing" then
store_crib_back_out_anim()
else
bg_saints_set_type(BG_TYPE_DEFAULT,true)
store_crib_back_out_anim()
end
end
function store_crib_open_cash(menu_data)
Previous_screen = menu_data.screen
Store_crib_current_menu_selection = menu_data.id
push_screen(menu_data.screen)
store_crib_enable_mouse(false)
end
function store_crib_open_garage(menu_data)
--LOCK INPUT
store_lock_controls()
Previous_screen = menu_data.screen
Store_crib_current_menu_selection = menu_data.id
Transition_to_garage_type = menu_data.garage_type
store_crib_back_out_anim(true)
store_crib_enable_mouse(false)
end
-- Base Menu Options always available
--[[
Store_crib_top_menu = {
[1] = { label = "COMPLETION_CASH", type = TYPE_BUTTON, on_select = store_crib_open_cash, screen = "store_crib_cash", id = 1 },
[2] = { label = "MENU_SWAP_WARDROBE", type = TYPE_BUTTON, on_select = store_crib_open_screen, screen = "store_clothing", id = 2},
[3] = { label = "GARAGE_CRIB_NAME", type = TYPE_BUTTON, on_select = store_crib_open_garage, screen = "store_vehicle", id = 3 },
[4] = { label = "WPNSTOR_TITLE_WEAPON_CACHE", type = TYPE_BUTTON, on_select = store_crib_open_screen, screen = "store_weapon", id = 4 },
}
--]]
-- =====================================
-- Mouse Specific Functions
-- =====================================
function store_crib_enable_mouse(enable)
if Game_platform == "PC" and enable ~= nil then
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:subscribe(enable)
end
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:subscribe(enable)
end
end
end
function store_crib_mouse_click(event, target_handle)
local hint_index = Store_common_hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
store_common_button_b()
end
end
function store_crib_mouse_move(event, target_handle)
-- Reset all highlights
Store_common_hint_bar:set_highlight(0)
-- Check if the mouse is over the hint bar buttons
local hint_index = Store_common_hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
Store_common_hint_bar:set_highlight(hint_index, Store_common_current_highlight_color)
return
end
-- Check if the mouse is over a button on the mega list
local old_index = Active_list:get_selection()
local new_index = Active_list:get_button_index(target_handle)
if new_index ~= 0 and new_index ~= old_index then
Active_list:set_selection(new_index)
Active_list:move_cursor(0, true)
return
end
end
function store_crib_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines)
end
function store_crib_mouse_drag(event, target_handle, mouse_x, mouse_y)
end
function store_crib_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
end