Rmxp, tout ce que l'on peut avoir

Forum sur Rm Xp
 
Accueil­Portail­Calendrier­FAQ­Rechercher­S'enregistrer­Membres­Groupes­Connexion
Partager | 
 

 Window_Message

Voir le sujet précédent Voir le sujet suivant Aller en bas 
AuteurMessage
sambarre
Administrateur Fondateur
Administrateur Fondateur


Masculin
Nombre de messages: 53
Age: 13
Localisation: Devant ta porte et je vais sonner dans 5 minutes
Emploi: J'étude en CM 2
Loisirs: Tout ce qui est électronique
Date d'inscription: 12/02/2007

Personnage
Pedeza :: 99 000
Status: Crée son jeu

MessageSujet: Window_Message   Jeu 7 Juin - 18:52

Voici un script pour vos messages !

Code:
#-----------------------------------------------------------------
# ¦ Slipknot's Advance Message System ¦
#-----------------------------------------------------------------
#  Dernière mise à jour : 02/01/06
#-----------------------------------------------------------------
#  - Objets, Armes, Armures et sorts par Dubealex
#  - Name Box par Dubealex
#  - Taille du texte par  Dubealex
#  - Tye de la police par Dubealex
#  - Nom de la map par Dubealex
#  - Window Over Event by Dubealex
#-----------------------------------------------------------------
#  Reporter les bugs aux adresses suivantes :
#  - dubealex.com/asylum
#  - rmxp.net/forums
#  - crankeye.com/forums
#-----------------------------------------------------------------

#-----------------------------------------------------------------
# This module carries the some message settings
#-----------------------------------------------------------------
module Message
  #---------------------------------------------------------------
  # ● Style de texte :
  #    0: normal
  #    1: ombré
  #    2: contours
  #---------------------------------------------------------------
  Default_Text = 1
  #---------------------------------------------------------------
  # ● Fade the name box and picture
  #---------------------------------------------------------------
  Fade = true
  #---------------------------------------------------------------
  # ● Change it to change the folder for the message
  # pictures
  #---------------------------------------------------------------
  Path = "Graphics/Pictures/"
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
# Add the text displays to the bitmap class
#-----------------------------------------------------------------
class Bitmap
  #---------------------------------------------------------------
  # ● Draws the text 5 times to get the outline effect
  #---------------------------------------------------------------
  def draw_text_outline x, y, wid, hei, str, ali=0
    color = font.color.dup
    font.color = Color.new 0, 0, 0, color.alpha #changer ces valeurs pour changer la couleur
    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
    font.color = color
    draw_text x, y, wid, hei, str, ali
  end
  #---------------------------------------------------------------
  # ● Draws the text 3 times to get the shadow effect
  #---------------------------------------------------------------
  def draw_text_shadow x, y, wid, hei, str, ali=0
    color = font.color.dup
    font.color = Color.new -20, 0, 0, (color.alpha*2/3) #changer ces valeurs pour changer la couleur
    font.color = color
    draw_text x, y, wid, hei, str, ali
  end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
