Project1

标题: 读取TXT作为对话脚本求修改 [打印本页]

作者: 喵呜喵5    时间: 2013-4-6 15:01
标题: 读取TXT作为对话脚本求修改
本帖最后由 喵呜喵5 于 2013-4-7 14:02 编辑

在外站上看到了这样一个脚本《SES External Text v1.8》(原文地址:http://forums.rpgmakerweb.com/in ... december-15th-2012/),脚本的功能是读取目录下的TXT文本文件,把其作为对话内容显示进游戏中,对于文本量较大的游戏来说这个功能相当实用,台词的修改以及把游戏翻译成其他语言有了这个功能以后变的相当方便(因为只要修改TXT文件即可……)。

但是我的问题就是,我使用这个脚本时一旦对话内容中包含中文的时候就会报错。
求高人修改此脚本成中文对话也能使用……

另外,这个脚本还附赠了一个多语言脚本(在同一地址中),可以在游戏开始的时候设置游戏的语言,求问这个多语言脚本如何使用。
作者: 沙漠点灰    时间: 2013-4-6 15:01
本帖最后由 沙漠点灰 于 2013-4-6 18:37 编辑

又是(??)喜闻乐见的编码问题(以前被害惨了)..
lz竟能用上这样的脚本,那么lz一定是剧情党了,做好游戏请务必通知一下我{:2_270:}
这种问题只要加上转码脚本一般就ok了。
RUBY 代码复制
  1. #------------------------------------------------------------------------------
  2. # Moonlight INN
  3. # [url]http://cgi.members.interq.or.jp/aquarius/rasetsu/[/url]
  4. # RaTTiE
  5. # [email][email protected][/email]
  6. #------------------------------------------------------------------------------
  7. # EasyConv::s2u(text) : S-JIS -> UTF-8
  8. # EasyConv::u2s(text) : UTF-8 -> S-JIS
  9. #==============================================================================
  10. module EasyConv
  11.   CP_ACP = 0
  12.   CP_UTF8 = 65001
  13.   #--------------------------------------------------------------------------
  14.   # 转 S-JIS -> UTF-8
  15.   #--------------------------------------------------------------------------
  16.   def s2u(text)
  17.     @@m2w ||= Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  18.     @@w2m ||= Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
  19.     # S-JIS -> Unicode
  20.     len = @@m2w.call(CP_ACP, 0, text, -1, nil, 0);
  21.     buf = "\0" * (len*2)
  22.     @@m2w.call(CP_ACP, 0, text, -1, buf, buf.size/2);
  23.     # Unicode -> UTF-8
  24.     len = @@w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil);
  25.     ret = "\0" * len
  26.     @@w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil);
  27.     return ret
  28.   end
  29.   module_function :s2u
  30.   #--------------------------------------------------------------------------
  31.   # 转 UTF-8 -> S-JIS
  32.   #--------------------------------------------------------------------------
  33.   def u2s(text)
  34.     @@m2w ||= Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  35.     @@w2m ||= Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
  36.     # UTF-8 -> Unicode
  37.     len = @@m2w.call(CP_UTF8, 0, text, -1, nil, 0);
  38.     buf = "\0" * (len*2)
  39.     @@m2w.call(CP_UTF8, 0, text, -1, buf, buf.size/2);
  40.     # Unicode -> S-JIS
  41.     len = @@w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil);
  42.     ret = "\0" * len
  43.     @@w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil);
  44.     return ret
  45.   end
  46.   module_function :u2s
  47. end


上面是转码脚本。




这是原来(External Text)的346行与347行
      file.readlines.each_with_index do |v, i|
        next if (v =~ /(^\s*(#|\/\/).*|^\s*$)/)

中间加一行
RUBY 代码复制
  1. v = EasyConv.s2u(v)

即可..

至于语言选择嘛..
那个脚本要插在那个“External Text”的后面

有这么一行(自行搜索)
Languages = ["English", "Simplified_Chinese"]

(原来只有English)修改成你支持的语言,这必须用英文(反正无所谓),


打开Game.ini
加一行

Language=Simplified_Chinese

即可
不过不知道原作者是不是忘了,不会自动生成,要手动改一下。

1.
先别用多语言脚本,运行游戏自动生成Text.rvdata2,

2.
加上脚本,
Languages = ["English", "Simplified_Chinese"]
修改这个

3.
打开Game.ini
加一行

Language=Simplified_Chinese

4.把生成的Text.rvdata2改为Simplified_Chinese.rvdata2

多语言重复步骤1,4

5.
完成游戏时,删除所有txt文件

(好麻烦~~~亦或者是我搞错了)


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

作者: satgo1546    时间: 2013-4-6 19:02
其实直接把文件另存为UTF-8格式就可以啦~~

作者: 晴兰    时间: 2013-4-6 21:54
提示: 作者被禁止或删除 内容自动屏蔽
作者: 喵呜喵5    时间: 2013-4-7 14:00
沙漠点灰 发表于 2013-4-6 18:23

谢谢,可以了用了

那个多语言脚本貌似是填入 Languages = ["English", "Simplified_Chinese"] 之后默认会使用第一种语言,不同语言的TXT文件则分别命名成English.txt、Simplified_Chinese.txt……

切换语言则是通过脚本附带的切换语言命令来进行……

我不懂的地方是脚本中切换语言界面中的提示文本如何用多语言来写的……

不过既然前面那个TXT脚本已经支持中文了就无所谓了,谢谢你的帮助!
作者: tseyik    时间: 2014-3-17 00:38
本帖最后由 tseyik 于 2014-3-17 00:41 编辑

1先加入External Text (v2.1)脚本(最新版)
2依格式做一個Text.txt的文本
3运行游戏自动生成Text.rvdata2,
4:把Text.rvdata2改名English.rvdata2
5:翻譯Text.txt成其他語言
6:运行游戏自动生成Text.rvdata2,
7:把Text.rvdata2改名Simplified_Chinese.rvdata2
8:把脚本“External Text”中的Languages = ["English"]改成Languages = ["English", "Simplified_Chinese"]
9:在遊戏中使用脚本SceneManager.call(Scene_LanguageSelect)會出現選用語言画面





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1