STORE_WEAPON_INVALID_INDEX = -1
STORE_WEAPON_INVALID_INDEX = -1
SCALE_FONT_STORE_WEAPON_LIST = 0.8
local STORE_WEAPON_RADIAL_CACHE_X = 320
local STORE_WEAPON_RADIAL_CACHE_SD_X = 260
local STORE_WEAPON_RADIAL_STORE_X = 260
local STORE_WEAPON_RADIAL_STORE_SD_X = 245
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
Store_weapon_doc_handle = -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 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
-- 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 = {}
-- 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
-- Used to track weapon radial input and state
Store_weapon_inventory = {
stick_mag = 0,
is_pressed = false,
selected_cb = nil,
nav_cb = nil
}
-- 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
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 = {} },
}
---------------------------------------------------------------------------
-- 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)
if Store_weapon_loaded_from_crib then
Weapon_store_highlight_color = COLOR_STORE_REWARDS_PRIMARY
else
Weapon_store_highlight_color = COLOR_STORE_WEAPON_PRIMARY
end
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, "STORE_ZOOM_ROTATE"},
-- }
-- Hint_bar_rotate:set_hints(hint_rotate_data)
-- Hint_bar_rotate:set_visible(true)
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)
-- Setup weapon stats
Weapon_stats_grp = Vdo_base_object:new("weapon_stats_grp", 0, Store_weapon_doc_handle)
Weapon_stats_grp:set_visible(false)
local gsi_grp = Vdo_base_object:new("gsi_grp",0, Store_weapon_doc_handle)
gsi_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
--Store_header:reformat_and_resize(false,306)
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 Saints background for future use
--Weapon_bg_grp = Vdo_base_object:new("crib_bg_grp", 0, Bg_saints_doc_handle)
-- Get reference to the weapon store background for future use
Weapon_bg_grp = Vdo_base_object:new("bg_grp", 0, Store_weapon_doc_handle)
local bg_gradient_top_h = vint_object_find("bg_gradient_top",0,Store_weapon_doc_handle)
--vint_set_property(bg_gradient_top_h,"visible",true)
-- 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"},
{CTRL_BUTTON_DPAD, "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
--store_weapon_cache_open_radial()
-- 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)
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(Weapon_store_highlight_color)
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_CENTER,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
Menu_data = {
on_cancel = store_weapon_cancel_radial,
[1] = { label = "STORE_WEAPON_AMMO", type = TYPE_BUTTON, on_select = store_weapon_ammo_open_radial },
[2] = { label = "STORE_WEAPON_BUY_UPGRADE", type = TYPE_BUTTON, on_select = store_weapon_purchase_open_radial },
[3] = { label = "STORE_WEAPON_CACHE", type = TYPE_BUTTON, on_select = store_weapon_cache_open_radial },
[4] = { label = "STORE_EXIT", type = TYPE_BUTTON, on_select = store_weapon_exit },
}
-- Are we in mission 3? Show GSI and fade out logo_grp
if cell_is_mission_complete("m03") == false then
Store_weapon_in_mission = true
end
local gsi_grp = Vdo_base_object:new("gsi_grp",0, Store_weapon_doc_handle)
local obj_txt = Vdo_base_object:new("obj_txt", 0, Store_weapon_doc_handle)
local gsi_bg = Vdo_base_object:new("gsi_bg", 0, Store_weapon_doc_handle)
local logo_grp = Vdo_base_object:new("logo_grp", 0, Store_weapon_doc_handle)
if Store_weapon_in_mission then
obj_txt:set_text("M03_OBJ_PURCHASE_AN_UPGRADE")
local obj_txt_x, obj_txt_y = obj_txt:get_anchor()
local obj_txt_width, obj_txt_height = element_get_actual_size(obj_txt.handle)
local gsi_bg_width, gsi_bg_height = element_get_actual_size(gsi_bg.handle)
element_set_actual_size(gsi_bg.handle, obj_txt_x + obj_txt_width + 5, gsi_bg_height)
logo_grp:set_alpha(.35)
gsi_grp:set_visible(true)
else
gsi_grp:set_visible(false)
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)
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)
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_grp", 0, Store_weapon_doc_handle)
Current_tier = MENU_TIER
store_weapon_cover_weapon(false)
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")
end
function store_weapon_intro_anim_complete()
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
-- 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()
-- 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()
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()
-- 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)
-- 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
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)
debug_print("vint", "new_index "..new_index.."old idx "..Old_index.."\n\n")
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)
Weapon_grid_idx = 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
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 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
-- Populate the active megalist menu, and hide the previous menu
--
-- list_data: this table contains the data to populate the megalist
-- current_index: the current index in the menu that's selected
--
function store_weapon_populate_list(list_data, current_index)
-- override the mega list width for standard def STORE_COMMON_LIST_SIZE
Active_list:draw_items(list_data, current_index, STORE_COMMON_LIST_SIZE, 10, SCALE_FONT_STORE_WEAPON_LIST)
--Active_list:set_visible(true)
--local hint_data = {
-- {CTRL_MENU_BUTTON_B, "MENU_BACK"},
--}
--Store_common_hint_bar:set_hints(hint_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
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()
Current_tier = MENU_TIER
end
-- Ammo purchasing ******************************************************************************************
-- Open the ammo purchasing radial menu.
--
function store_weapon_ammo_open_radial(menu_data)
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)
-- Show grenades
Store_weapon_radial:show_dpad_menu(true)
Store_weapon_radial:set_anchor(Radial_store_x,395)
-- Disable any slots where we can't buy ammo
for i = 2, 7 do
local ammo_info = store_weapon_ammo_find_by_id(i)
if ammo_info == nil 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)
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
-- 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 ammo_txt = Vdo_base_object:new("ammo_text", 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 = 1
local WEAPON_TXT_BUFFER_SD = 10
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
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
-- Note: incrementing weapon level because code uses base 0
if info.equipped == true then
local color = "[format][color:#B8492F]"
if Store_weapon_loaded_from_crib then
color = "[format][color:#9400c5]"
end
insert_values = {[0] = info.label, [1] = info.level + 1, [2] = color }
body = vint_insert_values_in_string("STORE_WEAPON_OWNED_EQUIPPED", insert_values)
--body = vint_insert_values_in_string("{0} !!LEVEL {1} [format][color:#B8492F](!!EQUIPPED)[/format]", insert_values)
else
insert_values = {[0] = info.label, [1] = info.level + 1}
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()
new_y = new_y + Weapon_txt_buffer * 2
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
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)
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"},
{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
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)
-- Show grenades
Store_weapon_radial:show_dpad_menu(true)
Store_weapon_radial:set_anchor(Radial_store_x,395)
-- 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
-- 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, 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
-- Purchase or upgrade weapons from the radial menu.
--
-- slot: the slot number chosen in the radial menu.
--
function store_weapon_grid_open(slot)
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 = {}
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_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
store_weapon_grid_populate_weapon_stats(Weapon_grid_idx)
-- set the titles on top
Store_header:push_title( nil, Store_weapon_categories[slot].label )
-- 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")
--Weapon_stats_grp:set_visible(true)
-- 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)
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
Store_common_hint_bar:set_hints(hint_data)
-- Get the currently selected weapon info
local idx = Store_common_color_grid:return_selected_index()
local weapon_info = Weapon_grid_data[idx]
-- 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)
-- 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
-- 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
function store_weapon_grid_populate_weapon_stats(idx)
-- Get the currently selected weapon info
local weapon_info = Weapon_grid_data[idx]
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)
local level_desc = Vdo_base_object:new("level_desc", 0, Store_weapon_doc_handle)
if vint_is_std_res() then
level_desc:set_property("wrap_width",340)
end
-- Display weapon stats
weapon_title:set_text(weapon_info.label)
local insert = { [0] = Weapon_grid_data[idx].level + 1 }
local body = vint_insert_values_in_string("STORE_WEAPON_LEVEL", insert)
weapon_level:set_text(body)
level_desc:set_text_crc(weapon_info.level_desc)
--Weapon_stats_grp:set_visible(true)
end
function store_weapon_cover_weapon(show_slot_stats)
-- make background so it covers the weapon
Weapon_bg_grp:set_property("background", false)
bg_saints_set_background(false)
-- this should be the situations when we don't want to show stats too
Weapon_stats_grp:set_visible(false)
Slot_stats_grp:set_visible(show_slot_stats and Stats_initialized)
-- SEH: 6/28/11: cut zoom/rotate
-- 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)
-- determine if we're at the grid or upgrade level
if Store_common_color_grid:get_visible() == true then
local idx = Weapon_grid_idx
if idx ~= nil and idx >= 1 then
store_weapon_grid_populate_weapon_stats(idx)
end
else
-- Show the correct stats/description
store_weapon_upgrade_populate_weapon_stats(Store_weapon_current_info.level, Store_weapon_current_info.desc)
end
Slot_stats_grp:set_visible(false)
-- SEH: 6/28/11: cut zoom/rotate
-- Show zoom/rotate hint
--Hint_bar_rotate:set_visible(true)
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)
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,
}
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)
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,
}
--Store_weapon_categories[slot].info = Weapon_grid_data[grid_idx]
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
local weapon_info = Weapon_grid_data[Store_common_color_grid:get_selection()]
-- 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()
-- 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)
-- 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
-- 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)
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()
-- And hide the weapon as well
--store_weapon_hide_weapon()
-- 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)
--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
Current_tier = RADIAL_TIER
end
end
function store_weapon_upgrade_show(category, id)
Active_list:set_visible(true)
-- Get data to populate the megalist
Store_weapon_building_menu = {}
vint_dataresponder_request("store_weapon_populate_upgrades", "store_weapon_upgrade_add_items", 0, category, id)
store_common_push_menu(Store_weapon_building_menu)
-- Show the correct stats/description
local start_index = Store_weapon_building_menu.start_index or 1
store_weapon_upgrade_populate_weapon_stats(start_index, Store_weapon_building_menu[start_index].level_desc)
Current_tier = LEVEL_TIER
end
function store_weapon_upgrade_add_items(desc_crc, price, is_purchased, is_locked)
local menu_idx = #Store_weapon_building_menu + 1
local insert = { [0] = menu_idx}
local body = vint_insert_values_in_string("STORE_WEAPON_LEVEL", insert)
local new_item = {
type = TYPE_BUTTON,
id = #Store_weapon_building_menu,
level_desc = desc_crc,
label = body,
is_purchased = is_purchased,
is_locked = is_locked,
price = price,
on_nav = store_weapon_upgrade_nav,
on_select = store_weapon_upgrade_purchase,
on_cancel = store_weapon_upgrade_revert,
}
Store_weapon_building_menu[menu_idx] = new_item
if is_purchased == true and is_locked == false then
Store_weapon_building_menu.start_index = menu_idx
-- Show the weapon/upgrade price
if price == 0 then
Store_header:set_price(nil)
else
Store_header:set_price(price)
end
Store_header:set_respect(nil)
end
end
function store_weapon_upgrade_nav(menu_data)
-- Preview the model of the selected weapon at the right upgrade level
store_weapon_change_weapon_preview(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_current_info.dual_wield, Store_weapon_is_cache, menu_data.id)
Store_weapon_current_info.level = menu_data.id + 1
Store_weapon_current_info.desc = menu_data.level_desc
-- Show the correct stats/description
--store_weapon_upgrade_populate_weapon_stats(menu_data.id + 1, menu_data.level_desc)
-- 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
Store_header:set_respect(nil)
end
function store_weapon_upgrade_populate_weapon_stats(level, level_desc_crc)
local weapon_level = Vdo_base_object:new("weapon_level", 0, Store_weapon_doc_handle)
local level_desc = Vdo_base_object:new("level_desc", 0, Store_weapon_doc_handle)
--debug_print("store_weapon","setting weapon level desc to "..level_desc_crc.."\n")
if vint_is_std_res() then
level_desc:set_property("wrap_width",340)
end
-- Display weapon stats
local insert = { [0] = level }
local body = vint_insert_values_in_string("STORE_WEAPON_LEVEL", insert)
weapon_level:set_text(body)
level_desc:set_text_crc(level_desc_crc)
--vint_set_property(weapon_level, "text_tag", body)
--vint_set_property(level_desc_h, "text_tag_crc", level_desc_crc)
--Weapon_stats_grp:set_visible(true)
end
function store_weapon_upgrade_purchase(menu_data)
-- Now check if the player can purchase this weapon.
if menu_data.is_purchased or menu_data.is_locked then
return
end
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_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_revert(menu_data)
-- 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)
--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_grid_populate_weapon_stats(Weapon_grid_idx)
Current_tier = WEAPON_TIER
Restore_weapon_radial_inputs = 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)
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" then
game_UI_audio_play("UI_Main_Menu_Nav_Back")
return
end
game_UI_audio_play("UI_Main_Menu_Select")
-- Did we select yes? This assumes yes is the first item
if Store_common_popup:get_selected_data() ~= 1 then
return
end
-- find current selection to get price
local menu_data = Active_list:return_selected_data()
store_weapon_purchase_weapon(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_is_cache, menu_data.price)
game_hud_update_inventory()
-- Update GSI if in mission
if Store_weapon_in_mission and Gsi_is_updated == false then
local obj_txt = Vdo_base_object:new("obj_txt",0, Store_weapon_doc_handle)
local gsi_bg = Vdo_base_object:new("gsi_bg", 0, Store_weapon_doc_handle)
obj_txt:set_text("M03_OBJ_EXIT_STORE")
local obj_txt_x, obj_txt_y = obj_txt:get_anchor()
local obj_txt_width, obj_txt_height = element_get_actual_size(obj_txt.handle)
local gsi_bg_width, gsi_bg_height = element_get_actual_size(gsi_bg.handle)
element_set_actual_size(gsi_bg.handle, obj_txt_x + obj_txt_width + 5, gsi_bg_height)
--gsi_bg:set_screen_size(obj_txt_x + obj_txt_width + 5, gsi_bg_height)
--don't call this again once it's updated
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)
Menu_data = Store_weapon_building_menu
store_weapon_populate_list(Menu_data, Menu_data.start_index)
-- 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)
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_cache_x,395)
-- 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 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_grid_populate_weapon_stats(Weapon_grid_idx)
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
--game_UI_audio_play("UI_HUD_Open_Weapon_Radial")
--TODO: 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
--If in cache and thrown is selected set slot back to 0
if Store_weapon_is_cache and 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 < 12 do
selected_slot = selected_slot + 1
end
if selected_slot >= 8 and Store_weapon_is_cache 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")
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_grid_populate_weapon_stats(Weapon_grid_idx)
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"},
{CTRL_BUTTON_DPAD, "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_grid_populate_weapon_stats(Weapon_grid_idx)
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_change_weapon_preview(category, id, dual_wield, is_cache, upgrade_level)
-- If we're only doing an upgrade swap, we don't need to lock grid input
if upgrade_level == nil then
-- lock input until the swap is done
Store_weapon_is_loading = true
end
-- Tell C to replace model
store_weapon_change_weapon(category, id, dual_wield, is_cache, upgrade_level)
end
function store_weapon_allow_grid_input()
return Store_weapon_is_loading == 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 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_grid_populate_weapon_stats(Weapon_grid_idx)
end
Old_index = weapon_index
end
end
end
function store_weapon_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines)
end
function store_weapon_mouse_drag(event, target_handle, mouse_x, mouse_y)
end
function store_weapon_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
end