Project1

标题: EngShun 的便民任务界面 窗口大小修改问题 [打印本页]

作者: gkl0510    时间: 2015-10-28 10:53
标题: EngShun 的便民任务界面 窗口大小修改问题

看到技术区的EngShun大神的便民任务界面用注释来添加觉得这个创意很好,想挪用到自己的游戏。
但是窗口的大小不同,其他的窗口都略作了调改,就右侧的文本输入窗口的大小不知道在哪里修改
应该是个小问题,但是难倒脚本盲啊
求指点




RUBY 代码复制
  1. #==============================================================================#
  2. #                          便民任务界面 by EngShun                             #
  3. #                                                                              #
  4. #    设置方法请参考范例                                                        #
  5. #                                                                              #
  6. #    效果说明:                                                                #
  7. #    支持普通对话框效果                                                        #
  8. #    \a[号码]     :更改左右对齐方式(0,1,2)。                                 #
  9. #    \va[号码]    :更改垂直对齐方式(0,1,2)。                                 #
  10. #    \itm[物品id] :物品数量                                                    #
  11. #    \wpn[武器id] :武器数量                                                    #
  12. #    \amr[防具id] :防具数量                                                    #
  13. #    \eval{脚本}  :运行脚本                                                    #
  14. #    \1line{内容} :把多行的内容显示为一行                                      #
  15. #    \bold        :字体加粗,插入多一次关闭                                    #
  16. #    \italic      :字体打斜,插入多一次关闭                                    #
  17. #    \f[字体名称] :更改字体                                                    #
  18. #    \s[号码]     :更改字体大小                                                #
  19. #    \p[名称]     :插入图片                                                    #
  20. #    \icon[名称]  :插入图标                                                    #
  21. #                                                                              #
  22. #==============================================================================#
  23.  
  24. #===============================================================================
  25. # ■ 队伍
  26. #===============================================================================
  27. class Game_Party
  28.   Mission = Struct.new(:id, :name, :info, :status)
  29.   alias org_init_mission initialize if !defined?(org_init_mission)
  30.   #--------------------------------------------------------------------------
  31.   # ● 重定义初始化对象
  32.   #--------------------------------------------------------------------------
  33.   def initialize
  34.     @mission = {}
  35.     org_init_mission
  36.   end
  37.   def no_mission?
  38.     return @mission == {}
  39.   end
  40.   def missions
  41.     if no_mission?
  42.       m = Mission.new(0,"没有错题","\n\n\n\\a[1]\\s[32]你还没有任何错题记录",0)
  43.       return [m]
  44.     end
  45.     return @mission.values.sort_by {|m|m.id}
  46.   end
  47.   def get_mission(mission,info)
  48.     return if @mission.has_key?(mission)
  49.     id = missions[-1].id + 1
  50.     @mission[mission] = Mission.new(id,mission,info,0)
  51.   end
  52.   def done_mission(mission)
  53.     @mission[mission].status = 1 if @mission[mission].status == 0
  54.   end
  55.   def delete_mission(mission)
  56.     @mission.delete(mission)
  57.   end
  58.   def fail_mission(mission)
  59.     @mission[mission].status = 2 if @mission[mission].status == 0
  60.   end
  61.   def resume_mission(mission)
  62.     @mission[mission].status = 0 if @mission[mission].status == 2
  63.   end
  64.   def done_all_mission
  65.     @mission.each{|k,m|m.status = 1}
  66.   end
  67.   def update_mission(mission,info)
  68.     @mission[mission].info = info
  69.   end
  70.   def add_mission_info(mission,info)
  71.     @mission[mission].info += "\n" + info
  72.   end
  73.   def delete_all_mission
  74.     @mission = {}
  75.   end
  76.   def resume_all_mission
  77.     @mission.each{|k,m|m.status = 0 if m.status == 2}
  78.   end
  79. end
  80.  
  81. #===============================================================================
  82. # ■ 任务列表窗口
  83. #===============================================================================
  84. class Window_Mission < Window_Selectable
  85.   #--------------------------------------------------------------------------
  86.   # ● 初始化对象
  87.   #--------------------------------------------------------------------------
  88.   def initialize
  89.     super(0, 64, 165, 416)
  90.     self.index = 0
  91.     @mission = $game_party.missions
  92.     @item_max = @mission.size
  93.     if self.contents != nil
  94.       self.contents.dispose
  95.       self.contents = nil
  96.     end
  97.     self.contents = Bitmap.new(width - 32, @item_max * 32)
  98.     for i in [email]0...@mission.size[/email]
  99.       t = @mission[i].status != 0
  100.       self.contents.font.color = t ? disabled_color : normal_color
  101.       text = @mission[i].name
  102.       self.contents.draw_text(4, i * 32, 160, 32, text.to_s)
  103.       self.contents.font.color = system_color
  104.       self.contents.draw_text(self.contents.width-32, i * 32, 32, 32, "",1) unless $game_party.no_mission?
  105.       if @mission[i].status == 1
  106.         self.contents.font.color = crisis_color
  107.         self.contents.draw_text(self.contents.width-32, i * 32, 32, 32, "√",1)
  108.       elsif @mission[i].status == 2
  109.         self.contents.font.color = knockout_color
  110.         self.contents.draw_text(self.contents.width-32, i * 32, 32, 32, "×",1)
  111.       end
  112.     end
  113.   end
  114. end
  115.  
  116. #===============================================================================
  117. # ■ 任务详情窗口
  118. #===============================================================================
  119. class Window_MissionInfo < Window_Base
  120.   attr_accessor :wait
  121.   attr_accessor :scroll_up
  122.   #--------------------------------------------------------------------------
  123.   # ● 初始化对象
  124.   #--------------------------------------------------------------------------
  125.   def initialize
  126.     super(165,64,475,416)
  127.     self.contents =  Bitmap.new(408, 384)
  128.     @scroll_up = false
  129.     @wait = 90
  130.   end
  131.   #--------------------------------------------------------------------------
  132.   # ● 刷新画面
  133.   #--------------------------------------------------------------------------
  134.   def update
  135.     super
  136.     return if self.contents.height <= 384
  137.     return @wait -= 1 if @wait > 0
  138.     self.oy += @scroll_up ? -1 : 1
  139.     self.oy = 0 if self.oy < 0
  140.     self.oy = oy_max if self.oy > oy_max
  141.     if self.oy <= 0
  142.       @scroll_up = false
  143.       @wait = 60
  144.     elsif self.oy >= oy_max
  145.       @scroll_up = true
  146.       @wait = 60
  147.     end
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # ● 滚动最大值
  151.   #--------------------------------------------------------------------------
  152.   def oy_max
  153.     return self.contents.height - 384
  154.   end
  155.   #--------------------------------------------------------------------------
  156.   # ● 刷新
  157.   #--------------------------------------------------------------------------
  158.   def refresh(str)
  159.     str = str.clone
  160.     @scroll_up = false
  161.     @wait = 120
  162.     @ver_align = 1
  163.     self.oy = 0
  164.     bitmap_height = 0
  165.     align = 0
  166.     begin
  167.       last_text = str.clone
  168.       str.gsub!(/\\v\[(\d+)\]/i) { $game_variables[$1.to_i] }
  169.       str.gsub!(/\\g/i) { $game_party.gold.to_s }
  170.       str.gsub!(/\\itm\[(\d+)\]/i) { $game_party.item_number($1.to_i) }
  171.       str.gsub!(/\\wpn\[(\d+)\]/i) { $game_party.weapon_number($1.to_i) }
  172.       str.gsub!(/\\amr\[(\d+)\]/i) { $game_party.armor_number($1.to_i) }
  173.       str.gsub!(/\\1line{(.+?)}/im) { $1.delete("\n") }
  174.       str.gsub!(/\\eval{(.+?)}/im) { eval($1) }
  175.     end until str == last_text
  176.       str.gsub!(/\\n\[(\d+)\]/i) do
  177.       $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  178.     end
  179.     lines = str.split("\n")
  180.     bitmaps = []
  181.     lines.each do |line|
  182.       bitmap,align = bitmap_line(line,align)
  183.       w = bitmap.width
  184.       h = bitmap.height
  185.       bitmap2 = Bitmap.new(408,h)
  186.       case align
  187.       when 0
  188.         x = 4
  189.       when 1
  190.         x = 204 - w / 2
  191.       when 2
  192.         x = 404 - w
  193.       end
  194.       bitmap_height += h
  195.       bitmap2.blt(x,0,bitmap,Rect.new(0,0,w,h))
  196.       bitmaps.push(bitmap2)
  197.     end
  198.     self.contents.dispose
  199.     self.contents = Bitmap.new(408, bitmap_height < 384 ? 384 : bitmap_height)
  200.     y = 0
  201.     bitmaps.each do |bitmap|
  202.       self.contents.blt(0,y,bitmap,Rect.new(0,0,408,bitmap.height))
  203.       y += bitmap.height
  204.     end
  205.   end
  206.   #--------------------------------------------------------------------------
  207.   # ● 描绘内容
  208.   #--------------------------------------------------------------------------
  209.   def bitmap_line(str,old_align)
  210.     w,h = get_wh(str.clone)
  211.     w = 1 if w == 0
  212.     bitmap = Bitmap.new(w,h)
  213.     text = str
  214.     align = old_align
  215.     x = 0
  216.     text.gsub!(/\\\\/) { "\000" }
  217.     text.gsub!(/\\a\[([0-2])\]/i){ align = $1.to_i; "" }
  218.     text.gsub!(/\\va\[([0-2])\]/i) { "\005[#{$1}]" }
  219.     text.gsub!(/\\c\[(\d+)\]/i) { "\001[#{$1}]" }
  220.     text.gsub!(/\\bold/i) { "\002" }
  221.     text.gsub!(/\\italic/i) { "\003" }
  222.     text.gsub!(/\\f\[(\w+)\]/i) { "\004[#{$1}]" }
  223.     text.gsub!(/\\s\[(\d+)\]/i) { "\006[#{$1}]" }
  224.     text.gsub!(/\\p\[(.+?)\]/i) { "\007[#{$1}]" }
  225.     text.gsub!(/\\icon\[(.+?)\]/i){ "\201[#{$1}]" }
  226.     while ((c = text.slice!(/./)) != nil)
  227.       if c == "\000"
  228.         c = "\\"
  229.       end
  230.       if c == "\001"
  231.         text.sub!(/\[(\d+)\]/, "")
  232.         color = $1.to_i
  233.         if color >= 0 and color <= 9
  234.           bitmap.font.color = text_color(color)
  235.         elsif color == 8
  236.           bitmap.font.color = disabled_color
  237.         elsif color == 9
  238.           bitmap.font.color = system_color
  239.         end
  240.         next
  241.       end
  242.       if c == "\002"
  243.         bitmap.font.bold = !bitmap.font.bold
  244.         next
  245.       end
  246.       if c == "\003"
  247.         bitmap.font.italic = !bitmap.font.italic
  248.         next
  249.       end
  250.       if c == "\004"
  251.         text.sub!(/\[(\w+)\]/,"")
  252.         bitmap.font.name = $1
  253.         next
  254.       end
  255.       if c == "\005"
  256.         text.sub!(/\[([0-2])\]/,"")
  257.         @ver_align = $1.to_i
  258.         next
  259.       end
  260.       if c == "\006"
  261.         text.sub!(/\[(\d+)\]/,"")
  262.         bitmap.font.size = $1.to_i
  263.         next
  264.       end
  265.       if c == "\007" or c == "\201"
  266.         text.sub!(/\[(.+?)\]/,"")
  267.         pic = c == "\007" ? RPG::Cache.picture($1) : pic = RPG::Cache.icon($1)
  268.         r = Rect.new(0,0,pic.width,pic.height)
  269.         y = h / 2 - pic.height / 2
  270.         y = 2 if @ver_align == 0
  271.         y = (h - pic.height - 2) if @ver_align == 2
  272.         bitmap.blt(x+2,y,pic,r)
  273.         x += pic.width + 4
  274.         next
  275.       end
  276.       dh = @ver_align != 1 ? bitmap.text_size(c).height : h
  277.       y = @ver_align == 2  ? h - dh - 2 : 2
  278.       y = 0 if @ver_align == 1
  279.       bitmap.draw_text(x,y,w,dh,c)
  280.       x += bitmap.text_size(c).width
  281.     end
  282.     return bitmap.clone,align
  283.   end
  284.   #--------------------------------------------------------------------------
  285.   # ● 计算高与宽
  286.   #--------------------------------------------------------------------------
  287.   def get_wh(str)
  288.     bitmap = Bitmap.new(160,160)
  289.     w = 0
  290.     h = 32
  291.     text = str
  292.     text.gsub!(/\\\\/) { "\000" }
  293.     text.gsub!(/\\a\[([0-2])\]/i) { "" }
  294.     text.gsub!(/\\c\[(\d+)\]/i) { "" }
  295.     text.gsub!(/\\bold/i) { "" }
  296.     text.gsub!(/\\italic/i) { "" }
  297.     text.gsub!(/\\f\[(\w+)\]/i) { "\001[#{$1}]" }
  298.     text.gsub!(/\\s\[(\d+)\]/i) { "\002[#{$1}]" }
  299.     text.gsub!(/\\p\[(.+?)\]/i) { "\003[#{$1}]" }
  300.     text.gsub!(/\\icon\[(.+?)\]/i) { "\004[#{$1}]" }
  301.     while ((c = text.slice!(/./)) != nil)
  302.       if c == "\000"
  303.         c = "\\"
  304.       end
  305.       if c == "\001"
  306.         text.sub!(/\[(\w+)]/,"")
  307.         bitmap.font.name = $1
  308.         next
  309.       end
  310.       if c == "\002"
  311.         text.sub!(/\[(\d+)]/,"")
  312.         bitmap.font.size = $1.to_i
  313.         next
  314.       end
  315.       if c == "\003" or c == "\004"
  316.         text.sub!(/\[(.+?)\]/,"")
  317.         pic = c == "\003" ? RPG::Cache.picture($1) : pic = RPG::Cache.icon($1)
  318.         w += pic.width + 4
  319.         h = pic.height + 4 if pic.height + 4 > h
  320.         next
  321.       end
  322.       w += bitmap.text_size(c).width
  323.       h = bitmap.text_size(c).height + 4 if bitmap.text_size(c).height + 4 > h
  324.     end
  325.     h = h < 32 ? 32 : h
  326.     return w,h
  327.   end
  328. end
  329.  
  330. #===============================================================================
  331. # ■ 任务界面
  332. #===============================================================================
  333. class Scene_Mission
  334.   #--------------------------------------------------------------------------
  335.   # ● 初始化
  336.   #--------------------------------------------------------------------------
  337.   def initialize
  338.     @last_scene = $scene
  339.   end
  340.   #--------------------------------------------------------------------------
  341.   # ● 主处理
  342.   #--------------------------------------------------------------------------
  343.   def main
  344.     @mission = $game_party.missions
  345.     @window1 = Window_Base.new(0,0,165,64)
  346.     @window1.contents = Bitmap.new(168,32)
  347.     @window1.contents.draw_text(0,0,140,32,"错题",1)
  348.     @window2 = Window_Base.new(165,0,475,64)
  349.     @window2.contents = Bitmap.new(408,32)
  350.     @window2.contents.draw_text(0,0,458,32,"错题说明",1)
  351.     @mission_window = Window_Mission.new
  352.     @mission_window.index = @mission.size - 1
  353.     @index = @mission_window.index
  354.     @info_window = Window_MissionInfo.new
  355.     @info_window.refresh(@mission[@index].info)
  356.     Graphics.transition
  357.     loop do
  358.       Graphics.update
  359.       Input.update
  360.       update
  361.       if $scene != self
  362.         break
  363.       end
  364.     end
  365.     Graphics.freeze
  366.     @window1.dispose
  367.     @window2.dispose
  368.     @mission_window.dispose
  369.     @info_window.dispose
  370.   end
  371.   #--------------------------------------------------------------------------
  372.   # ● 刷新画面
  373.   #--------------------------------------------------------------------------
  374.   def update
  375.     @mission_window.update
  376.     @info_window.update
  377.     if @index != @mission_window.index
  378.       @index = @mission_window.index
  379.       @info_window.refresh(@mission[@index].info)
  380.     end
  381.     return update_mission if @mission_window.active
  382.     update_info
  383.   end
  384.   #--------------------------------------------------------------------------
  385.   # ● 刷新任务
  386.   #--------------------------------------------------------------------------
  387.   def update_mission
  388.     if Input.trigger?(Input::C)
  389.       $game_system.se_play($data_system.decision_se)
  390.       @mission_window.active = false
  391.       @info_window.oy = 0
  392.     elsif Input.trigger?(Input::B)
  393.       $game_system.se_play($data_system.cancel_se)
  394.       $scene = @last_scene
  395.       return
  396.     end
  397.   end
  398.   #--------------------------------------------------------------------------
  399.   # ● 刷新人物详情
  400.   #--------------------------------------------------------------------------
  401.   def update_info
  402.     @info_window.wait = 90
  403.     if Input.press?(Input::UP)
  404.       @info_window.oy -= 3
  405.       @info_window.oy = 0 if @info_window.oy < 0
  406.     elsif Input.press?(Input::DOWN)
  407.       @info_window.oy += 3
  408.       @info_window.oy = @info_window.oy_max if @info_window.oy > @info_window.oy_max
  409.     elsif Input.repeat?(Input::L)
  410.       $game_system.se_play($data_system.cursor_se)
  411.       @mission_window.index -= 1
  412.       @mission_window.index = $game_party.mission.size - 1 if @mission_window.index < 0
  413.     elsif Input.repeat?(Input::R)
  414.       $game_system.se_play($data_system.cursor_se)
  415.       @mission_window.index += 1
  416.       @mission_window.index = 0 if @mission_window.index >= $game_party.mission.size
  417.     elsif Input.trigger?(Input::B)
  418.       $game_system.se_play($data_system.cancel_se)
  419.       @mission_window.active = true
  420.       @info_window.scroll_up = false
  421.       @info_window.oy = 0
  422.     end
  423.   end
  424. end
  425.  
  426. #===============================================================================
  427. # ■ 事件处理器
  428. #===============================================================================
  429. class Interpreter
  430.   alias orig_ec_mission execute_command if !defined?(orig_ec_mission)
  431.   #--------------------------------------------------------------------------
  432.   # ● 重定义执行事件命令
  433.   #--------------------------------------------------------------------------
  434.   def execute_command
  435.     if @index >= @list.size - 1
  436.       command_end
  437.       return true
  438.     end
  439.     @parameters = @list[@index].parameters
  440.     return command_108 if @list[@index].code == 108
  441.     return orig_ec_mission
  442.   end
  443.   #--------------------------------------------------------------------------
  444.   # ● 注释
  445.   #--------------------------------------------------------------------------
  446.   def command_108
  447.     case @list[@index].parameters[0]
  448.     when (/^删除错题\[(\w+)\]$/)
  449.       $game_party.delete_mission($1)
  450.       return true
  451.     when (/^完成错题\[(\w+)\]$/)
  452.       $game_party.done_mission($1)
  453.       return true
  454.     when "删除所有错题"
  455.       $game_party.delete_all_mission
  456.       return true
  457.     when "完成所有错题"
  458.       $game_party.done_all_mission
  459.       return true
  460.     when (/^放弃错题\[(\w+)\]$/)
  461.       $game_party.fail_mission($1)
  462.       return true
  463.     when (/^恢复错题\[(\w+)\]$/)
  464.       $game_party.resume_mission($1)
  465.       return true
  466.     when "恢复所有错题"
  467.       $game_party.resume_all_mission
  468.       return true
  469.     end
  470.     text = @list[@index].parameters[0]
  471.     loop do
  472.       if @list[@index+1].code == 108 or @list[@index+1].code == 408
  473.         text += "\n" + @list[@index+1].parameters[0]
  474.       else
  475.         break
  476.       end
  477.       @index += 1
  478.     end
  479.     split = text.split("\n")
  480.     if (split[0] == "错题设置" or split[0] == "错题更新" or split[0] == "错题说明") and split.size >= 3
  481.       info , name = split[2] , split[1]
  482.       if split.size >= 4
  483.         for i in 3...split.size
  484.           info += "\n" + split[i]
  485.         end
  486.       end
  487.       $game_party.get_mission(name,info) if split[0] == "错题设置"
  488.       $game_party.update_mission(name,info) if split[0] == "错题更新"
  489.       $game_party.add_mission_info(name,info) if split[0] == "追加说明"
  490.     end
  491.     return true
  492.   end
  493. end

作者: 夜狠简单    时间: 2015-10-28 14:18
是不是字体大小大了些
作者: 英顺的马甲    时间: 2015-10-28 23:25
你用的不是最新版本,最新版本有自动换行
作者: 孤云黑月    时间: 2015-10-29 09:13
126行括号里面的数字改一下就行了




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