#==============================================================================
# ■ HIDE_COIN_GAME_BASE vol.4.00(Scene_Mapより下に挿入)
#------------------------------------------------------------------------------
# ※『Slot_Machine』,『Poker_Game』,
# ※『Open_Panel』,『Coin_Shop』,『Roulette』より上に挿入
# 11/10/01
#==============================================================================
module HIDE_COIN_GAME_BASE
  # □点滅する選択肢文字を使用する(『Blink_Window_Command 3.00以上』必須)
  BLINK = false#true#
end
#==============================================================================
# ■ Scene_Map
#==============================================================================
class Scene_Map
  #--------------------------------------------------------------------------
  # ■ フレーム更新
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_scene_map_coingame_update update;end
  def update
    # □元の処理を実行
    hidesp_scene_map_coingame_update
    # プレイヤーの移動中ではない場合
    unless $game_player.moving?
      # □スロットマシーンの呼び出し
      if $game_temp.slot_calling
        call_slot
      end
      # □ポーカーの呼び出し
      if $game_temp.poker_calling
        call_poker
      end
      # □オープンパネルの呼び出し
      if $game_temp.panel_calling
        call_panel
      end
      # □ルーレットの呼び出し
      if $game_temp.roulette_calling
        call_roulette
      end
      # □コイン交換所の呼び出し
      if $game_temp.coin_shop_calling
        call_coin_shop
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ スロットマシーンの呼び出し
  #--------------------------------------------------------------------------
  def call_slot
    # スロット呼び出しフラグをクリア
    $game_temp.slot_calling = false
    # プレイヤーの姿勢を矯正
    $game_player.straighten
    # スロット画面に切り替え
    $scene = Scene_Slot.new
  end
  #--------------------------------------------------------------------------
  # ■ ポーカーの呼び出し
  #--------------------------------------------------------------------------
  def call_poker
    # ポーカー呼び出しフラグをクリア
    $game_temp.poker_calling = false
    # プレイヤーの姿勢を矯正
    $game_player.straighten
    # ポーカー画面に切り替え
    $scene = Scene_Poker.new
  end
  #--------------------------------------------------------------------------
  # ■ オープンパネルの呼び出し
  #--------------------------------------------------------------------------
  def call_panel
    # オープンパネル呼び出しフラグをクリア
    $game_temp.panel_calling = false
    # プレイヤーの姿勢を矯正
    $game_player.straighten
    # オープンパネル画面に切り替え
    $scene = Scene_Panel.new
  end
  #--------------------------------------------------------------------------
  # ■ ルーレットの呼び出し
  #--------------------------------------------------------------------------
  def call_roulette
    # ルーレット呼び出しフラグをクリア
    $game_temp.roulette_calling = false
    # プレイヤーの姿勢を矯正
    $game_player.straighten
    # ルーレット画面に切り替え
    $scene = Scene_Roulette.new
  end
  #--------------------------------------------------------------------------
  # ■ コイン交換所の呼び出し
  #--------------------------------------------------------------------------
  def call_coin_shop
    # コインショップ呼び出しフラグをクリア
    $game_temp.coin_shop_calling = false
    # プレイヤーの姿勢を矯正
    $game_player.straighten
    # コインショップ画面に切り替え
    case $game_temp.coin_shop_type
    when 0
      $scene = Scene_Coin_Chenge.new
    when 1
      $scene = Scene_Coin_shop.new
    end
  end
