查看: 3983|回复: 5

[已经解决] 属性防御描述

[复制链接]
梦石
0
星屑
17561
在线时间
4249 小时
注册时间
2013-7-18
回帖
2491
发表于 2018-11-9 19:53:51 | 显示全部楼层 |阅读模式

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

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

×
[pre lang="ruby"] # X☆R:状态防御描述
    if @item.guard_state_set != []
      draw_text(x, y, "防御:", SYSTEM_COLOR)
      txt = ""
      @item.guard_state_set.each{|i| txt += "/ #{$data_states.name} "}
      txt.sub!("/","")
      draw_text(x+52, y, txt, COMMON_COLOR)
    end
    y += @item.guard_state_set != [] ? 38 : 8
    set_description(y)
  end[/pre]

如何写属性防御描述代码?显示在状态防御描述上面
退隐....
梦石
1
星屑
24088
在线时间
3339 小时
注册时间
2011-7-8
回帖
3862

开拓者

发表于 2018-11-11 13:16:40 | 显示全部楼层
复制这一段,把guard_state_set 改成 guard_element_set,放到前面就行:
  1.     if @item.guard_elememt_set != []
  2.       draw_text(x, y, "防御:", SYSTEM_COLOR)
  3.       txt = ""
  4.       @item.guard_elememt_set.each{|i| txt += "/ #{$data_system.elements[i]} "}
  5.       txt.sub!("/","")
  6.       draw_text(x+52, y, txt, COMMON_COLOR)
  7.     end
  8.     y += @item.guard_elememt_set != [] ? 38 : 8
  9.     set_description(y)
复制代码

点评

可以了,谢谢  发表于 2018-11-13 19:14
去掉最后一行试试看?  发表于 2018-11-13 16:30
不错,多谢,可以了,就是还有点问题,说明文字出现了两次,位置也重合了  发表于 2018-11-12 09:29

评分

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

查看全部评分

熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复

使用道具 举报

梦石
0
星屑
17561
在线时间
4249 小时
注册时间
2013-7-18
回帖
2491
 楼主| 发表于 2018-11-12 09:34:23 | 显示全部楼层
guoxiaomi 发表于 2018-11-11 13:16
复制这一段,把guard_state_set 改成 guard_element_set,放到前面就行:

QQ图片20181112093208.png

