赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 1384 |
最后登录 | 2015-8-26 |
在线时间 | 27 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 27 小时
- 注册时间
- 2010-12-11
- 帖子
- 15
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
#==============================================================================
# ■ Sword Art Online
#------------------------------------------------------------------------------
# 储存SAO常量及特殊方法
#==============================================================================
class Bitmap
@@fontName = ["sao", "SimHei"]
def draw_textSAO(x, y, text)
self.font.outline = false
xPlus = 0
tSize = font.size
tHalf = ::SAO::FONT_SIZE-1
text.gsub!("\\n") {"\n"}
text.split(//).each{|char|
if char == "\n"
y+=self.font.size
xPlus = 0
next
end
if char.ord > 0xFF
self.font.name = @@fontName[1]
self.font.size = tSize-::SAO::FONT_SIZE
fontSizeRect = text_size(char)
draw_text(x+xPlus, y+tHalf, fontSizeRect.width+2, fontSizeRect.height, char)
xPlus += fontSizeRect.width+2
else
self.font.name = @@fontName[0]
self.font.size = tSize
fontSizeRect = text_size(char)
draw_text(x+xPlus, y, fontSizeRect.width, fontSizeRect.height, char)
xPlus += fontSizeRect.width
end
}
self.font.size = tSize
self.font.name = @@fontName[0]
end
end
module SAO
SAO_GREY = Color.new(90, 90, 90)
HEIGHT = 46
PRESS_SHOW_COUNT = 5 # 点击效果延长显示帧数
BTN_INIT_HRIGHT = 50 # 初始化下落高度
BTN_INIT_COUNT = 10 # 初始化效果帧数
BTN_INIT_COUNT_ADD = 5 # 后续初始化效果增加帧数
FONT_SIZE = 5 # 中文字体减小大小
def self.f(x)
return self.f(x+1) if x < 0
return self.f(x-1) if x > 2
(x-1)**2
end
def self.makeY(a, b, c)
c%2 == 0 ? (((a-b)%c-c/2)%c) : (((a-1-b)%c-c/2)%c)
end
def self.callMSGBOX(*arg)
$game_topZ = 4096
tmpRate = Graphics.frame_rate
sao = ::Sword_Art_Online_MessageBox.new(*arg)
Graphics.frame_rate = 60
loop {Graphics.update;Input.update;sao.update;break if sao.phase == :exit}
sao.dispose
Graphics.frame_rate = tmpRate
nil
end
def self.callMSGBOX_EX(t, c)
if c.is_a?(Array)
a = []
c.each{|i|a<<[nil,i]}
self.callMSGBOX(a, [[:String, t]])
else
self.callMSGBOX([[nil, c]], [[:String, t]])
end
end
end
#==============================================================================
# ■ Sword_Art_Online_MessageBox
#------------------------------------------------------------------------------
# 刀剑神域 消息盒子
#==============================================================================
class Sword_Art_Online_MessageBox
SHOW_COUNT = 40 # 显示一行帧数
ZOOM_COUNT = 10 # 缩放帧数
SCROLL_COUNT = 15 # 滚动帧数
LINE_HEIGHT = 5 # 临时分界线位图高度
HEAD_INIT_8 = 16 # 顶层不动位置0~它
HEAD_INIT_5 = 46 # 顶层复制位置
YFix = 32 # 整体向上移动距离
MDL_ADD_HEIGHT = 26 # 中间层复制基础量
CONTENT_TEXT_X = 80 # 中间层文字刻画X坐标
CONTENT_ICON_X = 70 # 中间层图标刻画X坐标
#~ CONTENT_FONT_S = 24 # 中间层文字大小
TOW_X1 = 32 # 显示2、3个时, 第一个的X坐标
TOW_X2 =280 # 显示2、3个时, 最后个的X坐标
TOW_XM =170 # 中间坐标
attr_reader :bool_SAOLeft
attr_reader :phase
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize(contents=[[nil, "文字测试"]], title=[[:String, "Message"]], x=0, y=0, &block)
@contents = contents
@box_viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
@box_viewport.z = $game_topZ
@box8 = Sprite.new(@box_viewport)
@box8.bitmap = makeHead(title)
@box8.ox = @box8.bitmap.width/2
@box8.oy = @box8.bitmap.height
@box8.x = Graphics.width/2 + x
@box8.y = Graphics.height/2-YFix + y
@box8.opacity = 0
@box8.zoom_x = @box8.zoom_y = 0.0
@box2 = Sprite.new(@box_viewport)
@box2.bitmap = Cache.picture("box2")
@box2.ox = @box2.bitmap.width/2
@box2.x = @box8.x
@box2.y = @box8.y-1
@box2.opacity = 0
@box2.zoom_x = @box2.zoom_y = 0.0
@box5 = Sprite.new(@box_viewport)
tBMP = Cache.picture("box5")
@box5.bitmap = Bitmap.new(tBMP.width, tBMP.font.size*contents.size+MDL_ADD_HEIGHT)
@box5.bitmap.font.name = 'sao'
@box5.bitmap.font.color = SAO::SAO_GREY
makeContent!(@box5.bitmap, tBMP)
@box5.ox = @box5.bitmap.width/2
@box5.x = @box8.x
@box5.y = @box2.y+1
@box5.src_rect.height = 0
@phase = :zoom_out
@phaseCounter = ZOOM_COUNT
@bool_SAOLeft = false
@BLock = block
@block_called = false
end
#--------------------------------------------------------------------------
# ● 生成内容!
#--------------------------------------------------------------------------
def makeContent!(bitmap, bBmp)
bitmap.height.times{|y|bitmap.blt(0, y, bBmp, bBmp.rect)}
@contents.each_with_index{|content, index|
nowY = MDL_ADD_HEIGHT/2+bitmap.font.size*index
if content[0] # 图标
icon_index = content[0].icon_index
icobmp = Cache.system("Iconset")
rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
bitmap.blt(TOW_X1, nowY, icobmp, rect)
bitmap.draw_textSAO(CONTENT_TEXT_X, nowY, content[0].name)
bitmap.draw_textSAO(TOW_X2, nowY, "×#{content[1]}")
next
end
bitmap.draw_textSAO(CONTENT_TEXT_X, nowY, content[1])
}
end
#--------------------------------------------------------------------------
# ● 重新刻画内容
#--------------------------------------------------------------------------
def redrawC(c)
@contents = c
@box5.bitmap.clear
makeContent!(@box5.bitmap, Cache.picture("box5"))
end
#--------------------------------------------------------------------------
# ● 刷新放大效果
#--------------------------------------------------------------------------
def update_zoom_out
@phaseCounter -= 1
vul = SAO.f(@phaseCounter.to_f/ZOOM_COUNT)
@box8.opacity = (vul*255).to_i
@box8.zoom_x = @box8.zoom_y = vul
@box2.opacity = @box8.opacity
@box2.zoom_x = @box2.zoom_y = @box8.zoom_x
if @phaseCounter <= 0
@box2.y+=1
@box8.zoom_x = @box8.zoom_y = 1.0
@box2.zoom_x = @box2.zoom_y = 1.0
@box8.opacity = 255
@box2.opacity = 255
@box8.move_to(nil, @[email protected]/2, nil, SCROLL_COUNT)
@box2.move_to(nil, @[email protected]/2, nil, SCROLL_COUNT)
@phase = :scrolling_out
playOUTSE
return @phaseCounter = SCROLL_COUNT
end
end
#--------------------------------------------------------------------------
# ● 刷新缩小效果
#--------------------------------------------------------------------------
def update_zoom_in
@phaseCounter -= 1
vul = SAO.f(@phaseCounter.to_f/ZOOM_COUNT)
@box8.opacity = 255-(vul*255).to_i
@box8.zoom_x = @box8.zoom_y = 1.0 - vul
@box2.opacity = @box8.opacity
@box2.zoom_x = @box2.zoom_y = @box8.zoom_x
if @phaseCounter <= 0
@phase = :exit
end
end
#--------------------------------------------------------------------------
# ● 展开音效
#--------------------------------------------------------------------------
def playOUTSE
Audio.se_play("Audio/SE/msg")
end
#--------------------------------------------------------------------------
# ● 刷新展开效果
#--------------------------------------------------------------------------
def update_scrolling_out
@phaseCounter -= 1
@box8.move_update
@box2.y = Graphics.height-YFix*[email protected]
@box5.src_rect.height = (@box2.y-Graphics.height/2+YFix)*2
@box5.src_rect.y = (@[email protected]_rect.height)/2
@box5.oy = @box5.src_rect.height/2
if @phaseCounter <= 0
@phase = :showing
return @phaseCounter = getShowCount
end
end
#--------------------------------------------------------------------------
# ● 刷新闭合效果
#--------------------------------------------------------------------------
def update_scrolling_in
@phaseCounter -= 1
@box8.move_update
@box2.y = Graphics.height-YFix*[email protected]
@box5.src_rect.height = (@box2.y-Graphics.height/2+YFix)*2
@box5.src_rect.y = (@[email protected]_rect.height)/2
@box5.oy = @box5.src_rect.height/2
if @phaseCounter <= 0
@box8.y = Graphics.height/2-YFix
@box2.y = @box8.y-1
@box5.src_rect.height = 0
@phase = :zoom_in
return @phaseCounter = ZOOM_COUNT
end
end
#--------------------------------------------------------------------------
# ● 刷新显示
#--------------------------------------------------------------------------
def update_showing
@phaseCounter -= 1
if @phaseCounter <= 0
@box8.move_to(nil, Graphics.height/2-YFix, nil, SCROLL_COUNT)
@box2.move_to(nil, Graphics.height/2-YFix+1, nil, SCROLL_COUNT)
@phase = :scrolling_in
return @phaseCounter = SCROLL_COUNT
end
end
#--------------------------------------------------------------------------
# ● 获取显示帧数
#--------------------------------------------------------------------------
def getShowCount
SHOW_COUNT * @contents.size
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def update
case @phase
when :zoom_out
update_zoom_out
when :scrolling_out
update_scrolling_out
when :showing
update_showing
when :scrolling_in
update_scrolling_in
when :zoom_in
update_zoom_in
end
#~ if (!@block_called || Mouse.trigger?(Mouse::RIGHT)) && @phase == :showing
#~ @block_called = true
#~ if @block
#~ re = @block.call
#~ eval(re) if re.is_a?(String)
#~ end
#~ end
end
#--------------------------------------------------------------------------
# ● 释放对像
#--------------------------------------------------------------------------
def dispose
@box2.dispose
@box5.dispose
@box5.bitmap.dispose
@box8.dispose
@box8.bitmap.dispose
@box_viewport.dispose
end
#--------------------------------------------------------------------------
# ● 生成头部 title.size-1的数来刻画分界线
#--------------------------------------------------------------------------
def makeHead(title)
tBMP = Cache.picture("box8")
reBMP= Bitmap.new(tBMP.width, (title.size-1)*HEAD_INIT_5+tBMP.height)
reBMP.font.color = SAO::SAO_GREY
reBMP.font.name = "SAO"
# 复制位图信息
bltRect = Rect.new(0, 0, tBMP.width, HEAD_INIT_8)
reBMP.blt(0, 0, tBMP, bltRect)
bltRect.set(0, HEAD_INIT_8, tBMP.width, HEAD_INIT_5)
title.size.times{|i|
reBMP.blt(0, HEAD_INIT_8+i*HEAD_INIT_5, tBMP, bltRect)
}
bltRect.set(0, HEAD_INIT_8+HEAD_INIT_5, tBMP.width, tBMP.height-HEAD_INIT_8-HEAD_INIT_5)
reBMP.blt(0, title.size*HEAD_INIT_5+HEAD_INIT_8, tBMP, bltRect)
title.each_with_index{|i, index|
if index > 0 # 分割线生成
lineBitmap = Bitmap.new(tBMP.width, LINE_HEIGHT)
lineWidth = tBMP.width*17/20
lineBitmap.fill_rect((tBMP.width-lineWidth)/2,
LINE_HEIGHT/2-1, lineWidth, 3, Color.new(100, 100, 100, 100))
lineBitmap.fill_rect((tBMP.width-lineWidth)/2,
LINE_HEIGHT/2,lineWidth, 1, Color.new(100, 100, 100))
lineBitmap.blur
reBMP.blt(0, index*HEAD_INIT_5+HEAD_INIT_8, lineBitmap, lineBitmap.rect)
lineBitmap.dispose
end
case i[0]
when :String
rStrBMPRect = reBMP.text_size(i[1])
reBMP.draw_textSAO((reBMP.width-rStrBMPRect.width)/2,
index*HEAD_INIT_5+HEAD_INIT_8+(HEAD_INIT_5-rStrBMPRect.height)/2, i[1])
when :Three
reBMP.draw_textSAO(TOW_X1,
index*HEAD_INIT_5+HEAD_INIT_8+(HEAD_INIT_5-reBMP.font.size)/2, i[1])
reBMP.draw_textSAO(TOW_X2,
index*HEAD_INIT_5+HEAD_INIT_8+(HEAD_INIT_5-reBMP.font.size)/2, i[2])
reBMP.draw_textSAO(TOW_XM,
index*HEAD_INIT_5+HEAD_INIT_8+(HEAD_INIT_5-reBMP.font.size)/2, i[3]) if i[3]
end
}
reBMP
end
end |
|