设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3319|回复: 5
打印 上一主题 下一主题

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

[复制链接]

Lv4.逐梦者

梦石
0
星屑
13096
在线时间
3787 小时
注册时间
2013-7-18
帖子
2279
跳转到指定楼层
1
发表于 2018-11-9 19:53:51 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
RUBY 代码复制
  1. # X☆R:状态防御描述
  2.     if @item.guard_state_set != []
  3.       draw_text(x, y, "防御:", SYSTEM_COLOR)
  4.       txt = ""
  5.       @item.guard_state_set.each{|i| txt += "/ #{$data_states[i].name} "}
  6.       txt.sub!("/","")
  7.       draw_text(x+52, y, txt, COMMON_COLOR)
  8.     end
  9.     y += @item.guard_state_set != [] ? 38 : 8
  10.     set_description(y)
  11.   end


如何写属性防御描述代码?显示在状态防御描述上面
山岚野人,快人快语,礼数不周,还望海涵....

Lv5.捕梦者 (版主)

梦石
1
星屑
23963
在线时间
3338 小时
注册时间
2011-7-8
帖子
3925

开拓者

2
发表于 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 网络脚本 *
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
13096
在线时间
3787 小时
注册时间
2013-7-18
帖子
2279
3
 楼主| 发表于 2018-11-12 09:34:23 | 只看该作者
guoxiaomi 发表于 2018-11-11 13:16
复制这一段,把guard_state_set 改成 guard_element_set,放到前面就行:



