查看: 2822|回复: 16

[已经解决] 窗口独立显示

[复制链接]
梦石
0
星屑
3850
在线时间
1899 小时
注册时间
2010-6-19
回帖
917
发表于 2022-11-16 17:57:57 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 黑米馒头 于 2022-11-17 22:51 编辑

试着弄了个提示窗口

先生成窗口
    $tip_window = Window_Help.new
    $tip_window.width = 300
    $tip_window.x = (640-$tip_window.width)/2
    $tip_window.visible = false
    @wait_count = 40

  def wait_count
    if @wait_count > 0
      @wait_count -= 1
    elsif @wait_count == 0
      $tip_window.visible = false
      @wait_count = 40
    end
  end  

然后刷新窗口
    # 刷新全局提示窗口
    $tip_window.update
    wait_count


测试的时候在事件输入
$tip_window.set_text("窗口提示")

效果如下
3.png

但是有个问题,就是比如我设置了多个文本的话,
文本是直接显示最后一个的,应该是把前面的文本给覆盖了,
要如何设置,让同个窗口可以实现多个文本独立的显示出来

4.png


多功能文本#===========================================================================
#  *  draw_text必备扩展
#===========================================================================
=begin

  !c[n]       #改用n号颜色 *注 颜色在color处自定
  !s[n]       #改用n号大小
  !n[name]    #改用名称为name的字体
  !b0         #关闭粗体
  !b1         #开启粗体
  !i0         #关闭斜体
  !i1         #开启斜体
  
  i[n]        #描绘id为n的物品的图标
  s[n]        #描绘id为n的特技的图标
  w[n]        #描绘id为n的武器的图标
  a[n]        #描绘id为n的防具的图标
  l[filename] #描绘文件名为filename的图标
  
  \\n         #手动换行
  
  其他功能——
  *投影
  *自动换行

