./vdo_newsticker.lua

  1. ---------------------------------------------------------------------------  
  2. -- Newsticker! 
  3. --------------------------------------------------------------------------- 
  4. Current_ticker = -1 
  5. local Screen_width = 1280 
  6.  
  7. local NEWSTICKER_SEPERATOR_PADDING	= 10 
  8. local NEWSTICKER_TEXT_PADDING			= 20 
  9. local PIXELS_PER_SECOND					= 60 
  10.  
  11. local Ticker_data_thread = -1 
  12. local Text_clones = { } 
  13.  
  14. local NTS_OFFLINE_STRINGS				= 0 
  15. local NTS_ONLINE_STRINGS				= 1 
  16.  
  17. function vdo_newsticker_init() 
  18. end 
  19.  
  20. function vdo_newsticker_cleanup() 
  21. end 
  22.  
  23. -- Inherited from Vdo_base_object 
  24. Vdo_newsticker = Vdo_base_object:new_base() 
  25.  
  26. function Vdo_newsticker:init() 
  27. 	self.lines = { }	 
  28. 	self.num_lines = 0 
  29. 	 
  30. 	self.clones = {} 
  31. 	self.clone_count = 0 
  32. 	 
  33. 	--Animation that slide that scales all the objects in. 
  34. 	 
  35. 	self.anim_h = vint_object_find("scroll_text_anim", self.handle) 
  36. 	self.twn_h = vint_object_find("scroll_text_twn", self.handle) 
  37. 	vint_set_property(self.twn_h, "end_event", "vint_anim_loop_callback") 
  38.  
  39. 	self.current_line = 0 
  40. 	Current_ticker = self 
  41. 	 
  42. 	Ticker_data_thread = thread_new("newsticker_data_request_thread") 
  43. end 
  44.  
  45. function Vdo_newsticker:on_destroy() 
  46. 	if Current_ticker == self then 
  47. 		Current_ticker = -1 
  48. 	end 
  49. 	 
  50. 	if Ticker_data_thread ~= -1 then 
  51. 		thread_kill(Ticker_data_thread) 
  52. 		Ticker_data_thread = -1 
  53. 	end 
  54. end 
  55.  
  56. function Vdo_newsticker:populate_strings(text_line, online_string) 
  57. 	self.lines[self.num_lines] = text_line 
  58. 	self.num_lines = self.num_lines + 1 
  59. end 
  60.  
  61. function Vdo_newsticker:build() 
  62. 	--remove all clones from before... 
  63. 	self:clones_destroy() 
  64.  
  65. 	local text_h = vint_object_find("text", self.handle) 
  66. 	local seperator_h = vint_object_find("seperator", self.handle) 
  67. 	local ticker_bg_h = vint_object_find("ticker_bg", self.handle) 
  68. 	local ticker_trim_h = vint_object_find("ticker_trim", self.handle) 
  69. 	local text_clone_h, seperator_clone_h 
  70. 	local text_x, text_y = vint_get_property(text_h, "anchor") 
  71. 	 
  72. 	--Skin 
  73. 	local main_doc_h = vint_document_find("main_menu_top") 
  74. 	local store_doc_h = vint_document_find("store_character") 
  75. 	--Main Menu 
  76. 	if (main_doc_h ~= nil and main_doc_h ~= 0) then 
  77. 		vint_set_property(text_h, "tint", 167/255, 167/255, 167/255) 
  78. 		vint_set_property(seperator_h, "image", "ui_menu_respect_ico") 
  79. 		vint_set_property(seperator_h, "offset", 0,0) 
  80. 		vint_set_property(seperator_h, "scale", .8,.8) 
  81. 		vint_set_property(seperator_h, "tint", 235/255, 214/255, 153/255) 
  82. 		vint_set_property(ticker_bg_h, "tint", 0,0,0) 
  83. 		vint_set_property(ticker_bg_h, "alpha", 1) 
  84. 		vint_set_property(ticker_trim_h, "tint", 113/255, 17/255, 17/255) 
  85. 		vint_set_property(ticker_trim_h, "alpha", 1) 
  86. 		--element_set_actual_size(ticker_trim_h, 1600, 2) 
  87. 		 
  88. 		 
  89. 	--Store Character 
  90. 	elseif (store_doc_h ~= nil and store_doc_h ~= 0) then 
  91. 		vint_set_property(text_h, "tint", 0/255, 0/255, 0/255) 
  92. 		vint_set_property(seperator_h, "image", "ui_pause_slider_arrow") 
  93. 		vint_set_property(seperator_h, "offset", 0,9) 
  94. 		vint_set_property(seperator_h, "scale", .6,.6) 
  95. 		vint_set_property(seperator_h, "tint", 220/255, 0/255, 0/255) 
  96. 		vint_set_property(ticker_bg_h, "tint", 220/255, 220/255, 220/255) 
  97. 		vint_set_property(ticker_bg_h, "alpha", 1) 
  98. 		vint_set_property(ticker_trim_h, "tint", 155/255, 24/255, 24/255) 
  99. 		vint_set_property(ticker_trim_h, "alpha", 1) 
  100. 		--element_set_actual_size(ticker_trim_h, 1600, 4) 
  101. 	end 
  102. 	 
  103. 	local seperator_x, seperator_y = vint_get_property(seperator_h, "anchor") 
  104. 	local text_width, text_height 	--leave undefined... need to check string length... 
  105. 	local seperator_width, seperator_height = element_get_actual_size(seperator_h) 
  106. 	local next_x = 0 
  107. 	 
  108. 	for i = 0, self.num_lines -1 do 
  109. 		local is_clone = false 
  110. 		if i == 0 then 
  111. 			text_clone_h		= text_h 
  112. 			seperator_clone_h = seperator_h 
  113. 		else 
  114. 			text_clone_h = vint_object_clone(text_h) 
  115. 			seperator_clone_h = vint_object_clone(seperator_h) 
  116. 			is_clone = false 
  117. 			self:clone_store(text_clone_h) 
  118. 			self:clone_store(seperator_clone_h) 
  119. 		end 
  120. 		 
  121. 		--Set text tag... 
  122. 		vint_set_property(text_clone_h, "text_tag", self.lines[i]) 
  123. 		 
  124. 		--Set positions... 
  125. 		seperator_x = next_x  
  126. 		text_x = seperator_x + seperator_width + NEWSTICKER_SEPERATOR_PADDING 
  127. 		vint_set_property(seperator_clone_h, "anchor", seperator_x , seperator_y)  
  128. 		vint_set_property(text_clone_h, "anchor", text_x, text_y) 
  129. 				 
  130. 		--Get width and height... to calculate for next ticker message... 
  131. 		text_width, text_height = element_get_actual_size(text_clone_h) 
  132. 		next_x = text_x + text_width + NEWSTICKER_TEXT_PADDING 
  133. 	end 
  134. 	 
  135. 	local twn_h = vint_object_find("scroll_text_twn", self.handle) 
  136. 	vint_set_property(twn_h, "duration", (Screen_width+next_x)/PIXELS_PER_SECOND) 
  137. 	vint_set_property(twn_h, "start_value", Screen_width, 0) 
  138. 	vint_set_property(twn_h, "end_value", -next_x, 0) 
  139. 	 
  140. 	lua_play_anim(self.anim_h) 
  141. 	 
  142. 	--width... 
  143. 	self.width = next_x 
  144. end 
  145.  
  146. function Vdo_newsticker:clone_store(clone_h) 
  147. 	self.clones[self.clone_count] = clone_h 
  148. 	self.clone_count = self.clone_count + 1 
  149. end 
  150.  
  151. function Vdo_newsticker:clones_destroy() 
  152. 	for i = 0, self.clone_count - 1 do  
  153. 		vint_object_destroy(self.clones[i]) 
  154. 	end 
  155. 	self.clone_count = 0 
  156. 	self.clones = {} 
  157. end 
  158.  
  159. ------------------------------------------------------------------------------- 
  160. -- news ticker utility functions... 
  161. ------------------------------------------------------------------------------- 
  162.  
  163. function newsticker_data_request_thread() 
  164. 	local main_doc_h = vint_document_find("main_menu_top") 
  165. 	local store_doc_h = vint_document_find("store_character") 
  166. 	--Main Menu 
  167. 	if (main_doc_h ~= nil and main_doc_h ~= 0) then 
  168. 		vint_dataresponder_request("newsticker_populate", "newsticker_populate", 0, NTS_OFFLINE_STRINGS) 
  169. 		Current_ticker:build() 
  170. 		 
  171. 		Current_ticker.num_lines = 0 
  172. 		vint_dataresponder_request("newsticker_populate", "newsticker_populate", 0, NTS_ONLINE_STRINGS) 
  173. 		Current_ticker:build() 
  174. 		 
  175. 	--Store Character 
  176. 	elseif (store_doc_h ~= nil and store_doc_h ~= 0) then 
  177. 		Current_ticker.num_lines = 0 
  178. 		 
  179. 		--ps3 can't handle a char anim and all this ticker text, it stutters 
  180. 		if (game_get_platform() == "PS3") then 
  181. 		 
  182. 			newsticker_populate("NEWSTICKER_STORE_01") 
  183. 			newsticker_populate("NEWSTICKER_STORE_02") 
  184. 			newsticker_populate("NEWSTICKER_STORE_03") 
  185. 			newsticker_populate("NEWSTICKER_STORE_04") 
  186. 			newsticker_populate("NEWSTICKER_STORE_05") 
  187. 			--newsticker_populate("NEWSTICKER_STORE_06") 
  188. 			--newsticker_populate("NEWSTICKER_STORE_07") 
  189. 			--newsticker_populate("NEWSTICKER_STORE_08") 
  190. 			--newsticker_populate("NEWSTICKER_STORE_09") 
  191. 			--newsticker_populate("NEWSTICKER_STORE_10") 
  192. 			--newsticker_populate("NEWSTICKER_STORE_11") 
  193. 			--newsticker_populate("NEWSTICKER_STORE_12") 
  194. 			--newsticker_populate("NEWSTICKER_STORE_13") 
  195. 			--newsticker_populate("NEWSTICKER_STORE_14") 
  196. 			--newsticker_populate("NEWSTICKER_STORE_15") 
  197. 			--newsticker_populate("NEWSTICKER_STORE_16") 
  198. 			--newsticker_populate("NEWSTICKER_STORE_17") 
  199. 			--newsticker_populate("NEWSTICKER_STORE_18") 
  200. 			--newsticker_populate("NEWSTICKER_STORE_19") 
  201. 			--newsticker_populate("NEWSTICKER_STORE_20") 
  202. 			--newsticker_populate("NEWSTICKER_STORE_21") 
  203. 			--newsticker_populate("NEWSTICKER_STORE_22") 
  204. 		else 
  205. 			newsticker_populate("NEWSTICKER_STORE_01") 
  206. 			newsticker_populate("NEWSTICKER_STORE_02") 
  207. 			newsticker_populate("NEWSTICKER_STORE_03") 
  208. 			newsticker_populate("NEWSTICKER_STORE_04") 
  209. 			newsticker_populate("NEWSTICKER_STORE_05") 
  210. 			newsticker_populate("NEWSTICKER_STORE_06") 
  211. 			newsticker_populate("NEWSTICKER_STORE_07") 
  212. 			newsticker_populate("NEWSTICKER_STORE_08") 
  213. 			newsticker_populate("NEWSTICKER_STORE_09") 
  214. 			newsticker_populate("NEWSTICKER_STORE_10") 
  215. 			newsticker_populate("NEWSTICKER_STORE_11") 
  216. 			newsticker_populate("NEWSTICKER_STORE_12") 
  217. 			newsticker_populate("NEWSTICKER_STORE_13") 
  218. 			newsticker_populate("NEWSTICKER_STORE_14") 
  219. 			newsticker_populate("NEWSTICKER_STORE_15") 
  220. 			newsticker_populate("NEWSTICKER_STORE_16") 
  221. 			newsticker_populate("NEWSTICKER_STORE_17") 
  222. 			newsticker_populate("NEWSTICKER_STORE_18") 
  223. 			newsticker_populate("NEWSTICKER_STORE_19") 
  224. 			newsticker_populate("NEWSTICKER_STORE_20") 
  225. 			newsticker_populate("NEWSTICKER_STORE_21") 
  226. 			newsticker_populate("NEWSTICKER_STORE_22") 
  227. 		end 
  228. 		 
  229. 		Current_ticker:build() 
  230. 	end 
  231. 	 
  232. 	Ticker_data_thread = -1 
  233. end 
  234.  
  235. function newsticker_populate(text_line, online) 
  236. 	if Current_ticker == -1 then 
  237. 		return 
  238. 	end 
  239. 		 
  240. 	Current_ticker:populate_strings(text_line, online) 
  241. end