Class: UI::Options::Button

Inherits:
SpriteStack show all
Defined in:
scripts/01450 Systems/00105 Options/00002 UI/00003 Button.rb

Constant Summary collapse

OPTION_OFFSET_Y =
40
OPTION_BASE_X =
19
OPTION_OFFSET_X =
4

Constants inherited from SpriteStack

SpriteStack::NO_INITIAL_IMAGE

Instance Attribute Summary collapse

Attributes inherited from SpriteStack

#animated, #data, #moving, #stack, #viewport, #x, #y

Instance Method Summary collapse

Methods inherited from SpriteStack

#[], #add_background, #add_line, #add_text, #anime, #anime_delta_set, #dispose, #each, #execute_anime, #move, #move_to, #opacity, #opacity=, #push, #push_sprite, #set_origin, #set_position, #simple_mouse_in?, #size, #stop_animation, #translate_mouse_coords, #update, #update_animation, #update_position, #visible, #visible=, #with_cache, #with_font, #with_surface, #z, #z=

Constructor Details

#initialize(viewport, index, option) ⇒ Button

Create a new Option Button

Parameters:



17
18
19
20
21
22
23
24
# File 'scripts/01450 Systems/00105 Options/00002 UI/00003 Button.rb', line 17

def initialize(viewport, index, option)
  super(viewport, OPTION_BASE_X, OPTION_OFFSET_Y * index)
  @option = option
  @value = option.current_value
  @option_background = add_background('options/option')
  @option_name = add_text(8, 3, 0, 16, @option.name, color: 10)
  @option_value = add_text(14, 19, 96, 16, value_text, 1)
end

Instance Attribute Details

#optionGamePlay::Options::Helper (readonly)

Option modified by the button



9
10
11
# File 'scripts/01450 Systems/00105 Options/00002 UI/00003 Button.rb', line 9

def option
  @option
end

#valueOption

Current value shown by the button

Returns:

  • (Option)


12
13
14
# File 'scripts/01450 Systems/00105 Options/00002 UI/00003 Button.rb', line 12

def value
  @value
end

Instance Method Details

#reload_texts

Reload the name of the button for when the language is changed in the options



48
49
50
51
# File 'scripts/01450 Systems/00105 Options/00002 UI/00003 Button.rb', line 48

def reload_texts
  @option_name.text = @option.name
  @option_value.text = value_text
end

#value_indexInteger

Return the value index

Returns:



28
29
30
31
# File 'scripts/01450 Systems/00105 Options/00002 UI/00003 Button.rb', line 28

def value_index
  return @value if @option.type == :slider
  @option.values.index(@value) || 0
end

#value_textString

Retreive the option value text

Returns:



42
43
44
45
# File 'scripts/01450 Systems/00105 Options/00002 UI/00003 Button.rb', line 42

def value_text
  return format(@option.values_text, @value) if @option.type == :slider
  @option.values_text[value_index]
end