Advertisement
modern_algebra

[VXA] Item Icon List 1.0.2

Jun 8th, 2013
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.02 KB | None | 0 0
  1. #==============================================================================
  2. #    Icon Item List
  3. #    Version: 1.0.2
  4. #    Author: modern algebra (rmrk.net)
  5. #    Date: 16 June 2013
  6. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. #  Description:
  8. #    
  9. #    This script changes the item window so that it shows only icons to
  10. #   represent the item and a number to show how many are held.
  11. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12. #  Instructions:
  13. #    
  14. #    Paste this script into its own slot in the Script Editor, above Main but
  15. #   below Materials.
  16. #
  17. #    You can also customize the size of each icon space, as well as various
  18. #   aspects of the font to draw the number, including size, colour, and whether
  19. #   it is bolded. As well, you can set it so that the name of the item shows up
  20. #   in the help window, and you can set its format as well. To do so, go to the
  21. #   Editable Region at line 53 and read the instructions contained there.
  22. #
  23. #    The script also allows you to set it so that each icon has a background
  24. #   colour and a shadow. Those are set at lines 90-95. You can also set it so
  25. #   that each item has its own background colour by using either of the
  26. #   following codes in its notebox
  27. #
  28. #      \back_colour[x]
  29. #      \back_colour[r, g, b, a]
  30. #
  31. #    If the former, the xth colour on the windowskin palette will be used. If
  32. #   the latter, then it will choose a colour with those rgb and alpha values.
  33. #
  34. #    Note: using the Name feature will reduce the amount of space you have for
  35. #   the actual description of your items. By default, it takes a whole line
  36. #   (although you can change that by altering the NAME_FORMAT string). If that
  37. #   is a problem, you could turn the feature off (but then it would not show
  38. #   the name anywhere). Another solution would be to increase the size of the
  39. #   help window. That can be done by using my Customizable Item Menu script,
  40. #   which you can find here:
  41. #
  42. #      http://rmrk.net/index.php/topic,46516.0.html
  43. #
  44. #   If you use the Image in Description feature, you should probably remove the
  45. #   \\icon from the NAME_FORMAT at line 112.
  46. #==============================================================================
  47.  
  48. $imported = {} unless $imported
  49. $imported[:MA_IconItemList] = true
  50.  
  51. module MA_IconItemList
  52. #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  53. #    BEGIN Editable Region
  54. #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  55.   # Size Settings
  56.   RECT_WIDTH = 28    # The width of each slot for the icon
  57.   RECT_HEIGHT = 28   # The height of each slot for the icon
  58.   SPACING = 12       # The space between icon slots
  59.   # Number Settings
  60.   #  NUM_FONTNAME - The font for the numbers. It should be an array of strings,
  61.   # with each string being a font name ranked by priority. It will use the
  62.   # first font in the array that exists on the user's computer. It will use
  63.   # the default if set to nil.
  64.   NUM_FONTNAME = nil
  65.   NUM_FONTSIZE = 20  # The size of the font showing how many items possessed
  66.   NUM_BOLD = true    # Whether the number of items should be bolded
  67.   NUM_ITALIC = false # Whether the number of items should be italicized
  68.   NUM_SHADOW = true  # Whether the number of items should have a shadow
  69.   NUM_OUTLINE = true # Whether the number of items should have an outline
  70.   NUM_ALIGN = 2      # Alignment of number. 0 => Left; 1 => Centre; 2 => Right
  71.   DO_NOT_DRAW_NUM_IF_1 = false # Don't draw num if only possess 1 of item
  72.   # Colours
  73.   #  Each of the colour settings can be either an integer, an array, or a
  74.   # Color object. If an integer (0, 1, ..., 31), it will take its colour from
  75.   # that index of the windowskin's colour palette. If an array, then it must
  76.   # be in the form: [red, green, blue, alpha], where each is an integer between
  77.   # 0 and 255. alphas is optional. Color objects may also be used, in which
  78.   # case it is: Color.new(red, green, blue, alpha)
  79.   #
  80.   #  Examples:
  81.   #    NUM_COLOUR = 0
  82.   #    NUM_COLOUR_WHEN_MAX = [100, 200, 145]
  83.   #    NUM_OUT_COLOUR = Color.new(75, 75, 75, 160)
  84.   #
  85.   #  If you set NUM_OUT_COLOUR to nil, then it will just use the default
  86.   # outline colour.
  87.   NUM_COLOUR = 0     # The colour of the number
  88.   NUM_COLOUR_WHEN_MAX = 17 # The colour of the number if holding maximum
  89.   NUM_OUT_COLOUR = nil # The colour of the outline, if showing. If nil, default
  90.   # Back Settings
  91.   #  These allow you to set a background colour for your items. The same
  92.   # The same options for setting colours are available here as they are above.
  93.   # Additionally, if set to nil, there will not be any colour.
  94.   #  
  95.   #  If you do decide to use them, recommended values for each are:
  96.   #    BACK_DEFAULT_COLOUR = Color.new(64, 64, 64, 160)
  97.   #    BACK_SHADOW_COLOUR = Color.new(0, 0, 0, 128)
  98.   BACK_DEFAULT_COLOUR = nil # Default Main Colour
  99.   BACK_SHADOW_COLOUR = nil  # Colour of Shadow
  100.   # Name Settings
  101.   #  SHOW_NAME_IN_DESCRIPTION - Set to true if you want to show the name of the
  102.   # item in the description window. Set it to false otherwise.
  103.   SHOW_NAME_IN_DESCRIPTION = true
  104.   #  NAME_FORMAT - This is the format of the name, if shown in the description
  105.   # window. The code \\icon will be replaced with the icon of the currently
  106.   # selected item, and \\name will be replaced with the name of the currently
  107.   # selected item. All the other message codes are also recognized, but you
  108.   # need to use two backslashes (\\), not one (\). Examples:
  109.   #    Good:     \\c[16]
  110.   #    Bad:      \c[16]
  111.   # The code \n (one backslash) will make a new line.
  112.   NAME_FORMAT = "\\icon \\c[16]\\name\\c[0]\n"
  113. #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  114. #    END Editable Region
  115. #//////////////////////////////////////////////////////////////////////////////
  116. end
  117.  
  118. #==============================================================================
  119. # *** RPG::BaseItem
  120. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  121. #  Summary of Changes:
  122. #    new method - back_colour
  123. #==============================================================================
  124.  
  125. class RPG::BaseItem
  126.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  127.   # * Back Colour
  128.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  129.   def maiil_back_colour
  130.     unless @maiil_back_colour
  131.       if note[/\\BACK_COLOU?R\[(.+?)\]/i]
  132.         dig = $1.scan(/\d+/).collect { |x| x.to_i }
  133.         @maiil_back_colour = dig.empty? ? nil : dig.size == 1 ? dig[0] : dig
  134.       else
  135.         @maiil_back_colour = MA_IconItemList::BACK_DEFAULT_COLOUR
  136.       end
  137.     end
  138.     return @maiil_back_colour
  139.   end
  140. end
  141.  
  142.  
  143. #==============================================================================
  144. # *** Window_MAIIL_Help
  145. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  146. #  This window can mix in to a help window to show the names of items.
  147. #==============================================================================
  148.  
  149. module Window_MAIIL_Help
  150.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  151.   # * Set Item
  152.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  153.   def set_item(item, *args)
  154.     if item                                     # if Item passed
  155.       text = MA_IconItemList::NAME_FORMAT.dup     # Get Name Format
  156.       text.gsub!(/\\ICON/i, "\\i[#{item.icon_index}]") # Replace Icon
  157.       text.gsub!(/\\NAME/i, item.name)            # Replace Name
  158.       text += item.description                    # Add Description
  159.       if $imported[:"MA Customizable Item Menu 1.0.x"] && self.is_a?(Window_MACIM_Help) # if using Custom Item Menu
  160.         image = item.is_a?(MACIM_RPG_ItemWeaponArmor) ? item.macim_desc_image : ""
  161.         set_text(text, image)                       # Set Text (CIM)
  162.       else
  163.         set_text(text)                              # Set Text (NO CIM)
  164.       end
  165.     else                                        # if nil Passed
  166.       set_text("")                                # Set Text when no item
  167.     end
  168.   end
  169. end
  170.  
  171. #==============================================================================
  172. # ** Window_ItemList
  173. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  174. #  Summary of Changes:
  175. #    overwritten methods - create_contents; text_color; draw_item;
  176. #      draw_item_number; col_max; spacing; line_height
  177. #    aliased method - help_window=
  178. #    new method - maiil_draw_item_icon
  179. #==============================================================================
  180.  
  181. class Window_ItemList
  182.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  183.   # * Create Contents
  184.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  185.   def create_contents(*args)
  186.     super(*args)
  187.     maiil_reset_font
  188.   end
  189.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  190.   # * Setup Font
  191.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  192.   def maiil_reset_font
  193.     fn = MA_IconItemList::NUM_FONTNAME ? MA_IconItemList::NUM_FONTNAME : Font.default_name
  194.     contents.font = Font.new(fn, MA_IconItemList::NUM_FONTSIZE) # name and size
  195.     contents.font.bold = MA_IconItemList::NUM_BOLD       # Set Bold
  196.     contents.font.italic = MA_IconItemList::NUM_ITALIC   # Set Italic
  197.     contents.font.shadow = MA_IconItemList::NUM_SHADOW   # Set Shadow
  198.     contents.font.outline = MA_IconItemList::NUM_OUTLINE # Set outline
  199.     oc = MA_IconItemList::NUM_OUT_COLOUR ? MA_IconItemList::NUM_OUT_COLOUR : Font.default_out_color
  200.     contents.font.out_color = text_color(oc) # outline color
  201.   end
  202.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  203.   # * Text Colour
  204.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  205.   def text_color(n)
  206.     case n
  207.     when Integer then super(n)
  208.     when Array then Color.new(*n)
  209.     when Color then n
  210.     else super(0)
  211.     end
  212.   end
  213.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  214.   # * Draw Item
  215.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  216.   def draw_item(index)
  217.     item = @data[index]              # get item
  218.     if item                          # if Item passed
  219.       rect = item_rect(index)        # get rect
  220.       contents.clear_rect(rect)
  221.       maiil_draw_item_icon(rect, item) # draw icon
  222.       draw_item_number(rect, item)     # draw number of items held
  223.     end
  224.   end
  225.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  226.   # * Draw Item Icon
  227.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  228.   def maiil_draw_item_icon(rect, item)
  229.     x, y = rect.x + 2, rect.y + ((rect.height - 24) / 2) # Get coordinates
  230.     if item.maiil_back_colour # Draw Border
  231.       bcs = MA_IconItemList::BACK_SHADOW_COLOUR
  232.       contents.fill_rect(x, y, 26, 26, text_color(bcs)) if bcs
  233.       contents.fill_rect(x - 1, y - 1, 26, 26, text_color(item.maiil_back_colour))
  234.     end
  235.     draw_icon(item.icon_index, x, y, enable?(item))      # Draw Icon
  236.   end
  237.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  238.   # * Draw Item Number
  239.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  240.   def draw_item_number(rect, item)
  241.     num = $game_party.item_number(item) # Get Number
  242.     return if MA_IconItemList::DO_NOT_DRAW_NUM_IF_1 && num < 2
  243.     # Set Number Colour
  244.     if num == $game_party.max_item_number(item)
  245.       contents.font.color = text_color(MA_IconItemList::NUM_COLOUR_WHEN_MAX)
  246.     else
  247.       contents.font.color = text_color(MA_IconItemList::NUM_COLOUR)
  248.     end
  249.     contents.font.color.alpha = translucent_alpha unless enable?(item) # Set Alpha
  250.     # Adjust Rect
  251.     rect2 = rect.dup
  252.     rect2.y += (rect.height - contents.font.size)
  253.     rect2.height = contents.font.size
  254.     # Draw Number
  255.     draw_text(rect2, num, MA_IconItemList::NUM_ALIGN)
  256.   end
  257.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  258.   # * Column Max
  259.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  260.   def col_max; (contents_width / (MA_IconItemList::RECT_WIDTH + spacing)); end
  261.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  262.   # * Spacing
  263.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  264.   def spacing; MA_IconItemList::SPACING; end
  265.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  266.   # * Line Height
  267.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  268.   def line_height; MA_IconItemList::RECT_HEIGHT; end
  269.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  270.   # * Help Window=
  271.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  272.   if MA_IconItemList::SHOW_NAME_IN_DESCRIPTION # IF showing name in Description
  273.     # If #help_window= has been redefined in Window_ItemList
  274.     if instance_methods(false).include?(:"help_window=")
  275.       alias maiil_helpwinset_4ka5 help_window=
  276.       def help_window=(*args)
  277.         maiil_helpwinset_4ka5(*args) # Call Original Method
  278.         @help_window.extend(Window_MAIIL_Help)
  279.       end
  280.     else # Inheriting #help_window= from Window_Selectable
  281.       def help_window=(*args)
  282.         super(*args) # Call Original Method
  283.         @help_window.extend(Window_MAIIL_Help)
  284.       end
  285.     end
  286.   end
  287. end
  288.  
  289. #==============================================================================
  290. # *** Scene_ItemBase
  291. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  292. #  Summary of Changes:
  293. #    overwritten method - cursor_left?
  294. #==============================================================================
  295.  
  296. class Scene_ItemBase
  297.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  298.   # * Determine if Cursor Is in Left Column
  299.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  300.   def cursor_left?
  301.     true
  302.   end
  303. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement