2006-12-7 13:24
Miliardo
[原创]BGM名称显示插件
模仿戏画的AVG引擎,随手写的……还有些功能想要完善,有时间看看吧……
详细的使用注释在代码内……
[code]
;Music Title Displaying Plugin/BGM曲名显示插件
;A Part of Project.FairyTale
;Version 0.97-beta(2007-03)
;Author:Miliardo (Whitefang Studio)
;Copyright 2001-2007 Whitefang Studio, All Right Reserved
@if exp="typeof(global.musicname_object) == 'undefined'"
@iscript
class MusicNamePlugin extends KAGPlugin
{
var fore, back;
var timer;
var window;
var dk,times;
var align="left";
var width,height,begintime;
function MusicNamePlugin(window)
{
super.KAGPlugin();
fore = new Layer(window, window.fore.base);
back = new Layer(window, window.back.base);
width=window.fore.base.width;
height=window.fore.base.height;
fore.setImagePos(0,0);
fore.setImageSize(width,height);
back.setImagePos(0,0);
fore.setImageSize(width,height);
fore.absolute = back.absolute = 2000000-2;
fore.hitType = back.hitType = htMask;
fore.hitThreshold = back.hitThreshold = 256;
fore.setSizeToImageSize();
fore.fillRect(0, 0, fore.imageWidth, fore.imageHeight, 0);
back.assignImages(fore);
back.setSizeToImageSize();
fore.visible = back.visible = fore.seen = back.seen = true;
fore.font.face = back.font.face = "Arial";
fore.font.bold = back.font.bold = true;
// back.font.mapPrerenderedFont("SH17.tft");
fore.font.height = back.font.height = 16;
timer = new Timer(onTimer, '');
timer.enabled=false;
this.window = window;
}
function finalize()
{
invalidate fore;
invalidate back;
invalidate timer;
super.finalize(...);
}
function setOptions(elm)
{
var lc;
var l=(int)elm.l;
var t=(int)elm.t;
if(elm.face || elm.face!="")
{
fore.font.face = back.font.face = elm.face;
}
if(elm.height || elm.height!="")
{
fore.font.height = back.font.height=(int)elm.height;
}
if (elm.align!=(void))
{
align=elm.align;
}
var str="BGM: "+elm.ch;
switch(align)
{
case "left":
lc=l;
break;
case "center":
lc=(width-fore.font.getTextWidth(str))/2+l;
break;
case "right":
lc=(width-fore.font.getTextWidth(str))-l;
break;
}
fore.opacity=0;
back.opacity=0;
fore.fillRect(0, 0, fore.imageWidth, fore.imageHeight, 0);
back.fillRect(0, 0, fore.imageWidth, fore.imageHeight, 0);
fore.drawText(lc,t,str,0xde6aff);
back.drawText(lc,t,str,0xde6aff);
timer.interval=20;
times=(int)elm.time;
begintime=System.getTickCount();
timer.enabled=true;
}
function onTimer()
{
var ctime=System.getTickCount()-begintime;
if(ctime<times/4)
{
fore.opacity=255*ctime/(times/4);
back.opacity=255*ctime/(times/4);
}
if(ctime>times/4*3)
{
fore.opacity=(255-255*(ctime-(times/4*3))/(times/4));
back.opacity=(255-255*(ctime-(times/4*3))/(times/4));
}
if(ctime>=times)
{
timer.enabled=false;
fore.fillRect(0, 0, fore.imageWidth, fore.imageHeight, 0);
back.fillRect(0, 0, fore.imageWidth, fore.imageHeight, 0);
}
}
function onStore(f, elm)
{
}
function onRestore(f, clear, elm)
{
}
function onStableStateChanged(stable)
{
}
function onMessageHiddenStateChanged(hidden)
{
}
function onCopyLayer(toback)
{
if(toback)
{
back.visible = fore.visible;
back.seen = fore.seen;
}
else
{
fore.visible = back.visible;
fore.seen = back.seen;
}
var tmp;
tmp = back;
back = fore;
fore = tmp;
}
function onExchangeForeBack()
{
var tmp;
tmp = back;
back = fore;
fore = tmp;
}
}
kag.addPlugin(global.musicname_object = new MusicNamePlugin(kag));
@endscript
@endif
@eval exp="tf.musname=Scripts.evalStorage('bgmname.tjs')"
@macro name="musicname"
;调用参数:
;必须:
;ch:显示字幕内容
;time:显示的每一阶段的时间
;l、t:分别为字幕左方、上方坐标(align=right时l为右边距)。
;可选:
;face:字体名称,默认为Arial
;height:字体大小(整数),默认为16
;align:对齐方式,可选“left”、“center”、“right”
@eval exp="musicname_object.setOptions(mp)"
@endmacro
@return[/code]随便举一个调用的例子吧……[code]
@musicname l=10 t=10 ch="Second Flight/KOTOKO & 佐藤裕美 ( Produced by I've Sound )" time=4000 align="right"[/code]
另:
[code] var str="BGM: "+elm.ch;[/code]
这行的BGM:推荐自己找一个字体里面的音符符号替换……例如说"♪"……(Discuz的code代码不能显示这个字符……=皿=)
2006-12-10 11:06
Miliardo
[quote]原帖由 [i]希德船长[/i] 于 2006-12-9 13:41 发表
叫习惯了,把层的所属窗口也叫成父窗口了。这里的所属窗口一般就是指主窗口了吧。
行号看错了,26行。
还有,LRC指的是什么?歌词显示?
我想写一个ASCII字符对图片的自动映射显示插件,为了解决没有合 ... [/quote]
字体的话……其实Krkr本身就自带了一个这样的机制了……大可不必再去写……
似乎称作Prerendered Font……
相关信息可以参考mappfont这个KAG Tag……还有Krkr文档中Font类的部分。
附属工具中的Krkrfont.exe就是生成这种字体文件用的。
LRC是指歌词显示……ORz
比较头痛的是时间的处理……个人感觉Krkr在字符串和文件的处理方面相当不足……
2006-12-20 11:24
Miliardo
BGM插件已修正…补入了对齐功能…LRC插件已完成…今天内发出…下一个目标:坦克大战OTL
------------------------------------------
UCWEB手机浏览器,手机上网第一选择