Project1
标题:
XP 脚本 模组化运动 & 全系列补完
[打印本页]
作者:
david50407
时间:
2010-11-14 23:31
标题:
XP 脚本 模组化运动 & 全系列补完
介于 VX 脚本有很好的模组化示范
XP 的脚本就到没那么有系列化的整理
(虽然偶比较喜欢 XP...)
所以在这里发起 XP 脚本 模组化运动
当然不是把脚本通通写成模组(Modules)
而是像 VX 那样有着良好的继承关系
在整理 XP 脚本的同时
希望也能一并附加上某些常用到的特殊功能(例: String 转码...)
也希望能够遵循以下MS是规则的东东
1. 不破坏原本架构=> 这是当然的, 要不RMXP 就只能靠脚本生存了= =|
2. 能附上良好的注释=> 让大家看懂你在做啥...
3. 发问请至沙发善用点评若针对某脚本可以在该帖点评=> 因为点评只有发帖者会收到提醒, 回覆时请记得PM对方
4. 请抱着学习的心态来完成=> 一边磨练脚本嘛...
5. 请保持过程身心愉悦
于是让我们开始吧~~
作者:
david50407
时间:
2010-11-14 23:31
本帖最后由 david50407 于 2010-11-15 23:52 编辑
于是S系列采用禾西的当作基础吧...
过几天整理整理我写的再放上来
作者:
darkscout3000
时间:
2010-11-15 00:35
这个很不错的样子(个人也是比较喜欢XP……主要是……VX的人物总是方的很纠结……)
这里提到的继承关系是指把无意义的重复代码给做成父类然后继承的意思么?
(顺便把一些写的垃圾的代码给优化下)
P.S. 不过一个人估计应该是做不来,多人做估计会做重复工……是不是具体分工下效率比较高……
作者:
enghao_lim
时间:
2010-11-15 00:40
本帖最后由 enghao_lim 于 2010-11-15 00:42 编辑
对xp比较有爱,如果有用我愿意意帮忙,
只是有点不解?是类似SDK这样的运动?
作者:
禾西
时间:
2010-11-15 03:53
本帖最后由 禾西 于 2010-11-15 04:04 编辑
哦?終于有人提出這個計劃了嗎?好吧,那麼最萌的scene_base先上
@wins[Symbol] = Window Obj #加入窗口實例
note: 將窗口加入wins中可以不需考慮釋放的問題
#=================================================================
# ■ ::Scene_Base / 原始介面類
#// Date 2.11.09
#// Ver. 1.01
#// by 禾西
#------------------------------------------------------------------------------
class Scene_Base
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
def main
@wins = {}
start
# 执行过渡
Graphics.transition
# 主循环
loop do
Input.update #刷新「輸入信息」
Graphics.update #刷新「游戏畫面」
# 刷新画面
update
# 如果切换画面就中断循环
break if $scene != self
end
# 准备过渡
Graphics.freeze
@wins.each_value do |window| window.dispose end
terminate
end
#--------------------------------------------------------------------------
# ● 开始
#--------------------------------------------------------------------------
def start
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def update
end
#--------------------------------------------------------------------------
# ● 终止
#--------------------------------------------------------------------------
def terminate
end
end
复制代码
一般來說,你只需要重定義 start、update、terminate就可以了。
而事實上,如果你把window丟進@win中,連terminate都不需要。
這是一個 Scene_End 的范例:
class Scene_End < Scene_Base
#--------------------------------------------------------------------------
# ● 开始
#--------------------------------------------------------------------------
def start
# 生成命令窗口
s1 = "返回标题画面"
s2 = "退出"
s3 = "取消"
@wins[:command] = Window_Command.new(192, [s1, s2, s3])
@wins[:command].x = 320 - @wins[:command].width / 2
@wins[:command].y = 240 - @wins[:command].height / 2
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
# 刷新命令窗口
@wins[:command].update
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 切换到菜单画面
$scene = Scene_Menu.new(5)
return
end
# 按下 C 键的场合下
if Input.trigger?(Input::C)
# 命令窗口光标位置分支
case @wins[:command].index
when 0 # 返回标题画面
command_to_title
when 1 # 退出
command_shutdown
when 2 # 取消
command_cancel
end
return
end
end
#--------------------------------------------------------------------------
# ● 选择命令 [返回标题画面] 时的处理
#--------------------------------------------------------------------------
def command_to_title
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 淡入淡出 BGM、BGS、ME
Audio.bgm_fade(800)
Audio.bgs_fade(800)
Audio.me_fade(800)
# 切换到标题画面
$scene = Scene_Title.new
end
#--------------------------------------------------------------------------
# ● 选择命令 [退出] 时的处理
#--------------------------------------------------------------------------
def command_shutdown
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 淡入淡出 BGM、BGS、ME
Audio.bgm_fade(800)
Audio.bgs_fade(800)
Audio.me_fade(800)
# 退出
$scene = nil
end
#--------------------------------------------------------------------------
# ● 选择命令 [取消] 时的处理
#--------------------------------------------------------------------------
def command_cancel
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 切换到菜单画面
$scene = Scene_Menu.new(5)
end
end
复制代码
召喚腳本上色功能,召喚腳本縮放功能……
作者:
禾西
时间:
2010-11-15 04:43
本帖最后由 禾西 于 2010-11-15 05:03 编辑
另外一個是 Window_Selectable
update 被斬開了。新增了on_left, on_right, on_up, on_down, on_L, on_R 方法來直接重定義鍵盤信息處理。
#==============================================================================
# ■ Wnd_Selectable / 拥有光标的移动以及滚动功能的原始窗口类。
# Date 08.06.10
# Draft 2 by 禾西
# Ver 1.1
# < Window_Base < Window
#==============================================================================
# 用變量 @rowh 代替列高
# 增加 #.close 方法來unactivate window
# update_cursor_rect 只在光標位置變更才調用
# 增加 on_left, on_right, on_up, on_down, on_L, on_R 方法
#------------------------------------
class Wnd_Selectable < Window_Base
#--------------------------------------------------------------------------
# ● 凍結選擇
#--------------------------------------------------------------------------
def close
@index = 0
update_cursor_rect
self.cursor_rect.empty
@index =-1
end
#==============================================================================
# 原始方法
#==============================================================================
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :index # 光标位置
attr_reader :help_window # 帮助窗口
#--------------------------------------------------------------------------
# ● 初始画对像
# x : 窗口的 X 坐标
# y : 窗口的 Y 坐标
# width : 窗口的宽
# height : 窗口的高
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
@item_max ||= 1
@column_max ||= 1
@index ||= -1
@rowh ||= 32
super(x, y, width, height)
end
#--------------------------------------------------------------------------
# ● 设置光标的位置
# index : 新的光标位置
#--------------------------------------------------------------------------
def index=(index)
@index = index
# 刷新帮助文本 (update_help 定义了继承目标)
if self.active and @help_window != nil
update_help
end
# 刷新光标矩形
update_cursor_rect
end
#--------------------------------------------------------------------------
# ● 获取行数
#--------------------------------------------------------------------------
def row_max
# 由项目数和列数计算出行数
return (@item_max + @column_max - 1) / @column_max
end
#--------------------------------------------------------------------------
# ● 获取开头行
#--------------------------------------------------------------------------
def top_row
# 将窗口内容的传送源 Y 坐标、1 行的高 @rowh 等分
return self.oy / @rowh
end
#--------------------------------------------------------------------------
# ● 设置开头行
# row : 显示开头的行
#--------------------------------------------------------------------------
def top_row=(row)
# row 未满 0 的场合更正为 0
if row < 0
row = 0
end
# row 超过 row_max - 1 的情况下更正为 row_max - 1
if row > row_max - 1
row = row_max - 1
end
# row 1 行高的 @rowh 倍、窗口内容的传送源 Y 坐标
self.oy = row * @rowh
end
#--------------------------------------------------------------------------
# ● 获取 1 页可以显示的行数
#--------------------------------------------------------------------------
def page_row_max
# 窗口的高度,设置画面的高度减去 @rowh ,除以 1 行的高度 @rowh
return (self.height - @rowh) / @rowh
end
#--------------------------------------------------------------------------
# ● 获取 1 页可以显示的项目数
#--------------------------------------------------------------------------
def page_item_max
# 将行数 page_row_max 乘上列数 @column_max
return page_row_max * @column_max
end
#--------------------------------------------------------------------------
# ● 帮助窗口的设置
# help_window : 新的帮助窗口
#--------------------------------------------------------------------------
def help_window=(help_window)
@help_window = help_window
# 刷新帮助文本 (update_help 定义了继承目标)
if self.active and @help_window != nil
update_help
end
end
#--------------------------------------------------------------------------
# ● 更新光标举行
#--------------------------------------------------------------------------
def update_cursor_rect
# 光标位置不满 0 的情况下
if @index < 0
self.cursor_rect.empty
return
end
# 获取当前的行
row = @index / @column_max
# 当前行被显示开头行前面的情况下
if row < self.top_row
# 从当前行向开头行滚动
self.top_row = row
end
# 当前行被显示末尾行之后的情况下
if row > self.top_row + (self.page_row_max - 1)
# 从当前行向末尾滚动
self.top_row = row - (self.page_row_max - 1)
end
# 计算光标的宽
cursor_width = self.width / @column_max - @rowh
# 计算光标坐标
x = @index % @column_max * (cursor_width + @rowh)
y = @index / @column_max * @rowh - self.oy
# 更新国标矩形
self.cursor_rect.set(x, y, cursor_width, @rowh)
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
super
# 可以移动光标的情况下
if self.active and @item_max >= 0 and @index >= 0
on_down() if Input.repeat?(Input::DOWN) # 方向键下被按下
on_up() if Input.repeat?(Input::UP) # 方向键上被按下
on_right() if Input.repeat?(Input::RIGHT)# 方向键右被按下
on_left() if Input.repeat?(Input::LEFT) # 方向键左被按下
on_R() if Input.repeat?(Input::R)# R 键被按下
on_L() if Input.repeat?(Input::L)# L 键被按下
end
# 刷新帮助文本 (update_help 定义了继承目标)
if self.active and @help_window != nil
update_help
end
end
#--------------------------------------------------------------------------
# ● 下
#--------------------------------------------------------------------------
def on_down
return if @item_max <= 0
# 列数不是 1 并且方向键的下的按下状态不是重复的情况、
# 或光标位置在(项目数-列数)之前的情况下
if (@column_max == 1 and Input.trigger?(Input::DOWN)) or
true#@index <= @item_max - @column_max #<==話說這個東東有啥有--a
# 光标向下移动
$game_system.se_play($data_system.cursor_se)
self.index = (@index + @column_max) % @item_max
end
end
#--------------------------------------------------------------------------
# ● 上
#--------------------------------------------------------------------------
def on_up
return if @item_max <= 0
# 列数不是 1 并且方向键的下的按下状态不是重复的情况、
# 或光标位置在列之后的情况下
if (@column_max == 1 and Input.trigger?(Input::UP)) or
true#@index >= @column_max #<==話說這個東東有啥有--a
# 光标向上移动
$game_system.se_play($data_system.cursor_se)
self.index = (@index - @column_max + @item_max) % @item_max
end
end
#--------------------------------------------------------------------------
# ● 右
#--------------------------------------------------------------------------
def on_right
# 列数为 2 以上并且、光标位置在(项目数 - 1)之前的情况下
if @column_max >= 2 and @index < @item_max - 1
# 光标向右移动
$game_system.se_play($data_system.cursor_se)
self.index += 1
end
end
#--------------------------------------------------------------------------
# ● 左
#--------------------------------------------------------------------------
def on_left
# 列数为 2 以上并且、光标位置在(项目数 - 1)之前的情况下
if @column_max >= 2 and @index > 0
# 光标向右移动
$game_system.se_play($data_system.cursor_se)
self.index -= 1
end
end
#--------------------------------------------------------------------------
# ● R
#--------------------------------------------------------------------------
def on_R
# 显示的最后行在数据中最后行上方的情况下
if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
# 光标向后移动一页
$game_system.se_play($data_system.cursor_se)
self.top_row += self.page_row_max
self.index = [@index + self.page_item_max, @item_max - 1].min
end
end
#--------------------------------------------------------------------------
# ● L
#--------------------------------------------------------------------------
def on_L
# 显示的开头行在位置 0 之后的情况下
if self.top_row > 0
# 光标向前移动一页
$game_system.se_play($data_system.cursor_se)
self.top_row -= self.page_row_max
self.index = [@index - self.page_item_max, 0].max
end
end
#--------------------------------------------------------------------------
# ● 虛函數
#--------------------------------------------------------------------------
def update_help
end
end
复制代码
這應該是個很好的示例,這個選擇窗口需要特殊的行高,同時也是斜向排布的,因此我需要把左、下二鍵;上右二鍵的行為設為一致:
class Window_Command < Wnd_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
# width : 窗口的宽
# commands : 命令字符串序列
#--------------------------------------------------------------------------
def initialize(commands)
@item_max = commands.size # 重定義的 item_max
@commands = commands
@rowh = 64 # 重定義的 rowh
super(-16, -16, 740, 580)
self.windowskin = nil
self.contents = loadbitmap("Graphics/menu/menu1.png")
self.index = 0
self.z = 10
self.opacity = 0
end
#--------------------------------------------------------------------------
# ● 索引
#--------------------------------------------------------------------------
def index=(int)
super(int)
if int >= 0
self.contents = loadbitmap("Graphics/menu/menu#{int+1}.png")
else
self.contents = nil
end
end
#--------------------------------------------------------------------------
# ● 重定義的左鍵
#--------------------------------------------------------------------------
def on_left
on_down
end
#--------------------------------------------------------------------------
# ● 重定義的右鍵
#--------------------------------------------------------------------------
def on_right
on_up
end
end
复制代码
作者:
禾西
时间:
2010-11-15 04:48
三連擊。以上兩個腳本都是新增的腳本,可以和原腳本并存。可以當作另一套kit?(笑)
作者:
dbshy
时间:
2010-11-15 12:57
说实话,这就是我觉得VX脚本看着不顺眼的地方
可能是我这只彩笔跟高手的区别吧
作者:
匿名
时间:
2010-11-15 13:48
本帖最后由 匿名 于 2010-11-15 13:54 编辑
于是……人类又开始逐步接近黑幕中的某些神秘力量了么(大雾)
搬个板凳围观一下
另:
其实所有窗口类只需要一个窗口类即可……
所有场景类只需要一个场景类即可……
去掉下面那个窗口中和MESSAGE类似的东西之外,汝等能发现什么微妙之处么
class Window_tessst < Window_Base
#这只是另一个低调的黑幕脚本
def initialize( x , y , weight , height , texxt )
super(x, y, weight, height)
self.contents = Bitmap.new(width - 32, height - 32)
self.z = 9998
@texxt = texxt
@tasklist = []
refresh
end
def pushtask(task)
@tasklist.push(task)
end
def settask(task)
@tasklist = task
end
def deletetask(task)
@tasklist.delete(task)
end
def cleantask
@tasklist = []
end
def refresh
new_contents_clear()
if @tasklist != nil and @tasklist != []
for i in @tasklist
eval(i)
end
end
self.contents.font.color = normal_color
x = y = 0
@cursor_width = 0
# 有等待显示的文字的情况下
if @texxt != nil
text = @texxt.clone
# 限制文字处理
begin
last_text = text.clone
text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
end until text == last_text
text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
$game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
end
# 为了方便、将 "\\\\" 变换为 "\000"
text.gsub!(/\\\\/) { "\000" }
# "\\C" 变为 "\001" に、"\\G" 变为 "\002"
text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
text.gsub!(/\\[Gg]/) { "\002" }
text.gsub!(/\\[Hh]\[([0-9]+)\]/) { "\025[#{$1}]" }
# c 获取 1 个字 (如果不能取得文字就循环)
while ((c = text.slice!(/./m)) != nil)
# \\ 的情况下
if c == "\000"
# 还原为本来的文字
c = "\\"
end
# \C[n] 的情况下
if c == "\001"
# 更改文字色
text.sub!(/\[([0-9]+)\]/, "")
color = $1.to_i
if color >= 0 and color <= 7
self.contents.font.color = text_color(color)
end
# 下面的文字
next
end
# \G 的情况下
if c == "\002"
# 生成金钱窗口
if @gold_window == nil
@gold_window = Window_Gold.new
@gold_window.x = 560 - @gold_window.width
if $game_temp.in_battle
@gold_window.y = 192
else
@gold_window.y = self.y >= 128 ? 32 : 384
end
@gold_window.opacity = self.opacity
@gold_window.back_opacity = self.back_opacity
end
# 下面的文字
next
end
if c == "\025"
text.sub!(/\[([0-9]+)\]/, "")
self.contents.font.size = [[$1.to_i, 6].max, 32].min
next
end
# 另起一行文字的情况下
if c == "\n"
# 刷新选择项及光标的高
if y >= $game_temp.choice_start
@cursor_width = [@cursor_width, x].max
end
# y 加 1
y += 1
x = 0
# 移动到选择项的下一行
if y >= $game_temp.choice_start
x = 8
end
# 下面的文字
next
end
# 描绘文字
self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
# x 为要描绘文字的加法运算
x += self.contents.text_size(c).width
end
end
end
def update
super
end
def setskin(name)
@windowskin_name = name
self.windowskin = RPG::Cache.windowskin(@windowskin_name)
end
def settext(text)
@texxt = text
end
def gettext
return @texxt
end
end
复制代码
作者:
david50407
时间:
2010-11-16 14:20
于是自顶防淹没 + 补充
表示如果有人写的话就会 +分分
看禾西的时间应该是之前写的吧
没想到竟然会在这揭露出来 (大惊
感谢fux2的高亮亮~~
表示先预订 Window_Gold 之类的简单类
因为想做简单Window的整合扩充
预计是WShow.new(:gold, :time) 之类的方法
也整合鼠标如何? (笑
(设置个啥默认关闭就好)
作者:
david50407
时间:
2010-11-20 14:55
本帖最后由 david50407 于 2010-11-20 14:55 编辑
#==============================================================================
# ■ WShow
#------------------------------------------------------------------------------
# 显示特定值的视窗。
#==============================================================================
class WShow < Window_Base
#--------------------------------------------------------------------------
# ● 初始化视窗
#--------------------------------------------------------------------------
def initialize(*args)
if args[0].is_a?(Hash)
width = args[0][:width]
height = args[0][:height]
args.shift
end
@kinds = args
width = 160 if width.nil?
height = 32 * args.length + 32 if height.nil?
super(0, 0, width, height)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# ● 更新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
x = 4
y = 0
for c in @kinds
case c
when :gold
cx = contents.text_size($data_system.words.gold).width
self.contents.font.color = normal_color
self.contents.draw_text(x, y, width - cx - 42, 32, $game_party.gold.to_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(width - 36 - cx, y, cx, 32, $data_system.words.gold, 2)
y += 32
when :playtime
self.contents.font.color = system_color
self.contents.draw_text(x, y, width - 40, 32, "游戏时间")
@total_sec = Graphics.frame_count / Graphics.frame_rate
hour = @total_sec / 60 / 60
min = @total_sec / 60 % 60
sec = @total_sec % 60
text = sprintf("%02d:%02d:%02d", hour, min, sec)
self.contents.font.color = normal_color
self.contents.draw_text(x, y + 32, width - 40, 32, text, 2)
y += 64
when :steps
self.contents.font.color = system_color
self.contents.draw_text(x, y, 120, 32, "步数")
self.contents.font.color = normal_color
self.contents.draw_text(x, y + 32, 120, 32, $game_party.steps.to_s, 2)
y += 64
end
end
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
if @kinds.include?(:playtime)
if Graphics.frame_count / Graphics.frame_rate != @total_sec
refresh
end
end
end
end
复制代码
用法...
@window = WShow.new({:height => 128 + 32}, :steps, :gold)
第一个参数可以是Hash {:height => 128, :width => 180}
也可以不是
剩下的参数是 :steps :gold :playtime
作者:
orochi2k
时间:
2010-11-20 14:57
其实我疯狂地想在update和refresh那种东西里加EVAL……
然后再给个@属性的东西里塞上要EVAL的东西
然后从此就彻底成万用型诡异物了……
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1