=begin
==============================================================================
** Window Sprites
------------------------------------------------------------------------------
Description:
------------
This set allows for sprite objects to be tagged onto a window.
Method List:
------------
Sprite
------
tag
in_rect?
Support Methods:
-------------
Window_Base
-----------
initialize
dispose
update
x=
y=
z=
ox=
oy=
width=
height=
contents_opacity=
back_opacity=
opacity=
visible=
Sprite
------
initialize
==============================================================================
=end
MACL::Loaded << 'Window Sprites'
class Window_Base
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
if @trick_sprites_windowbase.nil?
alias_method :trick_sprites_base_x=, :x=
alias_method :trick_sprites_base_y=, :y=
alias_method :trick_sprites_base_z=, :z=
alias_method :trick_sprites_base_ox=, :ox=
alias_method :trick_sprites_base_oy=, :oy=
alias_method :trick_sprites_base_width=, :width=
alias_method :trick_sprites_base_height=, :height=
alias_method :trick_sprites_base_contents_opacity=, :contents_opacity=
alias_method :trick_sprites_base_back_opacity=, :back_opacity=
alias_method :trick_sprites_base_opacity=, :opacity=
alias_method :trick_sprites_base_visible=, :visible=
@trick_sprites_windowbase = true
end
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias_method :trick_sprites_base_initialize, :initialize
def initialize(x, y, width, height)
# Setup Sprites Array
@window_sprites = []
# The Usual
trick_sprites_base_initialize(x, y, width, height)
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
alias_method :trick_sprites_base_dispose, :dispose
def dispose
# The Usual
trick_sprites_base_dispose
# Dispose all Sprites
@window_sprites.each {|sprite| sprite.dispose}
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
alias_method :trick_sprites_base_update, :update
def update
# The Usual
trick_sprites_base_update
# Update
@window_sprites.each {|sprite| sprite.update}
end
#--------------------------------------------------------------------------
# * Set X
#--------------------------------------------------------------------------
def x=(x)
# Run through each window sprite
@window_sprites.each do |sprite|
# If Has Method sprite type
if sprite.respond_to?(:sprite_type)
# Branch by Type
case sprite.sprite_type
when 'content', 'content2', 'cover', 'background'
# Include Scroll Calculation Set X
sprite.x = sprite.x - self.x + x + ox
when 'border'
# Exclude Scroll Calculation Set X
sprite.x = sprite.x - self.x + x
end
else
# Default is Content Sprite
sprite.x = sprite.x - self.x + x + ox
end
end
# The Usual
self.trick_sprites_base_x = x
end
#--------------------------------------------------------------------------
# * Set Y
#--------------------------------------------------------------------------
def y=(y)
# Update All Y's
@window_sprites.each do |sprite|
# If Has Method sprite type
if sprite.respond_to?(:sprite_type)
# Branch by Type
case sprite.sprite_type
when 'content', 'content2', 'cover', 'background'
# Include Scroll Calculation Set Y
sprite.y = sprite.y - self.y + y + oy
when 'border'
# Exclude Scroll Calculation Set Y
sprite.y = sprite.y - self.y + y
end
else
# Default is Content Sprite
sprite.y = sprite.y - self.y + y + oy
end
end
# The Usual
self.trick_sprites_base_y = y
end
#--------------------------------------------------------------------------
# * Set Z
#--------------------------------------------------------------------------
def z=(z)
# Update All Z's
@window_sprites.each do |sprite|
# If Has Method sprite type
if sprite.respond_to?(:sprite_type)
# Branch By Sprite Type
case sprite.sprite_type
when 'content'
sprite.z = self.z + 1
when 'content2'
sprite.z = self.z + 2
when 'cover', 'border'
sprite.z = self.z + 3
when 'background'
sprite.z = self.z
end
else
# Default is content
sprite.z = self.z + 1
end
end
# The Usual
self.trick_sprites_base_z = z
end
#--------------------------------------------------------------------------
# * Set Origin X
#--------------------------------------------------------------------------
def ox=(ox)
# Get Ox Change
cx = self.ox - ox
# Run Through Each Sprite
@window_sprites.each do |sprite|
# If Has Method sprite type
if sprite.respond_to?(:sprite_type)
# Branch By Sprite Type
case sprite.sprite_type
when 'content', 'content2', 'cover', 'background'
# Add to X
sprite.x += cx
# Setup Visibility
sprite.visible = sprite.x.between?(x + 16, x + width - 16) && visible
end
else
# Add to X
sprite.x += cx
# Setup Visibility
sprite.visible = sprite.x.between?(x + 16, x + width - 16) && visible
end
end
# The Usual
self.trick_sprites_base_ox = ox
end
#--------------------------------------------------------------------------
# * Set Origin Y
#--------------------------------------------------------------------------
def oy=(oy)
# Get Oy Change
cy = self.oy - oy
# Run Through Each Sprite
@window_sprites.each do |sprite|
# If Has Method sprite type
if sprite.respond_to?(:sprite_type)
# Branch By Sprite Type
case sprite.sprite_type
when 'content', 'content2', 'cover', 'background'
# Add to Y
sprite.y += cy
# Setup Visibility
sprite.visible = sprite.y.between?(y + 16, y + height - 16) && visible
end
else
# Add to Y
sprite.y += cy
# Setup Visibility
sprite.visible = sprite.y.between?(y + 16, y + height - 16) && visible
end
end
# The Usual
self.trick_sprites_base_oy = oy
end
#--------------------------------------------------------------------------
# * Set Width
#--------------------------------------------------------------------------
def width=(width)
# Run Through Each Sprite
@window_sprites.each do |sprite|
# If Has Method sprite type
if sprite.respond_to?(:sprite_type)
# Branch By Sprite Type
case sprite.sprite_type
when 'content', 'content2', 'cover', 'background'
# Setup Visibility
sprite.visible = sprite.x.between?(x + 16, x + width - 16) && visible
end
else
# Setup Visibility
sprite.visible = sprite.x.between?(x + 16, x + width - 16) && visible
end
end
# The Usual
self.trick_sprites_base_width = width
end
#--------------------------------------------------------------------------
# * Set Height
#--------------------------------------------------------------------------
def height=(height)
# Run Through Each Sprite
@window_sprites.each do |sprite|
# If Has Method sprite type
if sprite.respond_to?(:sprite_type)
# Branch By Sprite Type
case sprite.sprite_type
when 'content', 'content2', 'cover', 'background'
# Setup Visibility
sprite.visible = sprite.y.between?(y + 16, y + height - 16) && visible
end
else
# Setup Visibility
sprite.visible = sprite.y.between?(y + 16, y + height - 16) && visible
end
end
# The Usual
self.trick_sprites_base_height = height
end
#--------------------------------------------------------------------------
# * Set Contents Opacity
#--------------------------------------------------------------------------
def contents_opacity=(opacity)
# Run Through Each Sprite and Setup Opacity
@window_sprites.each do |sprite|
# If Has Method sprite type
if sprite.respond_to?(:sprite_type)
# Branch By Sprite Type
case sprite.sprite_type
when 'content', 'content2', 'cover', 'background'
# Setup Opacity
sprite.opacity = opacity
end
else
# Setup Opacity
sprite.opacity = opacity
end
end
# The Usual
self.trick_sprites_base_contents_opacity = opacity
end
#--------------------------------------------------------------------------
# * Set Back Opacity
#--------------------------------------------------------------------------
def back_opacity=(opacity)
# Run Through Each Sprite and Setup Opacity
@window_sprites.each do |sprite|
# If Has Method sprite type
if sprite.respond_to?(:sprite_type)
# Branch By Sprite Type
case sprite.sprite_type
when 'content', 'content2', 'cover', 'background'
# Setup Opacity
sprite.opacity = opacity
end
else
# Setup Opacity
sprite.opacity = opacity
end
end
# The Usual
self.trick_sprites_base_back_opacity = opacity
end
#--------------------------------------------------------------------------
# * Set Opacity
#--------------------------------------------------------------------------
def opacity=(opacity)
# Run Through Each Sprite and Setup Opacity
@window_sprites.each do |sprite|
# If Has Method sprite type
if sprite.respond_to?(:sprite_type)
# Branch By Sprite Type
case sprite.sprite_type
when 'content', 'content2', 'cover', 'background'
# Setup Opacity
sprite.opacity = opacity
end
else
# Setup Opacity
sprite.opacity = opacity
end
end
# The Usual
self.trick_sprites_base_opacity = opacity
end
#--------------------------------------------------------------------------
# * Set Visibility
#--------------------------------------------------------------------------
def visible=(bool)
# Get Rect
rect = Rect.new(x + 16, y + 16, width - 32, height - 32)
# Run Through Each Sprite
@window_sprites.each do |sprite|
# If Has Method sprite type
if sprite.respond_to?(:sprite_type)
# Branch By Sprite Type
case sprite.sprite_type
when 'content', 'content2', 'cover', 'background'
sprite.visible = bool && sprite.in_rect?(rect)
when 'border', 'tagged'
sprite.visible = visible
end
else
sprite.visible = bool && sprite.in_rect?(rect)
end
end
# Update Visibility
self.trick_sprites_base_visible = bool
end
end
class Sprite
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :sprite_type
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
if @trick_sprites_sprite.nil?
alias_method :trick_sprites_sprite_initialize, :initialize
@trick_sprites_sprite = true
end
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(*args)
# The Usual
trick_sprites_sprite_initialize(*args)
# Setup Default for sprite_type - 'content'
@sprite_type = 'content'
end
#-------------------------------------------------------------------------
# * Name : Tag
# Info : Tags a sprite to a window
# Author : Trickster
# Call Info : Window window - window to tag sprite to
#-------------------------------------------------------------------------
def tag(window)
# Get Attributes
x, y, width, height = window.x, window.y, window.width, window.height
# Setup Rect
rect = Rect.new(x + 16, y + 16, width - 32, height - 32)
# Branch by Sprite Type
case sprite_type
when 'content'
# Set Visibility
self.visible = in_rect?(rect) && window.visible
# Set Z Between Window
self.z = window.z + 1
# Setup Opacity
self.opacity = window.contents_opacity
when 'content2'
# Set Visibility
self.visible = in_rect?(rect) && window.visible
# Set Z Between Window
self.z = window.z + 2
# Setup Opacity
self.opacity = window.contents_opacity
when 'cover'
# Set Visibility
self.visible = in_rect?(rect) && window.visible
# Set Z Between Window
self.z = window.z + 3
# Setup Opacity
self.opacity = window.contents_opacity
when 'border'
# Set Visibility
self.visible = window.visible
# Set Z Between Window
self.z = window.z + 3
# Setup Opacity
self.opacity = window.opacity
when 'background'
# Set Visibility
self.visible = in_rect?(rect) && window.visible
# Set Z at Window
self.z = window.z
# Setup Opacity
self.opacity = window.back_opacity
when 'tagged'
# Set Visibility
self.visible = window.visible
# Setup Opacity
self.opacity = window.opacity
end
end
#-------------------------------------------------------------------------
# * Name : In Rectangle?
# Info : Is Sprite in Rectangle
# Author : Trickster
# Call Info : One or Four Arguments
# Rect rect - rectangle to check
# Integer x, y, width, height - rectangle to check
#-------------------------------------------------------------------------
def in_rect?(*rect)
# If 1 Argument Sent
if rect.size == 1
# Get Rect
rect = rect[0]
# Return in rect state
return (x.between?(rect.x, rect.x + rect.width) &&
y.between?(rect.y, rect.y + rect.height))
else
# Get variables sent
x, y, width, height = rect
# If In Rect
return self.x.between?(x, x + width) && self.y.between?(y, y + height)
end
end
end