Class: Core::GUI::CharSelector

Inherits:
Element show all
Defined in:
lib/gui/char_selector.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#h, #w, #x, #xoff, #y, #yoff, #zoff

Instance Method Summary collapse

Methods inherited from Element

#remove?

Constructor Details

#initialize(x, y, party, w = 256, h = 32) ⇒ CharSelector

Returns a new instance of CharSelector.



8
9
10
11
12
13
14
15
16
17
# File 'lib/gui/char_selector.rb', line 8

def initialize(x, y, party, w=256, h=32)
  super(x, y, w, h)
  @index = 0
  @changed = false
  @party = party
  @background = Core.sprite("gui/charselect_background")
  @font = Core.font(Core::DEFAULT_FONT, 24)
  @left = Button.new(x, y, 32, 32, "<", lambda {left}, false)
  @right = Button.new(x+w-32, y, 32, 32, ">", lambda {right}, false)
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



7
8
9
# File 'lib/gui/char_selector.rb', line 7

def index
  @index
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
# File 'lib/gui/char_selector.rb', line 38

def changed?
  if @changed
    @changed = false
    return true
  else
    return false
  end
end

#drawObject



46
47
48
49
50
51
# File 'lib/gui/char_selector.rb', line 46

def draw
  @background.draw(@x+@xoff, @y+@yoff, Core::GUI_Z + 9, @w/@background.width, @h/@background.height)
  @font.draw(@party.members[@index].name, @x+@xoff+(@w/2)-(@font.text_width(@party.members[@index].name)/2), @y+@yoff+(@h/6), Core::GUI_Z + 10, 1, 1, Gosu::Color::BLACK)
  @left.draw
  @right.draw
end

#leftObject



24
25
26
27
28
29
30
# File 'lib/gui/char_selector.rb', line 24

def left
  @index -= 1
  if @index < 0
    @index = @party.members.size-1
  end
  @changed = true
end

#rightObject



31
32
33
34
35
36
37
# File 'lib/gui/char_selector.rb', line 31

def right
  @index += 1
  if @index >= @party.members.size
    @index = 0
  end
  @changed = true
end

#updateObject



18
19
20
21
22
23
# File 'lib/gui/char_selector.rb', line 18

def update
  @left.xoff = @right.xoff = @xoff
  @left.yoff = @right.yoff = @yoff
  @left.update
  @right.update
end