2007-7-8 15:21
天娜
[废柴例] tjs右键菜单改-存档图像密集型
把那个日文的右键菜单改了一下,横5纵4,一共5页100个存档位置,因为地方很挤,删除了原本的comment和data保护功能。(原件大部分注释改为中文,自己添加了一些)
目前存档标签的字体比较让人郁闷,[b]求在tjs中更改字体的命令[/b]
使用:将脚本内容复制到rcilck_tjs.ks文件内,在frist.ks中@call storage="rclick_tjs.ks"
示意图:
[img]http://img.photobucket.com/albums/v40/tiannamaker/ANIME/save.jpg[/img]
=========== 以下全部为rclick_tjs.ks文件内容 ============
[code]@if exp="typeof(global.rclickconfig_object) == 'undefined'"
@iscript
// 用tjs编写的右键功能菜单
// 使用了100个储存位置
// Config.tjs中:
// 可能的书签的个数设置为100
// freeSaveDataMode设置为false
// saveThumbnail 像设置为true
class RButtonLayer extends ButtonLayer
// parent に onClick イベントを送るようにしたボタンレイヤ
{
var tag;
function RButtonLayer(window, parent)
{
super.ButtonLayer(window, parent);
focusable = false;
}
function finalize()
{
super.finalize(...);
}
function onClick()
{
super.onClick(...);
if(enabled)
parent.onButtonClick(this);
}
}
class SaveDataItemLayer extends KAGLayer
{
// 关于存档块
var num; // 存档号
var bgColor = 0xffbb0000; // 背景色 ( 0xAARRGGBB )
var focusedColor = 0xffffffff; // 鼠标点下正在活动状态的边沿,完全不透明的白色
function SaveDataItemLayer(window, parent, num) // 单个存档板块功能
{
super.KAGLayer(window, parent);
this.num = num;
setImageSize(135,140); // 窗口的Size
face = dfBoth;
fillRect(0, 0, imageWidth, imageHeight, bgColor);
setSizeToImageSize();
hitType = htMask;
hitThreshold = 0; // 把整个窗口作为点击对象
cursor = kag.cursorPointed; // 鼠标的形状
focusable = true; // 可以取得焦点,描绘选项的高亮框用
face = dfBoth;
// 序号的表示
var str = string (num + 1);
font.height = 12;
var ty = font.getTextHeight(str);
drawText(2, 102, "No."+str, 0x000000);
// 存档图像的读入,没有存档则描绘一黑色窗口,中为NO DATA
var tmplayer = new global.Layer(window, parent);
var tnname = kag.getBookMarkFileNameAtNum(num);
if(Storages.isExistentStorage(tnname))
{
tmplayer.loadImages(tnname);
}
else
{
tmplayer.setImageSize(133, 100);
tmplayer.fillRect(0, 0, imageWidth, imageHeight, 0x70000000);
var str = "NO DATA";
var tx = tmplayer.font.getTextWidth(str);
tmplayer.drawText((tmplayer.imageWidth - tx) \ 2, 40, str, 0xffffff);
}
copyRect(1, 1, tmplayer, 0, 0, tmplayer.imageWidth, tmplayer.imageHeight);
invalidate tmplayer;
// 存档的标签信息
font.height = 12;
var str = kag.bookMarkNames[num];
if(str == '') str = '没有记录';
drawText(5, 120, str, 0xffffff);
// 存档的日期信息
if(kag.bookMarkDates[num] == '')
str = "----/--/-- --:--";
else
str = kag.bookMarkDates[num];
drawText(37, 102, str, 0xff0000);
}
function finalize()
{
super.finalize(...);
}
function saveToSystemVariable()
{
// 增添量的记录
}
function onPaint()
{
super.onPaint(...);
// 边框绘制
// update()之后,描画之前使用
face = dfBoth;
if(focused)
{
fillRect(0, 0, imageWidth, 2, focusedColor);
fillRect(0, 2, 2, imageHeight - 2, focusedColor);
fillRect(imageWidth - 2, 2, 2, imageHeight - 2, focusedColor);
fillRect(2, imageHeight - 2, imageWidth - 4, 2, focusedColor);
}
else
{
fillRect(0, 0, imageWidth, 2, bgColor);
fillRect(0, 2, 2, imageHeight - 2, bgColor);
fillRect(imageWidth - 2, 2, 2, imageHeight - 2, bgColor);
fillRect(2, imageHeight - 2, imageWidth - 4, 2, bgColor);
}
}
function onFocus()
{
// 取得焦点
super.onFocus(...);
update();
}
function onBlur()
{
// 擦去焦点
super.onBlur(...);
update();
}
function onHitTest(x, y, process)
{
if(process)
{
// 在这里使用右键的话跳过envent
if(System.getKeyState(VK_RBUTTON))
super.onHitTest(x, y, false);
else
super.onHitTest(x, y, true);
}
}
function onKeyDown(key, shift, process)
{
// 使用键盘按键的情况
if(process && key == VK_RETURN || key == VK_SPACE)
{
// 使用空格或者回车键
super.onKeyDown(key, shift, false);
saveToSystemVariable();
parent.onLoadOrSave(num);
}
else
{
// 其它按键不做处理
super.onKeyDown(...);
}
}
function onMouseDown(x, y, button, shift)
{
super.onMouseDown(...);
if(button == mbLeft)
{
focus();
saveToSystemVariable();
parent.onLoadOrSave(num);
}
}
}
class RClickConfigLayer extends Layer // 设定右键菜单画面
{
var closeButton; // 设置“关闭”按钮
var saveButton; // 设置“保存”按钮
var loadButton; // 设置“读取”按钮
var hideMessageButton; // 设置消除message画面
var saveDataItems;
var state = -1; // 0 = 主菜单 1 = 读取 2 = 保存画面,判断返回主菜单的位置并区分操作
var owner; // RClickConfigPlugin Object参考
var currentPage = 0; // 存取界面的当前页数
var returnButton; // 设置“返回”按钮
var pageButtons; // 存取页面的当前页数跳跃按钮
function RClickConfigLayer(win, par, owner)
{
super.Layer(win, par);
this.owner = owner;
// Layer状态初期化
setImageSize(800, 600);
clearBase();
setSizeToImageSize();
setPos(0, 0);
hitType = htMask;
hitThreshold = 0; // 全域不透過
}
function finalize() //初始化
{
clear();
invalidate closeButton if closeButton !== void;
invalidate saveButton if saveButton !== void;
invalidate loadButton if loadButton !== void;
invalidate hideMessageButton if hideMessageButton !== void;
invalidate returnButton if returnButton !== void;
super.finalize(...);
}
function clearBase()
{
// 底色,背景色
fillRect(0, 0, imageWidth, imageHeight, 0x50000000);
}
function makeMainMenu()
{
// 右键主菜单
if(state != 0)
{
clear();
state = 0;
/*
制成按钮
这里使用的是文字按钮、
使用图像按钮的话:
if(closeButton === void)
{
closeButton = new RButtonLayer(window, this);
closeButton.showFocusImage = true;
closeButton.loadImages("ボタン画像ファイル名");
closeButton.left = 270;
closeButton.top = 350;
closeButton.focusable = true;
}
这样表述。
这里指定的图像是普通按钮图像
横向3连图像或者4连图像
showFocusImage = true的时候使用4连图像(推荐)
*/
// 「关闭」按钮的描绘
if(closeButton === void)
{
closeButton = new RButtonLayer(window, this);
closeButton.width = 100;
closeButton.height = 25;
closeButton.caption = "关闭";
closeButton.captionColor = 0xffffff;
closeButton.left = 270;
closeButton.top = 350;
closeButton.focusable = true;
}
closeButton.visible = true;
// 「保存」按钮的描绘
if(saveButton === void)
{
saveButton = new RButtonLayer(window, this);
saveButton.width = 100;
saveButton.height = 25;
saveButton.caption = "保存";
saveButton.captionColor = 0xffffff;
saveButton.left = 270;
saveButton.top = 100;
saveButton.focusable = true;
}
saveButton.enabled = kag.canStore();
saveButton.visible = true;
// 「读取」按钮的描绘
if(loadButton === void)
{
loadButton = new RButtonLayer(window, this);
loadButton.width = 100;
loadButton.height = 25;
loadButton.caption = "读取";
loadButton.captionColor = 0xffffff;
loadButton.left = 270;
loadButton.top = 150;
loadButton.focusable = true;
}
loadButton.enabled = kag.canRestore();
loadButton.visible = true;
// 「消除message」按钮的描绘
if(hideMessageButton === void)
{
hideMessageButton = new RButtonLayer(window, this);
hideMessageButton.width = 100;
hideMessageButton.height = 25;
hideMessageButton.caption = "消除文字信息";
hideMessageButton.captionColor = 0xffffff;
hideMessageButton.left = 270;
hideMessageButton.top = 200;
hideMessageButton.focusable = true;
}
hideMessageButton.visible = true;
}
}
function clearSaveDataItems()
{
// 清除存取页面的存档块
if(saveDataItems !== void)
{
for(var i = 0; i < saveDataItems.count; i++)
{
saveDataItems[i].saveToSystemVariable();
invalidate saveDataItems[i];
}
saveDataItems = void;
kag.setBookMarkMenuCaptions();
}
}
function makeSaveDataItems() // 存档块的罗列,自增加变量i,u,当前页数currentPage
{
// 存档的表示
clearSaveDataItems();
saveDataItems = [];
for(var i = 0; i < 4; i++) // 纵列
{
for (var u = 0; u < 5; u++) // 横列
{
var obj = new SaveDataItemLayer(window, this, currentPage * 20 + i*5+u); // 总计所有页面的存档数字
saveDataItems[i*5+u] = obj;
obj.setPos(140 * u + 100, 145 * i + 5); // 框的摆放+整体偏位
obj.visible = true;
}
}
}
function clearPageButtons()
{
// 清除页数按钮
if(pageButtons !== void)
{
for(var i = 0; i < pageButtons.count; i++)
{
invalidate pageButtons[i];
}
pageButtons = void;
}
}
function makePageButtons()
{
// 生成页数按钮
clearPageButtons();
pageButtons = [];
for(var i = 0; i < 5; i++)
{
var obj = new RButtonLayer(window, this);
pageButtons[i] = obj;
obj.width = 80;
obj.height = 25;
obj.color = currentPage == i ? 0xff0000 : 0x000000;
obj.caption = " 存档 " + (i*20+1) + "~" + ((i+1)*20);
obj.captionColor = 0xffffff;
obj.top = i * 30 + 350;
obj.left = 10;
obj.focusable = true;
obj.enabled = currentPage != i;
obj.visible = true;
obj.tag = 'page';
obj.page = i;
}
}
function changePage(newpage)
{
// 换页功能
if(pageButtons !== void)
{
pageButtons[currentPage].color = 0x000000;
pageButtons[currentPage].enabled = true;
pageButtons[newpage].color = 0xff0000;
pageButtons[newpage].enabled = false;
currentPage = newpage;
makeSaveDataItems();
}
}
function makeReturnButton()
{
// “返回”按钮
if(returnButton === void)
{
returnButton = new RButtonLayer(window, this);
returnButton.width = 80;
returnButton.height = 25;
returnButton.caption = "返回";
returnButton.captionColor = 0xffffff;
returnButton.left = 10;
returnButton.top = 550;
returnButton.focusable = true;
}
returnButton.visible = true;
}
function makeLoadMenu()
{
// 「读取」菜单界面的描绘
if(state != 1)
{
clear();
state = 1;
makeSaveDataItems(currentPage);
makeReturnButton();
makePageButtons();
font.height = 24;
drawText(30, 30, "ロード", 0xffffff);
}
}
function makeSaveMenu()
{
// 「保存」菜单界面的描绘
if(state != 2)
{
clear();
state = 2;
makeSaveDataItems(currentPage);
makeReturnButton();
makePageButtons();
font.height = 24;
drawText(30, 30, "セーブ", 0xffffff);
}
}
function clear()
{
// 隐藏画面上的所有无效按钮,清场
clearBase();
closeButton.visible = false if closeButton !== void;
saveButton.visible = false if saveButton !== void;
loadButton.visible = false if loadButton !== void;
hideMessageButton.visible = false if hideMessageButton !== void;
returnButton.visible = false if returnButton !== void;
clearSaveDataItems();
clearPageButtons();
}
function saveToSystemVariable()
{
// 需要保存系统变量数据的时候
if(saveDataItems !== void)
{
for(var i = 0; i < saveDataItems.count; i++)
saveDataItems[i].saveToSystemVariable();
kag.setBookMarkMenuCaptions();
}
}
function onButtonClick(sender)
{
// 按下按钮
switch(sender)
{
case closeButton: // 关闭
owner.onConfigClose();
break;
case saveButton: // 保存
makeSaveMenu();
break;
case loadButton: // 读取
makeLoadMenu();
break;
case hideMessageButton: // 消除message
owner.closeConfig();
kag.process('', '*hidemessage');
break;
case returnButton: // 返回
makeMainMenu();
break;
default:
if(sender.tag == 'page')
{
// 页数
changePage(sender.page);
}
}
}
function onLoadOrSave(num)
{
// 读取或者是存档
if(state == 1)
{
// load
kag.loadBookMarkWithAsk(num);
}
else
{
// save
if(kag.saveBookMarkWithAsk(num))
{
clearSaveDataItems();
makeSaveDataItems(); // 刷新信息
}
}
}
function show()
{
// layer的表示
visible = true;
setMode();
focus();
}
function hide()
{
// layer的隐藏
removeMode();
visible = false;
clear();
state = -1;
}
function onKeyDown(key)
{
super.onKeyDown(...);
if(key == VK_ESCAPE)
owner.onConfigClose(); // ESC键按下的时候关掉主菜单
}
function onMouseDown(x, y, button, shift)
{
if(button == mbRight)
{
if(state == 0)
{
// 主菜单上右键按下则关掉主菜单
owner.onConfigClose();
}
else if(state == 1 || state == 2)
{
// 存取界面按下右键则返回主菜单
makeMainMenu();
}
}
}
}
class RClickConfigPlugin extends KAGPlugin // 右键设定插件集
{
var window;
var config;
function RClickConfigPlugin(window)
{
// RClickPlugin 构造函数
super.KAGPlugin(); // 呼叫superclass的构造函数
this.window = window; // 保留窗口参照数据
}
function finalize()
{
invalidate config if config !== void;
super.finalize(...);
}
function show()
{
// 表示
if(config === void)
config = new RClickConfigLayer(window, kag.fore.base, this);
config.parent = window.fore.base;
// 关联再设定
// (根据过渡变换表层和背景层)
config.makeMainMenu();
config.show();
}
function onConfigClose()
{
// 打开设定页
closeConfig();
window.trigger('config'); // 'config'触发器
}
function closeConfig()
{
// 关闭设定页
config.hide() if config !== void;
}
// 以下、KAGPlugin 的方法的override
function onStore(f, elm)
{
}
function onRestore(f, clear, elm)
{
// 读取的时候
closeConfig();
}
function onStableStateChanged(stable)
{
}
function onMessageHiddenStateChanged(hidden)
{
}
function onCopyLayer(toback)
{
}
function onExchangeForeBack()
{
}
function onSaveSystemVariables()
{
if(config !== void) config.saveToSystemVariable();
}
}
kag.addPlugin(global.rclickconfig_object = new RClickConfigPlugin(kag));
@endscript
@endif
; 右键的设定
@rclick call=true storage="rclick_tjs.ks" target="*rclick" enabled=true name="MENU(&S) ..." enabled=true
@return
*rclick
; 单击右键时呼叫此
@locksnapshot
*rclick_2
@eval exp="rclickconfig_object.show()"
; show メソッドを呼ぶ
@waittrig name="config"
; ↑ 等待'config' 触发器
@unlocksnapshot
@return
*hidemessage
; message消除的话呼叫此
@hidemessage
@jump target=*rclick_2[/code]