Class: UI::Bag::ButtonList::ItemButton

Inherits:
SpriteStack show all
Defined in:
scripts/01450 Systems/00103 Bag/00002 UI/00060 ButtonList.rb

Overview

Button showing the item name

Constant Summary collapse

BACKGROUND =

Name of the button background

'bag/button_list'

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) ⇒ ItemButton

Create a new Item button

Parameters:



148
149
150
151
152
153
# File 'scripts/01450 Systems/00103 Bag/00002 UI/00060 ButtonList.rb', line 148

def initialize(viewport, index)
  @index = index
  super(viewport, BASE_X + (active? ? ACTIVE_OFFSET : 0), BASE_Y + BUTTON_OFFSET * index)
  create_background
  @item_name = create_text
end

Instance Attribute Details

#indexInteger

Returns Index of the button in the list.

Returns:

  • (Integer)

    Index of the button in the list



143
144
145
# File 'scripts/01450 Systems/00103 Bag/00002 UI/00060 ButtonList.rb', line 143

def index
  @index
end

Instance Method Details

#active?Boolean

Is the button active

Returns:

  • (Boolean)


156
157
158
# File 'scripts/01450 Systems/00103 Bag/00002 UI/00060 ButtonList.rb', line 156

def active?
  @index == 2
end

#reset

Reset the button coordinate



169
170
171
# File 'scripts/01450 Systems/00103 Bag/00002 UI/00060 ButtonList.rb', line 169

def reset
  set_position(BASE_X + (active? ? ACTIVE_OFFSET : 0), BASE_Y + BUTTON_OFFSET * index)
end

#text=(text)

Set the button text

Parameters:

  • text (String, nil)

    the item name



162
163
164
165
166
# File 'scripts/01450 Systems/00103 Bag/00002 UI/00060 ButtonList.rb', line 162

def text=(text)
  return unless (self.visible = !text.nil?)

  @item_name.text = text
end