Control Characters Everywhere

Control Characters Everywhere - Version: 1.0
By: Brewmeister

Introduction

Extends the use of Control Characters (\v[n], \N[n], \C[n]) to descriptions, names, pretty much anything in the database...
Developed for RMXP, but should work in RMVX as well.

Screenshots

Database Show
Image Image Image

In Game Show
ImageImage


Demo

N/A

Script

  1. #---------------------------------------------------------------------------
  2. #
  3. # Control Characters work for object descriptions & names.
  4. # Actor, Class, Items, Weapons, Armors, Skills, Enemies
  5. # Valid Control Characters: \V[n], \N[n], \C[n]
  6. #
  7. # 12Feb09 - Brew  (ref: RRR_supt)
  8. #---------------------------------------------------------------------------
  9.  
  10. class Bitmap
  11.   alias draw_parsed_text draw_text
  12.   def draw_text(*args)
  13.     #parse the text
  14.     if args[0].is_a?(Rect)
  15.       x = args[0].x
  16.       y = args[0].y
  17.       width = args[0].width
  18.       height = args[0].height
  19.       str = args[1]
  20.       align = args[2] != nil ? args[2] : 0
  21.     else
  22.       x = args[0]
  23.       y = args[1]
  24.       width = args[2]
  25.       height = args[3]
  26.       str = args[4]
  27.       align = args[5] != nil ? args[5] : 0
  28.     end
  29.     # If waiting for a message to be displayed
  30.     if str != nil
  31.       if str.is_a?(String)
  32.         text = str.clone
  33.       else
  34.         text = str.to_s
  35.       end
  36.       # Control text processing
  37.       begin
  38.         last_text = text.clone
  39.         text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  40.       end until text == last_text
  41.       text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  42.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  43.       end
  44.       # Change "\\C" to "\001" and "\\G" to "\002"
  45.       text.sub!(/\\[Cc]\[([0-9]+)\]/, "")
  46.       if $1 != nil
  47.         color = $1.to_i
  48.         font.color = text_color(color)
  49.       end
  50.     end
  51.     draw_parsed_text(x, y, width, height, text, align)
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # * Get Text Color
  55.   #     n : text color number (0-7)
  56.   #--------------------------------------------------------------------------
  57.   def text_color(n)
  58.     case n
  59.     when 0
  60.       return Color.new(255, 255, 255, 255)
  61.     when 1
  62.       return Color.new(128, 128, 255, 255)
  63.     when 2
  64.       return Color.new(255, 128, 128, 255)
  65.     when 3
  66.       return Color.new(128, 255, 128, 255)
  67.     when 4
  68.       return Color.new(128, 255, 255, 255)
  69.     when 5
  70.       return Color.new(255, 128, 255, 255)
  71.     when 6
  72.       return Color.new(255, 255, 128, 255)
  73.     when 7
  74.       return Color.new(192, 192, 192, 255)
  75.     else
  76.       return Color.new(255, 255, 255, 255)
  77.     end
  78.   end
  79. end
Expand to see the code.


Instructions

Paste Above Main

FAQ

Can I add colors?

Sure, to add "Bright Red" for example... after line 70 insert:

when 8
return Color.new(255, 0, 0, 255)


Can I have more than one color in a name or description?

No. Not with this script. This script sets the color before drawing the string.
Unlike the message script, that draws the characters one at a time.

Compatibility

Incompatible with Ccoa's UMS. (\name[#] won't convert the control characters correctly.)

Extends the Bitmap.draw_text method & supports both draw_text(x, y, width, height, str[, align]) and draw_text(rect, str[, align]) formats

Author's Notes

In response to several requests to display item names in different colors.

Terms and Conditions

