#====================================================================================
# Debuger调试器 version:demo2.0
# 作者及其版权:蚂蚁 允许修改
# 使用方法:
# 1:你需要初始化这个插件,建议将这一句 $debug = Debuger.new 放在main里面
# 2:当你要观察某个变量时,你可以这样 $debug.log( 要观察的变量 )
# 3:在debuger控制台中,你可以这样操作:
# (1)方向键控制显示区域
# (2)按住Ctrl键,上下方向键选择属性,左右方向键调整属性值,确定(回车键)进入属性
# (3)按住Shift调整变量自己的值(这个操作没有意义,因为这个操作只针对非引用类型,而
# 非引用类型本身修改不会影响到上一级,作用域限制),此功能纯属自慰。
#====================================================================================
class Debuger
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def initialize
@time = Graphics.frame_count # 获取刷新次数
@p = 0 # Y轴偏移
@px = 0 # X轴偏移
@line = 0 # 当前行
@col = 0 # 当前列
@f = 16 # 字体大小
@txtBit = # 行元素
@attrP = # 属性指针
@attrs = # 属性列表
@vars = nil # 自己
@attrPi = 0 # 属性当前选择项
end
#--------------------------------------------------------------------------
# ● 创建
#--------------------------------------------------------------------------
def create
dispose # 先把之前的状态全部释放
@sprite = Sprite.new # 创建新的精灵
bitmap = Bitmap.new(6400, @f)
@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 # 初始化字体
@txtBit.push(bitmap)
end
#--------------------------------------------------------------------------
# ● 释放
#--------------------------------------------------------------------------
def dispose
if @sprite
@sprite.dispose
end
i = 0
len = @txtBit.length
for i in 0...len
@txtBit.dispose
@txtBit.shift
end
if @content
@content.dispose
end
end
#--------------------------------------------------------------------------
# ● 渲染
#--------------------------------------------------------------------------
def render
@content.fill_rect(0, 0, 640, 480, Color.new(0,0,0, 150)) # 重绘画布
len = @txtBit.length
i = 0
for i in 0...len
@content.blt(@px*@f/4, i*(@f+4)+@p*24, @txtBit, Rect.new(0, 0,640,480)) # 重绘显示区域
end
end
#--------------------------------------------------------------------------
# ● 写文本到Debuger
# text : 输出内容
#--------------------------------------------------------------------------
def write( text )
while ((c = text.slice!(/./m)) != nil )
if c == "\n"
@txtBit.push( Bitmap.new(9000, @f+4) )
@line = @line + 1
@col = 0
elsif c == "\001"
# 这里可以扩展颜色管理
@txtBit.font.bold = false
@txtBit.font.color = Color.new(0,255,0)
elsif c == "\002" # 内容样式
@txtBit.font.bold = false
@txtBit.font.color = Color.new(0,174,192)
elsif c == "\003" # 内容样式2
@txtBit.font.bold = false
@txtBit.font.color = Color.new(237,144,243)
elsif c == "\004" # 属性样式
@txtBit.font.bold = false
@txtBit.font.color = Color.new(243,220,144)
elsif c == "\005" # 方法样式
@txtBit.font.color = Color.new(243,150,144)
@txtBit.font.bold = true
else
if c > 33 && c < 128
@txtBit.font.size = @f
@txtBit.draw_text(@col, 0, 640, @f+4, c)
@col = @col + @f/2
else
@txtBit.font.size = @f
@txtBit.draw_text(@col, 0, 640, @f+4, c)
@col = @col + @f
end
end
end
end
#--------------------------------------------------------------------------
# ● 输出
# vars : 要观察的信息变量
# f : 字体大小
#--------------------------------------------------------------------------
def log( vars, f = 22 )
initialize # 初始化
@f = f # 定义字体大小
create # 创建新的信息页面
# 创建信息
message = ""
message = message + " \001所属类: \002"+vars.class.to_s+"\n"
message = message + " \001内容: \003"+vars.to_s + "\n"
write( message ) # 写出信息
t = vars.methods
i = 0
attrs =
attrsM = ""
metsM = ""
mets =
logic = false
# 遍历元素的属性
for i in 0...t.length
c = t
logic = c > 64 && c < 91
logic = logic || c > 96 && c < 124
logic = logic || c > 127
if logic && c == 61
attrs.push(c.slice(0, c.length - 1))
tmp = " "
tmp = eval("vars."+attrs).to_s
attrsM = attrsM + " \004" + attrs + ":\002"+ tmp +"\n"
else
mets.push(c)
end
end
message = " \001属性: \002共"+attrs.length.to_s+"个 \n"
write( message )
@attrP =
@attrs = attrs
@vars = vars
write( attrsM ) # 写出元素属性总结报告
# 遍历元素的方法
for i in 0...attrs.length
mets.delete(attrs)
end
for i in 0...mets.length
metsM = metsM + " \001"+(i+1).to_s+"\002[ \005"+mets+" \002]\n"
end
write( " \001属性: \002共"+mets.length.to_s+"个 \n" )
write( metsM ) # 写出元素方法总结报告
render
@sprite.z = 10000
Graphics.transition
# 等待操作
wait
end
#--------------------------------------------------------------------------
# ● 单行写出
# text : 输出内容
# bitmap : 容器
#--------------------------------------------------------------------------
def writeLine( text, bitmap )
col = 0
while ((c = text.slice!(/./m)) != nil )
if 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 > 33 && c < 128
bitmap.font.size = @f
bitmap.draw_text(col, 0, 640, @f+4, c)
col = col + @f/2
else
bitmap.font.size = @f
bitmap.draw_text(col, 0, 640, @f+4, c)
col = col + @f
end
end
end
end
#--------------------------------------------------------------------------
# ● 属性渲染器(选择)
#--------------------------------------------------------------------------
def attrRender
# 判断是否有属性
if @attrs.length > 0
# 重绘某个属性
bit = @txtBit[ @attrP + @attrPi-1 ]
bit.clear
bit.fill_rect(0, 0, bit.width, bit.height, Color.new(50,0,160, 150))
tmp = " "
tmp = eval("@vars."+@attrs).to_s
attrsM = " \004" + @attrs + ":\002"+ tmp
writeLine( attrsM, bit )
end
end
#--------------------------------------------------------------------------
# ● 属性渲染器(还原)
#--------------------------------------------------------------------------
def attrRenderR
# 判断是否有属性
if @attrs.length > 0
# 重绘某个属性
bit = @txtBit[ @attrP + @attrPi-1 ]
bit.clear
tmp = " "
tmp = eval("@vars."+@attrs).to_s
attrsM = " \004" + @attrs + ":\002"+ tmp
writeLine( attrsM, bit )
end
end
#--------------------------------------------------------------------------
# ● 属性修改器
# logic : 修改逻辑?
#--------------------------------------------------------------------------
def attrOp(logic)
if @attrs.length > 0
if logic # 正方向下执行
tmp = eval("@vars."+@attrs)
if tmp.is_a? Numeric # 是否为数字
eval("@vars."+@attrs+"="+"@vars."+@attrs+"+1")
end
if tmp.is_a? TrueClass or tmp.is_a? FalseClass # 是否为逻辑
eval("@vars."+@attrs+"="+"!@vars."+@attrs)
end
if tmp.is_a? String # 是否为字符串
eval("@vars."+@attrs+"="+"@vars."+@attrs+"+\"=\"")
end
# 这里可以升级
else # 负方向下执行
tmp = eval("@vars."+@attrs)
if tmp.is_a? Numeric # 是否为数字
eval("@vars."+@attrs+"="+"@vars."+@attrs+"-1")
end
if tmp.is_a? TrueClass or tmp.is_a? FalseClass # 是否为逻辑
eval("@vars."+@attrs+"="+"!@vars."+@attrs)
end
if tmp.is_a? String # 是否为字符串
eval("@vars."+@attrs+"="+"@vars."+@attrs+"[0,@vars."+@attrs+".length-1]")
end
end
end
end
#--------------------------------------------------------------------------
# ● 自我修改器
# logic : 修改逻辑?
#--------------------------------------------------------------------------
def slfOp(logic)
if logic # 正方向下执行
tmp = @vars
if tmp.is_a? Numeric # 是否为数字
eval("@vars"+"="+"@vars"+"+1")
end
if tmp.is_a? TrueClass or tmp.is_a? FalseClass # 是否为逻辑
eval("@vars"+"="+"!@vars")
end
if tmp.is_a? String # 是否为字符串
eval("@vars"+"="+"@vars"+"+\"=\"")
end
# 这里可以升级
else # 负方向下执行
tmp = @vars
if tmp.is_a? Numeric # 是否为数字
eval("@vars"+"="+"@vars"+"-1")
end
if tmp.is_a? TrueClass or tmp.is_a? FalseClass # 是否为逻辑
eval("@vars"+"="+"!@vars")
end
if tmp.is_a? String # 是否为字符串
eval("@vars=@vars")
end
end
@txtBit.clear
writeLine( " \001内容: \003"+@vars.to_s, @txtBit )
render
end
#--------------------------------------------------------------------------
# ● 等待
#--------------------------------------------------------------------------
def wait
loop do
Graphics.update
Input.update
# 界面移动,以防显示不完全(方向键操控)
if Input.press?(Input::UP) && !Input.press?(Input::CTRL) && !Input.press?(Input::SHIFT)
@p = @p + 1
render
end
if Input.press?(Input::DOWN) && !Input.press?(Input::CTRL)&& !Input.press?(Input::SHIFT)
@p = @p - 1
render
end

