./vdo_button_toggle.lua

  1. ---------------------------------------------------------------------------  
  2. -- Vdo_button_toggle 
  3. -- 
  4. -- A button toggle that is 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.  
  11.  
  12. function vdo_button_toggle_cleanup() 
  13. end 
  14.  
  15. -- Inherited from Vdo_base_object 
  16. Vdo_button_toggle = Vdo_base_object:new_base() 
  17.  
  18. -- "defines" 
  19. COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED = {R = 218/255, G = 226/255; B = 230/255} 
  20. COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED = {R = 0/255, G = 0/255; B = 0/255} 
  21. COLOR_ICON_LOCK = {R = 90/255, G = 90/255; B = 90/255} 
  22. COLOR_ICON_CHECK = {R = 220/255, G = 220/255; B = 220/255} 
  23. COLOR_ICON_SPECIAL = {R = 118/255, G = 0/255; B = 157/255} 
  24. COLOR_ICON_SPECIAL_DARK = {R = 58/255, G = 0/255; B = 78/255} 
  25. COLOR_ICON_COMPLETED = {R = 90/255, G = 90/255; B = 90/255} 
  26.  
  27. local ICON2_ANCHOR_X = 19 
  28. local ICON2_ANCHOR_Y = 0 
  29. local BUTTON_TOGGLE_LOCK_OFFSET = 15 
  30. local STRIKE_THROUGH_OFFSET = 100 
  31.  
  32. BUTTON_TOGGLE_ICON_TYPE_NONE						= 0	--No Icon 
  33. BUTTON_TOGGLE_ICON_TYPE_LOCK 						= 1	--Lock icon 
  34. BUTTON_TOGGLE_ICON_TYPE_BOX						= 2	--Checkbox 
  35. BUTTON_TOGGLE_ICON_TYPE_BOX_CHECKED				= 3	--ChecboxChecked 
  36. BUTTON_TOGGLE_ICON_TYPE_INDENT					= 4	--Indented (No Icon) 
  37. BUTTON_TOGGLE_ICON_TYPE_NEW						= 5	--New item (exclamation point) 
  38. BUTTON_TOGGLE_ICON_TYPE_DLC						= 6	--DLC item (fleur) 
  39. BUTTON_TOGGLE_ICON_TYPE_SPECIAL					= 7	--Background highlight 
  40. BUTTON_TOGGLE_ICON_TYPE_COMPLETED				= 8	--Grey Checkbox Checked 
  41. BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED			= 9	--Dual arrows 
  42. BUTTON_TOGGLE_ICON_TYPE_QUEST_COMPLETE			= 10	--Square bullet point 
  43. BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED_COOP 	= 11 	--2 with arrow 
  44.  
  45.  
  46. function Vdo_button_toggle:init() 
  47. 	--Store references to icons... 
  48. 	self.icon1 = Vdo_base_object:new("icon1", self.handle, self.doc_handle) 
  49. 	self.icon2 = Vdo_base_object:new("icon2", self.handle, self.doc_handle) 
  50. 		 
  51. 	self.text_h = vint_object_find("toggle_text", self.handle, self.doc_handle) 
  52. 		 
  53. 	-- Hide optional icons 
  54. 	self:set_icon(0,0) 
  55. 	self.text_offset = 0 
  56. 	self.special = false 
  57. 	--HVS_JPM[KING] 12/11/2014: optional for special highlighted text (used in invite friends list) 
  58. 	self.special_color = nil 
  59. end 
  60.  
  61.  
  62. -- Sets the label of the button object 
  63. function Vdo_button_toggle:set_label(new_label) 
  64. 	if self.text_h ~= 0 then 
  65. 		vint_set_property(self.text_h, "text_tag", new_label)		 
  66. 	end 
  67. end 
  68.  
  69.  
  70. -- Sets the label crc of the button object 
  71. function Vdo_button_toggle:set_label_crc(new_label_crc) 
  72. 	if self.text_h ~= 0 then 
  73. 		vint_set_property(self.text_h, "text_tag_crc", new_label_crc)		 
  74. 	end 
  75. end 
  76.  
  77.  
  78. -- Sets the highlighted state of the button to on or off (will eventually have grayed out here too) 
  79. function Vdo_button_toggle:set_highlight(is_highlighted) 
  80. 	if is_highlighted then 
  81. 		local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  82. 		if self.special ~= true then 
  83. 			self.icon1:set_color(0,0,0) 
  84. 		else 
  85. 			self.icon1:set_color(COLOR_ICON_SPECIAL) 
  86. 		end 
  87. 		 
  88. 		if self.highlight_color ~= nil then 
  89. 			text_obj:set_color(self.highlight_color.R, self.highlight_color.G, self.highlight_color.B)	 
  90. 			if self.special ~= true then 
  91. 				self.icon1:set_color(self.highlight_color.R, self.highlight_color.G, self.highlight_color.B)	 
  92. 			end 
  93. 			self.icon2:set_color(self.highlight_color.R, self.highlight_color.G, self.highlight_color.B)	 
  94. 		else 
  95. 			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) 
  96. 			if self.special ~= true then 
  97. 				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) 
  98. 			end 
  99. 			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) 
  100. 		end 
  101. 	else 
  102. 		--HVS_JPM[KING] 12/11/2014: if we have a special color (for the invite friends screen) we will set the text to that instead of the regular list color (white or black) 
  103. 		local text_color = self.icon_color 
  104. 		if self.special_color ~= nil then 
  105. 			text_color = self.special_color 
  106. 		end 
  107. 		local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  108. 		text_obj:set_color(text_color.R, text_color.G, text_color.B) 
  109. 		if self.special ~= true then 
  110. 			self.icon1:set_color(self.icon_color.R, self.icon_color.G, self.icon_color.B) 
  111. 		else 
  112. 			self.icon1:set_color(COLOR_ICON_SPECIAL_DARK) 
  113. 		end 
  114. 		self.icon2:set_color(self.icon_color.R, self.icon_color.G, self.icon_color.B) 
  115. 	end 
  116. end 
  117.  
  118. -- Sets the enabled state of the button to on or off 
  119. function Vdo_button_toggle:set_enabled(enabled) 
  120.  
  121. 	local text = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  122. 	 
  123. 	if enabled then 
  124. 		text:set_alpha(1) 
  125. 		--text:set_color(1,1,1) 
  126. 	else 
  127. 		text:set_alpha(0.35) 
  128. 		--text:set_color(.2,.2,.2)	 
  129. 	end 
  130.  
  131. end 
  132.  
  133.  
  134. function Vdo_button_toggle:set_alpha(alpha) 
  135. 	local text = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  136. 	text:set_alpha(alpha) 
  137. end 
  138.  
  139.  
  140. --HVS_JPM[KING] 12/11/2014: added special color param for none highlighted special text color (optional) 
  141. function Vdo_button_toggle:set_highlight_color(new_color, special_color) 
  142. 	self.highlight_color = new_color 
  143. 	self.special_color = special_color 
  144. end 
  145.  
  146. ------------------------------------------------------------------------------- 
  147. -- Function Vdo_button_toggle:set_icon() 
  148. -- 
  149. -- Sets up to 2 icons on the button 
  150. -- 
  151. -- @param icon1		-- First icon 
  152. -- @param icon2		-- Second icon 
  153. -- 
  154. -- Icon types: 
  155. -- BUTTON_TOGGLE_ICON_TYPE_NONE						= 0	--No Icon 
  156. -- BUTTON_TOGGLE_ICON_TYPE_LOCK 						= 1	--Lock icon 
  157. -- BUTTON_TOGGLE_ICON_TYPE_BOX						= 2	--Checkbox 
  158. -- BUTTON_TOGGLE_ICON_TYPE_BOX_CHECKED				= 3	--ChecboxChecked 
  159. -- BUTTON_TOGGLE_ICON_TYPE_INDENT					= 4	--Indented (No Icon) 
  160. -- BUTTON_TOGGLE_ICON_TYPE_NEW						= 5	--New item (exclamation point) 
  161. -- BUTTON_TOGGLE_ICON_TYPE_DLC						= 6	--DLC item (fleur) 
  162. -- BUTTON_TOGGLE_ICON_TYPE_SPECIAL					= 7	--Background highlight 
  163. -- BUTTON_TOGGLE_ICON_TYPE_COMPLETED				= 8	--Grey checkboxChecked 
  164. -- BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED			= 9	--Dual arrows 
  165. -- BUTTON_TOGGLE_ICON_TYPE_QUEST_COMPLETE			= 10	--Square bullet point 
  166. -- BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED_COOP		= 11	--2 with an Arrow 
  167. -- 
  168. ------------------------------------------------------------------------------- 
  169. function Vdo_button_toggle:set_icon(icon1, icon2) 
  170. 	local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  171. 	local text_obj_x, text_obj_y = text_obj:get_anchor() 
  172. 	local icon2_x, icon2_y = ICON2_ANCHOR_X, ICON2_ANCHOR_Y 
  173. 	local indent_count = 0 
  174. 	 
  175. 	--Adjust for legacy icons - the checked box is offset by 2 
  176. 	self.icon2:set_anchor(ICON2_ANCHOR_X, -2) 
  177. 	 
  178. 	self.icon2:set_alpha(1) 
  179. 	 
  180. 	self.icon_color = COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED 
  181. 	 
  182. 	if icon1 == BUTTON_TOGGLE_ICON_TYPE_LOCK then 
  183. 		self.icon1:set_image("ui_store_icon_lock_sm") 
  184. 		self.icon1:set_visible(true) 
  185. 	 
  186. 		self.icon_color = COLOR_ICON_LOCK 
  187. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_BOX then 
  188. 		self.icon1:set_image("ui_store_icon_box") 
  189. 		self.icon1:set_visible(true) 
  190. 		 
  191. 		self.icon_color = COLOR_ICON_CHECK 
  192.  
  193. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_BOX_CHECKED then 
  194. 		self.icon1:set_image("ui_store_icon_checkbox") 
  195. 		self.icon1:set_visible(true) 
  196. 		 
  197. 		self.icon_color = COLOR_ICON_CHECK 
  198. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_NEW then 
  199. 		self.icon1:set_image("ui_menu_tmp_arrow_e") 
  200. 		self.icon1:set_visible(true) 
  201. 		 
  202. 		--self.icon_color = self.highlight_color 
  203. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_DLC then 
  204. 		self.icon1:set_image("ui_store_icon_dlc") 
  205. 		self.icon1:set_visible(true) 
  206. 		 
  207. 		--self.icon_color = self.highlight_color 
  208. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_SPECIAL then 
  209. 		self.icon1:set_image("ui_blank") 
  210. 		self.icon1:set_property("auto_offset", "w") 
  211. 		self.icon1:set_scale(60, 1.6) -- Hacky, but works 
  212. 		self.icon1:set_visible(true) 
  213. 		 
  214. 		local x, y = self.icon1:get_anchor() 
  215. 		self.icon1:set_anchor(x - 100, y) -- Hacky, but works 
  216. 		 
  217. 		self.icon1:set_color(COLOR_ICON_SPECIAL_DARK) 
  218. 		self.special = true 
  219. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_COMPLETED then 
  220. 		self.icon1:set_image("ui_store_icon_checkbox") 
  221. 		self.icon1:set_visible(true) 
  222. 		 
  223. 		self.icon_color = COLOR_ICON_COMPLETED 
  224. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED then 
  225. 		self.icon1:set_image("ui_quest_icon_pin") 
  226. 		self.icon1:set_visible(true) 
  227. 		 
  228. 		self.icon_color = COLOR_ICON_CHECK 
  229. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_QUEST_COMPLETE then 
  230. 		self.icon1:set_image("ui_quest_icon_complete") 
  231. 		self.icon1:set_visible(true) 
  232. 		 
  233. 		self.icon_color = COLOR_ICON_CHECK 
  234. 	elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED_COOP then 
  235. 		self.icon1:set_image("ui_quest_icon_pin_coop") 
  236. 		self.icon1:set_visible(true) 
  237. 		 
  238. 		self.icon_color = COLOR_ICON_CHECK 
  239. 	else	 
  240. 		self.icon1:set_visible(false) 
  241. 	end 
  242. 	 
  243. 	-- If we set icon2 move the button text over as well 
  244. 	if icon2 == BUTTON_TOGGLE_ICON_TYPE_INDENT then 
  245. 		-- Indent the text to align with other text w/ checkboxes 
  246. 		text_obj:set_anchor(icon2_x + BUTTON_TOGGLE_LOCK_OFFSET, text_obj_y) 
  247. 		indent_count = indent_count + 1 
  248. 		 
  249. 	elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_DLC then 
  250. 		self.icon2:set_image("ui_store_icon_dlc") 
  251. 		self.icon2:set_visible(true) 
  252. 		 
  253. 	elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_LOCK then 
  254. 		text_obj:set_anchor(icon2_x + BUTTON_TOGGLE_LOCK_OFFSET, text_obj_y) 
  255. 		self.icon2:set_image("ui_store_icon_lock_sm") 
  256. 		self.icon2:set_visible(true) 
  257. 		 
  258. 		self.icon_color = COLOR_ICON_LOCK 
  259. 		indent_count = indent_count + 1 
  260. 	elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_BOX then 
  261. 		text_obj:set_anchor(icon2_x + BUTTON_TOGGLE_LOCK_OFFSET, text_obj_y) 
  262. 		self.icon2:set_anchor(ICON2_ANCHOR_X + 3, -2) 
  263. 		self.icon2:set_image("ui_store_icon_box") 
  264. 		self.icon2:set_visible(true) 
  265. 		 
  266. 		self.icon_color = COLOR_ICON_CHECK 
  267. 		indent_count = indent_count + 1 
  268. 	elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_BOX_CHECKED then 
  269. 		text_obj:set_anchor(icon2_x + BUTTON_TOGGLE_LOCK_OFFSET, text_obj_y) 
  270. 		self.icon2:set_image("ui_store_icon_checkbox") 
  271. 		self.icon2:set_visible(true) 
  272. 		 
  273. 		self.icon_color = COLOR_ICON_CHECK 
  274. 		indent_count = indent_count + 1 
  275. 	elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_COMPLETED then 
  276. 		self.icon2:set_image("ui_store_icon_checkbox") 
  277. 		self.icon2:set_visible(true) 
  278. 		 
  279. 		self.icon_color = COLOR_ICON_COMPLETED			 
  280. 	elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED then 
  281. 		self.icon2:set_image("ui_quest_icon_pin") 
  282. 		self.icon2:set_visible(true) 
  283. 		 
  284. 		self.icon_color = COLOR_ICON_CHECK 
  285. 		indent_count = indent_count + 1 
  286. 		 
  287. 		self.icon2:set_anchor(icon2_x, 0)		 
  288. 	elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_QUEST_COMPLETE then 
  289. 		self.icon2:set_image("ui_blank") 
  290. 		self.icon2:set_visible(true) 
  291. 		 
  292. 		--Strike through the text 
  293. 		local label_width, label_height = element_get_actual_size(self.text_h) 
  294. 		vint_set_property(self.icon2.handle, "auto_offset", "w") 
  295. 				 
  296. 		element_set_actual_size(self.icon2.handle, label_width * .8, 2) 
  297. 		 
  298. 		self.icon2:set_anchor(ICON2_ANCHOR_X, ICON2_ANCHOR_Y) 
  299. 		 
  300. 		self.icon_color = COLOR_ICON_CHECK 
  301. 		self.icon2:set_alpha(.35) 
  302. 		 
  303. 		indent_count = indent_count + 1 
  304. 	elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED_COOP then 
  305. 		self.icon2:set_image("ui_quest_icon_pin_coop") 
  306. 		self.icon2:set_visible(true) 
  307. 		 
  308. 		self.icon_color = COLOR_ICON_CHECK 
  309. 		indent_count = indent_count + 1 
  310. 		 
  311. 		self.icon2:set_anchor(icon2_x, 0)	 
  312. 	else 
  313. 		self.icon2:set_visible(false) 
  314. 	end	 
  315. 	 
  316. 	--Count how many times we were indented and add it to our text offset... 
  317. 	self.text_offset = indent_count * (BUTTON_TOGGLE_LOCK_OFFSET + icon2_x) 
  318. end 
  319.  
  320. ------------------------------------------------------------------------------- 
  321. -- returns the size of the first text element... 
  322. ------------------------------------------------------------------------------- 
  323. function Vdo_button_toggle:get_text_width() 
  324. 	local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  325. 	local width, height = text_obj:get_actual_size() 
  326. 	--Size is the width of the text field plus the offset from the icon... 
  327. 	return width + self.text_offset 
  328. end 
  329.  
  330.  
  331. function Vdo_button_toggle:set_label_anchor(new_x) 
  332. 	local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  333. 	local toggle_text_x, toggle_text_y = text_obj:get_anchor() 
  334. 	 
  335. 	text_obj:set_anchor(new_x, toggle_text_y) 
  336. end 
  337.  
  338.  
  339. function Vdo_button_toggle:get_label_anchor() 
  340. 	local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle) 
  341. 	 
  342. 	return text_obj:get_anchor() 
  343. end 
  344.  
  345.  
  346. function Vdo_button_toggle:set_text_scale(scale) 
  347. 	local text_h = vint_object_find("toggle_text", self.handle, self.doc_handle) 
  348. 	vint_set_property(text_h, "text_scale", scale, scale) 
  349. end