Ring Menu ! For everywhere!

Ring Menu
Version: 1.8.1
By: Trebor777

Introduction

A nice customizable Ring Menu :) that you can where you want! It's not a scene! :)
but an actual "object" like a window.

Features
[list]
[*]Specify the radius for the Vertical and Horizontal dimension. :) If Horizontal is 0, you have a vertical riing menu.
[*]Pass a block of code to each options! :)
[*]Icons can be from the icon set or an independant file.
[*]"Perspective effect" if "zoom" activated.
[*]Smooth "scrolling" between options :) you can even specify how smooth you want it!
[*]Easy access to the "selected" option, and possibilty to disable options as well :)( they will be skipped when scrolling )
[*]Non-static => you can move the menu around and change its attributes after creation!
[*] Brings a few useful methods to the Array class :)[/list]

1.8->1.8.1
Fixed: You can now used Up/Down Keys when it's a vertical ring menu


Screenshots
-> From Castlevania :
Image
Image
Demo

Basic demo for VX 400KB
Basic demo for XP 262KB

Look at the Scene_Demo script :)

Script


script FOR VX Spoiler
  1. #===============================================================================
  2. =begin
  3. RING MENU advanced.
  4. by Trebor777
  5. v1.8.1
  6. 24/07/2009
  7. An independant, class free, Ring menu, easily usable, with a lot of options.
  8. =end
  9. #===============================================================================
  10. class Array
  11.   # rotate  n item(s) to the left ( first becomes last) as a new array
  12.   def rotate_l(n=1)
  13.     a = self.clone
  14.     n.times{a.push(a.shift)}
  15.     return a
  16.   end
  17.   # rotate  n item(s) to the right ( last becomes first) as a new array
  18.   def rotate_r(n=1)
  19.     a = self.clone
  20.     n.times{a.unshift(a.pop)}
  21.     return a
  22.   end
  23.   # rotate n item(s) to the left
  24.   def rotate_l!(n=1)
  25.     n.times{self.push(self.shift)}
  26.     return self
  27.   end
  28.   # rotate n item(s) to the right
  29.   def rotate_r!(n=1)
  30.     n.times{self.unshift(self.pop)}
  31.     return self
  32.   end
  33.   # Do the sum of all the items. (they need to be all of the same type)
  34.   def sum
  35.     inject( nil ) { |sum,x| sum ? sum+x : x if x.respond_to? "+" }
  36.   end
  37. end
  38. #===============================================================================
  39. class Sprite
  40.   #--------------------------------------------------------------------------
  41.   # * Draw Icon
  42.   #     icon_index : Icon number
  43.   #     x     : draw spot x-coordinate
  44.   #     y     : draw spot y-coordinate
  45.   #     enabled    : Enabled flag. When false, draw semi-transparently.
  46.   #--------------------------------------------------------------------------
  47.   def draw_icon(icon_index, x, y, enabled = true)
  48.     bitmap = Cache.system("Iconset")
  49.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  50.     self.bitmap.blt(x, y, bitmap, rect, enabled ? 255 : 128)
  51.   end
  52. end
  53. #===============================================================================
  54. module Cache
  55.   def self.icon(filename)
  56.     load_bitmap("Graphics/Icons/",filename)
  57.   end
  58. end
  59. #===============================================================================
  60. class Ring_Menu
  61.   RESO = 4
  62.   PLAY_SE = true
  63.   SELECTED_ANGLE= Math::PI/2.0 # 90°CW to set the "0" at the bottom
  64.   #---------------------------------
  65.   attr_reader :options, :h_radius, :v_radius, :center, :zoom, :visible, :opacity, :zoom_max, :reso
  66.   attr_accessor :active, :index
  67.   #---------------------------------
  68.   def initialize(h_rad=10,v_rad=10,center=Table.new(2),options=[])
  69.     @options=options
  70.     @v_radius=v_rad
  71.     @h_radius=h_rad
  72.     @center = center
  73.     @index=0
  74.     @reso = RESO
  75.     @visible = true
  76.     @zoom_max = 1.4
  77.     @opacity = 255
  78.     @active = true
  79.     @zoom = true
  80.     @angle = h_rad == 0 ? 0 : SELECTED_ANGLE
  81.     process
  82.   end
  83.   # Attributes
  84.   def options=(a=[])
  85.     @options=a
  86.     @index=0
  87.     process
  88.   end
  89.  
  90.   def vertical?
  91.     @h_radius == 0
  92.   end
  93.  
  94.   def x
  95.     @center[0]
  96.   end
  97.   def y
  98.     @center[1]
  99.   end
  100.   def x=(*args)
  101.     @center[0]= args.first
  102.     process
  103.   end
  104.   def y=(*args)
  105.     @center[1]= args.first
  106.     process
  107.   end
  108.   def visible=(value)
  109.     @visible = value
  110.     @options.each{|opt| opt.sprite.visible=value if !opt.nil?}
  111.   end
  112.   def opacity=(value)
  113.     value = 0 if value < 0
  114.     value = 255 if value > 255
  115.     @opacity = value
  116.     @options.each{|opt| opt.sprite.opacity=value}
  117.   end
  118.   def h_radius=(value)
  119.     @h_radius = value
  120.   end
  121.   def v_radius=(value)
  122.     @v_radius = value
  123.   end
  124.   def center=(value)
  125.     @center = value
  126.   end
  127.   def zoom=(value)
  128.     @zoom = value
  129.     draw
  130.   end
  131.  
  132.   def reso=(v)
  133.     @reso = v
  134.     process
  135.   end
  136.  
  137.   def zoom_max=(value)
  138.     @zoom_max= value
  139.     process
  140.   end
  141.   # ENd Attributes
  142.   #---------------------------------
  143.   # Update
  144.   #---------------------------------
  145.   def update
  146.     return if !self.active or !self.visible
  147.     update_flag = (@old_center!=@center or @old_hr != @h_radius or @old_vr != @v_radius)
  148.     if Input.repeat?(vertical? ? Input::UP : Input::LEFT)
  149.       loop do
  150.         rotate
  151.         break unless self.selected.disabled
  152.       end
  153.     elsif Input.repeat?(vertical? ? Input::DOWN : Input::RIGHT)
  154.       loop do
  155.         rotate(1)
  156.         break unless self.selected.disabled
  157.       end
  158.     end
  159.     process if update_flag
  160.   end
  161.  #---------------------------------
  162. # Process: Create/recreate according to the menu attributes, the position/zoom values of the options, and store them into arrays.
  163.  #---------------------------------
  164.   def process
  165.     # return if the menu is empty.
  166.     return if @options.empty?
  167.     # Get the maximum size for the arrays.
  168.     max_data=@options.size*@reso
  169.     # Divide a circle(2*Pi) by the numbers of options.
  170.     @base_angle = Math::PI*2.0/max_data
  171.     @zoom_step = (@zoom_max-0.5)/(max_data/2.0)
  172.     # set an array having precalculated pair of coordinates so we don't have to
  173.     # get process them for each rotation(we simply switch the options coords)
  174.     @coord_set= Array.new(max_data,0)
  175.     # and for zoom values as well
  176.     @zoom_set = Array.new(max_data,0)
  177.     max_data.times do |i|
  178.       angle = i*@base_angle+@angle
  179.       x = (Math::cos(angle)*@h_radius)+@center[0]
  180.       y = (Math::sin(angle)*@v_radius)+@center[1]
  181.       @coord_set[i]=([x,y])
  182.       @zoom_set[i]= i<max_data/2.0 ? @zoom_max-@zoom_step*i : @zoom_set[max_data/2.0-i-max_data/2.0-1]
  183.     end
  184.  
  185.     val = (@index % max_data)+1+((@reso-4)/2.0).round
  186.    
  187.     @coord_set.rotate_r!(val)
  188.     @zoom_set.rotate_r!(val)
  189.     @old_center = @center
  190.     @old_hr = @h_radius
  191.     @old_vr = @v_radius
  192.     draw
  193.     self.selected.selected = true
  194.     if @h_radius==0
  195.       self.selected.sprite.z =1000
  196.     end
  197.   end
  198.   #--------------------------------------
  199.   # Draw the options according to the current index
  200.   #--------------------------------------
  201.   def draw
  202.     @coord_set.each_index do |index|
  203.       i = (index / @reso.to_f).round
  204.       # next iteration if the current option is not a RMenu_Option
  205.       next if !@options[i].is_a?(RMenu_Option)
  206.       # Set the Option coords
  207.       (@options[i]).coord = @coord_set[index]
  208.       # Set the option's Z-index to its y.
  209.       @options[i].z = @coord_set[index][1]
  210.       #@options.zoom = 1.0 if !@zoom
  211.       @options[i].zoom = @zoom? @zoom_set[index] : 1.0
  212.       #@options[i].selected = (@options[i]==self.selected)
  213.     end
  214.     @old_zoom = @zoom
  215.     Graphics.update
  216.   end
  217.   #---------------------------------
  218.   # Rotate the menu options
  219.   #---------------------------------
  220.   def rotate(way=0)# 0 = left, 1 = right
  221.     self.selected.selected = false
  222.     Sound.play_cursor if PLAY_SE
  223.     frcount = Graphics.frame_count # Save the current frame count ( -> Game Time )
  224.       @index += way*2-1
  225.       @index %= @options.size
  226.       @reso.times do
  227.         if way==0
  228.           @coord_set.rotate_l!
  229.           @zoom_set.rotate_l!
  230.         elsif way==1
  231.           @coord_set.rotate_r!
  232.           @zoom_set.rotate_r!
  233.         end
  234.         draw
  235.       end
  236.     self.selected.selected = true
  237.     if @h_radius==0
  238.       self.selected.sprite.z =1000 # Set the selected option to the top
  239.     end
  240.     Graphics.frame_count = frcount # Reset the frame count to the previous value
  241.   end
  242.   #---------------------------------
  243.   # Return the current selected option
  244.   #---------------------------------
  245.   def selected
  246.     @options[@index % @options.size]
  247.   end
  248.   #---------------------------------
  249.   # Dispose the menu (and all the options)
  250.   #---------------------------------
  251.   def dispose
  252.     @options.each{|opt| opt.dispose}
  253.   end
  254.   #--------------------------------------------------------------------------
  255.   # * Save State
  256.   #--------------------------------------------------------------------------
  257.   def save_state
  258.     @state_visible = self.visible
  259.     @state_active = self.active
  260.   end
  261.   #--------------------------------------------------------------------------
  262.   # * Load State
  263.   #--------------------------------------------------------------------------
  264.   def load_state
  265.     self.visible = @state_visible unless @state_visible.nil?
  266.     self.active = @state_active unless @state_active.nil?
  267.   end
  268.   #--------------------------------------------------------------------------
  269.   # * Hide
  270.   #--------------------------------------------------------------------------
  271.   def hide
  272.     self.visible = false
  273.     self.active = false
  274.   end
  275.   #--------------------------------------------------------------------------
  276.   # * Show
  277.   #--------------------------------------------------------------------------
  278.   def show
  279.     self.visible = true
  280.     self.active = true
  281.   end
  282. end
  283. #===============================================================================
  284. # Menu option class
  285. class RMenu_Option
  286.   attr_reader :name, :icon, :coord, :sprite, :selected, :disabled
  287.   attr_accessor :angle
  288.   def initialize(name="",icon=0,viewport=nil,&block)
  289.     @name=name
  290.     @icon=icon
  291.     @block=block
  292.     @angle = 0
  293.     @coord=Table.new(2)
  294.     @disabled = false
  295.     @sprite = Sprite.new(viewport)
  296.     if icon != 0
  297.       @sprite.bitmap = Bitmap.new(24,24)
  298.       @sprite.draw_icon(@icon,0,0,true)
  299.     else
  300.       @sprite.bitmap = Cache.icon(name)
  301.     end
  302.     #p @sprite.bitmap.width/2,@sprite.bitmap.height/2
  303.     @sprite.ox = @sprite.bitmap.width/2
  304.     @sprite.oy = @sprite.bitmap.height/2
  305.     @selected = false
  306.     @sprite.tone.gray = 255
  307.   end
  308.   def call
  309.     return if @block.nil?
  310.     @block.call
  311.   end
  312.   def z=(value)
  313.     @sprite.z = value
  314.   end
  315.   def selected=(v)
  316.     if v != @selected
  317.       @sprite.tone.gray = (v==true ? 0 : 255)
  318.       @selected = v==true
  319.     end
  320.   end
  321.   def disabled=(v)
  322.     @disabled= v==true
  323.   end
  324.   def coord=(c = [0,0])
  325.     @coord=c
  326.     @sprite.x = @coord[0]
  327.     @sprite.y = @coord[1]
  328.   end
  329.   def x=(*args)
  330.     @coord[0]= args.first
  331.     @sprite.x= args.first
  332.   end
  333.   def y=(*args)
  334.     @coord[1]= args.first
  335.     @sprite.y= args.first
  336.   end
  337.   def zoom=value
  338.     @sprite.zoom_x = value
  339.     @sprite.zoom_y = value
  340.   end
  341.   def dispose
  342.     @coord=nil
  343.     @block=nil
  344.     @sprite.dispose
  345.   end
  346. end
