Class: UI::InputNumber
- Inherits:
-
SpriteStack
- Object
- SpriteStack
- UI::InputNumber
- Defined in:
- scripts/01450 Systems/00205 Input/00002 UI/00100 NumberInput.rb
Overview
UI element showing input number (for number choice & selling)
Constant Summary collapse
- IMAGE_SOURCE =
Image used as source for the UI build
'numin_bg'
- IMAGE_COMPOSITION =
List of coordinates used to know how to build the UI from the image
{ left: [0, 0, 33, 44], number: [33, 0, 24, 44], separator: [57, 0, 6, 44], right: [83, 0, 10, 44], money_add: [94, 0, 68, 44] }
- MONEY_PADDING =
Padding for money text
2
Constants inherited from SpriteStack
Instance Attribute Summary collapse
-
#max ⇒ Integer
Maximum value.
-
#min ⇒ Integer
Minimum value.
-
#number ⇒ Integer
Currently inputed number.
Attributes inherited from SpriteStack
#animated, #data, #moving, #stack, #viewport, #x, #y
Instance Method Summary collapse
-
#height ⇒ Integer
Get the height of the UI.
-
#initialize(viewport, max_digits, default_number = 0, accept_negatives = false) ⇒ InputNumber
constructor
Create a new Input number.
-
#update
Update the UI element.
-
#width ⇒ Integer
Get the width of the UI.
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_animation, #update_position, #visible, #visible=, #with_cache, #with_font, #with_surface, #z, #z=
Constructor Details
#initialize(viewport, max_digits, default_number = 0, accept_negatives = false) ⇒ InputNumber
Create a new Input number
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'scripts/01450 Systems/00205 Input/00002 UI/00100 NumberInput.rb', line 31 def initialize(, max_digits, default_number = 0, accept_negatives = false) super() @max_digits = max_digits @accept_negatives = accept_negatives @digit_index = 0 @max = (10**@max_digits) - 1 @min = accept_negatives ? -@max : 0 # @type [Array<Sprite>] @width_accounting_sprites = [] # @type [Array<Text>] @texts = [] create_sprites self.number = default_number @default_number = @number end |
Instance Attribute Details
#max ⇒ Integer
Maximum value
21 22 23 |
# File 'scripts/01450 Systems/00205 Input/00002 UI/00100 NumberInput.rb', line 21 def max @max end |
#min ⇒ Integer
Minimum value
18 19 20 |
# File 'scripts/01450 Systems/00205 Input/00002 UI/00100 NumberInput.rb', line 18 def min @min end |
#number ⇒ Integer
Currently inputed number
24 25 26 |
# File 'scripts/01450 Systems/00205 Input/00002 UI/00100 NumberInput.rb', line 24 def number @number end |
Instance Method Details
#height ⇒ Integer
Get the height of the UI
80 81 82 |
# File 'scripts/01450 Systems/00205 Input/00002 UI/00100 NumberInput.rb', line 80 def height @stack.first&.height || 0 end |
#update
Update the UI element
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'scripts/01450 Systems/00205 Input/00002 UI/00100 NumberInput.rb', line 48 def update if Input.repeat?(:DOWN) self.number -= 10**@digit_index elsif Input.repeat?(:UP) self.number += 10**@digit_index elsif Input.trigger?(:LEFT) @digit_index = (@digit_index + 1).clamp(0, @max_digits - 1) elsif Input.trigger?(:RIGHT) @digit_index = (@digit_index - 1).clamp(0, @max_digits - 1) elsif Input.trigger?(:B) self.number = @default_number else return # Prevent useless drawing end draw_digits end |
#width ⇒ Integer
Get the width of the UI
74 75 76 |
# File 'scripts/01450 Systems/00205 Input/00002 UI/00100 NumberInput.rb', line 74 def width @width_accounting_sprites.map(&:width).reduce(0, :+) end |