RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.
[VXA] Global Text Codes 1.0

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Global Text Codes
Version: 1.0a
Author: modern algebra
Date: April 5, 2012

Version History


  • <Version 1.0a> 2012.04.05 - Fixed an issue with replacement codes
  • <Version 1.0> 2012.01.05 - Original Release

Description


This script allows you to use special message codes in any window, not just message windows and help windows. Want to add an icon next to the menu commands? With this script you can do that and more.

Note: using special message codes in a text will make it so that the text will not shrink if it exceeds its specified width. As a result, you will need to be careful about that.

Features

  • Can use text codes anywhere
  • On manual, should work quite quickly
  • Compatible with other codes introduced in separate message systems, such as my ATS: Special Message Codes
  • Replacement Codes permit you to ignore otherwise strict size limitations in the database, allowing you to input long codes without sacrificing the text

Screenshots


All of the icons and colours were added through the use of message codes.

Instructions

Paste this script into its own slot in the Script Editor, above Main and below Materials. Beyond that, this script is pretty much plug & play.

The only thing to remember is that unless you change this script to operate automatically (not recommended), then in order for a phrase to recognize text codes, you must place \* somewhere in the text itself. In other words, if you are trying to add colour to the Hand Axe's name, then it is not sufficient to be: \c[5]Hand Axe\c[0]; it must be \*\c[5]Hand Axe\c[0].

Script


Code: [Select]
#==============================================================================
#    Global Text Codes [VXA]
#    Version: 1.0a
#    Author: modern algebra (rmrk.net)
#    Date: April 5, 2012
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script allows you to use special message codes in any window, not
#   just message windows and help windows. Want to add an icon next to the
#   menu commands? With this script you can do that and more.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Simply paste this script into its own slot above Main and below Materials
#   and other custom scripts.
#
#    There are two settings for this script - automatic and manual. If set to
#   automatic, then all you will need to do is put any of the special message
#   codes in anything and they will automatically work. If set to manual, then
#   you will also need to type the following code somewhere in the text field
#   to activate it: \*
#
#    The following default codes are available:
#
# \c[n] - Set the colour of the text being drawn to the nth colour of the
#     Windowskin palette. 0 is the normal color and 16 is the system color.
# \i[n] - Draw icon with index n.
# \p[n] - Draw the name of the actor in the xth position in the party. 1 is
#     the party leader, 2 is the second member, etc.
# \n[n] - Draw the name of the actor with ID n
# \v[n] - Draw the value of variable with ID n.
# \g - Draws the unit of currency.
#
#    Depending on whether you are using any custom message script, you may have
#   additional message codes at your disposal. This script is mostly compatible
#   with my ATS and every code except \x and ones related to message control
#   will work.
#==============================================================================

$imported = {} unless $imported
$imported[:MAGlobalTextCodes] = true
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#  Editable Region
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#  MAGTC_MANUAL_CODES - If this is true, then you must put a \* code in any
# field that you want to have codes interpreted in. Otherwise, codes will
# always automatically be interpreted. The recommended value for this is true,
# as the process for drawing text with codes is much slower than the process
# for drawing text without codes.
MAGTC_MANUAL_CODES = true
#  MAGTC RCODES - This feature is designed to overcome the space limitations in
# much of the database - since codes take so much of that space, it might be
# difficult to write everything you want into one of those fields. This feature
# permits you to write the term you want in to the following array, and then
# access it in the database with the code \r[n], where n is the ID you assign
# to the phrase in the following way:
#
#    n => "replacement",
#
# Please note that: it is =>, not =; the replacement must be within quotation
# marks; and there must be a comma after every line. If using double quotation
# marks ("", not ''), then you need to use two backslashes to access codes
# instead of one (\\c[1], not \c[1]).
#
#  EXAMPLE:
#   0 => "\\i[112]\\c[14]New Game\\c[0]",
#
#  Under the New Game field in the Terms of the Database, all I would then need
# to put is:
#    \*\r[0]
#  and it would be the same as if I had put:
#    \*\i[112]\c[14]New Game\c[0]
MAGTC_RCODES = { # <- Do not touch
  0 => "\\i[112]\\c[14]New Game\\c[0]", # Example
  1 => "", # You can make as many of these as you want
  2 => "\\i[40]Blood Hound",
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#  END Editable Region
#//////////////////////////////////////////////////////////////////////////////
}
MAGTC_RCODES.default = ""

#==============================================================================
# ** Window_Base
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased methods - draw_text; convert_escape_characters; process_new_line;
#      reset_font_settings
#    new methods - magtc_align_x; magtc_test_process_escape_character;
#      magtc_calc_line_width
#==============================================================================

