Slipknot Advance Message System
#1
Slipknot Advance Message System 3.0
by Sheol
Jan 2 2006

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.


NEW:
- SDK compatibility.
I think, is now compatible with SDK (you can remove it).
- Deleted some code.
Some things of the last version can be smaller.
- Hexadecimal color.
Some people request it, works like in the Dubealex script.
- Another fix to the cursor width.
I found a new way to manage it.
- Advance Cursor Width
Is based in the current choice width.
- Fixed input number window.
The back window's width now can't be smaller than the input number's width.

Code:
#==============================================================================
# ** Slipknot Advance Message System
#------------------------------------------------------------------------------
# Slipknot
# 3.0
# 02.23.06
#------------------------------------------------------------------------------
=begin
  Thanks to:
   - Dubealex, for some of the features.
   - Phylomorphis, for the hexadecimal color.
=end
#==============================================================================

#--------------------------------------------------------------------------
# SDK log
#--------------------------------------------------------------------------
SDK.log('Slipknot Advance Message System', 'Slipknot', '3.0', '02.23.06')
#--------------------------------------------------------------------------

#--------------------------------------------------------------------------
# Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.state 'Slipknot Advance Message System'
#--------------------------------------------------------------------------

module Message_Settings
  #--------------------------------------------------------------------------
  # • Default text display:
  #     0: normal
  #     1: shadow
  #     2: outline
  #--------------------------------------------------------------------------
  Default_Text = 0
  #--------------------------------------------------------------------------
  # • Name Box skin:
  #     nil = same as message box
  #--------------------------------------------------------------------------
  NB_skin = 'Charcoal XP'
  #--------------------------------------------------------------------------
  # • Fade the name box and picture
  #--------------------------------------------------------------------------
  Fade = true
  #--------------------------------------------------------------------------
  # • Cursor based in current choice width
  #--------------------------------------------------------------------------
  Advance_Cursor = false
  #--------------------------------------------------------------------------
  # • Folder for the message pictures
  #--------------------------------------------------------------------------
  Path = 'Graphics/Pictures/Message/'
  #--------------------------------------------------------------------------
end

#--------------------------------------------------------------------------
# Loads the maps' names
#--------------------------------------------------------------------------
$data_mapinfos = load_data 'Data/MapInfos.rxdata'
#--------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Begin Bitmap Edit
#------------------------------------------------------------------------------
class Bitmap
  #--------------------------------------------------------------------------
  # • Outline Text
  #--------------------------------------------------------------------------
  def draw_text_outline x, y, wid, hei, str, ali=0
    color = font.color.dup
    font.color.set 0, 0, 0, color.alpha
    draw_text x+1, y,     wid, hei, str, ali
    draw_text x-1,  y,     wid, hei, str, ali
    draw_text x,     y+1, wid, hei, str, ali
    draw_text x,     y-1,  wid, hei, str, ali
    font.color = color
    draw_text x, y, wid, hei, str, ali
  end
  #--------------------------------------------------------------------------
  # • Shadow Text
  #--------------------------------------------------------------------------
  def draw_text_shadow x, y, wid, hei, str, ali=0
    color = font.color.dup
    font.color.set 0, 0, 0, (color.alpha*2.0/3.0).ceil
    draw_text x+2, y+2, wid, hei, str, ali
    font.color = color
    draw_text x, y, wid, hei, str, ali
  end
end
#------------------------------------------------------------------------------
# End Bitmap Edit
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Begin Window_Message Edit
#------------------------------------------------------------------------------
class Window_Message < Window_Selectable
  #--------------------------------------------------------------------------
  # • Include Message_Settings constants
  #--------------------------------------------------------------------------
  include Message_Settings
  #--------------------------------------------------------------------------
  # • Window intialization
  #--------------------------------------------------------------------------
  def initialize
    super 0, 304, 640, 160
    self.contents = Bitmap.new 608, 128
    self.z = 9998
    @fade_in = @contents_showing = false
    self.index = -1
    self.opacity = @cursor_width = 0
    @back = Window_Base.new 65, 299, 510, 175
    @back.z = 9990
    self.active = self.visible = false
  end
  #--------------------------------------------------------------------------
  # • Hides or show the window contents and background
  #--------------------------------------------------------------------------
  def visible=(val)
    super
    @back.visible = val
  end
  #--------------------------------------------------------------------------
  # • Dispose of all internal objects
  #--------------------------------------------------------------------------
  def dispose
    terminate_message
    $game_temp.message_window_showing = false
    @back.dispose
    super
  end
  #--------------------------------------------------------------------------
  # • Terminates the message processing
  #--------------------------------------------------------------------------
  def terminate_message
    self.active = @back.pause = false
    self.index = -1
    contents.clear
    @contents_showing = false
    if $game_temp.message_proc != nil
      $game_temp.message_proc.call
    end
    [$game_temp].each do |t|
      t.message_text = t.message_proc = t.choice_proc = nil
      t.choice_start = t.num_input_start = 99
      t.choice_max = t.choice_cancel_type = 0
      t.num_input_variable_id = t.num_input_digits_max = 0
    end
    [@gold_window, @name_box, @picture, input_window].each do |x|
      x.dispose if exists? x
    end
  end
  #--------------------------------------------------------------------------
  # • Writes all the text in the window
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    [contents.font].each do |x|
      x.name = Font.default_name
      x.size = 22
      x.bold = x.italic = false
      x.color = normal_color
    end
    case Default_Text
    when 0 then disp_text
    when 1 then disp_text false, true
    when 2 then disp_text true end
    x = y = 0
    x = 8 if $game_temp.choice_start == 0
    return if (text = $game_temp.message_text).nil?
    
    text.gsub!(/\\[Rr]and\((\d+)\)/) { rand($1).to_s }
    text.gsub!(/\\[Vv]\[(\d+)\]/) { $game_variables[$1.to_i] }
    text.gsub!(/\\[Nn]\[(\d+)\]/) {
      $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : '' }
    text.gsub!(/\\[Nn][Pp]\[([\d+])\]/) { $game_party.actors[$1.to_i].name }
    text.gsub!(/\\\$\$/) {"#{$game_party.gold} #{$data_system.words.gold}"}
    text.gsub!(/\\\$/) { $game_party.gold.to_s }
    text.gsub!(/\\[Cc]lass\[(\d+)\]/) {
      $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].class_name : '' }
    text.gsub!(/\\[Mm]ap/) { $game_map.name }
    
    face = over_event = false
    picture = name_box = ''
    if (/\\[Nn]a\[(.+?)\]/.match(text)) != nil
      name_box = $1
      text.sub!(/\\[Nn]a\[.*?\]/) { '' }
    end
    if (/\\[Pp]ic\[(.+?)\]/.match(text)) != nil
      picture = $1
      text.sub!(/\\[Pp]ic\[.*?\]/) { '' }
    end
    # Right
    if (/\\[Ff]ace{(.+?)}/.match(text)) != nil
      face, face_name = 1, $1
      text.sub!(/\\[Ff]ace{.*?}/) { '' }
    end
    # Left
    if (/\\[Ff]ace\[(.+?)\]/.match(text)) != nil
      face, face_name = 2, $1
      text.sub!(/\\[Ff]ace\[.*?\]/) { '' }
    end
    if (/\\[Pp]\[([-1,0-9]+)\]/.match(text)) != nil
      over_event, event = true, $1.to_i
      text.sub!(/\\[Pp]\[[-1,0-9]+\]/) { '' }
    end
    if (/\\[Pp]/.match(text)) != nil
      over_event, event = true, $game_temp.this_event
      text.sub!(/\\[Pp]/) { '' }
    end
    
    text.gsub!(/\\\\/) { "\000" }
    text.gsub!(/\\[Cc]\[([[0-9][A-F][a-f]#]+)\]/) { "\001[#$1]" }
    text.gsub!(/\\[Gg]/) { "\002" }
    text.gsub!(/\\[Tt][Ss]\[(\d+)\]/) { "\003[#$1]" }
    text.gsub!(/\\[Ff]ont\[(.+?)\]/) { "\004[#$1]" }
    text.gsub!(/\\[Tt]ext\[([0-2])\]/) { "\005[#$1]" }
    text.gsub!(/\\[Ii]con\[(.+?)\]/) { "\006[#$1]" }
    text.gsub!(/\\[Ii]i{([IiWwAaSs]?)}\[(\d+)\]/) { change_icon($1, $2.to_i) }
    text.gsub!(/\\[Bb]/) { "\007" }
    text.gsub!(/\\[Ii]/) { "\010" }
    
    @cursor_width = 0, 0, 0, 0
    stxt = 0, 0, 0, 0
    icon = ''
    x = 104 if face == 2
    
    while (c = text.slice!(/./m)) != nil
      case c
      when "\000" then c = '\\'
      when "\001"
        text.sub!(/\[(.*?)\]/, '')
        hex = $1.to_s
        color = $1.to_i
        contents.font.color = text_color(color)
        if hex.slice!(/./m) == '#'
          contents.font.color = hex_color(hex)
          next
        end
        contents.font.color = text_color(color)
        next
      when "\002"
        next if @gold_window != nil
        @gold_window = Window_Gold.new
        @gold_window.x = 560 - @gold_window.width
        @gold_window.y = $game_temp.in_battle ? 192 : (self.y >= 128 ? 32 : 384)
        @gold_window.opacity = @back.opacity
        @gold_window.back_opacity = @back.back_opacity
        next
      when "\003"
        text.sub!(/\[([0-9]+)\]/, '')
        contents.font.size = [[$1.to_i, 6].max, 32].min
        next
      when "\004"
        text.sub!(/\[(.+?)\]/, '')
        contents.font.name = $1.to_s
        next
      when "\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
      when "\006"
        text.sub!(/\[(.+?)\]/, '')
        icon = $1.to_s
        c = ''
      when "\007"
        [contents.font].each do |h| h.bold = !h.bold end
        next
      when "\010"
        [contents.font].each do |h| h.italic = !h.italic end
        next
      when "\013"
        text.sub!(/\[(.*?)\]/, '')
        icon = $1.to_s
        c = ''
      when "\n"
        y += 1
        x = face == 2 ? 104 : 0
        if y >= $game_temp.choice_start
          x += 8
          @cursor_x = face == 2 ? 112 : 8
        end
        next
      end
      if icon != ''
        icon_y = (32-24)/2
        contents.blt(4+x, 32*y+4, RPG::Cache.icon(icon), Rect.new(0,0,24,24))
        stxt[y] += 24
        x += 24
        icon = ''
      end
      next if c == ''
      w = contents.text_size(c).width
      if @outline_text and !@shadow_text
        contents.draw_text_outline 4+x, 32*y, w*2, 32, c
      elsif @shadow_text and !@outline_text
        contents.draw_text_shadow 4+x, 32*y, w*2, 32, c
      else
        contents.draw_text 4+x, 32*y, w*2, 32, c
      end
      x += w
      stxt[y] += w
      @cursor_width[y] += w if y >= $game_temp.choice_start
    end
    indent = face ? 104 : 0
    @back.height = y*32+32
    @back.width = [stxt.max, (@cursor_width.max+16)].max + indent + 40
    fix_position
    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
      @back.height += 32
      @back.width = [@back.width, (input_window.width+indent+16)].max
      fix_position
      input_window.number = number
      input_window.y = self.y+$game_temp.num_input_start*32
      input_window.x = face == 2 ? self.x+indent+8 : self.x+8
    end
    if face
      fy = @back.height <= 128 ? 0 : (@back.height-128)/2
      fx = face == 2 ? 0 : stxt.max+16
      contents.blt fx, fy, image(face_name), Rect.new(0,0,96,96)
      @back.height = 128 if @back.height <= 128
      fix_position face
    end
    if over_event and $game_map.events != nil
      ch = event <= 0 ? $game_player : $game_map.events[event]
      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
    if picture != ''
      px = self.x+@back.width
      @picture = Sprite.new
      @picture.bitmap = image picture
      @picture.x = px-@picture.bitmap.width
      @picture.y = self.y-@picture.bitmap.height
      @picture.opacity = 0 if Fade
    end
    if name_box != ''
      @name_box = Sprite_NameBox.new self.x, self.y-15, name_box
      @name_box.opacity = 0 if Fade
      @name_box.back.opacity = $game_system.message_frame == 0 ? 255 : 0
    end
  end
  #--------------------------------------------------------------------------
  # • Frame update
  #--------------------------------------------------------------------------
  def update
    if @contents_showing
      super
      @back.update
    end
    if @fade_in
      self.contents_opacity += 24
      input_window.contents_opacity += 24 if exists? input_window
      @name_box.opacity += 24 if exists? @name_box and Fade
      @picture.opacity += 24 if exists? @picture and Fade
      @fade_in = false if contents_opacity == 255
      return
    end
    if input_window != nil
      input_window.update
      if Input.trigger? 13
        $game_system.se_play $data_system.decision_se
        $game_variables[$game_temp.num_input_variable_id] = input_window.number
        $game_map.need_refresh = true
        input_window.dispose
        @input_number_window = nil
        terminate_message
      end
      return
    end
    if @contents_showing
      @back.pause = true if $game_temp.choice_max == 0
      if Input.trigger? 12
        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? 13
        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 $game_temp.message_text != nil
      @contents_showing = true
      $game_temp.message_window_showing = true
      reset_window
      refresh
      Graphics.frame_reset
      self.visible = true
      self.contents_opacity = 0
      if input_window != nil
        input_window.contents_opacity = 0
      end
      @fade_in = true
      return
    end
    return unless visible
    self.opacity -= 48
    if opacity == 0
      self.visible = false
      $game_temp.message_window_showing = false
    end
  end
  #--------------------------------------------------------------------------
  # • Returns the file 'name' from the choosen folder
  #--------------------------------------------------------------------------
  def image name
    RPG::Cache.load_bitmap Path, name
  end
  #--------------------------------------------------------------------------
  # • Gets the name and icon from the database
  #--------------------------------------------------------------------------
  def change_icon option, index
    s = case option.downcase
      when 'i'  then $data_items[index]
      when 'w' then $data_weapons[index]
      when 'a'  then $data_armors[index]
      when 's'  then $data_skills[index] end
    sprintf("\013[%s]%s", s.icon_name, s.name) unless s.name.nil?
  end
  #--------------------------------------------------------------------------
  # • Returns @input_number_window
  #--------------------------------------------------------------------------
  def input_window
    @input_number_window
  end
  #--------------------------------------------------------------------------
  # • Changes the way of display the text
  #--------------------------------------------------------------------------
  def disp_text w1=false, w2=false
    @outline_text, @shadow_text = w1, w2
  end
  #--------------------------------------------------------------------------
  # • Return true if the object exists
  #--------------------------------------------------------------------------
  def exists? object
    not (object.nil? or object.disposed?)
  end
  #--------------------------------------------------------------------------
  # • Updates the position of the windows
  #--------------------------------------------------------------------------
  def fix_position face=false
    h2 = @back.height/2
    self.y = $game_temp.in_battle ? 96 - h2 :
      case $game_system.message_position
      when 0 then 96 - h2
      when 1 then 240-h2
      when 2 then 384-h2 end
    self.x = 320 - @back.width/2
    @back.x, @back.y = self.x, self.y
  end
  #--------------------------------------------------------------------------
  # • Reset the position of the windows
  #--------------------------------------------------------------------------
  def reset_window
    fix_position
    @back.opacity = $game_system.message_frame == 0 ? 255 : 0
    @back.back_opacity = 160
  end
  #--------------------------------------------------------------------------
  # • Updates the cursor rectangle
  #--------------------------------------------------------------------------
  def update_cursor_rect
    if @index >= 0
      n = $game_temp.choice_start + @index
      width = Advance_Cursor ? @cursor_width[n] : @cursor_width.max
      cursor_rect.set @cursor_x, n*32, width + 8, 32
    else cursor_rect.empty end
  end
end
#------------------------------------------------------------------------------
# End Window_Message Edit
#------------------------------------------------------------------------------
    
class Sprite_NameBox < Sprite
  #--------------------------------------------------------------------------
  # • Include Message_Settings constants
  #------------------------------------------------------------------------
  include Message_Settings
  #--------------------------------------------------------------------------
  # • Atributes
  #------------------------------------------------------------------------
  attr_reader :back
  #--------------------------------------------------------------------------
  # • Sprite initialization
  #------------------------------------------------------------------------
  def initialize x, y, text=' '
    dumb = Bitmap.new 320, 42
    size = dumb.text_size(text).width
    dumb.dispose
    @back = Window_Base.new x, y, size+12, 32
    @back.z = 9995
    unless NB_skin.nil?
      @back.windowskin = RPG::Cache.windowskin NB_skin
    end
    viewport = Viewport.new x+6, y+5, size, 22
    viewport.z = @back.z+10
    super viewport
    self.bitmap = Bitmap.new size, 22
    case Default_Text
    when 0 then bitmap.draw_text 0, 0, size, 22, text
    when 1 then bitmap.draw_text_shadow 0, 0, size, 22, text
    when 2 then bitmap.draw_text_outline 0, 0, size, 22, text end
  end
  #--------------------------------------------------------------------------
  # • Dispose self and the back
  #------------------------------------------------------------------------
  def dispose
    super
    @back.dispose
  end
end

#------------------------------------------------------------------------------
# Begin Game_Temp Edit
#------------------------------------------------------------------------------
class Game_Temp
  #--------------------------------------------------------------------------
  # • Store the current event
  #--------------------------------------------------------------------------
  attr_accessor :this_event
  #--------------------------------------------------------------------------
end
#------------------------------------------------------------------------------
# End Game_Temp Edit
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Begin Interpreter Edit
#------------------------------------------------------------------------------
class Interpreter
  #--------------------------------------------------------------------------
  alias slipknot_skams_interpreter_command101 command_101
  #--------------------------------------------------------------------------
  # • Get the caller event id
  #--------------------------------------------------------------------------
  def command_101
    $game_temp.this_event = @event_id
    slipknot_skams_interpreter_command101
  end
end
#------------------------------------------------------------------------------
# End Interpreter Edit
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Begin Game_Map Edit
#------------------------------------------------------------------------------
class Game_Map
  #--------------------------------------------------------------------------
  # • Return the name of the current map
  #--------------------------------------------------------------------------
  def name
    $data_mapinfos[@map_id].name
  end
end
#------------------------------------------------------------------------------
# End Game_Map Edit
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Begin Window_Base Edit
#------------------------------------------------------------------------------
class Window_Base < Window
  #--------------------------------------------------------------------------
  # • Convert 'string' to hexadecimal color
  #--------------------------------------------------------------------------
  def hex_color(string)
    return normal_color if string.size != 6
    r = g = b = 0
    6.times do |i|
      s = string.slice!(/./m)
      v = hex_convert(s.downcase)
      case i
      when 1 then r += v * 16
      when 2 then r += v
      when 3 then g += v * 16
      when 4 then g += v
      when 5 then b += v * 16
      when 6 then b += v end
    end
    Color.new(r, g, b)
  end
  #--------------------------------------------------------------------------
  # • Covert 'c' into hex value
  #--------------------------------------------------------------------------
  def hex_convert(c)
    return c.to_i if (/[0-9]/).match(c) != nil
    case c
    when 'a' then 10
    when 'b' then 11
    when 'c' then 12
    when 'd' then 13
    when 'e' then 14
    when 'f' then 15 end
  end
end
#------------------------------------------------------------------------------
# End Window_Base Edit
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Begin Window_InputNumber Edit
#------------------------------------------------------------------------------
class Window_InputNumber < Window_Base
  #--------------------------------------------------------------------------
  # • Fix the cursor width
  #--------------------------------------------------------------------------
  def initialize(digits_max)
    @digits_max = digits_max
    @number = 0
    dummy = Bitmap.new 32, 32
    @cursor_width = dummy.text_size('0').width+8
    dummy.dispose
    super 0, 0, @cursor_width*@digits_max+32, 64
    self.contents = Bitmap.new width-32, 32
    self.z += 9999
    self.opacity = @index = 0
    refresh
    update_cursor_rect
  end
end
#------------------------------------------------------------------------------
# End Window_InputNumber Edit
#------------------------------------------------------------------------------

#--------------------------------------------------------------------------
# End SDK Enabled Test
#--------------------------------------------------------------------------
end
#--------------------------------------------------------------------------
}


Messages In This Thread
Slipknot Advance Message System - by Sheol - 01-02-2006, 01:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Caldaron's Time System Caldaron 0 3,107 11-05-2006, 01:00 PM
Last Post: Caldaron
  Slipknot's adorable menu Ordaz 0 2,441 09-09-2006, 01:00 PM
Last Post: Ordaz
  Auto Skipping Message Sonokawa 0 2,362 09-02-2006, 01:00 PM
Last Post: Sonokawa
  Show a Message in any Scene Tsunokiette 1 3,445 08-17-2006, 01:15 PM
Last Post: GoldenShadow
  Lives System Constance 0 2,565 08-10-2006, 01:00 PM
Last Post: Constance
  Level Up system Jimmie 0 2,634 07-24-2006, 01:00 PM
Last Post: Jimmie
  State Immunity Message mudgolem 0 2,422 06-05-2006, 01:00 PM
Last Post: mudgolem
  Equipment Scrolling System Legacy 0 2,487 05-12-2006, 01:00 PM
Last Post: Legacy
  Inn & Savepoint System SephirothSpawn 0 2,486 03-08-2006, 01:00 PM
Last Post: SephirothSpawn
  New Battle System V1.5 (Added Side View) Guedez 0 2,807 01-12-2006, 01:00 PM
Last Post: Guedez



Users browsing this thread: 1 Guest(s)