SHARE
TWEET

[VXA] Ring Menu Addon

AngryPacman Jun 19th, 2014 624 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===============================================================================
  2. #
  3. # Ring Menu Addon (for PAC Main Menu Ace)
  4. # 19/06/2014
  5. # By Pacman
  6. #
  7. #===============================================================================
  8. #
  9. # This script is an addon for PAC Main Menu Ace. This script will only work
  10. # reliably if you have PAC Main Menu Ace version 1.2 or higher above it in the
  11. # scripts menu. (To get PAC Main Menu Ace - http://pastebin.com/Z7JN31gT)
  12. # This script will turn the main menu in to a ring menu reminiscent of SNES-era
  13. # RPGs.
  14. # This script allows for two different radii of the ring - an x-radius and a
  15. # y-radius. This means it has the capacity to produce ellipses as well as
  16. # circles.
  17. # This script can also scale the selected and deselected icons independently;
  18. # i.e. making the selected option larger.
  19. #
  20. #===============================================================================
  21.  
  22. module PAC::MM::RING
  23.   MENU_RADIUS_X = 128   # X Radius
  24.   MENU_RADIUS_Y = 64    # Y Radius
  25.   MENU_SPEED = 8        # Changes movement speed of icons
  26.   MENU_TEXT = true      # Show menu text? (true or false)
  27.   MENU_TEXT_SIZE = 18   # Menu Text size. integer or nil for default size
  28.   MENU_ICON_PLACEMENT = :bottom # :top or :bottom
  29.   BACKGROUND_ALPHA = 192 # integer (0 - 255)
  30.   SCALE_GAIN = 8  # pixels gained in big icon scaling
  31.   SCALE_LOSS = 4  # pixels lost in small icon scaling
  32. end
  33.  
  34. #===============================================================================
  35. #
  36. # END CONFIG
  37. #
  38. #==============================================================================
  39. # ** Math
  40. #------------------------------------------------------------------------------
  41. #  A module that supports floating-point calculations.
  42. #==============================================================================
  43.  
  44. module Math
  45.   #--------------------------------------------------------------------------
  46.   # * Trigonometric functions in degrees
  47.   #--------------------------------------------------------------------------
  48.   ["sin","cos","tan"].each { |type| trig_eval_code = %Q(
  49.     def self.#{type}d(value)
  50.       return self.#{type}(value * PI / 180)
  51.     end)
  52.     eval (trig_eval_code)
  53.   }
  54. end
  55.  
  56. #==============================================================================
  57. # ** Window_MenuCommand
  58. #------------------------------------------------------------------------------
  59. #  This command window appears on the menu screen.
  60. #==============================================================================
  61.  
  62. class Window_MenuCommand < Window_Command
  63.   #--------------------------------------------------------------------------
  64.   # * Public Instance Variables
  65.   #--------------------------------------------------------------------------
  66.   attr_reader :index
  67.   attr_reader :angle
  68.   attr_accessor :gosh_dang_it
  69.   #--------------------------------------------------------------------------
  70.   # * Object Initialization
  71.   #--------------------------------------------------------------------------
  72.   def initialize
  73.     @gosh_dang_it = false
  74.     @angle = 0
  75.     super(0, 0)
  76.     @list.delete_if {|i| !i[:enabled]}
  77.     self.width = Graphics.width
  78.     self.height = Graphics.height
  79.     self.opacity = 0
  80.     self.visible = self.active
  81.     refresh
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # * Get Angle Size
  85.   #--------------------------------------------------------------------------
  86.   def angle_size
  87.     return 360 / item_max
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # * Draw Big Icon
  91.   #     enabled : Enabled flag. When false, draw semi-transparently.
  92.   #--------------------------------------------------------------------------
  93.   def draw_big_icon(icon_index, x, y, enabled = true)
  94.     bitmap = Cache.system("Iconset")
  95.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  96.     dest = rect.clone
  97.     dest.width = dest.height = (24 + PAC::MM::RING::SCALE_GAIN)
  98.     dest.x = x - PAC::MM::RING::SCALE_GAIN/2
  99.     dest.y = y - PAC::MM::RING::SCALE_GAIN/2
  100.     contents.stretch_blt(dest, bitmap, rect, enabled ? 255 : translucent_alpha)
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # * Draw Small Icon
  104.   #     enabled : Enabled flag. When false, draw semi-transparently.
  105.   #--------------------------------------------------------------------------
  106.   def draw_small_icon(icon_index, x, y, enabled = true)
  107.     bitmap = Cache.system("Iconset")
  108.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  109.     dest = rect.clone
  110.     dest.width = dest.height = (24 - PAC::MM::RING::SCALE_LOSS)
  111.     dest.x = x + PAC::MM::RING::SCALE_LOSS/2
  112.     dest.y = y + PAC::MM::RING::SCALE_LOSS/2
  113.     contents.stretch_blt(dest, bitmap, rect, translucent_alpha / 2)
  114.   end
  115.   #--------------------------------------------------------------------------
  116.   # * Draw Item
  117.   #--------------------------------------------------------------------------
  118.   def draw_item(method_index, enabled = true)
  119.     radius = PAC::MM::RING::MENU_RADIUS_X
  120.     yradius = PAC::MM::RING::MENU_RADIUS_Y
  121.     yradius *= -1 if PAC::MM::RING::MENU_ICON_PLACEMENT == :top
  122.     n = (method_index - self.index) * angle_size + @angle
  123.     cx = radius * Math.sind(n) + (Graphics.width / 2)
  124.     cy = yradius * Math.cosd(n) + (Graphics.height / 2)
  125.     if n == 0   # Selected index
  126.       self.contents.font.color.alpha = enabled ? 255 : 128
  127.       s = self.contents.font.size
  128.       self.contents.font.size = PAC::MM::RING::MENU_TEXT_SIZE || s
  129.       self.contents.draw_text(Graphics.width / 2 - 80, Graphics.height / 2 -
  130.        line_height, 160, line_height, PAC::MM::COMMANDS[method_index][0], 1) if
  131.        PAC::MM::RING::MENU_TEXT
  132.       self.contents.font.size = s
  133.       draw_big_icon(PAC::MM::COMMANDS[method_index][2], cx - 12, cy - 12,
  134.         (enabled))
  135.     else  # All other indexes
  136.       draw_small_icon(PAC::MM::COMMANDS[method_index][2], cx - 12, cy - 12,
  137.         (false))
  138.     end
  139.   end
  140.   def okay
  141.     return
  142.   end
  143.   #--------------------------------------------------------------------------
  144.   # * Update Spin Animation
  145.   #--------------------------------------------------------------------------
  146.   def update_spin(reverse = false)
  147.     speed = PAC::MM::RING::MENU_SPEED
  148.     @angle += (reverse ? -angle_size : angle_size) / speed.to_f
  149.     Graphics.update
  150.     refresh
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # * Frame Update
  154.   #     aliasing is for chumps
  155.   #--------------------------------------------------------------------------
  156.   def update
  157.     super
  158.     update_index
  159.   end
  160.   #--------------------------------------------------------------------------
  161.   # * Update input thingies
  162.   #--------------------------------------------------------------------------
  163.   def update_index
  164.     return if !active
  165.     if Input.trigger?(:LEFT) || Input.repeat?(:LEFT) || Input.trigger?(:UP) ||
  166.        Input.repeat?(:UP)
  167.       Sound.play_cursor
  168.       while @angle.round < angle_size
  169.         update_spin
  170.       end
  171.       @index -= 1
  172.       @index %= item_max
  173.       @angle = 0
  174.       refresh
  175.     elsif Input.trigger?(:RIGHT) || Input.repeat?(:RIGHT) ||
  176.        Input.trigger?(:DOWN) || Input.repeat?(:DOWN)
  177.       Sound.play_cursor
  178.       while @angle.round > -angle_size
  179.         update_spin(true)
  180.       end
  181.       @index += 1
  182.       @index %= item_max
  183.       @angle = 0
  184.       refresh
  185.     end
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # * Fix the cursor
  189.   #--------------------------------------------------------------------------
  190.   def cursor_down(*args)
  191.     cursor_right(*args)
  192.   end
  193.   def cursor_up(*args)
  194.     cursor_left(*args)
  195.   end
  196.   def update_cursor
  197.   end
  198. end
  199.  
  200. #==============================================================================
  201. # ** Window_MenuStatus
  202. #------------------------------------------------------------------------------
  203. #  This window displays party member status on the menu screen.
  204. #==============================================================================
  205.  
  206. class Window_MenuStatus < Window_Selectable
  207.   #--------------------------------------------------------------------------
  208.   # * Object Initialization
  209.   #--------------------------------------------------------------------------
  210.   alias pac_mm_rm_init initialize
  211.   def initialize(*args)
  212.     pac_mm_rm_init(*args)
  213.     self.x = (Graphics.width - self.width) / 2
  214.     self.y = (Graphics.height - self.height) / 2
  215.   end
  216. end
  217.  
  218. #==============================================================================
  219. # ** Scene_Menu
  220. #------------------------------------------------------------------------------
  221. #  This class performs the menu screen processing.
  222. #==============================================================================
  223.  
  224. class Scene_Menu < Scene_MenuBase
  225.   #--------------------------------------------------------------------------
  226.   # Aliasing things
  227.   #--------------------------------------------------------------------------
  228.   alias pac_mm_rm_strt start
  229.   alias pac_mm_rm_cmdpnl command_personal
  230.   alias pac_mm_rm_cmdfrm command_formation
  231.   alias pac_mm_rm_onfc on_formation_cancel
  232.   #--------------------------------------------------------------------------
  233.   # * Start Processing
  234.   #--------------------------------------------------------------------------
  235.   def start(*args)
  236.     pac_mm_rm_strt(*args)
  237.     @command_window.hide if @@start_personal
  238.     @command_window.index = (@@last_index ||= 0)
  239.     @command_window.refresh
  240.     @status_window.hide unless @@start_personal
  241.     @status_window.close unless @@start_personal
  242.   end
  243.   #--------------------------------------------------------------------------
  244.   # * Create Background
  245.   #--------------------------------------------------------------------------
  246.   def create_background
  247.     @background_sprite = Sprite.new
  248.     @background_sprite.bitmap = SceneManager.background_bitmap
  249.     @background_sprite.color.set(16, 16, 16, PAC::MM::RING::BACKGROUND_ALPHA)
  250.   end
  251.   #--------------------------------------------------------------------------
  252.   # * [Skill], [Equipment] and [Status] Commands
  253.   #--------------------------------------------------------------------------
  254.   def command_personal(*args)
  255.     @command_window.close
  256.     @status_window.show
  257.     @status_window.open
  258.     pac_mm_rm_cmdpnl(*args)
  259.   end
  260.   #--------------------------------------------------------------------------
  261.   # * [Formation] Command
  262.   #--------------------------------------------------------------------------
  263.   def command_formation(*args)
  264.     @command_window.close
  265.     @status_window.show
  266.     @status_window.open
  267.     pac_mm_rm_cmdfrm(*args)
  268.   end
  269.   #--------------------------------------------------------------------------
  270.   # * [Cancel] Personal Command
  271.   #--------------------------------------------------------------------------
  272.   def on_personal_cancel(*args)
  273.     pac_mm_opc(*args)
  274.     @status_window.close
  275.     @command_window.show
  276.     @command_window.open
  277.     @@start_personal = false
  278.   end
  279.   #--------------------------------------------------------------------------
  280.   # * Formation [Cancel]
  281.   #--------------------------------------------------------------------------
  282.   def on_formation_cancel(*args)
  283.     pac_mm_rm_onfc(*args)
  284.     @status_window.close
  285.     @command_window.show
  286.     @command_window.open
  287.     @@start_personal = false
  288.   end
  289.   #--------------------------------------------------------------------------
  290.   # * Termination Processing
  291.   #--------------------------------------------------------------------------
  292.   def terminate(*args)
  293.     @@last_index = @command_window.index
  294.     super
  295.   end
  296. end
  297.  
  298. ($pac ||= {})[:ring] = 1
  299. unless $pac[:main_menu] >= 1.2
  300.   msgbox "You require PAC Main Menu Ace for the Ring Menu script to work."
  301.   msgbox "Find the script at http://pastebin.com/Z7JN31gT"; exit
  302. end
  303.  
  304.  
  305. #===============================================================================
  306. #
  307. # END OF SCRIPT
  308. #
  309. #===============================================================================
RAW Paste Data
Top