Class: UI::NameInputUI

Inherits:
Window show all
Defined in:
scripts/01450 Systems/00205 Input/00002 UI/00002 NameInputUI.rb

Constant Summary collapse

NO_CHAR =

Character used to indicate there's no char there

'_'

Instance Attribute Summary collapse

Attributes inherited from LiteRGSS::Window

#__index__, #active, #back_opacity, #contents_opacity, #cursor_rect, #cursorskin, #height, #opacity, #ox, #oy, #pause, #pause_x, #pause_y, #pauseskin, #stretch, #viewport, #visible, #width, #window_builder, #windowskin, #x, #y, #z

Instance Method Summary collapse

Methods inherited from Window

#simple_mouse_in?, #translate_mouse_coords

Methods inherited from LiteRGSS::Window

#lock, #locked?, new, #set_origin, #set_position, #set_size, #unlock

Methods inherited from LiteRGSS::Disposable

#dispose, #disposed?

Constructor Details

#initialize(viewport, max_size, chars, character, phrase) ⇒ NameInputUI

Create a new NameInputUI

Parameters:

  • viewport (Viewport)
  • max_size (Integer)

    maximum size of the name

  • chars (Array<String>)

    chars initialize there

  • character (PFM::Pokemon, String, nil)

    the character to display

  • phrase (String)

    the phrase to display in order to justify the name input



14
15
16
17
18
19
20
21
22
23
# File 'scripts/01450 Systems/00205 Input/00002 UI/00002 NameInputUI.rb', line 14

def initialize(viewport, max_size, chars, character, phrase)
  super(viewport, *window_parameters, skin: default_windowskin)
  @character = character
  @phrase = phrase
  @chars = chars
  @index = 0
  @max_size = max_size
  create_graphics
  @counter = 0
end

Instance Attribute Details

#charsArray<String> (readonly)

Return the chars the user has inserted

Returns:



5
6
7
# File 'scripts/01450 Systems/00205 Input/00002 UI/00002 NameInputUI.rb', line 5

def chars
  @chars
end

Instance Method Details

#add_char(char)



25
26
27
28
29
# File 'scripts/01450 Systems/00205 Input/00002 UI/00002 NameInputUI.rb', line 25

def add_char(char)
  return if @chars.size >= @max_size
  @chars.push(char)
  refresh_chars
end

#remove_char



31
32
33
34
# File 'scripts/01450 Systems/00205 Input/00002 UI/00002 NameInputUI.rb', line 31

def remove_char
  @chars.pop
  refresh_chars
end

#update



36
37
38
39
40
41
42
43
44
45
# File 'scripts/01450 Systems/00205 Input/00002 UI/00002 NameInputUI.rb', line 36

def update
  @counter += 1
  if @counter == 30
    @inputs[@chars.size]&.visible = false
  elsif @counter == 60
    @inputs[@chars.size]&.visible = true
    @counter = 0
  end
  @character_sprite&.update
end