Class: UI::GenericBase::ControlButton

Inherits:
SpriteStack show all
Defined in:
scripts/01450 Systems/00000 General/00100 UI Generics/00400 GenericBase.rb

Overview

Generic Button used to help the player to know what key he can press

Constant Summary collapse

COORDINATES =

Array of button coordinates

[[3, 219], [83, 219], [163, 219], [243, 219]]

Constants inherited from SpriteStack

SpriteStack::NO_INITIAL_IMAGE

Instance Attribute Summary

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, coords_index, key) ⇒ ControlButton

Create a new Button

Parameters:

  • viewport (Viewport)
  • coords_index (Integer)

    index of the coordinates to use in order to position the button

  • key (Symbol)

    key to show by default



134
135
136
137
138
139
140
141
142
143
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00400 GenericBase.rb', line 134

def initialize(viewport, coords_index, key)
  super(viewport, *COORDINATES[coords_index], default_cache: :pokedex)
  @background = add_background('buttons')
  # @type [KeyShortcut]
  @key_button = add_sprite(0, 1, NO_INITIAL_IMAGE, key, coords_index == 3, type: KeyShortcut)
  with_font(text_font) { @text = add_text(17, 3, 51, 13, nil.to_s, color: text_color(coords_index)) }
  @coords_index = coords_index
  self.pressed = false
  self.z = 501
end

Instance Method Details

#key=(value)

Set the key shown by the button

Parameters:

  • value (Symbol)


165
166
167
168
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00400 GenericBase.rb', line 165

def key=(value)
  return unless value.is_a?(Symbol)
  @key_button.find_key(value)
end

#pressed=(pressed) Also known as: set_press

Set the button pressed

Parameters:

  • pressed (Boolean)

    if the button is pressed or not



147
148
149
150
151
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00400 GenericBase.rb', line 147

def pressed=(pressed)
  @background.set_rect_div(@coords_index == 3 ? 1 : 0, pressed ? 1 : 0, 2, 2)
  @background.src_rect.x += 1 if @coords_index == 3
  @background.src_rect.y += 1 if pressed
end

#text=(value)

Set the text shown by the button

Parameters:

  • value (String)

    text to show



156
157
158
159
160
161
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00400 GenericBase.rb', line 156

def text=(value)
  return unless value.is_a?(String) || value.nil?

  @text.text = value if value
  self.visible = (value ? true : false)
end