=begin ************************************************************************
  ◆ 画像コマンドスクリプト (ベーススクリプト) Ver.1.82
  ---------------------------------------------------------------------------
    画像コマンドのベーススクリプトです。回転アイコンコマンドが使えます。
=end # ************************************************************************
 
#-information------------------------------------------------------------------
$ziifee ||= {}
$ziifee[:SpriteCommand] = true
#------------------------------------------------------------------------------
#-memo-------------------------------------------------------------------------
#  [必要画像] 以下の画像を Graphics/System にインポートしてください。
#    回転コマンド用カーソル画像 ( ファイル名 : RollIconCursor )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#  このスクリプトは可能な限り素材の中で上部に導入してください。
#  回転アイコンコマンド選択を行いたいクラスに以下を記述します。
#    include ZiifSpriteCommand_RollIcon  # 回転アイコンコマンド選択
#------------------------------------------------------------------------------
 
#==============================================================================
# ■ ZiifManager
#==============================================================================
 
module ZiifManager
  #--------------------------------------------------------------------------
  # ▼ 定数 (アイコン番号)
  #-memo---------------------------------------------------------------------
  #  回転コマンド上に表示するアイコンはここで設定します。
  #  以下の定義の symbol がここで設定するシンボルになります。
  #    add_command(name, symbol, enabled, ext) # コマンドの追加
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  #  IconSet[シンボル] = Hash.new(アイコン番号)
  #  IconSet[:skill][スキルタイプ番号] = アイコン番号  # スキルタイプ
  #--------------------------------------------------------------------------
  IconSet ||= Hash.new(Hash.new(16))           # デフォルト
  IconSet[:fight]       = Hash.new(147)        # 戦う   (バトル)
  IconSet[:escape]      = Hash.new(467)        # 逃げる (バトル)
  IconSet[:attack]      = Hash.new(175)        # 攻撃   (バトル)
  IconSet[:guard]       = Hash.new(506)        # 防御   (バトル)
  IconSet[:item]        = Hash.new(260)        # アイテム
  IconSet[:skill]       = Hash.new(112)        # スキル
  IconSet[:skill][1]    = 115                  # スキルタイプ ID:01
  IconSet[:skill][2]    = 117                  # スキルタイプ ID:02
  IconSet[:equip]       = Hash.new(436)        # 装備
  IconSet[:weapon]      = Hash.new(147)        # 武器
  IconSet[:armor]       = Hash.new(506)        # 防具
  IconSet[:key_item]    = Hash.new(243)        # キーアイテム
  IconSet[:optimize]    = Hash.new(437)        # 最強装備
  IconSet[:clear]       = Hash.new(143)        # 外す
  IconSet[:status]      = Hash.new(121)        # ステータス
  IconSet[:formation]   = Hash.new(183)        # 並び替え
  IconSet[:save]        = Hash.new(224)        # セーブ
  IconSet[:buy]         = Hash.new(270)        # 購入
  IconSet[:sell]        = Hash.new(262)        # 売却
  IconSet[:cancel]      = Hash.new(12)         # キャンセル
  IconSet[:new_game]    = Hash.new(234)        # ニューゲーム
  IconSet[:continue]    = Hash.new(224)        # コンティニュー
  IconSet[:game_end]    = Hash.new(257)        # ゲーム終了
  IconSet[:to_title]    = Hash.new(257)        # タイトルへ
  IconSet[:shutdown]    = Hash.new(143)        # シャットダウン
  #--------------------------------------------------------------------------
  # ● コマンドアイコン番号の取得
  #     command : ウィンドウのコマンド
  #--------------------------------------------------------------------------
  def self.command_icon_index(command)
    IconSet[command[:symbol]][command[:ext]]
  end
end
 
#==============================================================================
# ■ Game_System
#==============================================================================
 
class Game_System
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数 (オプション拡張用)
  #--------------------------------------------------------------------------
  attr_writer   :ziifop_reverse_roll      # 逆回転 ( true / false )
  attr_writer   :ziifop_roll_input_type   # 回転時 キー入力タイプ (0~2)
  attr_writer   :ziifop_roll_speed        # 回転時 速度 (0~4)
  #--------------------------------------------------------------------------
  # ▼ 逆回転の取得
  #--------------------------------------------------------------------------
  def ziifop_reverse_roll
    return false
  end
  #--------------------------------------------------------------------------
  # ▼ 回転キー入力タイプの取得 (0:プレス, 1:トリガー, 2:リピート)
  #--------------------------------------------------------------------------
  def ziifop_roll_input_type
    return 0
  end
  #--------------------------------------------------------------------------
  # ▼ 回転速度の取得 (0:遅い ~ 4:速い)
  #--------------------------------------------------------------------------
  def ziifop_roll_speed
    return 1
  end
end
 
#******************************************************************************
# ▼ 画像コマンド基本部
#******************************************************************************
 
#==============================================================================
# ■ Sprite_ZiifCommandSprite
#------------------------------------------------------------------------------
#  コマンド画像・背景・カーソル表示用スプライトのスーパークラスです。
#==============================================================================
 
class Sprite_ZiifCommandSprite < Sprite
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(command_set)
    super(command_set.viewport)
    @command_set = command_set
    init_basic_values
    create_bitmap
    update
  end
  #--------------------------------------------------------------------------
  # ● 基本変数の初期化
  #--------------------------------------------------------------------------
  def init_basic_values
  end
  #--------------------------------------------------------------------------
  # ● ビットマップの作成
  #--------------------------------------------------------------------------
  def create_bitmap
  end
  #--------------------------------------------------------------------------
  # ● 内容の作成
  #--------------------------------------------------------------------------
  def create_contents
  end
  #--------------------------------------------------------------------------
  # ● 内容の削除
  #--------------------------------------------------------------------------
  def clear_contents
  end
  #--------------------------------------------------------------------------
  # ● スプライトコマンドの取得
  #--------------------------------------------------------------------------
  def command_set
    return @command_set
  end
  #--------------------------------------------------------------------------
  # ● 位置の取得
  #--------------------------------------------------------------------------
  def index
    return command_set.sprite_index(self)
  end
  #--------------------------------------------------------------------------
  # ● コマンドのビューポートの取得
  #--------------------------------------------------------------------------
  def command_set_viewport
    return command_set.viewport
  end
  #--------------------------------------------------------------------------
  # ● コマンドの可視状態の取得
  #--------------------------------------------------------------------------
  def command_set_visible
    return command_set.visible && !command_set.close?
  end
  #--------------------------------------------------------------------------
  # ● コマンドの透明度の取得
  #--------------------------------------------------------------------------
  def command_set_opacity
    return command_set.contents_opacity
  end
  #--------------------------------------------------------------------------
  # ● 位置情報の更新
  #--------------------------------------------------------------------------
  def update_position
    self.viewport = command_set_viewport
    self.visible  = command_set_visible
    self.opacity  = command_set_opacity
  end
