./vdo_gsi_whored.lua

  1. ------------------------------------------------------------------------------- 
  2. --GSI  
  3. ------------------------------------------------------------------------------- 
  4. -- Inherited from Vdo_base_object 
  5. Vdo_gsi_whored = Vdo_base_object:new_base() 
  6.  
  7. -- Standard Init Function 
  8. function vdo_gsi_init() 
  9. end 
  10.  
  11. -- Standard Cleanup Function 
  12. function vdo_gsi_cleanup() 
  13. end 
  14.  
  15. ------------------------------------------------------------------------------- 
  16. --CONSTANTS 
  17. ------------------------------------------------------------------------------- 
  18. --Order of creation is timer, x/y, meter, info 
  19. --GSI Indicator Indexes, increment these if there is more than one 
  20. local GSI_TIMER 		= 0 
  21. local GSI_XY 			= 1 
  22. local GSI_METER		= 5 
  23. local GSI_INFO 		= 9 
  24. local GSI_COMBO 		= 13 
  25.  
  26. --Config Indexes, used to define the arangement of a configuration 
  27. local GSI_CONFIG_ROW = 1		--Row Number 
  28. local GSI_CONFIG_SKIN = 2		--Skin Type (Indicator Specific) 
  29.  
  30. --local 1 = initializing, 2 = running, 3 = end, 4 = mission change 
  31. local GSI_STATE_INITIALIZING			= 1 
  32. local GSI_STATE_RUNNING					= 2 
  33. local GSI_STATE_END						= 3 
  34. local GSI_STATE_MISSION_CHANGE		= 4 
  35.  
  36. HUD_KILL_ICON = 0 
  37. HUD_DEFEND_ICON = 1 
  38. HUD_USE_ICON = 2 
  39. HUD_REVIVE_ICON = 3 
  40. HUD_LOCATION_ICON = 4  
  41. HUD_COOP_ICON = 4  
  42.  
  43. local GSI_OBJECTIVE_ICONS = { 
  44. 	[HUD_KILL_ICON] = "ui_hud_gsi_obj_kill", 
  45. 	[HUD_DEFEND_ICON] = "ui_hud_gsi_obj_protect", 
  46. 	[HUD_USE_ICON] = "ui_hud_gsi_obj_use", 
  47. 	[HUD_LOCATION_ICON] = "ui_hud_gsi_obj_goto", 
  48. } 
  49.  
  50. --Enums for activity and other static configurations 
  51. local GSI_CONFIGS = {                           
  52. 	-- Horde Mode 
  53. 	[3] = { 
  54. 		[GSI_INFO]			= { 0, "",							}, 
  55. 		[GSI_INFO + 1]		= { 1, "",							}, 
  56. 		[GSI_INFO + 2]		= { 2, "",							}, 
  57. 		[GSI_XY]				= { 3, "",							}, 
  58. 	}, 
  59. } 
  60.  
  61. --Audio Constants 
  62. GSI_AUDIO_COUNT_POSITIVE = game_audio_get_audio_id("SYS_HUD_CNTDWN_POS") 
  63. GSI_AUDIO_TRAIL_BLAZING = game_audio_get_audio_id("SYS_HUD_CNTDWN_POS") 
  64. GSI_AUDIO_DIV_COMPLETE = game_audio_get_audio_id("SYS_HUD_CNTDWN_POS") 
  65.  
  66. --Formatting Constants 
  67. GSI_TEXT_SPACING = 9 
  68.  
  69. ------------------------------------------------------------------------------- 
  70. --Initializes GSI 
  71. ------------------------------------------------------------------------------- 
  72. function Vdo_gsi_whored:init()	 
  73.  
  74. 	--Setup Core Values for the GSI 
  75. 	self.status = { 
  76. 		config_index = -1, 
  77. 		config = -1, 
  78. 		indicator_count = 0, 
  79. 		grid_spacing = 10, 
  80. 		state = -1, 
  81. 		diversion_level = -1, 
  82. 		is_dirty = false, 
  83. 		debug_mode = false, 
  84. 	} 
  85. 	 
  86. 	--Store handles to our internal objects... 
  87. 	self.enemies_value_txt_h 		= vint_object_find("enemies_value_txt", self.handle) 
  88. 	self.enemies_title_txt_h 		= vint_object_find("enemies_title_txt", self.handle) 
  89. 	self.score_title_txt_h 			= vint_object_find("score_title_txt", self.handle) 
  90. 	self.score_value_txt_h 			= vint_object_find("score_value_txt", self.handle) 
  91. 	self.wave_description_txt_h 	= vint_object_find("wave_description_txt", self.handle) 
  92. 	self.wave_number_txt_h 			= vint_object_find("wave_number_txt", self.handle) 
  93. 	self.bg_bottom_h 					= vint_object_find("bg_bottom", self.handle) 
  94. 	self.bg_top_h 						= vint_object_find("bg_top", self.handle) 
  95. 	 
  96. 	--Store the vdo copies in memory... 
  97. 	self.indicators = {} 
  98. 	 
  99. 	--What grid the menu is using... 
  100. 	self.grid = {}  
  101. 				 
  102. 	--References to Animations 
  103. 	self.anims = {} 
  104. 	 
  105. 	--Initialize score... 
  106. 	self.score = 0 
  107. 	vint_set_property(self.score_value_txt_h , "text_tag", 0) 
  108. 	 
  109. 	--Start score thread... 
  110. 	self.gsi_whored_thread = thread_new("vdo_gsi_whored_score_thread", self) 
  111.  
  112. 	--Close the GSI 
  113. 	self:close() 
  114. end 
  115.  
  116. function Vdo_gsi_whored:on_destroy() 
  117. 	if self.gsi_whored_thread ~= nil then 
  118. 		thread_kill(self.gsi_whored_thread) 
  119. 	end 
  120. end 
  121.  
  122. ------------------------------------------------------------------------------- 
  123. -- Updates GSI via Data Item update... 
  124. -- **sr2_local_player_gameplay_indicator_status** 
  125. -- 
  126. -- The parameters are varied based on the data_type specified in the first  
  127. -- parameter from the dataitem.  
  128. ------------------------------------------------------------------------------- 
  129. function Vdo_gsi_whored:update(di_h) 
  130. 	local data_type, param1, param2, param3, param4, param5, param6, param7, param8, param9 = vint_dataitem_get(di_h) 
  131. 	 
  132. 	if self.status.debug_mode == true then 
  133. 		debug_print("vint", "GSI Update: " .. var_to_string(data_type).. "\n") 
  134. 	end 
  135. 	 
  136. 	--Determine what datatype we are passing through so we can figure out what  
  137. 	--to do with the rest of the parameters.	 
  138. 	if data_type == nil then 
  139. 		--No specified data_type so don't do anything. 
  140. 	elseif data_type == "configuration" then 
  141. 		--do nothing! 
  142. 	else 
  143. 		--Update Indicators 
  144. 		self:update_indicators(data_type, param1, param2, param3, param4, param5, param6, param7, param8, param9)	 
  145. 	end 
  146. end 
  147.  
  148. ------------------------------------------------------------------------------- 
  149. -- Updates any of the indicators. 
  150. -- 
  151. -- @param 	data_type		Determines what type of indicator we send the other 
  152. --									Parameters to. The additional paramters are generic 
  153. --									and re-used for all the indicators 
  154. --	@param	ind_index		Indicator Index, used to map indicators between game 
  155. --									and Interface Lua. 
  156. -- @param	visible			Is the indicator Visible? 
  157. -- @param	label_crc		Label for the indicator... 
  158. -- @param	icon_enum		Icon to use for this widget 
  159. -- @param.. param4-9			Generic parameters use for all the other indicators 
  160. ------------------------------------------------------------------------------- 
  161. function Vdo_gsi_whored:update_indicators(data_type, ind_index, visible, label_crc, icon_enum, param5, param6, param7, param8, param9) 
  162. 	 
  163. 	local wave_title_index = GSI_INFO 
  164. 	local wave_description_index = GSI_INFO + 1 
  165. 	local score_index = GSI_INFO + 2 
  166. 	local enemies_index = GSI_XY 
  167.  
  168. 	--information_indicator 
  169. 	local info_crc = param6 
  170. 	local info_value = param7 
  171. 	 
  172. 	--if its x_y 
  173. 	local x_value	=	param6	--Time: seconds left  
  174. 	local y_value	=	param7	--Is it a positive timer? 
  175. 	local is_cash	=	param8	--Is the indicator cash		 
  176. 	 
  177. 	if ind_index == wave_title_index then 
  178. 		local insert_values = { [0] = label_crc, [1] = info_value } 
  179. 		local txt_tag = vint_insert_values_in_string("{0:text_tag_crc} {1}", insert_values) 
  180. 			 
  181. 		-- Update wave_number_txt_hitle... 
  182. 		vint_set_property(self.wave_number_txt_h, "text_tag", txt_tag) 
  183. 	elseif ind_index == wave_description_index then 
  184. 		-- Update wave_number_txt_hitle... 
  185. 		vint_set_property(self.wave_description_txt_h, "text_tag_crc", label_crc) 
  186. 	elseif ind_index == score_index then 
  187. 	 
  188. 		--Set label with crc 
  189. 		if label_crc == 0 or label_crc == nil then 
  190. 			--No crc or Invalid crc 
  191. 			vint_set_property(self.score_title_txt_h, "text_tag", "") 
  192. 		else 
  193. 			-- Update score title... 
  194. 			vint_set_property(self.score_title_txt_h, "text_tag_crc", label_crc) 
  195. 		end 
  196. 	 
  197. 		--update score.. 
  198. 		local score = tonumber(info_value) 
  199. 		if info_value ~= nil and score ~= nil then 
  200. 			--store score here and we will process and update later... 
  201. 			self.score = score 
  202. 		end 
  203. 		 
  204. 	elseif ind_index == enemies_index then 
  205. 	 
  206. 		--Set label with crc 
  207. 		if label_crc == 0 or label_crc == nil then 
  208. 			--No crc or Invalid crc 
  209. 			vint_set_property(self.enemies_title_txt_h, "text_tag", "") 
  210. 		else 
  211. 			-- Update enemies title... 
  212. 			vint_set_property(self.enemies_title_txt_h, "text_tag_crc", label_crc) 
  213. 		end 
  214. 		 
  215. 		--Update value... 
  216. 		local x_y_value = x_value .. "/" .. y_value 
  217. 		vint_set_property(self.enemies_value_txt_h, "text_tag", x_y_value) 
  218. 	end 
  219. 	 
  220. 	--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... 
  221. 	self:update_layout() 
  222. end 
  223.  
  224. function Vdo_gsi_whored:grid_item_add(row, idx) 
  225. 	if self.grid[row] == nil then 
  226. 		self.grid[row] = idx 
  227. 	end 
  228. end 
  229.  
  230. ------------------------------------------------------------------------------- 
  231. -- Opens the GSI, causes the thing to creativly animate in...set_visible. true. 
  232. ------------------------------------------------------------------------------- 
  233. function Vdo_gsi_whored:open() 
  234. 	self:set_visible(true) 
  235. end 
  236.  
  237. ------------------------------------------------------------------------------- 
  238. -- Closes the GSI, rips the heart out bitches. My name is Kano. 
  239. ------------------------------------------------------------------------------- 
  240. function Vdo_gsi_whored:close() 
  241. 	self.status.is_dirty = true 
  242. 	self:set_visible(false) 
  243. end 
  244.  
  245. ------------------------------------------------------------------------------- 
  246. -- Show/Hide GSI 
  247. ------------------------------------------------------------------------------- 
  248. function Vdo_gsi_whored:show(visible) 
  249. 	self:set_visible(visible) 
  250. end 
  251.  
  252. ------------------------------------------------------------------------------- 
  253. -- Updates the layout of the GSI, Puts the indicators on their assigned lines. 
  254. -- Updates background... 
  255. ------------------------------------------------------------------------------- 
  256. function Vdo_gsi_whored:update_layout() 
  257. 	local top_box_width, 	top_box_height 	= element_get_actual_size(self.bg_top_h) 
  258. 	local bottom_box_width, bottom_box_height = element_get_actual_size(self.bg_bottom_h) 
  259.  
  260. 	local wave_description_width, wave_description_height = element_get_actual_size(self.wave_description_txt_h) 
  261. 	local enemies_title_width, enemies_title_height = element_get_actual_size(self.enemies_title_txt_h) 
  262. 	local score_title_width, score_title_height = element_get_actual_size(self.score_title_txt_h) 
  263. 	local enemies_value_width, enemies_value_height = element_get_actual_size(self.enemies_value_txt_h) 
  264. 	 
  265. 	local top_width = wave_description_width + 10 
  266. 	 
  267. 	local x, y = vint_get_property(self.enemies_title_txt_h, "anchor") 
  268. 	local bottom_width = max(enemies_value_width, enemies_title_width) 
  269. 	local bottom_width = bottom_width + x + 10 
  270. 	local width = max(top_width, bottom_width) 
  271. 	 
  272. 	-- Set background layer up... 
  273. 	element_set_actual_size(self.bg_top_h, width, top_box_height) 
  274. 	element_set_actual_size(self.bg_bottom_h, width, bottom_box_height) 
  275. end 
  276.  
  277. function vdo_gsi_whored_score_thread(object) 
  278. 	local display_score = 0 
  279. 	while true do	 
  280. 		-- Animate Cash 
  281. 		if display_score ~= object.score then 
  282. 			local diff_score = object.score - display_score 
  283. 			 
  284. 			if diff_score > 5 or diff_score < -5 then 
  285. 				diff_score = floor(diff_score * 0.5) 
  286. 			end 
  287. 			 
  288. 			display_score = display_score + diff_score 
  289. 			vint_set_property(object.score_value_txt_h , "text_tag", format_cash(display_score)) 
  290. 		end 
  291. 		thread_yield() 
  292. 	end 
  293. end 
  294.  
  295.  
  296.  
  297. --[[ 
  298. ######################################################################### 
  299. TEST FUNCTIONS 
  300. ######################################################################### 
  301. ]] 
  302.  
  303. --Used to show the bounding box of an object. (NOTE: Does not work for offsets that are not 0,0) 
  304. Bounds_util_data = {} 
  305. function element_bounds_debug(element_handle) 
  306. 	local h 
  307. 	if Bounds_util_data[element_handle] == nil then 
  308. 		h = vint_object_create("bounds_util", "bitmap", element_handle) 
  309. 		vint_set_property(h, "image", "ui_blank") 
  310. 		vint_set_property(h, "tint", rand_float(.3,1),rand_float(.3,1),rand_float(.3,1)) 
  311. 		vint_set_property(h, "alpha", .5) 
  312. 		vint_set_property(h, "depth", -5000) 
  313. 		Bounds_util_data[element_handle] = h 
  314. 	else 
  315. 		h = Bounds_util_data[element_handle] 
  316. 	end 
  317. 	vint_set_property(h, "anchor", 0,0) 
  318. 	local element_width, element_height = element_get_actual_size(element_handle) 
  319. 	element_set_actual_size(h, element_width, element_height) 
  320. end 
  321.  
  322. function element_bounds_debug_clear() 
  323. 	for key, val in pairs(Bounds_util_data) do 
  324. 		vint_object_destroy(val) 
  325. 	end 
  326. end 
  327.  
  328.