TheoAllen

Modified External Text

Sep 22nd, 2013
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.56 KB | None | 0 0
  1. module SES
  2.   module ExternalText
  3.     # ----------------------------------------------------------------------
  4.     # Overwrite Tags
  5.     # ----------------------------------------------------------------------
  6.     Tags = {
  7.    
  8.       /^\[Key\]\s*(.+)/i =>
  9.           %Q{ key = $1.to_s; text[key] = [["",0,nil,nil,""],"",[2,0],""] },
  10.                                          
  11.       /^\[Face\]\s*(.+),(?:\s*)(\d+)/i =>
  12.           %Q{ text[key][0][0], text[key][0][1] = $1.to_s, $2.to_i },
  13.                        
  14.       /^\[AFace\]\s*(\d+)/i =>
  15.           %Q{ text[key][0][2] = $1.to_i },
  16.    
  17.       /^\[PFace\]\s*(\d+)/i =>
  18.           %Q{ text[key][0][3] = $1.to_i },
  19.    
  20.       /^\[DFace\]\s*(.+)/i =>
  21.           %Q{ text[key][0][0] = SES::ExternalText::Faces[$1.to_s][0]
  22.               text[key][0][1] = SES::ExternalText::Faces[$1.to_s][1] },
  23.                    
  24.       /^\[Name\]\s*(.+)/i =>
  25.           %Q{ text[key][0][4] = $1.to_s },
  26.          
  27.       /^\[FName\]\s*(.+)/ =>
  28.           %Q{ text[key][0][4] = $1.to_s
  29.               text[key][0][0] = SES::ExternalText::Faces[$1.to_s][0]
  30.               text[key][0][1] = SES::ExternalText::Faces[$1.to_s][1] },
  31.              
  32.       /^\[Position\]\s*(Top|Center|Bottom)/i =>
  33.           %Q{ text[key][2][0] = if $1.downcase == "top" then 0
  34.                                 elsif $1.downcase == "center" then 1
  35.                                 else 2 end },
  36.                                  
  37.       /^\[Background\]\s*(Normal|Dim|Transparent)/i =>
  38.           %Q{ text[key][2][1] = if $1.downcase == "normal" then 0
  39.                                 elsif $1.downcase == "dim" then 1
  40.                                 else 2 end },
  41.      
  42.       # Added Right Namebox ~                                  
  43.       /^\[Rname\]\s*(.+)/i =>
  44.       %Q{ text[key][3] = $1.to_s},
  45.      
  46.     }
  47.   end
  48. end
  49.  
  50. class Game_Message
  51.   attr_accessor :rname
  52.  
  53.   alias modified_ext_text_clear clear
  54.   def clear
  55.     modified_ext_text_clear
  56.     @rname = ""
  57.   end
  58.   # ----------------------------------------------------------------------
  59.   # Overwrite Load Text
  60.   # ----------------------------------------------------------------------
  61.   def load_text(data, name = true)
  62.     if data[0][2]
  63.       actor = $game_actors[data[0][2]].actor
  64.       @face_name, @face_index = actor.face_name, actor.face_index
  65.     elsif data[0][3]
  66.       actor = $game_party.members[data[0][3]]
  67.       @face_name, @face_index = actor.face_name, actor.face_index
  68.     else
  69.       @face_name, @face_index = data[0][0], data[0][1]
  70.     end
  71.     @position, @background = data[2][0], data[2][1]
  72.     if name
  73.       if SES::ExternalText::NameStyle == :box
  74.         @name = data[0][4]
  75.         @rname = data[3]
  76.       else
  77.         name2 = data[0][4] << "\\c[0]"
  78.       end
  79.     end
  80.     text = data[1]
  81.     new_page
  82.     lines, i, cc = [""], 0, ""
  83.     (lines[0] = name2; i += 1; lines[i] = "") if name && name2
  84.     text.split(/\s/).each do |w|
  85.       cc = get_color(w) || cc
  86.       if too_wide?(lines[i] + w) || w =~ /(.*)\[Line\].*/i
  87.         w.gsub!(/\[Line\]/i) { "" }
  88.         i += 1; lines[i] = ""
  89.         if i % 4 == 0
  90.           lines[i] << (name2 || "") << cc;
  91.           (i += 1; lines[i] = "") if name
  92.         end
  93.       end
  94.       lines[i] << "#{w} "
  95.     end
  96.     return lines
  97.   end
  98.  
  99. end
  100.  
  101. class Window_NameBox < Window_Base
  102.   # ----------------------------------------------------------------------
  103.   # Overwrite update
  104.   # ----------------------------------------------------------------------
  105.   def update
  106.     super
  107.     update_name
  108.   end
  109.  
  110.   def update_name
  111.     set_name($game_message.name) if @name != $game_message.name
  112.   end
  113.  
  114. end
  115. # ----------------------------------------------------------------------
  116. # Right namebox window class
  117. # ----------------------------------------------------------------------
  118. class Window_Rnamebox < Window_NameBox
  119.  
  120.   def initialize
  121.     super
  122.     update_xpos
  123.   end
  124.  
  125.   def set_name(name)
  126.     super(name)
  127.     update_xpos
  128.   end
  129.  
  130.   def update_xpos
  131.     self.x = Graphics.width - width
  132.   end
  133.  
  134.   def update_name
  135.     set_name($game_message.rname) if @name != $game_message.rname
  136.   end
  137.  
  138. end
  139. # ----------------------------------------------------------------------
  140. # Overwrite create namebox
  141. # ----------------------------------------------------------------------
  142. class Scene_Map
  143.  
  144.   def create_namebox
  145.     @namebox = Window_NameBox.new
  146.     @rnamebox = Window_Rnamebox.new
  147.   end
  148.  
  149. end
  150.  
  151. class Scene_Battle
  152.  
  153.   def create_namebox
  154.     @namebox = Window_NameBox.new
  155.     @rnamebox = Window_Rnamebox.new
  156.   end
  157.  
  158. end
Advertisement
Add Comment
Please, Sign In to add comment