#============================================================================== # ■ VXAce-RGSS3-18 ギャラリー [Ver.1.0.1] by Claimh #------------------------------------------------------------------------------ # 写真を表示するギャラリーを作ります # なお、ギャラリーの管理情報は全セーブデータで共通となります。 #------------------------------------------------------------------------------ # ●ギャラリー全体の表示許可 # DataManager.garally.enable = true # ●写真の表示許可 # DataManager.garally[id] = true # ●写真の追加(LIST以外のスナップショットなどを追加) # DataManager.garally.push(id, GFile.new(filename, text)) # ●イベント等から呼び出す # SceneManager.call(Scene_ExGarally) #============================================================================== class GFile attr_reader :name attr_reader :text def initialize(filename, text="") @name = filename; @text = text end end module ExGarally # 写真の設定 LIST = { # ID => GFile.new("ファイル名(Graphics/Pictures)", 表示文字) 1 => GFile.new("BlueSky", "青い空\n改行"), 2 => GFile.new("CloudySky1", "曇った空"), 3 => GFile.new("CloudySky2"), 4 => GFile.new("DarkSpace1"), 5 => GFile.new("DarkSpace2"), 6 => GFile.new("Mountains1"), 7 => GFile.new("Mountains2"), 8 => GFile.new("Mountains3"), 9 => GFile.new("Mountains4"), 10 => GFile.new("Mountains5"), 12 => GFile.new("Ocean2"), 11 => GFile.new("Ocean1"), 13 => GFile.new("SeaofClouds"), 14 => GFile.new("StarlitSky"), # 15 => GFile.new("Sunset"), } # ヘルプウィンドウの行数(1〜3) HELP_LINES = 2 end #============================================================================== # ■ ExGarally #============================================================================== module ExGarally #-------------------------------------------------------------------------- # ● ギャラリーの表示有効? #-------------------------------------------------------------------------- def self.enable? DataManager.garally.enable end #-------------------------------------------------------------------------- # ● ファイル名 #-------------------------------------------------------------------------- def self.filename "exgallary.rvdata2" end #-------------------------------------------------------------------------- # ● セーブの実行 #-------------------------------------------------------------------------- def self.save_exdata(obj) save_data(obj, filename) end #-------------------------------------------------------------------------- # ● ロードの実行 #-------------------------------------------------------------------------- def self.load_exdata exist? ? load_data(filename) : Game_ExGarallyList.new end #-------------------------------------------------------------------------- # ● ファイル削除 #-------------------------------------------------------------------------- def self.delete_exdata return unless exist? File.delete(filename) rescue nil end #-------------------------------------------------------------------------- # ● ファイルの有無チェック #-------------------------------------------------------------------------- def self.exist? FileTest.exist?(filename) end end #============================================================================== # ■ DataManager #============================================================================== class << DataManager #-------------------------------------------------------------------------- # ● 各種ゲームオブジェクトの作成 #-------------------------------------------------------------------------- alias create_game_objects_exgrly create_game_objects def create_game_objects create_game_objects_exgrly load_garally end #-------------------------------------------------------------------------- # ● セーブの実行 #-------------------------------------------------------------------------- alias save_game_exgarally save_game def save_game(index) r = save_game_exgarally(index) save_garally if r r end #-------------------------------------------------------------------------- # ● ロードの実行 #-------------------------------------------------------------------------- alias load_game_exgrly load_game def load_game(index) r = load_game_exgrly(index) load_garally if r r end #-------------------------------------------------------------------------- # ● ギャラリー情報load #-------------------------------------------------------------------------- def load_garally @exgarally = ExGarally.load_exdata end #-------------------------------------------------------------------------- # ● ギャラリー情報load #-------------------------------------------------------------------------- def save_garally ExGarally.save_exdata(@exgarally) end #-------------------------------------------------------------------------- # ● ギャラリー情報削除 #-------------------------------------------------------------------------- def delete_garally ExGarally.delete_exdata load_garally end #-------------------------------------------------------------------------- # ● ギャラリー情報参照 #-------------------------------------------------------------------------- def garally @exgarally end end #============================================================================== # ■ Game_ExGarally #============================================================================== class Game_ExGarally attr_accessor :name # ファイル名 attr_accessor :text # 表示文字 attr_accessor :enable # 表示可否 #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(file, enable=false) @name = file.name @text = file.text @enable = enable end end #============================================================================== # ■ Game_ExGarallyList : DataManager.garallyで参照可能 #============================================================================== class Game_ExGarallyList LIST = ExGarally::LIST attr_accessor :enable attr_reader :size #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize clear end #-------------------------------------------------------------------------- # ● クリア #-------------------------------------------------------------------------- def clear @size = LIST.size @data = {} @enable = false end #-------------------------------------------------------------------------- # ● 参照 #-------------------------------------------------------------------------- def [](id) return nil if LIST[id].nil? and @data[id].nil? @data[id] = Game_ExGarally.new(LIST[id]) if @data[id].nil? @data[id] end #-------------------------------------------------------------------------- # ● 表示許可/禁止 #-------------------------------------------------------------------------- def []=(id, val) return nil if LIST[id].nil? and @data[id].nil? if val @data[id] = Game_ExGarally.new(LIST[id]) if @data[id].nil? @data[id].enable = true elsif !@data[id].nil? @data.delete(id) end end #-------------------------------------------------------------------------- # ● リスト #-------------------------------------------------------------------------- def list (@data.keys+LIST.keys).uniq.sort.collect {|id| self.[](id) } end #-------------------------------------------------------------------------- # ● 追加ギャラリー #-------------------------------------------------------------------------- def push(id, name, enable=true) @data[id] = Game_ExGarally.new(name, enable) @size += 1 if LIST[id].nil? end end #============================================================================== # ■ Sprite_ExGrlyPicture #============================================================================== class Sprite_ExGrlyPicture < Sprite #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(rect=Rect.new(0,0,Graphics.width,Graphics.height)) super(Viewport.new(rect)) viewport.z = 100 create_bitmap end #-------------------------------------------------------------------------- # ● オブジェクト解放 #-------------------------------------------------------------------------- def dispose dispose_bitmap super end #-------------------------------------------------------------------------- # ● ビットマップ生成 #-------------------------------------------------------------------------- def create_bitmap self.bitmap = Bitmap.new(vw, vh) end #-------------------------------------------------------------------------- # ● ビットマップ下方 #-------------------------------------------------------------------------- def dispose_bitmap self.bitmap.dispose end #-------------------------------------------------------------------------- # ● ピクチャ設定 #-------------------------------------------------------------------------- def picture(filename, enabled=true) dispose_bitmap if enabled self.bitmap = Cache.picture(filename) else create_bitmap self.bitmap.fill_rect(0,0,vw,vh,Color.new(0,0,0,160)) # self.bitmap.draw_text(0,0, vw, vh, filename, 1) end fit_screen resize end #-------------------------------------------------------------------------- # ● ズーム倍率再設定 #-------------------------------------------------------------------------- def resize(r=Rect.new(0,0,vw,vh)) self.ox = bitmap.width / 2 self.oy = bitmap.height / 2 self.x = r.width / 2 + r.x self.y = r.height / 2 + r.y end #-------------------------------------------------------------------------- # ● 画面にフィットさせる #-------------------------------------------------------------------------- def bwz; (bitmap.width * zoom_x).truncate; end # ズーム後のbitmap幅 def bhz; (bitmap.height* zoom_y).truncate; end # ズーム後のbitmap高さ def vw; viewport.rect.width; end def vh; viewport.rect.height; end def fit_screen(w=vw, h=vh) x_zoom = w * 1.0 / bitmap.width y_zoom = h * 1.0 / bitmap.height zoom = x_zoom < y_zoom ? x_zoom : y_zoom self.zoom_x = self.zoom_y = zoom end end #============================================================================== # ■ Sprite_ExGrlyPicture #============================================================================== class Sprite_ExGrlyPictFull < Sprite_ExGrlyPicture #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize super hide.viewport.z = 200 end #-------------------------------------------------------------------------- # ● ウィンドウの表示 #-------------------------------------------------------------------------- def show self.visible = true self end #-------------------------------------------------------------------------- # ● ウィンドウの非表示 #-------------------------------------------------------------------------- def hide self.visible = false self end #-------------------------------------------------------------------------- # ● ピクチャ設定 #-------------------------------------------------------------------------- def picture(filename, enabled=true) dispose_bitmap b = Cache.picture(filename) r = Rect.new(0, 0, b.width, b.height) self.bitmap = Bitmap.new(r.width, r.height) self.bitmap.stretch_blt(r, b, r) fit_screen resize end end #============================================================================== # ■ Grly_Thumbnail #============================================================================== class Grly_Thumbnail attr_reader :item attr_reader :rect #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(item, rect) @item = item; @rect = rect end end #============================================================================== # ■ SpritesetExGrlyPictures #============================================================================== class SpritesetExGrlyPictures #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize @sprites = [] end #-------------------------------------------------------------------------- # ● オブジェクト解放 #-------------------------------------------------------------------------- def dispose dispose_sprites end #-------------------------------------------------------------------------- # ● ピクチャスプライト生成 #-------------------------------------------------------------------------- def create_sprites(thumnails) thumnails.each do |thm| s = Sprite_ExGrlyPicture.new(thm.rect) s.picture(thm.item.name, thm.item.enable) @sprites.push(s) end end #-------------------------------------------------------------------------- # ● ピクチャスプライト解放 #-------------------------------------------------------------------------- def dispose_sprites @sprites.each { |s| s.dispose } end #-------------------------------------------------------------------------- # ● ピクチャスプライト更新 #-------------------------------------------------------------------------- def update_sprites(thumnails) dispose_sprites create_sprites(thumnails) end #-------------------------------------------------------------------------- # ● サムネイル矩形 #-------------------------------------------------------------------------- def thm_rect(i) @sprites[i].nil? ? nil : @sprites[i].thm end end #============================================================================== # ■ Window_GrlyPicture #============================================================================== class Window_GrlyPicture < Window_Selectable attr_accessor :thum_sprites #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize @thum_sprites = nil make_list super(0, help_height, Graphics.width, Graphics.height-help_height) activate end #-------------------------------------------------------------------------- # ● ヘルプウィンドウの高さ #-------------------------------------------------------------------------- def help_height fitting_height(ExGarally::HELP_LINES) end #-------------------------------------------------------------------------- # ● 桁数の取得 #-------------------------------------------------------------------------- def col_max return 3 end #-------------------------------------------------------------------------- # ● 横に項目が並ぶときの空白の幅を取得 #-------------------------------------------------------------------------- def spacing return 16 end #-------------------------------------------------------------------------- # ● 項目数の取得 #-------------------------------------------------------------------------- def item_max DataManager.garally.size end #-------------------------------------------------------------------------- # ● 項目の高さを取得 #-------------------------------------------------------------------------- def item_height (Graphics.height - help_height - standard_padding * 2) / 2 end #-------------------------------------------------------------------------- # ● 項目を描画する矩形の取得 #-------------------------------------------------------------------------- def item_rect(index) rect = super(index) thm = calc_thm_rect rect.x += (rect.width - (thm.width + 8)) / 2 rect.y += (rect.height - (thm.height + 8)) / 2 rect.width = thm.width + 8 rect.height = thm.height + 8 rect end #-------------------------------------------------------------------------- # ● サムネイル矩形計算 #-------------------------------------------------------------------------- def calc_thm_rect r = Rect.new r.width = item_width - 8 r.height = item_height - 8 if (Graphics.width / r.width) > (Graphics.height / r.height) r.height = r.width * Graphics.height / Graphics.width else r.width = r.height * Graphics.width / Graphics.height end r end #-------------------------------------------------------------------------- # ● サムネイルの表示位置を取得 #-------------------------------------------------------------------------- def thum_rect(index) r = item_rect_for_text(index) r.x += self.x + standard_padding r.y += self.y + standard_padding r end #-------------------------------------------------------------------------- # ● 先頭行のindex #-------------------------------------------------------------------------- def top_i (top_row * col_max) end #-------------------------------------------------------------------------- # ● 先頭行からの@index #-------------------------------------------------------------------------- def top_cur_i (@index - (top_row * col_max)) end #-------------------------------------------------------------------------- # ● サムネイルの表示位置を取得 #-------------------------------------------------------------------------- def thumnails n = [page_item_max, item_max - top_i].min idxs = [] n.times { |i| idxs.push(i) } idxs.collect { |i| Grly_Thumbnail.new(@list[i+top_i], thum_rect(i)) } end #-------------------------------------------------------------------------- # ● リスト生成 #-------------------------------------------------------------------------- def make_list @list = DataManager.garally.list end #-------------------------------------------------------------------------- # ● 選択中アイテム #-------------------------------------------------------------------------- def item @list[@index] end #-------------------------------------------------------------------------- # ● 選択項目の有効状態を取得 #-------------------------------------------------------------------------- def current_item_enabled? !item.nil? and item.enable end #-------------------------------------------------------------------------- # ● ヘルプテキスト更新 #-------------------------------------------------------------------------- def update_help text = ((!item.nil? and item.enable) ? item.text : "") @help_window.set_text(text) end #-------------------------------------------------------------------------- # ● カーソルの更新 #-------------------------------------------------------------------------- def update_cursor super @thum_sprites.update_sprites(thumnails) unless @thum_sprites.nil? end end #============================================================================== # ■ Scene_ExGarally #============================================================================== class Scene_ExGarally < Scene_Base #-------------------------------------------------------------------------- # ● 開始処理 #-------------------------------------------------------------------------- def start super create_background @help_window = Window_Help.new(ExGarally::HELP_LINES) @thumset = SpritesetExGrlyPictures.new @full_pict = Sprite_ExGrlyPictFull.new create_list_window end #-------------------------------------------------------------------------- # ● 終了処理 #-------------------------------------------------------------------------- def terminate super dispose_background @thumset.dispose @full_pict.dispose end #-------------------------------------------------------------------------- # ● 背景の作成 #-------------------------------------------------------------------------- def create_background @background_sprite = Sprite.new @background_sprite.bitmap = SceneManager.background_bitmap @background_sprite.color.set(16, 16, 16, 128) end #-------------------------------------------------------------------------- # ● 背景の解放 #-------------------------------------------------------------------------- def dispose_background @background_sprite.dispose end #-------------------------------------------------------------------------- # ● ピクチャリストウィンドウ生成 #-------------------------------------------------------------------------- def create_list_window @list_window = Window_GrlyPicture.new @list_window.thum_sprites = @thumset @list_window.help_window = @help_window set_full_handler @list_window.select(0) end #-------------------------------------------------------------------------- # ● フルスクリーン化用のハンドラ登録 #-------------------------------------------------------------------------- def set_full_handler @list_window.set_handler(:ok, method(:cmd_full)) @list_window.set_handler(:cancel, method(:return_scene)) end #-------------------------------------------------------------------------- # ● サムネイルリスト用のハンドラ登録 #-------------------------------------------------------------------------- def set_thum_handler @list_window.set_handler(:ok, method(:cmd_thum)) @list_window.set_handler(:cancel, method(:cmd_thum)) end #-------------------------------------------------------------------------- # ● フルスクリーン化 #-------------------------------------------------------------------------- def cmd_full Graphics.freeze @full_pict.show.picture(@list_window.item.name) perform_transition set_thum_handler @list_window.activate.cursor_fix = true end #-------------------------------------------------------------------------- # ● サムネイル化 #-------------------------------------------------------------------------- def cmd_thum Graphics.freeze @full_pict.hide perform_transition set_full_handler @list_window.activate.cursor_fix = false end end