end
 
#==============================================================================
# ■ ZiifSpriteCommand
#------------------------------------------------------------------------------
#  画像コマンド選択を行うためのモジュールです。Mix-Inにより使用します。
#==============================================================================
 
module ZiifSpriteCommand
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_reader   :windowskin               # ウィンドウスキン
  attr_reader   :viewport                 # ビューポート
  attr_reader   :active                   # 選択状態
  attr_reader   :visible                  # 可視状態
  attr_reader   :x                        # X座標
  attr_reader   :y                        # Y座標
  attr_reader   :width                    # 幅
  attr_reader   :height                   # 高さ
  attr_reader   :z                        # Z座標
  attr_reader   :ox                       # 転送元原点 X座標
  attr_reader   :oy                       # 転送元原点 Y座標
  attr_reader   :padding                  # 余白の大きさ
  attr_reader   :padding_bottom           # 下線余白の大きさ
  attr_reader   :opacity                  # 不透明度
  attr_reader   :back_opacity             # 背景の不透明度
  attr_reader   :contents_opacity         # コマンドの不透明度
  attr_reader   :openness                 # オープン度
  attr_reader   :tone                     # 背景の色調
  attr_reader   :index                    # カーソル位置
  attr_reader   :help_window              # ヘルプウィンドウ
  attr_accessor :cursor_fix               # カーソル固定フラグ
  attr_accessor :cursor_all               # カーソル全選択フラグ
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(*args)
    init_basic_values(*args)
    init_sprite_command
    update_tone
    refresh
    select(0)
    activate
  end
  #--------------------------------------------------------------------------
  # ● 基本変数の初期化
  #--------------------------------------------------------------------------
  def init_basic_values(x, y, width = window_width, height = window_height)
    @windowskin       = Cache.system("Window")
    @viewport         = nil
    @active           = true
    @visible          = true
    @x                = x
    @y                = y
    @width            = width
    [url=home.php?mod=space&uid=291977]@height[/url]           = height
    @z                = 100
    @ox               = 0
    @oy               = 0
    @padding          = 12
    @padding_bottom   = 12
    @opacity          = 255
    @back_opacity     = 255
    @contents_opacity = 255
    @openness         = 255
    @tone             = Tone.new
    @index            = -1
    @handler          = {}
    @cursor_fix       = false
    @cursor_all       = false
    @opening          = false
    @closing          = false
  end
  #--------------------------------------------------------------------------
  # ● スプライトコマンド変数の初期化
  #--------------------------------------------------------------------------
  def init_sprite_command
    @command_sprites  = []
    @object_sprites   = {}
    create_dummy_bitmap
  end
  #--------------------------------------------------------------------------
  # ● 解放
  #--------------------------------------------------------------------------
  def dispose
    dispose_dummy_bitmap
    dispose_object_sprites
    dispose_command_sprites
  end
  #--------------------------------------------------------------------------
  # ● ウィンドウ幅の取得
  #--------------------------------------------------------------------------
  def window_width
    return 96
  end
  #--------------------------------------------------------------------------
  # ● ウィンドウ高さの取得
  #--------------------------------------------------------------------------
  def window_height
    return 88
  end
  #--------------------------------------------------------------------------
  # ● 項目数の取得
  #--------------------------------------------------------------------------
  def item_max
    @list.size
  end
  #--------------------------------------------------------------------------
  # ● コマンドリストのクリア
  #--------------------------------------------------------------------------
  def clear_command_list
    @list = []
  end
  #--------------------------------------------------------------------------
  # ● コマンドリストの作成
  #--------------------------------------------------------------------------
  def make_command_list
  end
  #--------------------------------------------------------------------------
  # ● コマンドの追加
  #     name    : コマンド名
  #     symbol  : 対応するシンボル
  #     enabled : 有効状態フラグ
  #     ext     : 任意の拡張データ
  #--------------------------------------------------------------------------
  def add_command(name, symbol, enabled = true, ext = nil)
    @list.push({:name=>name, :symbol=>symbol, :enabled=>enabled, :ext=>ext})
  end
  #--------------------------------------------------------------------------
  # ● コマンド名の取得
  #--------------------------------------------------------------------------
  def command(index)
    @list[index]
  end
  #--------------------------------------------------------------------------
  # ● コマンド名の取得
  #--------------------------------------------------------------------------
  def command_name(index)
    @list[index][:name]
  end
  #--------------------------------------------------------------------------
  # ● コマンドの有効状態を取得
  #--------------------------------------------------------------------------
  def command_enabled?(index)
    @list[index][:enabled]
  end
  #--------------------------------------------------------------------------
  # ● コマンドシンボルの取得
  #--------------------------------------------------------------------------
  def command_symbol(index)
    @list[index][:symbol]
  end
  #--------------------------------------------------------------------------
  # ● コマンドの拡張データの取得
  #--------------------------------------------------------------------------
  def command_ext(index)
    @list[index][:ext]
  end
  #--------------------------------------------------------------------------
  # ● 選択項目のコマンドデータを取得
  #--------------------------------------------------------------------------
  def current_data
    index >= 0 ? @list[index] : nil
  end
  #--------------------------------------------------------------------------
  # ● 選択項目のコマンド名を取得
  #--------------------------------------------------------------------------
  def current_item_name
    current_data ? current_data[:name] : ""
  end
  #--------------------------------------------------------------------------
  # ● 選択項目の有効状態を取得
  #--------------------------------------------------------------------------
  def current_item_enabled?
    current_data ? current_data[:enabled] : false
  end
  #--------------------------------------------------------------------------
  # ● 選択項目のシンボルを取得
  #--------------------------------------------------------------------------
  def current_symbol
    current_data ? current_data[:symbol] : nil
  end
  #--------------------------------------------------------------------------
  # ● 選択項目の拡張データを取得
  #--------------------------------------------------------------------------
  def current_ext
    current_data ? current_data[:ext] : nil
  end
  #--------------------------------------------------------------------------
  # ● 指定されたシンボルを持つコマンドにカーソルを移動
  #--------------------------------------------------------------------------
  def select_symbol(symbol)
    @list.each_index {|i| select(i) if @list[i][:symbol] == symbol }
  end
  #--------------------------------------------------------------------------
  # ● 指定された拡張データを持つコマンドにカーソルを移動
  #--------------------------------------------------------------------------
  def select_ext(ext)
    @list.each_index {|i| select(i) if @list[i][:ext] == ext }
  end
  #--------------------------------------------------------------------------
  # ● スプライトコマンドクラスの取得
  #--------------------------------------------------------------------------
  def sprite_command_class
    return Sprite_ZiifCommandSprite
  end
  #--------------------------------------------------------------------------
  # ● コマンド背景クラスの取得
  #--------------------------------------------------------------------------
  def sprite_background_class
    return Sprite_ZiifCommandSprite
  end
  #--------------------------------------------------------------------------
  # ● コマンドカーソルクラスの取得
  #--------------------------------------------------------------------------
  def sprite_cursor_class
    return Sprite_ZiifCommandSprite
  end
  #--------------------------------------------------------------------------
  # ● コマンドスプライトの位置を取得
  #--------------------------------------------------------------------------
  def sprite_index(sprite)
    @command_sprites.index(sprite)
  end
  #--------------------------------------------------------------------------
  # ● コマンドスプライトの作成
  #--------------------------------------------------------------------------
  def make_command_sprites
    item_max.times {|i| @command_sprites[i] = sprite_command_class.new(self) }
  end
  #--------------------------------------------------------------------------
  # ● コマンドスプライトの解放
  #--------------------------------------------------------------------------
  def dispose_command_sprites
    @command_sprites.each {|sprite| sprite.dispose }
    @command_sprites.clear
  end
  #--------------------------------------------------------------------------
  # ● コマンドスプライトの更新
  #--------------------------------------------------------------------------
  def update_command_sprites
    @command_sprites.each {|sprite| sprite.update }
  end
  #--------------------------------------------------------------------------
  # ● コマンドスプライトの位置情報を更新
  #--------------------------------------------------------------------------
  def update_command_sprites_position
    @command_sprites.each {|sprite| sprite.update_position }
  end
  #--------------------------------------------------------------------------
  # ● オブジェクトスプライトの作成
  #--------------------------------------------------------------------------
  def make_object_sprites
    @object_sprites[:background] = sprite_background_class.new(self)
    @object_sprites[:cursor]     = sprite_cursor_class.new(self)
  end
  #--------------------------------------------------------------------------
  # ● オブジェクトスプライトの解放
  #--------------------------------------------------------------------------
  def dispose_object_sprites
    @object_sprites.each_value {|sprite| sprite.dispose }
    @object_sprites.clear
  end
  #--------------------------------------------------------------------------
  # ● オブジェクトスプライトの更新
  #--------------------------------------------------------------------------
  def update_object_sprites
    @object_sprites.each_value {|sprite| sprite.update }
  end
  #--------------------------------------------------------------------------
  # ● オブジェクトスプライトの位置情報を更新
  #--------------------------------------------------------------------------
  def update_object_sprites_position
    @object_sprites.each_value {|sprite| sprite.update_position }
  end
  #--------------------------------------------------------------------------
  # ● コマンド内容の作成
  #--------------------------------------------------------------------------
  def create_contents
    dispose_object_sprites
    dispose_command_sprites
    make_command_sprites
    make_object_sprites
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    update_tone
    update_open if @opening
    update_close if @closing
    update_move
    update_command_sprites
    update_object_sprites
    process_cursor_move
    process_handling
  end
  #--------------------------------------------------------------------------
  # ● 位置情報の更新
  #--------------------------------------------------------------------------
  def update_position
    update_command_sprites_position
    update_object_sprites_position
  end
  #--------------------------------------------------------------------------
  # ● X座標の変更
  #--------------------------------------------------------------------------
  def x=(x)
    @x = x
    update_position
  end
  #--------------------------------------------------------------------------
  # ● Y座標の変更
  #--------------------------------------------------------------------------
  def y=(y)
    @y = y
    update_position
  end
  #--------------------------------------------------------------------------
  # ● 幅の変更
  #--------------------------------------------------------------------------
  def width=(width)
    @width = width
    update_position
  end
  #--------------------------------------------------------------------------
  # ● 高さの変更
  #--------------------------------------------------------------------------
  def height=(height)
    [url=home.php?mod=space&uid=291977]@height[/url] = height
    update_position
  end
  #--------------------------------------------------------------------------
  # ● Z座標の変更
  #--------------------------------------------------------------------------
  def z=(z)
    @z = z
    update_position
  end
  #--------------------------------------------------------------------------
  # ● X座標、Y座標、幅、高さをまとめて変更
  #--------------------------------------------------------------------------
  def move(x, y, width, height)
    @x      = x
    @y      = y
    @width  = width
    @height = height
    update_position
  end
  #--------------------------------------------------------------------------
  # ● 転送元原点 X座標の変更
  #--------------------------------------------------------------------------
  def ox=(ox)
    @ox = ox
    update_position
  end
  #--------------------------------------------------------------------------
  # ● 転送元原点 Y座標の変更
  #--------------------------------------------------------------------------
  def oy=(oy)
    @oy = oy
    update_position
  end
  #--------------------------------------------------------------------------
  # ● 余白の大きさの変更
  #--------------------------------------------------------------------------
  def padding=(padding)
    @padding        = padding
    @padding_bottom = padding_bottom
    update_position
  end
  #--------------------------------------------------------------------------
  # ● 下線余白の大きさの変更
  #--------------------------------------------------------------------------
  def padding_bottom=(padding_bottom)
    @padding_bottom = padding_bottom
    update_position
  end
  #--------------------------------------------------------------------------
  # ● ウィンドウスキンの変更
  #--------------------------------------------------------------------------
  def windowskin=(windowskin)
    @windowskin = windowskin
    update_position
  end
  #--------------------------------------------------------------------------
  # ● ビューポートの変更
  #--------------------------------------------------------------------------
  def viewport=(viewport)
    @viewport = viewport
    update_position
  end
  #--------------------------------------------------------------------------
  # ● 可視状態の変更
  #--------------------------------------------------------------------------
  def visible=(visible)
    @visible = visible
    update_position
  end
  #--------------------------------------------------------------------------
  # ● 表示
  #--------------------------------------------------------------------------
  def show
    self.visible = true
    self
  end
  #--------------------------------------------------------------------------
  # ● 非表示
  #--------------------------------------------------------------------------
  def hide
    self.visible = false
    self
  end
  #--------------------------------------------------------------------------
  # ● アクティブ状態の変更
  #--------------------------------------------------------------------------
  def active=(active)
    @active = active
    update_cursor
    call_update_help
  end
  #--------------------------------------------------------------------------
  # ● アクティブ化
  #--------------------------------------------------------------------------
  def activate
    self.active = true
    self
  end
  #--------------------------------------------------------------------------
  # ● 非アクティブ化
  #--------------------------------------------------------------------------
  def deactivate
    self.active = false
    self
  end
  #--------------------------------------------------------------------------
  # ● 不透明度の変更
  #--------------------------------------------------------------------------
  def opacity=(opacity)
    @opacity = [[opacity, 255].min, 0].max
    update_position
  end
  #--------------------------------------------------------------------------
  # ● 背景の不透明度の変更
  #--------------------------------------------------------------------------
  def back_opacity=(opacity)
    @back_opacity = [[opacity, 255].min, 0].max
    update_position
  end
  #--------------------------------------------------------------------------
  # ● 内容の不透明度の変更
  #--------------------------------------------------------------------------
  def contents_opacity=(opacity)
    @contents_opacity = [[opacity, 255].min, 0].max
    update_position
  end
  #--------------------------------------------------------------------------
  # ● オープン度の変更
  #--------------------------------------------------------------------------
  def openness=(openness)
    @openness = [[openness, 255].min, 0].max
    update_position
  end
  #--------------------------------------------------------------------------
  # ● 完全に開いた状態かどうか?
  #--------------------------------------------------------------------------
  def open?
    (@openness == 255)
  end
  #--------------------------------------------------------------------------
  # ● 完全に閉じた状態かどうか?
  #--------------------------------------------------------------------------
  def close?
    (@openness == 0)
  end
  #--------------------------------------------------------------------------
  # ● 開く処理値の取得
  #--------------------------------------------------------------------------
  def opening_value
    return 48
  end
  #--------------------------------------------------------------------------
  # ● 閉じる処理値の取得
  #--------------------------------------------------------------------------
  def closing_value
    return 48
  end
  #--------------------------------------------------------------------------
  # ● 開く処理の更新
  #--------------------------------------------------------------------------
  def update_open
    self.openness += opening_value
    @opening = false if open?
  end
  #--------------------------------------------------------------------------
  # ● 閉じる処理の更新
  #--------------------------------------------------------------------------
  def update_close
    self.openness -= closing_value
    @closing = false if close?
  end
  #--------------------------------------------------------------------------
  # ● 開く
  #--------------------------------------------------------------------------
  def open
    @opening = true unless open?
    @closing = false
    self
  end
  #--------------------------------------------------------------------------
  # ● 閉じる
  #--------------------------------------------------------------------------
  def close
    @closing = true unless close?
    @opening = false
    self
  end
  #--------------------------------------------------------------------------
  # ● 色調の更新
  #--------------------------------------------------------------------------
  def update_tone
  end
  #--------------------------------------------------------------------------
  # ● 移動中かどうか?
  #--------------------------------------------------------------------------
  def move?
    return false
  end
  #--------------------------------------------------------------------------
  # ● 停止中かどうか?
  #--------------------------------------------------------------------------
  def stop?
    return true
  end
  #--------------------------------------------------------------------------
  # ● 位置移動の更新
  #--------------------------------------------------------------------------
  def update_move
  end
  #--------------------------------------------------------------------------
  # ● カーソル位置の設定
  #--------------------------------------------------------------------------
  def index=(index)
    @index = index
    update_cursor
    call_update_help
  end
  #--------------------------------------------------------------------------
  # ● 項目の選択
  #--------------------------------------------------------------------------
  def select(index)
    self.index = index if index
  end
  #--------------------------------------------------------------------------
  # ● 項目の選択解除
  #--------------------------------------------------------------------------
  def unselect
    self.index = -1
  end
  #--------------------------------------------------------------------------
  # ● 動作に対応するハンドラの設定
  #     method : ハンドラとして設定するメソッド (Method オブジェクト)
  #--------------------------------------------------------------------------
  def set_handler(symbol, method)
    @handler[symbol] = method
  end
  #--------------------------------------------------------------------------
  # ● ハンドラの存在確認
  #--------------------------------------------------------------------------
  def handle?(symbol)
    @handler.include?(symbol)
  end
  #--------------------------------------------------------------------------
  # ● ハンドラの呼び出し
  #--------------------------------------------------------------------------
  def call_handler(symbol)
    @handler[symbol].call if handle?(symbol)
  end
  #--------------------------------------------------------------------------
  # ● カーソルの移動可能判定
  #--------------------------------------------------------------------------
  def cursor_movable?
    stop? && active && open? && !@cursor_fix && !@cursor_all && item_max > 0
  end
  #--------------------------------------------------------------------------
  # ● 下キーが押されているかどうか?
  #--------------------------------------------------------------------------
  def input_down?
    Input.repeat?(:DOWN)
  end
  #--------------------------------------------------------------------------
  # ● 上キーが押されているかどうか?
  #--------------------------------------------------------------------------
  def input_up?
    Input.repeat?(:UP)
  end
  #--------------------------------------------------------------------------
  # ● 右キーが押されているかどうか?
  #--------------------------------------------------------------------------
  def input_right?
    Input.repeat?(:RIGHT)
  end
  #--------------------------------------------------------------------------
  # ● 左キーが押されているかどうか?
  #--------------------------------------------------------------------------
  def input_left?
    Input.repeat?(:LEFT)
  end
  #--------------------------------------------------------------------------
  # ● カーソルを下に移動
  #--------------------------------------------------------------------------
  def cursor_down(wrap = false)
  end
  #--------------------------------------------------------------------------
  # ● カーソルを上に移動
  #--------------------------------------------------------------------------
  def cursor_up(wrap = false)
  end
  #--------------------------------------------------------------------------
  # ● カーソルを右に移動
  #--------------------------------------------------------------------------
  def cursor_right(wrap = false)
  end
  #--------------------------------------------------------------------------
  # ● カーソルを左に移動
  #--------------------------------------------------------------------------
  def cursor_left(wrap = false)
  end
  #--------------------------------------------------------------------------
  # ● カーソルの移動前処理
  #--------------------------------------------------------------------------
  def process_before_cursor_move
    @cursor_sound_value = @index
  end
  #--------------------------------------------------------------------------
  # ● カーソルの移動後処理
  #--------------------------------------------------------------------------
  def process_after_cursor_move
    Sound.play_cursor if @index != @cursor_sound_value
  end
  #--------------------------------------------------------------------------
  # ● カーソルの移動処理
  #--------------------------------------------------------------------------
  def process_cursor_move
    return unless cursor_movable?
    process_before_cursor_move
    cursor_down (Input.trigger?(:DOWN))  if input_down?
    cursor_up   (Input.trigger?(:UP))    if input_up?
    cursor_right(Input.trigger?(:RIGHT)) if input_right?
    cursor_left (Input.trigger?(:LEFT))  if input_left?
    process_after_cursor_move
  end
  #--------------------------------------------------------------------------
  # ● 決定やキャンセルなどのハンドリング処理
  #--------------------------------------------------------------------------
  def process_handling
    return unless open? && active && stop?
    return process_ok       if ok_enabled?        && Input.trigger?(:C)
    return process_cancel   if cancel_enabled?    && Input.trigger?(:B)
    return process_pagedown if handle?(:pagedown) && Input.trigger?(:R)
    return process_pageup   if handle?(:pageup)   && Input.trigger?(:L)
  end
  #--------------------------------------------------------------------------
  # ● 決定処理の有効状態を取得
  #--------------------------------------------------------------------------
  def ok_enabled?
    return true
  end
  #--------------------------------------------------------------------------
  # ● キャンセル処理の有効状態を取得
  #--------------------------------------------------------------------------
  def cancel_enabled?
    handle?(:cancel)
  end
  #--------------------------------------------------------------------------
  # ● 決定ボタンが押されたときの処理
  #--------------------------------------------------------------------------
  def process_ok
    if current_item_enabled?
      Sound.play_ok
      Input.update
      deactivate
      call_ok_handler
    else
      Sound.play_buzzer
    end
  end
  #--------------------------------------------------------------------------
  # ● 決定ハンドラの呼び出し
  #--------------------------------------------------------------------------
  def call_ok_handler
    if handle?(current_symbol)
      call_handler(current_symbol)
    elsif handle?(:ok)
      call_ok_handler_default
    else
      activate
    end
  end
  #--------------------------------------------------------------------------
  # ● 決定ハンドラの呼び出し (デフォルト)
  #--------------------------------------------------------------------------
  def call_ok_handler_default
    call_handler(:ok)
  end
  #--------------------------------------------------------------------------
  # ● キャンセルボタンが押されたときの処理
  #--------------------------------------------------------------------------
  def process_cancel
    Sound.play_cancel
    Input.update
    deactivate
    call_cancel_handler
  end
  #--------------------------------------------------------------------------
  # ● キャンセルハンドラの呼び出し
  #--------------------------------------------------------------------------
  def call_cancel_handler
    call_handler(:cancel)
  end
  #--------------------------------------------------------------------------
  # ● L ボタン(PageUp)が押されたときの処理
  #--------------------------------------------------------------------------
  def process_pageup
    Sound.play_cursor
    Input.update
    deactivate
    call_handler(:pageup)
  end
  #--------------------------------------------------------------------------
  # ● R ボタン(PageDown)が押されたときの処理
  #--------------------------------------------------------------------------
  def process_pagedown
    Sound.play_cursor
    Input.update
    deactivate
    call_handler(:pagedown)
  end
  #--------------------------------------------------------------------------
  # ● カーソルの更新
  #--------------------------------------------------------------------------
  def update_cursor
    update_position
  end
  #--------------------------------------------------------------------------
  # ● ヘルプウィンドウの設定
  #--------------------------------------------------------------------------
  def help_window=(help_window)
    @help_window = help_window
    call_update_help
  end
  #--------------------------------------------------------------------------
  # ● ヘルプウィンドウ更新メソッドの呼び出し
  #--------------------------------------------------------------------------
  def call_update_help
    update_help if active && @help_window
  end
  #--------------------------------------------------------------------------
  # ● ヘルプウィンドウの更新
  #--------------------------------------------------------------------------
  def update_help
    @help_window.clear
  end
  #--------------------------------------------------------------------------
  # ● 全項目の描画
  #--------------------------------------------------------------------------
  def draw_all_items
    item_max.times {|i| draw_item(i) }
  end
  #--------------------------------------------------------------------------
  # ● 項目の描画
  #--------------------------------------------------------------------------
  def draw_item(index)
    @command_sprites[index].create_contents
  end
  #--------------------------------------------------------------------------
  # ● 項目の消去
  #--------------------------------------------------------------------------
  def clear_item(index)
    @command_sprites[index].clear_contents
  end
  #--------------------------------------------------------------------------
  # ● 項目の再描画
  #--------------------------------------------------------------------------
  def redraw_item(index)
    clear_item(index) if index >= 0
    draw_item(index)  if index >= 0
  end
  #--------------------------------------------------------------------------
  # ● 選択項目の再描画
  #--------------------------------------------------------------------------
  def redraw_current_item
    redraw_item(@index)
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    clear_command_list
    make_command_list
    create_contents
    draw_all_items
    update_position
  end
  #--------------------------------------------------------------------------
  # ○ ダミービットマップの作成 (ウィンドウ互換用)
  #--------------------------------------------------------------------------
  def create_dummy_bitmap
    @dummy_bitmap = Bitmap.new(32, 32)
  end
  #--------------------------------------------------------------------------
  # ○ ダミービットマップの解放 (ウィンドウ互換用)
  #--------------------------------------------------------------------------
  def dispose_dummy_bitmap
    @dummy_bitmap.dispose
  end
  #--------------------------------------------------------------------------
  # ○ ウィンドウ内容の取得 (ウィンドウ互換用)
  #--------------------------------------------------------------------------
  def contents
    @dummy_bitmap
  end
  #--------------------------------------------------------------------------
  # ○ カーソルの矩形 (ウィンドウ互換用)
  #--------------------------------------------------------------------------
  def cursor_rect
    Rect.new(self.x, self.y, self.width, self.height)
  end
  #--------------------------------------------------------------------------
  # ○ スクロール用矢印の可視状態 (ウィンドウ互換用)
  #--------------------------------------------------------------------------
  def arrows_visible
    return true
  end
  #--------------------------------------------------------------------------
  # ○ スクロール用矢印の可視状態の変更 (ウィンドウ互換用)
  #--------------------------------------------------------------------------
  def arrows_visible=(arrows_visible)
  end
  #--------------------------------------------------------------------------
  # ○ ポーズの可視状態 (ウィンドウ互換用)
  #--------------------------------------------------------------------------
  def pause
    return false
  end
  #--------------------------------------------------------------------------
  # ○ ポーズの可視状態の変更 (ウィンドウ互換用)
  #--------------------------------------------------------------------------
  def pause=(pause)
  end
