# 使用说明:
# Notification.post(信息) 发一则提示
# Notification.move(x,y,宽,高) 移动提示框位置(必须执行至少一次)
# Notification.clear 清除所有提示
# Notification.pause 为true期间post失效
# Notification.delay 新提示发布后提示延迟消失的时间(秒)
# Notification.opacity 不透明度,请配合pause一起使用
# Notification.font 提示字体(包括大小及颜色)
# Notification.limit 提示限制
Notification = Class.new do
attr_accessor :font, :msg
@@font = nil
@@sprite = Sprite.new
@@sprite.bitmap = Bitmap.new(1,1)
@@sprite.z = 999999
@@limit = 20
@@delay = 3
@@opacity = 0
@@pause = false
@@count = @@delay * 40
def self.move(x,y,width,height)
@@sprite.x = x
@@sprite.y = y
@@sprite.bitmap.dispose
@@sprite.bitmap = Bitmap.new(width, height)
self.redraw unless $game_system == nil
end
def self.limit=(max)
@@limit = max
end
def self.font
return @@font.nil? ? Font.new : @@font
end
def self.font=(fon)
@@font = fon
end
def self.post(msg)
return if @@pause
$game_system.notifications.push(new(msg))
while $game_system.notifications.size > 50
$game_system.notifications.delete_at(0)
end
self.redraw unless $game_system == nil
self.opacity = 255
@@count = @@delay * 40
end
def self.clear
$game_system.notifications = []
self.redraw
end
def self.redraw
b = @@sprite.bitmap
b.clear
b2 = Bitmap.new(b.width,640)
y = b.height
for n in $game_system.notifications.reverse[0,@@limit]
x = 0
y2 = 0
b2.font = n.font
h = b2.text_size(n.msg).height
n.msg.split('').each do |char|
if (x + b2.text_size(char).width) > b2.width
x = 0
y2 += h
end
b2.draw_text(x,y2,b2.width,h,char)
x += b2.text_size(char).width + 2
end
y -= (y2 + h)
b.blt(0,y,b2,Rect.new(0,0,b2.width,y2 + h))
b2.clear
y -= 4
end
b2.dispose
end
def self.update
return @@count -= 1 if @@count > 0
self.opacity -= 10 if self.opacity > 0
end
def initialize(msg)
@font = @@font.nil? ? Font.new : @@font.clone
@msg = msg
end
def self.show
@@sprite.visible = true
end
def self.hide
@@sprite.visible = false
end
def self.pause
return @@pause
end
def self.pause=(bool)
@@pause = true
end
def self.delay
return @@delay
end
def self.delay=(val)
@@delay = val
end
def self.opacity
return @@sprite.opacity
end
def self.opacity=(val)
@@sprite.opacity = val
end
def _dump(limit)
bin = []
bin.push(@font.size)
bin.push((@font.bold ? 1 : 0) + (@font.italic ? 16 : 0))
bin.push(@font.color.red)
bin.push(@font.color.green)
bin.push(@font.color.blue)
bin.push(@font.color.alpha)
bin = bin.pack("C*")
@font.name = [@font.name] unless !@font.name.is_a?(Array)
bin += (@font.name + [@msg]).join("\000:\000")
return bin
end
def self._load(bin)
bin = bin.unpack("C*")
no = new("")
no.font.size = bin.delete_at(0)
no.font.bold = (bin[0] % 16 > 0)
no.font.italic = (bin.delete_at(0) / 16 > 0)
no.font.color = Color.new(*bin[0,4])
bin[0,4]=[]
strs = bin.pack("C*").split("\000:\000")
no.msg = strs.delete_at(-1)
no.font.name = strs
return no
end
end
Game_System.class_eval do
attr_accessor :notifications
OrgInitialize4Notf = instance_method('initialize')
def initialize(*args)
OrgInitialize4Notf.bind(self).call(*args)
@notifications = []
end
end
Scene_Map.class_eval do
OrgMain4Notf = instance_method('main')
OrgUpdate4Notf = instance_method('update')
def main(*args)
Notification.show
OrgMain4Notf.bind(self).call(*args)
Notification.hide
end
def update(*args)
Notification.update
OrgUpdate4Notf.bind(self).call(*args)
end
end
Scene_Load.class_eval do
OrgReadData4Notf = instance_method('read_save_data')
def read_save_data(*args)
OrgReadData4Notf.bind(self).call(*args)
Notification.redraw
Notification.opacity = 0
end
end
Game_Party.class_eval do
OrgMeth4Notf = {}
["add_actor","remove_actor","gain_gold","gain_item","gain_weapon","gain_armor"].each do |meth|
OrgMeth4Notf[meth] = instance_method(meth)
end
def add_actor(id,*args)
actor = $game_actors[id]
if @actors.size < 4 and not @actors.include?(actor)
Notification.push(actor.name + "加入队伍!")
end
OrgMeth4Notf['add_actor'].bind(self).call(id,*args)
end
def remove_actor(id,*args)
actor = $game_actors[id]
if @actors.include?(actor)
Notification.push(actor.name + "离开队伍!")
end
OrgMeth4Notf['remove_actor'].bind(self).call(id,*args)
end
def gain_gold(*args)
gold_old = @gold
OrgMeth4Notf['gain_gold'].bind(self).call(*args)
if gold_old != @gold
value = @gold - gold_old
msg = "#{$game_party.actors[0].name}"+(value > 0 ? "得到" : "失去")+"了#{value.abs}#{$data_system.words.gold}"
Notification.post(msg)
end
end
def gain_item(id,*args)
num_old = item_number(id)
OrgMeth4Notf['gain_item'].bind(self).call(id,*args)
if num_old != item_number(id)
value = item_number(id) - num_old
msg = "#{$game_party.actors[0].name}"+(value > 0 ? "得到" : "失去")+"了#{value.abs}个#{$data_items[id].name}"
Notification.post(msg)
end
end
def gain_weapon(id,*args)
num_old = weapon_number(id)
OrgMeth4Notf['gain_weapon'].bind(self).call(id,*args)
if num_old != @gold
value = weapon_number(id) - num_old
msg = "#{$game_party.actors[0].name}"+(value > 0 ? "得到" : "失去")+"了#{value.abs}个#{$data_weapons[id].name}"
Notification.post(msg)
end
end
def gain_armor(id,*args)
num_old = armor_number(id)
OrgMeth4Notf['gain_armor'].bind(self).call(id,*args)
if num_old != @gold
value = armor_number(id) - num_old
msg = "#{$game_party.actors[0].name}"+(value > 0 ? "得到" : "失去")+"了#{value.abs}个#{$data_armors[id].name}"
Notification.post(msg)
end
end
end