Class: UI::Bar

Inherits:
Object show all
Defined in:
scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb

Overview

Class that display a bar on screen using the whole texture to display the bar component

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(viewport, x, y, bmp, bw, bh, bx, by, nb_states, background_width = nil) ⇒ Bar

Create a new bar

Parameters:

  • viewport (Viewport)

    the viewport in which the bar is shown

  • x (Integer)

    the x position of the bar

  • y (Integer)

    the y position of the bar

  • bmp (Texture)

    the texture of the bar (including the bar states)

  • bw (Integer)

    the bar width (progress part)

  • bh (Integer)

    the bar height (progress part)

  • bx (Integer)

    the x position of the bar inside the sprite

  • by (Integer)

    the y position of the bar inside the sprite

  • nb_states (Integer)

    the number of state the bar has

  • background_width (Integer) (defaults to: nil)

    the bar width (background part). Useful if the bar has a different width than its real image



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 20

def initialize(viewport, x, y, bmp, bw, bh, bx, by, nb_states, background_width = nil)
  @background = Sprite.new(viewport).set_bitmap(bmp)
  @background.src_rect.set(0, 0, background_width, bmp.height - nb_states * bh)
  @bar = Sprite.new(viewport).set_bitmap(bmp)
  @bar.src_rect.set(0, @background.src_rect.height, 0, @bh = bh)
  @nb_states = nb_states
  @bx = bx
  @by = by
  @bw = bw
  @bar.x = (@background.x = x) + bx
  @bar.y = (@background.y = y) + by
  @rate = 0
  @data_source = nil
end

Instance Attribute Details

#data_source

Return the data source to get the rate info through data=



8
9
10
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 8

def data_source
  @data_source
end

#rateNumeric

Returns the rate of the bar

Returns:

  • (Numeric)

    0 ~ 1



6
7
8
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 6

def rate
  @rate
end

Instance Method Details

#data=(data)

Change the data value (for SpriteStack usage)

Parameters:

  • data (Object)

    the data where we'll call the @data_source to get the actual rate



115
116
117
118
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 115

def data=(data)
  return unless @data_source
  self.rate = data.send(*@data_source) if (self.visible = data)
end

#dispose

Dispose the bar



108
109
110
111
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 108

def dispose
  @background.dispose
  @bar.dispose
end

#set_position(x, y)

Change the position of the bar

Parameters:



89
90
91
92
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 89

def set_position(x, y)
  @background.set_position(x, y)
  @bar.set_position(x + @bx, y + @by)
end

#visibleBoolean

Returns the visible state of the bar

Returns:

  • (Boolean)


56
57
58
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 56

def visible
  return @bar.visible
end

#visible=(value)

Change the visible state of the bar

Parameters:

  • value (Boolean)


50
51
52
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 50

def visible=(value)
  @bar.visible = @background.visible = value
end

#xInteger

Returns the x position of the bar

Returns:



62
63
64
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 62

def x
  return @background.x
end

#x=(value)

Change the x position of the bar

Parameters:



74
75
76
77
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 74

def x=(value)
  @background.x = value
  @bar.x = value + @bx
end

#yInteger

Returns the y position of the bar

Returns:



68
69
70
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 68

def y
  return @background.y
end

#y=(value)

Change the y position of the bar

Parameters:



81
82
83
84
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 81

def y=(value)
  @background.y = value
  @bar.y = value + @by
end

#zInteger

Returns the z position of the bar

Returns:



96
97
98
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 96

def z
  return @background.z
end

#z=(value)

Change the z position of the bar

Parameters:

  • value (Numeric)


102
103
104
105
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00300 Bar.rb', line 102

def z=(value)
  @background.z = value
  @bar.z = value
end