Grid Item Menu System

Grid Item Menu System
Version 1
By: EmuMaster2002 (If you choose to credit, please credit as Eathanu)

Introduction:
This is a relatively simple little item menu system that is the first script I've made basically on my own. Basically, instead of the item name being shown in the menu itself, it's in the description box, and the body of the menu is a grid of icons with little numbers beside them, like in a lot of Western RPGs and various MMORPGs (in my case directly inspired by Morrowind and to a lesser extent Neverwinter Nights 2). It's fairly minimalistic as far as editing goes, with only one or two small changes to Scene_Item itself, but a rewrite of Window_Help under a different name for compatibility reasons and a lot of changes to Window_Item. It's nothing hugely spectacular, but I've not seen any item menus like this before as far as I can remember.

Screenshots:
Content Hidden Show
The regular menu:
Image

As seen from battle:
Image


I didn't know how to make the help window work the same way in battle without breaking things or otherwise needing to rewrite a big important part of Scene_Battle 1, so I left it with just the description. I'm sure you can do it with aliasing, but I have no idea how that stuff works yet.

Script:
  1. #Grid Item Menu System
  2. #By Eathanu (or EmuMaster2002, as the case may be)
  3. #Posted as-is; I won't be able to offer much help if you run into problems.
  4.  
  5. #==============================================================================
  6. # ** Window_Help
  7. #------------------------------------------------------------------------------
  8. #  This window shows skill and item explanations along with actor status.
  9. #==============================================================================
  10.  
  11. class Window_Help_Item < Window_Base
  12.   #--------------------------------------------------------------------------
  13.   # * Object Initialization
  14.   #--------------------------------------------------------------------------
  15.   def initialize
  16.     super(0, 392, 640, 88)
  17.     self.contents = Bitmap.new(width - 32, height - 32)
  18.       if $game_temp.in_battle
  19.         self.y = 256
  20.         self.height = 88
  21.         self.back_opacity = 160
  22.       end
  23.   end
  24.   #--------------------------------------------------------------------------
  25.   # * Set Text
  26.   #  text  : text string displayed in window
  27.   #  align : alignment (0..flush left, 1..center, 2..flush right)
  28.   #--------------------------------------------------------------------------
  29.   def set_text(itemname, text, align = 0)
  30.     # If at least one part of text and alignment differ from last time
  31.     if itemname != @itemname or text != @text or align != @align
  32.       # Redraw text
  33.       self.contents.clear
  34.       self.contents.font.color = system_color
  35.       self.contents.draw_text(4, 0, self.width - 40, 32, itemname, 0)
  36.       self.contents.font.color = normal_color
  37.       self.contents.draw_text(4, 24, self.width - 40, 32, text, align)
  38.       @itemname = itemname
  39.       @text = text
  40.       @align = align
  41.       @actor = nil
  42.     end
  43.     self.visible = true
  44.   end
  45. end
  46.  
  47.  
  48. #==============================================================================
  49. # ** Window_Item
  50. #------------------------------------------------------------------------------
  51. #  This window displays items in possession on the item and battle screens.
  52. #==============================================================================
  53.  
  54. class Window_Item < Window_Selectable
  55.   #--------------------------------------------------------------------------
  56.   # * Object Initialization
  57.   #--------------------------------------------------------------------------
  58.   def initialize
  59.     super(0, 0, 640, 392)
  60.     @column_max = 10
  61.     refresh
  62.     self.index = 0
  63.     # If in battle, move window to center of screen
  64.     # and make it semi-transparent
  65.     if $game_temp.in_battle
  66.       self.y = 64
  67.       self.height = 256
  68.       self.back_opacity = 160
  69.     end
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # * Get Item
  73.   #--------------------------------------------------------------------------
  74.   def item
  75.     return @data[self.index]
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # * Refresh
  79.   #--------------------------------------------------------------------------
  80.   def refresh
  81.     if self.contents != nil
  82.       self.contents.dispose
  83.       self.contents = nil
  84.     end
  85.     @data = []
  86.     # Add item
  87.     for i in 1...$data_items.size
  88.       if $game_party.item_number(i) > 0
  89.         @data.push($data_items[i])
  90.       end
  91.     end
  92.     # Also add weapons and items if outside of battle
  93.     unless $game_temp.in_battle
  94.       for i in 1...$data_weapons.size
  95.         if $game_party.weapon_number(i) > 0
  96.           @data.push($data_weapons[i])
  97.         end
  98.       end
  99.       for i in 1...$data_armors.size
  100.         if $game_party.armor_number(i) > 0
  101.           @data.push($data_armors[i])
  102.         end
  103.       end
  104.     end
  105.     # If item count is not 0, make a bit map and draw all items
  106.     @item_max = @data.size
  107.     if @item_max > 0
  108.       self.contents = Bitmap.new(width - 32, row_max * 32)
  109.       for i in 0...@item_max
  110.         draw_item(i)
  111.       end
  112.     end
  113.   end
  114.   #--------------------------------------------------------------------------
  115.   # * Draw Item
  116.   #     index : item number
  117.   #--------------------------------------------------------------------------
  118.   def draw_item(index)
  119.     item = @data[index]
  120.     case item
  121.     when RPG::Item
  122.       number = $game_party.item_number(item.id)
  123.     when RPG::Weapon
  124.       number = $game_party.weapon_number(item.id)
  125.     when RPG::Armor
  126.       number = $game_party.armor_number(item.id)
  127.     end
  128.     x = 4 + index % 10 * 64
  129.     y = index / 10 * 32
  130.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  131.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  132.     bitmap = RPG::Cache.icon(item.icon_name)
  133.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), 255)
  134.     self.contents.font.size = 14
  135.     self.contents.draw_text(x + 2, y + 16, 24, 24, number.to_s, 2)
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # * Help Text Update
  139.   #--------------------------------------------------------------------------
  140.   def update_help
  141.       if $game_temp.in_battle
  142.         @help_window.set_text(self.item == nil ? "" : self.item.description)
  143.       else
  144.         @help_window.set_text(self.item == nil ? "" : self.item.name, self.item == nil ? "" : self.item.description)
  145.       end
  146.   end
  147. end
  148.  
  149.  
  150. #==============================================================================
  151. # ** Scene_Item
  152. #------------------------------------------------------------------------------
  153. #  This class performs item screen processing.
  154. #==============================================================================
  155.  
  156. class Scene_Item
  157.   #--------------------------------------------------------------------------
  158.   # * Main Processing
  159.   #--------------------------------------------------------------------------
  160.   def main
  161.     # Make help window, item window
  162.     @help_window = Window_Help_Item.new
  163.     @item_window = Window_Item.new
  164.     # Associate help window
  165.     @item_window.help_window = @help_window
  166.     # Make target window (set to invisible / inactive)
  167.     @target_window = Window_Target.new
  168.     @target_window.visible = false
  169.     @target_window.active = false
  170.     # Execute transition
  171.     Graphics.transition
  172.     # Main loop
  173.     loop do
  174.       # Update game screen
  175.       Graphics.update
  176.       # Update input information
  177.       Input.update
  178.       # Frame update
  179.       update
  180.       # Abort loop if screen is changed
  181.       if $scene != self
  182.         break
  183.       end
  184.     end
  185.     # Prepare for transition
  186.     Graphics.freeze
  187.     # Dispose of windows
  188.     @help_window.dispose
  189.     @item_window.dispose
  190.     @target_window.dispose
  191.   end
  192.   #--------------------------------------------------------------------------
  193.   # * Frame Update
  194.   #--------------------------------------------------------------------------
  195.   def update
  196.     # Update windows
  197.     @help_window.update
  198.     @item_window.update
  199.     @target_window.update
  200.     # If item window is active: call update_item
  201.     if @item_window.active
  202.       update_item
  203.       return
  204.     end
  205.     # If target window is active: call update_target
  206.     if @target_window.active
  207.       update_target
  208.       return
  209.     end
  210.   end
  211.   #--------------------------------------------------------------------------
  212.   # * Frame Update (when item window is active)
  213.   #--------------------------------------------------------------------------
  214.   def update_item
  215.     # If B button was pressed
  216.     if Input.trigger?(Input::B)
  217.       # Play cancel SE
  218.       $game_system.se_play($data_system.cancel_se)
  219.       # Switch to menu screen
  220.       $scene = Scene_Menu.new(0)
  221.       return
  222.     end
  223.     # If C button was pressed
  224.     if Input.trigger?(Input::C)
  225.       # Get currently selected data on the item window
  226.       @item = @item_window.item
  227.       # If not a use item
  228.       unless @item.is_a?(RPG::Item)
  229.         # Play buzzer SE
  230.         $game_system.se_play($data_system.buzzer_se)
  231.         return
  232.       end
  233.       # If it can't be used
  234.       unless $game_party.item_can_use?(@item.id)
  235.         # Play buzzer SE
  236.         $game_system.se_play($data_system.buzzer_se)
  237.         return
  238.       end
  239.       # Play decision SE
  240.       $game_system.se_play($data_system.decision_se)
  241.       # If effect scope is an ally
  242.       if @item.scope >= 3
  243.         # Activate target window
  244.         @item_window.active = false
  245.         @target_window.x = 0
  246.         @target_window.visible = true
  247.         @target_window.active = true
  248.         # Set cursor position to effect scope (single / all)
  249.         if @item.scope == 4 || @item.scope == 6
  250.           @target_window.index = -1
  251.         else
  252.           @target_window.index = 0
  253.         end
  254.       # If effect scope is other than an ally
  255.       else
  256.         # If command event ID is valid
  257.         if @item.common_event_id > 0
  258.           # Command event call reservation
  259.           $game_temp.common_event_id = @item.common_event_id
  260.           # Play item use SE
  261.           $game_system.se_play(@item.menu_se)
  262.           # If consumable
  263.           if @item.consumable
  264.             # Decrease used items by 1
  265.             $game_party.lose_item(@item.id, 1)
  266.             # Draw item window item
  267.             @item_window.draw_item(@item_window.index)
  268.           end
  269.           # Switch to map screen
  270.           $scene = Scene_Map.new
  271.           return
  272.         end
  273.       end
  274.       return
  275.     end
  276.   end
  277.   #--------------------------------------------------------------------------
  278.   # * Frame Update (when target window is active)
  279.   #--------------------------------------------------------------------------
  280.   def update_target
  281.     # If B button was pressed
  282.     if Input.trigger?(Input::B)
  283.       # Play cancel SE
  284.       $game_system.se_play($data_system.cancel_se)
  285.       # If unable to use because items ran out
  286.       unless $game_party.item_can_use?(@item.id)
  287.         # Remake item window contents
  288.         @item_window.refresh
  289.       end
  290.       # Erase target window
  291.       @item_window.active = true
  292.       @target_window.visible = false
  293.       @target_window.active = false
  294.       return
  295.     end
  296.     # If C button was pressed
  297.     if Input.trigger?(Input::C)
  298.       # If items are used up
  299.       if $game_party.item_number(@item.id) == 0
  300.         # Play buzzer SE
  301.         $game_system.se_play($data_system.buzzer_se)
  302.         return
  303.       end
  304.       # If target is all
  305.       if @target_window.index == -1
  306.         # Apply item effects to entire party
  307.         used = false
  308.         for i in $game_party.actors
  309.           used |= i.item_effect(@item)
  310.         end
  311.       end
  312.       # If single target
  313.       if @target_window.index >= 0
  314.         # Apply item use effects to target actor
  315.         target = $game_party.actors[@target_window.index]
  316.         used = target.item_effect(@item)
  317.       end
  318.       # If an item was used
  319.       if used
  320.         # Play item use SE
  321.         $game_system.se_play(@item.menu_se)
  322.         # If consumable
  323.         if @item.consumable
  324.           # Decrease used items by 1
  325.           $game_party.lose_item(@item.id, 1)
  326.           # Redraw item window item
  327.           @item_window.draw_item(@item_window.index)
  328.           @item_window.update_help
  329.         end
  330.         # Remake target window contents
  331.         @target_window.refresh
  332.         # If all party members are dead
  333.         if $game_party.all_dead?
  334.           # Switch to game over screen
  335.           $scene = Scene_Gameover.new
  336.           return
  337.         end
  338.         # If common event ID is valid
  339.         if @item.common_event_id > 0
  340.           # Common event call reservation
  341.           $game_temp.common_event_id = @item.common_event_id
  342.           # Switch to map screen
  343.           $scene = Scene_Map.new
  344.           return
  345.         end
  346.       end
  347.       # If item wasn't used
  348.       unless used
  349.         # Play buzzer SE
  350.         $game_system.se_play($data_system.buzzer_se)
  351.       end
  352.       return
  353.     end
  354.   end
  355. end
Expand to see the code.


Instructions:
Just paste above main somewhere. You can delete Scene_Item and Window_Item, if you want, but Window_Help is used elsewhere.
I would suggest using descriptive descriptions, rather than what the RTP does, so that picking out items is a little easier in battle.

Compatibility:
Should be fairly compatible with anything that doesn't affect the item menu or window.
That said, script offered as-is. If you do have problems, I can almost guarantee I won't know how to solve it.

Credits and Thanks:
MicKo for rewriting the menu system used in my game, which I was able to use to learn the very basics of RGSS.
Ares for giving me a little snippet that helped me debug this thing.

Terms and Conditions:
I don't need to be credited, personally, but you're certainly welcome to.
I have no love for commercial projects. Please don't use anything I make in one.
This is a really interesting idea. Currently, I can see no use for it in my game, but I will definitely keep it in mind.
hmmm... interesting~~! awesome job emu :thumb:

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