#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# ** Banking Script
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# Written by: Kain Nobel
# Version: 0.0
# Date Updated: 5/9/2008
# Date Created: 5/9/2008
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
################################################################################
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# * Game_Bank
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
class Game_Bank
 #[Attributes]- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 attr_accessor :gold        # How much gold you have on hand
 attr_accessor :checking      # Checking account balance
 attr_accessor :savings      # Savings account balance
 attr_accessor :credit_score    # Credit SCORE
 #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 def initialize
  @gold = $game_party.gold
  @checking = checking
  @savings = savings
  @credit_score = credit_score
 end
 #------------------
 # * Define Accounts
 #------------------
 def account
  case @accounts
  when 'Gold'
   @balance = $game_party.gold
  when 'Checking'
   @balance = checking
  when 'Savings'
   @balance = savings
  end
  return @balance
 end
 #------------------
 # * Define Balances
 #------------------
 def balance
  gold = @accounts('Gold')
  checking = @accounts('Checking')
  savings = @accounts('Saving')
 end
 #----------------
 # * Gain Checking
 #----------------
 def gain_checking(n)
  @checking = [[@checking + n, 0].max, 9999999].min
 end
 #----------------
 # * Lose Checking
 #----------------
 def lose_checking(n)
  checking(-n)
 end
 #---------------
 # * Gain Savings
 #---------------
 def gain_savings(n)
  @savings = [[@savings + n, 0].max, 9999999].min
 end
 #---------------
 # * Lose Savings
 #---------------
 def lose_savings(n)
  savings(-n)
 end
end
################################################################################
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# * Window_Bank
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
class Window_Bank < Window_Base
 #------------------------
 # * Initialization Method
 #------------------------
 def initialize
  # These variables control Window Offset & Size (see super)
  ox = 0
  oy = 0
  x = 260
  y = 128
  # Bank Window Dispose method is false
  bank_window_dispose = false
  # Create Window Offset & Size
  super(ox, oy, x, y)
  self.contents = Bitmap.new(width - 32, height - 32)
  # Initialize Banking Variables
  @mode = 0
  @gold = 0
  @checking = 0
  @savings = 0
  @credit_score = 0
  # Call Refresh method
  self.opacity = 160
  update
 end
 #-----------------
 # * Refresh Method
 #-----------------
 def update
  # Clear page for new data
  self.contents.clear
  # Define Banking variables
  @gold = $game_party.gold
  @checking = $game_variables[CHECKING]
  @savings = $game_variables[SAVINGS]
  @credit_score = $game_variables[CREDIT]
  # Set System Color
  self.contents.font.color = system_color
  # Draw Account names
  self.contents.draw_text(0, 0, 96, 36, "Gold :")
  self.contents.draw_text(0, 0, 96, 72, "Checking :")
  self.contents.draw_text(0, 0, 96, 106, "Savings :")
  self.contents.draw_text(0, 0, 192, 140, "CreditSCORE :")
  # Set Normal Color
  self.contents.font.color = normal_color
  # Draw Account variables
  self.contents.draw_text(128, 0, 96, 36, "$" + @gold.to_s, 2)
  self.contents.draw_text(128, 0, 96, 72, "$" + @checking.to_s, 2)
  self.contents.draw_text(128, 0, 96, 106, "$" + @savings.to_s, 2)
  self.contents.draw_text(128, 0, 96, 140, "$" + @credit_score.to_s, 2)
  # Dispose of Window with B button
 end
end
################################################################################
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# * Window_BankCommand
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
class Window_BankCommand < Window_Selectable
 #------------------------
 # * Initialization Method
 #------------------------
 def initialize
  # These variables control Window Offset & Size (see super)
  ox = 0
  oy = 0
  x = 128
  y = 128
  super(ox, oy, x, y)
  self.contents = Bitmap.new(width - 32, height - 32)
  @column_max = 1
  @item_max = 3
  # Write Commands
  b1 = "Checking Account"
  b2 = "Savings Account"
  b3 = "Credit & Loans"
  b4 = "Promotional"
  @commands = [b1, b2, b3, b4]
  refresh
  self.index = 0
 end
 #-----------------
 # * Refresh Method
 #-----------------
 def refresh
  self.contents.clear
  for i in 0...@item_max
   draw_item(i)
  end
 end
 #-------------------------
 # * Draw Item
 #   index : item number
 #-------------------------
 def draw_item(index)
  y = 5 + index * 160
  self.contents.draw_text(x, 0, 128, 32, @commands[index])
 end
