Class: Window_Base

Inherits:
Window
  • Object
show all
Defined in:
Window_Base.rb

Overview

** Window_Base


This is a super class of all windows within the game.

Direct Known Subclasses

Window_EquipStatus, Window_Gold, Window_Help, Window_MapName, Window_Message, Window_NameEdit, Window_NumberInput, Window_SaveFile, Window_ScrollText, Window_Selectable, Window_ShopStatus, Window_SkillStatus

Instance Method Summary (collapse)

Constructor Details

- (Window_Base) initialize(x, y, width, height)


  • Object Initialization




11
12
13
14
15
16
17
18
19
20
# File 'Window_Base.rb', line 11

def initialize(x, y, width, height)
  super
  self.windowskin = Cache.system("Window")
  # self.back_opacity = 200
  # self.openness = 255
  update_padding
  update_tone
  create_contents
  @opening = @closing = false
end

Instance Method Details

- (Object) activate


  • Activate Window




137
138
139
140
# File 'Window_Base.rb', line 137

def activate
  self.active = true
  self
end

- (Object) actor_name(n)


  • Get Name of Actor Number n




244
245
246
247
# File 'Window_Base.rb', line 244

def actor_name(n)
  actor = n >= 1 ? $game_actors[n] : nil
  actor ? actor.name : ""
end

- (Object) calc_line_height(text, restore_font_size = true)


  • Calculate Line Height

    restore_font_size : Return to original font size after calculating



346
347
348
349
350
351
352
353
354
355
356
# File 'Window_Base.rb', line 346

def calc_line_height(text, restore_font_size = true)
  result = [line_height, contents.font.size].max
  last_font_size = contents.font.size
  text.slice(/^.*$/).scan(/\e[\{\}]/).each do |esc|
    make_font_bigger  if esc == "\e{"
    make_font_smaller if esc == "\e}"
    result = [result, contents.font.size].max
  end
  contents.font.size = last_font_size if restore_font_size
  result
end

- (Object) change_color(color, enabled = true)


  • Change Text Drawing Color

    enabled : Enabled flag. When false, draw semi-transparently.



189
190
191
192
# File 'Window_Base.rb', line 189

def change_color(color, enabled = true)
  contents.font.color.set(color)
  contents.font.color.alpha = translucent_alpha unless enabled
end

- (Object) close


  • Close Window




115
116
117
118
119
# File 'Window_Base.rb', line 115

def close
  @closing = true unless close?
  @opening = false
  self
end

- (Object) contents_height


  • Calculate Height of Window Contents




55
56
57
# File 'Window_Base.rb', line 55

def contents_height
  height - standard_padding * 2
end

- (Object) contents_width


  • Calculate Width of Window Contents




49
50
51
# File 'Window_Base.rb', line 49

def contents_width
  width - standard_padding * 2
end

- (Object) convert_escape_characters(text)


  • Preconvert Control Characters

    As a rule, replace only what will be changed into text strings before
    starting actual drawing. The character "\" is replaced with the escape
    character (\e).



230
231
232
233
234
235
236
237
238
239
240
# File 'Window_Base.rb', line 230

def convert_escape_characters(text)
  result = text.to_s.clone
  result.gsub!(/\\/)            { "\e" }
  result.gsub!(/\e\e/)          { "\\" }
  result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i) }
  result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
  result.gsub!(/\eG/i)          { Vocab::currency_unit }
  result
end

- (Object) create_contents


  • Create Window Contents




73
74
75
76
77
78
79
80
# File 'Window_Base.rb', line 73

def create_contents
  contents.dispose
  if contents_width > 0 && contents_height > 0
    self.contents = Bitmap.new(contents_width, contents_height)
  else
    self.contents = Bitmap.new(1, 1)
  end
end

- (Object) crisis_color

Crisis



160
# File 'Window_Base.rb', line 160

def crisis_color;      text_color(17);  end

- (Object) deactivate


  • Deactivate Window




144
145
146
147
# File 'Window_Base.rb', line 144

def deactivate
  self.active = false
  self
end

- (Object) dispose


  • Free




24
25
26
27
# File 'Window_Base.rb', line 24

def dispose
  contents.dispose unless disposed?
  super
end

- (Object) draw_actor_class(actor, x, y, width = 112)


  • Draw Class




449
450
451
452
# File 'Window_Base.rb', line 449

def draw_actor_class(actor, x, y, width = 112)
  change_color(normal_color)
  draw_text(x, y, width, line_height, actor.class.name)
end

- (Object) draw_actor_face(actor, x, y, enabled = true)


  • Draw Actor Face Graphic




436
437
438
# File 'Window_Base.rb', line 436

def draw_actor_face(actor, x, y, enabled = true)
  draw_face(actor.face_name, actor.face_index, x, y, enabled)
end

- (Object) draw_actor_graphic(actor, x, y)


  • Draw Actor Walking Graphic




430
431
432
# File 'Window_Base.rb', line 430

def draw_actor_graphic(actor, x, y)
  draw_character(actor.character_name, actor.character_index, x, y)
end

- (Object) draw_actor_hp(actor, x, y, width = 124)


  • Draw HP




498
499
500
501
502
503
504
# File 'Window_Base.rb', line 498

def draw_actor_hp(actor, x, y, width = 124)
  draw_gauge(x, y, width, actor.hp_rate, hp_gauge_color1, hp_gauge_color2)
  change_color(system_color)
  draw_text(x, y, 30, line_height, Vocab::hp_a)
  draw_current_and_max_values(x, y, width, actor.hp, actor.mhp,
    hp_color(actor), normal_color)
end

- (Object) draw_actor_icons(actor, x, y, width = 96)


  • Draw State and Buff/Debuff Icons




472
473
474
475
# File 'Window_Base.rb', line 472

def draw_actor_icons(actor, x, y, width = 96)
  icons = (actor.state_icons + actor.buff_icons)[0, width / 24]
  icons.each_with_index {|n, i| draw_icon(n, x + 24 * i, y) }
end

- (Object) draw_actor_level(actor, x, y)


  • Draw Level




463
464
465
466
467
468
# File 'Window_Base.rb', line 463

def draw_actor_level(actor, x, y)
  change_color(system_color)
  draw_text(x, y, 32, line_height, Vocab::level_a)
  change_color(normal_color)
  draw_text(x + 32, y, 24, line_height, actor.level, 2)
end

- (Object) draw_actor_mp(actor, x, y, width = 124)


  • Draw MP




508
509
510
511
512
513
514
# File 'Window_Base.rb', line 508

def draw_actor_mp(actor, x, y, width = 124)
  draw_gauge(x, y, width, actor.mp_rate, mp_gauge_color1, mp_gauge_color2)
  change_color(system_color)
  draw_text(x, y, 30, line_height, Vocab::mp_a)
  draw_current_and_max_values(x, y, width, actor.mp, actor.mmp,
    mp_color(actor), normal_color)
end

- (Object) draw_actor_name(actor, x, y, width = 112)


  • Draw Name




442
443
444
445
# File 'Window_Base.rb', line 442

def draw_actor_name(actor, x, y, width = 112)
  change_color(hp_color(actor))
  draw_text(x, y, width, line_height, actor.name)
end

- (Object) draw_actor_nickname(actor, x, y, width = 180)


  • Draw Nickname




456
457
458
459
# File 'Window_Base.rb', line 456

def draw_actor_nickname(actor, x, y, width = 180)
  change_color(normal_color)
  draw_text(x, y, width, line_height, actor.nickname)
end

- (Object) draw_actor_param(actor, x, y, param_id)


  • Draw Parameters




539
540
541
542
543
544
# File 'Window_Base.rb', line 539

def draw_actor_param(actor, x, y, param_id)
  change_color(system_color)
  draw_text(x, y, 120, line_height, Vocab::param(param_id))
  change_color(normal_color)
  draw_text(x + 120, y, 36, line_height, actor.param(param_id), 2)
end

- (Object) draw_actor_simple_status(actor, x, y)


  • Draw Simple Status




528
529
530
531
532
533
534
535
# File 'Window_Base.rb', line 528

def draw_actor_simple_status(actor, x, y)
  draw_actor_name(actor, x, y)
  draw_actor_level(actor, x, y + line_height * 1)
  draw_actor_icons(actor, x, y + line_height * 2)
  draw_actor_class(actor, x + 120, y)
  draw_actor_hp(actor, x + 120, y + line_height * 1)
  draw_actor_mp(actor, x + 120, y + line_height * 2)
end

- (Object) draw_actor_tp(actor, x, y, width = 124)


  • Draw TP




518
519
520
521
522
523
524
# File 'Window_Base.rb', line 518

def draw_actor_tp(actor, x, y, width = 124)
  draw_gauge(x, y, width, actor.tp_rate, tp_gauge_color1, tp_gauge_color2)
  change_color(system_color)
  draw_text(x, y, 30, line_height, Vocab::tp_a)
  change_color(tp_color(actor))
  draw_text(x + width - 42, y, 42, line_height, actor.tp.to_i, 2)