Expand to see the code.


SCRIPT FOR XP Spoiler
  1. #===============================================================================
  2. =begin
  3. RING MENU advanced.
  4. by Trebor777
  5. v1.8.1
  6. 24/07/2009
  7. An independant, class free, Ring menu, easily usable, with a lot of options.
  8. =end
  9. #===============================================================================
  10. class Array
  11.   # rotate  n item(s) to the left ( first becomes last) as a new array
  12.   def rotate_l(n=1)
  13.     a = self.clone
  14.     n.times{a.push(a.shift)}
  15.     return a
  16.   end
  17.   # rotate  n item(s) to the right ( last becomes first) as a new array
  18.   def rotate_r(n=1)
  19.     a = self.clone
  20.     n.times{a.unshift(a.pop)}
  21.     return a
  22.   end
  23.   # rotate n item(s) to the left
  24.   def rotate_l!(n=1)
  25.     n.times{self.push(self.shift)}
  26.     return self
  27.   end
  28.   # rotate n item(s) to the right
  29.   def rotate_r!(n=1)
  30.     n.times{self.unshift(self.pop)}
  31.     return self
  32.   end
  33.   # Do the sum of all the items. (they need to be all of the same type)
  34.   def sum
  35.     inject( nil ) { |sum,x| sum ? sum+x : x if x.respond_to? "+" }
  36.   end
  37. end
  38. module Sound
  39.   #--------------------------------------------------------------------------
  40.   # * Play Sound Effect
  41.   #     se : sound effect to be played
  42.   #--------------------------------------------------------------------------
  43.   def self.se_play(se)
  44.     if se != nil and se.name != ""
  45.       Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
  46.     end
  47.   end
  48.  
  49.   def self.play_cursor
  50.     se_play($data_system.decision_se) unless $data_system.nil?
  51.   end
  52. end
  53. #===============================================================================
  54. class Ring_Menu
  55.   RESO = 4
  56.   PLAY_SE = true
  57.   SELECTED_ANGLE= Math::PI/2.0 # 90°CW to set the "0" at the bottom
  58.   #---------------------------------
  59.   attr_reader :options, :h_radius, :v_radius, :center, :zoom, :visible, :opacity, :zoom_max, :reso
  60.   attr_accessor :active, :index
  61.   #---------------------------------
  62.   def initialize(h_rad=10,v_rad=10,center=Table.new(2),options=[])
  63.     @options=options
  64.     @v_radius=v_rad
  65.     @h_radius=h_rad
  66.     @center = center
  67.     @index=0
  68.     @reso = RESO
  69.     @visible = true
  70.     @zoom_max = 1.4
  71.     @opacity = 255
  72.     @active = true
  73.     @zoom = true
  74.     @angle = h_rad == 0 ? 0 : SELECTED_ANGLE
  75.     process
  76.   end
  77.   # Attributes
  78.   def options=(a=[])
  79.     @options=a
  80.     @index=0
  81.     process
  82.   end
  83.  
  84.   def vertical?
  85.     @h_radius == 0
  86.   end
  87.  
  88.   def x
  89.     @center[0]
  90.   end
  91.   def y
  92.     @center[1]
  93.   end
  94.   def x=(*args)
  95.     @center[0]= args.first
  96.     process
  97.   end
  98.   def y=(*args)
  99.     @center[1]= args.first
  100.     process
  101.   end
  102.   def visible=(value)
  103.     @visible = value
  104.     @options.each{|opt| opt.sprite.visible=value if !opt.nil?}
  105.   end
  106.   def opacity=(value)
  107.     value = 0 if value < 0
  108.     value = 255 if value > 255
  109.     @opacity = value
  110.     @options.each{|opt| opt.sprite.opacity=value}
  111.   end
  112.   def h_radius=(value)
  113.     @h_radius = value
  114.   end
  115.   def v_radius=(value)
  116.     @v_radius = value
  117.   end
  118.   def center=(value)
  119.     @center = value
  120.   end
  121.   def zoom=(value)
  122.     @zoom = value
  123.     draw
  124.   end
  125.  
  126.   def reso=(v)
  127.     @reso = v
  128.     process
  129.   end
  130.  
  131.   def zoom_max=(value)
  132.     @zoom_max= value
  133.     process
  134.   end
  135.   # ENd Attributes
  136.   #---------------------------------
  137.   # Update
  138.   #---------------------------------
  139.   def update
  140.     return if !self.active or !self.visible
  141.     update_flag = (@old_center!=@center or @old_hr != @h_radius or @old_vr != @v_radius)
  142.     if Input.repeat?(vertical? ? Input::UP : Input::LEFT)
  143.       loop do
  144.         rotate
  145.         break unless self.selected.disabled
  146.       end
  147.     elsif Input.repeat?(vertical? ? Input::DOWN : Input::RIGHT)
  148.       loop do
  149.         rotate(1)
  150.         break unless self.selected.disabled
  151.       end
  152.     end
  153.     process if update_flag
  154.   end
  155.  #---------------------------------
  156. # Process: Create/recreate according to the menu attributes, the position/zoom values of the options, and store them into arrays.
  157.  #---------------------------------
  158.   def process
  159.     # return if the menu is empty.
  160.     return if @options.empty?
  161.     # Get the maximum size for the arrays.
  162.     max_data=@options.size*@reso
  163.     # Divide a circle(2*Pi) by the numbers of options.
  164.     @base_angle = Math::PI*2.0/max_data
  165.     @zoom_step = (@zoom_max-0.5)/(max_data/2.0)
  166.     # set an array having precalculated pair of coordinates so we don't have to
  167.     # get process them for each rotation(we simply switch the options coords)
  168.     @coord_set= Array.new(max_data,0)
  169.     # and for zoom values as well
  170.     @zoom_set = Array.new(max_data,0)
  171.     max_data.times do |i|
  172.       angle = i*@base_angle+@angle
  173.       x = (Math::cos(angle)*@h_radius)+@center[0]
  174.       y = (Math::sin(angle)*@v_radius)+@center[1]
  175.       @coord_set[i]=([x,y])
  176.       @zoom_set[i]= i<max_data/2.0 ? @zoom_max-@zoom_step*i : @zoom_set[max_data/2.0-i-max_data/2.0-1]
  177.     end
  178.  
  179.     val = (@index % max_data)+1+((@reso-4)/2.0).round
  180.    
  181.     @coord_set.rotate_r!(val)
  182.     @zoom_set.rotate_r!(val)
  183.     @old_center = @center
  184.     @old_hr = @h_radius
  185.     @old_vr = @v_radius
  186.     draw
  187.     self.selected.selected = true
  188.     if @h_radius==0
  189.       self.selected.sprite.z =1000
  190.     end
  191.   end
  192.   #--------------------------------------
  193.   # Draw the options according to the current index
  194.   #--------------------------------------
  195.   def draw
  196.     @coord_set.each_index do |index|
  197.       i = (index / @reso.to_f).round
  198.       # next iteration if the current option is not a RMenu_Option
  199.       next if !@options[i].is_a?(RMenu_Option)
  200.       # Set the Option coords
  201.       (@options[i]).coord = @coord_set[index]
  202.       # Set the option's Z-index to its y.
  203.       @options[i].z = @coord_set[index][1]
  204.       #@options.zoom = 1.0 if !@zoom
  205.       @options[i].zoom = @zoom? @zoom_set[index] : 1.0
  206.       #@options[i].selected = (@options[i]==self.selected)
  207.     end
  208.     @old_zoom = @zoom
  209.     Graphics.update
  210.   end
  211.   #---------------------------------
  212.   # Rotate the menu options
  213.   #---------------------------------
  214.   def rotate(way=0)# 0 = left, 1 = right
  215.     self.selected.selected = false
  216.     Sound.play_cursor if PLAY_SE
  217.     frcount = Graphics.frame_count # Save the current frame count ( -> Game Time )
  218.       @index += way*2-1
  219.       @index %= @options.size
  220.       @reso.times do
  221.         if way==0
  222.           @coord_set.rotate_l!
  223.           @zoom_set.rotate_l!
  224.         elsif way==1
  225.           @coord_set.rotate_r!
  226.           @zoom_set.rotate_r!
  227.         end
  228.         draw
  229.       end
  230.     self.selected.selected = true
  231.     if @h_radius==0
  232.       self.selected.sprite.z =1000 # Set the selected option to the top
  233.     end
  234.     Graphics.frame_count = frcount # Reset the frame count to the previous value
  235.   end
  236.   #---------------------------------
  237.   # Return the current selected option
  238.   #---------------------------------
  239.   def selected
  240.     @options[@index % @options.size]
  241.   end
  242.   #---------------------------------
  243.   # Dispose the menu (and all the options)
  244.   #---------------------------------
  245.   def dispose
  246.     @options.each{|opt| opt.dispose}
  247.   end
  248.   #--------------------------------------------------------------------------
  249.   # * Save State
  250.   #--------------------------------------------------------------------------
  251.   def save_state
  252.     @state_visible = self.visible
  253.     @state_active = self.active
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # * Load State
  257.   #--------------------------------------------------------------------------
  258.   def load_state
  259.     self.visible = @state_visible unless @state_visible.nil?
  260.     self.active = @state_active unless @state_active.nil?
  261.   end
  262.   #--------------------------------------------------------------------------
  263.   # * Hide
  264.   #--------------------------------------------------------------------------
  265.   def hide
  266.     self.visible = false
  267.     self.active = false
  268.   end
  269.   #--------------------------------------------------------------------------
  270.   # * Show
  271.   #--------------------------------------------------------------------------
  272.   def show
  273.     self.visible = true
  274.     self.active = true
  275.   end
  276. end
  277. #===============================================================================
  278. # Menu option class
  279. class RMenu_Option
  280.   attr_reader :name, :icon, :coord, :sprite, :selected, :disabled
  281.   attr_accessor :angle
  282.   def initialize(name="",icon=0,viewport=nil,&block)
  283.     @name=name
  284.     @icon=icon
  285.     @block=block
  286.     @angle = 0
  287.     @coord=Table.new(2)
  288.     @disabled = false
  289.     @sprite = Sprite.new(viewport)
  290.     @sprite.bitmap = RPG::Cache.icon(name)
  291.     #p @sprite.bitmap.width/2,@sprite.bitmap.height/2
  292.     @sprite.ox = @sprite.bitmap.width/2
  293.     @sprite.oy = @sprite.bitmap.height/2
  294.     @selected = false
  295.     @sprite.tone.gray = 255
  296.   end
  297.   def call
  298.     return if @block.nil?
  299.     @block.call
  300.   end
  301.   def z=(value)
  302.     @sprite.z = value
  303.   end
  304.   def selected=(v)
  305.     if v != @selected
  306.       @sprite.tone.gray = (v==true ? 0 : 255)
  307.       @selected = v==true
  308.     end
  309.   end
  310.   def disabled=(v)
  311.     @disabled= v==true
  312.   end
  313.   def coord=(c = [0,0])
  314.     @coord=c
  315.     @sprite.x = @coord[0]
  316.     @sprite.y = @coord[1]
  317.   end
  318.   def x=(*args)
  319.     @coord[0]= args.first
  320.     @sprite.x= args.first
  321.   end
  322.   def y=(*args)
  323.     @coord[1]= args.first
  324.     @sprite.y= args.first
  325.   end
  326.   def zoom=value
  327.     @sprite.zoom_x = value
  328.     @sprite.zoom_y = value
  329.   end
  330.   def dispose
  331.     @coord=nil
  332.     @block=nil
  333.     @sprite.dispose
  334.   end
  335. end
