Advertisement
LiTTleDRAgo

[RGSS] Drago - Iconset Loader

Feb 13th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.69 KB | None | 0 0
  1. #==============================================================================
  2. # ** Drago - Iconset Loader
  3. # Version : 1.00
  4. # Contact : littledrago.blogspot.com / forum.chaos-project.com
  5. #==============================================================================
  6. ($imported ||= {})[:drg_iconset_loader] = 1.00
  7. #==============================================================================
  8. #
  9. # Introduction :
  10. #
  11. #     This script loads icon graphics from VX / VXAce Iconset
  12. #
  13. # How to use :
  14. #
  15. #   Place Iconset.png in Graphics/System (you can get it from VX / VXAce RTP)
  16. #  
  17. #   Change every item/weapon/armor/skill icon index in the module below.
  18. #   Unconfigured item/weapon/armor/skill will keep using old image.
  19. #
  20. # Available effects :
  21. #
  22. #   :brighten!, :darken!, :frost!, :pixelate!, :invert!, :grayscale!,  :blur,  
  23. #   :flip_vertical!, :flip_horizontal!, :add_bitmap_blend, :sub_bitmap_blend
  24. #   :rotate90!, :rotate180!, :rotate270!
  25. #
  26. #==============================================================================
  27.  
  28. core = "This script needs Drago - Core Engine ver 1.58 or above"
  29. rmvx = "This script only for RMXP"
  30. ($imported[:drg_core_engine]||0) >= 1.58 || raise(core)
  31. LiTTleDRAgo::XP || raise(rmxp)
  32.  
  33. module Iconset
  34.   #============================================================================
  35.   # ■ Iconset::Item
  36.   #----------------------------------------------------------------------------
  37.   #
  38.   #============================================================================
  39.   module Item
  40.     def self.icon_index(id)
  41.       case id
  42.       when :ID then [:index, :hue, :effects, :effects, '...']
  43.       when 1   then [192]
  44.       when 2   then [192, 40, :brighten!, :brighten!]
  45.       when 3   then [192, 80, :brighten!, :brighten!, :brighten!]
  46.       when 4   then [193]
  47.       when 5   then [193, 40]
  48.       when 6   then [193, 80, :frost!]
  49.       end
  50.     end
  51.   end
  52.   #============================================================================
  53.   # ■ Iconset::Armor
  54.   #----------------------------------------------------------------------------
  55.   #
  56.   #============================================================================
  57.   module Armor
  58.     def self.icon_index(id)
  59.       case id
  60.       when :ID then [:index, :hue, :effects, :effects, '...']
  61.       end
  62.     end
  63.   end
  64.   #============================================================================
  65.   # ■ Iconset::Weapon
  66.   #----------------------------------------------------------------------------
  67.   #
  68.   #============================================================================
  69.   module Weapon
  70.     def self.icon_index(id)
  71.       case id
  72.       when :ID then [:index, :hue, :effects, :effects, '...']
  73.       end
  74.     end
  75.   end
  76.   #============================================================================
  77.   # ■ Iconset::Skill
  78.   #----------------------------------------------------------------------------
  79.   #
  80.   #============================================================================
  81.   module Skill
  82.     def self.icon_index(id)
  83.       case id
  84.       when :ID then [:index, :hue, :effects, :effects, '...']
  85.       end
  86.     end
  87.   end
  88. end
  89.  
  90. #==============================================================================
  91. # ■ RPG::Cache
  92. #------------------------------------------------------------------------------
  93. #
  94. #==============================================================================
  95. ModCache = LiTTleDRAgo.cache
  96. class << ModCache
  97.   #-----------------------------------------------------------------------
  98.   # * Alias Listing
  99.   #-----------------------------------------------------------------------
  100.   alias_sec_method :iconset_effect_change, :icon
  101.   #-----------------------------------------------------------------------
  102.   # * Aliased method: tileset
  103.   #-----------------------------------------------------------------------
  104.   def icon(filename,*args)
  105.     if (img = filename[/<Icon\s*(.+?)\>/i])
  106.       unless include?(filename)
  107.         array = img.get_ints
  108.         bitmap = Bitmap.new(24,24)
  109.         bitmap.draw_icon(array.at(0),0,0)
  110.         bitmap.change_hue(array.at(1)) if array.at(1)
  111.         $1.split(',').each do |method|
  112.           if method.not.empty? && bitmap.respond_to?(method.to_sym)
  113.             bitmap.send(method.to_sym)
  114.           end
  115.         end
  116.         @cache[filename] = bitmap
  117.       end
  118.       @cache[filename]
  119.     else
  120.       iconset_effect_change(filename,*args)
  121.     end
  122.   end
  123. end
  124.  
  125. #==============================================================================
  126. # ** Object
  127. #------------------------------------------------------------------------------
  128. #  This class is superclass for all class
  129. #==============================================================================
  130. class Object
  131.   #--------------------------------------------------------------------------
  132.   # * self.iconset_init
  133.   #--------------------------------------------------------------------------
  134.   def self.iconset_init(index)
  135.     method = case index
  136.     when 0 then 'Iconset::Item.icon_index(@id)'
  137.     when 1 then 'Iconset::Armor.icon_index(@id)'
  138.     when 2 then 'Iconset::Weapon.icon_index(@id)'
  139.     when 3 then 'Iconset::Skill.icon_index(@id)'
  140.     end
  141.     return unless method
  142.     send(:alias_sec_method, :iconset_effect_change, :icon_name)
  143.     send(:redirect_method,  :iconset_index, method)
  144.     send(:define_method,    :icon_name) do |*args|
  145.       return "<Icon #{iconset_index}>"           if iconset_index.is_a?(Integer)
  146.       return "<Icon #{iconset_index.join(',')}>" if iconset_index.is_a?(Array)
  147.       iconset_effect_change(*args)
  148.     end
  149.   end
  150. end
  151.  
  152. _class = [RPG::Item, RPG::Armor, RPG::Weapon, RPG::Skill]
  153. _class.each_with_index { |klass,index| klass.iconset_init(index) }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement