#----------------------------------------------------------------------------
# ● 无限图层显示系统 Unlimited Layers Display System By Taroxd
# XP移植 By RyanBern
#----------------------------------------------------------------------------
#
# 使用方法:导入此脚本后,在Data/ULDS.txt上(没有的话新建一个,编码方式选择
# UTF-8)编写如下内容。
#
#
#
# x: X坐标(公式,默认为 0)
# y: Y坐标(公式,默认为 0)
# z: Z坐标(整数,默认为 10,可以设置为 -100 来当作远景图使用)
# zoom: 缩放倍率(公式,默认为 1。缩放的原点为画面左上角。)
# zoom_x: 横向缩放倍率(公式,默认为 zoom)
# zoom_y: 纵向缩放倍率(公式,默认为 zoom)
# opacity: 不透明度(公式,默认为 255)
# blend_type: 合成方式(0、1、2,默认为 0)(0:正常、1:加法、2:减法)
# scroll: 跟随地图卷动的速度(实数,默认为 32。)
# scroll_x: 跟随地图横向卷动的比率(整数,远景图的比率为8,地图块的比率为4)
# scroll_y:跟随地图纵向卷动的比率(整数,远景图的比率为8,地图块的比率为4)
# loop:(循环。冒号后面不需要填写任何东西。)
# visible: 图片是否显示(公式,默认为 true)
# path: 图片的路径名(默认为 Panoramas)
# update: 图片显示时,每帧执行的更新代码(公式,默认为 @t += 1)
#
#
#
# 第一行和最后一行表示你的 ULDS 要铺在哪个地图上,填写地图 ID 即可。
#
# 其中 filename 是图片文件名(无需扩展名),放入 Panoramas 文件夹内
# 这个文件夹可以通过 path 设置更改
#
# 在 和 中间的部分均为选填。不填则自动设为默认值。
# 每一个设置项只能写一行。
# 每一行只能写一个设置项。
# 一般来说,正常使用时大部分都是不需要设置的。
#
# 设置项目中的“公式”表示,这一个设置项可以像技能的伤害公式一样填写。
# 可用 @t 表示当前已经显示的帧数,s[n], v[n] 分别表示 n 号开关和 n 号变量。
#
#----------------------------------------------------------------------------
# z 坐标详解:【-100】远景图
# 【0】最低图块层、在普通角色下方
# 【1000】在所有事件的上方(无论是不是[总在前面显示])
#----------------------------------------------------------------------------
# 更新记录(for VA):
# 2014.07.10 Ver1.01: 修正了 zoom、zoom_y 会报错的问题
# 2014.07.11 Ver1.02: 修正了切换图块组之后失效的问题
# 2014.08.14 Ver1.1: 增加了 speed_x, speed_y 的设置
# 2014.08.16 Ver1.2: fix 设定更改为 scroll
# 2014.08.29 Ver1.21: 修正了坐标误差
# 2014.09.19 Ver1.22: 修正了远景图与图层使用相同文件时报错的问题
# 2014.09.25 Ver2.0: 属性可以用公式进行设置了
# 2014.09.26 Ver2.01: 增加了 path、update 的设置
# 更新记录(for XP):
# 如果发现了BUG请通知我
#----------------------------------------------------------------------------
module Taroxd end
class Taroxd::ULDS
DEFAULT_PATH = 'Panoramas' # 图片文件的默认路径
DEFAULT_Z = 10 # 默认的 z 值
RE_OUTER = /(.*?)<\/ulds>/mi # 读取备注用的正则表达式
RE_INNER = /(\S+) *: *(.*)/ # 读取设置用的正则表达式
FILE_NAME = "Data/ULDS.txt"
include Math
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def initialize(settings, viewport = nil)
@settings = settings
init_picture(viewport)
init_const_attributes
update
end
#--------------------------------------------------------------------------
# ● 释放
#--------------------------------------------------------------------------
def dispose
@holder.bitmap.dispose
@holder.dispose
end
def update
s = $game_switches
v = $game_variables
visible = true
eval update_visibility_code
return unless visible
eval update_position_code 'x'
eval update_position_code 'y'
eval update_attribute_code 'zoom_x'
eval update_attribute_code 'zoom_y'
eval update_attribute_code 'opacity'
eval update_time_code
end
#--------------------------------------------------------------------------
# ● 私有方法
#--------------------------------------------------------------------------
private
#--------------------------------------------------------------------------
# ● 初始化图片
#--------------------------------------------------------------------------
def init_picture(viewport)
@holder = (extract('loop') ? Plane : Sprite).new(viewport)
filename = "Graphics/#{extract('path', DEFAULT_PATH)}/#{extract('name')}"
@holder.bitmap = Bitmap.new(filename)
end
#--------------------------------------------------------------------------
# ● 初始化属性(常数)
#--------------------------------------------------------------------------
def init_const_attributes
@holder.z = extract('z', DEFAULT_Z).to_i
@scroll_x = extract('scroll_x', 4).to_i
@scroll_y = extract('scroll_y', 4).to_i
@holder.blend_type = extract('blend_type', 0).to_i
@t = 0
end
#--------------------------------------------------------------------------
# ● 更新位置的代码
#--------------------------------------------------------------------------
def update_position_code(key)
formula = extract(key)
formula = formula == nil ? "" : " - (#{formula})"
return "@holder.o#{key} = $game_map.display_#{key} / @scroll_#{key}#{formula}"
end
#--------------------------------------------------------------------------
# ● 更新属性的代码
#--------------------------------------------------------------------------
def update_attribute_code(key)
formula = extract(key)
if formula != nil
return "@holder.#{key} = (#{formula})"
end
return ""
end
#--------------------------------------------------------------------------
# ● 更新是否显示的代码
#--------------------------------------------------------------------------
def update_visibility_code
formula = extract('visible')
if formula != nil
return "visible = @holder.visible = (#{formula})"
end
return ""
end
#--------------------------------------------------------------------------
# ● 更新时间的代码
#--------------------------------------------------------------------------
def update_time_code
extract('update', '@t += 1')
end
#--------------------------------------------------------------------------
# ● 获取备注中的设定值
#--------------------------------------------------------------------------
def extract(key, default = nil)
return @settings[key] if @settings.key?(key)
return @settings[$1] if /(.+)_[xy]\Z/ =~ key && @settings.key?($1)
default
end
end
class Game_Map
#--------------------------------------------------------------------------
# ● 获取地图的图片设置
#--------------------------------------------------------------------------
def ulds_settings
if FileTest.exist?(Taroxd::ULDS::FILE_NAME)
file = File.open(Taroxd::ULDS::FILE_NAME, "r")
str = file.read
file.close
re = /(.*?)<\/mapid>/mi
if re === str
str = $2
return str.scan(Taroxd::ULDS::RE_OUTER)
else
return []
end
else
return []
end
end
end
class Spriteset_Map
#==========================================================================
# 方法接入
#==========================================================================
alias rb_initialize_20141108 initialize
def initialize
rb_initialize_20141108
create_ulds
end
alias rb_update_20141108 update
def update
update_ulds
rb_update_20141108
end
alias rb_dispose_20141108 dispose
def dispose
dispose_ulds
rb_dispose_20141108
end
#--------------------------------------------------------------------------
# ● 创建图片
#--------------------------------------------------------------------------
def create_ulds
@ulds = $game_map.ulds_settings.map do |(name, contents)|
param = contents.scan(Taroxd::ULDS::RE_INNER)
settings = {}
param.each do |p|
settings[p[0]] = p[1]
end
settings['name'] = name
settings.each_value{|s| s.chomp!}
Taroxd::ULDS.new(settings, @viewport1)
end
@ulds_map_id = $game_map.map_id
end
#--------------------------------------------------------------------------
# ● 刷新图片
#--------------------------------------------------------------------------
def refresh_ulds
dispose_ulds
create_ulds
end
#--------------------------------------------------------------------------
# ● 更新图片
#--------------------------------------------------------------------------
def update_ulds
return if @ulds.nil?
refresh_ulds if @ulds_map_id != $game_map.map_id
@ulds.each{|u| u.update}
end
#--------------------------------------------------------------------------
# ● 释放图片
#--------------------------------------------------------------------------
def dispose_ulds
@ulds.each{|u| u.dispose} if @ulds != nil
end
end