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

Project1

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

[已经解决] 增强型对话框

[复制链接]

Lv1.梦旅人

梦石
0
星屑
239
在线时间
26 小时
注册时间
2018-12-25
帖子
18
跳转到指定楼层
1
发表于 2019-4-12 22:32:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
请教一下各位高手如何实现增强型对话框文字居中

Lv4.逐梦者

梦石
0
星屑
14048
在线时间
2070 小时
注册时间
2016-9-20
帖子
844
2
发表于 2019-4-13 13:19:08 | 只看该作者
不知你說哪款增强型对话框腳本, 我这款自帶这个功能
  1. #\a[n] : n帧之后自动关闭对话框
  2. #\b: Banner mode. 文字将显示在对话框的正中间(横竖都是中间)。不能与其他类似功能同用(柳柳按:

  3. 没什么用处的功能,中文不需要这么排版)
  4. #\c[n] 改变为第n种颜色. 使用\d或者\c[0]回复正常颜色。
  5. #\d: 回复默认字体、大小、颜色、高度。
  6. #\f[n] : 改变为第n种字体,使用\d回复默认字体。
  7. #\g : 显示金钱窗口
  8. #\h[n] : 改变文字的字沉高度,使用\d或\h[32]回复默认状态(柳柳按:这个功能没什么用处)
  9. #\j[n] : 显示n象素的空白(柳柳按:对于中文而言无用的功能)
  10. #\i[n] : 显示第n号物品的图标和名称
  11. #\k[n] : 显示第n号特技的图标和名称.
  12. #\m[n] : 显示第n号防具的图标和名称.
  13. #\w[n] : 显示第n号武器的图标和名称.
  14. #\n[n] : 显示第n号英雄名称(柳柳按:就是默认功能).
  15. #\o[n] : 更改文字的透明度为n.
  16. #\r: 右对齐(柳柳按:比较不实用).  
  17. #\s[n] : 更改字体大小(柳柳按:不要改得太大,否则会出格,会变丑的^__^).
  18. #\v[n] : 显示第n号变量的数值.
  19. #\x: 居中对齐,必须在一行的开头用(柳柳按:比较不实用。其实这些排版功能不如打几个空格).
  20. #\\ : 显示"\"这个符号.
  21. class Window_Message < Window_Selectable
  22.   attr_accessor :autoclosetime
  23.   attr_accessor :op
  24. # ----------------------------
  25.   def initialize
  26.     super(80, 304, 480, 160)
  27.     self.contents = Bitmap.new(width - 32, height - 32)
  28.     self.visible = false
  29.     self.z = 9998
  30.     @fade_in = false
  31.     @fade_out = false
  32.     @contents_showing = false
  33.     @cursor_width = 0
  34.     @autoclosetime = -1
  35.     @op = 255
  36.     @refreshflag = false
  37.     self.active = false
  38.     self.index = -1
  39.   end
  40. # ----------------------------
  41.   def dispose
  42.     terminate_message
  43.     $game_temp.message_window_showing = false
  44.     if @input_number_window != nil
  45.       @input_number_window.dispose
  46.     end
  47.     super
  48.   end
  49. # ----------------------------
  50.   def terminate_message
  51.     self.active = false
  52.     self.pause = false
  53.     self.inde = -1
  54.     self.contents.clear
  55.     @contents_showing = false
  56.     if $game_temp.message_proc != nil
  57.       $game_temp.message_proc.call
  58.     end
  59.     $game_temp.message_text = nil
  60.     $game_temp.message_proc = nil
  61.     $game_temp.choice_start = 99
  62.     $game_temp.choice_max = 0
  63.     $game_temp.choice_cancel_type = 0
  64.     $game_temp.choice_proc = nil
  65.     $game_temp.num_input_start = 99
  66.     $game_temp.num_input_variable_id = 0
  67.     $game_temp.num_input_digits_max = 0
  68.     if @gold_window != nil
  69.       @gold_window.dispose
  70.       @gold_window = nil
  71.     end
  72.   end
  73. # ----------------------------
  74.   def refresh
  75.     self.contents.clear
  76.     self.contents.font.color = normal_color
  77.     self.contents.font.name = "宋体"
  78.     self.contents.font.size = 18
  79.     x = y = 0
  80.     @cursor_width = 0
  81.     @autoclosetime = -1
  82.     @refreshflag = true
  83.     lineheight = 32
  84.     active = ""
  85.     a = ""
  86.     centerflag = false
  87.     rightflag = false
  88.     bannerflag = false
  89.     if $game_temp.choice_start == 0
  90.       x = 8
  91.     end
  92.     if $game_temp.message_text != nil
  93.       text = $game_temp.message_text
  94.       begin
  95.       last_text = text.clone
  96.       text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  97.       end until text == last_text
  98.       text.gsub!(/\\[Nn]\[([0-9]+)\]/) do

  99.    $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  100.       end
  101.       text.gsub!(/\\\\/) { "\000" }
  102.       text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  103.       text.gsub!(/\\[Gg]/) { "\002" }
  104.       text.gsub!(/\\[Ii]\[([0-9]+)\]/) { "\003[#{$1}]" }
  105.       text.gsub!(/\\[Ff]\[([0-9]+)\]/) { "\004[#{$1}]" }
  106.       text.gsub!(/\\[Aa]\[([0-9]+)\]/) { "\005[#{$1}]" }
  107.       text.gsub!(/\\[Xx]/) { "\006" }
  108.       text.gsub!(/\\[Rr]/) { "\007" }
  109.       text.gsub!(/\\[Dd]/) { "\011" }
  110.       text.gsub!(/\\[Ss]\[([0-9]+)\]/) { "\023[#{$1}]" }
  111.       text.gsub!(/\\[Bb]/) { "\017" }
  112.       text.gsub!(/\\[Ww]\[([0-9]+)\]/) { "\014[#{$1}]" }
  113.       text.gsub!(/\\[Mm]\[([0-9]+)\]/) { "\015[#{$1}]" }
  114.       text.gsub!(/\\[Oo]\[([0-9]+)\]/) { "\016[#{$1}]" }
  115.       text.gsub!(/\\[Jj]\[([0-9]+)\]/) { "\013[#{$1}]" }
  116.       text.gsub!(/\\[Hh]\[([0-9]+)\]/) { "\021[#{$1}]" }
  117.       text.gsub!(/\\[Kk]\[([0-9]+)\]/) { "\022[#{$1}]" }
  118.       while ((c = text.slice!(/./m)) != nil)
  119.         if c == "\000"
  120.           c = "\\"
  121.         end
  122.         if c == "\001"
  123.           text.sub!(/\[([0-9]+)\]/, "")
  124.           color = $1.to_i
  125.           if color >= 0 and color <= 7
  126.             self.contents.font.color = text_color(color)
  127.           end
  128.           next
  129.         end
  130.         if c == "\002"
  131.           if @gold_window == nil
  132.             @gold_window = Window_Gold.new
  133.             @gold_window.x = 560 - @gold_window.width
  134.             if $game_temp.in_battle
  135.               @gold_window.y = 192
  136.             else
  137.               @gold_window.y = self.y >= 128 ? 32 : 384
  138.             end
  139.             @gold_window.opacity = self.opacity
  140.             @gold_window.back_opacity = self.back_opacity
  141.           end
  142.           next
  143.         end
  144.           if c == "\003"
  145.           text.sub!(/\[([0-9]+)\]/, "")
  146.           item_sub = $1.to_i
  147.           c = $data_items[item_sub].name
  148.           l = self.contents.text_size©.width
  149.           draw_item_name($data_items[item_sub], x, y * 32 + 1)
  150.           x = x + l + 24
  151.           next
  152.         end
  153.          if c == "\004"
  154.           text.sub!(/\[([0-9]+)\]/, "")
  155.           fontize = $1.to_i
  156.           case fontize
  157.             when 1  
  158.               self.contents.font.name = "黑体"
  159.             when 2  
  160.               self.contents.font.name = "宋体"
  161.             when 3  
  162.               self.contents.font.name = "隶书"
  163.             when 4  
  164.               self.contents.font.name = "幼圆"
  165.           end
  166.           next
  167.         end
  168.          if c == "\005"
  169.           text.sub!(/\[([0-9]+)\]/, "")
  170.           @autoclosetime = $1.to_i
  171.           next
  172.         end
  173.         if c == "\006"
  174.           centerflag = true
  175.           next
  176.         end
  177.         if c == "\007"
  178.           rightflag = true
  179.           next
  180.         end
  181.         if c == "\011"
  182.           self.contents.font.name = "Arial"
  183.           self.contents.font.size = 18
  184.           self.contents.font.color = normal_color
  185.           lineheight = 32
  186.           next
  187.         end
  188.         if c == "\014"
  189.           text.sub!(/\[([0-9]+)\]/, "")

  190.   w_sub = $1.to_i
  191.           c = $data_weapons[w_sub].name
  192.           l = self.contents.text_size©.width
  193.           bitmap = RPG::Cache.icon($data_weapons[w_sub].icon_name)
  194.           self.contents.blt(x+4, y * 32+ 4, bitmap, Rect.new(0, 0, 24, 24))
  195.           x += 28
  196.           self.contents.draw_text(x+4, 32 * y, l+32, lineheight, c)
  197.           x = x + l
  198.           next
  199.         end
  200.           if c == "\015"
  201.           text.sub!(/\[([0-9]+)\]/, "")
  202.           a_sub = $1.to_i
  203.           c = $data_armors[a_sub].name
  204.           l = self.contents.text_size©.width
  205.           bitmap = RPG::Cache.icon($data_armors[a_sub].icon_name)
  206.           self.contents.blt(x+4, y * 32+ 4, bitmap, Rect.new(0, 0, 24, 24))
  207.           x += 28
  208.           self.contents.draw_text(x+4, 32 * y, l+32, lineheight, c)
  209.           x = x + l
  210.           next
  211.         end
  212.           if c == "\016"
  213.           text.sub!(/\[([0-9]+)\]/, "")
  214.           @op = $1.to_i
  215.           next
  216.         end
  217.          if c == "\017"
  218.           bannerflag = true
  219.           next
  220.         end
  221.         if c == "\018"
  222.           text.sub!(/\[([0-9]+)\]/, "")
  223.           jump = $1.to_i        
  224.           x += jump
  225.           next
  226.         end
  227.           if c == "\021"
  228.           text.sub!(/\[([0-9]+)\]/, "")
  229.           lineheight = $1.to_i
  230.           next
  231.         end
  232.         if c == "\022"
  233.           text.sub!(/\[([0-9]+)\]/, "")
  234.           skill_sub = $1.to_i
  235.           c = $data_skills[skill_sub].name
  236.           l = self.contents.text_size©.width
  237.           bitmap = RPG::Cache.icon($data_skills[skill_sub].icon_name)
  238.           self.contents.blt(x+4, y * 32+ 4, bitmap, Rect.new(0, 0, 24, 24))
  239.           x += 28
  240.           self.contents.draw_text(x+4, 32 * y, l+32, lineheight, c)
  241.           x = x + l
  242.           next
  243.         end
  244.          if c == "\023"
  245.           text.sub!(/\[([0-9]+)\]/, "")
  246.           bigness = $1.to_i
  247.           self.contents.font.size = bigness
  248.           next
  249.         end
  250.         if c == "\n"
  251.           if centerflag == true
  252.             x = 448 - x
  253.             x = x / 2
  254.             self.contents.draw_text(x, 32 * y, 448-x, lineheight, a)
  255.           end
  256.           if rightflag == true
  257.             x = 448 - x
  258.             self.contents.draw_text(x, 32 * y, 448-x, lineheight, a)
  259.           end
  260.           if bannerflag == true
  261.             x = 448 - x
  262.             x = x / 2
  263.             self.contents.draw_text(x, 44, 448-x, lineheight, a)
  264.           end
  265.           a = ""
  266.           centerflag = false
  267.           rightflag = false
  268.           bannerflag = false
  269.           if y >= $game_temp.choice_start
  270.             @cursor_width = [@cursor_width, x].max
  271.           end
  272.           y += 1
  273.           x = 0
  274.           if y >= $game_temp.choice_start
  275.             x = 8
  276.           end
  277.           next
  278.         end
  279.         if centerflag == false && rightflag == false && bannerflag == false
  280.         self.contents.draw_text(4 + x, 32 * y, 40, lineheight, c)
  281.         x += self.contents.text_size©.width
  282.       else
  283.         a += c
  284.         x += self.contents.text_size©.width

  285.    end
  286.       end
  287.     end
  288.     if $game_temp.choice_max > 0
  289.       @item_max = $game_temp.choice_max
  290.       self.active = true
  291.       self.index = 0
  292.     end
  293.     if $game_temp.num_input_variable_id > 0
  294.       digits_max = $game_temp.num_input_digits_max
  295.       number = $game_variables[$game_temp.num_input_variable_id]
  296.       @input_number_window = Window_InputNumber.new(digits_max)
  297.       @input_number_window.number = number
  298.       @input_number_window.x = self.x + 8
  299.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  300.     end
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # ● 设置窗口位置与不透明度
  304.   #--------------------------------------------------------------------------
  305.   def reset_window
  306.     if $game_temp.in_battle
  307.       self.y = 16
  308.     else
  309.       case $game_system.message_position
  310.       when 0  # 上
  311.         self.y = 16
  312.       when 1  # 中
  313.         self.y = 160
  314.       when 2  # 下
  315.         case $msr
  316.         when 0
  317.           self.y = 304
  318.         when 1
  319.           self.y =  
  320.       when 999  #自制对话框
  321.         self.x=180
  322.         self.y=306
  323.         self.width = 440
  324.         self.height = 160
  325.         self.opacity=0
  326.         self.back_opacity=0
  327.         self.contents = Bitmap.new(width - 32, height - 32)
  328.       end
  329.     end
  330.     if $game_system.message_frame == 0
  331.       self.opacity = 255
  332.     else
  333.       self.opacity = 0
  334.     end
  335.     self.back_opacity = 160
  336.   end
  337. # ----------------------------   
  338.   def update
  339.     super
  340.     if @refreshflag && @fade_in == false
  341.       self.contents_opacity = @op
  342.      end
  343.     if @autoclosetime == 0
  344.     @autoclosetime = -1
  345.      terminate_message
  346.    end
  347.     if @autoclosetime >= 1
  348.     @autoclosetime -= 1
  349.     end
  350.     if @fade_in
  351.       self.contents_opacity += 24
  352.       if @input_number_window != nil
  353.         @input_number_window.contents_opacity += 24
  354.       end
  355.       if self.contents_opacity >= @op
  356.         @fade_in = false
  357.       end
  358.       return
  359.     end
  360.     if @input_number_window != nil
  361.       @input_number_window.update
  362.       if Input.trigger?(Input::C)
  363.         $game_system.se_play($data_system.decision_se)
  364.         $game_variables[$game_temp.num_input_variable_id] =
  365.           @input_number_window.number
  366.         $game_map.need_refresh = true
  367.         @input_number_window.dispose
  368.         @input_number_window = nil
  369.         terminate_message
  370.       end
  371.       return
  372.     end
  373.     if @contents_showing
  374.       if $game_temp.choice_max == 0
  375.         self.pause = true
  376.       end
  377.       if Input.trigger?(Input::B)
  378.         if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
  379.           $game_system.se_play($data_system.cancel_se)
  380.           $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  381.           terminate_message
  382.         end
  383.       end
  384.       if Input.trigger?(Input::C)
  385.         if $game_temp.choice_max > 0
  386.           $game_system.se_play($data_system.decision_se)
  387.           $game_temp.choice_proc.call(self.index)
  388.         end
  389.         @op = 255
  390.         terminate_message
  391.       end
  392.       return
  393.     end
  394.     if @fade_out == false and $game_temp.message_text != nil
  395.       @contents_showing = true
  396.       $game_temp.message_window_showing = true
  397.       reset_window
  398.       refresh
  399.       Graphics.frame_reset
  400.       self.visible = true
  401.       self.contents_opacity = 0
  402.       if @input_number_window != nil
  403.         @input_number_window.contents_opacity = 0
  404.       end
  405.       @fade_in = true
  406.       return
  407.     end
  408.     if self.visible
  409.       @fade_out = true
  410.       self.opacity -= 48
  411.       if self.opacity == 0
  412.         self.visible = false
  413.         @fade_out = false
  414.         $game_temp.message_window_showing = false
  415.       end
  416.       return
  417.     end
  418.   end
  419. # ----------------------------
  420.   def update_cursor_rect
  421.     if @index >= 0
  422.       n = $game_temp.choice_start + @index
  423.       self.cursor_rect.set(8, n * 32, @cursor_width, 32)
  424.     else
  425.       self.cursor_rect.empty
  426.     end
  427.   end
  428. end

复制代码

评分

参与人数 1星屑 +100 收起 理由
guoxiaomi + 100 认可答案

查看全部评分

内容仅供参考,
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
239
在线时间
26 小时
注册时间
2018-12-25
帖子
18
3
 楼主| 发表于 2019-4-15 07:14:10 | 只看该作者
非常感谢
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-26 03:33

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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