end
 
#******************************************************************************
# ▼ 回転アイコンコマンド部
#******************************************************************************
 
#==============================================================================
# ■ Sprite_ZiifRollIconCommand
#------------------------------------------------------------------------------
#  回転コマンドアイコン表示用のスプライトです。
#==============================================================================
 
class Sprite_ZiifRollIconCommand < Sprite_ZiifCommandSprite
  #--------------------------------------------------------------------------
  # ● 解放
  #--------------------------------------------------------------------------
  def dispose
    self.bitmap.dispose
    super
  end
  #--------------------------------------------------------------------------
  # ● ビットマップの作成
  #--------------------------------------------------------------------------
  def create_bitmap
    self.bitmap = Bitmap.new(24, 24)
    self.ox     = self.bitmap.width / 2
    self.oy     = self.bitmap.height / 2
  end
  #--------------------------------------------------------------------------
  # ● アイコン番号の取得
  #--------------------------------------------------------------------------
  def icon_index
    ZiifManager.command_icon_index(command_set.command(self.index))
  end
  #--------------------------------------------------------------------------
  # ● アイコン番号の取得
  #--------------------------------------------------------------------------
  def enabled
    command_set.command_enabled?(self.index)
  end
  #--------------------------------------------------------------------------
  # ● 半透明描画用のアルファ値を取得
  #--------------------------------------------------------------------------
  def translucent_alpha
    return 160
  end
  #--------------------------------------------------------------------------
  # ● 内容の作成
  #--------------------------------------------------------------------------
  def create_contents
    draw_icon
  end
  #--------------------------------------------------------------------------
  # ● アイコンを描画
  #--------------------------------------------------------------------------
  def draw_icon
    bitmap     = Cache.system("Iconset")
    icon_index = self.icon_index
    rect       = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
    self.bitmap.blt(0, 0, bitmap, rect, enabled ? 255 : translucent_alpha)
  end
  #--------------------------------------------------------------------------
  # ● 内容の削除
  #--------------------------------------------------------------------------
  def clear_contents
    self.bitmap.clear
  end
  #--------------------------------------------------------------------------
  # ● 位置情報の更新
  #--------------------------------------------------------------------------
  def update_position
    super
    update_roll
  end
  #--------------------------------------------------------------------------
  # ● 回転幅の取得
  #--------------------------------------------------------------------------
  def roll_width
    command_set.width * command_set.openness / 510
  end
  #--------------------------------------------------------------------------
  # ● 回転高さの取得
  #--------------------------------------------------------------------------
  def roll_height
    command_set.height * command_set.openness / 510
  end
  #--------------------------------------------------------------------------
  # ● 回転角度の取得
  #--------------------------------------------------------------------------
  def roll_angle
    angle  = (self.index - command_set.index) * command_set.move_size
    angle += command_set.roll_angle
  end
  #--------------------------------------------------------------------------
  # ● 回転位置の更新
  #--------------------------------------------------------------------------
  def update_roll
    angle  = roll_angle
    self.x = roll_width  * Math.sin(angle)    + command_set.x
    self.y = roll_height * (-Math.cos(angle)) + command_set.y
    self.z = command_set.z
  end
end
 
#==============================================================================
# ■ Sprite_ZiifRollIconBackground
#------------------------------------------------------------------------------
#  画像コマンド背景のスプライトです。
#==============================================================================
 
class Sprite_ZiifRollIconBackground < Sprite_ZiifCommandSprite
  #--------------------------------------------------------------------------
  # ● 解放
  #--------------------------------------------------------------------------
  def dispose
    self.bitmap.dispose if command_set.background_filename.empty?
    super
  end
  #--------------------------------------------------------------------------
  # ● ビットマップの作成
  #--------------------------------------------------------------------------
  def create_bitmap
    self.bitmap = Cache.system(command_set.background_filename)
    self.ox     = self.bitmap.width / 2
    self.oy     = self.bitmap.height / 2
  end
  #--------------------------------------------------------------------------
  # ● コマンドの透明度の取得
  #--------------------------------------------------------------------------
  def command_set_opacity
    opacity  = command_set.opacity
    opacity *= command_set.back_opacity
    opacity *= command_set.openness
    opacity /= 65025
  end
  #--------------------------------------------------------------------------
  # ● 位置情報の更新
  #--------------------------------------------------------------------------
  def update_position
    super
    self.x = command_set.x
    self.y = command_set.y
    self.z = command_set.z - 10
  end
