Advertisement
estriole

EST - AUTO TEXT COLOR PLUS

Aug 26th, 2013
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.38 KB | None | 0 0
  1. =begin
  2. EST - AUTO TEXT COLOR PLUS
  3. v.1.2
  4. Author: Estriole
  5.  
  6. Changelog
  7.  v1.0 2013.08.27    - Initial Release
  8.  v1.1 2013.08.28    - Combine with regexp to recognize 'short' word.
  9.                       now it won't color damage if you put mag in the config.
  10.                       if there's bug report to me. since it's really hard dealing with regexp
  11.  v1.2 2013.08.28    - Regexp sure is confusing. but manage to improve the regexp.
  12.                       now it should accept any character beside a-z and 0-9 and _ (underscore).
  13.                       and it just by removing one symbol from regexp that i have tried before and fail.
  14.  
  15. Introduction
  16.   This script created because i got tired adding \c[4]Nobita\c[0] in the show
  17. message box. so this script make it automatic. each time i wrote Nobita it will
  18. change the color to what i set in the module. useful to color actor names or
  19. places or important things. i also add capitalization correction too. so if you
  20. write nobita. it could fixed to Nobita(what you set in the config) if you want.
  21. both auto color and auto caps correct can be binded to switch too if you don't
  22. want to always using it.
  23.  
  24. Feature
  25. - auto change color text you defined in the module
  26. - auto correct capitalization to what you defined in the module
  27. - have switch function for both feature (set it to 0 to make it always active).
  28.  
  29. Author Note
  30. Yes... I made doraemon games.
  31.  
  32. Feature
  33.  
  34. =end
  35. module ESTRIOLE
  36.   module AUTOCOLOR
  37.     #PUT THE STRING YOU WANT TO AUTO COLOR BELOW. USEFUL FOR NAMES
  38.     #FORMAT:   "STRING" => COLOR_ID,
  39.     AUTO_SETTING = { #DO NOT TOUCH THIS LINE
  40.     "Nobita" => 2,
  41.     "Doraemon" => 3,
  42.     "Giant" => 4,
  43.     "Suneo" => 5,
  44.     "Shizuka" => 6,
  45.     "Mag" => 10,
  46.     }#DO NOT TOUCH THIS LINE
  47.    
  48.     #return to this color after the text finished. # default 0
  49.     RETURN_COLOR = 0
  50.    
  51.     #switch to activate the auto color. if switch off then don't autocolor
  52.     #set it to 0. if you want to use switch (will always on)
  53.     AUTO_COLOR_SWITCH = 0
  54.    
  55.     #switch to activate the auto capitalization correction. (will use what you define
  56.     #in AUTOSETTING #if switch off then don't auto capitalization correction.
  57.     #set it to 0. if you want to use switch (will always on)
  58.     CORRECT_CAP_SWITCH = 0
  59.    
  60.     START_AUTO_COLOR = true
  61.     START_CORRECT_CAP = true
  62.   end
  63. end
  64.  
  65. class Game_Switches
  66.   include ESTRIOLE::AUTOCOLOR
  67.   alias est_autocolor_switch_initialize initialize
  68.   def initialize
  69.     est_autocolor_switch_initialize
  70.     @data[AUTO_COLOR_SWITCH] = START_AUTO_COLOR if AUTO_COLOR_SWITCH != 0
  71.     @data[CORRECT_CAP_SWITCH] = START_CORRECT_CAP if CORRECT_CAP_SWITCH != 0
  72.   end
  73. end
  74.  
  75.  
  76. class Window_Base < Window
  77.   include ESTRIOLE::AUTOCOLOR
  78.   alias est_auto_text_color_convert_escape_character convert_escape_characters
  79.   def convert_escape_characters(*args, &block)
  80.     result = est_auto_text_color_convert_escape_character(*args, &block)    
  81.     return result if AUTO_COLOR_SWITCH != 0 && !$game_switches[AUTO_COLOR_SWITCH]
  82.     AUTO_SETTING.each_key {|key|
  83.     return_color = RETURN_COLOR
  84.     color        = AUTO_SETTING[key]
  85.     if CORRECT_CAP_SWITCH!= 0 && !$game_switches[CORRECT_CAP_SWITCH]
  86.     result.gsub!(/(?<![\w])#{key}(?![\w])/i) {"\eC[#{color}]#{$&}\eC[#{return_color}]"}
  87.     else
  88.     result.gsub!(/(?<![\w])#{key}(?![\w])/i) {"\eC[#{color}]#{key}\eC[#{return_color}]"}
  89.     end
  90.     }
  91.     result    
  92.   end
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement