./vdo_cell_menu_button.lua

  1. function vdo_cell_menu_button_init() 
  2. end 
  3.  
  4. -- Inherited from Vdo_base_object 
  5. Vdo_cell_menu_button = Vdo_base_object:new_base() 
  6.  
  7. PAD_BTN_LABEL = 0 
  8. SCALE_BTN_HIGHLIGHT = 1 
  9. SCALE_BTN_UNHIGHLIGHT = 0.75 
  10. BTN_LABEL_BUFFER = 8 
  11.  
  12. local NUM_BG_SCALE = 0.8 
  13. local NUM_BG_SCALE_LARGE = 1.15 
  14.  
  15.  
  16. function Vdo_cell_menu_button:init() 
  17. 	self.btn_h = vint_object_find("btn_scale_grp", self.handle, self.doc_handle) 
  18. 	self.btn_grp_h = vint_object_find("btn_grp", self.handle, self.doc_handle) 
  19. 	self.btn_hint = Vdo_hint_button:new("btn_hint", self.handle, self.doc_handle) 
  20. 	self.btn_label_h = vint_object_find("btn_label", self.handle, self.doc_handle) 
  21. 	self.btn_img_h = vint_object_find("btn_img", self.handle, self.doc_handle) 
  22. 	self.btn_num_h = vint_object_find("btn_num", self.handle, self.doc_handle) 
  23. 	self.btn_num_bg_h = vint_object_find("btn_num_bg", self.handle, self.doc_handle) 
  24. 	--self.btn_meter_h = vint_object_find("btn_meter", self.handle, self.doc_handle) 
  25. 	self.btn_bg_h = vint_object_find("btn_bg_grp", self.handle, self.doc_handle) 
  26. 	self.btn_bg_img_h = vint_object_find("btn_bg_img", self.handle, self.doc_handle) 
  27. 	--self.btn_highlight_anim_h = vint_object_find("btn_highlight_anim", self.handle, self.doc_handle) 
  28. 	--self.btn_unhighlight_anim_h = vint_object_find("btn_unhighlight_anim", self.handle, self.doc_handle) 
  29. 	self.btn_intro_anim_h = vint_object_find("btn_intro_anim", self.handle, self.doc_handle) 
  30. 	 
  31. 	--Retarget the anim for this vdo 
  32. 	vint_set_property(self.btn_highlight_anim_h, "target_handle", self.btn_h)			 
  33. 	vint_set_property(self.btn_unhighlight_anim_h, "target_handle", self.btn_h)			 
  34. 	vint_set_property(self.btn_intro_anim_h, "target_handle", self.btn_h)		 
  35.  
  36. 	--vint_apply_start_values(self.btn_highlight_anim_h) 
  37. 	 
  38. 	--Hide the A button for now 
  39. 	self.btn_hint:set_visible(false)	 
  40. 	self.btn_hint:set_button(CTRL_MENU_BUTTON_A) 
  41. 	 
  42. 	--Init to unhighlighted 
  43. 	self:set_highlight(false)			 
  44. end 
  45.  
  46.  
  47. function Vdo_cell_menu_button:set_highlight(is_highlighted)	 
  48. 	if is_highlighted == true then				 
  49. 		--Are we using controller or mouse/keyboard? 
  50. 		if game_is_active_input_gamepad() then 
  51. 			self.btn_hint:set_button(CTRL_MENU_BUTTON_A) 
  52. 			self.btn_hint:set_visible(true) 
  53. 		else 
  54. 			self.btn_hint:set_visible(false) 
  55. 		end 
  56. 				 
  57. 		--Set text color 
  58. 		vint_set_property(self.btn_label_h, "tint", 0,0,0) --COLOR_CELL_MENU_HIGHLIGHT_TEXT.R, COLOR_CELL_MENU_HIGHLIGHT_TEXT.G, COLOR_CELL_MENU_HIGHLIGHT_TEXT.B)				 
  59. 		 
  60. 		--Show background image 
  61. 		vint_set_property(self.btn_bg_h, "alpha", 1) 
  62. 		vint_set_property(self.btn_bg_img_h, "alpha", 1)	 
  63. 		vint_set_property(self.btn_bg_img_h, "tint", 1, .58, .16)		 
  64. 		vint_set_property(self.btn_img_h, "tint", 0, 0, 0) 
  65. 		vint_set_property(self.btn_num_bg_h, "tint", 0, 0, 0)		 
  66. 		vint_set_property(self.btn_num_h, "tint", 1, .58, .16) 
  67.  
  68. 		 
  69. 		--Draw in front... 
  70. 		self:set_depth(-20) 
  71. 		 
  72. 		--lua_play_anim(self.btn_highlight_anim_h, 0)				 
  73. 	else		 
  74. 		--Hide the A button 
  75. 		self.btn_hint:set_visible(false)		 
  76. 		 
  77. 		--Set text color 
  78. 		vint_set_property(self.btn_label_h, "tint", .86, .86, .86)--COLOR_CELL_MENU_UNHIGHLIGHT_TEXT.R,COLOR_CELL_MENU_UNHIGHLIGHT_TEXT.G,COLOR_CELL_MENU_UNHIGHLIGHT_TEXT.B)				 
  79. 		 
  80. 		--Hide background image 
  81. 		vint_set_property(self.btn_bg_h, "alpha", 1)		 
  82. 		vint_set_property(self.btn_bg_img_h, "alpha", 0)	 
  83. 		vint_set_property(self.btn_bg_img_h, "tint", .2, .2, .2)			 
  84. 		vint_set_property(self.btn_img_h, "tint", .8, .8, .8) 
  85. 		vint_set_property(self.btn_num_bg_h, "tint", 1, .58, .16)		 
  86. 		vint_set_property(self.btn_num_h, "tint", 0, 0, 0) 
  87. 				 
  88. 		--Move to back 
  89. 		self:set_depth(10) 
  90. 		 
  91. 		--Play unhighlight anim, scale button back down 
  92. 		--lua_play_anim(self.btn_unhighlight_anim_h, 0)		 
  93. 	end	 
  94. end 
  95.  
  96.  
  97. function Vdo_cell_menu_button:populate_button(label, icon, is_enabled, new_items, is_visible, can_wrap, meter_value)	 
  98. 	vint_set_property(self.btn_label_h, "text_tag", label) 
  99. 	vint_set_property(self.btn_img_h, "image", icon) 
  100. 		 
  101. 	if is_visible ~= nil then 
  102. 		vint_set_property(self.btn_grp_h, "visible", is_visible) 
  103. 	end 
  104.  
  105. 	if new_items ~= nil and new_items > 0 and is_enabled ~= false then 
  106. 		vint_set_property(self.btn_num_h, "text_tag", new_items) 
  107. 		vint_set_property(self.btn_num_h, "visible", true) 
  108. 		vint_set_property(self.btn_num_bg_h, "visible", true) 
  109. 		 
  110. 		local num_bg_scale_x = NUM_BG_SCALE 
  111. 		local num_bg_scale_y = NUM_BG_SCALE 
  112. 		 
  113. 		--if larger than 100 then expand num bg to fit		 
  114. 		if new_items > 99 then 
  115. 			num_bg_scale_x = NUM_BG_SCALE_LARGE 
  116. 		end				 
  117. 		 
  118. 		vint_set_property(self.btn_num_bg_h, "scale", num_bg_scale_x, num_bg_scale_y) 
  119. 	else 
  120. 		vint_set_property(self.btn_num_h, "visible", false) 
  121. 		vint_set_property(self.btn_num_bg_h, "visible", false) 
  122. 	end 
  123. 	 
  124. 	if is_enabled ~= nil then 
  125. 		self.is_enabled = is_enabled		 
  126.  
  127. 		--If disabled, darken the button 
  128. 		if is_enabled == false then 
  129. 			self:set_color(0.33, 0.33, 0.33) 
  130. 			self:set_alpha(0.8) 
  131. 		end 
  132. 	end 
  133. end 
  134.  
  135.  
  136. function Vdo_cell_menu_button:animate_in(time_offset) 
  137. 	vint_apply_start_values(self.btn_intro_anim_h) 
  138. 	lua_play_anim(self.btn_intro_anim_h, time_offset, self.doc_handle) 
  139. end 
  140.