# The Window Message
#-----------------------------------------------------------------
class Window_Message < Window_Selectable
  #---------------------------------------------------------------
  # ● Include the modules to use their methods and
  # constants
  #---------------------------------------------------------------
  include Message, Input, RPG
  #---------------------------------------------------------------
  # ● Create the message window, and define some
  # variables
  #---------------------------------------------------------------
  def initialize
    super 65, 299, 510, 175
    self.contents = Bitmap.new width-32, height-32
    self.z = 9998
    @contents_showing = false
    self.index = -1
    self.opacity = @cursor_width = 0
    @back = Window_Base.new 65, 299, 510, 175
    self.active = self.visible = false
  end
  #---------------------------------------------------------------
  # ● Change visibility of the contents window and the
  # back one
  #---------------------------------------------------------------
  def visible=(val)
    super
    @back.visible = val
  end
  #---------------------------------------------------------------
  # ● Dispose all the windows
  #---------------------------------------------------------------
  def dispose
    terminate_message
    $game_temp.message_window_showing = false
    @back.dispose
    [@input_number_window].each{|i| if exists? i; i.dispose; end}
    super
  end
  #---------------------------------------------------------------
  # ● Terminates the message and dispose some objects
  #---------------------------------------------------------------
  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 {|t| t.message_text = t.message_proc = nil;
      t.choice_start = 99; t.choice_max = t.choice_cancel_type = 0;
      t.choice_proc = nil; t.num_input_start = 99;
      t.num_input_variable_id = t.num_input_digits_max = 0 }
    [@gold_window, @name_box, @picture].each{|o|
      o.dispose if exists? o }
  end
 #---------------------------------------------------------------
  # ● Read all the message text and write it into the
  # window
  #---------------------------------------------------------------
  def refresh
    contents.clear
    # Setting the text options to default
    [contents.font].each {|w| w.name = "Arial"
      w.size = 22; w.bold = w.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 = x = y = 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]+)\]/) {
        $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : "" }
      # Current money display
      text.gsub!(/\\\$\$/) {"#{$game_party.gold} #{$data_system.words.gold}"}
      text.gsub!(/\\\$/) { $game_party.gold.to_s }
      # Show Hero Class Name
      text.gsub!(/\\[Cc]lass\[([0-9]+)\]/) {
        $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].class_name : "" }
      # Show Current Map Name
      text.gsub!(/\\[Mm]ap/) { $game_map.name }
      # Set some variables to false
      name_box = face = picture = over_event = false
      # Name box
      if (/\\[Nn]a\[(.+?)\]/.match(text)) != nil
        name_box, name_text = true, $1
        text.sub!(/\\[Nn]a\[.*?\]/){""}
      end
      # Picture
      if (/\\[Pp]ic\[(.+?)\]/.match(text)) != nil
        picture, pic_name = true, $1
        text.sub!(/\\[Pp]ic\[.*?\]/){""}
      end
      # Face
      #  - 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 = 0, $1
        text.sub!(/\\[Ff]ace\[.*?\]/){""}
      end
      # Window over event
      if (/\\[Pp]\[([-1,0-9]+)\]/.match(text)) != nil
        over_event, event = true, $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]\[(\d+)\]/){"\003[#$1]"}
      # Text font
      text.gsub!(/\\[Ff]ont\[(.+?)\]/){"\004[#$1]"}
      # Text different display
      text.gsub!(/\\[Tt]ext\[([0-2])\]/){"\005[#$1]"}
      # SlipKnot's Icon
      text.gsub!(/\\[Ii]idiot\[(.+?)\]/){"\006[#$1]"}
      # Dubealex's Icon
      text.gsub!(/\\[Ii]i{([IiWwAaSs]?)}\[(\d+)\]/){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 = ""
      x = 104 if face == 0
      while (c = text.slice!(/./m)) != nil
        if c == "\000" then c = "\\" end
        if c == "\001"
          text.sub!(/\[([0-9]+)\]/, "")
          color = $1.to_i
          contents.font.color = text_color(color) if color >= 0
          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]+)\]/, "")
          contents.font.size = [[$1.to_i, 6].max, 32].min
          next
        end
        if c == "\004"
          text.sub!(/\[(.+?)\]/, "")
          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
          c = ""
        end

_________________
Venez sur : http://s9.bitefight.fr/c.php?uid=41139
C'est trop bien


Dernière édition par le Jeu 7 Juin - 18:54, édité 1 fois
Revenir en haut Aller en bas
Voir le profil de l'utilisateur http://wow-rmxp.weaponboard.net
sambarre
Administrateur Fondateur
Administrateur Fondateur


Masculin
Nombre de messages: 53
Age: 13
Localisation: Devant ta porte et je vais sonner dans 5 minutes
Emploi: J'étude en CM 2
Loisirs: Tout ce qui est électronique
Date d'inscription: 12/02/2007

