Class: UI::Shop::PkmList::ListButtonPkm

Inherits:
UI::SpriteStack show all
Defined in:
scripts/01450 Systems/00203 Shop/00002 PokemonShop UI/00010 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) ⇒ ListButtonPkm

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/01450 Systems/00203 Shop/00002 PokemonShop UI/00010 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(2, 0, false, NO_INITIAL_IMAGE, type: PokemonIconSprite)
  @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/01450 Systems/00203 Shop/00002 PokemonShop UI/00010 ItemList.rb', line 177

def index
  @index
end

Instance Method Details

#active?Boolean

Is the button active

Returns:

  • (Boolean)


196
197
198
# File 'scripts/01450 Systems/00203 Shop/00002 PokemonShop UI/00010 ItemList.rb', line 196

def active?
  @index == 1
end

#icon_data=(pkm_hash)

Set the item icon

Parameters:

  • pkm_hash (Hash)

    the Pokemon hash for the icon



216
217
218
219
220
221
222
# File 'scripts/01450 Systems/00203 Shop/00002 PokemonShop UI/00010 ItemList.rb', line 216

def icon_data=(pkm_hash)
  if self.visible == false
    @item_icon.set_bitmap(nil)
  else
    @item_icon.data=(PFM::Pokemon.generate_from_hash(pkm_hash))
  end
end

#price=(text)



208
209
210
211
212
# File 'scripts/01450 Systems/00203 Shop/00002 PokemonShop UI/00010 ItemList.rb', line 208

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

  @item_price.text = text[:price].to_s
end

#reset

Reset the button coordinate



225
226
227
# File 'scripts/01450 Systems/00203 Shop/00002 PokemonShop UI/00010 ItemList.rb', line 225

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/01450 Systems/00203 Shop/00002 PokemonShop UI/00010 ItemList.rb', line 202

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

  @item_name.text = text
end