Expand to see the code.



Instructions

Very easy to use, only a few things to keep in mind!

->Paste the script above main!

->Now to create a ring menu:
Step 1
- you need to create the options like this =>
  1. RMenu_Option.new("Name", [icon_id, viewport]) { optional_block }
Expand to see the code.

FOR VX ONLY : If icon_id is equal to 0 ( its default value), it will look for an image named with "Name" in a folder called "Icons" in the Graphics folder.

FOR XP only: Because XP doesn't have an icon set, the icon feature only works with the name, the xp script doesn't care about the Icon id, and will only look for a valid icon name

The block is optional as well :) if not needed, don't write anything after the parenthesis.

Step 2
You place those options inside a temporary array, this array will be used when creating the menu:
  1. opt  = [
  2.       RMenu_Option.new("SelData"){ $scene = Scene_Data.new },
  3.       RMenu_Option.new("CopData"){ $scene = Scene_Copy_Data.new },
  4.       RMenu_Option.new("DelData"){ $scene = Scene_Del_Data.new }
  5.       ]
  6.  
Expand to see the code.


Step 3
Create the menu!
  1. Ring_Menu.new( [h_radius, v_radius, [x,y], opt_array] )
Expand to see the code.

-> by default h_radius and v_radius = 10, x & y = 0 and opt_array is an empty array.
Yes that means you can add/remove options later on!