Personnage
Pedeza :: 99 000
Status: Crée son jeu

MessageSujet: Re: Window_Message   Jeu 7 Juin - 18:53

Code:
if c == "\007"
          [contents.font].each {|i| i.bold = !i.bold }
          next
        end
        if c == "\010"
          [contents.font].each {|i| i.italic = !i.italic }
          next
        end
        if c == "\013"
          text.sub!(/\[(.*?)\]/, "")
          icon = $1.to_s
          c = ""
        end
        if c == "\n"
          @cursor_width = [@cursor_width, x].max if y >= $game_temp.choice_start
          y += 1
          x = face == 0 ? 104 : 0
          if y >= $game_temp.choice_start
            x += 8
            @cursor_width = [@cursor_width, x].max
            if face == 0
              @cursor_width -= 104
              @cursor_x = 112
            else @cursor_x = 8 end
          end
          next
        else stxt[y] += contents.text_size(c).width end
        if icon != ""
          icon_y = (32-24)/2
          contents.blt(4+x, 32*y+4, Cache.icon(icon), Rect.new(0,0,24,24))
          stxt[y] += 24
          x += 24
          icon = ""
        end
        if @outline_text and !@shadow_text
          contents.draw_text_outline 4+x, 32*y, 40, 32, c
        elsif @shadow_text and !@outline_text
          contents.draw_text_shadow 4+x, 32*y, 40, 32, c
        else contents.draw_text 4+x, 32*y, 40, 32, c end
        x += contents.text_size(c).width
      end
      for i in 0..3 do stxt[i] += 104 end if face == 0
      @back.height = y*32+32
      @back.width = stxt.max+40
    end
    men_pos
    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
      width = [@back.width, @input_number_window.width-16].max
      @back.width = width
      [@input_number_window].each {|o|
        o.number = number
        o.y = self.y+$game_temp.num_input_start*32
        o.x = face != 0 ? self.x+8 : self.x+8+112 }
    end
    if face
      bitmap = Cache.load_bitmap Path, face_name
      fy = @back.height <= 128 ? 0 : (@back.height-128)/2
      fx = face == 0 ? 0 : stxt.max+8
      @back.width = stxt.max + 136 if face == 1
      contents.blt fx, fy, bitmap, Rect.new(0,0,96,96)
      @back.height = 128 if @back.height <= 128
      men_pos
    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 = Cache.load_bitmap Path, pic_name
      @picture.x = px-@picture.bitmap.width
      @picture.y = self.y-@picture.bitmap.height
      @picture.opacity = 0 if Fade
    end
    if name_box
      @name_box = Name_Box.new self.x, self.y-15, name_text
      @name_box.opacity = 0 if Fade
      @name_box.back.opacity = $game_system.message_frame == 0 ? 255 : 0
    end
  end
