Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Jaber's Super-Simple Message System v1.11

This is an add-on to the default message system that does two things:
1. Allows for more control over the positioning and display of message windows
2. Allows for the display of a face/name in a side window

You just stick it above main and you're done:
Code:
# Jaber's Super-Simple Message System v1.11

class Message_Data

  

  attr_accessor :pos, :face, :face_pos, :name, :name_pos, :offset, :battle_pos,

            :battle_offset, :opacity, :back_opacity, :face_offset, :last_data,

            :small_name

  

  def initialize

    @pos = 2

    @face = nil

    @face_pos = 4

    @name = nil

    @name_pos = 8

    @offset = 16

    @battle_pos = 8

    @battle_offset = 16

    @opacity = 255

    @back_opacity = 160

    @face_offset = 12

    @last_data = [@pos, @face, @face_pos, @name, @name_pos]

    @small_name = true

  end

  

  def get_data

    return [@pos, @face, @face_pos, @name, @name_pos]

  end

  

end

 

class Game_System

  

  attr_accessor :message_settings

  

  alias jaber_init initialize unless method_defined?(:jaber_init)

  def initialize

    jaber_init

    $message = nil

  end

  

end

 

class Scene_Save < Scene_File

  

  alias jaber_write_save write_save_data unless method_defined?(:jaber_write_save)

  def write_save_data(file)

    $game_system.message_settings = $message

    jaber_write_save(file)

  end

  

end

 

class Window_Message < Window_Selectable

  

  alias jaber_init initialize unless method_defined?(:jaber_init)

  def initialize

    jaber_init

    @face_window = Window_Face.new

    if $message == nil

      if $game_system.message_settings != nil

        $message = $game_system.message_settings

      else

        $message = Message_Data.new

      end

    end

  end

  

  alias jaber_dispose dispose unless method_defined?(:jaber_dispose)

  def dispose

    @face_window.dispose

    jaber_dispose

  end

  

  def reset_window

    pos = $game_temp.in_battle ? $message.battle_pos : $message.pos

    off = $game_temp.in_battle ? $message.battle_offset : $message.offset

    self.x = 0 if [1,4,7].include?(pos)

    self.x = 80 if [2,5,8].include?(pos)

    self.x = 160 if [3,6,9].include?(pos)

    self.y = 0 + off if [7,8,9].include?(pos)

    self.y = 160 if [4,5,6].include?(pos)

    self.y = 320 - off if [1,2,3].include?(pos)

    self.x += pos == 4 ? off : pos == 6 ? -off : 0

    self.back_opacity = $message.back_opacity

    self.opacity = $message.opacity

    @face_window.opacity = self.opacity

    @face_window.back_opacity = self.back_opacity

    case $message.face_pos

    when 1

      @face_window.x = self.x

      @face_window.y = self.y + self.height

    when 2

      @face_window.x = (self.x + (self.width / 2)) - (@face_window.width / 2)

      @face_window.y = self.y + self.height

    when 3

      @face_window.x = (self.x + self.width) - @face_window.width

      @face_window.y = self.y + self.height

    when 4

      @face_window.x = self.x - @face_window.width

      @face_window.y = self.y

    when 5 # derp

      @face_window.x = self.x + (self.width / 2) - (@face_window.width / 2)

      @face_window.y = self.y

    when 6

      @face_window.x = self.x + self.width

      @face_window.y = self.y

    when 7

      @face_window.x = self.x

      @face_window.y = self.y - @face_window.height

    when 8

      @face_window.x = (self.x + (self.width / 2)) - (@face_window.width / 2)

      @face_window.y = self.y - @face_window.height

    when 9

      @face_window.x = (self.x + self.width) - @face_window.width

      @face_window.y = self.y - @face_window.height

    end

    @face_window.update_name

    if $message.name == nil and $message.face == nil

      @face_window.visible = false

    else

      @face_window.visible = true

    end

    if @face_window.need_update

      @face_window.contents_opacity = 0 if @face_window.face != $message.face or @face_window.face == nil

      @face_window.update_face

    end

  end

  

  alias jaber_update update unless method_defined?(:jaber_update)

  def update

    @face_window.opacity = self.opacity

    @face_window.back_opacity = self.back_opacity

    @face_window.contents_opacity += 24 if @face_window.contents_opacity < 255

    @face_window.visible = false if $game_temp.message_text == nil and @face_window.showing

    @face_window.update

    jaber_update

  end

  

end

 

class Window_Face < Window_Base # Hey, that rhymes! Sort of!

  

  attr_accessor :face, :name

  

  def initialize

    @name_window = Window_Name.new

    super(0,0,160,160)

    self.contents = Bitmap.new(width - 32, height - 32)

    self.z = 9998

    self.opacity = 0

    self.back_opacity = 0

    self.contents_opacity = 0

    self.visible = false

    @name = nil

    @face = nil

    @name_pos = nil

    @face_offset = nil

  end

  

  def need_update

    if $message.last_data != $message.get_data

      $message.last_data = $message.get_data.dup

      @name = nil

      @face = nil

      return true

    end

    return (@face != $message.face or @name != $message.name or @face_offset != $message.face_offset or @name_pos != $message.name_pos)

  end

  

  def update_face

    @face = $message.face

    @name = $message.name

    @face_offset = $message.face_offset

    @name_pos = $message.name_pos

    self.contents.clear

    if $message.face == nil and $message.name != nil and $message.small_name == true

      self.visible = false

      align = [7,4,1].include?($message.name_pos) ? 0 : [8,5,2].include?($message.name_pos) ? 1 : 2

      @name_window.update($message.name.to_s, align)

      @name_window.visible = true

    else

      @visible = true

      @name_window.visible = false

      if $message.face != nil

        bitmap = RPG::Cache.picture($message.face) rescue bitmap = nil

        self.contents.blt((self.contents.width - bitmap.width) / 2, ((self.contents.height - bitmap.height) / 2) + $message.face_offset, bitmap, Rect.new(0, 0, bitmap.width, bitmap.height)) if bitmap != nil

      end

      if $message.name != nil

        align = [7,4,1].include?($message.name_pos) ? 0 : [8,5,2].include?($message.name_pos) ? 1 : 2

        y = [7,8,9].include?($message.name_pos) ? 0 : [4,5,6].include?($message.name_pos) ? (self.contents.height / 2) - 12 : self.contents.height - 24

        self.contents.draw_text(0, y, self.contents.width, 24, $message.name.to_s, align)

      end

    end

  end

  

  def visible=(bool)

    @name_window.visible = false unless bool

    super(bool)

  end

  

  def update

    update_name

    super

  end

  

  def update_name

    @name_window.x = self.x

    @name_window.y = self.y

    if [4,5,6].include?($message.face_pos)

      @name_window.y += 80 - (@name_window.height / 2) if [4,5,6].include?($message.name_pos)

      @name_window.y += 160 - @name_window.height if [1,2,3].include?($message.name_pos)

    end

    @name_window.y += 160 - @name_window.height if [7,8,9].include?($message.face_pos)

  end

  

  def opacity=(val)

    @name_window.opacity = val

    super(val)

  end

  

  def back_opacity=(val)

    @name_window.back_opacity = val

    super(val)

  end

  

  def contents_opacity=(val)

    @name_window.contents_opacity = val

    super(val)

  end

  

  def dispose

    @name_window.dispose

    super

  end

  

  def showing

    return (self.visible or @name_window.visible)

  end

  

end

 

class Window_Name < Window_Base

  

  def initialize

    super(0,0,160,64)

    self.contents = Bitmap.new(width - 32, height - 32)

    self.z = 9998

    self.opacity = 0

  end

  

  def update(name, align)

    self.contents.clear

    self.contents.draw_text(0, 0, self.contents.width, 24, name, align)

    super()

  end

  

end

The 'Change Text Options' event command will no longer have any effect on message windows, but that's okay because it won't be needed anymore.
The features are controlled from a script call by making changes to the new $message variables:
$message.small_name = X
This will toggle the use of the smaller name box when a face is not being displayed. X is true/false.

$message.pos = X
$message.battle_pos = X
$message.face_pos = X
$message.name_pos = X

These will change the location of the message window out of and during battle, the side of the message box that the face window is displayed on, and where the name text will be displayed in the face window, respectively. X is 1-9, where the location corresponds to that number's location on the numberpad, i.e. 1 = lower left, 5 = center, 8 = top, etc.
If a small name box is being used, name_pos determines the vertical alignment of the box(if face_pos is 4/5/6) and the alignment of the text inside(i.e. 1/4/7 = left justification, 2/5/8 = centered, 3/6/9 = right)

$message.offset = X
$message.battle_offset = X
$message.face_offset = X

This will modify the distance of the message box from the edge of the screen, and how high/low the face picture will be displayed in the face window.

$message.face = "X"
This will display an image from the pictures folder in the face window, where X is the name of the image in quotation marks. Set it to nil to stop displaying the image.

$message.name = "X"
This will write some text to the face window, where X is the text to be written, again in quotation marks. Set it to nil to stop displaying the text. If both $message.face and $message.text are set to nil, the face window will not be displayed.

$message.opacity = X
This will change the opacity of both the message window and face window. X is 0-255.

$message.back_opacity = X
This will change the opacity of the back of both the message window and face window. It won't display at a higher opacity than the $message.opacity is set to, though.





Changelog
v1.11
-Fixed issue with displaying the same name/face twice in a row

v1.1
-Added small name window
-Improved face window display transitions
-Fixed a bug wherein the face window would be cleared instead of hidden

v1.0
-Initial release
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top