=end
class Bitmap
  def dl_draw_text(x, y, text)
    #记录bitmap数据
    name_copy = self.font.name
    size_copy = self.font.size
    bold_copy = self.font.bold
    italic_copy = self.font.italic
    color_copy = self.font.color.clone
    #初始数据
    text_copy = text
    tx,ty = x,y
    rect = Rect.new(0, 0, 24, 24)
    #字体
    text_copy.gsub!(/!c\[([0-9]+)\]/) { "\001[#{$1}]" }
    text_copy.gsub!(/!s\[([0-9]+)\]/) { "\002[#{$1}]" }
    text_copy.gsub!(/!n\[(.+)\]/) { "\003[#{$1}]" }
    text_copy.gsub!(/!b0/) { "\004" }
    text_copy.gsub!(/!b1/) { "\005" }
    text_copy.gsub!(/!i0/) { "\006" }
    text_copy.gsub!(/!i1/) { "\007" }
    #图标
    text_copy.gsub!(/i\[([0-9]+)\]/) { "\020[#{$1}]" }
    text_copy.gsub!(/s\[([0-9]+)\]/) { "\021[#{$1}]" }
    text_copy.gsub!(/w\[([0-9]+)\]/) { "\022[#{$1}]" }
    text_copy.gsub!(/a\[([0-9]+)\]/) { "\023[#{$1}]" }
    text_copy.gsub!(/l\[(.+)\]/) { "\025[#{$1}]" }
    #其他
    text_copy.gsub!(/v\[([0-9]+)\]/) { $game_variables[$1.to_i] }
    text_copy.gsub!(/\\n/) { "\030" }
    #颜色
    color = []
    color[0] = Color.new(255, 255, 255, 255)#白
    color[1] = Color.new(128, 128, 255, 255)#蓝
    color[2] = Color.new(255, 0, 0, 255)#(255, 0, 80, 255)   #红
    color[3] = Color.new(128, 255, 128, 255)#绿
    color[4] = Color.new(128, 255, 255, 255)#青
    color[5] = Color.new(255, 128, 255, 255)#粉红
    color[6] = Color.new(255, 255, 128, 255)#黄
    color[7] = Color.new(192, 192, 192, 255)#灰
    color[8] = Color.new(255, 195, 105, 255)#桔色
    color[9] = Color.new(207, 212, 241, 255)#紫色

    while ((c = text_copy.slice!(/./m)) != nil)
      #====================================
      #设置字体
      #====================================
      #颜色
      if c == "\001"
        text_copy.sub!(/\[([0-9]+)\]/, "")
        next if color[$1.to_i].nil?
        self.font.color = color[$1.to_i]
        next
      end
      #大小
      if c == "\002"
        text_copy.sub!(/\[([0-9]+)\]/, "")
        self.font.size = $1.to_i
        next
      end
      #名称
      if c == "\003"
        text_copy.sub!(/\[(.+)\]/, "")
        self.font.name = $1 if Font.exist?($1)
        next
      end
      #粗体关
      if c == "\004"
        self.font.bold = false
        next
      end
      #粗体开
      if c == "\005"
        self.font.bold = true
        next
      end
      #斜体关
      if c == "\006"
        self.font.italic = false
        next
      end
      #斜体开
      if c == "\007"
        self.font.italic = true
        next
      end
      #====================================
      #描绘图标
      #====================================
      #物品
      if c == "\020"
        text_copy.sub!(/\[([0-9]+)\]/, "")
        if !$data_items[$1.to_i].nil? and $data_items[$1.to_i].icon_name != ""
          next if tx + 24 > self.width - 32
          bitmap = RPG::Cache.icon($data_items[$1.to_i].icon_name)
          self.blt(tx, ty, bitmap, rect)
          tx += 24
        end
        next
      end
      #特技
      if c == "\021"
        text_copy.sub!(/\[([0-9]+)\]/, "")
        if !$data_skills[$1.to_i].nil? and $data_skills[$1.to_i].icon_name != ""
          next if tx + 24 > self.width - 32
          bitmap = RPG::Cache.icon($data_skills[$1.to_i].icon_name)
          self.blt(tx, ty, bitmap, rect)
          tx += 24
        end
        next
      end
      #武器
      if c == "\022"
        text_copy.sub!(/\[([0-9]+)\]/, "")
        if !$data_weapons[$1.to_i].nil? and $data_weapons[$1.to_i].icon_name != ""
          next if tx + 24 > self.width - 32
          bitmap = RPG::Cache.icon($data_weapons[$1.to_i].icon_name)
          self.blt(tx, ty, bitmap, rect)
          tx += 24
        end
        next
      end
      #防具
      if c == "\023"
        text_copy.sub!(/\[([0-9]+)\]/, "")
        if !$data_armors[$1.to_i].nil? and $data_armors[$1.to_i].icon_name != ""
          next if tx + 24 > self.width - 32
          bitmap = RPG::Cache.icon($data_armors[$1.to_i].icon_name)
          self.blt(tx, ty, bitmap, rect)
          tx += 24
        end
        next
      end
      #自定
      if c == "\025"
        text_copy.sub!(/\[(.+)\]/, "")
        if $1 != ""
          next if tx + 24 > self.width - 32
          bitmap = RPG::Cache.icon($1)
          self.blt(tx, ty, bitmap, rect)
          tx += 24
        end
        next
      end
      #====================================
      #其他
      #====================================
      #换行
      if c == "\030"
        ty += self.font.size
        next
      end
      cx = self.text_size(c).width
      #投影
      #dl_color_copy = self.font.color.clone
      #self.font.color.set(0, 0, 0)
      #self.draw_text(tx+1, ty+1, cx, self.font.size, c)
      #self.draw_text(tx-1, ty+1, cx, self.font.size, c)
      #self.draw_text(tx+1, ty-1, cx, self.font.size, c)
      #self.draw_text(tx-1, ty-1, cx, self.font.size, c)
      #self.font.color = dl_color_copy
      self.draw_text(tx, ty, cx, self.font.size, c)
      tx += cx
      #自动换行
      if tx >= self.width
        tx = 0
        ty += self.font.size
      end
    end
    #恢复调整
    self.font.name = name_copy
    self.font.size = size_copy
    self.font.bold = bold_copy
    self.font.italic = italic_copy
    self.font.color = color_copy
  end