RUBY 代码复制
  1. #信息说明窗口
  2. class Explain < Sprite
  3.   #--------------------------------------------------------------------------
  4.   BACK_COLOR    = Color.new(40, 40, 40)      #<= 信息窗口底色。
  5.   #--------------------------------------------------------------------------
  6.   SYSTEM_COLOR  = Color.new(230,230, 250)  #<= 系统文字颜色。
  7.   #--------------------------------------------------------------------------
  8.   COMMON_COLOR  = Color.new(128, 235, 28)    #<= 一般文字颜色。
  9.   #--------------------------------------------------------------------------
  10.   SPECIAL_COLOR = Color.new(225, 0, 20)    #<= 特殊文字颜色。
  11.   #--------------------------------------------------------------------------
  12.   WARN_COLOR    = Color.new(160, 0, 0)      #<= 警告文字颜色。
  13.   #--------------------------------------------------------------------------
  14.   BOTTOM_COLOR  = Color.new(0, 0, 0)        #<= 文字阴影颜色。
  15.   #===========================================================================
  16.   attr_accessor :item
  17.   #--------------------------------------------------------------------------
  18.   # X☆R:初始化。
  19.   #--------------------------------------------------------------------------
  20.   def initialize
  21.     super()
  22.     self.x = 358        #<= 信息窗口X坐标。
  23.     self.z = 999        #<= 信息窗口Z值。
  24.     self.opacity = 205  #<= 信息窗口透明度。
  25.     @item = nil
  26.   end
  27.   #--------------------------------------------------------------------------
  28.   # X☆R:释放。
  29.   #--------------------------------------------------------------------------
  30.   def dispose
  31.     self.bitmap.dispose if self.bitmap
  32.     super
  33.   end
  34.   #--------------------------------------------------------------------------
  35.   # X☆R:计算窗口高度。
  36.   #--------------------------------------------------------------------------
  37.   def height_calculation
  38.     height = 140
  39.     case @item
  40.     when RPG::Item
  41.       height += 30 if @item.recover_hp > 0 or @item.recover_hp_rate > 0
  42.       height += 30 if @item.recover_sp > 0 or @item.recover_sp_rate > 0
  43.       height += 30 if @item.parameter_type > 0
  44.     when RPG::Weapon
  45.       height += 30 if @item.element_set != []
  46.       height += 30 if @item.atk > 0
  47.       height += 30 if @item.pdef > 0
  48.       height += 30 if @item.mdef > 0
  49.       data  = @item.str_plus > 0 ? 1 : 0
  50.       data += @item.dex_plus > 0 ? 1 : 0
  51.       data += @item.agi_plus > 0 ? 1 : 0
  52.       data += @item.int_plus > 0 ? 1 : 0
  53.       height += 30 * (data / 2 + data % 2)
  54.       height += 30 if @item.plus_state_set != []
  55.     when RPG::Armor
  56.       height += 30 if @item.pdef > 0
  57.       height += 30 if @item.mdef > 0
  58.       data  = @item.str_plus > 0 ? 1 : 0
  59.       data += @item.dex_plus > 0 ? 1 : 0
  60.       data += @item.agi_plus > 0 ? 1 : 0
  61.       data += @item.int_plus > 0 ? 1 : 0
  62.       height += 30 * (data / 2 + data % 2)
  63.       height += 30 if @item.guard_state_set != []
  64.     end
  65.     return height
  66.   end
  67.   #--------------------------------------------------------------------------
  68.   # X☆R: 刷新。
  69.   #--------------------------------------------------------------------------
  70.   def refresh
  71.     self.bitmap.dispose if self.bitmap
  72.     return unless @item
  73.     self.bitmap = Bitmap.new(246, height_calculation)
  74.     self.bitmap.fill_rect(0, 0, 246, self.bitmap.height, BACK_COLOR)
  75.     self.bitmap.font.size = 20
  76.     self.bitmap.font.bold = true
  77.     # X☆R:物品名描述
  78.     bitmap = RPG::Cache.icon(@item.icon_name)
  79.     self.bitmap.blt(6, 6, bitmap, Rect.new(0, 0, 24, 24))
  80.     color = @item.methods.include?('color_n') ? get_color(@item.color_n) : COMMON_COLOR
  81.     draw_text(34, 8, @item.name, color)
  82.     self.bitmap.font.size = 18
  83.     case @item
  84.     when RPG::Item
  85.       set_item
  86.     when RPG::Weapon
  87.       set_weapon
  88.     when RPG::Armor
  89.       set_armor
  90.     end
  91.   end
  92.   #--------------------------------------------------------------------------
  93.   # X☆R:文字阴影。
  94.   #--------------------------------------------------------------------------
  95.   def draw_text(x, y, txt, color)
  96.     cx = self.bitmap.text_size(txt).width
  97.     self.bitmap.font.color = BOTTOM_COLOR
  98.     self.bitmap.draw_text(x+1, y+1, cx, 20, txt)
  99.     self.bitmap.font.color = color
  100.     self.bitmap.draw_text(x, y, cx, 20, txt)
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # X☆R:颜色。
  104.   #--------------------------------------------------------------------------
  105.   def get_color(n)
  106.     case n
  107.     when 0 :return Color.new(255, 255, 255)
  108.  
  109.     when 1 :return Color.new(154, 205, 0, 255)
  110.  
  111.     when 2 :return Color.new(0, 191, 255, 255)
  112.  
  113.     when 3 :return Color.new(215, 0, 65, 255)
  114.  
  115.     when 4 :return Color.new(148, 0, 175, 255)
  116.  
  117.     when 5 :return Color.new(255, 185, 15, 255)
  118.  
  119.     when 6 :return Color.new(205, 137, 0, 255)
  120.  
  121.     when 7 :return Color.new(192, 192, 192)
  122.     end
  123.     return Color.new(255, 255, 255)
  124.   end
  125.   #--------------------------------------------------------------------------
  126.   # X☆R:设置物品。
  127.   #--------------------------------------------------------------------------
  128.   def set_item
  129.     x = 6; y = 42
  130.     # X☆R:使用场合描述
  131.     draw_text(x, y, "使用场合:", SYSTEM_COLOR)
  132.     txt = ["随时","战斗中","菜单中","不能使用"][@item.occasion]
  133.     color = $game_party.item_can_use?(@item.id) ? COMMON_COLOR : WARN_COLOR
  134.     draw_text(x+92, y, txt, color)
  135.     y += 26
  136.     # X☆R:HP回复描述
  137.     if @item.recover_hp > 0 or @item.recover_hp_rate > 0
  138.       txt = "回复#{$data_system.words.hp}:"
  139.       cx = self.bitmap.text_size(txt).width
  140.       draw_text(x, y, txt, SYSTEM_COLOR)
  141.       txt = @item.recover_hp > 0 ? "#{@item.recover_hp}" : ""
  142.       txt += " + " if @item.recover_hp > 0 and @item.recover_hp_rate > 0
  143.       txt += @item.recover_hp_rate > 0 ? "#{@item.recover_hp_rate}%" : ""
  144.       draw_text(x+cx+6, y, txt, COMMON_COLOR)
  145.       y += 26
  146.     end
  147.     # X☆R:SP回复描述
  148.     if @item.recover_sp > 0 or @item.recover_sp_rate > 0
  149.       txt = "回复#{$data_system.words.sp}:"
  150.       cx = self.bitmap.text_size(txt).width
  151.       draw_text(x, y, txt, SYSTEM_COLOR)
  152.       txt = @item.recover_sp > 0 ? "#{@item.recover_sp}" : ""
  153.       txt += " + " if @item.recover_sp > 0 and @item.recover_sp_rate > 0
  154.       txt += @item.recover_sp_rate > 0 ? "#{@item.recover_sp_rate}%" : ""
  155.       draw_text(x+cx+6, y, txt, COMMON_COLOR)
  156.       y += 26
  157.     end
  158.     # X☆R:能力值增加描述
  159.     if @item.parameter_type > 0
  160.       txt = ["","Max#{$data_system.words.hp}",
  161.       "Max#{$data_system.words.sp}",
  162.       $data_system.words.str,
  163.       $data_system.words.dex,
  164.       $data_system.words.agi,
  165.       $data_system.words.int]
  166.       [@item.parameter_type]
  167.       cx = self.bitmap.text_size(txt).width
  168.       draw_text(x, y, txt, SYSTEM_COLOR)
  169.       draw_text(x+cx+6, y, "+ #{@item.parameter_points}", COMMON_COLOR)
  170.       y += 26
  171.     end
  172.     y += 12
  173.     set_description(y)
  174.   end
  175.   #--------------------------------------------------------------------------
  176.   # X☆R:设置武器。
  177.   #--------------------------------------------------------------------------
  178.   def set_weapon
  179.     x = 6; y = 42
  180.     # X☆R:属性描述
  181.     draw_text(x, y, "属性:", SYSTEM_COLOR)
  182.     txt = ""
  183.     if @item.element_set != []
  184.       @item.element_set.each{|i| txt += "/ #{$data_system.elements[i]} "}
  185.     else
  186.       txt += "--"
  187.     end
  188.     txt.sub!("/","")
  189.     draw_text(x+52, y, txt, COMMON_COLOR)
  190.     y += 30
  191.     # X☆R:攻击力描述
  192.     if @item.atk > 0
  193.       draw_text(x, y, "#{$data_system.words.atk}:", SYSTEM_COLOR)
  194.       cx = self.bitmap.text_size("#{$data_system.words.atk}:").width
  195.       draw_text(x+cx+4, y, @item.atk.to_s, COMMON_COLOR)
  196.       y += 26
  197.     end
  198.     # X☆R:防御力描述
  199.     if @item.pdef > 0 or @item.mdef > 0
  200.       words = ["#{$data_system.words.pdef}:", "#{$data_system.words.mdef}:"]
  201.       text =[@item.pdef, @item.mdef]
  202.       for i in 0...text.size
  203.         next if text[i] == 0
  204.         draw_text(x, y, words[i], SYSTEM_COLOR)
  205.         cx = self.bitmap.text_size(words[i]).width
  206.         draw_text(x+cx+4, y, text[i].to_s, COMMON_COLOR)
  207.         y += 26
  208.       end
  209.     end
  210.     # X☆R:能力值增加描述
  211.     words = [$data_system.words.str, $data_system.words.dex,
  212.     $data_system.words.agi, $data_system.words.int]
  213.     text =[@item.str_plus,
  214.     @item.dex_plus,
  215.     @item.agi_plus,
  216.     @item.int_plus]
  217.     data = 0
  218.     for i in 0...text.size
  219.       if text[i] == 0
  220.         y += 30 if i == 3
  221.         next
  222.       end
  223.       ax = i % 2 * 120 + x ; data += 1
  224.       draw_text(ax, y, words[i], SYSTEM_COLOR)
  225.       cx = self.bitmap.text_size(words[i]).width
  226.       draw_text(ax+cx+12, y, " +#{text[i]}", COMMON_COLOR)
  227.       y += i == 3 ? 30 : (data == 2 ? 26 : 0)
  228.     end
  229.     y -= 30 if data == 0
  230.     # X☆R:附加状态描述
  231.     if @item.plus_state_set != []
  232.       draw_text(x, y, "附加:", SYSTEM_COLOR)
  233.       txt = ""
  234.       @item.element_set.each{|i| txt += "/ #{$data_states[i].name} "}
  235.       txt.sub!("/","")
  236.       draw_text(x+52, y, txt, COMMON_COLOR)
  237.     end
  238.     y += @item.plus_state_set != [] ? 38 : 8
  239.     set_description(y)
  240.   end
  241.   #--------------------------------------------------------------------------
  242.   # X☆R:设置防具。
  243.   #--------------------------------------------------------------------------
  244.   def set_armor
  245.     # X☆R:自动状态描述
  246.     if @item.auto_state_id > 0
  247.       txt = "〖#{$data_states[@item.auto_state_id].name}〗"
  248.       cx = self.bitmap.text_size(@item.name).width
  249.       draw_text(40+cx, 10, txt, SPECIAL_COLOR)
  250.     end
  251.     x = 6; y = 42
  252.     # X☆R:类型描述
  253.     draw_text(x, y, "类型:", SYSTEM_COLOR)
  254.     txt = [$data_system.words.armor1, $data_system.words.armor2,
  255.     $data_system.words.armor3, $data_system.words.armor4][@item.kind]
  256.     draw_text(x+52, y, txt, COMMON_COLOR)
  257.     y += 30
  258.     # X☆R:防御力描述
  259.     if @item.pdef > 0 or @item.mdef > 0
  260.       words = ["#{$data_system.words.pdef}:", "#{$data_system.words.mdef}:"]
  261.       text =[@item.pdef, @item.mdef]
  262.       for i in 0...text.size
  263.         next if text[i] == 0
  264.         draw_text(x, y, words[i], SYSTEM_COLOR)
  265.         cx = self.bitmap.text_size(words[i]).width
  266.         draw_text(x+cx+4, y, text[i].to_s, COMMON_COLOR)
  267.         y += 26
  268.       end
  269.     end
  270.     # X☆R:能力值增加描述
  271.     words = [$data_system.words.str, $data_system.words.dex,
  272.     $data_system.words.agi, $data_system.words.int]
  273.     text =[@item.str_plus, @item.dex_plus, @item.agi_plus, @item.int_plus]
  274.     data = 0
  275.     for i in 0...text.size
  276.       if text[i] == 0
  277.         y += 30 if i == 3
  278.         next
  279.       end
  280.       ax = i % 2 * 120 + x ; data += 1
  281.       draw_text(ax, y, words[i], SYSTEM_COLOR)
  282.       cx = self.bitmap.text_size(words[i]).width
  283.       draw_text(ax+cx+12, y, " +#{text[i]}", COMMON_COLOR)
  284.       y += i == 3 ? 30 : (data == 2 ? 26 : 0)
  285.     end
  286.     y -= 30 if data == 0
  287.  
  288.       # X☆R:属性防御描述
  289.         if @item.guard_element_set != []
  290.       draw_text(x, y, "防御:", SYSTEM_COLOR)
  291.       txt = ""
  292.       @item.guard_element_set.each{|i| txt += "/ #{$data_system.elements[i]} "}
  293.       txt.sub!("/","")
  294.       draw_text(x+52, y, txt, COMMON_COLOR)
  295.     end
  296.     y += @item.guard_element_set != [] ? 38 : 8
  297.     set_description(y)
  298.  
  299.      # X☆R:状态防御描述
  300.     if @item.guard_state_set != []
  301.       draw_text(x, y, "防御:", SYSTEM_COLOR)
  302.       txt = ""
  303.       @item.guard_state_set.each{|i| txt += "/ #{$data_states[i].name} "}
  304.       txt.sub!("/","")
  305.       draw_text(x+52, y, txt, COMMON_COLOR)
  306.     end
  307.     y += @item.guard_state_set != [] ? 38 : 8
  308.     set_description(y)
  309.       end
  310.  
  311.   #--------------------------------------------------------------------------
  312.   # X☆R:设置说明。
  313.   #--------------------------------------------------------------------------
  314.   def set_description(y)
  315.     text = @item.description.scan(/./)
  316.     ax = 24; ay = y
  317.     for i in 0...text.size
  318.       txt = text[i]
  319.       if (ax+18) > 240
  320.         ax = 6; ay += 40
  321.         break if ay + 20 > self.bitmap.height
  322.       end
  323.       draw_text(ax,ay,txt,SYSTEM_COLOR)
  324.       ax += 18
  325.     end
  326.   end
  327.   #--------------------------------------------------------------------------
  328.   # X☆R:刷新画面。
  329.   #--------------------------------------------------------------------------
  330.   def update
  331.     super
  332.     if @data_item != @item
  333.       @data_item = @item
  334.       refresh
  335.     end
  336.     return if @item.nil?
  337.     # X☆R:坐标限制,保证窗口完全在屏幕内。
  338.     self.x = [[self.x, 0].max, 394].min
  339.     self.y = [[self.y, 0].max, 480 - self.bitmap.height].min
  340.   end
  341. end


防具设置,直接复制到上面,出现了文字重叠,而且说明文字出现了两次,怎么办?
山岚野人,快人快语,礼数不周,还望海涵....
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-26 04:21

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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