local Building_purchase_subs = { }
local Building_purchasing_data = { }
local Building_purchase_is_crib = false
local Menu_sound_confirm = game_audio_get_audio_id("SYS_HUD_CONF_SERIOUS") -- Confirmation/warning dialog opens
local Building_purchase_sound = game_audio_get_audio_id("SYS_MENU_BUY_BUILDING")
local Mouse_input_tracker
local Bg_mask
local Input_tracker = {}
local City_control_meter = -1
function building_purchase_init()
-- TODO: RIP THIS OUT OF CODE?... or figure out if we need it?? (JMH 6/24/2010)
Building_purchase_is_crib = building_purchase_is_crib_being_purchased()
--Find and hide objects until we need them...
vint_set_property(vint_object_find("ctrl_info_grp"), "visible", false)
vint_set_property(vint_object_find("guns"), "visible", false)
vint_set_property(vint_object_find("main"), "visible", false)
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("pause", "building_purchase_pause", 50)
bg_saints_show(false)
--Initialize VDO for district control.
City_control_meter = Vdo_city_control:new("control_meter")
Building_purchase_subs[0] = vint_subscribe_to_input_event("all_unassigned", "bp_nothing")
if Building_purchase_is_crib == true then
vint_dataresponder_request("crib_purchase_get_crib_info", "update_building_purchase_text", 0)
else
vint_dataresponder_request("shop_purchase_get_shop_info", "update_building_purchase_text", 0)
end
--Set bg saints screen type...
bg_saints_set_type(BG_TYPE_COMPLETION)
if game_get_platform() == "PC" then
Mouse_input_tracker = Vdo_input_tracker:new()
local doc_handle = vint_document_find("building_purchase")
Bg_mask = Vdo_base_object:new("bg_clickable", 0, doc_handle)
Mouse_input_tracker:add_mouse_input("mouse_move", "building_purchase_mouse_move", 0, Bg_mask.handle)
Mouse_input_tracker:add_mouse_input("mouse_click", "building_purchase_mouse_click", 0, Bg_mask.handle)
Mouse_input_tracker:subscribe(false)
end
end
function building_purchase_pause(event)
dialog_open_pause_display()
end
function building_purchase_clean()
game_UI_audio_play("UI_Main_Menu_Select")
--Autosave after building purchase...
game_autosave()
pop_screen()
end
function building_not_enough_money()
pop_screen()
end
function building_purchase_cleanup()
for index, value in pairs(Building_purchase_subs) do
vint_unsubscribe_to_input_event(value)
end
-- DAD - 8/12/11 - Clean up is called from vint_doc destroy... we don't want to pop extra screens.
-- pop_screen()
end
-- Percentages should be sent in as numbers between 0 and 100, cause we'll floor them an print as text
function update_building_purchase_text(building_name, description_txt, store_cost, player_cash, profit, control_pct, control_pct_new, control_pct_increase, district, discount, is_store)
Building_purchasing_data.name = building_name
Building_purchasing_data.description_txt = description_txt
Building_purchasing_data.store_cost = store_cost
Building_purchasing_data.player_cash = player_cash
Building_purchasing_data.control_pct = control_pct
Building_purchasing_data.control_pct_new = control_pct_new
Building_purchasing_data.control_pct_increase = control_pct_increase
Building_purchasing_data.control_district = district
Building_purchasing_data.discount = discount
Building_purchasing_data.is_store = is_store
if Building_purchase_is_crib == false then
Building_purchasing_data.profit = profit
end
--Set control Percentage to start with...
if Building_purchasing_data.control_pct == nil then
Building_purchasing_data.control_pct = 0
debug_print("vint", "warning: no control percentage assigned to this property/building\n")
end
if Building_purchasing_data.control_pct_new == nil then
Building_purchasing_data.control_pct_new = 0
debug_print("vint", "warning: no control percentage assigned to this property/building\n")
end
if Building_purchasing_data.profit == nil then
Building_purchasing_data.profit = 10
debug_print("vint", "warning: no profit assigned to this property/building\n")
end
if Building_purchasing_data.control_district == nil then
Building_purchasing_data.control_district = "EMPTY DISTRICT NAME"
debug_print("vint", "warning: no district name assigned to this property/building\n")
end
if Building_purchasing_data.discount == nil then
Building_purchasing_data.discount = 10
debug_print("vint", "warning: no profit assigned to this property/building\n")
end
if player_cash < store_cost then
-- Show Dialog that says you can't afford it.
local header = "MENU_TITLE_NOTICE"
local body = "HUD_SHOP_INSUFFICIENT_FUNDS"
dialog_box_message(header, body, nil, nil, "building_not_enough_money")
else
-- Ask player if they really want to purchase it.
local header = "MENU_TITLE_CONFIRM"
local body
local insert_values = { [0] = building_name, [1] = format_cash(store_cost) }
if Building_purchase_is_crib == true then
body = vint_insert_values_in_string("BUILDING_PURCHASE_CRIB", insert_values)
else
body = vint_insert_values_in_string("BUILDING_PURCHASE_BUILDING", insert_values)
end
dialog_box_confirmation(header, body, "building_purchased")
end
end
function building_purchased(result, action)
if result == 0 then
--Set Text Items and Prepare animations... Starts from top of the screen to bottom... GO!!!
--Store Title
local store_title_txt_h = vint_object_find("store_title_txt")
vint_set_property(store_title_txt_h, "text_tag_crc", Building_purchasing_data.name)
--Resize long strings to fit
vint_set_property(store_title_txt_h, "scale", 1, 1)
local max_width = 442
local text_width, text_height = element_get_actual_size(store_title_txt_h)
if text_width >= max_width then
local text_scale = max_width/text_width
vint_set_property(store_title_txt_h, "scale", text_scale, 1)
end
--Set control Percentage to start with...
City_control_meter:update(0.01 * Building_purchasing_data.control_pct, false)
--Set callback to play control up during the animation...
local control_meter_twn_end_h = vint_object_find("control_meter_end_twn")
vint_set_property(control_meter_twn_end_h, "end_event", "building_purchase_control_anim")
--Set text using values/tag cool guy stuff...
local values, tag
--Control Increase...
local control_increase_txt_h = vint_object_find("control_increase_txt")
local new_pct = Building_purchasing_data.control_pct_increase
values = { [0] = floor(new_pct + 0.5)}
tag = vint_insert_values_in_string("BUILDING_PURCHASE_CONTROL_INCREASE", values) --LOCALIZE EXAMPLE: "10% CONTROL INCREASE"
vint_set_property(control_increase_txt_h, "text_tag", tag)
--Hoods taken over...
local control_increase_gang_txt_h = vint_object_find("control_increase_gang_txt")
--values = { [0] = Building_purchasing_data.control_district}
--tag = vint_insert_values_in_string("{0} DISTRICT", values) --LOCALIZE EXAMPLE: "DECKERS DISTRICT"
vint_set_property(control_increase_gang_txt_h, "text_tag", Building_purchasing_data.control_district )
--Cash Earned /Day
local cash_txt_h = vint_object_find("cash_day_text")
if Building_purchase_is_crib then
vint_set_property(cash_txt_h, "visible", false)
else
values = { [0] = format_cash(Building_purchasing_data.profit)}
tag = vint_insert_values_in_string("BUILDING_PURCHASE_CASH_PER_HOUR", values) --LOCALIZE EXAMPLE: "$3,000 PER HOUR"
vint_set_property(cash_txt_h, "text_tag", tag)
end
--Discount Earned /Day
local discount_text_h = vint_object_find("discount_text")
if Building_purchase_is_crib or Building_purchasing_data.is_store ~= true then
vint_set_property(discount_text_h, "visible", false)
else
values = { [0] = floor(Building_purchasing_data.discount + 0.5)}
tag = vint_insert_values_in_string("BUILDING_PURCHASE_DISCOUNT", values) --LOCALIZE EXAMPLE: "10% DISCOUNT"
vint_set_property(discount_text_h, "text_tag", tag)
end
--Set button on the interface
local button = Vdo_hint_button:new("ctrl_btn")
button:set_button(CTRL_MENU_BUTTON_A)
local button_highlight_h = vint_object_find("ctrl_btn_highlight")
vint_set_property(button_highlight_h, "image", CTRL_MENU_BUTTON_A)
if game_is_active_input_gamepad() == false then
vint_set_property(button.handle, "visible", false)
vint_set_property(button_highlight_h, "visible", false)
end
--Show Base Items...
vint_set_property(vint_object_find("ctrl_info_grp"), "visible", true)
vint_set_property(vint_object_find("guns"), "visible", true)
vint_set_property(vint_object_find("main"), "visible", true)
--Play all animations in...
local twn_h = vint_object_find("purchase_anchor_twn")
vint_set_property(twn_h, "start_event", "building_purchase_play_audio")
bg_saints_animate()
lua_play_anim(vint_object_find("text_anim"))
--vint_set_property(vint_object_find("left_shadow"),"visible",true)
--vint_set_property(vint_object_find("right_shadow"),"visible",true)
bg_saints_show(true)
--TODO: maybe a programmer should look at this, and figure out why we need two? (JMH 6/24/2010)
if Building_purchase_is_crib == true then
crib_purchase_purchase_crib()
else
shop_purchase_purchase_shop()
end
Building_purchase_subs[1] = vint_subscribe_to_input_event("select", "building_purchase_clean")
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(true)
end
else
pop_screen()
end
end
function building_purchase_play_audio()
game_UI_audio_play("UI_Buy_Building_Screen")
end
--Animates in the city control... this is for a callback from a tween
function building_purchase_control_anim(tween_h, event)
City_control_meter:update(0.01 * Building_purchasing_data.control_pct_new, true)
end
function building_purchase_mouse_click(event, target_handle)
building_purchase_clean()
end
function building_purchase_mouse_move(event, target_handle)
end