end
 
#==============================================================================
# ■ Sprite_ZiifRollIconCursor
#------------------------------------------------------------------------------
#  画像コマンドカーソルのスプライトです。
#==============================================================================
 
class Sprite_ZiifRollIconCursor < Sprite_ZiifCommandSprite
  #--------------------------------------------------------------------------
  # ● 解放
  #--------------------------------------------------------------------------
  def dispose
    self.bitmap.dispose if command_set.cursor_filename.empty?
    super
  end
  #--------------------------------------------------------------------------
  # ● ビットマップの作成
  #--------------------------------------------------------------------------
  def create_bitmap
    self.bitmap   = Cache.system(command_set.cursor_filename)
    self.ox       = self.bitmap.width / 2
    self.oy       = self.bitmap.height / 2
    @effect_count = 0
  end
  #--------------------------------------------------------------------------
  # ● コマンドの透明度の取得
  #--------------------------------------------------------------------------
  def command_set_opacity
    if @effect_count < 32
      value = 176 + @effect_count * 4
    else
      value = 432 - @effect_count * 4
    end
    return (value * command_set.contents_opacity / 255)
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    update_effect
  end
  #--------------------------------------------------------------------------
  # ● 演出効果の更新
  #--------------------------------------------------------------------------
  def update_effect
    self.opacity   = command_set_opacity
    @effect_count  = 0 if @effect_count == 64
    @effect_count += 1
  end
  #--------------------------------------------------------------------------
  # ● 回転幅の取得
  #--------------------------------------------------------------------------
  def roll_width
    return 0
  end
  #--------------------------------------------------------------------------
  # ● 回転高さの取得
  #--------------------------------------------------------------------------
  def roll_height
    (- command_set.height * command_set.openness / 510)
  end
  #--------------------------------------------------------------------------
  # ● 位置情報の更新
  #--------------------------------------------------------------------------
  def update_position
    super
    self.x = command_set.x + roll_width
    self.y = command_set.y + roll_height
    self.z = command_set.z - 5
  end
