设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2573|回复: 2

[原创发布] 事件·脚本扩张

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1680
在线时间
91 小时
注册时间
2019-5-16
帖子
45
发表于 2019-5-23 00:16:35 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
Q:它能做什么?
A:文章自动换行、排版,支持缩头避尾规则和英文排版规则。可以为选项设置出现条件、合法性检查和帮助文本。还有更多。请仔细阅读脚本说明。

Q:为什么除了最开始的说明,其他注释都是日语?
A:本来抱着练习日语的想法,注释全部以日语书写。既然要发出来,就把说明部分翻译成中文吧。

  1. #==============================================================================
  2. # ◆ 事件·脚本扩张 by Aephiex
  3. #------------------------------------------------------------------------------
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #------------------------------------------------------------------------------
  9. #
  10. #   主要机能:
  11. #   ◎ 添加控制符
  12. #      ○ \n -> 强制换行(大写无效;"\n[i]" 优先)
  13. #      ○ \f -> 强制换页(大写无效)
  14. #      ○ \NN[i] -> i号主角别名
  15. #      ○ \PN[i] -> i号队员别名
  16. #      ○ #{...} -> 花括弧以内的文字将作为 Ruby 脚本解析,替换成出现的文本
  17. #                   千万不要在脚本中使用 "{" 、 "}"
  18. #   ◎ 文章自动换行、排版
  19. #      ○ 自动避免将特定的标点符号放在行首、行末。
  20. #      ○ 通过将常量 "USE_ENGLISH_COMPOSITION" 设为 "true" 可启用英语排版。
  21. #         这时,将自动避免换行将单词切断。
  22. #      ○ 通过脚本 "AutoNewline.turnOff" 和 "AutoNewline.turnOn"
  23. #         可切换自动换行的使用状态。
  24. #      ○ 自动换行作用中,除 "\n" 之外的换行全部被无视。
  25. #      ○ 和文字放大、缩小的控制符一起使用时会出现问题。
  26. #   ◎ 滚动文章指令可作为常规文章使用
  27. #      ○ enable_batch_text(face_name, face_index, background, position)
  28. #         下一个滚动文章指令变成常规文章指令。
  29. #         配合 "\n" "\f" 和自动换行使用,比连续配置的多个常规文章指令更为方便。
  30. #   ◎ 事件页可设置脚本为出现条件
  31. #      ○ 事件页的第一个指令若为备注,且备注的第一行是 "Condition:",
  32. #         则除第一行之外的部分将作为 Ruby 脚本解析,成为事件的出现条件。
  33. #         如有任何多余文字则设定无效。
  34. #   ◎ 连续设置的多个选项将合并为一个选项
  35. #   ◎ 可以为选项设置出现条件、合法性检查和帮助文本
  36. #      ○ 在备注指令的第一行写上特定关键字来设定。如有任何多余文字则设定无效。
  37. #      ○ 备注的第一行写上 "Potential:",则第二行开始将作为 Ruby
  38. #         脚本解析,成为该选项的出现条件。
  39. #      ○ 备注的第一行写上 "Valid:",则第二行开始将作为 Ruby
  40. #         脚本解析,成为该选项的合法性检查。
  41. #      ○ 备注的第一行写上 "Tooltip:",则第二行开始将作为选项的帮助文本。
  42. #      ○ 这些备注块必须在选项效果的最开头连续地配置。中断点以来的设置无效。
  43. #   ◎ 增加操作独立开关的脚本
  44. #      ○ set_self_switch('A', map_id, event_id)
  45. #      ○ get_self_switch('A', map_id, event_id)
  46. #         Key 也可以设定为 'A' 'B' 'C' 'D' 之外的东西。
  47. #         若不指定地图ID,则会成为本地图的ID。
  48. #         若不指定事件ID,则会成为本事件的ID。
  49. #         适合与 "Condition:" 一同使用。
  50. #   ◎ 重置变量、开关和私有开关的指令
  51. #      ○ $game_variables.reset
  52. #      ○ $game_switches.reset
  53. #      ○ $game_self_switches.reset([map_id, [event_id]])
  54. #         若不指定地图ID,则会消除全部私有开关。
  55. #         若不指定事件ID,则会消除本地图的全部私有开关。
  56. #         通过 @map_id 和 @event_id 来限定本地图、本事件。
  57. #   ◎ 像公共事件一般呼出其他事件页
  58. #      ○ call_page(page_id, [event_id])
  59. #         若不指定事件ID,则会成为本事件的ID。
  60. #         无法呼出其他地图上的事件的事件页。
  61. #   ◎ 下次的选项指令的位置改变
  62. #      ○ set_choice_position(x, y, num_choices)
  63. #   ◎ 设置下次输入数字时的最小值和最大值
  64. #      ○ set_number_range(min, max)
  65. #   ◎ 事件中任何脚本出错都不会关闭游戏,会弹窗提示事件、地图ID以及脚本内容。
  66. #   ◎ 连续配置的脚本指令会合并为一个脚本指令,一起执行。
  67. #
  68. #==============================================================================

  69. #==============================================================================
  70. # ■ AutoNewline
  71. #------------------------------------------------------------------------------
  72. # 自動改行のモジュール。
  73. #==============================================================================
  74. module AutoNewline
  75.   #--------------------------------------------------------------------------
  76.   # ¤ 自動改行
  77.   # デフォルトオフにしたいなら "false" に
  78.   #--------------------------------------------------------------------------
  79.   SWITCH = true
  80.   #--------------------------------------------------------------------------
  81.   # ¤ 英語組版
  82.   #--------------------------------------------------------------------------
  83.   # While Off:
  84.   # > Hello, I'm Eric, a Rakdos Bers<
  85.   # > erker.                        <
  86.   #
  87.   # While On:
  88.   # > Hello, I'm Eric, a Rakdos     <
  89.   # > Berserker.                    <
  90.   #--------------------------------------------------------------------------
  91.   USE_ENGLISH_COMPOSITION = false
  92.   #--------------------------------------------------------------------------
  93.   # ¤ 自動改行使用中か
  94.   #--------------------------------------------------------------------------
  95.   def self.isTurnedOn
  96.     return SWITCH
  97.   end
  98.   #--------------------------------------------------------------------------
  99.   # ¤ 英語組版使用中か
  100.   #--------------------------------------------------------------------------
  101.   def self.useEnglishComposition
  102.     return USE_ENGLISH_COMPOSITION
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   # ¤ 自動改行停止
  106.   #--------------------------------------------------------------------------
  107.   def self.turnOff
  108.     self.const_set(:SWITCH, false)
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # ¤ 自動改行再開
  112.   #--------------------------------------------------------------------------
  113.   def self.turnOn
  114.     self.const_set(:SWITCH, true)
  115.   end
  116. end

  117. #==============================================================================
  118. # □ Game_Message
  119. #==============================================================================
  120. class Game_Message
  121.   #--------------------------------------------------------------------------
  122.   # ¤ インスタンス変数
  123.   #--------------------------------------------------------------------------
  124.   attr_accessor :next_choice_x     # 次に選択肢ウィンドウを表示する場合のx
  125.   attr_accessor :next_choice_y     # 次に選択肢ウィンドウを表示する場合のy
  126.   attr_accessor :choice_row_max    # 次に選択肢ウィンドウを表示する場合の表示数
  127.   attr_accessor :choice_validities # 選択肢の合法性
  128.   attr_accessor :choice_tooltips   # 選択肢の説明文章
  129.   #--------------------------------------------------------------------------
  130.   # ○ クリア
  131.   #--------------------------------------------------------------------------
  132.   alias clear_enhanced_text clear
  133.   def clear
  134.     clear_enhanced_text
  135.     @next_choice_x = nil
  136.     @next_choice_y = nil
  137.     @choice_row_max = 6
  138.     @choice_validities = []
  139.     @choice_tooltips = {}
  140.   end
  141. end

  142. #==============================================================================
  143. # □ Game_Event
  144. #==============================================================================
  145. class Game_Event
  146.   #--------------------------------------------------------------------------
  147.   # ○ イベントの出現条件の検察
  148.   #--------------------------------------------------------------------------
  149.   alias conditions_met_enhanced_text conditions_met?
  150.   def conditions_met?(page)
  151.     return false if !conditions_met_enhanced_text(page)
  152.     if page.list[0].code == 108 && page.list[0].parameters[0] == "Condition:"
  153.       pack = []
  154.       i = 1
  155.       while (page.list[i].code == 408)
  156.         pack.push(@list[i].parameters[0])
  157.         i += 1
  158.       end
  159.       string = pack.join("\n")
  160.       begin
  161.         s, v = $game_switches, $game_variables
  162.         return eval(string)
  163.       rescue
  164.         msgbox "Error in Event Condition\n" +
  165.                "Map: " + $game_map.display_name + " (" + @map_id.to_s + ")\n" +
  166.                "Event: " + @event.name + " ("+ @id.to_s + ")\n\n" +
  167.                "Script:\n" +
  168.                string
  169.         return true
  170.       end
  171.     end
  172.     return true
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # ¤ イベントページの取得
  176.   #--------------------------------------------------------------------------
  177.   def get_page(index)
  178.     @event.pages[index]
  179.   end
  180. end

  181. #==============================================================================
  182. # □ Game_Interpreter
  183. #==============================================================================
  184. class Game_Interpreter
  185.   #--------------------------------------------------------------------------
  186.   # ○ 余計なファイバー作成の防止
  187.   #--------------------------------------------------------------------------
  188.   alias create_fiber_enhanced_text create_fiber
  189.   def create_fiber
  190.     create_fiber_enhanced_text if @depth == 0
  191.   end
  192.   #--------------------------------------------------------------------------
  193.   # ○ スクロール文章の表示
  194.   #--------------------------------------------------------------------------
  195.   alias command_105_enhanced_text command_105
  196.   def command_105
  197.     if @ehv_batch_text
  198.       wait_for_message
  199.       $game_message.face_name = @ehv_batch_text[0]
  200.       $game_message.face_index = @ehv_batch_text[1]
  201.       $game_message.background = @ehv_batch_text[2]
  202.       $game_message.position = @ehv_batch_text[3]
  203.       while next_event_code == 405
  204.         @index += 1
  205.         $game_message.add(@list[@index].parameters[0])
  206.       end
  207.       case next_event_code
  208.       when 102
  209.         @index += 1
  210.         setup_choices(@list[@index].parameters)
  211.       when 103
  212.         @index += 1
  213.         setup_num_input(@list[@index].parameters)
  214.       when 104
  215.         @index += 1
  216.         setup_item_choice(@list[@index].parameters)
  217.       end
  218.       wait_for_message
  219.       @ehv_batch_text = nil
  220.     else
  221.       command_105_enhanced_text
  222.     end
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # ● スクリプト
  226.   #--------------------------------------------------------------------------
  227.   def command_355
  228.     pack = [@list[@index].parameters[0]]
  229.     while next_event_code == 355 || next_event_code == 655
  230.       @index += 1
  231.       pack.push(@list[@index].parameters[0])
  232.     end
  233.     script = pack.join("\n")
  234.     begin
  235.       s, v = $game_switches, $game_variables
  236.       eval(script)
  237.     rescue
  238.       msgbox "Error in Script:\n" +
  239.         "Map: #{@map_id}\nEvent: #{@event_id}\n\nScript: #{script}"
  240.     end
  241.   end
  242.   #--------------------------------------------------------------------------
  243.   # ○ 変数の設定
  244.   #--------------------------------------------------------------------------
  245.   alias command_122_enhanced_text command_122
  246.   def command_122
  247.     if @params[3] == 4
  248.       value = nil
  249.       begin
  250.         s, v = $game_switches, $game_variables
  251.         value = eval(@params[4])
  252.       rescue
  253.         msgbox "Error Setting Variable with Script:\n" +
  254.           "Map: #{@map_id}\nEvent: #{@event_id}\n\nScript: #{@params[4]}"
  255.         return
  256.       end
  257.       (@params[0]..@params[1]).each {|i| operate_variable(i, @params[2], value) }
  258.     else
  259.       command_122_enhanced_text
  260.     end
  261.   end
  262.   #--------------------------------------------------------------------------
  263.   # ○ 条件分岐
  264.   #--------------------------------------------------------------------------
  265.   alias command_111_enhanced_text command_111
  266.   def command_111
  267.     if @params[0] == 12
  268.       result = false
  269.       begin
  270.         s, v = $game_switches, $game_variables
  271.         result = eval(@params[1])
  272.       rescue
  273.         msgbox "Error Checking Condition Branch Script:\n" +
  274.           "Map: #{@map_id}\nEvent: #{@event_id}\n\nScript: #{@params[1]}"
  275.         result = false
  276.       end
  277.       @branch[@indent] = result
  278.       command_skip unless @branch[@indent]
  279.     else
  280.       command_111_enhanced_text
  281.     end
  282.   end
  283.   #--------------------------------------------------------------------------
  284.   # ● 条件分岐終了
  285.   #--------------------------------------------------------------------------
  286.   def command_404
  287.     if next_event_code == 102
  288.       @branch[@indent] -= 5 if @branch.include?(@indent)
  289.       @index += 1
  290.       command_skip
  291.     end
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # ● 選択肢のセットアップ
  295.   #--------------------------------------------------------------------------
  296.   def setup_choices(params)
  297.     result = []
  298.     iterativelyPushChoices(params, @index, result)
  299.     if !$game_message.choices.empty?
  300.       ci = result.index($game_message.choice_cancel_type - 1)
  301.       $game_message.choice_validities.push(!ci || $game_message.choice_validities[ci])
  302.       result.push($game_message.choice_cancel_type - 1)
  303.       $game_message.choice_proc = Proc.new {|n| @branch[@indent] = result[n] }
  304.     else
  305.       @branch[@indent] = -1
  306.     end
  307.   end
  308.   #--------------------------------------------------------------------------
  309.   # ¤ 選択肢追加の繰り返し
  310.   #--------------------------------------------------------------------------
  311.   def iterativelyPushChoices(params, i, result, d = 0)
  312.     visibilities = []
  313.     num_choice_added = 0
  314.     indent = @list[i].indent
  315.     loop do
  316.       i += 1
  317.       if @list[i].indent == indent
  318.         case @list[i].code
  319.         when 402
  320.           if isChoiceVisible(i + 1)
  321.             visibilities.push(true)
  322.             loadChoiceConditionTooltip(result.size + num_choice_added, i + 1)
  323.             num_choice_added += 1
  324.           else
  325.             visibilities.push(false)
  326.           end
  327.         when 404
  328.           break
  329.         end
  330.       end
  331.     end
  332.     params[0].each_with_index do |s, n|
  333.       if visibilities[n]
  334.         $game_message.choices.push(s)
  335.         result.push(n + d)
  336.       end
  337.     end
  338.     if params[1] == 5 || (params[1] > 0 && result.include?(params[1] - 1 + d))
  339.       $game_message.choice_cancel_type = params[1] + d
  340.     end
  341.     i += 1
  342.     iterativelyPushChoices(@list[i].parameters, i, result, d + 5) if @list[i].code == 102
  343.   end
  344.   #--------------------------------------------------------------------------
  345.   # ¤ 選択肢の表示条件のチェック
  346.   #--------------------------------------------------------------------------
  347.   def isChoiceVisible(i)
  348.     flag = false
  349.     pack = []
  350.     while (@list[i].code == 108 || @list[i].code == 408)
  351.       if @list[i].code == 108
  352.         break if flag
  353.         header = @list[i].parameters[0]
  354.         if header == "Potential:"
  355.           flag = true
  356.         elsif header == "Valid:"
  357.         elsif header == "Tooltip:"
  358.         else
  359.           break
  360.         end
  361.       else
  362.         pack.push(@list[i].parameters[0]) if flag
  363.       end
  364.       i += 1
  365.     end
  366.     return true if pack.empty?
  367.     string = pack.join("\n")
  368.     begin
  369.       s, v = $game_switches, $game_variables
  370.       return eval(string) ? true : false
  371.     rescue
  372.       msgbox "Error in Option Condition:\n#{string}"
  373.       return true
  374.     end
  375.   end
  376.   #--------------------------------------------------------------------------
  377.   # ¤ 選択肢の有効状態のチェック及び説明文章の取得
  378.   #--------------------------------------------------------------------------
  379.   def loadChoiceConditionTooltip(index_of_choice, i)
  380.     loadable = [ true, true ]
  381.     comments = [ [], [] ]
  382.     index = -1
  383.     while (@list[i].code == 108 || @list[i].code == 408)
  384.       if @list[i].code == 108
  385.         loadable[index] = false if index >= 0
  386.         index = -1
  387.         header = @list[i].parameters[0]
  388.         if header == "Potential:"
  389.         elsif header == "Valid:"
  390.           index = 0 if loadable[0]
  391.         elsif header == "Tooltip:"
  392.           index = 1 if loadable[1]
  393.         else
  394.           break
  395.         end
  396.       else
  397.         comments[index].push(@list[i].parameters[0]) if loadable[index]
  398.       end
  399.       i += 1
  400.     end
  401.     comments.each_with_index do |pack, j|
  402.       if j == 0
  403.         if pack.empty?
  404.           $game_message.choice_validities[index_of_choice] = true
  405.         else
  406.           string = pack.join("\n")
  407.           begin
  408.             s, v = $game_switches, $game_variables
  409.             $game_message.choice_validities[index_of_choice] = eval(string) ? true : false
  410.           rescue
  411.             msgbox "Error in Option Condition:\n#{string}"
  412.             $game_message.choice_validities[index_of_choice] = true
  413.           end
  414.         end
  415.       elsif j == 1
  416.         $game_message.choice_tooltips[index_of_choice] = pack.clone if !pack.empty?
  417.       end
  418.     end
  419.   end
  420.   #--------------------------------------------------------------------------
  421.   # ¤ スクリプト:セルフスイッチセッター
  422.   #--------------------------------------------------------------------------
  423.   def set_self_switch(key, status, map_id = @map_id, event_id = @event_id)
  424.     begin
  425.       $game_self_switches[[map_id, event_id, key]] = status ? true : false
  426.     rescue
  427.       msgbox "Error Setting Self Switch:\n" +
  428.         "Map: #{map_id}\nEvent: #{event_id}\nKey: #{key}\nStatus: #{status}"
  429.     end
  430.   end
  431.   #--------------------------------------------------------------------------
  432.   # ¤ スクリプト:セルフスイッチゲッター
  433.   #--------------------------------------------------------------------------
  434.   def get_self_switch(key, map_id = @map_id, event_id = @event_id)
  435.     begin
  436.       return $game_self_switches[[map_id, event_id, key]] ? true : false
  437.     rescue
  438.       msgbox "Error Checking Self Switch:\n" +
  439.         "Map: #{map_id}\nEvent: #{event_id}\nKey: #{key}"
  440.       return false
  441.     end
  442.   end
  443.   #--------------------------------------------------------------------------
  444.   # ¤ スクリプト:選択肢位置を一時的に調整する
  445.   #--------------------------------------------------------------------------
  446.   def set_choice_position(x, y, count = 99)
  447.     $game_message.next_choice_x = x
  448.     $game_message.next_choice_y = y
  449.     $game_message.choice_row_max = count
  450.   end
  451.   #--------------------------------------------------------------------------
  452.   # ¤ スクリプト:別のページを呼び出す
  453.   #     param : -1 ならプレイヤー、0 ならこのイベント、それ以外はイベント ID
  454.   #--------------------------------------------------------------------------
  455.   def call_page(index, param = 0)
  456.     event = get_character(param)
  457.     page = event ? event.get_page(index - 1) : nil
  458.     if page
  459.       child = Game_Interpreter.new(@depth + 1)
  460.       child.setup(page.list, same_map? ? @event_id : 0)
  461.       child.run
  462.     end
  463.   end
  464.   #--------------------------------------------------------------------------
  465.   # ¤ スクリプト:次回数字入力時の最小値と最大値の設定
  466.   #--------------------------------------------------------------------------
  467.   def set_number_range(min, max)
  468.     Window_NumberInput.setRange(min, max)
  469.   end
  470.   #--------------------------------------------------------------------------
  471.   # ¤ スクリプト:次のスクロール文章を通常文章とする
  472.   #--------------------------------------------------------------------------
  473.   def enable_batch_text(face_name, face_index, background, position)
  474.     @ehv_batch_text = [ face_name, face_index, background, position ]
  475.   end
  476. end

  477. #==============================================================================
  478. # □ Game_Switches
  479. #==============================================================================
  480. class Game_Switches
  481.   #--------------------------------------------------------------------------
  482.   # ¤ リセット
  483.   #--------------------------------------------------------------------------
  484.   def reset
  485.     @data = []
  486.     on_change
  487.   end
  488.   #--------------------------------------------------------------------------
  489.   # ● 設定する
  490.   #--------------------------------------------------------------------------
  491.   def []=(switch_id, value)
  492.     @data[switch_id] = value ? true : nil
  493.     on_change
  494.   end
  495. end

  496. #==============================================================================
  497. # □ Game_Variables
  498. #==============================================================================
  499. class Game_Variables
  500.   #--------------------------------------------------------------------------
  501.   # ¤ リセット
  502.   #--------------------------------------------------------------------------
  503.   def reset
  504.     @data = []
  505.     on_change
  506.   end
  507.   #--------------------------------------------------------------------------
  508.   # ● 設定する
  509.   #--------------------------------------------------------------------------
  510.   def []=(variable_id, value)
  511.     @data[variable_id] = value != 0 ? value : nil
  512.     on_change
  513.   end
  514. end

  515. #==============================================================================
  516. # □ Game_SelfSwitches
  517. #==============================================================================
  518. class Game_SelfSwitches
  519.   #--------------------------------------------------------------------------
  520.   # ¤ リセット
  521.   #--------------------------------------------------------------------------
  522.   def reset(map_id = nil, event_id = nil)
  523.     if map_id
  524.       @data.keys.each do |key|
  525.         @data.delete(key) if key[1] == map_id &&
  526.           (!event_id || key[2] == event_id)
  527.       end
  528.     else
  529.       @data = {}
  530.     end
  531.     on_change
  532.   end
  533.   #--------------------------------------------------------------------------
  534.   # ● 設定する
  535.   #--------------------------------------------------------------------------
  536.   def []=(key, value)
  537.     if value
  538.       @data[key] = true
  539.     else
  540.       @data.delete(key)
  541.     end
  542.     on_change
  543.   end
  544. end

  545. #==============================================================================
  546. # □ Window_Base
  547. #==============================================================================
  548. class Window_Base
  549.   #--------------------------------------------------------------------------
  550.   # ¤ クラス定数
  551.   #--------------------------------------------------------------------------
  552.   # 行頭に置く事ができない文字
  553.   NO_LINE_HEAD = [")", "]", "}", ">", "」", "』", "】", "〉", "》", "〕", "’", "”",
  554.                   ",", "、", "。", "?", "!", ";", ":",
  555.                   "ぁ", "ぃ", "ぅ", "ぇ", "ぉ", "ゃ", "ゅ", "ょ", "ゎ", "ー",
  556.                   "ァ", "ィ", "ゥ", "ェ", "ォ", "ャ", "ュ", "ョ", "ヮ"]
  557.   # 行末に置く事ができない文字
  558.   NO_LINE_END  = ["(", "[", "{", "<", "「", "『", "【", "〈", "《", "〔", "‘", "“"]
  559.   # 改行で分断できない両文字組
  560.   NO_BREAKING  = ["——", "……"]
  561.   #--------------------------------------------------------------------------
  562.   # ● 制御文字の事前変換
  563.   #--------------------------------------------------------------------------
  564.   def convert_escape_characters(text)
  565.     result = text.to_s.clone
  566.     result.gsub!(/\r\n/)               { "\n" }
  567.     result.gsub!(/\\/)                 { "\e" }
  568.     result.gsub!(/\e\e/)               { "\\" }
  569.     result.gsub!(/\#\{([^{}]+)\}/i)    { evalScriptedText($1) }
  570.     result.gsub!(/\eV\[(\d+)\]/i)      { $game_variables[$1.to_i] }
  571.     result.gsub!(/\eV\[(\d+)\]/i)      { $game_variables[$1.to_i] }
  572.     result.gsub!(/\eN\[(\d+)\]/i)      { actor_name($1.to_i) }
  573.     result.gsub!(/\eP\[(\d+)\]/i)      { party_member_name($1.to_i) }
  574.     result.gsub!(/\eNN\[(\d+)\]/i)     { actorNickname($1.to_i) }
  575.     result.gsub!(/\ePN\[(\d+)\]/i)     { memberNickname($1.to_i) }
  576.     result.gsub!(/\eG/i)               { Vocab::currency_unit }
  577.     if AutoNewline.isTurnedOn && AutoNewline.useEnglishComposition
  578.       result.gsub!(/[\n\f]/)           { " " }
  579.       result.gsub!(/\en/)              { "\n" }
  580.       result.gsub!(/\ef/)              { "\f" }
  581.       return applyEnglishComposition(result, contents.width - self.new_line_x)
  582.     else
  583.       result.gsub!(/[\n\f]/)           { "" } if AutoNewline.isTurnedOn
  584.       result.gsub!(/\en/)              { "\n" }
  585.       result.gsub!(/\ef/)              { "\f" }
  586.       return result
  587.     end
  588.   end
  589.   #--------------------------------------------------------------------------
  590.   # ¤ 英語組版を適用
  591.   #--------------------------------------------------------------------------
  592.   def applyEnglishComposition(text, width)
  593.     pages = text.split("\f")
  594.     pages.each_with_index do |page, i_page|
  595.       lines = page.split("\n")
  596.       lines.each_with_index do |line, i_line|
  597.         local_width = width
  598.         line_break_positions = {}
  599.         words = line.split(" ")
  600.         words.each_with_index do |word, i_word|
  601.           word_width = widthOfWord(word)
  602.           if local_width < word_width
  603.             line_break_positions[i_word] = true
  604.             local_width = width
  605.           end
  606.           local_width -= word_width
  607.           local_width -= contents.text_size(" ").width
  608.         end
  609.         lines[i_line] = ""
  610.         words.each_with_index do |word, i_word|
  611.           lines[i_line] += word
  612.           if i_word < words.size - 1
  613.             if line_break_positions[i_word + 1]
  614.               lines[i_line] += "\n"
  615.             else
  616.               lines[i_line] += " "
  617.             end
  618.           end
  619.         end
  620.       end
  621.       pages[i_page] = lines.join("\n")
  622.     end
  623.     return pages.join("\f")
  624.   end
  625.   #--------------------------------------------------------------------------
  626.   # ¤ 制御符を取り除いた文字幅
  627.   #--------------------------------------------------------------------------
  628.   def widthOfWord(word)
  629.     word_width = 0
  630.     word2 = word.dup
  631.     word2.gsub!(/\eI\[\d+\]/) { word_width += 24; next nil }
  632.     word2.gsub!(/\e[^Ii]\[[^\[\]]+\]/)
  633.     word2.gsub!(/\e./)
  634.     word_width += contents.text_size(word2).width
  635.     return word_width
  636.   end
  637.   #--------------------------------------------------------------------------
  638.   # ● 文字の処理
  639.   #--------------------------------------------------------------------------
  640.   def process_character(c, text, pos)
  641.     case c
  642.     when "\n"
  643.       process_new_line(text, pos)
  644.     when "\f"
  645.       process_new_page(text, pos)
  646.     when "\e"
  647.       process_escape_character(obtain_escape_code(text), text, pos)
  648.     else
  649.       if AutoNewline.isTurnedOn && !AutoNewline.useEnglishComposition
  650.         preNormalCharCheckLinebreak(c, pos, text.empty? ? nil : text[0, 1])
  651.       end
  652.       process_normal_character(c, pos)
  653.     end
  654.   end
  655.   #--------------------------------------------------------------------------
  656.   # ¤ 通常文字の処理(自動改行)
  657.   #--------------------------------------------------------------------------
  658.   def preNormalCharCheckLinebreak(c_next, pos, c_future = nil)
  659.     prev_width = pos[:x]
  660.     if prev_width >= contents.width
  661.       process_new_line(c_next, pos)
  662.     else
  663.       next_width = prev_width + contents.text_size(c_next).width
  664.       if next_width >= contents.width ||
  665.         (c_future && next_width + contents.text_size(c_future).width >= contents.width &&
  666.           (NO_LINE_END.include?(c_next) ||
  667.            NO_LINE_HEAD.include?(c_future) ||
  668.            NO_BREAKING.include?(c_next + c_future)))
  669.         process_new_line(c_next, pos)
  670.       end
  671.     end
  672.   end
  673.   #--------------------------------------------------------------------------
  674.   # ¤ 制御文字 #{...} の処理
  675.   #--------------------------------------------------------------------------
  676.   def evalScriptedText(str)
  677.     begin
  678.       s, v = $game_switches, $game_variables
  679.       return eval(str)
  680.     rescue
  681.       msgbox "Error Converting Script to String:\n" +
  682.         "Map: #{@map_id}\nEvent: #{@event_id}\n\nScript: \#\{#{str}\}"
  683.       return "<ERROR>"
  684.     end
  685.   end
  686.   #--------------------------------------------------------------------------
  687.   # ¤ アクターの二つ名
  688.   #--------------------------------------------------------------------------
  689.   def actorNickname(n)
  690.     actor = n >= 1 ? $game_actors[n] : nil
  691.     actor ? actor.nickname : ""
  692.   end
  693.   #--------------------------------------------------------------------------
  694.   # ¤ パティーメンバーの二つ名
  695.   #--------------------------------------------------------------------------
  696.   def memberNickname(n)
  697.     actor = n >= 1 ? $game_party.members[n-1] : nil
  698.     actor ? actor.nickname : ""
  699.   end
  700.   #--------------------------------------------------------------------------
  701.   # ▽ 改行位置の取得 (Window_Message に上書きられ)
  702.   #--------------------------------------------------------------------------
  703.   def new_line_x
  704.     return 0
  705.   end
  706. end

  707. #==============================================================================
  708. # □ Window_Message
  709. #==============================================================================
  710. class Window_Message
  711.   #--------------------------------------------------------------------------
  712.   # ● 改行文字の処理
  713.   #--------------------------------------------------------------------------
  714.   def process_new_line(text, pos)
  715.     @line_show_fast = false
  716.     super
  717.     if need_new_page?(text, pos)
  718.       input_pause
  719.       new_page(text, pos, true)
  720.     end
  721.   end
  722.   #--------------------------------------------------------------------------
  723.   # ○ 改ページ処理
  724.   #--------------------------------------------------------------------------
  725.   alias new_page_enhanced_text new_page
  726.   def new_page(text, pos, keep_font_settings = nil)
  727.     @keep_font_settings = keep_font_settings
  728.     new_page_enhanced_text(text, pos)
  729.     @keep_font_settings = nil
  730.   end
  731.   #--------------------------------------------------------------------------
  732.   # ○ フォント設定のリセット
  733.   #--------------------------------------------------------------------------
  734.   alias reset_font_settings_enhanced_text reset_font_settings
  735.   def reset_font_settings
  736.     return if @keep_font_settings
  737.     reset_font_settings_enhanced_text
  738.   end
  739.   #--------------------------------------------------------------------------
  740.   # ¤ 説明文章を強行クリア
  741.   #--------------------------------------------------------------------------
  742.   def forceClear
  743.     @gold_window.close
  744.     @fiber = nil
  745.     close
  746.   end
  747.   #--------------------------------------------------------------------------
  748.   # ¤ 説明文章を早送りにする
  749.   #--------------------------------------------------------------------------
  750.   def forceShowFast
  751.     @show_fast = true
  752.   end
  753. end

  754. #==============================================================================
  755. # □ Window_ChoiceList
  756. #==============================================================================
  757. class Window_ChoiceList
  758.   #--------------------------------------------------------------------------
  759.   # ● 入力処理の開始
  760.   #--------------------------------------------------------------------------
  761.   def start
  762.     return unless close?
  763.     update_placement
  764.     refresh
  765.     select(-1)
  766.     open
  767.     activate
  768.   end
  769.   #--------------------------------------------------------------------------
  770.   # ● ウィンドウ位置の更新
  771.   #--------------------------------------------------------------------------
  772.   def update_placement
  773.     self.width = [max_choice_width + 12, 96].max + padding * 2
  774.     self.width = [width, Graphics.width].min
  775.     h1 = fitting_height($game_message.choices.size)
  776.     h2 = fitting_height($game_message.choice_row_max)
  777.     self.height = h1 < h2 ? h1 : h2
  778.     self.x = $game_message.next_choice_x ? $game_message.next_choice_x : Graphics.width - width
  779.     if $game_message.next_choice_y
  780.       self.y = $game_message.next_choice_y
  781.     else
  782.       if @message_window.y >= Graphics.height / 2
  783.         self.y = @message_window.y - height
  784.       else
  785.         self.y = @message_window.y + @message_window.height
  786.       end
  787.     end
  788.   end
  789.   #--------------------------------------------------------------------------
  790.   # ● コマンドリストの作成
  791.   #--------------------------------------------------------------------------
  792.   def make_command_list
  793.     $game_message.choices.each_with_index do |choice, i|
  794.       add_command(choice, :choice, $game_message.choice_validities[i])
  795.     end
  796.   end
  797.   #--------------------------------------------------------------------------
  798.   # ○ 項目の描画
  799.   #--------------------------------------------------------------------------
  800.   alias draw_item_enhanced_text draw_item
  801.   def draw_item(index)
  802.     @choice_enabled = command_enabled?(index)
  803.     draw_item_enhanced_text(index)
  804.   end
  805.   #--------------------------------------------------------------------------
  806.   # ▲ テキスト描画色の変更
  807.   #--------------------------------------------------------------------------
  808.   def change_color(color, enabled = true)
  809.     super(color, enabled && @choice_enabled)
  810.   end
  811.   #--------------------------------------------------------------------------
  812.   # ▲ キャンセルボタンが押されたときの処理
  813.   #--------------------------------------------------------------------------
  814.   def process_cancel
  815.     if $game_message.choice_validities[item_max]
  816.       super
  817.     else
  818.       Sound.play_buzzer
  819.     end
  820.   end
  821.   #--------------------------------------------------------------------------
  822.   # ● キャンセルハンドラの呼び出し
  823.   #--------------------------------------------------------------------------
  824.   def call_cancel_handler
  825.     $game_message.choice_proc.call(item_max)
  826.     close
  827.   end
  828.   #--------------------------------------------------------------------------
  829.   # ▲ 閉じる
  830.   #--------------------------------------------------------------------------
  831.   def close
  832.     @message_window.forceShowFast unless $game_message.choice_tooltips.empty?
  833.     super
  834.   end
  835.   #--------------------------------------------------------------------------
  836.   # ▲ ヘルプウィンドウ更新メソッドの呼び出し
  837.   #--------------------------------------------------------------------------
  838.   def call_update_help
  839.     update_help if active && !$game_message.choice_tooltips.empty?
  840.   end
  841.   #--------------------------------------------------------------------------
  842.   # ▲ ヘルプウィンドウの更新
  843.   #--------------------------------------------------------------------------
  844.   def update_help
  845.     @message_window.forceClear
  846.     if $game_message.choice_tooltips.include?(index)
  847.       $game_message.texts.replace($game_message.choice_tooltips[index])
  848.     else
  849.       $game_message.texts.clear
  850.     end
  851.   end
  852.   #--------------------------------------------------------------------------
  853.   # △ カーソルを上に移動
  854.   #--------------------------------------------------------------------------
  855.   alias cursor_up_enhanced_text cursor_up
  856.   def cursor_up(wrap = false)
  857.     @index = 0 if @index == -1
  858.     cursor_up_enhanced_text(wrap)
  859.   end
  860.   #--------------------------------------------------------------------------
  861.   # △ 決定ボタンが押されたときの処理
  862.   #--------------------------------------------------------------------------
  863.   alias process_ok_enhanced_text process_ok
  864.   def process_ok
  865.     return if self.index == -1
  866.     process_ok_enhanced_text()
  867.   end
  868. end

  869. #==============================================================================
  870. # □ Window_NumberInput
  871. #==============================================================================
  872. class Window_NumberInput
  873.   #--------------------------------------------------------------------------
  874.   # ○ リフレッシュ
  875.   #--------------------------------------------------------------------------
  876.   alias refresh_unmodified refresh
  877.   def refresh
  878.     @number = @@min if @@min && @number < @@min
  879.     @number = @@max if @@max && @number > @@max
  880.     refresh_unmodified
  881.   end
  882.   #--------------------------------------------------------------------------
  883.   # ○ 決定ボタンが押されたときの処理
  884.   #--------------------------------------------------------------------------
  885.   alias process_ok_unmodified process_ok
  886.   def process_ok
  887.     @@min = nil
  888.     @@max = nil
  889.     process_ok_unmodified
  890.   end
  891.   #--------------------------------------------------------------------------
  892.   # ¤ 最小値と最大値の設定
  893.   #--------------------------------------------------------------------------
  894.   def self.setRange(min, max)
  895.     min = 0 if min < 0
  896.     max = 0 if max < 0
  897.     max = min if min > max
  898.     @@min = min
  899.     @@max = max
  900.   end
  901. end
复制代码

Lv6.析梦学徒

老鹰

梦石
39
星屑
33308
在线时间
6542 小时
注册时间
2012-5-26
帖子
3176

极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

发表于 2019-5-23 00:37:01 | 显示全部楼层
练习日语还行hhhh
不过好多杂七杂八的东西都堆在一个脚本里,不方便使用的人来决定优化与整合吧()
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1680
在线时间
91 小时
注册时间
2019-5-16
帖子
45
 楼主| 发表于 2019-5-23 00:43:54 | 显示全部楼层
百里_飞柳 发表于 2019-5-23 00:37
练习日语还行hhhh
不过好多杂七杂八的东西都堆在一个脚本里,不方便使用的人来决定优化与整合吧() ...


主要是为自己使用,功能上大体上在同一个领域就堆到一起了。类似地,我还有很多其他脚本也是这么出来的,但考虑到其功能已有大量重复的轮子存在,还有许多未完成项,所以不想发布。这个脚本,我所见为限,还没有看到过自动排版的重复轮子,所以决定发布。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-3-29 00:53

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表