Project1
标题: 求解释脚本内容 [打印本页]
作者: 柳妹妹 时间: 2013-12-14 23:43
标题: 求解释脚本内容
本帖最后由 柳妹妹 于 2013-12-15 12:45 编辑
#--------------------------------------------------------------------------
# ● 描绘项目
# 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
#--------------------------------------------------------------------------
# ● 描绘项目
# 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
作者: 774741359 时间: 2013-12-15 00:12
这一段脚本取自 Window_Item
这个方法的用途为:绘制一个道具
#--------------------------------------------------------------------------
# ● 描绘项目
# 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
#--------------------------------------------------------------------------
# ● 描绘项目
# 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
其实很简单,如果说有点复杂,也就是语法掌握不熟练。
需要详细解释的是下面的坐标计算。
# 这里是计算实际坐标[相对于游戏窗口]
# 这个坐标用于绘制图标
# 4=左侧起始间空,index=当前物品顺序ID
# %2 这个2是代表一行就显示两个,修改这个2可以改变一行显示的数量。
# *(288+32) 应该为项目宽
x = 4 + index % 2 * (288 + 32)
# index/2 这个2和上面的2为相同意义,必须相同。
# *32为行高
y = index / 2 * 32
# 这里是计算实际坐标[相对于游戏窗口]
# 这个坐标用于绘制图标
# 4=左侧起始间空,index=当前物品顺序ID
# %2 这个2是代表一行就显示两个,修改这个2可以改变一行显示的数量。
# *(288+32) 应该为项目宽
x = 4 + index % 2 * (288 + 32)
# index/2 这个2和上面的2为相同意义,必须相同。
# *32为行高
y = index / 2 * 32
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |