My own Message System
#1
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


I make my own Message system. Comes with a name box, easy picture use, Auto Resize, Change of font and size, Bold and Italic text. Check the demo or the images to view that.

Whats new?
- Added the window over event
- Show Picure inside the window
- Added the icon display
- Added the item, weapon, armor & skill icon display
- Added the hero class name
- Fixed some little things


Code:
#-----------------------------------------------------------------
# ¦ Slipknot's Advance Message System ¦
#-----------------------------------------------------------------
#  Last Update: 03/12/05
#   - Added the window over event
#   - Show Picure inside the window
#   - Added the icon display
#   - Added the item, weapon, armor & skill icon display
#   - Added the hero class name
#   - Fixed some little things
#-----------------------------------------------------------------
#  - Show Picture (above) by Slipknot
#  - Auto Resize by Slipknot
#  - Different Display Text by Slipknot
#  - Bold & Italic Text by Slipknot
#  - Hero Class Name by Slipknot
#  - Icon Display by Slipknot
#  - Item, Weapon, Armor & Skill icon by Dubealex*
#  - Show Picture (in) by Dubealex*
#  - Name Box by Dubealex*
#  - Text size by Dubealex*
#  - Text font by Dubealex*
#  - Window Over Event by Dubealex*
#  - Outline Text from Alestian Story*
#  - Shadow Text from Alestian Story*
#  * edited by Slipknot
#-----------------------------------------------------------------
# Set the default text display
$default_text = 0
#-----------------------------------------------------------------
class Window_Message < Window_Selectable
#-----------------------------------------------------------------
  def initialize
    super(65,299,510,175)
    self.contents = Bitmap.new(width-32,height-32)
    self.visible = false
    self.z = 9998
    @contents_showing = @fade_in = @fade_out = false
    @cursor_width = 0
    self.active = false
    self.index = -1
    self.opacity = 0
    # Change it to change the pictures folder for the messages
    @path = "Graphics/Pictures/Message/"
    @back = Window_Base.new(self.x,self.y,self.width,self.height)
    @back.visible = false
  end
#-----------------------------------------------------------------
  def dispose
    terminate_message
    $game_temp.message_window_showing = false
    @back.dispose
    if @input_number_window != nil
      @input_number_window.dispose
    end; super
  end
#-----------------------------------------------------------------
  alias sk_terminate_message terminate_message
  def terminate_message
    sk_terminate_message
    if @name_box != nil
     @name_box.dispose
     @name_box = nil
    end
    if @name_box_text  != nil
      @name_box_text.dispose
      @name_box_text = nil
    end
    if @picture != nil
      @picture.dispose
      @picture = nil
    end
  end
#-----------------------------------------------------------------
  def refresh
    self.contents.clear
    # Setting the text options to default
    self.contents.font.name = $defaultfonttype
    self.contents.font.size = 22
    self.contents.font.bold = false
    self.contents.font.italic = false
    case $default_text
    when 0 then disp_text
    when 1 then disp_text(false,true)
    when 2 then disp_text(true) end
    # Setting some variables to 0
    @cursor_width = color = x = y = sx = 0
    x=8 if $game_temp.choice_start == 0
    if $game_temp.message_text != nil
      text = $game_temp.message_text
      begin
        last_text = text.clone
        # Show Variables Value
        text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
      end until text == last_text
      # Show Hero Name
      text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
        $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
      end
      # Show Hero Class Name
      text.gsub!(/\\[Cc]lass\[([0-9]+)\]/) do
        $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].class_name : ""
      end
      name_box = face = picture = over_event = false
      # Name box
      if (/\\[Nn]a\[(.+?)\]/.match(text)) != nil
        name_box = true
        name_text = $1
        text.sub!(/\\[Nn]a\[(.*?)\]/){""}
      end
      # Picture
      if (/\\[Pp]ic\[(.+?)\]/.match(text)) != nil
        picture = true
        pic_name = $1
        text.sub!(/\\[Pp]ic\[(.*?)\]/){""}
      end
      # Face
      if (/\\[Ff]ace\[(.+?)\]/.match(text)) != nil
        @face = true
        face_name = $1
        text.sub!(/\\[Ff]ace\[(.*?)\]/){""}
      end
      # Window over event
      if (/\\[Pp]\[([-1,0-9]+)\]/.match(text)) != nil
        over_event = true
        event = $1.to_i
        text.sub!(/\\[Pp]\[([-1,0-9]+)\]/){""}
      end
      # "\" display
      text.gsub!(/\\\\/){"\000"}
      # Text Color
      text.gsub!(/\\[Cc]\[([0-9]+)\]/){"\001[#{$1}]"}
      # Show Gold Window
      text.gsub!(/\\[Gg]/){"\002"}
      # Text size
      text.gsub!(/\\[Tt][Ss]\[([0-9]+)\]/){"\003[#{$1}]"}
      # Text font
      text.gsub!(/\\[Ff]ont\[(.+?)\]/){"\004[#{$1}]"}
      # Text different display
      text.gsub!(/\\[Tt]ext\[([0-9]+)\]/){"\005[#{$1}]"}
      # SlipKnot's Icon
      text.gsub!(/\\[Ii]con\[(.+?)\]/){"\006[#{$1}]"}
      # Dubealex's Icon
      text.gsub!(/\\[Ii]i{([IiWwAaSs]?)}\[([0-9]+)\]/){change_icon($1,$2.to_i)}
      # Bold font
      text.gsub!(/\\[Bb]/){"\007"}
      # Italic font
      text.gsub!(/\\[Ii]/){"\010"}
      # Array with all the lines width
      stxt = [0,0,0,0]
      @back.height = 32
      icon = ""; val = 0
      x = 112 if @face
      while ((c = text.slice!(/./m)) != nil)
        if c == "\000" then c = "\\" end
        if c == "\001"
          text.sub!(/\[([0-9]+)\]/, "")
          color = $1.to_i
          self.contents.font.color = text_color(color) if color >= 0 and color <= 7
          next
        end
        if c == "\002"
          if @gold_window == nil
            @gold_window = Window_Gold.new
            @gold_window.x = 560 - @gold_window.width
            if $game_temp.in_battle then @gold_window.y = 192
            else @gold_window.y = self.y >= 128 ? 32 : 384 end
            @gold_window.opacity = @back.opacity
            @gold_window.back_opacity = @back.back_opacity
          end; next
        end
        if c == "\003"
          text.sub!(/\[([0-9]+)\]/, "")
          self.contents.font.size = [[$1.to_i,8].max,32].min
          next
        end
        if c == "\004"
          text.sub!(/\[(.+?)\]/, "")
          self.contents.font.name = $1.to_s
          next
        end
        if c == "\005"
          text.sub!(/\[([0-9]+)\]/, "")
          case $1.to_i
          when 0 then disp_text
          when 1 then disp_text(false,true)
          when 2 then disp_text(true) end
          next
        end
        if c == "\006"
          text.sub!(/\[(.+?)\]/, "")
          icon = $1.to_s
          val += 24; c = ""
        end
        if c == "\007"
          if self.contents.font.bold
            self.contents.font.bold = false
          else self.contents.font.bold = true end
          next
        end
        if c == "\010"
          if self.contents.font.italic
            self.contents.font.italic = false
          else self.contents.font.italic = true end
          next
        end
        if c == "\011"
          icon = $gold_name
          val += 24; c = ""
        end
        if c == "\013"
          text.sub!(/\[(.*?)\]/,"")
          icon = $1.to_s
          val += 24; c = ""
        end
        if c == "\n"
          @cursor_width = [@cursor_width,x].max if y >= $game_temp.choice_start
          y += 1; x = sx = 0
          sx = x = 112 if @face
          x,sx = 8,14 if y >= $game_temp.choice_start
          next
        else stxt[y] += (self.contents.text_size(c).width+val) end
        @back.height = (y*32)+64
        if icon != ""
          self.contents.blt(4+x,32*y+5,RPG::Cache.icon(icon),Rect.new(0,0,24,24))
          x += 24; val,icon = 0,""
        end
        if $outline_text and !$shadow_text
          draw_text_outline(4+x,32*y,40,32,c,color)
        elsif $shadow_text and !$outline_text
          draw_text_shadow(4+x,32*y,40,32,c,color)
        else
          self.contents.font.color = text_color(color)
          self.contents.draw_text(4+x,32*y,40,32,c)
        end
        x += self.contents.text_size(c).width
      end
      @back.width = stxt.max+42+sx
      men_pos
    end
    if $game_temp.choice_max > 0
      @item_max = $game_temp.choice_max
      self.active,self.index = true,0
    end
    if $game_temp.num_input_variable_id > 0
      digits_max = $game_temp.num_input_digits_max
      number = $game_variables[$game_temp.num_input_variable_id]
      @input_number_window = Window_InputNumber.new(digits_max)
      @input_number_window.number = number
      @back.height += 32
      width = [@back.width,(@input_number_window.width-16)].max
      @back.width = width; men_pos
    end
    if over_event
      if $game_map.events != nil
        if event <= 0 then ch = $game_player
        else ch = $game_map.events[event] end
        fx = [[ch.screen_x-@back.width/2,4].max,636-@back.width].min
        fy = [[ch.screen_y-(@back.height+48),4].max,476-@back.height].min
        self.x = @back.x = fx
        self.y = @back.y = fy
      end
    end
    if picture
      px = self.x + @back.width
      @picture = Sprite.new
      @picture.bitmap = RPG::Cache.load_bitmap(@path,pic_name)
      @picture.x = px - @picture.bitmap.width
      @picture.y = self.y - @picture.bitmap.height
    end
    if name_box
      nbx,nby = self.x,self.y-15
      w = self.contents.text_size(name_text).width+12
      @name_box = Window_Base.new(nbx,nby,w,32)
      @name_box.z = self.z+1
      nbx += 6; nby += 4
      @name_box_text  = Name_Box_Text.new(nbx,nby,name_text)
      @name_box_text.z = self.z+2
    end
    if @face
      face = RPG::Cache.load_bitmap(@path,face_name)
      @back.height <= 128 ? fy = 0 : fy = ((@back.height-128)/2)
      self.contents.blt(0,fy,face,Rect.new(0,0,96,96))
      @back.height = 128 if @back.height <= 128
      men_pos
      @face = false
    end
  end
