./vdo_store_header.lua

  1.  
  2.  
  3. function vdo_store_header_init() 
  4. end 
  5.  
  6. -- Inherited from Vdo_base_object 
  7. Vdo_store_header = Vdo_base_object:new_base() 
  8.  
  9. CRUMB_NUM_TITLE = 3 
  10. CRUMB_PAD = 3 
  11. CRUMB_FONT_SCALE_SMALL = .8 
  12. CRUMB_FONT_SCALE_MEDIUM = .9 
  13. CRUMB_FONT_SCALE_LARGE = 1.0 
  14. CRUMB_MAX_TITLE_WIDTH = 348 
  15. PCR_BAR_WIDTH = 435 
  16. PCR_CRUMB_ANCHOR_OFFSET = -70 
  17. STORE_HEADER_BAR_WIDTH = 360 
  18.  
  19.  
  20. Store_respect_meter = {} 
  21.  
  22. function Vdo_store_header:init() 
  23.  
  24. 	self.price = Vdo_base_object:new("price",self.handle, self.doc_handle) 
  25. 	self.respect = Vdo_base_object:new("store_respect",self.handle, self.doc_handle) 
  26. 	self.bar_bottom_grp = Vdo_base_object:new("bar_bottom_grp",self.handle, self.doc_handle) 
  27. 	self.bar_bottom = Vdo_base_object:new("bar_bottom", self.handle, self.doc_handle) 
  28. 	self.bar_end = Vdo_base_object:new("bar_end", self.handle, self.doc_handle) 
  29. 	self.bar_top = Vdo_base_object:new("bar_top",self.handle, self.doc_handle) 
  30. 	self.font_grp = Vdo_base_object:new("font_grp",self.handle, self.doc_handle) 
  31. 	self.bar_end_outline = Vdo_base_object:new("bar_end_outline", self.handle, self.doc_handle) 
  32. 	self.bar_left_line = Vdo_base_object:new("bar_left_line", self.handle, self.doc_handle) 
  33. 	self.bar_top_line = Vdo_base_object:new("bar_top_line", self.handle, self.doc_handle) 
  34. 	self.bar_bottom_line = Vdo_base_object:new("bar_bottom_line", self.handle, self.doc_handle) 
  35. 	 
  36. 	self.title = {} 
  37. 	self.arrow = {} 
  38. 	self.title_stack = {} 
  39.  
  40. 	for i = 1, CRUMB_NUM_TITLE do 
  41. 		self.title[i] = Vdo_base_object:new("title" .. i, self.handle, self.doc_handle) 
  42. 		self.title[i]:set_visible(false) 
  43. 		if i ~= CRUMB_NUM_TITLE then 
  44. 			self.arrow[i] = Vdo_base_object:new("arrow" .. i, self.handle, self.doc_handle) 
  45. 			self.arrow[i]:set_visible(false) 
  46. 		end 
  47. 	end 
  48. 	 
  49. 	self.cash = Vdo_base_object:new("cash",self.handle, self.doc_handle) 
  50. 	self.title_grp = Vdo_base_object:new("title_grp",self.handle, self.doc_handle) 
  51. 	 
  52. 	--unfortunatly this uses a global so, there cannot be multiple instances of this header at one time...(JMH 6/22/2010) 
  53. 	Store_respect_meter = Vdo_respect_meter:new("store_respect_meter", self.handle, self.doc_handle, "vdo_store_header.lua", "Store_respect_meter") 
  54. 	self.respect_meter = Store_respect_meter 	--store it as part of this instance... 
  55. 	 
  56. 	self.respect_meter:set_is_in_store(true) 
  57. 	 
  58. 	-- Scale max width for standard res 
  59. 	if vint_is_std_res() == true then 
  60. 		CRUMB_MAX_TITLE_WIDTH = CRUMB_MAX_TITLE_WIDTH * SCALE_STD_RES 
  61. 	end 
  62.  
  63. 	self:enable_price_respect(false) 
  64. end 
  65.  
  66. -- Update the titles (breadcrumbs) in the header. 
  67. -- The store header keeps a stack of titles that have been pushed onto it, and we use the 
  68. -- last CRUMB_NUM_TITLE titles to populate our header. 
  69. -- 
  70. function Vdo_store_header:set_title() 
  71. 	local title_count = #self.title_stack 
  72. 	 
  73. 	-- Get the last CRUMB_NUM_TITLE titles in the stack and set them in vint 
  74. 	for i = 1, CRUMB_NUM_TITLE do 
  75. 		local stack_index = title_count - CRUMB_NUM_TITLE + i 
  76. 		 
  77. 		-- Handle if we have less than CRUMB_NUM_TITLE titles 
  78. 		if stack_index < i then 
  79. 			stack_index = i 
  80. 		end 
  81. 		 
  82. 		if self.title_stack[stack_index] ~= nil then 
  83. 			if self.title_stack[stack_index].crc ~= nil then  
  84. 				self.title[i]:set_text_crc(self.title_stack[stack_index].crc) 
  85. 			else 
  86. 				self.title[i]:set_text(self.title_stack[stack_index].label) 
  87. 			end 
  88. 			self.title[i]:set_visible(true)	 
  89. 			if i > 1 then 
  90. 				self.arrow[i - 1]:set_visible(true) 
  91. 			end 
  92. 		else 
  93. 			self.title[i]:set_visible(false) 
  94. 			if i > 1 then 
  95. 				self.arrow[i - 1]:set_visible(false) 
  96. 			end 
  97. 		end			 
  98. 	end 
  99. 	 
  100. 	-- Handle Scaling, based on how many titles are visible.  Rightmost title is always largest, and ones to the left get smaller. 
  101. 	local scale_tbl = { [1] = CRUMB_FONT_SCALE_SMALL, [2] = CRUMB_FONT_SCALE_MEDIUM, [3] = CRUMB_FONT_SCALE_LARGE } 
  102. 	local curr_scale = 3 
  103. 	 
  104. 	for i = CRUMB_NUM_TITLE, 1, -1 do 
  105. 		if self.title[i]:get_property("visible") then 
  106. 			self.title[i]:set_property("scale", scale_tbl[curr_scale], scale_tbl[curr_scale]) 
  107. 			if curr_scale > 1 then 
  108. 				curr_scale = curr_scale - 1 
  109. 			end 
  110. 		end 
  111. 	end 
  112. 	 
  113. 	-- Now change titles to "..." to try to make text fit - start from left, and stop when it either fits, or we reach the last title. 
  114. 	for i = 1, CRUMB_NUM_TITLE - 1 do 
  115. 		if self:get_title_size() > CRUMB_MAX_TITLE_WIDTH then 
  116. 			self.title[i]:set_text("...") 
  117. 		end 
  118. 	end 
  119. 	 
  120. 	-- Position titles 
  121. 	for i = 1, CRUMB_NUM_TITLE - 1 do	 
  122. 		local title_width, title_height = self.title[i]:get_property("screen_size")	 
  123. 		local title_x,title_y = self.title[i]:get_anchor() 
  124. 		 
  125. 		local arrow_width, arrow_height = self.arrow[i]:get_property("screen_size") 
  126. 		local arrow_x, arrow_y = self.arrow[i]:get_anchor() 
  127. 		 
  128. 		--Scale for standard res 
  129. 		if vint_is_std_res() == true then 
  130. 			title_width = title_width / SCALE_STD_RES 
  131. 		end 
  132.  
  133. 		arrow_x = title_x + title_width + CRUMB_PAD * 2 
  134. 		local title2_x = arrow_x + arrow_width + CRUMB_PAD * 2 
  135. 		 
  136. 		self.arrow[i]:set_property("anchor",arrow_x, arrow_y) 
  137. 		self.title[i+1]:set_property("anchor",title2_x, title_y)		 
  138. 	end 
  139. 	 
  140. end 
  141.  
  142. -- Get the width of all the visible titles 
  143. function Vdo_store_header:get_title_size() 
  144. 	local total_title_width = 0 
  145. 	 
  146. 	for i = 1, CRUMB_NUM_TITLE do 
  147. 		if self.title[i]:get_visible() then 
  148. 			local title_width,title_height = self.title[i]:get_property("screen_size") 
  149. 			total_title_width = total_title_width + title_width 
  150. 		end 
  151. 	end 
  152.  
  153. 	return total_title_width 
  154. end 
  155.  
  156. function Vdo_store_header:set_color(primary, secondary, tertiary) 
  157.  
  158. 	self.bar_top:set_color(primary.R, primary.G, primary.B) 
  159. 	self.font_grp:set_color(primary.R, primary.G, primary.B) 
  160. 	self.title_grp:set_color(secondary.R, secondary.G, secondary.B) 
  161. 	self.cash:set_color(secondary.R, secondary.G, secondary.B) 
  162. 	self.bar_bottom_grp:set_color(tertiary.R, tertiary.G, tertiary.B) 
  163.  
  164. 	self.respect_meter:set_color(primary) 
  165. 	 
  166. 	for i = 1, CRUMB_NUM_TITLE - 1 do 
  167. 		self.arrow[i]:set_color(primary.R, primary.G, primary.B) 
  168. 	end 
  169. end 
  170.  
  171. function Vdo_store_header:set_cash(cash, is_orb) 
  172. 	 
  173. 	local body, insert_values 
  174. 		 
  175. 	if is_orb == true then 
  176. 		insert_values = { [0] = (cash) } 
  177. 		body = vint_insert_values_in_string("STORE_ORBS_TOTAL", insert_values) 
  178. 		self.cash:set_text(body) 
  179. 	else 
  180. 		self.cash:set_text("{GAME_CASH}" .. format_cash(cash)) 
  181. 	end 
  182. end 
  183.  
  184. function Vdo_store_header:show_cash(visible) 
  185. 	if visible == false then 
  186. 		self.cash:set_visible(false) 
  187. 	else 
  188. 		self.cash:set_visible(true) 
  189. 	end 
  190. end 
  191.  
  192. -- This function can be used to disable (or re-enable) the price and respect text fields, 
  193. -- regardless of what is set for price and respect.  Useful for modes like wardrobe. 
  194. -- 
  195. function Vdo_store_header:enable_price_respect(enabled) 
  196. 	self.price:set_visible(enabled) 
  197. 	self.respect:set_visible(enabled)		 
  198. end 
  199.  
  200. function Vdo_store_header:set_price(price, is_orb) 
  201. 	if type(price) == "string" then 
  202. 		 
  203. 		self.price:set_text(price)	 
  204. 		 
  205. 	elseif price ~= nil then  
  206. 	 
  207. 		-- don't allow negative prices 
  208. 		if price < 0 then 
  209. 			price = 0			 
  210. 		end 
  211. 		 
  212. 		self.price:set_visible(true) 
  213. 		local body, insert_values 
  214. 		 
  215. 		if is_orb == true then 
  216. 			insert_values = { [0] = (price) } 
  217. 			body = vint_insert_values_in_string("STORE_ORBS_PRICE", insert_values) 
  218. 		else 
  219. 			insert_values = { [0] = format_cash(price) } 
  220. 			body = vint_insert_values_in_string("STORE_PRICE", insert_values) 
  221. 		end 
  222. 		 
  223. 		self.price:set_text(body) 
  224. 	else 
  225. 		self.price:set_visible(false) 
  226. 	end 
  227. end 
  228.  
  229. function Vdo_store_header:set_respect(respect) 
  230. 	if respect ~= nil then 
  231. 		self.respect:set_visible(true) 
  232. 		local body 
  233. 		local insert_values = { [0] = respect } 
  234. 		body = vint_insert_values_in_string("STORE_RESPECT", insert_values) 
  235. 		self.respect:set_text(body)	 
  236. 	else 
  237. 		self.respect:set_visible(false) 
  238. 	end 
  239. end 
  240.  
  241. -- Pushes a title on the title stack and calls set_title to redraw the current titles 
  242. -- 
  243. function Vdo_store_header:push_title(title_crc, title_label) 
  244. 	local stack_index = #self.title_stack + 1 
  245. 	self.title_stack[stack_index] = { crc = title_crc, label = title_label } 
  246. 	self:set_title() 
  247. end 
  248.  
  249. -- Pops a title off the title stack and calls set_title to redraw the current titles 
  250. -- 
  251. function Vdo_store_header:pop_title() 
  252. 	local stack_index = #self.title_stack 
  253. 	self.title_stack[stack_index] = nil 
  254. 	self:set_title() 
  255. end 
  256.  
  257. -- Clears all titles off the stack. 
  258. -- 
  259. function Vdo_store_header:clear_titles() 
  260. 	self.title_stack = {} 
  261. 	self:set_title() 
  262. end 
  263.  
  264. ---------------------------------------------------- 
  265. -- Reuses the respect slot to show level needed 
  266. -- for items that require a level 
  267. -- 
  268. -- @ param level		level required to unlock item 
  269. ---------------------------------------------------- 
  270. function Vdo_store_header:set_level(level) 
  271. 	if level ~= nil and level ~= 0 then 
  272. 		self.respect:set_visible(true) 
  273. 		 
  274. 		local body 
  275. 		local insert_values = { [0] = level } 
  276. 		body = vint_insert_values_in_string("STORE_LEVEL_REQ", insert_values) 
  277. 		self.respect:set_text(body)			 
  278. 	else 
  279. 		self.respect:set_visible(false) 
  280. 	end 
  281. end 
  282.  
  283. function Vdo_store_header:set_respect_meter(total_respect, pct, rank) 
  284.  
  285. 	Store_respect_meter:update_respect(total_respect, pct, rank) 
  286.  
  287. end 
  288.  
  289. ---------------------------------------------------- 
  290. -- Hides elements not needed for player creation 
  291. -- and resizes graphics 
  292. ---------------------------------------------------- 
  293. function Vdo_store_header:reformat_and_resize(resize,custom_width) 
  294. 		 
  295. 	local arrow1_x, arrow1_y = self.arrow[1]:get_anchor() 
  296. 	local title1_x, title1_y = self.title[1]:get_anchor() 
  297. 	local bar_top_width, bar_top_height = element_get_actual_size(self.bar_top.handle)--:get_screen_size() 
  298. 	local bar_bottom_width, bar_bottom_height = element_get_actual_size(self.bar_bottom.handle)--:get_screen_size() 
  299. 	local bar_top_x, bar_top_y = self.bar_top:get_anchor() 
  300. 	local bar_bottom_x, bar_bottom_y = self.bar_bottom:get_anchor() 
  301. 	local cash_x,cash_y = self.cash:get_anchor() 
  302. 	local price_x,price_y = self.price:get_anchor() 
  303. 	local new_bar_width = 0 
  304. 	 
  305. 	if resize == false then 
  306. 		self.font_grp:set_visible(true) 
  307. 		self.cash:set_visible(true) 
  308. 		self.respect_meter:set_visible(true) 
  309. 		self.bar_end:set_visible(true) 
  310. 		self.bar_end_outline:set_visible(true) 
  311. 		self.bar_left_line:set_visible(false) 
  312. 		 
  313. 		self.title[1]:set_anchor(0, title1_y) 
  314. 		self.arrow[1]:set_anchor(0, arrow1_y) 
  315. 		 
  316. 		-- scale for standard res 
  317. 		if custom_width == nil then 
  318. 			new_bar_width = STORE_HEADER_BAR_WIDTH	 
  319. 		else 
  320. 			new_bar_width = custom_width 
  321. 		end 
  322. 		 
  323. 		self.bar_top:set_anchor(new_bar_width, bar_top_y) 
  324. 		self.bar_bottom:set_anchor(new_bar_width, bar_bottom_y) 
  325. 		 
  326. 	else	 
  327. 		self.font_grp:set_visible(false) 
  328. 		self.cash:set_visible(false) 
  329. 		self.respect_meter:set_visible(false) 
  330. 		self.bar_end:set_visible(false) 
  331. 		self.bar_end_outline:set_visible(false) 
  332. 		self.bar_left_line:set_visible(true) 
  333.  
  334. 		self.title[1]:set_anchor(PCR_CRUMB_ANCHOR_OFFSET, title1_y) 
  335. 		self.arrow[1]:set_anchor(PCR_CRUMB_ANCHOR_OFFSET, arrow1_y) 
  336.  
  337. 		-- scale for standard res 
  338. 		if custom_width == nil then 
  339. 			new_bar_width = PCR_BAR_WIDTH 
  340. 		else 
  341. 			new_bar_width = custom_width 
  342. 		end 
  343. 		 
  344. 		self.bar_top:set_anchor(new_bar_width - 74, bar_top_y) 
  345. 		self.bar_bottom:set_anchor(new_bar_width - 75, bar_bottom_y) 
  346. 		self.bar_left_line:set_anchor(-75, 38) 
  347. 	 
  348. 	end	 
  349.  
  350. 	self.cash:set_anchor(new_bar_width - 4, cash_y) 
  351. 	self.price:set_anchor(new_bar_width - 4, price_y) 
  352. 	 
  353. 	element_set_actual_size(self.bar_top.handle,new_bar_width, bar_top_height) 
  354. 	element_set_actual_size(self.bar_bottom.handle,new_bar_width, bar_bottom_height) 
  355. 	 
  356. 	element_set_actual_size(self.bar_top_line.handle, new_bar_width * -1, -2) 
  357. 	element_set_actual_size(self.bar_bottom_line.handle, new_bar_width * -1, -2) 
  358. 	 
  359. 	--self.bar_top:set_screen_size(new_bar_width, bar_top_height) 
  360. 	--self.bar_bottom:set_screen_size(new_bar_width, bar_bottom_height)			 
  361. 	 
  362. end 
  363.  
  364. function Vdo_store_header:respect_meter_show() 
  365. 	self.respect_meter:set_visible(true) 
  366. end 
  367.  
  368. function Vdo_store_header:respect_meter_hide() 
  369. 	self.respect_meter:set_visible(false) 
  370. end