That's for the basic Creation!

-> The menu needs to be updated! Like any normal graphical object in a scene. :) menu.update
No need to use code stuff for arrow keys, it's already done in the update method.

-> AND to be disposed as well :) menu.dispose

To get the current selected option : menu.selected
Therefore: to execute the optional block given at the option creation, -> menu.selected.call


Like a window, the menu is only active or visible when you want it: menu.active/visible = true/false,

The zoom attribute: if true ( menu.zoom = true ), it'll activate the perspective effect, -> basically the options 'in front' of us are bigger than the options in the back.
By default the "max size" is 40% bigger than the original file (zoom_x/y = 1.4)
But you can change that max value if required. For example -> menu.zoom_max = 1.0

If you need to change the fluidity of the menu scrolling: you need to use -> menu.reso= value
by default this value is 4, it means it takes 4 frames to go from one option to another.

If you intend to change the "fluidity", it's important that you do it before anything else.

You can play with the opacity, as well like sprites.

FAQ

[i]"I've noticed some constants in the RingMenu class, what are they? Can I use them?"

3 Constants:
- RESO : the default "fluidity"(number of frames) used to move from one option ot another, you can change it, if you don't want to do it for several menu that use the same value
- PLAY_SE : if false, the menu won't make any noise when being scrolled.
- SELECTED_ANGLE : I suggest you don't touch it. The function -> Because a 0° angle is on the right on the trigonometric circle, I need to "rotate" that circle in order to have the 0 , in front of me, which is at the bottom. It is used when the menu is "horizontal", to have the selected option, in front of us, instead of the right of the ring. The angle is in Radian.

