#--------------------------------------------------------------------------
# 作者:Daviant(蚂蚁)
#-------------------------------------------------------------------------- class Debuger
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def initialize
@time = Graphics.frame_count # 获取刷新次数
@p = 0 # Y轴偏移
@px = 0 # X轴偏移
@line = 0 # 当前行
@col = 0 # 当前列
@f = 16 # 字体大小
end
#--------------------------------------------------------------------------
# ● 创建
#--------------------------------------------------------------------------
def create
dispose # 先把之前的状态全部释放
@sprite = Sprite.new
@bitmap = Bitmap.new(6400, 6400*2)
@content = Bitmap.new(640, 480)
@content.fill_rect(0, 0, 640, 480, Color.new(0,0,0, 150))
@sprite.bitmap = @content
@bitmap.font.color = Color.new(0,255,0) #初始化颜色
@bitmap.font.size = @f
end
#--------------------------------------------------------------------------
# ● 释放
#--------------------------------------------------------------------------
def dispose
if @sprite
@sprite.dispose
end
if @bitmap
@bitmap.dispose
@content.dispose
end
end
#--------------------------------------------------------------------------
# ● 写文本到Debuger
# text : 输出内容
#--------------------------------------------------------------------------
def write( text )
while ((c = text.slice!(/./m)) != nil )
if c == "\n"
@line = @line + 1
@col = 0
elsif c == "\001"
# 这里可以扩展颜色管理
@bitmap.font.bold = false
@bitmap.font.color = Color.new(0,255,0)
elsif c == "\002" # 内容样式
@bitmap.font.bold = false
@bitmap.font.color = Color.new(0,174,192)
elsif c == "\003" # 内容样式2
@bitmap.font.bold = false
@bitmap.font.color = Color.new(237,144,243)
elsif c == "\004" # 属性样式
@bitmap.font.bold = false
@bitmap.font.color = Color.new(243,220,144)
elsif c == "\005" # 方法样式
@bitmap.font.color = Color.new(243,150,144)
@bitmap.font.bold = true
else
if c[0] > 33 && c[0] < 128
@bitmap.draw_text(@col, (@line-1)*@f, 640, @f, c)
@col = @col + @f/2
else
@bitmap.draw_text(@col, (@line-1)*@f, 640, @f, c)
@col = @col + @f
end
end
end
end
#--------------------------------------------------------------------------
# ● 输出
# vars : 要观察的信息变量
# f : 字体大小
#--------------------------------------------------------------------------
def log( vars, f = 22 )
# 初始化
@p = 0
@px = 0
@line = 0
@col = 0
@f = f
create
# 创建信息
message = "\n"
message = message + " \001所属类: \002"+vars.class.to_s+"\n"
message = message + " \001内容: \003"+vars.to_s + "\n"
t = vars.methods
i = 0
attrs = []
attrsM = ""
metsM = ""
mets = []
logic = false
for i in 0...t.length
# 获取属性表
c = t logic = c[0] > 64 && c[0] < 91
logic = logic || c[0] > 96 && c[0] < 124
logic = logic || c[0] > 127
if logic && c[c.length-1] == 61
# p c[0].to_s + " " + c[c.length-1].to_s
#p c
attrs.push(c.slice(0, c.length - 1))
tmp = " "
tmp = eval("vars."+attrs[attrs.length-1]).to_s
attrsM = attrsM + " \004" + attrs[attrs.length-1] + ":\002"+ tmp +"\n"
else
mets.push(c)
end
end
# 获取方法表
for i in 0...attrs.length
mets.delete(attrs)
end
for i in 0...mets.length
metsM = metsM + " \002[ \005"+mets+" \002]\n"
end
# 拼接信息
message = message + " \001属性: \002共"+attrs.length.to_s+"个 \n"
message = message + attrsM + "\n"
message = message + " \001方法:\002共"+mets.length.to_s+"个 \n"
message = message + metsM + "\n\001"
# 写出
write( message )
@content.blt(0, 0, @bitmap, Rect.new(@px*@f/2,@p*24,640,480))
@sprite.z = 10000
Graphics.transition
# 等待操作
wait
end
#--------------------------------------------------------------------------
# ● 等待
#--------------------------------------------------------------------------
def wait
loop do
Graphics.update
Input.update
if Input.press?(Input::UP)
@p = @p - 1
@content.fill_rect(0, 0, 640, 480, Color.new(0,0,0, 150))
@content.blt(0, 0, @bitmap, Rect.new(@px*@f/4,@p*6,640,480))
end
if Input.press?(Input::DOWN)
@p = @p + 1
@content.fill_rect(0, 0, 640, 480, Color.new(0,0,0, 150))
@content.blt(0, 0, @bitmap, Rect.new(@px*@f/4,@p*6,640,480))
end
if Input.press?(Input::LEFT)
@px = @px + 1
@content.fill_rect(0, 0, 640, 480, Color.new(0,0,0, 150))
@content.blt(0, 0, @bitmap, Rect.new(@px*@f/4,@p*6,640,480))
end
if Input.press?(Input::RIGHT)
@px = @px - 1
@content.fill_rect(0, 0, 640, 480, Color.new(0,0,0, 150))
@content.blt(0, 0, @bitmap, Rect.new(@px*@f/4,@p*6,640,480))
end
if Input.trigger?(Input::B)
dispose
break
end
end
end
end