Project1

标题: 【强迫症】对话框加强宽度设置求救 [打印本页]

作者: 550806810    时间: 2014-10-1 12:58
标题: 【强迫症】对话框加强宽度设置求救
RUBY 代码复制
  1. #==============================================================================
  2. #
  3. # ¥ Yami Engine Ace - Pop Message
  4. # -- Last Updated: 2012.06.07
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["YSE-PopMessage"] = true
  12.  
  13. #==============================================================================
  14. # ¥ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2012.06.07 - Fixed Compatible: YEA - Ace Message System.
  17. # 2012.05.11 - Fixed Message Position.
  18. #            - Remove Requirement: YSE - Fix Events Order.
  19. # 2012.05.07 - Fixed Face position.
  20. #            - Added Requirement: YSE - Fix Events Order.
  21. # 2012.04.06 - You can change Bubble Tag filename.
  22. # 2012.03.28 - Fixed Default Message Position and Sizes.
  23. # 2012.03.27 - Fixed Default Message.
  24. # 2012.03.27 - Added Bubble Tag.
  25. # 2012.03.25 - Fixed Escape Message.
  26. # 2012.03.24 - Fixed Battle Message.
  27. # 2012.03.24 - Rewrote script.
  28. #
  29. #==============================================================================
  30. # ¥ Instructions
  31. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  32. # To install this script, open up your script editor and copy/paste this script
  33. # to an open slot below ¥ Materials/‘fÞ but above ¥ Main. Remember to save.
  34. #
  35. # -----------------------------------------------------------------------------
  36. # Message Window text Codes - These go inside of your message window.
  37. # -----------------------------------------------------------------------------
  38. #  Position:   Effect:
  39. #    \bm[0]    - 主角对话框
  40. #    \bm[x]    - X事件号对话框
  41. #    \cbm      - Cancel bubble message.
  42. #
  43. #              *Note: Set to 0 to sets position to Game Player.
  44. #
  45. #==============================================================================
  46. # ¥ Compatibility
  47. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  48. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  49. # it will run with RPG Maker VX without adjusting.
  50. #
  51. #==============================================================================
  52.  
  53. module YSE
  54.   module POP_MESSAGE
  55.  
  56.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  57.     # - Visual Settings -
  58.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  59.     LIMIT = { # Start.
  60.       :limit_width    =>  450,  # Set to 0 to disable limit.
  61.       :limit_line     =>  0,  # Set to 0 to disable limit.
  62.     } # End.
  63.  
  64.     POSITION = { # Start.
  65.       :x_buffer       =>  0,
  66.       :y_buffer       =>  -36,
  67.       :face_x_buffer  =>  8,
  68.       :face_y_buffer  =>  24,
  69.       :tag_y_buffer   =>  -6,
  70.       :name_x_buffer  =>  112, # Require YEA - Message System.
  71.     } # End.
  72.  
  73.     EFFECT = { # Start.
  74.       :fade_face       =>  true,
  75.       :move_face       =>  true,
  76.       :use_bubble_tag  =>  true,
  77.       :bubble_tag_name => "BubbleTag",
  78.     } # End.
  79.  
  80.   end
  81. end
  82.  
  83. #==============================================================================
  84. # ¥ Editting anything past this point may potentially result in causing
  85. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  86. # halitosis so edit at your own risk.
  87. #==============================================================================
  88.  
  89. #==============================================================================
  90. # ¡ Spriteset_Map
  91. #==============================================================================
  92.  
  93. class Spriteset_Map
  94.  
  95.   #--------------------------------------------------------------------------
  96.   # public instance variables
  97.   #--------------------------------------------------------------------------
  98.   attr_accessor :character_sprites
  99.  
  100. end # Spriteset_Map
  101.  
  102. #==============================================================================
  103. # ¡ Window_Message_Face
  104. #==============================================================================
  105.  
  106. class Window_Message_Face < Window_Base
  107.  
  108.   #--------------------------------------------------------------------------
  109.   # initialize
  110.   #--------------------------------------------------------------------------
  111.   def initialize
  112.     super(0, 0, 120, 120)
  113.     self.opacity = 0
  114.     @face_name = ""
  115.     @face_index = 0
  116.     @move_x = 0
  117.     close
  118.   end
  119.  
  120.   #--------------------------------------------------------------------------
  121.   # message_window=
  122.   #--------------------------------------------------------------------------
  123.   def message_window=(window)
  124.     @message_window = window
  125.   end
  126.  
  127.   #--------------------------------------------------------------------------
  128.   # set_face
  129.   #--------------------------------------------------------------------------
  130.   def set_face
  131.     contents.clear
  132.     return unless @message_window
  133.     if !$game_message.face_name.empty?
  134.       draw_face($game_message.face_name, $game_message.face_index, 0, 0)
  135.       set_position
  136.       show_face
  137.     else
  138.       hide_face
  139.     end
  140.   end
  141.  
  142.   #--------------------------------------------------------------------------
  143.   # set_position
  144.   #--------------------------------------------------------------------------
  145.   def set_position
  146.     return unless @message_window
  147.     self.x = @message_window.x
  148.     self.y = @message_window.y - 96
  149.     self.x += YSE::POP_MESSAGE::POSITION[:face_x_buffer]
  150.     self.y += YSE::POP_MESSAGE::POSITION[:face_y_buffer]
  151.     self.y += (@message_window.real_lines - 1) * 24
  152.     self.z = @message_window.z + 1
  153.     if (@face_name != $game_message.face_name || @face_index != $game_message.face_index)
  154.       if YSE::POP_MESSAGE::EFFECT[:move_face]
  155.         @move_x = 30
  156.         self.x -= 30
  157.       end
  158.       @face_name = $game_message.face_name
  159.       @face_index = $game_message.face_index
  160.       self.contents_opacity = 0 if YSE::POP_MESSAGE::EFFECT[:fade_face]
  161.     end
  162.   end
  163.  
  164.   #--------------------------------------------------------------------------
  165.   # show_face
  166.   #--------------------------------------------------------------------------
  167.   def show_face
  168.     open
  169.   end
  170.  
  171.   #--------------------------------------------------------------------------
  172.   # hide_face
  173.   #--------------------------------------------------------------------------
  174.   def hide_face
  175.     contents.clear
  176.     close
  177.   end
  178.  
  179.   #--------------------------------------------------------------------------
  180.   # update
  181.   #--------------------------------------------------------------------------
  182.   def update
  183.     super
  184.     self.contents_opacity += 15 if self.contents_opacity < 255
  185.     unless @move_x <= 0
  186.       self.x += 2
  187.       @move_x -= 2
  188.     end
  189.   end
  190.  
  191. end # Sprite_Message_Face
  192.  
  193. #==============================================================================
  194. # ¡ Window_Message
  195. #==============================================================================
  196.  
  197. class Window_Message < Window_Base
  198.  
  199.   #--------------------------------------------------------------------------
  200.   # new method: face_window=
  201.   #--------------------------------------------------------------------------
  202.   def face_window=(window)
  203.     @face_window = window
  204.   end
  205.  
  206.   #--------------------------------------------------------------------------
  207.   # new method: bubble_tag=
  208.   #--------------------------------------------------------------------------
  209.   def bubble_tag=(sprite)
  210.     @bubble_tag = sprite
  211.   end
  212.  
  213.   #--------------------------------------------------------------------------
  214.   # new method: message_escape_characters_pop_message
  215.   #--------------------------------------------------------------------------
  216.   def message_escape_characters_pop_message(result)
  217.     result.gsub!(/\eBM\[(\d+)\]/i) { event_pop_message_setup($1.to_i, false) }
  218.     result.gsub!(/\eBMF\[(\d+)\]/i) { event_pop_message_setup($1.to_i, true) }
  219.     result.gsub!(/\eCBM/i) { event_pop_message_setup(nil, false) }
  220.     result
  221.   end
  222.  
  223.   #--------------------------------------------------------------------------
  224.   # alias method: convert_escape_characters
  225.   #--------------------------------------------------------------------------
  226.   alias yse_convert_escape_characters_pm convert_escape_characters
  227.   def convert_escape_characters(text)
  228.     result = yse_convert_escape_characters_pm(text)
  229.     result = message_escape_characters_pop_message(result)
  230.     result
  231.   end
  232.  
  233.   #--------------------------------------------------------------------------
  234.   # new method: event_pop_message_setup
  235.   #--------------------------------------------------------------------------
  236.   def event_pop_message_setup(event_id, follower = false)
  237.     if follower && $game_player.followers[event_id].nil?
  238.       @event_pop_id = nil
  239.       @event_pop_follower = false
  240.       return ""
  241.     end
  242.     @event_pop_follower = follower
  243.     @event_pop_id = event_id
  244.     return ""
  245.   end
  246.  
  247.   #--------------------------------------------------------------------------
  248.   # new method: set_face_position
  249.   #--------------------------------------------------------------------------
  250.   def set_face_position
  251.     return unless SceneManager.scene_is?(Scene_Map)
  252.     return unless @event_pop_id
  253.     return unless @face_window
  254.     contents.clear
  255.     @face_window.set_face
  256.     return unless $imported["YEA-MessageSystem"]
  257.     return if @face_window.close?
  258.     #@name_window.x = self.x + YSE::POP_MESSAGE::POSITION[:face_x_buffer] + YSE::POP_MESSAGE::POSITION[:name_x_buffer] if (@name_position == 1 || @name_position == 2)
  259.   end
  260.  
  261.   #--------------------------------------------------------------------------
  262.   # alias method: new_page
  263.   #--------------------------------------------------------------------------
  264.   alias window_message_new_page_pm_yse new_page
  265.   def new_page(text, pos)
  266.     window_message_new_page_pm_yse(text, pos)
  267.     set_face_position
  268.   end
  269.  
  270.   #--------------------------------------------------------------------------
  271.   # alias method: close
  272.   #--------------------------------------------------------------------------
  273.   alias pop_message_close close
  274.   def close
  275.     pop_message_close
  276.     return unless SceneManager.scene_is?(Scene_Map)
  277.     return unless @event_pop_id
  278.     @event_pop_id = nil
  279.     @event_pop_follower = false
  280.     @face_window.hide_face
  281.     return unless YSE::POP_MESSAGE::EFFECT[:use_bubble_tag]
  282.     @bubble_tag.visible = false if @bubble_tag
  283.   end
  284.  
  285.   #--------------------------------------------------------------------------
  286.   # alias method: open_and_wait
  287.   #--------------------------------------------------------------------------
  288.   alias pop_message_open_and_wait open_and_wait
  289.   def open_and_wait
  290.     pop_message_open_and_wait
  291.     return unless YSE::POP_MESSAGE::EFFECT[:use_bubble_tag]
  292.     @bubble_tag.visible = true if @event_pop_id && @bubble_tag
  293.   end
  294.  
  295.   #--------------------------------------------------------------------------
  296.   # alias method: process_all_text
  297.   #--------------------------------------------------------------------------
  298.   alias pop_message_process_all_text process_all_text
  299.   def process_all_text
  300.     @event_pop_id = nil
  301.     convert_escape_characters($game_message.all_text)
  302.     update_placement
  303.     adjust_pop_message($game_message.all_text)
  304.     pop_message_process_all_text
  305.   end
  306.  
  307.   #--------------------------------------------------------------------------
  308.   # alias method: update_placement
  309.   #--------------------------------------------------------------------------
  310.   alias event_pop_message_update_placement update_placement
  311.   def update_placement
  312.     if SceneManager.scene_is?(Scene_Map)
  313.       if @event_pop_id.nil?
  314.         fix_default_message
  315.         event_pop_message_update_placement
  316.       elsif @event_pop_id == 0
  317.         character = $game_player
  318.         self.y = character.screen_y - self.height + YSE::POP_MESSAGE::POSITION[:y_buffer]
  319.         self.x = character.screen_x - self.width / 2 + YSE::POP_MESSAGE::POSITION[:x_buffer]
  320.         fix_position_bubble(character)
  321.         set_bubble_tag(character)
  322.       elsif @event_pop_id > 0
  323.         hash = @event_pop_follower ? $game_player.followers : $game_map.events
  324.         character = hash[@event_pop_id]
  325.         self.y = character.screen_y - self.height + YSE::POP_MESSAGE::POSITION[:y_buffer]
  326.         self.x = character.screen_x - self.width / 2 + YSE::POP_MESSAGE::POSITION[:x_buffer]
  327.         fix_position_bubble(character)
  328.         set_bubble_tag(character)
  329.       end
  330.     else
  331.       event_pop_message_update_placement
  332.     end
  333.   end
  334.  
  335.   #--------------------------------------------------------------------------
  336.   # new method: fix_default_message
  337.   #--------------------------------------------------------------------------
  338.   def fix_default_message
  339.     self.width = window_width
  340.     self.height = window_height#[max_choice_width + 12, 96].max + padding * 2
  341.     self.x = 0
  342.     @face_window.hide_face if @face_window
  343.     create_contents
  344.     return unless YSE::POP_MESSAGE::EFFECT[:use_bubble_tag]
  345.     @bubble_tag.visible = false if @bubble_tag
  346.   end
  347.  
  348.   #--------------------------------------------------------------------------
  349.   # new method: fix_position_bubble
  350.   #--------------------------------------------------------------------------
  351.   def fix_position_bubble(character)
  352.     end_x = self.x + self.width
  353.     end_y = self.y + self.height
  354.     self.x = 0 if self.x < 0
  355.     self.y = character.screen_y if self.y < 0
  356.     self.x = Graphics.width - self.width if end_x > Graphics.width
  357.     self.y = Graphics.height - self.height if end_y > Graphics.height
  358.   end
  359.  
  360.   #--------------------------------------------------------------------------
  361.   # new method: set_bubble_tag
  362.   #--------------------------------------------------------------------------
  363.   def set_bubble_tag(character)
  364.     return unless YSE::POP_MESSAGE::EFFECT[:use_bubble_tag]
  365.     return unless @bubble_tag
  366.     up = self.y == character.screen_y
  367.     self.y += up ? @bubble_tag.height / 2 : [email]-@bubble_tag.height[/email] / 2
  368.     @bubble_tag.x = character.screen_x - @bubble_tag.width / 2
  369.     if up
  370.       @bubble_tag.src_rect.set(0, @bubble_tag.height, @bubble_tag.width, @bubble_tag.height)
  371.       @bubble_tag.y = self.y - @bubble_tag.height - YSE::POP_MESSAGE::POSITION[:tag_y_buffer]
  372.     else
  373.       @bubble_tag.src_rect.set(0, 0, @bubble_tag.width, @bubble_tag.height)
  374.       @bubble_tag.y = self.y + self.height + YSE::POP_MESSAGE::POSITION[:tag_y_buffer]
  375.     end
  376.   end
  377.  
  378.   #--------------------------------------------------------------------------
  379.   # new method: cal_number_line
  380.   #--------------------------------------------------------------------------
  381.   def cal_number_line(text)
  382.     result = 0
  383.     text.each_line { result += 1 }
  384.     return result
  385.   end
  386.  
  387.   #--------------------------------------------------------------------------
  388.   # new method: cal_width_line #?!!!!
  389.   #--------------------------------------------------------------------------
  390.   def cal_width_line(text)
  391.     result = 0
  392.     text.each_line { |line|
  393.       result = text_size(line).width if result < text_size(line).width
  394.     }
  395.     return result
  396.   end
  397.  
  398.   #--------------------------------------------------------------------------
  399.   # alias method: adjust_message_window_size
  400.   #--------------------------------------------------------------------------
  401.   if $imported["YEA-MessageSystem"]
  402.   alias yse_pop_message_adjust_message_window_size adjust_message_window_size
  403.   def adjust_message_window_size
  404.     start_name_window if @event_pop_id
  405.     return if @event_pop_id
  406.     yse_pop_message_adjust_message_window_size
  407.   end
  408.   end
  409.  
  410.   #--------------------------------------------------------------------------
  411.   # new method: adjust_pop_message
  412.   #--------------------------------------------------------------------------
  413.   def adjust_pop_message(text = " ")
  414.     return unless SceneManager.scene_is?(Scene_Map)
  415.     unless @event_pop_id
  416.       if $imported["YEA-MessageSystem"]
  417.         #adjust_message_window_size
  418.       end
  419.       return
  420.     end
  421.     n_line = cal_number_line(text)
  422.     n_line = YSE::POP_MESSAGE::LIMIT[:limit_line] if YSE::POP_MESSAGE::LIMIT[:limit_line] > 0 && cal_number_line(text) > YSE::POP_MESSAGE::LIMIT[:limit_line]
  423.     @real_lines = n_line
  424.     self.height = fitting_height(n_line)
  425.     self.width = cal_width_line(text) + 24
  426.     self.width += new_line_x
  427.     if self.width > YSE::POP_MESSAGE::LIMIT[:limit_width] && YSE::POP_MESSAGE::LIMIT[:limit_width] > 0
  428.       self.width = YSE::POP_MESSAGE::LIMIT[:limit_width]
  429.     end
  430.     create_contents
  431.     update_placement
  432.   end
  433.  
  434.   #--------------------------------------------------------------------------
  435.   # overwrite method: new_line_x
  436.   #--------------------------------------------------------------------------
  437.   def new_line_x
  438.     if $game_message.face_name.empty?
  439.       return 0
  440.     else
  441.       result = YSE::POP_MESSAGE::POSITION[:face_x_buffer]
  442.       p_x = $imported["YEA-MessageSystem"] ? YEA::MESSAGE::FACE_INDENT_X : 112
  443.       result += p_x
  444.       return result
  445.     end
  446.   end
  447.  
  448.   #--------------------------------------------------------------------------
  449.   # new method: real_lines
  450.   #--------------------------------------------------------------------------
  451.   def real_lines
  452.     @real_lines
  453.   end
  454.  
  455. end # Window_Message
  456.  
  457. #==============================================================================
  458. # ¡ Scene_Map
  459. #==============================================================================
  460.  
  461. class Scene_Map < Scene_Base
  462.  
  463.   #--------------------------------------------------------------------------
  464.   # alias method: create_message_window
  465.   #--------------------------------------------------------------------------
  466.   alias yse_pm_create_message_window create_message_window
  467.   def create_message_window
  468.     yse_pm_create_message_window
  469.     @face_window = Window_Message_Face.new
  470.     @face_window.message_window = @message_window
  471.     if YSE::POP_MESSAGE::EFFECT[:use_bubble_tag]
  472.       @bubble_tag_sprite = Sprite.new
  473.       @bubble_tag_sprite.visible = false
  474.       @bubble_tag_sprite.bitmap = Cache.system(YSE::POP_MESSAGE::EFFECT[:bubble_tag_name])
  475.       @bubble_tag_sprite.src_rect.set(0, 0, @bubble_tag_sprite.width, @bubble_tag_sprite.height / 2)
  476.       @message_window.bubble_tag = @bubble_tag_sprite
  477.     end
  478.     @message_window.face_window = @face_window
  479.   end
  480.  
  481.   #--------------------------------------------------------------------------
  482.   # alias method: dispose_spriteset
  483.   #--------------------------------------------------------------------------
  484.   alias pop_message_dispose_spriteset dispose_spriteset
  485.   def dispose_spriteset
  486.     pop_message_dispose_spriteset
  487.     return unless @bubble_tag_sprite
  488.     @bubble_tag_sprite.dispose
  489.   end
  490.  
  491. end # Scene_Map
  492.  
  493. #==============================================================================
  494. #
  495. # ¥ End of File
  496. #
  497. #==============================================================================



