-- NOTE: For PC-specific functions, they all start with pc_ so they can easily be removed or blanked out if necessary (due to memory constraints on consoles)
HINT_BUTTON_RMB_OVERRIDE = "rmb_override"
function vdo_hint_button_init()
end
function vdo_hint_button_cleanup()
end
-- Inherited from Vdo_base_object
Vdo_hint_button = Vdo_base_object:new_base()
function Vdo_hint_button:init()
if game_get_platform() == "PC" then
self:pc_init()
end
end
-- Do all the initialization for PC-centric hints
function Vdo_hint_button:pc_init()
-- Destroy any extra elements if they exist
self:pc_destroy_extra()
-- Hide the default hint icon
self.old_icon = Vdo_base_object:new("hint_icon", self.handle, self.doc_handle)
self.old_icon:set_visible(false)
-- Create default settings
self.max_width = 100 -- Not including the buffer
self.default_width = 28
self.height = 32 -- Includes buffer
self.text_offset = 6
self.width = self.default_width
self.buffer = 6
self.single_letter = true
self.two_line = false
self.bg_color = {R=220/255,G=220/255,B=220/255}
self.text_color = {R=220/255,G=220/255,B=220/255}
self.size_large = 0.75
self.size_small = 0.55
-- Create the backdrop (three images, move/scale them in set_button)
self.bg_left_h = vint_object_create("bg_left", "bitmap", self.handle)
self.bg_right_h = vint_object_create("bg_right", "bitmap", self.handle)
self.bg_middle_h = vint_object_create("bg_middle", "bitmap", self.handle)
self.bg_left = Vdo_base_object:new("bg_left", self.handle, self.doc_handle)
self.bg_right = Vdo_base_object:new("bg_right", self.handle, self.doc_handle)
self.bg_middle = Vdo_base_object:new("bg_middle", self.handle, self.doc_handle)
self.bg_left:set_property("auto_offset", "c")
self.bg_left:set_image("ui_pc_key_side")
self.bg_left:set_color(self.bg_color)
self.bg_left:set_anchor((self.width + self.buffer) * -0.5 + 4, 0)
self.bg_left:set_actual_size(8, self.height)
self.bg_left:set_visible(false)
self.bg_left:set_depth(2)
self.bg_right:set_property("auto_offset", "c")
self.bg_right:set_image("ui_pc_key_side")
self.bg_right:set_color(self.bg_color)
self.bg_right:set_anchor((self.width + self.buffer) * 0.5 - 4, 0)
self.bg_right:set_actual_size(-8, self.height)
self.bg_right:set_visible(false)
self.bg_right:set_depth(2)
self.bg_middle:set_property("auto_offset", "c")
self.bg_middle:set_image("ui_pc_key_middle")
self.bg_middle:set_color(self.bg_color)
self.bg_middle:set_actual_size(self.width + self.buffer - 16, self.height)
self.bg_middle:set_visible(false)
self.bg_middle:set_depth(2)
-- Set up text for key names
self.key_text1_h = vint_object_create("key_text1", "text", self.handle)
self.key_text2_h = vint_object_create("key_text2", "text", self.handle)
self.key_text1 = Vdo_base_object:new("key_text1", self.handle, self.doc_handle)
self.key_text2 = Vdo_base_object:new("key_text2", self.handle, self.doc_handle)
self.key_text1:set_property("font", "thin")
self.key_text1:set_property("auto_offset", "c")
self.key_text1:set_text("!")
self.key_text1:set_anchor(0, 0)
self.key_text1:set_scale(self.size_large, self.size_large)
self.key_text1:set_color(self.text_color)
self.key_text1:set_visible(false)
self.key_text2:set_property("font", "thin")
self.key_text2:set_property("auto_offset", "c")
self.key_text2:set_text("")
self.key_text2:set_anchor(0, self.text_offset) -- self.buffer * 0.5)
self.key_text2:set_scale(self.size_small, self.size_small)
self.key_text2:set_color(self.text_color)
self.key_text2:set_visible(false)
end
function Vdo_hint_button:pc_destroy_extra()
local temp_obj = Vdo_base_object:new("key_text1", self.handle, self.doc_handle)
if temp_obj ~= nil then
temp_obj:object_destroy()
end
temp_obj = Vdo_base_object:new("key_text2", self.handle, self.doc_handle)
if temp_obj ~= nil then
temp_obj:object_destroy()
end
temp_obj = Vdo_base_object:new("bg_left", self.handle, self.doc_handle)
if temp_obj ~= nil then
temp_obj:object_destroy()
end
temp_obj = Vdo_base_object:new("bg_right", self.handle, self.doc_handle)
if temp_obj ~= nil then
temp_obj:object_destroy()
end
temp_obj = Vdo_base_object:new("bg_middle", self.handle, self.doc_handle)
if temp_obj ~= nil then
temp_obj:object_destroy()
end
end
function Vdo_hint_button:pc_button_set_visible(visible)
local temp_obj = Vdo_base_object:new("key_text1", self.handle, self.doc_handle)
if temp_obj ~= nil then
temp_obj:set_visible(visible)
end
temp_obj = Vdo_base_object:new("key_text2", self.handle, self.doc_handle)
if temp_obj ~= nil then
temp_obj:set_visible(visible)
end
temp_obj = Vdo_base_object:new("bg_left", self.handle, self.doc_handle)
if temp_obj ~= nil then
temp_obj:set_visible(visible)
end
temp_obj = Vdo_base_object:new("bg_right", self.handle, self.doc_handle)
if temp_obj ~= nil then
temp_obj:set_visible(visible)
end
temp_obj = Vdo_base_object:new("bg_middle", self.handle, self.doc_handle)
if temp_obj ~= nil then
temp_obj:set_visible(visible)
end
end
-- Sets the Art and Color of the button object
function Vdo_hint_button:set_button( button, pc_key_text, force_gamepad_icon, force_kbd_icon )
force_gamepad_icon = force_gamepad_icon or false
force_kbd_icon = force_kbd_icon or false
local icon = Vdo_base_object:new( "hint_icon", self.handle, self.doc_handle)
if force_kbd_icon or (game_is_active_input_gamepad() == false and force_gamepad_icon == false) then
if game_get_platform() == "PC" then
if (pc_key_text ~= nil) then
self:pc_set_key_text(pc_key_text)
else
self:pc_set_button(button)
end
self:pc_button_set_visible(true)
end
icon:set_visible(false)
else
icon:set_image(button)
icon:set_visible(true)
if game_get_platform() == "PC" then
self:pc_button_set_visible(false)
end
end
if game_machinima_hide_hints() then
self:pc_button_set_visible(false)
icon:set_visible(false)
end
end
-- Set the button text based on the button given
function Vdo_hint_button:pc_set_button(button)
if button == CTRL_MENU_BUTTON_A then
self:pc_set_key_text(game_get_key_name(28)) -- "ENTER"
elseif button == CTRL_MENU_BUTTON_B then
self:pc_set_key_text(game_get_key_name(1)) -- "ESC"
elseif button == CTRL_BUTTON_X then
self:pc_set_key_text(game_get_key_name(59)) -- "F1"
elseif button == CTRL_BUTTON_Y then
self:pc_set_key_text(game_get_key_name(57), false) --"Space"
elseif button == HINT_BUTTON_RMB_OVERRIDE then
self:pc_set_key_text("MENU_RIGHT_MOUSE")
elseif button == CTRL_BUTTON_LB then
self:pc_set_key_text("LB")
elseif button == CTRL_BUTTON_RB then
self:pc_set_key_text("RB")
elseif button == CTRL_BUTTON_LT then
self:pc_set_key_text("LT")
elseif button == CTRL_BUTTON_RT then
self:pc_set_key_text("RT")
elseif button == CTRL_BUTTON_LS then
self:pc_set_key_text("LEFT", false, true, "STICK")
elseif button == CTRL_BUTTON_LS_PRESS then
self:pc_set_key_text("LEFT", false, true, "CLICK")
elseif button == CTRL_BUTTON_RS then
self:pc_set_key_text("RIGHT", false, true, "STICK")
elseif button == CTRL_BUTTON_RS_PRESS then
self:pc_set_key_text("RIGHT", false, true, "CLICK")
elseif button == CTRL_MENU_BUTTON_BACK then
self:pc_set_key_text(game_get_key_name(15), false) --"Tab"
elseif button == CTRL_BUTTON_START then
self:pc_set_key_text(game_get_key_name(28)) -- "ENTER"
elseif button == CTRL_BUTTON_DPAD then
self:pc_set_key_text("MENU_ARROW_KEYS")
elseif button == CTRL_BUTTON_DPAD_UP then
self:pc_set_key_text("UP")
elseif button == CTRL_BUTTON_DPAD_DOWN then
self:pc_set_key_text("DOWN")
elseif button == CTRL_BUTTON_DPAD_LEFT then
self:pc_set_key_text("LEFT")
elseif button == CTRL_BUTTON_DPAD_RIGHT then
self:pc_set_key_text("RIGHT")
elseif button == CTRL_BUTTON_DPAD_UP_DOWN then
self:pc_set_key_text("UP", false, true, "DOWN")
elseif button == CTRL_BUTTON_DPAD_LEFT_RIGHT then
self:pc_set_key_text("LEFT", false, true, "RIGHT")
elseif button == CTRL_BUTTON_MOUSE_SCROLL then
self:pc_set_key_text("PC_MOUSE", false, true, "PC_SCROLL")
else
self:pc_set_key_text("UNKNOWN KEY", false, true, "PLEASE ADD MAPPING")
end
end
-- Sets the key text
function Vdo_hint_button:pc_set_key_text(text, single, two_line, t2)
self.single_letter = single or false
self.two_line = two_line or false
local text2 = t2 or ""
-- Set the primary key text
self.key_text1:set_text(text)
self.key_text1:set_visible(true)
if self.single_letter then
-- Set to single letter scale
self.key_text1:set_scale(self.size_large, self.size_large)
self.key_text1:set_anchor(0, 0)
self.key_text2:set_text("")
self.key_text2:set_visible(false)
self.width = self.default_width
else
local max_width = self.default_width
local w, h, w2
-- Set text scale and resize if necessary
self.key_text1:set_scale(self.size_small, self.size_small)
self.key_text2:set_scale(self.size_small, self.size_small)
w, h = self.key_text1:get_actual_size()
max_width = max(max_width, w)
if max_width > self.max_width then
self.key_text1:set_actual_size(self.max_width, h)
max_width = self.max_width
end
if self.two_line then
self.key_text1:set_anchor(0, -self.text_offset)
self.key_text2:set_text(text2)
self.key_text2:set_visible(true)
-- Readjust size
w, h = self.key_text2:get_actual_size()
max_width = max(max_width, w)
if max_width > self.max_width then
self.key_text2:set_actual_size(self.max_width, h)
max_width = self.max_width
end
else
self.key_text1:set_anchor(0, 0)
self.key_text2:set_text("")
self.key_text2:set_visible(false)
end
-- Find the smallest X scale for the two text fields and set that scale for all dimensions of both fields
w, h = self.key_text1:get_scale()
w = w or 1.0
w2, h = self.key_text2:get_scale()
w2 = w2 or 1.0
w = min(w, w2)
self.key_text1:set_scale(w, w)
self.key_text2:set_scale(w, w)
self.width = max_width
end
-- Readjust the backdrop size
self.bg_left:set_anchor((self.width + self.buffer) * -0.5 + 4, 0)
self.bg_right:set_anchor((self.width + self.buffer) * 0.5 - 4, 0)
self.bg_middle:set_actual_size(self.width + self.buffer - 16, self.height)
self.bg_left:set_visible(true)
self.bg_right:set_visible(true)
self.bg_middle:set_visible(true)
end
function Vdo_hint_button:get_size()
if game_is_active_input_gamepad() == false then
local width, height = self.bg_middle:get_actual_size()
width = width + 16
return width, height
else
local icon = Vdo_base_object:new("hint_icon", self.handle, self.doc_handle)
local width, height = icon:get_actual_size()
return width, height
end
end
-- Gets the width of the default hint icon (used for alignment on PC)
function Vdo_hint_button:get_default_width()
local icon = Vdo_base_object:new("hint_icon", self.handle, self.doc_handle)
local width, height = icon:get_actual_size()
return width
end
function Vdo_hint_button:set_disabled()
local hint_anim = Vdo_anim_object:new("hint_ring_anim",self.handle, self.doc_handle)
hint_anim:stop()
end
function Vdo_hint_button:set_enabled()
local hint_anim = Vdo_anim_object:new("hint_ring_anim",self.handle, self.doc_handle)
hint_anim:play()
end