-- REMAINING PC ISSUES
-- Rim style grid only responds to first mouse move before stopping
-- Rim size toggle doesn't respond to mouse
-- Canceling COLOR GRID purchase also doubles the header text (not PC specific)
-- First tire tread disappears after mousing off first time
-- Wheel width and size don't slide quite correctly (approx. double the actual mouse movement)
-- Lots of stuff with Garage probably doesn't work
local Store_logo1
local Store_logo2
local Not_popup_grp
local Reward_image
local Triangle_select
local Vehicle_stats
local Empty_garage
local Vehicle_stats_data = {}
local SCALE_FONT_STORE_VEHICLE_LIST = 0.8
local MODE_VCUST = 0
local MODE_GARAGE = 1
local Color_grid_data = {}
local Old_vehicle_grid_index = -1 -- For navigating a grid with the mouse
local Old_vehicle_grid_category = -1 -- For navigating a grid with the mouse
local Store_vehicle_curr_cat_tbl
local Store_vehicle_curr_feat_tbl
local Store_vehicle_building_menu
local STORE_VEHICLE_POPULATE_AREAS = 0
local STORE_VEHICLE_POPULATE_CURRENT_MENU = 1
local STORE_VEHICLE_POPULATE_COMPONENT_MENU = 2
local STORE_VEHICLE_POPULATE_COLOR_REGION = 4
local Store_vehicle_show_slot = -1
local Store_vehicle_show_region = false
local Vehicle_just_upgrade = false
local Store_vehicle_component_selected
local Store_vehicle_chosen_axle = -1
local Store_vehicle_rebuild_wheel_menu = true
local Returning_to_crib = false
local Store_vehicle_wheel_price = {
rim = 0,
tire = 0,
size = 0,
}
local Store_vehicle_wheel_respect = {
rim = 0,
tire = 0,
size = 0,
}
local Store_vehicle_wheel_base_price = 100
local Store_vehicle_wheel_base_respect = 5
local Store_vehicle_color_slot = -1
local Store_vehicle_color_selection = 0
local Store_vehicle_color_price = 0
local Store_vehicle_color_respect = 0
local Store_vehicle_current_logo = -1
local Store_vehicle_select_palette_first = false
local Store_vehicle_purchase_item = nil
local Store_vehicle_current_rim_id = 0
local Store_vehicle_current_cat_id = 0
local Rim_jobs_grp = 0
local Store_vehicle_is_garage = false
local Garage_leave_with_car = false
local Garage_select_choices = {}
-- flag to indicate how many menus we need to back up later
local Store_vehicle_region_menu_bypassed = false
local Store_vehicle_multiple_palettes = false
Store_vehicle_doc_handle = -1
STORE_VEHICLE_TYPE_CATEGORY = 0
STORE_VEHICLE_TYPE_SLOT = 1
STORE_VEHICLE_TYPE_COMPONENT = 2
STORE_VEHICLE_TYPE_COLOR_REGION = 3
STORE_VEHICLE_TYPE_COLOR_PALETTE = 4
STORE_VEHICLE_TYPE_COLOR_GRID = 5
STORE_VEHICLE_TYPE_WHEEL = 6
STORE_VEHICLE_TYPE_PERFORMANCE = 7
STORE_VEHICLE_TYPE_PERFORMANCE_SLOT = 8
local STORE_VEHICLE_UNDERGLOW_COLOR = -2
VEHICLE_CUST_RIM_PEG = "ui_bms_veh_rims"
VEHICLE_CUST_TIRE_PEG = "ui_bms_veh_tires"
VEHICLE_CUST_SPINNER_PEG = "ui_bms_veh_s_0"
VEHICLE_CUST_GLASS_PEG = "ui_bms_veh_glass"
COLOR_STORE_VEHICLE_PRIMARY = {R=150/255, G=150/255, B=150/255}
local Store_vehicle_spinner_cat = {}
Store_vehicle_rim_sizes = {
median_rim_size = 3,
[1] = "VCUST_EXTRA_HIGH_PROFILE",
[2] = "VCUST_HIGH_PROFILE",
[3] = "VCUST_NORMAL_PROFILE",
[4] = "VCUST_LOW_PROFILE",
[5] = "VCUST_EXTRA_LOW_PROFILE",
}
local Store_vehicle_loaded_from_crib = false
local Store_vehicle_begin_from_garage = false
-- Mouse input-related variables
local Game_platform
local Hint_bar_mouse_input_tracker
-- Menu Tiers
local MENU_TIER = 1
local COLOR_TIER = 2
local PALETTE_TIER = 3
local TIRE_TIER = 4
local RIM_TIER = 5
local Current_tier = MENU_TIER
-- Defines for specially handled finish/palettes
--
STORE_VEHICLE_HERO_MATTE = 0
STORE_VEHICLE_HERO_GLOSS = 1
STORE_VEHICLE_IRIDESCENT = 2
STORE_VEHICLE_PEARLESCENT = 3
STORE_VEHICLE_CANDY = 4
local GARAGE_SELECT_REPAIR = 1
local GARAGE_SELECT_CUSTOMIZE = 2
local GARAGE_SELECT_RETRIEVE = 3
local GARAGE_SELECT_DELETE = 4
local GARAGE_SELECT_CRIB = 5
local GARAGE_SELECT_CANCEL = 6
local GVT_INVALID = -1
local GVT_CARS = 0
local GVT_HELICOPTERS = 1
local GVT_AIRPLANES = 2
local GVT_WATERCRAFT = 3
local Screen_cover_count = 0
----------------------
function store_vehicle_crib_exit()
store_vehicle_do_return_to_crib()
end
function store_vehicle_return_to_crib()
-- lock input during animation
store_lock_controls()
Store_common_spinner:set_visible(false)
local vehicle_logo_h = vint_object_find("vehicle_logo", 0, Store_vehicle_doc_handle)
vint_set_property(vehicle_logo_h, "visible", false)
-- make background so car is covered up
bg_saints_set_background(false)
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_vehicle_crib_exit")
back_out_anim:play(0)
Returning_to_crib = true;
end
function store_vehicle_clear_header()
Store_header:enable_price_respect(false)
store_vehicle_set_description(nil)
end
function store_vehicle_nav_slot(menu_data)
vcust_adjust_camera_angle( menu_data.id )
-- local hint_rotate_data = {
-- {CTRL_BUTTON_RS, "STORE_ZOOM"},
-- }
-- Store_common_rotate_hint:set_hints(hint_rotate_data)
Store_common_rotate_hint:set_visible(false)
end
function store_vehicle_nav_component(menu_data)
local item = Menu_data[Active_list:get_selection()]
vcust_preview_component(0, item.id)
-- Update the store header price and respect values
local price = item.price
local respect = item.style
if price ~= nil and price > 0 then
Store_header:set_price(price)
Store_header:set_respect(item.style)
Store_header:enable_price_respect(true)
else
-- Passing nil to hide price
--Store_header:set_price(nil)
store_vehicle_clear_header()
end
end
-- Remove any preview for items we didn't select
function store_vehicle_revert_component(menu_data)
vcust_preview_component(0, Menu_data[Menu_data.start_index].id)
store_vehicle_clear_header()
end
-- Garage select options
function store_vehicle_garage_vehicle_select()
-- disable popup until garage vehicle is loaded
if garage_vehicle_load_pending() then
return
end
Garage_select_choices = {}
-- can always retrieve
Garage_select_choices[#Garage_select_choices + 1] =
{
type = TYPE_BUTTON,
select_type = GARAGE_SELECT_RETRIEVE,
label = "GARAGE_RETRIEVE_VEHICLE",
id = #Garage_select_choices + 1
}
local repair_cost = garage_get_repair_cost()
if repair_cost > 0 then
local insert_values = { [0] = repair_cost }
local tag = vint_insert_values_in_string("GARAGE_REPAIR_VEHICLE", insert_values)
Garage_select_choices[#Garage_select_choices + 1] =
{
type = TYPE_BUTTON,
select_type = GARAGE_SELECT_REPAIR,
label = tag,
id = #Garage_select_choices + 1
}
end
local customize = garage_can_customize()
if customize then
Garage_select_choices[#Garage_select_choices + 1] =
{
type = TYPE_BUTTON,
select_type = GARAGE_SELECT_CUSTOMIZE,
label = "GARAGE_CUSTOMIZE_VEHICLE",
id = #Garage_select_choices + 1
}
end
local delete = garage_can_delete()
if delete then
Garage_select_choices[#Garage_select_choices + 1] =
{
type = TYPE_BUTTON,
select_type = GARAGE_SELECT_DELETE,
label = "GARAGE_REMOVE_VEHICLE",
id = #Garage_select_choices + 1
}
end
Garage_select_choices[#Garage_select_choices + 1] =
{
type = TYPE_BUTTON,
select_type = GARAGE_SELECT_CANCEL,
label = "CONTROL_CANCEL",
id = #Garage_select_choices + 1
}
local allow_crib = Store_vehicle_loaded_from_crib
--[[if allow_crib then
Garage_select_choices[#Garage_select_choices + 1] =
{
type = TYPE_BUTTON,
select_type = GARAGE_SELECT_CRIB,
label = "VCUST_RETURN_TO_CRIB",
id = #Garage_select_choices + 1
}
end--]]
Store_common_popup:populate_list(Garage_select_choices, 1, STORE_COMMON_LIST_SIZE, #Garage_select_choices)
Store_common_popup:set_title("GARAGE_VEHICLE_OPTION")
Store_common_popup:set_text("")
Store_common_popup:nav_enable(true, "store_garage_select", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
if store_vehicle_selection_should_lock_controls() then
store_lock_controls()
--store_vehicle_enable_controls(false)
end
-- Disable mouse input for active_list and hint_bar
store_vehicle_enable_mouse(false)
end
-- Possibly make a purchase
function store_vehicle_select_component(menu_data)
-- Confirm the purchase if we can afford it
if Store_common_player_cash >= menu_data.price and menu_data.price ~= 0 and menu_data.owned ~= true then
Store_vehicle_component_selected = menu_data
local insert = { [0] = menu_data.label, [1] = format_cash(menu_data.price) }
local body = vint_insert_values_in_string("VCUST_PURCHASE_PROMPT", insert)
local heading = "MENU_TITLE_CONFIRM"
Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title(heading)
Store_common_popup:set_text(body)
Store_common_popup:nav_enable(true, "store_vehicle_component_confirm", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
-- Disable mouse input for active_list and hint_bar
store_vehicle_enable_mouse(false)
elseif menu_data.price ~= 0 and menu_data.owned ~= true then
Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1)
Store_common_popup:set_title("MENU_TITLE_NOTICE")
Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")
Store_common_popup:nav_enable(true, "store_vehicle_fail_msg", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
-- Disable mouse input for active_list and hint_bar
store_vehicle_enable_mouse(false)
else
Store_vehicle_component_selected = menu_data
Vehicle_just_upgrade = true
-- just populate list because next function assumes we made a choice in the dialog box
--Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1)
--store_vehicle_component_confirm("accept")
store_vehicle_component_confirm_final()
end
end
function store_garage_repair_confirm(event)
-- only used in the case of insufficient funds
--"STORE_TITLE_INSUFFICIENT_FUNDS", "GARAGE_TEXT_INSUFFICIENT_FUNDS"
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
Active_list:set_visible(true)
-- 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")
return
end
game_UI_audio_play("UI_Main_Menu_Select")
end
function store_garage_customize_repair_confirm(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
Active_list:set_visible(true)
-- 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")
return
end
game_UI_audio_play("UI_Main_Menu_Select")
if Store_common_popup:get_selected_data() ~= 1 then
return
end
if Store_common_player_cash < garage_get_repair_cost() then
-- INSUFFICIENT FUNDS MESSAGE BOX
Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1)
Store_common_popup:set_title("MENU_TITLE_NOTICE")
Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")
Store_common_popup:nav_enable(true, "store_garage_repair_confirm", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
-- Disable mouse input for active_list and hint_bar
store_vehicle_enable_mouse(false)
return
end
garage_repair_vehicle()
store_vehicle_switch_mode()
end
function store_garage_destroy_confirm(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
Active_list:set_visible(true)
-- Re-enable mouse input?
-- 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")
store_unlock_controls()
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
-- determine start index of repopulated list
local cur_sel = Active_list:get_selection()
local size = #Menu_data
local next_sel = cur_sel
if cur_sel == size then
next_sel = 1
end
-- delete active garage vehicle
garage_remove_vehicle()
garage_build_areas()
store_vehicle_populate_list(Menu_data, next_sel)
garage_preview_vehicle(Menu_data[next_sel].id)
else
game_UI_audio_play("UI_Main_Menu_Nav_Back")
store_unlock_controls()
end
end
function store_garage_select(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
Active_list:set_visible(true)
-- 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")
Active_list:set_visible(true)
store_unlock_controls()
return
end
game_UI_audio_play("UI_Main_Menu_Select")
local choice_index = Store_common_popup:get_selected_data()
local select_type = Garage_select_choices[choice_index].select_type
if select_type == GARAGE_SELECT_CANCEL then
Active_list:set_visible(true)
store_unlock_controls()
return
elseif select_type == GARAGE_SELECT_REPAIR then
-- do repair
if Store_common_player_cash >= garage_get_repair_cost() then
garage_repair_vehicle()
else
-- INSUFFICIENT FUNDS MESSAGE BOX
Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1)
Store_common_popup:set_title("MENU_TITLE_NOTICE")
Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")
Store_common_popup:nav_enable(true, "store_garage_repair_confirm", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
-- Disable mouse input for active_list and hint_bar
store_vehicle_enable_mouse(false)
end
end
if select_type == GARAGE_SELECT_CUSTOMIZE then
local repair_cost = garage_get_repair_cost()
if repair_cost == 0 then
-- do customize
store_vehicle_switch_mode()
else
local insert_values = { [0] = repair_cost }
local tag = vint_insert_values_in_string("GARAGE_REPAIR_VEHICLE", insert_values)
local customize_choices = {
[1] = {
type = TYPE_BUTTON,
label = tag,
id = 1,
},
[2] = {
type = TYPE_BUTTON,
label = "CONTROL_CANCEL",
id = 2,
},
}
-- NEED FULL REPAIR MESSAGE BOX
Store_common_popup:populate_list(customize_choices, 1, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("MENU_TITLE_NOTICE")
Store_common_popup:set_text("GARAGE_REPAIR_BEFORE_CUSTOMIZATION")
Store_common_popup:nav_enable(true, "store_garage_customize_repair_confirm", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
-- Disable mouse input for active_list and hint_bar
store_vehicle_enable_mouse(false)
end
end
if select_type == GARAGE_SELECT_RETRIEVE then
-- do retrieve
-- lock controls, because a bug was found where user can push input during leaving and cause a crash
store_lock_controls()
store_vehicle_retrieve_car_and_exit()
end
if select_type == GARAGE_SELECT_DELETE then
-- DESTROY CONFIRMATION MESSAGE BOX
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("GARAGE_REMOVE_PROMPT")
Store_common_popup:nav_enable(true, "store_garage_destroy_confirm", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
-- Disable mouse input for active_list and hint_bar
store_vehicle_enable_mouse(false)
end
if select_type == GARAGE_SELECT_CRIB then
store_vehicle_return_to_crib()
end
end
-- Make the purchase for realz
function store_vehicle_component_confirm(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
Active_list:set_visible(true)
store_vehicle_enable_mouse(true)
-- 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")
return
end
-- Did we select yes? This assumes yes is the first item
if Store_common_popup:get_selected_data() ~= 1 then
return
end
if vcust_show_nos_hydraulic_warning() == true then
Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("MENU_TITLE_CONFIRM")
Store_common_popup:set_text("VCUST_PERFORMANCE_WARNING")
Store_common_popup:nav_enable(true, "store_vehicle_component_confirm2", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
-- Disable mouse input for active_list and hint_bar
store_vehicle_enable_mouse(false)
else
store_vehicle_component_confirm2("accept")
end
end
function store_vehicle_component_confirm2(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
Active_list:set_visible(true)
-- Re-enable the mouse for disabled elements
store_vehicle_enable_mouse(true)
-- 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")
return
end
-- Did we select yes? This assumes yes is the first item
if Store_common_popup:get_selected_data() ~= 1 then
return
end
if Store_vehicle_component_selected.price ~= 0 then
game_award_respect(Store_vehicle_component_selected.style)
ui_audio_post_event("vehicle_purchase")
if Vehicle_just_upgrade == true then
Vehicle_just_upgrade = false
end
end
Store_vehicle_component_selected.owned = true
store_vehicle_component_confirm_final()
end
function store_vehicle_component_confirm_final()
-- Stop previewing the component, keep it and deduct cash
vcust_purchase_component()
-- Clear out the on_back function, so we don't revert this choice when backing out of menu
Menu_data[Active_list:get_selection()].on_back = nil
-- make sure to clear header of old price data.
store_vehicle_clear_header()
-- back out of menu
store_common_button_b()
end
function store_vehicle_fail_msg(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
game_UI_audio_play("UI_Main_Menu_Select")
-- Re-enable the mouse for active_list and hint_bar
if Current_tier ~= PALETTE_TIER and Current_tier ~= COLOR_TIER then
store_vehicle_enable_mouse(true)
Active_list:set_visible(true)
else
Active_list:set_visible(false)
-- Re-enable the mouse
if Store_vehicle_select_palette_first then
Store_common_color_grid:nav_enable(true, "store_vehicle_trim_color_selected", "store_vehicle_trim_color_grid_nav")
else
if Store_vehicle_multiple_palettes == false then
store_vehicle_return_to_color_grid()
else
Store_common_color_grid:nav_enable(true, "store_vehicle_palette_selected", "store_vehicle_palette_grid_nav")
end
end
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:subscribe(true)
end
end
end
---[ Generic Menu ]---
function store_vehicle_build_menu(menu_data)
Store_vehicle_show_slot = Menu_data[Active_list:get_selection()].id
-- If we get back here, we need to rebuild the wheel menu next time we go in
Store_vehicle_rebuild_wheel_menu = true
Store_vehicle_building_menu = menu_data.sub_menu
Store_vehicle_building_menu.start_index = 1
-- Make the request to build the menu
if Store_vehicle_show_slot == -1 or Store_vehicle_show_region == true then
-- Build region menu
if Store_vehicle_show_region == true then
Store_vehicle_show_region = false
vint_dataresponder_request("vcust_populate_menu", "store_vehicle_populate_menu", 0, STORE_VEHICLE_POPULATE_COLOR_REGION)
-- If we only have 1 color region, just skip this menu and go on
if #Store_vehicle_building_menu == 1 then
local item = Store_vehicle_building_menu[1]
menu_data.sub_menu = {}
if Store_vehicle_select_palette_first then
store_vehicle_populate_trim_palette_menu(item)
else
store_vehicle_populate_color_grid(item)
end
end
-- flag to indicate how many menus we need to back up later
Store_vehicle_region_menu_bypassed = (#Store_vehicle_building_menu == 1)
else
vint_dataresponder_request("vcust_populate_menu", "store_vehicle_populate_menu", 0, STORE_VEHICLE_POPULATE_CURRENT_MENU)
end
else
vint_dataresponder_request("vcust_populate_menu", "store_vehicle_populate_items_menu", 0, STORE_VEHICLE_POPULATE_COMPONENT_MENU, Store_vehicle_show_slot)
local component = Store_vehicle_building_menu[Store_vehicle_building_menu.start_index]
vcust_preview_component(0, component.id)
end
Store_vehicle_show_slot = -1 -- Reset it so we don't get stuck in perma-slot menu
if #Store_vehicle_building_menu == 0 then
local item = { label = "STORE_NO_ITEMS_IN_CATEGORY", type = TYPE_BUTTON }
Store_vehicle_building_menu[1] = item
end
end
function store_vehicle_populate_items_menu(display_name, cat_type, id, price, current, level, desc, respect)
-- Add the item
local item = { label = display_name, type = TYPE_BUTTON, sub_menu = nil, id = id, price = price,
equipped = current, on_select = store_vehicle_select_component, on_nav = store_vehicle_nav_component,
on_back = store_vehicle_revert_component }
if price == 0 then
item.owned = true
item.style = 0
elseif price == nil then
-- Don't show checkbox for items that can't be purchased
item.owned = nil
item.style = 0
else
item.owned = false
item.style = respect
end
local menu_idx = #Store_vehicle_building_menu + 1
Store_vehicle_building_menu[menu_idx] = item
-- is this the currently owned item?
if current == true then
Store_vehicle_building_menu.start_index = menu_idx
end
end
-- Wheel menus
-----------------------------------
function store_vehicle_rim_peg_loaded()
-- input_data, current_option, max_width, max_height, button_w, button_h, hint_button_offset, current_category, outline_scale, background_enabled, show_current_button_bool, grid_spacing, set_size
Store_common_color_grid:draw_items(Color_grid_data, 1, 5, 4, 82, 80, 30, nil, 1.1, true, false, nil, nil)
-- Initialize grid navigation for mouse
Old_vehicle_grid_index = -1
Old_vehicle_grid_category = -1
Store_common_color_grid:nav_enable(true, "store_vehicle_rim_selected", "store_vehicle_rim_grid_nav")
-- update price and respect
local item = Store_common_color_grid:return_selected_data()
if item.price ~= nil and item.price > 0 then
Store_header:set_price(item.price)
Store_header:set_respect(item.style)
Store_header:enable_price_respect(true)
else
store_vehicle_clear_header()
end
Store_vehicle_wheel_price.rim = item.price
Store_vehicle_wheel_respect.rim = item.style
Store_common_color_grid:set_visible(true)
Active_list:set_visible(false)
-- set the titles on top
Store_header:push_title(nil, "VCUST_RIM_FAMILY_TITLE")
-- Disable the mouse for the active list when showing the color grid
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:subscribe(false)
end
Current_tier = RIM_TIER
end
function store_vehicle_build_rim_menu(menu_data)
-- New menu, clear out all items
table_clear(Color_grid_data, true)
vint_force_lua_gc()
-- We need special tables for all the spinners, which will be the last category
Store_vehicle_spinner_cat = { category_name = "VCUST_SPINNERS_TITLE" }
-- Fill all the categories
vint_dataresponder_request("vcust_populate_wheel_menu", "store_vehicle_populate_rim_category", 0, 8) -- 8 = VCUST_INTF_POPULATE_RIM_FAMILY_MENU
-- place the spinner categories as the last two in the grid, as long as they contain entries
if #Store_vehicle_spinner_cat > 0 then
Color_grid_data[#Color_grid_data + 1] = Store_vehicle_spinner_cat
end
-- Load peg and wait for callback
game_peg_load_with_cb("store_vehicle_rim_peg_loaded", 1, VEHICLE_CUST_RIM_PEG)
end
function store_vehicle_populate_rim_category(display_name, current, id)
local category = { category_name = display_name }
local cat_index = #Color_grid_data + 1
Store_vehicle_current_rim_id = 0
Color_grid_data[cat_index] = category
-- Used to store the rim category for spinners, since they are put in a different category in the UI then the code needs
Store_vehicle_current_cat_id = id
Store_vehicle_building_menu = Color_grid_data[cat_index]
-- Make the request to fill the category
vint_dataresponder_request("vcust_populate_wheel_grid_menu", "store_vehicle_populate_rim_grid", 0, 9, id) -- 9 = VCUST_INTF_POPULATE_RIM_MENU
-- Make the request to find spinners in this category
local prev_spinner_count = #Store_vehicle_spinner_cat
Store_vehicle_building_menu = Store_vehicle_spinner_cat
Store_vehicle_current_rim_id = 0
vint_dataresponder_request("vcust_populate_wheel_grid_menu", "store_vehicle_populate_rim_grid", 0, 12, id) -- 12 = VCUST_INTF_POPULATE_SPINNERS_MENU
end
function store_vehicle_populate_rim_grid(display_name, image_crc, price, current, respect)
local item_index = #Store_vehicle_building_menu + 1
if display_name == nil then
local insert_values = { [0] = item_index, }
display_name = vint_insert_values_in_string("VCUST_RIM_NUMBER", insert_values)
end
local item = { label = display_name, type = TYPE_BUTTON, icon_crc = image_crc, price = price, category_id = Store_vehicle_current_cat_id,
id = item_index - 1, color = {red = 1, green = 1, blue = 1}, }
Store_vehicle_current_rim_id = Store_vehicle_current_rim_id + 1
if price == 0 then
item.owned = true
else
item.owned = false
item.style = respect
end
Store_vehicle_building_menu[item_index] = item
end
function store_vehicle_rim_selected(event)
-- remove title
Store_header:pop_title()
-- Did the player make a selection?
if event == "select" or event == "mouse_click" then
local idx = Store_common_color_grid:return_selected_index()
if idx <= #Color_grid_data then
end
game_UI_audio_play("UI_Main_Menu_Select")
else
game_UI_audio_play("UI_Main_Menu_Nav_Back")
end
game_peg_unload(VEHICLE_CUST_RIM_PEG)
store_vehicle_update_total_price()
Store_common_color_grid:nav_enable(false, nil, nil)
Store_common_color_grid:set_visible(false)
Active_list:set_visible(true)
Current_tier = MENU_TIER
store_vehicle_enable_mouse(true)
end
function store_vehicle_build_tire_menu(menu_data)
-- make sure to load our pegs, starting in 1st category
game_peg_load_with_cb("store_vehicle_tire_peg_loaded", 1, VEHICLE_CUST_TIRE_PEG)
end
function store_vehicle_tire_peg_loaded()
-- New menu, clear out all items
table_clear(Color_grid_data, true)
vint_dataresponder_request("vcust_populate_wheel_grid_menu", "store_vehicle_populate_tire_menu", 0, 10) -- 10 = VCUST_INTF_POPULATE_TIRE_MENU
local grid_rows = ceil(#Color_grid_data / 4)
--Vdo_grid_list:draw_items(input_data, current_option, max_width, max_height, button_w, button_h, hint_button_offset, current_category, outline_scale, background_enabled, show_current_button_bool, grid_spacing, set_size)
Store_common_color_grid:draw_items(Color_grid_data, 1, 4, grid_rows, 105, 80, 35, nil, 1.1, true, false)
-- Initialize grid navigation for mouse
Old_vehicle_grid_index = -1
Store_common_color_grid:nav_enable(true, "store_vehicle_tire_selected", "store_vehicle_tire_grid_nav")
-- update price and respect
local item = Store_common_color_grid:return_selected_data()
if item.price ~= nil and item.price > 0 then
Store_header:set_price(item.price)
Store_header:set_respect(item.style)
Store_header:enable_price_respect(true)
else
store_vehicle_clear_header()
end
Store_vehicle_wheel_price.tire = item.price
Store_vehicle_wheel_respect.tire = item.style
Store_common_color_grid:set_visible(true)
Active_list:set_visible(false)
-- set the titles on top
Store_header:push_title(nil, "VCUST_TIRE_TREAD_OPTION")
-- Disable the mouse for the active list when showing the color grid
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:subscribe(false)
end
Current_tier = TIRE_TIER
end
function store_vehicle_populate_tire_menu(display_name, image_crc, price, current, respect)
local item_index = #Color_grid_data + 1
local insert_values = { [0] = item_index, }
local rim_name = vint_insert_values_in_string("VCUST_TIRE_TREAD_NUMBER", insert_values)
local item = { label = rim_name, type = TYPE_BUTTON, icon_crc = image_crc, price = price,
id = item_index - 1, color = {red = 1, green = 1, blue = 1}, }
if price == 0 then
item.owned = true
else
item.owned = false
item.style = respect
end
Color_grid_data[item_index] = item
end
function store_vehicle_tire_grid_nav(event, value)
store_vehicle_grid_nav(event, false, value)
Store_header:enable_price_respect(true)
-- update price and respect
local item = Store_common_color_grid:return_selected_data()
if item.price ~= nil and item.price > 0 then
Store_header:set_price(item.price)
Store_header:set_respect(item.style)
Store_header:enable_price_respect(true)
else
store_vehicle_clear_header()
end
Store_vehicle_wheel_price.tire = item.price
Store_vehicle_wheel_respect.tire = item.style
-- preview the tire
local idx = Store_common_color_grid:return_selected_index()
vcust_preview_component(2, 1, idx - 1)
end
function store_vehicle_tire_selected(event)
-- remove title
Store_header:pop_title()
-- Did the player make a selection?
if event == "select" or event == "mouse_click" then
local idx = Store_common_color_grid:return_selected_index()
if idx <= #Color_grid_data then
end
game_UI_audio_play("UI_Main_Menu_Select")
else
game_UI_audio_play("UI_Main_Menu_Nav_Back")
end
game_peg_unload(VEHICLE_CUST_TIRE_PEG)
store_vehicle_update_total_price()
Store_common_color_grid:nav_enable(false, nil, nil)
Store_common_color_grid:set_visible(false)
Active_list:set_visible(true)
-- Re-enable the mouse
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:subscribe(true)
end
Current_tier = MENU_TIER
end
function store_vehicle_update_total_price()
local price = Store_vehicle_wheel_price.rim + Store_vehicle_wheel_price.tire + Store_vehicle_wheel_price.size
if Store_vehicle_wheel_respect.rim == nil then
Store_vehicle_wheel_respect.rim = 0
end
if Store_vehicle_wheel_respect.tire == nil then
Store_vehicle_wheel_respect.tire = 0
end
if Store_vehicle_wheel_respect.size == nil then
Store_vehicle_wheel_respect.size = 0
end
local respect = Store_vehicle_wheel_respect.rim + Store_vehicle_wheel_respect.tire + Store_vehicle_wheel_respect.size
if price ~= nil and price > 0 then
Store_header:set_price(price)
Store_header:set_respect(respect)
Store_header:enable_price_respect(true)
else
store_vehicle_clear_header()
end
return price, respect
end
function store_vehicle_purchase_wheels(menu_data)
local price, respect = store_vehicle_update_total_price()
-- Is it free?
if price == 0 then
vcust_purchase_wheels(price)
store_common_button_b()
-- do this so holding down the button doesn't cause repeated actions
store_lock_controls()
store_unlock_controls()
return
else
-- Are we short on cash?
if price > Store_common_player_cash then
Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1)
Store_common_popup:set_title("MENU_TITLE_NOTICE")
Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")
Store_common_popup:nav_enable(true, "store_vehicle_fail_msg", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
-- Disable mouse input for active_list and hint_bar
store_vehicle_enable_mouse(false)
return
end
-- Make sure they want to buy this
Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("STORE_TITLE_PURCHASING")
local insert = { [0] = format_cash(price) }
local body = vint_insert_values_in_string("VCUST_PURCHASE_WHEELS_PROMPT", insert)
Store_common_popup:set_text(body)
Store_common_popup:nav_enable(true, "store_vehicle_purchase_wheels_final", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
-- Disable the mouse for active_list and hint_bar
store_vehicle_enable_mouse(false)
end
end
-- Make the purchase for realz
function store_vehicle_purchase_wheels_final(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
Active_list:set_visible(true)
-- Re-enable the mouse
store_vehicle_enable_mouse(true)
-- The user hit the B button and are cancelling the purchase
-- This is redundant to selecting "No" in the list
if event == "back" then
game_UI_audio_play("UI_Main_Menu_Nav_Back")
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
return
end
-- award respect and actually purchase the item
local price, respect = store_vehicle_update_total_price()
game_award_respect(respect)
vcust_purchase_wheels(price)
ui_audio_post_event("vehicle_purchase")
-- back up a menu
store_common_button_b()
-- do this so holding down the button doesn't cause repeated actions
store_lock_controls()
store_unlock_controls()
--Input_tracker:subscribe(false)
--Input_tracker:subscribe(true)
end
function store_vehicle_select_axle(menu_data)
-- subtract 2 now, since indexing starts at 1
Store_vehicle_chosen_axle = Active_list:get_selection() - 2 -- -1 = both, 0 = front, 1 = rear
end
function store_vehicle_fill_wheel_menu(menu_data)
Store_vehicle_building_menu = menu_data.sub_menu
vint_dataresponder_request("vcust_populate_wheel_menu", "store_vehicle_populate_wheel_menu", 0, 7, true, Store_vehicle_chosen_axle) -- 7 = VCUST_INTF_POPULATE_WHEEL_MENU
Store_vehicle_rebuild_wheel_menu = false
end
function store_vehicle_rim_size_update(menu_data)
Store_vehicle_wheel_price.size = Store_vehicle_wheel_base_price
Store_vehicle_wheel_respect.size = Store_vehicle_wheel_base_respect
store_vehicle_update_total_price()
vcust_preview_rim_sizing(menu_data.current_value - 1)
end
function store_vehicle_wheel_size_update(menu_data)
Store_vehicle_wheel_price.size = Store_vehicle_wheel_base_price
Store_vehicle_wheel_respect.size = Store_vehicle_wheel_base_respect
store_vehicle_update_total_price()
vcust_preview_wheel_sizing(menu_data.current_value, -1)
end
function store_vehicle_wheel_width_update(menu_data)
Store_vehicle_wheel_price.size = Store_vehicle_wheel_base_price
Store_vehicle_wheel_respect.size = Store_vehicle_wheel_base_respect
store_vehicle_update_total_price()
vcust_preview_wheel_sizing(-1, menu_data.current_value)
end
-- Data responder callback. This populates our wheel menu with the data specific to this vehicle.
-- Called by the sub_menu_fill callback to populate our megalist submenu data.
--
function store_vehicle_populate_wheel_menu(rim_display_name, tire_index, spinner_index, current_rim_family, rim_size,
wheel_size_min, wheel_size_max, wheel_size,
wheel_width_min, wheel_width_max, wheel_width, price, respect)
local index = 1
Store_vehicle_building_menu[index] = { label = "VCUST_RIM_STYLE_OPTION", type = TYPE_BUTTON, on_select = store_vehicle_build_rim_menu, on_cancel = vcust_revert_wheels}
index = index + 1
Store_vehicle_building_menu[index] = { label = "VCUST_TIRE_TREAD_OPTION", type = TYPE_BUTTON, on_select = store_vehicle_build_tire_menu, on_cancel = vcust_revert_wheels }
index = index + 1
Store_vehicle_building_menu[index] = { label = "VCUST_RIM_SIZE_OPTION", type = TYPE_TOGGLE, on_value_update = store_vehicle_rim_size_update,
options = Store_vehicle_rim_sizes, on_cancel = vcust_revert_wheels }
local rim_size_index = rim_size + 1
if rim_size_index < 1 or rim_size_index > #Store_vehicle_rim_sizes then
rim_size_index = Store_vehicle_rim_sizes.median_rim_size
end
Store_vehicle_building_menu[index].current_value = rim_size_index
index = index + 1
local wheel_size_mapping = { [0] = 7, 9, 12, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 41, 45, 52 }
if wheel_size_min ~= wheel_size_max then
Store_vehicle_building_menu[index] = { label = "VCUST_WHEEL_SIZE_OPTION", type = TYPE_SLIDER,
min = wheel_size_min, max = wheel_size_max, step = 1, current_value = wheel_size,
on_value_update = store_vehicle_wheel_size_update, on_cancel = vcust_revert_wheels,
mapping = wheel_size_mapping }
index = index + 1
end
if wheel_width_min ~= wheel_width_max then
Store_vehicle_building_menu[index] = { label = "VCUST_WHEEL_WIDTH_OPTION", type = TYPE_SLIDER,
min = wheel_width_min, max = wheel_width_max, step = 1, current_value = wheel_width,
on_value_update = store_vehicle_wheel_width_update, disabled = false, on_cancel = vcust_revert_wheels}
index = index + 1
end
Store_vehicle_building_menu[index] = { label = "VCUST_PURCHASE_OPTION", type = TYPE_BUTTON, on_select = store_vehicle_purchase_wheels, on_cancel = vcust_revert_wheels }
index = index + 1
Store_vehicle_wheel_price.rim = 0
Store_vehicle_wheel_price.tire = 0
Store_vehicle_wheel_price.size = 0
Store_vehicle_wheel_respect.rim = 0
Store_vehicle_wheel_respect.tire = 0
Store_vehicle_wheel_respect.size = 0
Store_vehicle_wheel_base_price = price
Store_vehicle_wheel_base_respect = respect
end
function store_vehicle_clear_rim_selections()
store_vehicle_clear_header()
Store_vehicle_wheel_price.rim = 0
Store_vehicle_wheel_price.tire = 0
Store_vehicle_wheel_price.size = 0
end
Store_vehicle_axle_menu = {
on_enter = store_vehicle_clear_rim_selections,
[1] = { label = "VCUST_BOTH_AXLES_OPTION", type = TYPE_BUTTON, on_sub_menu_fill = store_vehicle_fill_wheel_menu, on_select = store_vehicle_select_axle, vcamera = "Both_axle" },
[2] = { label = "VCUST_FRONT_AXLE_OPTION", type = TYPE_BUTTON, on_sub_menu_fill = store_vehicle_fill_wheel_menu, on_select = store_vehicle_select_axle, vcamera = "Front_axle" },
[3] = { label = "VCUST_REAR_AXLE_OPTION" , type = TYPE_BUTTON, on_sub_menu_fill = store_vehicle_fill_wheel_menu, on_select = store_vehicle_select_axle, vcamera = "Rear_axle" },
}
-- Color menus
-------------------------------------
function store_vehicle_select_region(menu_data)
Store_vehicle_color_slot = menu_data.id
vcust_select_paint_slot(Store_vehicle_color_slot) -- Build the paint slots
Store_vehicle_show_region = true
store_vehicle_build_menu(menu_data)
end
function store_vehicle_palette_selected(event)
-- Did the player make a selection?
if event == "select" or event == "mouse_click" then
local idx = Store_common_color_grid:return_selected_index()
if idx <= #Color_grid_data then
end
Store_common_color_grid:nav_enable(false, nil, nil) -- disable input going to grid control
store_vehicle_enable_mouse(false)
-- Now we need to check for purchasing
-- Are we short on cash?
if Store_vehicle_color_price > Store_common_player_cash then
Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1)
Store_common_popup:set_title("MENU_TITLE_NOTICE")
Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")
Store_common_popup:nav_enable(true, "store_vehicle_fail_msg", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
return
end
-- Make sure they want to buy this
Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("STORE_TITLE_PURCHASING")
local insert = { [0] = Color_grid_data[idx].label, [1] = format_cash(Store_vehicle_color_price) }
local body = vint_insert_values_in_string("VCUST_PURCHASE_PROMPT", insert)
Store_common_popup:set_text(body)
Store_common_popup:nav_enable(true, "store_vehicle_purchase_color_final", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
return
end
Current_tier = MENU_TIER
game_UI_audio_play("UI_Main_Menu_Nav_Back")
-- revert color choice
vcust_revert_color()
-- remove titles
Store_header:pop_title()
Store_header:pop_title()
game_peg_unload(VEHICLE_CUST_GLASS_PEG)
Store_common_color_grid:set_visible(false)
-- disable input going to grid control
Store_common_color_grid:nav_enable(false, nil, nil) -- disable input going to grid control
-- disable input going to grid control
Store_common_color_grid:nav_enable(false, nil, nil)
store_vehicle_enable_mouse(false)
-- back up to color grid
local temp_item = { id = Store_vehicle_color_slot }
store_vehicle_populate_color_grid(temp_item, false, false, true)
end
function store_vehicle_purchase_color_final(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
-- The user hit the B button and are cancelling the purchase
-- This is redundant to selecting "No" in the list
if event == "back" then
game_UI_audio_play("UI_Main_Menu_Nav_Back")
-- Re-enable the mouse
if Store_vehicle_select_palette_first then
Store_common_color_grid:nav_enable(true, "store_vehicle_trim_color_selected", "store_vehicle_trim_color_grid_nav")
else
Store_common_color_grid:nav_enable(true, "store_vehicle_palette_selected", "store_vehicle_palette_grid_nav")
end
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:subscribe(true)
end
-- was palette grid bypassed?
if #Color_grid_data == 1 then
store_vehicle_return_to_color_grid()
-- work around for too many title headers showing up because of redrawing the grid
Store_header:pop_title()
end
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
-- Re-enable the mouse
if Store_vehicle_select_palette_first then
Store_common_color_grid:nav_enable(true, "store_vehicle_trim_color_selected", "store_vehicle_trim_color_grid_nav")
else
Store_common_color_grid:nav_enable(true, "store_vehicle_palette_selected", "store_vehicle_palette_grid_nav")
end
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:subscribe(true)
end
-- was palette grid bypassed?
if #Color_grid_data == 1 then
store_vehicle_return_to_color_grid()
-- work around for too many title headers showing up because of redrawing the grid
Store_header:pop_title()
end
return
end
Current_tier = MENU_TIER
-- Re-enable the mouse
store_vehicle_enable_mouse(true)
-- award respect and actually purchase the item
game_award_respect(Store_vehicle_color_respect)
vcust_purchase_paint(Store_vehicle_color_price)
ui_audio_post_event("vehicle_purchase")
game_peg_unload(VEHICLE_CUST_GLASS_PEG)
Store_common_color_grid:nav_enable(false, nil, nil)
Store_common_color_grid:set_visible(false)
store_vehicle_clear_header()
Active_list:set_visible(true)
local bypass_animate_next_time = false --can't do 2 button bs in a row because of the animate
-- back out of region menu
if Store_vehicle_region_menu_bypassed ~= true then
store_common_button_b()
bypass_animate_next_time = true
end
-- back up another menu if we showed the palette as a menu instead of a grid
if Store_vehicle_select_palette_first == true then
if bypass_animate_next_time then
Store_common_bypass_animate = true --can't do 2 button bs in a row because of the animate
end
store_common_button_b()
end
-- reset titles
while #Store_header.title_stack > 1 do
Store_header:pop_title()
end
-- do this so holding down the button doesn't cause repeated actions
store_lock_controls()
store_unlock_controls()
--Input_tracker:subscribe(false)
--Input_tracker:subscribe(true)
end
function store_vehicle_return_to_color_grid()
game_peg_unload(VEHICLE_CUST_GLASS_PEG)
Store_common_color_grid:set_visible(false)
-- disable input going to grid control
Store_common_color_grid:nav_enable(false, nil, nil)
store_vehicle_enable_mouse(false)
-- back up to color grid
local temp_item = { id = Store_vehicle_color_slot }
store_vehicle_populate_color_grid(temp_item, false, false, true)
end
function store_vehicle_populate_palette_grid(menu_data)
-- New menu, clear out all items
table_clear(Color_grid_data, true)
vint_force_lua_gc()
-- Populate all our possible finishes
vint_dataresponder_request("vcust_populate_palette_menu", "store_vehicle_add_palette", 0, Store_vehicle_color_slot, false)
-- if we only have 1 palette choice, then bypass the grid
if Store_vehicle_multiple_palettes == false then
--Store_common_color_grid:nav_enable(false, nil, nil) -- disable input going to grid control
store_vehicle_enable_mouse(false)
-- Now we need to check for purchasing
-- Are we short on cash?
if Store_vehicle_color_price > Store_common_player_cash then
Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1)
Store_common_popup:set_title("MENU_TITLE_NOTICE")
Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")
Store_common_popup:nav_enable(true, "store_vehicle_fail_msg", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
-- Re-enable the grid inside store_vehicle_fail_msg, not here (screws up mouse inputs if it's done here)
return
end
-- Make sure they want to buy this
Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("STORE_TITLE_PURCHASING")
local insert = { [0] = Color_grid_data[1].label, [1] = format_cash(Store_vehicle_color_price) }
local body = vint_insert_values_in_string("VCUST_PURCHASE_PROMPT", insert)
Store_common_popup:set_text(body)
Store_common_popup:nav_enable(true, "store_vehicle_purchase_color_final", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
return
else
Store_common_color_grid:draw_items(Color_grid_data, 1, 9, 1, 53.5, 53.5, 15, nil, 1.1, true, true, -7, true)
-- set the titles on top
Store_header:push_title(nil, "VCUST_COLOR_PALETTE_TITLE")
store_vehicle_palette_grid_nav()
-- Initialize grid navigation for mouse
Old_vehicle_grid_index = -1
Store_common_color_grid:nav_enable(true, "store_vehicle_palette_selected", "store_vehicle_palette_grid_nav")
Current_tier = PALETTE_TIER
end
end
function store_vehicle_add_palette(display_name, current, base_r, base_g, base_b, spec_col_r, spec_col_g, spec_col_b, spec_alpha, fres_col_r, fres_col_g, fres_col_b, fres_con, refl, is_glass, palette_type, palette_id)
local index = #Color_grid_data + 1
local item = {
label = display_name,
icon = "ui_menu_veh_pnt_base",
color = { red = base_r, green = base_g, blue = base_b },
base_r = base_r, base_g = base_g, base_b = base_b, -- Base paint color, used on base
spec_col_r = spec_col_r, spec_col_g = spec_col_g, spec_col_b = spec_col_b, -- Specular color, used on spec and irr
spec_alpha = spec_alpha, -- Specular alpha, used on spec
fres_col_r = fres_col_r, fres_col_g = fres_col_g, fres_col_b = fres_col_b, -- Fresnel color, used on fres, refl, sky
fres_con = fres_con, -- Fresnel 'alpha' (contrast), used on fres
refl = refl, -- Reflection color
is_glass = is_glass,
is_layered = true, -- Do we use the layered button for paint finishes?
palette_type = palette_type,
id = palette_id,
type = TYPE_BUTTON, -- this function is only used for palettes that are rendered in a menu instead of a grid (rim, trim)
on_nav = store_vehicle_trim_palette_menu_nav, -- this function is only used for palettes that are rendered in a menu instead of a grid (rim, trim)
on_select = store_vehicle_trim_palette_selected, -- this function is only used for palettes that are rendered in a menu instead of a grid (rim, trim)
on_cancel = store_vehicle_trim_palette_reverted, -- this function is only used for palettes that are rendered in a menu instead of a grid (rim, trim)
}
Color_grid_data[index] = item
end
function store_vehicle_color_selected(event)
Store_common_color_grid:nav_enable(false, nil, nil)
-- Did the player make a selection?
if event == "select" or event == "mouse_click" then
game_UI_audio_play("UI_Main_Menu_Select")
local idx = Store_common_color_grid:return_selected_index()
if idx <= #Color_grid_data then
Store_vehicle_color_selection = idx
store_vehicle_populate_palette_grid()
return
end
end
game_UI_audio_play("UI_Main_Menu_Nav_Back")
-- restore original color
vcust_revert_color()
-- remove title
Store_header:pop_title()
game_peg_unload(VEHICLE_CUST_GLASS_PEG)
Store_common_color_grid:set_visible(false)
store_vehicle_clear_header()
Active_list:set_visible(true)
-- Enable the mouse for active_list and hint_bar
store_vehicle_enable_mouse(true)
Current_tier = MENU_TIER
end
-- This is the draw items call for the body paint
function store_vehicle_color_grid_draw()
local grid_rows = ceil(#Color_grid_data / 9)
if( grid_rows > 5 )then
grid_rows = 5
end
Store_common_color_grid:draw_items(Color_grid_data, Color_grid_data.current, 9, grid_rows, 53.5, 53.5, 15, nil, 1.1, true, true, -7, true)
Store_header:enable_price_respect(not Store_vehicle_multiple_palettes)
local index = Store_common_color_grid:return_selected_index()
Store_vehicle_color_price = Color_grid_data[index].price
Store_vehicle_color_respect = Color_grid_data[index].style
Store_header:set_price(Store_vehicle_color_price)
Store_header:set_respect(Store_vehicle_color_respect)
-- Initialize grid navigation for mouse
Old_vehicle_grid_index = -1
Store_common_color_grid:nav_enable(true, "store_vehicle_color_selected", "store_vehicle_color_grid_nav")
-- do an initial nav to initialize header, etc. (pass in dummy movement value for navigation)
store_vehicle_color_grid_nav("do_not_move")
Store_common_color_grid:set_visible(true)
Active_list:set_visible(false)
-- set the titles on top
Store_header:push_title(nil, "VCUST_COLOR_GRID_TITLE")
-- Disable the mouse for the active list
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:subscribe(false)
end
Current_tier = COLOR_TIER
end
-- This function puts in a dataresponder request to get 1 palette of colors, which in turn will call a callback that requests all
-- the colors in that palette. We then use this list of colors to populate our grid. The grid is initialized empty in this function.
-- This function also triggers loading of the glass swatch peg.
--
-- menu_data: standard table for the menu selection passed to all menu callbacks.
-- save_original: optional boolean which is false if we are repopulating the color grid, but we do not want the C code to save
-- our original color slot color as the "original" used for restoring if purchasing is cancelled.
--
function store_vehicle_populate_color_grid(menu_data, save_original, show_layered, restore_current)
Store_vehicle_color_slot = menu_data.id
-- New menu, clear out all items
table_clear(Color_grid_data, true)
Color_grid_data.show_layered = show_layered or false
Store_vehicle_multiple_palettes = false
if save_original == nil then
save_original = true
end
vint_dataresponder_request("vcust_populate_palette_menu", "store_vehicle_get_palette_colors", 0, Store_vehicle_color_slot, save_original)
if restore_current == true then
Color_grid_data.current = Store_vehicle_color_selection
end
game_peg_load_with_cb("store_vehicle_color_grid_draw", 1, VEHICLE_CUST_GLASS_PEG)
if Hint_bar_mouse_input_tracker ~= nil and Hint_bar_mouse_input_tracker ~= 0 then
Hint_bar_mouse_input_tracker:subscribe(true)
end
end
function store_vehicle_get_palette_colors(display_name, current, base_r, base_g, base_b, spec_col_r, spec_col_g, spec_col_b, spec_alpha, fres_col_r, fres_col_g, fres_col_b, fres_con, refl, is_glass)
-- We're just collecting colors right now. We only add colors for the first palette, but we still want to know if there's more than one palette, because if there's only one we skip the palette grid.
if #Color_grid_data == 0 then
vint_dataresponder_request("vcust_populate_color_grid", "store_vehicle_add_color", 0, Store_vehicle_color_slot)
else
Store_vehicle_multiple_palettes = true
end
end
function store_vehicle_add_color(display_name, current, base_r, base_g, base_b, spec_col_r, spec_col_g, spec_col_b, spec_alpha, fres_col_r, fres_col_g, fres_col_b, fres_con, refl, price, is_glass, respect, ui_col_r, ui_col_g, ui_col_b, refl_alpha)
local index = #Color_grid_data + 1
local item = {
label = display_name,
icon = "ui_menu_veh_pnt_base",
color = { red = base_r, green = base_g, blue = base_b },
base_r = base_r, base_g = base_g, base_b = base_b, -- Base paint color, used on base
spec_col_r = spec_col_r, spec_col_g = spec_col_g, spec_col_b = spec_col_b, -- Specular color, used on spec and irr
spec_alpha = spec_alpha, -- Specular alpha, used on spec
fres_col_r = fres_col_r, fres_col_g = fres_col_g, fres_col_b = fres_col_b, -- Fresnel color, used on fres, refl, sky
fres_con = fres_con, -- Fresnel 'alpha' (contrast), used on fres
refl = refl, -- Reflection color
price = price,
owned = current,
is_glass = is_glass, -- Glass or Interior or normal
is_layered = false,
style = respect,
refl_alpha = refl_alpha,
}
if is_glass == true then
--item.icon = "ui_menu_veh_glass"
if ui_col_r ~= nil then
item.color = { red = ui_col_r, green = ui_col_g, blue = ui_col_b }
end
end
if current == true then
Color_grid_data.current = index
end
Color_grid_data[index] = item
end
function store_vehicle_populate_trim_palette_menu(menu_data)
Store_vehicle_color_slot = menu_data.id
-- New menu, clear out all items
table_clear(Color_grid_data, true)
vint_force_lua_gc()
-- Populate all our possible finishes
vint_dataresponder_request("vcust_populate_palette_menu", "store_vehicle_add_palette", 0, Store_vehicle_color_slot, true)
store_common_push_menu(Color_grid_data)
-- Store_common_color_grid:draw_items(Color_grid_data, Color_grid_data.current, 9, 1, 53.5, 53.5, 15, nil, 1.1, true, true, -7, true)
-- Store_common_color_grid:nav_enable(true, "store_vehicle_trim_palette_selected", "store_vehicle_trim_palette_menu_nav")
-- -- do an initial nav to initialize header, etc. (pass in dummy movement value for navigation)
-- --store_vehicle_color_grid_nav("do_not_move")
-- Store_common_color_grid:set_visible(true)
-- Active_list:set_visible(false)
-- set the titles on top
--Store_header:push_title(nil, "VCUST_COLOR_PALETTE_TITLE")
-- -- Disable the mouse for the active list
-- if Mouse_input_tracker ~= 0 then
-- Mouse_input_tracker:subscribe(false)
-- end
-- Current_tier = PALETTE_TIER
end
function store_vehicle_trim_palette_menu_nav(menu_data)
vcust_preview_palette(0, menu_data.id, 0)
end
-- function store_vehicle_trim_palette_menu_nav(event, value)
-- store_vehicle_grid_nav(event, false, value)
-- -- slot is hardcoded to 0
-- -- color is hardcoded to 0
-- local item = Store_common_color_grid:return_selected_data()
-- vcust_preview_palette(0, item.id, 0)
-- end
function store_vehicle_trim_palette_reverted(menu_data)
-- revert color choice
vcust_revert_color()
end
function store_vehicle_trim_palette_selected(menu_data)
Store_common_color_grid:set_visible(true)
Active_list:set_visible(false)
-- Disable the mouse for the active list
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:subscribe(false)
end
Store_vehicle_color_selection = Active_list:get_selection() - 1
store_vehicle_populate_trim_color_grid()
end
-- function store_vehicle_trim_palette_selected(event)
-- Store_common_color_grid:nav_enable(false, nil, nil)
-- -- Did the player make a selection?
-- if event == "select" or event == "mouse_click" then
-- local idx = Store_common_color_grid:return_selected_index()
-- if idx <= #Color_grid_data then
-- Store_vehicle_color_selection = idx - 1
-- store_vehicle_populate_trim_color_grid()
-- return
-- end
-- end
-- -- restore original color
-- vcust_revert_color()
-- -- remove title
-- Store_header:pop_title()
-- Store_common_color_grid:set_visible(false)
-- store_vehicle_clear_header()
-- Active_list:set_visible(true)
-- -- Enable the mouse for active_list and hint_bar
-- store_vehicle_enable_mouse(true)
-- Current_tier = MENU_TIER
-- end
function store_vehicle_populate_trim_color_grid()
-- New menu, clear out all items
Color_grid_data = {}
-- Populate all our possible colors
vint_dataresponder_request("vcust_populate_color_grid", "store_vehicle_add_color", 0, Store_vehicle_color_slot, Store_vehicle_color_selection)
local grid_rows = ceil(#Color_grid_data / 9)
if( grid_rows > 5 )then
grid_rows = 5
end
Store_common_color_grid:draw_items(Color_grid_data, Color_grid_data.current, 9, grid_rows, 53.5, 53.5, 15, nil, 1.1, true, true, -7, true)
-- set the titles on top
Store_header:push_title(nil, "VCUST_COLOR_GRID_TITLE")
-- Initialize grid navigation for mouse
Old_vehicle_grid_index = -1
Store_common_color_grid:nav_enable(true, "store_vehicle_trim_color_selected", "store_vehicle_trim_color_grid_nav")
Current_tier = COLOR_TIER
Store_header:enable_price_respect(true)
local index = Store_common_color_grid:return_selected_index()
Store_vehicle_color_price = Color_grid_data[index].price
Store_vehicle_color_respect = Color_grid_data[index].style
Store_header:set_price(Store_vehicle_color_price)
Store_header:set_respect(Store_vehicle_color_respect)
Store_header:enable_price_respect(true)
end
function store_vehicle_trim_color_grid_nav(event, value)
store_vehicle_grid_nav(event, false, value)
-- subtract 1 because grid indexing starts at 1
local index = Store_common_color_grid:return_selected_index()
vcust_preview_color(index - 1)
Store_vehicle_color_price = Color_grid_data[index].price
Store_vehicle_color_respect = Color_grid_data[index].style
Store_header:set_price(Store_vehicle_color_price)
Store_header:set_respect(Store_vehicle_color_respect)
Store_header:enable_price_respect(true)
end
function store_vehicle_trim_color_selected(event)
-- Did the player make a selection?
if event == "select" or event == "mouse_click" then
local idx = Store_common_color_grid:return_selected_index()
if idx <= #Color_grid_data then
end
-- Now we need to check for purchasing
-- Disable mouse input for active_list and hint_bar
store_vehicle_enable_mouse(false)
Store_common_color_grid:nav_enable(false, nil, nil)
-- Are we short on cash?
if Store_vehicle_color_price > Store_common_player_cash then
Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1)
Store_common_popup:set_title("MENU_TITLE_NOTICE")
Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")
Store_common_popup:nav_enable(true, "store_vehicle_fail_msg", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
return
end
-- Make sure they want to buy this
Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("STORE_TITLE_PURCHASING")
local insert = { [0] = Color_grid_data[idx].label, [1] = format_cash(Store_vehicle_color_price) }
local body = vint_insert_values_in_string("VCUST_PURCHASE_PROMPT", insert)
Store_common_popup:set_text(body)
Store_common_popup:nav_enable(true, "store_vehicle_purchase_color_final", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
return
end
Current_tier = MENU_TIER
-- going back to menu
Store_common_color_grid:nav_enable(false, nil, nil)
Active_list:set_visible(true)
store_vehicle_populate_list(Menu_data, Active_list:get_selection())
Store_header:enable_price_respect(false)
-- revert color choice
vcust_revert_color()
-- remove titles
Store_header:pop_title()
--Store_header:pop_title()
Store_common_color_grid:set_visible(false)
end
function store_vehicle_populate_underglow_grid()
Store_vehicle_color_slot = STORE_VEHICLE_UNDERGLOW_COLOR
-- New menu, clear out all items
table_clear(Color_grid_data, true)
Color_grid_data.show_layered = false
vint_dataresponder_request("vcust_populate_underglow_color", "store_vehicle_underglow_color_add", 0)
if Hint_bar_mouse_input_tracker ~= nil and Hint_bar_mouse_input_tracker ~= 0 then
Hint_bar_mouse_input_tracker:subscribe(true)
end
Store_common_color_grid:draw_items(Color_grid_data, Color_grid_data.current, 9, 5, 53.5, 53.5, 15, nil, 1.1, true, true, -7, true)
Store_header:enable_price_respect(true)
local index = Store_common_color_grid:return_selected_index()
Store_vehicle_color_price = Color_grid_data[1].price
Store_vehicle_color_respect = Color_grid_data[1].respect
Store_header:set_price(Store_vehicle_color_price)
Store_header:set_respect(Store_vehicle_color_respect)
-- Initialize grid navigation for mouse
Old_vehicle_grid_index = -1
Store_common_color_grid:nav_enable(true, "store_vehicle_underglow_color_selected", "store_vehicle_underglow_color_grid_nav")
-- do an initial nav to initialize header, etc. (pass in dummy movement value for navigation)
store_vehicle_underglow_color_grid_nav("do_not_move")
Store_common_color_grid:set_visible(true)
Active_list:set_visible(false)
-- set the titles on top
Store_header:push_title(nil, "VCUST_COLOR_GRID_TITLE")
-- Disable the mouse for the active list
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:subscribe(false)
end
Current_tier = COLOR_TIER
end
function store_vehicle_underglow_color_add(display_name, current, price, respect, base_r, base_g, base_b)
local index = #Color_grid_data + 1
local item = {
label = display_name,
icon = "ui_menu_veh_pnt_base",
color = { red = base_r, green = base_g, blue = base_b },
base_r = base_r, base_g = base_g, base_b = base_b, -- Base paint color, used on base
price = price,
owned = current,
is_glass = false, -- Glass or Interior or normal
is_layered = false,
respect = respect,
}
if current == true then
Color_grid_data.current = index
end
Color_grid_data[index] = item
end
function store_vehicle_underglow_color_grid_nav(event, value)
store_vehicle_grid_nav(event, false, value)
end
function store_vehicle_underglow_color_selected(event)
Store_common_color_grid:nav_enable(false, nil, nil)
-- Did the player make a selection?
if event == "select" or event == "mouse_click" then
game_UI_audio_play("UI_Main_Menu_Select")
local idx = Store_common_color_grid:return_selected_index()
if idx <= #Color_grid_data then
Store_vehicle_color_selection = idx
Store_vehicle_color_price = Color_grid_data[idx].price
--Store_common_color_grid:nav_enable(false, nil, nil) -- disable input going to grid control
store_vehicle_enable_mouse(false)
-- Now we need to check for purchasing
-- Are we short on cash?
if Store_vehicle_color_price > Store_common_player_cash then
Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1)
Store_common_popup:set_title("MENU_TITLE_NOTICE")
Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")
Store_common_popup:nav_enable(true, "store_vehicle_underglow_fail_msg", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
-- Re-enable the grid inside store_vehicle_fail_msg, not here (screws up mouse inputs if it's done here)
return
end
-- Make sure they want to buy this
Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("STORE_TITLE_PURCHASING")
local insert = { [0] = Color_grid_data[idx].label, [1] = format_cash(Store_vehicle_color_price) }
local body = vint_insert_values_in_string("VCUST_PURCHASE_PROMPT", insert)
Store_common_popup:set_text(body)
Store_common_popup:nav_enable(true, "store_vehicle_underglow_purchase_color_final", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
return
end
end
game_UI_audio_play("UI_Main_Menu_Nav_Back")
-- remove title
Store_header:pop_title()
Store_common_color_grid:set_visible(false)
store_vehicle_clear_header()
Active_list:set_visible(true)
-- Enable the mouse for active_list and hint_bar
store_vehicle_enable_mouse(true)
Current_tier = MENU_TIER
end
function store_vehicle_underglow_fail_msg(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
game_UI_audio_play("UI_Main_Menu_Select")
-- Re-enable the mouse for active_list and hint_bar
if Current_tier ~= PALETTE_TIER and Current_tier ~= COLOR_TIER then
store_vehicle_enable_mouse(true)
else
-- Re-enable the mouse
Store_common_color_grid:nav_enable(true, "store_vehicle_underglow_color_selected", "store_vehicle_underglow_color_grid_nav")
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:subscribe(true)
end
end
end
function store_vehicle_underglow_purchase_color_final(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
-- The user hit the B button and are cancelling the purchase
-- This is redundant to selecting "No" in the list
if event == "back" then
vcust_revert_color()
game_UI_audio_play("UI_Main_Menu_Nav_Back")
-- Re-enable the mouse
Store_common_color_grid:nav_enable(true, "store_vehicle_underglow_color_selected", "store_vehicle_underglow_color_grid_nav")
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:subscribe(true)
end
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
vcust_revert_color()
-- Re-enable the mouse
Store_common_color_grid:nav_enable(true, "store_vehicle_underglow_color_selected", "store_vehicle_underglow_color_grid_nav")
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:subscribe(true)
end
return
end
Current_tier = MENU_TIER
-- Re-enable the mouse
store_vehicle_enable_mouse(true)
-- award respect and actually purchase the item
game_award_respect(Store_vehicle_color_respect)
-- subtract 1 because grid indexing starts at 1
local index = Store_common_color_grid:return_selected_index()
vcust_set_underglow(index - 1, Store_vehicle_color_price)
ui_audio_post_event("vehicle_purchase")
-- reset titles
while #Store_header.title_stack > 1 do
Store_header:pop_title()
end
Store_common_color_grid:nav_enable(false, nil, nil)
Store_common_color_grid:set_visible(false)
store_vehicle_clear_header()
Active_list:set_visible(true)
-- do this so holding down the button doesn't cause repeated actions
store_lock_controls()
store_unlock_controls()
end
-- Performance upgrades
--------------------------------------
function store_vehicle_purchase_upgrade(menu_data)
-- Disable the mouse for active_list and hint_bar
store_vehicle_enable_mouse(false)
-- Are we short on cash?
if menu_data.price > Store_common_player_cash then
Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1)
Store_common_popup:set_title("MENU_TITLE_NOTICE")
Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")
Store_common_popup:nav_enable(true, "store_vehicle_fail_msg", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
return
end
-- Make sure they want to buy this
Store_vehicle_purchase_item = menu_data
Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("STORE_TITLE_PURCHASING")
Store_common_popup:set_text("STORE_TEXT_CONFIRM_PURCHASE_BLANK")
Store_common_popup:nav_enable(true, "store_vehicle_purchase_upgrade_final", "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(.5)
Active_list:set_visible(false)
end
-- LAS: This is already defined, commenting out, though it can likely be deleted
--[[function store_vehicle_fail_msg(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
game_UI_audio_play("UI_Main_Menu_Select")
-- Re-enable the mouse
store_vehicle_enable_mouse(true)
end]]
-- Finalize or cancel a purchase based on the result of the confirmation question.
--
-- response: how did the user respond?
-- action: indicates if the dialog box was closed or some other action.
--
function store_vehicle_purchase_upgrade_final(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
Active_list:set_visible(true)
-- Re-enable the mouse
store_vehicle_enable_mouse(true)
-- The user hit the B button and are cancelling the purchase
-- This is redundant to selecting "No" in the list
if event == "back" then
game_UI_audio_play("UI_Main_Menu_Nav_Back")
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
return
end
-- award respect and actually purchase the item
game_award_respect(Store_vehicle_purchase_item.style)
vcust_purchase_performance_upgrade(Store_vehicle_purchase_item.id)
ui_audio_post_event("vehicle_purchase")
-- repopulate the menu
Store_vehicle_building_menu = {}
vint_dataresponder_request("vcust_populate_menu", "store_vehicle_populate_menu", 0, STORE_VEHICLE_POPULATE_CURRENT_MENU)
Menu_data = Store_vehicle_building_menu
local index = Active_list:get_selection()
store_vehicle_populate_list(Menu_data, index)
store_vehicle_upgrade_nav(Menu_data[index])
-- do this so holding down the button doesn't cause repeated actions
store_lock_controls()
store_unlock_controls()
--Input_tracker:subscribe(false)
--Input_tracker:subscribe(true)
end
function store_vehicle_upgrade_enter(menu_data)
debug_print("vint", "entered store_vehicle_upgrade_enter\n")
local index = Active_list:get_selection()
store_vehicle_upgrade_nav(menu_data[index])
-- repopulate the menu
Store_vehicle_building_menu = {}
vint_dataresponder_request("vcust_populate_menu", "store_vehicle_populate_menu", 0, STORE_VEHICLE_POPULATE_CURRENT_MENU)
Menu_data = Store_vehicle_building_menu
local index = Active_list:get_selection()
store_vehicle_populate_list(Menu_data, index)
store_vehicle_upgrade_nav(Menu_data[index])
end
function store_vehicle_upgrade_nav(menu_data)
-- Update the store header price and respect values
if menu_data.price ~= nil and menu_data.price > 0 and menu_data.level < menu_data.max_level then
Store_header:enable_price_respect(true)
Store_header:set_price(menu_data.price)
Store_header:set_respect(menu_data.style)
else
store_vehicle_clear_header()
end
store_vehicle_set_description(menu_data.desc)
end
function garage_preview(menu_data)
-- clear out "new" status if it is true
if menu_data.is_new then
garage_clear_new(menu_data.id)
--Remove our mouse inputs first...
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
end
--Get index from the list and then remove the flag...
local index = Active_list:get_index_from_id(menu_data.id)
Active_list:remove_new_flag(index)
--Update cursor,
Active_list:move_cursor(0)
--Re add mouse inputs...
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
Active_list:add_mouse_inputs("store_common", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
if #Menu_data == 1 then
-- Can't go up or down if there's just one item.
return
end
if Active_list:get_selection() ~= nil and Menu_data[Active_list:get_selection()] ~= nil then
garage_preview_vehicle( Menu_data[Active_list:get_selection()].id )
--local rim_jobs_grp = vint_object_find("rim_jobs_grp", 0, Store_vehicle_doc_handle)
--vint_set_property(rim_jobs_grp, "background", false) -- Changing cars, so hiding the transition
end
end
-- This is called once the car is fully loaded in. At this point, all component data is loaded.
-- We'll update stats and also show the background as a background
function garage_populate_performance_stats(di_h)
local index, label, level, max_level = vint_dataitem_get(di_h)
if index == 0 then
-- 0 indicates that we are done
--Vehicle_stats:set_visible(true)
Vehicle_stats:draw_items(Vehicle_stats_data)
Vehicle_stats_data = {}
local rim_jobs_grp = vint_object_find("rim_jobs_grp", 0, Store_vehicle_doc_handle)
vint_set_property(rim_jobs_grp, "background", true)
bg_saints_set_background(true)
else
Vehicle_stats_data[index] = {
label = label,
max_level = max_level,
level = level,
}
end
end
function garage_update_stat_visibility()
if garage_get_garage_type == GVT_CARS then
Vehicle_stats:set_visible(true)
end
end
function garage_select(menu_data)
store_vehicle_garage_vehicle_select()
end
function garage_populate_car_list(display_name, id, retrieval_cost, current, is_new, is_dlc)
-- Add the item
local item = { label = display_name, type = TYPE_BUTTON, id = id, price = retrieval_cost, is_new = is_new, is_dlc = is_dlc }
local menu_idx = #Store_vehicle_building_menu + 1
Store_vehicle_building_menu[menu_idx] = item
item.on_nav = garage_preview
item.on_select = garage_select
-- is this the currently owned item?
if current == true then
Menu_data.start_index = menu_idx
-- Do what we would when navigating to the currently highlighted item
if item.on_nav ~= nil then
item.on_nav(item)
end
end
end
-- populate the top level menu
function garage_build_areas()
Menu_data = {}
Menu_data.on_enter = garage_nav_areas
Store_vehicle_building_menu = Menu_data
vint_dataresponder_request("garage_populate", "garage_populate_car_list", 0)
if Menu_data.start_index == nil then
Menu_data.start_index = 1
end
if #Menu_data == 0 then
Empty_garage = true
else
garage_preview_vehicle(Menu_data[Menu_data.start_index].id)
Empty_garage = false
end
-- TODO: May need to enable the mouse for active_list and hint_bar
end
-- Update the Current Menu selection
function garage_nav_areas(menu_data)
-- subtracting one because C code is 0-indexed
--garage_change_top_level_menu(0, Active_list:get_selection() - 1)
end
-- Customization Top level menus
--------------------------------------
function store_vehicle_populate_menu(display_name, cat_type, id, price, current, level, desc, respect, palette_first)
-- Add the item
local item = { label = display_name, type = TYPE_BUTTON, id = id }
-- Fill in values specific to different menu types
if cat_type == STORE_VEHICLE_TYPE_SLOT then
item.on_nav = store_vehicle_nav_slot
item.on_sub_menu_fill = store_vehicle_build_menu
elseif cat_type == STORE_VEHICLE_TYPE_COMPONENT then
item.on_sub_menu_fill = store_vehicle_build_menu
elseif cat_type == STORE_VEHICLE_TYPE_COLOR_REGION then
-- we handle underglow color in a completely different manner
if item.id == STORE_VEHICLE_UNDERGLOW_COLOR then
item.on_select = store_vehicle_populate_underglow_grid
else
item.on_sub_menu_fill = store_vehicle_select_region
end
elseif cat_type == STORE_VEHICLE_TYPE_COLOR_PALETTE then
-- some color regions start with the palette/material grid, some start with the color grid
Store_vehicle_select_palette_first = palette_first
if palette_first then
item.on_select = store_vehicle_populate_trim_palette_menu
else
item.on_select = store_vehicle_populate_color_grid
end
elseif cat_type == STORE_VEHICLE_TYPE_PERFORMANCE then
item.on_nav = store_vehicle_upgrade_nav
item.max_level = 4
item.desc = desc
item.show_next_level = true
item.type = TYPE_PIP
-- do we already own the max level?
if level == item.max_level then
item.level = level
item.show_next_level = false
else
item.level = level
item.price = price
item.style = respect
item.on_select = store_vehicle_purchase_upgrade
end
Store_vehicle_building_menu.performance_menu = true
elseif cat_type == STORE_VEHICLE_TYPE_PERFORMANCE_SLOT then
item.on_nav = store_vehicle_upgrade_nav
item.on_sub_menu_fill = store_vehicle_build_menu
Store_vehicle_building_menu.on_enter = store_vehicle_upgrade_enter
item.max_level = 1
item.desc = desc
item.show_next_level = false
--Making nitrous and kneecappers a button because they don't really behave like pips.
--The user has to select them first then choose upgrade or stock in a different menu.
item.type = TYPE_BUTTON
-- do we already own the max level?
if level == item.max_level then
item.level = level
item.show_next_level = false
else
item.level = level
item.price = price
item.style = respect
end
else
debug_print("vint", "Vehicle Customization - Invalid Category type: " .. cat_type .. "\n")
end
local menu_idx = #Store_vehicle_building_menu + 1
Store_vehicle_building_menu[menu_idx] = item
-- is this the currently owned item?
if current == true then
Store_vehicle_building_menu.start_index = menu_idx
end
end
-- populate the current sub menu
function store_vehicle_build_current_menu(menu_data)
Store_vehicle_building_menu = menu_data.sub_menu
Store_vehicle_building_menu.start_index = 1
vint_dataresponder_request("vcust_populate_menu", "store_vehicle_populate_menu", 0, STORE_VEHICLE_POPULATE_CURRENT_MENU)
-- Do what we would when navigating to the currently highlighted item
local i = Store_vehicle_building_menu[Store_vehicle_building_menu.start_index]
if i.on_nav ~= nil then
i.on_nav(i)
end
end
-- populate the top level menu
function store_vehicle_build_areas()
Menu_data = {}
Menu_data.on_enter = store_vehicle_area_on_enter
Store_vehicle_building_menu = Menu_data
vint_dataresponder_request("vcust_populate_menu", "store_vehicle_add_area", 0, STORE_VEHICLE_POPULATE_AREAS)
store_vehicle_clear_header()
if #Menu_data ~= 0 then
if store_vehicle_allow_garage() then
local item = {
--label = "GARAGE_CRIB_NAME", type = TYPE_BUTTON, on_select = store_vehicle_switch_mode, disabled = true,
label = "GARAGE_CRIB_NAME", type = TYPE_BUTTON, on_select = store_vehicle_switch_mode,
}
Menu_data[#Menu_data + 1] = item
end
-- add exit store option
local exit_item = {
label = "MENU_RESUME_GAME", type = TYPE_BUTTON, on_select = store_vehicle_resume_game
}
Menu_data[#Menu_data + 1] = exit_item
-- add return to crib option
-- can't return to crib from customization, need to go back to garage first.
--[[
if Store_vehicle_loaded_from_crib then
local crib_exit_item = {
label = "VCUST_RETURN_TO_CRIB", type = TYPE_BUTTON, on_select = store_vehicle_return_to_crib
}
Menu_data[#Menu_data + 1] = crib_exit_item
end
]]
store_vehicle_populate_list(Menu_data, 1)
end
end
-- C code was just informed us that the swap to a customizable vehicle is complete. If we couldn't populate the top level menu
-- earlier, we do so now.
--
function store_vehicle_signal_swap_complete()
if #Menu_data == 0 then
store_vehicle_build_areas()
end
end
function store_vehicle_add_area(display_name, index, ignored, ignored2, is_wheel_menu)
-- Add the item
local item = { label = display_name, type = TYPE_BUTTON, id = index, on_nav = store_vehicle_nav_areas }
if is_wheel_menu then
item.sub_menu = Store_vehicle_axle_menu
else
item.on_sub_menu_fill = store_vehicle_build_current_menu
end
local menu_idx = #Store_vehicle_building_menu + 1
Store_vehicle_building_menu[menu_idx] = item
end
function store_vehicle_area_on_enter(menu_data)
-- reset camera back to standard view
vcust_set_camera_pos("Standard")
store_vehicle_nav_areas(menu_data)
end
-- Update the Current Menu selection
function store_vehicle_nav_areas(menu_data)
-- subtracting one because C code is 0-indexed
vcust_change_top_level_menu(0, Active_list:get_selection() - 1)
-- When returning to the top level menu, we want to make sure to clear the header and performance descriptions.
store_vehicle_clear_header()
local hint_rotate_data = {
{CTRL_BUTTON_RS, "STORE_ZOOM_ROTATE"},
}
Store_common_rotate_hint:set_hints(hint_rotate_data)
if Game_platform ~= "PC" then
Store_common_rotate_hint:set_visible(true)
end
end
function store_vehicle_init()
Store_common_current_highlight_color = COLOR_STORE_VEHICLE_PRIMARY
store_lock_controls()
Store_vehicle_loaded_from_crib = store_common_crib_is_loaded()
-- If we're in the crib, we're only doing garage (not store).
-- For initial load, check with C which mode we should be in.
if store_vehicle_get_state() == MODE_VCUST and Store_vehicle_loaded_from_crib == false then
Store_vehicle_is_garage = false
else
Store_vehicle_is_garage = true
end
Store_vehicle_begin_from_garage = Store_vehicle_is_garage
-- unload the full screen map to pillage memory
if Store_vehicle_loaded_from_crib == false then
pause_map_dump()
end
Screen_cover_count = 0
Store_vehicle_doc_handle = vint_document_find("store_vehicle")
-- Set up some callbacks for the common store script
Store_common_populate_list_cb = store_vehicle_populate_list
Store_common_exit_cb = store_vehicle_exit
-- Declare stage objects
Not_popup_grp = Vdo_base_object:new("not_popup_grp", 0, Store_common_doc_handle) -- Everything that is not in the popup so we can fade it when the popup is active
-- Setup purchase popup
Store_common_popup:set_visible(false)
Store_common_popup:set_size(STORE_COMMON_LIST_SIZE, (LIST_BUTTON_HEIGHT * 5) + (LIST_BUTTON_SPACE * 5))
--local popup_x,popup_y = Store_common_popup:get_anchor()
--Store_common_popup:set_anchor(155,popup_y)
-- MAYBE MOVE THIS TO store_vehicle_mode_set_init?
-- Save the platform and set up the hint_bar mouse input
Game_platform = game_get_platform()
if Game_platform == "PC" then
Hint_bar_mouse_input_tracker = Vdo_input_tracker:new()
end
--Setup Button Hints
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
--{CTRL_BUTTON_X, "GARAGE_CRIB_NAME"},
}
Store_common_hint_bar:set_hints(hint_data)
Store_common_hint_bar:set_visible(true)
local hint_rotate_data = {
{CTRL_BUTTON_RS, "STORE_ZOOM_ROTATE"},
}
Store_common_rotate_hint:set_hints(hint_rotate_data)
Store_common_rotate_hint:enable_text_shadow(true)
if Game_platform ~= "PC" then
Store_common_rotate_hint:set_visible(true)
end
Store_header:set_visible(true)
-- Setup Color grid
Store_common_color_grid:set_visible(false)
Store_common_color_grid:set_ui_screen("store_vehicle")
local grid_x, grid_y = Store_common_color_grid:get_anchor()
Store_common_color_grid:set_anchor(grid_x, STORE_COMMON_GRID_VEHICLE_Y)
Rim_jobs_grp = Vdo_base_object:new("rim_jobs_grp", 0,Store_vehicle_doc_handle)
Rim_jobs_grp:set_visible(false)
if Store_vehicle_loaded_from_crib then
bg_saints_set_type(BG_TYPE_CRIB_USE, true, 1280, 0)
elseif Store_vehicle_begin_from_garage then
bg_saints_set_type(BG_TYPE_CRIB_USE, false, 1280, 0)
bg_saints_slide_in(1280, 0)
else
bg_saints_set_type(BG_TYPE_CRIB_USE, true, 1280, 0)
end
if Store_vehicle_is_garage then
local store_logo = Vdo_base_object:new("rj_logo", 0, Store_vehicle_doc_handle)
store_logo:set_visible(false)
bg_saints_show(true)
vint_set_property(vint_object_find("vignette_grp_1",0,Store_vehicle_doc_handle),"visible",false)
Store_header:reformat_and_resize(true)
ui_audio_post_event("Enter_Garage")
else
bg_saints_show(false)
if Store_vehicle_loaded_from_crib == false then
ui_audio_post_event("enter_rim_jobs")
end
end
store_vehicle_bg_is_loaded()
Vehicle_stats = Vdo_item_stats:new("item_stats", 0, Store_vehicle_doc_handle)
Vehicle_stats:set_visible(false)
-- Make background so vehicle shows on top
if Store_vehicle_loaded_from_crib == false then
-- moved color switching to store_vehicle_mode_set_init()
else
-- crib specific stuff
local store_main_grp = Vdo_base_object:new("store_main_grp", 0, Store_common_doc_handle)
store_main_grp:set_anchor(0,0)
Store_common_spinner:set_color(COLOR_SAINTS_PURPLE)
-- animate in ui for vehicles (shared by all stores)
local store_vehicle_in_anim = Vdo_anim_object:new("store_common_in_anim", 0, Store_common_doc_handle)
local end_event_twn = Vdo_tween_object:new("end_event_twn", store_vehicle_in_anim.handle, Store_common_doc_handle)
end_event_twn:set_end_event("store_unlock_controls")
vint_apply_start_values(store_vehicle_in_anim.handle)
store_vehicle_in_anim:play(0)
-- make background so car is on top
bg_saints_set_background(false)
-- Hide vehicle store background since we use the saints background in crib
local vehicle_bg_grp = Vdo_base_object:new("rj_bg", 0, Store_vehicle_doc_handle)
vehicle_bg_grp:set_visible(false)
vehicle_bg_grp = Vdo_base_object:new("dots_grp", 0, Store_vehicle_doc_handle)
vehicle_bg_grp:set_visible(false)
vehicle_bg_grp = Vdo_base_object:new("vignette_grp_1", 0, Store_vehicle_doc_handle)
vehicle_bg_grp:set_visible(false)
end
-- This must come after we set highlight colors, or it will fail
store_vehicle_mode_set_init()
-- subscribe to data items
vint_datagroup_add_subscription("garage_performance_stats", "update", "garage_populate_performance_stats")
character_enable_mouse_drag(true)
end
function store_vehicle_bg_is_loaded()
if Store_vehicle_loaded_from_crib == false --[[and not Store_vehicle_is_garage]] then
local rim_jobs_bg_anim = Vdo_anim_object:new("rim_jobs_bg_anim", 0, Store_vehicle_doc_handle)
local store_vehicle_in_anim = Vdo_anim_object:new("store_common_in_anim", 0, Store_common_doc_handle)
local rim_jobs_bg_twn = Vdo_tween_object:new("rim_jobs_bg_twn")
local bg_end_event_twn = Vdo_tween_object:new("bg_end_event_twn", rim_jobs_bg_anim.handle)
bg_end_event_twn:set_end_event("store_vehicle_screen_is_covered")
rim_jobs_bg_twn:set_end_event("store_vehicle_loop_bg_anims")
vint_apply_start_values(rim_jobs_bg_anim.handle)
vint_apply_start_values(store_vehicle_in_anim.handle)
rim_jobs_bg_anim:play(0)
store_vehicle_in_anim:play(0)
if Store_vehicle_is_garage == false then
Rim_jobs_grp:set_visible(true)
end
end
end
function store_vehicle_screen_is_covered()
Screen_cover_count = Screen_cover_count + 1
if Screen_cover_count == 1 then
store_unlock_controls()
end
if vcust_is_camera_tool_mode() == false then
-- notify C code to begin vehicle swap
store_vehicle_notify_screen_covered()
end
end
function store_vehicle_loop_bg_anims(tween_handle)
local animation = vint_object_parent(tween_handle)
-- Loop bg anim starting at frame 40
lua_play_anim(animation, -1.5)
end
--function store_vehicle_unlock_controls()
-- Input_tracker:subscribe(true)
-- store_vehicle_enable_mouse(true)
--end
function store_vehicle_cleanup()
-- make sure all pegs are unloaded
game_peg_unload(VEHICLE_CUST_RIM_PEG)
game_peg_unload(VEHICLE_CUST_GLASS_PEG)
game_peg_unload(VEHICLE_CUST_TIRE_PEG)
if Store_vehicle_current_logo ~= -1 and Hud_current_veh_logo ~= Store_vehicle_current_logo then
--unload vehicle logo
game_peg_unload(Store_vehicle_current_logo)
end
-- reload the full screen map
if Store_vehicle_loaded_from_crib == false then
pause_map_restore()
end
character_enable_mouse_drag(false)
-- 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
function store_vehicle_exit_final(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(0)
Vehicle_stats:set_alpha(0)
-- 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)
Vehicle_stats:set_alpha(1)
Active_list:set_visible(true)
store_vehicle_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)
Vehicle_stats:set_alpha(1)
Active_list:set_visible(true)
store_vehicle_enable_mouse(true)
return
end
-- Exit customization to garage
if Store_vehicle_begin_from_garage and Store_vehicle_is_garage == false and Garage_leave_with_car ~= true then
Not_popup_grp:set_alpha(1)
Vehicle_stats:set_alpha(1)
store_vehicle_enable_mouse(true)
Active_list:set_visible(true)
store_vehicle_switch_mode()
return
end
bg_saints_show(false)
-- lock controls, because a bug was found where user can push input during leaving and cause a crash
store_lock_controls()
store_vehicle_retrieve_car_and_exit()
end
function store_vehicle_no_vehicle_exit_final(event)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(0)
Vehicle_stats:set_alpha(0)
-- 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)
Vehicle_stats:set_alpha(1)
Active_list:set_visible(true)
store_vehicle_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)
Vehicle_stats:set_alpha(1)
Active_list:set_visible(true)
store_vehicle_enable_mouse(true)
return
end
-- Exit garage to customization
if Store_vehicle_begin_from_garage == false and Store_vehicle_is_garage then
Not_popup_grp:set_alpha(1)
Vehicle_stats:set_alpha(1)
Active_list:set_visible(true)
store_vehicle_enable_mouse(true)
--hide the vehicle logo
local vehicle_logo_h = vint_object_find("vehicle_logo", 0, Store_vehicle_doc_handle)
vint_set_property(vehicle_logo_h, "visible", false)
-- if back to customize returns true, go ahead and call store_vehicle_switch_mode
-- otherwise, wait for vehicle to load in garage, then game will call store_vehicle_switch_mode
-- garage_back_to_customize
garage_back_to_customize()
--store_vehicle_switch_mode()
return
end
--hide the vehicle logo
local vehicle_logo_h = vint_object_find("vehicle_logo", 0, Store_vehicle_doc_handle)
vint_set_property(vehicle_logo_h, "visible", false)
store_vehicle_no_vehicle_exit()
end
function store_vehicle_resume_game()
store_vehicle_exit(nil,true)
end
function store_vehicle_exit(menu_data, leave_with_car)
-- If a popup is active, don't try to exit (to crib or switch modes)
if Store_common_popup:get_visible() then
return
end
-- no confirmation needed if we're just going back to the crib menu
if Store_vehicle_loaded_from_crib then
if Store_vehicle_is_garage then
store_lock_controls()
store_vehicle_return_to_crib()
return
elseif leave_with_car ~= true then
--return to crib garage
store_vehicle_switch_mode()
return
end
end
--[[if Store_vehicle_begin_from_garage then
store_vehicle_switch_mode()
return
end
--store_vehicle_enable_controls(false)
end]]
-- don't allow exit popup (ignore controls) if vehicle not fully streamed in
if store_vehicle_selection_should_lock_controls() then
return
end
local body
local callback
if Store_vehicle_is_garage then
body = "VCUST_GARAGE_EXIT_PROMPT"
callback = "store_vehicle_no_vehicle_exit_final"
else
body = "VCUST_EXIT_PROMPT"
callback = "store_vehicle_exit_final"
end
local heading = "MENU_TITLE_WARNING"
Store_common_popup:populate_list(Yes_no_choices, 2, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title(heading)
Store_common_popup:set_text(body)
Store_common_popup:nav_enable(true, callback, "store_vehicle_popup_nav")
Not_popup_grp:set_alpha(0.5)
Vehicle_stats:set_alpha(0.5)
Active_list:set_visible(false)
Garage_leave_with_car = leave_with_car
-- Disable mouse input for other items while the popup is up
store_vehicle_enable_mouse(false)
end
function store_vehicle_set_description(text)
local upgrade_desc = Vdo_base_object:new("upgrade_desc", 0, Store_common_doc_handle)
if text ~= nil then
upgrade_desc:set_color(COLOR_STORE_VEHICLE_PRIMARY.R, COLOR_STORE_VEHICLE_PRIMARY.G, COLOR_STORE_VEHICLE_PRIMARY.B)
upgrade_desc:set_text(text)
upgrade_desc:set_visible(true)
else
upgrade_desc:set_visible(false)
end
end
function store_vehicle_popup_nav(event, value)
if event == "mouse_move" then
vint_set_mouse_cursor("")
Store_common_hint_bar:set_highlight(0)
end
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
-- Populate the active megalist 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_vehicle_populate_list(list_data, current_index)
local max_list_size = 9
--if Store_vehicle_is_garage then
-- max_list_size = 9
--end
local selected_index = current_index
if list_data.performance_menu == true and Game_platform == "PC" then
-- On PC and performance menu, we will first select the last item in the list built the inputs and then
-- set the selection to the right index. This is to setup the inputs properly because this type of list is
-- doublelined and not really supported by the mouse input tracker. This was an easy workaround.
selected_index = #list_data
end
Active_list:draw_items(list_data, selected_index, STORE_COMMON_LIST_SIZE, max_list_size, LIST_FONT_SCALE)
Active_list:set_visible(true)
-- Add mouse inputs for active_list
if Game_platform == "PC" then
Mouse_input_tracker:remove_all()
Active_list:set_store("store_vehicle")
Active_list:add_mouse_inputs("store_common", Mouse_input_tracker)
if list_data.performance_menu == true then
Active_list:set_selection(current_index)
Active_list:move_cursor(0, true)
end
store_vehicle_enable_mouse(true)
end
end
function store_vehicle_rim_grid_nav(event, value)
-- true is passed to indicate we don't want the grid list vdo to redraw; we want to wait for swatch loads
local redraw_grid = store_vehicle_grid_nav(event, true, value)
-- update price and respect
local item = Store_common_color_grid:return_selected_data()
if item.price ~= nil and item.price > 0 then
Store_header:set_price(item.price)
Store_header:set_respect(item.style)
else
store_vehicle_clear_header()
end
Store_vehicle_wheel_price.rim = item.price
Store_vehicle_wheel_respect.rim = item.style
-- preview the selected rim
local cat_index = Store_common_color_grid:return_selected_cat()
-- spinners must store their original category individually, since they are grouped
-- into different categories for the UI.
if Color_grid_data[cat_index].category_name == "VCUST_SPINNERS_TITLE" then
vcust_preview_component(2, 3, item.category_id, item.id)
else
vcust_preview_component(2, 0, cat_index - 1, item.id)
end
if redraw_grid then
Store_common_color_grid:draw_items(Store_common_color_grid.data, Store_common_color_grid.current_idx, Store_common_color_grid.max_width, Store_common_color_grid.max_height, Store_common_color_grid.button_w, Store_common_color_grid.button_h, Store_common_color_grid.hint_button_offset, Store_common_color_grid.current_cat, nil, true, false)
Store_common_color_grid:update_mouse_inputs()
end
end
function store_vehicle_palette_grid_nav(event, value)
store_vehicle_grid_nav(event, false, value)
-- slot is hardcoded to 0
-- subtract 1 because grid indexing starts at 1
local item = Store_common_color_grid:return_selected_data()
vcust_preview_palette(0, item.id, Store_vehicle_color_selection - 1)
Store_header:enable_price_respect(true)
local index = Store_common_color_grid:return_selected_index()
Store_header:set_price(Store_vehicle_color_price)
Store_header:set_respect(Store_vehicle_color_respect)
end
function store_vehicle_color_grid_nav(event, value)
store_vehicle_grid_nav(event, false, value)
-- subtract 1 because grid indexing starts at 1
local index = Store_common_color_grid:return_selected_index()
vcust_preview_color(index - 1)
Store_vehicle_color_price = Color_grid_data[index].price
Store_vehicle_color_respect = Color_grid_data[index].style
end
-- Handle navigating grid
-- Returns true if the grid index changed
function store_vehicle_grid_nav(event, do_not_redraw, value, rim_resubscribe)
if event == "nav_up" then
Store_common_color_grid:move_cursor(-2, do_not_redraw)
elseif event == "nav_down" then
Store_common_color_grid:move_cursor(2, do_not_redraw)
elseif event == "nav_left" then
Store_common_color_grid:move_cursor(-1, do_not_redraw)
elseif event == "nav_right" then
Store_common_color_grid:move_cursor(1, do_not_redraw)
elseif event == "mouse_move" then
-- value contains the target_handle in this case
local new_index, new_category = Store_common_color_grid:get_data_index(value)
if new_index ~= 0 and (Old_vehicle_grid_index ~= new_index or Old_vehicle_grid_category ~= new_category) then
Store_common_color_grid:set_selection(new_index, new_category)
Store_common_color_grid:move_cursor(0, do_not_redraw, false)
-- Store the index/etc for the next comparison
Old_vehicle_grid_index = new_index
Old_vehicle_grid_category = new_category
else
return false
end
else
--do nothing
return false
end
return true
end
function store_vehicle_set_hints(mode_switch_enabled)
local hint_data = { {CTRL_MENU_BUTTON_B, "MENU_BACK"} }
Store_common_hint_bar:set_hints(hint_data)
-- Add mouse input subscriptions
if Game_platform == "PC" then
Hint_bar_mouse_input_tracker:remove_all()
Store_common_hint_bar:add_mouse_inputs("store_vehicle", Hint_bar_mouse_input_tracker)
Hint_bar_mouse_input_tracker:subscribe(true)
end
local hint_rotate_data = {
{CTRL_BUTTON_RS, "STORE_ZOOM_ROTATE"},
}
Store_common_rotate_hint:set_hints(hint_rotate_data)
end
function store_vehicle_mode_set_init()
-- Reset our header
Store_header:clear_titles()
store_vehicle_clear_header()
-- Populate the areas and draw the first menu
local store_vehicle_name
if Store_vehicle_is_garage then
-- set colors for garage
Store_header:set_color(COLOR_STORE_CRIB_PRIMARY, COLOR_STORE_CRIB_SECONDARY, COLOR_STORE_CRIB_TERTIARY)
Active_list:set_highlight_color(COLOR_STORE_CRIB_PRIMARY, COLOR_STORE_CRIB_SECONDARY)
Store_common_color_grid:set_highlight_color(COLOR_STORE_CRIB_PRIMARY, COLOR_STORE_CRIB_SECONDARY, COLOR_STORE_CRIB_TERTIARY)
Store_common_popup:set_color(COLOR_STORE_CRIB_PRIMARY, COLOR_STORE_CRIB_SECONDARY, COLOR_STORE_CRIB_TERTIARY)
Store_common_spinner:set_color(COLOR_STORE_CRIB_PRIMARY)
store_vehicle_name = "garage"
Store_header:enable_price_respect(false)
local title = "TUT_TITLE_CRIB_GARAGE"
local vehicle_type = garage_get_garage_type()
if vehicle_type == GVT_WATERCRAFT then
title = "GARAGE_DOCK"
elseif vehicle_type == GVT_AIRPLANES then
title = "GARAGE_HANGAR"
elseif vehicle_type == GVT_HELICOPTERS then
title = "GARAGE_HELIPORT"
end
Store_header:push_title(nil, title)
local rim_jobs_grp = vint_object_find("rim_jobs_grp", 0, Store_vehicle_doc_handle)
vint_set_property(rim_jobs_grp, "background", false) -- car isn't loaded yet
bg_saints_set_background(false)
else
-- set colors for vehicle store
Store_header:set_color(COLOR_STORE_VEHICLE_PRIMARY, COLOR_STORE_VEHICLE_SECONDARY, COLOR_STORE_VEHICLE_TERTIARY)
Active_list:set_highlight_color(COLOR_STORE_VEHICLE_PRIMARY, COLOR_STORE_VEHICLE_SECONDARY, COLOR_STORE_VEHICLE_TERTIARY)
Store_common_color_grid:set_highlight_color(COLOR_STORE_VEHICLE_PRIMARY, COLOR_STORE_VEHICLE_SECONDARY, COLOR_STORE_VEHICLE_TERTIARY)
Store_common_popup:set_color(COLOR_STORE_VEHICLE_PRIMARY, COLOR_STORE_VEHICLE_SECONDARY, COLOR_STORE_VEHICLE_TERTIARY)
Store_common_spinner:set_color(COLOR_STORE_VEHICLE_PRIMARY)
store_vehicle_name = "DEBUG_CLOTHING_STORE"
Store_header:enable_price_respect(true)
local rim_jobs_grp = vint_object_find("rim_jobs_grp", 0, Store_vehicle_doc_handle)
vint_set_property(rim_jobs_grp, "background", true)
bg_saints_set_background(true)
end
-- reset our store stacks
store_common_stack_clear_menu()
store_common_stack_clear_id()
store_common_stack_clear_index()
Menu_data = { }
if vcust_is_camera_tool_mode() == false then
-- Subscribe to the button presses we need, Input_tracker is created in store_common.lua
--Input_tracker:subscribe(true)
-- Populate the areas and draw the first menu
if Store_vehicle_is_garage then
garage_build_areas()
-- SEH, removing for now because it's broken
--[[if Store_vehicle_loaded_from_crib == false then
local item = {
label = "GARAGE_CUST_NAME", type = TYPE_BUTTON, on_select = store_vehicle_switch_mode,
}
Menu_data[#Menu_data + 1] = item
end
--]]
--[[ Remove exit option for garage. Exit is done using "back"
-- add exit store option
local exit_item = {
label = "STORE_EXIT", type = TYPE_BUTTON, on_select = store_vehicle_exit
Menu_data[#Menu_data + 1] = exit_item
--]]
-- don't display menu if it's empty
if #Menu_data > 0 then
store_vehicle_populate_list(Menu_data, 1)
end
else
store_vehicle_build_areas()
end
else
store_lock_controls()
--Input_tracker:subscribe(false)
-- Fill in a fake menu with enough data to show the scrollbar
for i = 1,20 do
local dummy_item = { label = "GIBBERISH", type = TYPE_BUTTON }
Menu_data[i] = dummy_item
end
store_vehicle_populate_list(Menu_data, 1)
end
-- Update our hints
store_vehicle_set_hints(Store_vehicle_loaded_from_crib == false and
(Store_vehicle_is_garage == false or Empty_garage == false))
end
function store_vehicle_switch_mode()
local store_main_grp = Vdo_base_object:new("store_main_grp", 0, Store_common_doc_handle)
-- reusing wardrobe animations for garage
local store_to_garage_anim = Vdo_anim_object:new("store_to_wardrobe_anim",0, Store_common_doc_handle)
local logo_to_garage_anim = Vdo_anim_object:new("logo_to_garage_anim",0, Store_vehicle_doc_handle)
local garage_twn_1 = Vdo_tween_object:new("wardrobe_twn_1", store_to_garage_anim.handle)
local garage_twn_2 = Vdo_tween_object:new("wardrobe_twn_2", store_to_garage_anim.handle)
store_main_grp:set_property("background", true)
if Store_vehicle_is_garage == true then
Store_vehicle_is_garage = false
garage_twn_1:set_end_event("store_vehicle_switch_to_store")
if Store_vehicle_loaded_from_crib then
--hide the crib logo
vint_set_property(Crib_title,"visible",false)
end
--hide the vehicle logo
local vehicle_logo_h = vint_object_find("vehicle_logo", 0, Store_vehicle_doc_handle)
vint_set_property(vehicle_logo_h, "visible", false)
--show the rim jobs bg
Rim_jobs_grp:set_visible(true)
local vehicle_bg_grp = Vdo_base_object:new("rj_bg", 0, Store_vehicle_doc_handle)
vehicle_bg_grp:set_visible(true)
vehicle_bg_grp = Vdo_base_object:new("dots_grp", 0, Store_vehicle_doc_handle)
vehicle_bg_grp:set_visible(true)
vehicle_bg_grp = Vdo_base_object:new("vignette_grp_1", 0, Store_vehicle_doc_handle)
vehicle_bg_grp:set_visible(true)
local rim_jobs_bg_anim = Vdo_anim_object:new("rim_jobs_bg_anim", 0, Store_vehicle_doc_handle)
local rim_jobs_bg_twn = Vdo_tween_object:new("rim_jobs_bg_twn")
local bg_end_event_twn = Vdo_tween_object:new("bg_end_event_twn", rim_jobs_bg_anim.handle)
bg_end_event_twn:set_end_event("store_vehicle_screen_is_covered")
rim_jobs_bg_twn:set_end_event("store_vehicle_loop_bg_anims")
local rj_logo_h = vint_object_find("rj_logo", 0, Store_vehicle_doc_handle)
vint_set_property(rj_logo_h, "anchor", 343, 94)
vint_apply_start_values(rim_jobs_bg_anim.handle)
rim_jobs_bg_anim:play(0)
store_vehicle_change_mode(MODE_VCUST)
else
Store_vehicle_is_garage = true
bg_saints_show(true)
store_vehicle_clear_header()
garage_twn_1:set_end_event("store_vehicle_switch_to_garage")
if Store_vehicle_loaded_from_crib then
vint_set_property(Crib_title,"visible",false)
end
local anim_out = Vdo_anim_object:new("rim_jobs_anim_out", 0, Store_vehicle_doc_handle)
local rim_jobs_bg_anim = Vdo_anim_object:new("rim_jobs_bg_anim", 0, Store_vehicle_doc_handle)
local end_event_twn = Vdo_tween_object:new("rim_jobs_end_event", anim_out.handle)
end_event_twn:set_end_event("store_vehicle_hide_custom_bg")
anim_out:play(0)
rim_jobs_bg_anim:stop()
--[[elseif Store_vehicle_begin_from_garage then
local anim_out = Vdo_anim_object:new("rim_jobs_anim_out", 0, Store_vehicle_doc_handle)
local end_event_twn = Vdo_tween_object:new("rim_jobs_end_event", anim_out.handle)
end_event_twn:set_end_event("store_vehicle_hide_custom_bg")
anim_out:play(0)
end]]
store_vehicle_change_mode(MODE_GARAGE)
end
garage_twn_2:set_end_event("store_vehicle_switch_mode_complete")
store_to_garage_anim:play(0)
logo_to_garage_anim:play(0)
-- Lock controls until animation is done
store_lock_controls()
--Input_tracker:subscribe(false)
--store_vehicle_enable_mouse(false)
-- Set camera position back to whole body
-- store_set_camera_pos("body")
end
function store_vehicle_hide_custom_bg()
Rim_jobs_grp:set_visible(false)
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)
local vehicle_bg_grp = Vdo_base_object:new("vignette_grp_1", 0, Store_vehicle_doc_handle)
vehicle_bg_grp:set_visible(false)
end
function store_vehicle_switch_mode_complete()
local store_main_grp = Vdo_base_object:new("store_main_grp", 0, Store_common_doc_handle)
--Vehicle_stats:set_property("background", false)
store_main_grp:set_property("background", false)
store_unlock_controls()
end
function store_vehicle_switch_to_garage()
local store_logo = Vdo_base_object:new("rj_logo", 0, Store_vehicle_doc_handle)
local store_vehicle_move_list_anim = Vdo_anim_object:new("store_vehicle_move_list_anim", 0, Store_common_doc_handle)
local store_vehicle_list_twn = Vdo_tween_object:new("store_vehicle_list_twn", store_vehicle_move_list_anim.handle)
bg_saints_show(true)
store_vehicle_list_twn:set_property("end_value", 0, 0)
store_logo:set_visible(false)
Store_header:reformat_and_resize(true)
Vehicle_stats:set_visible(false)
store_vehicle_move_list_anim:play(0)
store_vehicle_mode_set_init()
end
function store_vehicle_switch_to_store()
local store_logo = Vdo_base_object:new("rj_logo", 0, Store_vehicle_doc_handle)
local store_vehicle_move_list_anim = Vdo_anim_object:new("store_vehicle_move_list_anim", 0, Store_common_doc_handle)
local store_vehicle_list_twn = Vdo_tween_object:new("store_vehicle_list_twn", store_vehicle_move_list_anim.handle)
store_vehicle_list_twn:set_property("end_value", 0, 0)
store_logo:set_visible(true)
Store_header:reformat_and_resize(false)
Vehicle_stats:set_visible(false)
store_vehicle_move_list_anim:play(0)
store_vehicle_mode_set_init()
end
function store_vehicle_play_exit_anim()
if Store_vehicle_loaded_from_crib and Returning_to_crib then
-- done immediately & bg_saints is full screen until after teleport return to crib
store_unload_doc()
else
-- exit with vehicle or exit to garage desk
--[[
local anim_out = Vdo_anim_object:new("rim_jobs_anim_out", 0, Store_vehicle_doc_handle)
local end_event_twn = Vdo_tween_object:new("rim_jobs_end_event", anim_out.handle)
end_event_twn:set_end_event("store_unload_doc")
anim_out:play(0)
store_common_play_anim_out()]]
end
end
function store_unload_doc()
vint_document_unload()
end
function store_vehicle_debug_hide_toggle()
local grp = vint_object_find("non_bg_grp")
local visible = vint_get_property(grp, "visible")
vint_set_property(grp, "visible", not visible)
Active_list:set_visible(not visible)
Store_common_hint_bar:set_visible(not visible)
Store_common_rotate_hint:set_visible(not visible)
Store_header:set_visible(not visible)
end
-- =====================================
-- Mouse Specific Functions
-- =====================================
function store_vehicle_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_vehicle_mouse_click(event, target_handle)
local hint_index = Store_common_hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
if Current_tier == MENU_TIER then
-- If a popup is active, don't try to exit (to crib or switch modes)
if Store_common_popup:get_visible() then
if Store_common_popup.callback_action ~= nil then
--Hacky hack so we can easily go from a string to a function call.
thread_new(Store_common_popup.callback_action, "back")
end
else
store_common_button_b()
end
elseif Current_tier == COLOR_TIER then
store_vehicle_color_selected("back")
elseif Current_tier == PALETTE_TIER then
store_vehicle_palette_selected("back")
elseif Current_tier == TIRE_TIER then
store_vehicle_tire_selected("back")
elseif Current_tier == RIM_TIER then
store_vehicle_rim_selected("back")
end
end
end
function store_vehicle_mouse_move(event, target_handle)
vint_set_mouse_cursor("")
store_common_mouse_zoom(0.0)
Store_common_hint_bar:set_highlight(0)
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)
end
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)
-- If the item has a callback for navigation, do it (such as putting clothes on)
local data_item = Active_list:return_selected_data()
if data_item.on_nav ~= nil then
data_item.on_nav(data_item)
end
return
end
end
function store_vehicle_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines)
if scroll_lines ~= 0 then
if Store_common_color_grid.bg.handle == target_handle then
Store_common_color_grid:scroll_list(scroll_lines * -1)
end
end
end
function store_vehicle_mouse_drag(event, target_handle, mouse_x, mouse_y)
if Store_common_color_grid.scrollbar.tab_grp.handle == target_handle then
local new_start_index = Store_common_color_grid.scrollbar:drag_scrolltab(mouse_y, Store_common_color_grid.rows - (Store_common_color_grid.max_height - 1))
Store_common_color_grid:scroll_list(0, new_start_index)
end
end
function store_vehicle_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
if Store_common_color_grid.scrollbar.tab_grp.handle == target_handle then
local start_row = Store_common_color_grid:get_visible_rows()
Store_common_color_grid.scrollbar:release_scrolltab(start_row, Store_common_color_grid.rows - (Store_common_color_grid.max_height - 1))
Store_common_color_grid:update_mouse_inputs()
end
end
function store_vehicle_background_hide_vehicle(hide)
local rim_jobs_grp = vint_object_find("rim_jobs_grp", 0, Store_vehicle_doc_handle)
local visible = not hide
vint_set_property(rim_jobs_grp, "background", visible)
bg_saints_set_background(visible)
end
function store_lock_controls()
Input_tracker:subscribe(false)
store_vehicle_enable_mouse(false)
end
function store_unlock_controls()
Input_tracker:subscribe(true)
store_vehicle_enable_mouse(true)
end
function garage_vehicle_load_completed(vehicle_logo_name)
if store_vehicle_get_state() == MODE_VCUST then
ui_audio_post_event("rim_job_camera_zoom")
end
local vehicle_logo_h = vint_object_find("vehicle_logo", 0, Store_vehicle_doc_handle)
-- Display a new vehicle logo
if store_vehicle_get_state() == MODE_GARAGE then
if Store_vehicle_current_logo ~= vehicle_logo_name then
if vehicle_logo_name == "__unloaded" or vehicle_logo_name == 0 or vehicle_logo_name == "" then
vint_set_property(vehicle_logo_h, "visible", false)
else
game_peg_unload(Store_vehicle_current_logo)
Store_vehicle_current_logo = vehicle_logo_name
-- Load vehicle logo peg
game_peg_load_with_cb("garage_set_vehicle_logo", 1, vehicle_logo_name)
end
else
vint_set_property(vehicle_logo_h, "visible", true)
end
else
vint_set_property(vehicle_logo_h, "visible", false)
end
Store_common_spinner:set_visible(false)
store_unlock_controls()
end
function garage_set_vehicle_logo()
local vehicle_logo_h = vint_object_find("vehicle_logo", 0, Store_vehicle_doc_handle)
vint_set_property(vehicle_logo_h, "image", Store_vehicle_current_logo)
vint_set_property(vehicle_logo_h, "visible", true)
end
function garage_vehicle_load_begin()
Store_common_spinner:set_visible(true)
local vehicle_logo_h = vint_object_find("vehicle_logo", 0, Store_vehicle_doc_handle)
vint_set_property(vehicle_logo_h, "visible", false)
end
function store_vehicle_exit_begin_bg_clear()
-- start transitioning out background for non-crib exit
local anim_out = Vdo_anim_object:new("rim_jobs_anim_out", 0, Store_vehicle_doc_handle)
local rim_jobs_bg_anim = Vdo_anim_object:new("rim_jobs_bg_anim", 0, Store_vehicle_doc_handle)
local end_event_twn = Vdo_tween_object:new("rim_jobs_end_event", anim_out.handle)
ui_audio_post_event("UI_Store_Exit")
bg_saints_slide_out(1300)
end_event_twn:set_end_event("store_unload_doc")
anim_out:play(0)
rim_jobs_bg_anim:stop(0)
store_common_play_anim_out()
-- call store_vehicle_exit_bg_cleared() when this is complete
end