此脚本就是问题所在……实际上无需图片,因为VA本身就没有对宽度的文章判定,最多也就是有人出了个选项宽度的修复,而对于文章窗口宽度的定义没有…………本身是不需要的,但是这个脚本使用的时候一旦有很多的控制符就会出现大段空白,所以求帮助……
代码里有些奇怪的注释不要在意,本人脚本渣。
作者: taroxd    时间: 2014-10-1 13:15
最多也就是有人出了个选项宽度的修复


这也就是你需要的东西了。用“选项宽度的修复”脚本中获取宽度的语句代替这个脚本中设置宽度的语句就好了。
作者: 550806810    时间: 2014-10-1 13:52
  1. class Window_ChoiceList

  2.   def max_choice_width
  3.     $game_message.choices.collect {|s| pro_ex(s) }.max
  4.   end
  5.   
  6.   def pro_ex(str)
  7.     s = convert_escape_characters(str)
  8.     pos = {:x => 0, :y => -Graphics.height, :new_x => 0, :height => calc_line_height(s)}
  9.     process_character(s.slice!(0, 1), s, pos) until s.empty?
  10.     pos[:x]
  11.   end
  12. end
复制代码
选项宽度修复的脚本……求适当的修改嗯……
作者: taroxd    时间: 2014-10-1 13:55
550806810 发表于 2014-10-1 13:52
选项宽度修复的脚本……求适当的修改嗯……
  1. class Window_Message < Window_Base
  2.   def cal_width_line(text)
  3.     text.each_line.map(&method(:pro_ex)).max
  4.   end
  5. end
复制代码
没测试,瞎写的

思路就是这样,用 pro_ex 代替原本文字的宽度
作者: 550806810    时间: 2014-10-1 14:36
taroxd 发表于 2014-10-1 13:55
没测试,瞎写的

思路就是这样,用 pro_ex 代替原本文字的宽度

嗯,最上面有选项宽度修复,然后再下是对话框加强,最后是你这个……不过你这个默认会报错,我在下面加上了选项宽度修复的def pro_ex(text)……然后就会只有人物头像,文字不会显示出来……




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