--BUTTON MASH TYPES...
local BUTTON_MASH_HIDDEN = -1
local BUTTON_MASH_A = 0
local BUTTON_MASH_X = 1
local BUTTON_MASH_Y = 2
local BUTTON_MASH_ROTATE_LS_LEFT = 3
local BUTTON_MASH_ROTATE_LS_RIGHT = 4
local BUTTON_MASH_ROTATE_RS_LEFT = 5
local BUTTON_MASH_ROTATE_RS_RIGHT = 6
--Button mashing states...
local HUD_BTNMASH_STATE_HIDDEN = -1 --used internally...
local HUD_BTNMASH_STATE_UPDATE = 1
local HUD_BTNMASH_STATE_SUCCESS = 2
local HUD_BTNMASH_STATE_FAIL = 3
local HUD_BTNMASH_STATE_HIDE = 4
Hud_btnmash_platform_is_ps3 = false
local HUD_BTNMASH_COLOR_DIM = {128/255, 128/255, 128/255}
local HUD_BTNMASH_STICK_OFFSET = -18
-------------------------------------------------------------------------------
--Handles
-------------------------------------------------------------------------------
--Base groups
local Hud_btnmash_fail_grp_h = 0
local Hud_btnmash_win_grp_h = 0
local Hud_btnmash_btn_mash_grp_h = 0
-- Left Stick
local Hud_btnmash_stick_ls_grp_h = 0
local Hud_btnmash_stick_ls_base_bmp_h = 0
local Hud_btnmash_stick_ls_pad_h = 0
local Hud_btnmash_stick_ls_label_h = 0
-- Right Stick
local Hud_btnmash_stick_rs_grp_h = 0
local Hud_btnmash_stick_rs_base_bmp_h = 0
local Hud_btnmash_stick_rs_pad_h = 0
local Hud_btnmash_stick_rs_label_h = 0
-- Button
local Hud_btnmash_btn_grp_h = 0
local Hud_btnmash_btn_1_h = 0
local Hud_btnmash_btn_2_h = 0
-- Mouse
local Hud_btnmash_mouse_grp_h = 0
-- Key
local Hud_btnmash_key_grp_h = 0
local Hud_btnmash_pc_key = 0
-- Meter
local Hud_btnmash_meter_grp_h = 0
local Hud_btnmash_meter_bg_h = 0
local Hud_btnmash_meter_fill_h = 0
local Hud_btnmash_meter_fill_bg_h = 0
-- Timer
local Hud_btnmash_timer_grp_h = 0
local Hud_btnmash_timer_txt_h = 0
local Hud_btnmash_meter_fill_h = 0
local Hud_btnmash_meter_fill_h = 0
-- Help Text
local Hud_btnmash_help_txt_grp_h = 0
local Hud_btnmash_help_txt_h = 0
local Hud_btnmash_help_txt_bg_h = 0
-- Mash/Rotate Animations
local Hud_btn_mash_btn_mash_anim_h = 0
local Hud_btn_mash_ls_rotate_left_anim_h = 0
local Hud_btn_mash_ls_rotate_right_anim_h = 0
local Hud_btn_mash_rs_rotate_left_anim_h = 0
local Hud_btn_mash_rs_rotate_right_anim_h = 0
local Hud_btn_mash_btnmash_fade_in_anim_h = 0
local Hud_btn_mash_btnmash_fade_out_anim_h = 0
local Hud_btn_mash_mouse_left_anim_h = 0
local Hud_btn_mash_mouse_right_anim_h = 0
--Fade/State Animations
local Hud_btn_mash_fade_in_anim_h = 0
local Hud_btn_mash_fade_out_anim_h = 0
local Hud_btn_mash_fail_anim_h = 0
local Hud_btn_mash_success_anim_h = 0
--Global State variables
local Hud_btnmash_button_index = -2
local Hud_btnmash_help_txt = -1
local Hud_btnmash_meter_pct = -1
local Hud_btnmash_timer_value = -1
local Hud_btnmash_state = -1
--Scale base for the meter fill...
local Hud_btnmash_meter_base_width = 1
local Hud_btnmash_meter_base_height = 1
-------------------------------------------------------------------------------
-- Init
--
function hud_btnmash_init()
local hud_btnmash_doc_h = vint_document_find("hud_btnmash")
--get the platform
local platform = game_get_platform()
if platform == "XBOX360" then
Hud_btnmash_platform_is_ps3 = false
elseif platform == "PS3" then
Hud_btnmash_platform_is_ps3 = true
end
--Find handles to everything...
--Base groups
Hud_btnmash_fail_grp_h = vint_object_find("fail_grp")
Hud_btnmash_win_grp_h = vint_object_find("win_grp")
Hud_btnmash_btn_mash_grp_h = vint_object_find("btn_mash_grp")
--Left Stick
Hud_btnmash_stick_ls_grp_h = vint_object_find("stick_ls_grp")
Hud_btnmash_stick_ls_pad_h = vint_object_find("stick_ls_pad")
Hud_btnmash_stick_ls_label_h = vint_object_find("stick_ls_label")
Hud_btnmash_stick_ls_base_bmp_h = vint_object_find("stick_ls_base_bmp")
--Right Stick
Hud_btnmash_stick_rs_grp_h = vint_object_find("stick_rs_grp")
Hud_btnmash_stick_rs_pad_h = vint_object_find("stick_rs_pad")
Hud_btnmash_stick_rs_label_h = vint_object_find("stick_rs_label")
Hud_btnmash_stick_rs_base_bmp_h = vint_object_find("stick_rs_base_bmp")
-- Button
Hud_btnmash_btn_grp_h = vint_object_find("btn_grp")
Hud_btnmash_btn_1_h = vint_object_find("btn_1")
Hud_btnmash_btn_2_h = vint_object_find("btn_2")
-- Mouse and keyboard
Hud_btnmash_mouse_grp_h = vint_object_find("mouse_rotate_grp")
Hud_btnmash_key_grp_h = vint_object_find("key_grp")
--Meter
Hud_btnmash_meter_grp_h = vint_object_find("meter_grp")
Hud_btnmash_meter_bg_h = vint_object_find("meter_bg")
Hud_btnmash_meter_fill_h = vint_object_find("meter_fill")
Hud_btnmash_meter_fill_bg_h = vint_object_find("meter_fill_bg")
--Timer
Hud_btnmash_timer_grp_h = vint_object_find("timer_grp")
Hud_btnmash_timer_txt_h = vint_object_find("timer_txt")
Hud_btnmash_meter_fill_h = vint_object_find("meter_fill")
Hud_btnmash_meter_fill_h = vint_object_find("meter_fill")
--Help Text
Hud_btnmash_help_txt_grp_h = vint_object_find("help_txt_grp")
Hud_btnmash_help_txt_h = vint_object_find("help_txt")
Hud_btnmash_help_txt_bg_h = vint_object_find("help_txt_bg")
--Animations
Hud_btn_mash_btn_mash_anim_h = vint_object_find("btn_mash_anim")
Hud_btn_mash_ls_rotate_left_anim_h = vint_object_find("ls_rotate_left_anim")
Hud_btn_mash_ls_rotate_right_anim_h = vint_object_find("ls_rotate_right_anim")
Hud_btn_mash_rs_rotate_left_anim_h = vint_object_find("rs_rotate_left_anim")
Hud_btn_mash_rs_rotate_right_anim_h = vint_object_find("rs_rotate_right_anim")
Hud_btn_mash_mouse_left_anim_h = vint_object_find("mouse_rotate_left_anim")
Hud_btn_mash_mouse_right_anim_h = vint_object_find("mouse_rotate_right_anim")
--State Animations
Hud_btn_mash_fade_in_anim_h = vint_object_find("fade_in_anim")
Hud_btn_mash_fade_out_anim_h = vint_object_find("fade_out_anim")
Hud_btn_mash_fail_anim_h = vint_object_find("fail_anim")
Hud_btn_mash_success_anim_h = vint_object_find("btn_mash_success_anim")
--These tweens get played when we are done, these are used to tell the game we are finished displaying the UI.
local success_end_twn_h = vint_object_find("success_end_twn")
local fail_end_twn_h = vint_object_find("fail_end_twn")
local fade_out_twn_h = vint_object_find("fade_out_twn")
vint_set_property(success_end_twn_h, "end_event", "hud_btnmash_complete")
vint_set_property(fail_end_twn_h, "end_event", "hud_btnmash_complete")
vint_set_property(fade_out_twn_h, "end_event", "hud_btnmash_complete")
--setup looping tweens for button mash (sticks loop normally)
local btn_1_off_standard_twn_h = vint_object_find("btn_1_off_standard", Hud_btn_mash_btn_mash_anim_h)
vint_set_property(btn_1_off_standard_twn_h, "end_event", "vint_anim_loop_callback")
--Initialize QTE key
Hud_btnmash_pc_key = Vdo_qte_key:new("pc_key", 0, hud_btnmash_doc_h)
Hud_btnmash_pc_key:set_text(game_get_key_name_for_action("CBA_OFC_JUMP_CLIMB"))
local width = Hud_btnmash_pc_key:get_width()
local x, y = vint_get_property(Hud_btnmash_pc_key.handle, "anchor")
vint_set_property(Hud_btnmash_pc_key.handle, "anchor", -(width * 0.5), y)
--Initialize Meter Variables
Hud_btnmash_meter_base_width, Hud_btnmash_meter_base_height = vint_get_property(Hud_btnmash_meter_fill_bg_h, "scale")
--localize text
local fail_txt_h = vint_object_find("fail_txt")
local win_txt_h = vint_object_find("win_txt")
vint_set_property(fail_txt_h, "text_tag", "FAILED!")
vint_set_property(win_txt_h, "text_tag", "SUCCESS!")
vint_set_property(Hud_btnmash_fail_grp_h, "alpha", 0)
vint_set_property(Hud_btnmash_win_grp_h, "alpha", 0)
vint_set_property(Hud_btnmash_btn_mash_grp_h, "alpha", 0)
--subscription
vint_dataitem_add_subscription("button_mashing_minigame", "update", "hud_btnmash_update")
Hud_btnmash_button_index = -1
end
-------------------------------------------------------------------------------
-- Cleanup
--
function hud_btnmash_cleanup()
end
-------------------------------------------------------------------------------
-- Dataitem update for button mashing.
-- button index - Button image to display from BUTTON MASH TYPES enums.
-- help_text - display string ID
-- meter_pct - percentage (0-1) complete
-- timer_value - time remaining in minigame.
-- state - [1 = update, 2 = success, 3 = fail, 4 = hide] (Button mashing states)
--
-------------------------------------------------------------------------------
function hud_btnmash_update(di_h, event)
local button_index, help_txt, meter_pct, timer_value, state = vint_dataitem_get(di_h)
if Hud_btnmash_button_index ~= button_index then
-- Set button images
if (Hud_btnmash_platform_is_ps3 == true) then
-- use PS3 button images
if (button_index == BUTTON_MASH_A) then -- CROSS
vint_set_property(Hud_btnmash_btn_1_h, "image", "ui_qte_cross_up_ps3")
vint_set_property(Hud_btnmash_btn_2_h, "image", "ui_qte_cross_down_ps3")
elseif (button_index == BUTTON_MASH_X) then -- SQUARE
vint_set_property(Hud_btnmash_btn_1_h, "image", "ui_qte_square_up_ps3")
vint_set_property(Hud_btnmash_btn_2_h, "image", "ui_qte_square_down_ps3")
elseif (button_index == BUTTON_MASH_Y) then -- TRIANGLE
vint_set_property(Hud_btnmash_btn_1_h, "image", "ui_qte_triangle_up_ps3")
vint_set_property(Hud_btnmash_btn_2_h, "image", "ui_qte_triangle_down_ps3")
elseif (button_index >= BUTTON_MASH_ROTATE_LS_LEFT and button_index <= BUTTON_MASH_ROTATE_RS_RIGHT ) then --Stick
vint_set_property(Hud_btnmash_stick_ls_pad_h, "image", "ui_qte_stick_ps3")
vint_set_property(Hud_btnmash_stick_ls_base_bmp_h, "image", "ui_qte_base_ps3")
vint_set_property(Hud_btnmash_stick_rs_pad_h, "image", "ui_qte_stick_ps3")
vint_set_property(Hud_btnmash_stick_rs_base_bmp_h, "image", "ui_qte_base_ps3")
vint_set_property(Hud_btnmash_stick_ls_label_h, "text_tag", "L")
vint_set_property(Hud_btnmash_stick_rs_label_h, "text_tag", "R")
else
--If btn value isn't accounted for throw up a garbage texture to let us know in game
vint_set_property(Hud_qte_btn_1_h, "image", "ui_hud_not_police")
vint_set_property(Hud_qte_btn_2_h, "image", "ui_hud_not_police")
end
else
-- use XBOX2 button images
if (button_index == BUTTON_MASH_A) then
vint_set_property(Hud_btnmash_btn_1_h, "image", "ui_qte_a_up_xbox2")
vint_set_property(Hud_btnmash_btn_2_h, "image", "ui_qte_a_down_xbox2")
elseif (button_index == BUTTON_MASH_X) then
vint_set_property(Hud_btnmash_btn_1_h, "image", "ui_qte_x_up_xbox2")
vint_set_property(Hud_btnmash_btn_2_h, "image", "ui_qte_x_down_xbox2")
elseif (button_index == BUTTON_MASH_Y) then
vint_set_property(Hud_btnmash_btn_1_h, "image", "ui_qte_y_up_xbox2")
vint_set_property(Hud_btnmash_btn_2_h, "image", "ui_qte_y_down_xbox2")
elseif (button_index >= BUTTON_MASH_ROTATE_LS_LEFT and button_index <= BUTTON_MASH_ROTATE_RS_RIGHT ) then --Stick
vint_set_property(Hud_btnmash_stick_ls_pad_h, "image", "ui_qte_stick_xbox2")
vint_set_property(Hud_btnmash_stick_ls_base_bmp_h, "image", "ui_qte_base_xbox2")
vint_set_property(Hud_btnmash_stick_rs_pad_h, "image", "ui_qte_stick_xbox2")
vint_set_property(Hud_btnmash_stick_rs_base_bmp_h, "image", "ui_qte_base_xbox2")
vint_set_property(Hud_btnmash_stick_ls_label_h, "text_tag", "LS")
vint_set_property(Hud_btnmash_stick_rs_label_h, "text_tag", "RS")
else
--If btn value isn't accounted for throw up a garbage texture to let us know in game
vint_set_property(Hud_btnmash_btn_1_h, "image", "ui_hud_not_police")
vint_set_property(Hud_qte_btn_2_h, "image", "ui_hud_not_police")
end
end
--Now modify the screen and play the appropriate action.
--Pause all playing animations..
vint_set_property(Hud_btn_mash_btn_mash_anim_h, "is_paused", true)
vint_set_property(Hud_btn_mash_ls_rotate_left_anim_h, "is_paused", true)
vint_set_property(Hud_btn_mash_ls_rotate_right_anim_h, "is_paused", true)
vint_set_property(Hud_btn_mash_rs_rotate_left_anim_h, "is_paused", true)
vint_set_property(Hud_btn_mash_rs_rotate_right_anim_h, "is_paused", true)
vint_set_property(Hud_btn_mash_btn_mash_anim_h, "is_paused", true)
vint_set_property(Hud_btn_mash_mouse_left_anim_h, "is_paused", true)
vint_set_property(Hud_btn_mash_mouse_right_anim_h, "is_paused", true)
Hud_btnmash_pc_key:mash(-1)
if button_index >= BUTTON_MASH_A and button_index <= BUTTON_MASH_Y then
--Button Mashing
--Hide sticks, show button
vint_set_property(Hud_btnmash_stick_rs_grp_h, "visible", false)
vint_set_property(Hud_btnmash_stick_ls_grp_h, "visible", false)
vint_set_property(Hud_btnmash_mouse_grp_h, "visible", false)
if game_is_active_input_gamepad() then
vint_set_property(Hud_btnmash_btn_grp_h, "visible", true)
vint_set_property(Hud_btnmash_key_grp_h, "visible", false)
else
vint_set_property(Hud_btnmash_btn_grp_h, "visible", false)
vint_set_property(Hud_btnmash_key_grp_h, "visible", true)
end
--Play button mash anim
lua_play_anim(Hud_btn_mash_btn_mash_anim_h)
Hud_btnmash_pc_key:mash(HUD_QTE_ANIM_MASH_STANDARD)
elseif button_index >= BUTTON_MASH_ROTATE_LS_LEFT and button_index <= BUTTON_MASH_ROTATE_RS_RIGHT then
--Stick movements
--Show sticks, hide button
if game_is_active_input_gamepad() then
vint_set_property(Hud_btnmash_stick_rs_grp_h, "visible", true)
vint_set_property(Hud_btnmash_stick_ls_grp_h, "visible", true)
vint_set_property(Hud_btnmash_mouse_grp_h, "visible", false)
else
vint_set_property(Hud_btnmash_stick_rs_grp_h, "visible", false)
vint_set_property(Hud_btnmash_stick_ls_grp_h, "visible", false)
vint_set_property(Hud_btnmash_mouse_grp_h, "visible", true)
end
vint_set_property(Hud_btnmash_btn_grp_h, "visible", false)
vint_set_property(Hud_btnmash_key_grp_h, "visible", false)
local stick_ls_rotate_h = vint_object_find("stick_ls_rotate")
local stick_ls_unrotate_h = vint_object_find("stick_ls_unrotate")
local stick_rs_rotate_h = vint_object_find("stick_rs_rotate")
local stick_rs_unrotate_h = vint_object_find("stick_rs_unrotate")
--Default left stick is active...
local stick_grp_h = Hud_btnmash_stick_ls_grp_h
local stick_rotate_h = stick_ls_rotate_h
local stick_unrotate_h = stick_ls_unrotate_h
local dim_stick_grp_h = Hud_btnmash_stick_rs_grp_h
local dim_stick_rotate_h = stick_rs_rotate_h
local dim_stick_unrotate_h = stick_rs_unrotate_h
if button_index >= BUTTON_MASH_ROTATE_RS_LEFT and button_index <= BUTTON_MASH_ROTATE_RS_RIGHT then
--Right stick is active...
stick_grp_h = Hud_btnmash_stick_rs_grp_h
stick_rotate_h = stick_rs_rotate_h
stick_unrotate_h = stick_rs_unrotate_h
dim_stick_grp_h = Hud_btnmash_stick_ls_grp_h
dim_stick_rotate_h = stick_ls_rotate_h
dim_stick_unrotate_h = stick_ls_unrotate_h
end
--Dim stick, center and unrotate...
vint_set_property(dim_stick_grp_h, "tint", HUD_BTNMASH_COLOR_DIM[1], HUD_BTNMASH_COLOR_DIM[2], HUD_BTNMASH_COLOR_DIM[3])
vint_set_property(dim_stick_unrotate_h, "anchor", 0, 0)
vint_set_property(dim_stick_unrotate_h, "rotation", 0)
vint_set_property(dim_stick_rotate_h, "rotation", 0)
--Reset normal stick anchor of unrotated item and tint...
vint_set_property(stick_unrotate_h, "anchor", 0, HUD_BTNMASH_STICK_OFFSET)
vint_set_property(stick_grp_h, "tint", 255, 255, 255)
--Play animation on appropraite stick...
if button_index == BUTTON_MASH_ROTATE_LS_LEFT then
lua_play_anim(Hud_btn_mash_ls_rotate_left_anim_h)
lua_play_anim(Hud_btn_mash_mouse_left_anim_h)
elseif button_index == BUTTON_MASH_ROTATE_LS_RIGHT then
lua_play_anim(Hud_btn_mash_ls_rotate_right_anim_h)
lua_play_anim(Hud_btn_mash_mouse_right_anim_h)
elseif button_index == BUTTON_MASH_ROTATE_RS_LEFT then
lua_play_anim(Hud_btn_mash_rs_rotate_left_anim_h)
lua_play_anim(Hud_btn_mash_mouse_left_anim_h)
elseif button_index == BUTTON_MASH_ROTATE_RS_RIGHT then
lua_play_anim(Hud_btn_mash_rs_rotate_right_anim_h)
lua_play_anim(Hud_btn_mash_mouse_right_anim_h)
end
end
Hud_btnmash_button_index = button_index
end
--Update help text
if Hud_btnmash_help_txt ~= help_txt then
if help_txt == "" then
vint_set_property(Hud_btnmash_help_txt_grp_h, "visible", false)
else
vint_set_property(Hud_btnmash_help_txt_grp_h, "visible", true)
end
--Update text field
vint_set_property(Hud_btnmash_help_txt_h, "text_tag", help_txt)
--Update background of text
local width, height = element_get_actual_size(Hud_btnmash_help_txt_h)
local base_width, base_height = element_get_actual_size(Hud_btnmash_help_txt_bg_h)
element_set_actual_size(Hud_btnmash_help_txt_bg_h, width + 15, base_height)
Hud_btnmash_help_txt = help_txt
end
--Update Meter
if Hud_btnmash_meter_pct ~= meter_pct then
local meter_x_scale = Hud_btnmash_meter_base_width * meter_pct
vint_set_property(Hud_btnmash_meter_fill_h, "scale", meter_x_scale, Hud_btnmash_meter_base_height)
Hud_btnmash_meter_pct = meter_pct
end
--Update Timer
if Hud_btnmash_timer_value ~= timer_value then
if timer_value >= 0 then
vint_set_property(Hud_btnmash_timer_grp_h, "visible", true)
local time_formatted = format_clock(timer_value, true)
vint_set_property(Hud_btnmash_timer_txt_h, "text_tag", ":" .. time_formatted)
else
vint_set_property(Hud_btnmash_timer_grp_h, "visible", false)
end
Hud_btnmash_timer_value = timer_value
end
--Play animation to switch the the appropriate state...
-- Also hide groups using Alpha that don't belong in the state...
if Hud_btnmash_state ~= state then
--Always pause all animations...
vint_set_property(Hud_btn_mash_fade_in_anim_h, "is_paused", true)
vint_set_property(Hud_btn_mash_success_anim_h, "is_paused", true)
vint_set_property(Hud_btn_mash_fail_anim_h, "is_paused", true)
vint_set_property(Hud_btn_mash_fade_out_anim_h, "is_paused", true)
if state == HUD_BTNMASH_STATE_UPDATE then
-- fade in
lua_play_anim(Hud_btn_mash_fade_in_anim_h)
vint_set_property(Hud_btnmash_fail_grp_h, "alpha", 0)
vint_set_property(Hud_btnmash_win_grp_h, "alpha", 0)
elseif state == HUD_BTNMASH_STATE_SUCCESS then
--Success
lua_play_anim(Hud_btn_mash_success_anim_h)
vint_set_property(Hud_btnmash_fail_grp_h, "alpha", 0)
elseif state == HUD_BTNMASH_STATE_FAIL then
--FAIL
lua_play_anim(Hud_btn_mash_fail_anim_h)
vint_set_property(Hud_btnmash_fail_grp_h, "alpha", 0)
elseif state == HUD_BTNMASH_STATE_HIDE then
--Hide immediatly...
vint_set_property(Hud_btnmash_btn_mash_grp_h, "alpha", 0)
vint_set_property(Hud_btnmash_fail_grp_h, "alpha", 0)
vint_set_property(Hud_btnmash_win_grp_h, "alpha", 0)
end
Hud_btnmash_state = state
end
end
function hud_btnmash_complete()
-- Tell C++ here that we have finished. and can start another one.
-- This will get called eventually if any of the states change from UPDATE to SUCCESS, FAIL, or HIDE. Via tween callback...
Hud_btnmash_state = HUD_BTNMASH_STATE_HIDDEN
autil_mashing_minigame_faded_out()
end