Class: Window_NameEdit

Inherits:
Window_Base show all
Defined in:
Window_NameEdit.rb

Overview

** Window_NameEdit


This window is used to edit an actor's name on the name input screen.

Instance Attribute Summary (collapse)

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, #update_close, #update_open, #update_padding, #update_tone

Constructor Details

- (Window_NameEdit) initialize(actor, max_char)


  • Object Initialization




17
18
19
20
21
22
23
24
25
26
27
# File 'Window_NameEdit.rb', line 17

def initialize(actor, max_char)
  x = (Graphics.width - 360) / 2
  y = (Graphics.height - (fitting_height(4) + fitting_height(9) + 8)) / 2
  super(x, y, 360, fitting_height(4))
  @actor = actor
  @max_char = max_char
  @default_name = @name = actor.name[0, @max_char]
  @index = @name.size
  deactivate
  refresh
end

Instance Attribute Details

- (Object) index (readonly)

cursor position



12
13
14
# File 'Window_NameEdit.rb', line 12

def index
  @index
end

- (Object) max_char (readonly)

maximum number of characters



13
14
15
# File 'Window_NameEdit.rb', line 13

def max_char
  @max_char
end

- (Object) name (readonly)


  • Public Instance Variables




11
12
13
# File 'Window_NameEdit.rb', line 11

def name
  @name
end

Instance Method Details

- (Object) add(ch)


  • Add Text Character

    ch : character to add



41
42
43
44
45
46
47
# File 'Window_NameEdit.rb', line 41

def add(ch)
  return false if @index >= @max_char
  @name += ch
  @index += 1
  refresh
  return true
end

- (Object) back


  • Go Back One Character




51
52
53
54
55
56
57
# File 'Window_NameEdit.rb', line 51

def back
  return false if @index == 0
  @index -= 1
  @name = @name[0, @index]
  refresh
  return true
end

- (Object) char_width


  • Get Character Width




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

def char_width
  text_size($game_system.japanese? ? "" : "A").width 
end

- (Object) draw_char(index)


  • Draw Text




112
113
114
115
116
117
118
# File 'Window_NameEdit.rb', line 112

def draw_char(index)
  rect = item_rect(index)
  rect.x -= 1
  rect.width += 4
  change_color(normal_color)
  draw_text(rect, @name[index] || "")
end

- (Object) draw_underline(index)


  • Draw Underline




106
107
108
# File 'Window_NameEdit.rb', line 106

def draw_underline(index)
  contents.fill_rect(underline_rect(index), underline_color)
end

- (Object) face_width


  • Get Width of Face Graphic




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

def face_width
  return 96
end

- (Object) item_rect(index)


  • Get Rectangle for Displaying Item




81
82
83
# File 'Window_NameEdit.rb', line 81

def item_rect(index)
  Rect.new(left + index * char_width, 36, char_width, line_height)
end

- (Object) left


  • Get Coordinates of Left Side for Drawing Name




73
74
75
76
77
# File 'Window_NameEdit.rb', line 73

def left
  name_center = (contents_width + face_width) / 2
  name_width = (@max_char + 1) * char_width
  return [name_center - name_width / 2, contents_width - name_width].min
end

- (Object) refresh


  • Refresh




122
123
124
125
126
127
128
# File 'Window_NameEdit.rb', line 122

def refresh
  contents.clear
  draw_actor_face(@actor, 0, 0)
  @max_char.times {|i| draw_underline(i) }
  @name.size.times {|i| draw_char(i) }
  cursor_rect.set(item_rect(@index))
end

- (Object) restore_default


  • Revert to Default Name




31
32
33
34
35
36
# File 'Window_NameEdit.rb', line 31

def restore_default
  @name = @default_name
  @index = @name.size
  refresh
  return !@name.empty?
end

- (Object) underline_color


  • Get Underline Color




98
99
100
101
102
# File 'Window_NameEdit.rb', line 98

def underline_color
  color = normal_color
  color.alpha = 48
  color
end

- (Object) underline_rect(index)


  • Get Underline Rectangle




87
88
89
90
91
92
93
94
# File 'Window_NameEdit.rb', line 87

def underline_rect(index)
  rect = item_rect(index)
  rect.x += 1
  rect.y += rect.height - 4
  rect.width -= 2
  rect.height = 2
  rect
end