I added the separate window option. But I'm not going to implement mouse controls.
Added two new options, DISPLAY_TYPE and DISPLAY_POSITION.
#===============================================================================
# Ring Menu Show Choices
# Version 1.1
# Author gameus
#-------------------------------------------------------------------------------
# Intro:
# Displays a ring of options when using the 'Show Choices' command. The ring
# can be toggled allowing use for both the ring menu and the regular command.
#
# Instructions:
# Do the little amount of configuration below. Ignore the DISABLED_ICON option.
# It's useless but is needed to be there.
#
# To use the ring menu, use this script call before using 'Show Choices'
# $game_system.ring = true
# To go back to the regular show choices, use this
# $game_system.ring = false
# That's pretty much it.
#
# Oh, and you need to have your icons titled as such and placed in the icons
# folder.
# choice_icon
# Example, your choices are Talk, Barter, Nevermind
# Talk_icon
# Barter_icon
# Nevermind_icon
#
# If the icon isn't found, it'll use the placeholder configured below.
#
# Credits
# gameus ~ For making it
# Unknown Author ~ For base Ring Menu
# Colonel Blinx ~ For requesting it
# Zeriab ~ For interpreter fix (included in this script)
#===============================================================================
module Gameus
# You can either display the option in the ring menu, or a separate window
# 0 = ring, 1 = separate menu
DISPLAY_TYPE = 1
# X and Y for the window in display type 1
DISPLAY_POSITION = [64, 64]
# Radius for the ring menu, 64 is a pretty good value
RING_MENU_RADIUS = 64
# Ignore this
DISABLED_ICON = ''
# This is the sound effect that plays when the ring opens up
# blank = no sound
SE_STARTUP = ''
# This is the placeholder icon for icons not found
PLACEHOLDER = '001-Weapon01'
end
class Game_System
attr_accessor :ring
alias gg_init_ring_event_lat initialize
def initialize
@ring = false
gg_init_ring_event_lat
end
end
class Game_Temp
attr_accessor :setup_ring
attr_accessor :parameters
attr_accessor :event_id
alias gg_init_ring_temp_lat initialize
def initialize
@setup_ring = false
@parameters = nil
gg_init_ring_temp_lat
end
end
class Window_Message < Window_Selectable
alias gg_upd_ring_event_lat update
def update
if $game_temp.setup_ring
$game_temp.setup_ring = false
event = $game_map.events[$game_temp.event_id]
px = calc_pos_x(event)
py = calc_pos_y(event)
@ring = Sprite_Ring.new($game_temp.parameters[0], px, py)
if Gameus::DISPLAY_TYPE == 1
@help = Window_RingHelp.new
end
end
if @ring != nil
@ring.update
if @help != nil
@help.set_text(@ring.commands[@ring.index], 1)
end
if Input.trigger?(Input::B)
if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
$game_system.se_play($data_system.cancel_se)
$game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
dispose_ring
terminate_message
end
return
elsif Input.trigger?(Input::C)
if $game_temp.choice_max > 0
$game_system.se_play($data_system.decision_se)
$game_temp.choice_proc.call(@ring.index)
end
dispose_ring
terminate_message
return
end
else
gg_upd_ring_event_lat
end
end
def dispose_ring
if @help != nil
@help.dispose
@help = nil
end
@ring.dispose
@ring = nil
end
def calc_pos_x(char)
if char.screen_x >= 640 - Gameus::RING_MENU_RADIUS
px = char.screen_x - 15 - Gameus::RING_MENU_RADIUS
elsif char.screen_x <= Gameus::RING_MENU_RADIUS
px = char.screen_x - 15 + Gameus::RING_MENU_RADIUS
else
px = char.screen_x - 15
end
return px
end
def calc_pos_y(char)
if char.screen_y >= 480 - Gameus::RING_MENU_RADIUS
py = char.screen_y - 24 - Gameus::RING_MENU_RADIUS
elsif char.screen_y <= Gameus::RING_MENU_RADIUS
py = char.screen_y - 24 + Gameus::RING_MENU_RADIUS
else
py = char.screen_y - 24
end
return py
end
end
class Interpreter
alias gg_setup_ring_choices_lat setup_choices
def setup_choices(parameters)
if !$game_system.ring
gg_setup_ring_choices_lat(parameters)
return
end
$game_temp.choice_max = parameters[0].size
$game_temp.setup_ring = true
$game_temp.parameters = parameters
$game_temp.event_id = @event_id
$game_temp.choice_cancel_type = parameters[1]
current_indent = @list[@index].indent
$game_temp.choice_proc = Proc.new { |n| @branch[current_indent] = n }
end
end
class Window_RingHelp < Window_Base
def initialize
super(Gameus::DISPLAY_POSITION[0], Gameus::DISPLAY_POSITION[1], 160, 64)
self.contents = Bitmap.new(width - 32, height - 32)
@text =''
self.back_opacity = 128
end
def set_text(text, align = 0)
if text != @text
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, self.width - 40, 32, text, align)
@text = text
end
end
end
class Sprite_Ring < Sprite
#--------------------------------------------------------------------------
# › ƒNƒ‰ƒX'è"
#--------------------------------------------------------------------------
STARTUP_FRAMES = 20
MOVING_FRAMES = 5
MODE_START = 1
MODE_WAIT = 2
MODE_MOVEL = 3
MODE_MOVER = 4
SIZE = Gameus::RING_MENU_RADIUS * 2
#--------------------------------------------------------------------------
# › ƒAƒNƒZƒT
#--------------------------------------------------------------------------
attr_accessor :index
attr_accessor :active
attr_reader :commands
#--------------------------------------------------------------------------
# The stuff in the section below can be accomodated for new menu entries
#--------------------------------------------------------------------------
def initialize( commands, center_x, center_y, r = Gameus::RING_MENU_RADIUS )
super(Viewport.new(0, 0, 640, 480))
self.viewport.z = 10000
self.bitmap = Bitmap.new(SIZE * 2, SIZE * 2)
@active = true
@data = commands
@commands = []
@items = []
@data.each { |i|
@commands.push(i)
begin
icon = RPG::Cache.icon(i + "_icon")
rescue
icon = RPG::Cache.icon(Gameus::PLACEHOLDER)
end
@items.push(icon)
}
# I changed this to prevent glitches when modifying the number of menu items
@item_max = @commands.size
@index = 0
@disabled = Array.new(@commands.size, false)
self.x = center_x - SIZE / 2
self.y = center_y - SIZE / 2
@center_x = center_x
@center_y = center_y
@cx = SIZE / 2
@cy = SIZE / 2
@radius = r
setup_move_start
refresh
end
def dispose
self.viewport.dispose
super
end
def item
return @data[@index]
end
#--------------------------------------------------------------------------
# œ ƒtƒŒ[ƒ€XV
#--------------------------------------------------------------------------
def update
super
refresh
return if animation? || !@active
if Input.repeat?(Input::UP) || Input.repeat?(Input::LEFT)
$game_system.se_play($data_system.cursor_se)
setup_move_move(MODE_MOVEL)
return
end
if Input.repeat?(Input::DOWN) || Input.repeat?(Input::RIGHT)
$game_system.se_play($data_system.cursor_se)
setup_move_move(MODE_MOVER)
return
end
end
#--------------------------------------------------------------------------
# œ ‰æ-ÊÄ•`‰æ
#--------------------------------------------------------------------------
def refresh
self.bitmap.clear
# ƒAƒCƒRƒ",ð•`‰æ
case @mode
when MODE_START
refresh_start
when MODE_WAIT
refresh_wait
when MODE_MOVER
refresh_move(1)
when MODE_MOVEL
refresh_move(0)
end
# ƒAƒNƒeƒBƒu,ȃRƒ}ƒ"ƒh-¼•\Ž¦
rect = Rect.new(-@cx + 16, @cy + 24, self.bitmap.width, 32)
if Gameus::DISPLAY_TYPE == 0
self.bitmap.draw_text(rect, @commands[@index],1)
end
end
#--------------------------------------------------------------------------
# › ‰æ-ÊÄ•`‰æ(‰Šú‰»Žž)
#--------------------------------------------------------------------------
def refresh_start
d1 = 2.0 * Math::PI / @item_max
d2 = 1.0 * Math::PI / STARTUP_FRAMES
r = @radius - 1.0 * @radius * @steps / STARTUP_FRAMES
for i in 0...@item_max
j = i - @index
d = d1 * j + d2 * @steps
x = @cx + ( r * Math.sin( d ) ).to_i
y = @cy - ( r * Math.cos( d ) ).to_i
draw_menu_item(x, y, i)
end
@steps -= 1
if @steps < 1
@mode = MODE_WAIT
end
end
#--------------------------------------------------------------------------
# › ‰æ-ÊÄ•`‰æ('Ò‹@Žž)
#--------------------------------------------------------------------------
def refresh_wait
d = 2.0 * Math::PI / @item_max
for i in 0...@item_max
j = i - @index
x = @cx + ( @radius * Math.sin( d * j ) ).to_i
y = @cy - ( @radius * Math.cos( d * j ) ).to_i
draw_menu_item(x, y, i)
end
end
#--------------------------------------------------------------------------
# › ‰æ-ÊÄ•`‰æ(‰ñ"]Žž)
# mode : 0="½ŽžŒv‰ñ,è 1=ŽžŒv‰ñ,è
#--------------------------------------------------------------------------
def refresh_move( mode )
d1 = 2.0 * Math::PI / @item_max
d2 = d1 / MOVING_FRAMES
d2 *= -1 if mode != 0
for i in 0...@item_max
j = i - @index
d = d1 * j + d2 * @steps
x = @cx + ( @radius * Math.sin( d ) ).to_i
y = @cy - ( @radius * Math.cos( d ) ).to_i
draw_menu_item(x, y, i)
end
@steps -= 1
if @steps < 1
@mode = MODE_WAIT
end
end
#--------------------------------------------------------------------------
# œ €-Ú,Ì•`‰æ
# x :
# y :
# i : €-Ú"Ô†
#--------------------------------------------------------------------------
def draw_menu_item(x, y, i)
#p "x=" + x.to_s + " y=" + y.to_s + " i=" + @items[i].to_s
rect = Rect.new(0, 0, @items[i].width, @items[i].height)
if @index == i
if @disabled[i]
self.bitmap.blt( x, y, Gameus::DISABLED_ICON, rect )
else
self.bitmap.blt( x, y, @items[i], rect )
end
else
if @disabled[i]
self.bitmap.blt( x, y, Gameus::DISABLED_ICON, rect, 128 )
else
self.bitmap.blt( x, y, @items[i], rect, 128 )
end
end
end
#--------------------------------------------------------------------------
# œ €-Ú,ð-³Œø,É,·,é
# index : €-Ú"Ô†
#--------------------------------------------------------------------------
def disable_item(index)
@disabled[index] = true
end
#--------------------------------------------------------------------------
# › ‰Šú‰»ƒAƒjƒ[ƒVƒ‡ƒ",Ì€"õ
#--------------------------------------------------------------------------
def setup_move_start
@mode = MODE_START
@steps = STARTUP_FRAMES
if Gameus::SE_STARTUP != ""
Audio.se_play("Audio/SE/" + Gameus::SE_STARTUP, 80, 100)
end
end
#--------------------------------------------------------------------------
# › ‰ñ"]ƒAƒjƒ[ƒVƒ‡ƒ",Ì€"õ
#--------------------------------------------------------------------------
def setup_move_move(mode)
if mode == MODE_MOVER
@index -= 1
@index = @items.size - 1 if @index < 0
elsif mode == MODE_MOVEL
@index += 1
@index = 0 if @index >= @items.size
else
return
end
@mode = mode
@steps = MOVING_FRAMES
end
#--------------------------------------------------------------------------
# › ƒAƒjƒ[ƒVƒ‡ƒ"'†,©,Ç,¤,©
#--------------------------------------------------------------------------
def animation?
return @mode != MODE_WAIT
end
end
class Interpreter
SCRIPT_WAIT_RESULTS = [:wait, FalseClass]
#-------------------------------------------------------------------
# * Script
#-------------------------------------------------------------------
def command_355
# Set first line to script
script = @list[@index].parameters[0] + "\n"
# Store index in case we need to wait.
current_index = @index
# Loop
loop do
# If next event command is second line of script or after
if @list[@index+1].code == 655
# Add second line or after to script
script += @list[@index+1].parameters[0] + "\n"
# If event command is not second line or after
else
# Abort loop
break
end
# Advance index
@index += 1
end
# Evaluation
result = eval(script)
# If return value is false
if SCRIPT_WAIT_RESULTS.include?(result)
# Set index back (If multi-line script call)
@index = current_index
# End and wait
return false
end
# Continue
return true
end
end