Catalogue Base
Version: 1.1
Author: modern algebra
Date: October 6, 2009
Version History
- <Version 1.1> 10.06.2009 - updated for an easier way to vary the size of windows. This makes it possible to have a much more dynamic design
- <Version 1.0> 08.16.2009 - Original Release
Description
This script acts as a base script for my catalogue scripts, and it is required for each of those scripts. It has a number of shared classes and methods that thereby reduce unnecessary coding for those scripts.
It is, however, strictly a support script. It has no useful purpose on its own.
Features
- This is really just a helper script, so it doesn't have many features worth listing. The format can be seen in the Screenshots section
- It allows for easy creation of other Catalogues. All that needs to be done is to make a subclass of Catalogue_Base, and make a new Card window with the info you want to show.
ScreenshotsThis is what the basic format of all my catalogue scripts will be:
Instructions No real insructions. For any script that requires this, just paste it above Main and above the scripts that require it but below the default scripts. If you wish to use it to write your own scripts, than post and I will write some instructions. But if nobody wants to, I don't want to write them all out
Script
#==============================================================================
# Catalogue Base
# Version: 1.1
# Author: modern algebra (rmrk.net)
# Date: October 6, 2009
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Description:
#
# This script acts as a base script for my catalogue scripts, and it is
# required for each of those scripts. It has a number of shared classes and
# methods that thereby reduce unnecessary coding for those scripts.
#
# It is, however, strictly a support script. It has no useful purpose on
# its own.
#==============================================================================
#==============================================================================
# ** Data Catalogues
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# This class handles catalogues. It's a wrapper for the built-in class Array
#==============================================================================
class Data_Catalogues
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def initialize
@data = []
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Get Catalogue
# catalogue_id : ID of the catalogue
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def [](catalogue_id)
if @data[catalogue_id] == nil
return Catalogue_Base.new
else
return @data[catalogue_id]
end
end
end
#==============================================================================
# ** Catalogue_Base
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This is the base to all Catalogue Groups.
#==============================================================================
class Catalogue_Base
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Public Instance Variables
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
attr_reader :name
attr_reader :objects
attr_accessor :visible_objects
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def initialize (name = 'Catalogue', objects = [], show_all = false)
# Set variables
@name = name
@objects = objects
@visible_objects = []
@show_all = show_all
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Card
#``````````````````````````````````````````````````````````````````````````
# This method returns the Card Window for a Catalogue, and should be
# overwritten by any subclasses
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def card
return Window_CatalogueCard
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Include?
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def include? (index)
return true
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Enable?
# index : the index of object in objects array
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def enable? (index)
return true
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def object (index)
return @objects[index]
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Icon
# index : The index of the object in objects array
#``````````````````````````````````````````````````````````````````````````
# This returns an icon to show in Window_CatalogueCommand. By default, it
# will return the output of the object method icon_index. It must be
# overwritten if the object class has no icon_index method
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def object_icon (index)
return index < @objects.size ? object (index).icon_index : 0
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Name
# index : The index of the object in objects array
#``````````````````````````````````````````````````````````````````````````
# This returns a name to show in Window_CatalogueCommand. By default, it
# will return the output of the object method name. It must be overwritten
# if the object class has no name method
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def object_name (index)
return index < @objects.size ? object (index).name : ''
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Help Text
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def object_help_text (index)
return ''
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * C Disabled?
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def c_disabled
return true
end
end
#==============================================================================
# ** Window Base
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# new method - cb_outline_rect
#==============================================================================
class Window_Base
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Outline_Rect
# x, y, width, height : rect to outline around
# colour : the colour object for this box
# t : thickness of the edges
# type : 0 => rounded rectangle; 1 => rectangle
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def cb_outline_rect (x, y, width, height, colour = system_color, t = 2, type = 0)
# If fill round, check if possible
if type == 0
if !contents.methods.include? ("fill_rounded_rect")
type = 1
else
contents.fill_rounded_rect (Rect.new (x, y, width, height), colour)
rect = Rect.new (x + t, y + t, width - (2*t), height - (2*t))
contents.fill_rounded_rect (rect, Color.new (0,0,0,0))
end
end
# Otherwise, draw rectangle
if type == 1
# Draw Horizontal
contents.fill_rect (x, y, width, t, colour)
contents.fill_rect (x, y + height - t, width, t, colour)
# Draw Vertical
contents.fill_rect (x, y + t, t, height - (2*t), colour)
contents.fill_rect (x + width - t, y + t, t, height - (2*t), colour)
end
end
end
#==============================================================================
# ** Window_CatalogueCard
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This window display information on objects in the catalogue
#==============================================================================
class Window_CatalogueCard < Window_Base
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Initialize
# catalogue : the catalogue information this card shows
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def initialize (catalogue)
super (224, 0, Graphics.width - 224, Graphics.height - 32 - WLH)
@catalogue = catalogue
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Refresh (index)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def refresh (index = nil)
contents.clear
return false if index == nil
@object = @catalogue.object (index)
end
end
#==============================================================================
# ** Window Catalogue Label
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# This window displays the name of the Catalogue
#==============================================================================
class Window_CatalogueLabel < Window_Base
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def initialize (x, y, width, height, name)
super (x, y, width, height)
contents.font.color = system_color
contents.draw_text (0, 0, contents.width, contents.height, name, 1)
end
end
#==============================================================================
# ** Window Catalogue Command
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# This window lists all available objects from the catalogue
#==============================================================================
class Window_CatalogueCommand < Window_Command
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def initialize (width, catalogue, *args)
@catalogue = catalogue
super (width, Array.new (@catalogue.visible_objects.size), 1)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Draw Item
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def draw_item (window_index)
# Get real object Index
cat_index = @catalogue.visible_objects[window_index]
enabled = @catalogue.enable? (cat_index)
rect = item_rect(window_index)
self.contents.clear_rect(rect)
# Draw Icon
draw_icon (@catalogue.object_icon (cat_index), rect.x, rect.y, enabled)
rect.x += 28
rect.width -= 28
self.contents.font.color = normal_color
self.contents.font.color.alpha = enabled ? 255 : 128
self.contents.draw_text(rect, @catalogue.object_name (cat_index))
end
end
#==============================================================================
# ** Scene Title
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# aliased methods - load_database; load_bt_database
#==============================================================================
class Scene_Title
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Load Database
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias mdnabalg_ctlge_base_lddata_5hv9 load_database
def load_database (*args)
mdnabalg_ctlge_base_lddata_5hv9 (*args) # Run Original Method
$data_catalogues = Data_Catalogues.new
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Load Battle Test Database
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias algebramodern_catalogues_btdatabselod_3hb7 load_bt_database
def load_bt_database (*args)
algebramodern_catalogues_btdatabselod_3hb7 (*args) # Run Original Method
$data_catalogues = Data_Catalogues.new
end
end
#==============================================================================
# ** Scene Catalogue
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# This scene handles processing for a catalogue scene
#==============================================================================
class Scene_Catalogue < Scene_Base
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
# catalogue_id : the ID of the catalogue to be opened
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def initialize(catalogue_id)
@catalogue = $data_catalogues[catalogue_id]
# Get all included and visible objects
for i in 0...@catalogue.objects.size
if @catalogue.include? (i)
@catalogue.visible_objects.push (i)
end
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Start
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def start
super
wlh = Window_Base::WLH
# Create Label Window
height = (Graphics.height - 96 - 2*wlh) % wlh
height += 32 + wlh
create_label_window (0, 0, 224, height)
# Create Command Window
height = Graphics.height - @label_window.height - 32 - wlh
create_command_window (0, @label_window.height, 224, height)
create_card_window
create_help_window (0, Graphics.height - 32 - wlh, Graphics.width, 32 + wlh)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Terminate Scene
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def terminate
super
@catalogue.visible_objects.clear
# Dispose all windows
@label_window.dispose unless @label_window.nil? || @label_window.disposed?
@command_window.dispose unless @command_window.nil? || @command_window.disposed?
@card_window.dispose unless @card_window.nil? || @card_window.disposed?
@help_window.dispose unless @help_window.nil? || @help_window.disposed?
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Frame Update
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def update
super
if @command_window.active
update_command
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Create Label Window
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def create_label_window (x, y, width, height)
@label_window = Window_CatalogueLabel.new (x, y, width, height, @catalogue.name)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Create Command Window
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def create_command_window (x, y, width, height)
@command_window = Window_CatalogueCommand.new (width, @catalogue)
@command_window.x, @command_window.y = x, y
@command_window.height = height
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Create Card Window
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def create_card_window
# X, Y, Width, Height set in the window itself, which has to be altered.
@card_window = @catalogue.card.new (@catalogue)
@card_window.refresh (@catalogue.visible_objects[0])
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Create Help Window
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def create_help_window (x, y, width, height)
@help_window = Window_Help.new
@help_window.width, @help_window.height = width, height
@help_window.create_contents
@help_window.x, @help_window.y = x, y
@help_window.set_text (@catalogue.object_help_text (@catalogue.visible_objects[0]))
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Update Command Window
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def update_command
old_index = @command_window.index
@command_window.update
# Get catalogue index for selected object
cat_index = @catalogue.visible_objects[@command_window.index]
# If cursor has moved
if old_index != @command_window.index
# Update Card Window
@card_window.refresh (cat_index)
@help_window.set_text (@catalogue.object_help_text (cat_index))
end
if Input.trigger? (Input::B)
Sound.play_cancel
return_scene
elsif Input.trigger? (Input::C)
if @catalogue.c_disabled || !@catalogue.enable? (cat_index)
Sound.play_buzzer
else
process_button_c
end
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Processing if Button C is pressed and valid
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def process_button_c
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Return Scene
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def return_scene
$scene = Scene_Map.new
end
end
Credit
Addons
Any addons in this section will work for any type of catalogue I create.
Support
For support, please post directly in this topic at RMRK.net. Don't PM me.
Known Compatibility Issues
No known compatibility problems.
Author's Notes
I made this script to serve as a base for my own catalogue scripts (planned to make an Items & Skills Catalogue, as well as a Monster Catalogue script and possibly a Character Catalogue Script), but it's free to use if anybody else would like to make their own catalogues.
[/list]
This script by
modern algebra is licensed under a
Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.