Background Message System

Background Message System
Version: 1.0


Introduction

This script allows you to display text onscreen without interrupting the action. This is useful for cutscenes, minigames, etc. This has several advantages over the default message system.
  1. It does not interrupt the action. Events and characters can still move around and things can blow up while a message is onscreen.
  2. The player can still input, move the character, use items, etc. while the text is onscreen. This is useful for minigames where you don't want to interrupt the action.
  3. You can set the message to disappear exactly when you want it to in the events. This will make it much easier to make cutscenes by reducing the amount of trial and error.
  4. You can format the text of each individual line. You can change the face, size, color, outline, shadow, bold and italic status.
Screenshot

Included in attachment

Script


KGC_FrameShadowText Spoiler
Give credit to KGC for this script!
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#_/    ◆縁取り・影文字描画 - KGC_FrameShadowTextâ—†
#_/----------------------------------------------------------------------------
#_/  draw_text を強化し、縁取りや影文字の描画機能を追加します。
#_/  Provides functions to draw texts which framed or dropped shadow.
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

=begin
┏━━━━ 搭載メソッド - Methods ━━━━━━━━━━━━━━━━━━━━━━━
┠─── Class - Bitmap ────────────────────────────
┃ draw_frame_text(x, y, width, height, string[, align, frame_color])
┃ draw_frame_text(rect, string[, align, frame_color])
┃   x, y          : 描画先座標    [Integer]
┃                   Destination.
┃   width, height : 描画サイズ    [Integer]
┃                   Size.
┃   rect          : 描画領域      [Rect]
┃                   Rectangle.
┃   string        : 描画文字列    [String]
┃                   Output text.
┃   align         : 文字整列形式  [Integer]
┃                   Alignment.
┃   frame_color   : 縁取り色      [Color]
┃                   Frame color.
┃ 周りを frame_color で縁取りした文字列を描画します。
┃ Draws a character string framed in 'frame_color'.
┃
┃ draw_shadow_text(x, y, width, height, string[, align, frame_color])
┃ draw_shadow_text(rect, string[, align, frame_color])
┃   x, y          : 描画先座標    [Integer]
┃                   Destination.
┃   width, height : 描画サイズ    [Integer]
┃                   Size.
┃   rect          : 描画領域      [Rect]
┃                   Rectangle.
┃   string        : 描画文字列    [String]
┃                   Output text.
┃   align         : 文字整列形式  [Integer]
┃                   Alignment.
┃   frame_color   : 縁取り色      [Color]
┃                   Frame color.
┃ 右下に影を落とした文字列を描画します。
┃ Draws a character string which drops shadow to lower right.
┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
=end

$imported = {} if $imported == nil
$imported["FrameShadowText"] = true

#==============================================================================
# â–  Bitmap
#==============================================================================

