./vdo_weapon_radial_slot.lua

  1. -- Inherited from Vdo_base_object 
  2. Vdo_weapon_radial_slot = Vdo_base_object:new_base() 
  3.  
  4. local Weapon_store_images = { 
  5. 	[1] = "ui_hud_inv_gen_melee", 
  6. 	[2] = "ui_hud_inv_gen_pistol", 
  7. 	[3] = "ui_hud_inv_gen_smg", 
  8. 	[4] = "ui_hud_inv_gen_shotgun", 
  9. 	[5] = "ui_hud_inv_gen_rifle", 
  10. 	[6] = "ui_hud_inv_gen_explosive", 
  11. 	[7] = "ui_hud_inv_gen_spc", 
  12. 	[8] = "ui_hud_inv_gen_grenade", 
  13. 	[9] = "ui_hud_inv_gen_molotov", 
  14. 	[10] = "ui_hud_inv_gen_flash", 
  15. 	[11] = "ui_hud_inv_gen_electric", 
  16. 	[12] = "ui_hud_inv_gen_melee", 
  17. } 
  18.  
  19. --Local Constants 
  20. local AMMO_ANGLE_FULL 	= PI2 * -1 
  21. local AMMO_ANGLE_EMPTY 	= -4.7 
  22.  
  23. local Vdo_weapon_radial_slot_dual_1_x = 	0 
  24. local Vdo_weapon_radial_slot_dual_1_y = 	0 
  25. local Vdo_weapon_radial_slot_dual_2_x =	0  
  26. local Vdo_weapon_radial_slot_dual_2_y = 	0 
  27.  
  28.  
  29. function vdo_weapon_radial_slot_init() 
  30. 	local dual_1_h = vint_object_find("dual_inv_1_bmp") 
  31. 	local dual_2_h = vint_object_find("dual_inv_2_bmp") 
  32. 	Vdo_weapon_radial_slot_dual_1_x, Vdo_weapon_radial_slot_dual_1_y = vint_get_property(dual_1_h, "anchor") 
  33. 	Vdo_weapon_radial_slot_dual_2_x, Vdo_weapon_radial_slot_dual_2_y = vint_get_property(dual_2_h, "anchor") 
  34. end 
  35.  
  36.  
  37. function Vdo_weapon_radial_slot:init() 
  38. 	--Member Variables 
  39. 	self.slot_num = -1         	--not used, just for debugging 
  40. 	self.weapon_name_crc = - 1		--crc for name of item 
  41. 	self.weapon_bmp = nil 			--Weapon Bitmap, if set to nil the no weapon 
  42. 	self.ammo_cur = -1				--Current ammount of ammo for clip 
  43. 	self.ammo_max = -1				--Maximum ammount of ammo for clip 
  44. 	self.ammo_infinite = -1 		--Do we have infinite ammo? 
  45. 	self.dual_wield = -1 			--Is weapon Dual wield? 
  46. 	self.weapon_bmp_name = -1		--Bitmap name for weapon 
  47. 	self.level = -1					--What is the current weapon level 
  48. 	self.availability = -1			--Is the weapon available 
  49. 	self.ammo_type = -1				--Bitmap for ammo type 
  50. 	self.is_outline = false			--Is icon a placeholder outline?	 
  51. 	self.is_highlighted = false	--Is the slot highlighted or not? 
  52. 	self.element = -1					--Enum for the equipped element 
  53. 	self.weapon_class_crc = -1		--crc for class of item 
  54. 	self.weapon_name = -1			-- the weapon name in english 
  55. end 
  56.  
  57.  
  58. function Vdo_weapon_radial_slot:cleanup() 
  59. end 
  60.  
  61.  
  62. function Vdo_weapon_radial_slot:update(slot_num, availability, weapon_name_crc, weapon_bmp_name, ammo_cur, ammo_max, dual_wield, ammo_infinite, level, depleted, ammo_type, store_mode_is_enabled, element, weapon_class_crc, cache_is_enabled, weapon_name, is_seven_deadly_sin) 
  63. 	--Find bitmap references to update 
  64. 	local ammo_bar_fill_bmp = Vdo_base_object:new("ammo_circle", self.handle, self.doc_handle) 
  65. 	local ammo_bar_bg_bmp = Vdo_base_object:new("ammo_bg", self.handle, self.doc_handle) 
  66. 	local infinity_bmp = Vdo_base_object:new("infinity_bmp", self.handle, self.doc_handle) 
  67. 	 
  68. 	--Find objects to change weapon bitmaps 
  69. 	local dual_inv_1_bmp = Vdo_base_object:new("dual_inv_1_bmp", self.handle, self.doc_handle) 
  70. 	local dual_inv_2_bmp = Vdo_base_object:new("dual_inv_2_bmp", self.handle, self.doc_handle) 
  71. 	local element_bmp_h = vint_object_find("element_bmp", self.handle, self.doc_handle) 
  72. 	 
  73. 	--Tint ammo bar red if recharging 
  74. 	--local depleted = true 
  75. 	if depleted == true then 
  76. 		ammo_bar_fill_bmp:set_color(220/255, 37/255, 0/255) 
  77. 		dual_inv_1_bmp:set_alpha(.5) 
  78. 		dual_inv_2_bmp:set_alpha(.5) 
  79. 	else 
  80. 		ammo_bar_fill_bmp:set_color(220/255, 220/255, 220/255) 
  81. 		dual_inv_1_bmp:set_alpha(1) 
  82. 		dual_inv_2_bmp:set_alpha(1) 
  83. 	end 
  84. 	 
  85. 	--Ammo Update 
  86. 	if ammo_cur ~= self.ammo_cur or ammo_max ~= self.ammo_max or ammo_infinite ~= self.ammo_infinite then 
  87. 		if ammo_max == 0 then 
  88. 			--No ammo clip, hide ammo bar and infinity symbol 
  89. 			ammo_bar_fill_bmp:set_visible(false) 
  90. 			ammo_bar_bg_bmp:set_visible(false) 
  91. 			infinity_bmp:set_visible(false) 
  92.  
  93. 			self.ammo_infinite = -1 
  94. 		else 
  95. 			--Ammo Bar Fill 
  96. 			local ammo_percent = ammo_cur/ammo_max 
  97. 			if ammo_percent > 1 then  
  98. 				ammo_percent = 1 
  99. 			end 
  100. 			 
  101. 			local angle = AMMO_ANGLE_EMPTY + (AMMO_ANGLE_FULL - AMMO_ANGLE_EMPTY) * ammo_percent 
  102. 			ammo_bar_fill_bmp:set_property("start_angle", angle) 
  103. 			 
  104. 			--Do we show Infinity Symbol or Ammo bar? 
  105. 			if ammo_infinite ~= self.ammo_infinite then 
  106. 				if ammo_infinite == true then 
  107. 					ammo_bar_fill_bmp:set_visible(false) 
  108. 					ammo_bar_bg_bmp:set_visible(false) 
  109. 					infinity_bmp:set_visible(true) 
  110. 				else	 
  111. 					ammo_bar_fill_bmp:set_visible(true) 
  112. 					ammo_bar_bg_bmp:set_visible(true) 
  113. 					infinity_bmp:set_visible(false) 
  114. 				end	 
  115. 				 
  116. 				self.ammo_infinite = ammo_infinite 
  117. 			end	 
  118. 			 
  119. 			self.ammo_cur = ammo_cur 
  120. 			self.ammo_max = ammo_max 
  121. 		end	 
  122. 	end 
  123. 	 
  124. 	self.store_mode_is_enabled = store_mode_is_enabled 
  125.  
  126. 	if store_mode_is_enabled == false then 
  127. 		-- Determines if we show ammo or not... based on if there is no ammo in the clip. 
  128. 		local has_ammo = true 
  129. 		if ammo_max >= 1 and ammo_cur < 1 then 
  130. 			has_ammo = false 
  131. 		end 
  132. 		 
  133. 		if ammo_infinite then 
  134. 			has_ammo = true 
  135. 		end 
  136. 		if availability and has_ammo then 
  137. 			self.is_enabled = true 
  138. 		else 
  139. 			self.is_enabled = false 
  140. 		end 
  141. 	end 
  142. 	 
  143. 	self.weapon_name = weapon_name 
  144. 	if weapon_name_crc ~= self.weapon_name_crc or dual_wield ~= self.dual_wield or weapon_bmp_name ~= self.weapon_bmp_name or Store_weapon_is_loaded == true then  
  145. 		if weapon_bmp_name == nil then 
  146. 			--No weapon, so hide other elements 
  147. 			local ammo_bar_fill_bmp = Vdo_base_object:new("ammo_circle", self.handle, self.doc_handle) 
  148. 			local ammo_bar_bg_bmp = Vdo_base_object:new("ammo_bg", self.handle, self.doc_handle) 
  149. 			local infinity_bmp = Vdo_base_object:new("infinity_bmp", self.handle, self.doc_handle) 
  150. 			ammo_bar_fill_bmp:set_visible(false) 
  151. 			ammo_bar_bg_bmp:set_visible(false) 
  152. 			infinity_bmp:set_visible(false) 
  153. 			if slot_num < 8 then 
  154. 				dual_inv_1_bmp:set_visible(false) 
  155. 				dual_inv_2_bmp:set_visible(false) 
  156. 			end 
  157. 			 
  158. 			-- Show placeholder weapon icon 
  159. 			if store_mode_is_enabled and cache_is_enabled ~= true then 
  160. 				dual_inv_1_bmp:set_anchor(0, 0) 
  161. 				dual_inv_1_bmp:set_image(Weapon_store_images[slot_num]) 
  162. 				dual_inv_1_bmp:set_visible(true) 
  163. 				 
  164. 				self.is_outline = true 
  165. 			end 
  166. 			 
  167. 		else 
  168. 			--Change Weapon bitmap 
  169. 			dual_inv_1_bmp:set_image(weapon_bmp_name) 
  170. 			dual_inv_2_bmp:set_image(weapon_bmp_name) 
  171.  
  172. 			--Check if Dual wielding for formating differences 
  173. 			if dual_wield == true then	 
  174. 				--Dual Wield Weapon 
  175. 				dual_inv_1_bmp:set_visible(true) 
  176. 				dual_inv_2_bmp:set_visible(true) 
  177. 				 
  178. 				--Reposition to stored values in init() 
  179. 				dual_inv_1_bmp:set_anchor(Vdo_weapon_radial_slot_dual_1_x, Vdo_weapon_radial_slot_dual_1_y) 
  180. 				dual_inv_2_bmp:set_anchor(Vdo_weapon_radial_slot_dual_2_x, Vdo_weapon_radial_slot_dual_2_y) 
  181. 			else 
  182. 				--Single Wield Weapon 
  183. 				dual_inv_1_bmp:set_anchor(0, 0) 
  184. 				dual_inv_1_bmp:set_visible(true) 
  185. 				dual_inv_2_bmp:set_visible(false) 
  186. 			end 
  187. 				 
  188. 			--Exception for layer depth for the following weapon bitmaps. 
  189. 			--We want these bitmaps to draw in front of the ammo bar. 
  190. 			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 
  191. 				dual_inv_1_bmp:set_depth(-400) 
  192. 				dual_inv_2_bmp:set_depth(-300) 
  193. 			else 
  194. 				dual_inv_1_bmp:get_depth(-200) 
  195. 				dual_inv_2_bmp:get_depth(-100) 
  196. 			end 
  197. 		end 
  198. 		 
  199. 		self.dual_wield = dual_wield 
  200. 		self.weapon_bmp_name = weapon_bmp_name 
  201. 		self.weapon_name_crc = weapon_name_crc  
  202. 		self.weapon_class_crc = weapon_class_crc 
  203. 	end 
  204. 	 
  205. 	local gold_upgrade_bmp_h = vint_object_find("icon_upgrade_icon", self.handle, self.doc_handle) 
  206. 	if ui_hud_is_weapon_fully_upgraded(weapon_name) then 
  207. 		vint_set_property(gold_upgrade_bmp_h, "visible", true) 
  208. 	else 
  209. 		vint_set_property(gold_upgrade_bmp_h, "visible", false) 
  210. 	end 
  211.  
  212. 	local sin_bmp_h = vint_object_find("icon_seven_sins", self.handle, self.doc_handle) 
  213. 	if is_seven_deadly_sin then 
  214. 		vint_set_property(sin_bmp_h, "visible", true) 
  215. 	else 
  216. 		vint_set_property(sin_bmp_h, "visible", false) 
  217. 	end 
  218. 	--element 
  219. 	--local element = 8 
  220. 	if element ~= nil and element ~= -1 then 
  221. 		if element ~= self.element then 
  222. 			vint_set_property(element_bmp_h, "image", POWERS_ELEMENTS_ENUMS[element].bitmap) 
  223. 			vint_set_property(element_bmp_h, "visible", true) 
  224. 		end 
  225. 	else 
  226. 		vint_set_property(element_bmp_h, "visible", false) 
  227. 	end 
  228. 	self.element = element 
  229. 	 
  230. 	self.availability = availability 
  231. 	self.level = level 
  232. 	self.slot_num = slot_num 
  233. 	self.ammo_type = ammo_type		 
  234. 	 
  235. 	if store_mode_is_enabled == false then 
  236. 		--Updates state of radial slot 
  237. 		self:redraw() 
  238. 	end 
  239. end 
  240.  
  241.  
  242. function Vdo_weapon_radial_slot:update_element(element) 
  243. 	local element_bmp_h = vint_object_find("element_bmp", self.handle, self.doc_handle) 
  244.  
  245. 	if element ~= nil and element ~= -1 then 
  246. 		if element ~= self.element then 
  247. 			vint_set_property(element_bmp_h, "image", POWERS_ELEMENTS_ENUMS[element].bitmap) 
  248. 			vint_set_property(element_bmp_h, "visible", true) 
  249. 		end 
  250. 	else 
  251. 		vint_set_property(element_bmp_h, "visible", false) 
  252. 	end 
  253. 	self.element = element 
  254. end 
  255.  
  256.  
  257. function Vdo_weapon_radial_slot:set_highlight(is_highlighted) 
  258. 	if is_highlighted == nil then 
  259. 		is_highlighted = self.is_highlighted 
  260. 	end 
  261. 	 
  262. 	self.is_highlighted = is_highlighted 
  263. 	self:redraw() 
  264. end 
  265.  
  266.  
  267. function Vdo_weapon_radial_slot:set_enabled(is_enabled) 
  268. 	self.is_enabled = is_enabled 
  269. 	self:redraw() 
  270. end 
  271.  
  272.  
  273. function Vdo_weapon_radial_slot:redraw() 
  274. 	local dual_inv_1_bmp_h = vint_object_find("dual_inv_1_bmp", self.handle, self.doc_handle) 
  275. 	local dual_inv_2_bmp_h = vint_object_find("dual_inv_2_bmp", self.handle, self.doc_handle) 
  276. 	local ammo_circle_h = vint_object_find("ammo_circle", self.handle, self.doc_handle)	 
  277. 	local base_bmp_h = vint_object_find("base_bmp", self.handle, self.doc_handle) 
  278. 	local element_bmp_h = vint_object_find("element_bmp", self.handle, self.doc_handle) 
  279.  
  280. 	if self.weapon_bmp_name ~= nil then 
  281. 		vint_set_property(dual_inv_1_bmp_h, "visible", true) 
  282. 		if self.element ~= nil and self.element ~= -1 then 
  283. 			vint_set_property(element_bmp_h, "visible", true) 
  284. 		else 
  285. 			vint_set_property(element_bmp_h, "visible", false) 
  286. 		end 
  287. 	else 
  288. 	 
  289. 		-- If we're in the store and don't have a weapon for a category show a generic 
  290. 		-- outline weapon icon. 
  291. 		if self.is_outline == true then 
  292. 			vint_set_property(dual_inv_1_bmp_h, "visible", true) 
  293. 			vint_set_property(dual_inv_2_bmp_h, "visible", false) 
  294. 		else 
  295. 			vint_set_property(dual_inv_1_bmp_h, "visible", false)	 
  296. 			vint_set_property(dual_inv_2_bmp_h, "visible", false)			 
  297. 		end 
  298. 		vint_set_property(element_bmp_h, "visible", false) 
  299. 	end 
  300. 	 
  301. 	--Set visuals based on weapon availability 
  302. 	if self.is_highlighted then		 
  303. 		if self.is_enabled or self.weapon_name == "Explosive-Ark" then 
  304. 			--Highlighted and Enabeled 
  305. 			vint_set_property(dual_inv_1_bmp_h, "tint", 1, 1, 1) 
  306. 			vint_set_property(dual_inv_2_bmp_h, "tint", 1, 1, 1)			 
  307. 			vint_set_property(base_bmp_h, "visible", false) 
  308. 			vint_set_property(ammo_circle_h, "alpha", 1) 
  309. 			vint_set_property(element_bmp_h, "tint", 1, 1, 1)	 
  310. 			vint_set_property(element_bmp_h, "alpha", 1) 
  311. 		else			 
  312. 			--Highlighted and Disabled 
  313. 			vint_set_property(dual_inv_1_bmp_h, "tint", .15, .15, .15) 
  314. 			vint_set_property(dual_inv_2_bmp_h, "tint", .15, .15, .15)	 
  315. 			vint_set_property(base_bmp_h, "tint", .15, .15, .15) 
  316. 			vint_set_property(base_bmp_h, "visible", false) 
  317. 			vint_set_property(ammo_circle_h, "alpha", .5) 
  318. 			vint_set_property(element_bmp_h, "tint", .15, .15, .15) 
  319. 			vint_set_property(element_bmp_h, "alpha", 1)		 
  320. 		end 
  321. 	else 
  322. 		if self.is_enabled or self.weapon_name == "Explosive-Ark" then 
  323. 			--Not Highlighted and Enabeled 
  324. 			vint_set_property(dual_inv_1_bmp_h, "tint", .65, .65, .65) 
  325. 			vint_set_property(dual_inv_2_bmp_h, "tint", .65, .65, .65)	 
  326. 			vint_set_property(base_bmp_h, "tint", .15, .15, .15) 
  327. 			vint_set_property(base_bmp_h, "visible", true) 
  328. 			vint_set_property(ammo_circle_h, "alpha", .5) 
  329. 			vint_set_property(element_bmp_h, "tint", .65, .65, .65)		 
  330. 			vint_set_property(element_bmp_h, "alpha", 1) 
  331. 		else 
  332. 			--Not Highlighted and Disabled			 
  333. 			 
  334. 			--Are we in the store? 
  335. 			if self.store_mode_is_enabled then 
  336. 			 
  337. 				--Make disabled slots darker in store 
  338. 				vint_set_property(dual_inv_1_bmp_h, "tint", .10, .10, .10) 
  339. 				vint_set_property(dual_inv_2_bmp_h, "tint", .10, .10, .10)	 
  340. 				vint_set_property(base_bmp_h, "tint", .10, .10, .10)	 
  341. 				vint_set_property(base_bmp_h, "visible", true) 
  342. 				vint_set_property(ammo_circle_h, "alpha", .35) 
  343. 				vint_set_property(element_bmp_h, "tint", .10, .10, .10) 
  344. 				vint_set_property(element_bmp_h, "alpha", 1)		 
  345. 			else 
  346. 				vint_set_property(dual_inv_1_bmp_h, "tint", .25, .25, .25) 
  347. 				vint_set_property(dual_inv_2_bmp_h, "tint", .25, .25, .25)	 
  348. 				vint_set_property(base_bmp_h, "tint", .15, .15, .15)	 
  349. 				vint_set_property(base_bmp_h, "visible", true) 
  350. 				vint_set_property(ammo_circle_h, "alpha", .65) 
  351. 				vint_set_property(element_bmp_h, "tint", .15, .15, .15) 
  352. 				vint_set_property(element_bmp_h, "alpha", 1)			 
  353. 			end						 
  354. 		end 
  355. 	end 
  356. end 
  357.  
  358.  
  359. function Vdo_weapon_radial_slot:show_ammo(is_visible) 
  360. 	local ammo_bg_h = vint_object_find("ammo_bg", self.handle, self.doc_handle) 
  361. 	local ammo_circle_h = vint_object_find("ammo_circle", self.handle, self.doc_handle) 
  362.  
  363. 	vint_set_property(ammo_bg_h, "visible", is_visible) 
  364. 	vint_set_property(ammo_circle_h, "visible", is_visible)	 
  365. end 
  366.  
  367. function Vdo_weapon_radial_slot:has_infinite_ammo() 
  368. 	if self.ammo_infinite then 
  369. 		return true 
  370. 	else 
  371. 		return false 
  372. 	end 
  373. end 
  374.