end
#==============================================================================
# ■ Game_Temp
#==============================================================================
class Game_Temp
  #--------------------------------------------------------------------------
  # ■ 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_accessor :slot_calling              # スロット呼び出しフラグ
  attr_accessor :slot_type                 # スロットタイプを格納
  attr_accessor :slot_pattern              # スロットの絵柄パターンを格納
  attr_accessor :poker_calling             # ポーカー呼び出しフラグ
  attr_accessor :poker_type                # ポーカータイプを格納
  attr_accessor :panel_calling             # オープンパネル呼び出しフラグ
  attr_accessor :panel_type                # オープンパネルタイプを格納
  attr_accessor :panel_pattern             # オープンパネルの絵柄パターンを格納
  attr_accessor :coin_shop_calling         # コインショップ呼び出しフラグ
  attr_accessor :coin_shop_type            # 0=コイン購入 1=アイテムに交換
  attr_accessor :coin_shop_pattern         # コインショップパターンを格納
  
  attr_accessor :roulette_calling          # ルーレット呼び出しフラグ
  attr_accessor :roulette_type             # ルーレットタイプを格納
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_game_temp_coingame_initialize initialize;end
  def initialize
    # □元の処理を実行
    hidesp_game_temp_coingame_initialize
    @slot_calling = false
    @slot_type = 0
    @slot_pattern = 0
    @poker_calling = false
    @poker_type = 0
    @panel_calling = false
    @panel_type = 0
    @panel_pattern = 0
    @coin_shop_calling = false
    @coin_shop_type = 0
    @coin_shop_pattern = 0
    @roulette_calling = false
    @roulette_type = 0
    
  end
end
#==============================================================================
# ■ Game_Party
#==============================================================================
class Game_Party
  #--------------------------------------------------------------------------
  # ■ 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_accessor :roulette_average          # ルーレット確立を格納
  attr_accessor :roulette_draw
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_coin_game_party_initialize initialize;end
  def initialize
    @roulette_average = []
    @roulette_draw = []
    # □元の処理を開始
    hidesp_coin_game_party_initialize
  end
end
#==============================================================================
# ■ Interpreter
#==============================================================================
class Interpreter
  #--------------------------------------------------------------------------
  # ■ スロットの処理
  #--------------------------------------------------------------------------
  def make_slot(type = 0,pattern = nil)
    # バトル中断フラグをセット
    $game_temp.battle_abort = true
    # インデックスを進める
    @index += 1
    # □スロット呼び出しフラグをセット
    $game_temp.slot_calling = true
    # □スロットタイプを格納
    $game_temp.slot_type = type
    # □スロットの絵柄パターンを格納
    $game_temp.slot_pattern = pattern
    # 終了
    return false
  end
  #--------------------------------------------------------------------------
  # ■ ポーカーの処理
  #--------------------------------------------------------------------------
  def make_poker(type = 0)
    # バトル中断フラグをセット
    $game_temp.battle_abort = true
    # インデックスを進める
    @index += 1
    # □ポーカー呼び出しフラグをセット
    $game_temp.poker_calling = true
    # □ポーカータイプを格納
    $game_temp.poker_type = type
    # 終了
    return false
  end
  #--------------------------------------------------------------------------
  # ■ オープンパネルの処理
  #--------------------------------------------------------------------------
  def make_panel(type = 0,pattern = 0)
    # バトル中断フラグをセット
    $game_temp.battle_abort = true
    # インデックスを進める
    @index += 1
    # □オープンパネル呼び出しフラグをセット
    $game_temp.panel_calling = true
    # □オープンパネルタイプを格納
    $game_temp.panel_type = type
    # □オープンパネルの絵柄パターンを格納
    $game_temp.panel_pattern = pattern
    # 終了
    return false
  end
  #--------------------------------------------------------------------------
  # ■ ルーレットの処理
  #--------------------------------------------------------------------------
  def make_roulette(type = 0)
    # バトル中断フラグをセット
    $game_temp.battle_abort = true
    # インデックスを進める
    @index += 1
    # □ルーレット呼び出しフラグをセット
    $game_temp.roulette_calling = true
    # □ルーレットタイプを格納
    $game_temp.roulette_type = type
    # 終了
    return false
  end
  #--------------------------------------------------------------------------
  # ■ コイン交換所の処理
  #--------------------------------------------------------------------------
  def make_coin_shop(type = 0,pattern = 0)
    # バトル中断フラグをセット
    $game_temp.battle_abort = true
    # インデックスを進める
    @index += 1
    # □コイン交換所タイプを格納
    $game_temp.coin_shop_type = type
    # □コイン交換所パターンを格納
    $game_temp.coin_shop_pattern = pattern
    # □コイン交換所呼び出しフラグをセット
    $game_temp.coin_shop_calling = true
    # 終了
    return false
  end
