Advertisement
Guest User

Enelvon's Script External Text

a guest
Feb 16th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 31.89 KB | None | 0 0
  1. #═╦═════════════════════════════════════════════════════════════════════════════
  2. # ║ § External Text (v2.2) by Enelvon                   [License: CC BY-SA 3.0]
  3. # ║                                                            <RMVX Ace>
  4. #═╬═════════════════════════════════════════════════════════════════════════════
  5. # ║ § Change Log
  6. #─╫─────────────────────────────────────────────────────────────────────────────
  7. # ║ v1.0 (November 30th, 2012) - Initial release
  8. # ║ v1.1 (November 31st, 2012) - Fixed a bug with Battle Test not loading text
  9. # ║ v1.2 (November 31st, 2012) - Added nameboxes and a newline tag
  10. # ║ v1.3 (December 6th, 2012) - Fixed a bug with persistent colors
  11. # ║ v1.4 (December 6th, 2012) - Added an additional style for names
  12. # ║ v1.5 (December 7th, 2012) - Added the [FName] tag, made adding tags easier,
  13. # ║                             fixed a bug with the namebox, added block text
  14. # ║                             call
  15. # ║ v1.6 (December 10th, 2012) - Added in the ability to alter message window
  16. # ║                             location and background
  17. # ║ v1.7 (December 11th, 2012) - Added the [get_text] calls and a text code for
  18. # ║                              referencing $game_text
  19. # ║ v1.8 (December 12th, 2012) - Added a fix for the choice window
  20. # ║ v1.9 (June 1st, 2013) - Width calculation is now based solely on the font
  21. # ║                         size of Window_Message, rather than the default size
  22. # ║ v2.0 (June 1st, 2013) - Added scrolling text support
  23. # ║ v2.1 (June 13th, 2013)     - Added Unicode support
  24. # ║ v2.2 (June 30th, 2013)     - Fixed issue with EOL characters and get_text
  25. #═╬═════════════════════════════════════════════════════════════════════════════
  26. # ║ § Summary
  27. #─╫─────────────────────────────────────────────────────────────────────────────
  28. # ║ This script allows you to create a text file and use its contents in the
  29. # ║ in-game message windows. It will automatically wrap text, allowing you to
  30. # ║ avoid worrying about whether or not your text will fit in the message
  31. # ║ window. It uses a simple tagging system to divide the file into messages and
  32. # ║ supply them with faces to be displayed (if desired).
  33. # ║
  34. #═╬═════════════════════════════════════════════════════════════════════════════
  35. # ║ § Required Scripts
  36. #─╫─────────────────────────────────────────────────────────────────────────────
  37. # ║ None
  38. # ║
  39. #═╬═════════════════════════════════════════════════════════════════════════════
  40. # ║ § Known Incompatibilities
  41. #─╫─────────────────────────────────────────────────────────────────────────────
  42. # ║ None specifically - though while ordinary text codes (\c, \n, etc) can be
  43. # ║ used, custom ones cannot if they are persistent (like \c is) - they will be
  44. # ║ reset whenever text wraps to a new page. \c is handled so that it will not
  45. # ║ be reset, and it is possible to add handlers for other persistent codes.
  46. # ║
  47. #═╬═════════════════════════════════════════════════════════════════════════════
  48. # ║ § Installation
  49. #─╫─────────────────────────────────────────────────────────────────────────────
  50. # ║ Puts this script below Materials and above Main. The exact location doesn't
  51. # ║ really matter, as every method this uses is either aliased or new.
  52. # ║
  53. #═╬═════════════════════════════════════════════════════════════════════════════
  54. # ║ § Configuration
  55. #─╫─────────────────────────────────────────────────────────────────────────────
  56. # ║ Create a text file in the Data folder. Name it Text. There, you've done the
  57. # ║ hard part! To add text to the file, use this format:
  58. # ║
  59. # ║     [Key] !Key!
  60. # ║     [Face] !File!, !Index!
  61. # ║     !Text!
  62. # ║
  63. # ║ You may omit the [Face] line to have a message without a face, but the [Key]
  64. # ║ line and the text itself are necessary. The replacements you should use with
  65. # ║ the above format are:
  66. # ║
  67. # ║     !Key! with an identifier for the text. Each of these *must* be unique.
  68. # ║     !File! with the name of the faceset you want to display, minus the
  69. # ║         extension.
  70. # ║     !Index! with the index of the face in the file, starting with 0.
  71. # ║     !Text! with the message you want to display. Note that new lines within
  72. # ║         a message have no effect other than adding a space.
  73. # ║
  74. # ║ Note that you must playtest the game before creating an encrypted archive,
  75. # ║ or your changes in Data.txt will not be reflected in the game, as it reads
  76. # ║ data by creating a Data.rvdata2 file from Data.txt - something that it will
  77. # ║ be unable to do after encryption.
  78. # ║
  79. # ║ There are three additional face tags, one of which will require you to
  80. # ║ modify the Faces hash in SES::ExternalText. I'll break them all down here:
  81. # ║
  82. # ║     [AFace] !Index!
  83. # ║
  84. # ║ This is pretty self-explanatory. Replace !Index! with the ID of the actor
  85. # ║ whose face you want to show.
  86. # ║
  87. # ║     [PFace] !Index!
  88. # ║
  89. # ║ Another easy one. Replace !Index! with an index that will correspond to the
  90. # ║ player's party at the time they receive the message. The first slot is 0,
  91. # ║ the second is 1, and so on.
  92. # ║
  93. # ║     [DFace] !Key!
  94. # ║
  95. # ║ This is the one that requires some modification. It's handy for recurring
  96. # ║ NPCs - you define a face in the Faces hash of SES::ExternalText and replace
  97. # ║ !Key! with the name you gave it in the hash. There is an example for Ralph
  98. # ║ already in the hash, as well as format instructions, so this should be easy
  99. # ║ for you to use as well.
  100. # ║
  101. # ║ Another tag you can include is [Name]. It will display a namebox with the
  102. # ║ given name. Text codes will work with it.
  103. # ║
  104. # ║     [Name] \c[15]\n[1]
  105. # ║
  106. # ║ Would use the first actor's name in color 15.
  107. # ║
  108. # ║     [Name] Ralph
  109. # ║
  110. # ║ Would use 'Ralph', and so on. There are actually two styles for names: the
  111. # ║ namebox (which is the default) and in-text names, which are displayed at the
  112. # ║ top of each message page. You can toggle it with the NameStyle constant in
  113. # ║ SES::ExternalText. Set it to :box to use the namebox or :text to use in-text
  114. # ║ names.
  115. # ║
  116. # ║ As of v1.5, there is also the [FName] tag, which works like the [Name] tag
  117. # ║ except it also sets the face to whatever is entered, like [DFace] would.
  118. # ║ This method of setting the name does not allow you to use text codes, unlike
  119. # ║ the normal one, unless you have set up the key in the Faces hash to include
  120. # ║ them.
  121. # ║
  122. # ║ There's the newline tag [Line]. Include it in front of a word to
  123. # ║ force a line break, like this:
  124. # ║
  125. # ║     Text [Line]Text2
  126. # ║
  127. # ║ That would be displayed like this:
  128. # ║
  129. # ║     Text
  130. # ║     Text2
  131. # ║
  132. # ║ Always remember the space before the [Line] tag - it prevents issues.
  133. # ║
  134. # ║ You can comment out lines by beginning them with a # or //. You can use this
  135. # ║ to divide your Text file into sections, to help with organization.
  136. # ║
  137. # ║ v1.5 also alters how text tags are checked - they are now stored in a hash
  138. # ║ in the SES::ExternalText module, making it easy to add your own. The keys
  139. # ║ of the hash should be Regular Expressions, and the values should be strings
  140. # ║ for evaluation.
  141. # ║
  142. # ║ New to v1.6 are the location and background tags. To alter the location of
  143. # ║ the message window, use this tag:
  144. # ║
  145. # ║     [Position] !Pos!
  146. # ║
  147. # ║ !Pos! can be Top, Center, or Bottom. You will likely never need to use the
  148. # ║ Bottom tag, as the default position is Bottom. It is included for the sake
  149. # ║ of completeness.
  150. # ║
  151. # ║ The background tag allows you to choose between Normal, Dim, and Transparent
  152. # ║ backgrounds, like you would for normal text. You use it like this:
  153. # ║
  154. # ║     [Background] !Back!
  155. # ║
  156. # ║ Replace !Back! with Normal, Dim, or Transparent. You will probably never use
  157. # ║ Normal, as it's the default. Much like Bottom for positions, it was included
  158. # ║ solely for the sake of completeness.
  159. # ║
  160. # ║ v1.7 adds in a text code that can be used to call text. I would only bother
  161. # ║ using it if you have a global text codes script of some kind - this script
  162. # ║ does not provide such a function, and I do not intend to add one. Note that
  163. # ║ the text code *will not* auto-wrap text, so you will still have to test
  164. # ║ its length yourself. You can use this alongside a global text codes script
  165. # ║ to make translating your game into multiple languages easy - just use it
  166. # ║ in the names/descriptions of Database objects. You use it like this:
  167. # ║
  168. # ║     \t[!Key!]
  169. # ║
  170. # ║ !Key! is, of course, the key of the text you're referencing.
  171. # ║
  172. #═╬═════════════════════════════════════════════════════════════════════════════
  173. # ║ § Script Calls
  174. #─╫─────────────────────────────────────────────────────────────────────────────
  175. # ║ To display text, place this in an event's script command:
  176. # ║
  177. # ║     text(!Key!)
  178. # ║
  179. # ║     !Key! should be replaced with a string corresponding to the key of the
  180. # ║         text that you want to display. As an example, if I had a text key
  181. # ║         called Intro, I would use this to call it:
  182. # ║
  183. # ║         text("Intro")
  184. # ║
  185. # ║ You can also display multiple sections of text at once with this:
  186. # ║
  187. # ║     block_text(!Key!)
  188. # ║
  189. # ║     !Key should be replaced with either a Regular Expression or a string.
  190. # ║         If you use a regular expression, it will display the text for all
  191. # ║         keys that match it. If you use a string, it will display the text
  192. # ║         for all keys that include it. This is simply a faster way to display
  193. # ║         scenes. As an example, let's say we have a number of messages for
  194. # ║         our introduction. Their keys are called Intro 1 through Intro 12.
  195. # ║         Instead of 12 calls of text("Intro #"), we could use one of these:
  196. # ║
  197. # ║         block_text(/^Intro \d+/)
  198. # ║
  199. # ║         block_text("Intro")
  200. # ║
  201. # ║         The first one is better, of course, but both work. The problem with
  202. # ║         the second comes in if we have another key that's similar - let's
  203. # ║         say Ralph's Introduction. It would be called too, because it contains
  204. # ║         Intro. It would not be called with the first one.
  205. # ║
  206. # ║ As of v1.7, there are two get_text calls. One can be used only in an event,
  207. # ║ and is used like this:
  208. # ║
  209. # ║     get_text(!Key!)
  210. # ║
  211. # ║ I would recommend you use this with variable assignment, as it has no real
  212. # ║ use otherwise. !Key! is obviously the key of the text you want to use. You
  213. # ║ can also use a form of this command in your own scripts, by calling this:
  214. # ║
  215. # ║     SES::ExternalText.get_text(key)
  216. # ║
  217. # ║ As of v2.0, you can now use External Text in conjunction with the Scrolling
  218. # ║ Text feature by using this call:
  219. # ║
  220. # ║     scrolling_text(!Key!, !Speed!, !NoFast!)
  221. # ║
  222. # ║ !Key! is obviously the key for the text. !Speed! is how quickly you want it
  223. # ║ to move - 2 is the default. !NoFast! is whether or not the player should be
  224. # ║ blocked from hold the action key to increase the scroll speed - false allows
  225. # ║ them to do so, true prevents it. The default is false.
  226. # ║
  227. #═╬═════════════════════════════════════════════════════════════════════════════
  228. # ║ § Aliased Methods
  229. #─╫─────────────────────────────────────────────────────────────────────────────
  230. # ║ ● module Data_Manager
  231. # ║     self.load_normal_database
  232. # ║
  233. # ║ ● class Window_ChoiceList
  234. # ║     max_choice_width
  235. # ║
  236. # ║ ● class Scene_Battle
  237. # ║     max_choice_width
  238. # ║
  239. # ║ ● class Scene_Map
  240. # ║     create_all_windows
  241. # ║
  242. # ║ ● class Scene_Battle
  243. # ║     create_all_windows
  244. # ║
  245. #═╬═════════════════════════════════════════════════════════════════════════════
  246. # ║ § New Methods
  247. #─╫─────────────────────────────────────────────────────────────────────────────
  248. # ║ ● module Data_Manager
  249. # ║     self.create_text
  250. # ║
  251. # ║ ● class Game_Message
  252. # ║     get_color(text)
  253. # ║     load_text(data)
  254. # ║     slice_escape_characters(text)
  255. # ║     too_wide?(text)
  256. # ║
  257. # ║ ● class Window_NameBox (new class)
  258. # ║     set_name(name)
  259. # ║
  260. # ║ ● class Game_Interpreter
  261. # ║     text(key)
  262. # ║
  263. # ║ ● class Scene_Map
  264. # ║     create_namebox
  265. # ║
  266. # ║ ● class Scene_Battle
  267. # ║     create_namebox
  268. # ║
  269. #═╬═════════════════════════════════════════════════════════════════════════════
  270. # ║ ▼ module SES::ExternalText
  271. #═╩═════════════════════════════════════════════════════════════════════════════
  272. module SES
  273.   module ExternalText
  274.    
  275.     # Enable this if you're not using a choice script like Raizen's and want to
  276.     # use text codes in choices. It will force the choice window to evaluate
  277.     # escape characters before displaying, causing it to size properly. In
  278.     # general, it won't hurt to leave this on as long as this script is above
  279.     # any other scripts that affect the choice window.
  280.     ChoiceFix = true
  281.    
  282.     # Add faces here. The format is "Name" => ["Faceset", Index],
  283.     Faces = {
  284.      
  285.       "Ralph" => ["Actor1", 0],
  286.      
  287.     }
  288.    
  289.     # Set this to either :box or :text. :box uses the name box, :text will
  290.     # include the name at the top of each page.
  291.     NameStyle = :box
  292.    
  293.     # This is a hash of tags that will be searched for in the Text.txt file. You
  294.     # can customize this to add new tags. Scripters can add new tags in their
  295.     # scripts by making a new hash and calling SES::ExternalText::Tags.merge!
  296.     # with it.
  297.     Tags = {
  298.    
  299.       /^\[Key\]\s*(.+)/i =>
  300.           %Q{ key = $1.to_s; text[key] = [["",0,nil,nil,""],"",[2,0]] },
  301.                                          
  302.       /^\[Face\]\s*(.+),(?:\s*)(\d+)/i =>
  303.           %Q{ text[key][0][0], text[key][0][1] = $1.to_s, $2.to_i },
  304.                        
  305.       /^\[AFace\]\s*(\d+)/i =>
  306.           %Q{ text[key][0][2] = $1.to_i },
  307.    
  308.       /^\[PFace\]\s*(\d+)/i =>
  309.           %Q{ text[key][0][3] = $1.to_i },
  310.    
  311.       /^\[DFace\]\s*(.+)/i =>
  312.           %Q{ text[key][0][0] = SES::ExternalText::Faces[$1.to_s][0]
  313.               text[key][0][1] = SES::ExternalText::Faces[$1.to_s][1] },
  314.                    
  315.       /^\[Name\]\s*(.+)/i =>
  316.           %Q{ text[key][0][4] = $1.to_s },
  317.          
  318.       /^\[FName\]\s*(.+)/ =>
  319.           %Q{ text[key][0][4] = $1.to_s
  320.               text[key][0][0] = SES::ExternalText::Faces[$1.to_s][0]
  321.               text[key][0][1] = SES::ExternalText::Faces[$1.to_s][1] },
  322.              
  323.       /^\[Position\]\s*(Top|Center|Bottom)/i =>
  324.           %Q{ text[key][2][0] = if $1.downcase == "top" then 0
  325.                                 elsif $1.downcase == "center" then 1
  326.                                 else 2 end },
  327.                                  
  328.       /^\[Background\]\s*(Normal|Dim|Transparent)/i =>
  329.           %Q{ text[key][2][1] = if $1.downcase == "normal" then 0
  330.                                 elsif $1.downcase == "dim" then 1
  331.                                 else 2 end },
  332.     }
  333.    
  334.     # You can call this with SES::ExternalText.get_key(key) to get text and do
  335.     # things like store it in a variable.
  336.     def self.get_text(key)
  337.       return $game_text[key].nil? ? nil : $game_text[key][1].strip
  338.     end    
  339.   end
  340. end
  341.                 ($imported ||= {})["SES - External Text"] = 2.2
  342. #═╦═════════════════════════════════════════════════════════════════════════════
  343. # ║ ▲ module SES::ExternalText
  344. #─╫─────────────────────────────────────────────────────────────────────────────
  345. # ║ ▼ module DataManager
  346. #═╩═════════════════════════════════════════════════════════════════════════════
  347. module DataManager
  348.  
  349.   class << self
  350.     alias en_et_dm_lnd load_normal_database
  351.     alias en_et_dm_lbd load_battle_test_database
  352.   end
  353.  
  354.   # Creates the Text.rvdata2 file, which is a Ruby-serialized hash created from
  355.   # the Text.txt file. This allows it to be read from inside of an encrypted
  356.   # archive.
  357.   def self.create_text
  358.     text = {}
  359.     key = ""
  360.     File.open("Data/Text.txt", "r:BOM|UTF-*") do |file|
  361.       file.readlines.each_with_index do |v, i|
  362.         next if v =~ /(^\s*(#|\/\/).*|^\s*$)/
  363.         SES::ExternalText::Tags.each_pair do |k,p|
  364.           (eval(p); v = "") if v =~ k
  365.         end
  366.         unless v.empty?
  367.           v.gsub!(/\[Line\]/i) { "\n" }
  368.           text[key][1] << v
  369.         end
  370.       end
  371.     end
  372.     File.open("Data/Text.rvdata2", "w") do |file|
  373.       Marshal.dump(text, file)
  374.     end
  375.   end
  376.  
  377.   def self.load_normal_database
  378.     en_et_dm_lnd
  379.     create_text if FileTest.exist?("Data/Text.txt")
  380.     $game_text = load_data("Data/Text.rvdata2")
  381.   end
  382.  
  383.   def self.load_battle_test_database
  384.     en_et_dm_lbd
  385.     create_text if FileTest.exist?("Data/Text.txt")
  386.     $game_text = load_data("Data/Text.rvdata2")
  387.   end
  388. end
  389. #═╦═════════════════════════════════════════════════════════════════════════════
  390. # ║ ▲ module DataManager
  391. #─╫─────────────────────────────────────────────────────────────────────────────
  392. # ║ ▼ class Game_Message
  393. #═╩═════════════════════════════════════════════════════════════════════════════
  394. class Game_Message
  395.  
  396.   attr_reader :name
  397.  
  398.   alias en_et_gm_c clear
  399.   def clear
  400.     en_et_gm_c
  401.     @name = ""
  402.   end
  403.  
  404.   # Gets the most recently used text color code and stores it so that it can be
  405.   # used on future pages.
  406.   def get_color(text)
  407.     win, cc = Window_Base.new(0,0,0,0), nil
  408.     win.convert_escape_characters(text).gsub(/\eC(\[(\w+)\])?/i) {|s| cc = s}
  409.     return cc
  410.   end
  411.  
  412.   # Sets up the called text, as well as any face and name data it contains.
  413.   def load_text(data, name = true)
  414.     if data[0][2]
  415.       actor = $game_actors[data[0][2]].actor
  416.       @face_name, @face_index = actor.face_name, actor.face_index
  417.     elsif data[0][3]
  418.       actor = $game_party.members[data[0][3]]
  419.       @face_name, @face_index = actor.face_name, actor.face_index
  420.     else
  421.       @face_name, @face_index = data[0][0], data[0][1]
  422.     end
  423.     @position, @background = data[2][0], data[2][1]
  424.     if name
  425.       if SES::ExternalText::NameStyle == :box then @name = data[0][4]
  426.       else name2 = data[0][4] << "\\c[0]" unless data[0][4].empty? end
  427.     end
  428.     text = data[1]
  429.     new_page
  430.     lines, i, cc = [""], 0, ""
  431.     (lines[0] = name2; i += 1; lines[i] = "") if name2
  432.     text.split(/\s/).each do |w|
  433.       cc = get_color(w) || cc
  434.       if too_wide?(lines[i] + w) || w =~ /(.*)\[Line\].*/i
  435.         w.gsub!(/\[Line\]/i) { "" }
  436.         i += 1; lines[i] = ""
  437.         if i % 4 == 0
  438.           lines[i] << (name2 || "") << cc;
  439.           (i += 1; lines[i] = "") if name2
  440.         end
  441.       end
  442.       lines[i] << "#{w} "
  443.     end
  444.     return lines
  445.   end
  446.  
  447.   def set_text(text)
  448.     @texts = text
  449.   end
  450.  
  451.   # Removes the escape characters from the given text and returns it. Used when
  452.   # calculating display width.
  453.   def slice_escape_characters(text)
  454.     win = Window_Base.new(0,0,0,0)
  455.     win.convert_escape_characters(text).gsub(/\e(\w)(\[(\w+)\])?/) {""}
  456.   end
  457.  
  458.   # Checks if adding the word would make the line too long to fit in the window.
  459.   def too_wide?(text)
  460.     win = Window_Message.new
  461.     width = Graphics.width - (@face_name.empty? ? 24 : 136)
  462.     win.text_size(slice_escape_characters(text)).width > width
  463.   end
  464. end
  465. #═╦═════════════════════════════════════════════════════════════════════════════
  466. # ║ ▲ class Game_Message
  467. #─╫─────────────────────────────────────────────────────────────────────────────
  468. # ║ ▼ class Game_Interpreter
  469. #═╩═════════════════════════════════════════════════════════════════════════════
  470. class Game_Interpreter
  471.  
  472.   # Method invoked to call text.
  473.   def text(key)
  474.     $game_message.set_text($game_message.load_text($game_text[key]) ||
  475.                             "There is no text for the key #{key}.")
  476.     wait_for_message
  477.   end
  478.  
  479.   # Allows you to call multiple lines of text at once.
  480.   def block_text(key)
  481.     $game_text.keys.sort.each do |k|
  482.       if key.is_a?(String) then text(k) if k.include?(key)
  483.       else text(k) if k =~ key end
  484.     end
  485.   end
  486.  
  487.   def scrolling_text(key, speed = 2, no_fast = false)
  488.     Fiber.yield while $game_message.visible
  489.     $game_message.scroll_mode = true
  490.     $game_message.scroll_speed = speed
  491.     $game_message.scroll_no_fast = no_fast
  492.     list = $game_message.load_text($game_text[key], false)
  493.     index = 0
  494.     while index < list.size
  495.       $game_message.add(list[index])
  496.       index += 1
  497.     end
  498.     wait_for_message
  499.   end
  500.  
  501.   # Allows you to retrieve text by calling get_text(key) in an event's script
  502.   # call.
  503.   def get_text(key)
  504.     SES::ExternalText.get_text(key).strip
  505.   end
  506. end
  507. #═╦═════════════════════════════════════════════════════════════════════════════
  508. # ║ ▲ class Game_Interpreter
  509. #─╫─────────────────────────────────────────────────────────────────────────────
  510. # ║ ▼ class Window_Base
  511. #═╩═════════════════════════════════════════════════════════════════════════════
  512. class Window_Base
  513.  
  514.   alias en_et_wb_cec convert_escape_characters
  515.   def convert_escape_characters(*args, &block)
  516.     result = en_et_wb_cec(*args, &block)
  517.     result.gsub!(/\eT\[(.+)\]/i) { if $game_text.keys.include?($1)
  518.                                       $game_text[$1][1]
  519.                                    else
  520.                                       "Invalid key [#{$1}]. No matching text exists."
  521.                                    end
  522.                                  }
  523.     result
  524.   end
  525. end
  526. #═╦═════════════════════════════════════════════════════════════════════════════
  527. # ║ ▲ class Window_Base
  528. #─╫─────────────────────────────────────────────────────────────────────────────
  529. # ║ ▼ class Window_ChoiceList
  530. #═╩═════════════════════════════════════════════════════════════════════════════
  531. class Window_ChoiceList
  532.  
  533.   alias en_et_wcl_mcw max_choice_width
  534.   def max_choice_width
  535.     if SES::ExternalText::ChoiceFix
  536.       $game_message.choices.collect {|s|
  537.         text_size(convert_escape_characters(s)).width
  538.       }.max
  539.     else
  540.       en_et_wcl_mcw
  541.     end
  542.   end
  543. end
  544. #═╦═════════════════════════════════════════════════════════════════════════════
  545. # ║ ▲ class Window_ChoiceList
  546. #─╫─────────────────────────────────────────────────────────────────────────────
  547. # ║ ▼ class Window_NameBox
  548. #═╩═════════════════════════════════════════════════════════════════════════════
  549. class Window_NameBox < Window_Base
  550.  
  551.   def initialize
  552.     super(0, Graphics.height - 168, 0, 0)
  553.     @position = 2
  554.     self.visible = false; close
  555.     self.height = 48
  556.     self.width = 130
  557.     @name = ""
  558.     self.arrows_visible = false
  559.   end
  560.  
  561.   # Passes the window with a name and displays the window
  562.   def set_name(name)
  563.     return unless name
  564.     @name = name
  565.     self.visible = true if !self.visible
  566.     if @name.empty?
  567.       close if open?
  568.     else
  569.       if $game_message.position > 0 && $game_message.position != @position
  570.         @position = $game_message.position
  571.         self.y = @position * (Graphics.height - fitting_height(4)) / 2 -
  572.                  self.height
  573.       else
  574.         unless $game_message.position == @position
  575.           @position = $game_message.position
  576.           self.y = fitting_height(4)
  577.         end
  578.       end
  579.       open if !open?
  580.       create_contents
  581.       self.draw_text_ex((contents_width - text_size(@name).width) / 2, 0, @name)
  582.     end
  583.   end
  584.  
  585.   def update
  586.     super
  587.     set_name($game_message.name) if @name != $game_message.name
  588.   end
  589. end
  590. #═╦═════════════════════════════════════════════════════════════════════════════
  591. # ║ ▲ class Window_NameBox
  592. #─╫─────────────────────────────────────────────────────────────────────────────
  593. # ║ ▼ class Scene_Map
  594. #═╩═════════════════════════════════════════════════════════════════════════════
  595. class Scene_Map < Scene_Base
  596.  
  597.   alias en_et_sm_caw create_all_windows
  598.   def create_all_windows
  599.     en_et_sm_caw
  600.     create_namebox
  601.   end
  602.  
  603.   def create_namebox
  604.     @namebox = Window_NameBox.new
  605.   end
  606. end
  607. #═╦═════════════════════════════════════════════════════════════════════════════
  608. # ║ ▲ class Scene_Map
  609. #─╫─────────────────────────────────────────────────────────────────────────────
  610. # ║ ▼ class Scene_Battle
  611. #═╩═════════════════════════════════════════════════════════════════════════════
  612. class Scene_Battle < Scene_Base
  613.  
  614.   alias en_et_sb_caw create_all_windows
  615.   def create_all_windows
  616.     en_et_sb_caw
  617.     create_namebox
  618.   end
  619.  
  620.   def create_namebox
  621.     @namebox = Window_NameBox.new
  622.   end
  623. end
  624. #═╦═════════════════════════════════════════════════════════════════════════════
  625. # ║ ▲ class Scene_Battle
  626. #═╩═════════════════════════════════════════════════════════════════════════════
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement