Class: Window_Message

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

Overview

** Window_Message


This message window is used to display text.

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, #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, #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

#initializeWindow_Message


  • Object Initialization




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

def initialize
  super(0, 0, window_width, window_height)
  self.z = 200
  self.openness = 0
  create_all_windows
  create_back_bitmap
  create_back_sprite
  clear_instance_variables
end

Instance Method Details

#all_close?Boolean


  • Determine if All Windows Are Fully Closed


Returns:

  • (Boolean)


245
246
247
248
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 245

def all_close?
  close? && @choice_window.close? &&
  @number_window.close? && @item_window.close?
end

#back_color1Object


  • Get Background Color 1




113
114
115
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 113

def back_color1
  Color.new(0, 0, 0, 160)
end

#back_color2Object


  • Get Background Color 2




119
120
121
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 119

def back_color2
  Color.new(0, 0, 0, 0)
end

#clear_flagsObject


  • Clear Flag




44
45
46
47
48
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 44

def clear_flags
  @show_fast = false          # Fast forward flag
  @line_show_fast = false     # Fast forward by line flag
  @pause_skip = false         # Input standby omission flag
end

#clear_instance_variablesObject


  • Clear Instance Variables




35
36
37
38
39
40
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 35

def clear_instance_variables
  @fiber = nil                # Fiber
  @background = 0             # Background type
  @position = 2               # Display position
  clear_flags
end

#close_and_waitObject


  • Close Window and Wait for It to Fully Close




238
239
240
241
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 238

def close_and_wait
  close
  Fiber.yield until all_close?
end

#create_all_windowsObject


  • Create All Windows




89
90
91
92
93
94
95
96
97
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 89

def create_all_windows
  @gold_window = Window_Gold.new
  @gold_window.x = Graphics.width - @gold_window.width
  @gold_window.y = 0
  @gold_window.openness = 0
  @choice_window = Window_ChoiceList.new(self)
  @number_window = Window_NumberInput.new(self)
  @item_window = Window_KeyItem.new(self)
end

#create_back_bitmapObject


  • Create Background Bitmap




101
102
103
104
105
106
107
108
109
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 101

def create_back_bitmap
  @back_bitmap = Bitmap.new(width, height)
  rect1 = Rect.new(0, 0, width, 12)
  rect2 = Rect.new(0, 12, width, height - 24)
  rect3 = Rect.new(0, height - 12, width, 12)
  @back_bitmap.gradient_fill_rect(rect1, back_color2, back_color1, true)
  @back_bitmap.fill_rect(rect2, back_color1)
  @back_bitmap.gradient_fill_rect(rect3, back_color1, back_color2, true)
end

#create_back_spriteObject


  • Create Background Sprite




125
126
127
128
129
130
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 125

def create_back_sprite
  @back_sprite = Sprite.new
  @back_sprite.bitmap = @back_bitmap
  @back_sprite.visible = false
  @back_sprite.z = z - 1
end

#disposeObject


  • Free




58
59
60
61
62
63
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 58

def dispose
  super
  dispose_all_windows
  dispose_back_bitmap
  dispose_back_sprite
end

#dispose_all_windowsObject


  • Free All Windows




134
135
136
137
138
139
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 134

def dispose_all_windows
  @gold_window.dispose
  @choice_window.dispose
  @number_window.dispose
  @item_window.dispose
end

#dispose_back_bitmapObject


  • Free Background Bitmap




143
144
145
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 143

def dispose_back_bitmap
  @back_bitmap.dispose
end

#dispose_back_spriteObject


  • Free Background Sprite




149
150
151
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 149

def dispose_back_sprite
  @back_sprite.dispose
end

#fiber_mainObject


  • Main Processing of Fiber




173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 173

def fiber_main
  $game_message.visible = true
  update_background
  update_placement
  loop do
    process_all_text if $game_message.has_text?
    process_input
    $game_message.clear
    @gold_window.close
    Fiber.yield
    break unless text_continue?
  end
  close_and_wait
  $game_message.visible = false
  @fiber = nil
end

#input_choiceObject


  • Choice Input Processing




379
380
381
382
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 379

def input_choice
  @choice_window.start
  Fiber.yield while @choice_window.active
end

#input_itemObject


  • Item Selection Processing




393
394
395
396
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 393

def input_item
  @item_window.start
  Fiber.yield while @item_window.active
end

#input_numberObject


  • Number Input Processing




386
387
388
389
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 386

def input_number
  @number_window.start
  Fiber.yield while @number_window.active
end

#input_pauseObject


  • Input Pause Processing




369
370
371
372
373
374
375
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 369

def input_pause
  self.pause = true
  wait(10)
  Fiber.yield until Input.trigger?(:B) || Input.trigger?(:C)
  Input.update
  self.pause = false
end

#need_new_page?(text, pos) ⇒ Boolean


  • Determine if New Page Is Needed


Returns:

  • (Boolean)


321
322
323
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 321

def need_new_page?(text, pos)
  pos[:y] + pos[:height] > contents.height && !text.empty?
end

#new_line_xObject


  • Get New Line Position




297
298
299
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 297

def new_line_x
  $game_message.face_name.empty? ? 0 : 112
end

#new_page(text, pos) ⇒ Object


  • New Page




284
285
286
287
288
289
290
291
292
293
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 284

