=begin RGSS3 ★ 方向キー入力型選択肢 ★ 選択肢の形式をコマンド選択型から方向キー入力型に変更します。 決定キーは使用せず、選択肢のある方向に対応した方向キーを入力することで、 選択肢を選びます。 あまり長い文字列がある選択肢には向かない・・ ● 機能と使用法 ●================================================== 使用方法はデフォルトのイベントコマンド「選択肢の表示」とほぼ同じです。 -------------------------------------------------------------------- [デフォルトと異なる点] デフォルトでは例えば2択の選択肢を作りたい場合、 イベントコマンド「選択肢の表示」で選択肢1と選択肢2の欄に文字列を設定します。 このスクリプトを導入して同じことを実現しようとした場合、 「選択肢1と選択肢3の欄を使う」「選択肢3と選択肢4の欄を使う」といったことが 可能になります。 選択肢の1~4の欄は、選択肢が表示される位置を意味するようになり、 何も入力されていない欄は選択肢として判定されません。 -------------------------------------------------------------------- 選択肢1~4の位置関係は以下のとおりです。   選択肢 1 : 左に選択肢が表示されます。   選択肢 2 : 右に選択肢が表示されます。   選択肢 3 : 上に選択肢が表示されます。  選択肢 4 : 下に選択肢が表示されます。 -------------------------------------------------------------------- ↓ 即席:設定例の図 http://kaisou-ryouiki.sakura.ne.jp/material/manual/img/choice_manual.png ==================================================================== ver1.00 Last Update : 2014/01/07 01/07 : 新規 ろかん   http://kaisou-ryouiki.sakura.ne.jp/ =end $rsi ||= {} $rsi["方向キー入力型選択肢"] = true class Sprite_ChoiceItem < Sprite #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(index, parent) super(nil) @index = index @parent = parent setup end #-------------------------------------------------------------------------- # ● 初期設定 #-------------------------------------------------------------------------- def setup create_basebitmep self.z = 500 self.ox = @base_bitmap.width / 2 self.oy = @base_bitmap.height / 2 self.visible = false case @index when 0 self.x = Graphics.width / 4 - 10 self.y = Graphics.height / 2 when 1 self.x = Graphics.width / 4 * 3 + 10 self.y = Graphics.height / 2 when 2 self.x = Graphics.width / 2 self.y = Graphics.height / 4 - 10 when 3 self.x = Graphics.width / 2 self.y = Graphics.height / 4 * 3 + 10 end end #-------------------------------------------------------------------------- # ● ベースビットマップの作成 #-------------------------------------------------------------------------- def create_basebitmep @base_bitmap = Bitmap.new(170, 22) @base_bitmap.gradient_fill_rect(0, 0, 85, 22, gradient_color2, gradient_color1) @base_bitmap.gradient_fill_rect(85, 0, 85, 22, gradient_color1, gradient_color2) @base_bitmap.font.size = 20 end #-------------------------------------------------------------------------- # ● 背景グラデーションカラーの取得1 #-------------------------------------------------------------------------- def gradient_color1 Color.new(0, 0, 80, 180) end #-------------------------------------------------------------------------- # ● 背景グラデーションカラーの取得2 #-------------------------------------------------------------------------- def gradient_color2 Color.new(0, 0, 80, 20) end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.bitmap.dispose if self.bitmap self.bitmap = @base_bitmap.dup if $game_message.choices[@index] && !$game_message.choices[@index].empty? self.visible = true self.bitmap.draw_text(0, 1, 170, 22, $game_message.choices[@index], 1) else self.visible = false end self.opacity = 0 self.zoom_x = 1 self.zoom_y = 1 end #-------------------------------------------------------------------------- # ● 解放 #-------------------------------------------------------------------------- def dispose @base_bitmap.dispose self.bitmap.dispose if self.bitmap super end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update super if @parent.active self.opacity += 28 else unless self.opacity.zero? if @parent.index == @index self.zoom_x += 0.08 self.zoom_y += 0.03 self.opacity -= 13 else self.opacity -= 28 end end end end end class Spriteset_DirectionChoice #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :active attr_reader :index #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize @active = false @index = -1 create_sprites end #-------------------------------------------------------------------------- # ● 選択肢スプライトの作成 #-------------------------------------------------------------------------- def create_sprites @command_sprites = [] 4.times{|i| @command_sprites << Sprite_ChoiceItem.new(i, self)} end #-------------------------------------------------------------------------- # ● 入力処理の開始 #-------------------------------------------------------------------------- def start @active = true @index = -1 @command_sprites.each{|sprite| sprite.refresh} end #-------------------------------------------------------------------------- # ● 入力処理の終了 #-------------------------------------------------------------------------- def terminate @active = false end #-------------------------------------------------------------------------- # ● 選択肢が完全に閉じているか #-------------------------------------------------------------------------- def close? @command_sprites.all?{|sprite| sprite.opacity.zero?} end #-------------------------------------------------------------------------- # ● 解放 #-------------------------------------------------------------------------- def dispose @command_sprites.each{|sprite| sprite.dispose} end #-------------------------------------------------------------------------- # ● キャンセル処理の有効状態を取得 #-------------------------------------------------------------------------- def cancel_enabled? $game_message.choice_cancel_type > 0 end #-------------------------------------------------------------------------- # ● 選択肢の有効判定 #-------------------------------------------------------------------------- def active_choice?(i) $game_message.choices[i] && !$game_message.choices[i].empty? end #-------------------------------------------------------------------------- # ● 選択肢の選択後処理 #-------------------------------------------------------------------------- def choiced_process(index) @index = index $game_message.choice_proc.call(index) @command_sprites[index].flash(Color.new(255, 255, 255, 200), 35) Sound.play_ok Input.update terminate end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update @command_sprites.each{|sprite| sprite.update} if @active if cancel_enabled? && Input.trigger?(:B) $game_message.choice_proc.call($game_message.choice_cancel_type - 1) Sound.play_cancel Input.update terminate else if Input.trigger?(:DOWN) choiced_process(3) if active_choice?(3) elsif Input.trigger?(:LEFT) choiced_process(0) if active_choice?(0) elsif Input.trigger?(:RIGHT) choiced_process(1) if active_choice?(1) elsif Input.trigger?(:UP) choiced_process(2) if active_choice?(2) end end end end end class Window_Message < Window_Base #-------------------------------------------------------------------------- # ● 全ウィンドウの作成 #-------------------------------------------------------------------------- alias _create_all_windows_recreate_choice create_all_windows def create_all_windows _create_all_windows_recreate_choice @choice_window.dispose @choice_window = Spriteset_DirectionChoice.new end end