-------------------------------------------------------------------------------
--GSI
-------------------------------------------------------------------------------
-- Inherited from Vdo_base_object
Vdo_gsi_whored = Vdo_base_object:new_base()
-- Standard Init Function
function vdo_gsi_init()
end
-- Standard Cleanup Function
function vdo_gsi_cleanup()
end
-------------------------------------------------------------------------------
--CONSTANTS
-------------------------------------------------------------------------------
--Order of creation is timer, x/y, meter, info
--GSI Indicator Indexes, increment these if there is more than one
local GSI_TIMER = 0
local GSI_XY = 1
local GSI_METER = 5
local GSI_INFO = 9
local GSI_COMBO = 13
--Config Indexes, used to define the arangement of a configuration
local GSI_CONFIG_ROW = 1 --Row Number
local GSI_CONFIG_SKIN = 2 --Skin Type (Indicator Specific)
--local 1 = initializing, 2 = running, 3 = end, 4 = mission change
local GSI_STATE_INITIALIZING = 1
local GSI_STATE_RUNNING = 2
local GSI_STATE_END = 3
local GSI_STATE_MISSION_CHANGE = 4
HUD_KILL_ICON = 0
HUD_DEFEND_ICON = 1
HUD_USE_ICON = 2
HUD_REVIVE_ICON = 3
HUD_LOCATION_ICON = 4
HUD_COOP_ICON = 4
local GSI_OBJECTIVE_ICONS = {
[HUD_KILL_ICON] = "ui_hud_gsi_obj_kill",
[HUD_DEFEND_ICON] = "ui_hud_gsi_obj_protect",
[HUD_USE_ICON] = "ui_hud_gsi_obj_use",
[HUD_LOCATION_ICON] = "ui_hud_gsi_obj_goto",
}
--Enums for activity and other static configurations
local GSI_CONFIGS = {
-- Horde Mode
[3] = {
[GSI_INFO] = { 0, "", },
[GSI_INFO + 1] = { 1, "", },
[GSI_INFO + 2] = { 2, "", },
[GSI_XY] = { 3, "", },
},
}
--Audio Constants
GSI_AUDIO_COUNT_POSITIVE = game_audio_get_audio_id("SYS_HUD_CNTDWN_POS")
GSI_AUDIO_TRAIL_BLAZING = game_audio_get_audio_id("SYS_HUD_CNTDWN_POS")
GSI_AUDIO_DIV_COMPLETE = game_audio_get_audio_id("SYS_HUD_CNTDWN_POS")
--Formatting Constants
GSI_TEXT_SPACING = 9
-------------------------------------------------------------------------------
--Initializes GSI
-------------------------------------------------------------------------------
function Vdo_gsi_whored:init()
--Setup Core Values for the GSI
self.status = {
config_index = -1,
config = -1,
indicator_count = 0,
grid_spacing = 10,
state = -1,
diversion_level = -1,
is_dirty = false,
debug_mode = false,
}
--Store handles to our internal objects...
self.enemies_value_txt_h = vint_object_find("enemies_value_txt", self.handle)
self.enemies_title_txt_h = vint_object_find("enemies_title_txt", self.handle)
self.score_title_txt_h = vint_object_find("score_title_txt", self.handle)
self.score_value_txt_h = vint_object_find("score_value_txt", self.handle)
self.wave_description_txt_h = vint_object_find("wave_description_txt", self.handle)
self.wave_number_txt_h = vint_object_find("wave_number_txt", self.handle)
self.bg_bottom_h = vint_object_find("bg_bottom", self.handle)
self.bg_top_h = vint_object_find("bg_top", self.handle)
--Store the vdo copies in memory...
self.indicators = {}
--What grid the menu is using...
self.grid = {}
--References to Animations
self.anims = {}
--Initialize score...
self.score = 0
vint_set_property(self.score_value_txt_h , "text_tag", 0)
--Start score thread...
self.gsi_whored_thread = thread_new("vdo_gsi_whored_score_thread", self)
--Close the GSI
self:close()
end
function Vdo_gsi_whored:on_destroy()
if self.gsi_whored_thread ~= nil then
thread_kill(self.gsi_whored_thread)
end
end
-------------------------------------------------------------------------------
-- Updates GSI via Data Item update...
-- **sr2_local_player_gameplay_indicator_status**
--
-- The parameters are varied based on the data_type specified in the first
-- parameter from the dataitem.
-------------------------------------------------------------------------------
function Vdo_gsi_whored:update(di_h)
local data_type, param1, param2, param3, param4, param5, param6, param7, param8, param9 = vint_dataitem_get(di_h)
if self.status.debug_mode == true then
debug_print("vint", "GSI Update: " .. var_to_string(data_type).. "\n")
end
--Determine what datatype we are passing through so we can figure out what
--to do with the rest of the parameters.
if data_type == nil then
--No specified data_type so don't do anything.
elseif data_type == "configuration" then
--do nothing!
else
--Update Indicators
self:update_indicators(data_type, param1, param2, param3, param4, param5, param6, param7, param8, param9)
end
end
-------------------------------------------------------------------------------
-- Updates any of the indicators.
--
-- @param data_type Determines what type of indicator we send the other
-- Parameters to. The additional paramters are generic
-- and re-used for all the indicators
-- @param ind_index Indicator Index, used to map indicators between game
-- and Interface Lua.
-- @param visible Is the indicator Visible?
-- @param label_crc Label for the indicator...
-- @param icon_enum Icon to use for this widget
-- @param.. param4-9 Generic parameters use for all the other indicators
-------------------------------------------------------------------------------
function Vdo_gsi_whored:update_indicators(data_type, ind_index, visible, label_crc, icon_enum, param5, param6, param7, param8, param9)
local wave_title_index = GSI_INFO
local wave_description_index = GSI_INFO + 1
local score_index = GSI_INFO + 2
local enemies_index = GSI_XY
--information_indicator
local info_crc = param6
local info_value = param7
--if its x_y
local x_value = param6 --Time: seconds left
local y_value = param7 --Is it a positive timer?
local is_cash = param8 --Is the indicator cash
if ind_index == wave_title_index then
local insert_values = { [0] = label_crc, [1] = info_value }
local txt_tag = vint_insert_values_in_string("{0:text_tag_crc} {1}", insert_values)
-- Update wave_number_txt_hitle...
vint_set_property(self.wave_number_txt_h, "text_tag", txt_tag)
elseif ind_index == wave_description_index then
-- Update wave_number_txt_hitle...
vint_set_property(self.wave_description_txt_h, "text_tag_crc", label_crc)
elseif ind_index == score_index then
--Set label with crc
if label_crc == 0 or label_crc == nil then
--No crc or Invalid crc
vint_set_property(self.score_title_txt_h, "text_tag", "")
else
-- Update score title...
vint_set_property(self.score_title_txt_h, "text_tag_crc", label_crc)
end
--update score..
local score = tonumber(info_value)
if info_value ~= nil and score ~= nil then
--store score here and we will process and update later...
self.score = score
end
elseif ind_index == enemies_index then
--Set label with crc
if label_crc == 0 or label_crc == nil then
--No crc or Invalid crc
vint_set_property(self.enemies_title_txt_h, "text_tag", "")
else
-- Update enemies title...
vint_set_property(self.enemies_title_txt_h, "text_tag_crc", label_crc)
end
--Update value...
local x_y_value = x_value .. "/" .. y_value
vint_set_property(self.enemies_value_txt_h, "text_tag", x_y_value)
end
--always update layout... i know this function call is slow but there is no other way right now. because i cannot find out when all the updates have been called...
self:update_layout()
end
function Vdo_gsi_whored:grid_item_add(row, idx)
if self.grid[row] == nil then
self.grid[row] = idx
end
end
-------------------------------------------------------------------------------
-- Opens the GSI, causes the thing to creativly animate in...set_visible. true.
-------------------------------------------------------------------------------
function Vdo_gsi_whored:open()
self:set_visible(true)
end
-------------------------------------------------------------------------------
-- Closes the GSI, rips the heart out bitches. My name is Kano.
-------------------------------------------------------------------------------
function Vdo_gsi_whored:close()
self.status.is_dirty = true
self:set_visible(false)
end
-------------------------------------------------------------------------------
-- Show/Hide GSI
-------------------------------------------------------------------------------
function Vdo_gsi_whored:show(visible)
self:set_visible(visible)
end
-------------------------------------------------------------------------------
-- Updates the layout of the GSI, Puts the indicators on their assigned lines.
-- Updates background...
-------------------------------------------------------------------------------
function Vdo_gsi_whored:update_layout()
local top_box_width, top_box_height = element_get_actual_size(self.bg_top_h)
local bottom_box_width, bottom_box_height = element_get_actual_size(self.bg_bottom_h)
local wave_description_width, wave_description_height = element_get_actual_size(self.wave_description_txt_h)
local enemies_title_width, enemies_title_height = element_get_actual_size(self.enemies_title_txt_h)
local score_title_width, score_title_height = element_get_actual_size(self.score_title_txt_h)
local enemies_value_width, enemies_value_height = element_get_actual_size(self.enemies_value_txt_h)
local top_width = wave_description_width + 10
local x, y = vint_get_property(self.enemies_title_txt_h, "anchor")
local bottom_width = max(enemies_value_width, enemies_title_width)
local bottom_width = bottom_width + x + 10
local width = max(top_width, bottom_width)
-- Set background layer up...
element_set_actual_size(self.bg_top_h, width, top_box_height)
element_set_actual_size(self.bg_bottom_h, width, bottom_box_height)
end
function vdo_gsi_whored_score_thread(object)
local display_score = 0
while true do
-- Animate Cash
if display_score ~= object.score then
local diff_score = object.score - display_score
if diff_score > 5 or diff_score < -5 then
diff_score = floor(diff_score * 0.5)
end
display_score = display_score + diff_score
vint_set_property(object.score_value_txt_h , "text_tag", format_cash(display_score))
end
thread_yield()
end
end
--[[
#########################################################################
TEST FUNCTIONS
#########################################################################
]]
--Used to show the bounding box of an object. (NOTE: Does not work for offsets that are not 0,0)
Bounds_util_data = {}
function element_bounds_debug(element_handle)
local h
if Bounds_util_data[element_handle] == nil then
h = vint_object_create("bounds_util", "bitmap", element_handle)
vint_set_property(h, "image", "ui_blank")
vint_set_property(h, "tint", rand_float(.3,1),rand_float(.3,1),rand_float(.3,1))
vint_set_property(h, "alpha", .5)
vint_set_property(h, "depth", -5000)
Bounds_util_data[element_handle] = h
else
h = Bounds_util_data[element_handle]
end
vint_set_property(h, "anchor", 0,0)
local element_width, element_height = element_get_actual_size(element_handle)
element_set_actual_size(h, element_width, element_height)
end
function element_bounds_debug_clear()
for key, val in pairs(Bounds_util_data) do
vint_object_destroy(val)
end
end