end
#==============================================================================
# ■ Window_Coin_Game_back
# コインゲームの背景を作成するクラス
#==============================================================================
class Window_Coin_Game_back
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(background,text = "" ,num = nil,x = 0,y = 0)
    # ■背景ウィンドウを作成
    @back_window = Sprite.new
    @back_window.bitmap = Bitmap.new(640,480)
    @back_window.bitmap = RPG::Cache.windowskin(background)
    if text != "" && num != nil
      @num = num
      @text = text
      refresh(x,y)
    end
  end
  #--------------------------------------------------------------------------
  # ■ 更新
  #--------------------------------------------------------------------------
  def refresh(x,y)
    cx = @back_window.bitmap.text_size(@num.to_s).width
    ncr = Color.new(255,255,0,255)
    scr = Color.new(0,0,0,255)
    fonts = Copy_Font.new(20,false,false,true,false,["Georgia","ＭＳ ゴシック"],ncr,scr)
    @back_window.bitmap.draw_cache_text(x,y,160,32,@num.to_s,2,fonts)
    @back_window.bitmap.draw_cache_text(x+30,y,160,32,@text,0,fonts)
    fonts = Copy_Font.new(16,true,false,true,false,["Arial","ＭＳ ゴシック"],ncr,scr)
    @back_window.bitmap.draw_cache_text(x-cx-4,y,160,32,"x",2,fonts)
  end
  #--------------------------------------------------------------------------
  # ■ テキストの追加描画
  #--------------------------------------------------------------------------
  def draw_text(x,y,w,h,text,align,fonts)
    @back_window.bitmap.draw_cache_text(x,y,w,h,text,align,fonts)
  end
  #--------------------------------------------------------------------------
  # ■ テキストの追加描画
  #--------------------------------------------------------------------------
  def draw_rect(x,y,pic,rect,opa = 255)
    @back_window.bitmap.blt(x,y,pic,rect,opa = 255)
  end
  #--------------------------------------------------------------------------
  # ■ bitmap
  #--------------------------------------------------------------------------
  def bitmap
    return @back_window.bitmap
  end
  #--------------------------------------------------------------------------
  # ■ 解放
  #--------------------------------------------------------------------------
  def dispose
    if @back_window.bitmap != nil
      @back_window.bitmap.dispose
    end
    @back_window.dispose
  end