When I press Up/Down on a vertical ring menu, nothing happens, Why ?
-> Check that the horizontal radius is 0, if not, Use the left/right keys!

Compatibility

I've added Methods to the cache module, to the array Class, the sprite Class as well
As long as no other classes are called like mines, it should be fine. ( too lazy to put mine into a module. )

Author's Notes

I did this script for the 1st time in 12/2007 on XP :) and updated for my needs with time.
It's used in Castlevania as well. And I thought I should release it, cause it's a very convenient thing to use!

Terms and Conditions
Everywhere you want, just credit me :)
Bump

Demo posted :) and Script updated as well !
Wow, it's great, thank trebor777 :D
Trebor I'm just wondering, can you also used it inside the battle system? :)
yes you can use it in any script you want:) that's the point of it. It replaces easily any "windows_selectable/command"
I remember using a previous version of this script to do a paid commission for a mario RPG like battle system.
This looks like a really wonderful setup. Beautiful outlay. Love it. :)
Lookas amazing!! Would it be possible to make XP version too?
My XP version exists already(been created originally on XP), I just need to update it first to have all the features of the VX version. But yeah :) It's possible.
Can we get a demo to the XP version?
trebor777 wrote:
My XP version exists already(been created originally on XP), I just need to update it first to have all the features of the VX version. But yeah :) It's possible.


