03-07-2008, 04:11 AM
Image Gallery
Version: 1.0
By Syvkal
Version: 1.0
By Syvkal
Introduction
I made this script for a request by Punk. But now he doesn't need it... so I can post it for anyone else who wants it. It makes a scene that holds all the pictures in a certain directory, which you can then click on and it shows them full size.
Features
Allows you view lots of pictures in game.
Screenshots
I don't have any good pictures to make a screenshot (I used the transitions to test mine... xD )
Script
Script
Code:
#==============================================================================
# ** Image_Gallery
#------------------------------------------------------------------------------
# by Syvkal
# Version 1.0
# 05-03-08
#==============================================================================
#
# --Disabling Pictures--
#
# To disable any pictures use:
#
# Gallery.disable(x)
#
# To enable any pictures use:
#
# Gallery.enable(x)
#
# The 'x' is the picture index, starting with 0
#
# --Return Scene--
#
# To edit where this scene returns to search:
#
# ##RETURN SCENE##
#
#==============================================================================
#=================================================#
# ** C O N F I G U R A T I O N ** #
#=================================================#
# This is where you can change the custom directory
module Pictures
DIR = 'Graphics/Gallery/'
# This is where you add your pictures types
NAMES = Dir.glob(DIR+'*.{jpg,jpeg,bmp,png}')
for i in 0...NAMES.size
NAMES[i].slice!(DIR)
NAMES[i].slice!('.png')
NAMES[i].slice!('.jpg')
NAMES[i].slice!('.jpeg')
NAMES[i].slice!('.bmp')
end
end
#=================================================#
#==============================================================================
# ** Scene_Gallery
#==============================================================================
class Scene_Gallery
def main
# Make window
@gallery_window = Window_Gallery.new
@picture = 0
@picture_window = Window_Picture.new(@picture)
@picture_window.active = false
@picture_window.visible = false
# 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
@gallery_window.dispose
@picture_window.dispose
end
#--------------------------------------------------------------------------
def update
# Update windows
@gallery_window.update
@picture = @gallery_window.index
@picture_window.update
if @gallery_window.active
update_gallery
return
end
if @picture_window.active
update_picture
return
end
end
#--------------------------------------------------------------------------
def update_gallery
# If B button was pressed
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
##RETURN SCENE##
$scene = Scene_Menu.new(0)
return
end
# If C button was pressed
if Input.trigger?(Input::C)
if $game_system.disable[@gallery_window.index] == true
$game_system.se_play($data_system.buzzer_se)
return
else
$game_system.se_play($data_system.decision_se)
@picture_window = Window_Picture.new(@picture)
@gallery_window.active = false
@gallery_window.visible = false
return
end
end
end
#--------------------------------------------------------------------------
def update_picture
# If B button was pressed
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@picture_window.active = false
@picture_window.visible = false
@gallery_window.active = true
@gallery_window.visible = true
return
end
end
end
#==============================================================================
class Game_System
attr_accessor :disable
alias initialize_original initialize
def initialize
initialize_original
@disable = []
for i in 0...Gallery::PICS.size
@disable[i] = false
end
end
end
#==============================================================================
module RPG
module Cache
def self.gallery(filename)
self.load_bitmap(Pictures::DIR, filename)
end
end
end
#==============================================================================
module Gallery
PICS = []
for i in 0...Pictures::NAMES.size - 1
PICS.push(RPG::Cache.gallery(Pictures::NAMES[i]))
end
def self.disable(i)
$game_system.disable[i] = true
end
def self.enable(i)
$game_system.disable[i] = nil
end
end
#==============================================================================
# ** Window_Gallery
#==============================================================================
class Window_Gallery < Window_Selectable
def initialize
super(0, 0, 640, 480)
@column_max = 3
@pics = Gallery::PICS
@disabled = $game_system.disable
refresh
self.index = 0
end
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in 0...@pics.size
@data.push(@pics[i])
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, (row_max+1) * 128)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
def page_row_max
return (self.height - 32) / 128
end
#--------------------------------------------------------------------------
def top_row
return self.oy / 128
end
#--------------------------------------------------------------------------
def top_row=(row)
if row < 0
row = 0
end
if row > row_max - 1
row = row_max - 1
end
self.oy = (row * 128) + (row * 24)
end
#--------------------------------------------------------------------------
def draw_item(i)
cursor_width = self.width / @column_max - 32
cursor_height = self.height / page_row_max - 40
x = i % @column_max * (cursor_width + 32)
y = i / @column_max * (cursor_height + 32) - self.oy
rect = Rect.new(0, 0, @pics[i].width, @pics[i].height)
rect2 = Rect.new(x + 3, y + 8, 176, 128)
self.contents.stretch_blt(rect2, @pics[i], rect , @disabled[i] ? 128 : 255)
self.contents.font.color = Color.new(0,0,0,192)
self.contents.draw_text(x+2, y+7, 176, 128, Pictures::NAMES[i], 1)
self.contents.draw_text(x+4, y+9, 176, 128, Pictures::NAMES[i], 1)
self.contents.font.color = normal_color
self.contents.draw_text(x+3, y+8, 176, 128, Pictures::NAMES[i], 1)
end
#--------------------------------------------------------------------------
def update_cursor_rect
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 = self.width / @column_max - 32
cursor_height = self.height / page_row_max - 40
x = @index % @column_max * (cursor_width + 32)
y = @index / @column_max * (cursor_height + 32) - self.oy
self.cursor_rect.set(x-5, y, 192, 144)
end
end
#==============================================================================
# ** Window_Picture
#==============================================================================
class Window_Picture < Window_Base
#--------------------------------------------------------------------------
def initialize(picture)
super(0, 0, 640, 480)
self.contents = Bitmap.new(width - 32, height - 32)
@pic = Gallery::PICS
@pics = @pic[picture]
refresh
end
#--------------------------------------------------------------------------
def refresh
self.contents.clear
x = (640 - @pics.width) / 2
y = (480 - @pics.height) / 2
rect = Rect.new(0, 0, @pics.width, @pics.height)
rect2 = Rect.new(x, y, @pics.width>608 ? 608 : @pics.width, @pics.height>448 ? 448 : @pics.height)
self.contents.stretch_blt(rect2, @pics, rect)
end
end
Instructions
Put it above Main.
Further instructions can be found in the script header.
Compatibility
Not sure what it's compatible with.... Should be pretty much everything...
Author's Notes
I am willing to make this for VX aswell, but only if someone wants it. It probably already works for VX, but VX allows you cut out lots of unnecessary coding, so I still count this as a XP script...
Enjoy xD