11-12-2014, 11:52 PM
คนที่เคยลง RPGMAKER XP Version เล่มม่วง (ดักแก่) น่าจะจำได้ว่าใน Version นั้นสามารถตั้งชื่อไทยได้ แต่เวลาตั้งชื่อจะเกิดปัญหาสระลอย ดังนี้
แต่ด้วยสคริปต์นี้ จะทำให้เมนูตั้ชื่อของคุณกลับมาสวยงาม ดังที่ควรจะเป็น
วิธีใช้
Copy script ข้างล่างไปทับ Window_NameEdit ของเก่า
ฺBonus สำหรับคนที่ไม่มีตัว Input ภาษาไทย
นำ script ข้างล่างไปทับ Window_NameInput ของเก่า
Show ContentSpoiler:
Show ContentSpoiler:
Copy script ข้างล่างไปทับ Window_NameEdit ของเก่า
Show ContentSpoiler:
#==============================================================================
# ** Window_NameEdit
#------------------------------------------------------------------------------
# This window is used to edit your name on the input name screen.
# ซ่อมสระลอย By TenesCross
#==============================================================================
class Window_NameEdit < Window_Base
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :name # name
attr_reader :index # cursor position
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
# max_char : maximum number of characters
#--------------------------------------------------------------------------
def initialize(actor, max_char)
super(0, 0, 640, 128)
self.contents = Bitmap.new(width - 32, height - 32)
@actor = actor
@name = actor.name
@max_char = max_char
# Fit name within maximum number of characters
name_array = @name.split(//)[0...@max_char]
@name = ""
for i in 0...name_array.size
@name += name_array[i]
end
@default_name = @name
@index = name_array.size
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# * Return to Default Name
#--------------------------------------------------------------------------
def restore_default
@name = @default_name
@index = @name.split(//).size
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# * Add Character
# character : text character to be added
#--------------------------------------------------------------------------
def add(character)
if @index < @max_char and character != ""
@name += character
@index += 1
refresh
update_cursor_rect
end
end
#--------------------------------------------------------------------------
# * Delete Character
#--------------------------------------------------------------------------
def back
if @index > 0
# Delete 1 text character
name_array = @name.split(//)
@name = ""
for i in 0...name_array.size-1
@name += name_array[i]
end
@index -= 1
refresh
update_cursor_rect
end
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
# Draw name
name_array = @name.split(//)
#ซ่อมสระ========
a = 0
for i in 0...@max_char
c = name_array[i]
if c == nil
c = "_" #_
end
if c == "ำ" or c == "้" or c == "่" or c == "๊" or c == "๋" or c == "ี" or c == "ิ" or c == "ื" or c == "ึ" or c == "ุ" or c == "ู" or c == "ั" or c == "็" or c == "์"
a = a+1
end
#==============
x = 320 - @max_char * 14 + (i-a) * 28
self.contents.draw_text(x, 32, 28, 32, c, 1)
end
# Draw graphic
draw_actor_graphic(@actor, 320 - @max_char * 14 - 40, 80)
end
#--------------------------------------------------------------------------
# * Cursor Rectangle Update
#--------------------------------------------------------------------------
def update_cursor_rect
name_array = @name.split(//)
a = 0
for i in 0...@max_char
c = name_array[i]
if c == "ำ" or c == "้" or c == "่" or c == "๊" or c == "๋" or c == "ี" or c == "ิ" or c == "ื" or c == "ึ" or c == "ุ" or c == "ู" or c == "ั" or c == "็" or c == "์"
a = a+1
end
end
x = 320 - @max_char * 14 + (@index-a) * 28
self.cursor_rect.set(x, 32, 28, 32)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
update_cursor_rect
end
end[/quote]
# ** Window_NameEdit
#------------------------------------------------------------------------------
# This window is used to edit your name on the input name screen.
# ซ่อมสระลอย By TenesCross
#==============================================================================
class Window_NameEdit < Window_Base
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :name # name
attr_reader :index # cursor position
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
# max_char : maximum number of characters
#--------------------------------------------------------------------------
def initialize(actor, max_char)
super(0, 0, 640, 128)
self.contents = Bitmap.new(width - 32, height - 32)
@actor = actor
@name = actor.name
@max_char = max_char
# Fit name within maximum number of characters
name_array = @name.split(//)[0...@max_char]
@name = ""
for i in 0...name_array.size
@name += name_array[i]
end
@default_name = @name
@index = name_array.size
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# * Return to Default Name
#--------------------------------------------------------------------------
def restore_default
@name = @default_name
@index = @name.split(//).size
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# * Add Character
# character : text character to be added
#--------------------------------------------------------------------------
def add(character)
if @index < @max_char and character != ""
@name += character
@index += 1
refresh
update_cursor_rect
end
end
#--------------------------------------------------------------------------
# * Delete Character
#--------------------------------------------------------------------------
def back
if @index > 0
# Delete 1 text character
name_array = @name.split(//)
@name = ""
for i in 0...name_array.size-1
@name += name_array[i]
end
@index -= 1
refresh
update_cursor_rect
end
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
# Draw name
name_array = @name.split(//)
#ซ่อมสระ========
a = 0
for i in 0...@max_char
c = name_array[i]
if c == nil
c = "_" #_
end
if c == "ำ" or c == "้" or c == "่" or c == "๊" or c == "๋" or c == "ี" or c == "ิ" or c == "ื" or c == "ึ" or c == "ุ" or c == "ู" or c == "ั" or c == "็" or c == "์"
a = a+1
end
#==============
x = 320 - @max_char * 14 + (i-a) * 28
self.contents.draw_text(x, 32, 28, 32, c, 1)
end
# Draw graphic
draw_actor_graphic(@actor, 320 - @max_char * 14 - 40, 80)
end
#--------------------------------------------------------------------------
# * Cursor Rectangle Update
#--------------------------------------------------------------------------
def update_cursor_rect
name_array = @name.split(//)
a = 0
for i in 0...@max_char
c = name_array[i]
if c == "ำ" or c == "้" or c == "่" or c == "๊" or c == "๋" or c == "ี" or c == "ิ" or c == "ื" or c == "ึ" or c == "ุ" or c == "ู" or c == "ั" or c == "็" or c == "์"
a = a+1
end
end
x = 320 - @max_char * 14 + (@index-a) * 28
self.cursor_rect.set(x, 32, 28, 32)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
update_cursor_rect
end
end[/quote]
ฺBonus สำหรับคนที่ไม่มีตัว Input ภาษาไทย
นำ script ข้างล่างไปทับ Window_NameInput ของเก่า
Show ContentSpoiler:
#==============================================================================
# * Window_NameInput
#------------------------------------------------------------------------------
# In the name input picture, it is the window which selects letter.
#==============================================================================
class Window_NameInput < Window_Base
CHARACTER_TABLE =
[
"1","2","3","4","5",
"!","@","#","$","%",
"A","B","C","D","E",
"F","G","H","I","J",
"K","L","M","N","O",
"P","Q","R","S","T",
"U","V","W","X","Y",
"Z"," "," "," "," ",
" "," "," "," "," ",
"6","7","8","9","0",
"^","&","*","(",")",
"a","b","c","d","e",
"f","g","h","i","j",
"k","l","m","n","o",
"p","q","r","s","t",
"u","v","w","x","y",
"z"," "," "," "," ",
" "," "," ", " "," ",
"๑","๒","๓","๔","๕",
"<",">","?","฿","-",
"ก","ข","ฃ","ค","ฅ",
"ซ","ฌ","ญ","ฎ","ฏ",
"ต","ถ","ท","ธ","น",
"ฟ","ภ","ม","ย","ร",
"ห","ฬ","อ","ฮ","",
"โ","ใ","ไ","ั","ิ",
"่","้","๋","๊","็",
"๖","๗","๘","๙","๐",
"+","_","/","[","]",
"ฆ","ง","จ","ฉ","ช",
"ฐ","ฑ","ฒ","ณ","ด",
"บ","ป","ผ","ฝ","พ",
"ล","ว","ศ","ษ","ส",
"ะ","า","ำ","เ","แ",
"ี","ึ","ื","ุ","ู",
" "," "," "," "," ",
]
#--------------------------------------------------------------------------
# - Object initialization
#--------------------------------------------------------------------------
def initialize
super(0, 128, 640, 352)
self.contents = Bitmap.new(width - 32, height - 32)
@index = 0
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# - Acquisition of letter
#--------------------------------------------------------------------------
def character
return CHARACTER_TABLE[@index]
end
#--------------------------------------------------------------------------
# - Refreshment
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
for i in 0..179
x = 4 + i / 5 / 9 * 152 + i % 5 * 28
y = i / 5 % 9 * 32
self.contents.draw_text(x, y, 28, 32, CHARACTER_TABLE[i], 1)
end
self.contents.draw_text(544, 9 * 32, 64, 32, "Accept", 1)
end
#--------------------------------------------------------------------------
# - Rectangle renewal of cursor
#--------------------------------------------------------------------------
def update_cursor_rect
# When cursor position [ decision ] is
if @index >= 180
self.cursor_rect.set(544, 9 * 32, 64, 32)
# When cursor position [ decision ] it is other than
else
x = 4 + @index / 5 / 9 * 152 + @index % 5 * 28
y = @index / 5 % 9 * 32
self.cursor_rect.set(x, y, 28, 32)
end
end
#--------------------------------------------------------------------------
# - Frame renewal
#--------------------------------------------------------------------------
def update
super
# When cursor position [ decision ] is
if @index >= 180
# Down cursor
if Input.trigger?(Input:OWN)
$game_system.se_play($data_system.cursor_se)
@index -= 180
end
# Up cursor
if Input.repeat?(Input::UP)
$game_system.se_play($data_system.cursor_se)
@index -= 180 - 40
end
# When cursor position [ decision ] it is other than
else
# When the right of the direction button is pushed
if Input.repeat?(Input::RIGHT)
# Depression state is not repeat when
# When cursor position is not right hand edge
if Input.trigger?(Input::RIGHT) or
@index / 45 < 3 or @index % 5 < 4
# Moving cursor to the right
$game_system.se_play($data_system.cursor_se)
if @index % 5 < 4
@index += 1
else
@index += 45 - 4
end
if @index >= 180
@index -= 180
end
end
end
# When the left of the direction button is pushed
if Input.repeat?(Input::LEFT)
# Depression state is not repeat when
# When cursor position is not the left edge
if Input.trigger?(Input::LEFT) or
@index / 45 > 0 or @index % 5 > 0
# Moving cursor to the left
$game_system.se_play($data_system.cursor_se)
if @index % 5 > 0
@index -= 1
else
@index -= 45 - 4
end
if @index < 0
@index += 180
end
end
end
# When the bottom of the direction button is pushed
if Input.repeat?(Input:OWN)
# Moving cursor down
$game_system.se_play($data_system.cursor_se)
if @index % 45 < 40
@index += 5
else
@index += 180 - 40
end
end
# When the top of the direction button is pushed
if Input.repeat?(Input::UP)
# Depression state is not repeat when
# When cursor position is not the top
if Input.trigger?(Input::UP) or @index % 45 >= 5
# Moving cursor up
$game_system.se_play($data_system.cursor_se)
if @index % 45 >= 5
@index -= 5
else
@index += 180
end
end
end
# The L when button or the R button is pushed
if Input.repeat?(Input::L) or Input.repeat?(Input::R)
# Hiragana/katakana movement
$game_system.se_play($data_system.cursor_se)
if @index / 45 < 2
@index += 90
else
@index -= 90
end
end
end
update_cursor_rect
end
end
# * Window_NameInput
#------------------------------------------------------------------------------
# In the name input picture, it is the window which selects letter.
#==============================================================================
class Window_NameInput < Window_Base
CHARACTER_TABLE =
[
"1","2","3","4","5",
"!","@","#","$","%",
"A","B","C","D","E",
"F","G","H","I","J",
"K","L","M","N","O",
"P","Q","R","S","T",
"U","V","W","X","Y",
"Z"," "," "," "," ",
" "," "," "," "," ",
"6","7","8","9","0",
"^","&","*","(",")",
"a","b","c","d","e",
"f","g","h","i","j",
"k","l","m","n","o",
"p","q","r","s","t",
"u","v","w","x","y",
"z"," "," "," "," ",
" "," "," ", " "," ",
"๑","๒","๓","๔","๕",
"<",">","?","฿","-",
"ก","ข","ฃ","ค","ฅ",
"ซ","ฌ","ญ","ฎ","ฏ",
"ต","ถ","ท","ธ","น",
"ฟ","ภ","ม","ย","ร",
"ห","ฬ","อ","ฮ","",
"โ","ใ","ไ","ั","ิ",
"่","้","๋","๊","็",
"๖","๗","๘","๙","๐",
"+","_","/","[","]",
"ฆ","ง","จ","ฉ","ช",
"ฐ","ฑ","ฒ","ณ","ด",
"บ","ป","ผ","ฝ","พ",
"ล","ว","ศ","ษ","ส",
"ะ","า","ำ","เ","แ",
"ี","ึ","ื","ุ","ู",
" "," "," "," "," ",
]
#--------------------------------------------------------------------------
# - Object initialization
#--------------------------------------------------------------------------
def initialize
super(0, 128, 640, 352)
self.contents = Bitmap.new(width - 32, height - 32)
@index = 0
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# - Acquisition of letter
#--------------------------------------------------------------------------
def character
return CHARACTER_TABLE[@index]
end
#--------------------------------------------------------------------------
# - Refreshment
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
for i in 0..179
x = 4 + i / 5 / 9 * 152 + i % 5 * 28
y = i / 5 % 9 * 32
self.contents.draw_text(x, y, 28, 32, CHARACTER_TABLE[i], 1)
end
self.contents.draw_text(544, 9 * 32, 64, 32, "Accept", 1)
end
#--------------------------------------------------------------------------
# - Rectangle renewal of cursor
#--------------------------------------------------------------------------
def update_cursor_rect
# When cursor position [ decision ] is
if @index >= 180
self.cursor_rect.set(544, 9 * 32, 64, 32)
# When cursor position [ decision ] it is other than
else
x = 4 + @index / 5 / 9 * 152 + @index % 5 * 28
y = @index / 5 % 9 * 32
self.cursor_rect.set(x, y, 28, 32)
end
end
#--------------------------------------------------------------------------
# - Frame renewal
#--------------------------------------------------------------------------
def update
super
# When cursor position [ decision ] is
if @index >= 180
# Down cursor
if Input.trigger?(Input:OWN)
$game_system.se_play($data_system.cursor_se)
@index -= 180
end
# Up cursor
if Input.repeat?(Input::UP)
$game_system.se_play($data_system.cursor_se)
@index -= 180 - 40
end
# When cursor position [ decision ] it is other than
else
# When the right of the direction button is pushed
if Input.repeat?(Input::RIGHT)
# Depression state is not repeat when
# When cursor position is not right hand edge
if Input.trigger?(Input::RIGHT) or
@index / 45 < 3 or @index % 5 < 4
# Moving cursor to the right
$game_system.se_play($data_system.cursor_se)
if @index % 5 < 4
@index += 1
else
@index += 45 - 4
end
if @index >= 180
@index -= 180
end
end
end
# When the left of the direction button is pushed
if Input.repeat?(Input::LEFT)
# Depression state is not repeat when
# When cursor position is not the left edge
if Input.trigger?(Input::LEFT) or
@index / 45 > 0 or @index % 5 > 0
# Moving cursor to the left
$game_system.se_play($data_system.cursor_se)
if @index % 5 > 0
@index -= 1
else
@index -= 45 - 4
end
if @index < 0
@index += 180
end
end
end
# When the bottom of the direction button is pushed
if Input.repeat?(Input:OWN)
# Moving cursor down
$game_system.se_play($data_system.cursor_se)
if @index % 45 < 40
@index += 5
else
@index += 180 - 40
end
end
# When the top of the direction button is pushed
if Input.repeat?(Input::UP)
# Depression state is not repeat when
# When cursor position is not the top
if Input.trigger?(Input::UP) or @index % 45 >= 5
# Moving cursor up
$game_system.se_play($data_system.cursor_se)
if @index % 45 >= 5
@index -= 5
else
@index += 180
end
end
end
# The L when button or the R button is pushed
if Input.repeat?(Input::L) or Input.repeat?(Input::R)
# Hiragana/katakana movement
$game_system.se_play($data_system.cursor_se)
if @index / 45 < 2
@index += 90
else
@index -= 90
end
end
end
update_cursor_rect
end
end