#============================================================================== # ■ Window_Selectable 機能拡張 By 貪藻矢射妥← #------------------------------------------------------------------------------ # カーソルの移動やスクロールの機能を持つウィンドウクラスです。 # # 一番上にあるデータ群がセレクトされている状態で上、左キーを押すと # 一番下にあるデータ群にカーソルが移る。 # また、その逆に対しても同様の動きを実装させてみました。 # #============================================================================== # 変更履歴 # # 2009:05:02 # ・列数が3以上でも大丈夫とか言っておきながら全然大丈夫じゃなかったバグを修正 # # 2009:09:14 # ・L/Rキーによるループも実装 # # 2015:10:01 # ・VXA風Sound対応 class Window_Selectable < Window_Base #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update super # カーソルの移動が可能な状態の場合 if self.active and @item_max > 0 and @index >= 0 # 方向ボタンの下が押された場合 if Input.repeat?(Input::DOWN) # 列数が 1 かつ 方向ボタンの下の押下状態がリピートでない場合か、 # またはカーソル位置が(項目数 - 列数)より前の場合 if (@column_max == 1 && Input.trigger?(Input::DOWN)) || (@index < @item_max - @column_max || @index > @item_max - @column_max - 1) # カーソルを下に移動 Sound.play_cursor @max2 = (@item_max.to_f / @column_max.to_f).ceil * @column_max @index = (@index + @column_max) % @max2 if @index >= @item_max @index = @max2 - @index end end end # 方向ボタンの上が押された場合 if Input.repeat?(Input::UP) # 列数が 1 かつ 方向ボタンの上の押下状態がリピートでない場合か、 # またはカーソル位置が列数より後ろの場合 if (@column_max == 1 && Input.trigger?(Input::UP)) || (@index > @column_max - 1 || @index < @column_max) # カーソルを上に移動 Sound.play_cursor @max2 = (@item_max.to_f / @column_max.to_f).ceil * @column_max @index = (@max2 - @column_max + @index) % @max2 if @index >= @item_max @index -= @column_max end end end # 方向ボタンの右が押された場合 if Input.repeat?(Input::RIGHT) # 列数が 2 以上で、カーソル位置が(項目数 - 1)より前の場合 if @column_max >= 2# && @index < @item_max - 1 # カーソルを右に移動 Sound.play_cursor if @index < @item_max - 1 @index += 1 else @index = 0 end end end # 方向ボタンの左が押された場合 if Input.repeat?(Input::LEFT) # 列数が 2 以上で、カーソル位置が 0 より後ろの場合 if @column_max >= 2# && @index > 0 # カーソルを左に移動 Sound.play_cursor if @index != 0 @index -= 1 else @index = @item_max - 1 end end end # R ボタンが押された場合 if Input.repeat?(Input::R) # ページ移動する必要がない場合 if self.page_item_max > @item_max Sound.play_buzzer else Sound.play_cursor # 表示されている最後尾の行が、データ上の最後の行よりも前の場合 if self.top_row + (self.page_row_max - 1) < (self.row_max - 1) # カーソルを 1 ページ後ろに移動 @index = [@index + self.page_item_max, @item_max - 1].min self.top_row += self.page_row_max # ページの最後の場合 else @index = @index % self.page_item_max self.top_row = 0 end end end # L ボタンが押された場合 if Input.repeat?(Input::L) # ページ移動する必要がない場合 if self.page_item_max > @item_max Sound.play_buzzer else Sound.play_cursor # 表示されている先頭の行が 0 より後ろの場合 if self.top_row > 0 # カーソルを 1 ページ前に移動 @index = [@index - self.page_item_max, 0].max self.top_row -= self.page_row_max # ページの最初の場合 else @index = [@item_max / self.page_item_max * self.page_item_max + @index, @item_max - 1].min self.top_row = @item_max / self.page_item_max * self.page_item_max end end end end # ヘルプテキストを更新 (update_help は継承先で定義される) if self.active and @help_window != nil update_help end # カーソルの矩形を更新 update_cursor_rect end end |