end
 
#==============================================================================
# ■ Window_ZiifRollIconCommandName
#------------------------------------------------------------------------------
#  回転アイコンコマンドの選択コマンド名を表示するウィンドウです。
#==============================================================================
 
class Window_ZiifRollIconCommandName < Window_Base
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(command_set)
    super(0, 0, command_set.width, fitting_height(1))
    @command_set = command_set
    self.opacity = 0
  end
  #--------------------------------------------------------------------------
  # ● スプライトコマンドの取得
  #--------------------------------------------------------------------------
  def command_set
    return @command_set
  end
  #--------------------------------------------------------------------------
  # ● X座標の取得
  #--------------------------------------------------------------------------
  def window_x
    (command_set.x - self.width / 2)
  end
  #--------------------------------------------------------------------------
  # ● Y座標の取得
  #--------------------------------------------------------------------------
  def window_y
    (command_set.y - self.height / 2)
  end
  #--------------------------------------------------------------------------
  # ● コマンドのビューポートの取得
  #--------------------------------------------------------------------------
  def command_set_viewport
    return command_set.viewport
  end
  #--------------------------------------------------------------------------
  # ● コマンドの可視状態の取得
  #--------------------------------------------------------------------------
  def command_set_visible
    return command_set.visible && command_set.open?
  end
  #--------------------------------------------------------------------------
  # ● コマンドの透明度の取得
  #--------------------------------------------------------------------------
  def command_set_opacity
    return command_set.contents_opacity
  end
  #--------------------------------------------------------------------------
  # ● 位置情報の更新
  #--------------------------------------------------------------------------
  def update_position
    set_information
    update_base_position
  end
  #--------------------------------------------------------------------------
  # ● 基本の位置情報の更新
  #--------------------------------------------------------------------------
  def update_base_position
    self.viewport         = command_set_viewport
    self.visible          = command_set_visible
    self.contents_opacity = command_set_opacity
    self.x                = window_x + command_set.info_window_offset_x
    self.y                = window_y + command_set.info_window_offset_y
    self.z                = command_set.z + 10
  end
  #--------------------------------------------------------------------------
  # ● 表示情報の設定
  #--------------------------------------------------------------------------
  def set_information
    return if command_set.current_item_name == @name
    @name = command_set.current_item_name
    refresh
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    texts = command_set.info_text_separate? ? @name.scan(/\S+/) : [@name]
    texts.push("") if texts.empty?
    self.width  = texts.collect {|text| text_size(text).width + 8 }.max
    self.width += standard_padding * 2
    self.height = fitting_height(texts.size)
    create_contents
    texts.each_with_index do |text, line|
      draw_text(0, line_height * line, contents.width, line_height, text, 1)
    end
  end