Awsome! :>
OMG this is sexy! Also it so happened that I had made the same kind of methods for the Array class for one of my menus but your array methods totally pwn mine, thanks ;)

BTW, thats really bad ass you decided to post this for us (patiently awaiting your XP version)! Next menu/selection type thing I do I'm gonna purposely make sure to use this with it 😀

:thumb: x 100
Cool script, im always coming back here looking for something new scripts and updates as well, keep up the good work. 🙂
Thx for your comments people!

I've updated the 1st post with the XP version :)
There is a minor change in the instructions for XP :) be sure to have a look at that.

Funny, took me longer to convert the actual demo scene, than the script itself.
Enjoy!
Help me please, how could i put this inside a battle system? All this seems confusing to me, cuz the demo and your instructions are very different :/

I mean, how to replace this:

s1 = $data_system.words.attack
s2 = $data_system.words.skill
s3 = $data_system.words.guard
s4 = $data_system.words.item
@actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])
@actor_command_window.y = 160
@actor_command_window.back_opacity = 160
@actor_command_window.active = false
@actor_command_window.visible = false

for a ring menu?
you'll need icons(pictures) to represent each option, if you want text in those icons, you either do it when you create the icons or do that with the script (though it's a bit tricky) Icons in XP can be any size:)
If you use the name method in VX for the icon, then they can be anysize as well.

Then you create the options, I suggest to do that in an array, so you can access them independently later: (let's go for the xp version )
  1.  
  2. options = []
  3. options << RMenu_Option.new("Attack_ico",im_a_number_if_needed, viewport_if_needed)# Im anumber can be anything for XP, but for VX can be 0 (then it's using the name to find the icon) or a the icon_id from the iconset. If you don't need the number and the viewport, you don't have to specify them.
  4. # ETC. for the other icons
  5.  
Expand to see the code.


then you create the menu
  1.  
  2. # Radius of 100, kind of arbitrary, but it's to stick with the 160width of the original window (100 + 2*ico width)
  3. @actor_command_window = Ring_Menu.new(100,10, [x,160], options) # X is created from a constant * the actor_id I think :) doesn't matter, like a window, the x can be specified later. And i guess it's specified somewhere else in the code.
  4. # Sorry no back_opacity :) as there is no back lol.
  5. @actor_command_window.active = false
  6. @actor_command_window.visible = false
  7.  
Expand to see the code.


Hopefully we don't need more edition :), as you can still use "menu.index" like you would do "window.index" so the rest of the system should work properly. No need to insert code in the options and such, as it would require a major rewrite of the update methods as well.

#-------------------------------------------------------
Completly unrelated:

- For those who explored a bit the script, nothing prevents you to use the ring_menu for esthetic purpose only :), it can turn on it's own if you call the rotate method on it. :)