Please link to this thread instead of posting the script elsewhere. (even though I've posted it elsewhere) :scruff:
Feel free use for any legal purpose you can think of. Feel free to edit, modify, bend, spindle mutilate.
If you make edits or additions, please post them here so I can either include them, or link to them as enhancements.
Hey so this is actually a pretty cool feature that I'm suprised was never added to the editor in the first place, lol.
Oh hey never thought of doing that, that's ace.
Very nice script.

I did the exact same thing for VX a few years ago but I don't know why, I have never released it. And that's awesome, we did it the exact same way.

Major kudos Brew!
Thanks Darg.

yeh, I expect there are a finite # of ways of doing it, and adding the code from Window_Message to draw_text seemed the most logical.

I saw several requests for colored item names, and thought this would be more robust for other users.

Be Well
I found some compatibility issues when using with XAS v3.9. XAS v3.9 has an active hud script which require a face graphic: hero_HFace.png, where hero is the name of an actor in the database. Since this script requires the color code \c[n] and file formats cannot start with '\' character, it poses some issues.
Souloux wrote:
I found some compatibility issues when using with XAS v3.9. XAS v3.9 has an active hud script which require a face graphic: hero_HFace.png, where hero is the name of an actor in the database. Since this script requires the color code \c[n] and file formats cannot start with '\' character, it poses some issues.


Actually, this wouldn't work with that even if it used a different format. This script modifies the game so that text that gets drawn to the screen will be affected, which means that other things, like your example, would not be affected at all.
@Souloux
The problem isn't with this script, but with the hud (using the actor's name isn't the best way to add faces on a hud). It wouldn't be hard to make the hud consider another parameter, like the actor.character_name instead of the actor.name.

It's an great script, i made something similar that only for the help window, but it had some other features like drawing icons and items/skill/equips names. I was planning to make it work for everywhere but i got my hands full with another scripts XD
Souloux, If you want colored actor names & use the actor name for the faces, you could modify the hud script to remove the escape sequence from the name before assembling the file name.. (using the same .sub! method from this script)

Atoa, I started with the idea of making it work just for items, but then a lightbulb went on & I realized I could just implement it in draw_text & it would work everywhere.

Glad you guys like it. I hope some people find it useful.

Funny thing, I have almost 200 projects with scripts I wrote from requests. I need to take the time to clean up & document some of the more useful ones & get them posted.

Be Well
I find this script to be rather useful, so I tried pairing it with Ccoa's UMS. I add the color code to the actor and tried using the name window feature in Ccoa's UMS.

Image

This is how it appears when using the text command in RMXP.
Image

However it works fine in the menu screens.
Image
Soooo simple, yet efficient for anyone who is using the standard menus. It's probably still useful for CMS as well. Thanks Brew for this cool script, Ima save it to my collections incase I ever actually finish a game.
@Souloux: Obviously, scripts that draw text different than the default will output it differently. What you got simply looks like you could switch the positions of this script and the UMS around and it should work fine.

@Brew: It's indeed a little and cool snippet to put into projects if you're too lazy to script custom color outputs for all your scenes... or simply can't. Personally, I prefer the 'direct' way for no special reason... but then again, I'm not exactly the "yay coloured text" person really :p
I'm personally not 100% about VX compatibility... did anyone check that by now?
@blueScope
the draw_text from VX is identical to the XP
Souloux, let me know if Bluescope's suggestion fixes it. Otherwise, I'll take a look at UMS & see if I can make them compatible.

I just tested in VX, and it error'd. Apparently, draw_text in VX converts non-strings so they call it with numbers as well. Fixed script to work in both.

Star, thanks.
@BlueScope I tried switching the position of the scripts. Either way came out with the same output.
  1. #       if str.is_a?(String)
  2. #         text = str.clone
  3. #       else
  4. #         text = str.to_s
  5. #       end
Expand to see the code.
Why do you clone the string here?
text = str.to_s.dup
would do the same thing, regardless of the value of the str.
Habit.
The string is not frozen, so clone & dup are the same in this case.
didn't occur to me to convert a string to a string.
i do this a lot when not sure if the variable will be always the way it's expected to be, so to ensure that it will be always of the type i expect i do something like this xD if the text is as string, no problem nothing changes, but if it's not, it will be converted.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=74073