class Bitmap
  #--------------------------------------------------------------------------
  # ● 縁取り文字描画
  #     x, y, width, height, string[, align, frame_color]
  #     rect, string[, align, frame_color]
  #--------------------------------------------------------------------------
  def draw_frame_text(*args)
    # 引数判定
    if args[0].is_a?(Rect)
      if args.size >= 2 && args.size <= 4
        # 引数を処理用のローカル変数へコピー
        x, y = args[0].x, args[0].y
        width, height = args[0].width, args[0].height
        string = args[1]
        align = args[2].equal?(nil) ? 0 : args[2]
        frame_color = args[3].equal?(nil) ? Color.new(0, 0, 0) : args[3]
      else
        # 引数が不正ならエラーを吐く
        raise(ArgumentError, "wrong number of arguments(#{args.size} of #{args.size < 2 ? 2 : 4})")
        return
      end
    else
      if args.size >= 5 && args.size <= 7
        # 引数を処理用のローカル変数へコピー
        x, y, width, height = args
        string = args[4]
        align = args[5].equal?(nil) ? 0 : args[5]
        frame_color = args[6].equal?(nil) ? Color.new(0, 0, 0) : args[6]
      else
        # 引数が不正ならエラーを吐く
        raise(ArgumentError, "wrong number of arguments(#{args.size} of #{args.size < 5 ? 5 : 7})")
        return
      end
    end
    # 元の色を保存
    origin_color = font.color.dup
    # 縁取り
    font.color = frame_color
    draw_text(x - 1, y - 1, width, height, string, align)
    draw_text(x - 1, y + 1, width, height, string, align)
    draw_text(x + 1, y - 1, width, height, string, align)
    draw_text(x + 1, y + 1, width, height, string, align)
    # 元の色に戻す
    font.color = origin_color
    draw_text(x, y, width, height, string, align)
  end
  #--------------------------------------------------------------------------
  # ● 影文字描画
  #     x, y, width, height, string[, align, shadow_color]
  #     rect, string[, align, shadow_color]
  #--------------------------------------------------------------------------
  def draw_shadow_text(*args)
    # 引数判定
    if args[0].is_a?(Rect)
      if args.size >= 2 && args.size <= 4
        # 引数を処理用のローカル変数へコピー
        x, y = args[0].x, args[0].y
        width, height = args[0].width, args[0].height
        string = args[1]
        align = args[2].equal?(nil) ? 0 : args[2]
        shadow_color = args[3].equal?(nil) ? Color.new(0, 0, 0) : args[3]
      else
        # 引数が不正ならエラーを吐く
        raise(ArgumentError, "wrong number of arguments(#{args.size} of #{args.size < 2 ? 2 : 4})")
        return
      end
    else
      if args.size >= 5 && args.size <= 7
        # 引数を処理用のローカル変数へコピー
        x, y, width, height = args
        string = args[4]
        align = args[5].equal?(nil) ? 0 : args[5]
        shadow_color = args[6].equal?(nil) ? Color.new(0, 0, 0) : args[6]
      else
        # 引数が不正ならエラーを吐く
        raise(ArgumentError, "wrong number of arguments(#{args.size} of #{args.size < 5 ? 5 : 7})")
        return
      end
    end
    # 元の色を保存
    origin_color = font.color.dup
    # 影描画
    font.color = shadow_color
    draw_text(x + 2, y + 2, width, height, string, align)
    # 元の色に戻す
    font.color = origin_color
    draw_text(x, y, width, height, string, align)
  end
end
Expand to see the code.

BMS Strings Spoiler
=begin
These are strings to be used in JesseG88's Background
Message System.

You can easily modify the strings or create new ones.
Just put them inside module STRINGS.

Refer to [Background Message] for instructions.
=end

module STRINGS
  BLANK = ""
  HELLO1 = "If you were hoping to see World, preceded by Hello, too bad!"
  HELLO2 = "Putting that in would be detrimental to my sanity."
  RED_ALERT = "Red Alert!  Red Alert!  Enemy forces detected!"
  BATTLE_STATIONS = "All hands to battle stations!"
end
Expand to see the code.

Background Message System Spoiler
=begin
#=======================================
# ** Background Message System
#------------------------------------------------------------------------------
# JesseG88
# 1.0
# 2006-06-06
#=======================================
# This allows text to show up onscreen during the game
# without interrupting events.  All event processing,
# including player input and "normal" messages will
# continue uninterrupted while text is displayed.  This
# is useful for cutscenes, minigames, etc.
#=======================================

#=====================================
#  Instructions
#=====================================

- Installation -
Place the strings file and the BMS file (this one) between
[Scene_Debug] and [Main].  Make sure to place the
strings ABOVE this file.

In addition, make sure to install [KGC_FrameShadowText]
or you will get an error.

- Making text strings -
Go into [BMS Strings] and look at the existing strings to see what
they should look like.  You can create new strings easile by following
the format and keeping them in the strings module.

For example:

module STRINGS
  STRING_NAME = "Text inside string"
end


