STORE_WEAPON_INVALID_INDEX = -1
STORE_WEAPON_INVALID_INDEX = -1
SCALE_FONT_STORE_WEAPON_LIST = 0.8
local STORE_WEAPON_RADIAL_CACHE_X = 345
local STORE_WEAPON_RADIAL_CACHE_SD_X = 285
local STORE_WEAPON_RADIAL_STORE_X = 345
local STORE_WEAPON_RADIAL_STORE_SD_X = 285
local STORE_WEAPON_STATS_GRP_X = 645
local STORE_WEAPON_STATS_GRP_SD_X = 526
local STORE_WEAPON_STATS_GRP_Y = 230
local STORE_WEAPON_STATS_GRP_MAX = 393
--Keep track of current costume name and description
local Current_costume_name_crc = nil
local Current_costume_desc_crc = nil
local Current_skin_name_crc = nil
local Store_weapon_default_crc = -1
--Were we forced out by taking damage rather than exiting by choice
--True until the player exits the store
local Store_weapon_forced_out = true
local Store_weapon_skin_was_previewed = false
--Used in store_weapon_costume_add_items() to pick out the info we need
--this function isn't called in a loop, so we need globals
local Store_weapon_parsed_costume_name_crc
local Store_weapon_parsed_costume_desc_crc
--Need lighter color for weapon info in crib mode
local STORE_CRIB_TITLE_COLOR = {R = 167/255, G = 191/255, B = 216/255}
local STORE_CRIB_DESC_COLOR = {R = 32/255, G = 32/255, B = 32/255}
local STORE_WEAPON_CUSTOMIZE_OPTION = 1
Store_weapon_doc_handle = -1
--Thread id for dumping pause map and loading store weapon pegs
local Store_weapon_pegs_thread_id = -1
local Store_weapon_radial
local Hint_bar_mouse_input_tracker
local Radial_mouse_input_tracker
local Game_platform
local Store_weapon_in_mission = false
local Weapon_gsi_is_updated = false
local Upgrade_gsi_is_updated = false
local MENU_TIER = 1
local RADIAL_TIER = 2
local WEAPON_TIER = 3
local LEVEL_TIER = 4
local GRENADE_UPGRADE_TIER = 5
local Current_tier = MENU_TIER
local Skip_next_populate = false
local Restore_weapon_radial_inputs = false
local Current_slot = -1
local Prev_slot = -1
local Radial_cache_x = STORE_WEAPON_RADIAL_CACHE_X
local Radial_store_x = STORE_WEAPON_RADIAL_STORE_X
local Radial_y = 0
-- Hint bar and store header vdo's.
local Store_logo1
local Store_logo2
local Not_popup_grp
local Reward_image
local Weapon_bg_grp
local Weapon_stats_grp
local Store_weapon_not_bg_grp
local Slot_stats_grp
local Weapons_owned = {}
local Weapons_available = {}
local Stats_initialized = false
local Weapon_store_highlight_color = {}
local Store_weapon_new_image = -1
local Store_weapon_loading_img = nil
local Store_weapon_unload_img = nil
local Store_weapon_img_update_thread = -1
-- We used this as a reference to the current submenu we are building.
local Store_weapon_building_menu = {}
local Store_weapon_loaded_from_crib = false
-- Determines if we're in "store" or "cache" mode.
local Store_weapon_is_cache = false
-- Stores data regarding ammo that is not stored in the radial menu vdo.
local Store_weapon_ammo_info = {}
local Store_weapon_thrown_ammo_info = {}
-- Info on weapon that may be purchaed.
local Store_weapon_current_info = {}
-- Used to flag we are leaving UI because the player entered the cache with no weapons
local Store_weapon_cache_no_weapons = false
-- True if we're currently waiting on a weapon swap/load
local Store_weapon_is_loading = false
-- Save the previous grid index to prevent mouse move triggering every frame
local Old_index = 0
-- Store off costume id
local Costume_id = 0
-- Used to track weapon radial input and state
Store_weapon_inventory = {
stick_mag = 0,
is_pressed = false,
selected_cb = nil,
nav_cb = nil
}
-- local Hint_bar_rotate
-- Stores data regarding the grid selector for weapons
local Weapon_grid_data = {}
-- Index of the starting weapon grid choice to highlight.
local Weapon_grid_idx = 1
local Store_weapon_tool_mode = false
-- Menu category enums
local STORE_WEAPON_CATEGORY_AMMO = 2
local STORE_WEAPON_CATEGORY_UPGRADES = 3
local STORE_WEAPON_CATEGORY_WEAPON_CACHE = 4
-- Start on the first selection
local Store_weapon_menu_category = STORE_WEAPON_CATEGORY_AMMO
-- Used to find where we are in the flow
local STORE_WEAPON_LEVEL_MAIN = 1
local STORE_WEAPON_LEVEL_GRID = 2
local STORE_WEAPON_LEVEL_UPGRADE = 3
local STORE_WEAPON_LEVEL_COSTUME = 4
local Store_weapon_menu_level = STORE_WEAPON_LEVEL_MAIN
local Store_weapon_categories = {
[1] = { label = "WPN_STORE_MELEE_TITLE", category = "melee", info = {} },
[2] = { label = "WPN_STORE_PISTOL_TITLE", category = "pistol", info = {} },
[3] = { label = "WPN_STORE_SMG_TITLE", category = "smg", info = {} },
[4] = { label = "WPN_STORE_SHOTGUN_TITLE", category = "shotgun", info = {} },
[5] = { label = "WPN_STORE_RIFLE_TITLE", category = "rifle", info = {} },
[6] = { label = "WPN_STORE_EXPLOSIVE_TITLE", category = "explosive", info = {} },
[7] = { label = "WPN_STORE_SPECIAL_TITLE", category = "special", info = {} },
[8] = { label = "WPN_STORE_THROWN_TITLE", category = "thrown", info = {} },
[9] = { label = "WPN_STORE_THROWN_TITLE", category = "thrown", info = {} },
[10] = { label = "WPN_STORE_THROWN_TITLE", category = "thrown", info = {} },
[11] = { label = "WPN_STORE_THROWN_TITLE", category = "thrown", info = {} },
}
local Store_weapon_alien = {
[1] = {label = "ui_hud_inv_35_abduction"},
[2] = {label = "ui_hud_inv_35_black_hole"},
[3] = {label = "ui_hud_inv_35_disintegrator"},
[4] = {label = "ui_hud_inv_35_glitch"},
[5] = {label = "ui_hud_inv_35_laser_mg"},
[6] = {label = "ui_hud_inv_35_minefield"},
[7] = {label = "ui_hud_inv_35_plasma"},
[8] = {label = "ui_hud_inv_35_shrink"},
[9] = {label = "ui_hud_inv_35_tentacle"},
}
local Store_weapon_always_loaded_icons = {
[1] = "ui_hud_inv_35_abduction",
[2] = "ui_hud_inv_35_black_hole",
[3] = "ui_hud_inv_35_disintegrator",
[4] = "ui_hud_inv_35_glitch",
[5] = "ui_hud_inv_35_laser_mg",
[6] = "ui_hud_inv_35_minefield",
[7] = "ui_hud_inv_35_plasma",
[8] = "ui_hud_inv_35_shrink",
[9] = "ui_hud_inv_35_tentacle",
[10] = "ui_hud_inv_spc_dubstep",
[11] = "ui_hud_inv_35_probe",
[12] = "ui_hud_inv_s_spc_merica",
[13] = "ui_hud_inv_s_spc_murder_laser",
[14] = "ui_hud_inv_35_locust",
[15] = "ui_hud_inv_exp_satchels",
[16] = "ui_hud_inv_melee_killbane",
[17] = "ui_hud_inv_s_exp_murder_mine",
[18] = "ui_hud_inv_spc_airstrike",
[19] = "ui_hud_inv_spc_chumgun",
[20] = "ui_hud_inv_spc_genkigun",
[21] = "ui_hud_inv_brute_flame",
[22] = "ui_hud_inv_pick_luchadore_gl",
[23] = "ui_hud_inv_pick_brute_mg",
[24] = "ui_hud_inv_spc_sonicgun",
[25] = "ui_hud_inv_dlc_brute_mg",
[26] = "ui_hud_inv_dlc_brute_flame",
[27] = "ui_hud_inv_dlc_dubstep",
[28] = "ui_hud_inv_s_dlc_hillbilly_pg",
[29] = "ui_hud_inv_dlc_knifelauncher",
[30] = "ui_hud_inv_dlc_bb_gun",
[31] = "ui_hud_inv_s_dlc_dub_xmas",
[32] = "ui_hud_inv_dlc_polar",
[33] = "ui_hud_inv_tf2_flame",
[34] = "ui_hud_inv_tf2_rainblower",
[35] = "ui_hud_inv_tf2_rocket",
[36] = "ui_hud_inv_dlc_bb_gun",
}
local Notoriety_level_clear_cost_data = {}
-- Removing these weapons from the alien category because they use ammo now
--"ui_hud_inv_35_laser_smg"
--"ui_hud_inv_35_laser_rifle"
--"ui_hud_inv_35_railgun"
--"ui_hud_inv_35_revolver"
--"ui_hud_inv_35_locust"
--[[Weapon_data = {
[WEAPON_1] = {
title = ".45 SHEPERD",
id = 1,
attributes = {
[ATTRIBUTE_1] = {
label = "AMMO CAPACITY"
max_levels = 6
levels_owned = 1
level_data = {
[LEVEL_1] = {
desc = "Increase ammo capcity by 20%",
price = 1000,
},
[LEVEL_2] = {
desc = "Increase ammo capcity by 30%",
price = 2000,
},
[LEVEL_3] = {
desc = "Increase ammo capcity by 40%",
price = 3000,
},
[LEVEL_4] = {
desc = "Increase ammo capcity by 50%",
price = 4000,
},
[LEVEL_5] = {
desc = "Increase ammo capcity by 60%",
price = 5000,
},
[LEVEL_6] = {
desc = "Increase ammo capcity by 70%",
price = 6000,
},
}
},
[ATTRIBUTE_2] = {
label = "RELOAD SPEED"
max_levels = 4
levels_owned = 2
level_data = {
[LEVEL_1] = {
desc = "Increase reload speed by 20%",
price = 1000,
},
[LEVEL_2] = {
desc = "Increase reload speed by 30%",
price = 2000,
},
[LEVEL_3] = {
desc = "Increase reload speed by 40%",
price = 3000,
},
[LEVEL_4] = {
desc = "Increase reload speed by 50%",
price = 4000,
},
}
},
}
}
}]]
---------------------------------------------------------------------------
-- Initialize Weapon Store
---------------------------------------------------------------------------
function store_weapon_init()
Game_platform = game_get_platform()
Store_weapon_loaded_from_crib = store_common_crib_is_loaded()
-- If we're in the crib, we're only doing cache (not store).
Store_weapon_is_cache = Store_weapon_loaded_from_crib
Store_weapon_doc_handle = vint_document_find("store_weapon")
Store_weapon_radial = Vdo_weapon_radial:new("weapon_radial", 0, Store_weapon_doc_handle)
Store_weapon_radial:set_visible(false)
Store_weapon_radial:cache_mode_enable(Store_weapon_is_cache)
--No grenades in SR4, just powers... hide the dpad in the store.
Store_weapon_radial:show_dpad_menu(false)
--Get y of weapon radial in vint doc
local radial_x, new_y = Store_weapon_radial:get_anchor()
Radial_y = new_y
if Store_weapon_loaded_from_crib then
Weapon_store_highlight_color = COLOR_STORE_CRIB_PRIMARY
else
Weapon_store_highlight_color = COLOR_STORE_WEAPON_PRIMARY
end
-- Iniitialize weapon store image...
Reward_image = Vdo_bitmap_viewer:new("reward_image", 0, Store_weapon_doc_handle)
-- Hide description
Reward_image:set_description(" ", nil)
Reward_image:set_visible(false)
Store_common_current_highlight_color = Weapon_store_highlight_color
Store_weapon_radial:set_highlight_color(Weapon_store_highlight_color)
Store_weapon_not_bg_grp = Vdo_base_object:new("weapon_not_bg_grp", 0, Store_weapon_doc_handle)
-- This turns on "store mode" for weapon radial, which makes changes like shows hint buttons and disables choices.
Store_weapon_radial:store_mode_enable(true)
-- Set up some callbacks for the common store script
Store_common_populate_list_cb = store_weapon_populate_list
Store_common_exit_cb = store_weapon_exit
-- Initialize mouse input trackers and create mouse tracker for the hint bar
if Game_platform == "PC" then
Mouse_input_tracker:subscribe(false)
Hint_bar_mouse_input_tracker = Vdo_input_tracker:new()
Radial_mouse_input_tracker = Vdo_input_tracker:new()
end
-- Subscribe to the button presses we need, Input_tracker is created in store_common.lua
store_lock_controls()
--Setup Button Hints
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
--{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"},
--{CTRL_BUTTON_DPAD, "STORE_WEAPON_NAVIGATE"},
}
Store_common_hint_bar:set_hints(hint_data)
Store_common_hint_bar:set_visible(true)
-- SEH: 6/28/11: cut zoom/rotate
-- Hint_bar_rotate = Vdo_hint_bar:new("hint_rotate", 0, Store_common_doc_handle)
-- local hint_rotate_data = {
-- {CTRL_BUTTON_RS, "CONTROL_ROTATE"},
-- }
-- Hint_bar_rotate:set_hints(hint_rotate_data)
-- if game_is_active_input_gamepad() == true then
-- Hint_bar_rotate:set_visible(true)
-- end
Store_header:set_visible(true)
-- Everything that is not in the popup so we can fade it when the popup is active
Not_popup_grp = Vdo_base_object:new("not_popup_grp", 0, Store_common_doc_handle)
-- Setup purchase popup
Store_common_popup:set_visible(false)
Store_common_popup:set_size(STORE_COMMON_LIST_SIZE, (LIST_BUTTON_HEIGHT * 5) + (LIST_BUTTON_SPACE * 5))
-- Setup Color grid
Store_common_color_grid:set_visible(false)
Store_common_color_grid:set_ui_screen("store_weapon")
-- Setup weapon stats
Weapon_stats_grp = Vdo_base_object:new("weapon_stats_grp", 0, Store_weapon_doc_handle)
Weapon_stats_grp:set_visible(false)
-- Setup slot stats
Slot_stats_grp = Vdo_base_object:new("slot_stats_grp", 0, Store_weapon_doc_handle)
Slot_stats_grp:set_visible(false)
-- don't do anything else when we're in customization camera tool mode
if vcust_is_camera_tool_mode() then
Store_header:set_visible(false)
-- make background so it is behind the weapon
--Weapon_bg_grp = Vdo_base_object:new("bg_grp", 0, Store_weapon_doc_handle)
--Weapon_bg_grp:set_property("background", true)
-- draw bogus weapon info
local weapon_title = Vdo_base_object:new("weapon_title", 0, Store_weapon_doc_handle)
local weapon_level = Vdo_base_object:new("weapon_level", 0, Store_weapon_doc_handle)
-- Display weapon stats
weapon_title:set_text("BOGUS WEAPON NAME")
local insert = { [0] = 1 }
local body = vint_insert_values_in_string("STORE_WEAPON_LEVEL", insert)
weapon_level:set_text("Weapon description")
Weapon_stats_grp:set_visible(true)
Store_weapon_tool_mode = true
return
end
if vint_is_std_res() then
Radial_cache_x = STORE_WEAPON_RADIAL_CACHE_SD_X
Radial_store_x = STORE_WEAPON_RADIAL_STORE_SD_X
end
if Store_weapon_loaded_from_crib then
-- Get reference to the weapon store background for future use
Weapon_bg_grp = Vdo_base_object:new("bg_grp", 0, Store_weapon_doc_handle)
-- From the crib, we just go straight to the weapon radial
Active_list:set_visible(false)
-- Set the hint based on the platform
local hint_data = {}
if game_get_platform() == "PC" then
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
else
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"},
}
end
Store_common_hint_bar:set_hints(hint_data)
if Hint_bar_mouse_input_tracker ~= nil then
Store_common_hint_bar:add_mouse_inputs("store_weapon", Hint_bar_mouse_input_tracker)
Hint_bar_mouse_input_tracker:subscribe(true)
end
-- Hide separate bullet tile grp
local bullet_tile_grp_h = vint_object_find("bullet_tile_grp", 0, Store_weapon_doc_handle)
vint_set_property(bullet_tile_grp_h, "visible", false)
-- Hide vignette
local vignette_grp_h = vint_object_find("vignette_grp", 0, Store_weapon_doc_handle)
vint_set_property(vignette_grp_h, "visible", false)
-- Hide weapon store background since we use the saints background in crib
local weapon_store_bg_grp = Vdo_base_object:new("bg_texture_group", 0, Store_weapon_doc_handle)
weapon_store_bg_grp:set_visible(false)
local weapon_logo_grp = Vdo_base_object:new("logo_grp", 0, Store_weapon_doc_handle)
weapon_logo_grp:set_visible(false)
local red_bar_h = vint_object_find("red_bar",0,Store_weapon_doc_handle)
local grey = 30/255
vint_set_property(red_bar_h,"tint",grey,grey,grey)
Weapon_bg_grp:set_property("visible", false)
local header_txt = Vdo_base_object:new("header_txt", 0, Store_weapon_doc_handle)
header_txt:set_color(Weapon_store_highlight_color.R,Weapon_store_highlight_color.G,Weapon_store_highlight_color.B)
local weapon_title = Vdo_base_object:new("weapon_title", 0, Store_weapon_doc_handle)
weapon_title:set_color(Weapon_store_highlight_color.R,Weapon_store_highlight_color.G,Weapon_store_highlight_color.B)
local texture_bg = vint_object_find("bg_texture_grp", 0, Store_weapon_doc_handle)
vint_set_property(texture_bg, "background", true)
vint_set_property(texture_bg, "visible", false)
Store_common_color_grid:set_highlight_color(COLOR_STORE_CRIB_PRIMARY)
Store_header:push_title(nil, "WPNSTOR_TITLE_WEAPON_CACHE")
Store_header:enable_price_respect(false)
store_weapon_cover_weapon(true)
local mask_h = vint_object_find("mask",0,Store_weapon_doc_handle)
vint_set_property(mask_h,"scale",150,71)
local store_main_grp = Vdo_base_object:new("store_main_grp", 0, Store_common_doc_handle)
store_main_grp:set_anchor(0,0)
bg_saints_set_type(BG_TYPE_CRIB,true,1280)
local anim_in = Vdo_anim_object:new("store_weapon_crib_anim_in", 0, Store_weapon_doc_handle)
local store_intro_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_intro_anim.handle)
end_event_twn:set_end_event("store_weapon_intro_anim_complete")
vint_apply_start_values(store_intro_anim.handle)
vint_apply_start_values(anim_in.handle)
-- Start animation now
anim_in:play(0)
store_intro_anim:play(0)
Current_tier = RADIAL_TIER
else
--Populate store common list with store weapon main menu data
Menu_data = {
on_cancel = store_weapon_cancel_radial,
[1] = { label = "STORE_WEAPON_WIPE_NOTORIETY", type = TYPE_BUTTON, on_select = store_weapon_wipe_notoriety, on_nav = store_weapon_main_menu_nav },
[2] = { label = "STORE_WEAPON_AMMO", type = TYPE_BUTTON, on_select = store_weapon_ammo_open_radial, on_nav = store_weapon_main_menu_nav },
[3] = { label = "STORE_WEAPON_BUY_UPGRADE", type = TYPE_BUTTON, on_select = store_weapon_purchase_open_radial, on_nav = store_weapon_main_menu_nav },
}
--if store_weapon_is_tutorial_mode() == false then
Menu_data[#Menu_data + 1] = { label = "STORE_WEAPON_CACHE", type = TYPE_BUTTON, on_select = store_weapon_cache_open_radial }
--end
Menu_data[#Menu_data + 1] = { label = "STORE_EXIT", type = TYPE_BUTTON, on_select = store_weapon_exit }
local logo_grp_h = vint_object_find("logo_grp", 0, Store_weapon_doc_handle)
-- Are we in mission mm_1_1? Show GSI and fade out logo_grp
if store_weapon_is_tutorial_mode() == true then
Store_weapon_in_mission = true
-- Does the player have any weapons? If yes, then skip to buy upgrade objective
--if store_weapon_any_weapon_equipped() == true then
Store_common_gsi:update("MM_1_1_OBJ_PURCHASE_AN_UPGRADE", "ui_target_icon_use")
Weapon_gsi_is_updated = true
--else
-- Store_common_gsi:update("MM_1_1_OBJ_PURCHASE_A_WEAPON", "ui_target_icon_use")
--end
vint_set_property(logo_grp_h, "alpha", .35)
end
local logo_intro_anim = Vdo_anim_object:new("store_weapon_logo_intro", 0, Store_weapon_doc_handle)
local store_intro_anim = Vdo_anim_object:new("store_common_in_anim",0, Store_common_doc_handle)
local bg_anim = Vdo_anim_object:new("store_weapon_anim_in",0, Store_weapon_doc_handle)
local end_event_twn = Vdo_tween_object:new("end_event_twn", store_intro_anim.handle)
local tile_anim = Vdo_anim_object:new("store_weapon_bullet_tile_anim",0, Store_weapon_doc_handle)
end_event_twn:set_end_event("store_weapon_intro_anim_complete")
vint_apply_start_values(logo_intro_anim.handle)
vint_apply_start_values(store_intro_anim.handle)
vint_apply_start_values(bg_anim.handle)
logo_intro_anim:play(0)
store_intro_anim:play(0)
bg_anim:play(0)
tile_anim:play(0)
ui_audio_post_event("enter_friendly_fire")
-- Set Store Header colors
Store_header:set_color(Weapon_store_highlight_color, COLOR_STORE_WEAPON_SECONDARY, COLOR_STORE_WEAPON_TERTIARY)
Active_list:set_highlight_color(Weapon_store_highlight_color, COLOR_STORE_WEAPON_SECONDARY)
Store_common_popup:set_color(Weapon_store_highlight_color, COLOR_STORE_WEAPON_SECONDARY, COLOR_STORE_WEAPON_TERTIARY)
-- Pass the table data to the megalist vdo.
store_weapon_populate_list(Menu_data, 1)
Active_list:set_visible(true)
-- Get reference to the weapon store background for future use
Weapon_bg_grp = Vdo_base_object:new("bg_black", 0, Store_weapon_doc_handle)
Current_tier = MENU_TIER
store_weapon_cover_weapon(false)
Notoriety_level_clear_cost_data = {} -- reset the cost data
vint_dataresponder_request("store_weapon_populate_notoriety", "store_weapon_notoriety_cost_update", 0)
local player_notoriety_level = vint_get_player_notoriety();
if player_notoriety_level > 6 then
player_notoriety_level = 6
end
if player_notoriety_level > 0 then
Store_header:set_price(Notoriety_level_clear_cost_data[player_notoriety_level].cost)
else
Store_header:set_price(nil)
end
end
-- Subscribe to data group that will give us the currently equipped inventory
vint_datagroup_add_subscription("sr2_local_player_inventory", "update", "store_weapon_radial_update")
vint_datagroup_add_subscription("sr2_local_player_inventory", "insert", "store_weapon_radial_update")
--Dump the pause map to make room for store images
Store_weapon_pegs_thread_id = thread_new("store_weapon_load_pegs")
--Set global flag if store weapon is loaded.
Store_weapon_is_loaded = true
end
-------------------------------------------------------------------------------
-- Dump pause map and load store weapon pegs
--
function store_weapon_load_pegs()
pause_map_dump()
game_peg_load_with_cb("store_weapon_load_peg_complete", 2, "ui_bms_store_weapon", "ui_bms_store_weapon_costumes")
end
-------------------------------------------------------------------------------
-- Store weapon pegs are loaded
--
function store_weapon_load_peg_complete()
end
-- Cleanup function called on document unload.
--
function store_weapon_cleanup()
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:remove_all()
end
if Radial_mouse_input_tracker ~= nil then
Radial_mouse_input_tracker:remove_all()
end
if Store_weapon_tool_mode == false then
if Store_weapon_loaded_from_crib == false then
-- Nuke all button subscriptions
store_lock_controls()
end
end
if Store_weapon_inventory.thread ~= nil then
thread_kill(Store_weapon_inventory.thread)
Store_weapon_inventory.thread = nil
end
Store_weapon_radial:cleanup()
-- 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()
-- If we were forced out call preview one last time to make sure the equipped weapon has the correct skin
if Store_weapon_forced_out == true and Store_weapon_skin_was_previewed == true and Weapon_grid_data.category ~= nil then
local weapon_info = Weapon_grid_data[Weapon_grid_idx]
--store_weapon_change_weapon(Weapon_grid_data.category, weapon_info.id, weapon_info.dual_wield, Store_weapon_is_cache, nil, weapon_info.costume_id, weapon_info.skin_id, true)
--store_weapon_set_costume(Weapon_grid_data.category, weapon_info.id, weapon_info.costume_id)
end
-- clean out end events
local store_intro_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_intro_anim.handle)
end_event_twn:set_end_event(nil)
-- clean out radial inputs
store_weapon_lock_radial()
local current_image = Reward_image:get_image()
if current_image ~= nil then
game_peg_unload(current_image)
end
if Store_weapon_unload_img ~= nil then
game_peg_unload(Store_weapon_unload_img)
end
if Store_weapon_loading_img ~= nil then
game_peg_unload(Store_weapon_loading_img)
end
-- Unload store weapon pegs and reload pause map
game_peg_unload("ui_bms_store_weapon")
game_peg_unload("ui_bms_store_weapon_costumes")
pause_map_restore()
-- Kill peg load thread
thread_kill(Store_weapon_pegs_thread_id)
Store_weapon_pegs_thread_id = -1
--Set global store weapon is no longer loaded...
Store_weapon_is_loaded = false
end
function store_weapon_intro_anim_complete()
--Turn the lights on
store_weapon_enable_lights(true)
store_weapon_process_post_bg_covered()
store_common_bg_anim_complete()
if Store_weapon_loaded_from_crib == false then
store_unlock_controls()
else
-- Don't unlock radial input if we are showing the "you don't own any weapons" popup
if Store_weapon_cache_no_weapons == false then
store_weapon_cache_open_radial()
store_weapon_unlock_radial()
else
Store_weapon_cache_no_weapons = false
end
end
end
function store_lock_controls()
Input_tracker:subscribe(false)
store_weapon_enable_mouse(false)
end
function store_unlock_controls()
Input_tracker:subscribe(true)
store_weapon_enable_mouse(true)
end
function store_weapon_lock_radial()
--lock all the radial input
if Store_weapon_inventory.subs_x ~= nil then
vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_x)
vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_y)
vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_up)
vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_right)
vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_down)
vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_left)
if Store_weapon_inventory.extra_buttons ~= nil then
for idx, val in pairs(Store_weapon_inventory.extra_buttons) do
vint_unsubscribe_to_input_event(val)
end
end
end
end
function store_weapon_unlock_radial()
Store_weapon_inventory.extra_buttons = {
vint_subscribe_to_input_event("select", "store_weapon_inventory_input"),
vint_subscribe_to_input_event("back", "store_weapon_inventory_input"),
vint_subscribe_to_input_event("map", "store_weapon_inventory_input"),
vint_subscribe_to_input_event("pause", "store_weapon_inventory_input"),
}
Store_weapon_inventory.subs_x = vint_subscribe_to_raw_input("inventory_x", "store_weapon_inventory_input")
Store_weapon_inventory.subs_y = vint_subscribe_to_raw_input("inventory_y", "store_weapon_inventory_input")
Store_weapon_inventory.subs_up = vint_subscribe_to_raw_input("inventory_up", "store_weapon_inventory_input")
Store_weapon_inventory.subs_right = vint_subscribe_to_raw_input("inventory_right", "store_weapon_inventory_input")
Store_weapon_inventory.subs_down = vint_subscribe_to_raw_input("inventory_down", "store_weapon_inventory_input")
Store_weapon_inventory.subs_left = vint_subscribe_to_raw_input("inventory_left", "store_weapon_inventory_input")
end
function store_weapon_exit()
-- no confirmation needed if we're just going back to the crib menu
if Store_weapon_loaded_from_crib then
game_UI_audio_play("UI_Main_Menu_Nav_Back")
store_lock_controls()
store_weapon_lock_radial()
-- make background so player 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 weapon_back_out_anim = Vdo_anim_object:new("store_weapon_crib_anim_out",0, Store_weapon_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_weapon_crib_exit")
back_out_anim:play(0)
weapon_back_out_anim:play(0)
else
Store_common_popup:populate_list(Yes_no_choices, 2, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("MENU_TITLE_WARNING")
if Store_weapon_is_cache then
Store_common_popup:set_text("WPN_STORE_EXIT_PROMPT")
else
Store_common_popup:set_text("STORE_EXIT_WARNING_BODY")
end
Store_common_popup:nav_enable(true, "store_weapon_exit_final", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
game_UI_audio_play("UI_HUD_HELP")
store_weapon_enable_mouse(false)
end
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:subscribe(false)
end
end
function store_weapon_crib_exit()
--Player exiting by choice, was not forced out from damage
Store_weapon_forced_out = false
-- called when we slide out to the crib
pop_screen()
end
function store_weapon_exit_final(event)
Store_common_popup:nav_enable(false, nil, nil)
-- The user hit the B button and is exiting
-- This is redundant to selecting "No" in the list
if event == "back" then
game_UI_audio_play("UI_Main_Menu_Nav_Back")
Not_popup_grp:set_alpha(1)
Store_weapon_not_bg_grp:set_alpha(1)
store_weapon_enable_mouse(true)
return
end
game_UI_audio_play("UI_Main_Menu_Select")
-- Did we select yes? This assumes yes is the first item
if Store_common_popup:get_selected_data() ~= 1 then
Not_popup_grp:set_alpha(1)
Store_weapon_not_bg_grp:set_alpha(1)
store_weapon_enable_mouse(true)
return
end
ui_audio_post_event("UI_Store_Exit")
store_lock_controls()
Not_popup_grp:set_alpha(0)
Store_weapon_not_bg_grp:set_alpha(0)
--Turn the lights off
store_weapon_enable_lights(false)
--Player exiting by choice, was not forced out from damage
Store_weapon_forced_out = false
-- exit the interface
local anim_out = Vdo_anim_object:new("store_weapon_anim_out", 0, Store_weapon_doc_handle)
anim_out:play(0)
pop_screen()
end
function store_weapon_no_weapons()
Store_common_popup:nav_enable(false, nil, nil)
game_UI_audio_play("UI_Main_Menu_Select")
Not_popup_grp:set_alpha(1)
Store_weapon_not_bg_grp:set_alpha(1)
Store_common_popup:set_visible(false)
if Store_weapon_loaded_from_crib then
store_weapon_lock_radial()
else
store_weapon_cancel_radial()
end
if Store_weapon_loaded_from_crib then
-- exit the interface
store_weapon_tutorial_mode(false)
pop_screen()
end
end
-- Handles navigation of any popups
function store_weapon_popup_nav(event, value)
if event == "nav_up" then
Store_common_popup.list:move_cursor(-1)
elseif event == "nav_down" then
Store_common_popup.list:move_cursor(1)
elseif event == "mouse_move" then
-- value contains the target_handle in this case
local new_index = Store_common_popup.list:get_button_index(value)
if new_index ~= 0 then
Store_common_popup.list:set_selection(new_index)
Store_common_popup.list:move_cursor(0, true)
end
else
--do nothing
end
end
-- Handle navigation of the grid
function store_weapon_grid_nav(event, value)
-- Reset all highlights
Store_common_hint_bar:set_highlight(0)
local prev_index = Store_common_color_grid:return_selected_index()
if event == "nav_up" then
Store_common_color_grid:move_cursor(-2)
elseif event == "nav_down" then
Store_common_color_grid:move_cursor(2)
elseif event == "nav_left" then
Store_common_color_grid:move_cursor(-1)
elseif event == "nav_right" then
Store_common_color_grid:move_cursor(1)
elseif event == "mouse_move" then
-- value contains the target_handle in this case
local new_index = Store_common_color_grid:get_data_index(value)
if new_index ~= 0 then
if Old_index ~= new_index then
Store_common_color_grid:set_selection(new_index)
Store_common_color_grid:move_cursor(0, false, false)
Old_index = new_index
end
end
else
--do nothing
end
-- Get the currently selected weapon info
local idx = Store_common_color_grid:return_selected_index()
-- if index hasn't changed, don't proceed
if idx == prev_index then
return
end
local weapon_info = Weapon_grid_data[idx]
if weapon_info ~= nil then
-- Preview the model of the selected weapon
store_weapon_change_weapon_preview(Weapon_grid_data.category, weapon_info.id, weapon_info.dual_wield, Store_weapon_is_cache, nil, weapon_info.costume_id, weapon_info.skin_id, weapon_info.store_name_crc)
Weapon_grid_idx = idx
--Update current costume name and description
Current_costume_name_crc = weapon_info.costume_name_crc
Current_costume_desc_crc = weapon_info.costume_desc_crc
Current_skin_name_crc = weapon_info.skin_name_crc
store_weapon_price_update()
Store_header:set_respect(nil)
end
end
function store_weapon_fail_msg(event)
Store_common_popup:nav_enable(false, nil, nil)
game_UI_audio_play("UI_Main_Menu_Select")
Not_popup_grp:set_alpha(1)
Store_weapon_not_bg_grp:set_alpha(1)
-- Enable the active list or weapon radial if it's showing
if Current_tier ~= RADIAL_TIER and Current_tier ~= WEAPON_TIER then
store_weapon_enable_mouse(true)
else
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:subscribe(true)
Radial_mouse_input_tracker:subscribe(true)
end
end
end
-------------------------------------------------------------------------------
-- Function store_weapon_populate_list()
--
-- Populate the megalist. Update Store_weapon_building_menu with new data
--
-- @param list_data -- data to display in the megalist
-- @param current_index -- current index to highlight
-- @param animate_list -- determines whether we should animate the list
--
-------------------------------------------------------------------------------
function store_weapon_populate_list(list_data, current_index, animate_list)
-- override the mega list width for standard def STORE_COMMON_LIST_SIZE
-- data, current_option, width, max_buttons, font_scale, force_width, animate_list
Active_list:set_scale_text_if_too_big(true)
Active_list:draw_items(list_data, current_index, STORE_COMMON_LIST_SIZE, 10, LIST_FONT_SCALE, false, animate_list)
-- Make sure our data matches what is sent to the megalist
Store_weapon_building_menu = list_data
-- Add mouse input subscriptions
if Mouse_input_tracker ~= 0 then
Hint_bar_mouse_input_tracker:remove_all()
Store_common_hint_bar:add_mouse_inputs("store_weapon", Hint_bar_mouse_input_tracker)
Mouse_input_tracker:remove_all()
Radial_mouse_input_tracker:remove_all()
Active_list:set_store("store_weapon")
Active_list:add_mouse_inputs("store_common", Mouse_input_tracker)
store_weapon_enable_mouse(true)
-- When we're coming back from the upgrade screen, adjust what gets mouse inputs (best way to override behavior that's due to store_common)
if Skip_next_populate == true then
Skip_next_populate = false
Mouse_input_tracker:subscribe(false)
Hint_bar_mouse_input_tracker:subscribe(true)
if Restore_weapon_radial_inputs then
Store_weapon_radial:add_mouse_inputs("store_weapon", Radial_mouse_input_tracker, 50)
Radial_mouse_input_tracker:subscribe(true)
end
end
Restore_weapon_radial_inputs = false
end
end
-- User is going back to top level menu
function store_weapon_cancel_radial()
Store_header:set_price(nil)
Store_header:pop_title()
store_weapon_close_radial()
game_UI_audio_play("UI_Main_Menu_Nav_Back")
-- Hide weapon and stats/description
store_weapon_cover_weapon(false)
--Weapon_stats_grp:set_visible(false)
-- Hide the weapon preview
store_weapon_hide_weapon()
Current_tier = MENU_TIER
--Save where we are in the flow
Store_weapon_menu_level = STORE_WEAPON_LEVEL_MAIN
end
-- Close the ammo purchasing interface
--
function store_weapon_close_radial()
-- Show megalist menu
Active_list:set_visible(true)
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
Store_common_hint_bar:set_hints(hint_data)
-- Hide radial and stop input/thread.
store_weapon_inventory_hide()
--Set the list data back to first level options
store_weapon_menu_data_reset()
Current_tier = MENU_TIER
end
-- Ammo purchasing ******************************************************************************************
-- Open the ammo purchasing radial menu.
--
function store_weapon_ammo_open_radial(menu_data)
Store_weapon_menu_category = STORE_WEAPON_CATEGORY_AMMO
Active_list:set_visible(false)
store_weapon_stats_update(1, false)
store_weapon_cover_weapon(true)
store_weapon_hide_weapon()
Store_weapon_is_cache = false
-- Set the callback to use when the user selects a cateogory from the radial menu
Store_weapon_inventory.selected_cb = store_weapon_ammo_purchase
Store_weapon_inventory.nav_cb = store_weapon_ammo_nav
Store_weapon_ammo_info = {}
Store_weapon_thrown_ammo_info = {}
vint_dataresponder_request("store_weapon_populate_ammo", "store_weapon_ammo_add_items", 0)
-- Disable first two slots that don't use ammo
Store_weapon_radial:slot_disable(0)
Store_weapon_radial:slot_disable(1)
--disable super powers slots
for i=8, 11 do
Store_weapon_radial:slot_disable(i)
end
--Hide grenades
Store_weapon_radial:show_dpad_menu(false)
--Position radial
Store_weapon_radial:set_anchor(Radial_store_x,Radial_y)
-- Disable any slots where we can't buy ammo
for slot_i = 2, 7 do
local ammo_info = store_weapon_ammo_find_by_id(slot_i)
if ammo_info == nil then
Store_weapon_radial:slot_disable(slot_i)
Store_weapon_radial:slot_show_ammo(slot_i, false)
else
Store_weapon_radial:slot_enable(slot_i)
Store_weapon_radial:slot_show_ammo(slot_i, true)
end
-- Disable alien weapon slots
for weapon_i = 1, #Store_weapon_alien do
if Store_weapon_radial:get_weapon_name(slot_i) == Store_weapon_alien[weapon_i].label then
Store_weapon_radial:slot_disable(slot_i)
Store_weapon_radial:slot_show_ammo(slot_i, false)
end
end
-- Disable if this weapon has infinite ammo
if Store_weapon_radial:slot_has_infinite_ammo(slot_i) then
Store_weapon_radial:slot_disable(slot_i)
Store_weapon_radial:slot_show_ammo(slot_i, false)
end
end
-- Open the radial menu
store_weapon_inventory_show(menu_data)
end
function store_weapon_ammo_nav(slot_id)
-- Can't purchase ammo for some categories
if slot_id < 2 then
Store_header:set_price(nil)
return
end
local ammo_info
-- is this thrown or normal weapon?
if slot_id < 8 then
ammo_info = store_weapon_ammo_find_by_id(slot_id)
else
ammo_info = store_weapon_thrown_ammo_find_by_id(slot_id - 8)
end
-- ammo is not available for this category
if ammo_info == nil then
Store_header:set_price(nil)
return
end
-- Disable if this weapon has infinite ammo
if Store_weapon_radial:slot_has_infinite_ammo(slot_id) then
Store_header:set_price(nil)
return
end
-- Show the ammo price
if ammo_info.price == 0 then
Store_header:set_price(nil)
else
Store_header:set_price(ammo_info.price)
end
store_weapon_stats_update(slot_id, false)
end
function store_weapon_stats_update(slot_id, show_available, force_update)
-- If force_update is set to true, we want to stay on the same slot id
if force_update == true then
if slot_id == -1 then
slot_id = Prev_slot
end
else
if slot_id == Prev_slot then
return
end
Prev_slot = slot_id
end
Stats_initialized = true
--[[Info in Weapon_grid_data
icon = icon_name,
label = name_str,
color = { red = 1, green = 1, blue = 1 },
is_owned = own,
id = id,
dual_wield = dual_wield,
price = price,
level = upgrade_level,
level_desc = desc_crc,
is_checked = false,
equipped = equipped,
]]--
-- Get new data for Weapon_grid_data
store_weapon_populate_weapon_grid(Store_weapon_categories[slot_id].category, slot_id)
-- Display slot info
local header_txt = Vdo_base_object:new("header_txt", 0, Store_weapon_doc_handle)
local owned_grp = Vdo_base_object:new("owned_grp", 0, Store_weapon_doc_handle)
local available_grp = Vdo_base_object:new("available_grp", 0, Store_weapon_doc_handle)
local owned_txt = Vdo_base_object:new("owned_txt", 0, Store_weapon_doc_handle)
local available_txt = Vdo_base_object:new("available_txt", 0, Store_weapon_doc_handle)
local base_weapon_txt = Vdo_base_object:new("base_weapon_txt", 0, Store_weapon_doc_handle)
local base_txt_x, base_txt_y = base_weapon_txt:get_anchor()
local base_txt_width, base_txt_height = element_get_actual_size(base_weapon_txt.handle)
local num_weapons = #Weapon_grid_data
local new_x, new_y = base_txt_x, base_txt_y
local WEAPON_TXT_BUFFER_HD = 5
local WEAPON_TXT_BUFFER_SD = 12
local HEADER_TXT_MAX_WIDTH_HD = 530
local HEADER_TXT_MAX_WIDTH_SD = 350
local Weapon_txt_buffer = WEAPON_TXT_BUFFER_HD
local max_header_width = HEADER_TXT_MAX_WIDTH_HD
-- Set headers
header_txt:set_text(Store_weapon_categories[slot_id].label)
owned_txt:set_text("STORE_WEAPON_OWNED")
available_txt:set_text("STORE_WEAPON_AVAILABLE")
base_weapon_txt:set_visible(false)
-- Resize header text to fit in other languages
if vint_is_std_res() then
max_header_width = HEADER_TXT_MAX_WIDTH_SD
base_weapon_txt:set_property("wrap_width", 320)
Weapon_txt_buffer = WEAPON_TXT_BUFFER_SD
end
--Change color if we're in the crib cache
local subheader_bar_h = vint_object_find("subheader_bar", owned_grp.handle, Store_weapon_doc_handle)
local subheader_bar_1_h = vint_object_find("subheader_bar_1", available_grp.handle, Store_weapon_doc_handle)
if Store_weapon_loaded_from_crib then
vint_set_property(subheader_bar_h, "alpha", 1)
vint_set_property(subheader_bar_1_h, "alpha", 1)
base_weapon_txt:set_color(STORE_CRIB_DESC_COLOR.R, STORE_CRIB_DESC_COLOR.G, STORE_CRIB_DESC_COLOR.B)
header_txt:set_color(STORE_CRIB_TITLE_COLOR.R, STORE_CRIB_TITLE_COLOR.G, STORE_CRIB_TITLE_COLOR.B)
end
header_txt:set_scale(1, 1)
local header_width, header_height = element_get_actual_size(header_txt.handle)
if header_width >= max_header_width then
local text_scale = max_header_width/header_width
header_txt:set_scale(text_scale, text_scale)
end
new_y = new_y + base_txt_height + Weapon_txt_buffer
-- Destroy clones and reset tables
for i = 1, #Weapons_owned do
Weapons_owned[i]:object_destroy()
end
Weapons_owned = {}
for i = 1, #Weapons_available do
Weapons_available[i]:object_destroy()
end
Weapons_available = {}
-- Create "owned" list
local num_weapons_owned = 1
for i = 1, num_weapons do
local info = Weapon_grid_data[i]
if info.is_owned == true then
--clone text
local cur_weapon
local skip_dual_item = false
if info.dual_wield == true then
skip_dual_item = true
cur_weapon = Weapons_owned[num_weapons_owned-1]
else
cur_weapon = Vdo_base_object:clone(base_weapon_txt.handle)
end
-- Append level to each weapon and equipped status
local body, insert_values
-- Display weapon name and equipped status
if info.equipped == true then
local color = "[format][color:#ff932a]"
if Store_weapon_loaded_from_crib then
color = "[format][color:#b6d6f6]"
end
insert_values = {[0] = info.label, [1] = color }
body = vint_insert_values_in_string("STORE_WEAPON_OWNED_EQUIPPED", insert_values)
else
insert_values = {[0] = info.label}
body = vint_insert_values_in_string("STORE_WEAPON_OWNED_NOT_EQUIPPED", insert_values)
end
cur_weapon:set_text(body)
local cur_weapon_width, cur_weapon_height = element_get_actual_size(cur_weapon.handle)
cur_weapon:set_anchor(new_x, new_y)
new_y = new_y + cur_weapon_height + Weapon_txt_buffer
cur_weapon:set_visible(true)
--Store to global for cleanup
if skip_dual_item == false then
Weapons_owned[num_weapons_owned] = cur_weapon
num_weapons_owned = num_weapons_owned + 1
end
end
end
-- Display none if no weapons are owned
if Weapons_owned[1] == nil then
local cur_weapon = Vdo_base_object:clone(base_weapon_txt.handle)
cur_weapon:set_text("LOCALIZE_NONE")
local cur_weapon_width, cur_weapon_height = element_get_actual_size(cur_weapon.handle)
cur_weapon:set_anchor(new_x, new_y)
new_y = new_y + cur_weapon_height + Weapon_txt_buffer
cur_weapon:set_visible(true)
--Store for cleanup
Weapons_owned[1] = cur_weapon
end
-- Get positioning for next list
local avail_x, avail_y = available_grp:get_anchor()
if vint_is_std_res() then
new_y = new_y + Weapon_txt_buffer * 2
else
new_y = new_y + Weapon_txt_buffer * 4
end
available_grp:set_anchor(avail_x, new_y)
-- Create "available" list
local num_available_weapons = 1
for i = 1, num_weapons do
local info = Weapon_grid_data[i]
if info.is_owned == false then
--clone text
local cur_weapon = Vdo_base_object:clone(base_weapon_txt.handle)
cur_weapon:set_text(info.label)
local cur_weapon_width, cur_weapon_height = element_get_actual_size(cur_weapon.handle)
new_y = new_y + cur_weapon_height + Weapon_txt_buffer
cur_weapon:set_anchor(new_x, new_y)
cur_weapon:set_visible(true)
--Store to global for cleanup
Weapons_available[num_available_weapons] = cur_weapon
num_available_weapons = num_available_weapons + 1
end
end
-- Show available weapons group?
if show_available ~= nil then
if #Weapons_available > 0 then
available_grp:set_visible(show_available)
for i = 1, #Weapons_available do
Weapons_available[i]:set_visible(show_available)
end
else
available_grp:set_visible(false)
end
else
if Weapons_available[1] ~= nil then
available_grp:set_visible(true)
else
available_grp:set_visible(false)
end
end
--is the list of weapons past safe frame? If so, move it up by that amount
local new_stats_y = STORE_WEAPON_STATS_GRP_Y
if new_y > STORE_WEAPON_STATS_GRP_MAX then
new_stats_y = new_stats_y - (new_y - STORE_WEAPON_STATS_GRP_MAX)
end
if vint_is_std_res() then
Slot_stats_grp:set_anchor(STORE_WEAPON_STATS_GRP_SD_X, new_stats_y)
else
Slot_stats_grp:set_anchor(STORE_WEAPON_STATS_GRP_X, new_stats_y)
end
end
function store_weapon_populate_weapon_grid(category, slot)
-- Initialize data for grid
Weapon_grid_data = {}
Weapon_grid_data.category = category
vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category, slot - 8) -- last param is only used for grenade slot index
end
function store_weapon_ammo_find_by_id(id)
for i = 1, #Store_weapon_ammo_info do
if Store_weapon_ammo_info[i].id == id then
debug_print("store_weapon","returning ammo info with name "..Store_weapon_ammo_info[i].icon_name.."\n")
return Store_weapon_ammo_info[i]
end
end
return nil
end
function store_weapon_thrown_ammo_find_by_id(id)
for i = 1, #Store_weapon_thrown_ammo_info do
if Store_weapon_thrown_ammo_info[i].thrown_wpn_id == id then
return Store_weapon_thrown_ammo_info[i]
end
end
return nil
end
-- Callback for data responder that populates ammo information for each category.
--
function store_weapon_ammo_add_items(unused, icon_name, unused, price, clip_size, current_amount, max_amount, id, thrown_wpn_id)
if thrown_wpn_id == nil or thrown_wpn_id == -1 then
local index = #Store_weapon_ammo_info + 1
Store_weapon_ammo_info[index] = {
price = price, icon_name = icon_name, clip_size = clip_size, ammo_current = current_amount, ammo_max = max_amount, id = id, thrown_wpn_id = nil
}
else
local index = #Store_weapon_thrown_ammo_info + 1
-- SEH: make const for 1000 (special value from code)
Store_weapon_thrown_ammo_info[index] = {
price = price, icon_name = icon_name, clip_size = clip_size, ammo_current = current_amount, ammo_max = max_amount, id = 1000, thrown_wpn_id = thrown_wpn_id
}
end
end
-- Purchase ammo from the radial menu.
--
-- slot: the slot number chosen in the radial menu.
--
function store_weapon_ammo_purchase(slot)
-- Can't purchase ammo for some categories
if slot < 2 then
return
end
-- Disable if this weapon has infinite ammo
if Store_weapon_radial:slot_has_infinite_ammo(slot) then
return
end
local ammo_info
-- is this thrown or normal weapon?
if slot < 8 then
ammo_info = store_weapon_ammo_find_by_id(slot)
else
ammo_info = store_weapon_thrown_ammo_find_by_id(slot - 8)
end
-- ammo is not available for this category
if ammo_info == nil then
return
end
-- Check if we have space for ammo, and enough money.
if ammo_info.ammo_current < ammo_info.ammo_max then
if Store_common_player_cash >= ammo_info.price then
local saved_cash = Store_common_player_cash
-- Make the purchase.
store_weapon_purchase_ammo(ammo_info.id, ammo_info.thrown_wpn_id, ammo_info.clip_size, ammo_info.price)
ammo_info.ammo_current = ammo_info.ammo_current + ammo_info.clip_size
if ammo_info.ammo_current > ammo_info.ammo_max then
ammo_info.ammo_current = ammo_info.ammo_max
end
--play the purchase sound
ui_audio_post_event("ammo_purchase")
-- Refresh the ammo information
Store_weapon_ammo_info = {}
Store_weapon_thrown_ammo_info = {}
vint_dataresponder_request("store_weapon_populate_ammo", "store_weapon_ammo_add_items", 0)
-- refresh the stats info
store_weapon_stats_update(-1, false, true)
else
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_weapon_fail_msg", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
game_UI_audio_play("UI_HUD_HELP")
store_weapon_enable_mouse(false)
return
end
else
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("WPNSTOR_TEXT_MAX_AMMO_STORE")
Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
game_UI_audio_play("UI_HUD_HELP")
store_weapon_enable_mouse(false)
return
end
end
-- Weapon purchasing and upgrading ******************************************************************************************
-- Open the weapon purchasing and upgrading radial menu.
--
function store_weapon_purchase_open_radial(menu_data)
Store_weapon_menu_category = STORE_WEAPON_CATEGORY_UPGRADES
Active_list:set_visible(false)
store_weapon_cover_weapon(true)
store_weapon_hide_weapon()
-- Set the hint based on the platform
local hint_data = {}
if game_get_platform() == "PC" then
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
else
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"},
}
end
Store_common_hint_bar:set_hints(hint_data)
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:subscribe(true)
end
Store_weapon_is_cache = false
-- Set the callback to use when the user selects a cateogory from the radial menu
Store_weapon_inventory.selected_cb = store_weapon_grid_open
Store_weapon_inventory.nav_cb = store_weapon_purchase_nav
-- Disable the unarmed slot
Store_weapon_radial:slot_disable(0)
--Hide grenades
Store_weapon_radial:show_dpad_menu(false)
Store_weapon_radial:set_anchor(Radial_store_x,Radial_y)
-- Enable or disable slots based on availability
for i = 1, 7 do
--Hide ammo when only dealing with weapons
Store_weapon_radial:slot_show_ammo(i, false)
-- Initialize data for grid
Weapon_grid_data = {}
local category = Store_weapon_categories[i].category
vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category)
-- If there are no choices, then disable
if #Weapon_grid_data == 0 then
Store_weapon_radial:slot_disable(i)
else
Store_weapon_radial:slot_enable(i)
end
Store_weapon_categories[i].info = Weapon_grid_data
end
-- Open the radial menu
store_weapon_inventory_show(menu_data)
end
function store_weapon_purchase_nav(slot_id)
store_weapon_stats_update(slot_id)
store_weapon_cover_weapon(true)
end
-------------------------------------------------------------------------------
-- Function store_weapon_grid_open()
--
-- Purchase or upgrade weapons from the radial menu.
--
-- @param slot -- the slot number chosen in the radial menu
-- @param grid_index -- which item in grid is selected. default is 1
-- @param push_title -- determines if we push a new title to Store_header
--
-------------------------------------------------------------------------------
function store_weapon_grid_open(slot, grid_index, push_title)
debug_print("store_weapon", "called store_weapon_grid_open\n")
Current_slot = slot
Old_index = 0
-- Can't purchase some categories
if slot < 1 then
return
end
-- Initialize data for grid
Weapon_grid_data = {}
-- Get the category name string for the chosen slot.
local category = Store_weapon_categories[slot].category
vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category, slot - 8) -- last param is only used for grenade slot index
-- If there are no choices, don't go to grid
if #Weapon_grid_data == 0 then
debug_print("store_weapon", "not opening grid because there are no choices\n")
return
end
-- Save of where we are in the flow
Store_weapon_menu_level = STORE_WEAPON_LEVEL_GRID
--Force a specific grid index if specified. Otherwise use 1
--Weapon_grid_idx = grid_index or 1
-- set the titles on top
if push_title ~= false then
Store_header:push_title( nil, Store_weapon_categories[slot].label )
end
-- display the grid
Weapon_grid_data.category = category
Store_common_color_grid:set_highlight_color(Weapon_store_highlight_color)
Store_common_color_grid:draw_items(Weapon_grid_data, Weapon_grid_idx, 3, 3, 120, 100, 40, nil, nil, false)
Store_common_color_grid:set_visible(true)
Store_common_color_grid:nav_enable(true, "store_weapon_grid_selected", "store_weapon_grid_nav")
-- hide grid highlighted name
Store_common_color_grid.highlight_name:set_visible(false)
-- Close the radial before we show the grid.
store_weapon_close_radial()
-- Hide the megalist (close_radial function unhides it).
Active_list:set_visible(false)
if Game_platform == "PC" then
Hint_bar_mouse_input_tracker:subscribe(false)
end
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
Store_common_hint_bar:set_hints(hint_data)
if Game_platform == "PC" then
Hint_bar_mouse_input_tracker:subscribe(true)
end
-- Get the currently selected weapon info
local idx = Store_common_color_grid:return_selected_index()
local weapon_info = Weapon_grid_data[idx]
--Update current costume name and description
Current_costume_name_crc = weapon_info.costume_name_crc
Current_costume_desc_crc = weapon_info.costume_desc_crc
Current_skin_name_crc = weapon_info.skin_name_crc
-- Preview the model of the selected weapon
--local current_idx = Store_common_color_grid:get_selection()
local current_weapon_info = Weapon_grid_data[Weapon_grid_idx]
store_weapon_populate_weapon_stats(current_weapon_info.label, Current_costume_name_crc, current_weapon_info.level_desc)
store_weapon_change_weapon_preview(Weapon_grid_data.category, weapon_info.id, weapon_info.dual_wield, Store_weapon_is_cache, nil, weapon_info.costume_id, weapon_info.skin_id, weapon_info.store_name_crc)
-- Update price
store_weapon_price_update()
-- For thrown weapons, bypass the grid
if category == "thrown" then
Current_tier = GRENADE_UPGRADE_TIER
store_weapon_grid_selected("select")
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:subscribe(false)
end
if Radial_mouse_input_tracker ~= nil then
Radial_mouse_input_tracker:subscribe(false)
end
else
Current_tier = WEAPON_TIER
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:subscribe(false)
end
if Radial_mouse_input_tracker ~= nil then
Radial_mouse_input_tracker:subscribe(false)
end
end
end
-- Updates price in weapon grid. Displays "OWNED" if weapon is owned.
--
function store_weapon_price_update()
local weapon_info = Weapon_grid_data[Weapon_grid_idx]
-- Show the weapon/upgrade price
if weapon_info.price == 0 or Store_weapon_is_cache == true then
Store_header:set_price(nil)
else
Store_header:set_price(weapon_info.price)
end
--Show "OWNED" if weapon is owned
if weapon_info.is_owned == true and Store_weapon_is_cache ~=true then
Store_header:set_price("STORE_WEAPON_OWNED")
end
end
-- Updates the price for notoriety wipe. Does not display price if notoriety level is 0
--
function store_weapon_notoriety_price_update()
local wipe_price = 100;
-- Show the weapon/upgrade price
if wipe_price == 0 then
Store_header:set_price(nil)
else
Store_header:set_price(wipe_price)
end
end
-- Updates weapon title, description, and/or costume name on right side of the screen
--
function store_weapon_populate_weapon_stats(title, costume_name, desc_crc)
local weapon_info = Weapon_grid_data[Weapon_grid_idx]
local new_title = title or weapon_info.label
local new_costume_name = costume_name or 0
local new_desc_crc = desc_crc or weapon_info.costume_desc_crc or weapon_info.level_desc
-- Get the currently selected weapon info
local weapon_title_h = vint_object_find("weapon_title", 0, Store_weapon_doc_handle)
local weapon_level_h = vint_object_find("weapon_level", 0, Store_weapon_doc_handle)
local level_desc_h = vint_object_find("level_desc", 0, Store_weapon_doc_handle)
if vint_is_std_res() then
vint_set_property(level_desc_h, "wrap_width", 340)
end
--Change color and alpha if in crib
local weapon_level_bar_h = vint_object_find("weapon_level_bar", 0, Store_weapon_doc_handle)
if Store_weapon_loaded_from_crib then
vint_set_property(weapon_level_bar_h, "alpha", 1)
vint_set_property(weapon_title_h, "tint", STORE_CRIB_TITLE_COLOR.R, STORE_CRIB_TITLE_COLOR.G, STORE_CRIB_TITLE_COLOR.B)
vint_set_property(level_desc_h, "tint", STORE_CRIB_DESC_COLOR.R, STORE_CRIB_DESC_COLOR.G, STORE_CRIB_DESC_COLOR.B)
end
-- Set weapon title/category
-- Determine if we're a string or crc
if type(new_title) == "string" then
vint_set_property(weapon_title_h, "text_tag", new_title)
else
vint_set_property(weapon_title_h, "text_tag_crc", new_title)
end
-- Shrink title text to fit in safe frame
resize_text_element(weapon_title_h, 350)
-- Set costume name (shown in grey bar)
-- Determine if we're a string or crc
if type(new_costume_name) == "string" then
vint_set_property(weapon_level_h, "text_tag", new_costume_name)
else
vint_set_property(weapon_level_h, "text_tag_crc", new_costume_name)
end
vint_set_property(level_desc_h, "text_tag_crc", new_desc_crc)
end
function store_weapon_cover_weapon(show_slot_stats)
if Store_weapon_menu_level == STORE_WEAPON_LEVEL_MAIN or show_slot_stats == true then
-- this should be the situations when we don't want to show stats too
Weapon_stats_grp:set_visible(false)
end
Slot_stats_grp:set_visible(show_slot_stats and Stats_initialized)
-- Hide zoom/rotate hint
-- Hint_bar_rotate:set_visible(false)
end
function store_weapon_uncover_weapon()
-- make background so it is behind the weapon
--Weapon_bg_grp:set_property("background", true)
bg_saints_set_background(true)
-- this should be the situations when we don't want to show stats too
Weapon_stats_grp:set_visible(true)
-- Get current grid idx
--local current_idx = Store_common_color_grid:get_selection()
--Get data for current weapon
local current_weapon_info = Weapon_grid_data[Weapon_grid_idx]
--Determine where we are in the flow
if Store_weapon_menu_level == STORE_WEAPON_LEVEL_COSTUME then
local current_idx = Active_list:get_selection()
-- Update costume info
store_weapon_populate_weapon_stats(Store_weapon_building_menu[current_idx].label_crc, nil, Store_weapon_building_menu[current_idx].costume_desc_crc)
elseif Store_weapon_menu_level == STORE_WEAPON_LEVEL_UPGRADE then
-- Update costume info
store_weapon_populate_weapon_stats(Current_costume_name_crc, Current_skin_name_crc, Current_costume_desc_crc)
else
-- Show weapon category info
store_weapon_populate_weapon_stats(current_weapon_info.label, current_weapon_info.costume_name_crc, current_weapon_info.level_desc)
end
Slot_stats_grp:set_visible(false)
-- Show zoom/rotate hint
-- if game_is_active_input_gamepad() == true then
-- hint_bar_rotate:set_visible(true)
-- end
Store_weapon_is_loading = false
end
function store_weapon_grid_add_thrown_items(name_str, icon_name, price, own, equipped, id, ammo_current, ammo_max, unlimited_ammo, dual_wield, upgrade_level, desc_crc, costume_id, num_costumes, costume_name_crc, store_name_str)
local grid_idx = #Weapon_grid_data + 1
Weapon_grid_data[grid_idx] = {
icon = icon_name,
label = name_str,
color = { red = 1, green = 1, blue = 1 },
is_owned = own,
id = id,
dual_wield = dual_wield,
price = price,
level = upgrade_level,
level_desc = desc_crc,
is_checked = own,
equipped = equipped,
costume_id = costume_id,
num_costumes = num_costumes,
costume_name_crc = costume_name_crc,
store_name_crc = store_name_str,
}
if equipped == true then
Weapon_grid_idx = grid_idx
end
if Store_weapon_is_cache then
Weapon_grid_data[grid_idx].is_checked = false
end
end
function store_weapon_grid_add_items(name_str, icon_name, price, own, equipped, id, ammo_current, ammo_max, unlimited_ammo, dual_wield, upgrade_level, desc_crc, costume_id, num_costumes, costume_name_crc, skin_id, costume_desc_crc, skin_name_crc, is_streamed, store_name_str)
local grid_idx = #Weapon_grid_data + 1
--Append "_c" to weapon costume icons that have to be streamed
--They are pulled from ui_bms_store_weapon_costumes
local temp_icon_name = icon_name
if is_streamed then
temp_icon_name = icon_name.."_c"
-- Some weapons are sent in by code as streamed, but their icons are always loaded
-- Check that table and make sure to use their always loaded icon
for i = 1, #Store_weapon_always_loaded_icons do
if icon_name == Store_weapon_always_loaded_icons[i] then
temp_icon_name = icon_name
end
end
end
Weapon_grid_data[grid_idx] = {
icon = temp_icon_name,
label = costume_name_crc, --name_str
color = { red = 1, green = 1, blue = 1 },
is_owned = own,
id = id,
dual_wield = dual_wield,
price = price,
level = upgrade_level,
level_desc = desc_crc,
is_checked = own,
equipped = equipped,
costume_id = costume_id,
num_costumes = num_costumes,
costume_name_crc = name_str, --costume_name_crc
skin_id = skin_id, -- Sean, this id needs to be added - it is currently nil
costume_desc_crc = costume_desc_crc,
skin_name_crc = skin_name_crc, --skin_name_crc
store_name_crc = store_name_str,
}
if equipped == true then
Weapon_grid_idx = grid_idx
end
if Store_weapon_is_cache then
Weapon_grid_data[grid_idx].is_checked = false
end
end
-- Callback to handle when the player is on the weapon purchase/upgrade grid and makes a selection or cancels.
--
function store_weapon_grid_selected(event)
-- if the weapon is still loading, don't allow grid selection
if store_weapon_allow_grid_input() == false then
return
end
-- Reset skip flag if the grid is used
if Mouse_input_tracker ~= 0 then
Skip_next_populate = false
end
--Did the player select a weapon?
if event == "select" or event == "mouse_click" then
-- Save off currently selected grid index, so we can know which one to start at when backing out of the upgrade menu.
Weapon_grid_idx = Store_common_color_grid:get_selection()
local weapon_info = Weapon_grid_data[Weapon_grid_idx]
-- If we're in the weapon cache, we're just equipping it, so no need for the other checks done below for purchasing.
if Store_weapon_is_cache then
game_UI_audio_play("UI_Main_Menu_Select")
-- Equip weapon if in cache
store_weapon_purchase_weapon(Weapon_grid_data.category, weapon_info.id, Store_weapon_is_cache, 0)
-- Go back to main menu.
Store_common_color_grid:nav_enable(false, nil, nil)
Store_common_color_grid:set_visible(false)
Store_common_color_grid:cleanup()
store_weapon_cover_weapon(true)
store_weapon_hide_weapon()
local current_image = Reward_image:get_image()
if current_image ~= nil then
game_peg_unload(current_image)
end
Reward_image:set_visible(false)
Store_weapon_loading_img = nil
-- do this so holding down the button doesn't cause repeated actions
Input_tracker:subscribe(false)
Input_tracker:subscribe(true)
-- pop off header titles
Store_header:pop_title()
--Store_header:pop_title()
Store_header:set_price(nil)
--Active_list:set_visible(true)
-- Open the radial menu
store_weapon_inventory_show()
if Store_weapon_loaded_from_crib then
store_weapon_unlock_radial()
end
return
end
-- Hide the grid
Store_common_color_grid:nav_enable(false, nil, nil)
Store_common_color_grid:set_visible(false)
Store_common_color_grid:cleanup()
game_UI_audio_play("UI_Main_Menu_Select")
Store_weapon_current_info = weapon_info
--Bring up purchase popup if weapon is not owned. Otherwise advance to upgrades.
if weapon_info.is_owned == false then
store_weapon_grid_purchase(weapon_info)
else
-- We are now going to go to another menu (megalist) with the upgrade levels
store_weapon_upgrade_show(Weapon_grid_data.category, weapon_info.id)
end
else
Old_index = 0
-- Go back to main menu.
Store_common_color_grid:nav_enable(false, nil, nil)
Store_common_color_grid:set_visible(false)
Store_common_color_grid:cleanup()
store_weapon_cover_weapon(true)
store_weapon_hide_weapon()
local current_image = Reward_image:get_image()
if current_image ~= nil then
game_peg_unload(current_image)
end
Reward_image:set_visible(false)
Store_weapon_loading_img = nil
-- If we came from the crib, we need to pop this doc off the stack
--[[if Store_weapon_loaded_from_crib then
store_lock_controls()
pop_screen()
return
end ]]
game_UI_audio_play("UI_Main_Menu_Nav_Back")
-- pop off header titles
Store_header:pop_title()
--Store_header:pop_title()
Store_header:set_price(nil)
--Did we back out/cancel from the weapon cache? If so, make sure we go back to the weapon cache radial
if Store_weapon_is_cache then
store_weapon_cache_open_radial()
else
-- Else open store radial
store_weapon_purchase_open_radial()
end
if Store_weapon_loaded_from_crib then
store_weapon_unlock_radial()
end
Current_tier = RADIAL_TIER
end
end
-- Handle purchase popup for purchasing weapons from the grid
--
function store_weapon_grid_purchase(menu_data)
if Store_common_player_cash >= menu_data.price then
Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("MENU_TITLE_CONFIRM")
local insert = { [0] = menu_data.label, [1] = format_cash(menu_data.price) }
local body = vint_insert_values_in_string("WPN_STORE_PURCHASE_PROMPT", insert)
Store_common_popup:set_text(body)
Store_common_popup:nav_enable(true, "store_weapon_grid_confirm", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
store_weapon_enable_mouse(false)
game_UI_audio_play("UI_HUD_HELP")
else
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_weapon_grid_refresh", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
store_weapon_enable_mouse(false)
game_UI_audio_play("UI_HUD_HELP")
end
end
-------------------------------------------------------------------------------
-- Hide popup and bring weapon grid back
--
function store_weapon_grid_refresh()
--Open the grid again, but don't push another title to Store_header
store_weapon_grid_open(Current_slot, Weapon_grid_idx, false)
store_weapon_fail_msg()
end
function store_weapon_upgrade_confirm(event)
store_weapon_enable_mouse(true)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
Store_weapon_not_bg_grp:set_alpha(1)
local upgrade_idx = Active_list:get_selection()
-- The user hit the B button and are cancelling the purchase
-- This is the same as selecting "No" in the list
if event == "back" or Store_common_popup:get_selected_data() ~= 1 then
--Return to upgrades menu
store_weapon_upgrade_refresh(upgrade_idx)
--Pop current selection title that store_common pushes after we draw a new menu
Store_header:pop_title()
return
end
game_UI_audio_play("UI_Main_Menu_Select")
--Call C to make the purchase
store_weapon_purchase_weapon_upgrade(Weapon_grid_data.category, Weapon_grid_data[Weapon_grid_idx].id, Store_weapon_building_menu[upgrade_idx].attribute_id)
--Call purchase weapon to equip the weapon since an upgrade was purchased for it
store_weapon_purchase_weapon(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_is_cache, 0)
game_hud_update_inventory()
-- Update GSI if in mission
if Store_weapon_in_mission and Upgrade_gsi_is_updated == true then
Store_common_gsi:update("MM_1_1_OBJ_EXIT_STORE", "ui_target_icon_use")
--don't call this again once it's updated
Upgrade_gsi_is_updated = true
end
store_weapon_upgrade_refresh(upgrade_idx)
--Pop current selection title that store_common pushes after we draw a new menu
Store_header:pop_title()
ui_audio_post_event("weapon_purchase")
end
-------------------------------------------------------------------------------
-- Update the megalist after a purchase is made
--
function store_weapon_upgrade_refresh(idx)
Store_weapon_menu_level = STORE_WEAPON_LEVEL_UPGRADE
Active_list:set_visible(true)
Store_header:set_price(nil)
-- Get data to populate the megalist
Store_weapon_building_menu = {}
local current_weapon = Weapon_grid_data[Weapon_grid_idx]
--Do we have costumes?
if current_weapon.num_costumes == 1 then
Store_weapon_building_menu = {
[1] = {
type = TYPE_HEADER,
label = "MENU_UPGRADES",
}
}
elseif current_weapon.num_costumes > 1 then
--Make the first selection the style option
Store_weapon_building_menu = {
[1] = {
type = TYPE_HEADER,
label = "MENU_STYLE",
},
[2] = {
type = TYPE_BUTTON,
id = STORE_WEAPON_CUSTOMIZE_OPTION,
label = "STORE_WEAPON_CUSTOMIZE", --current_weapon.costume_name_crc,
costume_desc_crc = current_weapon.costume_desc_crc,
price = 0,
on_nav = store_weapon_upgrade_nav,
on_select = store_weapon_upgrade_purchase,
on_cancel = store_weapon_upgrade_back,
},
[3] = {
type = TYPE_HEADER,
label = "MENU_UPGRADES",
}
}
end
vint_dataresponder_request("store_weapon_populate_upgrades", "store_weapon_upgrade_add_items", 0, Weapon_grid_data.category, current_weapon.id)
--Make sure idx is valid (if we came from a callback it could be a table)
if type(idx) == "table" or idx == nil then
idx = 2
end
Store_weapon_building_menu.start_index = idx
Menu_data = Store_weapon_building_menu
Active_list:set_selection(idx)
store_common_push_menu(Store_weapon_building_menu)
--store_weapon_populate_list(Store_weapon_building_menu, Store_weapon_building_menu.start_index, false)
local current_selection = Active_list:get_selection()
--Are we on costume or upgrade?
if current_weapon.num_costumes > 1 and current_selection == 2 then
--Update the name and description
store_weapon_populate_weapon_stats(Current_costume_name_crc, Current_skin_name_crc, Current_costume_desc_crc)
--Change the weapon model
store_weapon_change_weapon_preview(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_current_info.dual_wield, Store_weapon_is_cache, -1, Weapon_grid_data[Weapon_grid_idx].costume_id, Weapon_grid_data[Weapon_grid_idx].skin_id, Weapon_grid_data[Weapon_grid_idx].store_name_crc)
else
--Upate upgrade info
store_weapon_upgrade_nav(Store_weapon_building_menu[current_selection])
end
Weapon_stats_grp:set_visible(true)
end
-------------------------------------------------------------------------------
-- Function store_weapon_menu_data_refresh()
--
-- Menu_data may have been overwritten. This function is called
-- when we return to the main menu to reset the menu back to store weapon's
-- initial choices
--
-------------------------------------------------------------------------------
function store_weapon_menu_data_reset()
--Remove any pushed menus
store_common_stack_clear_menu()
--Populate store common list with store weapon main menu data
Menu_data = {
on_cancel = store_weapon_cancel_radial,
[1] = { label = "STORE_WEAPON_WIPE_NOTORIETY", type = TYPE_BUTTON, on_select = store_weapon_wipe_notoriety, on_nav = store_weapon_main_menu_nav },
[2] = { label = "STORE_WEAPON_AMMO", type = TYPE_BUTTON, on_select = store_weapon_ammo_open_radial, on_nav = store_weapon_main_menu_nav },
[3] = { label = "STORE_WEAPON_BUY_UPGRADE", type = TYPE_BUTTON, on_select = store_weapon_purchase_open_radial, on_nav = store_weapon_main_menu_nav },
}
--if store_weapon_is_tutorial_mode() == false then
Menu_data[#Menu_data + 1] = { label = "STORE_WEAPON_CACHE", type = TYPE_BUTTON, on_select = store_weapon_cache_open_radial }
--end
Menu_data[#Menu_data + 1] = { label = "STORE_EXIT", type = TYPE_BUTTON, on_select = store_weapon_exit }
--Draw the new list
store_weapon_populate_list(Menu_data, Store_weapon_menu_category)
end
-------------------------------------------------------------------------------
-- Function store_weapon_upgrade_show
--
-- Draw the costume (optional) and upgrade list for the first time
--
-- @param cateogry -Weapon category ex: melee, pistol, etc.
-- @param id -Weapon id
-- @param start_index -Starting index for the list
--
-------------------------------------------------------------------------------
function store_weapon_upgrade_show(category, id, start_index)
Store_weapon_menu_level = STORE_WEAPON_LEVEL_UPGRADE
--Hide list and price until we're done updating
Active_list:set_visible(true)
Store_header:set_price(nil)
--Get data to populate the megalist
Store_weapon_building_menu = {}
--Save reference to current weapon
local current_weapon = Weapon_grid_data[Weapon_grid_idx]
--Do we have costumes?
if current_weapon.num_costumes == 1 then
--No costumes, go straight to upgrades
Store_weapon_building_menu = {
[1] = {
type = TYPE_HEADER,
label = "MENU_UPGRADES",
}
}
elseif current_weapon.num_costumes > 1 then
--Costumes, Default the first selection to the costume option
Store_weapon_building_menu = {
[1] = {
type = TYPE_HEADER,
label = "MENU_STYLE",
},
[2] = {
type = TYPE_BUTTON,
id = STORE_WEAPON_CUSTOMIZE_OPTION,
label = "STORE_WEAPON_CUSTOMIZE", --current_weapon.costume_name_crc,
costume_desc_crc = current_weapon.costume_desc_crc,
price = 0,
on_nav = store_weapon_upgrade_nav,
on_select = store_weapon_upgrade_purchase,
on_cancel = store_weapon_upgrade_back,
},
[3] = {
type = TYPE_HEADER,
label = "MENU_UPGRADES",
}
}
end
--Get upgrade data from code
vint_dataresponder_request("store_weapon_populate_upgrades", "store_weapon_upgrade_add_items", 0, category, id)
--Set intial start index for the list
Store_weapon_building_menu.start_index = start_index or 2
--store_weapon_populate_list(Store_weapon_building_menu, Store_weapon_building_menu.start_index)
store_common_push_menu(Store_weapon_building_menu)
-- Add mouse input subscriptions
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
Active_list:set_store("store_weapon")
Active_list:add_mouse_inputs("store_common", Mouse_input_tracker)
store_weapon_enable_mouse(true)
end
--Determine which description to display based on if costumes are present
local current_selection = Active_list:get_selection()
if current_weapon.num_costumes > 1 and current_selection == 2 then
--Update name and description
store_weapon_populate_weapon_stats(Current_costume_name_crc, Current_skin_name_crc, Current_costume_desc_crc)
else
--We're on an upgrade - show upgrade desc
local desc_crc = Store_weapon_building_menu[current_selection].upgrade_desc_crc
local label_crc = Store_weapon_building_menu[current_selection].label_crc
store_weapon_populate_weapon_stats( label_crc, nil, desc_crc )
Store_header:set_price(Store_weapon_building_menu[current_selection].price)
end
Current_tier = LEVEL_TIER
--Override the titles coming from store_common
Store_header:pop_title()
Store_header:push_title(nil, "MENU_UPGRADES")
Weapon_stats_grp:set_visible(true)
end
--Get data for upgrade list
function store_weapon_upgrade_add_items(upgrade_desc_crc, level_desc_crc, level_price, current_level, max_level, attribute_id, is_ultimate)
local menu_idx = #Store_weapon_building_menu + 1
local new_item = {
type = TYPE_PIP,
id = #Store_weapon_building_menu,
upgrade_desc_crc = level_desc_crc,
label_crc = upgrade_desc_crc,
max_level = max_level,
level = current_level,
price = level_price,
attribute_id = attribute_id,
on_nav = store_weapon_upgrade_nav,
on_select = store_weapon_upgrade_purchase,
on_cancel = store_weapon_upgrade_back,
}
Store_weapon_building_menu[menu_idx] = new_item
-- if level_is_locked == false then
-- Store_weapon_building_menu.start_index = menu_idx
-- -- Show the weapon/upgrade price
-- if level_price == 0 then
-- Store_header:set_price(nil)
-- else
-- Store_header:set_price(level_price)
-- end
-- Store_header:set_respect(nil)
-- end
end
-------------------------------------------------------------------------------
-- Function store_weapon_upgrade_nav()
--
-- @param menu_data --data for currently selected item
--
-- Updates price and description for highlighted weapon
--
-------------------------------------------------------------------------------
function store_weapon_upgrade_nav(menu_data)
-- Show the weapon/upgrade price
if menu_data.price <= 0 then
Store_header:set_price(nil)
else
Store_header:set_price(menu_data.price)
end
-- Don't show respect
Store_header:set_respect(nil)
local current_weapon = Weapon_grid_data[Weapon_grid_idx]
local current_selection = Active_list:get_selection()
if current_weapon.num_costumes > 1 and current_selection == 2 then
store_weapon_populate_weapon_stats(menu_data.label_crc, Current_skin_name_crc, menu_data.upgrade_desc_crc)
else
store_weapon_populate_weapon_stats(menu_data.label_crc, nil, menu_data.upgrade_desc_crc)
end
end
function store_weapon_upgrade_purchase(weapon_data)
-- Now check if the player can purchase this weapon.
if weapon_data.is_purchased or weapon_data.is_locked then
return
end
--If we hit the customize option bring up list of costumes
if weapon_data.id == STORE_WEAPON_CUSTOMIZE_OPTION and Weapon_grid_data[Weapon_grid_idx].num_costumes > 1 then
store_weapon_upgrade_populate_costumes()
--Cover the weapon and stats until they're streamed in
store_weapon_cover_weapon(false)
return
end
local upgrade_idx = Active_list:get_selection()
if Store_common_player_cash >= weapon_data.price then
if Store_weapon_building_menu[upgrade_idx].level == weapon_data.max_level then
--Upgrade is at max level, show popup and return to upgrade list
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("STORE_WEAPON_UPGRADE_MAX_LEVEL")
Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
store_weapon_enable_mouse(false)
game_UI_audio_play("UI_HUD_HELP")
else
--Valid purchase
Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("MENU_TITLE_CONFIRM")
local insert = { [0] = weapon_data.label_crc, [1] = format_cash(weapon_data.price) }
local body = vint_insert_values_in_string("WPN_STORE_UPGRADE_PROMPT", insert)
Store_common_popup:set_text(body)
Store_common_popup:nav_enable(true, "store_weapon_upgrade_confirm", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
store_weapon_enable_mouse(false)
game_UI_audio_play("UI_HUD_HELP")
end
else
--Not enough funds
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_weapon_fail_msg", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
store_weapon_enable_mouse(false)
game_UI_audio_play("UI_HUD_HELP")
end
end
-------------------------------------------------------------------------------
-- Backing out from upgrade menu
--
function store_weapon_upgrade_back(menu_data)
if store_weapon_allow_grid_input() == false then
return
end
-- for thrown weapons, go back to the radial
if Weapon_grid_data.category == "thrown" then
store_weapon_grid_selected("back")
Current_tier = RADIAL_TIER
Restore_weapon_radial_inputs = true
else
-- save off currently highlighted weapon - otherwise it will get overwritten to the currently equipped weapon
local current_idx = Weapon_grid_idx
store_weapon_populate_weapon_grid(Weapon_grid_data.category, Current_slot)
-- Save of where we are in the flow
Store_weapon_menu_level = STORE_WEAPON_LEVEL_GRID
--input_data, current_option, max_width, max_height, button_w, button_h, hint_button_offset, current_category, outline_scale, background_enabled, show_current_button, grid_padding, set_size
Store_common_color_grid:draw_items(Weapon_grid_data, current_idx, 3, 3, 120, 100, 40, nil, nil, false)
Store_common_color_grid:set_visible(true)
Weapon_grid_idx = current_idx
Store_common_color_grid:nav_enable(true, "store_weapon_grid_selected", "store_weapon_grid_nav")
store_weapon_change_weapon_preview(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_current_info.dual_wield, Store_weapon_is_cache, Weapon_grid_data[Weapon_grid_idx].level, Store_weapon_current_info.costume_id, Store_weapon_current_info.skin_id, Store_weapon_current_info.store_name_crc)
store_weapon_populate_weapon_stats(nil, Current_costume_name_crc, Weapon_grid_data[Weapon_grid_idx].level_desc)
store_weapon_price_update()
Current_tier = WEAPON_TIER
Restore_weapon_radial_inputs = false
--Cover the weapon and stats until they're streamed in
store_weapon_cover_weapon(false)
end
-- Skip adding mouse_inputs in the next populate_list (see store_weapon_populate_list)
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
Skip_next_populate = true
end
Active_list:set_visible(false)
-- refresh the stats info
store_weapon_stats_update(-1, true, true)
store_lock_controls()
store_unlock_controls()
end
-------------------------------------------------------------------------------
-- Populate list with weapon costumes
--
function store_weapon_upgrade_populate_costumes()
Store_weapon_menu_level = STORE_WEAPON_LEVEL_COSTUME
Store_weapon_building_menu = { }
vint_dataresponder_request("store_weapon_populate_costumes", "store_weapon_costume_add_items", 0, Weapon_grid_data.category, Store_weapon_current_info.id)
--Find our current costume for initial selection
local current_weapon = Weapon_grid_data[Weapon_grid_idx]
store_common_push_menu(Store_weapon_building_menu)
--Override the titles coming from store_common
Store_header:pop_title()
Store_header:push_title(nil, "MENU_STYLE")
--Update the description and title to the highlighted costume
store_weapon_costume_nav()
local current_selection = Active_list:get_selection()
Weapon_grid_data[Weapon_grid_idx].costume_desc_crc = Store_weapon_building_menu[current_selection].costume_desc_crc
end
-------------------------------------------------------------------------------
-- Function store_weapon_costume_add_items()
--
-- Builds costume/skins table
--
-- @param id -- id for costume or skin
-- @param label_crc -- name of costume
-- @param costume_desc_crc -- description for costume
-- @param is_costume -- determines if item is a costume or skin
-- @param is_equipped -- is the costume equipped?
-- @param is_dlc -- is the costume part of dlc
--
-------------------------------------------------------------------------------
function store_weapon_costume_add_items( id, label_crc, costume_desc_crc, is_costume, is_equipped, is_dlc )
local menu_idx = #Store_weapon_building_menu + 1
local new_item
-- Determine if we're a skin or costume
-- If starting a new costume, add a header
if is_costume == true then
Costume_id = id
Store_weapon_parsed_costume_name_crc = label_crc
Store_weapon_parsed_costume_desc_crc = costume_desc_crc
new_item = {
type = TYPE_HEADER,
is_costume = is_costume,
label_crc = label_crc,
costume_id = Costume_id,
is_dlc = is_dlc,
}
else
-- Find the crc for the "default" skin
-- Only need to do this once
if Store_weapon_default_crc == -1 then
Store_weapon_default_crc = label_crc
end
new_item = {
type = TYPE_BUTTON,
costume_id = Costume_id,
skin_id = id,
label_crc = label_crc,
costume_desc_crc = costume_desc_crc,
on_nav = store_weapon_costume_nav,
on_select = store_weapon_costume_purchase,
on_cancel = store_weapon_costume_revert,
default_costume_name_crc = Store_weapon_parsed_costume_name_crc,
default_costume_desc_crc = Store_weapon_parsed_costume_desc_crc,
is_dlc = is_dlc,
}
end
Store_weapon_building_menu[menu_idx] = new_item
-- Find our current costume for initial selection
local current_costume_id = Weapon_grid_data[Weapon_grid_idx].costume_id
local current_skin_id = Weapon_grid_data[Weapon_grid_idx].skin_id
if current_costume_id == Costume_id and current_skin_id == id then
Store_weapon_building_menu.start_index = menu_idx
end
menu_idx = #Store_weapon_building_menu + 1
end
-------------------------------------------------------------------------------
-- Function store_weapon_costume_revert()
--
-- Pops store header title added by store_common, resets list back to
-- upgrades with the costume highlighted, and reverts any costume changes.
--
-------------------------------------------------------------------------------
function store_weapon_costume_revert()
Store_header:pop_title()
store_weapon_upgrade_refresh(2)
--Cover the weapon and stats until they're streamed in
store_weapon_cover_weapon(false)
end
-------------------------------------------------------------------------------
-- Function store_weapon_costume_nav()
--
-- Handle navigation for cosutmes. Updates the costume and description.
--
-------------------------------------------------------------------------------
function store_weapon_costume_nav()
--Get highlighted costume id
local current_idx = Active_list:get_selection()
--Get highlighted costume info
local current_item = Store_weapon_building_menu[current_idx]
--Change the weapon model
store_weapon_change_weapon_preview(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_current_info.dual_wield, Store_weapon_is_cache, -1, current_item.costume_id, current_item.skin_id, current_item.store_name_crc)
--Update description
store_weapon_populate_weapon_stats(current_item.label_crc, nil, current_item.costume_desc_crc)
end
-------------------------------------------------------------------------------
-- Set the costume of the current weapon
--
function store_weapon_costume_purchase(event)
local current_idx = Active_list:get_selection()
local current_item = Store_weapon_building_menu[current_idx]
--Update costume id
Store_weapon_current_info.costume_id = current_item.costume_id
--Tell code the new costume
store_weapon_set_costume(Weapon_grid_data.category, Store_weapon_current_info.id, current_item.costume_id)
--Select costume
store_weapon_purchase_weapon(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_is_cache, 0)
--Update current costume name and description
Current_costume_name_crc = current_item.default_costume_name_crc
Current_costume_desc_crc = current_item.default_costume_desc_crc
--Update the current skin name. Set it to blank if it's default
if current_item.label_crc ~= Store_weapon_default_crc then
Current_skin_name_crc = current_item.label_crc
else
Current_skin_name_crc = nil
end
--Update costume name for this category
Weapon_grid_data[Weapon_grid_idx].costume_name_crc = Current_costume_name_crc
--Save off skin id
Weapon_grid_data[Weapon_grid_idx].skin_id = current_item.skin_id
--Pop "STYLE" title
Store_header:pop_title()
--Refresh upgrades/style menu
store_weapon_upgrade_refresh()
--Cover the weapon and stats until they're streamed in
store_weapon_cover_weapon(false)
--Pop current selection title that store common pushes after we draw a new menu
Store_header:pop_title()
end
-------------------------------------------------------------------------------
-- Backing out from costumes and skins
--
function store_weapon_upgrade_customize_revert()
--store_weapon_upgrade_show(Weapon_grid_data.category, Store_weapon_current_info.id)
end
-- Confirm purchase of a weapon/upgrade
--
function store_weapon_grid_confirm(event)
store_weapon_enable_mouse(true)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
Store_weapon_not_bg_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" or Store_common_popup:get_selected_data() ~= 1 then
store_weapon_grid_refresh()
return
end
game_UI_audio_play("UI_Main_Menu_Select")
--Purchase weapon
store_weapon_purchase_weapon(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_is_cache, Store_weapon_current_info.price)
--Update game inventory
game_hud_update_inventory()
-- Update GSI if in mission
if Store_weapon_in_mission and Weapon_gsi_is_updated == false then
--Store_common_gsi:update("MM_1_1_OBJ_PURCHASE_AN_UPGRADE", "ui_target_icon_use")
--don't call this again once it's updated
Weapon_gsi_is_updated = true
end
--Play weapon purchase audio
ui_audio_post_event("weapon_purchase")
--Continue to upgrade/costume flow
store_weapon_upgrade_show(Weapon_grid_data.category, Store_weapon_current_info.id)
-- Update GSI if in mission
if Store_weapon_in_mission then
Store_common_gsi:update("MM_1_1_OBJ_EXIT_STORE", "ui_target_icon_use")
--don't call this again once it's updated
Upgrade_gsi_is_updated = true
end
--[[
-- Need to refresh the mega list
Store_weapon_building_menu = {}
vint_dataresponder_request("store_weapon_populate_upgrades", "store_weapon_upgrade_add_items", 0, Weapon_grid_data.category, Store_weapon_current_info.id)
-- This is necessary to "reload" the ammo purchases for thrown weapons
vint_dataresponder_request("store_weapon_populate_ammo", "store_common_do_nothing", 0)
ui_audio_post_event("weapon_purchase")
-- do this so holding down the button doesn't cause repeated actions
Input_tracker:subscribe(false)
Input_tracker:subscribe(true)
]]--
end
-- Weapon cache ******************************************************************************************
-- Open the weapon cache radial menu
--
function store_weapon_cache_open_radial(menu_data)
Store_weapon_menu_category = STORE_WEAPON_CATEGORY_WEAPON_CACHE
Active_list:set_visible(false)
Store_weapon_is_cache = true
debug_print("store_weapon", "called store_weapon_cache_open_radial\n")
-- Set the callback to use when the user selects a cateogory from the radial menu
Store_weapon_inventory.selected_cb = store_weapon_grid_open
Store_weapon_inventory.nav_cb = store_weapon_cache_nav
-- Disable the unarmed slot
Store_weapon_radial:slot_disable(0)
-- Hide grenades for weapon cache
Store_weapon_radial:show_dpad_menu(false)
Store_weapon_radial:set_anchor(Radial_store_x,Radial_y)
-- Enable or disable slots based on availability
for i = 1, 7 do
-- Initialize data for grid
Weapon_grid_data = {}
local category = Store_weapon_categories[i].category
vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category)
-- If there are no choices, then disable
if #Weapon_grid_data == 0 then
Store_weapon_radial:slot_disable(i)
else
Store_weapon_radial:slot_enable(i)
end
end
-- Open the radial menu
store_weapon_inventory_show(menu_data)
-- Set the hint based on the platform
local hint_data = {}
if game_get_platform() == "PC" then
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
else
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"},
--{CTRL_BUTTON_DPAD, "STORE_WEAPON_NAVIGATE"},
}
end
Store_common_hint_bar:set_hints(hint_data)
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:subscribe(true)
end
end
function store_weapon_cache_nav(slot_id)
store_weapon_stats_update(slot_id, false, true)
store_weapon_cover_weapon(true)
end
--Updates the Weapon Radial Menu VDO
function store_weapon_radial_update(di_h)
Store_weapon_radial:slots_update(di_h)
-- May be needed to update ammo totals
--Store_weapon_radial:weapon_highlight(-1, true, true)
end
-- Stuff copied from HUD script for weapon radial ********************************************************
--Input handling for the radial
function store_weapon_inventory_input(event, value)
if event == "inventory" then
-- nothing
elseif event == "select" then
-- A/accept button pushed, do callback for appropriate category
local slot = Store_weapon_radial:get_selected_slot()
Store_weapon_inventory.selected_cb(slot)
game_UI_audio_play("UI_Main_Menu_Select")
elseif event == "back" then
-- B/cancel button pushed, close radial menu
-- If we came from the crib, we need to pop this doc off the stack
if Store_weapon_loaded_from_crib then
store_weapon_exit()
else
store_weapon_cancel_radial()
end
if Radial_mouse_input_tracker ~= nil then
Radial_mouse_input_tracker:subscribe(false)
end
elseif event == "inventory_x" then
--Move Analog Stick X
if Store_weapon_inventory.x ~= value then
Store_weapon_inventory.x = value
Store_weapon_inventory.stale = true
end
elseif event == "inventory_y" then
--Move Analog Stick Y
if Store_weapon_inventory.y ~= value then
Store_weapon_inventory.y = value
Store_weapon_inventory.stale = true
end
elseif( event == "pause" ) then
-- Allow pause in the radial view
dialog_open_pause_display()
elseif Store_weapon_is_cache == false then
local slot = 0
if event == "inventory_up" and value > INVENTORY_DPAD_THRESHOLD then
slot = 8
elseif event == "inventory_right" and value > INVENTORY_DPAD_THRESHOLD then
slot = 9
elseif event == "inventory_down" and value > INVENTORY_DPAD_THRESHOLD then
slot = 10
elseif event == "inventory_left" and value > INVENTORY_DPAD_THRESHOLD then
slot = 11
end
-- Only highlight the slot if it isn't disabled
if slot ~= 0 and Store_weapon_radial:slot_is_disabled(slot) ~= true then
Store_weapon_radial:weapon_highlight(slot)
-- Initialize data for grid
Weapon_grid_data = {}
Weapon_grid_idx = 1
-- Get the category name string for the chosen slot.
local category = Store_weapon_categories[slot].category
vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_thrown_items", 0, Store_weapon_is_cache, category, slot - 8)
-- If there are no choices, don't show weapon stats
if #Weapon_grid_data ~= 0 then
store_weapon_populate_weapon_stats()
end
-- Call navigation callback
if Store_weapon_inventory.nav_cb ~= nil then
Store_weapon_inventory.nav_cb(slot)
end
end
end
end
-- Input handling for slots
function store_weapon_inventory_show(menu_data)
--game_store_weapon_update_inventory()
Current_tier = RADIAL_TIER
-- Disable menu input.
store_lock_controls()
-- Set the titles on top; if menu_data is nil, that is because we are only returning to the radial from the weapons grid,
-- and we don't need to add a title because they are already there.
if menu_data ~= nil then
local title = nil
local title_crc = nil
title_crc = menu_data.label_crc
if title_crc == nil then
title = menu_data.label
end
Store_header:push_title( title_crc, title )
end
if Store_weapon_inventory.thread == nil then
--Show Inventory
Store_weapon_radial:show(true)
--Reset visual analog stick and get the proper text tag on it.
Store_weapon_inventory.x = 0
Store_weapon_inventory.y = 0
if Store_weapon_loaded_from_crib == false then
--Subscribe to input
store_weapon_unlock_radial()
end
--Highlight Currently equipped slots
local selected_slot = Store_weapon_radial:get_selected_slot()
if selected_slot < 0 or selected_slot >= 12 then
selected_slot = 0
end
if Store_weapon_radial:slot_is_disabled(selected_slot) then
selected_slot = 0
end
--Disable grenades for 3.5 since we have "powers" now
if selected_slot >= 8 then
selected_slot = 0
end
--Walk through weapon radial to find first enabled slot
while Store_weapon_radial:slot_is_disabled(selected_slot) and selected_slot < 11 do
selected_slot = selected_slot + 1
end
if selected_slot >= 8 then
-- hide everything and show popup
Store_weapon_radial:set_visible(false)
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_NO_WEAPONS")
Store_common_popup:nav_enable(true, "store_weapon_no_weapons", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
Store_common_popup:set_visible(true)
game_UI_audio_play("UI_HUD_HELP")
Slot_stats_grp:set_visible(false)
Store_weapon_cache_no_weapons = true
return
end
Store_weapon_radial:weapon_highlight(selected_slot, true)
Store_weapon_radial:stick_update_position(0, 0)
Store_weapon_radial:stick_update_tag()
Store_weapon_radial:stick_arrow_reset()
Store_weapon_inventory.thread = thread_new("store_weapon_inventory_process")
-- Preview the model of the selected weapon
if selected_slot >= 1 then
local selected_cat_index = selected_slot - 1
-- Initialize data for grid
Weapon_grid_data = {}
Weapon_grid_idx = 1
-- Get the category name string for the chosen slot.
local category = Store_weapon_categories[selected_slot].category
if category == "thrown" == true then
vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_thrown_items", 0, Store_weapon_is_cache, category, selected_slot - 8)
else
vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category)
end
-- If there are no choices, don't show weapon stats
if #Weapon_grid_data ~= 0 then
store_weapon_populate_weapon_stats()
end
-- Call navigation callback
if Store_weapon_inventory.nav_cb ~= nil then
Store_weapon_inventory.nav_cb(selected_slot)
end
end
end
-- Set the hint based on the platform
local hint_data = {}
if game_get_platform() == "PC" then
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
if Radial_mouse_input_tracker ~= nil then
-- Also add inputs for the weapon radial
Store_weapon_radial:add_mouse_inputs("store_weapon", Radial_mouse_input_tracker, 50)
Radial_mouse_input_tracker:subscribe(true)
end
else
if Store_weapon_is_cache == true then
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"},
}
else
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"},
}
end
end
Store_common_hint_bar:set_hints(hint_data)
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:subscribe(true)
end
end
function store_weapon_inventory_hide()
-- Enable menu controls
store_unlock_controls()
-- if aborted == false then
-- Store_weapon_radial:game_equip_selected_slots()
-- end
--Hide Radial Menu
Store_weapon_radial:show(false)
store_weapon_lock_radial()
if Store_weapon_inventory.thread ~= nil then
Store_weapon_inventory.extra_buttons = nil
thread_kill(Store_weapon_inventory.thread)
Store_weapon_inventory.thread = nil
end
end
-- Radial input handling
function store_weapon_inventory_process()
while true do
if Store_weapon_inventory.stale == true then
local x = Store_weapon_inventory.x
local y = Store_weapon_inventory.y
local selected_weapon_index = 0
local mag = sqrt((x * x) + (y * y))
local pi = 3.14159
if mag > 0.5 then
-- Y resolves out so don't bother with it
x = x/mag
local radians = acos(x)
if y < 0.0 then
radians = pi + (pi - radians)
end
local eighth = pi / 8
local fourth = pi / 4
local selected_weapon_index = 0
if radians < eighth then
selected_weapon_index = 2;
elseif radians < (fourth + eighth) then
selected_weapon_index = 1
elseif radians < (2.0 * fourth + eighth) then
selected_weapon_index = 0
elseif radians < (3.0 * fourth + eighth) then
selected_weapon_index = 7
elseif radians < (4.0 * fourth + eighth) then
selected_weapon_index = 6
elseif radians < (5.0 * fourth + eighth) then
selected_weapon_index = 5
elseif radians < (6.0 * fourth + eighth) then
selected_weapon_index = 4;
elseif radians < (7.0 * fourth + eighth) then
selected_weapon_index = 3;
else
selected_weapon_index = 2;
end
-- Only highlight the slot if it isn't disabled
if Store_weapon_radial:slot_is_disabled(selected_weapon_index) ~= true and selected_weapon_index >= 1 then
-- Call navigation callback
if Store_weapon_inventory.nav_cb ~= nil then
Store_weapon_inventory.nav_cb(selected_weapon_index)
end
Store_weapon_radial:weapon_highlight(selected_weapon_index)
-- Initialize data for grid
Weapon_grid_data = {}
Weapon_grid_idx = 1
-- Get the category name string for the chosen slot.
local category = Store_weapon_categories[selected_weapon_index].category
if category == "thrown" == true then
vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_thrown_items", 0, Store_weapon_is_cache, category)
else
vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category)
end
-- If there are no choices, don't show weapon stats
if #Weapon_grid_data ~= 0 then
store_weapon_populate_weapon_stats()
end
end
Store_weapon_radial:stick_update_arrow(radians)
end
--Update Stick location on radial menu
Store_weapon_radial:stick_update_position(Store_weapon_inventory.x, Store_weapon_inventory.y)
Store_weapon_inventory.stick_mag = mag
Store_weapon_inventory.stale = false
end
thread_yield()
end
end
function store_weapon_image_update()
delay(0.2)
if Store_weapon_unload_img ~= nil then
Reward_image:set_visible(false)
game_peg_unload(Store_weapon_unload_img)
end
if Store_weapon_loading_img ~= nil then
game_peg_load_with_cb("store_weapon_show_image", 1, Store_weapon_loading_img)
end
Store_weapon_img_update_thread = -1
end
-- Callback for when an image is done loading.
-- SEH: It might make sense to roll this into vdo_bitmap_viewer...
--
function store_weapon_show_image()
local new_image = Store_weapon_new_image
local img_scale_x = 1.0
local img_scale_y = 1.0
if Store_weapon_loading_img == new_image and Store_weapon_loading_img ~= Store_weapon_unload_img then
Reward_image:set_image(new_image, false, true, 0, 0, img_scale_x, img_scale_y, nil)
if game_peg_is_loaded(new_image) then
Reward_image:set_visible(true)
end
--Store_weapon_unload_img = Store_weapon_loading_img
--Store_weapon_loading_img = nil
else
-- a new image was picked while we were loading - load this now, and unload the one we just loaded
if new_image ~= nil then
Reward_image:set_visible(false)
Store_weapon_unload_img = Store_weapon_loading_img
Store_weapon_loading_img = new_image
Store_weapon_img_update_thread = thread_new("store_weapon_image_update")
else
Reward_image:set_visible(false)
game_peg_unload(Store_weapon_loading_img)
Store_weapon_loading_img = nil
end
end
end
function store_weapon_change_weapon_preview(category, id, dual_wield, is_cache, upgrade_level, costume, skin, img_crc)
--Flag that we are previewing the weapon so we can revert back to equipped weapon if player is forced out of the store
Store_weapon_skin_was_previewed = true
local immediate = false
if costume == nil then
costume = -1
end
-- Tell C to replace model
local loading = store_weapon_change_weapon(category, id, dual_wield, is_cache, upgrade_level, costume, skin, immediate)
-- If we're only doing an upgrade swap, we don't need to lock grid input
if loading == true then
-- lock input until the swap is done
Store_weapon_is_loading = true
--store_weapon_cover_weapon(false)
--store_weapon_uncover_weapon(false)
if img_crc ~= nil then
Store_weapon_new_image = img_crc
store_weapon_show_image()
else
Reward_image:set_visible(false)
end
end
end
function store_weapon_allow_grid_input()
return Store_weapon_is_loading == false
end
-- =====================================
-- Notoriety Wipe
-- =====================================
function store_weapon_main_menu_nav()
local menu_idx = Active_list:get_selection()
local player_notoriety_level = vint_get_player_notoriety();
if player_notoriety_level > 6 then
player_notoriety_level = 6
end
if menu_idx == 1 then
if player_notoriety_level > 0 then
Store_header:set_price(Notoriety_level_clear_cost_data[player_notoriety_level].cost)
else
Store_header:set_price(nil)
end
else
Store_header:set_price(nil)
end
end
function store_weapon_notoriety_cost_update( level_cost )
local cost_index = #Notoriety_level_clear_cost_data + 1
Notoriety_level_clear_cost_data[cost_index] = {
cost = level_cost
}
end
function store_weapon_wipe_notoriety()
local player_notoriety_level = vint_get_player_notoriety();
if player_notoriety_level > 6 then
player_notoriety_level = 6
end
if mission_is_active() and game_is_prologue_complete() 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("MAP_EVENT_NOTO") -- Going to need new string for missions
Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
game_UI_audio_play("UI_HUD_HELP")
store_weapon_enable_mouse(false)
return
end
-- Check if we have any notoriety, and enough money.
if player_notoriety_level > 0 then
if Store_common_player_cash >= Notoriety_level_clear_cost_data[player_notoriety_level].cost then
--Valid purchase
Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("MENU_TITLE_CONFIRM")
local insert = { [0] = format_cash(Notoriety_level_clear_cost_data[player_notoriety_level].cost) }
local body = vint_insert_values_in_string("WPN_STORE_WIPE_NOTO_PROMPT", insert)
Store_common_popup:set_text(body)
Store_common_popup:nav_enable(true, "store_weapon_notoriety_wipe_confirm", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
store_weapon_enable_mouse(false)
game_UI_audio_play("UI_HUD_HELP")
return
else
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_weapon_fail_msg", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
game_UI_audio_play("UI_HUD_HELP")
store_weapon_enable_mouse(false)
return
end
else
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("WPNSTORE_TEXT_NO_NOTORIETY") -- Going to need new string for no notoriety
Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
game_UI_audio_play("UI_HUD_HELP")
store_weapon_enable_mouse(false)
return
end
end
function store_weapon_notoriety_wipe_confirm(event)
store_weapon_enable_mouse(true)
Store_common_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
Store_weapon_not_bg_grp:set_alpha(1)
-- The user hit the B button and are cancelling the purchase
-- This is the same as selecting "No" in the list
if event == "back" or Store_common_popup:get_selected_data() ~= 1 then
return
end
local player_notoriety_level = vint_get_player_notoriety();
local cost = 0;
if player_notoriety_level > 0 then
cost = Notoriety_level_clear_cost_data[player_notoriety_level].cost
end
local saved_cash = Store_common_player_cash
-- Make the purchase.
vint_notoriety_reset("police", cost);
Store_header:set_price(nil)
--play the purchase sound
ui_audio_post_event("ammo_purchase")
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("WPNSTORE_TEXT_NOTORIETY_RESET_SUCCESS")
Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav")
Not_popup_grp:set_alpha(.5)
Store_weapon_not_bg_grp:set_alpha(.5)
store_weapon_enable_mouse(false)
end
-- =====================================
-- Mouse Specific Functions
-- =====================================
function store_weapon_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
if enable == false then
if Radial_mouse_input_tracker ~= nil then
Radial_mouse_input_tracker:subscribe(false)
end
end
end
end
function store_weapon_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
store_common_button_b()
elseif Current_tier == LEVEL_TIER then
store_common_button_b()
elseif Current_tier == RADIAL_TIER then
store_weapon_inventory_input("back")
elseif Current_tier == WEAPON_TIER or Current_tier == GRENADE_UPGRADE_TIER then
store_weapon_grid_selected("back")
end
end
local weapon_index = Store_weapon_radial:get_slot_index(target_handle)
if weapon_index ~= 0 and weapon_index < 8 then
-- Highlight the correct weapon, and select it
Store_weapon_radial:weapon_highlight(weapon_index)
store_weapon_inventory_input("select")
end
end
function store_weapon_mouse_move(event, target_handle)
-- Reset all highlights
Store_common_hint_bar:set_highlight(0)
-- Check if the mouse is over the hint bar buttons
local hint_index = Store_common_hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
Store_common_hint_bar:set_highlight(hint_index, Store_common_current_highlight_color)
return
end
-- Check if the mouse is over a button on the mega list
local old_index = Active_list:get_selection()
local new_index = Active_list:get_button_index(target_handle)
if new_index ~= 0 and new_index ~= old_index then
Active_list:set_selection(new_index)
Active_list:move_cursor(0, true)
-- 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
local weapon_index = Store_weapon_radial:get_slot_index(target_handle)
if weapon_index ~= 0 and Old_index ~= weapon_index then
-- Only highlight the slot if it isn't disabled
if Store_weapon_radial:slot_is_disabled(weapon_index) ~= true and weapon_index>= 1 then
-- Call navigation callback
if Store_weapon_inventory.nav_cb ~= nil then
Store_weapon_inventory.nav_cb(weapon_index)
end
Store_weapon_radial:weapon_highlight(weapon_index, true, true)
-- Initialize data for grid
Weapon_grid_data = {}
Weapon_grid_idx = 1
-- Get the category name string for the chosen slot.
local category = Store_weapon_categories[weapon_index].category
if category == "thrown" == true then
vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_thrown_items", 0, Store_weapon_is_cache, category)
else
vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category)
end
-- If there are no choices, don't show weapon stats
if #Weapon_grid_data ~= 0 then
store_weapon_populate_weapon_stats()
end
Old_index = weapon_index
end
end
end
function store_weapon_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_weapon_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_weapon_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