YesNoDialog图片窗口版
// YesNoDialog.tjs - はい/いいえを選択するダイアログボックス
// Copyright (C)2001-2006, W.Dee and contributors 改変&配布は自由です
//Edit by VariableD
//Graphic by 翔岚
class YesNoDialogWindow extends Window
{
var yesButton; // [はい] ボタン
var noButton; // [いいえ] ボタン
var result = false; // no:false yes:true
//添加临时层
var tempLayer;
property temporaryLayer
{
// ワークエリアとして一時的に使用できるレイヤを返す
getter()
{
if(tempLayer === void)
{
tempLayer = new KAGLayer(this, primaryLayer);
tempLayer.name = "一時ワークレイヤ";
}
return tempLayer;
}
}
function YesNoDialogWindow(message, cap)
{
super.Window();
// メインウィンドウから cursor**** の情報をとってくる
if(global.Window.mainWindow !== null &&
typeof global.Window.mainWindow.cursorDefault != "undefined")
this.cursorDefault = global.Window.mainWindow.cursorDefault;
if(global.Window.mainWindow !== null &&
typeof global.Window.mainWindow.cursorPointed != "undefined")
this.cursorPointed = global.Window.mainWindow.cursorPointed;
// 外見の調整
borderStyle = bsNone;
innerSunken = false;
caption = cap;
// プライマリレイヤの作成
add(new Layer(this, null));
// プライマリのマウスカーソルを設定
if(typeof this.cursorDefault !== "undefined")
primaryLayer.cursor = cursorDefault;
//不同询问窗口的底图
if (message=="是否退出?")
primaryLayer.loadImages("yn_exit_cn");
else if (message=="是否回到开始?")
primaryLayer.loadImages("yn_return_cn");
else
primaryLayer.loadImages("yn_bgd");
primaryLayer.setSizeToImageSize();
// 文字样式设定
primaryLayer.font.face="黑体";
primaryLayer.font.height=28;
var tw = primaryLayer.font.getTextWidth(message);
var th = primaryLayer.font.getTextHeight(message);
// サイズを決定
var max_tw = 0;
var sum_th = 0;
var messages = message.split('\n');
for (var i=0; i < messages.count; i++)
{
var lw = primaryLayer.font.getTextWidth(messages[i]);
var lh = primaryLayer.font.getTextHeight(messages[i]);
if (lw > max_tw)
max_tw = tw;
sum_th += lh + 0; // 行間が必要なら+0より大きくする
}
tw = max_tw;
th = sum_th;
var w =primaryLayer.width;
var h = primaryLayer.height;
setInnerSize(w, h);
primaryLayer.width = w;
primaryLayer.height = h;
// ウィンドウ位置の調整
if(global.Window.mainWindow !== null && global.Window.mainWindow isvalid)
{
var win = global.Window.mainWindow;
var l, t;
l = ((win.width - width)>>1) + win.left;
t = ((win.height - height)>>1) + win.top;
if(l < 0) l = 0;
if(t < 0) t = 0;
if(l + width > System.screenWidth) l = System.screenWidth - width;
if(t + height > System.screenHeight) t = System.screenHeight - height;
setPos(l, t);
}
else
{
setPos((System.screenWidth - width)>>1, (System.screenHeight - height)>>1);
}
// message文字的描绘
var msgpos_y = 60;
if (message!="是否退出?" && message!="是否回到开始?")
{
for (var i=0; i < messages.count; i++)
{
var lw = primaryLayer.font.getTextWidth(messages[i]);
var lh = primaryLayer.font.getTextHeight(messages[i]);
var msgpos_x = (w - lw)\2;
primaryLayer.drawText(msgpos_x, msgpos_y, messages[i],0xFFFFFF);
msgpos_y += lh + 10; // 调整行间距
}
}
// Yesボタン
add(yesButton = new ButtonLayer(this, primaryLayer));
yesButton.loadButtons("yn_yes_cn_1.png","yn_yes_cn_2.png","yn_yes_cn_2.png");//确认按钮的图片
yesButton.top = 135;//调整按钮显示位置
yesButton.left = (primaryLayer.width/3)-(yesButton.width/2);//调整按钮显示位置
yesButton.visible = true;
// Noボタン
add(noButton = new ButtonLayer(this, primaryLayer));
noButton.loadButtons("yn_no_cn_1.png","yn_no_cn_2.png","yn_no_cn_2.png");//取消按钮的图片
noButton.top = 135;//调整按钮显示位置
noButton.left = (primaryLayer.width*2/3)-(yesButton.width/2);;//调整按钮显示位置
noButton.visible = true;
}
function finalize()
{
super.finalize(...);
}
function action(ev)
{
// action
if(ev.type == "onClick")
{
if(ev.target == yesButton)
{
result = true;
close();
}
else if(ev.target == noButton)
{
result = false;
close();
}
}
else if(ev.type == "onKeyDown" && ev.target === this)
{
// パッド入力に対応する処理
switch(ev.key)
{
case VK_PADLEFT:
yesButton.focus();
break;
case VK_PADRIGHT:
noButton.focus();
break;
case VK_PAD1:
if(focusedLayer == yesButton)
{
result = true;
close();
}
else if(focusedLayer == noButton)
{
result = false;
close();
}
break;
case VK_PAD2:
result = false;
close();
break;
}
}
}
function onKeyDown(key, shift)
{
super.onKeyDown(...);
if(key == VK_ESCAPE)
{
// ESC キーが押された
// 「いいえ」として処理
result = false;
close();
}
}
}
// Yes か No かはっきりさせる関数
function askYesNo(message, caption = "确认", yesFunc=void, noFunc=void, param=void, doneFunc=void)
{
var win = new YesNoDialogWindow(message, caption);
win.showModal();
var res = win.result;
invalidate win;
if (res) {
if (yesFunc !== void) {
yesFunc(param);
}
} else {
if (noFunc !== void) {
noFunc(param);
}
}
if (doneFunc !== void) {
doneFunc(param);
} return res;
}
// Copyright (C)2001-2006, W.Dee and contributors 改変&配布は自由です
//Edit by VariableD
//Graphic by 翔岚
class YesNoDialogWindow extends Window
{
var yesButton; // [はい] ボタン
var noButton; // [いいえ] ボタン
var result = false; // no:false yes:true
//添加临时层
var tempLayer;
property temporaryLayer
{
// ワークエリアとして一時的に使用できるレイヤを返す
getter()
{
if(tempLayer === void)
{
tempLayer = new KAGLayer(this, primaryLayer);
tempLayer.name = "一時ワークレイヤ";
}
return tempLayer;
}
}
function YesNoDialogWindow(message, cap)
{
super.Window();
// メインウィンドウから cursor**** の情報をとってくる
if(global.Window.mainWindow !== null &&
typeof global.Window.mainWindow.cursorDefault != "undefined")
this.cursorDefault = global.Window.mainWindow.cursorDefault;
if(global.Window.mainWindow !== null &&
typeof global.Window.mainWindow.cursorPointed != "undefined")
this.cursorPointed = global.Window.mainWindow.cursorPointed;
// 外見の調整
borderStyle = bsNone;
innerSunken = false;
caption = cap;
// プライマリレイヤの作成
add(new Layer(this, null));
// プライマリのマウスカーソルを設定
if(typeof this.cursorDefault !== "undefined")
primaryLayer.cursor = cursorDefault;
//不同询问窗口的底图
if (message=="是否退出?")
primaryLayer.loadImages("yn_exit_cn");
else if (message=="是否回到开始?")
primaryLayer.loadImages("yn_return_cn");
else
primaryLayer.loadImages("yn_bgd");
primaryLayer.setSizeToImageSize();
// 文字样式设定
primaryLayer.font.face="黑体";
primaryLayer.font.height=28;
var tw = primaryLayer.font.getTextWidth(message);
var th = primaryLayer.font.getTextHeight(message);
// サイズを決定
var max_tw = 0;
var sum_th = 0;
var messages = message.split('\n');
for (var i=0; i < messages.count; i++)
{
var lw = primaryLayer.font.getTextWidth(messages[i]);
var lh = primaryLayer.font.getTextHeight(messages[i]);
if (lw > max_tw)
max_tw = tw;
sum_th += lh + 0; // 行間が必要なら+0より大きくする
}
tw = max_tw;
th = sum_th;
var w =primaryLayer.width;
var h = primaryLayer.height;
setInnerSize(w, h);
primaryLayer.width = w;
primaryLayer.height = h;
// ウィンドウ位置の調整
if(global.Window.mainWindow !== null && global.Window.mainWindow isvalid)
{
var win = global.Window.mainWindow;
var l, t;
l = ((win.width - width)>>1) + win.left;
t = ((win.height - height)>>1) + win.top;
if(l < 0) l = 0;
if(t < 0) t = 0;
if(l + width > System.screenWidth) l = System.screenWidth - width;
if(t + height > System.screenHeight) t = System.screenHeight - height;
setPos(l, t);
}
else
{
setPos((System.screenWidth - width)>>1, (System.screenHeight - height)>>1);
}
// message文字的描绘
var msgpos_y = 60;
if (message!="是否退出?" && message!="是否回到开始?")
{
for (var i=0; i < messages.count; i++)
{
var lw = primaryLayer.font.getTextWidth(messages[i]);
var lh = primaryLayer.font.getTextHeight(messages[i]);
var msgpos_x = (w - lw)\2;
primaryLayer.drawText(msgpos_x, msgpos_y, messages[i],0xFFFFFF);
msgpos_y += lh + 10; // 调整行间距
}
}
// Yesボタン
add(yesButton = new ButtonLayer(this, primaryLayer));
yesButton.loadButtons("yn_yes_cn_1.png","yn_yes_cn_2.png","yn_yes_cn_2.png");//确认按钮的图片
yesButton.top = 135;//调整按钮显示位置
yesButton.left = (primaryLayer.width/3)-(yesButton.width/2);//调整按钮显示位置
yesButton.visible = true;
// Noボタン
add(noButton = new ButtonLayer(this, primaryLayer));
noButton.loadButtons("yn_no_cn_1.png","yn_no_cn_2.png","yn_no_cn_2.png");//取消按钮的图片
noButton.top = 135;//调整按钮显示位置
noButton.left = (primaryLayer.width*2/3)-(yesButton.width/2);;//调整按钮显示位置
noButton.visible = true;
}
function finalize()
{
super.finalize(...);
}
function action(ev)
{
// action
if(ev.type == "onClick")
{
if(ev.target == yesButton)
{
result = true;
close();
}
else if(ev.target == noButton)
{
result = false;
close();
}
}
else if(ev.type == "onKeyDown" && ev.target === this)
{
// パッド入力に対応する処理
switch(ev.key)
{
case VK_PADLEFT:
yesButton.focus();
break;
case VK_PADRIGHT:
noButton.focus();
break;
case VK_PAD1:
if(focusedLayer == yesButton)
{
result = true;
close();
}
else if(focusedLayer == noButton)
{
result = false;
close();
}
break;
case VK_PAD2:
result = false;
close();
break;
}
}
}
function onKeyDown(key, shift)
{
super.onKeyDown(...);
if(key == VK_ESCAPE)
{
// ESC キーが押された
// 「いいえ」として処理
result = false;
close();
}
}
}
// Yes か No かはっきりさせる関数
function askYesNo(message, caption = "确认", yesFunc=void, noFunc=void, param=void, doneFunc=void)
{
var win = new YesNoDialogWindow(message, caption);
win.showModal();
var res = win.result;
invalidate win;
if (res) {
if (yesFunc !== void) {
yesFunc(param);
}
} else {
if (noFunc !== void) {
noFunc(param);
}
}
if (doneFunc !== void) {
doneFunc(param);
} return res;
}