#============================================================================
# ** Ring Command
#----------------------------------------------------------------------------
# by Fantasist
# Version GAX1
# 22-Nov-2009
#----------------------------------------------------------------------------
# Version History:
#
# 1.0 - First functional version
# GAX1 - Alteration made for GuardianAngelX72's menu system
#----------------------------------------------------------------------------
# Description:
#
# A rotating ring with pictures, can be used as a command window.
#----------------------------------------------------------------------------
# Compatibility:
#
# Should not cause any problems. Not tested with the SDK.
#----------------------------------------------------------------------------
# Instructions:
#
# Place this script anywhere below 'Scene_Debug' and above 'Main'.
#
# Usage:
#
# Make the ring like this:
#
# Ring_Command.new(x, y, radius, commands)
#
# where
# x, y: Position if the ring (top-left corner, not the center).
# radius: Radius of the ring.
# commands: An array of bitmaps.
#----------------------------------------------------------------------------
# Configuration:
#
# class Icon_Ring:
#
# Icon_BG: Background to be used behind all ring icons (optional)
# Icon_Disable: Icon overlay for 'disabled' options (optional, but
# there's no other way to show a disabled icon.
# Select_Indication: nil - No indication
# 0 - Blink
# <number> - ID of animation
#
# class Ring_Command:
#
# Frames: Movement Speed. Larger number means slower movement.
# Depth: Depth of the ring, meaning the 'tilt' factor.
#----------------------------------------------------------------------------
# Issues:
#
# None so far.
#----------------------------------------------------------------------------
# Credits and Thanks:
#
# Credits: Fantasist for making this.
# Thanks: Chaos Project (Game) for inspiration
#----------------------------------------------------------------------------
# Notes:
#
# If you have any comments or problems, you can find me at:
#
# - forum.chaos-project.com
#
# Enjoy ^_^
#============================================================================
#=============================================================================
# ** Icon_Ring
#=============================================================================
class Icon_Ring < RPG::Sprite
Icon_BG = '' # Background to be used behind all ring icons (optional)
Icon_Disable = '' # Icon overlay for 'disabled' options (optional, but
# there's noother way to show a disabled icon.
Select_Indication = 1 # nil: No indication
# 0: Blink
# Any number > 0: ID of animation
def initialize(item, disabled=false)
super()
@item = item
self.bitmap = make_bmp(item, disabled)
self.ox, self.oy = self.bitmap.width / 2, self.bitmap.height / 2
end
def make_bmp(item, disabled=false)
bg = RPG::Cache.icon(Icon_BG).clone rescue Bitmap.new(32, 32)
result = nil
# Draw item
if item.is_a?(Numeric)
bg.draw_text(0, 0, bg.width, bg.height, item.to_s, 1)
result = bg
elsif item.is_a?(String)
bg.draw_text(0, 0, bg.width, bg.height, item, 1)
result = bg
elsif item.is_a?(Bitmap)
b = Bitmap.new(item.width, item.height)
b.blt(b.width/2 - bg.width/2, b.height/2 - bg.height/2, bg, bg.rect)
b.blt(b.width/2 - item.width/2, b.height/2 - item.height/2, item, item.rect)
result = b
end
# Disable
disable(result) if disabled
return result
end
def disable(bmp=self.bitmap)
return if bmp.nil? || bmp.disposed?
x = RPG::Cache.icon(Icon_Disable) rescue Bitmap.new(32, 32)
bmp.blt(bmp.width/2 - x.rect.width/2, bmp.height/2 - x.rect.height/2, x, x.rect)
end
def enable
self.bitmap = make_bmp(@item)
end
def select
return if Select_Indication == nil
if Select_Indication <= 0
self.blink_on
else
animation = $data_animations[Select_Indication]
self.loop_animation(animation) rescue self.blink_on
end
end
def deselect
self.blink_off
self.loop_animation(nil)
end
end
#=============================================================================
# ** Ring_Command
#=============================================================================
class Ring_Command < Sprite
Frames = 6 # Movement Speed. Larger number means slower movement
Depth = 6 # Depth of the ring, meaning the 'tilt' factor.
attr_reader :index
attr_reader :radius
attr_reader :commands
attr_accessor :active
# Dummy values for window compatibility
attr_accessor :windowskin, :contents, :stretch, :cursor_rect, :pause,
:back_opacity, :contents_opacity
def initialize(x=320, y=240, r=200, commands=15, win_w=0, win_h=0)
super()
set_icons(commands)
@unit_angle = 360.0/@commands.size
@win_offset = [win_w/2, win_h]
self.radius, self.x, self.y = r, x, y
self.index = 0
self.active = false
@moving = 0
end
def set_icons(commands)
# Dispose previous icons
if @commands != nil
@commands.each {|sprite|
sprite.bitmap.dispose
sprite.dispose}
end
# Make icons
@commands = []
if commands.is_a?(Array)
commands.each {|item| @commands.push(Icon_Ring.new(item))}
elsif commands.is_a?(Integer)
(1..commands).each {|i| @commands.push(Icon_Ring.new(i))}
end
end
def set_items(ang=self.angle)
@commands.each_index {|i|
@commands[i].deselect
@commands[i].x = self.x + self.radius * sin(ang + @unit_angle * i)
@commands[i].y = self.y + self.radius/Depth * cos(ang + @unit_angle * i)
@commands[i].z = self.z + @commands[i].y
unless Depth == 1
multiplier = (@commands[i].y - (self.y-self.radius/Depth)).to_f / (2*self.radius/Depth)
zoom = 0.8 + 0.2 * multiplier
@commands[i].zoom_x = @commands[i].zoom_y = zoom
end
}
end
def move(dir=0)
@moving = (dir == 0 ? Frames : -Frames)
end
def update
if self.active
@commands[@index].update
@commands[@index].select
if @moving != 0
ang = (@unit_angle / Frames)
self.angle += (@moving > 0 ? ang : -ang)
self.angle -= 360 if self.angle > 360.0
self.angle += 360 if self.angle < -360.0
set_items
@moving += (@moving < 0 ? 1 : -1)
else
if Input.repeat?(Input::RIGHT)
$game_system.se_play($data_system.cursor_se)
move(1)
@index = (@index + 1) % @commands.size
elsif Input.repeat?(Input::LEFT)
$game_system.se_play($data_system.cursor_se)
move(0)
@index = (@index + @commands.size - 1) % @commands.size
end
end
end
end
def disable_item(index)
@commands[index].disable
end
def sin(val)
Math.sin(Math::PI*val/180)
end
def cos(val)
Math.cos(Math::PI*val/180)
end
def dispose
super
@commands.each {|sp|
sp.bitmap.dispose
sp.dispose}
end
def visible=(val)
super(val)
@commands.each {|sp| sp.visible = val}
end
def active=(val)
@active = val
@commands.each {|c| c.deselect} unless val
end
def index=(i)
@index = i
self.angle = i * @unit_angle
set_items
end
def radius=(r)
@radius = r
set_items
end
def commands=(commands)
#dispose previous icons
if @commands != nil
@commands.each {|sp|
sp.bitmap.dispose
sp.dispose}
end
@commands = commands
@unit_angle = 360.0/@commands.size
self.angle = 0
self.index = 0
end
def x=(x)
super(x+@win_offset[0])
set_items
end
def y=(y)
super(y+@win_offset[1])
set_items
end
end