From bc7df1fe9bf24afdbb38226d542e08f99c366e59 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Mon, 19 Jul 2021 16:36:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E7=BB=98=E6=A0=87=E9=A2=98=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E5=B1=85=E4=B8=AD=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/table/plugins.comment.js | 6 + libs/actions.js | 9 +- project/data.js | 346 +++++++++++++++++++++++++------ project/plugins.js | 87 ++++++++ 4 files changed, 382 insertions(+), 66 deletions(-) diff --git a/_server/table/plugins.comment.js b/_server/table/plugins.comment.js index 71ae9196..88633f3c 100644 --- a/_server/table/plugins.comment.js +++ b/_server/table/plugins.comment.js @@ -80,6 +80,12 @@ var plugins_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_type": "textarea", "_range": "typeof(thiseval)=='string' || thiseval==null", "_data": "勇士四帧行走动画" + }, + "startCanvas": { + "_leaf": true, + "_type": "textarea", + "_range": "typeof(thiseval)=='string' || thiseval==null", + "_data": "自绘标题界面居中" } } if (obj[key]) return obj[key]; diff --git a/libs/actions.js b/libs/actions.js index b8d65cb4..ce6c6a4e 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -452,9 +452,8 @@ actions.prototype._sys_keyUp = function (keyCode, altKey) { ////// 点击(触摸)事件按下时 ////// actions.prototype.ondown = function (loc) { - var lx = Math.max(loc.x, 0), ly = Math.max(loc.y, 0); - var x = parseInt(lx / loc.size), y = parseInt(ly / loc.size); - var px = parseInt(lx / core.domStyle.scale), py = parseInt(ly / core.domStyle.scale); + var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); + var px = parseInt(loc.x / core.domStyle.scale), py = parseInt(loc.y / core.domStyle.scale); this.doRegisteredAction('ondown', x, y, px, py); } @@ -628,7 +627,7 @@ actions.prototype._getClickLoc = function (x, y) { var left = core.dom.gameGroup.offsetLeft + statusBar.x; var top = core.dom.gameGroup.offsetTop + statusBar.y; - var loc = {'x': x - left, 'y': y - top, 'size': size}; + var loc = {'x': Math.max(x - left), 'y': Math.max(y - top, 0), 'size': size}; return loc; } @@ -881,7 +880,7 @@ actions.prototype.onStatusBarClick = function (e) { var left = core.dom.gameGroup.offsetLeft + 3; var top = core.dom.gameGroup.offsetTop + 3; var px = parseInt((e.clientX - left) / core.domStyle.scale), py = parseInt((e.clientY - top) / core.domStyle.scale); - return this.doRegisteredAction('onStatusBarClick', px, py); + return this.doRegisteredAction('onStatusBarClick', Math.max(px, 0), Math.max(py, 0)); } actions.prototype._sys_onStatusBarClick = function (px, py, vertical) { diff --git a/project/data.js b/project/data.js index 74ee53bc..c0774f03 100644 --- a/project/data.js +++ b/project/data.js @@ -146,86 +146,258 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = "text": "也可以直接切换到其他楼层(比如某个开始剧情楼层)进行操作。" }, { - "type": "showImage", - "code": 1, - "image": "bg.jpg", - "loc": [ - 0, - 0 - ], - "opacity": 1, - "time": 0 + "type": "previewUI", + "action": [ + { + "type": "fillRect", + "x": 0, + "y": 0, + "width": "core.__PIXELS__", + "height": "core.__PIXELS__", + "style": [ + 82, + 82, + 82, + 1 + ] + }, + { + "type": "setAttribute", + "align": "center" + }, + { + "type": "fillBoldText", + "x": "core.__PIXELS__ / 2", + "y": 80, + "style": [ + 255, + 255, + 255, + 1 + ], + "strokeStyle": [ + 0, + 0, + 0, + 1 + ], + "font": "bold 40px Verdana", + "text": "${core.firstData.title}" + } + ] + }, + { + "type": "setValue", + "name": "flag:selection", + "value": "0" + }, + { + "type": "comment", + "text": "在右下方自绘一个对话框进行显示选择项" + }, + { + "type": "previewUI", + "action": [ + { + "type": "fillRect", + "x": 230, + "y": 250, + "width": 150, + "height": 142, + "radius": 10, + "style": [ + 50, + 54, + 159, + 0.85 + ] + }, + { + "type": "strokeRect", + "x": 230, + "y": 250, + "width": 150, + "height": 142, + "radius": 10, + "style": [ + 255, + 255, + 255, + 1 + ], + "lineWidth": 2 + }, + { + "type": "fillBoldText", + "x": 305, + "y": 290, + "style": [ + 255, + 255, + 255, + 1 + ], + "font": "bold 25px Verdana", + "text": "开始游戏" + }, + { + "type": "fillBoldText", + "x": 305, + "y": 330, + "font": "bold 25px Verdana", + "text": "读取存档" + }, + { + "type": "fillBoldText", + "x": 305, + "y": 370, + "font": "bold 25px Verdana", + "text": "回放录像" + } + ] }, { "type": "while", "condition": "1", "data": [ { - "type": "comment", - "text": "给用户提供选择项,这里简单的使用了choices事件" + "type": "drawSelector", + "image": "winskin.png", + "code": 1, + "x": 245, + "y": "261 + 40*flag:selection", + "width": 120, + "height": 40 }, { - "type": "comment", - "text": "也可以贴按钮图然后使用等待操作来完成" - }, - { - "type": "choices", - "choices": [ + "type": "wait", + "data": [ { - "text": "开始游戏", + "case": "keyboard", + "keycode": "13,32", + "break": true, "action": [ { - "type": "comment", - "text": "检查bgm状态,下同" - }, - { - "type": "function", - "function": "function(){\ncore.control.checkBgm()\n}" - }, - { - "type": "if", - "condition": "main.levelChoose.length == 0", - "true": [ + "type": "switch", + "condition": "flag:selection", + "caseList": [ { - "type": "comment", - "text": "直接开始游戏" - } - ], - "false": [ - { - "type": "comment", - "text": "动态生成难度选择项" + "case": "0", + "action": [ + { + "type": "comment", + "text": "在“开始游戏”确定" + }, + { + "type": "break", + "n": 1 + } + ] }, { - "type": "function", - "function": "function(){\nvar choices = [];\nmain.levelChoose.forEach(function (one) {\n\tchoices.push({\n\t\t\"text\": one.title || '',\n\t\t\"action\": [\n\t\t\t{ \"type\": \"function\", \"function\": \"function() { core.status.hard = '\" + (one.name || '') + \"'; }\" }\n\t\t]\n\t});\n})\ncore.insertAction({ \"type\": \"choices\", \"choices\": choices });\n}" + "case": "1", + "action": [ + { + "type": "comment", + "text": "在“读取存档”确定" + }, + { + "type": "callLoad" + } + ] + }, + { + "case": "2", + "action": [ + { + "type": "comment", + "text": "在“回放录像”确定" + }, + { + "type": "if", + "condition": "(!core.isReplaying())", + "true": [ + { + "type": "function", + "function": "function(){\ncore.chooseReplayFile()\n}" + } + ] + } + ] } ] - }, - { - "type": "hideImage", - "code": 1, - "time": 0 - }, - { - "type": "comment", - "text": "成功选择难度" - }, - { - "type": "break" } ] }, { - "text": "读取存档", + "case": "keyboard", + "keycode": "38", + "break": true, "action": [ { - "type": "function", - "function": "function(){\ncore.control.checkBgm()\n}" + "type": "comment", + "text": "光标上键" }, + { + "type": "setValue", + "name": "flag:selection", + "value": "(flag:selection + 2) % 3" + } + ] + }, + { + "case": "keyboard", + "keycode": "40", + "break": true, + "action": [ { "type": "comment", - "text": "简单的使用“呼出读档界面”来处理" + "text": "光标下键" + }, + { + "type": "setValue", + "name": "flag:selection", + "value": "(flag:selection + 1) % 3" + } + ] + }, + { + "case": "mouse", + "px": [ + 245, + 365 + ], + "py": [ + 261, + 300 + ], + "break": true, + "action": [ + { + "type": "comment", + "text": "点击“开始游戏”" + }, + { + "type": "break", + "n": 1 + } + ] + }, + { + "case": "mouse", + "px": [ + 245, + 365 + ], + "py": [ + 301, + 340 + ], + "break": true, + "action": [ + { + "type": "comment", + "text": "点击“读取存档”" }, { "type": "callLoad" @@ -233,15 +405,20 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = ] }, { - "text": "回放录像", + "case": "mouse", + "px": [ + 245, + 365 + ], + "py": [ + 341, + 380 + ], + "break": true, "action": [ - { - "type": "function", - "function": "function(){\ncore.control.checkBgm()\n}" - }, { "type": "comment", - "text": "这段代码会弹框选择录像文件" + "text": "点击“播放录像”" }, { "type": "if", @@ -259,9 +436,56 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = } ] }, + { + "type": "setValue", + "name": "flag:selection", + "value": "null" + }, + { + "type": "drawSelector", + "code": 1 + }, + { + "type": "clearMap" + }, + { + "type": "function", + "function": "function(){\ncore.control.checkBgm()\n}" + }, + { + "type": "if", + "condition": "(main.levelChoose.length == 0)", + "true": [ + { + "type": "comment", + "text": "没有难度选择:直接开始游戏" + } + ], + "false": [ + { + "type": "comment", + "text": "难度选择:作为样例,这里只提供了一个显示选择项。" + }, + { + "type": "function", + "function": "function(){\nvar choices = [];\nmain.levelChoose.forEach(function (one) {\n\tchoices.push({\n\t\t\"text\": one.title || '',\n\t\t\"action\": [\n\t\t\t{ \"type\": \"function\", \"function\": \"function() { core.status.hard = '\" + (one.name || '') + \"'; }\" }\n\t\t]\n\t});\n})\ncore.insertAction({ \"type\": \"choices\", \"choices\": choices });\n}" + }, + { + "type": "comment", + "text": "你也可以仿照上面的样例进行自己创建等待用户操作来处理不同的难度分歧。\n如需自己处理,请设置 core.status.hard \n(例如,自定义js脚本:core.status.hard = 'Easy' )" + } + ] + }, + { + "type": "clearMap" + }, { "type": "comment", "text": "接下来会执行startText中的事件" + }, + { + "type": "comment", + "text": "状态栏默认处于隐藏状态;可以使用“显示状态栏”事件进行显示。" } ], "startText": [ diff --git a/project/plugins.js b/project/plugins.js index aaf1d455..3757b2f2 100644 --- a/project/plugins.js +++ b/project/plugins.js @@ -1310,5 +1310,92 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = } return false; } +}, + "startCanvas": function () { + // 使用本插件可以将自绘的标题界面居中。仅在【标题开启事件化】后才有效。 + // 由于一些技术性的原因,标题界面事件化无法应用到覆盖状态栏的整个界面。 + // 这是一个较为妥协的插件,会在自绘标题界面时隐藏状态栏、工具栏和边框,并将画布进行居中。 + // 本插件仅在全塔属性的 "startCanvas" 生效;进入 "startText" 时将会离开居中状态,回归正常界面。 + + // 是否开启本插件,默认禁用;将此改成 true 将启用本插件。 + var __enable = true; + if (!__enable) return; + + // 检查【标题开启事件化】是否开启 + if (!core.flags.startUsingCanvas || main.mode != 'play') return; + + + var _isTitleCanvasEnabled = false; + var _getClickLoc = core.actions._getClickLoc; + this._setTitleCanvas = function () { + if (_isTitleCanvasEnabled) return; + _isTitleCanvasEnabled = true; + + // 禁用窗口resize + window.onresize = function () {}; + core.resize = function () {} + + // 隐藏状态栏 + core.dom.statusBar.style.display = 'none'; + core.dom.statusCanvas.style.display = 'none'; + core.dom.toolBar.style.display = 'none'; + // 居中画布 + if (core.domStyle.isVertical) { + core.dom.gameDraw.style.top = + (parseInt(core.dom.gameGroup.style.height) - parseInt(core.dom.gameDraw.style.height)) / 2 + "px"; + } else { + core.dom.gameDraw.style.right = + (parseInt(core.dom.gameGroup.style.width) - parseInt(core.dom.gameDraw.style.width)) / 2 + "px"; + } + core.dom.gameDraw.style.border = '3px transparent solid'; + core.actions._getClickLoc = function (x, y) { + var left = core.dom.gameGroup.offsetLeft + core.dom.gameDraw.offsetLeft + 3; + var top = core.dom.gameGroup.offsetTop + core.dom.gameDraw.offsetTop + 3; + var loc = { 'x': Math.max(x - left, 0), 'y': Math.max(y - top, 0), 'size': 32 * core.domStyle.scale }; + return loc; + } + } + + this._resetTitleCanvas = function () { + if (!_isTitleCanvasEnabled) return; + _isTitleCanvasEnabled = false; + window.onresize = function () { try { main.core.resize(); } catch (e) { main.log(e); } } + core.resize = function () { return core.control.resize(); } + core.resize(); + core.actions._getClickLoc = _getClickLoc; + } + + // 复写“开始游戏” + core.events._startGame_start = function (hard, seed, route, callback) { + console.log('开始游戏'); + core.resetGame(core.firstData.hero, hard, null, core.cloneArray(core.initStatus.maps)); + core.setHeroLoc('x', -1); + core.setHeroLoc('y', -1); + + if (seed != null) { + core.setFlag('__seed__', seed); + core.setFlag('__rand__', seed); + } else core.utils.__init_seed(); + + core.clearStatusBar(); + core.plugin._setTitleCanvas(); + + var todo = []; + core.hideStatusBar(); + core.push(todo, core.firstData.startCanvas); + core.push(todo, { "type": "function", "function": "function() { core.plugin._resetTitleCanvas(); core.events._startGame_setHard(); }" }) + core.push(todo, core.firstData.startText); + this.insertAction(todo, null, null, function () { + core.events._startGame_afterStart(callback); + }); + + if (route != null) core.startReplay(route); + } + + var _loadData = core.control.loadData; + core.control.loadData = function (data, callback) { + core.plugin._resetTitleCanvas(); + _loadData.call(core.control, data, callback); + } } } \ No newline at end of file