local STORE_VENDOR_LOA_DUST = 0
local STORE_VENDOR_BSOD = 1
local STORE_VENDOR_ALLEY_JUICE = 2
local STORE_VENDOR_BATH_SALTS = 3
local Data = {
[STORE_VENDOR_LOA_DUST] = {
title = "LOA DUST",
image = "ui_vend_loa_dust",
price = 100,
desc = "Smoke a bulb. Walk through walls."
},
[STORE_VENDOR_BSOD] = {
title = "BSOD",
image = "ui_vend_bsod",
price = 120,
desc = "Expose the errors of the Dominatrix. Go on a text adventure."
},
[STORE_VENDOR_ALLEY_JUICE] = {
title = "ALLEY JUICE",
image = "ui_vend_alley_juice",
price = 20,
desc = "Do you trust it? Peds become transformed."
},
[STORE_VENDOR_BATH_SALTS] = {
title = "BATH SALTS",
image = "ui_vend_bath_salts",
price = 80,
desc = "Dispose of human shields in a face melting way."
},
}
local Store_vendor_doc_handle = -1
local Input_tracker = -1
local Buttons_h = {}
local Curr_index = 0
local Num_items = 0
local Audio_intro_h = -1
function store_vendor_init()
Store_vendor_doc_handle = vint_document_find("store_vendor")
Input_tracker = Vdo_input_tracker:new()
--lock inputs until intro anim is finished
Input_tracker:add_input("all_unassigned", "store_vendor_grid_nav_do_nothing", 50)
Input_tracker:subscribe(true)
--set hints
local hint_data = {
{CTRL_MENU_BUTTON_A, "PURCHASE"},
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
local hint_bar = Vdo_hint_bar:new("hint_bar", 0, Store_vendor_doc_handle)
hint_bar:set_hints(hint_data)
--display cash
vint_dataitem_add_subscription("sr2_local_player_status_infrequent", "update", "store_vendor_cash_update")
--draw grid
store_vendor_grid_draw_items(Data, 0)
store_vendor_grid_set_highlight()
--load peg
pause_map_dump()
--FOR TEST ONLY
thread_new("store_vendor_test")
--setup screen initial state
local intro_anim_h = vint_object_find("intro_anim")
local end_event_twn_h = vint_object_find("end_event_twn", intro_anim_h)
vint_set_property(end_event_twn_h, "end_event", "store_vendor_unlock_inputs")
vint_apply_start_values(intro_anim_h)
end
function store_vendor_test()
delay(.005)
store_vendor_peg_load()
end
function store_vendor_cleanup()
game_peg_unload("ui_bms_store_vend")
pause_map_restore()
end
function store_vendor_peg_load()
game_peg_load_with_cb("store_vendor_play_intro", 1, "ui_bms_store_vend")
end
function store_vendor_play_intro()
local intro_anim_h = vint_object_find("intro_anim")
lua_play_anim(intro_anim_h)
Audio_intro_h = audio_object_post_event("Drug_Dealer_VO",nil,nil,nil,false)
end
function store_vendor_unlock_inputs()
Input_tracker:add_input("nav_left", "store_vendor_grid_nav_left", 50)
Input_tracker:add_input("nav_right", "store_vendor_grid_nav_right", 50)
Input_tracker:add_input("back", "store_vendor_exit", 50)
Input_tracker:add_input("select", "store_vendor_purchase_item", 50)
Input_tracker:subscribe(true)
end
function store_vendor_exit()
local outro_anim_h = vint_object_find("outro_anim")
local outro_event_twn_h = vint_object_find("end_event_twn", outro_anim_h)
vint_set_property(outro_event_twn_h, "end_event", "store_vendor_exit_anim_complete")
lua_play_anim(outro_anim_h)
audio_stop(Audio_intro_h)
end
function store_vendor_exit_anim_complete()
Input_tracker:subscribe(false)
pop_screen()
end
function store_vendor_purchase_item()
if Curr_index >= STORE_VENDOR_LOA_DUST and Curr_index <= STORE_VENDOR_BATH_SALTS then
--call c to make purchase
store_vendor_purchase(Curr_index)
ui_audio_post_event("Drug_Dealer_Purchase")
store_vendor_exit()
end
end
function store_vendor_cash_update(di_h)
local cash = vint_dataitem_get(di_h)
local cash_txt_h = vint_object_find("cash_txt", 0, Store_vendor_doc_handle)
vint_set_property(cash_txt_h, "text_tag", "{GAME_CASH}" .. format_cash(cash))
end
function store_vendor_grid_draw_items(data, index)
local base_button_grp_h = vint_object_find("base_button_grp")
local base_button_x, base_button_y = vint_get_property(base_button_grp_h, "anchor")
Buttons_h = {}
Num_items = #data
Curr_index = index
local GRID_SPACE = 120
for i = 0, Num_items do
--clone button
Buttons_h[i] = vint_object_clone(base_button_grp_h)
local button_img_h = vint_object_find("button_img", Buttons_h[i])
--set image
vint_set_property(button_img_h, "image", data[i].image)
--position button
local new_x = base_button_x + (GRID_SPACE * i)
vint_set_property(Buttons_h[i], "anchor", new_x, base_button_y)
end
vint_set_property(base_button_grp_h, "visible", false)
end
function store_vendor_grid_move_cursor(direction)
--updated index
Curr_index = Curr_index + direction
--handle wrapping
if Curr_index > Num_items then
Curr_index = 0
elseif Curr_index < 0 then
Curr_index = Num_items
end
--call set highlight
store_vendor_grid_set_highlight()
end
function store_vendor_grid_set_highlight()
local highlight_grp_h = vint_object_find("button_highlight_grp")
--position highlight
local button_x, button_y = vint_get_property(Buttons_h[Curr_index],"anchor")
vint_set_property(highlight_grp_h, "anchor", button_x, button_y)
--scale highlighted item and reset scale of all other images
for i = 0, Num_items do
local button_img_h = vint_object_find("button_img", Buttons_h[i])
if i == Curr_index then
vint_set_property(button_img_h, "scale", 1.2,1.2)
else
vint_set_property(button_img_h, "scale", 1.0,1.0)
end
end
--update info
local title_txt_h = vint_object_find("title_txt", 0, Store_vendor_doc_handle)
local price_txt_h = vint_object_find("price_txt", 0, Store_vendor_doc_handle)
local desc_txt_h = vint_object_find("desc_txt", 0, Store_vendor_doc_handle)
vint_set_property(title_txt_h, "text_tag", Data[Curr_index].title)
vint_set_property(price_txt_h, "text_tag", "{GAME_CASH}" .. format_cash(Data[Curr_index].price))
vint_set_property(desc_txt_h, "text_tag", Data[Curr_index].desc)
--play audio
game_UI_audio_play("UI_Cell_Nav")
end
function store_vendor_grid_nav_left()
store_vendor_grid_move_cursor(-1)
end
function store_vendor_grid_nav_right()
store_vendor_grid_move_cursor(1)
end
function store_vendor_grid_nav_do_nothing()
end