./vdo_button_toggle.lua

  1. ---------------------------------------------------------------------------  
  2. -- Vdo_button_toggle 
  3. -- 
  4. -- A button toggle that ise designed for use in the Vdo_pause_mega_list  
  5. -- This item has 2 text strings label and a value. 
  6. --------------------------------------------------------------------------- 
  7.  
  8. function vdo_button_toggle_init() 
  9. end 
  10. function vdo_button_toggle_cleanup() 
  11. end 
  12.  
  13. -- Inherited from Vdo_base_object 
  14. Vdo_button_toggle = Vdo_base_object:new_base() 
  15.  
  16. -- "defines" 
  17. COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED = {R = 218/255, G = 226/255; B = 230/255} 
  18. COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED = {R = 0/255, G = 0/255; B = 0/255} 
  19. COLOR_ICON_LOCK = {R = 90/255, G = 90/255; B = 90/255} 
  20. COLOR_ICON_CHECK = {R = 220/255, G = 220/255; B = 220/255} 
  21. COLOR_ICON_SPECIAL = {R = 118/255, G = 0/255; B = 157/255} 
  22. COLOR_ICON_SPECIAL_DARK = {R = 58/255, G = 0/255; B = 78/255} 
  23. local BUTTON_TOGGLE_LOCK_OFFSET = 15 
  24.  
  25. BUTTON_TOGGLE_ICON_TYPE_NONE			= 0	--No Icon 
  26. BUTTON_TOGGLE_ICON_TYPE_LOCK 			= 1	--Lock icon 
  27. BUTTON_TOGGLE_ICON_TYPE_BOX			= 2	--Checkbox 
  28. BUTTON_TOGGLE_ICON_TYPE_BOX_CHECKED	= 3	--ChecboxChecked 
  29. BUTTON_TOGGLE_ICON_TYPE_INDENT		= 4	--Indented (No Icon) 
  30. BUTTON_TOGGLE_ICON_TYPE_NEW			= 5	--New item (exclamation point) 
  31. BUTTON_TOGGLE_ICON_TYPE_DLC			= 6	--DLC item (fleur) 
  32. BUTTON_TOGGLE_ICON_TYPE_SPECIAL		= 7	--Background highlight 
  33.  
  34.  
  35. function Vdo_button_toggle:init() 
  36. 	--Store references to icons... 
  37. 	self.icon1 = Vdo_base_object:new("icon1", self.handle, self.doc_handle) 
  38. 	self.icon2 = Vdo_base_object:new("icon2", self.handle, self.doc_handle) 
  39. 	 
  40. 	-- Hide optional icons 
  41. 	self:set_icon(0,0) 
  42. 	self.text_offset = 0 
  43. 	self.special = false 
  44. end 
  45.  
  46. -- Sets the label of the button object 
  47. function Vdo_button_toggle:set_label(new_label) 
  48. 	local text = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  49. 	 
  50. 	if text.handle ~= 0 then 
  51. 		text:set_property("text_tag", new_label) 
  52. 	end 
  53. end 
  54.  
  55. -- Sets the label crc of the button object 
  56. function Vdo_button_toggle:set_label_crc(new_label_crc) 
  57. 	local text = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  58. 	 
  59. 	if text.handle ~= 0 then 
  60. 		text:set_property("text_tag_crc", new_label_crc) 
  61. 	end 
  62. end 
  63.  
  64.  
  65. -- Sets the width of the button toggle object 
  66. function Vdo_button_toggle:set_width(width) 
  67. 	--this does nothing!?... should be removed? 
  68. end 
  69.  
  70. -- Sets the highlighted state of the button to on or off (will eventually have grayed out here too) 
  71. function Vdo_button_toggle:set_highlight(is_highlighted) 
  72.  
  73. 	if is_highlighted then 
  74. 		local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  75. 		if self.special ~= true then 
  76. 			self.icon1:set_color(0,0,0) 
  77. 		else 
  78. 			self.icon1:set_color(COLOR_ICON_SPECIAL) 
  79. 		end 
  80. 		 
  81. 		if self.highlight_color ~= nil then 
  82. 			text_obj:set_color(self.highlight_color.R, self.highlight_color.G, self.highlight_color.B)	 
  83. 			if self.special ~= true then 
  84. 				self.icon1:set_color(self.highlight_color.R, self.highlight_color.G, self.highlight_color.B)	 
  85. 			end 
  86. 			self.icon2:set_color(self.highlight_color.R, self.highlight_color.G, self.highlight_color.B)	 
  87. 		else 
  88. 			text_obj:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.R, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.G, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.B) 
  89. 			if self.special ~= true then 
  90. 				self.icon1:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.R, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.G, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.B) 
  91. 			end 
  92. 			self.icon2:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.R, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.G, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.B) 
  93. 		end 
  94. 	else 
  95. 		local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  96. 		text_obj:set_color(self.icon_color.R, self.icon_color.G, self.icon_color.B) 
  97. 		if self.special ~= true then 
  98. 			self.icon1:set_color(self.icon_color.R, self.icon_color.G, self.icon_color.B) 
  99. 		else 
  100. 			self.icon1:set_color(COLOR_ICON_SPECIAL_DARK) 
  101. 		end 
  102. 		self.icon2:set_color(self.icon_color.R, self.icon_color.G, self.icon_color.B) 
  103. 	end 
  104.  
  105. end 
  106.  
  107. -- Sets the enabled state of the button to on or off 
  108. function Vdo_button_toggle:set_enabled(enabled) 
  109.  
  110. 	local text = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  111. 	 
  112. 	if enabled then 
  113. 		text:set_alpha(1) 
  114. 		--text:set_color(1,1,1) 
  115. 	else 
  116. 		text:set_alpha(0.35) 
  117. 		--text:set_color(.2,.2,.2)	 
  118. 	end 
  119.  
  120. end 
  121.  
  122. function Vdo_button_toggle:set_highlight_color(new_color) 
  123. 	self.highlight_color = new_color 
  124. end 
  125.  
  126. ------------------------------------------------------------- 
  127. -- Sets an icon where the (A) button is 
  128. -- 
  129. -- @param icon		Corresponds to one of the following icons 
  130. -- BUTTON_TOGGLE_ICON_TYPE_NONE			= 0	--No Icon 
  131. -- BUTTON_TOGGLE_ICON_TYPE_LOCK 			= 1	--Lock icon 
  132. -- BUTTON_TOGGLE_ICON_TYPE_BOX			= 2	--Checkbox 
  133. -- BUTTON_TOGGLE_ICON_TYPE_BOX_CHECKED	= 3	--ChecboxChecked 
  134. -- BUTTON_TOGGLE_ICON_TYPE_INDENT		= 4	--Indented (No Icon) 
  135. -- BUTTON_TOGGLE_ICON_TYPE_NEW			= 5	--New item (exclamation point) 
  136. -- BUTTON_TOGGLE_ICON_TYPE_DLC			= 6	--DLC item (fleur) 
  137. -- BUTTON_TOGGLE_ICON_TYPE_SPECIAL		= 7	--Background highlight 
  138.  
  139. ------------------------------------------------------------- 
  140. function Vdo_button_toggle:set_icon(icon1, icon2) 
  141. 	local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  142. 	local text_obj_x, text_obj_y = text_obj:get_anchor() 
  143. 	local icon2_x, icon2_y = self.icon2:get_anchor() 
  144. 	local indent_count = 0 
  145. 	 
  146. 	self.icon_color = COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED 
  147. 	 
  148. 	if icon1 == BUTTON_TOGGLE_ICON_TYPE_LOCK then 
  149. 		self.icon1:set_image("ui_store_icon_lock_sm") 
  150. 		self.icon1:set_visible(true) 
  151. 	 
  152. 		self.icon_color = COLOR_ICON_LOCK 
  153. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_BOX then 
  154. 		self.icon1:set_image("ui_store_icon_box") 
  155. 		self.icon1:set_visible(true) 
  156. 		 
  157. 		self.icon_color = COLOR_ICON_CHECK 
  158.  
  159. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_BOX_CHECKED then 
  160. 		self.icon1:set_image("ui_store_icon_checkbox") 
  161. 		self.icon1:set_visible(true) 
  162. 		 
  163. 		self.icon_color = COLOR_ICON_CHECK 
  164. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_NEW then 
  165. 		self.icon1:set_image("ui_menu_tmp_arrow_e") 
  166. 		self.icon1:set_visible(true) 
  167. 		 
  168. 		--self.icon_color = self.highlight_color 
  169. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_DLC then 
  170. 		self.icon1:set_image("ui_store_icon_dlc") 
  171. 		self.icon1:set_visible(true) 
  172. 		 
  173. 		--self.icon_color = self.highlight_color 
  174. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_SPECIAL then 
  175. 		self.icon1:set_image("ui_blank") 
  176. 		self.icon1:set_property("auto_offset", "w") 
  177. 		self.icon1:set_scale(60, 1.6) -- Hacky, but works 
  178. 		self.icon1:set_visible(true) 
  179. 		 
  180. 		local x, y = self.icon1:get_anchor() 
  181. 		self.icon1:set_anchor(x - 100, y) -- Hacky, but works 
  182. 		 
  183. 		self.icon1:set_color(COLOR_ICON_SPECIAL_DARK) 
  184. 		self.special = true 
  185. 	else 
  186. 		self.icon1:set_visible(false) 
  187. 	end 
  188. 	 
  189. 	-- If we set icon2 move the button text over as well 
  190. 	if icon2 == BUTTON_TOGGLE_ICON_TYPE_INDENT then 
  191. 		-- Indent the text to align with other text w/ checkboxes 
  192. 		text_obj:set_anchor(icon2_x + BUTTON_TOGGLE_LOCK_OFFSET, text_obj_y) 
  193. 		indent_count = indent_count + 1 
  194. 	elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_LOCK then 
  195. 		text_obj:set_anchor(icon2_x + BUTTON_TOGGLE_LOCK_OFFSET, text_obj_y) 
  196. 		self.icon2:set_image("ui_store_icon_lock_sm") 
  197. 		self.icon2:set_visible(true) 
  198. 		 
  199. 		self.icon_color = COLOR_ICON_LOCK 
  200. 		indent_count = indent_count + 1 
  201. 	elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_BOX then 
  202. 		text_obj:set_anchor(icon2_x + BUTTON_TOGGLE_LOCK_OFFSET, text_obj_y) 
  203. 		self.icon2:set_image("ui_store_icon_box") 
  204. 		self.icon2:set_visible(true) 
  205. 		 
  206. 		self.icon_color = COLOR_ICON_CHECK 
  207. 		indent_count = indent_count + 1 
  208. 	elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_BOX_CHECKED then 
  209. 		text_obj:set_anchor(icon2_x + BUTTON_TOGGLE_LOCK_OFFSET, text_obj_y) 
  210. 		self.icon2:set_image("ui_store_icon_checkbox") 
  211. 		self.icon2:set_visible(true) 
  212. 		 
  213. 		self.icon_color = COLOR_ICON_CHECK 
  214. 		indent_count = indent_count + 1 
  215. 	else 
  216. 		self.icon2:set_visible(false) 
  217. 	end	 
  218. 	 
  219. 	--Count how many times we were indented and add it to our text offset... 
  220. 	self.text_offset = indent_count * (BUTTON_TOGGLE_LOCK_OFFSET + icon2_x) 
  221. end 
  222.  
  223. ------------------------------------------------------------------------------- 
  224. -- returns the size of the first text element... 
  225. ------------------------------------------------------------------------------- 
  226. function Vdo_button_toggle:get_text_width() 
  227. 	local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  228. 	local width, height = text_obj:get_actual_size() 
  229. 	--Size is the width of the text field plus the offset from the icon... 
  230. 	return width + self.text_offset 
  231. end 
  232.  
  233. function Vdo_button_toggle:set_label_anchor(new_x) 
  234. 	local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  235. 	local toggle_text_x, toggle_text_y = text_obj:get_anchor() 
  236. 	 
  237. 	text_obj:set_anchor(new_x, toggle_text_y) 
  238. end 
  239.  
  240. function Vdo_button_toggle:get_label_anchor() 
  241. 	local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  242. 	 
  243. 	return text_obj:get_anchor() 
  244. end 
  245.  
  246. function Vdo_button_toggle:set_text_scale(scale) 
  247. 	local text_h = vint_object_find("toggle_text", self.handle, self.doc_handle) 
  248. 	vint_set_property(text_h, "text_scale", scale, scale) 
  249. end 
  250.