#============================================================================== # ★ ウィンドウ画像生成 ver1.0 by USK #------------------------------------------------------------------------------ # ・任意サイズのウィンドウ画像のPNGファイルを生成します。 #============================================================================== =begin ・新規プロジェクトにこのスクリプトを導入し、ゲームを起動するとウィンドウサイズ  の入力が始まります。入力したサイズのウィンドウ画像がゲームフォルダに生成され  ます。 ・生成されるウィンドウはGraphics/SystemフォルダにあるWindow.pngから生成されます。 =end #============================================================================== # ■ Scene_Title #============================================================================== class Scene_Title #-------------------------------------------------------------------------- # ● 開始処理 #-------------------------------------------------------------------------- def start super SceneManager.clear command_new_game end #-------------------------------------------------------------------------- # ● 終了処理 #-------------------------------------------------------------------------- def terminate super end #-------------------------------------------------------------------------- # ● コマンド[ニューゲーム] #-------------------------------------------------------------------------- def command_new_game DataManager.setup_new_game $game_map.autoplay SceneManager.goto(Scene_Map) end end #============================================================================== # ■ Scene_Map #============================================================================== class Scene_Map #-------------------------------------------------------------------------- # ● 開始後処理 #-------------------------------------------------------------------------- def post_start super $data_common_events[1] = RPG::CommonEvent.new $data_common_events[1].trigger = 1 command = RPG::EventCommand.new(101,0,["",0,0,2]) $data_common_events[1].list << command command = RPG::EventCommand.new(401,0,["ウィンドウの横幅を入力(32〜640)"]) $data_common_events[1].list << command command = RPG::EventCommand.new(401,0,["終了する場合は 000 を入力"]) $data_common_events[1].list << command command = RPG::EventCommand.new(103,0,[1, 3]) $data_common_events[1].list << command command = RPG::EventCommand.new(101, 0, ["",0,0,2]) $data_common_events[1].list << command command = RPG::EventCommand.new(401,0,["ウィンドウの縦幅を入力(32〜480)"]) $data_common_events[1].list << command command = RPG::EventCommand.new(103,0,[2, 3]) $data_common_events[1].list << command command = RPG::EventCommand.new(999,0,[]) $data_common_events[1].list << command command = RPG::EventCommand.new(101, 0, ["",0,0,2]) $data_common_events[1].list << command command = RPG::EventCommand.new(401,0,["ゲームフォルダに画像が生成されました"]) $data_common_events[1].list << command $data_common_events[1].list << RPG::EventCommand.new $game_switches[1] = true end end #============================================================================== # ■ Game_Variables #============================================================================== class Game_Variables #-------------------------------------------------------------------------- # ● 変数の設定時の処理 #-------------------------------------------------------------------------- def on_change exit if @data[1] == 0 $game_map.need_refresh = true end end #============================================================================== # ■ #============================================================================== class Game_Interpreter #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def command_999 exit if $game_variables[1] == 0 create_window($game_variables[1], $game_variables[2]) create_file Graphics.wait(120) @window.dispose end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def create_window(w, h) w = [640, [w, 32].max].min h = [480, [h, 32].max].min bmp = Cache.system("Window") @window = Sprite.new @window.ox = w >> 1 @window.oy = h >> 1 @window.x = Graphics.width >> 1 @window.y = Graphics.height >> 1 @window.z += 100 wb = @window.bitmap = Bitmap.new(w, h) back = Bitmap.new(w - 4, h - 4) back.stretch_blt(back.rect, bmp, Rect.new(0, 0, 64, 64)) x = y = 0 back.blur while y < back.height while x < back.width back.blt(x, y, bmp, Rect.new(0, 64, 64, 64)) x += 64 end x = 0 y += 64 end back.height.times do |y| back.width.times do |x| c = back.get_pixel(x, y) c.red += $game_system.window_tone.red c.red = [c.red, 0].max c.green += $game_system.window_tone.green c.green = [c.green, 0].max c.blue += $game_system.window_tone.blue c.blue = [c.blue, 0].max back.set_pixel(x, y, c) end end wb.blt(2, 2, back, back.rect, 192) wb.blt( 0, 0, bmp, Rect.new( 64, 0, 16, 16)) wb.blt(w - 16, 0, bmp, Rect.new(112, 0, 16, 16)) wb.blt( 0, h - 16, bmp, Rect.new( 64, 48, 16, 16)) wb.blt(w - 16, h - 16, bmp, Rect.new(112, 48, 16, 16)) x = y = 16 ww, hh = w - 32, h - 32 while ww > 32 wb.blt(x, 0, bmp, Rect.new(80, 0, 32, 16)) wb.blt(x, h - 16, bmp, Rect.new(80, 48, 32, 16)) ww -= 32 x += 32 end if ww > 0 wb.blt(x, 0, bmp, Rect.new(80, 0, ww, 16)) wb.blt(x, h - 16, bmp, Rect.new(80, 48, ww, 16)) end while hh > 32 wb.blt( 0, y, bmp, Rect.new( 64, 16, 16, 32)) wb.blt(w - 16, y, bmp, Rect.new(112, 16, 16, 32)) hh -= 32 y += 32 end if hh > 0 wb.blt( 0, y, bmp, Rect.new( 64, 16, 16, 32)) wb.blt(w - 16, y, bmp, Rect.new(112, 16, 16, 32)) end end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def create_file name = sprintf("%dx%d.png", @window.width, @window.height) Snap.snapshot(@window.bitmap, name) end end #============================================================================== # ■ Snap #============================================================================== module Snap #-------------------------------------------------------------------------- # ● カスタマイズ #-------------------------------------------------------------------------- DIR_NAME = "" DEFAULT_NAME = "%s.png" #-------------------------------------------------------------------------- # ● スナップショットの作成 #-------------------------------------------------------------------------- def self.snapshot(snap, name) begin filename = add_extension(name) data = make_png(snap) fw = File.open(filename, "wb") fw.write(data) fw.close Graphics.frame_reset return true rescue Graphics.frame_reset return false end end #-------------------------------------------------------------------------- # ● PNG用ピクセルデータの取得 #-------------------------------------------------------------------------- def self.get_bmp_for_png(snap) width = snap.width height = snap.height bmp = Array.new(width * height * 4 + height) addr = 0 height.times do |y| bmp[addr] = 0x00 addr += 1 width.times do |x| color = snap.get_pixel(x, y) bmp[addr, 4] = color.red.to_i, color.green.to_i, color.blue.to_i, color.alpha.to_i addr += 4 end end return bmp end #-------------------------------------------------------------------------- # ● 拡張子の付加 #-------------------------------------------------------------------------- def self.add_extension(name) name = DIR_NAME + name bk = name index = 2 while File.exist?(name) name = DIR_NAME + File.basename(bk,".png")+"_"+index.to_s+".png" index += 1 break if index > 10 end return name end #-------------------------------------------------------------------------- # ● PNGの作成 #-------------------------------------------------------------------------- def self.make_png(snap) bmp = get_bmp_for_png(snap) data = PNG.make_png(snap.width, snap.height, bmp) end end #============================================================================== # ■ PNG #============================================================================== module PNG #-------------------------------------------------------------------------- # ● 定数 #-------------------------------------------------------------------------- SIGN = "\x89PNG\r\n\x1a\n".unpack("C*") IHDR = "IHDR".unpack("C*") IDAT = "IDAT".unpack("C*") IEND = "IEND".unpack("C*") #-------------------------------------------------------------------------- # ● crc32 #-------------------------------------------------------------------------- def self.crc32(buf) crc = Zlib.crc32(buf.pack("C*")) return crc end #-------------------------------------------------------------------------- # ● deflate #-------------------------------------------------------------------------- def self.deflate(data) level = Zlib::BEST_COMPRESSION ret = Zlib::Deflate.deflate(data.pack("C*"), level) return ret.unpack("C*") end #-------------------------------------------------------------------------- # ● IHDR #-------------------------------------------------------------------------- def self.make_header(width, height) tag = IHDR body = get_bytes(width) + get_bytes(height) body += [0x08, 0x06, 0x00, 0x00, 0x00] return make_chunk(tag, body) end #-------------------------------------------------------------------------- # ● IDAT #-------------------------------------------------------------------------- def self.make_data(data) tag = IDAT body = deflate(data) return make_chunk(tag, body) end #-------------------------------------------------------------------------- # ● IEND #-------------------------------------------------------------------------- def self.make_edf() tag = IEND body = [] return make_chunk(tag, body) end #-------------------------------------------------------------------------- # ● chunk #-------------------------------------------------------------------------- def self.make_chunk(tag, body) length = get_bytes(body.size) body = tag + body crc = get_bytes(crc32(body)) chunk = length + body + crc return chunk end #-------------------------------------------------------------------------- # ● ビッグエンディアンバイト配列生成 #-------------------------------------------------------------------------- def self.get_bytes(n) return [n].pack("N").unpack("C*") end #-------------------------------------------------------------------------- # ● png #-------------------------------------------------------------------------- def self.make_png(width, height, buf) header = make_header(width, height) data = make_data(buf) edf = make_edf return (SIGN + header + data + edf).pack("C*") end end