Advertisement
TheSixth

Image Grid Menu by Sixth

Mar 3rd, 2016
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 93.19 KB | None | 0 0
  1. #===============================================================================
  2. # * [ACE] Image Grid Menu
  3. #===============================================================================
  4. # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
  5. # * Version: 1.4
  6. # * Updated: 27/05/2016
  7. # * Requires: -------
  8. #-------------------------------------------------------------------------------
  9. # * < Change Log >
  10. #-------------------------------------------------------------------------------
  11. # * Version 1.0 (04/03/2016)
  12. #   - Initial release.
  13. # * Version 1.1 (04/03/2016)
  14. #   - The cursor sound will not play anymore if the cursor can't move in the
  15. #     pressed direction.
  16. #   - Added a new option which enables you to show a special "command" when the
  17. #     regular command list is empty. This can only happen if all of the commands
  18. #     are hidden when the grid menu is opened.
  19. #   - The above new feature fixes the crashing issues when the list is empty.
  20. #   - Added a new feature which lets you skip columns and rows forcibly after a
  21. #     command. Can be useful in some menu types.
  22. # * Version 1.2 (14/03/2016)
  23. #   - Added an optional feature which lets you set up texts for the help images.
  24. # * Version 1.3 (19/03/2016)
  25. #   - Added some new options for setting up the position of the grid and images.
  26. #     This will allow you to make dynamic position settings based on the current
  27. #     resolution of your game. These settings should work with all resolution
  28. #     changing scripts.
  29. # * Version 1.4 (27/05/2016)
  30. #   - Fixed a crash issue with the dynamic position settings (from v1.3).
  31. #   - Fixed a specific crash issue which happens with grid "windows" disposed
  32. #     before the termination of the scene (when the 'update' method is running).
  33. #   - Fixed numerous visual errors regarding the image animations.
  34. #   - The grid commands can now scroll in any directions on their own viewport.
  35. #     This makes it possible to show infinite amount of commands without them
  36. #     getting out of screen. Arrow pointers will indicate if the commands can
  37. #     be scrolled in a specific direction or not.
  38. #   - You can now use horizontal and vertical image sheets as well for your
  39. #     animated images. This setting is not a global setting, so you can mix
  40. #     horizontal and vertical image sheets if you want.
  41. #   - Added a new setting which lets you set specific/additional horizontal and
  42. #     vertical spacing for each of your commands. Now you can make not so
  43. #     grid-like command lists too if you want.
  44. #-------------------------------------------------------------------------------
  45. # * < Description >
  46. #-------------------------------------------------------------------------------
  47. # * This script will let you make a new scene which can be whatever you want it
  48. #   to be. For example, it can be a menu for:
  49. #   - Displaying help information / game manual.
  50. #   - Displaying achievements in your game.
  51. #   - Stage selection.
  52. #   - Quick travel menu.
  53. #   And there can be many other uses as well...
  54. #   Some examples above require scripting knowledge!
  55. # * The menu is fully image based!
  56. # * The menu can be fully animated with many effects available!
  57. # * You can make unlimited amount of these new grid menus!
  58. #   Want one for game manual, one for quick travel menu and another one for
  59. #   achievements? No problem, you can do it! That is, if you don't mind to
  60. #   setup all of them. :P
  61. # * People with some scripting knowledge can trigger any method/code for any
  62. #   command button! This makes the grid menu a pretty versatile one.
  63. # * Advanced scripters can re-use the new classes from this script to make their
  64. #   own menu with one or even more grid selection command "windows".
  65. #-------------------------------------------------------------------------------
  66. # * < Script Calls >
  67. #-------------------------------------------------------------------------------
  68. # * To open the new image grid menu, use this script call:
  69. #
  70. #     open_grid_menu(module_name)
  71. #
  72. #   The argument 'module_name' is an optional one.
  73. #   If you don't plan to make more image grid menus you can ignore it.
  74. #
  75. #   If you want, however, you can copy the module settings in the script (the
  76. #   entire settings area enclosed with the module name and the 'end' line) and
  77. #   paste it into it's own slot in the script editor (or below the default
  78. #   settings, but that would kill your scroll button on your mouse, right? :P).
  79. #   After this, just rename the name of the module to whatever you want (just
  80. #   make sure that no other script uses that name for any class/module), and
  81. #   set up the settings for it however you want.
  82. #   With this done, now you can open the new menu you just set up by using it's
  83. #   module name as an argument in the above mentioned script call.
  84. #
  85. #   Examples:
  86. #  
  87. #     open_grid_menu
  88. #   Opens the default grid menu (which uses the 'SGridMenu' module name).
  89. #
  90. #     open_grid_menu(SGridMenu_2)
  91. #   Opens a grid menu using the settings in the 'SGridMenu_2' module.
  92. #-------------------------------------------------------------------------------
  93. # * < Image Setup >
  94. #-------------------------------------------------------------------------------
  95. # * The command images can be animated by using a sprite-sheet.
  96. #   This sprite-sheet must follow some rules or else the animation will look
  97. #   weird or flat out bad.
  98. #   These rules are:
  99. #   - The animation frames must be lined up vertically or horizontally
  100. #     on the sprite-sheet.
  101. #   - These frames are indexed, and these indexes are used in the animation
  102. #     settings in the script.
  103. #     The first image frame's index is 0 (top one for horizontal sheets and
  104. #     left-most one for vertical sheets), the second is 1, and so on!
  105. #   - All frames on the sprite-sheet must use the same dimensions!
  106. #     If the 1st frame is 32x32 (width x height), all the others must use the
  107. #     same dimensions!
  108. #   - A sprite-sheet can have unlimited number of frames!
  109. # * A little visual representation showing the index numbers of the image
  110. #   frames on a sprite-sheet:
  111. #   - Correct sprite-sheet:             - Incorrect sprite-sheet:
  112. #     * Same frame dimensions!            * Different frame dimensions!
  113. #     -----   -----------------           -----   -------------------
  114. #     | 0 |   | 0 | 1 | 2 | 3 |           | 0 |   | 0 | 1 |  2  | 3 |
  115. #     -----   -----------------           -----   -------------------
  116. #     | 1 |      Horizontal               | 1 |        Horizontal
  117. #     -----        Sheet                  |   |          Sheet
  118. #     | 2 |                               -----
  119. #     -----  Vertical                     | 2 |  Vertical
  120. #     | 3 |    Sheet                      |   |    Sheet
  121. #     -----                               -----
  122. # * It is not mandatory to animate your command buttons. You can make simple
  123. #   images, set up the settings to disable the animation for them, and your
  124. #   commands will not be animated.
  125. # * Almost all images (with the exception of regular background images) are
  126. #   centered! This means, when you set their X and Y position, that position
  127. #   will be the center of the image on the screen and NOT their top left corner!
  128. #-------------------------------------------------------------------------------
  129. # * < Installation >
  130. #-------------------------------------------------------------------------------
  131. # * Place this script between Materials and Main!
  132. #-------------------------------------------------------------------------------
  133. # * < Compatibility Info >
  134. #-------------------------------------------------------------------------------
  135. # * No known incompatibilities.
  136. # * This script does NOT use ANY default Window class/sub-class components!
  137. #   For that reason, mouse scripts which only check for the default selectable
  138. #   windows (mostly all of them) will NOT work on any SpriteGrid class without
  139. #   a patch!
  140. #-------------------------------------------------------------------------------
  141. # * < Known Issues >
  142. #-------------------------------------------------------------------------------
  143. # * No known issues.
  144. #-------------------------------------------------------------------------------
  145. # * < Terms of Use >
  146. #-------------------------------------------------------------------------------
  147. # * Free to use for whatever purposes you want.
  148. # * Credit me (Sixth) in your game, pretty please! :P
  149. # * Posting modified versions of this script is allowed as long as you notice me
  150. #   about it with a link to it!
  151. #===============================================================================
  152. $imported = {} if $imported.nil?
  153. $imported["SixthImgGridMenu"] = true
  154. #===============================================================================
  155. # Settings:
  156. #===============================================================================
  157. module SGridMenu
  158.   #-----------------------------------------------------------------------------
  159.   # Image Folder Settings:
  160.   #-----------------------------------------------------------------------------
  161.   # Set up the folders which contains the images used for the grid menu.
  162.   # All of the images used must be in these folders!
  163.   #
  164.   # :cmds = Folder containing the command images for the grid menu.
  165.   #         In addition, the background for the grid "window" goes here too,
  166.   #         as well as the scroll indicator images (arrows usually).
  167.   # :help = Folder containing the help images for the grid menu.
  168.   # :back = Folder containing the backgrounds for the grid menu.
  169.   #-----------------------------------------------------------------------------
  170.   ImgFolders = {
  171.     :cmds => "Graphics/GridMenu/Commands/",
  172.     :help => "Graphics/GridMenu/Helps/",
  173.     :back => "Graphics/GridMenu/Backgrounds/",
  174.   }
  175.      
  176.   #-----------------------------------------------------------------------------
  177.   # Background Settings:
  178.   #-----------------------------------------------------------------------------
  179.   # This is the place to setup your background images for the grid menu.
  180.   #
  181.   # You can either make scrolling images, static images, or combine them both!
  182.   # If you have set a :scroll setting for the background, it will be a scrolling
  183.   # background, if you omit that setting, it will be a static one!
  184.   # You can make as many backgrounds as you want!
  185.   #
  186.   # Format:
  187.   #
  188.   #   key => {
  189.   #     :img => "file name",
  190.   #     :pos => [x,y], # Only for static backgrounds!
  191.   #     :opa => value,
  192.   #     :z => value,
  193.   #     :scroll => [x_scroll,y_scroll], # Only for scrolling backgrounds!
  194.   #   },
  195.   #
  196.   #   key => {
  197.   # This is the key for the background. You can set this to anything you want,
  198.   # strings, numbers, symbols, arrays of data, and so on. The only thing you
  199.   # need to take care is that there can be no duplicate keys in the settings!
  200.   #
  201.   #   :img => "file name",
  202.   # The image used for the background.
  203.   # All images must be in the folder you have set up in the above setting!
  204.   #
  205.   #   :pos => [x,y],
  206.   # The X and Y position of the background.
  207.   # This only needs to be set for static backgrounds!
  208.   # NEW FEATURE:
  209.   # From v1.3, you have a few new options to set a dynamic position based on
  210.   # the game's resolution. You can set up the X and Y position separately with
  211.   # these new options:
  212.   # :center = This will make the image centered on the specified axis.
  213.   # [value] = This will automatically center the image AND will add the value
  214.   #           you have used in the array to that position.
  215.   # You can still use the old fashioned way of setting the position up (with a
  216.   # direct co-ordinate on the screen). In fact, only some specific resolution
  217.   # changing scripts require these new features (like Dekita+Venka's Resolution
  218.   # Selection script). If you don't use these scripts, you can stick to the
  219.   # Graphics.width and Graphics.height value for using the game's resolution
  220.   # in your position settings.
  221.   # Examples: [:center,130] - Centers horizontally, Y will be set to 130.
  222.   #           [[-50],100] - X will be 50 pixels to the left from the horizontal
  223.   #                         center of the game's screen, Y will be set to 100.
  224.   #
  225.   #   :opa => value,
  226.   # The opacity value for the background image. Valid values: 0 - 255.
  227.   #
  228.   #   :z => value,
  229.   # The Z value for the background.
  230.   #
  231.   #   :scroll => [x_scroll,y_scroll],
  232.   # The scrolling speed of the background.
  233.   # The higher the values, the quicker it will scroll!
  234.   # The 1st value is the scrolling on the X axis, the 2nd is for the Y axis!
  235.   # Only add this setting if you want the background to be a scrolling one!
  236.   #
  237.   # NOTE:
  238.   # If you don't want any background, leave the setting hash empty, but do NOT
  239.   # remove or comment it out!
  240.   #-----------------------------------------------------------------------------
  241.   Backgrounds = {
  242.     :back1 => {
  243.       :img => "menuback1", :pos => [0,0], :opa => 255, :z => 0,
  244.     },
  245.     # Add more background settings here!
  246.   }
  247.  
  248.   #-----------------------------------------------------------------------------
  249.   # Help Image Settings:
  250.   #-----------------------------------------------------------------------------
  251.   # A help image can be shown for each command on the grid.
  252.   # Different images can be shown for enabled and disabled commands.
  253.   #
  254.   # Details:
  255.   #
  256.   #   :pos => [x,y],
  257.   # The X and Y position of the help images.
  258.   # Note that all help images will be displayed at this position!
  259.   # NEW FEATURE:
  260.   # From v1.3, you have a few new options to set a dynamic position based on
  261.   # the game's resolution. You can set up the X and Y position separately with
  262.   # these new options. For more on this, read the position setting explanation
  263.   # in the 'Backgrounds' settings details!
  264.   #
  265.   #   :opa => value,
  266.   # The opacity value of the image.
  267.   #
  268.   #   :z => value,
  269.   # The Z value of the image.
  270.   #
  271.   #   :locked => "text",
  272.   # Like I already mentioned, different help images can be shown for enabled and
  273.   # disabled commands. The image displayed for disabled commands will use the
  274.   # same file name as the image for the enabled command, plus this text added at
  275.   # the end of that name.
  276.   # Example with this setting set to "_locked":
  277.   # Enabled: "stage2-3"   *#*   Disabled: "stage2-3_locked"
  278.   # And by knowing this, if you want to show the same image for enabled and
  279.   # disabled commands alike, you can simply set this to be an empty string
  280.   # ( "" )!
  281.   #
  282.   # NEW SETTINGS (from v1.2 update):
  283.   #
  284.   # As of v1.2, you can set up plain texts to be shown for your help display.
  285.   # I added a few settings for the text display.
  286.   # Note that the help display still requires an image to be set up for your
  287.   # commands! The text for your commands will be drawn on that image!
  288.   #
  289.   #   :tpos => [x,y],
  290.   # The position of the text INSIDE the help image.
  291.   # The Y position will set the Y position of the help text's first line.
  292.   # If the help text got more than 1 lines, those will be placed below the 1st.
  293.   # The X position setting will be applied to all lines!
  294.   #
  295.   #   :lheight => height,
  296.   # The height reserved for one line.
  297.   # You can set up more than one line for your help texts. Each new line will
  298.   # be drawn this many pixels below the previous one. So, this is the vertical
  299.   # spacing of the help lines.
  300.   #
  301.   #   :talign => value,
  302.   # The alignment of the help text. Can be:
  303.   # 0 - Left, 1 - Middle, 2 - Right.
  304.   # All lines will use the same alignment!
  305.   #
  306.   #   :font => {
  307.   #     :type => "font type name",
  308.   #     :size => size,
  309.   #     :color => Color.new(R,G,B,A),
  310.   #   },
  311.   # The font properties of the help text.
  312.   # These are kinda self-explanatory, right? :P
  313.   #-----------------------------------------------------------------------------
  314.   Help = {
  315.     :pos => [:center,65], :opa => 255, :z => 200, :locked => "_locked",
  316.     :tpos => [10,10], :lheight => 24, :talign => 1,
  317.     :font => {
  318.       :type => "Tw Cen MT Condensed",
  319.       :size => 24, :color => Color.new(155,255,255,255),
  320.     },
  321.   }
  322.  
  323.   #-----------------------------------------------------------------------------
  324.   # Grid Settings:
  325.   #-----------------------------------------------------------------------------
  326.   # These settings will determine where your grid of images will show, how many
  327.   # columns it has, how big the reserved size is for a cell on the grid, and
  328.   # how many space is left between the cells.
  329.   #
  330.   # Details:
  331.   #
  332.   #   :view => {:pos => [x,y], :size => [width,height], :z => value},
  333.   # This is a new setting from v1.4. From now on, this will determine the
  334.   # position and size of the viewport on which your image commands will appear.
  335.   # The position settings (:pos) work the same like all position settings
  336.   # explained in the above setting explanations, so check it's options there
  337.   # if you need!
  338.   # The :size setting will simply set the width and height of the viewport.
  339.   # Basically, this will determine how many command images will be shown maximum
  340.   # at once on the screen. If there are some images which can't fit into the
  341.   # viewport, the viewport becomes scrollable, just like a regular window would
  342.   # scroll if there are more items than the window can show. The difference is
  343.   # that in this case, the viewport can scroll in all directions if needed (so,
  344.   # not only horizontal or only vertical scroll), and it will actually scroll
  345.   # to the selected command gradually with a movement animation (so, it won't
  346.   # just teleport to the selection at once).
  347.   # The :z setting will set the viewport's Z value. This should be higher than
  348.   # the Z value for your backgrounds, for example, so that your commands appear
  349.   # on top of your backrounds.
  350.   #
  351.   #   :padding => {:l => pixels, :r => pixels, :u => pixels, :d => pixels},
  352.   # This will be the padding used for the viewport. The symbols mean:
  353.   # :l = Padding on the left side of the viewport.
  354.   # :r = Padding on the right side of the viewport.
  355.   # :u = Padding on the top of the viewport.
  356.   # :d = Padding on the bottom of the viewport.
  357.   # Depending on your command images used, and the :isize settings used, you
  358.   # might need to adjust the padding settings, so that your images won't get
  359.   # cut down on any sides. If you notice that your images are cut down on a
  360.   # side of the viewport, increase the padding on that side.
  361.   #
  362.   #   :scroll_time => frames,
  363.   # The scrolling time, which will actually decide the scrolling speed of the
  364.   # viewport. The scrolling animation will be this many frames (in time) long
  365.   # regardless how much the viewport needs to scroll itself.
  366.   # 60 frames means 1 second!
  367.   #
  368.   #   :max_cols => number,
  369.   # The amount of maximum columns shown.
  370.   # A new row will be created automatically if it is needed based on this
  371.   # setting.
  372.   #
  373.   #   :isize => [width,height],
  374.   # The width and height reserved for one command image.
  375.   # Because it is a grid based menu, all command images got the same dimension
  376.   # reserved, but that doesn't mean that the images used must be the same size!
  377.   # Although, using big and small images might look awkward because of the extra
  378.   # space between some commands that way.
  379.   #
  380.   #   :spacing => [horizontal,vertical],
  381.   # The horizontal and vertical spacing between each commands.
  382.   # In case you want some space between your images, you can use this setting
  383.   # to add some.
  384.   # The grid will automatically adjust the spacing for all images!
  385.   #
  386.   # NEW SETTING:
  387.   # From v1.3, this new setting is added:
  388.   #
  389.   #   :max_rows => number,
  390.   # A setting which is only needed for calculating the correct Y position with
  391.   # the new position setting features. If you don't plan on using the new
  392.   # position setting option for the Y position, you might as well ignore this.
  393.   # If you are using that feature, set this to the maximum number of rows your
  394.   # grid can have.
  395.   # From v1.4, you should set up this setting, regardless if you want to use
  396.   # the dynamic position settings or not! This is mandatory for the scrolling
  397.   # function, and will decide when your UP/DOWN scroll indicators appear.
  398.   #-----------------------------------------------------------------------------
  399.   Grid = {
  400.     :view => {:pos => [:center,180], :size => [220,90], :z => 100},
  401.     :padding => {:l => 16, :r => 20, :u => 8, :d => 10},
  402.     :scroll_time => 60,
  403.     :max_cols => 8,
  404.     :max_rows => 6,
  405.     :isize => [32,30],
  406.     :spacing => [6,6],
  407.   }
  408.  
  409.   #-----------------------------------------------------------------------------
  410.   # Command Background Settings:
  411.   #-----------------------------------------------------------------------------
  412.   # You can choose to show a background image for the command images if you
  413.   # want. This is almost the same as a regular background, but in addition,
  414.   # this one can be animated.
  415.   # The animation will only play if the grid "window" is active!
  416.   # By default, it is always active, but in case you want to do other things
  417.   # with this, it is good to know how it works, right? :P
  418.   #
  419.   # Details:
  420.   #
  421.   #   :img => "filename"
  422.   # The name of the image you want to use. This image, regardless of being a
  423.   # background, needs to be in the same folder as your command images are!
  424.   # Also, you can set this to an empty string ( "" ) if you don't want to show
  425.   # an animated background at all.
  426.   #
  427.   #   :pos => [x,y],
  428.   # Okay, starting to get redundant, right?
  429.   # You should already know what this is. :P
  430.   # NEW FEATURE:
  431.   # From v1.3, you have a few new options to set a dynamic position based on
  432.   # the game's resolution. You can set up the X and Y position separately with
  433.   # these new options. For more on this, read the position setting explanation
  434.   # in the 'Backgrounds' settings details!
  435.   #
  436.   #   :opa => value,
  437.   # Same as above...
  438.   #
  439.   #   :z => value,
  440.   # And yet again, same as above...
  441.   #
  442.   #   :rows => number,
  443.   #       * or *
  444.   #   :cols => number, # <-- From v1.4!
  445.   # This is used to show the correct image frame from your sprite-sheet.
  446.   # Enter the total amount of image frames (rows or columns) on your
  447.   # sprite-sheet.
  448.   # If you don't want to animate your command, enter 1 for this!
  449.   # If you use :rows, your image-sheet must be vertical, if you use :cols,
  450.   # your image-sheet must be horizontal!
  451.   # Do NOT use both :rows and :cols settings, only one of them!
  452.   #
  453.   #   :frames => [f1, f2, f3, ...],
  454.   # This is the setting which will determine the animation sequence played.
  455.   # You can enter as many frame indexes into the array as you want!
  456.   # These will determine which image frame will be shown in what order during
  457.   # the animation. When all the frames are played, it will re-start the
  458.   # animation from the beginning!
  459.   # You can re-use the same image frames from your sprite-sheet multiple times!
  460.   # If you don't want to animate the background, just set this to [0]!
  461.   # Although, if you don't want to animate it, you are better off using a
  462.   # regular background...
  463.   #
  464.   #   :wait => frames,
  465.   # This is the amount of frames (meaning time here, 60 frames = 1 second!)
  466.   # each image frame is shown before switching to the next one.
  467.   # In short, this is the speed of the animation itself.
  468.   # Lower numbers mean quicker animation, while higher ones will make a slow
  469.   # animation (almost like a slide-show if high enough).
  470.   # If you don't animate your background, enter a higher number for this (like
  471.   # 60 or higher), so that it won't check for the image frames too often in
  472.   # vain. But again, if you don't animate it, you really shouldn't use this
  473.   # feature.
  474.   #
  475.   #   :zoom => true/false,
  476.   # I mentioned at the beginning, that if the grid "window" is active, it will
  477.   # be animated, but if it is NOT active, it will NOT be animated.
  478.   # Well, a similar function is to zoom in/out the background when it is
  479.   # active/inactive. Combine this with the button zoom feature, and you can
  480.   # make the whole grid "window" slowly (or quickly) zoom out if inactive or
  481.   # zoom in if active. This is, of course, just an example why this option was
  482.   # made.
  483.   # But since this feature is not always needed, it can be turned ON or OFF with
  484.   # this setting. Set it to true to turn it ON, or false to turn it OFF.
  485.   #
  486.   #   :zspeed => [x_axis,y_axis],
  487.   # If the above zoom feature is enabled, this will control the speed of the
  488.   # zooming. You can set up a separate speed for the X and Y axis.
  489.   # The X axis setting will set the horizontal zoom speed, while the Y axis
  490.   # setting will set the vertical zoom speed.
  491.   # The lower the values here, the slower the zooming will be!
  492.   # Note that the default zoom value is 1.0 for all images! Higher values will
  493.   # make the image bigger, lower values will make it smaller!
  494.   #-----------------------------------------------------------------------------
  495.   CmdBack = {
  496.     :img => "storyback1", :pos => [:center,150], :opa => 255, :z => 180,
  497.     :rows => 1, :frames => [0], :wait => 60,
  498.     :zoom => true, :zspeed => [0.05,0.05],
  499.   }
  500.  
  501.   #-----------------------------------------------------------------------------
  502.   # Command Settings:
  503.   #-----------------------------------------------------------------------------
  504.   # And this is where you can set up all the stuffs for your commands.
  505.   # You got many options, so lets check them all!
  506.   # But before that, there is something that needs to be cleared first...
  507.   #
  508.   # The command images got several different states. These are:
  509.   # - active = When the "cursor" is currently on the command,
  510.   #            but NOT yet triggered!
  511.   # - inactive = When the "cursor" is not on the command.
  512.   # - selected = When the "cursor" is currently on the command, AND it has been
  513.   #              triggered. This state is only possible if you added a custom
  514.   #              method for your command button which makes the grid "window"
  515.   #              inactive. This state can NOT happen when the grid "window" is
  516.   #              active!
  517.   #
  518.   # In addition to the above, make sure to read how to set up your image-sheets
  519.   # correctly if you want to animate your command buttons! You can find all the
  520.   # info you need about this in the header of this script!
  521.   #
  522.   # Now that these are out of the way, lets see the details!
  523.   #
  524.   # Details:
  525.   #
  526.   #   key => { *settings inside* },
  527.   # The key is the key component here (this sounded way cooler in my head).
  528.   # So, that key can be anything from integers across symbols and strings to
  529.   # arrays of data. The only thing you need to keep in mind that you can NOT
  530.   # make duplicate keys, all of them must be unique!
  531.   # I used symbols in the sample settings, because I like those the most (they
  532.   # can be named however I want, but unlike strings, they require only one extra
  533.   # character - the : sign), but you can name them however you want.
  534.   # Note that these keys can be accessed in the trigger and cancel methods you
  535.   # set up for your command buttons in the methods which trigger upon
  536.   # confirming/canceling on a command button. More on this a bit later below...
  537.   # The *settings inside* are basically every setting for the command button.
  538.   # All of them are explained below.
  539.   # NEW NOTE:
  540.   # As of v1.1, :empty as a key is reserved! The command settings with that key
  541.   # will be automatically loaded when there are no shown command images at all
  542.   # on the grid menu.
  543.   # If you won't have that situation, feel free to use that key for any command
  544.   # if you want, but if it can happen, make sure to reserve that key for the
  545.   # purpose of showing something for the player when the grid menu is opened!
  546.   #
  547.   #   :ea => "file name",
  548.   # The name of the image you want to use when the command is active AND
  549.   # enabled (enabled + active = :ea).
  550.   #
  551.   #   :ei => "file name",
  552.   # The name of the image you want to use when the command is NOT active but
  553.   # still enabled (enabled + inactive = :ei).
  554.   #
  555.   #   :da => "file name",
  556.   # The name of the image you want to use when the command is active BUT
  557.   # NOT enabled (disabled + active = :da).
  558.   #
  559.   #   :di => "file name",
  560.   # The name of the image you want to use when the command is NOT active AND
  561.   # NOT enabled (disabled + inactive = :di).
  562.   #
  563.   #   :help => "file name",
  564.   # The name of the image you want to show as a "help image" for the command.
  565.   # You can use an empty string ( "" ) if you don't want to show any help image
  566.   # for the command.
  567.   # NOTE:
  568.   # The help image will use a different image for disabled commands than for
  569.   # enabled ones! The disabled help images must be named the same, and at the
  570.   # end of their name, you must add the text you specified in the 'Help' setting
  571.   # above! More info on this can be found in the mentioned setting above!
  572.   #
  573.   #   :opa => [enabled,disabled],
  574.   # The opacity value for the command.
  575.   # You can set two values up, the first one is for when the command is enabled,
  576.   # while the second one is for when the command is disabled.
  577.   #
  578.   #   :z => [active,inactive],
  579.   # The Z value of the command image.
  580.   # You can enter 2 settings here as well. The first one will be used if the
  581.   # command is active, and the second one is used if the command is inactive.
  582.   # This can prevent some awkward clipping issues when the images are close
  583.   # to each other, the selected one can be set to be show above the inactive
  584.   # ones always.
  585.   #
  586.   #   :rows => number,
  587.   #       * or *
  588.   #   :cols => number, # <-- From v1.4!
  589.   # This is used to show the correct image frame from your sprite-sheet.
  590.   # Enter the total amount of image frames (rows or columns) on your
  591.   # sprite-sheet.
  592.   # If you don't want to animate your command, enter 1 for this!
  593.   # If you use :rows, your image-sheet must be vertical, if you use :cols,
  594.   # your image-sheet must be horizontal!
  595.   # Do NOT use both :rows and :cols settings, only one of them!
  596.   #
  597.   #   :frames => [f1, f2, f3, ...],
  598.   # This is the setting which will determine the animation sequence played.
  599.   # You can enter as many frame indexes into the array as you want!
  600.   # These will determine which image frame will be shown in what order during
  601.   # the animation. When all the frames are played, it will re-start the
  602.   # animation from the beginning!
  603.   # You can re-use the same image frames from your sprite-sheet multiple times!
  604.   # If you don't want to animate the command, just set this to [0]!
  605.   #
  606.   #   :wait => frames,
  607.   # This is the amount of frames (meaning time here, 60 frames = 1 second!)
  608.   # each image frame is shown before switching to the next one.
  609.   # In short, this is the speed of the animation itself.
  610.   # Lower numbers mean quicker animation, while higher ones will make a slow
  611.   # animation (almost like a slide-show if high enough).
  612.   # If you don't want to animate your command, enter a higher number for this
  613.   # (like 60 or higher), so that it won't check for the image frames too often
  614.   # in vain.
  615.   #
  616.   #   :enable => enable_setting,
  617.   # This is the setting which will determine when the command is enabled and
  618.   # when it is disabled. You can set this one up in a few different ways:
  619.   # 1. Enter an integer number to tie the enable state of the command to a
  620.   #    game switch. The integer number will be the ID of the switch. When that
  621.   #    switch is ON, the command will be enabled, when it is OFF, the command
  622.   #    will be disabled.
  623.   #    Example: :enable => 12,
  624.   # 2. Set it to a symbol if you want to run a defined method found in the
  625.   #    SpriteGrid class. The result of that method will determine whether the
  626.   #    command will be enabled or not. This requires scripting knowledge to be
  627.   #    of any use for the developers! If you do have some coding knowledge, you
  628.   #    can make a method in the mentioned class, and use the name of that method
  629.   #    (as a symbol) here to call it. The method must return true or false!
  630.   #    The method also can't have any mandatory arguments!
  631.   #    Example: :enable => :check_cost,
  632.   # 3. Enter a valid ruby code as a string, and the evaluation of that code will
  633.   #    determine whether the command button is enabled or not. As with the above
  634.   #    option, this requires scripting knowledge too! The result of the
  635.   #    evaluated code must return true or false!
  636.   #    Example: :enable => "$game_party.gold >= 1000000",
  637.   # 4. You can use an array with two elements: a method name as a symbol, and
  638.   #    another array which will be the arguments of the method.
  639.   #    This is the same as the second option, but with this, you can use some
  640.   #    basic arguments for your used method (still, these can only be static
  641.   #    arguments, since they are evaluated in the module settings and not in the
  642.   #    SpriteGrid class, so keep this in mind!). Again, this requires scripting
  643.   #    knowledge!
  644.   #    Example: :enable => [:check_levels,[2,4,8,16]],
  645.   # 5. Set it to either true or false. Setting it to true will make the command
  646.   #    be always enabled, while setting it to false will make it disabled
  647.   #    forever. No idea why would you do the latter, but the option is there. :P
  648.   #    Example: :enable => true,
  649.   #
  650.   #   :show => show_setting,
  651.   # This setting will determine whether the command will be shown or hidden.
  652.   # You got the same options here like in the :enable setting above!
  653.   # Hidden commands will not how up at all until they become shown!
  654.   # If there are commands after the hidden command(s), the rest of the shown
  655.   # commands will line up on the grid continuously, so even if some commands are
  656.   # hidden, there won't be empty holes on the grid, because the rest of the
  657.   # shown commands will fill the "holes", just like a regular command window
  658.   # would do!
  659.   #
  660.   #   :method => method_setting,
  661.   # This setting requires scripting knowledge!
  662.   # If this setting is set to nil or omitted completely, the command button
  663.   # won't do anything at all aside from playing the confirm/buzzer sound effect
  664.   # and showing a flash effect when it is triggered.
  665.   # However, you can run any method from the scene class where the SpriteGrid
  666.   # class is made or you can run a direct ruby code too!
  667.   # The method/code will be executed when the button is triggered.
  668.   # The layout of the setting is the same as some options from the :enable
  669.   # setting, specifically, you can use these:
  670.   # - Option 2: Symbol (method without arguments),
  671.   # - Option 3: String (string to evaluate as code),
  672.   # - Option 4: Array (method with static arguments).
  673.   # Note that the grid "window" will NOT be deactivated or activated
  674.   # automatically upon using any of these options, so if you want that to
  675.   # happen, you must include it in your method/code!
  676.   # These methods and codes will be run/evaluated in the current scene class!
  677.   # The method which triggers these methods/codes got some built-in variables
  678.   # which you can use if you want/need. These are:
  679.   # - key = This is the key identifier of the grid "window" where the triggered
  680.   #         command button is. This is completely useless if you are using only
  681.   #         one grid "windows", but if you use multiple of them in the same
  682.   #         scene, this can be useful, because regardless in which one the
  683.   #         triggered button is, the same method is run.
  684.   # - sym = The "symbol" of the triggered button. Actually, this is the key
  685.   #         identifier of the triggered command button, but since I didn't want
  686.   #         to use "key2" or other very similar variable names (to avoid mixing
  687.   #         them up), I settled with "sym". Although it can be anything, not
  688.   #         just symbols (depends what kind of key did you used for the command
  689.   #         buttons in the module settings).
  690.   # In addition to these, you can, of course, use any instance/global variables
  691.   # found in the scene/anywhere. I won't write those down, obviously. :P
  692.   #
  693.   #   :cancel => cancel_method_settings,
  694.   # This is the same as the above, but this will happen when the cancel button
  695.   # is pressed on a command button.
  696.   # You can use the same config options as for the :method setting.
  697.   # I set this to :return_scene by default, which will make the player exit the
  698.   # scene when the cancel button is pressed.
  699.   #
  700.   # Phew! I hope, I wrote all setting explanation down! *.*
  701.   #
  702.   # NEW SETTINGS:
  703.   # Or maybe not... Some new options are added with v1.1. These are:
  704.   #
  705.   #   :skip_col => amount,
  706.   # Skips the amount of columns AFTER the command image which got this option,
  707.   # which will be reflected in the placement of the subsequent command images.
  708.   # Note that the regular order will still be counted, and if it happens to be
  709.   # that the command image with this setting is in the last column, no columns
  710.   # will be skipped, and the command will be placed on the first column of the
  711.   # next row! Same happens if the columns skipped would place the next command
  712.   # outside of the range of maximum columns available, it will simply skip the
  713.   # maximum columns possible and start the next row instead of placing the
  714.   # command outside of the grid layout.
  715.   # This option is fully optional, you can omit it if you want!
  716.   #
  717.   #   :skip_row => amount,
  718.   # This will make the next command skip the amount of rows you set up here.
  719.   # Regardless if the next command is on the 1st column or in the middle, it
  720.   # will skip all subsequent columns and jumps to the start of the next row.
  721.   # If you enter a higher amount than 1, it will skip additional rows as well.
  722.   # Note that the regular order is still maintained, so if a command image on
  723.   # the last column got this option, it will jump to the next row automatically
  724.   # (because it reached the maximum columns available) AND it will skip the
  725.   # amount of rows you set up here additionally!
  726.   #
  727.   # EVEN NEWER SETTINGS:
  728.   # The v1.2 update brings you these new settings:
  729.   #
  730.   #   :help_txt => {
  731.   #     :enabled => [ # Only shows if the command is enabled.
  732.   #       "help text - line 1",
  733.   #       "help text - line 2",
  734.   #       ...
  735.   #     ],
  736.   #     :disabled => [ # Only shows if the command is disabled.
  737.   #       "help text - line 1",
  738.   #       "help text - line 2",
  739.   #       ...
  740.   #     ],
  741.   #   },
  742.   # This will set up help texts for your command buttons. These texts will be
  743.   # drawn on the command's help image, so you still have to use a help image!
  744.   # Each separate string set up in the arrays will show up on a new line!
  745.   # You can add as many lines as you want!
  746.   # And as you can see, you can make a separate text setting for enabled and
  747.   # disabled command states.
  748.   # This settings is optional! If it is not set, no text will be drawn on the
  749.   # command's help image!
  750.   # Also, you don't have to set up both the enabled and disabled texts. The
  751.   # text type which is not set up will simply not show anything.
  752.   # For example, a text setting with only the :enabled option set up will show
  753.   # the help text only when the command is enabled, not when it is disabled!
  754.   #
  755.   # SOME MORE SETTINGS:
  756.   # The following new (optional) settings are added with the v1.4 update:
  757.   #
  758.   #   :add_pos => [x,y],
  759.   # This will make your command image appear this many pixels from it's original
  760.   # grid position. In other words, these are offset position settings.
  761.   # This is optional, you don't have to use it!
  762.   # If you use this, note that ALL of your command images after the image with
  763.   # this setting will be shifted this many pixels, so, not just the next image!
  764.   # Also, if you use this in more than one command settings, it will add up ALL
  765.   # the additional positions you added with this option, and use that for
  766.   # setting the position of ALL subsequent command images.
  767.   # An example:
  768.   # 3rd command settings got this additional position setting:
  769.   #   :add_pos => [16,0]
  770.   # This will shift the 4th command image 16 pixels to the right, as well as any
  771.   # other command images after the 4th one.
  772.   # The 7th command image got this additional position setting:
  773.   #   :add_pos => [-8,6],
  774.   # Now, the 4th, 5th, 6th and 7th command images will be moved 16 pixels to the
  775.   # right (because of the setting found in the 3rd command settings), and the
  776.   # 8th and any other command images after will be moved 8 pixels to the right
  777.   # (16 - 8 = 8) and 6 pixels down (0 + 6 = 6).
  778.   # In short, all of these settings are additive!
  779.   #
  780.   #   :add_reset => [:x,:y],
  781.   # This setting is related to the above one, like the name suggests it.
  782.   # If you use this one, ALL of the additional position settings will be reset
  783.   # on the choosen axis (X or Y, meaning horizontal or vertical).
  784.   # In other words, this will reset the position of ALL of the command images
  785.   # coming after to the original grid position (in short, sets the :add_pos
  786.   # setting to [0,0], it's initial value, regardless of what value it had
  787.   # before).
  788.   # You can insert :x into the array setting to reset the additional X position
  789.   # and you can insert :y to reset the additional Y position.
  790.   # You can use both if you want, or only one.
  791.   # Note that the reset happens before the :add_pos setting is added, so you can
  792.   # reset it and add a new value for it immediately in the same command button
  793.   # setting if you want!
  794.   #
  795.   # CHANGE OF SETTINGS:
  796.   #
  797.   # From v1.4, the position of the :empty command will be automatically centered
  798.   # on the viewport of the grid! So, the :pos setting for the :empty command
  799.   # is not required anymore, in fact, it does nothing!
  800.   #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  801.   # Just for some examples, I wrote 2 methods which can be called with arguments
  802.   # in the scene. Feel free to test them out!
  803.   #
  804.   # Example 1 - Teleport:
  805.   #
  806.   # Obviously, this can be quite awesome for a stage selection or a quick travel
  807.   # menu. Here is how you can use it:
  808.   #
  809.   #   :method => [:teleport,[map_id,x,y,dir,fade_type]],
  810.   #
  811.   # The :teleport is the name of the method which will do the automated "hard"
  812.   # work in the script.
  813.   # map_id = The ID of the map to teleport to.
  814.   # x,y = The X and Y position on the map to teleport to.
  815.   # dir = The player's direction after the teleport.
  816.   #       (2 = Down, 4 = Left, 6 = Right, 8 = Up)
  817.   # fade_type = The fade type used for the teleport.
  818.   #             (0 = Black, 1 = White, 2 = None)
  819.   #
  820.   # I took the liberty to set up an actual example setting for the 1st command,
  821.   # so, if you trigger that button, it will teleport you to the designated
  822.   # place. Yay!
  823.   #
  824.   # Example 2 - Show Image:
  825.   #
  826.   # A basic way to show custom images upon selecting a command.
  827.   # The image will appear at the same place the command button is, and will
  828.   # move to the designated position within the given time.
  829.   # In addition, the image will start on zoom level 0.0, and will get to 1.0
  830.   # at the same time when the destination is reached.
  831.   # The image will stay there until the player presses the confirm button again.
  832.   #
  833.   # Here is how to use this method:
  834.   #
  835.   #   :method => [:show_image,["file name","folder",x,y,time]],
  836.   #
  837.   # The :show_image is the name of the method which will do the automated hard
  838.   # work in the script.
  839.   # "file name" = The name of the image file to show.
  840.   # "folder" = The folder path to the image file used.
  841.   # x,y = The destination co-ordinates where the image should travel.
  842.   # time = The time it takes the image to travel to the destination point.
  843.   #
  844.   # I made an example setup for this method too for the 2nd command, so if you
  845.   # trigger that one, it will show an image like I described above. Cool!
  846.   #
  847.   # Alright, that's all for the example methods!
  848.   # Feel free to check these methods in the script itself to see how they work,
  849.   # or create your own ones!
  850.   #-----------------------------------------------------------------------------
  851.   Commands = {
  852.     :s01 => {
  853.       :ea => "0-1a", :ei => "0-1b", :da => "disabled1a", :di => "disabled1b",
  854.       :help => "0-1helpa", :opa => [255,255], :z => [300,250],
  855.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  856.       :enable => true, :show => true, :method => [:teleport,[4,8,14,2,1]],
  857.       :cancel => :return_scene,
  858.       :help_txt => {
  859.         :enabled => [
  860.           "Just a text for testing.",
  861.           "Lets see how this shows up...",
  862.           "Three lines for the win! And for the bunnies!",
  863.         ],
  864.         :disabled => [
  865.           "This shows only if the command is disabled!",
  866.         ],
  867.       },
  868.     },
  869.     :s02 => {
  870.       :ea => "0-2a", :ei => "0-2b", :da => "disabled1a", :di => "disabled1b",
  871.       :help => "0-2helpa", :opa => [255,255], :z => [300,250],
  872.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  873.       :enable => true, :show => true, #:skip_row => 1,
  874.       :method => [:show_image,["pl2name_down",ImgFolders[:back],320,400,120]],
  875.       :cancel => :return_scene,
  876.       :help_txt => {
  877.         :enabled => ["Another sample text. Only if the command is enabled. Yay!"],
  878.       },
  879.     },
  880.     :s11 => {
  881.       :ea => "1-1a", :ei => "1-1b", :da => "disabled1a", :di => "disabled1b",
  882.       :help => "1-1helpa", :opa => [255,255], :z => [300,250],
  883.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  884.       :enable => false, :show => true, :method => nil, :cancel => :return_scene,
  885.       :help_txt => {
  886.         :disabled => ["This command is disabled, ohh noes!"],
  887.       },
  888.     },
  889.     :s12 => {
  890.       :ea => "1-2a", :ei => "1-2b", :da => "disabled1a", :di => "disabled1b",
  891.       :help => "1-2helpa", :opa => [255,255], :z => [300,250],
  892.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  893.       :enable => false, :show => true, :method => nil, :cancel => :return_scene,
  894.     },
  895.     :s13 => {
  896.       :ea => "1-3a", :ei => "1-3b", :da => "disabled1a", :di => "disabled1b",
  897.       :help => "1-3helpa", :opa => [255,255], :z => [300,250],
  898.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  899.       :enable => true, :show => true, :method => nil, :cancel => :return_scene,
  900.     },
  901.     :s14 => {
  902.       :ea => "1-4a", :ei => "1-4b", :da => "disabled1a", :di => "disabled1b",
  903.       :help => "1-4helpa", :opa => [255,255], :z => [300,250],
  904.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  905.       :enable => false, :show => true, :method => nil, :cancel => :return_scene,
  906.     },
  907.     :s15 => {
  908.       :ea => "1-5a", :ei => "1-5b", :da => "disabled1a", :di => "disabled1b",
  909.       :help => "1-5helpa", :opa => [255,255], :z => [300,250],
  910.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  911.       :enable => true, :show => true, :method => nil, :cancel => :return_scene,
  912.     },
  913.     :s21 => {
  914.       :ea => "2-1a", :ei => "2-1b", :da => "disabled1a", :di => "disabled1b",
  915.       :help => "2-1helpa", :opa => [255,255], :z => [300,250],
  916.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  917.       :enable => false, :show => true, :method => nil, :cancel => :return_scene,
  918.     },
  919.     :s22 => {
  920.       :ea => "2-2a", :ei => "2-2b", :da => "disabled1a", :di => "disabled1b",
  921.       :help => "2-2helpa", :opa => [255,255], :z => [300,250],
  922.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  923.       :enable => true, :show => true, :method => nil, :cancel => :return_scene,
  924.     },
  925.     :s23 => {
  926.       :ea => "2-3a", :ei => "2-3b", :da => "disabled1a", :di => "disabled1b",
  927.       :help => "2-3helpa", :opa => [255,255], :z => [300,250],
  928.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  929.       :enable => true, :show => true, :method => nil, :cancel => :return_scene,
  930.     },
  931.     :s24 => {
  932.       :ea => "2-4a", :ei => "2-4b", :da => "disabled1a", :di => "disabled1b",
  933.       :help => "2-4helpa", :opa => [255,255], :z => [300,250],
  934.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  935.       :enable => true, :show => true, :method => nil, :cancel => :return_scene,
  936.     },
  937.     :s25 => {
  938.       :ea => "2-5a", :ei => "2-5b", :da => "disabled1a", :di => "disabled1b",
  939.       :help => "2-5helpa", :opa => [255,255], :z => [300,250],
  940.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  941.       :enable => true, :show => true, :method => nil, :cancel => :return_scene,
  942.     },
  943.     :s31 => {
  944.       :ea => "3-1a", :ei => "3-1b", :da => "disabled1a", :di => "disabled1b",
  945.       :help => "3-1helpa", :opa => [255,255], :z => [300,250],
  946.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  947.       :enable => true, :show => true, :method => nil, :cancel => :return_scene,
  948.     },
  949.     :s32 => {
  950.       :ea => "3-2a", :ei => "3-2b", :da => "disabled1a", :di => "disabled1b",
  951.       :help => "3-2helpa", :opa => [255,255], :z => [300,250],
  952.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  953.       :enable => false, :show => true, :method => nil, :cancel => :return_scene,
  954.     },
  955.     :s33 => {
  956.       :ea => "3-3a", :ei => "3-3b", :da => "disabled1a", :di => "disabled1b",
  957.       :help => "3-3helpa", :opa => [255,255], :z => [300,250],
  958.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  959.       :enable => true, :show => true, :method => nil, :cancel => :return_scene,
  960.     },
  961.     :s34 => {
  962.       :ea => "3-4a", :ei => "3-4b", :da => "disabled1a", :di => "disabled1b",
  963.       :help => "3-4helpa", :opa => [255,255], :z => [300,250],
  964.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6, #:skip_row => 1,
  965.       :enable => true, :show => true, :method => nil, :cancel => :return_scene,
  966.     },
  967.     :s41 => {
  968.       :ea => "4-1a", :ei => "4-1b", :da => "disabled1a", :di => "disabled1b",
  969.       :help => "4-1helpa", :opa => [255,255], :z => [300,250],
  970.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  971.       :enable => true, :show => true, :method => nil, :cancel => :return_scene,
  972.     },
  973.     :s42 => {
  974.       :ea => "4-2a", :ei => "4-2b", :da => "disabled1a", :di => "disabled1b",
  975.       :help => "4-2helpa", :opa => [255,255], :z => [300,250],
  976.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  977.       :enable => true, :show => true, :method => nil, :cancel => :return_scene,
  978.     },
  979.     :s43 => {
  980.       :ea => "4-3a", :ei => "4-3b", :da => "disabled1a", :di => "disabled1b",
  981.       :help => "4-3helpa", :opa => [255,255], :z => [300,250],
  982.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6, #:skip_row => 1,
  983.       :enable => true, :show => true, :method => nil, :cancel => :return_scene,
  984.     },
  985.     :s51 => {
  986.       :ea => "5-1a", :ei => "5-1b", :da => "disabled1a", :di => "disabled1b",
  987.       :help => "5-1helpa", :opa => [255,255], :z => [300,250],
  988.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  989.       :enable => false, :show => true, :method => nil, :cancel => :return_scene,
  990.     },
  991.     :empty => { # Reserved key! This will only appear if the list is empty!
  992.       :pos => [:center,250],
  993.       :ea => "empty1a", :ei => "empty1b", :da => "empty1a", :di => "empty1b",
  994.       :help => "emptyhelp1a", :opa => [255,255], :z => [300,250],
  995.       :rows => 4, :frames => [0,1,2,3,2,1], :wait => 6,
  996.       :enable => false, :show => true, :method => nil, :cancel => :return_scene,
  997.     },
  998.   }
  999.  
  1000.   #-----------------------------------------------------------------------------
  1001.   # Arrow Settings:
  1002.   #-----------------------------------------------------------------------------
  1003.   # These settings are new settings from v1.4!
  1004.   #
  1005.   # If your viewport for the grid commands can't display all command images at
  1006.   # once (because the size of the viewport is too small for it), these arrow
  1007.   # images will indicate that you can scroll the commands in the specified
  1008.   # directions. They will only appear if the viewport can be scrolled in the
  1009.   # direction, otherwise, they will be hidden from the player.
  1010.   #
  1011.   # The settings here use the same layout as the image settings for your command
  1012.   # images (in the 'Commands' settings above).
  1013.   # There are a few differences (the settings here got only one :opa and :z
  1014.   # settings, and all of the images got a :pos setting), but I guess, these are
  1015.   # still obvious ones, so I won't explain them again.
  1016.   #
  1017.   # Note that if you don't want a scroll indicator for a direction, you can set
  1018.   # it to nil, or just simply omit it from the 'Arrows' setting as well.
  1019.   # If you don't want or need any scroll indicators, you can set this whole
  1020.   # setting to nil too.
  1021.   #-----------------------------------------------------------------------------
  1022.   Arrows = {
  1023.     :up => { # Shows up when you can scroll upwards.
  1024.       :img => "arrowup2", :opa => 255, :z => 400, :pos => [:center,168],
  1025.       :rows => 3, :frames => [0,1,2,1], :wait => 6,
  1026.     },
  1027.     :down => { # Shows up when you can scroll downwards.
  1028.       :img => "arrowdown2", :opa => 255, :z => 400, :pos => [:center,282],
  1029.       :rows => 3, :frames => [2,1,0,1], :wait => 6,
  1030.     },
  1031.     :left => { # Shows up when you can scroll left.
  1032.       :img => "arrowleft2", :opa => 255, :z => 400, :pos => [[-124],225],
  1033.       :cols => 3, :frames => [0,1,2,1], :wait => 6,
  1034.     },
  1035.     :right => { # Shows up when you can scroll right.
  1036.       :img => "arrowright2", :opa => 255, :z => 400, :pos => [[124],225],
  1037.       :cols => 3, :frames => [2,1,0,1], :wait => 6,
  1038.     },
  1039.   }
  1040.  
  1041.   #-----------------------------------------------------------------------------
  1042.   # Flash Settings:
  1043.   #-----------------------------------------------------------------------------
  1044.   # You can set up flash effects which will play when the button is triggered.
  1045.   # Depending on the state of the command button (enabled or disabled), a
  1046.   # different flash effect can be shown.
  1047.   #
  1048.   # Details:
  1049.   #
  1050.   #   :color => Colow.new(R,G,B,A),
  1051.   # The color used for the flash effect. Uses RGBA codes!
  1052.   #
  1053.   #   :dur => frames,
  1054.   # The duration of the flash effect in frames. 60 frames = 1 second!
  1055.   #
  1056.   # I guess, I don't need to write down what :enabled and :disabled means here,
  1057.   # right? :P
  1058.   #
  1059.   # Ohh, be sure to keep the brackets and commas everywhere!
  1060.   # Except if you don't want to use any flash effects, in which case you can set
  1061.   # the whole :enabled or :disabled setting to be nil. Looks like:
  1062.   #   :enabled => nil,  *or* :disabled => nil,
  1063.   #-----------------------------------------------------------------------------
  1064.   Flash = {
  1065.     :enabled => {:color => Color.new(255,255,50,250), :dur => 20},
  1066.     :disabled => {:color => Color.new(255,50,50,250), :dur => 20},
  1067.   }
  1068.  
  1069.   #-----------------------------------------------------------------------------
  1070.   # Zoom Settings:
  1071.   #-----------------------------------------------------------------------------
  1072.   # Depending on the state of the command buttons and the grid "window" itself,
  1073.   # you can show different zooming effects for your button images and for the
  1074.   # grid "window" background.
  1075.   #
  1076.   #   :grid => {:active => [x_zoom,y_zoom], :inactive => [x_zoom,y_zoom]},
  1077.   # This setting will affect the whole grid "window", including all the command
  1078.   # buttons and it's background!
  1079.   # :active sets the overall zoom level for when the grid "window" is active
  1080.   # (and it is always active by default, unless you change it, which requires
  1081.   # scripting knowledge), and :inactive sets the zoom level when it's... well,
  1082.   # inactive, obviously.
  1083.   # This means that the :limit settings you will set in the other settings here
  1084.   # will be multiplied by these values, and the result will be the overall zoom
  1085.   # level for the command images (the background will directly use these values
  1086.   # as it's zoom level).
  1087.   #
  1088.   #   :ea => {:speed => [x_speed,y_speed], :limit => [x_zoom,y_zoom]},
  1089.   # When a command is enabled and active, these settings will be applied.
  1090.   # So, the zoom level will change to the :limit setting you set up here either
  1091.   # slowly or quickly depending on the :speed settings.
  1092.   # The lower the :speed setting is, the slower it will change the zoom level.
  1093.   # The lower the :limit setting is, the smaller the image gets.
  1094.   # Remember that the default zoom level is 1.0 for all images!
  1095.   # And make sure to keep all the brackets and commas here!
  1096.   #
  1097.   #   :ei => {:speed => [x_speed,y_speed], :limit => [x_zoom,y_zoom]},
  1098.   #   :da => {:speed => [x_speed,y_speed], :limit => [x_zoom,y_zoom]},
  1099.   #   :di => {:speed => [x_speed,y_speed], :limit => [x_zoom,y_zoom]},
  1100.   #  :sel => {:speed => [x_speed,y_speed], :limit => [x_zoom,y_zoom]},
  1101.   # These all use the same layout as the above setting, but these will take over
  1102.   # when the button is:
  1103.   # :ei = Enabled AND inactive.
  1104.   # :da = Disabled AND active.
  1105.   # :di = Disabled AND inactive.
  1106.   # :sel = Selected (so it must have been enabled AND active as well).
  1107.   # If you don't know what these command button states mean, feel free to
  1108.   # refresh your memory at the top of the 'Commands' settings explanation!
  1109.   #
  1110.   # NOTE:
  1111.   # To disable all kind of zooming effects, you can set all of the :limit and
  1112.   # :grid settings to [1.0,1.0]!
  1113.   #-----------------------------------------------------------------------------
  1114.   Zoom = {
  1115.     :grid => {:active => [1.0,1.0], :inactive => [0.8,0.8]},
  1116.     :ea => {:speed => [0.05,0.05], :limit => [1.0,1.0]},
  1117.     :ei => {:speed => [0.05,0.05], :limit => [0.75,0.75]},
  1118.     :da => {:speed => [0.05,0.05], :limit => [1.0,1.0]},
  1119.     :di => {:speed => [0.05,0.05], :limit => [0.75,0.75]},
  1120.     :sel => {:speed => [0.05,0.05], :limit => [1.0,1.0]},
  1121.   }
  1122.  
  1123.   #-----------------------------------------------------------------------------
  1124.   # Move Settings:
  1125.   #-----------------------------------------------------------------------------
  1126.   # You can move the selected command somewhere if you want with these settings.
  1127.   # When the command is selected, it will move to the original position plus
  1128.   # the :dist setting you set up here, and when it is not selected, it will move
  1129.   # back to it's original position.
  1130.   # The movement speed of the command image depends on the :speed settings.
  1131.   # The higher it is, the quicker will the image move to it's destination.
  1132.   #
  1133.   # Note that by default, no command button can be in the "selected" state, so
  1134.   # if you don't plan to use some of the advanced features this script got and
  1135.   # stick to the default :method and :cancel settings, you can completely
  1136.   # ignore these settings!
  1137.   #
  1138.   # The default settings will not move the command images anywhere!
  1139.   #-----------------------------------------------------------------------------
  1140.   Move = {
  1141.     :speed => [1,1], :dist => [0,0],
  1142.   }
  1143.  
  1144.   #-----------------------------------------------------------------------------
  1145.   # Audio Settings:
  1146.   #-----------------------------------------------------------------------------
  1147.   # These settings are kinda self-explanatory, but just in case:
  1148.   # :confirm = Plays when triggering an enabled button.
  1149.   # :disabled = Plays when triggering a disabled button.
  1150.   # :cancel = Plays when the cancel button is pressed on a button.
  1151.   # :cursor = Plays when changing buttons (when the "cursor" position changes).
  1152.   #
  1153.   # Format:
  1154.   #
  1155.   #   :key => RPG::SE.new("file name",volume,pitch),
  1156.   #
  1157.   # If you don't want a sound effect for something, just set the file name for
  1158.   # it to an empty string ( "" )!
  1159.   #-----------------------------------------------------------------------------
  1160.   Sound = {
  1161.     :confirm => RPG::SE.new("Decision1",80,100),
  1162.     :disabled => RPG::SE.new("Buzzer1",80,100),    
  1163.     :cancel => RPG::SE.new("Cancel2",80,100),
  1164.     :cursor => RPG::SE.new("Cursor1",80,100),
  1165.   }
  1166.  
  1167.   #-----------------------------------------------------------------------------
  1168.   # Button Settings:
  1169.   #-----------------------------------------------------------------------------
  1170.   # You can make your own controls for your grid "windows" here.
  1171.   # I think, it is pretty clear what the below settings do, so I won't write my
  1172.   # usual wall of text here. :P
  1173.   # For the default available button symbols, you can look up the help files
  1174.   # of RPG Maker VX Ace.
  1175.   # Aside from the default buttons, you can use custom ones if you use a custom
  1176.   # input script.
  1177.   #-----------------------------------------------------------------------------
  1178.   Buttons = {
  1179.     :confirm => :C, :cancel => :B,
  1180.     :prev_row => :UP, :next_row => :DOWN,
  1181.     :prev_col => :LEFT, :next_col => :RIGHT,
  1182.   }
  1183.  
  1184. end
  1185. #===============================================================================
  1186. # End of settings! Editing anything below may lead to... you know it, right? o.o
  1187. #===============================================================================
  1188.  
  1189. module Cache
  1190.  
  1191.   def self.custom_imgs(filename,folder)
  1192.     load_bitmap(folder,filename)
  1193.   end
  1194.  
  1195. end
  1196.  
  1197. module DynXY
  1198.  
  1199.   def self.get_x(xx,ww,extra=nil)
  1200.     case xx
  1201.     when Array
  1202.       x = (Graphics.width-ww)/2
  1203.       x += xx[0]
  1204.       x += extra if extra
  1205.     when :center
  1206.       x = (Graphics.width-ww)/2
  1207.       x += extra if extra
  1208.     else
  1209.       x = xx
  1210.     end
  1211.     p "X: #{x}"
  1212.     return x
  1213.   end
  1214.  
  1215.   def self.get_y(yy,hh,extra=nil)
  1216.     case yy
  1217.     when Array
  1218.       y = (Graphics.height-hh)/2
  1219.       y += yy[0]
  1220.       y += extra if extra
  1221.     when :center
  1222.       y = (Graphics.height-hh)/2
  1223.       y += extra if extra
  1224.     else
  1225.       y = yy
  1226.     end
  1227.     p "Y: #{y}"
  1228.     return y
  1229.   end
  1230.  
  1231. end
  1232.  
  1233. class Game_Interpreter
  1234.  
  1235.   def open_grid_menu(mod=SGridMenu)
  1236.     SceneManager.call(Grid_Menu)
  1237.     SceneManager.scene.prepare(mod)
  1238.   end
  1239.  
  1240. end
  1241.  
  1242. class Grid_Menu < Scene_Base
  1243.  
  1244.   def start
  1245.     super
  1246.     init_sprites
  1247.   end
  1248.  
  1249.   def prepare(mod)
  1250.     @mod = mod
  1251.   end
  1252.  
  1253.   def init_sprites
  1254.     init_backgrounds
  1255.     init_help_img
  1256.     init_grid_commands
  1257.   end
  1258.  
  1259.   def init_backgrounds
  1260.     @backs = {}
  1261.     folder = @mod::ImgFolders[:back]
  1262.     @mod::Backgrounds.each do |sym,data|
  1263.       @backs[sym] = data[:scroll].nil? ? Sprite.new : Plane.new
  1264.       @backs[sym].bitmap = Cache.custom_imgs(data[:img],folder)
  1265.       if @backs[sym].is_a?(Sprite)
  1266.         x = DynXY.get_x(data[:pos][0],@backs[sym].bitmap.width,@backs[sym].ox)
  1267.         y = DynXY.get_y(data[:pos][1],@backs[sym].bitmap.height,@backs[sym].oy)
  1268.         @backs[sym].x = x
  1269.         @backs[sym].y = y
  1270.       end
  1271.       @backs[sym].opacity = data[:opa]
  1272.       @backs[sym].z = data[:z]
  1273.     end
  1274.   end
  1275.  
  1276.   def init_help_img
  1277.     data = @mod::Help
  1278.     folder = @mod::ImgFolders[:help]
  1279.     @helpy = SpriteHelp.new(data,folder,"")
  1280.   end
  1281.  
  1282.   def init_grid_commands
  1283.     grid = @mod::Grid
  1284.     data = @mod::Commands
  1285.     folder = @mod::ImgFolders[:cmds]
  1286.     flash = @mod::Flash
  1287.     zoom = @mod::Zoom
  1288.     move = @mod::Move
  1289.     sound = @mod::Sound
  1290.     back = @mod::CmdBack
  1291.     buttons = @mod::Buttons
  1292.     arrows = @mod::Arrows
  1293.     @grid = SpriteGrid.new(:grid,grid,data,folder,flash,zoom,move,sound,buttons,arrows,back,true)
  1294.     @grid.show
  1295.     @grid.update_help
  1296.   end
  1297.  
  1298.   def trigger_command(key,sym)
  1299.     case key
  1300.     when :grid
  1301.       if @grid.data[sym][:method]
  1302.         run_method(key,sym,:method)
  1303.       else
  1304.         @grid.activate
  1305.       end
  1306.     end
  1307.   end
  1308.  
  1309.   def cancel_command(key,sym)
  1310.     case key
  1311.     when :grid
  1312.       if @grid.commands.size <= 0
  1313.         return_scene
  1314.       elsif @grid.data[sym][:cancel]
  1315.         run_method(key,sym,:cancel)
  1316.       else
  1317.         @grid.deactivate
  1318.       end
  1319.     end
  1320.   end
  1321.  
  1322.   def run_method(key,sym,type)
  1323.     case key
  1324.     when :grid
  1325.       mtd = @grid.data[sym][type]
  1326.     end
  1327.     case mtd
  1328.     when Symbol
  1329.       method(mtd).call
  1330.     when Array
  1331.       method(mtd[0]).call(*mtd[1])
  1332.     when String
  1333.       eval(mtd)
  1334.     end
  1335.   end
  1336.  
  1337.   def update_help(key,sym)
  1338.     case key
  1339.     when :grid
  1340.       if @grid.commands.size <= 0
  1341.         img = ""; txt = nil
  1342.       elsif @grid.enabled[@grid.index]
  1343.         img = @grid.data[sym][:help]
  1344.         if @grid.data[sym][:help_txt]
  1345.           txt = @grid.data[sym][:help_txt][:enabled]
  1346.         end
  1347.       else
  1348.         img = @grid.data[sym][:help] + @helpy.data[:locked]
  1349.         txt = @grid.data[sym][:help_txt][:disabled] if @grid.data[sym][:help_txt]
  1350.       end
  1351.       img = "" if img == @helpy.data[:locked]
  1352.       @helpy.set_img(img,@mod::ImgFolders[:help],txt)
  1353.     end
  1354.   end
  1355.  
  1356.   def teleport(map_id,x,y,dir,f_type) # Example 1 for custom method calls.
  1357.     @grid.deactivate
  1358.     RPG::SE.new("Darkness8",80,100).play
  1359.     trigger_time = Graphics.frame_count
  1360.     until Graphics.frame_count >= trigger_time + 30
  1361.       Graphics.update
  1362.       @grid.update
  1363.     end
  1364.     return_scene
  1365.     $game_player.reserve_transfer(map_id, x, y, dir)
  1366.     $game_temp.fade_type = f_type
  1367.   end
  1368.  
  1369.   def show_image(img_n,folder,x,y,time) # Example 2 for custom method calls.
  1370.     @grid.deactivate([1.0,1.0])         # Got a bit carried away here, sorry! :P
  1371.     img = Sprite.new
  1372.     img.bitmap = Cache.custom_imgs(img_n,folder)
  1373.     img.x = ox = @grid.imgs[@grid.index].x
  1374.     img.y = oy = @grid.imgs[@grid.index].y
  1375.     img.ox = img.bitmap.width/2
  1376.     img.oy = img.bitmap.height/2
  1377.     img.opacity = 255
  1378.     img.z = 400
  1379.     img.zoom_x = img.zoom_y = 0.0
  1380.     inc_x = (x - img.x)/time.to_f
  1381.     inc_y = (y - img.y)/time.to_f
  1382.     inc_z = 1.0/time.to_f
  1383.     ax = ay = 0
  1384.     until img.zoom_x >= 1.0 && img.y == y && img.x == x
  1385.       Graphics.update
  1386.       Input.update
  1387.       @grid.update
  1388.       mult = Input.press?(:C) ? 2 : 1
  1389.       img.zoom_x += inc_z * mult if img.zoom_x != 1.0
  1390.       img.zoom_y += inc_z * mult if img.zoom_y != 1.0
  1391.       img.zoom_x = 1.0 if img.zoom_x > 1.0
  1392.       img.zoom_y = 1.0 if img.zoom_y > 1.0
  1393.       ax += inc_x * mult
  1394.       ay += inc_y * mult
  1395.       img.x = ox + ax
  1396.       img.y = oy + ay
  1397.       img.x = x if (inc_x > 0 && img.x > x) || (inc_x < 0 && img.x < x)
  1398.       img.y = y if (inc_y > 0 && img.y > y) || (inc_y < 0 && img.y < y)
  1399.     end
  1400.     until Input.trigger?(:C)
  1401.       Graphics.update
  1402.       Input.update
  1403.       @grid.update
  1404.     end
  1405.     RPG::SE.new("Bell3",80,100).play
  1406.     ax = ay = 0
  1407.     ox = img.x
  1408.     oy = img.y
  1409.     inc_x = -inc_x
  1410.     inc_y = -inc_y
  1411.     xx = @grid.imgs[@grid.index].x
  1412.     yy = @grid.imgs[@grid.index].y
  1413.     until img.zoom_x <= 0.0 && img.x == xx && img.y == yy
  1414.       Graphics.update
  1415.       Input.update
  1416.       @grid.update
  1417.       mult = Input.press?(:C) ? 2 : 1
  1418.       img.zoom_x -= inc_z * mult if img.zoom_x > 0.0
  1419.       img.zoom_y -= inc_z * mult if img.zoom_y > 0.0
  1420.       ax += inc_x * mult
  1421.       ay += inc_y * mult
  1422.       img.x = ox + ax
  1423.       img.y = oy + ay
  1424.       img.x = xx if (inc_x > 0 && img.x > xx) || (inc_x < 0 && img.x < xx)
  1425.       img.y = yy if (inc_y > 0 && img.y > yy) || (inc_y < 0 && img.y < yy)
  1426.     end
  1427.     img.bitmap.dispose
  1428.     img.dispose
  1429.     @grid.activate
  1430.   end
  1431.  
  1432.   def update
  1433.     super
  1434.     update_scrolling_backs
  1435.     @grid.update
  1436.   end
  1437.    
  1438.   def update_scrolling_backs
  1439.     @backs.each do |sym,sprite|
  1440.       next if @mod::Backgrounds[sym][:scroll].nil?
  1441.       sprite.ox += @mod::Backgrounds[sym][:scroll][0]
  1442.       sprite.oy += @mod::Backgrounds[sym][:scroll][1]
  1443.     end
  1444.   end
  1445.  
  1446.   def dispose_all_windows
  1447.     @grid.dispose
  1448.     @helpy.dispose
  1449.     @backs.each_value {|s| s.bitmap.dispose; s.dispose}
  1450.     super
  1451.   end
  1452.  
  1453. end
  1454.  
  1455. class SpriteGrid
  1456.  
  1457.   attr_accessor :key, :data, :index, :commands, :imgs,
  1458.                 :current, :current_sym, :active, :visible, :enabled
  1459.  
  1460.   def initialize(key,grid,data,folder,flash,zoom,move,sound,buttons,arrows,
  1461.                  back=nil,active=true,init_index=[0,0])
  1462.     @key = key          # The identifier for the grid "window".
  1463.     @grid = grid        # The grid settings.
  1464.     @data = data        # The command settings.
  1465.     @folder = folder    # The image folder used for images.
  1466.     @flash = flash      # The flash settings.
  1467.     @zoom = zoom        # The zoom settings.
  1468.     @move = move        # The move settings.
  1469.     @sound = sound      # The sound settings.
  1470.     @buttons = buttons  # The button settings.
  1471.     @arrows = arrows    # The arrow settings.
  1472.     @back = back if back[:img] != "" # The background settings.
  1473.     @active = active
  1474.     @visible = false
  1475.     @index = init_index # The current position - [row,col].
  1476.     zt = @active == true ? :active : :inactive
  1477.     @zoom_level = @zoom[:grid][zt].clone
  1478.     @counter = {}; @pattern = {}
  1479.     [:back,:cmds].each {|sym| @counter[sym] = 0; @pattern[sym] = 0}
  1480.     [:left,:right,:up,:down].each {|sym| @counter[sym] = 0; @pattern[sym] = 0}
  1481.     init_viewport
  1482.     init_back if @back
  1483.     init_commands
  1484.     init_imgs
  1485.     if @commands.size > 0
  1486.       @current_sym = @sym_pos.find {|sym,pos| pos == @index}[0]
  1487.     end
  1488.     init_arrows
  1489.   end
  1490.  
  1491.   def init_viewport
  1492.     ww = @grid[:view][:size][0]
  1493.     hh = @grid[:view][:size][1]    
  1494.     xx = DynXY.get_x(@grid[:view][:pos][0],ww)
  1495.     yy = DynXY.get_y(@grid[:view][:pos][1],hh)
  1496.     @view = Viewport.new(xx,yy,ww,hh)
  1497.     @view.z = @grid[:view][:z]
  1498.     @vhorz = {:top => 0, :bottom => horz_imax - 1, :dest => 0, :spd => 0.0, :add => 0.0}
  1499.     @vvert = {:top => 0, :bottom => vert_imax - 1, :dest => 0, :spd => 0.0, :add => 0.0}
  1500.   end
  1501.  
  1502.   def init_back
  1503.     @bimg = Sprite.new
  1504.     @bimg.bitmap = Cache.custom_imgs(@back[:img],@folder)
  1505.     if @back[:cols]
  1506.       @bimg.src_rect.width = @bimg.bitmap.width / @back[:cols]
  1507.       @bimg.oy = @bimg.bitmap.height / 2
  1508.       @bimg.ox = @bimg.src_rect.width / 2
  1509.       ww = @bimg.src_rect.width
  1510.       hh = @bimg.bitmap.height
  1511.       @bimg.src_rect.x = @back[:frames][@pattern[:back]] * @bimg.src_rect.width
  1512.     else
  1513.       @bimg.src_rect.height = @bimg.bitmap.height / @back[:rows]
  1514.       @bimg.ox = @bimg.bitmap.width / 2
  1515.       @bimg.oy = @bimg.src_rect.height / 2
  1516.       ww = @bimg.bitmap.width
  1517.       hh = @bimg.src_rect.height
  1518.       @bimg.src_rect.y = @back[:frames][@pattern[:back]] * @bimg.src_rect.height
  1519.     end
  1520.     x = DynXY.get_x(@back[:pos][0],ww,@bimg.ox)
  1521.     y = DynXY.get_y(@back[:pos][1],hh,@bimg.oy)
  1522.     if @back[:zoom]
  1523.       @bimg.zoom_x = @zoom_level[0]
  1524.       @bimg.zoom_y = @zoom_level[1]
  1525.     end
  1526.     @bimg.x = x
  1527.     @bimg.y = y
  1528.     @bimg.opacity = @back[:opa]
  1529.     @bimg.z = @back[:z]
  1530.   end
  1531.  
  1532.   def init_commands
  1533.     @commands = []; @show = {}
  1534.     @data.each do |k,dt|
  1535.       next if k == :empty
  1536.       @commands << k if check_info(k,:show)
  1537.     end
  1538.     if @commands.empty?
  1539.       @commands << :empty
  1540.     end
  1541.   end
  1542.        
  1543.   def init_imgs
  1544.     @imgs = {}; @enabled = {}; row = col = 0; @iopa = {}; @add_pos = [0,0]
  1545.     @ipos = {}; @sym_pos = {}; @get_sym = {}; @max_row = {}; @max_col = {}
  1546.     @commands.each do |sym|
  1547.       dt = @data[sym]
  1548.       init_img(sym,dt,row,col)
  1549.       col += 1
  1550.       col += dt[:skip_col] if dt[:skip_col]
  1551.       @add_pos[0] = 0 if dt[:add_reset] && dt[:add_reset].include?(:x)
  1552.       @add_pos[1] = 0 if dt[:add_reset] && dt[:add_reset].include?(:y)
  1553.       if dt[:add_pos]
  1554.         @add_pos[0] += dt[:add_pos][0]
  1555.         @add_pos[1] += dt[:add_pos][1]
  1556.       end
  1557.       if col > @grid[:max_cols] - 1
  1558.         col = 0; row += 1
  1559.       end
  1560.       if dt[:skip_row]
  1561.         row += dt[:skip_row]; col = 0
  1562.       end
  1563.     end
  1564.   end
  1565.    
  1566.   def init_img(sym,dt,row,col)
  1567.     @imgs[[row,col]] = SpriteCmd.new(@view)
  1568.     @enabled[[row,col]] = check_info(sym,:enable)
  1569.     if @enabled[[row,col]]
  1570.       pic = @index == [[row,col]] ? :ea : :ei
  1571.     else
  1572.       pic = @index == [[row,col]] ? :da : :di
  1573.     end
  1574.     @imgs[[row,col]].bitmap = Cache.custom_imgs(dt[pic],@folder).clone
  1575.     @imgs[[row,col]].bitmap_name = dt[pic]
  1576.     if dt[:cols]
  1577.       @imgs[[row,col]].src_rect.width = @imgs[[row,col]].bitmap.width / dt[:cols]
  1578.       @imgs[[row,col]].oy = @imgs[[row,col]].bitmap.height/2
  1579.       @imgs[[row,col]].ox = @imgs[[row,col]].src_rect.width/2
  1580.       @imgs[[row,col]].src_rect.x = dt[:frames][@pattern[:cmds]] * @imgs[[row,col]].src_rect.width
  1581.     else
  1582.       @imgs[[row,col]].src_rect.height = @imgs[[row,col]].bitmap.height / dt[:rows]
  1583.       @imgs[[row,col]].ox = @imgs[[row,col]].bitmap.width/2
  1584.       @imgs[[row,col]].oy = @imgs[[row,col]].src_rect.height/2
  1585.       @imgs[[row,col]].src_rect.y = dt[:frames][@pattern[:cmds]] * @imgs[[row,col]].src_rect.height
  1586.     end
  1587.     if sym == :empty
  1588.       x = @view.rect.width/2
  1589.       y = @view.rect.height/2
  1590.     else
  1591.       x = col * (@grid[:isize][0] + @grid[:spacing][0]) + @grid[:isize][0]/2 + @grid[:padding][:l]
  1592.       y = row * (@grid[:isize][1] + @grid[:spacing][1]) + @grid[:isize][1]/2 + @grid[:padding][:u]
  1593.     end
  1594.     @imgs[[row,col]].x = x + @add_pos[0]
  1595.     @imgs[[row,col]].y = y + @add_pos[1]
  1596.     if row.between?(@vvert[:top],@vvert[:bottom]) &&
  1597.        col.between?(@vhorz[:top],@vhorz[:bottom])
  1598.       @imgs[[row,col]].opacity = dt[:opa][@enabled[[row,col]] ? 0 : 1]
  1599.     else
  1600.       @imgs[[row,col]].opacity = 0
  1601.     end
  1602.     @imgs[[row,col]].z = dt[:z][@index == [[row,col]] ? 0 : 1]
  1603.     @imgs[[row,col]].zoom_x = @zoom[pic][:limit][0] * @zoom_level[0]
  1604.     @imgs[[row,col]].zoom_y = @zoom[pic][:limit][1] * @zoom_level[1]
  1605.     # Grid variables:
  1606.     @ipos[[row,col]] = [@imgs[[row,col]].x,@imgs[[row,col]].y]
  1607.     @iopa[[row,col]] = {:dest => @imgs[[row,col]].opacity, :spd => 0, :add => 0}
  1608.     @sym_pos[sym] = [row,col]
  1609.     @get_sym[[row,col]] = sym
  1610.     @max_row[col] = row
  1611.     @max_col[row] = col
  1612.   end
  1613.  
  1614.   def init_arrows
  1615.     @aimgs = {}
  1616.     return if @arrows.nil?
  1617.     @arrows.each do |key,dt|
  1618.       next if dt.nil?
  1619.       @aimgs[key] = Sprite.new
  1620.       @aimgs[key].bitmap = Cache.custom_imgs(dt[:img],@folder)
  1621.       if dt[:cols]
  1622.         @aimgs[key].src_rect.width = @aimgs[key].bitmap.width / dt[:cols]
  1623.         @aimgs[key].oy = @aimgs[key].bitmap.height / 2
  1624.         @aimgs[key].ox = @aimgs[key].src_rect.width / 2
  1625.         ww = @aimgs[key].src_rect.width
  1626.         hh = @aimgs[key].bitmap.height
  1627.         @aimgs[key].src_rect.x = dt[:frames][@pattern[key]] * @aimgs[key].src_rect.width
  1628.       else
  1629.         @aimgs[key].src_rect.height = @aimgs[key].bitmap.height / dt[:rows]
  1630.         @aimgs[key].ox = @aimgs[key].bitmap.width / 2
  1631.         @aimgs[key].oy = @aimgs[key].src_rect.height / 2
  1632.         ww = @aimgs[key].bitmap.width
  1633.         hh = @aimgs[key].src_rect.height
  1634.         @aimgs[key].src_rect.y = dt[:frames][@pattern[key]] * @aimgs[key].src_rect.height
  1635.       end
  1636.       x = DynXY.get_x(dt[:pos][0],ww,@aimgs[key].ox)
  1637.       y = DynXY.get_y(dt[:pos][1],hh,@aimgs[key].oy)
  1638.       @aimgs[key].x = x
  1639.       @aimgs[key].y = y
  1640.       @aimgs[key].z = dt[:z]
  1641.       @aimgs[key].opacity = dt[:opa]
  1642.       set_arrow_vis(@aimgs[key],key)
  1643.     end
  1644.   end
  1645.  
  1646.   def width
  1647.     return @view.rect.width
  1648.   end
  1649.  
  1650.   def height
  1651.     return @view.rect.height
  1652.   end
  1653.  
  1654.   def max_cols
  1655.     return @max_col.values.max
  1656.   end
  1657.  
  1658.   def max_rows
  1659.     return @max_row.values.max
  1660.   end
  1661.  
  1662.   def horz_size
  1663.     @view.rect.width - (@grid[:padding][:l] + @grid[:padding][:r]) + @grid[:spacing][0]
  1664.   end
  1665.  
  1666.   def vert_size
  1667.     @view.rect.height - (@grid[:padding][:u] + @grid[:padding][:d]) + @grid[:spacing][1]
  1668.   end
  1669.  
  1670.   def horz_imax # max visible columns
  1671.     horz_size / (@grid[:isize][0] + @grid[:spacing][0])
  1672.   end
  1673.  
  1674.   def vert_imax # max visible rows
  1675.     vert_size / (@grid[:isize][1] + @grid[:spacing][1])
  1676.   end
  1677.  
  1678.   def x=(val)
  1679.     @view.rect.x = val
  1680.   end
  1681.  
  1682.   def y=(val)
  1683.     @view.rect.y = val
  1684.   end
  1685.  
  1686.   def check_zoom(val)
  1687.     return @imgs[@index].zoom_x == val[0] && @imgs[@index].zoom_y == val[1]
  1688.   end
  1689.  
  1690.   def set_arrow_vis(img,key)
  1691.     if !@visible
  1692.       img.visible = false if img.visible
  1693.       return
  1694.     end
  1695.     case key
  1696.     when :up
  1697.       if @vvert[:top] > 0
  1698.         img.visible = true if !img.visible
  1699.       else
  1700.         img.visible = false if img.visible
  1701.       end
  1702.     when :down
  1703.       if @vvert[:bottom] < self.max_rows
  1704.         img.visible = true if !img.visible
  1705.       else
  1706.         img.visible = false if img.visible
  1707.       end
  1708.     when :left
  1709.       if @vhorz[:top] > 0
  1710.         img.visible = true if !img.visible
  1711.       else
  1712.         img.visible = false if img.visible
  1713.       end
  1714.     when :right
  1715.       if @vhorz[:bottom] < self.max_cols
  1716.         img.visible = true if !img.visible
  1717.       else
  1718.         img.visible = false if img.visible
  1719.       end
  1720.     end
  1721.   end
  1722.      
  1723.   def check_info(sym,type)
  1724.     case @data[sym][type]
  1725.     when Integer
  1726.       return $game_switches[@data[sym][type]]
  1727.     when Symbol
  1728.       return method(@data[sym][type]).call
  1729.     when String
  1730.       return eval(@data[sym][type])
  1731.     when Array
  1732.       return method(@data[sym][type][0]).call(*@data[sym][type][1])
  1733.     else
  1734.       return @data[sym][type]
  1735.     end
  1736.   end
  1737.    
  1738.   def activate(z_lvl=nil,u_help=false)
  1739.     zx = z_lvl.nil? ? @zoom[:grid][:active][0] : z_lvl[0]
  1740.     zy = z_lvl.nil? ? @zoom[:grid][:active][1] : z_lvl[1]
  1741.     @zoom_level[0] = zx
  1742.     @zoom_level[1] = zy
  1743.     @active = true
  1744.     update_help if u_help
  1745.   end
  1746.  
  1747.   def deactivate(z_lvl=nil)
  1748.     zx = z_lvl.nil? ? @zoom[:grid][:inactive][0] : z_lvl[0]
  1749.     zy = z_lvl.nil? ? @zoom[:grid][:inactive][1] : z_lvl[1]
  1750.     @zoom_level[0] = zx
  1751.     @zoom_level[1] = zy
  1752.     @active = false
  1753.     reset_frame
  1754.   end
  1755.  
  1756.   def show
  1757.     @imgs.each do |key,img|
  1758.       set_img_visibility(key,img,true)
  1759.     end
  1760.     @bimg.visible = true if @back
  1761.     @visible = true
  1762.     @aimgs.each {|key,img| set_arrow_vis(img,key) } if @aimgs
  1763.   end
  1764.  
  1765.   def hide
  1766.     @imgs.each do |key,img|
  1767.       set_img_visibility(key,img,false)
  1768.     end
  1769.     @bimg.visible = false if @back
  1770.     @visible = false
  1771.     @aimgs.each {|key,img| img.visible = false } if @aimgs
  1772.   end
  1773.  
  1774.   def set_img_visibility(key,img,state)
  1775.     img.visible = state
  1776.   end
  1777.  
  1778.   def select_sym(sym)
  1779.     before = @index
  1780.     b_sym = @current_sym
  1781.     reset_frame
  1782.     @index = @sym_pos[sym]
  1783.     @index = before if @index.nil?
  1784.     @current_sym = @sym_pos.find {|sym,pos| pos == @index}[0]
  1785.     @aimgs.each {|key,img| set_arrow_vis(img,key) } if @aimgs
  1786.     update_help if before != @index || b_sym != @current_sym
  1787.   end
  1788.  
  1789.   def refresh
  1790.     before = @index
  1791.     b_sym = @current_sym
  1792.     @imgs.each {|k,sp| sp.dispose}
  1793.     init_commands
  1794.     init_imgs
  1795.     @index = before
  1796.     @index = [0,0] if @index.nil?
  1797.     @current_sym = @sym_pos.find {|sym,pos| pos == @index}[0]
  1798.     @aimgs.each {|key,img| set_arrow_vis(img,key) } if @aimgs
  1799.     update_help if before != @index || b_sym != @current_sym
  1800.   end
  1801.    
  1802.   def update
  1803.     return if @disposed || !@visible
  1804.     update_command_images if @commands.size > 0
  1805.     update_back_img if @back && @back[:zoom]
  1806.     update_view
  1807.     update_arrows if @aimgs
  1808.     if @active == true
  1809.       update_back_frames if @back
  1810.       update_sprite_frames if @commands.size > 0
  1811.       update_cursor if @commands.size > 0
  1812.       update_confirm if Input.trigger?(@buttons[:confirm])
  1813.       update_cancel if Input.trigger?(@buttons[:cancel])
  1814.     end
  1815.   end
  1816.  
  1817.   def update_back_img
  1818.     if @bimg.zoom_x < @zoom_level[0]
  1819.       @bimg.zoom_x += @back[:zspeed][0]
  1820.       @bimg.zoom_x = @zoom_level[0] if @bimg.zoom_x > @zoom_level[0]
  1821.     elsif @bimg.zoom_x > @zoom_level[0]
  1822.       @bimg.zoom_x -= @back[:zspeed][0]
  1823.       @bimg.zoom_x = @zoom_level[0] if @bimg.zoom_x < @zoom_level[0]
  1824.     end
  1825.     if @bimg.zoom_y < @zoom_level[1]
  1826.       @bimg.zoom_y += @back[:zspeed][1]
  1827.       @bimg.zoom_y = @zoom_level[1] if @bimg.zoom_y > @zoom_level[1]
  1828.     elsif @bimg.zoom_y > @zoom_level[1]
  1829.       @bimg.zoom_y -= @back[:zspeed][1]
  1830.       @bimg.zoom_y = @zoom_level[1] if @bimg.zoom_y < @zoom_level[1]
  1831.     end
  1832.   end
  1833.  
  1834.   def update_cursor
  1835.     move_left if Input.trigger?(@buttons[:prev_col]) || Input.repeat?(@buttons[:prev_col])
  1836.     move_right if Input.trigger?(@buttons[:next_col]) || Input.repeat?(@buttons[:next_col])
  1837.     move_up if Input.trigger?(@buttons[:prev_row]) || Input.repeat?(@buttons[:prev_row])
  1838.     move_down if Input.trigger?(@buttons[:next_row]) || Input.repeat?(@buttons[:next_row])
  1839.   end
  1840.      
  1841.   def correct_ox
  1842.     @vhorz[:dest] = @vhorz[:top] * (@grid[:isize][0] + @grid[:spacing][0])
  1843.     @vhorz[:spd] = (@vhorz[:dest] - @view.ox)/@grid[:scroll_time].to_f
  1844.     @vhorz[:add] = 0
  1845.     correct_imgs_opa
  1846.     @aimgs.each {|key,img| set_arrow_vis(img,key) } if @aimgs
  1847.   end
  1848.    
  1849.   def correct_oy
  1850.     @vvert[:dest] = @vvert[:top] * (@grid[:isize][1] + @grid[:spacing][1])
  1851.     @vvert[:spd] = (@vvert[:dest] - @view.oy)/@grid[:scroll_time].to_f
  1852.     @vvert[:add] = 0
  1853.     correct_imgs_opa
  1854.     @aimgs.each {|key,img| set_arrow_vis(img,key) } if @aimgs
  1855.   end
  1856.  
  1857.   def correct_imgs_opa
  1858.     @imgs.each do |key,img|
  1859.       if key[0].between?(@vvert[:top],@vvert[:bottom]) &&
  1860.          key[1].between?(@vhorz[:top],@vhorz[:bottom])
  1861.         ori_opa = @data[@get_sym[key]][:opa][@enabled[key] ? 0 : 1]
  1862.         @iopa[key][:dest] = ori_opa
  1863.         @iopa[key][:spd] = (@iopa[key][:dest] - img.opacity)/@grid[:scroll_time].to_f
  1864.         @iopa[key][:add] = 0
  1865.       else
  1866.         @iopa[key][:dest] = 0
  1867.         @iopa[key][:spd] = (@iopa[key][:dest] - img.opacity)/@grid[:scroll_time].to_f
  1868.         @iopa[key][:add] = 0
  1869.       end
  1870.     end
  1871.   end
  1872.  
  1873.   def update_opacity(key,img)
  1874.     if img.opacity < @iopa[key][:dest]
  1875.       @iopa[key][:add] += @iopa[key][:spd]
  1876.       img.opacity = img.opacity + @iopa[key][:add]
  1877.       img.opacity = @iopa[key][:dest] if img.opacity > @iopa[key][:dest]
  1878.     elsif img.opacity > @iopa[key][:dest]
  1879.       @iopa[key][:add] += @iopa[key][:spd]
  1880.       img.opacity = img.opacity + @iopa[key][:add]
  1881.       img.opacity = @iopa[key][:dest] if img.opacity < @iopa[key][:dest]
  1882.     end
  1883.   end
  1884.  
  1885.   def update_view
  1886.     if @view.ox < @vhorz[:dest]
  1887.       @vhorz[:add] += @vhorz[:spd]
  1888.       @view.ox = @view.ox + @vhorz[:add]
  1889.       @view.ox = @vhorz[:dest] if @view.ox > @vhorz[:dest]
  1890.     elsif @view.ox > @vhorz[:dest]
  1891.       @vhorz[:add] += @vhorz[:spd]
  1892.       @view.ox = @view.ox + @vhorz[:add]
  1893.       @view.ox = @vhorz[:dest] if @view.ox < @vhorz[:dest]
  1894.     end
  1895.     if @view.oy < @vvert[:dest]
  1896.       @vvert[:add] += @vvert[:spd]
  1897.       @view.oy = @view.oy + @vvert[:add]
  1898.       @view.oy = @vvert[:dest] if @view.oy > @vvert[:dest]
  1899.     elsif @view.oy > @vvert[:dest]
  1900.       @vvert[:add] += @vvert[:spd]
  1901.       @view.oy = @view.oy + @vvert[:add]
  1902.       @view.oy = @vvert[:dest] if @view.oy < @vvert[:dest]
  1903.     end
  1904.   end
  1905.  
  1906.   def move_left
  1907.     return if @max_col[@index[0]] <= 0
  1908.     @sound[:cursor].play
  1909.     reset_frame
  1910.     @index[1] -= 1
  1911.     if @index[1] < 0
  1912.       @index[1] = @max_col[@index[0]]
  1913.       force = true
  1914.     end
  1915.     while @imgs[@index].nil?
  1916.       @index[1] -= 1
  1917.       if @index[1] < 0
  1918.         @index[1] = @max_col[@index[0]]
  1919.         force = true
  1920.       end
  1921.     end
  1922.     @current_sym = @sym_pos.find {|sym,pos| pos == @index}[0]
  1923.     if force
  1924.       @vhorz[:bottom] = @index[1]
  1925.       @vhorz[:bottom] = horz_imax - 1 if @vhorz[:bottom] < horz_imax - 1
  1926.       @vhorz[:top] = @index[1] - (horz_imax - 1)
  1927.       @vhorz[:top] = 0 if @vhorz[:top] < 0
  1928.       correct_ox
  1929.     elsif !@index[1].between?(@vhorz[:top],@vhorz[:bottom])
  1930.       @vhorz[:top] = @index[1]
  1931.       @vhorz[:bottom] = @index[1] + horz_imax - 1
  1932.       @vhorz[:bottom] = self.max_cols if @vhorz[:bottom] > self.max_cols
  1933.       correct_ox
  1934.     end
  1935.     update_help
  1936.   end
  1937.  
  1938.   def move_right
  1939.     return if @max_col[@index[0]] <= 0
  1940.     @sound[:cursor].play
  1941.     reset_frame
  1942.     @index[1] += 1
  1943.     if @index[1] > @max_col[@index[0]]
  1944.       @index[1] = 0
  1945.       force = true
  1946.     end
  1947.     while @imgs[@index].nil?
  1948.       @index[1] += 1
  1949.       if @index[1] > @max_col[@index[0]]
  1950.         @index[1] = 0
  1951.         force = true
  1952.       end
  1953.     end
  1954.     @current_sym = @sym_pos.find {|sym,pos| pos == @index}[0]
  1955.     if force
  1956.       @vhorz[:top] = @index[1]
  1957.       @vhorz[:bottom] = @index[1] + horz_imax - 1
  1958.       @vhorz[:bottom] = self.max_cols if @vhorz[:bottom] > self.max_cols
  1959.       correct_ox
  1960.     elsif !@index[1].between?(@vhorz[:top],@vhorz[:bottom])
  1961.       @vhorz[:bottom] = @index[1]
  1962.       @vhorz[:bottom] = horz_imax - 1 if @vhorz[:bottom] < horz_imax - 1
  1963.       @vhorz[:top] = @index[1] - (horz_imax - 1)
  1964.       @vhorz[:top] = 0 if @vhorz[:top] < 0
  1965.       correct_ox
  1966.     end
  1967.     update_help
  1968.   end
  1969.  
  1970.   def move_up
  1971.     return if @max_row[@index[1]] <= 0
  1972.     @sound[:cursor].play
  1973.     reset_frame
  1974.     @index[0] -= 1
  1975.     if @index[0] < 0
  1976.       @index[0] = @max_row[@index[1]]
  1977.       force = true
  1978.     end
  1979.     while @imgs[@index].nil?
  1980.       @index[0] -= 1
  1981.       if @index[0] < 0
  1982.         @index[0] = @max_row[@index[1]]
  1983.         force = true
  1984.       end
  1985.     end
  1986.     @current_sym = @sym_pos.find {|sym,pos| pos == @index}[0]
  1987.     if force
  1988.       @vvert[:bottom] = @index[0]
  1989.       @vvert[:bottom] = vert_imax - 1 if @vvert[:bottom] < vert_imax - 1
  1990.       @vvert[:top] = @index[0] - (vert_imax - 1)
  1991.       @vvert[:top] = 0 if @vvert[:top] < 0
  1992.       correct_oy
  1993.     elsif !@index[0].between?(@vvert[:top],@vvert[:bottom])
  1994.       @vvert[:top] = @index[0]
  1995.       @vvert[:bottom] = @index[0] + vert_imax - 1
  1996.       @vvert[:bottom] = self.max_rows if @vvert[:bottom] > self.max_rows
  1997.       correct_oy
  1998.     end
  1999.     update_help
  2000.   end
  2001.  
  2002.   def move_down
  2003.     return if @max_row[@index[1]] <= 0
  2004.     @sound[:cursor].play
  2005.     reset_frame
  2006.     @index[0] += 1
  2007.     if @index[0] > @max_row[@index[1]]
  2008.       @index[0] = 0
  2009.       force = true
  2010.     end
  2011.     while @imgs[@index].nil?
  2012.       @index[0] += 1
  2013.       if @index[0] > @max_row[@index[1]]
  2014.         @index[0] = 0
  2015.         force = true
  2016.       end
  2017.     end
  2018.     @current_sym = @sym_pos.find {|sym,pos| pos == @index}[0]
  2019.     if force
  2020.       @vvert[:top] = @index[0]
  2021.       @vvert[:bottom] = @index[0] + vert_imax - 1
  2022.       @vvert[:bottom] = self.max_rows if @vvert[:bottom] > self.max_rows
  2023.       correct_oy
  2024.     elsif !@index[0].between?(@vvert[:top],@vvert[:bottom])
  2025.       @vvert[:bottom] = @index[0]
  2026.       @vvert[:bottom] = vert_imax - 1 if @vvert[:bottom] < vert_imax - 1
  2027.       @vvert[:top] = @index[0] - (vert_imax - 1)
  2028.       @vvert[:top] = 0 if @vvert[:top] < 0
  2029.       correct_oy
  2030.     end
  2031.     update_help
  2032.   end
  2033.  
  2034.   def update_confirm
  2035.     if @enabled[@index] && @commands.size > 0
  2036.       @sound[:confirm].play
  2037.       Input.update
  2038.       @imgs[@index].flash(*@flash[:enabled].values) if @flash[:enabled]
  2039.       SceneManager.scene.trigger_command(@key,@current_sym)
  2040.     else
  2041.       @sound[:disabled].play
  2042.       return if @commands.size <= 0
  2043.       @imgs[@index].flash(*@flash[:disabled].values) if @flash[:disabled]
  2044.     end
  2045.   end
  2046.    
  2047.   def update_cancel
  2048.     @sound[:cancel].play
  2049.     Input.update
  2050.     SceneManager.scene.cancel_command(@key,@current_sym)
  2051.   end
  2052.  
  2053.   def update_command_images
  2054.     @imgs.each do |key,img|
  2055.       next if img.nil? || img.disposed?
  2056.       update_img(key,img)
  2057.     end
  2058.   end
  2059.    
  2060.   def update_arrows
  2061.     @aimgs.each do |key,img|
  2062.       next if img.nil? || img.disposed?
  2063.       update_arrow_frames(key)
  2064.     end
  2065.   end
  2066.  
  2067.   def reset_frame
  2068.     @counter[:cmds] = 0; @pattern[:cmds] = 0
  2069.     if @data[@current_sym][:cols]
  2070.       @imgs[@index].src_rect.x = @data[@current_sym][:frames][@pattern[:cmds]] * @imgs[@index].src_rect.width
  2071.     else
  2072.       @imgs[@index].src_rect.y = @data[@current_sym][:frames][@pattern[:cmds]] * @imgs[@index].src_rect.height
  2073.     end
  2074.   end
  2075.  
  2076.   def reset_img(key,img,type)
  2077.     return if img.bitmap_name == @data[@get_sym[key]][type]
  2078.     img.bitmap.dispose unless img.bitmap.disposed?
  2079.     img.bitmap = Cache.custom_imgs(@data[@get_sym[key]][type],@folder).clone
  2080.     img.bitmap_name = @data[@get_sym[key]][type]
  2081.     if @data[@get_sym[key]][:cols]
  2082.       img.src_rect.width = img.bitmap.width / @data[@get_sym[key]][:cols]
  2083.       img.oy = img.bitmap.height/2
  2084.       img.ox = img.src_rect.width/2
  2085.       img.src_rect.x = @data[@get_sym[key]][:frames][@pattern[:cmds]] * img.src_rect.width
  2086.     else
  2087.       img.src_rect.height = img.bitmap.height / @data[@get_sym[key]][:rows]
  2088.       img.ox = img.bitmap.width/2
  2089.       img.oy = img.src_rect.height/2
  2090.       img.src_rect.y = @data[@get_sym[key]][:frames][@pattern[:cmds]] * img.src_rect.height
  2091.     end
  2092.   end
  2093.  
  2094.   def update_zoom_eff(img,type)
  2095.     if img.zoom_x > @zoom[type][:limit][0] * @zoom_level[0]
  2096.       img.zoom_x -= @zoom[type][:speed][0]
  2097.       img.zoom_x = @zoom[type][:limit][0] * @zoom_level[0] if img.zoom_x < @zoom[type][:limit][0] * @zoom_level[0]
  2098.     elsif img.zoom_x < @zoom[type][:limit][0] * @zoom_level[0]
  2099.       img.zoom_x += @zoom[type][:speed][0]
  2100.       img.zoom_x = @zoom[type][:limit][0] * @zoom_level[0] if img.zoom_x > @zoom[type][:limit][0] * @zoom_level[0]
  2101.     end
  2102.     if img.zoom_y > @zoom[type][:limit][1] * @zoom_level[1]
  2103.       img.zoom_y -= @zoom[type][:speed][1]
  2104.       img.zoom_y = @zoom[type][:limit][1] * @zoom_level[1] if img.zoom_y < @zoom[type][:limit][1] * @zoom_level[1]
  2105.     elsif img.zoom_y < @zoom[type][:limit][1] * @zoom_level[1]
  2106.       img.zoom_y += @zoom[type][:speed][1]
  2107.       img.zoom_y = @zoom[type][:limit][1] * @zoom_level[1] if img.zoom_y > @zoom[type][:limit][1] * @zoom_level[1]
  2108.     end
  2109.   end
  2110.    
  2111.   def update_img(key,img)
  2112.     img.update
  2113.     update_opacity(key,img)
  2114.     if @index == key
  2115.       if @enabled[key] == true
  2116.         reset_img(key,img,:ea)
  2117.       elsif @enabled[key] == false
  2118.         reset_img(key,img,:da)
  2119.       end
  2120.       img.z = @data[@get_sym[key]][:z][0] if img.z != @data[@get_sym[key]][:z][0]
  2121.       if @active == true
  2122.         update_zoom_eff(img,:ea)
  2123.         if img.x != @ipos[key][0]
  2124.           img.x -= @move[:speed][0] if img.x > @ipos[key][0]
  2125.           img.x += @move[:speed][0] if img.x < @ipos[key][0]
  2126.         end
  2127.         if img.y != @ipos[key][1]
  2128.           img.y -= @move[:speed][1] if img.y > @ipos[key][1]
  2129.           img.y += @move[:speed][1] if img.y < @ipos[key][1]
  2130.         end
  2131.       else
  2132.         update_zoom_eff(img,:sel)
  2133.         if img.x != @ipos[key][0] + @move[:dist][0]
  2134.           img.x -= @move[:speed][0] if img.x > @ipos[key][0] + @move[:dist][0]
  2135.           img.x += @move[:speed][0] if img.x < @ipos[key][0] + @move[:dist][0]
  2136.         end
  2137.         if img.y != @ipos[key][1] + @move[:dist][1]
  2138.           img.y -= @move[:speed][1] if img.y > @ipos[key][1] + @move[:dist][1]
  2139.           img.y += @move[:speed][1] if img.y < @ipos[key][1] + @move[:dist][1]
  2140.         end
  2141.       end
  2142.     else
  2143.       if @enabled[key] == true
  2144.         reset_img(key,img,:ei)
  2145.       elsif @enabled[key] == false
  2146.         reset_img(key,img,:di)
  2147.       end
  2148.       img.z = @data[@get_sym[key]][:z][1] if img.z != @data[@get_sym[key]][:z][1]
  2149.       update_zoom_eff(img,:ei)
  2150.       if img.x != @ipos[key][0]
  2151.         img.x -= @move[:speed][0] if img.x > @ipos[key][0]
  2152.         img.x += @move[:speed][0] if img.x < @ipos[key][0]
  2153.       end
  2154.       if img.y != @ipos[key][1]
  2155.         img.y -= @move[:speed][1] if img.y > @ipos[key][1]
  2156.         img.y += @move[:speed][1] if img.y < @ipos[key][1]
  2157.       end
  2158.     end
  2159.   end
  2160.  
  2161.   def update_sprite_frames
  2162.     @counter[:cmds] += 1
  2163.     if @counter[:cmds] % @data[@current_sym][:wait] == 0      
  2164.       @pattern[:cmds] += 1
  2165.       @pattern[:cmds] = 0 if @pattern[:cmds] >= @data[@current_sym][:frames].size
  2166.       if @data[@current_sym][:cols]
  2167.         @imgs[@index].src_rect.x = @data[@current_sym][:frames][@pattern[:cmds]] * @imgs[@index].src_rect.width
  2168.       else
  2169.         @imgs[@index].src_rect.y = @data[@current_sym][:frames][@pattern[:cmds]] * @imgs[@index].src_rect.height
  2170.       end
  2171.     end
  2172.   end
  2173.  
  2174.   def update_arrow_frames(key)
  2175.     @counter[key] += 1
  2176.     if @counter[key] % @arrows[key][:wait] == 0      
  2177.       @pattern[key] += 1
  2178.       @pattern[key] = 0 if @pattern[key] >= @arrows[key][:frames].size
  2179.       if @arrows[key][:cols]
  2180.         @aimgs[key].src_rect.x = @arrows[key][:frames][@pattern[key]] * @aimgs[key].src_rect.width
  2181.       else
  2182.         @aimgs[key].src_rect.y = @arrows[key][:frames][@pattern[key]] * @aimgs[key].src_rect.height
  2183.       end
  2184.     end
  2185.   end
  2186.  
  2187.   def update_back_frames
  2188.     @counter[:back] += 1
  2189.     if @counter[:back] % @back[:wait] == 0
  2190.       @pattern[:back] += 1
  2191.       @pattern[:back] = 0 if @pattern[:back] >= @back[:frames].size
  2192.       if @back[:cols]
  2193.         @bimg.src_rect.x = @back[:frames][@pattern[:back]] * @bimg.src_rect.width
  2194.       else
  2195.         @bimg.src_rect.y = @back[:frames][@pattern[:back]] * @bimg.src_rect.height
  2196.       end
  2197.     end
  2198.   end
  2199.  
  2200.   def update_help
  2201.     SceneManager.scene.update_help(@key,@current_sym)
  2202.   end
  2203.  
  2204.   def disposed?
  2205.     return @disposed
  2206.   end
  2207.  
  2208.   def dispose
  2209.     @imgs.each_value {|sp| sp.dispose}
  2210.     if @back
  2211.       @bimg.bitmap.dispose
  2212.       @bimg.dispose
  2213.     end
  2214.     @aimgs.each_value {|img| img.bitmap.dispose; img.dispose }
  2215.     @view.dispose
  2216.     @disposed = true
  2217.   end
  2218.  
  2219. end
  2220.  
  2221. class SpriteCmd < Sprite
  2222.  
  2223.   attr_accessor :bitmap_name
  2224.  
  2225.   def dispose
  2226.     self.bitmap.dispose if self.bitmap
  2227.     super
  2228.   end
  2229.  
  2230. end
  2231.  
  2232. class SpriteHelp
  2233.  
  2234.   attr_accessor :data
  2235.  
  2236.   def initialize(data,folder="",init_pic="")
  2237.     @data = data; @folder = folder
  2238.     init_pic = init_pic.to_s unless init_pic.is_a?(String)
  2239.     @pic = init_pic
  2240.     init_img
  2241.   end
  2242.  
  2243.   def init_img
  2244.     @img = Sprite.new
  2245.     @img.z = @data[:z]
  2246.     @img.opacity = @data[:opa]
  2247.     unless @pic.empty? || @folder.empty?
  2248.       @img.bitmap = Cache.custom_imgs(@pic,@folder)
  2249.       @img.ox = @img.bitmap.width/2
  2250.       @img.oy = @img.bitmap.height/2
  2251.     end
  2252.     if @img.bitmap
  2253.       x = DynXY.get_x(@data[:pos][0],@img.bitmap.width,@img.ox)
  2254.       y = DynXY.get_y(@data[:pos][1],@img.bitmap.height,@img.oy)
  2255.       @img.x = x; @img.y = y
  2256.     end
  2257.   end
  2258.  
  2259.   def hide
  2260.     @img.visible = false if @img
  2261.   end
  2262.  
  2263.   def show
  2264.     @img.visible = true if @img
  2265.   end
  2266.  
  2267.   def set_img(pic,folder,txt=nil)
  2268.     @pic = pic; @folder = folder
  2269.     @pic = @pic.to_s unless @pic.is_a?(String)
  2270.     @img.bitmap.dispose if @img.bitmap && !@img.bitmap.disposed?
  2271.     return if @pic.empty?
  2272.     @img.bitmap = Cache.custom_imgs(@pic,@folder)
  2273.     @img.ox = @img.bitmap.width/2
  2274.     @img.oy = @img.bitmap.height/2
  2275.     if @img.bitmap && !@img.bitmap.disposed?
  2276.       x = DynXY.get_x(@data[:pos][0],@img.bitmap.width,@img.ox)
  2277.       y = DynXY.get_y(@data[:pos][1],@img.bitmap.height,@img.oy)
  2278.       @img.x = x; @img.y = y
  2279.     end
  2280.     if txt
  2281.       @img.bitmap.font.name = @data[:font][:type]
  2282.       @img.bitmap.font.size = @data[:font][:size]
  2283.       @img.bitmap.font.color = @data[:font][:color]
  2284.       y = @data[:tpos][1]; th = @data[:lheight]; al = @data[:talign]
  2285.       txt.each do |text|
  2286.         @img.bitmap.draw_text(@data[:tpos][0],y,@img.bitmap.width,th,text,al)
  2287.         y += th
  2288.       end
  2289.     end
  2290.   end
  2291.  
  2292.   def update
  2293.     @img.update
  2294.   end
  2295.  
  2296.   def dispose
  2297.     if @img && !@img.disposed?
  2298.       @img.bitmap.dispose if @img.bitmap && !@img.bitmap.disposed?
  2299.       @img.dispose
  2300.     end
  2301.   end
  2302.  
  2303. end
  2304. #==============================================================================
  2305. # !!END OF SCRIPT - OHH, NOES!!
  2306. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement