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

Project1

 找回密码
 注册会员
搜索
查看: 1186|回复: 2
打印 上一主题 下一主题

谁能帮我简单化对话框加强脚本

 关闭 [复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
3 小时
注册时间
2007-5-31
帖子
89
跳转到指定楼层
1
发表于 2007-6-17 02:27:28 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

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

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

x
\n[1]:显示1号角色的姓名
\m[李逍遥]:显示一个“李逍遥”方框,表示说话人姓名
\m[\n[1]]:显示一号人物名子的方框

我只要这几种功能就好,其他不要
  1. #==============================================================================
  2. # ◎ GPRA_Window_Message
  3. #------------------------------------------------------------------------------
  4. # ◎ 顯示文章的信息窗口加強。
  5. #------------------------------------------------------------------------------
  6. class Window_Message < Window_Selectable
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化狀態
  9.   #--------------------------------------------------------------------------
  10.   def initialize
  11. #    super(60,304,520,160)
  12.     super(135,304,500,160)
  13.     self.contents = Bitmap.new(width - 32,height - 32)
  14.     self.visible = false
  15.     self.z = 9998
  16.     @fade_in = false
  17.     @fade_out = false
  18.     @contents_showing = false
  19.     @cursor_width = 0
  20.     @op = 255 # 不透明度
  21.     @head_bmp = nil # 裝載頭像用
  22.     @head_file = nil # 頭像檔案名
  23.     @text = nil # 記錄所處理文字
  24.     @skip = false # 記錄是否跳過此次對話
  25.     @auto_close = -1 # 預設不打開自動關閉
  26.     @type_mode=-1 # 打字模式
  27.     @delay=-1 # 等待n畫格標誌
  28.     @finish=false # 記錄文字處理是否結束
  29.     @is_read_txt =false # 預設不是在讀取txt檔案
  30.     self.active = false
  31.     self.index = -1
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # ● 釋放
  35.   #--------------------------------------------------------------------------
  36.   def dispose
  37.     terminate_message
  38.     $game_temp.message_window_showing = false
  39.     if @input_number_window != nil
  40.       @input_number_window.dispose
  41.     end
  42.     super
  43.   end
  44.   #--------------------------------------------------------------------------
  45.   # ● 處理信息結束
  46.   #--------------------------------------------------------------------------
  47.   def terminate_message
  48.    
  49. #以下為增加姓名框處理
  50.     if @name_window_frame != nil
  51.       @name_window_frame.dispose
  52.       @name_window_frame = nil
  53.     end
  54.     if @name_window_text != nil
  55.       @name_window_text.dispose
  56.       @name_window_text = nil
  57.     end
  58. #以上為增加姓名框處理

  59.     self.active = false
  60.     self.pause = false
  61.     self.index = -1
  62.     self.contents.clear
  63.     # 清除顯示中標誌
  64.     @contents_showing = false
  65.     # 呼叫信息調用
  66.     if $game_temp.message_proc != nil
  67.       $game_temp.message_proc.call
  68.     end
  69.     # 清除文章,選擇項,輸入數值的相關變量
  70.     $game_temp.message_text = nil
  71.     $game_temp.message_proc = nil
  72.     $game_temp.choice_start = 99
  73.     $game_temp.choice_max = 0
  74.     $game_temp.choice_cancel_type = 0
  75.     $game_temp.choice_proc = nil
  76.     $game_temp.num_input_start = 99
  77.     $game_temp.num_input_variable_id = 0
  78.     $game_temp.num_input_digits_max = 0
  79.     # 開放金錢窗口
  80.     if @gold_window != nil
  81.       @gold_window.dispose
  82.       @gold_window = nil
  83.     end
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # ● 刷新
  87.   #--------------------------------------------------------------------------
  88.   def refresh
  89.     # 清空原先內容
  90.     self.contents.clear
  91.     # 恢復一般字色
  92.     self.contents.font.color = normal_color
  93.     # 恢復字體大小
  94.     self.contents.font.size = 20
  95.     # 繪製文字位置初始化
  96.     @x = @y = 0
  97.     # 字體高度記錄
  98.     @height = 32
  99.     # 文字不透明度設定為255
  100.     @op = 255
  101.     # 頭像預設顯示在右邊
  102.     @right = true
  103.     # 頭像預設顯示一般表情
  104.     @face = nil
  105.     # 預設顯示角色姓名
  106.     @name = nil
  107.     # 預設不跳過此次對話
  108.     @skip = false
  109.     # 從變量讀取自動關閉設置
  110.     @auto_close = $game_variables[102]
  111.     # 從變量讀取打字模式設置
  112.     @type_mode=$game_variables[103]
  113.     # 預設不等待
  114.     @delay=-1
  115.     # 設定文字沒有處理結束
  116.     @finish=false
  117.     # 光標寬度初始化為零
  118.     @cursor_width = 0
  119.     # 到選擇項的下一行字
  120.     if $game_temp.choice_start == 0
  121.       @x = 16
  122.     end
  123.     # 有等待顯示的文字的情況下
  124.     # (註:因為一旦文字非空就處理,所以可以設定 $game_temp.message_text 達到顯示文章的效果)
  125.     if $game_temp.message_text != nil
  126. #      # @text 功能改進
  127. #      if @text==nil or @text==""
  128. #      @text = $game_temp.message_text.dup
  129. #      else
  130. #        @text = @text + $game_temp.message_text
  131. #      end



  132. #以下為對話記錄
  133.       clue = $game_temp.message_text.split(/@clu/)[1]
  134.       if clue != nil
  135.         if @text==nil
  136.           @text = $game_temp.message_text.split(/@/)[0]
  137.         else
  138.           @text = @text + $game_temp.message_text.split(/@/)[0]
  139.         end
  140.        # @text = $game_temp.message_text.split(/@/)[0]
  141.       
  142.         if $game_variables[36].include?($game_variables[3])==false
  143.           $game_variables[36][$game_variables[3]]={}
  144.         end#當前魔塔編號不存在就創建它
  145.         if $game_variables[36][$game_variables[3]].include?($game_variables[2])==false
  146.           $game_variables[36][$game_variables[3]][$game_variables[2]]=[]
  147.         end#當前魔塔編號當前樓層不存在就創建它
  148.         if $game_variables[36][0].include?($game_variables[3])==false
  149.           $game_variables[36][0][$game_variables[3]]=0
  150.         end#當前魔塔編號對話記錄次數不存在就創建它
  151.         if $game_variables[36][$game_variables[3]][1000]==nil
  152.           $game_variables[36][$game_variables[3]][1000]=[]
  153.         end#當前魔塔編號對話記錄順序排列不存在就創建它

  154. #       p $game_temp.message_text.split(/@/)[0]
  155. #       p $game_variables[36][$game_variables[3]][$game_variables[2]].include?($game_temp.message_text.split(/@/)[0])
  156.         if $game_variables[36][$game_variables[3]][$game_variables[2]].include?($game_temp.message_text.split(/@/)[0])==false
  157.           $game_variables[36][$game_variables[3]][$game_variables[2]].push ($game_temp.message_text.split(/@/)[0])


  158.           $game_variables[36][0][$game_variables[3]]+=1# 已知的對話條數
  159.           @j=0
  160.           for i in 0...$game_variables[2]+1
  161.             if $game_variables[36][$game_variables[3]].include?(i)
  162.               @j+=$game_variables[36][$game_variables[3]][i].size
  163.             end
  164.           end
  165.           @j-=1
  166.           @j=0 if @j<=0

  167.           $game_variables[36][$game_variables[3]][1000].insert @j,[$game_variables[2],$game_variables[36][$game_variables[3]][$game_variables[2]][$game_variables[36][$game_variables[3]][$game_variables[2]].size-1]]
  168.         end
  169.       else
  170.         if @text==nil
  171.           @text = $game_temp.message_text.dup
  172.         else
  173.           @text = @text + $game_temp.message_text
  174.         end
  175. #        @text = $game_temp.message_text
  176.       end
  177. #以上為對話記錄      
  178.       
  179.       # 最先必須要將 "\\\\" 變換為 "\000"
  180.       @text.gsub!(/\\\\/)                { "\000" }
  181.       
  182.       # 在TXT模式還沒有打開的時候
  183.       if !@is_read_txt
  184.         # TXT讀取模式打開
  185.         if @text.slice!(/\\[Tt][Xx][Tt]\[(\w+)\]\[(\w+)\]/)!=nil
  186.           # 打開檔案,成功打開後再進入後面部分
  187.           if @ts.open($1,$2)
  188.             # 根據顯示模式確定需要打開行數
  189.             case $game_variables[1]
  190.             when 0 # 正常模式
  191.               @text =  @ts.get_text(4)
  192.             when 1 # 圖書模式
  193.               @text =  @ts.get_text(12)
  194.             when 2 # 全螢幕模式
  195.               @text =  @ts.get_text(15)
  196.             end
  197.             # 如果包含[END]
  198.             if @text.gsub!(/\[END\]/){""}!=nil
  199.               #退出TXT讀取模式
  200.               @is_read_txt=false
  201.             else
  202.               #否則設置正在讀取標誌
  203.               @is_read_txt=true
  204.             end
  205.           end
  206.         else
  207.           if @text.slice!(/\\[Tt][Xx][Tt]\[(\w+)\]/)!=nil
  208.             # 打開檔案,成功打開後再進入後面部分
  209.             if @ts.open($1,"")
  210.               # 根據顯示模式確定需要打開行數
  211.               case $game_variables[101]
  212.               when 0 # 正常模式
  213.                 @text =  @ts.get_text(4)
  214.               when 1 # 圖書模式
  215.                 @text =  @ts.get_text(12)
  216.               when 2 # 全螢幕模式
  217.                 @text =  @ts.get_text(15)
  218.               end
  219.               # 如果包含[END]
  220.               if @text.gsub!(/\[END\]/){""}!=nil
  221.                 #退出TXT讀取模式
  222.                 @is_read_txt=false
  223.               else
  224.                 #否則設置正在讀取標誌
  225.                 @is_read_txt=true
  226.               end
  227.             end
  228.           end
  229.         end
  230.       end
  231.         
  232.       # 如果取得的字符含"\\~"時
  233.       if @text.slice!(/\\~/)!=nil
  234.         # 跳過此次對話
  235.         terminate_message
  236.         # 設置跳過此次對話標誌
  237.         @skip = true
  238.         # 直接返回等待連接後面部分
  239.         return
  240.       end
  241.       
  242.       # 限制文字處理(註:這裡是預設功能。)
  243.       begin
  244.         last_text = @text.clone
  245.         @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  246.       end until @text == last_text
  247.       @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  248.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  249.       end
  250.       #(註:後面將單個字符循環判斷,所以這裡將控制符全部換成單個字符)
  251.       # 為了方便將 "\\C" 變為 "\001"
  252.       @text.gsub!(/\\[Cc]\[([0-9#a-zA-Z]+)\]/)  { "\001[#{$1}]" }
  253.       # "\\G" 變為 "\002"
  254.       @text.gsub!(/\\[Gg]/)              { "\002" }
  255.       
  256.       # ========================增強功能========================
  257.       
  258.       #對話加強      
  259.       @now_text=$game_temp.message_text
  260.       name_window_set = false#\m[姓名]在對話框上增加姓名
  261.       if (/\\[Mm]\[(.+?)\]/.match(@now_text)) != nil
  262. #        name_window_set = true
  263.         name_text = $1
  264.         @now_text.sub!(/\\[Mm]\[(.*?)\]/) { "" }
  265.       end

  266.       @text.gsub!(/\\[Mm]\[(.+?)\]/) do
  267.         name_window_set = true
  268.         name_text = $1
  269.         @now_text.sub!(/\\[Mm]\[(.*?)\]/) { "" }
  270.       end
  271.       #對話加強
  272.       
  273.       
  274.       # "\\/" 刪除行尾換行符號
  275.       @text.gsub!(/\\\/\n/) {""}
  276.       # 去掉不在行尾的"\\/"符號,防止出錯
  277.       @text.gsub!(/\\\//) {""}
  278.       
  279.       # "\\S" 字體大小(只修改第一個"\\S")
  280.       # 這裡首先刪掉能找到的第一個"\\S"
  281.       if @text.slice!(/\\[Ss]\[([0-9]+)\]/)!=nil
  282.         # 當找了"\\S"時滿足上述條件,就設置文字大小
  283.         self.set_font_size($1.to_i)
  284.       end
  285.       # "\\O" 文字透明度(使用注意同上,模擬聲音變小……)
  286.       if @text.slice!(/\\[Oo]\[([0-9]+)\]/)!=nil
  287.         self.set_font_op($1.to_i)
  288.       end

  289.       # "\\=" 停頓固定畫格(延時)
  290.       @text.gsub!(/\\=\[([0-9]+)\]/)    { "\024[#{$1}]" }
  291.       # "\\." 停頓3畫格
  292.       @text.gsub!(/\\\./)               { "\024[3]" }
  293.       # "\\_" 停頓1秒(30畫格)
  294.       @text.gsub!(/\\_/)                { "\024[30]" }
  295.       
  296.       # "\\L" 指定頭像左邊顯示
  297.       if @text.slice!(/\\[Ll]/)!=nil
  298.         # 設定頭像居右標誌為假
  299.         @right=false
  300.         # 順便要設置@x=104,文字在右邊顯示
  301.         @x=104
  302.       end
  303.       # "\\X" 指定不要顯示姓名,帶參數就是指定顯示姓名(可內部使用"\\N[]")
  304.       # 首先是尋找有沒有帶參數的"\\X"
  305.       if @text.slice!(/\\[Xx]\[(\w+)\]/)!=nil
  306.         # 找到的話將參數賦予@name
  307.         @name=$1
  308.       # 沒有找到的話
  309.       else
  310.         # 再去尋找有沒有不帶參數的"\\X"
  311.         if @text.slice!(/\\[Xx]/)!=nil
  312.           # 找到的話就將姓名變成"???"
  313.           @name="???"
  314.         end
  315.       end
  316.       # "\\F" 指定表情(Face 用來指定表情啦)
  317.       # 這裡"\w"表示匹配字母+數字還有下劃線,同樣支援中文
  318.       if @text.slice!(/\\[Ff]\[(\w+)\]/)!=nil
  319.         # 找到的話就設定表情
  320.         @face=$1
  321.       end
  322.       # "\\H" 顯示頭像(不明白大家為什麼都喜歡用 Face 表示頭像……)
  323.       # 這裡我將把顯示頭像放到字串的最前面,因為頭像應該先顯示出來
  324.       if @text.slice!(/\\[Hh]\[([0-9]+)\]/)!=nil
  325.         # 找到的話就提到字符串最前面
  326.         @text="\030[#{$1}]"+@text
  327.       end
  328.       
  329.       # ================ 分析部分結束,下面是顯示部分 ================
  330.    
  331.       # 在此調用過程完成,因為在update部分也會有相同代碼
  332.       self.refresh_

  333.     end
  334.     # 選擇項的情況
  335.     if $game_temp.choice_max > 0
  336.       @item_max = $game_temp.choice_max
  337.       self.active = true
  338.       self.index = 0
  339.     end
  340.     # 輸入數值的情況
  341.     if $game_temp.num_input_variable_id > 0
  342.       digits_max = $game_temp.num_input_digits_max
  343.       number = $game_variables[$game_temp.num_input_variable_id]
  344.       @input_number_window = Window_InputNumber.new(digits_max)
  345.       @input_number_window.number = number
  346.       @input_number_window.x = self.x + 8
  347.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  348.     end
  349.    
  350. #對話加強
  351. #    reset_window
  352.     if name_window_set
  353.       off_x = 0
  354.       off_y = -40
  355.       space = 2
  356.       x = self.x + off_x - space / 2
  357.       y = self.y + off_y - space / 2
  358.       w = self.contents.text_size(name_text).width + 26 + space
  359.       h = 40 + space
  360.       @name_window_frame = Window_Frame.new(x,y,w,h)
  361.       @name_window_frame.z = self.z + 1
  362.       x = self.x + off_x + 4
  363.       y = self.y + off_y
  364.       @name_window_text = Air_Text.new(x+4,y+6,name_text)
  365.       @name_window_text.z = self.z + 2
  366.     end
  367. #對話加強

  368.   end
  369.   #--------------------------------------------------------------------------
  370.   # ● 設置窗口位置與不透明度
  371.   #--------------------------------------------------------------------------
  372.   def reset_window
  373.     # 判斷現在的顯示模式
  374.     case $game_variables[101]
  375.     when 0 # 普通模式
  376.       self.width=480
  377.       self.height=160
  378.       self.contents = Bitmap.new(width - 32,height - 32)
  379. #      self.x = 80
  380.       self.x = 145
  381.       if $game_temp.in_battle
  382. #        self.y = 16
  383.         self.y = 50
  384.       else
  385.         case $game_system.message_position
  386.         when 0  # 上
  387. #          self.y = 16
  388.           self.y = 50
  389.         when 1  # 中
  390.           self.y = 160
  391.         when 2  # 下
  392.           self.y = 304
  393.         end
  394.       end
  395.     when 1 # 圖書模式
  396.       self.width=532
  397.       self.height=416
  398.       self.contents = Bitmap.new(width - 32,height - 32)
  399.       self.x = 54
  400.       self.y = 32
  401.     when 2 # 全螢幕模式
  402.       self.width=672
  403.       self.height=512
  404.       self.contents = Bitmap.new(width - 32,height - 32)
  405.       self.x = -16
  406.       self.y = -16
  407.     end
  408.     if $game_system.message_frame == 0
  409.       self.opacity = 255
  410.     else
  411.       self.opacity = 0
  412.     end
  413.     self.back_opacity = 192
  414.   end
  415.   #--------------------------------------------------------------------------
  416.   # ● 刷新畫面
  417.   #--------------------------------------------------------------------------
  418.   def update
  419.     super
  420.     # 漸變的情況下
  421.     if @fade_in
  422.       # 腳本在這裡設定透明度
  423.       self.contents_opacity += @op/8
  424.       if @input_number_window != nil
  425.         @input_number_window.contents_opacity += 32
  426.       end
  427.       if self.contents_opacity >= @op
  428.         @fade_in = false
  429.       end
  430.       return
  431.     end
  432.     # 輸入數值的情況下
  433.     if @input_number_window != nil
  434.       @input_number_window.update
  435.       
  436. #取消-使輸入框可以被取消
  437.       if Input.trigger?(Input::B)
  438.         $game_switches[44]=true
  439.         $game_system.se_play($data_system.cancel_se)
  440.         @input_number_window.dispose
  441.         @input_number_window = nil
  442.         terminate_message
  443.       end#以上為增加的功能
  444.       
  445.       # 確定
  446.       if Input.trigger?(Input::C)
  447.         $game_system.se_play($data_system.decision_se)
  448.         $game_variables[$game_temp.num_input_variable_id] =
  449.           @input_number_window.number
  450.         $game_map.need_refresh = true
  451.         # 釋放輸入數值窗口
  452.         @input_number_window.dispose
  453.         @input_number_window = nil
  454.         terminate_message
  455.       end
  456.       return
  457.     end
  458.     # 顯示信息中的情況下
  459.     if @contents_showing
  460.       # 刷新文本
  461.       self.refresh_
  462.       # 如果不是在顯示選擇項中就顯示暫停標誌
  463.       if $game_temp.choice_max == 0
  464.         self.pause = true
  465.       end
  466.       # 取消
  467.       if Input.trigger?(Input::B)
  468.         if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
  469.           $game_system.se_play($data_system.cancel_se)
  470.           $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  471.           terminate_message
  472.         end
  473.       end
  474.       # @auto_close自減計數
  475.       @auto_close-=1
  476.       # 確定或者自動關閉
  477.       if Input.trigger?(Input::C) or @auto_close==0 # @auto_close為0自動關閉,所以一開始為負數或0就不會自動關閉
  478.         # 文字還沒有處理完的時候
  479.         if !@finish
  480.           # 刪除所有停頓效果
  481.           @text.gsub!(/\024\[([0-9]+)\]/) { "" }
  482.           # 刪除當前延遲效果
  483.           @delay = 0
  484.           # 關閉打字效果
  485.           @type_mode=-1
  486.           # 一次處理完所有的字
  487.           self.refresh_
  488.         else
  489.           # 有選擇項的情況
  490.           if $game_temp.choice_max > 0
  491.             $game_system.se_play($data_system.decision_se)
  492.             $game_temp.choice_proc.call(self.index)
  493.           end
  494.           # 清空文字
  495.           terminate_message
  496.           # 在讀取TXT的模式下,需要繼續打開文字
  497.           if @is_read_txt
  498.             # 根據顯示模式確定需要打開行數
  499.             case $game_variables[101]
  500.             when 0 # 正常模式
  501.               $game_temp.message_text =  @ts.get_text(4)
  502.             when 1 # 圖書模式
  503.               $game_temp.message_text =  @ts.get_text(12)
  504.             when 2 # 全螢幕模式
  505.               $game_temp.message_text =  @ts.get_text(15)
  506.             end
  507.             # 如果包含[END]則退出TXT讀取模式
  508.             if $game_temp.message_text.gsub!(/\[END\]/){""}!=nil
  509.               @is_read_txt=false
  510.             end
  511.           end
  512.         end
  513.       end
  514.       return
  515.     end
  516.     # 在漸變以外的狀態下有等待顯示的信息與選擇項的場合
  517.     if @fade_out == false and !($game_temp.message_text == nil or $game_temp.message_text == "")
  518.       @contents_showing = true
  519.       $game_temp.message_window_showing = true
  520.       reset_window
  521.       refresh
  522.       Graphics.frame_reset
  523.       # 當不跳過對話時才進行淡入操作
  524.       if !@skip
  525.         self.visible = true
  526.         self.contents_opacity = 0
  527.         if @input_number_window != nil
  528.           @input_number_window.contents_opacity = 0
  529.         end
  530.         @fade_in = true
  531.       end
  532.       return
  533.     end
  534.     # 沒有可以顯示的信息,但是窗口為可見的情況下
  535.     if self.visible
  536.       @fade_out = true
  537.       self.opacity -= 48
  538.       if self.opacity == 0
  539.         self.visible = false
  540.         @fade_out = false
  541.         $game_temp.message_window_showing = false
  542.       end
  543.       return
  544.     end
  545.   end
  546.   #--------------------------------------------------------------------------
  547.   # ● 刷新光標矩形
  548.   #--------------------------------------------------------------------------
  549.   def update_cursor_rect
  550.     if @index >= 0
  551.       n = $game_temp.choice_start + @index
  552.       self.cursor_rect.set(8,n * 32,@cursor_width,32)
  553.     else
  554.       self.cursor_rect.empty
  555.     end
  556.   end
  557.   #--------------------------------------------------------------------------
  558.   # ● 設定字體大小
  559.   #--------------------------------------------------------------------------
  560.   def set_font_size(size=20)
  561.     # 最大字96號,再大就超過文字欄了,而且Ruby本來有限制……
  562.     if size>96
  563.       size=96
  564.     end
  565.     # 設定字的大小
  566.     self.contents.font.size = size
  567.     # 如果字太大了就要加高每行文字高度。
  568.     if size > 28
  569.       @height=size+4
  570.     else
  571.       @height=32
  572.     end
  573.   end
  574.   #--------------------------------------------------------------------------
  575.   # ● 設定文字透明
  576.   #--------------------------------------------------------------------------
  577.   def set_font_op(op=255)
  578.     # 限制透明度為0-255
  579.     if op>255
  580.       op=255
  581.     elsif op<0
  582.       op=0
  583.     end
  584.     # 這裡設定文字透明是沒有用的,設定透明在update過程開始
  585.     @op = op
  586.   end
  587.   #--------------------------------------------------------------------------
  588.   # ● 顯示文字/頭像過程
  589.   #--------------------------------------------------------------------------
  590.   def refresh_
  591.     # 處理已經結束的情況下直接return
  592.     if @finish
  593.       return
  594.     end
  595.     # 延時處理
  596.     @delay-=1
  597.     if @delay<=0
  598.       # 每次處理i個標誌,這裡i就設置為@type_mode了
  599.       i=@type_mode
  600.       # c 獲取 1 個字 (如果不能取得文字就循環)
  601.       while ((c = @text.slice!(/./m)) != nil)
  602.         # \\ 的情況下
  603.         if c == "\000"
  604.           # 還原為本來的文字
  605.           c = "\\"
  606.         end
  607.         # \C[n] 的情況下
  608.         if c == "\001"
  609.           # 取得字色編碼
  610.           @text.sub!(/\[([0-9#a-zA-Z]+)\]/,"")
  611.           # 如果是設定RGB顏色
  612.           if $1[0,1]=="#"
  613.             # 先拷貝一下文字
  614.             c=$1.dup
  615.             # 分3段分別取出R,G,B顏色
  616.             c.sub!(/#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})/,"")
  617.             # 設定文字顏色
  618.             self.contents.font.color = Color.new($1.to_i(16),$2.to_i(16),$3.to_i(16),@op)
  619.             next
  620.           else
  621.             # 記錄到變量 color
  622.             color = $1.to_i
  623.             # 字色0~7是有效的
  624.             if color >= 0 and color <= 7
  625.               # 設置文字顏色
  626.               self.contents.font.color = text_color(color)
  627.             end
  628.           end
  629.           # 進行下次循環
  630.           next
  631.         end
  632.         # 顯示金錢窗口,這個……不用說了吧……
  633.         if c == "\002"
  634.           if @gold_window == nil
  635.             @gold_window = Window_Gold.new
  636.             @gold_window.x = 560 - @gold_window.width
  637.             if $game_temp.in_battle
  638.               @gold_window.y = 192
  639.             else
  640.               @gold_window.y = self.y >= 128 ? 32 : 384
  641.             end
  642.             @gold_window.opacity = self.opacity
  643.             @gold_window.back_opacity = self.back_opacity
  644.           end
  645.           next
  646.         end
  647.         # 另起一行文字的情況下
  648.         if c == "\n"
  649.           # 刷新選擇項及光標的高
  650.           if @y >= $game_temp.choice_start
  651.             @cursor_width = [@cursor_width,@x>440 ? 448 : @x+8].max
  652.           end
  653.           # y 加 1
  654.           @y += 1
  655.           # 因為字體大小會變化,這裡添加判斷語句,超出就不顯示了
  656.           if @y>=self.contents.height/@height
  657.             # 刪除@text剩餘的所有內容
  658.             @text=nil
  659.             # 然後返回
  660.             break
  661.           end
  662.           # 因為頭像的緣故,這裡需要改寫
  663.           if @right
  664.             # 頭像右邊顯示的時候是0
  665.             @x=0
  666.           else
  667.             # 頭像靠左顯示時@x要留出繪製頭像空間
  668.             @x=104
  669.           end
  670.           # 移動到選擇項的下一行
  671.           if @y >= $game_temp.choice_start
  672.             @x=16
  673.           end
  674.           # 下面的文字
  675.           next
  676.         end

  677.         # 等待n畫格
  678.         if c == "\024"
  679.           # 取得參數(需要等待多少畫格)
  680.           @text.sub!(/\[([0-9]+)\]/,"")
  681.           # 設定@delay標誌
  682.           @delay = $1.to_i
  683.           # 退出此次循環
  684.           break
  685.         end
  686.         
  687.         # 顯示頭像
  688.         if c == "\030"
  689.           #暫時記錄文字大小,用於顯示完頭像恢復
  690.           size=self.contents.font.size
  691.           # 設定為正常的20號字
  692.           self.contents.font.size=20
  693.           # 設定系統字色,為寫名字做準備的
  694.           self.contents.font.color = system_color
  695.           # 取得"[]"內的字符並從原字串中刪除這一部分
  696.           @text.sub!(/\[([0-9]+)\]/,"")
  697.           # 記錄到head變量
  698.           head=$1
  699.           # 判斷頭像和原來的是不是一樣的
  700.           if @face == nil
  701.             # 不一樣
  702.             if @head_file != head
  703.               # 改變成現在的頭像檔案名
  704.               @head_file = head
  705.               # 不一樣的話再重新載入頭像
  706.               @head_bmp=RPG::Cache.character("head/gpra_"+@head_file,0)
  707.             end
  708.           else
  709.             # 當表情不是空的時候需要考慮表情的
  710.             if @head_file != head + "_" + @face
  711.               # 改變成現在的頭像檔案名
  712.               @head_file = head + "_" + @face
  713.               # 不一樣的話再重新載入頭像
  714.               @head_bmp=RPG::Cache.character("head/gpra_"+@head_file,0)
  715.             end
  716.           end
  717.           # 顯示頭像,分左右兩種情況
  718.           if @right
  719.             # 繪製頭像圖片
  720.             self.contents.blt(348,0,@head_bmp,Rect.new(0,0,100,100))
  721.             # 顯示角色姓名
  722.             if @name==nil
  723.               # 取得角色姓名到變量 c
  724.               c = $game_actors[head.to_i].name
  725.               # 描繪角色的姓名
  726.               self.contents.draw_text(348,104,100,24,c,1)
  727.             else
  728.               # 取得"???"到變量 c,當然這個"???"可以改為其他的預設值
  729.               c = @name
  730.               # 描繪角色的姓名
  731.               self.contents.draw_text(348,104,100,24,c,1)
  732.             end
  733.           else
  734.             # 繪製頭像圖片
  735.             self.contents.blt(0,0,@head_bmp,Rect.new(0,0,100,100))
  736.             # 顯示角色姓名
  737.             if @name==nil
  738.               # 取得角色姓名到變量 c
  739.               c = $game_actors[head.to_i].name
  740.               # 描繪角色的姓名
  741.               self.contents.draw_text(0,104,100,24,c,1)
  742.             else
  743.               # 取得"???"到變量 c,當然這個"???"可以改為其他的預設值
  744.               c = @name
  745.               # 描繪角色的姓名
  746.               self.contents.draw_text(0,104,100,24,c,1)
  747.             end
  748.           end
  749.           # 恢復預設字色
  750.           self.contents.font.color = normal_color
  751.           # 恢復字體大小
  752.           self.contents.font.size=size
  753.           # 進行下一次循環
  754.           next
  755.         end
  756.         # 描繪文字
  757.         self.contents.draw_text(4+@x,@height*@y,@height,@height,c)
  758.         # x 為描繪文字寬度進行自增運算,計算下一個文字起始位置
  759.         @x += self.contents.text_size(c).width
  760.         
  761.         # 操作了@type_mode個字符後就退出循環了,@type_mode為負則操作一次完成
  762.         i-=1
  763.         if i==0
  764.           break
  765.         end
  766.       
  767.       end
  768.     end
  769.     # 如果@text處理結束了,就設置結束標誌
  770.     if @text==nil or @text==""
  771.       @finish=true
  772.     end
  773.   end
  774. #==============================================================================
  775. # ■ Window_Frame (樺だけで中身の無いウィンドウ)
  776. #==============================================================================
  777. class Window_Frame < Window_Base
  778.   #--------------------------------------------------------------------------
  779.   # ● オブジェクト初期化
  780.   #--------------------------------------------------------------------------
  781.   def initialize(x,y,width,height)
  782.     super(x,y,width,height)
  783.     self.contents = nil
  784.     self.back_opacity =200
  785.   end
  786.   #--------------------------------------------------------------------------
  787.   # ● 解放
  788.   #--------------------------------------------------------------------------
  789.   def dispose
  790.     super
  791.     end
  792.   end
  793. #==============================================================================
  794. # ■ Air_Text (何も無いところに文字描寫 = 樺の無い瞬間表示メッセージウィンドウ)
  795. #==============================================================================
  796. class Air_Text < Window_Base
  797.   #--------------------------------------------------------------------------
  798.   # ● オブジェクト初期化
  799.   #--------------------------------------------------------------------------
  800.   def initialize(x,y,designate_text)
  801.     super(x-16,y-16,32 + designate_text.size * 12,56)
  802.     self.opacity = 0
  803.     self.back_opacity = 0
  804.     self.contents = Bitmap.new(self.width - 32,self.height - 32)
  805.     w = self.contents.width
  806.     h = self.contents.height
  807.     self.contents.draw_text(0,0,w,h,designate_text)
  808.   end
  809.   #--------------------------------------------------------------------------
  810.   # ● 解放
  811.   #--------------------------------------------------------------------------
  812.   def dispose
  813.     self.contents.clear
  814.     super
  815.     end
  816.   end
  817. end
复制代码

本贴由论坛斑竹叶舞枫结贴,如楼主认为问题未解决,请重新将此贴编辑为“有事请教”,并回帖叙述疑点即可~ ^-^

Lv1.梦旅人

Dancer-

梦石
0
星屑
55
在线时间
76 小时
注册时间
2006-11-9
帖子
3551

开拓者贵宾

3
发表于 2007-6-18 22:17:32 | 只看该作者
那你就用那3个功能就行了,其他别用,反正米影响。
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
3 小时
注册时间
2007-5-31
帖子
89
2
 楼主| 发表于 2007-6-17 02:27:28 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

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

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

x
\n[1]:显示1号角色的姓名
\m[李逍遥]:显示一个“李逍遥”方框,表示说话人姓名
\m[\n[1]]:显示一号人物名子的方框

我只要这几种功能就好,其他不要
  1. #==============================================================================
  2. # ◎ GPRA_Window_Message
  3. #------------------------------------------------------------------------------
  4. # ◎ 顯示文章的信息窗口加強。
  5. #------------------------------------------------------------------------------
  6. class Window_Message < Window_Selectable
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化狀態
  9.   #--------------------------------------------------------------------------
  10.   def initialize
  11. #    super(60,304,520,160)
  12.     super(135,304,500,160)
  13.     self.contents = Bitmap.new(width - 32,height - 32)
  14.     self.visible = false
  15.     self.z = 9998
  16.     @fade_in = false
  17.     @fade_out = false
  18.     @contents_showing = false
  19.     @cursor_width = 0
  20.     @op = 255 # 不透明度
  21.     @head_bmp = nil # 裝載頭像用
  22.     @head_file = nil # 頭像檔案名
  23.     @text = nil # 記錄所處理文字
  24.     @skip = false # 記錄是否跳過此次對話
  25.     @auto_close = -1 # 預設不打開自動關閉
  26.     @type_mode=-1 # 打字模式
  27.     @delay=-1 # 等待n畫格標誌
  28.     @finish=false # 記錄文字處理是否結束
  29.     @is_read_txt =false # 預設不是在讀取txt檔案
  30.     self.active = false
  31.     self.index = -1
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # ● 釋放
  35.   #--------------------------------------------------------------------------
  36.   def dispose
  37.     terminate_message
  38.     $game_temp.message_window_showing = false
  39.     if @input_number_window != nil
  40.       @input_number_window.dispose
  41.     end
  42.     super
  43.   end
  44.   #--------------------------------------------------------------------------
  45.   # ● 處理信息結束
  46.   #--------------------------------------------------------------------------
  47.   def terminate_message
  48.    
  49. #以下為增加姓名框處理
  50.     if @name_window_frame != nil
  51.       @name_window_frame.dispose
  52.       @name_window_frame = nil
  53.     end
  54.     if @name_window_text != nil
  55.       @name_window_text.dispose
  56.       @name_window_text = nil
  57.     end
  58. #以上為增加姓名框處理

  59.     self.active = false
  60.     self.pause = false
  61.     self.index = -1
  62.     self.contents.clear
  63.     # 清除顯示中標誌
  64.     @contents_showing = false
  65.     # 呼叫信息調用
  66.     if $game_temp.message_proc != nil
  67.       $game_temp.message_proc.call
  68.     end
  69.     # 清除文章,選擇項,輸入數值的相關變量
  70.     $game_temp.message_text = nil
  71.     $game_temp.message_proc = nil
  72.     $game_temp.choice_start = 99
  73.     $game_temp.choice_max = 0
  74.     $game_temp.choice_cancel_type = 0
  75.     $game_temp.choice_proc = nil
  76.     $game_temp.num_input_start = 99
  77.     $game_temp.num_input_variable_id = 0
  78.     $game_temp.num_input_digits_max = 0
  79.     # 開放金錢窗口
  80.     if @gold_window != nil
  81.       @gold_window.dispose
  82.       @gold_window = nil
  83.     end
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # ● 刷新
  87.   #--------------------------------------------------------------------------
  88.   def refresh
  89.     # 清空原先內容
  90.     self.contents.clear
  91.     # 恢復一般字色
  92.     self.contents.font.color = normal_color
  93.     # 恢復字體大小
  94.     self.contents.font.size = 20
  95.     # 繪製文字位置初始化
  96.     @x = @y = 0
  97.     # 字體高度記錄
  98.     @height = 32
  99.     # 文字不透明度設定為255
  100.     @op = 255
  101.     # 頭像預設顯示在右邊
  102.     @right = true
  103.     # 頭像預設顯示一般表情
  104.     @face = nil
  105.     # 預設顯示角色姓名
  106.     @name = nil
  107.     # 預設不跳過此次對話
  108.     @skip = false
  109.     # 從變量讀取自動關閉設置
  110.     @auto_close = $game_variables[102]
  111.     # 從變量讀取打字模式設置
  112.     @type_mode=$game_variables[103]
  113.     # 預設不等待
  114.     @delay=-1
  115.     # 設定文字沒有處理結束
  116.     @finish=false
  117.     # 光標寬度初始化為零
  118.     @cursor_width = 0
  119.     # 到選擇項的下一行字
  120.     if $game_temp.choice_start == 0
  121.       @x = 16
  122.     end
  123.     # 有等待顯示的文字的情況下
  124.     # (註:因為一旦文字非空就處理,所以可以設定 $game_temp.message_text 達到顯示文章的效果)
  125.     if $game_temp.message_text != nil
  126. #      # @text 功能改進
  127. #      if @text==nil or @text==""
  128. #      @text = $game_temp.message_text.dup
  129. #      else
  130. #        @text = @text + $game_temp.message_text
  131. #      end



  132. #以下為對話記錄
  133.       clue = $game_temp.message_text.split(/@clu/)[1]
  134.       if clue != nil
  135.         if @text==nil
  136.           @text = $game_temp.message_text.split(/@/)[0]
  137.         else
  138.           @text = @text + $game_temp.message_text.split(/@/)[0]
  139.         end
  140.        # @text = $game_temp.message_text.split(/@/)[0]
  141.       
  142.         if $game_variables[36].include?($game_variables[3])==false
  143.           $game_variables[36][$game_variables[3]]={}
  144.         end#當前魔塔編號不存在就創建它
  145.         if $game_variables[36][$game_variables[3]].include?($game_variables[2])==false
  146.           $game_variables[36][$game_variables[3]][$game_variables[2]]=[]
  147.         end#當前魔塔編號當前樓層不存在就創建它
  148.         if $game_variables[36][0].include?($game_variables[3])==false
  149.           $game_variables[36][0][$game_variables[3]]=0
  150.         end#當前魔塔編號對話記錄次數不存在就創建它
  151.         if $game_variables[36][$game_variables[3]][1000]==nil
  152.           $game_variables[36][$game_variables[3]][1000]=[]
  153.         end#當前魔塔編號對話記錄順序排列不存在就創建它

  154. #       p $game_temp.message_text.split(/@/)[0]
  155. #       p $game_variables[36][$game_variables[3]][$game_variables[2]].include?($game_temp.message_text.split(/@/)[0])
  156.         if $game_variables[36][$game_variables[3]][$game_variables[2]].include?($game_temp.message_text.split(/@/)[0])==false
  157.           $game_variables[36][$game_variables[3]][$game_variables[2]].push ($game_temp.message_text.split(/@/)[0])


  158.           $game_variables[36][0][$game_variables[3]]+=1# 已知的對話條數
  159.           @j=0
  160.           for i in 0...$game_variables[2]+1
  161.             if $game_variables[36][$game_variables[3]].include?(i)
  162.               @j+=$game_variables[36][$game_variables[3]][i].size
  163.             end
  164.           end
  165.           @j-=1
  166.           @j=0 if @j<=0

  167.           $game_variables[36][$game_variables[3]][1000].insert @j,[$game_variables[2],$game_variables[36][$game_variables[3]][$game_variables[2]][$game_variables[36][$game_variables[3]][$game_variables[2]].size-1]]
  168.         end
  169.       else
  170.         if @text==nil
  171.           @text = $game_temp.message_text.dup
  172.         else
  173.           @text = @text + $game_temp.message_text
  174.         end
  175. #        @text = $game_temp.message_text
  176.       end
  177. #以上為對話記錄      
  178.       
  179.       # 最先必須要將 "\\\\" 變換為 "\000"
  180.       @text.gsub!(/\\\\/)                { "\000" }
  181.       
  182.       # 在TXT模式還沒有打開的時候
  183.       if !@is_read_txt
  184.         # TXT讀取模式打開
  185.         if @text.slice!(/\\[Tt][Xx][Tt]\[(\w+)\]\[(\w+)\]/)!=nil
  186.           # 打開檔案,成功打開後再進入後面部分
  187.           if @ts.open($1,$2)
  188.             # 根據顯示模式確定需要打開行數
  189.             case $game_variables[1]
  190.             when 0 # 正常模式
  191.               @text =  @ts.get_text(4)
  192.             when 1 # 圖書模式
  193.               @text =  @ts.get_text(12)
  194.             when 2 # 全螢幕模式
  195.               @text =  @ts.get_text(15)
  196.             end
  197.             # 如果包含[END]
  198.             if @text.gsub!(/\[END\]/){""}!=nil
  199.               #退出TXT讀取模式
  200.               @is_read_txt=false
  201.             else
  202.               #否則設置正在讀取標誌
  203.               @is_read_txt=true
  204.             end
  205.           end
  206.         else
  207.           if @text.slice!(/\\[Tt][Xx][Tt]\[(\w+)\]/)!=nil
  208.             # 打開檔案,成功打開後再進入後面部分
  209.             if @ts.open($1,"")
  210.               # 根據顯示模式確定需要打開行數
  211.               case $game_variables[101]
  212.               when 0 # 正常模式
  213.                 @text =  @ts.get_text(4)
  214.               when 1 # 圖書模式
  215.                 @text =  @ts.get_text(12)
  216.               when 2 # 全螢幕模式
  217.                 @text =  @ts.get_text(15)
  218.               end
  219.               # 如果包含[END]
  220.               if @text.gsub!(/\[END\]/){""}!=nil
  221.                 #退出TXT讀取模式
  222.                 @is_read_txt=false
  223.               else
  224.                 #否則設置正在讀取標誌
  225.                 @is_read_txt=true
  226.               end
  227.             end
  228.           end
  229.         end
  230.       end
  231.         
  232.       # 如果取得的字符含"\\~"時
  233.       if @text.slice!(/\\~/)!=nil
  234.         # 跳過此次對話
  235.         terminate_message
  236.         # 設置跳過此次對話標誌
  237.         @skip = true
  238.         # 直接返回等待連接後面部分
  239.         return
  240.       end
  241.       
  242.       # 限制文字處理(註:這裡是預設功能。)
  243.       begin
  244.         last_text = @text.clone
  245.         @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  246.       end until @text == last_text
  247.       @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  248.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  249.       end
  250.       #(註:後面將單個字符循環判斷,所以這裡將控制符全部換成單個字符)
  251.       # 為了方便將 "\\C" 變為 "\001"
  252.       @text.gsub!(/\\[Cc]\[([0-9#a-zA-Z]+)\]/)  { "\001[#{$1}]" }
  253.       # "\\G" 變為 "\002"
  254.       @text.gsub!(/\\[Gg]/)              { "\002" }
  255.       
  256.       # ========================增強功能========================
  257.       
  258.       #對話加強      
  259.       @now_text=$game_temp.message_text
  260.       name_window_set = false#\m[姓名]在對話框上增加姓名
  261.       if (/\\[Mm]\[(.+?)\]/.match(@now_text)) != nil
  262. #        name_window_set = true
  263.         name_text = $1
  264.         @now_text.sub!(/\\[Mm]\[(.*?)\]/) { "" }
  265.       end

  266.       @text.gsub!(/\\[Mm]\[(.+?)\]/) do
  267.         name_window_set = true
  268.         name_text = $1
  269.         @now_text.sub!(/\\[Mm]\[(.*?)\]/) { "" }
  270.       end
  271.       #對話加強
  272.       
  273.       
  274.       # "\\/" 刪除行尾換行符號
  275.       @text.gsub!(/\\\/\n/) {""}
  276.       # 去掉不在行尾的"\\/"符號,防止出錯
  277.       @text.gsub!(/\\\//) {""}
  278.       
  279.       # "\\S" 字體大小(只修改第一個"\\S")
  280.       # 這裡首先刪掉能找到的第一個"\\S"
  281.       if @text.slice!(/\\[Ss]\[([0-9]+)\]/)!=nil
  282.         # 當找了"\\S"時滿足上述條件,就設置文字大小
  283.         self.set_font_size($1.to_i)
  284.       end
  285.       # "\\O" 文字透明度(使用注意同上,模擬聲音變小……)
  286.       if @text.slice!(/\\[Oo]\[([0-9]+)\]/)!=nil
  287.         self.set_font_op($1.to_i)
  288.       end

  289.       # "\\=" 停頓固定畫格(延時)
  290.       @text.gsub!(/\\=\[([0-9]+)\]/)    { "\024[#{$1}]" }
  291.       # "\\." 停頓3畫格
  292.       @text.gsub!(/\\\./)               { "\024[3]" }
  293.       # "\\_" 停頓1秒(30畫格)
  294.       @text.gsub!(/\\_/)                { "\024[30]" }
  295.       
  296.       # "\\L" 指定頭像左邊顯示
  297.       if @text.slice!(/\\[Ll]/)!=nil
  298.         # 設定頭像居右標誌為假
  299.         @right=false
  300.         # 順便要設置@x=104,文字在右邊顯示
  301.         @x=104
  302.       end
  303.       # "\\X" 指定不要顯示姓名,帶參數就是指定顯示姓名(可內部使用"\\N[]")
  304.       # 首先是尋找有沒有帶參數的"\\X"
  305.       if @text.slice!(/\\[Xx]\[(\w+)\]/)!=nil
  306.         # 找到的話將參數賦予@name
  307.         @name=$1
  308.       # 沒有找到的話
  309.       else
  310.         # 再去尋找有沒有不帶參數的"\\X"
  311.         if @text.slice!(/\\[Xx]/)!=nil
  312.           # 找到的話就將姓名變成"???"
  313.           @name="???"
  314.         end
  315.       end
  316.       # "\\F" 指定表情(Face 用來指定表情啦)
  317.       # 這裡"\w"表示匹配字母+數字還有下劃線,同樣支援中文
  318.       if @text.slice!(/\\[Ff]\[(\w+)\]/)!=nil
  319.         # 找到的話就設定表情
  320.         @face=$1
  321.       end
  322.       # "\\H" 顯示頭像(不明白大家為什麼都喜歡用 Face 表示頭像……)
  323.       # 這裡我將把顯示頭像放到字串的最前面,因為頭像應該先顯示出來
  324.       if @text.slice!(/\\[Hh]\[([0-9]+)\]/)!=nil
  325.         # 找到的話就提到字符串最前面
  326.         @text="\030[#{$1}]"+@text
  327.       end
  328.       
  329.       # ================ 分析部分結束,下面是顯示部分 ================
  330.    
  331.       # 在此調用過程完成,因為在update部分也會有相同代碼
  332.       self.refresh_

  333.     end
  334.     # 選擇項的情況
  335.     if $game_temp.choice_max > 0
  336.       @item_max = $game_temp.choice_max
  337.       self.active = true
  338.       self.index = 0
  339.     end
  340.     # 輸入數值的情況
  341.     if $game_temp.num_input_variable_id > 0
  342.       digits_max = $game_temp.num_input_digits_max
  343.       number = $game_variables[$game_temp.num_input_variable_id]
  344.       @input_number_window = Window_InputNumber.new(digits_max)
  345.       @input_number_window.number = number
  346.       @input_number_window.x = self.x + 8
  347.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  348.     end
  349.    
  350. #對話加強
  351. #    reset_window
  352.     if name_window_set
  353.       off_x = 0
  354.       off_y = -40
  355.       space = 2
  356.       x = self.x + off_x - space / 2
  357.       y = self.y + off_y - space / 2
  358.       w = self.contents.text_size(name_text).width + 26 + space
  359.       h = 40 + space
  360.       @name_window_frame = Window_Frame.new(x,y,w,h)
  361.       @name_window_frame.z = self.z + 1
  362.       x = self.x + off_x + 4
  363.       y = self.y + off_y
  364.       @name_window_text = Air_Text.new(x+4,y+6,name_text)
  365.       @name_window_text.z = self.z + 2
  366.     end
  367. #對話加強

  368.   end
  369.   #--------------------------------------------------------------------------
  370.   # ● 設置窗口位置與不透明度
  371.   #--------------------------------------------------------------------------
  372.   def reset_window
  373.     # 判斷現在的顯示模式
  374.     case $game_variables[101]
  375.     when 0 # 普通模式
  376.       self.width=480
  377.       self.height=160
  378.       self.contents = Bitmap.new(width - 32,height - 32)
  379. #      self.x = 80
  380.       self.x = 145
  381.       if $game_temp.in_battle
  382. #        self.y = 16
  383.         self.y = 50
  384.       else
  385.         case $game_system.message_position
  386.         when 0  # 上
  387. #          self.y = 16
  388.           self.y = 50
  389.         when 1  # 中
  390.           self.y = 160
  391.         when 2  # 下
  392.           self.y = 304
  393.         end
  394.       end
  395.     when 1 # 圖書模式
  396.       self.width=532
  397.       self.height=416
  398.       self.contents = Bitmap.new(width - 32,height - 32)
  399.       self.x = 54
  400.       self.y = 32
  401.     when 2 # 全螢幕模式
  402.       self.width=672
  403.       self.height=512
  404.       self.contents = Bitmap.new(width - 32,height - 32)
  405.       self.x = -16
  406.       self.y = -16
  407.     end
  408.     if $game_system.message_frame == 0
  409.       self.opacity = 255
  410.     else
  411.       self.opacity = 0
  412.     end
  413.     self.back_opacity = 192
  414.   end
  415.   #--------------------------------------------------------------------------
  416.   # ● 刷新畫面
  417.   #--------------------------------------------------------------------------
  418.   def update
  419.     super
  420.     # 漸變的情況下
  421.     if @fade_in
  422.       # 腳本在這裡設定透明度
  423.       self.contents_opacity += @op/8
  424.       if @input_number_window != nil
  425.         @input_number_window.contents_opacity += 32
  426.       end
  427.       if self.contents_opacity >= @op
  428.         @fade_in = false
  429.       end
  430.       return
  431.     end
  432.     # 輸入數值的情況下
  433.     if @input_number_window != nil
  434.       @input_number_window.update
  435.       
  436. #取消-使輸入框可以被取消
  437.       if Input.trigger?(Input::B)
  438.         $game_switches[44]=true
  439.         $game_system.se_play($data_system.cancel_se)
  440.         @input_number_window.dispose
  441.         @input_number_window = nil
  442.         terminate_message
  443.       end#以上為增加的功能
  444.       
  445.       # 確定
  446.       if Input.trigger?(Input::C)
  447.         $game_system.se_play($data_system.decision_se)
  448.         $game_variables[$game_temp.num_input_variable_id] =
  449.           @input_number_window.number
  450.         $game_map.need_refresh = true
  451.         # 釋放輸入數值窗口
  452.         @input_number_window.dispose
  453.         @input_number_window = nil
  454.         terminate_message
  455.       end
  456.       return
  457.     end
  458.     # 顯示信息中的情況下
  459.     if @contents_showing
  460.       # 刷新文本
  461.       self.refresh_
  462.       # 如果不是在顯示選擇項中就顯示暫停標誌
  463.       if $game_temp.choice_max == 0
  464.         self.pause = true
  465.       end
  466.       # 取消
  467.       if Input.trigger?(Input::B)
  468.         if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
  469.           $game_system.se_play($data_system.cancel_se)
  470.           $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  471.           terminate_message
  472.         end
  473.       end
  474.       # @auto_close自減計數
  475.       @auto_close-=1
  476.       # 確定或者自動關閉
  477.       if Input.trigger?(Input::C) or @auto_close==0 # @auto_close為0自動關閉,所以一開始為負數或0就不會自動關閉
  478.         # 文字還沒有處理完的時候
  479.         if !@finish
  480.           # 刪除所有停頓效果
  481.           @text.gsub!(/\024\[([0-9]+)\]/) { "" }
  482.           # 刪除當前延遲效果
  483.           @delay = 0
  484.           # 關閉打字效果
  485.           @type_mode=-1
  486.           # 一次處理完所有的字
  487.           self.refresh_
  488.         else
  489.           # 有選擇項的情況
  490.           if $game_temp.choice_max > 0
  491.             $game_system.se_play($data_system.decision_se)
  492.             $game_temp.choice_proc.call(self.index)
  493.           end
  494.           # 清空文字
  495.           terminate_message
  496.           # 在讀取TXT的模式下,需要繼續打開文字
  497.           if @is_read_txt
  498.             # 根據顯示模式確定需要打開行數
  499.             case $game_variables[101]
  500.             when 0 # 正常模式
  501.               $game_temp.message_text =  @ts.get_text(4)
  502.             when 1 # 圖書模式
  503.               $game_temp.message_text =  @ts.get_text(12)
  504.             when 2 # 全螢幕模式
  505.               $game_temp.message_text =  @ts.get_text(15)
  506.             end
  507.             # 如果包含[END]則退出TXT讀取模式
  508.             if $game_temp.message_text.gsub!(/\[END\]/){""}!=nil
  509.               @is_read_txt=false
  510.             end
  511.           end
  512.         end
  513.       end
  514.       return
  515.     end
  516.     # 在漸變以外的狀態下有等待顯示的信息與選擇項的場合
  517.     if @fade_out == false and !($game_temp.message_text == nil or $game_temp.message_text == "")
  518.       @contents_showing = true
  519.       $game_temp.message_window_showing = true
  520.       reset_window
  521.       refresh
  522.       Graphics.frame_reset
  523.       # 當不跳過對話時才進行淡入操作
  524.       if !@skip
  525.         self.visible = true
  526.         self.contents_opacity = 0
  527.         if @input_number_window != nil
  528.           @input_number_window.contents_opacity = 0
  529.         end
  530.         @fade_in = true
  531.       end
  532.       return
  533.     end
  534.     # 沒有可以顯示的信息,但是窗口為可見的情況下
  535.     if self.visible
  536.       @fade_out = true
  537.       self.opacity -= 48
  538.       if self.opacity == 0
  539.         self.visible = false
  540.         @fade_out = false
  541.         $game_temp.message_window_showing = false
  542.       end
  543.       return
  544.     end
  545.   end
  546.   #--------------------------------------------------------------------------
  547.   # ● 刷新光標矩形
  548.   #--------------------------------------------------------------------------
  549.   def update_cursor_rect
  550.     if @index >= 0
  551.       n = $game_temp.choice_start + @index
  552.       self.cursor_rect.set(8,n * 32,@cursor_width,32)
  553.     else
  554.       self.cursor_rect.empty
  555.     end
  556.   end
  557.   #--------------------------------------------------------------------------
  558.   # ● 設定字體大小
  559.   #--------------------------------------------------------------------------
  560.   def set_font_size(size=20)
  561.     # 最大字96號,再大就超過文字欄了,而且Ruby本來有限制……
  562.     if size>96
  563.       size=96
  564.     end
  565.     # 設定字的大小
  566.     self.contents.font.size = size
  567.     # 如果字太大了就要加高每行文字高度。
  568.     if size > 28
  569.       @height=size+4
  570.     else
  571.       @height=32
  572.     end
  573.   end
  574.   #--------------------------------------------------------------------------
  575.   # ● 設定文字透明
  576.   #--------------------------------------------------------------------------
  577.   def set_font_op(op=255)
  578.     # 限制透明度為0-255
  579.     if op>255
  580.       op=255
  581.     elsif op<0
  582.       op=0
  583.     end
  584.     # 這裡設定文字透明是沒有用的,設定透明在update過程開始
  585.     @op = op
  586.   end
  587.   #--------------------------------------------------------------------------
  588.   # ● 顯示文字/頭像過程
  589.   #--------------------------------------------------------------------------
  590.   def refresh_
  591.     # 處理已經結束的情況下直接return
  592.     if @finish
  593.       return
  594.     end
  595.     # 延時處理
  596.     @delay-=1
  597.     if @delay<=0
  598.       # 每次處理i個標誌,這裡i就設置為@type_mode了
  599.       i=@type_mode
  600.       # c 獲取 1 個字 (如果不能取得文字就循環)
  601.       while ((c = @text.slice!(/./m)) != nil)
  602.         # \\ 的情況下
  603.         if c == "\000"
  604.           # 還原為本來的文字
  605.           c = "\\"
  606.         end
  607.         # \C[n] 的情況下
  608.         if c == "\001"
  609.           # 取得字色編碼
  610.           @text.sub!(/\[([0-9#a-zA-Z]+)\]/,"")
  611.           # 如果是設定RGB顏色
  612.           if $1[0,1]=="#"
  613.             # 先拷貝一下文字
  614.             c=$1.dup
  615.             # 分3段分別取出R,G,B顏色
  616.             c.sub!(/#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})/,"")
  617.             # 設定文字顏色
  618.             self.contents.font.color = Color.new($1.to_i(16),$2.to_i(16),$3.to_i(16),@op)
  619.             next
  620.           else
  621.             # 記錄到變量 color
  622.             color = $1.to_i
  623.             # 字色0~7是有效的
  624.             if color >= 0 and color <= 7
  625.               # 設置文字顏色
  626.               self.contents.font.color = text_color(color)
  627.             end
  628.           end
  629.           # 進行下次循環
  630.           next
  631.         end
  632.         # 顯示金錢窗口,這個……不用說了吧……
  633.         if c == "\002"
  634.           if @gold_window == nil
  635.             @gold_window = Window_Gold.new
  636.             @gold_window.x = 560 - @gold_window.width
  637.             if $game_temp.in_battle
  638.               @gold_window.y = 192
  639.             else
  640.               @gold_window.y = self.y >= 128 ? 32 : 384
  641.             end
  642.             @gold_window.opacity = self.opacity
  643.             @gold_window.back_opacity = self.back_opacity
  644.           end
  645.           next
  646.         end
  647.         # 另起一行文字的情況下
  648.         if c == "\n"
  649.           # 刷新選擇項及光標的高
  650.           if @y >= $game_temp.choice_start
  651.             @cursor_width = [@cursor_width,@x>440 ? 448 : @x+8].max
  652.           end
  653.           # y 加 1
  654.           @y += 1
  655.           # 因為字體大小會變化,這裡添加判斷語句,超出就不顯示了
  656.           if @y>=self.contents.height/@height
  657.             # 刪除@text剩餘的所有內容
  658.             @text=nil
  659.             # 然後返回
  660.             break
  661.           end
  662.           # 因為頭像的緣故,這裡需要改寫
  663.           if @right
  664.             # 頭像右邊顯示的時候是0
  665.             @x=0
  666.           else
  667.             # 頭像靠左顯示時@x要留出繪製頭像空間
  668.             @x=104
  669.           end
  670.           # 移動到選擇項的下一行
  671.           if @y >= $game_temp.choice_start
  672.             @x=16
  673.           end
  674.           # 下面的文字
  675.           next
  676.         end

  677.         # 等待n畫格
  678.         if c == "\024"
  679.           # 取得參數(需要等待多少畫格)
  680.           @text.sub!(/\[([0-9]+)\]/,"")
  681.           # 設定@delay標誌
  682.           @delay = $1.to_i
  683.           # 退出此次循環
  684.           break
  685.         end
  686.         
  687.         # 顯示頭像
  688.         if c == "\030"
  689.           #暫時記錄文字大小,用於顯示完頭像恢復
  690.           size=self.contents.font.size
  691.           # 設定為正常的20號字
  692.           self.contents.font.size=20
  693.           # 設定系統字色,為寫名字做準備的
  694.           self.contents.font.color = system_color
  695.           # 取得"[]"內的字符並從原字串中刪除這一部分
  696.           @text.sub!(/\[([0-9]+)\]/,"")
  697.           # 記錄到head變量
  698.           head=$1
  699.           # 判斷頭像和原來的是不是一樣的
  700.           if @face == nil
  701.             # 不一樣
  702.             if @head_file != head
  703.               # 改變成現在的頭像檔案名
  704.               @head_file = head
  705.               # 不一樣的話再重新載入頭像
  706.               @head_bmp=RPG::Cache.character("head/gpra_"+@head_file,0)
  707.             end
  708.           else
  709.             # 當表情不是空的時候需要考慮表情的
  710.             if @head_file != head + "_" + @face
  711.               # 改變成現在的頭像檔案名
  712.               @head_file = head + "_" + @face
  713.               # 不一樣的話再重新載入頭像
  714.               @head_bmp=RPG::Cache.character("head/gpra_"+@head_file,0)
  715.             end
  716.           end
  717.           # 顯示頭像,分左右兩種情況
  718.           if @right
  719.             # 繪製頭像圖片
  720.             self.contents.blt(348,0,@head_bmp,Rect.new(0,0,100,100))
  721.             # 顯示角色姓名
  722.             if @name==nil
  723.               # 取得角色姓名到變量 c
  724.               c = $game_actors[head.to_i].name
  725.               # 描繪角色的姓名
  726.               self.contents.draw_text(348,104,100,24,c,1)
  727.             else
  728.               # 取得"???"到變量 c,當然這個"???"可以改為其他的預設值
  729.               c = @name
  730.               # 描繪角色的姓名
  731.               self.contents.draw_text(348,104,100,24,c,1)
  732.             end
  733.           else
  734.             # 繪製頭像圖片
  735.             self.contents.blt(0,0,@head_bmp,Rect.new(0,0,100,100))
  736.             # 顯示角色姓名
  737.             if @name==nil
  738.               # 取得角色姓名到變量 c
  739.               c = $game_actors[head.to_i].name
  740.               # 描繪角色的姓名
  741.               self.contents.draw_text(0,104,100,24,c,1)
  742.             else
  743.               # 取得"???"到變量 c,當然這個"???"可以改為其他的預設值
  744.               c = @name
  745.               # 描繪角色的姓名
  746.               self.contents.draw_text(0,104,100,24,c,1)
  747.             end
  748.           end
  749.           # 恢復預設字色
  750.           self.contents.font.color = normal_color
  751.           # 恢復字體大小
  752.           self.contents.font.size=size
  753.           # 進行下一次循環
  754.           next
  755.         end
  756.         # 描繪文字
  757.         self.contents.draw_text(4+@x,@height*@y,@height,@height,c)
  758.         # x 為描繪文字寬度進行自增運算,計算下一個文字起始位置
  759.         @x += self.contents.text_size(c).width
  760.         
  761.         # 操作了@type_mode個字符後就退出循環了,@type_mode為負則操作一次完成
  762.         i-=1
  763.         if i==0
  764.           break
  765.         end
  766.       
  767.       end
  768.     end
  769.     # 如果@text處理結束了,就設置結束標誌
  770.     if @text==nil or @text==""
  771.       @finish=true
  772.     end
  773.   end
  774. #==============================================================================
  775. # ■ Window_Frame (樺だけで中身の無いウィンドウ)
  776. #==============================================================================
  777. class Window_Frame < Window_Base
  778.   #--------------------------------------------------------------------------
  779.   # ● オブジェクト初期化
  780.   #--------------------------------------------------------------------------
  781.   def initialize(x,y,width,height)
  782.     super(x,y,width,height)
  783.     self.contents = nil
  784.     self.back_opacity =200
  785.   end
  786.   #--------------------------------------------------------------------------
  787.   # ● 解放
  788.   #--------------------------------------------------------------------------
  789.   def dispose
  790.     super
  791.     end
  792.   end
  793. #==============================================================================
  794. # ■ Air_Text (何も無いところに文字描寫 = 樺の無い瞬間表示メッセージウィンドウ)
  795. #==============================================================================
  796. class Air_Text < Window_Base
  797.   #--------------------------------------------------------------------------
  798.   # ● オブジェクト初期化
  799.   #--------------------------------------------------------------------------
  800.   def initialize(x,y,designate_text)
  801.     super(x-16,y-16,32 + designate_text.size * 12,56)
  802.     self.opacity = 0
  803.     self.back_opacity = 0
  804.     self.contents = Bitmap.new(self.width - 32,self.height - 32)
  805.     w = self.contents.width
  806.     h = self.contents.height
  807.     self.contents.draw_text(0,0,w,h,designate_text)
  808.   end
  809.   #--------------------------------------------------------------------------
  810.   # ● 解放
  811.   #--------------------------------------------------------------------------
  812.   def dispose
  813.     self.contents.clear
  814.     super
  815.     end
  816.   end
  817. end
复制代码

本贴由论坛斑竹叶舞枫结贴,如楼主认为问题未解决,请重新将此贴编辑为“有事请教”,并回帖叙述疑点即可~ ^-^
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2025-9-21 06:09

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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