---------------------------------------------------------------------------
-- Newsticker!
---------------------------------------------------------------------------
Current_ticker = -1
local Screen_width = 1280
local NEWSTICKER_SEPERATOR_PADDING = 10
local NEWSTICKER_TEXT_PADDING = 20
local PIXELS_PER_SECOND = 60
local Ticker_data_thread = -1
local Text_clones = { }
local NTS_OFFLINE_STRINGS = 0
local NTS_ONLINE_STRINGS = 1
function vdo_newsticker_init()
end
function vdo_newsticker_cleanup()
end
-- Inherited from Vdo_base_object
Vdo_newsticker = Vdo_base_object:new_base()
function Vdo_newsticker:init()
self.lines = { }
self.num_lines = 0
self.clones = {}
self.clone_count = 0
--Animation that slide that scales all the objects in.
self.anim_h = vint_object_find("scroll_text_anim", self.handle)
self.twn_h = vint_object_find("scroll_text_twn", self.handle)
vint_set_property(self.twn_h, "end_event", "vint_anim_loop_callback")
self.current_line = 0
Current_ticker = self
Ticker_data_thread = thread_new("newsticker_data_request_thread")
end
function Vdo_newsticker:on_destroy()
if Current_ticker == self then
Current_ticker = -1
end
if Ticker_data_thread ~= -1 then
thread_kill(Ticker_data_thread)
Ticker_data_thread = -1
end
end
function Vdo_newsticker:populate_strings(text_line, online_string)
self.lines[self.num_lines] = text_line
self.num_lines = self.num_lines + 1
end
function Vdo_newsticker:build()
--remove all clones from before...
self:clones_destroy()
local text_h = vint_object_find("text", self.handle)
local seperator_h = vint_object_find("seperator", self.handle)
local ticker_bg_h = vint_object_find("ticker_bg", self.handle)
local ticker_trim_h = vint_object_find("ticker_trim", self.handle)
local text_clone_h, seperator_clone_h
local text_x, text_y = vint_get_property(text_h, "anchor")
--Skin
local main_doc_h = vint_document_find("main_menu_top")
local store_doc_h = vint_document_find("store_character")
--Main Menu
if (main_doc_h ~= nil and main_doc_h ~= 0) then
vint_set_property(text_h, "tint", 167/255, 167/255, 167/255)
vint_set_property(seperator_h, "image", "ui_menu_respect_ico")
vint_set_property(seperator_h, "offset", 0,0)
vint_set_property(seperator_h, "scale", .8,.8)
vint_set_property(seperator_h, "tint", 235/255, 214/255, 153/255)
vint_set_property(ticker_bg_h, "tint", 0,0,0)
vint_set_property(ticker_bg_h, "alpha", 1)
vint_set_property(ticker_trim_h, "tint", 113/255, 17/255, 17/255)
vint_set_property(ticker_trim_h, "alpha", 1)
--element_set_actual_size(ticker_trim_h, 1600, 2)
--Store Character
elseif (store_doc_h ~= nil and store_doc_h ~= 0) then
vint_set_property(text_h, "tint", 0/255, 0/255, 0/255)
vint_set_property(seperator_h, "image", "ui_pause_slider_arrow")
vint_set_property(seperator_h, "offset", 0,9)
vint_set_property(seperator_h, "scale", .6,.6)
vint_set_property(seperator_h, "tint", 220/255, 0/255, 0/255)
vint_set_property(ticker_bg_h, "tint", 220/255, 220/255, 220/255)
vint_set_property(ticker_bg_h, "alpha", 1)
vint_set_property(ticker_trim_h, "tint", 155/255, 24/255, 24/255)
vint_set_property(ticker_trim_h, "alpha", 1)
--element_set_actual_size(ticker_trim_h, 1600, 4)
end
local seperator_x, seperator_y = vint_get_property(seperator_h, "anchor")
local text_width, text_height --leave undefined... need to check string length...
local seperator_width, seperator_height = element_get_actual_size(seperator_h)
local next_x = 0
for i = 0, self.num_lines -1 do
local is_clone = false
if i == 0 then
text_clone_h = text_h
seperator_clone_h = seperator_h
else
text_clone_h = vint_object_clone(text_h)
seperator_clone_h = vint_object_clone(seperator_h)
is_clone = false
self:clone_store(text_clone_h)
self:clone_store(seperator_clone_h)
end
--Set text tag...
vint_set_property(text_clone_h, "text_tag", self.lines[i])
--Set positions...
seperator_x = next_x
text_x = seperator_x + seperator_width + NEWSTICKER_SEPERATOR_PADDING
vint_set_property(seperator_clone_h, "anchor", seperator_x , seperator_y)
vint_set_property(text_clone_h, "anchor", text_x, text_y)
--Get width and height... to calculate for next ticker message...
text_width, text_height = element_get_actual_size(text_clone_h)
next_x = text_x + text_width + NEWSTICKER_TEXT_PADDING
end
local twn_h = vint_object_find("scroll_text_twn", self.handle)
vint_set_property(twn_h, "duration", (Screen_width+next_x)/PIXELS_PER_SECOND)
vint_set_property(twn_h, "start_value", Screen_width, 0)
vint_set_property(twn_h, "end_value", -next_x, 0)
lua_play_anim(self.anim_h)
--width...
self.width = next_x
end
function Vdo_newsticker:clone_store(clone_h)
self.clones[self.clone_count] = clone_h
self.clone_count = self.clone_count + 1
end
function Vdo_newsticker:clones_destroy()
for i = 0, self.clone_count - 1 do
vint_object_destroy(self.clones[i])
end
self.clone_count = 0
self.clones = {}
end
-------------------------------------------------------------------------------
-- news ticker utility functions...
-------------------------------------------------------------------------------
function newsticker_data_request_thread()
local main_doc_h = vint_document_find("main_menu_top")
local store_doc_h = vint_document_find("store_character")
--Main Menu
if (main_doc_h ~= nil and main_doc_h ~= 0) then
vint_dataresponder_request("newsticker_populate", "newsticker_populate", 0, NTS_OFFLINE_STRINGS)
Current_ticker:build()
Current_ticker.num_lines = 0
vint_dataresponder_request("newsticker_populate", "newsticker_populate", 0, NTS_ONLINE_STRINGS)
Current_ticker:build()
--Store Character
elseif (store_doc_h ~= nil and store_doc_h ~= 0) then
Current_ticker.num_lines = 0
--ps3 can't handle a char anim and all this ticker text, it stutters
if (game_get_platform() == "PS3") then
newsticker_populate("NEWSTICKER_STORE_01")
newsticker_populate("NEWSTICKER_STORE_02")
newsticker_populate("NEWSTICKER_STORE_03")
newsticker_populate("NEWSTICKER_STORE_04")
newsticker_populate("NEWSTICKER_STORE_05")
--newsticker_populate("NEWSTICKER_STORE_06")
--newsticker_populate("NEWSTICKER_STORE_07")
--newsticker_populate("NEWSTICKER_STORE_08")
--newsticker_populate("NEWSTICKER_STORE_09")
--newsticker_populate("NEWSTICKER_STORE_10")
--newsticker_populate("NEWSTICKER_STORE_11")
--newsticker_populate("NEWSTICKER_STORE_12")
--newsticker_populate("NEWSTICKER_STORE_13")
--newsticker_populate("NEWSTICKER_STORE_14")
--newsticker_populate("NEWSTICKER_STORE_15")
--newsticker_populate("NEWSTICKER_STORE_16")
--newsticker_populate("NEWSTICKER_STORE_17")
--newsticker_populate("NEWSTICKER_STORE_18")
--newsticker_populate("NEWSTICKER_STORE_19")
--newsticker_populate("NEWSTICKER_STORE_20")
--newsticker_populate("NEWSTICKER_STORE_21")
--newsticker_populate("NEWSTICKER_STORE_22")
else
newsticker_populate("NEWSTICKER_STORE_01")
newsticker_populate("NEWSTICKER_STORE_02")
newsticker_populate("NEWSTICKER_STORE_03")
newsticker_populate("NEWSTICKER_STORE_04")
newsticker_populate("NEWSTICKER_STORE_05")
newsticker_populate("NEWSTICKER_STORE_06")
newsticker_populate("NEWSTICKER_STORE_07")
newsticker_populate("NEWSTICKER_STORE_08")
newsticker_populate("NEWSTICKER_STORE_09")
newsticker_populate("NEWSTICKER_STORE_10")
newsticker_populate("NEWSTICKER_STORE_11")
newsticker_populate("NEWSTICKER_STORE_12")
newsticker_populate("NEWSTICKER_STORE_13")
newsticker_populate("NEWSTICKER_STORE_14")
newsticker_populate("NEWSTICKER_STORE_15")
newsticker_populate("NEWSTICKER_STORE_16")
newsticker_populate("NEWSTICKER_STORE_17")
newsticker_populate("NEWSTICKER_STORE_18")
newsticker_populate("NEWSTICKER_STORE_19")
newsticker_populate("NEWSTICKER_STORE_20")
newsticker_populate("NEWSTICKER_STORE_21")
newsticker_populate("NEWSTICKER_STORE_22")
end
Current_ticker:build()
end
Ticker_data_thread = -1
end
function newsticker_populate(text_line, online)
if Current_ticker == -1 then
return
end
Current_ticker:populate_strings(text_line, online)
end