#=========================================================================
# 行走图转换工具 VA->XP Ver 1.0
#-------------------------------------------------------------------------
# @Author : RyanBern
#-------------------------------------------------------------------------
# 用法:
# 将待转换的 VA 行走图放入工程根目录的 vx_chara_s 文件夹下,并新建一个
# 文件夹 xp_chara_s 用于存放转换好的 XP 行走图。新的行走图文件名会命名
# 为 原行走图_00~原行走图_07.png,必要时请设置横向和纵向格栅数。
# 然后将此脚本插入到 Main 组之前,运行游戏工程,在标题画面按下 Z 键即可
# 进行批量转换。使用完毕后,可以将此脚本删除(附带的MGC_PNG.dll如果用不
# 到也可以删掉)
#=========================================================================
module Char_VA2XP
# VA 行走图文件夹(输入)
Dir_In = "vx_chara_s"
# XP 行走图文件夹(输出)
Dir_Out = "xp_chara_s"
# 横向格栅数(即一张图横向有多少个角色)
NUMS_X = 4
# 纵向格栅数(即一张图纵向有多少个角色)
NUMS_Y = 2
def self.start_covert
$scene = Scene_Char_Convert
end
class Window_Progress < ::Window_Base
def initialize
super(0, 0, 288, 96)
@curr = @tol = 0
self.contents = Bitmap.new(width - 32, height - 32)
self.x = 320 - width / 2
self.y = 240 - height / 2
self.opacity = 0
refresh
end
def refresh
self.contents.clear
refresh_words
refresh_progress
end
def refresh_words
self.contents.draw_text(4, 0, width - 36, 32, "Converting...Please wait...")
end
def refresh_progress
self.contents.fill_rect(0, 32, width - 32, 32, Color.new(0, 0, 0, 0))
self.contents.draw_text(96, 32, 48, 32, @curr.to_s, 2)
self.contents.draw_text(144, 32, 24, 32, "/", 1)
self.contents.draw_text(168, 32, 48, 32, @tol.to_s)
end
def set(curr, tol)
if @curr != curr || @tol != tol
@curr, @tol = curr, tol
refresh_progress
end
end
end
class Scene_Char_Convert
def main
@progress_window = Window_Progress.new
Graphics.transition
start_convert
Graphics.freeze
@progress_window.dispose
print "done"
exit
end
def start_convert
filenames_in = []
unless FileTest.exist?(Dir_Out)
Dir.mkdir(Dir_Out)
end
Dir.foreach(Dir_In) do |s|
filenames_in << s if s != "." && s != ".."
end
tol = NUMS_X * NUMS_Y
curr = 0
@progress_window.set(curr, tol)
Graphics.update
filenames_in.each do |filename|
filename_out_base = filename.split(/\./)[0]
src_bitmap = Bitmap.new(Dir_In + "/" + filename)
(0...tol).each do |i|
w = src_bitmap.width / NUMS_X
h = src_bitmap.height / NUMS_Y
x = i % NUMS_X * w
y = i / NUMS_X * h
out_bitmap = Bitmap.new(w / 3 * 4, h)
src_rect1 = Rect.new(x, y, w, h)
src_rect2 = Rect.new(x + w / 3, y, w / 3, h)
out_bitmap.blt(0, 0, src_bitmap, src_rect2)
out_bitmap.blt(w / 3, 0, src_bitmap, src_rect1)
filename_out = sprintf("%s_%02d.png", filename_out_base, i)
out_bitmap.save_as_png(Dir_Out + "/" + filename_out)
curr += 1
@progress_window.set(curr, tol * filenames_in.size)
Graphics.update
out_bitmap.dispose
end
src_bitmap.dispose
end
end
end
end
class Scene_Title
alias rb_update_20160202 update
def update
if Input.trigger?(Input::A)
$scene = Char_VA2XP::Scene_Char_Convert.new
return
end
rb_update_20160202
end
end
#==============================================================================
# ■ Bitmap
#------------------------------------------------------------------------------
# 关联到Bitmap。
#==============================================================================
class Bitmap
#--------------------------------------------------------------------------
# * Constantes
#--------------------------------------------------------------------------
CREATE_PNG = Win32API.new("MGC_PNG", "createPNG", "ll", "l")
#--------------------------------------------------------------------------
# * Méthode d'appel pour créer un fichier PNG
# chemin : chemin + nom du fichier à créer
#--------------------------------------------------------------------------
def save_as_png(chemin)
unless chemin[/\//] then chemin = './' << chemin end
CREATE_PNG.call(self.__id__, chemin.__id__)
end
end