end
#==============================================================================
# ■ Window_Picture_Select  vol.1.00
#------------------------------------------------------------------------------
# 11/10/01
#==============================================================================
class Window_Picture_Select < Window_Selectable
  include HIDE_COIN_GAME_BASE
  attr_accessor :fonts          # 文字装飾を取得
  attr_accessor :colors         # 通常色/無効色の切り替えフラグ
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(x,y,width,height,coms,picture,fonts,helps,help_fonts)
    @dx = width % 128 == 0 ? 0 : 32
    super(x,y,width + @dx,height)
    self.contents = Bitmap.new(width - 32 + @dx,height - 32)
    @c_width = width
    @item_max = coms.size
    @column_max = coms.size
    @commands = coms
    @picture = picture
    @fonts = fonts
    @helps = helps
    @help_fonts = help_fonts
    # □ヘルプの初期化
    reset?
    @colors = [false]*@item_max
    if HIDE_COIN_GAME_BASE::BLINK
      self.windowskin = Bitmap.new(1,1)
    else
      self.opacity = 0
    end
    self.active = false
    self.visible = false
    self.index = -1
    refresh
    make_helps(helps)
  end
  #--------------------------------------------------------------------------
  # ■ 点滅文字ウィンドウの座標更新
  #     index    : カーソルのindex
  #     ch       : カーソルの移動幅
  #--------------------------------------------------------------------------
  def set_blink_window?(index,ch = 32,
    x = @index % @column_max * (@c_width / @column_max) + self.x + 16,
    y = @index / @column_max * 32 - self.oy + self.y + 16)
    unless @blink_window == nil or @blink_window.disposed?
      if index == -1
        @blink_window.viewport.oy = -[ch,32].max
        return
      end
      @blink_window.viewport.rect.x = x
      @blink_window.viewport.ox = index % @column_max * (@c_width/@column_max)
      @blink_window.viewport.rect.y = y
      @blink_window.viewport.oy = index / @column_max * ch
    end
    # カーソルの座標を計算
    x = @index % @column_max * (@c_width / @column_max)
    y = @index / @column_max * 32 - self.oy
    # □カーソルの矩形を更新
    self.cursor_rect.set(x,y,@c_width / @column_max,32)
  end
  #--------------------------------------------------------------------------
  # ■ カーソルの矩形更新
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # カーソル位置が 0 未満の場合
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # 現在の行を取得
    row = @index / @column_max
    # 現在の行が、表示されている先頭の行より前の場合
    if row < self.top_row
      # 現在の行が先頭になるようにスクロール
      self.top_row = row
    end
    # 現在の行が、表示されている最後尾の行より後ろの場合
    if row > self.top_row + (self.page_row_max - 1)
      # 現在の行が最後尾になるようにスクロール
      self.top_row = row - (self.page_row_max - 1)
    end
    # カーソルの幅を計算
    cursor_width = @dx == 0 ? @c_width/@column_max - 32 : @c_width/@item_max - 4
    # カーソルの座標を計算
    x = @dx == 0 ? @index % @column_max * (cursor_width + 32) : @index * (@c_width/@item_max)
    y = @index / @column_max * 32 - self.oy
    # カーソルの矩形を更新
    self.cursor_rect.set(x, y, cursor_width, 32)
    # □点滅文字ウィンドウの更新
    if HIDE_COIN_GAME_BASE::BLINK
      set_blink_window?(@index)
      @blink_window.visible = self.visible
    end
  end
  #--------------------------------------------------------------------------
  # ■ ヘルプBitmapを作成(軽量化)
  #--------------------------------------------------------------------------
  def make_helps(data)
    @helps_bitmap = Bitmap.new(640-32,32*data.size)
    for i in 0...data.size
      @helps_bitmap.draw_cache_text(8,i*32,640,32,data[i],0,@help_fonts)
    end
  end
  #--------------------------------------------------------------------------
  # ■ ヘルプの初期化
  #--------------------------------------------------------------------------
  def reset?
    @old_data = ""
  end
  #--------------------------------------------------------------------------
  # ■ リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # ■ 項目の描画
  #--------------------------------------------------------------------------
  def draw_item(index)
    @sw = @c_width/@item_max
    fonts = @fonts.dup
    # □点滅ウィンドウの作成
    if HIDE_COIN_GAME_BASE::BLINK
      make_blink_window?(32,self.x+16,self.y+16,@c_width/@column_max-32+@dx,width,row_max*32)
    end
    if @colors[index]
      # □無効色
      fonts.color = Color.new(80,80,80,255)
    end
    x = index * @sw
    pic = RPG::Cache.windowskin(@picture)
    fonts.cache_key?(@picture + "icon")
    self.contents.draw_cache_text(x,0,@sw-32+@dx,32,@commands[index],1,fonts)
    self.contents.blt(x,0,pic,Rect.new(0,0,96,32))
    # □点滅文字の描画
    if HIDE_COIN_GAME_BASE::BLINK
      fonts.color = Color.new(255,255,0,255)
      fonts.cache_key?(@picture + "icon")
      @blink_window.bitmap.blt(x,0,pic,Rect.new(96,0,96,32))
      @blink_window.bitmap.draw_cache_text(x,0,@sw-32+@dx,32,@commands[index],1,fonts)
    end
  end
  #--------------------------------------------------------------------------
  # ■ アイテムの取得
  #--------------------------------------------------------------------------
  def data
    return @helps[self.index]
  end
  #--------------------------------------------------------------------------
  # ■ ヘルプテキスト更新
  #--------------------------------------------------------------------------
  def update_help
    @help_window.contents = @helps_bitmap
    @help_window.oy = self.index*32
  end
end
