#信息说明窗口
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[i]} "}
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[i] == 0
draw_text(x, y, words[i], SYSTEM_COLOR)
cx = self.bitmap.text_size(words[i]).width
draw_text(x+cx+4, y, text[i].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[i] == 0
y += 30 if i == 3
next
end
ax = i % 2 * 120 + x ; data += 1
draw_text(ax, y, words[i], SYSTEM_COLOR)
cx = self.bitmap.text_size(words[i]).width
draw_text(ax+cx+12, y, " +#{text[i]}", 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[i].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[i] == 0
draw_text(x, y, words[i], SYSTEM_COLOR)
cx = self.bitmap.text_size(words[i]).width
draw_text(x+cx+4, y, text[i].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[i] == 0
y += 30 if i == 3
next
end
ax = i % 2 * 120 + x ; data += 1
draw_text(ax, y, words[i], SYSTEM_COLOR)
cx = self.bitmap.text_size(words[i]).width
draw_text(ax+cx+12, y, " +#{text[i]}", 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[i]} "}
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[i].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[i]
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