查看: 2323|回复: 1

[已经解决] 求解释脚本内容

[复制链接]
梦石
0
星屑
374
在线时间
55 小时
注册时间
2013-12-6
回帖
15
发表于 2013-12-14 23:43:20 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 柳妹妹 于 2013-12-15 12:45 编辑

[pre lang="ruby" line="1"]  #--------------------------------------------------------------------------
  # ● 描绘项目
  #     index : 项目编号
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    if item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      self.contents.font.color = Color.new(64,70,124,255)
    else
      self.contents.font.color = Color.new(224,96,112,255)
    end
    x = 4 + index % 3 * (288 + 32)
    y = index / 3 * 32
   
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.font.bold = false
    self.contents.fill_rect(rect, Color.new(64,70,124,0))
    #bitmap = RPG::Cache.icon(item.icon_name)
    #self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    opacity = self.contents.font.color == Color.new(224,96,112,255) ? 255 : 128.
    #self.contents.font.color = Color.new(64,70,124,255)
     self.contents.draw_text(x + 4, y, 212, 32, item.name, 0)
     self.contents.draw_text(x + 190, y, 16, 32, "X", 1)
     self.contents.draw_text(x + 210, y, 24, 32, number.to_s, 2)
  end
[/pre]
梦石
0
星屑
100
在线时间
211 小时
注册时间
2011-8-16
回帖
246
发表于 2013-12-15 00:12:01 | 显示全部楼层
这一段脚本取自 Window_Item
这个方法的用途为:绘制一个道具
[pre lang="ruby" line="1"]  #--------------------------------------------------------------------------
  # ● 描绘项目
  #     index : 项目编号
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]          # 从data数组里获取第index号数据
    # 判断物品类型,并获得他们的持有数量
    case item                    
    when RPG::Item  # 物品
      number = $game_party.item_number(item.id)
    when RPG::Weapon# 武器
      number = $game_party.weapon_number(item.id)
    when RPG::Armor # 防具
      number = $game_party.armor_number(item.id)
    end
    # 判断能否使用,可使用=>字体颜色正常;不可使用=>字体颜色为无效颜色
    if item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    # 这里是计算实际坐标[相对于游戏窗口]
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    # 获取绘制图标的矩形
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    # 填充矩形 不知所意  去掉无妨
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    # 获取图标
    bitmap = RPG::Cache.icon(item.icon_name)
    # 判断不透明度,如果可使用=>完全不透明 如果不可使用=>半透明
    opacity = self.contents.font.color == normal_color ? 255 : 128
    # 绘制图标
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    # 绘制道具名
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    # 绘制一个冒号
    self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
    # 绘制持有数量
    self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  end[/pre]

其实很简单,如果说有点复杂,也就是语法掌握不熟练。
需要详细解释的是下面的坐标计算。
[pre lang="ruby" line="1"]    # 这里是计算实际坐标[相对于游戏窗口]
    # 这个坐标用于绘制图标
    # 4=左侧起始间空,index=当前物品顺序ID
    # %2 这个2是代表一行就显示两个,修改这个2可以改变一行显示的数量。
    # *(288+32) 应该为项目宽
    x = 4 + index % 2 * (288 + 32)
    # index/2 这个2和上面的2为相同意义,必须相同。
    # *32为行高
    y = index / 2 * 32[/pre]

点评

哦,谢谢,懂了!  发表于 2013-12-15 00:14
RPGMaker 脚本/学习交流群:143356012
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部