#=========================================================================== # ◆ A1 Scripts ◆ # ゲームオプション:本体(RGSS3) # # バージョン : 1.00 (2011/12/15) # 作者 : A1 # URL     : http://a1tktk.web.fc2.com/ #--------------------------------------------------------------------------- # 機能: # ・オプション設定の本体 #--------------------------------------------------------------------------- # 更新履歴   :2011/12/15 Ver1.00 リリース #--------------------------------------------------------------------------- # 設置場所 #  RGSS3用A1共通スクリプトより下 # ゲームオプション:設定項目 より下 # # 必要スクリプト # RGSS3用A1共通スクリプト # ゲームオプション:設定項目 #--------------------------------------------------------------------------- # 使い方 # ゲームオプション:設定項目に記述 # 必要があれば別途スクリプトを記述 #============================================================================== $imported ||= {} $imported["A1_GameOptionMain"] = true if $imported["A1_Common_Script"] and $imported["A1_GameOption"] #============================================================================== # ■ DataManager #------------------------------------------------------------------------------ #  データベースとゲームオブジェクトを管理するモジュールです。ゲームで使用する # ほぼ全てのグローバル変数はこのモジュールで初期化されます。 #============================================================================== module DataManager #-------------------------------------------------------------------------- # ○ エイリアス用特異メソッド #-------------------------------------------------------------------------- class << self alias :a1_game_option_create_game_objects :create_game_objects end #-------------------------------------------------------------------------- # ☆ 各種ゲームオブジェクトの作成 #-------------------------------------------------------------------------- def self.create_game_objects a1_game_option_create_game_objects if File.exist?("System/GameOption.rvdata2") $game_option = load_data("System/GameOption.rvdata2") else $game_option = Game_Option.new save_data($game_option, "System/GameOption.rvdata2") end $game_option.put_options end end #============================================================================== # ■ Game_Option #============================================================================== class Game_Option #-------------------------------------------------------------------------- # ○ 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :option_list #-------------------------------------------------------------------------- # ○ オブジェクト初期化 #-------------------------------------------------------------------------- def initialize @option_list = {} set_default end #-------------------------------------------------------------------------- # ○ オプション全取得 #-------------------------------------------------------------------------- def options return OPTIONS end #-------------------------------------------------------------------------- # ○ デフォルトのセット #-------------------------------------------------------------------------- def set_default OPTIONS.each {|opt| @option_list[opt["key"]] = opt["default"] } end #-------------------------------------------------------------------------- # ○ デフォルトの取得 #-------------------------------------------------------------------------- def get_default(key) OPTIONS.each {|opt| return opt["default"] if opt["key"] == key } end #-------------------------------------------------------------------------- # ○ オプションの取得 #-------------------------------------------------------------------------- def get_option(key) @option_list[key] ||= get_default(key) return @option_list[key] end #-------------------------------------------------------------------------- # ○ オプションのセット #-------------------------------------------------------------------------- def set_option(key, value) @option_list[key] = value end #-------------------------------------------------------------------------- # ○ オプションをゲームに反映 #-------------------------------------------------------------------------- def put_options OPTIONS.each {|opt| next if opt["variable"] == nil value = get_option(opt["key"]) eval("#{opt["variable"]} = value") } end end #============================================================================== # ■ Window_OptionTitle #============================================================================== class Window_OptionTitle < Window_Base #-------------------------------------------------------------------------- # ○ オブジェクト初期化 #-------------------------------------------------------------------------- def initialize width = Graphics.width - 100 x = (Graphics.width - width) / 2 super(x, 0, width, fitting_height(1)) self.openness = 0 refresh end #-------------------------------------------------------------------------- # ○ リフレッシュ #-------------------------------------------------------------------------- def refresh contents.clear draw_text(0, 0, self.width, line_height, "オプション", 1) end end #============================================================================== # ■ Window_OptionSection #============================================================================== class Window_OptionSection < Window_Selectable #-------------------------------------------------------------------------- # ○ オブジェクト初期化 #-------------------------------------------------------------------------- def initialize @options = $game_option.options @command_window = nil super(0, 0, Graphics.width - 300, fitting_height(5)) self.openness = 0 self.index = 0 self.active = true end #-------------------------------------------------------------------------- # ○ リフレッシュ #-------------------------------------------------------------------------- def refresh contents.clear super @help_window.set_text(@options[self.index]["help"]) @help_window.refresh refresh_command end #-------------------------------------------------------------------------- # ○ コマンドのリフレッシュ #-------------------------------------------------------------------------- def refresh_command @command_window.clear return if @command_window == nil @command_window.set_command(item["command"]) @command_window.refresh option = @options[self.index] index = -1 index = now_index(option) if option["command"] != nil @command_window.index = index end #-------------------------------------------------------------------------- # ○ コマンドの選択項目 #-------------------------------------------------------------------------- def now_index(option) index = -1 for i in 0...option["command"].size if option["command"][i]["value"] == $game_option.get_option(option["key"]) index = i break end end return index end #-------------------------------------------------------------------------- # ○ 決定ボタンが押されたときの処理 #-------------------------------------------------------------------------- def process_ok return call_ok_handler if current_item_enabled? Sound.play_buzzer end #-------------------------------------------------------------------------- # ○ 項目の選択 #-------------------------------------------------------------------------- def select(index) super @help_window.set_text(@options[self.index]["help"]) refresh_command end #-------------------------------------------------------------------------- # ○ 選択項目を取得 #-------------------------------------------------------------------------- def item return @options[self.index] end #-------------------------------------------------------------------------- # ○ 選択項目のシンボルを取得 #-------------------------------------------------------------------------- def current_symbol return item["symbol"] if self.index >= 0 end #-------------------------------------------------------------------------- # ○ 項目数の取得 #-------------------------------------------------------------------------- def item_max @options.size end #-------------------------------------------------------------------------- # ○ 項目の描画 #-------------------------------------------------------------------------- def draw_item(index) option = @options[index] rect = item_rect(index) draw_text(4, rect.y, self.width, line_height, option["name"]) end #-------------------------------------------------------------------------- # ○ コマンドウィンドウのセット #-------------------------------------------------------------------------- def command_window=(window) @command_window = window end end #============================================================================== # ■ Window_OptionCommand #============================================================================== class Window_OptionCommand < Window_Selectable #-------------------------------------------------------------------------- # ○ オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(width) @commands = [] super(0, 0, width, fitting_height(5)) self.openness = 0 self.active = false end #-------------------------------------------------------------------------- # ○ 選択項目を取得 #-------------------------------------------------------------------------- def item return @commands[self.index] end #-------------------------------------------------------------------------- # ○ 決定ボタンが押されたときの処理 #-------------------------------------------------------------------------- def process_ok return call_ok_handler if current_item_enabled? Sound.play_buzzer end #-------------------------------------------------------------------------- # ○ コマンドの設定 #-------------------------------------------------------------------------- def set_command(commands) @commands = commands @commands ||= [] end #-------------------------------------------------------------------------- # ○ 項目の選択 #-------------------------------------------------------------------------- def select(index) super call_handler(:move) end #-------------------------------------------------------------------------- # ○ 項目の描画 #-------------------------------------------------------------------------- def draw_item(index) command = @commands[index] rect = item_rect(index) draw_text(4, rect.y, self.width, line_height, command["name"]) end #-------------------------------------------------------------------------- # ○ 項目数の取得 #-------------------------------------------------------------------------- def item_max @commands.size end #-------------------------------------------------------------------------- # ○ リフレッシュ #-------------------------------------------------------------------------- def refresh contents.clear self.index = -1 if @commands.empty? super end #-------------------------------------------------------------------------- # ○ クリア #-------------------------------------------------------------------------- def clear contents.clear end end #============================================================================== # ■ Scene_Option #============================================================================== class Scene_Option < Scene_MenuBase #-------------------------------------------------------------------------- # ○ 開始処理 #-------------------------------------------------------------------------- def start super @last_active_window = nil create_option_window end #-------------------------------------------------------------------------- # ○ ウィンドウの解放 #-------------------------------------------------------------------------- def end_option @window_option_title.close @window_option_section.close @window_option_command.close @window_option_help.close SceneManager.return end #-------------------------------------------------------------------------- # ○ オプションウィンドウの作成 #-------------------------------------------------------------------------- def create_option_window @window_option_title = Window_OptionTitle.new @window_option_section = Window_OptionSection.new @window_option_command = Window_OptionCommand.new(@window_option_title.width - @window_option_section.width) @window_option_help = Window_HelpEx.new(@window_option_title.width, 3) @window_option_help.openness = 0 option_height = @window_option_title.height + @window_option_section.height + @window_option_help.height @window_option_title.y = (Graphics.height - option_height) / 2 @window_option_section.y = @window_option_title.y + @window_option_title.height @window_option_command.y = @window_option_section.y @window_option_help.y = @window_option_title.y + @window_option_title.height + @window_option_section.height @window_option_section.x = @window_option_title.x @window_option_command.x = @window_option_section.x + @window_option_section.width @window_option_help.x = @window_option_title.x @window_option_command.width = @window_option_title.width - @window_option_section.width @window_option_section.help_window = @window_option_help @window_option_section.command_window = @window_option_command create_handler open_option_window end #-------------------------------------------------------------------------- # ○ ハンドラーの作成 #-------------------------------------------------------------------------- def create_handler @window_option_section.set_handler(:ok, method(:process_options)) @window_option_section.set_handler(:cancel, method(:end_option)) @window_option_section.refresh end #-------------------------------------------------------------------------- # ○ コマンドウィンドウのハンドラーの作成 #-------------------------------------------------------------------------- def create_handler_option_command @window_option_command.set_handler(:ok, method(:process_options_command)) @window_option_command.set_handler(:cancel, method(:process_cancel_option_command)) @window_option_command.set_handler(:move, method(:cursor_move)) @window_option_section.active = false @window_option_command.active = true end #-------------------------------------------------------------------------- # ○ コマンドウィンドウのカーソルを動かした時の処理 #-------------------------------------------------------------------------- def cursor_move method = @window_option_command.item["method"] return proc_method(method) if method != nil end #-------------------------------------------------------------------------- # ○ コマンドウィンドウのオプションの処理 #-------------------------------------------------------------------------- def process_options_command Sound.play_ok Input.update key = @window_option_section.item["key"] $game_option.set_option(key, @window_option_command.item["value"]) @window_option_section.active = true @window_option_command.active = false @window_option_section.refresh end #-------------------------------------------------------------------------- # ○ コマンドメソッドの処理 #-------------------------------------------------------------------------- def proc_method(method) case method when :end_option; end_option else send(method) if respond_to?(method) end end #-------------------------------------------------------------------------- # ○ オプションの処理 #-------------------------------------------------------------------------- def process_options Sound.play_ok Input.update method = @window_option_section.item["method"] return proc_method(method) if method != nil create_handler_option_command @window_option_section.refresh end #-------------------------------------------------------------------------- # ○ コマンドウィンドウでキャンセルボタンが押されたときの処理 #-------------------------------------------------------------------------- def process_cancel_option_command Sound.play_cancel Input.update @window_option_section.active = true @window_option_command.active = false @window_option_section.refresh end #-------------------------------------------------------------------------- # ○ オプション画面の終了 #-------------------------------------------------------------------------- def end_option Input.update close_option_window save_data($game_option, "System/GameOption.rvdata2") SceneManager.return end #-------------------------------------------------------------------------- # ○ 全ウィンドウを非アクティブに #-------------------------------------------------------------------------- def all_window_no_active @last_active_window = @window_option_section if @window_option_section.active @last_active_window = @window_option_command if @window_option_command.active @window_option_section.active = false @window_option_command.active = false end #-------------------------------------------------------------------------- # ○ 全ウィンドウを閉じる #-------------------------------------------------------------------------- def close_option_window @window_option_title.close @window_option_section.close @window_option_command.close @window_option_help.close update until @window_option_title.close? and @window_option_section.close? and @window_option_command.close? and @window_option_help.close? end #-------------------------------------------------------------------------- # ○ 全ウィンドウを開く #-------------------------------------------------------------------------- def open_option_window @window_option_title.open @window_option_section.open @window_option_command.open @window_option_help.open end end #============================================================================== # ■ Window_TitleCommand #------------------------------------------------------------------------------ #  タイトル画面で、ニューゲーム/コンティニューを選択するウィンドウです。 #============================================================================== class Window_TitleCommand < Window_Command #-------------------------------------------------------------------------- # ○ コマンドリストの作成 #-------------------------------------------------------------------------- alias a1_game_option_wt_make_command_list make_command_list def make_command_list a1_game_option_wt_make_command_list add_command("オプション", :option) $a1_common.change_array(@list, @list.size - 1, @list.size - 2) end end #============================================================================== # ■ Scene_Title #------------------------------------------------------------------------------ #  タイトル画面の処理を行うクラスです。 #============================================================================== class Scene_Title < Scene_Base #-------------------------------------------------------------------------- # ☆ コマンドウィンドウの作成 #-------------------------------------------------------------------------- alias a1_game_option_st_create_command_window create_command_window def create_command_window a1_game_option_st_create_command_window @command_window.set_handler(:option, method(:command_option)) end #-------------------------------------------------------------------------- # ○ コマンド[オプション] #-------------------------------------------------------------------------- def command_option close_command_window SceneManager.call(Scene_Option) end end end