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