#-----------------------------------------------------------------
  def update
    super
    if @fade_in
      self.contents_opacity += 24
      if @input_number_window != nil
        @input_number_window.contents_opacity += 24
      end
      @fade_in = false if self.contents_opacity == 255
      return
    end
    if @input_number_window != nil
      @input_number_window.update
      if Input.trigger?(Input::C)
        $game_system.se_play($data_system.decision_se)
        $game_variables[$game_temp.num_input_variable_id] =
          @input_number_window.number
        $game_map.need_refresh = true
        @input_number_window.dispose
        @input_number_window = nil
        terminate_message
      end; return
    end
    if @contents_showing
      if Input.trigger?(Input::B)
        if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
          $game_system.se_play($data_system.cancel_se)
          $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
          terminate_message
        end
      end
      if Input.trigger?(Input::C)
        if $game_temp.choice_max > 0
          $game_system.se_play($data_system.decision_se)
          $game_temp.choice_proc.call(self.index)
        end; terminate_message
      end; return
    end
    if @fade_out == false and $game_temp.message_text != nil
      @contents_showing = true
      $game_temp.message_window_showing = true
      reset_window; refresh
      Graphics.frame_reset
      sk_visible
      self.contents_opacity = 0
      if @input_number_window != nil
        @input_number_window.contents_opacity = 0
      end
      @fade_in = true; return
    end
    if self.visible
      @fade_out = true
      @back.opacity -= 48
      if @back.opacity == 0
        sk_visible(false)
        @fade_out = false
        $game_temp.message_window_showing = false
      end; return
    end
  end
#-----------------------------------------------------------------
  def change_icon(option,index)
    option == nil ? option = "" : nil
    option.downcase!
    case option
    when "i" then s = $data_items[index]
    when "w" then s = $data_weapons[index]
    when "a" then s = $data_armors[index]
    when "s" then s = $data_skills[index] end
    return sprintf("\013[%s]%s",s.icon_name,s.name) unless s.name == nil
  end
#-----------------------------------------------------------------
  def disp_text(w1=false,w2=false)
    $outline_text,$shadow_text = w1,w2
  end
