./vdo_weapon_radial_slot.lua

  1. -- Inherited from Vdo_base_object 
  2. Vdo_weapon_radial_slot = Vdo_base_object:new_base() 
  3.  
  4.  
  5. WEAPON_SLOT_STATE_DISABLED 	= 0 
  6. WEAPON_SLOT_STATE_ENABLED 		= 1 
  7. WEAPON_SLOT_STATE_HIGHLIGHTED = 2 
  8.  
  9. local Weapon_store_images = { 
  10. 	[1] = "ui_hud_inv_gen_melee", 
  11. 	[2] = "ui_hud_inv_gen_pistol", 
  12. 	[3] = "ui_hud_inv_gen_smg", 
  13. 	[4] = "ui_hud_inv_gen_shotgun", 
  14. 	[5] = "ui_hud_inv_gen_rifle", 
  15. 	[6] = "ui_hud_inv_gen_explosive", 
  16. 	[7] = "ui_hud_inv_gen_spc", 
  17. 	[8] = "ui_hud_inv_gen_grenade", 
  18. 	[9] = "ui_hud_inv_gen_molotov", 
  19. 	[10] = "ui_hud_inv_gen_flash", 
  20. 	[11] = "ui_hud_inv_gen_electric", 
  21. 	[12] = "ui_hud_inv_gen_melee", 
  22. } 
  23.  
  24. --Local Constants 
  25. local AMMO_ANGLE_FULL 	= PI2 * -1 
  26. local AMMO_ANGLE_EMPTY 	= -4.7 
  27.  
  28. local Vdo_weapon_radial_slot_dual_1_x = 	0 
  29. local Vdo_weapon_radial_slot_dual_1_y = 	0 
  30. local Vdo_weapon_radial_slot_dual_2_x =	0  
  31. local Vdo_weapon_radial_slot_dual_2_y = 	0 
  32.  
  33.  
  34.  
  35. function vdo_weapon_radial_slot_init() 
  36. 	local dual_1_h = vint_object_find("dual_inv_1_bmp") 
  37. 	local dual_2_h = vint_object_find("dual_inv_2_bmp") 
  38. 	Vdo_weapon_radial_slot_dual_1_x, Vdo_weapon_radial_slot_dual_1_y = vint_get_property(dual_1_h, "anchor") 
  39. 	Vdo_weapon_radial_slot_dual_2_x, Vdo_weapon_radial_slot_dual_2_y = vint_get_property(dual_2_h, "anchor") 
  40. end 
  41.  
  42. function Vdo_weapon_radial_slot:init() 
  43.  
  44. 	--Member Variables 
  45. 	self.slot_num = -1         --not used, just for debugging 
  46. 	self.weapon_name_crc = - 1	--crc for name of item 
  47. 	self.weapon_bmp = -1 		--Weapon Bitmap, if set to nil the no weapon 
  48. 	self.ammo_cur = -1			--Current ammount of ammo for clip 
  49. 	self.ammo_max = -1			--Maximum ammount of ammo for clip 
  50. 	self.ammo_infinite = -1 	--Do we have infinite ammo? 
  51. 	self.dual_wield = -1 		--Is weapon Dual wield? 
  52. 	self.weapon_bmp_name = -1	--Bitmap name for weapon 
  53. 	self.level = -1				--What is the current weapon level 
  54. 	self.availability = -1		--Is the weapon available 
  55. 	self.ammo_type = -1			--Bitmap for ammo type 
  56. 	self.is_outline = false		--Is icon a placeholder outline? 
  57.  
  58. end 
  59. function Vdo_weapon_radial_slot:cleanup() 
  60. end 
  61.  
  62.  
  63. function Vdo_weapon_radial_slot:update(slot_num, availability, weapon_name_crc, weapon_bmp_name, ammo_cur, ammo_max, dual_wield, ammo_infinite, level, ammo_type, store_mode_is_enabled) 
  64.  
  65. 	--Find bitmap references to update 
  66. 	local ammo_bar_fill_bmp = Vdo_base_object:new("ammo_circle", self.handle, self.doc_handle) 
  67. 	local ammo_bar_bg_bmp = Vdo_base_object:new("ammo_bg", self.handle, self.doc_handle) 
  68. 	local infinity_bmp = Vdo_base_object:new("infinity_bmp", self.handle, self.doc_handle) 
  69. 			 
  70. 	--Ammo Update 
  71. 	if ammo_cur ~= self.ammo_cur or ammo_max ~= self.ammo_max or ammo_infinite ~= self.ammo_infinite then 
  72.  
  73. 		if ammo_max == 0 then 
  74. 			--No ammo clip, hide ammo bar and infinity symbol 
  75. 			ammo_bar_fill_bmp:set_visible(false) 
  76. 			ammo_bar_bg_bmp:set_visible(false) 
  77. 			infinity_bmp:set_visible(false) 
  78.  
  79. 			self.ammo_infinite = -1 
  80. 		else 
  81.  
  82. 			--Ammo Bar Fill 
  83. 			local ammo_percent = ammo_cur/ammo_max 
  84. 			local angle = AMMO_ANGLE_EMPTY + (AMMO_ANGLE_FULL - AMMO_ANGLE_EMPTY) * ammo_percent 
  85. 			ammo_bar_fill_bmp:set_property("start_angle", angle) 
  86. 			 
  87. 			--Do we show Infinity Symbol or Ammo bar? 
  88. 			if ammo_infinite ~= self.ammo_infinite then 
  89. 				if ammo_infinite == true then 
  90. 					ammo_bar_fill_bmp:set_visible(false) 
  91. 					ammo_bar_bg_bmp:set_visible(false) 
  92. 					infinity_bmp:set_visible(true) 
  93. 				else	 
  94. 					ammo_bar_fill_bmp:set_visible(true) 
  95. 					ammo_bar_bg_bmp:set_visible(true) 
  96. 					infinity_bmp:set_visible(false) 
  97. 				end	 
  98. 				 
  99. 				self.ammo_infinite = ammo_infinite 
  100. 			end 
  101. 			 
  102. 			self.ammo_cur = ammo_cur 
  103. 			self.ammo_max = ammo_max 
  104.  
  105. 		end	 
  106. 	end 
  107.  
  108. 	--Modify weapon Bitmaps 
  109. 	 
  110. 	--Find objects to change weapon bitmaps 
  111. 	local dual_inv_1_bmp = Vdo_base_object:new("dual_inv_1_bmp", self.handle, self.doc_handle) 
  112. 	local dual_inv_2_bmp = Vdo_base_object:new("dual_inv_2_bmp", self.handle, self.doc_handle) 
  113. 	 
  114. 	if store_mode_is_enabled == false then 
  115. 		local has_ammo = true 
  116. 		if ammo_max >= 1 and ammo_cur < 1 then 
  117. 			has_ammo = false 
  118. 		end 
  119. 		if availability and has_ammo then 
  120. 			self:set_state(WEAPON_SLOT_STATE_HIGHLIGHTED) 
  121. 		else 
  122. 			self:set_state(WEAPON_SLOT_STATE_DISABLED) 
  123. 		end 
  124. 	end 
  125. 	 
  126. 	if weapon_name_crc ~= self.weapon_name_crc or dual_wield ~= self.dual_wield then 
  127. 	 
  128. 		if weapon_bmp_name == nil then 
  129. 			--No weapon, so hide other elements 
  130. 			local ammo_bar_fill_bmp = Vdo_base_object:new("ammo_circle", self.handle, self.doc_handle) 
  131. 			local ammo_bar_bg_bmp = Vdo_base_object:new("ammo_bg", self.handle, self.doc_handle) 
  132. 			local infinity_bmp = Vdo_base_object:new("infinity_bmp", self.handle, self.doc_handle) 
  133. 			ammo_bar_fill_bmp:set_visible(false) 
  134. 			ammo_bar_bg_bmp:set_visible(false) 
  135. 			infinity_bmp:set_visible(false) 
  136. 			if slot_num < 8 then 
  137. 				dual_inv_1_bmp:set_visible(false) 
  138. 				dual_inv_2_bmp:set_visible(false) 
  139. 			end 
  140. 			 
  141. 			-- Show placeholder weapon icon 
  142. 			if store_mode_is_enabled then 
  143. 				dual_inv_1_bmp:set_anchor(0, 0) 
  144. 				dual_inv_1_bmp:set_image(Weapon_store_images[slot_num]) 
  145. 				dual_inv_1_bmp:set_visible(true) 
  146. 				 
  147. 				self.is_outline = true 
  148. 			end 
  149. 			 
  150. 		else 
  151. 			--Change Weapon bitmap 
  152. 			dual_inv_1_bmp:set_image(weapon_bmp_name) 
  153. 			dual_inv_2_bmp:set_image(weapon_bmp_name) 
  154.  
  155. 			--Check if Dual wielding for formating differences 
  156. 			if dual_wield == true then	 
  157. 				--Dual Wield Weapon 
  158. 				dual_inv_1_bmp:set_visible(true) 
  159. 				dual_inv_2_bmp:set_visible(true) 
  160. 				 
  161. 				--Reposition to stored values in init() 
  162. 				dual_inv_1_bmp:set_anchor(Vdo_weapon_radial_slot_dual_1_x, Vdo_weapon_radial_slot_dual_1_y) 
  163. 				dual_inv_2_bmp:set_anchor(Vdo_weapon_radial_slot_dual_2_x, Vdo_weapon_radial_slot_dual_2_y) 
  164. 			else 
  165. 				--Single Wield Weapon 
  166. 				dual_inv_1_bmp:set_anchor(0, 0) 
  167. 				dual_inv_1_bmp:set_visible(true) 
  168. 				dual_inv_2_bmp:set_visible(false) 
  169. 			end 
  170. 				 
  171. 			--Exception for layer depth for the following weapon bitmaps. 
  172. 			--We want these bitmaps to draw in front of the ammo bar. 
  173. 			if weapon_bmp_name == "ui_hud_inv_w_ar50grenade" or weapon_bmp_name == "ui_hud_inv_w_minigun" or weapon_bmp_name == "ui_hud_inv_w_flamethrower" then 
  174. 				dual_inv_1_bmp:set_depth(-400) 
  175. 				dual_inv_2_bmp:set_depth(-300) 
  176. 			else 
  177. 				dual_inv_1_bmp:get_depth(-200) 
  178. 				dual_inv_2_bmp:get_depth(-100) 
  179. 			end 
  180. 		end 
  181. 		 
  182. 		self.dual_wield = dual_wield 
  183. 		self.weapon_bmp_name = weapon_bmp_name 
  184. 		self.weapon_name_crc = weapon_name_crc  
  185. 	end 
  186.  
  187. 	self.availability = availability 
  188. 	self.level = level 
  189. 	self.slot_num = slot_num 
  190. 	self.ammo_type = ammo_type 
  191. 	 
  192. end 
  193.  
  194. ------------------------------------------------------------ 
  195. -- Vdo_weapon_radial_slot:set_state() 
  196. -- 
  197. -- State Enums 
  198. -- 
  199. -- Disabled				= 0 
  200. -- Enabled				= 1 
  201. -- Highlighted			= 2 
  202. ------------------------------------------------------------ 
  203. function Vdo_weapon_radial_slot:set_state(state) 
  204. 	--Find objects to change weapon bitmaps 
  205. 	local dual_inv_1_bmp = Vdo_base_object:new("dual_inv_1_bmp", self.handle) 
  206. 	local dual_inv_2_bmp = Vdo_base_object:new("dual_inv_2_bmp", self.handle) 
  207. 	local main = Vdo_base_object:new("safe_frame", self.handle) 
  208. 	 
  209. 	main:set_color(1,1,1) 
  210. 	dual_inv_1_bmp:set_visible(true) 
  211. 	 
  212. 	--Set tint based on weapon availability 
  213. 	if state == WEAPON_SLOT_STATE_DISABLED then 
  214. 		main:set_color(.15,.15,.15) 
  215. 		if self.is_outline then 
  216. 			dual_inv_1_bmp:set_visible(false) 
  217. 		end 
  218. 	elseif state == WEAPON_SLOT_STATE_ENABLED then 
  219. 		dual_inv_1_bmp:set_color(.5, .5, .5) 
  220. 		dual_inv_2_bmp:set_color(.5, .5, .5)		 
  221. 	else 
  222. 		-- set to highlighted 
  223. 		dual_inv_1_bmp:set_color(1, 1, 1) 
  224. 		dual_inv_2_bmp:set_color(1, 1, 1) 
  225. 	end 
  226. end 
  227.  
  228. function Vdo_weapon_radial_slot:set_store_weapon_icon(slot) 
  229.  
  230. 	 
  231.  
  232. end 
  233.