查看: 115|回复: 0

[转载发布] 【RM】Log信息提示

[复制链接]
  • TA的每日心情
    开心
    昨天 10:15
  • 签到天数: 73 天

    连续签到: 1 天

    [LV.6]常住居民II

    2044

    主题

    86

    回帖

    8602

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    -2
    卡币
    6460
    OK点
    16
    积分
    8602
    发表于 2024-4-12 23:00:52 | 显示全部楼层 |阅读模式
    脚本内容
    [Ruby] 纯文本查看 复制代码
    #encoding:utf-8
    #==============================================================================
    # ■ Log信息提示v1.1 By_QQEat
    #
    #   说明:提示信息使用。
    #   依赖:此脚本需依赖 【Timer_定时器】脚本。
    #   地址:http://rpg. blue/home.php?mod=space&uid=326184&do=blog&id=16491
    #
    #   [创建/更新/释放]
    #
    #     @log = Log.new
    #     @log.update
    #     @log.dispose
    #
    #   [使用]
    #     
    #     @log.add({
    #       text: 'message',        # 提示信息
    #       font: '黑体',           # 字体名称
    #       size: 24,               # 字体大小
    #       color: color,           # 字体颜色
    #       background: color,      # 背景颜色
    #       lineColor: color,       # 边缘颜色
    #       clear: 180,             # 消失帧数
    #       format: 0,              # 格式(0普通, 1支持字符格式)
    #       viewport: viewport,     # 显示端口
    #       location: 1,            # 显示位置(0:左下, 1右下)
    #       moveType: 'in-bounce',  # 弹出方式('in-/out-/in-out-/out-in-' + 'quad/cubic/quart/quint/sine/expo/circ/back/bounce/elastic')
    #       moveSpeed: 40,          # 弹出速度
    #     })
    #
    #   [内容字符支持格式]
    #
    #      \n      换行
    #      \\c[x]  更改颜色
    #      \\i[x]  绘制图标
    #      \\{     字体增大 8 号
    #      \\}     字体缩小 8 号
    #
    #   [范例]
    #
    #     @log.add({text: '提示信息'})
    #
    #   [全局使用]
    #
    #     $log.add({text: '全局提示信息'})
    #
    #==============================================================================
    
    class Log
      attr_accessor :logs
      def initialize
        @logs = []
      end
      def update
        @logs.each do |log|
          log.update
          if log.dead
            log.dispose
            @logs.delete(log)
          end
        end
      end
      def dispose
        @logs.each(&:dispose)
      end
      def add(set={})
        # 默认参数,在这里修改
        text = set[:text] || ''
        font = set[:font]
        size = set[:size] || 24
        color = set[:color] || Color.new(255,255,255)
        background = set[:background] || Color.new(0,0,0,125)
        lineColor = set[:lineColor] || Color.new(255,255,255)
        clear = set[:clear] || 180
        format = set[:format] || 0
        viewport = set[:viewport]
        location = set[:location] || 1
        moveType = set[:moveType] || 'in-bounce'
        moveSpeed = set[:moveSpeed] || 40
        @logs.push LogText.new(text, font, size, color, background, lineColor, clear, format, viewport, location, moveType, moveSpeed)
        @logs.each{|l| l.move_up(@logs[-1]) if l.viewport == viewport }
      end
    end
    
    class LogText < Sprite_Base
      attr_accessor :dead
      def initialize(text, font, size, color, background, lineColor, clear, format, viewport, location, moveType, moveSpeed)
        super(viewport)
        # 属性设置
        tmpBitmap = (Bitmap.new(1,1).tap do |b| b.font.size = size end)
        if format = 1 # 字符处理
          arrStr,arrWid = text.dup.split("\n"),[]
          # 计算每行宽度,取最大宽度的那行
          arrStr.each_with_index{|s,i|
            arrWid[i] = 0
            s.gsub!(/\\(.)(\[(\d)+\])?/){arrWid[i]+=$1.upcase=='I'?24:0;''}
            arrWid[i] += tmpBitmap.text_size(s).width
          }
          rect = Rect.new(0,0, arrWid.max, arrStr.size*(size||24))
        else
          tmpBitmap.text_size(text)
        end
        self.bitmap = Bitmap.new(rect.width + 24, rect.height + 24)
        self.bitmap.font.name = font if font
        self.bitmap.font.size = size if size
        self.bitmap.fill_rect(self.bitmap.rect, background) if background
        if lineColor
          self.bitmap.fill_rect(0,0,1,self.bitmap.height, lineColor)
          self.bitmap.fill_rect(self.bitmap.width-1,0,1,self.bitmap.height, lineColor)
        end
        self.bitmap.font.color = color if color
       
        # 文字绘制
        case format
        when 0
          self.bitmap.draw_text(self.bitmap.rect, text, 1)
        when 1
          temp = Sprite.new
          temp.bitmap = self.bitmap.dup
          temp.bitmap.clear
          temp.draw_text_ex_drawLog(self.bitmap.rect, text.dup)
          self.bitmap.blt((self.width-rect.width)/2, (self.height-rect.height)/2, temp.bitmap, temp.bitmap.rect)
          temp.dispose
        end
       
        # 显示位置
        self.x = case location
        when 0; (viewport.nil? ? 0 : viewport.rect.x) + 10
        when 1; (viewport.nil? ? Graphics.width : viewport.rect.width) - (self.width + 5)
        end
        self.y = (viewport.nil? ? Graphics.height : viewport.rect.height)
        self.z = 99999999
       
        # 滑动
        @timer = Timer.new
        @clear, @moveType, @moveSpeed = clear, moveType, moveSpeed
      end
      def update
        super
        @timer.update
        self.dead = true if self.y + self.height < 0
      end
      def dispose
        super
        @timer.dispose
      end
      def move_up(obj)
        @timer.tween(@moveSpeed || 30, self, {y: self.y - (obj.height + 5)}, @moveType)
        @timer.after(@clear, proc{
            @timer.tween(30, self, {opacity: 0}, 'linear', proc{ self.dead = true })
        })
      end
    end
    
    class Sprite
      #--------------------------------------------------------------------------
      # ● 绘制带有控制符的文本内容
      #--------------------------------------------------------------------------
      def draw_text_ex_drawLog(*args)
        case args.size
        when 2
          x, y, w, h, text = args[0].x,args[0].y,args[0].width,args[0].height,args[1]
        when 5
          x, y, w, h, text = *args
        else
          p '信息框内容格式 1 绘制参数传递错误'
          return
        end
        text.gsub!(/\\/)            { "\e" }
        text.gsub!(/\e\e/)          { "\\" }
        pos = {:x => x, :y => y, :new_x => x, :height => [24, self.bitmap.font.size].max}
        until text.empty?
          process_new_line = Proc.new{
            pos[:x] = pos[:new_x]
            pos[:y] += pos[:height]
            pos[:height] = [24, self.bitmap.font.size].max
          }
          c = text.slice!(0, 1)
          case c
          when "\r"   # 回车
            return
          when "\n"   # 换行
            process_new_line.call
          when "\e"   # 控制符
            code = text.slice!(/^[\$\.\|\^!><\{\}\\]|^[A-Z]+/i)
            param = Proc.new{|s| s.slice!(/^\[\d+\]/)[/\d+/].to_i rescue 0 }
            case code.upcase
            when 'C'
              n = param.call text
              self.bitmap.font.color = Cache.system("Window").get_pixel(64 + (n % 8) * 8, 96 + (n / 8) * 8)
            when 'I'
              icon_index = param.call text
              icon_bitmap = Cache.system("Iconset")
              rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
              process_new_line.call if pos[:x] + rect.width >= w
              self.bitmap.blt(pos[:x], pos[:y], icon_bitmap, rect, 255)
              pos[:x] += rect.width
            when '{'
              self.bitmap.font.size += 8 if self.bitmap.font.size <= 64
              pos[:height] = [24, self.bitmap.font.size].max
            when '}'
              self.bitmap.font.size -= 8 if self.bitmap.font.size >= 16
              pos[:height] = [24, self.bitmap.font.size].max
            end
          else        # 普通文字
            text_width = self.bitmap.text_size(c).width
            process_new_line.call if pos[:x] + text_width >= w
            self.bitmap.draw_text(pos[:x], pos[:y], text_width * 2, pos[:height], c)
            pos[:x] += text_width
          end
        end
        return pos[:x],pos[:y] + pos[:height]
      end
    end
    
    class << Input
      alias :qqeat_log_input_update :update unless $@
      def update
        $log ||= Log.new
        $log.update
        qqeat_log_input_update
      end
    end


    更新内容





    提示信息使用...
    范例下载:


                 本帖来自P1论坛作者张咚咚,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg. blue/forum.php?mod=viewthread&tid=410508  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2024-9-21 14:47 , Processed in 0.051335 second(s), 42 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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