end
梦石
0
星屑
2821
在线时间
585 小时
注册时间
2022-7-13
回帖
81
发表于 2022-11-16 19:32:56 | 显示全部楼层
本帖最后由 我为鱼肉 于 2022-11-18 12:58 编辑

做了个简单的范例 网游式全场景提示窗口.zip (986.41 KB, 下载次数: 7)
GIF预览 网游式全场景提示窗口-39-FPS-2022-11-16-22-47-12.gif

代码
  1. #==============================================================================
  2. # ** RPG::Cache 高速缓存UI
  3. #==============================================================================
  4. module RPG::Cache
  5.   def self.ui(filename)
  6.     self.load_bitmap("Graphics/UI/", filename)
  7.   end
  8. end
  9. #==============================================================================
  10. # ** Bitmap 拓展
  11. #==============================================================================
  12. class Bitmap
  13.   #--------------------------------------------------------------------------
  14.   # * draw_windowskin 描绘窗口皮肤
  15.   # window_x      窗口X坐标  默认0
  16.   # window_Y      窗口Y坐标  默认0
  17.   # window_width  窗口width  默认self.width
  18.   # window_height 窗口height 默认self.height
  19.   #--------------------------------------------------------------------------
  20.   def draw_windowskin(window_x = 0, window_y = 0, window_width = self.width, window_height = self.height)
  21.     src_bitmap = RPG::Cache.ui("帮助窗口背景.png")
  22.     src_rect = Rect.new(0, 0, 0, 0)
  23.     dest_rect = Rect.new(0, 0, 0, 0)
  24.     #上
  25.     src_rect.set(0, 0, 5, 5)
  26.     self.blt(window_x, window_y, src_bitmap, src_rect)
  27.     src_rect.set(6, 0, 5, 5)
  28.     self.blt(window_x + window_width - 5, window_y, src_bitmap, src_rect)
  29.     dest_rect.set(window_x + 5, window_y, window_width - 10, 5)
  30.     src_rect.set(5, 0, 1, 5)
  31.     self.stretch_blt(dest_rect, src_bitmap, src_rect)
  32.     #下
  33.     src_rect.set(0, 6, 5, 5)
  34.     self.blt(window_x, window_y + window_height - 5, src_bitmap, src_rect)
  35.     src_rect.set(6, 6, 5, 5)
  36.     self.blt(window_x + window_width - 5, window_y + window_height - 5, src_bitmap, src_rect)
  37.     dest_rect.set(window_x + 5, window_y + window_height - 5, window_width - 10, 5)
  38.     src_rect.set(5, 6, 1, 5)
  39.     self.stretch_blt(dest_rect, src_bitmap, src_rect)
  40.     #其余
  41.     dest_rect.set(window_x, window_y + 5, 5, window_height - 10)
  42.     src_rect.set(0, 5, 5, 1)
  43.     self.stretch_blt(dest_rect, src_bitmap, src_rect)
  44.     dest_rect.set(window_x + window_width - 5, window_y + 5, 5, window_height - 10)
  45.     src_rect.set(6, 5, 5, 1)
  46.     self.stretch_blt(dest_rect, src_bitmap, src_rect)
  47.     dest_rect.set(window_x + 5, window_y + 5, window_width - 10, window_height - 10)
  48.     src_rect.set(5, 5, 1, 1)
  49.     self.stretch_blt(dest_rect, src_bitmap, src_rect)
  50.   end
  51. end
  52. #bitmap.draw_windowskin描绘测试
  53. #sprite = Sprite.new
  54. #sprite.bitmap = Bitmap.new(640, 480)
  55. #sprite.bitmap.draw_windowskin(160, 226, 320, 28)
  56. #loop do
  57. #  Graphics.update
  58. #end
  59. #==============================================================================
  60. # ** Sprite 提示窗口
  61. #==============================================================================
  62. class Wwyr_Tips < Sprite
  63.   #--------------------------------------------------------------------------
  64.   # * initialize 初始化
  65.   # x        X坐标
  66.   # y        Y坐标
  67.   # text     文本
  68.   # viewport 视口  默认nil
  69.   #--------------------------------------------------------------------------
  70.   def initialize(x, y, text, viewport = nil)
  71.     super(viewport)
  72.     self.z = 99999
  73.     self.x = x
  74.     self.y = y
  75.     self.bitmap = Bitmap.new(320, 28) ##窗口大小
  76.     self.bitmap.font.size = 16 ##字体大小
  77.     self.bitmap.draw_windowskin
  78.     self.bitmap.draw_text(4, 0, self.bitmap.width, self.bitmap.height, text)
  79.     @count = 60 ##提示窗口展示的时间(刷新次数)
  80.   end
  81.   #--------------------------------------------------------------------------
  82.   # * update 刷新
  83.   #--------------------------------------------------------------------------
  84.   def update
  85.     if @count > 0
  86.       @count -= 1
  87.     else
  88.       self.visible = false
  89.     end
  90.     super
  91.   end
  92. end
  93. #==============================================================================
  94. # ** Graphics 提示窗口《操作库》
  95. #==============================================================================
  96. class << Graphics
  97.   #--------------------------------------------------------------------------
  98.   # * tip_init 初始化
  99.   #--------------------------------------------------------------------------
  100.   def tip_init
  101.     @tips = [] ##精灵
  102.     @text = [] ##tips文本的数组
  103.     @count = 0 ##tips计数
  104.   end
  105.   #--------------------------------------------------------------------------
  106.   # * tip 提示(单个)
  107.   # text 文本
  108.   #--------------------------------------------------------------------------
  109.   def tip(text)
  110.     for i in 0...@tips.size
  111.       @tips[i].y = 226 - (@tips.size - i) * 14
  112.     end
  113.     tip = Wwyr_Tips.new(160, 226, text)
  114.     @tips.push(tip)
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # * tips 提示(同时、多个)
  118.   # text  文本数组
  119.   # frame 间隔帧数 默认4
  120.   #--------------------------------------------------------------------------
  121.   def tips(text, frame = 4)
  122.     @text = @text | text
  123.     @count = 0
  124.     @frame = frame
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # * update 刷新
  128.   #--------------------------------------------------------------------------
  129.   alias wwyralias_update_for_tips update unless method_defined? :wwyralias_update_for_tips
  130.   def update
  131.     if @text.size > 0
  132.       if @count == 0
  133.         text = @text.shift
  134.         tip(text)
  135.         @count = @frame
  136.       else
  137.         @count -= 1
  138.       end
  139.     end
  140.     clear_data = false
  141.     for i in 0...@tips.size
  142.       @tips[i].update
  143.       unless @tips[i].visible
  144.         @tips[i].dispose
  145.         @tips[i] = nil
  146.         clear_data = true
  147.       end
  148.     end
  149.     @tips.compact! if clear_data
  150.     wwyralias_update_for_tips
  151.   end
  152. end
  153. Graphics.tip_init
  154. #代码测试
  155. loop do
  156.   Graphics.tips(["0", "1", "2"]) if Graphics.frame_count % 9 == 0
  157.   #Graphics.tip(Graphics.frame_count.to_s) if Graphics.frame_count % 4 == 0
  158.   Graphics.update
  159. end
复制代码

点评

大佬,能不能弄一个开关,当开关打开的时候提示窗口只有1个,提示更新的时候只刷新文本内容,就和默认的1个窗口一样。  发表于 2022-11-19 19:27
感谢!  发表于 2022-11-18 10:14
再把宽度高度参数删除掉  发表于 2022-11-17 22:58
78行draw_text改为dl_draw_text就行了  发表于 2022-11-17 22:57
大佬能帮我把主楼的多功能文本整合进去吗  发表于 2022-11-17 22:52

评分

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

查看全部评分

回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部