- If you want to write text on a single "background" for the options, Like all the options have the same look, but different text: To do that without problems of text overwriting each other is:
-> load the bitmap of the original icon in a variable
-> Create the option with the "original_icon" to use.
-> then edit the option with something like this:
option.sprite.bitmap = local_bitmap.clone # Clone will create a new bitmap instead of using the one in the cache :)
-> Write you text on it :) : option.sprite.bitmap.draw_text(all theargs)
-> Create your menu as normal.

That's what I do for the title screen in Castlevania.
:angel: plz help me i dont no how to install this shit plz video tutorial
It's completely plug and play(if you know how to script).

It's not a menu system, it's a system for making your own menus.

By the way Trebor, the key input for it doesn't work(at least not on my computer).
Ulqiorra wrote:
It's completely plug and play(if you know how to script).
Absolute big grin at this sentence! :D


@trebor: Good script as in functionality theory. However, practical test allowed me selecting the disabled option quite a few times (resulting in the script sometimes executing the moveme-selection, and sometimes putting me on Scene_Map with completely accessible sapnish menu), so if that wasn't intentional, you got quite a bit of bugfixing ahead of ya (no time to test it any further really, and it's easier for you either way). If it WAS intentional, you have BAD design errors in there as far as guidance goes ^^

Keep up the good work!
I'm glad you noticed that Blue.

But yeah, the XP demo is missing the Key Input code(which i already added to my version, by the way), you should fix that.

And why does it give the menu a slanted perspective even when :h_radius and :v_radius are the same? isn't there a formula you can use to calculate the perspective from the horizontal and vertical radius's?
It's not a formula that calculates the "perspective", but just a boolean, called zoom.

Yeah sorry about the code input in the demo, I've a tendancy to forget updating my demos...

I think I did a pretty bad demo anyway, made it very quickly, mixing 2 menu on the same scene, which was something i never tried before, but thought it could work.

Blue can you tell me how you've managed to end up on the disabled option ?
Oh, alright. No worries, I have a habit of leaving my script topics alone for months after i update the script...
@trebor: Not really, seemed kinda random to me... either way, I think I noticed something like everytime I chose an option, it'd return to the 'move' option being highlighted... and well, all of a sudden, it turned to the disabled option... (I probably should've checked if it'D skip another option now and therefor shift the displayed items or something...)
I suppose it's got something to do with two menues being activated at the same time, along with like a single exchangd number or leter in the script noone ever notices while scripting ^^ (I know that...)

If I got time to test this a little more in-depth, I'll give it a shot...
Wow, this looks SO amazing! Too bad i dont have very much scripting knowledge--tried but, cant even put it into something as simple as the title screen-- otherwise, i would add it to everything!
Wow! This looks absolutely incredible!

I've been looking for something I can use to spice up my game a bit, and I think this is just what I've been looking for. This will go really well in my battle system.

Trebor, you're a beast.
I wish I could script...
But I can't :(

No fair, now I can't put this in my battles ;(

Maybe you could upload a demo where it is implied in the battle system?
Would be appriciated by, I guess, alot of people.
@Trebor: I haven't been able to reproduce the bug, but it all seems to be originated at one being able to scroll through the options and ending up at different options than "move/stop" by doing that at just the right moment. Your code looks fine too (well, it's not exactly good style, but it looks flawless from a more quicker glance), so I guess if you just prevent the player from scrolling through the options while movement is still executed and therefore switching options, that shoudl settle it.
I should probably mention that what I tested was the VX version.

@gast: There are detailed instructions in the first post which really are pretty easy to follow... maybe the reason you can't script is because you never wanted to work for it, eh? ;)
That aside, why would you want something in your game everyone else has as well, getting it directly from a pre-made battle script? Just use the defaults then...
Humpf, I'll try to put it in, but if it won't work... Yea...

But I did try to understand it!
In that case, you're always welcome to ask for support in the RGSS Support forums... ^^
Hello Trebor~ I found a bug D=
I asked my friends to figure out how to use your ring menu and it worked pretty sweetly~ but there's a problem

Image