=end
#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Background Message System', 'JesseG88', '1.0', '2006-06-06')
#------------------------------------------------------------------------------
# Begin SDK Enabled Check
#------------------------------------------------------------------------------
if SDK.state('Background Message System') == true
  module BMS
    #Perform any customizations inside this module.
 
    #Windowskin Opacity
    WINDOW_OPACITY = 0
   
    #Upper Left Corner
    WINDOW_X1 = 0
    WINDOW_Y1 = 0 #Set to 0 for top, 160 for middle, 320 for bottom.
 
    #Window Size
    WINDOW_X2 = 640
    WINDOW_Y2 = 160
 
    #Line 1 Settings
    LINE1_FONT_FACE = "Arial"
    LINE1_FONT_SIZE = 20
    LINE1_FONT_BOLD = true
    LINE1_FONT_ITALIC = false
    LINE1_FONT_COLOR = Color.new(255, 255, 255, 255)
    LINE1_FST_MODE = 0 # 0-Plain,  1-Frame,  2-Shadow
    LINE1_STRING = STRINGS::BLANK
 
    #Line 2 Settings
    LINE2_FONT_FACE = "Arial"
    LINE2_FONT_SIZE = 20
    LINE2_FONT_BOLD = true
    LINE2_FONT_ITALIC = false
    LINE2_FONT_COLOR = Color.new(255, 255, 255, 255)
    LINE2_FST_MODE = 0 # 0-Plain,  1-Frame,  2-Shadow
    LINE2_STRING = STRINGS::BLANK
 
    #Line 3 Settings
    LINE3_FONT_FACE = "Arial"
    LINE3_FONT_SIZE = 20
    LINE3_FONT_BOLD = true
    LINE3_FONT_ITALIC = false
    LINE3_FONT_COLOR = Color.new(255, 255, 255, 255)
    LINE3_FST_MODE = 0 # 0-Plain,  1-Frame,  2-Shadow
    LINE3_STRING = STRINGS::BLANK
 
    #Line 4 Settings
    LINE4_FONT_FACE = "Arial"
    LINE4_FONT_SIZE = 20
    LINE4_FONT_BOLD = true
    LINE4_FONT_ITALIC = false
    LINE4_FONT_COLOR = Color.new(255, 255, 255, 255)
    LINE4_FST_MODE = 0 # 0-Plain,  1-Frame,  2-Shadow
    LINE4_STRING = STRINGS::BLANK
 
    #Unless you know what you are doing,
    #do not modify anything below this line.
  end

  class Window_BGMessage < Window_Base
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    def initialize
      super(BMS::WINDOW_X1, BMS::WINDOW_Y1, BMS::WINDOW_X2, BMS::WINDOW_Y2)
      self.contents = Bitmap.new(width - 32, height - 32)
      self.opacity = BMS::WINDOW_OPACITY
      refresh
    end
    #--------------------------------------------------------------------------
    # * Refresh
    #--------------------------------------------------------------------------
    def refresh
      self.contents.clear
     
      #Collect settings from BMS module, then print text.
      #Start of Line 1
      self.contents.font.name = BMS::LINE1_FONT_FACE
      self.contents.font.size = BMS::LINE1_FONT_SIZE
      self.contents.font.bold = BMS::LINE1_FONT_BOLD
      self.contents.font.italic = BMS::LINE1_FONT_ITALIC
      self.contents.font.color = BMS::LINE1_FONT_COLOR
      case BMS::LINE1_FST_MODE
      when 0
        self.contents.draw_text(0, 0, 608, 32, BMS::LINE1_STRING)
      when 1
        self.contents.draw_frame_text(0, 0, 608, 32, BMS::LINE1_STRING)
      when 2
        self.contents.draw_shadow_text(0, 0, 608, 32, BMS::LINE1_STRING)
      end
      #End of Line 1
   
      #Start of Line 2
      self.contents.font.name = BMS::LINE2_FONT_FACE
      self.contents.font.size = BMS::LINE2_FONT_SIZE
      self.contents.font.bold = BMS::LINE2_FONT_BOLD
      self.contents.font.italic = BMS::LINE2_FONT_ITALIC
      self.contents.font.color = BMS::LINE2_FONT_COLOR
      case BMS::LINE2_FST_MODE
      when 0
        self.contents.draw_text(0, 32, 608, 32, BMS::LINE2_STRING)
      when 1
        self.contents.draw_frame_text(0, 32, 608, 32, BMS::LINE2_STRING)
      when 2
        self.contents.draw_shadow_text(0, 32, 608, 32, BMS::LINE2_STRING)
      end
      #End of Line 2
   
      #Start of Line 3
      self.contents.font.name = BMS::LINE3_FONT_FACE
      self.contents.font.size = BMS::LINE3_FONT_SIZE
      self.contents.font.bold = BMS::LINE3_FONT_BOLD
      self.contents.font.italic = BMS::LINE3_FONT_ITALIC
      self.contents.font.color = BMS::LINE3_FONT_COLOR
      case BMS::LINE3_FST_MODE
      when 0
        self.contents.draw_text(0, 64, 608, 32, BMS::LINE3_STRING)
      when 1
        self.contents.draw_frame_text(0, 64, 608, 32, BMS::LINE3_STRING)
      when 2
        self.contents.draw_shadow_text(0, 64, 608, 32, BMS::LINE3_STRING)
      end
      #End of Line 3
   
      #Start of Line 4
      self.contents.font.name = BMS::LINE4_FONT_FACE
      self.contents.font.size = BMS::LINE4_FONT_SIZE
      self.contents.font.bold = BMS::LINE4_FONT_BOLD
      self.contents.font.italic = BMS::LINE4_FONT_ITALIC
      self.contents.font.color = BMS::LINE4_FONT_COLOR
      case BMS::LINE4_FST_MODE
      when 0
        self.contents.draw_text(0, 128, 608, 32, BMS::LINE4_STRING)
      when 1
        self.contents.draw_frame_text(0, 128, 608, 32, BMS::LINE4_STRING)
      when 2
        self.contents.draw_shadow_text(0, 128, 608, 32, BMS::LINE4_STRING)
      end
      #End of Line 4
   
    end #of def refresh
  end #of class Window_BGMessage
 
