#==============================================================================
# ■ VX Ace窗口样式 by SailCat
#------------------------------------------------------------------------------
# 本脚本令XP拥有和VA完全一样的窗口外观。
# 功能:
# 1. 支持VA的窗口式样,包括边框(通过皮肤实现)、底色、扫描水印
# 2. 支持RGSS3的窗口色调改变功能
# 3. 支持RGSS3的窗口开闭效果
# 4. 保留XP特有的窗口皮肤平铺功能(VA只能拉伸)
# 5. 窗口色调支持不同窗口个别调整和灰度变化(RGSS3不支持)
# 6. 扫描水印不喜欢可以关掉(RGSS3关不掉,只能改皮肤)
# 使用方法:
# 1. 插入本脚本到Main前面
# 2. 下载002-VXAce.png并放到Windowskins文件夹
# 你当然也可以用你自己喜欢的XP皮肤或默认皮肤
# 3. (可选)如果要替换VA默认的扫描线效果,制作一个水印放到Pictures文件夹,
# 更改相应设置即可,窗口水印的大小没要求,附件的Scanline为VA默认效果
# 4. 调整窗口的色调:
# 全局调整:使用$game_system.window_tone = Tone.new(r, g, b, gray)
# 个别调整:使用window.tone = Tone.new(r, g, b, gray)
# 或者window.tone.set(r, g, b, gray)
# 5. 窗口的开闭效果:
# window.openness = x (x为0-255) 设置打开度,0为完全关,255为完全开
# window.open或window.close,在相应的Scene的update里调用
# 6. 其他设定见下面的参数表
#==============================================================================
class Window_Base < Window
# 如果你更改了分辨率请更改下面的两个值
SCREEN_W = 640
SCREEN_H = 480
# 如果不要扫描线把下面改为false
SCANLINE_EFFECT = true
# 如果更改VA默认的扫描线效果,把下面改为扫描线的文件名(放在Pictures文件夹)
SCANLINE_FILENAME = ""
# 窗口垂直打开为false,水平打开为true
OPEN_HORZ = false
# 窗口垂直关闭为false, 水平关闭为true
CLOSE_HORZ = false
# 窗口的默认色调
DEFAULT_TONE = Tone.new(-34, 0, 68, 0)
#==============================================================================
alias sailcat_dispose dispose unless method_defined?(:sailcat_dispose)
alias sailcat_back_opacity= back_opacity= unless method_defined?(:sailcat_back_opacity=)
alias sailcat_update update unless method_defined?(:sailcat_update)
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :tone # 窗口的色调
attr_reader :openness # 窗口的开启程度
#--------------------------------------------------------------------------
# ● 初始化对像
# x : 窗口的 X 坐标
# y : 窗口的 Y 坐标
# width : 窗口的宽
# height : 窗口的宽
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super()
@windowskin_name = $game_system.windowskin_name
self.windowskin = RPG::Cache.windowskin(@windowskin_name)
@back_sprite = Sprite.new
@back_sprite.ox = 0
@back_sprite.oy = 0
@scan_sprite = Sprite.new
@scan_sprite.ox = 0
@scan_sprite.oy = 0
@scan_sprite.visible = true
@opening = false
@closing = false
@real_x = x
@real_y = y
@real_width = width
@real_height = height
self.x = x
self.y = y
self.width = width
self.height = height
self.z = 100
self.sailcat_back_opacity = 0
self.back_opacity = 192
self.tone = $game_system.window_tone.clone
draw_background
self.scanline = SCANLINE_EFFECT
end
def tone=(tone)
@tone = tone
@back_sprite.tone = tone
@scan_sprite.tone = tone
end
def update_open
self.openness += 24
@opening = false if open?
end
def open?
@openness == 255
end
def open
@opening = true unless open?
@closing = false
end
def update_close
self.openness -= 24
@closing = false if close?
end
def close?
@openness == 0
end
def close
@closing = true unless close?
@opening = false
end
def draw_background
if stretch
@back_sprite.bitmap = self.windowskin
@back_sprite.src_rect = Rect.new(0, 0, 128, 128)
@back_sprite.zoom_x = (width - 4) / 128.0
@back_sprite.zoom_y = (height - 4) / 128.0
else
@back_sprite.bitmap = @tiled_bitmap
@back_sprite.src_rect = Rect.new(0, 0, width - 4, height - 4)
@back_sprite.zoom_x = 1.0
@back_sprite.zoom_y = 1.0
end
end
def draw_scanline
return if self.scanline == false or @scan_bitmap != nil
if SCANLINE_FILENAME == ""
@scan_bitmap = Bitmap.new(SCREEN_W - 4, SCREEN_H - 4)
for i in 0..((SCREEN_H - 5) / 2)
@scan_bitmap.fill_rect(0, i * 2 + 1, SCREEN_W - 4, 1, Color.new(5, 5, 5, 40))
end
else
bmp = RPG::Cache.picture(SCANLINE_FILENAME)
@scan_bitmap = Bitmap.new(SCREEN_W - 4, SCREEN_H - 4)
for i in 0..((SCREEN_W - 5) / bmp.width)
for j in 0..((SCREEN_H - 5) / bmp.height)
@scan_bitmap.blt(i * bmp.width, j * bmp.height, bmp, Rect.new(0, 0, bmp.width, bmp.height))
end
end
end
@scan_sprite.bitmap = @scan_bitmap
@scan_sprite.src_rect = Rect.new(0, 0, width - 4, height - 4)
@scan_sprite.zoom_x = 1.0
@scan_sprite.zoom_y = 1.0
end
def dispose
sailcat_dispose
@back_sprite.dispose
@tiled_bitmap.dispose
@scan_sprite.dispose
@scan_bitmap.dispose
end
def back_opacity
return @back_sprite.opacity
end
def back_opacity=(value)
@back_sprite.opacity = value
@scan_sprite.opacity = value
end
def x=(x)
@real_x = x
super
@back_sprite.x = x + 2
@scan_sprite.x = x + 2
end
def y=(y)
@real_y = y
super
@back_sprite.y = y + 2
@scan_sprite.y = y + 2
end
def z=(z)
super
@back_sprite.z = z - 2
@scan_sprite.z = z - 1
end
def width=(width)
@real_width = width
super
if stretch
@back_sprite.zoom_x = (width - 4) / 128.0
else
@back_sprite.src_rect = Rect.new(0, 0, width - 4, height - 4)
end
@scan_sprite.src_rect = Rect.new(0, 0, width - 4, height - 4)
end
def height=(height)
@real_height = height
super
if stretch
@back_sprite.zoom_y = (height - 4) / 128.0
else
@back_sprite.src_rect = Rect.new(0, 0, width - 4, height - 4)
end
@scan_sprite.src_rect = Rect.new(0, 0, width - 4, height - 4)
end
def visible=(visible)
super
@back_sprite.visible = visible
@scan_sprite.visible = visible
end
def stretch=(stretch)
if stretch != self.stretch
super
@back_sprite.bitmap.dispose if stretch
draw_background
end
end
def scanline
@scan_sprite.visible
end
def scanline=(scanline)
@scan_sprite.visible = scanline
draw_scanline
end
def windowskin=(windowskin)
super
unless @tiled_bitmap.nil? or @tiled_bitmap.disposed?
@tiled_bitmap.dispose
end
@tiled_bitmap = Bitmap.new(SCREEN_W - 4, SCREEN_H - 4)
for i in 0..4
for j in 0..4
@tiled_bitmap.blt(i * 128, j * 128, self.windowskin,
Rect.new(0, 0, 128, 128))
end
end
draw_background unless @back_sprite.nil?
end
def update
sailcat_update
update_open if @opening
update_close if @closing
end
def openness=(openness)
last_x = @real_x
last_y = @real_y
last_w = @real_width
last_h = @real_height
@openness = [[openness, 255].min, 0].max
if OPEN_HORZ
self.x = last_x + (last_w / 2) * (255 - @openness) / 255
self.width = last_w * @openness / 255
self.ox = self.x - last_x
@real_x = last_x
@real_width = last_w
else
self.y = last_y + (last_h / 2) * (255 - @openness) / 255
self.height = last_h * @openness / 255
self.oy = self.y - last_y
@real_y = last_y
@real_height = last_h
end
self.contents_opacity = @openness
end
end
class Game_System
#--------------------------------------------------------------------------
# ● 取得窗口的色调
#--------------------------------------------------------------------------
def window_tone
# 返回窗口的色调,未设置返回默认值
@window_tone.nil? ? (@window_tone = Window_Base::DEFAULT_TONE) : @window_tone
end
#--------------------------------------------------------------------------
# ● 设置窗口的色调
# value : 色调值,传入错误的参数不会更改色调
#--------------------------------------------------------------------------
def window_tone=(value)
@window_tone = value if value.is_a?(Tone)
end
end