Class: UI::Shop::ItemList::ListButton

Inherits:
UI::SpriteStack show all
Defined in:
scripts/01300 UI/00700 Shop/00030 ItemList.rb

Constant Summary

Constants inherited from UI::SpriteStack

UI::SpriteStack::NO_INITIAL_IMAGE

Instance Attribute Summary collapse

Attributes inherited from UI::SpriteStack

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

Instance Method Summary collapse

Methods inherited from UI::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) ⇒ ListButton

Create a new Item sell button

Parameters:

  • viewport (Viewport)

    the viewport in which the SpriteStack will be displayed

  • index (Integer)


182
183
184
185
186
187
188
189
190
191
192
193
# File 'scripts/01300 UI/00700 Shop/00030 ItemList.rb', line 182

def initialize(viewport, index)
  @index = index
  super(viewport, BASE_X + (active? ? ACTIVE_OFFSET : 0), BASE_Y + BUTTON_OFFSET * index)
  add_background('shop/button_list').set_z(1)
  @item_name = add_text(37, 8, 92, 18, nil.to_s, 1, color: 10)
  @item_name.z = 2
  @item_price = add_text(133, 8, 37, 17, nil.to_s, 2, color: 0)
  @item_price.draw_shadow = false
  @item_price.z = 2
  @item_icon = add_sprite(3, 2, NO_INITIAL_IMAGE, type: ItemSprite)
  @item_icon.z = 3
end

Instance Attribute Details

#indexInteger

Returns Index of the button in the list.

Returns:

  • (Integer)

    Index of the button in the list



177
178
179
# File 'scripts/01300 UI/00700 Shop/00030 ItemList.rb', line 177

def index
  @index
end

Instance Method Details

#active?Boolean

Is the button active

Returns:

  • (Boolean)


196
197
198
# File 'scripts/01300 UI/00700 Shop/00030 ItemList.rb', line 196

def active?
  @index == 1
end

#icon_data=(icon)

Set the item icon

Parameters:

  • icon (Integer)

    the item id for the icon



218
219
220
221
222
223
224
# File 'scripts/01300 UI/00700 Shop/00030 ItemList.rb', line 218

def icon_data=(icon)
  if self.visible == false
    @item_icon.set_bitmap(nil)
  else
    @item_icon.data = icon
  end
end

#price=(price)

Set the item price

Parameters:

  • price (Integer, nil)

    the item price



210
211
212
213
214
# File 'scripts/01300 UI/00700 Shop/00030 ItemList.rb', line 210

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

  @item_price.text = price.to_s
end

#reset

Reset the button coordinate



227
228
229
# File 'scripts/01300 UI/00700 Shop/00030 ItemList.rb', line 227

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



202
203
204
205
206
# File 'scripts/01300 UI/00700 Shop/00030 ItemList.rb', line 202

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

  @item_name.text = text
end