end #of if SDK.state('Background Message System') == true
#------------------------------------------------------------------------------
# End SDK Enabled Test
#------------------------------------------------------------------------------
Expand to see the code.

Instructions

Installation

Get the SDK, and all the scripts listed above. Place them in the following order in the editor:
  • SDK
  • KGC_FrameShadowText
  • BMS Strings
  • Background Message
Setting up Strings
Go into BMS strings and look at the example strings that are already in there. Adding a new string should be ridiculously easy.

Formatting the window
Go into Background Message and look at module BMS. (Lines 49-101) Simply change the attributes to suit your needs. You can even change the attirbutes in-game. Just add "BMS::", without quotes, to an attribute in an in-game script. It should similar to this:
BMS::LINE1_FST_MODE = 1
BMS::LINE1_FONT_COLOR = Color.new(255, 0, 0, 255)
Expand to see the code.

Making the message appear in-game
Run a script like this:
BMS::LINE1_STRING = STRINGS::HELLO1
BMS::LINE2_STRING = STRINGS::HELLO2
@BGMessage = Window_BGMessage.new
Expand to see the code.

The line BMS::LINE1_STRING = STRINGS::HELLO1 binds a text string to a line. Change the blue to the line you want to set, and the red text to the string ID you want to use. Note that for very short strings, you may just want to set the string text in the command itself, as in
BMS::LINE1_STRING = "Aluxus"

The line @BGMessage = Window_BGMessage.new causes the message to appear onscreen.

Removing a message
Run this script:
@BGMessage.dispose
Expand to see the code.

Note that if you want to change the message to display a different string, you will need to dispose the current message first before calling a new one. Otherwise, they will both show up at the same time and cause problems.

Compatibility
This script requires the SDK. It also needs KGC's Frame and Shadow Text script, which I included.

Bugs, Errors
If you call a message and dispose of it on a different page or event, you may get an error message. To avoid this, call the message and dispose of it on the same event page.

Credits and Thanks

SDK Team - SDK
KGC Software - Frame and Shadow Text script, as well as the idea of customization modules.

Author's Notes

This is the first script I have posted, so it may not be all that great.
I may post a demo later.
This is pretty cool, if I find that I need it in my game, I'll definately use it.
Couldn't you just Parallel Process? But then again, this might reduce the lag. Well done!
does it have to use the SDK ?
sorry to ask but i have mostly non SDK and this would make a good addition but would kill my other Scripts if i have to use the SDK (it screws literally everything)
Yeah, SDK-must is not good, as it decreases script usuability instead of increasing it ^_^ I'd also like to see a AMS-version to show text strings over close NPCs.
Simply remove the SDK lines. These lines...
#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Background Message System', 'JesseG88', '1.0', '2006-06-06')
#------------------------------------------------------------------------------
# Begin SDK Enabled Check
#------------------------------------------------------------------------------
if SDK.state('Background Message System') == true
Expand to see the code.
And these.
end #of if SDK.state('Background Message System') == true
#------------------------------------------------------------------------------
# End SDK Enabled Test
#------------------------------------------------------------------------------
Expand to see the code.
Nice job, this would be cool for a game which uses the ABS, since the action wont be interuppted :)
This is pretty sweet. Very useful for my game actually. This'll stop the lagging.
Great work!
I Juss' gotta say - you are an amazing person. I've been trying to do something like this for a while now, but just don't have the brains - I hand it to you :D Now ive just got to put it in my game...hmmm....
is there any way to make it fade after a certain amount of time?
^Sorry
This could help a lot in my game since I hate having all the lag due to the many cutscenes.
Thanks!

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