[pre lang="ruby"]#信息说明窗口
class Explain < Sprite
  #--------------------------------------------------------------------------
  BACK_COLOR    = Color.new(40, 40, 40)      #<= 信息窗口底色。
  #--------------------------------------------------------------------------
  SYSTEM_COLOR  = Color.new(230,230, 250)  #<= 系统文字颜色。
  #--------------------------------------------------------------------------
  COMMON_COLOR  = Color.new(128, 235, 28)    #<= 一般文字颜色。
  #--------------------------------------------------------------------------
  SPECIAL_COLOR = Color.new(225, 0, 20)    #<= 特殊文字颜色。
  #--------------------------------------------------------------------------
  WARN_COLOR    = Color.new(160, 0, 0)      #<= 警告文字颜色。
  #--------------------------------------------------------------------------
  BOTTOM_COLOR  = Color.new(0, 0, 0)        #<= 文字阴影颜色。
  #===========================================================================
  attr_accessor :item
  #--------------------------------------------------------------------------
  # X☆R:初始化。
  #--------------------------------------------------------------------------
  def initialize
    super()
    self.x = 358        #<= 信息窗口X坐标。
    self.z = 999        #<= 信息窗口Z值。
    self.opacity = 205  #<= 信息窗口透明度。
    @item = nil
  end
  #--------------------------------------------------------------------------
  # X☆R:释放。
  #--------------------------------------------------------------------------
  def dispose
    self.bitmap.dispose if self.bitmap
    super
  end
  #--------------------------------------------------------------------------
  # X☆R:计算窗口高度。
  #--------------------------------------------------------------------------
  def height_calculation
    height = 140
    case @item
    when RPG::Item
      height += 30 if @item.recover_hp > 0 or @item.recover_hp_rate > 0
      height += 30 if @item.recover_sp > 0 or @item.recover_sp_rate > 0
      height += 30 if @item.parameter_type > 0
    when RPG::Weapon
      height += 30 if @item.element_set != []
      height += 30 if @item.atk > 0
      height += 30 if @item.pdef > 0
      height += 30 if @item.mdef > 0
      data  = @item.str_plus > 0 ? 1 : 0
      data += @item.dex_plus > 0 ? 1 : 0
      data += @item.agi_plus > 0 ? 1 : 0
      data += @item.int_plus > 0 ? 1 : 0
      height += 30 * (data / 2 + data % 2)
      height += 30 if @item.plus_state_set != []
    when RPG::Armor
      height += 30 if @item.pdef > 0
      height += 30 if @item.mdef > 0
      data  = @item.str_plus > 0 ? 1 : 0
      data += @item.dex_plus > 0 ? 1 : 0
      data += @item.agi_plus > 0 ? 1 : 0
      data += @item.int_plus > 0 ? 1 : 0
      height += 30 * (data / 2 + data % 2)
      height += 30 if @item.guard_state_set != []
    end
    return height
  end
  #--------------------------------------------------------------------------
  # X☆R: 刷新。
  #--------------------------------------------------------------------------
  def refresh
    self.bitmap.dispose if self.bitmap
    return unless @item
    self.bitmap = Bitmap.new(246, height_calculation)
    self.bitmap.fill_rect(0, 0, 246, self.bitmap.height, BACK_COLOR)
    self.bitmap.font.size = 20
    self.bitmap.font.bold = true
    # X☆R:物品名描述
    bitmap = RPG::Cache.icon(@item.icon_name)
    self.bitmap.blt(6, 6, bitmap, Rect.new(0, 0, 24, 24))
    color = @item.methods.include?('color_n') ? get_color(@item.color_n) : COMMON_COLOR
    draw_text(34, 8, @item.name, color)
    self.bitmap.font.size = 18
    case @item
    when RPG::Item
      set_item
    when RPG::Weapon
      set_weapon
    when RPG::Armor
      set_armor
    end
  end
  #--------------------------------------------------------------------------
  # X☆R:文字阴影。
  #--------------------------------------------------------------------------
  def draw_text(x, y, txt, color)
    cx = self.bitmap.text_size(txt).width
    self.bitmap.font.color = BOTTOM_COLOR
    self.bitmap.draw_text(x+1, y+1, cx, 20, txt)
    self.bitmap.font.color = color
    self.bitmap.draw_text(x, y, cx, 20, txt)
  end
  #--------------------------------------------------------------------------
  # X☆R:颜色。
  #--------------------------------------------------------------------------
  def get_color(n)
    case n
    when 0 :return Color.new(255, 255, 255)
      
    when 1 :return Color.new(154, 205, 0, 255)
      
    when 2 :return Color.new(0, 191, 255, 255)
      
    when 3 :return Color.new(215, 0, 65, 255)
      
    when 4 :return Color.new(148, 0, 175, 255)
      
    when 5 :return Color.new(255, 185, 15, 255)
      
    when 6 :return Color.new(205, 137, 0, 255)
      
    when 7 :return Color.new(192, 192, 192)
    end
    return Color.new(255, 255, 255)
  end
  #--------------------------------------------------------------------------
  # X☆R:设置物品。
  #--------------------------------------------------------------------------
  def set_item
    x = 6; y = 42
    # X☆R:使用场合描述
    draw_text(x, y, "使用场合:", SYSTEM_COLOR)
    txt = ["随时","战斗中","菜单中","不能使用"][@item.occasion]
    color = $game_party.item_can_use?(@item.id) ? COMMON_COLOR : WARN_COLOR
    draw_text(x+92, y, txt, color)
    y += 26
    # X☆R:HP回复描述
    if @item.recover_hp > 0 or @item.recover_hp_rate > 0
      txt = "回复#{$data_system.words.hp}:"
      cx = self.bitmap.text_size(txt).width
      draw_text(x, y, txt, SYSTEM_COLOR)
      txt = @item.recover_hp > 0 ? "#{@item.recover_hp}" : ""
      txt += " + " if @item.recover_hp > 0 and @item.recover_hp_rate > 0
      txt += @item.recover_hp_rate > 0 ? "#{@item.recover_hp_rate}%" : ""
      draw_text(x+cx+6, y, txt, COMMON_COLOR)
      y += 26
    end
    # X☆R:SP回复描述
    if @item.recover_sp > 0 or @item.recover_sp_rate > 0
      txt = "回复#{$data_system.words.sp}:"
      cx = self.bitmap.text_size(txt).width
      draw_text(x, y, txt, SYSTEM_COLOR)
      txt = @item.recover_sp > 0 ? "#{@item.recover_sp}" : ""
      txt += " + " if @item.recover_sp > 0 and @item.recover_sp_rate > 0
      txt += @item.recover_sp_rate > 0 ? "#{@item.recover_sp_rate}%" : ""
      draw_text(x+cx+6, y, txt, COMMON_COLOR)
      y += 26
    end
    # X☆R:能力值增加描述
    if @item.parameter_type > 0
      txt = ["","Max#{$data_system.words.hp}",
      "Max#{$data_system.words.sp}",
      $data_system.words.str,
      $data_system.words.dex,
      $data_system.words.agi,
      $data_system.words.int]
      [@item.parameter_type]
      cx = self.bitmap.text_size(txt).width
      draw_text(x, y, txt, SYSTEM_COLOR)
      draw_text(x+cx+6, y, "+ #{@item.parameter_points}", COMMON_COLOR)
      y += 26
    end
    y += 12
    set_description(y)
  end
  #--------------------------------------------------------------------------
  # X☆R:设置武器。
  #--------------------------------------------------------------------------
  def set_weapon
    x = 6; y = 42
    # X☆R:属性描述
    draw_text(x, y, "属性:", SYSTEM_COLOR)
    txt = ""
    if @item.element_set != []
      @item.element_set.each{|i| txt += "/ #{$data_system.elements} "}
    else
      txt += "--"
    end
    txt.sub!("/","")
    draw_text(x+52, y, txt, COMMON_COLOR)
    y += 30
    # X☆R:攻击力描述
    if @item.atk > 0
      draw_text(x, y, "#{$data_system.words.atk}:", SYSTEM_COLOR)
      cx = self.bitmap.text_size("#{$data_system.words.atk}:").width
      draw_text(x+cx+4, y, @item.atk.to_s, COMMON_COLOR)
      y += 26
    end
    # X☆R:防御力描述
    if @item.pdef > 0 or @item.mdef > 0
      words = ["#{$data_system.words.pdef}:", "#{$data_system.words.mdef}:"]
      text =[@item.pdef, @item.mdef]
      for i in 0...text.size
        next if text == 0
        draw_text(x, y, words, SYSTEM_COLOR)
        cx = self.bitmap.text_size(words).width
        draw_text(x+cx+4, y, text.to_s, COMMON_COLOR)
        y += 26
      end
    end
    # X☆R:能力值增加描述
    words = [$data_system.words.str, $data_system.words.dex,
    $data_system.words.agi, $data_system.words.int]
    text =[@item.str_plus,
    @item.dex_plus,
    @item.agi_plus,
    @item.int_plus]
    data = 0
    for i in 0...text.size
      if text == 0
        y += 30 if i == 3
        next
      end
      ax = i % 2 * 120 + x ; data += 1
      draw_text(ax, y, words, SYSTEM_COLOR)
      cx = self.bitmap.text_size(words).width
      draw_text(ax+cx+12, y, " +#{text}", COMMON_COLOR)
      y += i == 3 ? 30 : (data == 2 ? 26 : 0)
    end
    y -= 30 if data == 0
    # X☆R:附加状态描述
    if @item.plus_state_set != []
      draw_text(x, y, "附加:", SYSTEM_COLOR)
      txt = ""
      @item.element_set.each{|i| txt += "/ #{$data_states.name} "}
      txt.sub!("/","")
      draw_text(x+52, y, txt, COMMON_COLOR)
    end
    y += @item.plus_state_set != [] ? 38 : 8
    set_description(y)
  end
  #--------------------------------------------------------------------------
  # X☆R:设置防具。
  #--------------------------------------------------------------------------
  def set_armor
    # X☆R:自动状态描述
    if @item.auto_state_id > 0
      txt = "〖#{$data_states[@item.auto_state_id].name}〗"
      cx = self.bitmap.text_size(@item.name).width
      draw_text(40+cx, 10, txt, SPECIAL_COLOR)
    end
    x = 6; y = 42
    # X☆R:类型描述
    draw_text(x, y, "类型:", SYSTEM_COLOR)
    txt = [$data_system.words.armor1, $data_system.words.armor2,
    $data_system.words.armor3, $data_system.words.armor4][@item.kind]
    draw_text(x+52, y, txt, COMMON_COLOR)
    y += 30
    # X☆R:防御力描述
    if @item.pdef > 0 or @item.mdef > 0
      words = ["#{$data_system.words.pdef}:", "#{$data_system.words.mdef}:"]
      text =[@item.pdef, @item.mdef]
      for i in 0...text.size
        next if text == 0
        draw_text(x, y, words, SYSTEM_COLOR)
        cx = self.bitmap.text_size(words).width
        draw_text(x+cx+4, y, text.to_s, COMMON_COLOR)
        y += 26
      end
    end
    # X☆R:能力值增加描述
    words = [$data_system.words.str, $data_system.words.dex,
    $data_system.words.agi, $data_system.words.int]
    text =[@item.str_plus, @item.dex_plus, @item.agi_plus, @item.int_plus]
    data = 0
    for i in 0...text.size
      if text == 0
        y += 30 if i == 3
        next
      end
      ax = i % 2 * 120 + x ; data += 1
      draw_text(ax, y, words, SYSTEM_COLOR)
      cx = self.bitmap.text_size(words).width
      draw_text(ax+cx+12, y, " +#{text}", COMMON_COLOR)
      y += i == 3 ? 30 : (data == 2 ? 26 : 0)
    end
    y -= 30 if data == 0
   
      # X☆R:属性防御描述
        if @item.guard_element_set != []
      draw_text(x, y, "防御:", SYSTEM_COLOR)
      txt = ""
      @item.guard_element_set.each{|i| txt += "/ #{$data_system.elements} "}
      txt.sub!("/","")
      draw_text(x+52, y, txt, COMMON_COLOR)
    end
    y += @item.guard_element_set != [] ? 38 : 8
    set_description(y)
   
     # X☆R:状态防御描述
    if @item.guard_state_set != []
      draw_text(x, y, "防御:", SYSTEM_COLOR)
      txt = ""
      @item.guard_state_set.each{|i| txt += "/ #{$data_states.name} "}
      txt.sub!("/","")
      draw_text(x+52, y, txt, COMMON_COLOR)
    end
    y += @item.guard_state_set != [] ? 38 : 8
    set_description(y)
      end
   
  #--------------------------------------------------------------------------
  # X☆R:设置说明。
  #--------------------------------------------------------------------------
  def set_description(y)
    text = @item.description.scan(/./)
    ax = 24; ay = y
    for i in 0...text.size
      txt = text
      if (ax+18) > 240
        ax = 6; ay += 40
        break if ay + 20 > self.bitmap.height
      end
      draw_text(ax,ay,txt,SYSTEM_COLOR)
      ax += 18
    end
  end
  #--------------------------------------------------------------------------
  # X☆R:刷新画面。
  #--------------------------------------------------------------------------
  def update
    super
    if @data_item != @item
      @data_item = @item
      refresh
    end
    return if @item.nil?
    # X☆R:坐标限制,保证窗口完全在屏幕内。
    self.x = [[self.x, 0].max, 394].min
    self.y = [[self.y, 0].max, 480 - self.bitmap.height].min
  end
end
[/pre]

防具设置,直接复制到上面,出现了文字重叠,而且说明文字出现了两次,怎么办?
退隐....
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部