Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #sb:nap_text_img_gallery [menu]
- =begin
- Napoleons Text Image Gallery
- Version: 1.00
- Commissioned by: AlliedG
- Author: Napoleon
- About:
- - A basic image gallery (but with texts).
- - Supports locking and unlocking images.
- - Compatible with Yanfly's Menu Engine. Just set ADD_TO_MENU to false and
- configure the menu options in his script instead.
- - Supports saving & loading.
- - The menu-command is disabled when all images are locked.
- Instructions:
- - Place below "▼ Materials" but above "▼ Main Process".
- - Script Calls:
- # id = the id of the image, if no id was specified in the settings-section then
- # the id is the filename.
- gallery_show(id)
- gallery_lock(id)
- gallery_unlock(id)
- gallery_lock_all
- gallery_unlock_all
- Requires:
- - RPG Maker VX Ace
- Terms of Use:
- - Attribution 3.0 Unported (CC BY 3.0)
- http://creativecommons.org/licenses/by/3.0/
- - Credits:
- AlliedG
- Napoleon
- Version History:
- 1.00 (18 August 2014)
- - First Release
- =end
- #===============================================================================
- $imported ||= {}
- $imported[:nap_text_img_gallery] = 1.00
- module Nap; module Image_Gallery
- #===============================================================================
- # Settings
- #===============================================================================
- FOLDER = 'Pictures' # The folder that contains the images.
- DEFAULT_LOCKED = true # Lock images by default?
- CENTER_TEXT = true # Center the image display_name text?
- ADD_TO_MENU = false # Add a menu item for this script?
- MENU_TEXT = 'Gallery' # The menu display-text if ADD_TO_MENU is set to true.
- # Enter your image data here. Images not entered will be ignored.
- # Optional settings:
- # id = your UNIQUE id. Both symbols and strings can be used (probably more but not tested).
- # display_name = the display name of this image in the menu. If left out then the filename is used for the display name instead.
- # locked = true/false. Defaults to DEFAULT_LOCKED.
- IMAGES = [ # Only :filename is required. Do not use duplicate ID's or you will overwrite the previous one.
- { :id => :battlefield, :filename => 'battlefield', :display_name => 'Oludian Battlefield', :locked => false},
- { :id => :grave, :filename => 'Grave_scene', :display_name => 'Elizabeth Grave', :locked => false},
- { :id => :road, :filename => 'arcton_road', :display_name => 'Arcton Road', :locked => false},
- { :id => :castle, :filename => 'arcton_castle', :display_name => 'Arcton Castle' },
- { :id => :newmont, :filename => 'newmont_port', :display_name => 'Newmont Port' },
- { :id => :fish, :filename => 'erika_fish', :display_name => 'Hungry Erika' },
- { :id => :misty, :filename => 'Misty_Cavern', :display_name => 'Misty Cavern' },
- { :id => :dasia, :filename => 'dasia_port', :display_name => 'Dasia Port' },
- { :id => :dasiaj, :filename => 'Dasia_Jungle', :display_name => 'Dasia Jungle' },
- ]
- #===============================================================================
- # Do not edit below this line!
- # Class Image
- #===============================================================================
- class Img
- attr_reader :id
- attr_accessor :filename
- attr_accessor :display_name
- attr_accessor :locked
- #---------------------------------------------------------------------------
- # Initialize
- #---------------------------------------------------------------------------
- def initialize(params={})
- raise 'Img.initialize: missing parameter!' if !([:filename].all? { |key| params.key?(key) })
- params = {:id => params[:filename], :display_name => params[:filename], :locked => DEFAULT_LOCKED}.merge(params)
- @id = params[:id]
- @filename = params[:filename]
- @display_name = params[:display_name]
- @locked = params[:locked]
- end
- #---------------------------------------------------------------------------
- # To String
- #---------------------------------------------------------------------------
- def to_s
- @display_name
- end
- end
- #===============================================================================
- # Image Data
- #===============================================================================
- class Image_Data
- attr_accessor :images
- def [](key); @images[key]; end
- #---------------------------------------------------------------------------
- # Initialize
- #---------------------------------------------------------------------------
- def initialize
- reset
- end
- #---------------------------------------------------------------------------
- # Reset
- #---------------------------------------------------------------------------
- def reset
- @images = {}
- IMAGES.each { |img_hash|
- new_img = Img.new(img_hash)
- @images[new_img.id] = new_img
- }
- end
- #---------------------------------------------------------------------------
- # Visible Images
- #---------------------------------------------------------------------------
- def visible_images
- @images.values.select { |img| !img.locked}
- end
- end
- $image_data = Image_Data.new # Create the global data
- end; end
- #===============================================================================
- # Cache
- #===============================================================================
- module Cache
- #-----------------------------------------------------------------------------
- # Napoleons Image Gallery
- #-----------------------------------------------------------------------------
- def self.nap_img_gallery(filename)
- load_bitmap("Graphics/#{Nap::Image_Gallery::FOLDER}/", filename)
- end
- end
- #===============================================================================
- # Saving & Loading
- #===============================================================================
- module DataManager
- class << self
- alias nap_img_gallery_make_save_contents make_save_contents
- alias nap_img_gallery_extract_save_contents extract_save_contents
- end
- #-----------------------------------------------------------------------------
- # Make Save Contents [ALIAS]
- #-----------------------------------------------------------------------------
- def self.make_save_contents
- contents = nap_img_gallery_make_save_contents
- contents[:nap_img_gallery] = $image_data
- contents
- end
- #-----------------------------------------------------------------------------
- # Extract Save Contents [ALIAS]
- #-----------------------------------------------------------------------------
- def self.extract_save_contents(contents)
- nap_img_gallery_extract_save_contents(contents)
- $image_data = contents[:nap_img_gallery]
- end
- end
- #===============================================================================
- # Game Interpreter
- #===============================================================================
- class Game_Interpreter
- #-----------------------------------------------------------------------------
- # Gallery Show [NEW]
- #-----------------------------------------------------------------------------
- def gallery_show(id)
- SceneManager.call(Scene_fullscreen_img)
- SceneManager.scene.prepare($image_data[id])
- end
- #-----------------------------------------------------------------------------
- # Gallery Unlock [NEW]
- # *args: id of the image to unlock (can be more than one).
- #-----------------------------------------------------------------------------
- def gallery_unlock(*args)
- args.each { |id| $image_data[id].locked = false }
- end
- #-----------------------------------------------------------------------------
- # Unlock All [NEW]
- #-----------------------------------------------------------------------------
- def gallery_unlock_all
- $image_data.images.values.each { |img_data| img_data.locked = false }
- end
- #-----------------------------------------------------------------------------
- # Lock All [NEW]
- #-----------------------------------------------------------------------------
- def gallery_lock_all
- $image_data.images.values.each { |img_data| img_data.locked = true }
- end
- #-----------------------------------------------------------------------------
- # Gallery Lock [NEW]
- # *args: id of the image to lock (can be more than one).
- #-----------------------------------------------------------------------------
- def gallery_lock(*args)
- args.each { |id| $image_data[id].locked = true }
- end
- end
- #===============================================================================
- # Window Text Image Gallery
- #===============================================================================
- class Window_Text_Img_Gallery < Window_Selectable
- @@last_idx = -1
- def last_idx; @@last_idx; end
- def last_idx=(value); @@last_idx = value; end
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize
- @data = $image_data.visible_images
- super(0, 0, Graphics.width, Graphics.height)
- activate
- set_initial_selection
- refresh
- end
- #-----------------------------------------------------------------------------
- # Set Initial Selection
- #-----------------------------------------------------------------------------
- def set_initial_selection
- if (last_idx > 0) && (last_idx < item_max)
- select(last_idx)
- elsif item_max > 0
- select(0)
- end
- end
- #-----------------------------------------------------------------------------
- # Column Max
- #-----------------------------------------------------------------------------
- def col_max
- return 2
- end
- #--------------------------------------------------------------------------
- # Spacing
- #--------------------------------------------------------------------------
- def spacing
- return 16
- end
- #-----------------------------------------------------------------------------
- # Item Max
- #-----------------------------------------------------------------------------
- def item_max
- return @data.length
- end
- #-----------------------------------------------------------------------------
- # Update
- #-----------------------------------------------------------------------------
- def update
- super
- if Input.trigger?(:B)
- SceneManager.return
- Sound.play_cancel
- end
- end
- #-----------------------------------------------------------------------------
- # Draw Item
- #-----------------------------------------------------------------------------
- def draw_item(index)
- draw_text(item_rect_for_text(index), @data[index].display_name, Nap::Image_Gallery::CENTER_TEXT ? 1 : 0)
- end
- #-----------------------------------------------------------------------------
- # Ok Enabled?
- #-----------------------------------------------------------------------------
- def ok_enabled?
- true
- end
- #-----------------------------------------------------------------------------
- # Process Ok
- #-----------------------------------------------------------------------------
- def process_ok
- if current_item_enabled?
- Sound.play_ok
- Input.update
- on_ok
- else
- Sound.play_buzzer
- end
- end
- #-----------------------------------------------------------------------------
- # On Ok
- #-----------------------------------------------------------------------------
- def on_ok
- SceneManager.call(Scene_fullscreen_img)
- SceneManager.scene.prepare(@data[index])
- end
- #-----------------------------------------------------------------------------
- # Dispose
- #-----------------------------------------------------------------------------
- def dispose
- self.last_idx = index
- super
- end
- end # class Window_Text_Img_Gallery < Window_Selectable
- #===============================================================================
- # Scene Image Gallery
- #===============================================================================
- class Scene_Img_Gallery < Scene_Base
- #-----------------------------------------------------------------------------
- # Start
- #-----------------------------------------------------------------------------
- def start
- super
- @window = Window_Text_Img_Gallery.new
- end
- end
- #===============================================================================
- # Scene Full Screen Image
- #===============================================================================
- class Scene_fullscreen_img < Scene_Base
- #-----------------------------------------------------------------------------
- # Start
- #-----------------------------------------------------------------------------
- def start
- super
- @sprite = Sprite.new
- @sprite.z = 999
- @sprite.bitmap = Cache.nap_img_gallery(@data.filename)
- end
- #-----------------------------------------------------------------------------
- # Prepare
- #-----------------------------------------------------------------------------
- def prepare(data)
- @data = data
- end
- #-----------------------------------------------------------------------------
- # Update
- #-----------------------------------------------------------------------------
- def update
- super
- if Input.trigger?(:B)
- Sound.play_cancel
- SceneManager.return
- end
- end
- #-----------------------------------------------------------------------------
- # Terminate
- #-----------------------------------------------------------------------------
- def terminate
- super
- @sprite.dispose
- end
- end
- #===============================================================================
- # Window MenuCommand
- # For: Adding a menu item to the main menu
- #===============================================================================
- if Nap::Image_Gallery::ADD_TO_MENU
- class Window_MenuCommand < Window_Command
- #---------------------------------------------------------------------------
- # Text Image Gallery Enabled [NEW]
- #---------------------------------------------------------------------------
- def text_img_gallery_enabled
- $image_data.visible_images.length > 0
- end
- #---------------------------------------------------------------------------
- # Add Original Commands [ALIAS]
- #---------------------------------------------------------------------------
- alias nap_txt_img_gallery_add_original_commands add_original_commands
- def add_original_commands
- add_command(Nap::Image_Gallery::MENU_TEXT, :img_gallery, text_img_gallery_enabled )
- nap_txt_img_gallery_add_original_commands
- end
- end # class Window_MenuCommand < Window_Command
- end # if ADD_TO_MENU
- #===============================================================================
- # Scene Menu
- #===============================================================================
- class Scene_Menu < Scene_MenuBase
- #-----------------------------------------------------------------------------
- # Command Image Gallery [NEW]
- #-----------------------------------------------------------------------------
- def command_img_gallery
- SceneManager.call(Scene_Img_Gallery)
- end
- if Nap::Image_Gallery::ADD_TO_MENU
- #---------------------------------------------------------------------------
- # Create Command Window [ALIAS]
- #---------------------------------------------------------------------------
- alias nap_txt_img_gallery_create_command_window create_command_window
- def create_command_window
- nap_txt_img_gallery_create_command_window
- @command_window.set_handler(:img_gallery, method(:command_img_gallery))
- end
- end # if ADD_TO_MENU
- end
- #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement