--[[
CRIB_CASH_TRANSFER_FROM_BANK
CRIB_CASH_PLAYER_CASH
CRIB_CASH_INCOME ==INCOME PER DAY
CRIB_CASH_TRANSFER_CAP ==TRANSFER CAP
CRIB_CASH_READY ==Ready
CRIB_CASH_TRANSFER ==Transfering
CRIB_CASH_TRANSFER_COMPLETE ==TRANSFER COMPLETE
CRIB_CASH_DO_TRANSFER ==TRANSFER
CRIB_CASH_DO_CONTINUE ==CONTINUE
]]
--Globals...
local Hint_bar
local Input_tracker
local Crib_cash_mouse_input_tracker
local Crib_cash_data = {}
local CRIB_CASH_SUCCESS = 0
local CRIB_CASH_WARNING = 1
--Screen states...
local CRIB_CASH_SCREEN_STATE_PRE_TRANSFER = 0
local CRIB_CASH_SCREEN_STATE_TRANSFERING = 1
local CRIB_CASH_SCREEN_STATE_POST_TRANSFER = 2
local CRIB_CASH_COLOR_PRIMARY = {R=16/255, G=102/255, B=148/255}
local Crib_cash_screen_state = CRIB_CASH_SCREEN_STATE_PRE_TRANSFER --Set current screen state...
function store_crib_cash_init()
local screen_grp_h = vint_object_find("screen_grp")
vint_set_property(screen_grp_h, "alpha", 0)
--Populate hint bar...
local hints = { {CTRL_MENU_BUTTON_A, "CRIB_CASH_DO_TRANSFER"}}
Hint_bar = Vdo_hint_bar:new("hint_bar")
Hint_bar:set_hints(hints)
Hint_bar:set_visible(false)
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("select", "store_crib_input", 50)
Input_tracker:add_input("map", "store_crib_input", 50)
Input_tracker:add_input("back", "store_crib_input", 50)
Input_tracker:add_input("all_unassigned", "store_crib_input", 50)
Input_tracker:subscribe(true)
-- Initialize mouse inputs
if game_get_platform() == "PC" then
Crib_cash_mouse_input_tracker = Vdo_input_tracker:new()
Hint_bar:add_mouse_inputs("store_crib_cash", Crib_cash_mouse_input_tracker)
Crib_cash_mouse_input_tracker:subscribe(true)
end
--Fake populate... (should be done with dataresponder) ...
--store_crib_cash_populate(5000,50000,1500,5000)
vint_dataresponder_request("store_crib_cash_request_data", "store_crib_cash_populate", 0)
local cell_complete_h = vint_object_find("cell_complete_grp")
vint_set_property(cell_complete_h, "alpha", 0)
local transfer_h = vint_object_find("transfer_cash")
vint_set_property(transfer_h, "visible", false)
--transfer_h = vint_object_find("transfer_bank")
--vint_set_property(transfer_h, "visible", false)
local trans_in_event_tween = vint_object_find("cell_fade_wait")
if Crib_cash_data.cash_from_bank <= 0 then
vint_set_property(trans_in_event_tween,"end_event","store_crib_cash_popup")
else
vint_set_property(trans_in_event_tween,"end_event","store_crib_cash_cb")
end
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_CASH, CELL_SCREEN_MAIN, store_crib_cash_nothing)
end
function store_crib_cash_nothing()
end
function store_crib_cash_cleanup()
end
function store_crib_cash_cb(tween_h)
vint_object_destroy(vint_object_parent(tween_h))
--Do transfer...
crib_get_cash_stash() -- C function call
thread_new("store_crib_cash_transfer")
end
function store_crib_cash_popup( popup_type )
local popup_title_h = vint_object_find("popup_title")
local popup_text_h = vint_object_find("popup_text")
local popup_grp_h = vint_object_find("popup_grp")
local success_grp_h = vint_object_find("success_grp")
local popup_background_h = vint_object_find("popup_background")
if popup_type == CRIB_CASH_SUCCESS then
vint_set_property(success_grp_h, "visible", true)
vint_set_property(popup_background_h, "visible", false)
vint_set_property(popup_grp_h, "visible", false)
else
vint_set_property(popup_grp_h, "visible", true)
vint_set_property(success_grp_h, "visible", false)
vint_set_property(popup_title_h, "text_tag", "MENU_TITLE_WARNING")
vint_set_property(popup_text_h, "text_tag", "MENU_ACCOUNT_EMPTY")
game_UI_audio_play("UI_HUD_Help")
end
local popup_fill_h = vint_object_find("popup_fill")
local popup_border_h = vint_object_find("popup_border")
local text_w,text_h = vint_get_property(popup_text_h, "screen_size")
local popup_fill_w,crap = vint_get_property(popup_fill_h, "screen_size")
local popup_border_w,crap = vint_get_property(popup_border_h, "screen_size")
vint_set_property(popup_fill_h, "screen_size", popup_fill_w, text_h + 20)
vint_set_property(popup_border_h, "screen_size", popup_border_w, text_h + 59)
--Populate hint bar...
local hints = { {CTRL_MENU_BUTTON_A, "PAUSE_MENU_ACCEPT"}}
Hint_bar = Vdo_hint_bar:new("hint_bar")
Hint_bar:set_hints(hints)
Hint_bar:set_visible(true)
local popup_anim_h = vint_object_find("popup_anim")
lua_play_anim(popup_anim_h, 0)
Crib_cash_screen_state = CRIB_CASH_SCREEN_STATE_POST_TRANSFER
end
-------------------------------------------------------------------------------
-- Called by C++ via data responder
--
-- cash_from_bank how much the bank is paying the player
-- player_cash how much cash the player has before withdrawl
-- daily_cash how much cash the player earns per day...
-- transfer_cap How much cash the bank can max out on.
-------------------------------------------------------------------------------
function store_crib_cash_populate(cash_from_bank, player_cash, daily_cash, transfer_cap)
local bank_val_txt_h = vint_object_find("bank_val_txt")
local player_cash_val_txt_h = vint_object_find("player_cash_val_txt")
local perday_val_txt_h = vint_object_find("perday_val_txt")
local transfer_cap_val_txt_h = vint_object_find("transfer_cap_val_txt")
vint_set_property(bank_val_txt_h, "text_tag", "$" .. format_cash(cash_from_bank))
vint_set_property(player_cash_val_txt_h, "text_tag", "$" .. format_cash(player_cash))
vint_set_property(perday_val_txt_h, "text_tag", "$" .. format_cash(daily_cash))
vint_set_property(transfer_cap_val_txt_h, "text_tag", "$" .. format_cash(transfer_cap))
local transfer_h = vint_object_find("transfer_bank")
if cash_from_bank > 0 then
vint_set_property(transfer_h, "visible", true)
else
vint_set_property(transfer_h, "visible", false)
end
--Store off to process later...
Crib_cash_data = {
cash_from_bank = cash_from_bank,
player_cash = player_cash,
daily_cash = daily_cash,
transfer_cap = transfer_cap,
}
end
-------------------------------------------------------------------------------
-- Process input
-------------------------------------------------------------------------------
function store_crib_input(event)
if event == "back" or event == "select" or event == "map" then
if Crib_cash_screen_state == CRIB_CASH_SCREEN_STATE_POST_TRANSFER then
Input_tracker:subscribe(false)
Crib_cash_mouse_input_tracker:subscribe(false)
store_crib_cash_exit()
end
end
end
function store_crib_cash_exit()
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_CASH, store_crib_cash_exit_final)
end
function store_crib_cash_exit_final()
pop_screen()
end
-------------------------------------------------------------------------------
-- Cash transfer action...
-------------------------------------------------------------------------------
function store_crib_cash_transfer()
Crib_cash_screen_state = CRIB_CASH_SCREEN_STATE_TRANSFERING
--init stuff
local start_cash = 0 -- $ amount to start cash from...
local cash_end = Crib_cash_data.cash_from_bank -- $ amount to end cash on...
local cash_this_frame = -1 -- How much cash gets displayed in the current frame...
local bank_cash_this_frame = -1 --
local pct_this_frame = -1 -- How much cash gets displayed in the current frame...
local is_complete = false -- Is the screen complete?
--local amt_min = 100
--local amt_max = 20000
local time_max = 1200
local init_time = floor(vint_get_time_index() * 1000)
local cur_time = init_time
local time_to_count = time_max
local bank_val_txt_h = vint_object_find("bank_val_txt")
local player_cash_val_txt_h = vint_object_find("player_cash_val_txt")
local transfer_bank_h = vint_object_find("transfer_bank")
local transfer_cash_h = vint_object_find("transfer_cash")
local transfer_scale_x, transfer_scale_y = vint_get_property(transfer_cash_h, "scale")
vint_set_property(transfer_cash_h, "visible", true)
vint_set_property(transfer_bank_h, "visible", true)
game_UI_audio_play("UI_Cell_Cash_Transfer")
Hint_bar:set_visible(false)
if cash_end > 0 then
while is_complete == false do
local cur_time = floor(vint_get_time_index() * 1000) - init_time
--set my values
pct_this_frame = (cur_time / time_to_count)
cash_this_frame = cash_end * pct_this_frame
bank_cash_this_frame = cash_end - cash_this_frame
if cur_time >= time_to_count then
--force the values to end
vint_set_property(player_cash_val_txt_h, "text_tag", "$" .. format_cash(cash_end + Crib_cash_data.player_cash ))
vint_set_property(bank_val_txt_h, "text_tag", "$" .. "0")
vint_set_property(transfer_cash_h, "scale", transfer_scale_x, transfer_scale_y )
vint_set_property(transfer_bank_h, "scale", 0, transfer_scale_y )
--End Loop
is_complete = true
else
vint_set_property(player_cash_val_txt_h, "text_tag", "$" .. format_cash(cash_this_frame + Crib_cash_data.player_cash))
vint_set_property(bank_val_txt_h, "text_tag", "$" .. format_cash(bank_cash_this_frame))
vint_set_property(transfer_cash_h, "scale", transfer_scale_x * pct_this_frame, transfer_scale_y )
vint_set_property(transfer_bank_h, "scale", transfer_scale_x * (1 - pct_this_frame), transfer_scale_y )
end
thread_yield()
store_crib_cash_popup(CRIB_CASH_SUCCESS)
end
end
Crib_cash_screen_state = CRIB_CASH_SCREEN_STATE_POST_TRANSFER
end
-- =====================================
-- Mouse Specific Functions
-- =====================================
function store_crib_cash_mouse_click(event, target_handle)
-- Check if the user clicked on the hint bar button
local hint_index = Hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
store_crib_input("select")
end
end
function store_crib_cash_mouse_move(event, target_handle)
-- Reset all highlights
Hint_bar:set_highlight(0)
-- Check if the mouse is over the hint bar buttons
local hint_index = Hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
Hint_bar:set_highlight(hint_index, CRIB_CASH_COLOR_PRIMARY)
return
end
end