./vdo_button_remap.lua

  1. ---------------------------------------------------------------------------  
  2. -- Vdo_button_remap 
  3. -- 
  4. -- A PC-specific button for remapping shortcut keys 
  5. --------------------------------------------------------------------------- 
  6.  
  7. function vdo_button_remap_init() 
  8. end 
  9. function vdo_button_remap_cleanup() 
  10. end 
  11.  
  12. -- Inherited from Vdo_base_object 
  13. Vdo_button_remap = Vdo_base_object:new_base() 
  14.  
  15. local DEFAULT_VALUE1_OFFSET = 200 
  16. local DEFAULT_VALUE2_OFFSET = 350 
  17.  
  18. local SCALE_UNSELECTED = 0.75 
  19. local SCALE_SELECTED = 0.95 
  20.  
  21. function Vdo_button_remap:init() 
  22. 	self.value_bg = {} 
  23. 	self.value_text = {} 
  24. 	self.value_button = {} 
  25. 	 
  26. 	-- Get references to the subelements 
  27. 	self.label_text =  Vdo_base_object:new("label_text", self.handle, self.doc_handle) 
  28. 	self.value_bg[1] =  Vdo_base_object:new("value1_bg1", self.handle, self.doc_handle) 
  29. 	self.value_text[1] =  Vdo_base_object:new("value1_text", self.handle, self.doc_handle) 
  30. 	self.value_button[1] =  Vdo_hint_button:new("value1_button", self.handle, self.doc_handle) 
  31. 	self.value_bg[2] =  Vdo_base_object:new("value2_bg", self.handle, self.doc_handle) 
  32. 	self.value_text[2] =  Vdo_base_object:new("value2_text", self.handle, self.doc_handle) 
  33. 	self.value_button[2] =  Vdo_hint_button:new("value2_button", self.handle, self.doc_handle) 
  34. 	 
  35. 	self.value_bg[1]:set_visible(false) 
  36. 	self.value_bg[2]:set_visible(false) 
  37. 	 
  38. 	-- Set blank defaults 
  39. 	self:set_shortcut(1, nil) 
  40. 	self:set_shortcut(2, nil) 
  41. 	self:set_label("EMPTY") 
  42. 	 
  43. 	-- Nothing highlighted by default 
  44. 	self:set_highlight_column(0) 
  45. 	 
  46. 	self:set_highlight(false) 
  47. end 
  48.  
  49. -- Moves the value elements to their proper location 
  50. function Vdo_button_remap:set_value_offset(offset) 
  51. 	self.value_bg[1]:set_anchor(DEFAULT_VALUE1_OFFSET + offset, 0) 
  52. 	self.value_text[1]:set_anchor(DEFAULT_VALUE1_OFFSET + offset, 0) 
  53. 	self.value_button[1]:set_anchor(DEFAULT_VALUE1_OFFSET + offset, 0) 
  54. 	self.value_bg[2]:set_anchor(DEFAULT_VALUE2_OFFSET + offset, 0) 
  55. 	self.value_text[2]:set_anchor(DEFAULT_VALUE2_OFFSET + offset, 0) 
  56. 	self.value_button[2]:set_anchor(DEFAULT_VALUE2_OFFSET + offset, 0) 
  57. end 
  58.  
  59. -- Sets the shortcut (nil to clear) 
  60. function Vdo_button_remap:set_shortcut(column, shortcut) 
  61. 	if shortcut == nil then 
  62. 		self.value_text[column]:set_text("--") 
  63. 		self.value_text[column]:set_visible(true) 
  64. 		self.value_button[column]:set_visible(false) 
  65. 	else 
  66. 		self.value_text[column]:set_visible(false) 
  67. 		self.value_button[column]:set_visible(true) 
  68. 		self.value_button[column]:set_button(nil, shortcut) 
  69. 	end 
  70. end 
  71.  
  72. -- Wait for the player to press a button (show a "?") 
  73. function Vdo_button_remap:wait_for_key(index, column) 
  74. 	self.value_text[column]:set_text("?") 
  75. 	self.value_text[column]:set_visible(true) 
  76. 	self.value_button[column]:set_visible(false) 
  77. 	-- Remap_category_index is in pause_options_remap 
  78. 	vint_options_remap_set_key_binding(Remap_category_index, index - 1, column == 2) -- Subtract 1 because category is index 1, remapping starts at 2 
  79. end 
  80.  
  81. -- Sets the label of the button object 
  82. function Vdo_button_remap:set_label(new_label) 
  83. 	self.label_text:set_property("text_tag", new_label) 
  84. end 
  85.  
  86. -- Sets the width of the button toggle object 
  87. function Vdo_button_remap:set_width(width) 
  88. 	--this does nothing!?... should be removed? 
  89. end 
  90.  
  91. -- Sets highlighting on/off for the megalist 
  92. function Vdo_button_remap:set_highlight(highlight)	 
  93. 	if highlight == false then 
  94. 		self.label_text:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED)	 
  95. 		self.current_column = 0 
  96. 	else 
  97. 		self.label_text:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED) 
  98. 		 
  99. 		if self.current_column == 0 then 
  100. 			self.current_column = 1 
  101. 		end 
  102. 	end 
  103. 	 
  104. 	self:update_column_highlight() 
  105. end 
  106.  
  107. -- Sets which column is highlighted, or 0 for none (the whole thing is not highlighted) 
  108. function Vdo_button_remap:set_highlight_column(highlight_column)	 
  109. 	self.current_column = highlight_column 
  110. 	 
  111. 	self:update_column_highlight() 
  112. end 
  113.  
  114. function Vdo_button_remap:update_column_highlight() 
  115. 	self.value_text[1]:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED)	 
  116. 	self.value_text[2]:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED)	 
  117. 	self.value_button[1]:set_scale(SCALE_UNSELECTED, SCALE_UNSELECTED) 
  118. 	self.value_button[2]:set_scale(SCALE_UNSELECTED, SCALE_UNSELECTED) 
  119. 	self.value_button[1]:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED)	 
  120. 	self.value_button[2]:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED) 
  121. 	self.value_button[1]:set_scale(SCALE_UNSELECTED, SCALE_UNSELECTED) 
  122. 	self.value_button[2]:set_scale(SCALE_UNSELECTED, SCALE_UNSELECTED) 
  123. 	 
  124. 	if self.current_column > 0 then 
  125. 		self.value_text[self.current_column]:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED)	 
  126. 		self.value_button[self.current_column]:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED)	 
  127. 		self.value_text[self.current_column]:set_scale(SCALE_SELECTED, SCALE_SELECTED) 
  128. 		self.value_button[self.current_column]:set_scale(SCALE_SELECTED, SCALE_SELECTED) 
  129. 	end 
  130. end 
  131.  
  132. function Vdo_button_remap:get_target_column(handle) 
  133. 	if handle == self.value_bg[1].handle then 
  134. 		return 1 
  135. 	elseif handle == self.value_bg[2].handle then 
  136. 		return 2 
  137. 	else 
  138. 		return 0 
  139. 	end 
  140. end 
  141.  
  142. -- Sets the enabled state of the button to on or off 
  143. function Vdo_button_remap:set_enabled(enabled)	 
  144. 	if enabled then 
  145. 		self.label_text:set_alpha(1) 
  146. 	else 
  147. 		self.label_text:set_alpha(0.35) 
  148. 	end 
  149. end 
  150.  
  151. function Vdo_button_remap:set_highlight_color(new_color) 
  152. 	self.highlight_color = new_color 
  153. end 
  154.  
  155. -- Get the size of the label's text 
  156. function Vdo_button_remap:get_text_width() 
  157. 	local width, height = self.label_text:get_actual_size() 
  158.  
  159. 	return width 
  160. end