SHARE
TWEET

[RGSS3] Text to Icon

DrDhoom Jul 26th, 2015 (edited) 295 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. #
  3. # • Dhoom Text to Icon v.1.0a
  4. #   drd-workshop.blogspot.com
  5. # -- Last Updated: 26.07.2015
  6. # -- Requires: None
  7. #
  8. #==============================================================================
  9. # Convert any specified text into icon. You can set conditions for specific
  10. # icon to be displayed. Works with every script that use draw_text method in
  11. # window.
  12. #==============================================================================
  13. # • CHANGELOG
  14. # - 27.07.2015 v1.0a
  15. #   - Adding ways to disable text to icon convertion
  16. #==============================================================================
  17.   $imported ||= {}
  18.   $imported[:dhoom_text_to_icon] = true
  19. #==============================================================================
  20. module Dhoom
  21.   module TextToIcon
  22. #==============================================================================
  23. # • CONFIGURATION
  24. #==============================================================================
  25.     Icons = {} #<-- Don't Remove!
  26. #------------------------------------------------------------------------------
  27. #   Icons[Text] = Icon Index or Array
  28. #     If array, the format is
  29. #     [
  30. #       [Icon Index, Script Condition],
  31. #       ...
  32. #       [Icon Index, Script Condition],
  33. #     ]
  34. #     Script condition must be converted into string.
  35. #     actor => will return the last actor that used to draw anything
  36. #              in Window_Base.
  37. #------------------------------------------------------------------------------
  38.     Icons['HP'] = [
  39.                    [123, 'actor.hp_rate <= 0.5'],
  40.                    [122, 'actor.hp_rate == 1.0'],
  41.                    [124, 'true'],
  42.                   ]
  43.     Icons['MP'] = 125
  44.     Icons['Eric'] = 1
  45.     Icons['Potion'] = 9
  46.     Icons['ATK'] = 34
  47.     Icons['DEF'] = 35
  48.     Icons['AGI'] = 38
  49.    
  50. #------------------------------------------------------------------------------
  51. #   SceneExlude = [Scene Class, Scene Class, ...]
  52. #   Disable text to icon convertion if current scene is included in this array
  53. #------------------------------------------------------------------------------
  54.     SceneExclude = [Scene_Status, Scene_Battle]
  55.    
  56. #------------------------------------------------------------------------------
  57. #   WindowExlude = [Window Class, Window Class, ...]
  58. #   Disable text to icon convertion in window that are included in this array
  59. #------------------------------------------------------------------------------
  60.     WindowExclude = [Window_ItemList, Window_EquipItem]
  61.    
  62. #------------------------------------------------------------------------------
  63. #   DisableSwitch = Switch ID
  64. #   Disable text to icon convertion when switch is ON
  65. #------------------------------------------------------------------------------
  66.     DisableSwitch = 1
  67.    
  68. #==============================================================================
  69. # • END OF CONFIGURATION
  70. #==============================================================================
  71.   end
  72. end
  73.  
  74. class Window_Base < Window
  75.   alias :dhoom_txttoic_wndbase_draw_text :draw_text
  76.   def draw_text(*args)
  77.     if Dhoom::TextToIcon::WindowExclude.include?(self.class) ||
  78.        Dhoom::TextToIcon::SceneExclude.include?(SceneManager.scene.class) ||
  79.        $game_switches[Dhoom::TextToIcon::DisableSwitch]
  80.       return dhoom_txttoic_wndbase_draw_text(*args)
  81.     end
  82.     text = args.size > 3 ? args[4] : args[1]
  83.     if Dhoom::TextToIcon::Icons[text]
  84.       data = Dhoom::TextToIcon::Icons[text]
  85.       icon = nil
  86.       if data.is_a?(Array)
  87.         actor = @last_actor
  88.         data.each do |cond|
  89.           begin; icon = cond[0] if eval(cond[1]); rescue; next; end
  90.           break if icon
  91.         end
  92.       else
  93.         icon = data
  94.       end      
  95.       unless icon
  96.         dhoom_txttoic_wndbase_draw_text(*args)
  97.         return
  98.       end
  99.       rect = args.size > 3 ? Rect.new(args[0], args[1], args[2], args[3]) : args[0]
  100.       y = rect.y + (rect.height - 24) / 2
  101.       align = args.size > 3 ? args[5] : [3]
  102.       case align
  103.       when 1
  104.         x = rect.x + rect.width / 2 - 12
  105.       when 2
  106.         x = rect.x + rect.width - 24
  107.       else
  108.         x = rect.x
  109.       end
  110.       draw_icon(icon, x, y)
  111.     else
  112.       dhoom_txttoic_wndbase_draw_text(*args)
  113.     end
  114.   end
  115.  
  116.   alias :dhoom_txttoic_wndbase_hp_color :hp_color
  117.   def hp_color(actor)
  118.     set_last_actor(actor)
  119.     dhoom_txttoic_wndbase_hp_color(actor)
  120.   end
  121.  
  122.   alias :dhoom_txttoic_wndbase_mp_color :mp_color
  123.   def mp_color(actor)
  124.     set_last_actor(actor)
  125.     dhoom_txttoic_wndbase_mp_color(actor)
  126.   end
  127.  
  128.   alias :dhoom_txttoic_wndbase_tp_color :tp_color
  129.   def tp_color(actor)
  130.     set_last_actor(actor)
  131.     dhoom_txttoic_wndbase_tp_color(actor)
  132.   end
  133.  
  134.   alias :dhoom_txttoic_wndbase_draw_actor_hp :draw_actor_hp
  135.   def draw_actor_hp(actor, x, y, width = 124)
  136.     set_last_actor(actor)
  137.     dhoom_txttoic_wndbase_draw_actor_hp(actor, x, y, width)
  138.   end  
  139.  
  140.   alias :dhoom_txttoic_wndbase_draw_actor_graphic :draw_actor_graphic
  141.   def draw_actor_graphic(actor, x, y)
  142.     set_last_actor(actor)
  143.     dhoom_txttoic_wndbase_draw_actor_graphic(actor, x, y)
  144.   end
  145.  
  146.   alias :dhoom_txttoic_wndbase_draw_actor_face :draw_actor_face
  147.   def draw_actor_face(actor, x, y, enabled = true)
  148.     set_last_actor(actor)
  149.     dhoom_txttoic_wndbase_draw_actor_face(actor, x, y, enabled)
  150.   end
  151.  
  152.   alias :dhoom_txttoic_wndbase_draw_actor_name :draw_actor_name
  153.   def draw_actor_name(actor, x, y, width = 112)
  154.     set_last_actor(actor)
  155.     dhoom_txttoic_wndbase_draw_actor_name(actor, x, y, width)
  156.   end
  157.  
  158.   alias :dhoom_txttoic_wndbase_draw_actor_class :draw_actor_class
  159.   def draw_actor_class(actor, x, y, width = 112)
  160.     set_last_actor(actor)
  161.     dhoom_txttoic_wndbase_draw_actor_class(actor, x, y, width)
  162.   end
  163.  
  164.   alias :dhoom_txttoic_wndbase_draw_actor_nickname :draw_actor_nickname
  165.   def draw_actor_nickname(actor, x, y, width = 180)
  166.     set_last_actor(actor)
  167.     dhoom_txttoic_wndbase_draw_actor_nickname(actor, x, y, width)
  168.   end
  169.  
  170.   alias :dhoom_txttoic_wndbase_draw_actor_level :draw_actor_level
  171.   def draw_actor_level(actor, x, y)
  172.     set_last_actor(actor)
  173.     dhoom_txttoic_wndbase_draw_actor_level(actor, x, y)
  174.   end
  175.  
  176.   alias :dhoom_txttoic_wndbase_draw_actor_icons :draw_actor_icons
  177.   def draw_actor_icons(actor, x, y, width = 96)
  178.     set_last_actor(actor)
  179.     dhoom_txttoic_wndbase_draw_actor_icons(actor, x, y, width)
  180.   end
  181.  
  182.   alias :dhoom_txttoic_wndbase_draw_actor_mp :draw_actor_mp
  183.   def draw_actor_mp(actor, x, y, width = 124)
  184.     set_last_actor(actor)
  185.     dhoom_txttoic_wndbase_draw_actor_mp(actor, x, y, width)
  186.   end
  187.  
  188.   alias :dhoom_txttoic_wndbase_draw_actor_tp :draw_actor_tp
  189.   def draw_actor_tp(actor, x, y, width = 124)
  190.     set_last_actor(actor)
  191.     dhoom_txttoic_wndbase_draw_actor_tp(actor, x, y, width)
  192.   end
  193.  
  194.   alias :dhoom_txttoic_wndbase_draw_actor_simple_status :draw_actor_simple_status
  195.   def draw_actor_simple_status(actor, x, y)
  196.     set_last_actor(actor)
  197.     dhoom_txttoic_wndbase_draw_actor_simple_status(actor, x, y)
  198.   end
  199.  
  200.   alias :dhoom_txttoic_wndbase_draw_actor_param :draw_actor_param
  201.   def draw_actor_param(actor, x, y, param_id)
  202.     set_last_actor(actor)
  203.     dhoom_txttoic_wndbase_draw_actor_param(actor, x, y, param_id)
  204.   end
  205.  
  206.   def set_last_actor(actor)
  207.     @last_actor = actor
  208.   end
  209. end
RAW Paste Data
Top