#-----------------------------------------------------------------
  def sk_visible(s=true)
    self.visible,@back.visible = s,s
  end
#-----------------------------------------------------------------
  def men_pos
    if $game_temp.in_battle then self.y = 96 - @back.height/2
    else
      case $game_system.message_position
      when 0 then self.y = 96 - @back.height/2
      when 1 then self.y = 240 - @back.height/2
      when 2 then self.y = 384 - @back.height/2 end
    end
    self.x = 320 - @back.width/2
    if @input_number_window != nil
      @input_number_window.y = (self.y+$game_temp.num_input_start*32)
      @input_number_window.x = self.x+8
      @input_number_window.x = self.x+8+112 if @face
    end
    @back.x,@back.y = self.x,self.y
  end
#-----------------------------------------------------------------
  def reset_window
    men_pos
    if $game_system.message_frame == 0 then @back.opacity = 255
    else @back.opacity = 0 end
    @back.back_opacity = 160
  end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Name_Box_Text < Window_Base
#-----------------------------------------------------------------
  def initialize(x,y,text)
    super(x-16,y-16,text.size*12+32,56)
    init; self.opacity = 0
    w,h = self.contents.width,self.contents.height
    if $outline_text and !$shadow_text then draw_text_outline(0,0,w,h,text)
    elsif $shadow_text and !$outline_text then draw_text_shadow(0,0,w,h,text)
    else self.contents.draw_text(0,0,w,h,text) end
  end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Base < Window
#-----------------------------------------------------------------
  def draw_text_outline(x,y,wid,hei,str,col=0,ali=0)
    self.contents.font.color = Color.new(0,0,0,255)
    self.contents.draw_text(x+1,y,wid,hei,str,ali)
    self.contents.draw_text(x-1,y,wid,hei,str,ali)
    self.contents.draw_text(x,y+1,wid,hei,str,ali)
    self.contents.draw_text(x,y-1,wid,hei,str,ali)
    self.contents.font.color = text_color(col)
    self.contents.draw_text(x,y,wid,hei,str,ali)
  end
#-----------------------------------------------------------------
  def draw_text_shadow(x,y,wid,hei,str,col=0,ali=0)
    self.contents.font.color = Color.new(0,0,0,192)
    self.contents.draw_text(x+1,y+1,wid,hei,str,ali)
    self.contents.font.color = Color.new(0,0,0,96)
    self.contents.draw_text(x+2,y+2,wid,hei,str,ali)
    self.contents.font.color = text_color(col)
    self.contents.draw_text(x,y,wid,hei,str,ali)
  end
#-----------------------------------------------------------------
  def init(win=self,type=0,size=0,wid=0,hei=0)
    swid = (wid == 0 ? win.width-32 : wid)
    shei = (hei == 0 ? win.height-32 : hei)
    win.contents = Bitmap.new(swid,shei)
    type = $defaultfonttype if type == 0
    size = $defaultfontsize if size == 0
    win.contents.font.name = type
    win.contents.font.size = size
  end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Caldaron's Time System Caldaron 0 3,119 11-05-2006, 01:00 PM
Last Post: Caldaron
  Auto Skipping Message Sonokawa 0 2,373 09-02-2006, 01:00 PM
Last Post: Sonokawa
  Show a Message in any Scene Tsunokiette 1 3,458 08-17-2006, 01:15 PM
Last Post: GoldenShadow
  Lives System Constance 0 2,581 08-10-2006, 01:00 PM
Last Post: Constance
  Level Up system Jimmie 0 2,647 07-24-2006, 01:00 PM
Last Post: Jimmie
  State Immunity Message mudgolem 0 2,430 06-05-2006, 01:00 PM
Last Post: mudgolem
  Equipment Scrolling System Legacy 0 2,499 05-12-2006, 01:00 PM
Last Post: Legacy
  Inn & Savepoint System SephirothSpawn 0 2,497 03-08-2006, 01:00 PM
Last Post: SephirothSpawn
  New Battle System V1.5 (Added Side View) Guedez 0 2,817 01-12-2006, 01:00 PM
Last Post: Guedez
  Slipknot Advance Message System Sheol 0 2,676 01-02-2006, 01:00 PM
Last Post: Sheol



Users browsing this thread: 1 Guest(s)