class Window_Base
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Draw Text
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias ma_gtc_drwtxt_3fs1 draw_text
  def draw_text(*args, &block)
    # Get the arguments
    if args[0].is_a?(Rect)
    x, y, w, h = args[0].x, args[0].y, args[0].width, args[0].height
    text, align = *args[1, 2]
  else
    x, y, w, h, text, align = *args[0, 6]
  end
    align = 0 unless align
    #  Draw normally if text is not a string, draw normally if the text is not
    # long enough to hold a code, and draw normally when the script is set to
    # manual and \* is included in the text
  if !text.is_a?(String) || text.size < 2 || (MAGTC_MANUAL_CODES && text[/\\\*/].nil?)
    ma_gtc_drwtxt_3fs1(*args, &block) # Run Original Method
  else
      @magtc_reset_font = contents.font.dup # Do not automatically reset font
      @magtc_rect, @magtc_align = Rect.new(x, y, w, h), align
      # Get first line of the text to test for alignment
      @magtc_test_line = convert_escape_characters(text[/.*/])
      y += [(h - calc_line_height(@magtc_test_line)) / 2, 0].max
      # Draw text with message codes
    draw_text_ex(magtc_align_x(x), y, text)
      @magtc_reset_font = nil # Do not automatically reset font
      @magtc_rect, @magtc_align = nil, nil # Reset Rect and Alignment
  end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Convert Escape Characters
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias ma_gtc_convescchar_5tk9 convert_escape_characters
  def convert_escape_characters(text, *args, &block)
    # Remove \* codes
    new_text = text.gsub(/\\\*/, "")
    # Substitute for the R Codes
    new_text.gsub!(/\\[Rr]\[(\d+)\]/) { MAGTC_RCODES[$1.to_i].to_s }
    ma_gtc_convescchar_5tk9(new_text, *args, &block) # Call Original Method
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Reset Font Settings
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias magtc_resetfonts_4ga5 reset_font_settings
  def reset_font_settings(*args, &block)
    magtc_resetfonts_4ga5(*args, &block) # Call Original Method
    contents.font = @magtc_reset_font if @magtc_reset_font
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Process New Line
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias magtc_prcsnewl_5gn9 process_new_line
  def process_new_line(text, pos, *args, &block)
    magtc_prcsnewl_5gn9(text, pos, *args, &block) # Run Original Method
    if @magtc_align && @magtc_rext
      @magtc_test_line = text[/.*/] # Get new line
      pos[:x] = magtc_align_x       # Get the correct x, depending on alignment
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Get Alignment X
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def magtc_align_x(start_x = @magtc_rect.x)
    return start_x unless (@magtc_rect && @magtc_align && @magtc_test_line) || @magtc_align != 0
    tw = magtc_calc_line_width(@magtc_test_line)
    case @magtc_align
    when 1 then return start_x + ((@magtc_rect.width - tw) / 2)
    when 2 then return start_x + (@magtc_rect.width - tw)
    end
    start_x
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Calc Line Width
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def magtc_calc_line_width(line)
    # Remove all escape codes
    line = line.clone
    line.gsub!(/[\n\r\f]/, "")
    real_contents = contents # Preserve Real Contents
    # Create a dummy contents
    self.contents = Bitmap.new(@magtc_rect.width, @magtc_rect.height)
    reset_font_settings
    pos = {x: 0, y: 0, new_x: 0, height: calc_line_height(line)}
    tw = 0
    while line[/^(.*?)\e(.*)/]
      tw += text_size($1).width
      line = $2
      # Remove all ancillaries to the code, like parameters
      code = obtain_escape_code(line)
      magtc_test_process_escape_character(code, line, pos)
    end
    #  Add width of remaining text, as well as the value of pos[:x] under the
    # assumption that any additions to it are because the special code is
    # replaced by something which requires space (like icons)
    tw += text_size(line).width + pos[:x]
    self.contents.dispose # Dispose dummy contents
    self.contents = real_contents # Restore real contents
    return tw
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Test Process Escape Character
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def magtc_test_process_escape_character(code, text, pos)
    if $imported[:ATS_SpecialMessageCodes] && ['X', 'HL'].include?(code.upcase)
      obtain_escape_param(text)
      return
    end
    process_escape_character(code, text, pos)
  end
end

Credit


  • modern algebra

Support


Please post in this topic at RMRK to report any errors or to ask any questions about this script.

Known Compatibility Issues

This script can use many of the codes added by my ATS: Special Message Codes. Though untested, I suspect that it also works with Yanfly's Message System and will likely work with some other message systems as well.
« Last Edit: April 05, 2012, 11:46:41 AM by modern algebra »

**
Rep:
Level 72
RMRK Junior
This will be very helpful.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
The famous script returns! Very nice.


**
Rep:
Level 66
RMRK Junior
it's a very useful script! but I have problem with ATS.
There is an image:

http://imageshack.us/f/16/atsgc.png/
Text color works nice in Items/Equipment/etc, but I need, after open the chest, show Item Icon and colored Item Name. However, I have this \*\c[22]Black Bullets\c[0] code in message.. What I'm doing wrong?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
What is happening is just that the relevant substitutions are performed before the \ni \na \nw substitutions.

