Advertisement
Rafael_Sol_Maker

RAFAEL_SOL_MAKER's VX SINGLE ICON & FACE v1.1

Nov 17th, 2011
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.89 KB | None | 0 0
  1. #===============================================================================
  2. #                RAFAEL_SOL_MAKER's VX SINGLE ICON & FACE v1.1
  3. #              Based on 'Enable single icon usage' by snstar2006
  4. #-------------------------------------------------------------------------------
  5. # Description:  Allows the use of individual faces, no matter the index used,
  6. #               and also allows the use of custom icons and iconsets even in
  7. #               the Database.
  8. #-------------------------------------------------------------------------------
  9. # How to Use:   Put a '$' at the beginning of the file name and it will be used
  10. #               as "unique" size, the script take care of the rest, regardless
  11. #               the selected index.
  12. #               Additional iconsets should be placed in the folder
  13. #               'Graphics/Icons', if no file is specified it will use the
  14. #               default iconset.
  15. #               To use a different icon in database use the command
  16. #               <ICON "filename">, with no quotes, and to specify the icon you
  17. #               can use <ICON_ID x> to select the one you want. (x is the ID)
  18. #               The default iconset was kept for convenience in the editor and
  19. #               compatibility.
  20. #               It's possible to use two commands, if they are in the same
  21. #               line use ';' to separate them.
  22. #-------------------------------------------------------------------------------
  23. # Special Thanks: snstar2006
  24. #-------------------------------------------------------------------------------
  25. #===============================================================================
  26.  
  27. module Cache
  28.   def self.icon(filename)
  29.     load_bitmap('Graphics/Icons/', filename)
  30.   end  
  31. end
  32.  
  33. module PowerPackVX_Advanced_Configs  
  34.   ICON = /<(?:ICON|icon)\s*(.*)>/i  
  35.   ICON_ID = /<(?:ICON_ID|icon id)\s*(\d+)>/i  
  36. end
  37.  
  38. class RPG::BaseItem  
  39.   include PowerPackVX_Advanced_Configs
  40.    
  41.   def prepare_base_functions
  42.     @custom_icon = ''
  43.     @custom_icon_index = 0
  44.      
  45.     self.note.split(/[\r\n;]+/).each { |line|
  46.     case line
  47.     when ICON_ID
  48.       @custom_icon_index = $1.to_i
  49.     when ICON
  50.       a = line.split(/ /)[1]
  51.       d = ""
  52.       while ((c = a.slice!(/./m)) != nil)
  53.         d += c if c != ">"
  54.       end
  55.       @custom_icon = d
  56.     end }
  57.   end
  58.    
  59.   def custom_icon
  60.     prepare_base_functions if @icon == nil
  61.     return @custom_icon
  62.   end
  63.    
  64.   def custom_icon_index
  65.     prepare_base_functions if @icon_index == nil
  66.     return @custom_icon_index
  67.   end  
  68.    
  69. end
  70.  
  71. class Window_Base < Window
  72.  
  73.   def draw_face(face_name, face_index, x, y, size = 96)
  74.     return if face_name == nil
  75.     bitmap = Cache.face(face_name)
  76.     sign = face_name[/^[\!\$]./]  
  77.     rect = Rect.new(0, 0, size, size)
  78.     if sign == nil or ! sign.include?('$')
  79.       rect.x = face_index % 4 * 96 + (96 - size) / 2
  80.       rect.y = face_index / 4 * 96 + (96 - size) / 2
  81.     end
  82.     self.contents.blt(x, y, bitmap, rect)
  83.     bitmap.dispose
  84.   end
  85.  
  86.   def draw_icon(icon_index, x, y, enabled = true, icon_name = "" )
  87.     icon_name == "" ? bitmap = Cache.system("Iconset") : bitmap = Cache.icon(icon_name)
  88.     sign = icon_name[/^[\!\$]./]
  89.     icon_index = 0 if sign != nil and sign.include?("$")
  90.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)    
  91.     self.contents.blt(x, y, bitmap, rect, enabled ? 255 : 128)
  92.   end
  93.  
  94.   def draw_item_name(item, x, y, enabled = true)
  95.     if item != nil
  96.       if item.custom_icon != ""
  97.         index = item.custom_icon_index;  index = 0 if index.nil?    
  98.         draw_icon(index, x, y, enabled, item.custom_icon)
  99.       else
  100.         draw_icon(item.icon_index, x, y, enabled)
  101.       end
  102.       self.contents.font.color = normal_color
  103.       self.contents.font.color.alpha = enabled ? 255 : 128
  104.       self.contents.draw_text(x + 24, y, 172, WLH, item.name)
  105.     end
  106.   end
  107.  
  108. end
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement