#==============================================================================
# ** Picture Gallery
#------------------------------------------------------------------------------
# © Dargor, 2008
#Â 16/10/08
#Â Version 1.0
#Â Requested by iceblue
#------------------------------------------------------------------------------
#Â VERSION HISTORY:
#Â - 1.0 (16/10/08), Initial release
#------------------------------------------------------------------------------
#Â INSTRUCTIONS:
#Â - Paste this above main
#Â - Edit the constants in the Picture Gallery module
#Â - To lock/unlock a picture, use the following lines of code:
#Â Â Â Â $game_system.lock_picture(picture_id)
#Â Â Â Â $game_system.unlock_picture(picture_id)
#==============================================================================
# Vocabulary
Vocab::CommandPictureGallery = 'Gallery'
#==============================================================================
# ** Picture Gallery Configuration Module
#==============================================================================
module Picture_Gallery
 # Galleries
 # SYNTAX: {'Gallery Name' => [picture_id, picture_id]}
 Galleries = {'Name 1' => [1,2], 'Name 2' => [3,4]}
 # Picture Names
 # SYNTAX: {picture_id => 'name'}
 Pictures = {1 => 'Cave', 2 => 'Mountain', 3 => 'Sky', 4 => 'Ocean'}
 # Name of locked pictures
 Pictures.default = '- Empty -'
 # Files
 # SYNTAX: {picture_id => 'filename'}
 Files = {1 =>'Cave', 2 =>'Mountain', 3 =>'Sea of clouds', 4 =>'Ocean'}
 # Filename of locked pictures
 Files.default = 'Empty'
 # Window XY cpprdinates
 Window_X = 16
 Window_Y = 16
 # Add Picture Gallery to the main menu? (Requires the Custom Commands script)
 Main_Menu = false
end
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#Â This class handles system-related data. Also manages vehicles and BGM, etc.
# The instance of this class is referenced by $game_system.
#==============================================================================
class Game_System
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_accessor :unlocked_pictures
 #--------------------------------------------------------------------------
 # * Alias Listing
 #--------------------------------------------------------------------------
 alias game_system_picture_gallery_system_initialize initialize
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
  game_system_picture_gallery_system_initialize
  @unlocked_pictures = []
 end
 #--------------------------------------------------------------------------
 # * Unlock Picture
 #--------------------------------------------------------------------------
 def unlock_picture(id)
  @unlocked_pictures << id
 end
 #--------------------------------------------------------------------------
 # * Lock Picture
 #--------------------------------------------------------------------------
 def lock_picture(id)
  @unlocked_pictures.delete!(id)
 end
end
#==============================================================================
# ** Window_Command
#------------------------------------------------------------------------------
#Â This window deals with general command choices.
#==============================================================================
class Window_Command < Window_Selectable
 #--------------------------------------------------------------------------
 # * Set Commands
 #--------------------------------------------------------------------------
 def commands=(commands)
  row_max = (commands.size + column_max - 1) / column_max
  remake_contents(width, row_max * WLH + 32)
  @commands = commands
  @item_max = commands.size
  refresh
 end
end
#==============================================================================
# ** Scene_PictureGallery
#------------------------------------------------------------------------------
#Â This class performs the picture gallery screen processing.
#==============================================================================
class Scene_PictureGallery < Scene_Base
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize(from_menu = false)
  @from_menu = from_menu
 end
 #--------------------------------------------------------------------------
 # * Start Processing
 #--------------------------------------------------------------------------
 def start
  @picture_sprite = Sprite.new
  @gallery_window = Window_Command.new(160,Picture_Gallery::Galleries.keys)
  @gallery_window.x = Picture_Gallery::Window_X
  @gallery_window.y = Picture_Gallery::Window_Y
  @gallery_window.height = 56
  @gallery_window.active = false
  @picture_window = Window_Command.new(160, ['','','',''])
  @picture_window.x = Picture_Gallery::Window_X
  @picture_window.y = Picture_Gallery::Window_Y + 56
  @picture_window.height = (4 * 24) + 32
  update_picture_window_contents
  update_picture_window
 end
 #--------------------------------------------------------------------------
 # * Terminate Processing
 #--------------------------------------------------------------------------
 def terminate
  @picture_sprite.dispose
  @gallery_window.dispose
  @picture_window.dispose
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
  @gallery_window.update
  @picture_window.update
  if @gallery_window.active
   update_gallery_window
   return
  end
  if @picture_window.active
   update_picture_window
   return
  end
 end
 #--------------------------------------------------------------------------
 # * Update Gallery Window
 #--------------------------------------------------------------------------
 def update_gallery_window
  if Input.trigger?(Input::B)
   Sound.play_cancel
   if @from_menu
    index = $game_system.menu_commands.index(Vocab::CommandPictureGallery)
    $scene = Scene_Menu.new(index)
   else
    $scene = Scene_Map.new
   end
   return
   return
  end
  update_picture_window_contents
  if Input.trigger?(Input::C)
   @gallery_window.active = false
   @picture_window.active = true
  end
 end
 #--------------------------------------------------------------------------
 # * Update Picture Window
 #--------------------------------------------------------------------------
 def update_picture_window
  if Input.trigger?(Input::B)
   @gallery_window.active = true
   @picture_window.active = false
   return
  end
  gallery = Picture_Gallery::Galleries[@gallery_window.selection]
  picture_id = gallery[@picture_window.index]
  if $game_system.unlocked_pictures.include?(picture_id)
   file = Picture_Gallery::Files[picture_id]
  else
   file = Picture_Gallery::Files.default
  end
  @picture_sprite.bitmap = Cache.picture(file)
 end
 #--------------------------------------------------------------------------
 # * Update Picture Window Contents
 #--------------------------------------------------------------------------
 def update_picture_window_contents
  pictures = []
  picture_ids = []
  for picture_id in Picture_Gallery::Galleries[@gallery_window.selection]
   picture_ids << picture_id
   if $game_system.unlocked_pictures.include?(picture_id)
    pictures << Picture_Gallery::Pictures[picture_id]
   else
    pictures << Picture_Gallery::Pictures.default
   end
  end
  return if @picture_window.commands == pictures
  @picture_window.commands = pictures
  @picture_window.height = (4 * 24) + 32
  for i in 0...picture_ids.size
   unless $game_system.unlocked_pictures.include?(picture_ids[i])
    @picture_window.draw_item(i, false)
   end
  end
 end
end
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#Â This class performs the menu screen processing.
#==============================================================================
class Scene_Menu < Scene_Base
 #--------------------------------------------------------------------------
 # * Alias Listing
 #--------------------------------------------------------------------------
 alias dargor_vx_cmcpicgal_menu_create_command_window create_command_window
 alias dargor_vx_cmcpicgal_menu_update_command_selection update_command_selection
 #--------------------------------------------------------------------------
 # * Create Command Window
 #--------------------------------------------------------------------------
 def create_command_window
  if Picture_Gallery::Main_Menu
   commands = $game_system.menu_commands
   index = commands.index(Vocab::save)
   $game_system.add_menu_command(index, Vocab::CommandPictureGallery)
  end
  dargor_vx_cmcpicgal_menu_create_command_window
 end
 #--------------------------------------------------------------------------
 # * Update Command Selection
 #--------------------------------------------------------------------------
 def update_command_selection
  dargor_vx_cmcpicgal_menu_update_command_selection
  if Picture_Gallery::Main_Menu
   command = @command_window.selection
   if Input.trigger?(Input::C)
    case @command_window.selection
    when Vocab::CommandPictureGallery
     $scene = Scene_PictureGallery.new(true)
    end
   end
  end
 end
end