--Globals
Reward_granted_doc = -1 --Global Reference to doc...
--Locals!
local Reward = {}
local Rewards_count = 0
local Rewards_current_display = 0
local Fluer_outline_anims = {}
local Fluer_outline_objects = {}
local Peg_image_name = -1
local Reward_granted_input_tracker
local Control_blocked = 0
local Reward_granted_end_cb
local Upgrades_descriptions = {}
local Bg_mouse_input_tracker
local Bg_image
local DESC_GRP_SPACING = 20
local Desc_cloned_grps = {}
--Initialize
function reward_granted_init()
Reward_granted_doc = vint_document_find("reward_granted")
--Setup fleur Outline Anims
--Clone fleur outline animation and object. Then Retarget and store handles for later...
local fleur_outline = Vdo_anim_object:new("fleur_outline", 0, Reward_granted_doc)
local fleur_outline_anim = Vdo_anim_object:new("fleur_outline_zoom_anim", 0, Reward_granted_doc)
fleur_outline:set_alpha(0)
for index = 1, 7 do
local fleur_outline_clone = Vdo_base_object:clone(fleur_outline.handle)
local anim = Vdo_anim_object:clone(fleur_outline_anim.handle)
anim:set_target_handle(fleur_outline_clone.handle)
fleur_outline_clone:set_alpha(0)
anim:stop()
Fluer_outline_objects[index] = fleur_outline_clone
Fluer_outline_anims[index] = anim
end
--Show Button Tips
local hint_data = {
{CTRL_MENU_BUTTON_A, "COMPLETION_CONTINUE"},
}
local button_tips = Vdo_hint_bar:new("button_tips")
button_tips:set_hints(hint_data)
if( game_get_platform() ~= "PC" ) then
button_tips:pulse(1)
end
--Hide the stuff until we are ready...
local h = vint_object_find("big_container", 0, Reward_granted_doc)
vint_set_property(h, "alpha", 0)
local background_grp_h = vint_object_find("respect_background_grp")
vint_set_property(background_grp_h, "alpha", 0)
--setup callbacks for screen_fade_out anims
local fade_out_anim_h = vint_object_find("fade_out_anim", 0, Reward_granted_doc)
local fade_out_twn_h = vint_object_find("screen_fade_out_twn", 0, Reward_granted_doc)
vint_set_property(fade_out_twn_h, "end_event", "reward_screen_fade_cb")
local fade_out_anim_h = vint_object_find("fade_out_anim", 0, Reward_granted_doc)
local button_tip_twn_h = vint_object_find("button_tip_twn", 0, Reward_granted_doc)
vint_set_property(button_tip_twn_h, "end_event", "screen_in_complete")
end
--Close
function reward_granted_cleanup()
--unload old peg if loaded...
local peg_name = Peg_image_name
if Peg_image_name ~= -1 then
game_peg_unload("bms_pause_menu")
game_peg_unload(Peg_image_name)
Peg_image_name = -1
end
reward_granted_inputs_unsubscribe()
end
function noop()
-- Does nothing
end
--------------------------------------------------------------------------------------------------------------
-- Unsubscribe from inputs...
--
function reward_granted_inputs_unsubscribe()
--Unsubscribe...
if Reward_granted_input_tracker ~= nil then
Reward_granted_input_tracker:subscribe(false)
end
if Bg_mouse_input_tracker ~= nil then
Bg_mouse_input_tracker:subscribe(false)
end
end
--Starts the reward sequence... This is designed to be called by its parent completion document or directly from c++...
function reward_granted_start()
local h = vint_object_find("safe_frame",0, Reward_granted_doc)
vint_set_property(h, "visible", true)
Reward_granted_input_tracker = Vdo_input_tracker:new()
Reward_granted_input_tracker:add_input("nav_left", "noop", 100)
Reward_granted_input_tracker:add_input("nav_right", "noop", 100)
Reward_granted_input_tracker:add_input("nav_up", "noop", 100)
Reward_granted_input_tracker:add_input("nav_down", "noop", 100)
Reward_granted_input_tracker:add_input("back", "noop", 100)
Reward_granted_input_tracker:add_input("map", "noop", 100)
Reward_granted_input_tracker:add_input("select", "reward_granted_button_press", 100)
Reward_granted_input_tracker:add_input("pause", "reward_granted_button_press", 100)
Reward_granted_input_tracker:subscribe(true)
Bg_image = Vdo_base_object:new("respect_background_bmp", 0, Reward_granted_doc)
-- Mouse input
if game_get_platform() == "PC" then
Bg_mouse_input_tracker = Vdo_input_tracker:new()
Bg_mouse_input_tracker:add_mouse_input("mouse_move", "reward_granted_mouse_move", 0, Bg_image.handle)
Bg_mouse_input_tracker:add_mouse_input("mouse_click", "reward_granted_mouse_click", 0, Bg_image.handle)
Bg_mouse_input_tracker:subscribe(true)
end
--Show Screen
reward_screen_fade_cb()
--Block controls until we are complete...
control_block(true)
end
-- Callback when the a button is pressed.
function reward_granted_button_press()
if is_control_blocked() == false then
game_UI_audio_play("UI_Main_Menu_Select")
reward_granted_next_screen()
end
end
--Starts the next screen...
function reward_granted_next_screen()
--fade out current screen, a callback will attempt to bring in the next... reward_screen_fade_cb()
local fade_out_anim_h = vint_object_find("fade_out_anim", 0, Reward_granted_doc)
lua_play_anim(fade_out_anim_h)
--Block controls until we are complete...
control_block(true)
end
--This is the callback after the VBM has loaded.
function reward_granted_next_cb()
--Plays back the screen...
local item_image = Reward.item_image
local item_name = Reward.item_name
local item_desc = Reward.item_desc
local unlockable_id = Reward.unlockable_id
local is_silverlink = Reward.is_silverlink
--replace image with queued up image...
local unlockable_bmp = vint_object_find("unlockable_bmp", 0, Reward_granted_doc)
vint_set_property(unlockable_bmp, "image", item_image)
--Set title
local title_h = vint_object_find("reward_name", 0, Reward_granted_doc)
vint_set_property(title_h, "text_tag", item_name)
resize_text_element(title_h, 435)
--If Silverlink unlockable show the silverlink logo...
local silverlink_bmp_h = vint_object_find("silverlink_bmp", 0 , Reward_granted_doc)
vint_set_property(silverlink_bmp_h, "visible", is_silverlink)
------------------
--Set descritpions
------------------
--Destroy any cloned grps
for i = 1, #Desc_cloned_grps do
vint_object_destroy(Desc_cloned_grps[i])
end
Upgrades_descriptions = {}
--Sean we need an identifier here in place of menu_data.id
vint_dataresponder_request("powers_upgrades_dr", "reward_granted_add_upgrades_descriptions", 0, "get_upgrade_desc", unlockable_id)
--[[reward_granted_add_upgrades_descriptions("Test ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.", 1)
reward_granted_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit.", 2)
reward_granted_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.", 3)
reward_granted_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit.", 2)]]
local description_h = vint_object_find("reward_description", 0, Reward_granted_doc)
local final_y, final_x
local align_grp_h = vint_object_find("align_grp", 0, Reward_granted_doc)
local desc_grp_h = vint_object_find("desc_grp", 0, Reward_granted_doc)
vint_set_property(desc_grp_h, "visible", false)
if #Upgrades_descriptions ~= 0 and Upgrades_descriptions[1].element ~= -1 then
--hide simple description
vint_set_property(description_h, "visible", false)
--base group that holds cloned groups
local desc_move_grp_h = vint_object_find("desc_move_grp", 0, Reward_granted_doc)
local desc_move_grp_x, desc_move_grp_y = vint_get_property(desc_move_grp_h, "anchor")
local prev_height = 0
Desc_cloned_grps = {}
for i = 1, #Upgrades_descriptions do
--get data out of table
local description = Upgrades_descriptions[i].description
local element = Upgrades_descriptions[i].element
--clone base item...
local h = vint_object_clone(desc_grp_h)
--Set Text
local desc_type_txt_h = vint_object_find("desc_type_txt", h)
local desc_txt_h = vint_object_find("desc_txt", h)
vint_set_property(desc_type_txt_h, "text_tag", POWERS_ELEMENTS_ENUMS[element].short_label)
vint_set_property(desc_txt_h, "text_tag", description)
--Set icon
local desc_icon_h = vint_object_find("desc_icon", h)
vint_set_property(desc_icon_h, "image", POWERS_ELEMENTS_ENUMS[element].bitmap)
--Position grp...
local x, y = vint_get_property(h, "anchor")
local width1, height1 = element_get_actual_size(desc_type_txt_h)
local width2, height2 = element_get_actual_size(desc_txt_h)
y = ( (i - 1) * DESC_GRP_SPACING ) + prev_height
vint_set_property(h, "anchor", x, y )
prev_height = prev_height + height1 + height2
--store cloned grps in table to be destroyed
Desc_cloned_grps[i] = h
--Show grp
vint_set_property(h, "visible", true)
--Store off height and y of last group to align button hints
final_x = x + desc_move_grp_x - 11
final_y = ( (i - 1) * DESC_GRP_SPACING ) + prev_height + desc_move_grp_y + DESC_GRP_SPACING + 3
end
--scale if nessesary
local max_desc_height = 400
local scale_grp_h = vint_object_find("scale_grp", 0, Reward_granted_doc)
local scale_amount = 1
if prev_height > max_desc_height then
scale_amount = max_desc_height/prev_height
vint_set_property(scale_grp_h, "scale", scale_amount, scale_amount)
else
vint_set_property(scale_grp_h, "scale", 1,1)
end
vint_set_property(align_grp_h, "anchor", 0, -(((prev_height * scale_amount)/2) - 37))
--use simple upgrade text box if element is -1
else
vint_set_property(desc_grp_h, "visible", false)
vint_set_property(description_h, "text_tag", item_desc)
vint_set_property(description_h, "visible", true)
local x, y = vint_get_property(description_h, "anchor")
local w, h = element_get_actual_size(description_h)
final_x = x
final_y = y + h + 41
local scale_grp_h = vint_object_find("scale_grp", 0, Reward_granted_doc)
vint_set_property(scale_grp_h, "scale", 1,1)
vint_set_property(align_grp_h, "anchor", 0, 0)
end
--align button hints
local button_tips_h = vint_object_find("button_tips", 0, Reward_granted_doc)
vint_set_property(button_tips_h, "anchor", final_x + 13, final_y)
--Background anim in only on first playback...
if Rewards_current_display == 0 then
local anim_h = vint_object_find("background_anim_in", 0, Reward_granted_doc)
lua_play_anim(anim_h)
end
--Play animation
local anim_h = vint_object_find("animate_in", 0, Reward_granted_doc)
vint_apply_start_values(anim_h)
lua_play_anim(anim_h)
anim_h = vint_object_find("circles", 0, Reward_granted_doc)
vint_apply_start_values(anim_h)
lua_play_anim(anim_h)
--Play Fleur outline animation...
for index = 1, 7 do
Fluer_outline_objects[index]:set_alpha(0)
Fluer_outline_anims[index]:play(index * .125)
end
--Play Audio
ui_audio_post_event("UI_Reward_Bonus")
ui_audio_post_event("UI_Reward_Loop")
Rewards_current_display = Rewards_current_display + 1
end
-- Gets called when the screen starts
-- or when the callback from when the previous screen fades out
function reward_screen_fade_cb()
--Determine if there are rewards left to display...
if Rewards_current_display == Rewards_count then
--No more rewards...
ui_audio_post_event("UI_Reward_Loop_Stop")
--Hide this doc...
local safe_frame_h = vint_object_find("safe_frame", 0, Reward_granted_doc)
vint_set_property(safe_frame_h, "visible", false)
--unload old peg if loaded...
if Peg_image_name ~= -1 then
game_peg_unload(Peg_image_name)
Peg_image_name = -1
end
--lets call the callback function set by the parent document.
Reward_granted_end_cb()
--Nothing else to do with inputs on this screen. unsubscribe them.
reward_granted_inputs_unsubscribe()
return
else
--Still more rewards..
--Query game for next reward...
vint_dataresponder_request("cmp_fetch_unlockable", "reward_granted_add", 0, Rewards_current_display)
--Load next set of pegs...
local item_image = Reward.item_image
--unload old peg if loaded...
if Peg_image_name ~= -1 then
game_peg_unload(Peg_image_name)
Peg_image_name = -1
end
--Load peg.. and then wait for it to load...
game_peg_load_with_cb("reward_granted_next_cb", 1, item_image)
Peg_image_name = item_image
end
end
--Gets called when a current screen is done displaying...
function screen_in_complete()
--Unlock controls
control_block(false)
end
--Provides functionality to stack blocking of the control input...
--
--@param is_blocked bool determines whether we want to block or unblock controls.
function control_block(is_blocked)
if is_blocked == true then
Control_blocked = Control_blocked + 1
else
Control_blocked = Control_blocked - 1
end
end
--Function to check if the controls are blocked
--
--@return bool True if the controls are blocked.
function is_control_blocked()
local ctrl_block = Control_blocked
if Control_blocked > 0 then
return true
else
return false
end
end
--This is set by the parent document to be called later...
function set_reward_granted_end_cb(func)
Reward_granted_end_cb = func
end
--Sets the amount of rewards that we should cycle through...
function reward_granted_set_reward_count(count)
Rewards_count = count
end
-------------------------------------------------------------
-- Populates the script from the dataresponder...
--
-- @param ignore_first_param Unused Parameter
-- @param ignore_second_param Unused Parameter
-- @param item_name Name of the item.
-- @param item_image This is the name of the image... also same name of VBM to stream from disc.
-- @param item_desc Description of the item...
--
function reward_granted_add(ignore_first_param, ignore_second_param, item_name, item_image, item_desc, unlockable_id, is_silverlink)
Reward = {
item_name = item_name,
item_image = item_image,
item_desc = item_desc,
unlockable_id = unlockable_id,
is_silverlink = is_silverlink,
}
end
--call this once for each list item, and it will fill in the appropriate number of descriptions
function reward_granted_add_upgrades_descriptions(description, element)
local i = #Upgrades_descriptions + 1
Upgrades_descriptions[i] = {}
local t = Upgrades_descriptions[i]
t.description = description
t.element = element
end
-- Mouse inputs
function reward_granted_mouse_click(event, target_handle)
if target_handle == Bg_image.handle then
reward_granted_button_press()
end
end
function reward_granted_mouse_move(event, target_handle)
end