In case you are curious on what we did~
  1.  
  2. class Scene_Battle
  3.  
  4.   alias create_info_viewport_old create_info_viewport unless $@
  5.   def create_info_viewport
  6.     create_info_viewport_old
  7.     @actor_command_window.dispose
  8.     @actor_command_window = nil
  9. #~  @actor_command_window.visible = false
  10.   end
  11.  
  12.   def create_options
  13.     # Create empty options with no graphics, with just block of instructions
  14.     @command_name = Sprite.new
  15.     opt = [
  16.     RMenu_Option.new("Attack", 1)  , # Bitmap.new("Graphics\Whatever\Filename")
  17.     RMenu_Option.new("Skill", 100)  ,
  18.     RMenu_Option. new("Guard", 52)  ,
  19.     RMenu_Option.new("Item", 64)  ,
  20.     ]
  21.   end
  22.  
  23.   alias old_terminate terminate unless $@
  24.   def terminate
  25.     old_terminate
  26.     @actor_command_window.dispose
  27.   end
  28.   #-----------------------------------------------
  29.   alias old_update update unless $@
  30.   def update
  31.     old_update
  32.    
  33.     animate_menu if @animate
  34.    
  35.     #@actor_command_window.update
  36.     @actor_command_window.selected.call if Input.trigger? Input::C
  37.   end
  38.   #-----------------------------------------------
  39.   def animate_menu
  40.      if Graphics.frame_count < 120
  41.       @actor_command_window.x +=2
  42.       @actor_command_window.y -=1
  43.       @actor_command_window.z = self.z - 1
  44.     end
  45.     if Graphics.frame_count.between?(120,240)
  46.       @actor_command_window.x -= 2
  47.       @actor_command_window.y +=1      
  48.       @actor_command_window.z = self.z - 1
  49.     end
  50.    
  51.     if Graphics.frame_count.between?(400,500)
  52.       @actor_command_window.opacity -=2
  53.     else
  54.       @actor_command_window.opacity +=2
  55.     end
  56.    
  57.     Graphics.frame_count %= 500
  58.   end
  59.   #                   ID      Battler 1   Battler 2   Battler 3   Battler 4
  60.   ABATVX_FORMATION = { 0 => [ [350, 200], [395, 235], [440, 270], [485, 305] ],
  61.                        1 => [ [485, 200], [440, 235], [395, 270], [350, 305] ] }
  62.  
  63.   def start_actor_command_selection
  64.     @actor_command_window = Ring_Menu.new(30,10,[Graphics.width/2,Graphics.height/2-60], create_options)
  65.     @actor_command_window.visible = false
  66.     @actor_command_window.x = @active_battler.screen_x - 0
  67.     @actor_command_window.y = @active_battler.screen_y - 65
  68.     @party_command_window.active = false
  69.     #@actor_command_window.setup(@active_battler)
  70.     @actor_command_window.visible = true
  71.     @actor_command_window.active = true
  72.     @actor_command_window.index = 0
  73.     @active_battler.action.basic = 3 if @active_battler.action.basic == 1
  74.   end
  75.  
  76.   def start_skill_selection
  77.     @help_window = Window_HelpArcheia.new
  78.     @skill_window = Window_SkillArcheia.new(-3, 135, 530, 80, @active_battler)
  79.     @skill_window.help_window = @help_window
  80.     @actor_command_window.active = false
  81.     @actor_command_window.visible = false
  82.   end
  83.     def end_skill_selection
  84.     if @skill_window != nil
  85.       @skill_window.dispose
  86.       @skill_window = nil
  87.       @help_window.dispose
  88.       @help_window = nil
  89.     end
  90.     @actor_command_window.active = true
  91.     @actor_command_window.visible = true
  92.   end
  93.    def start_item_selection
  94.     @help_window = Window_HelpArcheia.new
  95.     @item_window = Window_ItemArcheia.new(-3, 135, 530, 80)
  96.     @item_window.help_window = @help_window
  97.     @actor_command_window.active = false
  98.     @actor_command_window.visible = false
  99.   end
  100.  
  101.   def end_item_selection
  102.     if @item_window != nil
  103.       @item_window.dispose
  104.       @item_window = nil
  105.       @help_window.dispose
  106.       @help_window = nil
  107.     end
  108.     @actor_command_window.active = true
  109.     @actor_command_window.visible = true
  110.   end
  111.   def start_party_command_selection(skip = false)
  112.     if skip
  113.       if $game_temp.in_battle
  114.         @status_window.refresh
  115.         @status_window.index = @actor_index = -1
  116.         @active_battler = nil
  117.         @info_viewport.visible = true
  118.         @message_window.visible = false
  119.         @party_command_window.active = false
  120.         @party_command_window.index = 0
  121.         #@actor_command_window.active = false
  122.         $game_party.clear_actions
  123.         if $game_troop.surprise or not $game_party.inputable?
  124.           start_main
  125.         end
  126.         @status_window.index = @actor_index = -1
  127.         next_actor
  128.       end
  129.     else
  130.       #Process the original
  131.       vxctb_start_party_command_selection
  132.     end
  133.   end
  134.  
  135. def update_info_viewport
  136.     @party_command_window.update
  137.     @actor_command_window.update if @actor_command_window != nil
  138.     @status_window.update
  139.   end
  140. end  
  141.  
Expand to see the code.
sorry for the late answer...
I think it's because you're recreating a new ring menu each time, when it is the actor's turn... I'm sorry , i don't really remember how things are in rm, lol haven't touch it in month, even more on the default rgss script themselves.
So yeah, i'm not sure, but that could explain, the previous menu being still here and not disposed when displaying the new one. the ring menu, like the original command window(if my memories are correct, should be created in the initialize method of the scene_battle.
and then simply moved to the correct place ( like you do on line 66-67 ) in start_actor_command_selection.

Basically ring_menu act as a window ( you'll see that both classes share similar methods ). So
1st -> replace the original window where it's created.
2nd -> just adapt code from the way you can access current option from the menu ( which doesn't seem to be the problem here anyway )
3rd -> ENjoy!

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=66249