end
################################################################################
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# * Scene_Bank
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
class Scene_Bank
 #------------------------
 # * Initialization Method
 #------------------------
 def initialize
  # Create Window_Bank
  @window_bank = Window_Bank.new
  @window_bank.ox = (self.x * -1)
  @window_bank.oy = (self.y * -1)
  @window_bank.opacity = 160
  # Create Window_BankCommand
  @command_window = Window_BankCommand.new
  @command_window.ox = 0
  @command_window.oy = 0
  @window_bank.opacity = 160
  # Create Window_Help
  @window_help = Window_Help.new
  @window_help.ox = (self.x * -1)
  @window_help.oy = (self.y * -1)
  @window_help.opacity = 160
  # Execute transition
  Graphics.transition
  # Main loop
  loop do
   # Update game screen
   Graphics.update
   # Update input information
   Input.update
   # Frame update
   update
   # Abort loop if screen is changed
   if $scene != self
    break
   end
  end
  # Prepare for transition
  Graphics.freeze
  # Dispose of windows
  @command_window.dispose
  @window_bank.dispose
  @window_help.dispose
 end
 #----------------
 # * Update Method
 #----------------
 def update
  #[Window Animation]---------------------------------------------------------
  # Animate Positioning Window_Bank (Window Comes in from bottom-right corner.)
  if @window_bank.ox < @window_bank.x or @window_bank.oy < @window_bank.y
   @window_bank.ox -= (@window_bank.x * 10)
   @window_bank.oy -= (@window_bank.y * 10)
   @window_bank.opacity += (@window_bank.opacity / 10)
  end
  # Animate Positioning Window_BankCommand (Window comes in from left side)
  if @command_window.ox < @command_window.x
   @command_window.ox += (@command_window.x * 10)
   @command_window.opacity += (@command_window.opacity / 10)
  end
  # Animate Positioning Window_Help (Window comes in from top)
  if @window_help.oy < @window_help.y
   @window_help.oy += (@window_help.y / 10)
   @window_help.opacity += (@window_help.opacity / 10)
  end
  #[Account Access]-----------------------------------------------------------
  # Disable ALL Account Access
  if $game_bank.all_disabled
   @command_window.disable_item(0) # Checking Account
   @command_window.disable_item(1) # Savings Account
   @command_window.disable_item(2) # Credit and Loans
   @command_window.disable_item(3) # Promotional Deals
  else
   # Disable Checking Account
   if $game_bank.checking_disabled
    @command_window.disable_item(0)
   end
   # Disable Savings Account
   if $game_bank.savings_disabled
    @command_window.disable_item(1)
   end
   # Disable Credit and Loans
   if $game_bank.loans_disabled
    @command_window.disable_item(2)
   end
   # Disable Promotions and Deals
   if $game_bank.deals_disabled
    @command_window.disable_item(3)
   end
   #[Input::C]---------------------------------------------------------------
   if Input.press?(Input::C) # Selection Button
    case @command_window.index
    # Checking Account
    when 0
     checking_account
     return
    end
    # Savings Account
    when 1
     savings_account
     return
    end
    # Credit and Loans
    when 2
     credit_and_loans
     return
    end
    # Promotional Deals"
    when 3
     promotional
     return
    else
     # Cycle Cursor
     if @command_window.index > (@command_window.item_max - 1)
      @command_window.index = 0
     end
    end
   end
   #[Input::B]---------------------------------------------------------------
   if Input.press?(Input::B) # Cancel button
    if @command_window.active == false
     @command_window.active = true
     @transaction_window.active = false
    else
     $scene = Scene_Map.new
    end
   end
  end
 end
 #--------------------------
 # * Define Checking Account
 #--------------------------
 def help_update
  # Window_BankCommand
  if @command_window.active = true
   @window_transaction.active = false
   @window_transaction.visible = false
   for i in 0..@command_window.index
    case @command_window.index
    when 0
     @window_help.set_text("Access your Checking Account.")
    when 1
     @window_help.set_text("Access your Savings Account.")
    when 2
     @window_help.set_text("Do you need Cash? Do you need it now?")
    when 3
     @window_help.set_text("Find the latest and greatest Promotional Offers!")
    end
   end
  end
  # Window_Transaction
  if @command_window.active == false && @window_transaction.active == true
   @window_transaction.visible = true
   for i in 0..@transaction_window.index
    case @window_transaction.index
    when 0
     @window_help.set_text("Deposit Money into Checking.")
    when 1
     @window_help.set_text("Withdraw Money from Checking.")
    when 2
     @window_help.set_text("Transfer Money from Savings.")
    end
   end
  end
 end
end