赠:【脚本插件:文章居中】
零、本文范例:【脚本范例】
一、名词解释
1.0 类
class 就是类。以class起头,以end结尾
class Window_GameEnd < Window_Command # ←表示“Window_GameEnd”【继承于】“Window_Command”。
# “Window_Command”是“Window_GameEnd”的【父类】
# 而“Window_GameEnd”是“Window_Command”的【子类】。
1.1 类的继承
在父类与子类中,【使用同一个方法名】的方法,就是同一个方法。
子类可在【自己范围内】,继承父类预置的内容,或补充、重定义父类预置的东西:
1) 某方法a,见于父类,不见于子类,在子类中,以父类里书写的方式运行。
2) 某方法a,不在父类,却见于子类,在子类中,以子类里书写的方式运行。
3) 某方法a,见于父类,也见于子类,在两类中不太相同,在子类中:
若是 子类方法a 补充了父类中没有的内容,则两者的内容都运行
若是 子类方法a 重写了父类中相同的命令,则按照子类中的运行
4) 某方法a,见于父类,也见于子类,在两类中完全相同,则无需赘言。
1.2 【类的继承 例举】
2. 方法
def 就是方法。以def起头,以end结尾
def make_command_list
add_command(Vocab::to_title, :to_title)
add_command(Vocab::shutdown, :shutdown)
add_command(Vocab::cancel, :cancel)
end
# make_command_list是【方法名】
二、操作步骤
1. 窗口中的文字居中
!选项中的文字,无法用此方法居中
【Window_Command】类的【 alignment】方法中
#--------------------------------------------------------------------------
# ● 获取对齐方向
#--------------------------------------------------------------------------
def alignment
return 0 # 改为 return 1
end
# 0 = 左对齐
# 1 = 居中
# 2 = 右对齐
2. 选项窗口居中
【Window_ChoiceList】类的【update_placement】方法中
#--------------------------------------------------------------------------
# ● 更新窗口的位置
#--------------------------------------------------------------------------
def update_placement
self.width = [max_choice_width + 12, 96].max + padding * 2
self.width = [width, Graphics.width].min
self.height = fitting_height($game_message.choices.size)
self.x = Graphics.width - width # 改为 self.x = (Graphics.width - width)/2
if @message_window.y >= Graphics.height / 2
self.y = @message_window.y - height
else
self.y = @message_window.y + @message_window.height
end
end
猜测其含义可能是:
【Window_ChoiceList的x坐标】=【整个游戏画面的宽度】-【Window_ChoiceList的宽度】
3. 选项控制符修正
(左:修正。右:不修)
Window_ChoiceList】类中,【update_placement】方法之下
#--------------------------------------------------------------------------
# ● 获取选项的最大宽度
#--------------------------------------------------------------------------
def max_choice_width
$game_message.choices.collect {|s| text_size(s).width }.max
end
改为:
#--------------------------------------------------------------------------
# ● 获取选项的最大宽度
#--------------------------------------------------------------------------
def max_choice_width
$game_message.choices.collect {|s| pro_ex(s) }.max
end
def pro_ex(str)
s = convert_escape_characters(str)
pos = {:x => 0, :y => -Graphics.height, :new_x => 0, :height => calc_line_height(s)}
process_character(s.slice!(0, 1), s, pos) until s.empty?
pos[:x]
end
【代码读取顺序】:方法的调用要先于方法的定义。
“update_placement”中调用“max_choice_width”方法,
故“max_choice_width”要在“update_placement”的下面写
4. 增减菜单命令
一个命令要分为两个部分:
1) 以“Scene_”开头的类中, "make_command_list"方法
注释掉此方法中的命令,则命令将不显示。“判定命令是否有效”的语句要写在这里(如save是否灰色显示)。
2) 以“Window_”开头的类中, "create_command_window"方法
注释掉此方法中的命令,则命令将失效。
3) 要修改“结束游戏”菜单中的项目,主要修改【Window_GameEnd】与【Scene_End】两个类。
5. 返回游戏 debug
【Scene_End】类中,增加:
def return_scene
close_command_window
SceneManager.return
SceneManager.return
end