That is what the \RESUB feature is for - just add \resub into the message box (not the name of the item) anywhere and it will run through the substitution method again.

That said, I apparently broke that feature in the ATS SMC, so you will need to go into the ATS SMC script around line 360 and change these two lines:

Code: [Select]
  def convert_escape_characters(*args, &block)
    result = ma_atssmc_convesc_4rc1(*args, &block) # Run Original Method

to:

Code: [Select]
  def convert_escape_characters(text, *args, &block)
    result = ma_atssmc_convesc_4rc1(text, *args, &block) # Run Original Method


Once you fix that error, all you will need to do is put the \resub code into the message. In other words, instead of:

Display Text: Found \ia[64]\na[64]!

Do this:

Display Text: Found \ia[64]\na[64]!\resub
« Last Edit: February 03, 2012, 09:52:52 PM by modern algebra »

**
Rep:
Level 66
RMRK Junior
Thanks a lot! Message code is not very long, and it solves my problem. Great!

I'll continue my experiments with ATS : )

*
Rep:
Level 73
Artista
2012 Best Artist2012 Best RPG Maker User (Graphical)2011 Best RPG Maker User (Graphical)Winner - 2011 Summer Project of the Season
I'm currently setting up this script with a project, and I seem to have encountered an issue with the replacement codes.

No matter what number I put in \*\r[n], it always returns as 0 - so it only displays the first line on the list. I'm not sure why it does that, but I figured I would report it.

I am using the version that's currently in the first post. In terms of message scripts, I'm currently using Yanfly's Ace Message script and an arrow font fix (scriplet that replaces the arrow in the equip menu if the font doesn't have the right character).

I can post a list of other scripts, too, if needed. :)
My current project:

**
Rep:
Level 56
RMRK Junior
I hope I'm not insulting your intelligence by asking this, but you have set up the number you're putting in square brackets under the MAGTC_RCODES constant, right?
It's more like a big ball of wibbly wobbly...timey wimey...stuff.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Alright, I fixed that error - grab the script again from the first post.

*
Rep:
Level 73
Artista
2012 Best Artist2012 Best RPG Maker User (Graphical)2011 Best RPG Maker User (Graphical)Winner - 2011 Summer Project of the Season
@Trihan:
Yes, I was. I double and triple checked to make sure I wasn't messing up the configuration.  :lol:

@modern algebra:
Thank you! It displays the right line.

Now, the only small issue I have is when I use it to replace the "New Game" etc, the window doesn't get extended to compensate for extra text length. It's not a big deal, and I can certainly re-word the commands to take up less space. But I figured it would help to report it.
My current project:

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, that is not within the scope of this particular script, but it is actually extremely easy to widen the title screen's command window. Just paste the following code into its own slot above Main and below Materials:

Code: [Select]
class Window_TitleCommand
  def window_width
    160
  end
end

Change the 160 on the third line to whatever width you want the window to be (in pixels).

*
Rep:
Level 73
Artista
2012 Best Artist2012 Best RPG Maker User (Graphical)2011 Best RPG Maker User (Graphical)Winner - 2011 Summer Project of the Season
Ah, thank you!  :)

I certainly appreciate the help.
My current project:

****
Rep:
Level 69
I put in the \* before the name and I got this error:

Is it compatible with special message codes or did I forget to do something?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
No, the two scripts are compatible.

My guess is that you failed to identify a code properly and received the error that my Escape Codes Fix responds to. Check and make sure that there are no codes like \[] where you failed to put anything between the \ and the [.


If that's not the problem, please upload a project with the error recreated so that I can take a look.
« Last Edit: April 27, 2012, 11:40:49 PM by modern algebra »

****
Rep:
Level 69
It works, I don't know what I did wrong but it works now. ;D
I probably put the wrong slash or something.

****
Rep:
Level 69
I was coloring some things and I wanted 'Shutdown' on the main screen to be white and yellow for going at it from the game menu, but it colors both at the same time, is there any way to 'split' it?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
No, since both use the same string. If you wanted that, you'd need to manually change the string for one or the other. For instance, you could set it up with the yellow code in the database, and then go into the Window_TitleCommand and find this method at lines 31 to 38:

Code: [Select]

  #--------------------------------------------------------------------------
  # * Create Command List
  #--------------------------------------------------------------------------
  def make_command_list
    add_command(Vocab::new_game, :new_game)
    add_command(Vocab::continue, :continue, continue_enabled)
    add_command(Vocab::shutdown, :shutdown)
  end

You could then replace the last line with:

Code: [Select]
    add_command("Shutdown", :shutdown)

Replace Shutdown with whatever you want the command to be on the title screen, but keep the quotation marks. Where " " is being used, you'll need to use \\ instead of \ if you want any codes. Ie: "\\*\\c[4]Shutdown", and not: "\*\c[4]Shutdown"
« Last Edit: March 17, 2013, 03:47:14 AM by modern algebra »

****
Rep:
Level 69
Thank you very much! It works!