if Input.press?(Input::LEFT) && !Input.press?(Input::CTRL)&& !Input.press?(Input::SHIFT)
@px = @px - 1
render
end
if Input.press?(Input::RIGHT) && !Input.press?(Input::CTRL)&& !Input.press?(Input::SHIFT)
@px = @px + 1
render
end
# 属性选择,可以更加直观的观察属性,按住Ctrl键,上下方向键选择属性
# 回车键显示属性信息,左右方向键修改属性值
if Input.press?(Input::CTRL)
attrRender
render
if Input.trigger?(Input::UP)
if @attrPi > 0
$game_system.se_play($data_system.cursor_se)
attrRenderR
@attrPi = @attrPi - 1
else
$game_system.se_play($data_system.buzzer_se)
end
end
if Input.trigger?(Input::DOWN)
if @attrPi < @attrP - 1
$game_system.se_play($data_system.cursor_se)
attrRenderR
@attrPi = @attrPi + 1
else
$game_system.se_play($data_system.buzzer_se)
end
end
if Input.trigger?(Input::RIGHT)
$game_system.se_play($data_system.decision_se)
attrOp(true)
end
if Input.trigger?(Input::LEFT)
$game_system.se_play($data_system.decision_se)
attrOp(false)
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
slf = Debuger.new
#@sprite.visible = false
@sprite.opacity = 100
slf.log(eval("@vars."+@attrs))
@sprite.opacity = 255
@sprite.visible = true
Graphics.update
Input.update
slf.dispose
end
end
# 自己的内容修改器,按住Shift键,左右方向键更改内容
if Input.press?(Input::SHIFT)
if Input.trigger?(Input::RIGHT)
$game_system.se_play($data_system.decision_se)
slfOp(true)
end
if Input.trigger?(Input::LEFT)
$game_system.se_play($data_system.decision_se)
slfOp(false)
end
end
# 如果退出的情况
if Input.trigger?(Input::B) && !Input.press?(Input::CTRL) && !Input.press?(Input::SHIFT)
$game_system.se_play($data_system.cancel_se)
dispose
Input.update
break
end
end
end
end