Project1

标题: 我只是想用帖子备个份,不会被删吧? [打印本页]

作者: gaofei677    时间: 2014-12-11 11:51
标题: 我只是想用帖子备个份,不会被删吧?
本帖最后由 gaofei677 于 2014-12-12 09:08 编辑

RUBY 代码复制
  1. #==============================================================================
  2. #■ AVG式对话框(未通用化)
  3. #   功能:
  4. #           1. 用图片代替默认对话框
  5. #           2. 额外显示对话者姓名
  6. #           3. 姓名&对话内容自动染色
  7. #==============================================================================
  8.  
  9. #==============================================================================
  10. # ■ Window_Base
  11. #------------------------------------------------------------------------------
  12. #  游戏中所有窗口的父类
  13. #==============================================================================
  14.  
  15. class Window_Base < Window
  16.   #--------------------------------------------------------------------------
  17.   # ● 进行控制符的事前变换
  18.   #    在实际绘制前、将控制符替换为实际的内容。
  19.   #    为了减少歧异,文字「\」会被首先替换为转义符(\e)。
  20.   #--------------------------------------------------------------------------
  21.   def convert_escape_characters(text)
  22.     result = text.to_s.clone
  23.     result.gsub!(/\\/)            { "\e" }
  24.     result.gsub!(/\e\e/)          { "\\" }
  25.     result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  26.     result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  27.     result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i) }
  28.     result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
  29.     result.gsub!(/\eG/i)          { Vocab::currency_unit }
  30.     result.gsub!(/^\eName\[(.+)\]/i){""}
  31.     @speaker_name = $1.to_s
  32.     result
  33.   end
  34.   #--------------------------------------------------------------------------
  35.   # ● 处理普通文字
  36.   #--------------------------------------------------------------------------
  37.   def process_normal_character(c, pos)
  38.     text_width = text_size(c).width
  39.     talk_color
  40.     draw_text(pos[:x], pos[:y], text_width * 2, pos[:height], c)
  41.     pos[:x] += text_width
  42.   end
  43.   #--------------------------------------------------------------------------
  44.   # ● 角色文字染色
  45.   #--------------------------------------------------------------------------
  46.   def talk_color
  47.     if $has_color_change != true
  48.       case @speaker_name
  49.       when "柔一"
  50.         contents.font.color.set(145,55,0)
  51.       when "坚二"
  52.         contents.font.color.set(165,75,0)
  53.       else
  54.         contents.font.color.set(255,255,255)
  55.       end
  56.     end
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # ● 控制符的处理
  60.   #     code : 控制符的实际形式(比如“\C[1]”是“C”)
  61.   #     text : 绘制处理中的字符串缓存(字符串可能会被修改)
  62.   #     pos  : 绘制位置 {:x, :y, :new_x, :height}
  63.   #--------------------------------------------------------------------------
  64.   def process_escape_character(code, text, pos)
  65.     case code.upcase
  66.     when 'C'
  67.       $has_color_change = true
  68.       change_color(text_color(obtain_escape_param(text)))
  69.     when 'I'
  70.       process_draw_icon(obtain_escape_param(text), pos)
  71.     when '{'
  72.       make_font_bigger
  73.     when '}'
  74.       make_font_smaller
  75.     end
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # ● 绘制内容
  79.   #     args : 与 Bitmap#draw_text 相同
  80.   #--------------------------------------------------------------------------
  81.   def draw_text(*args)
  82.     if contents.font.bold != true
  83.       contents.font.name = "微软雅黑"
  84.       contents.font.bold = true
  85.       contents.font.shadow = true
  86.       contents.font.size = 27
  87.     end
  88.     contents.draw_text(*args)
  89.   end
  90. end
  91.  
  92. #==============================================================================
  93. # ■ Window_Message
  94. #------------------------------------------------------------------------------
  95. #  显示文字信息的窗口。
  96. #==============================================================================
  97.  
  98. class Window_Message < Window_Base
  99.   #--------------------------------------------------------------------------
  100.   # ● 初始化对象
  101.   #--------------------------------------------------------------------------
  102.   alias old_initialize initialize
  103.   def initialize
  104.     old_initialize
  105.     creat_bg_pic
  106.   end
  107.   #--------------------------------------------------------------------------
  108.   # ● 获取窗口的高度
  109.   #--------------------------------------------------------------------------
  110.   def window_height
  111.     fitting_height(visible_line_number) + 30
  112.   end
  113.   #--------------------------------------------------------------------------
  114.   # ● 获取背景图片
  115.   #--------------------------------------------------------------------------
  116.   def creat_bg_pic
  117.     @bg_sprite = Sprite.new
  118.     @bg_sprite.x = 15
  119.     @bg_sprite.y = 380
  120.     @bg_sprite.bitmap = Cache.ui("Dialog").clone
  121.     @bg_sprite.visible = false
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # ● 更新窗口背景
  125.   #--------------------------------------------------------------------------
  126.   alias old_update_background update_background
  127.   def update_background
  128.     old_update_background
  129.     self.opacity = 0
  130.     self.height = 150
  131.     self.x = 25
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # ● 处理纤程的主逻辑
  135.   #--------------------------------------------------------------------------
  136.   def fiber_main
  137.     $game_message.visible = true
  138.     @bg_sprite.visible = true
  139.     update_background
  140.     update_placement
  141.     loop do
  142.       process_all_text if $game_message.has_text?
  143.       process_input
  144.       $game_message.clear
  145.       @gold_window.close
  146.       Fiber.yield
  147.       $has_color_change = false
  148.       clear_dialog_name
  149.       break unless text_continue?
  150.     end
  151.     close_and_wait
  152.     clear_dialog_name
  153.     @bg_sprite.visible = false
  154.     $game_message.visible = false
  155.     @fiber = nil
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # ● 处理所有内容
  159.   #--------------------------------------------------------------------------
  160.   def process_all_text
  161.     open_and_wait
  162.     text = convert_escape_characters($game_message.all_text)
  163.     show_dialog_name
  164.     pos = {}
  165.     new_page(text, pos)
  166.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  167.   end
  168.   #--------------------------------------------------------------------------
  169.   # ● 显示对话姓名
  170.   #--------------------------------------------------------------------------
  171.   def show_dialog_name
  172.     @name_viewport = Viewport.new
  173.     @name_string_sprite = Sprite.new(@name_viewport)
  174.     @name_string_sprite.x = -130
  175.     @name_string_sprite.y = 348
  176.     @name_string_sprite.z = 1
  177.     @name_string_sprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
  178.     if @name_string_sprite.bitmap.font.bold != true
  179.       @name_string_sprite.bitmap.font.name = "微软雅黑"
  180.       @name_string_sprite.bitmap.font.bold = true
  181.       @name_string_sprite.bitmap.font.shadow = true
  182.       @name_string_sprite.bitmap.font.size = 27
  183.     end
  184.     name_color
  185.     @name_string_sprite.bitmap.draw_text(200, 0, 100, 100, @speaker_name)
  186.     if !@speaker_name.empty?
  187.       @name_pic_sprite = Sprite.new(@name_viewport)
  188.       @name_pic_sprite.bitmap = Cache.ui("nameBack").clone
  189.       @name_pic_sprite.x = 15
  190.       @name_pic_sprite.y = 380
  191.       @name_pic_sprite.z = 0
  192.     end
  193.   end
  194.   #--------------------------------------------------------------------------
  195.   # ● 姓名染色
  196.   #--------------------------------------------------------------------------
  197.   def name_color
  198.     case @speaker_name
  199.     when "柔一"
  200.       name_color = Color.new(145,55,0)
  201.     when "坚二"
  202.       name_color = Color.new(165,75,0)
  203.     else
  204.       name_color = Color.new(255,255,255)
  205.     end
  206.     @name_string_sprite.bitmap.font.color.set(name_color)
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # ● 清除对话姓名
  210.   #--------------------------------------------------------------------------
  211.   def clear_dialog_name
  212.     @name_pic_sprite.bitmap.dispose
  213.     @name_string_sprite.bitmap.dispose
  214.     @name_viewport.dispose
  215.   end
  216. end


无聊在办公室写的,回家方便用,既然是水区,这个贴应该不会被删吧?

忽然发现这样发还能大家讨论,真不错。
作者: 永燃的狂炎    时间: 2014-12-11 12:08
6r自带的群也能存放东西。
作者: taroxd    时间: 2014-12-11 12:38
要么建一个群组(建议),要么可以发到开水区
作者: VIPArcher    时间: 2014-12-11 13:03
没认真看,不过楼主好像忘记释放了呢。
作者: taroxd    时间: 2014-12-11 17:47
本帖最后由 taroxd 于 2014-12-11 17:56 编辑


$has_color_change 有点意义不明。为什么是全局?难道不是应该每个窗口的实例分别有一个实例变量么?

还有,别忘了释放
作者: 美丽晨露    时间: 2014-12-11 22:34
表示看不出是XP还是VA,反正肯定不是VX
作者: kuerlulu    时间: 2014-12-11 22:47
你可以写到空间的日志里
作者: 精灵使者    时间: 2014-12-12 10:05
移动到技术讨论区或者发布区会有更好的人气哦。
作者: 王硕    时间: 2014-12-12 10:18
你把论坛当网盘吗?




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