myprompt & myconfirm

This commit is contained in:
oc 2019-03-20 02:32:31 +08:00
parent bb8182d589
commit 69e4215e03
10 changed files with 245 additions and 93 deletions

View File

@ -791,7 +791,7 @@ editor_mode = function (editor) {
var pixel = getPixel(imgData, i, j);
if (pixel[3]==0) trans++;
if (pixel[0]==255 && pixel[1]==255 && pixel[2]==255 && pixel[3]==255) white++;
if (pixel[0]==0 && pixel[1]==0 && pixel[2]==0 && pixel[3]==255) black++;
// if (pixel[0]==0 && pixel[1]==0 && pixel[2]==0 && pixel[3]==255) black++;
}
}
if (white>black && white>trans*10 && confirm("看起来这张图片是以纯白为底色,是否自动调整为透明底色?")) {
@ -807,6 +807,7 @@ editor_mode = function (editor) {
tempCanvas.putImageData(imgData, 0, 0);
changed = true;
}
/*
if (black>white && black>trans*10 && confirm("看起来这张图片是以纯黑为底色,是否自动调整为透明底色?")) {
for (var i=0;i<image.width;i++) {
for (var j=0;j<image.height;j++) {
@ -820,6 +821,7 @@ editor_mode = function (editor) {
tempCanvas.putImageData(imgData, 0, 0);
changed = true;
}
*/
// Step 2: 检测长宽比
var ysize = selectAppend.value.indexOf('48') === -1 ? 32 : 48;

View File

@ -491,6 +491,14 @@
<canvas class='gameCanvas' id='data' width='416' height='416'>此浏览器不支持HTML5</canvas>
</div>
</div>
<div id='inputBackground'>
<div id='inputDialog'>
<p id="inputMessage">请输入文字...</p>
<input id='inputBox' type="text"/>
<button id='inputYes'>确定</button>
<button id='inputNo'>取消</button>
</div>
</div>
<!-- */</script> -->
<!-- =========================================================== -->

View File

@ -474,6 +474,14 @@
<canvas class='gameCanvas' id='data' width='416' height='416'>此浏览器不支持HTML5</canvas>
</div>
</div>
<div id='inputBackground'>
<div id='inputDialog'>
<p id="inputMessage">请输入文字...</p>
<input id='inputBox' type="text"/>
<button id='inputYes'>确定</button>
<button id='inputNo'>取消</button>
</div>
</div>
<!-- */</script> -->
<!-- =========================================================== -->

View File

@ -25,6 +25,7 @@
<div id='startTopProgress'></div>
</div>
<p id='startTopLoadTips'>资源即将开始加载</p>
<p id='startTopHint'>HTML5魔塔游戏平台享受更多魔塔游戏<br/>https://h5mota.com/</p>
</div>
<img id='startBackground'>
<p id='startLogo'></p>
@ -148,6 +149,14 @@
<canvas class='gameCanvas' id='data' width='416' height='416'>此浏览器不支持HTML5</canvas>
</div>
</div>
<div id='inputDiv'>
<div id='inputDialog'>
<p id="inputMessage">请输入文字...</p>
<input id='inputBox' type="text"/>
<button id='inputYes'>确定</button>
<button id='inputNo'>取消</button>
</div>
</div>
<script src='libs/thirdparty/lz-string.min.js'></script>
<script src='libs/thirdparty/priority-queue.min.js'></script>
<script src='libs/thirdparty/localforage.min.js'></script>

View File

@ -1606,10 +1606,11 @@ actions.prototype._clickSL = function (x, y) {
core.ui.drawSLPanel(index);
}
else {
var index = parseInt(prompt("请输入读档编号")) || 0;
if (index > 0) {
core.doSL(index, core.status.event.id);
}
core.myprompt("请输入读档编号", null, function (index) {
index = parseInt(index) || 0;
if (index > 0)
core.doSL(index, core.status.event.id);
});
}
return;
}
@ -1722,11 +1723,12 @@ actions.prototype._keyUpSL = function (keycode) {
}
return;
}
if (keycode == 69 && core.status.event.id == 'load') { // E
var index = parseInt(prompt("请输入读档编号")) || 0;
if (index > 0) {
core.doSL(index, core.status.event.id);
}
if (keycode == 69 && core.status.event.id != 'save') { // E
core.myprompt("请输入读档编号", null, function (index) {
index = parseInt(index) || 0;
if (index > 0)
core.doSL(index, core.status.event.id);
});
return;
}
if (keycode == 46) {
@ -2061,55 +2063,55 @@ actions.prototype._clickStorageRemove = function (x, y) {
var selection = y - topIndex;
switch (selection) {
case 0:
if (!confirm("你确定要清除【全部塔】的所有本地存档?\n此行为不可逆"))
break;
if (core.platform.useLocalForage) {
core.ui.drawWaiting("正在清空,请稍后...");
localforage.clear(function () {
core.ui.closePanel();
core.myconfirm("你确定要清除【全部塔】的所有本地存档?\n此行为不可逆", function () {
if (core.platform.useLocalForage) {
core.ui.drawWaiting("正在清空,请稍后...");
localforage.clear(function () {
core.ui.closePanel();
core.drawText("\t[操作成功]你的所有存档已被清空。");
core.saves.saveIndex = 1;
core.removeLocalStorage('saveIndex');
});
}
else {
localStorage.clear();
core.drawText("\t[操作成功]你的所有存档已被清空。");
core.saves.saveIndex = 1;
core.removeLocalStorage('saveIndex');
});
}
else {
localStorage.clear();
core.drawText("\t[操作成功]你的所有存档已被清空。");
core.saves.saveIndex = 1;
core.removeLocalStorage('saveIndex');
}
}
});
break;
case 1:
if (!confirm("你确定要清除本塔的所有本地存档?\n此行为不可逆"))
break;
if (core.platform.useLocalForage) {
core.ui.drawWaiting("正在清空,请稍后...");
Object.keys(core.saves.ids).forEach(function (v) {
if (v != 0)
core.removeLocalForage("save" + v);
});
core.removeLocalForage("autoSave", function () {
core.myconfirm("你确定要清除本塔的所有本地存档?\n此行为不可逆", function () {
if (core.platform.useLocalForage) {
core.ui.drawWaiting("正在清空,请稍后...");
Object.keys(core.saves.ids).forEach(function (v) {
if (v != 0)
core.removeLocalForage("save" + v);
});
core.removeLocalForage("autoSave", function () {
core.saves.autosave.data = null;
core.saves.autosave.updated = false;
core.ui.closePanel();
core.drawText("\t[操作成功]当前塔的存档已被清空。");
core.saves.saveIndex = 1;
core.removeLocalStorage('saveIndex');
});
}
else {
Object.keys(core.saves.ids).forEach(function (v) {
if (v != 0)
core.removeLocalStorage("save" + v);
});
core.removeLocalStorage("autoSave");
core.saves.autosave.data = null;
core.saves.autosave.updated = false;
core.ui.closePanel();
core.drawText("\t[操作成功]当前塔的存档已被清空。");
core.saves.saveIndex = 1;
core.removeLocalStorage('saveIndex');
});
}
else {
Object.keys(core.saves.ids).forEach(function (v) {
if (v != 0)
core.removeLocalStorage("save" + v);
});
core.removeLocalStorage("autoSave");
core.saves.autosave.data = null;
core.saves.autosave.updated = false;
core.drawText("\t[操作成功]当前塔的存档已被清空。");
core.saves.saveIndex = 1;
core.removeLocalStorage('saveIndex');
}
break;
}
break;
});
case 2:
core.status.event.selection = 6;
core.ui.drawSyncSave();
@ -2200,8 +2202,10 @@ actions.prototype._clickGameInfo = function (x, y) {
case 1:
if (core.platform.isPC)
window.open("editor.html", "_blank");
else if (confirm("即将离开本塔,跳转至本塔工程页面,确认?")) {
window.location.href = "editor-mobile.html";
else {
core.myconfirm("即将离开本塔,跳转至本塔工程页面,确认?", function () {
window.location.href = "editor-mobile.html";
});
}
break;
case 2:
@ -2209,9 +2213,9 @@ actions.prototype._clickGameInfo = function (x, y) {
window.open("/score.php?name=" + core.firstData.name + "&num=10", "_blank");
}
else {
if (confirm("即将离开本塔,跳转至本塔评论页面,确认?")) {
core.myconfirm("即将离开本塔,跳转至本塔评论页面,确认?", function () {
window.location.href = "/score.php?name=" + core.firstData.name + "&num=10";
}
});
}
break;
case 3:

View File

@ -1033,12 +1033,15 @@ control.prototype._updateDamage_extraDamage = function (floorId, ctx, refresh) {
control.prototype.chooseReplayFile = function () {
core.readFile(function (obj) {
if (obj.name!=core.firstData.name) return alert("存档和游戏不一致!");
if (obj.version && obj.version!=core.firstData.version) {
if (!confirm("游戏版本不一致!\n你仍然想播放录像吗"))
return;
}
if (!obj.route) return alert("无效的录像!");
core.startGame(core.flags.startUsingCanvas?'':obj.hard||'', obj.seed, core.decodeRoute(obj.route));
var _replay = function () {
core.startGame(core.flags.startUsingCanvas?'':obj.hard||'', obj.seed, core.decodeRoute(obj.route));
}
if (obj.version && obj.version!=core.firstData.version) {
core.myconfirm("游戏版本不一致!\n你仍然想播放录像吗", _replay);
return;
}
_replay();
});
}
@ -1526,14 +1529,15 @@ control.prototype._doSL_load = function (id) {
control.prototype._doSL_load_afterGet = function (id, data) {
if (!data) return alert("无效的存档");
var _replay = function () {
core.startGame(data.hard, data.hero.flags.__seed__, core.decodeRoute(data.route));
};
if (core.flags.checkConsole && data.hashCode != null && data.hashCode != core.hashCode(data.hero)) {
if (confirm("存档校验失败,请勿修改存档文件!\n你想回放此存档的录像吗"))
core.startGame(data.hard, data.hero.flags.__seed__, core.decodeRoute(data.route));
core.myconfirm("存档校验失败,请勿修改存档文件!\n你想回放此存档的录像吗\n可以随时停止录像播放以继续游戏。", _replay);
return;
}
if (data.version != core.firstData.version) {
if (confirm("存档版本不匹配!\n你想回放此存档的录像吗\n可以随时停止录像播放以继续游戏。"))
core.startGame(data.hard, data.hero.flags.__seed__, core.decodeRoute(data.route));
core.myconfirm("存档版本不匹配!\n你想回放此存档的录像吗\n可以随时停止录像播放以继续游戏。", _replay);
return;
}
core.ui.closePanel();
@ -1610,15 +1614,14 @@ control.prototype._syncSave_http = function (saves) {
////// 从服务器加载存档 //////
control.prototype.syncLoad = function () {
core.interval.onDownInterval = 'tmp';
var id = prompt("请输入存档编号:") || "";
if (id=="") return core.ui.drawSyncSave();
core.interval.onDownInterval = 'tmp';
var password = prompt("请输入存档密码:") || "";
if (password=="") return core.ui.drawSyncSave();
core.ui.drawWaiting("正在同步,请稍后...");
this._syncLoad_http(id, password);
core.myprompt("请输入存档编号", null, function (id) {
if (!id) return core.ui.drawSyncSave();
core.myprompt("请输入存档密码:", null, function (password) {
if (!password) return core.ui.drawSyncSave();
core.ui.drawWaiting("正在同步,请稍后...");
core.control._syncLoad_http(id, password);
});
});
}
control.prototype._syncLoad_http = function (id, password) {

View File

@ -142,8 +142,14 @@ events.prototype._gameOver_confirmUpload = function (ending, norank) {
return;
}
core.ui.drawConfirmBox("你想记录你的ID和成绩吗", function () {
var username = main.isCompetition ? "" : prompt("请输入你的ID", core.getCookie('id') || "");
core.events._gameOver_doUpload(username, ending, norank);
if (main.isCompetition) {
core.events._gameOver_doUpload("", ending, norank);
}
else {
core.myprompt("请输入你的ID", core.getCookie('id') || "", function (username) {
core.events._gameOver_doUpload(username, ending, norank);
});
}
}, function () {
if (main.isCompetition)
core.events._gameOver_confirmDownload(ending);
@ -184,9 +190,7 @@ events.prototype._gameOver_doUpload = function (username, ending, norank) {
else
core.http("POST", "/games/upload.php", formData);
setTimeout(function () {
core.events._gameOver_confirmDownload(ending);
}, 200);
core.events._gameOver_confirmDownload(ending);
}
events.prototype._gameOver_confirmDownload = function (ending) {
@ -1267,23 +1271,24 @@ events.prototype._action_setHeroIcon = function (data, x, y, prefix) {
}
events.prototype._action_input = function (data, x, y, prefix) {
var value = this.__action_getInput(data.text, false);
if (value == null) return;
value = Math.abs(parseInt(value) || 0);
core.status.route.push("input:" + value);
core.setFlag("input", value);
core.doAction();
this.__action_getInput(data.text, false, function (value) {
value = Math.abs(parseInt(value) || 0);
core.status.route.push("input:" + value);
core.setFlag("input", value);
core.doAction();
});
}
events.prototype._action_input2 = function (data, x, y, prefix) {
var value = this.__action_getInput(data.text, true);
if (value == null) return;
core.status.route.push("input2:" + core.encodeBase64(value));
core.setFlag("input", value);
core.doAction();
this.__action_getInput(data.text, true, function (value) {
value = value || "";
core.status.route.push("input2:" + core.encodeBase64(value));
core.setFlag("input", value);
core.doAction();
});
}
events.prototype.__action_getInput = function (hint, isText) {
events.prototype.__action_getInput = function (hint, isText, callback) {
var value, prefix = isText ? "input2:" : "input:";
if (core.isReplaying()) {
var action = core.status.replay.toReplay.shift();
@ -1292,20 +1297,18 @@ events.prototype.__action_getInput = function (hint, isText) {
throw new Error("录像文件出错!当前需要一个 " + prefix + " 项,实际为 " + action);
if (isText) value = core.decodeBase64(action.substring(7));
else value = parseInt(action.substring(6));
callback(value);
}
catch (e) {
main.log(e);
core.stopReplay();
core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type": "exit"}]);
core.doAction();
return null;
}
}
else {
core.interval.onDownInterval = 'tmp';
value = prompt(core.replaceText(hint)) || "";
core.myprompt(core.replaceText(hint), null, callback);
}
return value;
}
events.prototype._action_if = function (data, x, y, prefix) {

View File

@ -884,6 +884,30 @@ utils.prototype.copy = function (data) {
return successful;
}
////// 显示一段confirm //////
utils.prototype.myconfirm = function (hint, yesCallback, noCallback) {
main.dom.inputDiv.style.display = 'block';
main.dom.inputMessage.innerHTML = hint.replace(/\n/g, '<br/>');
main.dom.inputBox.style.display = 'none';
main.dom.inputYes.focus();
core.platform.successCallback = yesCallback;
core.platform.errorCallback = noCallback;
}
////// 让用户输入一段文字 //////
utils.prototype.myprompt = function (hint, value, callback) {
main.dom.inputDiv.style.display = 'block';
main.dom.inputMessage.innerHTML = hint.replace(/\n/g, '<br/>');
main.dom.inputBox.style.display = 'block';
main.dom.inputBox.value = value==null?"":value;
setTimeout(function () {
main.dom.inputBox.focus();
});
core.platform.successCallback = core.platform.errorCallback = callback;
}
////// 动画显示某对象 //////
utils.prototype.show = function (obj, speed, callback) {
obj.style.display = 'block';

36
main.js
View File

@ -69,7 +69,12 @@ function main() {
'skillCol': document.getElementById('skillCol'),
'hard': document.getElementById('hard'),
'statusCanvas': document.getElementById('statusCanvas'),
'statusCanvasCtx': document.getElementById('statusCanvas').getContext('2d')
'statusCanvasCtx': document.getElementById('statusCanvas').getContext('2d'),
'inputDiv': document.getElementById('inputDiv'),
'inputMessage': document.getElementById('inputMessage'),
'inputBox': document.getElementById('inputBox'),
'inputYes': document.getElementById('inputYes'),
'inputNo': document.getElementById('inputNo')
};
this.mode = 'play';
this.loadList = [
@ -335,6 +340,7 @@ window.onresize = function () {
////// 在界面上按下某按键时 //////
main.dom.body.onkeydown = function(e) {
try {
if (main.dom.inputDiv.style.display == 'block') return;
if (main.core && (main.core.isPlaying() || main.core.status.lockControl))
main.core.onkeyDown(e);
} catch (ee) { main.log(ee); }
@ -343,6 +349,7 @@ main.dom.body.onkeydown = function(e) {
////// 在界面上放开某按键时 //////
main.dom.body.onkeyup = function(e) {
try {
if (main.dom.inputDiv.style.display == 'block') return;
if (main.core && (main.core.isPlaying() || main.core.status.lockControl))
main.core.onkeyUp(e);
} catch (ee) { main.log(ee); }
@ -672,6 +679,33 @@ window.onblur = function () {
}
}
main.dom.inputYes.onclick = function () {
main.dom.inputDiv.style.display = 'none';
var func = core.platform.successCallback;
core.platform.successCallback = core.platform.errorCallback = null;
if (func) func(main.dom.inputBox.value);
}
main.dom.inputNo.onclick = function () {
main.dom.inputDiv.style.display = 'none';
var func = core.platform.errorCallback;
core.platform.successCallback = core.platform.errorCallback = null;
if (func) func(null);
}
main.dom.inputDiv.onkeyup = function (e) {
if (e.keyCode == 13) {
setTimeout(function () {
main.dom.inputYes.click();
}, 50);
}
else if (e.keyCode == 27) {
setTimeout(function () {
main.dom.inputNo.click();
}, 50);
}
}
}//listen end
var main = new main();

View File

@ -79,6 +79,15 @@
z-index: 15;
}
#startTopHint {
color: #66CCFF;
position: absolute;
bottom: 0;
left: 5%;
z-index: 15;
font-size: 18px;
}
#startBackground {
position:absolute;
top:50%;
@ -308,4 +317,52 @@ p#name {
#data {
z-index: 170;
}
#inputDiv {
display: none;
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
background: rgba(127,127,127,0.6);
z-index: 2000
}
#inputDialog {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -60%);
background: white;
width: 250px;
min-height: 50px;
max-height: 250px;
}
#inputMessage {
word-wrap: break-word;
text-align: left;
margin-left: 8%;
margin-right: 5%;
}
#inputBox {
margin-left: 8%;
width: 80%;
margin-bottom: 10px;
padding: 5px 3px;
border: 1px solid;
background: #F0F0F0;
}
#inputYes {
margin-bottom: 15px;
margin-left: 8%;
}
#inputNo {
float:right;
margin-right: 10%;
}