01-08-2006, 01:00 PM
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
No support is given. If you are the owner of the thread, please contact administration.
This creates a menu in which the choices shift places rather than the cursor.
Paste this script right below Window_Command.
Code
Code:
#/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/
#
# Scrolling menu Script by Ultrapokemaniac and Khatharr
# version 0.9
# Date: 6 Jan. 2005
#
# Thanks to Khatharr for his support. (and for writing about 60% of the script) ^_^
#
# For ease of testing, here is the line to put into the main menu of the defualt system. ^_^
# Note: change "vert"(also 1) to "horz"(also 0) for the horizontal menu,
#
# @command_window = Scrolling_Command.new("vert", 80, [s1, s2, s3, s4, s5, s6], 1, @menu_index)
#
# The Custom Settings section Allows flexibility of the script.
#
# SPEED Refers to the speed of the animation in the menu, The Higher it is,
# the faster the scrolling animation.
# HORZ_SPACING is the number of pixel of width for each letter of the
# largest command. Used to configure the width of space for each command. --- Usable only with Horz Menus
#
# Call this script By using Scrolling_Command.new(align, number, Menu choices (in array), focus, starting index)
# where align is whether horizontal or vertical.
# and where number is the other side not determined by autosizing. (width for Vert.) (height for Horz.)
#/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/
class Scrolling_Command < Window_Base
attr_reader :index
attr_reader :help_window
#--------------------------------------------------------------------------
#- Customize the script Here.
#--------------------------------------------------------------------------
SPEED = 2
HORZ_SPACING = 10
#--------------------------------------------------------------------------
#This is the initialize method, (duh)
#--------------------------------------------------------------------------
def initialize(align, side, commands, focus, startindex, disabled = [])
startup(align, side, commands, focus, disabled)
super(0, 0, @width, @height)
self.contents = Bitmap.new(@width_2, @height_2)
self.contents.font.name = $defaultfonttype
self.contents.font.size = $defaultfontsize
self.index = startindex
refresh
end
#--------------------------------------------------------------------------
# I put most of the variable declarations into this method, because Inititialize was getting cluttered. :D
#--------------------------------------------------------------------------
def startup(align, side, commands, focus, disabled)
@focus = (focus - 1) #to solve a graphical error this was done.
@commands = commands
@align = align
check_align # verify and convert the value of @align
set_spacing (side) #set the window sizes based on what type of menu we're using
@disabled = disabled
@com = @commands.size
@com -= 1#a graphical bug prevention step
return
end
#--------------------------------------------------------------------------
# The Refresh method.
#--------------------------------------------------------------------------
def refresh
self.contents.clear
if @align == 0 #if using a verticle menu use the appropriate method
for i in -1...@com# again a step to prevent a graphical bug
draw_item_vert(i, normal_color)
end
elsif @align == 1 #and use the appropriate method if using a horizontal menu
for i in -1...@com #graphical bug prevention
draw_item_horz(i, normal_color)
end
end
end
#--------------------------------------------------------------------------
# Set the size of the menu through automatic routines.
# side = either width or height depending on the menu setting.
# Verticle menu; side = Width
# Horizontal menu; side = Height
#--------------------------------------------------------------------------
def set_spacing(side)
# if verticle, make the heigth determined by the # of options, and the width by the spare side variable
if @align == 0
@height = @commands.size*32 - 32
@width = side
@height_2 = @commands.size*32 - 64
@width_2 = side - 32
#and vica versa for the horizontal menu.
elsif @align == 1
old_size = @commands[1].size # just to make it not nil
for i in @commands
if i.size >= old_size
old_size = i.size
end
end
@size = old_size * HORZ_SPACING
@height = side
@width = @commands.size*(@size) - ((@size*(3.0/2.0)).abs)
@height_2 = side - 32
@width_2 = @width - 32
horz_offset_temp=[((@size)*0.25), ((@size)*0.50), ((@size)*0.75)]
@horz_offset = horz_offset_temp.each { |x| x.abs }
end
end
#--------------------------------------------------------------------------
#-This method converts the strings to either 1 or 0 depending on the menu.
# 0 = Vertical menu
# 1 = Horizontal menu
#--------------------------------------------------------------------------
def check_align
if @align == "vert"
@align = 0
elsif @align == "horz"
@align = 1
end
#debug script
if @align == 0
# print "vert"
elsif @align == 1
# print "horz"
else #if invalid input was found in @align, set to vertical menu.
# print "error"
@align = 0
end
end
#--------------------------------------------------------------------------
#-Animation routine for the verticle menu.
#--------------------------------------------------------------------------
def anim_vert(direction)
for a in [8, 16, 24] #1/4, 1/2, and 3/4 of the destination value
click = Graphics.frame_count
self.contents.clear# clear window to keep from streaking.
for i in -1...@com #again graphic bug prevention
offset_draw_item_vert(i, normal_color, direction * a) #Draw the animation.
end
Graphics.update until Graphics.frame_count >= click + SPEED
end
refresh # draw new placement of commands
end
#--------------------------------------------------------------------------
#-Animation routine for the Horizontal menu
#-Since the routine is different for the Vert & Horz menus, Anim is not merged;
#-But will be merged in future
#--------------------------------------------------------------------------
def anim_horz(direction)
for a in @horz_offset #<<1/4, 1/2, and 3/4 of the destination value
click = Graphics.frame_count
self.contents.clear
for i in -1...@com
offset_draw_item_horz(i, normal_color, direction * a) #Draw the animation
end
Graphics.update until Graphics.frame_count >= click + SPEED
end
refresh
end
#--------------------------------------------------------------------------
#-This method draws the menu items for the Horizontal menu.
#--------------------------------------------------------------------------
def draw_item_horz(index, color)
nindex = (index - @focus + [@index, 0].max) % @commands.size
self.contents.font.color = @disabled.include?(nindex) ? disabled_color : normal_color
rect = Rect.new((@size)* index, 4, (@size), self.contents.height - 8)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[nindex])
end
#--------------------------------------------------------------------------
#-This method draws the menu items for the Vertical menu
#--------------------------------------------------------------------------
def draw_item_vert(index, color)# no need to explain this method yet, willdo that later. ^_^ *is tired*
nindex = (index - @focus + [@index, 0].max) % @commands.size
self.contents.font.color = @disabled.include?(nindex) ? disabled_color : normal_color
rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[nindex])
end
#--------------------------------------------------------------------------
#This method draws the Verticle menu for the animation routine
#--------------------------------------------------------------------------
def offset_draw_item_vert(index, color, offset)
trip = offset == offset.abs ? 1 : -1
nindex = ((index + trip) - @focus + [@index, 0].max) % @commands.size
self.contents.font.color = @disabled.include?(nindex) ? disabled_color : normal_color
rect = Rect.new(4, (32 * index) + offset, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[nindex])
end
#--------------------------------------------------------------------------
#-This method draws the Horizontal menu for the animation routine
#--------------------------------------------------------------------------
def offset_draw_item_horz(index, color, offset)
trip = offset == offset.abs ? 1 : -1
nindex = ((index + trip) - @focus + [@index, 0].max) % @commands.size
self.contents.font.color = @disabled.include?(nindex) ? disabled_color : normal_color
rect = Rect.new(((@size)* index) + offset, 4, (@size), self.contents.height - 8)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[nindex])
end
#--------------------------------------------------------------------------
#-Simple disable option.
#--------------------------------------------------------------------------
def disable_item(index)
@disabled.push(index)
refresh
end
#--------------------------------------------------------------------------
#-Simple enable option.
#--------------------------------------------------------------------------
def enable_item(index)
@disabled.delete(index)
refresh
end
#--------------------------------------------------------------------------
#-The index method
#--------------------------------------------------------------------------
def index=(index)
@index = index
if @index >= @commands.size
@index = 0
end
if @index < 0
@index = @commands.size - 1
end
if self.active and @help_window != nil
update_help
end
update_cursor_rect
end
#--------------------------------------------------------------------------
#-The help_window method. Used the same way as the one in Window_Selectable
#--------------------------------------------------------------------------
def help_window=(help_window)
@help_window = help_window
if self.active and @help_window != nil
update_help
end
end
#--------------------------------------------------------------------------
#-Draws the cursor in proportion to the size of the window
#--------------------------------------------------------------------------
def update_cursor_rect
if @focus < 0
self.cursor_rect.empty
return
end
if @align == 0
cursor_width = self.width - 32
y = @focus * 32 - self.oy
self.cursor_rect.set(0, y, cursor_width, 32)
elsif @align == 1
cursor_height = self.height - 32
x = (@focus * (@size) - self.ox - 6)
self.cursor_rect.set(x, 0, (@size), cursor_height)
end
end
#--------------------------------------------------------------------------
#-The update routine for the menus
#--------------------------------------------------------------------------
def update
super
if self.active and @commands.size > 0 and @index >= 0
if @align == 0
if Input.repeat?(Input::DOWN)
$game_system.se_play($data_system.cursor_se)
self.index += 1
anim_vert(-1)
end
if Input.repeat?(Input::UP)
$game_system.se_play($data_system.cursor_se)
self.index -= 1
anim_vert(1)
end
elsif @align == 1
if Input.repeat?(Input::RIGHT)
$game_system.se_play($data_system.cursor_se)
self.index += 1
anim_horz(-1)
end
if Input.repeat?(Input::LEFT)
$game_system.se_play($data_system.cursor_se)
self.index -= 1
anim_horz(1)
end
end
end
if self.active and @help_window != nil
update_help
end
update_cursor_rect
refresh
end
#end update-------------------------------------------------------
end
#end class
I have attempted to work all the bugs out of this script. If you find any let me know.
For almost all purposes, this script can be treated the same ways as the defualt selectable menu.
-Old demo was lost- (
Screenshots will not help demonstrate this script so there won't be any.
Just for the record. This is not to be reposted at RMXP.org under any circumstances, unless posted by me. I have my reasons. PM me if you really must know why.
Edit: Khatharr has such right as well, being an author of this script, same as me.
Edit2: Fixed some old information and removed the broken demo link. Contact me if you have a copy of the demo and I'll re-upload it)