=begin ▼ 選択肢拡張 ver. 1.0 RPGツクールVXAce用スクリプト 制作 : 木星ペンギン URL : http://woodpenguin.blog.fc2.com/ ------------------------------------------------------------------------------ 概要 □ 選択肢を連続して設定した場合、つなげて一つの選択肢にする機能の追加。 □ 条件を設定することで、その項目を表示しない機能の追加。 □ 選択肢内容が前回と同じだった場合、 カーソルの初期位置を前回選んだ項目にする機能の追加。 ------------------------------------------------------------------------------ 使い方 □ 選択肢の表示を続けて配置すると、一つの選択肢にまとめられます。 ・「キャンセルの場合」の処理は、無効以外を設定したものが適用され、 複数ある場合は後に設定された選択肢のものが適用されます。 □ 選択肢の文章中に if(条件) と入れ、その条件が偽になると項目が表示されなくなります。 ・s でスイッチ、v で変数を参照できます。 ・「キャンセルの場合」の項目が表示されない場合、無効と同じ処理をします。 =end module WdTk module ChoiceEX #////////////////////////////////////////////////////////////////////////////// # # 設定項目 # #////////////////////////////////////////////////////////////////////////////// #-------------------------------------------------------------------------- # ● 選択肢の最大行数 # 選択肢を表示するウィンドウの行数の最大数です。 # 選択肢がこの数より小さければ、選択肢の数に合わせます。 #-------------------------------------------------------------------------- RowMax = 4 #-------------------------------------------------------------------------- # ● 選択肢の位置記憶 # 前回表示した選択肢と全く同じ内容の選択肢を表示する場合、 # カーソルの初期位置を前回選んだ項目にする機能です。 # false で無効化できます。 #-------------------------------------------------------------------------- Store = true end #////////////////////////////////////////////////////////////////////////////// # # 以降、変更する必要なし # #////////////////////////////////////////////////////////////////////////////// @material ||= [] @material << :ChoiceEX def self.include?(sym) @material.include?(sym) end end #============================================================================== # ■ Game_Interpreter #============================================================================== class Game_Interpreter #-------------------------------------------------------------------------- # ☆ 選択肢のセットアップ #-------------------------------------------------------------------------- def setup_choices(params) result = [] add_choices(params, @index, result) unless $game_message.choices.empty? result << $game_message.choice_cancel_type - 1 $game_message.choice_proc = Proc.new {|n| @branch[@indent] = result[n] } else @branch[@indent] = -1 end end #-------------------------------------------------------------------------- # ● 選択肢の追加 #-------------------------------------------------------------------------- def add_choices(params, i, result, d = 0) params[0].each_with_index do |s, n| choice = s.dup next if choice.slice!(/\s+if\((.+)\)$/i) && !choice_eval($1) $game_message.choices << choice result << n + d end $game_message.choice_cancel_type = params[1] + d if params[1] > 0 indent = @list[i].indent i += 1 until @list[i].code == 404 && @list[i].indent == indent i += 1 add_choices(@list[i].parameters, i, result, d + 5) if @list[i].code == 102 end #-------------------------------------------------------------------------- # ● 分岐終了の場合 #-------------------------------------------------------------------------- def choice_eval(formula) s, v = $game_switches, $game_variables begin Kernel.eval(formula) rescue msgbox "以下の条件判定でエラーが出ました。\n\n", formula true end end #-------------------------------------------------------------------------- # ● 分岐終了の場合 #-------------------------------------------------------------------------- def command_404 if next_event_code == 102 @branch[@indent] -= 5 @index += 1 command_skip end end end #============================================================================== # ■ Window_ChoiceList #============================================================================== class Window_ChoiceList < Window_Command #-------------------------------------------------------------------------- # ● 指定行数に適合するウィンドウの高さを計算 #-------------------------------------------------------------------------- def fitting_height(line_number) super([line_number, WdTk::ChoiceEX::RowMax].min) end #-------------------------------------------------------------------------- # ☆ 入力処理の開始 #-------------------------------------------------------------------------- def start return unless close? last_choices = @list.collect {|c| c[:name] } update_placement refresh unless WdTk::ChoiceEX::Store && last_choices == $game_message.choices select(0) end open activate end #-------------------------------------------------------------------------- # ☆ キャンセルハンドラの呼び出し #-------------------------------------------------------------------------- def call_cancel_handler $game_message.choice_proc.call(item_max) close end end