CODE / 23 OCT 2016

Example Code: Bob's Categorized Item Menu

Ruby
#===============================================================================
# Bob's Item menu
# -Bob423
# Seperates the item menu into 3 catagories: Useable, Equipment, and Key Items
#===============================================================================
     
#===============================================================================
# Config
     
# Names of catagories
    Bob_USE = "Useable"
    Bob_EQP = "Equipment"
    Bob_KEY = "Key Items"
     
# The ID of the first Key Item
# Everything above will be useable items, and everything below will be key items.
    First_Key = 23
   
# Set to 1 to make the quantity of an item change color if it is 1 or 99
# Set to 0 to make it not do that.
    $colored_numbers = 0
   
# The color when the player has 99 of an item
# (Red, Green, Blue, Grey) If grey is 0, the color will be black
# Default is the default system color (192, 224, 255, 255)
    def max_color # Don't touch this line!
      return Color.new(192, 224, 255, 255) # This is the line you should touch
    end # Don't touch this line!
   
# The color when the player has 1 of an item
# Default is yellow (255, 255, 0, 255)
    def low_color # Don't touch this line!
      return Color.new(255, 255, 0, 255) # This is the line you should touch
    end # Don't touch this line!
   
# End Config                                                                   #
#===============================================================================
 
#==============================================================================
# Normal item window
#==============================================================================
     
    class Window_Item < Window_Selectable
      #--------------------------------------------------------------------------
      # * Object Initialization
      #--------------------------------------------------------------------------
      def initialize
        super(0, 64, 640, 416)
        @column_max = 2
        refresh
        self.index = 0
        # If in battle, move window to center of screen
        # and make it semi-transparent
        if $game_temp.in_battle
          self.y = 64
          self.height = 256
          self.back_opacity = 160
        end
      end
      #--------------------------------------------------------------------------
      # * Get Item
      #--------------------------------------------------------------------------
      def item
        return @data[self.index]
      end
      #--------------------------------------------------------------------------
      # * Refresh
      #--------------------------------------------------------------------------
      def refresh
        if self.contents != nil
          self.contents.dispose
          self.contents = nil
        end
        @data = []
        # Add item
        for i in 1...First_Key
          if $game_party.item_number(i) > 0
            @data.push($data_items[i])
          end
        end
        # If item count is not 0, make a bit map and draw all items
        @item_max = @data.size
        if @item_max > 0
          self.contents = Bitmap.new(width - 32, row_max * 32)
          for i in 0...@item_max
            draw_item(i)
          end
        end
      end
      #--------------------------------------------------------------------------
      # * Draw Item
      #     index : item number
      #--------------------------------------------------------------------------
      def draw_item(index)
        item = @data[index]
        case item
        when RPG::Item
          number = $game_party.item_number(item.id)
        end
        if item.is_a?(RPG::Item) and
           $game_party.item_can_use?(item.id)
          self.contents.font.color = normal_color
        else
          self.contents.font.color = disabled_color
        end
        x = 4 + index % 2 * (288 + 32)
        y = index / 2 * 32
        rect = Rect.new(x, y, self.width / @column_max - 32, 32)
        self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
        bitmap = RPG::Cache.icon(item.icon_name)
        opacity = self.contents.font.color == normal_color ? 255 : 128
        self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
        self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
        self.contents.draw_text(x + 245, y, 16, 32, "x", 1)
       
        # Colored Numbers
        if number == 1 and $game_party.item_can_use?(item.id) and $colored_numbers == 1
          self.contents.font.color = low_color
        elsif number == 99 and $game_party.item_can_use?(item.id) and $colored_numbers == 1
          self.contents.font.color = max_color
        elsif number > 1 and number < 99 and $game_party.item_can_use?(item.id) and $colored_numbers == 1
          self.contents.font.color = normal_color
        end
       
        self.contents.draw_text(x + 258, y, 24, 32, number.to_s, 2)
      end
      #--------------------------------------------------------------------------
      # * Help Text Update
      #--------------------------------------------------------------------------
      def update_help
        @help_window.set_text(self.item == nil ? "" : self.item.description)
      end
    end
     
    #==============================================================================
    # This is where the window that lists equipment is made
    #==============================================================================
     
    class Window_EQUIP < Window_Selectable
      #--------------------------------------------------------------------------
      # * Object Initialization
      #--------------------------------------------------------------------------
      def initialize
        super(0, 64, 640, 416)
        @column_max = 2
        refresh
        self.index = 0
        # If in battle, move window to center of screen
        # and make it semi-transparent
        if $game_temp.in_battle
          self.y = 64
          self.height = 256
          self.back_opacity = 160
        end
      end
      #--------------------------------------------------------------------------
      # * Get Item
      #--------------------------------------------------------------------------
      def item
        return @data[self.index]
      end
      #--------------------------------------------------------------------------
      # * Refresh
      #--------------------------------------------------------------------------
      def refresh
        if self.contents != nil
          self.contents.dispose
          self.contents = nil
        end
        @data = []
        # Add item
          for i in 1...$data_weapons.size
            if $game_party.weapon_number(i) > 0
              @data.push($data_weapons[i])
            end
          end
          for i in 1...$data_armors.size
            if $game_party.armor_number(i) > 0
              @data.push($data_armors[i])
            end
          end
        # If item count is not 0, make a bit map and draw all items
        @item_max = @data.size
        if @item_max > 0
          self.contents = Bitmap.new(width - 32, row_max * 32)
          for i in 0...@item_max
            draw_item(i)
          end
        end
      end
      #--------------------------------------------------------------------------
      # * Draw Item
      #     index : item number
      #--------------------------------------------------------------------------
      def draw_item(index)
        item = @data[index]
        case item
        when RPG::Weapon
          number = $game_party.weapon_number(item.id)
        when RPG::Armor
          number = $game_party.armor_number(item.id)
        end
       
        self.contents.font.color = normal_color
       
        x = 4 + index % 2 * (288 + 32)
        y = index / 2 * 32
        rect = Rect.new(x, y, self.width / @column_max - 32, 32)
        self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
        bitmap = RPG::Cache.icon(item.icon_name)
        opacity = self.contents.font.color == normal_color ? 255 : 128
        self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
        self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
        self.contents.draw_text(x + 245, y, 16, 32, "x", 1)
        self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
      end
      #--------------------------------------------------------------------------
      # * Help Text Update
      #--------------------------------------------------------------------------
      def update_help
        @help_window.set_text(self.item == nil ? "" : self.item.description)
      end
    end
    #==============================================================================
    # Key Item Window
    #==============================================================================
     
    class Window_KEY < Window_Selectable
      #--------------------------------------------------------------------------
      # * Object Initialization
      #--------------------------------------------------------------------------
      def initialize
        super(0, 64, 640, 416)
        @column_max = 2
        refresh
        self.index = 0
        # If in battle, move window to center of screen
        # and make it semi-transparent
        if $game_temp.in_battle
          self.y = 64
          self.height = 256
          self.back_opacity = 160
        end
      end
      #--------------------------------------------------------------------------
      # * Get Item
      #--------------------------------------------------------------------------
      def item
        return @data[self.index]
      end
      #--------------------------------------------------------------------------
      # * Refresh
      #--------------------------------------------------------------------------
      def refresh
        if self.contents != nil
          self.contents.dispose
          self.contents = nil
        end
        @data = []
        # Add item
        for i in First_Key...$data_items.size
        if $game_party.item_number(i) > 0
            @data.push($data_items[i])
          end
        end
        # If item count is not 0, make a bit map and draw all items
        @item_max = @data.size
        if @item_max > 0
          self.contents = Bitmap.new(width - 32, row_max * 32)
          for i in 0...@item_max
            draw_item(i)
          end
        end
      end
      #--------------------------------------------------------------------------
      # * Draw Item
      #     index : item number
      #--------------------------------------------------------------------------
      def draw_item(index)
        item = @data[index]
        case item
        when RPG::Item
          number = $game_party.item_number(item.id)
        end
       
        self.contents.font.color = normal_color
       
        x = 4 + index % 2 * (288 + 32)
        y = index / 2 * 32
        rect = Rect.new(x, y, self.width / @column_max - 32, 32)
        self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
        bitmap = RPG::Cache.icon(item.icon_name)
        opacity = self.contents.font.color == normal_color ? 255 : 255
        self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
        self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
      end
      #--------------------------------------------------------------------------
      # * Help Text Update
      #--------------------------------------------------------------------------
      def update_help
        @help_window.set_text(self.item == nil ? "" : self.item.description)
      end
    end
    #==============================================================================
    # ** Window_Target
    #------------------------------------------------------------------------------
    #  This window selects a use target for the actor on item and skill screens.
    #==============================================================================
     
    class Window_Target < Window_Selectable
      #--------------------------------------------------------------------------
      # * Object Initialization
      #--------------------------------------------------------------------------
      def initialize
        party_size = $game_party.actors.size
        super(0, 0, 200, party_size * 120)
        if party_size < 3
          self.height = 5 + party_size * 120
        end
        self.contents = Bitmap.new(width - 32, height - 32)
        self.z += 10
        @item_max = $game_party.actors.size
        refresh
      end
      #--------------------------------------------------------------------------
      # * Refresh
      #--------------------------------------------------------------------------
      def refresh
        self.contents.clear
        party_size = $game_party.actors.size
        for i in 0...party_size
          actor_size = (self.height / party_size) - 5
          x = 4
          y = i * actor_size
          actor = $game_party.actors[i]
          draw_actor_graphic(actor, x +  9, y + 48)
          draw_actor_name(actor,    x + 26, y -  2)
          draw_actor_hp(actor,      x + 26, y + 18)
          draw_actor_sp(actor,      x + 26, y + 40)
          draw_actor_state(actor,   x + 23, y + 66)
        end
      end
      #--------------------------------------------------------------------------
      # * Cursor Rectangle Update
      #--------------------------------------------------------------------------
      def update_cursor_rect
        party_size = $game_party.actors.size
        actor_size = (self.height / party_size)
        case @index
          when 0
            rectY = @index * actor_size
          when 1
            rectY = (@index * actor_size) - 5
          when 2
            rectY = (@index * actor_size) - 10
          when 3
            rectY = (@index * actor_size) - 15
        end
        # Cursor position -1 = all choices, -2 or lower = independent choice
        # (meaning the user's own choice)
        if @index 

GDU Refinery is a show & tell so it's not really for completed scripts (there's a scripts section for that). But anything code-related :)

(Btw who knew Bob made scripts?????)

21

Mark M

9

Ben S - 1 year ago

I actually modified this from the default item menus when I was still learning. I still don't know anything about rgss, but I've learned a little Java and Javascript since then and I doubt I could make anything like this from scratch...yet.

 
 
21

Mark M @Bob423 - 1 year ago

Uhuh... that's you learn. I learned to make websites but messing around with Joomla CMS components. You have a piece of code but you wana change a little thing here, a little thing here.... nek minit boom, can build something like the GDU Refinery. You just can't get the same value from a book or written tutorials

 
{?global_avatar?}
You must login to comment.