end

- (Object) draw_character(character_name, character_index, x, y)


  • Draw Character Graphic




391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'Window_Base.rb', line 391

def draw_character(character_name, character_index, x, y)
  return unless character_name
  bitmap = Cache.character(character_name)
  sign = character_name[/^[\!\$]./]
  if sign && sign.include?('$')
    cw = bitmap.width / 3
    ch = bitmap.height / 4
  else
    cw = bitmap.width / 12
    ch = bitmap.height / 8
  end
  n = character_index
  src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
end

- (Object) draw_currency_value(value, unit, x, y, width)


  • Draw Number (Gold Etc.) with Currency Unit




558
559
560
561
562
563
564
# File 'Window_Base.rb', line 558

def draw_currency_value(value, unit, x, y, width)
  cx = text_size(unit).width
  change_color(normal_color)
  draw_text(x, y, width - cx - 2, line_height, value, 2)
  change_color(system_color)
  draw_text(x, y, width, line_height, unit, 2)
end

- (Object) draw_current_and_max_values(x, y, width, current, max, color1, color2)


  • Draw Current Value/Maximum Value in Fractional Format

    current : Current value
    max     : Maximum value
    color1  : Color of current value
    color2  : Color of maximum value



483
484
485
486
487
488
489
490
491
492
493
494
# File 'Window_Base.rb', line 483

def draw_current_and_max_values(x, y, width, current, max, color1, color2)
  change_color(color1)
  xr = x + width
  if width < 96
    draw_text(xr - 40, y, 42, line_height, current, 2)
  else
    draw_text(xr - 92, y, 42, line_height, current, 2)
    change_color(color2)
    draw_text(xr - 52, y, 12, line_height, "/", 2)
    draw_text(xr - 42, y, 42, line_height, max, 2)
  end
end

- (Object) draw_face(face_name, face_index, x, y, enabled = true)


  • Draw Face Graphic

    enabled : Enabled flag. When false, draw semi-transparently.



382
383
384
385
386
387
# File 'Window_Base.rb', line 382

def draw_face(face_name, face_index, x, y, enabled = true)
  bitmap = Cache.face(face_name)
  rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
  contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  bitmap.dispose
end

- (Object) draw_gauge(x, y, width, rate, color1, color2)


  • Draw Gauge

    rate   : Rate (full at 1.0)
    color1 : Left side gradation
    color2 : Right side gradation



363
364
365
366
367
368
# File 'Window_Base.rb', line 363

def draw_gauge(x, y, width, rate, color1, color2)
  fill_w = (width * rate).to_i
  gauge_y = y + line_height - 8
  contents.fill_rect(x, gauge_y, width, 6, gauge_back_color)
  contents.gradient_fill_rect(x, gauge_y, fill_w, 6, color1, color2)
end

- (Object) draw_icon(icon_index, x, y, enabled = true)


  • Draw Icon

    enabled : Enabled flag. When false, draw semi-transparently.



373
374
375
376
377
# File 'Window_Base.rb', line 373

def draw_icon(icon_index, x, y, enabled = true)
  bitmap = Cache.system("Iconset")
  rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
end

- (Object) draw_item_name(item, x, y, enabled = true, width = 172)


  • Draw Item Name

    enabled : Enabled flag. When false, draw semi-transparently.



549
550
551
552
553
554
# File 'Window_Base.rb', line 549

def draw_item_name(item, x, y, enabled = true, width = 172)
  return unless item
  draw_icon(item.icon_index, x, y, enabled)
  change_color(normal_color, enabled)
  draw_text(x + 24, y, width, line_height, item.name)
end

- (Object) draw_text(*args)


  • Draw Text

    args : Same as Bitmap#draw_text.



197
198
199
# File 'Window_Base.rb', line 197

def draw_text(*args)
  contents.draw_text(*args)
end

- (Object) draw_text_ex(x, y, text)


  • Draw Text with Control Characters




209
210
211
212
213
214
# File 'Window_Base.rb', line 209

def draw_text_ex(x, y, text)
  reset_font_settings
  text = convert_escape_characters(text)
  pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  process_character(text.slice!(0, 1), text, pos) until text.empty?
end

- (Object) fitting_height(line_number)


  • Calculate Height of Window Suited to Specified Number of Lines




61
62
63
# File 'Window_Base.rb', line 61

def fitting_height(line_number)
  line_number * line_height + standard_padding * 2
end

- (Object) gauge_back_color

Gauge background



162
# File 'Window_Base.rb', line 162

def gauge_back_color;  text_color(19);  end

- (Object) hide


  • Hide Window




130
131
132
133
# File 'Window_Base.rb', line 130

def hide
  self.visible = false
  self
end

- (Object) hp_color(actor)


  • Get HP Text Color




409
410
411
412
413
# File 'Window_Base.rb', line 409

def hp_color(actor)
  return knockout_color if actor.hp == 0
  return crisis_color if actor.hp < actor.mhp / 4
  return normal_color
end

- (Object) hp_gauge_color1

HP gauge 1



163
# File 'Window_Base.rb', line 163

def hp_gauge_color1;   text_color(20);  end

- (Object) hp_gauge_color2

HP gauge 2



164
# File 'Window_Base.rb', line 164

def hp_gauge_color2;   text_color(21);  end

- (Object) knockout_color

Knock out



161
# File 'Window_Base.rb', line 161

def knockout_color;    text_color(18);  end

- (Object) line_height


  • Get Line Height




31
32
33
# File 'Window_Base.rb', line 31

def line_height
  return 24
end

- (Object) make_font_bigger


  • Increase Font Size




333
334
335
# File 'Window_Base.rb', line 333

def make_font_bigger
  contents.font.size += 8 if contents.font.size <= 64
end

- (Object) make_font_smaller


  • Decrease Font Size




339
340
341
# File 'Window_Base.rb', line 339

def make_font_smaller
  contents.font.size -= 8 if contents.font.size >= 16
end

- (Object) mp_color(actor)


  • Get MP Text Color




417
418
419
420
# File 'Window_Base.rb', line 417

def mp_color(actor)
  return crisis_color if actor.mp < actor.mmp / 4
  return normal_color
end

- (Object) mp_cost_color

TP cost



167
# File 'Window_Base.rb', line 167

def mp_cost_color;     text_color(23);  end

- (Object) mp_gauge_color1

MP gauge 1



165
# File 'Window_Base.rb', line 165

def mp_gauge_color1;   text_color(22);  end

- (Object) mp_gauge_color2

MP gauge 2



166
# File 'Window_Base.rb', line 166

def mp_gauge_color2;   text_color(23);  end

- (Object) normal_color


  • Get Text Colors




158
# File 'Window_Base.rb', line 158

def normal_color;      text_color(0);   end

- (Object) obtain_escape_code(text)


  • Destructively Get Control Code




297
298
299
# File 'Window_Base.rb', line 297

def obtain_escape_code(text)
  text.slice!(/^[\$\.\|\^!><\{\}\\]|^[A-Z]+/i)
end

- (Object) obtain_escape_param(text)


  • Destructively Get Control Code Argument




303
304
305
# File 'Window_Base.rb', line 303

def obtain_escape_param(text)
  text.slice!(/^\[\d+\]/)[/\d+/].to_i rescue 0
end

- (Object) open


  • Open Window




107
108
109
110
111
# File 'Window_Base.rb', line 107

def open
  @opening = true unless open?
  @closing = false
  self
end

- (Object) param_change_color(change)


  • Get Parameter Change Color




568
569
570
571
572
# File 'Window_Base.rb', line 568

def param_change_color(change)
  return power_up_color   if change > 0
  return power_down_color if change < 0
  return normal_color
end

- (Object) party_member_name(n)


  • Get Name of Party Member n




251
252
253
254
# File 'Window_Base.rb', line 251

def party_member_name(n)
  actor = n >= 1 ? $game_party.members[n - 1] : nil
  actor ? actor.name : ""
end

- (Object) pending_color


  • Get Background Color of Pending Item




176
177
178
# File 'Window_Base.rb', line 176

def pending_color
  windowskin.get_pixel(80, 80)
end

- (Object) power_down_color

Equipment power down



169
# File 'Window_Base.rb', line 169

def power_down_color;  text_color(25);  end

- (Object) power_up_color

Equipment power up



168
# File 'Window_Base.rb', line 168

def power_up_color;    text_color(24);  end

- (Object) process_character(c, text, pos)


  • Character Processing

    c    : Characters
    text : A character string buffer in drawing processing (destructive)
    pos  : Draw position {:x, :y, :new_x, :height}



261
262
263
264
265
266
267
268
269
270
271
272
# File 'Window_Base.rb', line 261

def process_character(c, text, pos)
  case c
  when "\n"   # New line
    process_new_line(text, pos)
  when "\f"   # New page
    process_new_page(text, pos)
  when "\e"   # Control character
    process_escape_character(obtain_escape_code(text), text, pos)
  else        # Normal character
    process_normal_character(c, pos)
  end
end

- (Object) process_draw_icon(icon_index, pos)


  • Icon Drawing Process by Control Characters




326
327
328
329
# File 'Window_Base.rb', line 326

def process_draw_icon(icon_index, pos)
  draw_icon(icon_index, pos[:x], pos[:y])
  pos[:x] += 24
end

- (Object) process_escape_character(code, text, pos)


  • Control Character Processing

    code : the core of the control character
           e.g. "C" in the case of the control character \C[1].



311
312
313
314
315
316
317
318
319
320
321
322
# File 'Window_Base.rb', line 311

def process_escape_character(code, text, pos)
  case code.upcase
  when 'C'
    change_color(text_color(obtain_escape_param(text)))
  when 'I'
    process_draw_icon(obtain_escape_param(text), pos)
  when '{'
    make_font_bigger
  when '}'
    make_font_smaller
  end
end

- (Object) process_new_line(text, pos)


  • New Line Character Processing




284
285
286
287
288
# File 'Window_Base.rb', line 284

def process_new_line(text, pos)
  pos[:x] = pos[:new_x]
  pos[:y] += pos[:height]
  pos[:height] = calc_line_height(text)
end

- (Object) process_new_page(text, pos)


  • New Page Character Processing




292
293
# File 'Window_Base.rb', line 292

def process_new_page(text, pos)
end

- (Object) process_normal_character(c, pos)


  • Normal Character Processing




276
277
278
279
280
# File 'Window_Base.rb', line 276

def process_normal_character(c, pos)
  text_width = text_size(c).width
  draw_text(pos[:x], pos[:y], text_width * 2, pos[:height], c)
  pos[:x] += text_width
end

- (Object) reset_font_settings


  • Reset Font Settings




218
219
220
221
222
223
# File 'Window_Base.rb', line 218

def reset_font_settings
  change_color(normal_color)
  contents.font.size = Font.default_size
  contents.font.bold = Font.default_bold
  contents.font.italic = Font.default_italic
end

- (Object) show


  • Show Window




123
124
125
126
# File 'Window_Base.rb', line 123

def show
  self.visible = true
  self
end

- (Object) standard_padding


  • Get Standard Padding Size




37
38
39
# File 'Window_Base.rb', line 37

def standard_padding
  return 12
end

- (Object) system_color

System



159
# File 'Window_Base.rb', line 159

def system_color;      text_color(16);  end

- (Object) text_color(n)


  • Get Text Color

    n : Text color number (0..31)



152
153
154
# File 'Window_Base.rb', line 152

def text_color(n)
  windowskin.get_pixel(64 + (n % 8) * 8, 96 + (n / 8) * 8)
end

- (Object) text_size(str)


  • Get Text Size




203
204
205
# File 'Window_Base.rb', line 203

def text_size(str)
  contents.text_size(str)
end

- (Object) tp_color(actor)


  • Get TP Text Color




424
425
426
# File 'Window_Base.rb', line 424

def tp_color(actor)
  return normal_color
end

- (Object) tp_cost_color

TP cost



172
# File 'Window_Base.rb', line 172

def tp_cost_color;     text_color(29);  end

- (Object) tp_gauge_color1

TP gauge 1



170
# File 'Window_Base.rb', line 170

def tp_gauge_color1;   text_color(28);  end

- (Object) tp_gauge_color2

TP gauge 2



171
# File 'Window_Base.rb', line 171

def tp_gauge_color2;   text_color(29);  end

- (Object) translucent_alpha


  • Get Alpha Value of Translucent Drawing




182
183
184
# File 'Window_Base.rb', line 182

def translucent_alpha
  return 160
end

- (Object) update


  • Frame Update




84
85
86
87
88
89
# File 'Window_Base.rb', line 84

def update
  super
  update_tone
  update_open if @opening
  update_close if @closing
end

- (Object) update_close


  • Update Close Processing




100
101
102
103
# File 'Window_Base.rb', line 100

def update_close
  self.openness -= 48
  @closing = false if close?
end

- (Object) update_open


  • Update Open Processing




93
94
95
96
# File 'Window_Base.rb', line 93

def update_open
  self.openness += 48
  @opening = false if open?
end

- (Object) update_padding


  • Update Padding




43
44
45
# File 'Window_Base.rb', line 43

def update_padding
  self.padding = standard_padding
end

- (Object) update_tone


  • Update Tone




67
68
69
# File 'Window_Base.rb', line 67

def update_tone
  self.tone.set($game_system.window_tone)
end