SHARE
TWEET

Untitled

a guest Sep 22nd, 2012 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ** Ring Menu
  3. #------------------------------------------------------------------------------
  4. #  by Syvkal
  5. #  Version 1.2
  6. #  03-04-12
  7. #------------------------------------------------------------------------------
  8. # * Original available at:
  9. #  www.rpgmakervxace.net  &  forums.rpgmakerweb.com
  10. #  Please do not redistribute this script
  11. #------------------------------------------------------------------------------
  12. # * Terms of Use
  13. #  Available for use in commercial games provided that I get a free copy :P
  14. #  Email me: syvkal@hotmail.co.uk
  15. #  Please do not redistribute this script
  16. #==============================================================================
  17. #
  18. #  - INTRODUCTION -
  19. #
  20. #  This system implements a Plug 'N' Play Ring Menu
  21. #  Movement based off XRXS, Dubealex & Hypershadow180's original XP Ring Menu,
  22. #  which was devised through some simple, but clever trigonometry
  23. #
  24. #------------------------------------------------------------------------------
  25. #
  26. #  - USAGE -
  27. #
  28. #  Any additional scenes that are added to the menu require an icon
  29. #  Place them in the pictures folder, they are advised to be 48x48 pixels
  30. #
  31. #  The name of the icons must be of the form:
  32. #    [Command Name] Icon
  33. #
  34. #  For example 'Items Icon.png' or 'Equipment Icon.png'
  35. #
  36. #  If you are unsure what it needs to be called, wait for the error message,
  37. #  then call it the name of the file it can not find
  38. #
  39. #------------------------------------------------------------------------------
  40. #
  41. #  - COMPATIBILITY -
  42. #
  43. #  Additional scenes should be automatically added assuming thier creators
  44. #  utilise the 'add_original_commands' feature in Window_MenuCommand
  45. #
  46. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  47. #
  48. #  This script redefines the following methods:
  49. #  * create_status_window             (Scene_Menu)
  50. #  * on_formation_ok                  (Scene_Menu)
  51. #  * on_formation_cancel              (Scene_Menu)
  52. #  * draw_character                   (Window_Base)
  53. #
  54. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  55. #
  56. #  This script Aliases the following methods:
  57. #  * add_save_command                 (Window_MenuCommand)
  58. #  * start                            (Scene_Menu)
  59. #  * create_command_window            (Scene_Menu)
  60. #  * command_personal                 (Scene_Menu)
  61. #  * command_formation                (Scene_Menu)
  62. #  * on_personal_cancel               (Scene_Menu)
  63. #
  64. #==============================================================================
  65.  
  66.             #===================================================#
  67.             #  **  C O N F I G U R A T I O N   S Y S T E M  **  #
  68.             #===================================================#
  69.  
  70.   #--------------------------------------------------------------------------
  71.   # * Startup Frames
  72.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  73.   #  Amount of frames for the Startup Animation
  74.   #--------------------------------------------------------------------------
  75.     STARTUP_FRAMES = 20
  76.   #--------------------------------------------------------------------------
  77.   # * Movement Frames
  78.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  79.   #  Amount of frames for Movement Animation
  80.   #--------------------------------------------------------------------------
  81.     MOVING_FRAMES = 15
  82.   #--------------------------------------------------------------------------
  83.   # * Menu Ring Radius
  84.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  85.   #  Radius of the Menu Ring
  86.   #--------------------------------------------------------------------------
  87.     RING_R = 75
  88.   #--------------------------------------------------------------------------
  89.   # * Show Disabled Options
  90.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  91.   #  Set to false to exclude disabled options for the menu
  92.   #--------------------------------------------------------------------------
  93.     DISABLED_SHOW = false
  94.   #--------------------------------------------------------------------------
  95.   # * Disabled Icon
  96.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  97.   #  The icon displayed over disabled options
  98.   #  (only used when DISABLED_SHOW =  true)
  99.   #--------------------------------------------------------------------------
  100.     ICON_DISABLE = Cache::picture('Disable Icon')
  101.   #--------------------------------------------------------------------------
  102.   # * Skip Single Actor Select
  103.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  104.   #  Set to true to skip the actor selection if there's only one party member
  105.   #--------------------------------------------------------------------------
  106.     ACTOR_SKIP = true
  107.   #--------------------------------------------------------------------------
  108.   # * Load Command Vocab
  109.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  110.   #  Text displayed for the loading option
  111.   #--------------------------------------------------------------------------
  112.     Vocab::Load = "Load"
  113.      
  114.             #===================================================#
  115.             #  **     E N D   C O N F I G U R A T I O N     **  #
  116.             #===================================================#
  117.  
  118. #==============================================================================
  119. # ** Ring_Menu Module
  120. #------------------------------------------------------------------------------
  121. #  Module designed to rewrite methods defined in the desired Superclass.
  122. #==============================================================================
  123.  
  124. module Ring_Menu
  125.   #--------------------------------------------------------------------------
  126.   # * Object Initialization
  127.   #--------------------------------------------------------------------------
  128.   def initialize(*args)
  129.     super(*args)
  130.     @cx = contents.width / 2; @cy = contents.height / 2
  131.     self.opacity = 0
  132.     @startup = STARTUP_FRAMES
  133.     @icons = []
  134.     @mode = :start
  135.     @steps = @startup
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # * Update Cursor
  139.   #--------------------------------------------------------------------------
  140.   def update_cursor
  141.   end
  142.   #--------------------------------------------------------------------------
  143.   # * Determines if is moving
  144.   #--------------------------------------------------------------------------
  145.   def animation?
  146.     return @mode != :wait
  147.   end
  148.   #--------------------------------------------------------------------------
  149.   # * Move Cursor Down
  150.   #--------------------------------------------------------------------------
  151.   def cursor_down(wrap)
  152.     cursor_right(wrap)
  153.   end
  154.   #--------------------------------------------------------------------------
  155.   # * Move Cursor Up
  156.   #--------------------------------------------------------------------------
  157.   def cursor_up(wrap)
  158.     cursor_left(wrap)
  159.   end
  160.   #--------------------------------------------------------------------------
  161.   # * Move Cursor Right
  162.   #--------------------------------------------------------------------------
  163.   def cursor_right(wrap)
  164.     unless animation?
  165.       select((index + 1) % item_max)
  166.       @mode = :mover
  167.       @steps = MOVING_FRAMES
  168.       Sound.play_cursor
  169.     end
  170.   end
  171.   #--------------------------------------------------------------------------
  172.   # * Move Cursor Left
  173.   #--------------------------------------------------------------------------
  174.   def cursor_left(wrap)
  175.     unless animation?
  176.       select((index - 1 + item_max) % item_max)
  177.       @mode = :movel
  178.       @steps = MOVING_FRAMES
  179.       Sound.play_cursor
  180.     end
  181.   end
  182.   #--------------------------------------------------------------------------
  183.   # * Frame Update
  184.   #--------------------------------------------------------------------------
  185.   def update
  186.     super
  187.     refresh if animation?
  188.   end
  189.   #--------------------------------------------------------------------------
  190.   # * Refresh
  191.   #--------------------------------------------------------------------------
  192.   def refresh    
  193.     self.contents.clear
  194.     case @mode
  195.     when :start
  196.       refresh_start
  197.     when :wait
  198.       refresh_wait
  199.     when :mover
  200.       refresh_move(1)
  201.     when :movel
  202.       refresh_move(0)
  203.     end
  204.   end
  205.   #--------------------------------------------------------------------------
  206.   # * Refresh Start Period
  207.   #--------------------------------------------------------------------------
  208.   def refresh_start
  209.     d1 = 2.0 * Math::PI / item_max
  210.     d2 = 1.0 * Math::PI / @startup
  211.     r = RING_R - 1.0 * RING_R * @steps / @startup
  212.     for i in 0...item_max
  213.       d = d1 * i + d2 * @steps
  214.       x = @cx + ( r * Math.sin( d ) ).to_i
  215.       y = @cy - ( r * Math.cos( d ) ).to_i
  216.       draw_item(x, y, i)
  217.     end
  218.     @steps -= 1
  219.     if @steps < 0
  220.       @mode = :wait
  221.     end
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # * Refresh Wait Period
  225.   #--------------------------------------------------------------------------
  226.   def refresh_wait
  227.     d = 2.0 * Math::PI / item_max
  228.     for i in 0...item_max
  229.       j = i - index
  230.       x = @cx + ( RING_R * Math.sin( d * j) ).to_i
  231.       y = @cy - ( RING_R * Math.cos( d * j) ).to_i
  232.       draw_item(x, y, i)
  233.     end
  234.   end
  235.   #--------------------------------------------------------------------------
  236.   # * Refresh Movement Period
  237.   #--------------------------------------------------------------------------
  238.   def refresh_move( mode )
  239.     d1 = 2.0 * Math::PI / item_max
  240.     d2 = d1 / MOVING_FRAMES
  241.     d2 *= -1 unless mode != 0
  242.     for i in 0...item_max
  243.       j = i - index
  244.       d = d1 * j + d2 * @steps
  245.       x = @cx + ( RING_R * Math.sin( d ) ).to_i
  246.       y = @cy - ( RING_R * Math.cos( d ) ).to_i
  247.       draw_item(x, y, i)
  248.     end
  249.     @steps -= 1
  250.     if @steps < 0
  251.       @mode = :wait
  252.     end
  253.   end
  254. end
  255.  
  256. #==============================================================================
  257. # ** Window_MenuCommand
  258. #------------------------------------------------------------------------------
  259. #  Converted into a Ring Menu.
  260. #==============================================================================
  261.  
  262. class Window_MenuCommand < Window_Command
  263.   #--------------------------------------------------------------------------
  264.   # * Includes The Ring_Menu Module
  265.   #--------------------------------------------------------------------------  
  266.   include Ring_Menu
  267.   #--------------------------------------------------------------------------
  268.   # * Alias Listings
  269.   #--------------------------------------------------------------------------  
  270.   alias add_save_command_ring_menu_original add_save_command
  271.   #--------------------------------------------------------------------------
  272.   # * Object Initialization
  273.   #--------------------------------------------------------------------------
  274.   def initialize
  275.     super(0, 0)
  276.     unless DISABLED_SHOW
  277.       @list.delete_if {|i| !i[:enabled]}
  278.     end
  279.     for i in 0...item_max
  280.       @icons.push(Cache::picture(command_name(i) + ' Icon'))
  281.     end
  282.     if @@last_command_symbol != nil
  283.       index = @list.index(@@last_command_symbol)
  284.       @mode = :wait
  285.     end
  286.     select_last
  287.     refresh
  288.   end
  289.   #--------------------------------------------------------------------------
  290.   # * Refresh
  291.   #--------------------------------------------------------------------------
  292.   def refresh
  293.     super
  294.     rect = Rect.new(0, 196, self.contents.width, line_height)
  295.     draw_text(rect, command_name(index), 1)
  296.   end
  297.   #--------------------------------------------------------------------------
  298.   # * Get Window Width
  299.   #--------------------------------------------------------------------------
  300.   def window_width
  301.     return 544
  302.   end
  303.   #--------------------------------------------------------------------------
  304.   # * Get Window Height
  305.   #--------------------------------------------------------------------------
  306.   def window_height
  307.     return 416
  308.   end  
  309.   #--------------------------------------------------------------------------
  310.   # * Add Load to Command List
  311.   #--------------------------------------------------------------------------
  312.   def add_save_command
  313.     add_save_command_ring_menu_original
  314.     add_command(Vocab::Load, :load)
  315.   end
  316.   #--------------------------------------------------------------------------
  317.   # * Draw Item
  318.   #     x     : draw spot x-coordinate
  319.   #     y     : draw spot y-coordinate
  320.   #     i     : item number
  321.   #--------------------------------------------------------------------------
  322.   def draw_item(x, y, i)
  323.     rect = Rect.new(0, 0, @icons[i].width, @icons[i].height)
  324.     if i == index
  325.       self.contents.blt(x - rect.width/2, y - rect.height/2, @icons[i], rect )
  326.       unless command_enabled?(index)
  327.         self.contents.blt(x - rect.width/2, y - rect.height/2, ICON_DISABLE, rect )
  328.       end
  329.     else
  330.       self.contents.blt(x - rect.width/2, y - rect.height/2, @icons[i], rect, 128 )
  331.     end
  332.   end
  333. end
  334.  
  335. #==============================================================================
  336. # ** Window_RingStatus
  337. #------------------------------------------------------------------------------
  338. #  Ring Menu for selection of Party Members
  339. #==============================================================================
  340.  
  341. class Window_RingStatus < Window_Selectable
  342.   #--------------------------------------------------------------------------
  343.   # * Includes The Ring_Menu Module
  344.   #--------------------------------------------------------------------------  
  345.   include Ring_Menu
  346.   #--------------------------------------------------------------------------
  347.   # * Public Instance Variables
  348.   #--------------------------------------------------------------------------
  349.   attr_accessor   :pending_index            # Pending position (for formation)
  350.   attr_accessor   :pending                  # Pending
  351.   #--------------------------------------------------------------------------
  352.   # * Object Initialization
  353.   #--------------------------------------------------------------------------
  354.   def initialize
  355.     super(0, 0, 544, 416)
  356.     self.hide
  357.     @mode = :wait
  358.     @pending_index = -1
  359.     @pending = false
  360.     refresh
  361.   end
  362.   #--------------------------------------------------------------------------
  363.   # * Refresh
  364.   #--------------------------------------------------------------------------
  365.   def refresh    
  366.     super
  367.     rect = Rect.new(0, 196, self.contents.width, line_height)
  368.     draw_text(rect, $game_party.members[index].name, 1)
  369.   end
  370.   #--------------------------------------------------------------------------
  371.   # * Get Number of Items
  372.   #--------------------------------------------------------------------------
  373.   def item_max
  374.     $game_party.members.size
  375.   end
  376.   #--------------------------------------------------------------------------
  377.   # * Refresh Movement Period
  378.   #--------------------------------------------------------------------------
  379.   def refresh_move( mode )
  380.     unless pending_index >= 0
  381.       super
  382.     else
  383.       d = 2.0 * Math::PI / item_max
  384.       for i in 0...item_max
  385.         j = i - pending_index
  386.         x = @cx + ( RING_R * Math.sin( d * j) ).to_i
  387.         y = @cy - ( RING_R * Math.cos( d * j) ).to_i
  388.         draw_item(x, y, i)
  389.       end
  390.       @mode = :wait
  391.     end
  392.   end
  393.   #--------------------------------------------------------------------------
  394.   # * Draw Item
  395.   #     x     : draw spot x-coordinate
  396.   #     y     : draw spot y-coordinate
  397.   #     index : item number
  398.   #--------------------------------------------------------------------------
  399.   def draw_item(x, y, i)
  400.     if i == index && !(@pending && @pending_index < 0)
  401.       draw_character($game_party.members[i].character_name,
  402.       $game_party.members[i].character_index , x, y, true, true)
  403.     else
  404.       draw_character($game_party.members[i].character_name,
  405.       $game_party.members[i].character_index , x, y, false, true)
  406.     end
  407.   end
  408.   #--------------------------------------------------------------------------
  409.   # * Processing When OK Button Is Pressed
  410.   #--------------------------------------------------------------------------
  411.   def process_ok
  412.     super
  413.     $game_party.menu_actor = $game_party.members[index] unless pending
  414.   end
  415.   #--------------------------------------------------------------------------
  416.   # * Restore Previous Selection Position
  417.   #--------------------------------------------------------------------------
  418.   def select_last
  419.     select($game_party.members.index($game_party.menu_actor) || 0)
  420.     refresh
  421.   end
  422. end
  423.  
  424. #==============================================================================
  425. # ** Scene_Menu
  426. #==============================================================================
  427.  
  428. class Scene_Menu < Scene_MenuBase
  429.   #--------------------------------------------------------------------------
  430.   # * Alias Listings
  431.   #--------------------------------------------------------------------------  
  432.   alias start_ring_original start
  433.   alias create_command_window_ring_menu_original create_command_window
  434.   alias command_personal_ring_original command_personal
  435.   alias command_formation_ring_original command_formation
  436.   alias on_personal_cancel_ring_original on_personal_cancel
  437.   #--------------------------------------------------------------------------
  438.   # * Start Processing
  439.   #--------------------------------------------------------------------------
  440.   def start
  441.     start_ring_original
  442.     create_location_window
  443.   end
  444.   #--------------------------------------------------------------------------
  445.   # * Create Location Window
  446.   #--------------------------------------------------------------------------
  447.   def create_location_window
  448.     @location_window = Window_location.new(0, 0)
  449.   end
  450.   #--------------------------------------------------------------------------
  451.   # * Create Command Window
  452.   #--------------------------------------------------------------------------
  453.   def create_command_window
  454.     create_command_window_ring_menu_original
  455.     @command_window.set_handler(:load,      method(:command_load))
  456.   end
  457.   #--------------------------------------------------------------------------
  458.   # * Create Status Window
  459.   #--------------------------------------------------------------------------
  460.   def create_status_window
  461.     @status_window = Window_RingStatus.new
  462.   end
  463.   #--------------------------------------------------------------------------
  464.   # * [Skill], [Equipment] and [Status] Commands
  465.   #--------------------------------------------------------------------------
  466.   def command_personal
  467.     if $game_party.members.size < 2 && ACTOR_SKIP
  468.       on_personal_ok
  469.     else
  470.       @command_window.hide
  471.       @status_window.show
  472.       command_personal_ring_original
  473.     end
  474.   end
  475.   #--------------------------------------------------------------------------
  476.   # * [Formation] Command
  477.   #--------------------------------------------------------------------------
  478.   def command_formation
  479.     @status_window.pending = true
  480.     @command_window.hide
  481.     command_formation_ring_original
  482.     @status_window.index = 0
  483.     @status_window.refresh
  484.     @status_window.show
  485.   end
  486.   #--------------------------------------------------------------------------
  487.   # * [Load] Command
  488.   #--------------------------------------------------------------------------
  489.   def command_load
  490.     SceneManager.call(Scene_Load)
  491.   end
  492.   #--------------------------------------------------------------------------
  493.   # * [Cancel] Personal Command
  494.   #--------------------------------------------------------------------------
  495.   def on_personal_cancel
  496.     @status_window.hide
  497.     on_personal_cancel_ring_original
  498.     @status_window.deactivate
  499.     @command_window.show
  500.   end
  501.   #--------------------------------------------------------------------------
  502.   # * Formation [OK]
  503.   #--------------------------------------------------------------------------
  504.   def on_formation_ok
  505.     if @status_window.pending_index >= 0
  506.       $game_party.swap_order(@status_window.index,
  507.                              @status_window.pending_index)
  508.       @status_window.index = @status_window.pending_index
  509.       @status_window.pending_index = -1
  510.     else
  511.       @status_window.pending_index = @status_window.index
  512.     end
  513.     @status_window.refresh
  514.     @status_window.activate
  515.   end
  516.   #--------------------------------------------------------------------------
  517.   # * Formation [Cancel]
  518.   #--------------------------------------------------------------------------
  519.   def on_formation_cancel
  520.     if @status_window.pending_index >= 0
  521.       @status_window.index = @status_window.pending_index
  522.       @status_window.pending_index = -1
  523.       @status_window.activate
  524.       @status_window.refresh
  525.     else
  526.       @status_window.pending = false
  527.       @status_window.hide
  528.       @status_window.select_last
  529.       @status_window.deactivate
  530.       @command_window.show
  531.       @command_window.activate
  532.     end
  533.   end
  534. end
  535.  
  536. #==============================================================================
  537. # ** Window_Base
  538. #------------------------------------------------------------------------------
  539. #  Edited to allow disabled character icons and y centring
  540. #==============================================================================
  541.  
  542. class Window_Base < Window
  543.   #--------------------------------------------------------------------------
  544.   # * Draw Character Graphic
  545.   #--------------------------------------------------------------------------
  546.   def draw_character(character_name, character_index, x, y, enabled = true, centred = false)
  547.     return if character_name == nil
  548.     bitmap = Cache.character(character_name)
  549.     sign = character_name[/^[\!\$]./]
  550.     if sign && sign.include?('$')
  551.       cw = bitmap.width / 3
  552.       ch = bitmap.height / 4
  553.     else
  554.       cw = bitmap.width / 12
  555.       ch = bitmap.height / 8
  556.     end
  557.     n = character_index
  558.     src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  559.     self.contents.blt(x - cw / 2, centred ? y - ch/2 : y - ch, bitmap, src_rect,
  560.     enabled ? 255 : 128)
  561.   end
  562. end
  563.  
  564. #==============================================================================
  565. # ** Window_Location
  566. #------------------------------------------------------------------------------
  567. #  This class shows the current map name.
  568. #==============================================================================
  569.  
  570. class Window_location < Window_Base
  571.   #--------------------------------------------------------------------------
  572.   # * Object Initialization
  573.   #--------------------------------------------------------------------------
  574.   def initialize(x, y)
  575.     super(x, y, 160, (line_height*2) + 32)
  576.     refresh
  577.   end
  578.   #--------------------------------------------------------------------------
  579.   # * Refresh
  580.   #--------------------------------------------------------------------------
  581.   def refresh
  582.     contents.clear
  583.     @map = load_data(sprintf("Data/Map%03d.rvdata2", $game_map.map_id))
  584.     change_color(system_color)
  585.     draw_text(4, 0, 128, line_height, "Location :")
  586.     change_color(normal_color)
  587.     draw_text(0, line_height, 128, line_height, @map.display_name, 1)
  588.   end
  589. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top