Class: Window_NumberInput

Inherits:
Window_Base show all
Defined in:
lib/rgss3_default_scripts/Window_NumberInput.rb

Overview

** Window_NumberInput


This window is used for the event command [Input Number].

Instance Method Summary collapse

Methods inherited from Window_Base

#activate, #actor_name, #calc_line_height, #change_color, #close, #contents_height, #contents_width, #convert_escape_characters, #create_contents, #crisis_color, #deactivate, #dispose, #draw_actor_class, #draw_actor_face, #draw_actor_graphic, #draw_actor_hp, #draw_actor_icons, #draw_actor_level, #draw_actor_mp, #draw_actor_name, #draw_actor_nickname, #draw_actor_param, #draw_actor_simple_status, #draw_actor_tp, #draw_character, #draw_currency_value, #draw_current_and_max_values, #draw_face, #draw_gauge, #draw_icon, #draw_item_name, #draw_text, #draw_text_ex, #fitting_height, #gauge_back_color, #hide, #hp_color, #hp_gauge_color1, #hp_gauge_color2, #knockout_color, #line_height, #make_font_bigger, #make_font_smaller, #mp_color, #mp_cost_color, #mp_gauge_color1, #mp_gauge_color2, #normal_color, #obtain_escape_code, #obtain_escape_param, #open, #param_change_color, #party_member_name, #pending_color, #power_down_color, #power_up_color, #process_character, #process_draw_icon, #process_escape_character, #process_new_line, #process_new_page, #process_normal_character, #reset_font_settings, #show, #standard_padding, #system_color, #text_color, #text_size, #tp_color, #tp_cost_color, #tp_gauge_color1, #tp_gauge_color2, #translucent_alpha, #update_close, #update_open, #update_padding, #update_tone

Constructor Details

#initialize(message_window) ⇒ Window_NumberInput


  • Object Initialization




11
12
13
14
15
16
17
18
19
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 11

def initialize(message_window)
  @message_window = message_window
  super(0, 0, 0, 0)
  @number = 0
  @digits_max = 1
  @index = 0
  self.openness = 0
  deactivate
end

Instance Method Details

#cursor_left(wrap) ⇒ Object


  • Move Cursor Left

    wrap : Wraparound allowed
    



60
61
62
63
64
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 60

def cursor_left(wrap)
  if @index > 0 || wrap
    @index = (@index + @digits_max - 1) % @digits_max
  end
end

#cursor_right(wrap) ⇒ Object


  • Move Cursor Right

    wrap : Wraparound allowed
    



51
52
53
54
55
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 51

def cursor_right(wrap)
  if @index < @digits_max - 1 || wrap
    @index = (@index + 1) % @digits_max
  end
end

#item_rect(index) ⇒ Object


  • Get Rectangle for Displaying Item




126
127
128
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 126

def item_rect(index)
  Rect.new(index * 20, 0, 20, line_height)
end

#process_cancelObject


  • Processing When Cancel Button Is Pressed




121
122
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 121

def process_cancel
end

#process_cursor_moveObject


  • Cursor Movement Processing




78
79
80
81
82
83
84
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 78

def process_cursor_move
  return unless active
  last_index = @index
  cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
  cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
  Sound.play_cursor if @index != last_index
end

#process_digit_changeObject


  • Change Processing for Digits




88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 88

def process_digit_change
  return unless active
  if Input.repeat?(:UP) || Input.repeat?(:DOWN)
    Sound.play_cursor
    place = 10 ** (@digits_max - 1 - @index)
    n = @number / place % 10
    @number -= n * place
    n = (n + 1) % 10 if Input.repeat?(:UP)
    n = (n + 9) % 10 if Input.repeat?(:DOWN)
    @number += n * place
    refresh
  end
end

#process_handlingObject


  • Handling Processing for OK and Cancel




104
105
106
107
108
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 104

def process_handling
  return unless active
  return process_ok     if Input.trigger?(:C)
  return process_cancel if Input.trigger?(:B)
end

#process_okObject


  • Processing When OK Button Is Pressed




112
113
114
115
116
117
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 112

def process_ok
  Sound.play_ok
  $game_variables[$game_message.num_input_variable_id] = @number
  deactivate
  close
end

#refreshObject


  • Refresh




132
133
134
135
136
137
138
139
140
141
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 132

def refresh
  contents.clear
  change_color(normal_color)
  s = sprintf("%0*d", @digits_max, @number)
  @digits_max.times do |i|
    rect = item_rect(i)
    rect.x += 1
    draw_text(rect, s[i,1], 1)
  end
end

#startObject


  • Start Input Processing




23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 23

def start
  @digits_max = $game_message.num_input_digits_max
  @number = $game_variables[$game_message.num_input_variable_id]
  @number = [[@number, 0].max, 10 ** @digits_max - 1].min
  @index = 0
  update_placement
  create_contents
  refresh
  open
  activate
end

#updateObject


  • Frame Update




68
69
70
71
72
73
74
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 68

def update
  super
  process_cursor_move
  process_digit_change
  process_handling
  update_cursor
end

#update_cursorObject


  • Update Cursor




145
146
147
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 145

def update_cursor
  cursor_rect.set(item_rect(@index))
end

#update_placementObject


  • Update Window Position




37
38
39
40
41
42
43
44
45
46
# File 'lib/rgss3_default_scripts/Window_NumberInput.rb', line 37

def update_placement
  self.width = @digits_max * 20 + padding * 2
  self.height = fitting_height(1)
  self.x = (Graphics.width - width) / 2
  if @message_window.y >= Graphics.height / 2
    self.y = @message_window.y - height - 8
  else
    self.y = @message_window.y + @message_window.height + 8
  end
end