#---------------------------------------------------------------
  # ● Update the cursor, the pause graphic, fade the
  # windows and handle the input
  #---------------------------------------------------------------
  def update
    super
    @back.update
    if @input_number_window != nil
      @input_number_window.update
      if Input.trigger? 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
      @back.pause = true if $game_temp.choice_max == 0
      if Input.trigger? 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? 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 $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_number_window != nil
        @input_number_window.contents_opacity = 0
      end
      loop do
        Graphics.update
        self.contents_opacity += 24
        @name_box.opacity += 24 if exists? @name_box and Fade
        @picture.opacity += 24 if exists? @picture and Fade
        if @input_number_window != nil
          @input_number_window.contents_opacity += 24
        end
        break if self.contents_opacity == 255
      end
      return
    end
    if self.visible
      loop do
        Graphics.update
        @back.opacity -= 48
        break if @back.opacity == 0
      end
      self.visible = false
      $game_temp.message_window_showing = false
      return
    end
  end
  #---------------------------------------------------------------
  # ● Get the icon bitmaps and names of each item,
  # armor, weapon and skills
  #    option: item, weapon, armor or skill
  #    index: the id of the object
  #---------------------------------------------------------------
  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
    return sprintf("\013[%s]%s", s.icon_name, s.name) unless s.name == nil
  end
  #---------------------------------------------------------------
  # ● Set the variables for outline and shadow text
  #    w1: outline text true or false
  #    w2: shadow text true or false
  #---------------------------------------------------------------
  def disp_text w1=false, w2=false
    @outline_text, @shadow_text = w1, w2
  end
  #---------------------------------------------------------------
  # ● Return false if the objects is nil or is disposed
  #---------------------------------------------------------------
  def exists? object
    return false if object.nil? or object.disposed?
    return true
  end
  #---------------------------------------------------------------
  # ● Resize the windows and set their positions
  #---------------------------------------------------------------
  def men_pos
    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
  #---------------------------------------------------------------
  # ● Change the visibility of the windows and call
  # men_pos to resize them
  #---------------------------------------------------------------
  def reset_window
    men_pos
    @back.opacity = $game_system.message_frame == 0 ? 255 : 0
    @back.back_opacity = 160
  end
  #---------------------------------------------------------------
  # ● Update the cursor rect, if this is needed
  #---------------------------------------------------------------
  def update_cursor_rect
    if @index >= 0
      n = $game_temp.choice_start + @index
      cursor_rect.set @cursor_x, n*32, @cursor_width, 32
    else cursor_rect.empty end
  end
  #---------------------------------------------------------------
  # The name box sprite
  #---------------------------------------------------------------
  class Name_Box < Sprite
    #---------------------------------------------------------------
    attr_accessor "back"
    #---------------------------------------------------------------
    # ● Create the name box text sprite
    #    x: the x position of the text
    #    y: the y position of the text
    #    text: the text chosen to be displayed
    #---------------------------------------------------------------
    def initialize x, y, text=" "
      dumb = Bitmap.new 320, 42
      # Ajout Krazplay pour correction, la police doit être la même que plus bas
      dumb.font = Font.new("Georgia")
      dumb.draw_text(0, 0, 320, 22, text)
      # Fin ajout Krazplay
      size = dumb.text_size(text).width
      dumb.dispose
      @back = Window_Base.new x, y, size+12, 32
      @back.back_opacity = 255      # Opacité du fond de la name box (max 255)
      viewport = Viewport.new x+6, y+5, size, 22
      viewport.z = @back.z+10
      super viewport
      self.bitmap = Bitmap.new size, 22
      self.bitmap.font = Font.new("Georgia")  # Police d'écriture de la name box
      case Message::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 the text and back
    #---------------------------------------------------------------
    def dispose
      super
      @back.dispose
    end
  #---------------------------------------------------------------
  end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
# Little modification to get the maps names
#-----------------------------------------------------------------
class Scene_Title
  #---------------------------------------------------------------
  $map_infos = load_data "Data/MapInfos.rxdata"
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Game_Map
  #---------------------------------------------------------------
  def name; $map_infos[@map_id].name; end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
# Little modification to fix the cursor width
#-----------------------------------------------------------------
class Window_InputNumber < Window_Base
  #---------------------------------------------------------------
  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+64, 64
    self.contents = Bitmap.new width-32, 32
    self.z += 9999
    self.opacity = @index = 0
    refresh
    update_cursor_rect
  end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------

_________________
Venez sur : http://s9.bitefight.fr/c.php?uid=41139
C'est trop bien
Revenir en haut Aller en bas
Voir le profil de l'utilisateur http://wow-rmxp.weaponboard.net
 

Window_Message

Voir le sujet précédent Voir le sujet suivant Revenir en haut 
Page 1 sur 1

Permission de ce forum:Vous ne pouvez pas répondre aux sujets dans ce forum
Rmxp, tout ce que l'on peut avoir :: Zone : Rm XP :: Script :: Dépot-