def new_page(text, pos)
  contents.clear
  draw_face($game_message.face_name, $game_message.face_index, 0, 0)
  reset_font_settings
  pos[:x] = new_line_x
  pos[:y] = 0
  pos[:new_x] = new_line_x
  pos[:height] = calc_line_height(text)
  clear_flags
end

#open_and_waitObject


  • Open Window and Wait for It to Fully Open




231
232
233
234
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 231

def open_and_wait
  open
  Fiber.yield until open?
end

#process_all_textObject


  • Process All Text




207
208
209
210
211
212
213
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 207

def process_all_text
  open_and_wait
  text = convert_escape_characters($game_message.all_text)
  pos = {}
  new_page(text, pos)
  process_character(text.slice!(0, 1), text, pos) until text.empty?
end

#process_draw_icon(icon_index, pos) ⇒ Object


  • Icon Drawing Process by Control Characters




335
336
337
338
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 335

def process_draw_icon(icon_index, pos)
  super
  wait_for_one_character
end

#process_escape_character(code, text, pos) ⇒ Object


  • Control Character Processing

    code : the core of the control character
           e.g. "C" in the case of the control character \C[1].
    text : character string buffer in drawing processing (destructive)
    pos  : draw position {:x, :y, :new_x, :height}
    



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 346

def process_escape_character(code, text, pos)
  case code.upcase
  when '$'
    @gold_window.open
  when '.'
    wait(15)
  when '|'
    wait(60)
  when '!'
    input_pause
  when '>'
    @line_show_fast = true
  when '<'
    @line_show_fast = false
  when '^'
    @pause_skip = true
  else
    super
  end
end

#process_inputObject


  • Input Processing




217
218
219
220
221
222
223
224
225
226
227
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 217

def process_input
  if $game_message.choice?
    input_choice
  elsif $game_message.num_input?
    input_number
  elsif $game_message.item_choice?
    input_item
  else
    input_pause unless @pause_skip
  end
end

#process_new_line(text, pos) ⇒ Object


  • New Line Character Processing




310
311
312
313
314
315
316
317
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 310

def process_new_line(text, pos)
  @line_show_fast = false
  super
  if need_new_page?(text, pos)
    input_pause
    new_page(text, pos)
  end
end

#process_new_page(text, pos) ⇒ Object


  • New Page Character Processing




327
328
329
330
331
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 327

def process_new_page(text, pos)
  text.slice!(/^\n/)
  input_pause
  new_page(text, pos)
end

#process_normal_character(c, pos) ⇒ Object


  • Normal Character Processing




303
304
305
306
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 303

def process_normal_character(c, pos)
  super
  wait_for_one_character
end

#settings_changed?Boolean


  • Determine if Background and Position Changed


Returns:

  • (Boolean)


258
259
260
261
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 258

def settings_changed?
  @background != $game_message.background ||
  @position != $game_message.position
end

#text_continue?Boolean


  • Determine Whether to Continue Displaying Text


Returns:

  • (Boolean)


252
253
254
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 252

def text_continue?
  $game_message.has_text? && !settings_changed?
end

#updateObject


  • Frame Update




67
68
69
70
71
72
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 67

def update
  super
  update_all_windows
  update_back_sprite
  update_fiber
end

#update_all_windowsObject


  • Update All Windows




155
156
157
158
159
160
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 155

def update_all_windows
  @gold_window.update
  @choice_window.update
  @number_window.update
  @item_window.update
end

#update_back_spriteObject


  • Update Background Sprite




164
165
166
167
168
169
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 164

def update_back_sprite
  @back_sprite.visible = (@background == 1)
  @back_sprite.y = y
  @back_sprite.opacity = openness
  @back_sprite.update
end

#update_backgroundObject


  • Update Window Background




192
193
194
195
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 192

def update_background
  @background = $game_message.background
  self.opacity = @background == 0 ? 255 : 0
end

#update_fiberObject


  • Update Fiber




76
77
78
79
80
81
82
83
84
85
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 76

def update_fiber
  if @fiber
    @fiber.resume
  elsif $game_message.busy? && !$game_message.scroll_mode
    @fiber = Fiber.new { fiber_main }
    @fiber.resume
  else
    $game_message.visible = false
  end
end

#update_placementObject


  • Update Window Position




199
200
201
202
203
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 199

def update_placement
  @position = $game_message.position
  self.y = @position * (Graphics.height - height) / 2
  @gold_window.y = y > 0 ? 0 : Graphics.height - @gold_window.height
end

#update_show_fastObject


  • Update Fast Forward Flag




271
272
273
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 271

def update_show_fast
  @show_fast = true if Input.trigger?(:C)
end

#visible_line_numberObject


  • Get Number of Lines to Show




52
53
54
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 52

def visible_line_number
  return 4
end

#wait(duration) ⇒ Object


  • Wait




265
266
267
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 265

def wait(duration)
  duration.times { Fiber.yield }
end

#wait_for_one_characterObject


  • Wait After Output of One Character




277
278
279
280
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 277

def wait_for_one_character
  update_show_fast
  Fiber.yield unless @show_fast || @line_show_fast
end

#window_heightObject


  • Get Window Height




29
30
31
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 29

def window_height
  fitting_height(visible_line_number)
end

#window_widthObject


  • Get Window Width




23
24
25
# File 'lib/rgss3_default_scripts/Window_Message.rb', line 23

def window_width
  Graphics.width
end