Class: UI::TeamButton

Inherits:
SpriteStack show all
Defined in:
scripts/01450 Systems/00102 Party/00002 UI/02000 UI__TeamButton.rb

Overview

Button that show basic information of a Pokemon

Constant Summary collapse

CoordinatesY =

List of the Y coordinate of the button (index % 6), relative to the contents definition !

[0, 24, 64, 88, 128, 152]
CoordinatesX =

List of the X coordinate of the button (index % 2), relative to the contents definition !

[0, 160]
TextureBackgroundY =

List of the Y coordinate of the background textures

[0, 56, 112, 168]
TextureBackgroundHeight =

Height of the background texture

56

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

Create a new Team button

Parameters:

  • viewport (Viewport)

    viewport where to show the button

  • index (Integer)

    Index of the button in the team



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'scripts/01450 Systems/00102 Party/00002 UI/02000 UI__TeamButton.rb', line 21

def initialize(viewport, index)
  @index = index
  super(viewport, CoordinatesX[index % 2], CoordinatesY[index % 6])

  # Show the background
  @background = add_sprite(15, 7, background_name)
  @background.src_rect.height = TextureBackgroundHeight
  # Show the Pokemon icon sprite
  @icon = add_sprite(32, 24, NO_INITIAL_IMAGE, type: PokemonIconSprite)
  # Show the Pokemon nickname
  add_text(50, 17, 79, 16, :given_name, type: SymText, color: 9)
  # Show the Pokemon gender
  add_sprite(132, 20, NO_INITIAL_IMAGE, type: GenderSprite)
  # Show the Pokemon item hold
  add_sprite(123, 31, 'team/Item', type: HoldSprite)
  # Show the level of the Pokemon
  add_text(38, 38, 61, 16, :level_pokemon_number, type: SymText, color: 9)
  # Show the status of the Pokemon
  add_sprite(119, 46, NO_INITIAL_IMAGE, type: StatusSprite)
  # Show the HP Bar
  @hp = add_custom_sprite(create_hp_bar)
  # add_text(62, 34, 56, 16, :hp_pokemon_number, 2, type: SymText, color: 9)
  # Show the HP text with Power Small Green font
  with_font(20) do
    add_text(62, 34 + 5, 56, 13, :hp_text, 1, type: SymText, color: 9)
  end
  # Show the item button
  @item_sprite = add_sprite(24, 39, 'team/But_Object', 1, 2, type: SpriteSheet)
  # Show the Pokemon item name
  @item_text = add_text(27, 40, 113, 16, :item_name, type: SymText)
  # Hide item by default
  hide_item_name
  @selected = false
  # Position adjustment
  @x += 15
  @y += 7
end

Instance Attribute Details

#item_textSymText (readonly)

Get the Item text to perform specific operations

Returns:



6
7
8
# File 'scripts/01450 Systems/00102 Party/00002 UI/02000 UI__TeamButton.rb', line 6

def item_text
  @item_text
end

#selectedBoolean

Get the selected state of the sprite

Returns:

  • (Boolean)


17
18
19
# File 'scripts/01450 Systems/00102 Party/00002 UI/02000 UI__TeamButton.rb', line 17

def selected
  @selected
end

Instance Method Details

#data=(data)

Set the data of the SpriteStack

Parameters:



61
62
63
64
65
# File 'scripts/01450 Systems/00102 Party/00002 UI/02000 UI__TeamButton.rb', line 61

def data=(data)
  super(data)
  @item_text.visible = @item_sprite.visible
  update_background
end

#hide_item_name

Hide the item name



91
92
93
# File 'scripts/01450 Systems/00102 Party/00002 UI/02000 UI__TeamButton.rb', line 91

def hide_item_name
  @item_sprite.visible = @item_text.visible = false
end

#refresh

Refresh the button



96
97
98
# File 'scripts/01450 Systems/00102 Party/00002 UI/02000 UI__TeamButton.rb', line 96

def refresh
  self.data = @data
end

#show_item_name

Show the item name



86
87
88
# File 'scripts/01450 Systems/00102 Party/00002 UI/02000 UI__TeamButton.rb', line 86

def show_item_name
  @item_sprite.visible = @item_text.visible = true
end

#update_background

Update the background according to the selected state



68
69
70
71
72
73
74
# File 'scripts/01450 Systems/00102 Party/00002 UI/02000 UI__TeamButton.rb', line 68

def update_background
  if @data.dead?
    @background.src_rect.y = TextureBackgroundY[@selected ? 3 : 2]
  else
    @background.src_rect.y = TextureBackgroundY[@selected ? 1 : 0]
  end
end

#update_graphics

Update the graphics



101
102
103
# File 'scripts/01450 Systems/00102 Party/00002 UI/02000 UI__TeamButton.rb', line 101

def update_graphics
  @icon.update
end