./vdo_cell_menu_button.lua

  1. function vdo_cell_menu_button_init() 
  2. end 
  3.  
  4. COLOR_STORE_REWARDS_PRIMARY = {R=148/255, G=0/255, B=197/255} 
  5. -- Inherited from Vdo_base_object 
  6. Vdo_cell_menu_button = Vdo_base_object:new_base() 
  7.  
  8. PAD_BTN_LABEL = 0 
  9. SCALE_BTN_HIGHLIGHT = 1 
  10. SCALE_BTN_UNHIGHLIGHT = 0.95 
  11. BTN_LABEL_BUFFER = 8 
  12.  
  13. local NUM_BG_SCALE = 0.8 
  14. local NUM_BG_SCALE_LARGE = 1.04 
  15.  
  16. function Vdo_cell_menu_button:init() 
  17. 	self.btn = Vdo_base_object:new("btn_scale_grp", self.handle, self.doc_handle) 
  18. 	self.btn_blur = Vdo_base_object:new("btn_blur", self.handle, self.doc_handle) 
  19. 	self.btn_grp = Vdo_base_object:new("btn_grp", self.handle, self.doc_handle) 
  20. 	self.btn_hint = Vdo_hint_button:new("btn_hint", self.handle, self.doc_handle) 
  21. 	self.btn_label = Vdo_base_object:new("btn_label", self.handle, self.doc_handle) 
  22. 	self.btn_img = Vdo_base_object:new("btn_img", self.handle, self.doc_handle) 
  23. 	self.btn_num = Vdo_base_object:new("btn_num", self.handle, self.doc_handle) 
  24. 	self.btn_num_bg = Vdo_base_object:new("btn_num_bg", self.handle, self.doc_handle) 
  25. 		 
  26. 	self.btn_label_x,self.btn_label_y = self.btn_label:get_anchor()	 
  27. 	self.btn_hint_x,self.btn_hint_y = self.btn_hint:get_anchor() 
  28.  
  29. 	self.btn_hint:set_visible(false) 
  30. 	self.btn_hint:set_button(CTRL_MENU_BUTTON_A) 
  31. 	self:set_highlight(false)	 
  32. end 
  33.  
  34. function Vdo_cell_menu_button:set_highlight(is_highlighted) 
  35. 	 
  36. 	local btn_width, btn_height 
  37. 	 
  38. 	if is_highlighted then 
  39. 	 
  40. 		if game_is_active_input_gamepad() then 
  41. 			self.btn_hint:set_button(CTRL_MENU_BUTTON_A) 
  42. 			self.btn_hint:set_visible(true) 
  43. 		else 
  44. 			self.btn_hint:set_visible(false) 
  45. 		end 
  46. 		 
  47. 		self.btn:set_scale(SCALE_BTN_HIGHLIGHT,SCALE_BTN_HIGHLIGHT) 
  48. 		 
  49. 		btn_width, btn_height = self.btn_img:get_actual_size() 
  50. 		 
  51. 		self.btn_label:set_anchor(0 , btn_height * 0.55 + BTN_LABEL_BUFFER) 
  52. 		 
  53. 		self.btn_label:set_property("horz_align","center") 
  54. 		self.btn_label:set_property("auto_offset", "n") 
  55. 		 
  56. 		self.btn_blur:set_visible(true) 
  57. 		 
  58. 		local btn_pulse = Vdo_anim_object:new("btn_pulse", self.handle, self.doc_handle) 
  59. 		btn_pulse:set_target_handle(self.btn_blur.handle) 
  60. 		btn_pulse:play(0) 
  61. 				 
  62. 		self.btn_label:set_color(COLOR_CELL_MENU_HIGHLIGHT_TEXT.R,COLOR_CELL_MENU_HIGHLIGHT_TEXT.G,COLOR_CELL_MENU_HIGHLIGHT_TEXT.B) 
  63. 		 
  64. 		--Draw in front... 
  65. 		self:set_depth(-20) 
  66. 	else	 
  67. 	 
  68. 		self.btn_hint:set_visible(false) 
  69. 		 
  70. 		self.btn:set_scale(SCALE_BTN_UNHIGHLIGHT,SCALE_BTN_UNHIGHLIGHT) 
  71. 		 
  72. 		btn_width, btn_height = self.btn_img:get_actual_size() 
  73. 		 
  74. 		self.btn_label:set_anchor(0, btn_height * 0.5 + BTN_LABEL_BUFFER) 
  75. 		 
  76. 		self.btn_label:set_property("horz_align","center") 
  77. 		self.btn_label:set_property("auto_offset", "n") 
  78. 		 
  79. 		self.btn_blur:set_visible(false) 
  80. 				 
  81. 		self.btn_label:set_color(COLOR_CELL_MENU_UNHIGHLIGHT_TEXT.R,COLOR_CELL_MENU_UNHIGHLIGHT_TEXT.G,COLOR_CELL_MENU_UNHIGHLIGHT_TEXT.B) 
  82. 		 
  83. 		--Move to back 
  84. 		self:set_depth(10) 
  85. 	end 
  86.  
  87. end 
  88.  
  89. function Vdo_cell_menu_button:populate_button(label, icon, is_enabled, new_items, is_visible, can_wrap) 
  90.  
  91. 	self.btn_label:set_text(label) 
  92. 	self.btn_img:set_image(icon) 
  93. 	 
  94. 	if is_visible ~= nil then 
  95. 		self.btn_grp:set_visible(is_visible) 
  96. 	end 
  97.  
  98. 	if new_items ~= nil and new_items > 0 then 
  99. 		self.btn_num:set_text(new_items) 
  100. 		self.btn_num:set_visible(true)	 
  101. 		self.btn_num_bg:set_visible(true) 
  102. 		 
  103. 		--if larger than 100 then expand num bg to fit 
  104. 		self.btn_num_bg:set_scale(NUM_BG_SCALE, NUM_BG_SCALE) 
  105. 		 
  106. 		if new_items > 99 then 
  107. 			self.btn_num_bg:set_scale(NUM_BG_SCALE_LARGE, NUM_BG_SCALE) 
  108. 		end				 
  109. 		 
  110. 		self.btn_num:set_visible(true)	 
  111. 		self.btn_num_bg:set_visible(true)		 
  112. 	else 
  113. 		self.btn_num:set_visible(false)	 
  114. 		self.btn_num_bg:set_visible(false) 
  115. 	end 
  116. 	 
  117. 	if is_enabled ~= nil then 
  118. 		self.is_enabled = is_enabled 
  119. 		self:set_color(.5,.5,.5) 
  120. 	end 
  121. 	 
  122. 	if can_wrap == false then 
  123. 		self.btn_label:set_property("word_wrap", false) 
  124. 	else 
  125. 		self.btn_label:set_property("word_wrap", true) 
  126. 	end 
  127. 	 
  128. end 
  129.