end
 
#==============================================================================
# ■ ZiifSpriteCommand_RollIcon
#------------------------------------------------------------------------------
#  回転アイコンコマンド選択を行うモジュールです。Mix-Inにより使用します。
#==============================================================================
 
module ZiifSpriteCommand_RollIcon
  #--------------------------------------------------------------------------
  # ● Mix-In
  #--------------------------------------------------------------------------
  include ZiifSpriteCommand               # 画像コマンド選択モジュール
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_reader   :move_size                # 移動サイズ
  attr_reader   :move_speed               # 移動速度
  attr_reader   :move_count               # 移動カウント
  attr_reader   :move_type                # 移動タイプ
  #--------------------------------------------------------------------------
  # ● スプライトコマンド変数の初期化
  #--------------------------------------------------------------------------
  def init_sprite_command
    super
    @move_size  = 0
    @move_speed = 64
    @move_count = 0
    @move_type  = nil
  end
  #--------------------------------------------------------------------------
  # ● 逆回転の判定
  #--------------------------------------------------------------------------
  def reverse_roll?
    return $game_system.ziifop_reverse_roll
  end
  #--------------------------------------------------------------------------
  # ● 角度の差の取得
  #--------------------------------------------------------------------------
  def angle_difference
    (item_max > 0 ? Math::PI * 2 / item_max : 0)
  end
  #--------------------------------------------------------------------------
  # ● 回転速度の取得
  #--------------------------------------------------------------------------
  def roll_speed
    ([64 - item_max * 3, 16].max * correct_roll_speed)
  end
  #--------------------------------------------------------------------------
  # ● 回転速度の補正値の取得
  #--------------------------------------------------------------------------
  def correct_roll_speed
    case $game_system.ziifop_roll_speed
    when 0; return 0.6   # 遅い
    when 1; return 0.8   # やや遅い
    when 2; return 1     # 普通
    when 3; return 1.2   # やや速い
    when 4; return 1.4   # 速い
    end
  end
  #--------------------------------------------------------------------------
  # ● 回転動作時の角度の取得
  #--------------------------------------------------------------------------
  def roll_angle
    (move? ? move_count * move_speed * correct_roll_angle / 360 : 0)
  end
  #--------------------------------------------------------------------------
  # ● 回転方向の補正値の取得
  #--------------------------------------------------------------------------
  def correct_roll_angle
    case @move_type
    when :right ; return 1   # 右回転
    when :left  ; return -1  # 左回転
    else        ; return 0
    end
  end
  #--------------------------------------------------------------------------
  # ● 回転カウント値の設定
  #--------------------------------------------------------------------------
  def roll_count
    (move_size * 360 / move_speed)
  end
  #--------------------------------------------------------------------------
  # ● 背景画像のファイル名を取得
  #--------------------------------------------------------------------------
  def background_filename
    return ""
  end
  #--------------------------------------------------------------------------
  # ● カーソル画像のファイル名を取得
  #--------------------------------------------------------------------------
  def cursor_filename
    return "RollIconCursor"
  end
  #--------------------------------------------------------------------------
  # ● 情報ウィンドウの空白文字での改行判定
  #--------------------------------------------------------------------------
  def info_text_separate?
    return false
  end
  #--------------------------------------------------------------------------
  # ● 情報ウィンドウのX座標調整
  #--------------------------------------------------------------------------
  def info_window_offset_x
    return 0
  end
  #--------------------------------------------------------------------------
  # ● 情報ウィンドウのY座標調整
  #--------------------------------------------------------------------------
  def info_window_offset_y
    return 0
  end
  #--------------------------------------------------------------------------
  # ● スプライトコマンドクラスの取得
  #--------------------------------------------------------------------------
  def sprite_command_class
    return Sprite_ZiifRollIconCommand
  end
  #--------------------------------------------------------------------------
  # ● コマンド背景クラスの取得
  #--------------------------------------------------------------------------
  def sprite_background_class
    return Sprite_ZiifRollIconBackground
  end
  #--------------------------------------------------------------------------
  # ● コマンドカーソルクラスの取得
  #--------------------------------------------------------------------------
  def sprite_cursor_class
    return Sprite_ZiifRollIconCursor
  end
  #--------------------------------------------------------------------------
  # ● 情報ウィンドウクラスの取得
  #--------------------------------------------------------------------------
  def info_window_class
    return Window_ZiifRollIconCommandName
  end
  #--------------------------------------------------------------------------
  # ● オブジェクトスプライトの作成
  #--------------------------------------------------------------------------
  def make_object_sprites
    @object_sprites[:info_window] = info_window_class.new(self)
    super
  end
  #--------------------------------------------------------------------------
  # ● コマンド内容の作成
  #--------------------------------------------------------------------------
  def create_contents
    super
    set_roll_value
  end
  #--------------------------------------------------------------------------
  # ● 回転値の設定
  #--------------------------------------------------------------------------
  def set_roll_value
    @move_size  = angle_difference
    @move_speed = roll_speed
  end
  #--------------------------------------------------------------------------
  # ● 動作中かどうか?
  #--------------------------------------------------------------------------
  def move?
    @move_type
  end
  #--------------------------------------------------------------------------
  # ● 停止中かどうか?
  #--------------------------------------------------------------------------
  def stop?
    !@move_type
  end
  #--------------------------------------------------------------------------
  # ● 位置移動の更新
  #--------------------------------------------------------------------------
  def update_move
    if move?
      @move_count -= 1
      @move_type   = nil if @move_count <= 0
      update_cursor
    end
  end
  #--------------------------------------------------------------------------
  # ● コマンドを右に回転
  #--------------------------------------------------------------------------
  def roll_right
    @index      = (@index + 1) % item_max
    @move_type  = :right
    @move_count = roll_count
    call_update_help
  end
  #--------------------------------------------------------------------------
  # ● コマンドを左に回転
  #--------------------------------------------------------------------------
  def roll_left
    @index      = (@index - 1 + item_max) % item_max
    @move_type  = :left
    @move_count = roll_count
    call_update_help
  end
  #--------------------------------------------------------------------------
  # ● 回転キーが押されているかどうか?
  #--------------------------------------------------------------------------
  def input_roll?(symbol)
    case $game_system.ziifop_roll_input_type
    when 0; return Input.press?(symbol)     # プレス
    when 1; return Input.trigger?(symbol)   # トリガー
    when 2; return Input.repeat?(symbol)    # リピート
    else  ; return Input.repeat?(symbol)
    end
  end
  #--------------------------------------------------------------------------
  # ● カーソルの移動前処理
  #--------------------------------------------------------------------------
  def process_before_cursor_move
    @cursor_sound_value = false
  end
  #--------------------------------------------------------------------------
  # ● カーソルの移動後処理
  #--------------------------------------------------------------------------
  def process_after_cursor_move
    Sound.play_cursor if @cursor_sound_value
  end
  #--------------------------------------------------------------------------
  # ● 右キーが押されているかどうか?
  #--------------------------------------------------------------------------
  def input_right?
    input_roll?(:RIGHT)
  end
  #--------------------------------------------------------------------------
  # ● 左キーが押されているかどうか?
  #--------------------------------------------------------------------------
  def input_left?
    input_roll?(:LEFT)
  end
  #--------------------------------------------------------------------------
  # ● カーソルを右に移動
  #--------------------------------------------------------------------------
  def cursor_right(wrap = false)
    reverse_roll? ? roll_left : roll_right
    @cursor_sound_value = true
  end
  #--------------------------------------------------------------------------
  # ● カーソルを左に移動
  #--------------------------------------------------------------------------
  def cursor_left(wrap = false)
    reverse_roll? ? roll_right : roll_left
    @cursor_sound_value = true
  end
end