--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 Bg_mouse_input_tracker
local Bg_image
--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)
button_tips:pulse(1)
--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
--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)
--Set Name
local description_h = vint_object_find("reward_description", 0, Reward_granted_doc)
vint_set_property(description_h, "text_tag", item_desc)
local desc_text_h = vint_object_find("reward_description", 0, Reward_granted_doc)
local x, y = vint_get_property(desc_text_h, "anchor")
local w, h = element_get_actual_size(desc_text_h)
local button_tips_h = vint_object_find("button_tips", 0, Reward_granted_doc)
vint_set_property(button_tips_h, "anchor", x + 13, y + h + 30)
--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)
lua_play_anim(anim_h)
anim_h = vint_object_find("circles", 0, Reward_granted_doc)
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
game_UI_audio_play("UI_Unlock_Reward")
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...
--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)
Reward = {
item_name = item_name,
item_image = item_image,
item_desc = item_desc,
}
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