--[[
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
]]
STORE_CRIB_CASH_MAX_PERCENT = 340
STORE_CRIB_CIRCLE_MAX = 6.28 -- 2pi
STORE_CRIB_CASH_GRAPH_SPACER = 0.025
--Graph section enums
STORE_CRIB_CASH_ACTIVITIES = 0
STORE_CRIB_CASH_TARGETS = 1
--STORE_CRIB_CASH_FIREWALLS = 2 -- Firewalls were removed but leaving this here to help explain the hackyness in store_crib_category_populate()
STORE_CRIB_CASH_STORE_HACKING = 2
STORE_CRIB_CASH_BONUS = 3
local Cache_graph_data = {
total_cache_earned = 2000,
[STORE_CRIB_CASH_ACTIVITIES] = {
label = "PAUSE_MAP_FILTER_ACTIVITIES",
total_items = 50,
owned_items = 20,
cache_earned = 1000,
val_txt = "activities_val_txt",
title_txt ="activities_title_txt",
grp = "activities_grp",
rotation_grp = "activities_rot_grp",
circle = "cache_meter_activities",
twn = "activities_circle_twn",
tint = {R = 0, G = 101/255, B = 153/255},
},
[STORE_CRIB_CASH_TARGETS] = {
label = "PAUSE_MAP_FILTER_DIVERSIONS",
total_items = 50,
owned_items = 15,
cache_earned = 500,
val_txt = "targets_val_txt",
title_txt = "targets_title_txt",
grp = "targets_grp",
rotation_grp = "targets_rot_grp",
circle = "cache_meter_targets",
twn = "targets_circle_twn",
tint = {R = 165/255, G = 16/255, B = 21/255},
},
--[[[STORE_CRIB_CASH_FIREWALLS] = { -- Firewalls were removed but leaving this here to help explain the hackyness in store_crib_category_populate()
label = "FIREWALLS",
total_items = 20,
owned_items = 0,
cache_earned = 0,
val_txt = "firewalls_val_txt",
title_txt = "firewalls_title_txt",
grp = "firewalls_grp",
rotation_grp = "firewalls_rot_grp",
circle = "cache_meter_firewalls",
twn = "firewalls_circle_twn",
tint = {R = 148/255, G = 0/255, B = 197/255},
}, ]]--
[STORE_CRIB_CASH_STORE_HACKING] = {
label = "HACKING_TITLE",
total_items = 20,
owned_items = 10,
cache_earned = 500,
val_txt = "store_hacking_val_txt",
title_txt = "store_hacking_title_txt",
grp = "store_hacking_grp",
rotation_grp = "store_hacking_rot_grp",
circle = "cache_meter_store_hacking",
twn = "store_hacking_circle_twn",
tint = {R = 150/255, G = 194/255, B = 70/255},
},
[STORE_CRIB_CASH_BONUS] = {
label = "MENU_CACHE", --"HUB_CACHE_BONUS",
total_items = 20,
owned_items = 10,
cache_earned = 0,
val_txt = "bonus_val_txt",
title_txt = "bonus_title_txt",
grp = "bonus_grp",
rotation_grp = "bonus_rot_grp",
circle = "cache_meter_bonus",
twn = "bonus_circle_twn",
tint = {R = 220/255, G = 148/255, B = 29/255},
},
}
--Globals...
local Hint_bar
local Input_tracker
local Crib_cash_mouse_input_tracker
local Bg_image
local Crib_cash_data = {}
local Store_crib_cash_doc_h = -1
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_screen_state = CRIB_CASH_SCREEN_STATE_PRE_TRANSFER --Set current screen state...
-- Flag to block input to prevent skipping through the screen too quickly
local Store_crib_cash_input_is_blocked = false
-- Thread to delay input
local Store_crib_cash_input_delay_thread = -1
function store_crib_cash_init()
local Store_crib_cash_doc_h = vint_document_find("store_crib_cash")
--Hide screen grp
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, "PAUSE_MENU_ACCEPT"}}
Hint_bar = Vdo_hint_bar:new("hint_bar")
Hint_bar:set_hints(hints)
Hint_bar:set_alpha(0)
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("select", "store_crib_input", 50)
Input_tracker:add_input("map", "store_crib_cash_nav_map", 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)
Bg_image = Vdo_base_object:new("store_crib_cash_background_bmp", 0, Store_crib_cash_doc_h)
Crib_cash_mouse_input_tracker:add_mouse_input("mouse_move", "store_crib_cash_mouse_move", 0, Bg_image.handle)
Crib_cash_mouse_input_tracker:add_mouse_input("mouse_click", "store_crib_cash_mouse_click", 0, Bg_image.handle)
Crib_cash_mouse_input_tracker:subscribe(true)
end
--Fake populate... (should be done with dataresponder) ...
--store_crib_cash_populate(50000,50000,1500,5000)
vint_dataresponder_request("store_crib_cash_request_data", "store_crib_cash_populate", 0)
vint_dataresponder_request("store_crib_cash_request_data", "store_crib_category_populate", 0, "per_category")
--Hide complete popup
local popup_grp_h = vint_object_find("popup_grp")
vint_set_property(popup_grp_h, "alpha", 0)
--Hide meter until needed
local meter_grp_h = vint_object_find("meter_grp", 0, Store_crib_cash_doc_h)
vint_set_property(meter_grp_h, "alpha", 0)
--Set up title
local cell_title_h = Vdo_cell_title:new("cell_title", 0, Store_crib_cash_doc_h)
cell_title_h:set_text("COMPLETION_CASH")
cell_title_h:set_icon("ui_cell_icon_cash")
cell_title_h:play_dots_anim()
--Setup pie chart tweens and hide elements for now
store_crib_cash_set_graph_values()
--If no money to transfer (early in the game) show informative popup
if Crib_cash_data.cash_from_bank <= 0 and Crib_cash_data.daily_cash == 0 then
store_crib_cash_popup()
else
local trans_in_event_twn_h = vint_object_find("cell_fade_wait")
vint_set_property(trans_in_event_twn_h,"end_event","store_crib_cash_cb")
end
--Transition screen in
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_CASH, CELL_SCREEN_MAIN, store_crib_cash_nothing)
--Glitch screen in
--glitch_cell()
end
function store_crib_cash_nothing()
end
function store_crib_cash_cleanup()
Input_tracker:subscribe(false)
Input_tracker:remove_all()
if game_get_platform() == "PC" then
Crib_cash_mouse_input_tracker:subscribe(false)
Crib_cash_mouse_input_tracker:remove_all()
end
end
function store_crib_cash_cb(tween_h)
--Do transfer...
crib_get_cash_stash() -- C function call
thread_new("store_crib_cash_transfer")
end
--Show informational popup on how to increase income
function store_crib_cash_popup()
local cell_content_grp_h = vint_object_find("cell_content_grp")
vint_set_property(cell_content_grp_h, "visible", false)
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
local meter_clip_h = vint_object_find("popup_meter_clip")
local meter_fill_img_h = vint_object_find("popup_meter_fill_img")
local meter_clip_width, meter_clip_height = vint_get_property(meter_clip_h, "clip_size")
local METER_MAX = 100
local meter_pct = 1 - Crib_cash_data.next_transfer_percent
local new_value = meter_pct * METER_MAX
local incriment = METER_MAX/16
for i = 0, METER_MAX, incriment do
if new_value >= i and new_value < (i + incriment) then
new_value = i
end
end
--Tint meter white
vint_set_property(meter_fill_img_h, "tint", 220/255, 220/255, 220/255)
--Set meter clip size
vint_set_property(meter_clip_h, "clip_size", new_value, meter_clip_height)
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, next_transfer_percent, cat_activity, cat_target, cat_diversion, cat_store, cat_bonus)
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", "{GAME_CASH}" .. format_cash(cash_from_bank))
vint_set_property(player_cash_val_txt_h, "text_tag", "{GAME_CASH}" .. format_cash(player_cash))
vint_set_property(perday_val_txt_h, "text_tag", "{GAME_CASH}" .. format_cash(daily_cash))
vint_set_property(transfer_cap_val_txt_h, "text_tag", "{GAME_CASH}" .. format_cash(transfer_cap))
--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,
next_transfer_percent = next_transfer_percent,
}
if cash_from_bank > 0 then
--Transferring money, play animation
local transfer_anim_h = vint_object_find("transfer_anim")
--Pulse hints when done
local transfer_event_twn_h = vint_object_find("transfer_event_twn", transfer_anim_h)
vint_set_property(transfer_event_twn_h, "end_event", "store_crib_cash_pulse_hint")
lua_play_anim(transfer_anim_h, 0)
ui_audio_post_event("ui_cache_transfer")
else
store_crib_cash_popup()
local hints = {{CTRL_MENU_BUTTON_B, "CONTROL_BACK"}}
Hint_bar:set_hints(hints)
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
end
Cache_graph_data.total_cache_earned = cash_from_bank
end
function store_crib_category_populate( category_id, total, owned, cash )
--FIREWALLS were originally in category 2 so we need to move that money into targets
if(category_id == 2) then
Cache_graph_data[1].total_items = Cache_graph_data[1].total_items + total
Cache_graph_data[1].owned_items = Cache_graph_data[1].owned_items + owned
Cache_graph_data[1].cache_earned = Cache_graph_data[1].cache_earned + cash
--FIREWALLS were originally in category 2 so anything after needs to be pushed one position down
elseif( category_id > 2 ) then
local curr_section = Cache_graph_data[ category_id - 1 ]
curr_section.total_items = total
curr_section.owned_items = owned
curr_section.cache_earned = cash
else
local curr_section = Cache_graph_data[ category_id ]
curr_section.total_items = total
curr_section.owned_items = owned
curr_section.cache_earned = cash
end
end
-------------------------------------------------------------------------------
-- Process input
-------------------------------------------------------------------------------
function store_crib_input(event)
if event == "back" or event == "select" or event == "map" then
-- Input is delayed, return early
if Store_crib_cash_input_is_blocked == true then
return
end
-- Skip transfer animation if we're transferring
if Crib_cash_screen_state == CRIB_CASH_SCREEN_STATE_TRANSFERING then
-- Block input so we don't skip through too quickly
store_crib_cash_input_block_delay()
-- Set up end events and skip ahead
local transfer_anim_h = vint_object_find("transfer_anim")
local transfer_event_twn_h = vint_object_find("transfer_event_twn", transfer_anim_h)
vint_set_property(transfer_event_twn_h, "end_event", "store_crib_cash_pulse_hint")
lua_play_anim(transfer_anim_h, -6)
-- Stop cache transfer audio since we're stopping early
ui_audio_post_event("ui_cache_transfer_stop")
-- We're done transferring
Crib_cash_screen_state = CRIB_CASH_SCREEN_STATE_POST_TRANSFER
return
end
if Crib_cash_screen_state == CRIB_CASH_SCREEN_STATE_POST_TRANSFER then
Input_tracker:subscribe(false)
if Crib_cash_mouse_input_tracker ~= nil then
Crib_cash_mouse_input_tracker:subscribe(false)
end
store_crib_cash_exit()
end
end
end
function store_crib_cash_exit()
ui_audio_post_event("UI_Hub_Menu_Back")
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_CASH, store_crib_cash_exit_final)
end
function store_crib_cash_nav_map()
ui_audio_post_event("UI_Hub_Menu_Back")
cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_CASH, store_crib_cash_exit_to_game)
end
function store_crib_cash_exit_final()
pop_screen()
end
function store_crib_cash_exit_to_game()
pop_screen()
pop_screen()
pop_screen()
end
function store_crib_cash_pulse_hint()
Hint_bar:pulse(1)
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 = 3450
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")
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 or Crib_cash_screen_state == CRIB_CASH_SCREEN_STATE_POST_TRANSFER then
--force the values to end
vint_set_property(player_cash_val_txt_h, "text_tag", "{GAME_CASH}" .. format_cash(cash_end + Crib_cash_data.player_cash ))
vint_set_property(bank_val_txt_h, "text_tag", "{GAME_CASH}" .. "0")
--End Loop
is_complete = true
else
vint_set_property(player_cash_val_txt_h, "text_tag", "{GAME_CASH}" .. format_cash(cash_this_frame + Crib_cash_data.player_cash))
vint_set_property(bank_val_txt_h, "text_tag", "{GAME_CASH}" .. format_cash(bank_cash_this_frame))
end
thread_yield()
end
end
Crib_cash_screen_state = CRIB_CASH_SCREEN_STATE_POST_TRANSFER
end
--RAD_TO_DEG = 57.29199821758228
-- Divide pie chart into the correct sections
--
function store_crib_cash_set_graph_values()
local num_items = #Cache_graph_data
local start_angle = 0
local total_cache_earned = Cache_graph_data.total_cache_earned
-- Make space for a section if no cache is earned
-- We still want to show it on the graph to let the user know there are more areas to gain income from
local num_zero_sections = 0
local MIN_VALUE = 0.4
-- How many sections are zero?
for i = 0, num_items do
local cache_earned = Cache_graph_data[i].cache_earned
if cache_earned == 0 then
num_zero_sections = num_zero_sections + 1
end
end
local zero_section_offset = 0
--Remaining circle of 2pi not taken up by default degree size and spacers
local remaining_pi = STORE_CRIB_CIRCLE_MAX - (MIN_VALUE *(num_items + 1)) - (STORE_CRIB_CASH_GRAPH_SPACER *(num_items + 1))
if num_zero_sections < num_items then
zero_section_offset = (num_zero_sections * MIN_VALUE) / (num_items - num_zero_sections)
end
--Set text, text position, and end angle for each section
for i = 0, num_items do
local curr_section = Cache_graph_data[i]
local cache_earned = curr_section.cache_earned
local end_angle = 0
if cache_earned == 0 then
end_angle = start_angle + MIN_VALUE
else
end_angle = start_angle + MIN_VALUE + ((cache_earned/ total_cache_earned) * remaining_pi)
end
local circle_h = vint_object_find(curr_section.circle)
local twn_h = vint_object_find(curr_section.twn)
vint_set_property(circle_h, "start_angle", start_angle)
vint_set_property(twn_h, "start_value", start_angle)
vint_set_property(twn_h, "end_value", end_angle)
local new_rotation = ((end_angle - start_angle) * 0.5) + start_angle
vint_set_property(vint_object_find(curr_section.grp), "rotation", new_rotation)
vint_set_property(vint_object_find(curr_section.grp), "alpha", 0)
local val_txt_h = vint_object_find(curr_section.val_txt)
local title_txt_h = vint_object_find(curr_section.title_txt)
local rotation_grp_h = vint_object_find(curr_section.rotation_grp)
vint_set_property(val_txt_h, "text_tag", "{GAME_CASH}" ..format_cash(curr_section.cache_earned))
-- Using insert values to create a string with the following format:
-- "SECTION TITLE X/Y"
local insert_values = { [0] = curr_section.label, [1] = curr_section.owned_items, [2] = curr_section.total_items }
local body = vint_insert_values_in_string("HUB_CACHE_SECTION_XY", insert_values)
vint_set_property(title_txt_h, "text_tag", body)
vint_set_property(val_txt_h, "tint", curr_section.tint.R, curr_section.tint.G, curr_section.tint.B)
vint_set_property(rotation_grp_h, "rotation", new_rotation * -1)
--If rotation is past 180 flip the alignment
if new_rotation >= 3.14 then
vint_set_property(val_txt_h, "auto_offset", "ne")
vint_set_property(title_txt_h, "auto_offset", "ne")
end
--Start the next section at the end of the previous section
start_angle = end_angle + STORE_CRIB_CASH_GRAPH_SPACER
end
end
-------------------------------------------------------------------------------
-- Function store_crib_cash_input_block_delay()
--
-- Delay input for 0.75s so user doesn't skip through the screen too quickly
--
-------------------------------------------------------------------------------
function store_crib_cash_input_block_delay()
Store_crib_cash_input_is_blocked = true
if Store_crib_cash_input_delay_thread ~= -1 then
thread_kill(Store_crib_cash_input_delay_thread)
end
if Store_crib_cash_input_delay_thread == -1 then
Store_crib_cash_input_delay_thread = thread_new("store_crib_cash_input_block_thread")
end
end
function store_crib_cash_input_block_thread()
delay(.75)
Store_crib_cash_input_is_blocked = false
Store_crib_cash_input_delay_thread = -1
end
-- =====================================
-- Mouse Specific Functions
-- =====================================
function store_crib_cash_mouse_click(event, target_handle)
-- Check if the user clicked anywhere on the screen
if target_handle == Bg_image.handle then
store_crib_input("select")
return
end
-- 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")
return
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)
return
end
end