diff --git a/README.md b/README.md index 066ff6c4..b81aa04b 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,12 @@ HTML5 canvas制作的魔塔样板,支持全平台游戏! │ ├─ /sounds/ # 音效目录 │ ├─ data.js # 全局变量信息 │ ├─ enemys.js # 怪物属性数据 +│ ├─ events.js # 公共事件 │ ├─ functions.js # 可能会被修改的脚本代码 │ ├─ icons.js # 素材和ID的对应关系定义 │ ├─ items.js # 道具的定义,获得道具的效果 -│ └─ maps.js # 地图和数字的对应关系 +│ ├─ maps.js # 地图和数字的对应关系 +│ └─ plugins.js # 自定义插件 ├── /常用工具/ # 一些常用工具,可以辅助造塔;具体可参见下面的【相关工具】 ├── editor.html # 可视化地图编辑工具 ├── editor-mobile.html # 可视化地图编辑工具(手机版) diff --git a/_docs/event.md b/_docs/event.md index 0ff220b4..73961975 100644 --- a/_docs/event.md +++ b/_docs/event.md @@ -901,6 +901,30 @@ needKey是可选的,如果设置为true则需要钥匙才能打开此门。如 !> needKey仅对当前楼层开门有效!跨楼层的门仍然不需要钥匙即可打开,如有需求请自行判定。 +### closeDoor:关门 + +从V2.6开始提供了关门事件`{"type": "closeDoor"}`,拥有关门动画和对应的音效。 + +``` js +"x,y": [ // 实际执行的事件列表 + {"type": "closeDoor", "id": "yellowDoor", "loc": [3,6]}, // 给(3,6)点关上黄门 + {"type": "closeDoor", "id": "specialDoor"}, // 不写loc则视为当前点 +] +``` + +id为你要关门的ID,需要是一个合法的门,系统默认只支持如下几种: + +``` +yellowDoor, blueDoor, redDoor, greenDoor, specialDoor, steelDoor, +yellowWall, blueWall, whiteWall +``` + +如果需要自己添加门,请参考[新增门和对应的钥匙](personalization#新增门和对应的钥匙)。 + +loc可选,为要关的位置,不填默认为当前点。 + +关门事件需要保证该点是空地,否则将无视此事件。 + ### changeFloor:楼层切换 在事件中也可以对楼层进行切换。一个比较典型的例子就是TSW中,勇士在三楼的陷阱被扔到了二楼,就是一个楼层切换事件。 diff --git a/_server/blockly/MotaAction.g4 b/_server/MotaAction.g4 similarity index 99% rename from _server/blockly/MotaAction.g4 rename to _server/MotaAction.g4 index a31b4afd..6cf3b5d3 100644 --- a/_server/blockly/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -256,6 +256,7 @@ action | waitAsync_s | battle_s | openDoor_s + | closeDoor_s | changeFloor_s | changePos_0_s | changePos_1_s @@ -961,6 +962,23 @@ var code = '{"type": "openDoor"'+floorstr+IdString_0+Bool_0+'},\n'; return code; */; +closeDoor_s + : '关门' 'x' PosString? ',' 'y' PosString? 'ID' IdString Newline + + +/* closeDoor_s +tooltip : closeDoor: 关门事件,需要该点本身无事件 +helpUrl : https://h5mota.com/games/template/docs/#/event?id=opendoor%EF%BC%9A%E5%BC%80%E9%97%A8 +default : ["","","yellowDoor"] +colour : this.dataColor +var floorstr = ''; +if (PosString_0 && PosString_1) { + floorstr = ', "loc": ['+PosString_0+','+PosString_1+']'; +} +var code = '{"type": "closeDoor", "id": "'+IdString_0+'"'+floorstr+'},\n'; +return code; +*/; + changeFloor_s : '楼层切换' IdString? 'x' PosString? ',' 'y' PosString? '朝向' DirectionEx_List '动画时间' Int? Newline @@ -2338,6 +2356,11 @@ ActionParser.prototype.parseAction = function() { this.next = MotaActionBlocks['openDoor_s'].xmlText([ data.loc[0],data.loc[1],data.floorId||'',data.needKey||false,this.next]); break; + case "closeDoor": // 关一个门,需要该点无事件 + data.loc=data.loc||['',''] + this.next = MotaActionBlocks['closeDoor_s'].xmlText([ + data.loc[0],data.loc[1],data.id,this.next]); + break; case "useItem": // 使用道具 this.next = MotaActionBlocks['useItem_s'].xmlText([ data.id,this.next]); diff --git a/_server/editor.js b/_server/editor.js index 0923d516..b675d7ff 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -721,7 +721,7 @@ editor.prototype.listen = function () { mouseOutCheck = 2; setTimeout(clear1); e.stopPropagation(); - uc.clearRect(0, 0, core.__SIZE__, core.__SIZE__); + uc.clearRect(0, 0, core.__PIXELS__, core.__PIXELS__); var loc = eToLoc(e); var pos = locToPos(loc,true); stepPostfix = []; diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 017805b8..7fdf310f 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -93,6 +93,7 @@ editor_blockly = function () { MotaActionBlocks['changePos_1_s'].xmlText(), MotaActionBlocks['battle_s'].xmlText(), MotaActionBlocks['openDoor_s'].xmlText(), + MotaActionBlocks['closeDoor_s'].xmlText(), MotaActionBlocks['useItem_s'].xmlText(), MotaActionBlocks['openShop_s'].xmlText(), MotaActionBlocks['setBlock_s'].xmlText(), @@ -312,7 +313,8 @@ document.getElementById('blocklyDiv').onmousewheel = function(e){ //console.log(e); e.preventDefault(); var hvScroll = e.shiftKey?'hScroll':'vScroll'; - workspace.scrollbar[hvScroll].handlePosition_+=( ((e.deltaY||0)+(e.detail||0)) >0?20:-20); + var mousewheelOffsetValue=20/380*workspace.scrollbar[hvScroll].handleLength_*3; + workspace.scrollbar[hvScroll].handlePosition_+=( ((e.deltaY||0)+(e.detail||0)) >0?mousewheelOffsetValue:-mousewheelOffsetValue); workspace.scrollbar[hvScroll].onScroll_(); workspace.setScale(workspace.scale); } @@ -442,13 +444,13 @@ function omitedcheckUpdateFunction(event) { xhr.onreadystatechange = function () { if (xhr.readyState != 4) return; if (xhr.status != 200) { - alert("无法在file://下加载"); + alert("图块描述文件加载失败, 请在'启动服务.exe'中打开编辑器"); return; } input_ = xhr.responseText; editor_blockly.runOne(); } - xhr.open('GET', '_server/blockly/MotaAction.g4', true); + xhr.open('GET', '_server/MotaAction.g4', true); xhr.send(null); codeAreaHL = CodeMirror.fromTextArea(document.getElementById("codeArea"), { diff --git a/_server/events.comment.js b/_server/events.comment.js index 62fdbfef..a96301d7 100644 --- a/_server/events.comment.js +++ b/_server/events.comment.js @@ -13,14 +13,21 @@ var events_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_type": "event", "_range": "thiseval instanceof Array", "_event": "commonEvent", - "_data": "打败怪物后进行加点" + "_data": "打败怪物后加点" }, "毒衰咒处理": { "_leaf": true, "_type": "event", "_range": "thiseval instanceof Array", "_event": "commonEvent", - "_data": "对毒衰咒效果进行的处理" + "_data": "毒衰咒效果处理" + }, + "滑冰事件": { + "_leaf": true, + "_type": "event", + "_range": "thiseval instanceof Array", + "_event": "commonEvent", + "_data": "滑冰事件" }, } if (obj[key]) return obj[key]; diff --git a/_server/functions.comment.js b/_server/functions.comment.js index 2120f717..1d295260 100644 --- a/_server/functions.comment.js +++ b/_server/functions.comment.js @@ -42,6 +42,12 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_lint": true, "_data": "切换楼层后" }, + "flyTo": { + "_leaf": true, + "_type": "textarea", + "_lint": true, + "_data": "楼层飞行" + }, "beforeBattle": { "_leaf": true, "_type": "textarea", @@ -147,12 +153,6 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_lint": true, "_data": "读档操作" }, - "flyTo": { - "_leaf": true, - "_type": "textarea", - "_lint": true, - "_data": "楼层飞行" - }, "updateStatusBar": { "_leaf": true, "_type": "textarea", @@ -176,6 +176,12 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_type": "textarea", "_lint": true, "_data": "瞬间移动处理" + }, + "parallelDo": { + "_leaf": true, + "_type": "textarea", + "_lint": true, + "_data": "并行事件处理" } } }, @@ -201,23 +207,6 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_data": "绘制关于界面" } } - }, - "plugins": { - "_type": "object", - "_data": { - "parallelDo": { - "_leaf": true, - "_type": "textarea", - "_lint": true, - "_data": "并行事件处理" - }, - "plugin": { - "_leaf": true, - "_type": "textarea", - "_lint": true, - "_data": "自定义插件编写" - } - } } } } \ No newline at end of file diff --git a/_server/plugins.comment.js b/_server/plugins.comment.js index 20a3f361..e708c576 100644 --- a/_server/plugins.comment.js +++ b/_server/plugins.comment.js @@ -3,17 +3,17 @@ var plugins_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_type": "object", "_data": function (key) { var obj = { - "test": { + "init": { "_leaf": true, "_type": "textarea", "_range": "typeof(thiseval)=='string'", - "_data": "插件函数执行测试, 这个函数在导入后被直接执行(因此不允许删除)" + "_data": "自定义插件" }, "drawLight": { "_leaf": true, "_type": "textarea", "_range": "typeof(thiseval)=='string' || thiseval==null", - "_data": "绘制灯光/漆黑层效果" + "_data": "绘制灯光效果" }, } if (obj[key]) return obj[key]; diff --git a/editor-mobile.html b/editor-mobile.html index 5f9ce2d9..67c58418 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -503,7 +503,7 @@ -
请输入文字...
diff --git a/editor.html b/editor.html index a8f8e1b3..391c4745 100644 --- a/editor.html +++ b/editor.html @@ -486,7 +486,7 @@请输入文字...
diff --git a/libs/actions.js b/libs/actions.js index 44574b82..5bf8c43a 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -94,7 +94,7 @@ actions.prototype.doRegisteredAction = function (action) { var actions = this.actions[action]; if (!actions) return false; for (var i = 0; i < actions.length; ++i) { - if (core.doFunc.apply(this, [actions[i].func].concat(Array.prototype.slice.call(arguments, 1)))) + if (core.doFunc.apply(core, [actions[i].func, this].concat(Array.prototype.slice.call(arguments, 1)))) return true; } return false; @@ -109,7 +109,7 @@ actions.prototype.checkReplaying = function () { ////// 检查是否在录像播放中,如果是,则停止交互 actions.prototype._sys_checkReplay = function () { - if (this.checkReplaying()) return true; + if (core.actions.checkReplaying()) return true; } ////// 按下某个键时 ////// @@ -127,10 +127,10 @@ actions.prototype._sys_onkeyDown = function (e) { } } core.status.holdingKeys.push(e.keyCode); - this.pressKey(e.keyCode); + core.actions.pressKey(e.keyCode); } else { if (e.keyCode == 17) core.status.ctrlDown = true; - this.keyDown(e.keyCode); + core.actions.keyDown(e.keyCode); } } @@ -140,7 +140,7 @@ actions.prototype.onkeyUp = function (e) { } actions.prototype._sys_onkeyUp_replay = function (e) { - if (this.checkReplaying()) { + if (core.actions.checkReplaying()) { if (e.keyCode == 27) // ESCAPE core.stopReplay(); else if (e.keyCode == 90) // Z @@ -179,10 +179,10 @@ actions.prototype._sys_onkeyUp = function (e) { break; } } - this.keyUp(e.keyCode, e.altKey); + core.actions.keyUp(e.keyCode, e.altKey); } else { if (e.keyCode == 17) core.status.ctrlDown = false; - this.keyUp(e.keyCode, e.altKey); + core.actions.keyUp(e.keyCode, e.altKey); } } @@ -209,32 +209,32 @@ actions.prototype._sys_keyDown_lockControl = function (keyCode) { if (!core.status.lockControl) return false; // Ctrl跳过对话 if (keyCode == 17) { - this.keyDownCtrl(); + core.actions.keyDownCtrl(); return true; } switch (core.status.event.id) { case 'action': - this._keyDownAction(keyCode); + core.actions._keyDownAction(keyCode); break; case 'book': - this._keyDownBook(keyCode); + core.actions._keyDownBook(keyCode); break; case 'fly': - this._keyDownFly(keyCode); + core.actions._keyDownFly(keyCode); break; case 'viewMaps': - this._keyDownViewMaps(keyCode); + core.actions._keyDownViewMaps(keyCode); break; case 'equipbox': - this._keyDownEquipbox(keyCode); + core.actions._keyDownEquipbox(keyCode); break; case 'toolbox': - this._keyDownToolbox(keyCode); + core.actions._keyDownToolbox(keyCode); break; case 'save': case 'load': case 'replayLoad': - this._keyDownSL(keyCode); + core.actions._keyDownSL(keyCode); break; case 'shop': case 'selectShop': @@ -246,10 +246,10 @@ actions.prototype._sys_keyDown_lockControl = function (keyCode) { case 'storageRemove': case 'replay': case 'gameInfo': - this._keyDownChoices(keyCode); + core.actions._keyDownChoices(keyCode); break; case 'cursor': - this._keyDownCursor(keyCode); + core.actions._keyDownCursor(keyCode); break; } return true; @@ -282,7 +282,7 @@ actions.prototype.keyUp = function (keyCode, altKey, fromReplay) { } actions.prototype._sys_keyUp_replay = function (keyCode, altKey, fromReplay) { - if (!fromReplay && this.checkReplaying()) return true; + if (!fromReplay && core.actions.checkReplaying()) return true; } actions.prototype._sys_keyUp_lockControl = function (keyCode, altKey) { @@ -298,10 +298,10 @@ actions.prototype._sys_keyUp_lockControl = function (keyCode, altKey) { ok() && core.drawText(); break; case 'confirmBox': - this._keyUpConfirmBox(keyCode); + core.actions._keyUpConfirmBox(keyCode); break; case 'action': - this._keyUpAction(keyCode); + core.actions._keyUpAction(keyCode); break; case 'about': ok() && core.ui.closePanel(); @@ -310,69 +310,69 @@ actions.prototype._sys_keyUp_lockControl = function (keyCode, altKey) { ok() && core.ui.closePanel(); break; case 'book': - this._keyUpBook(keyCode); + core.actions._keyUpBook(keyCode); break; case 'book-detail': - ok() && this._clickBookDetail(); + ok() && core.actions._clickBookDetail(); break; case 'fly': this._keyUpFly(keyCode); break; case 'viewMaps': - this._keyUpViewMaps(keyCode); + core.actions._keyUpViewMaps(keyCode); break; case 'shop': - this._keyUpShop(keyCode); + core.actions._keyUpShop(keyCode); break; case 'selectShop': - this._keyUpQuickShop(keyCode); + core.actions._keyUpQuickShop(keyCode); break; case 'toolbox': - this._keyUpToolbox(keyCode); + core.actions._keyUpToolbox(keyCode); break; case 'equipbox': - this._keyUpEquipbox(keyCode, altKey); + core.actions._keyUpEquipbox(keyCode, altKey); break; case 'save': case 'load': case 'replayLoad': - this._keyUpSL(keyCode); + core.actions._keyUpSL(keyCode); break; case 'keyBoard': ok() && core.ui.closePanel(); break; case 'switchs': - this._keyUpSwitchs(keyCode); + core.actions._keyUpSwitchs(keyCode); break; case 'settings': - this._keyUpSettings(keyCode); + core.actions._keyUpSettings(keyCode); break; case 'syncSave': - this._keyUpSyncSave(keyCode); + core.actions._keyUpSyncSave(keyCode); break; case 'syncSelect': - this._keyUpSyncSelect(keyCode); + core.actions._keyUpSyncSelect(keyCode); break; case 'localSaveSelect': - this._keyUpLocalSaveSelect(keyCode); + core.actions._keyUpLocalSaveSelect(keyCode); break; case 'storageRemove': - this._keyUpStorageRemove(keyCode); + core.actions._keyUpStorageRemove(keyCode); break; case 'cursor': - this._keyUpCursor(keyCode); + core.actions._keyUpCursor(keyCode); break; case 'replay': - this._keyUpReplay(keyCode); + core.actions._keyUpReplay(keyCode); break; case 'gameInfo': - this._keyUpGameInfo(keyCode); + core.actions._keyUpGameInfo(keyCode); break; case 'centerFly': - this._keyUpCenterFly(keyCode); + core.actions._keyUpCenterFly(keyCode); break; case 'paint': - this._keyUpPaint(keyCode); + core.actions._keyUpPaint(keyCode); break; } return true; @@ -399,7 +399,7 @@ actions.prototype.ondown = function (loc) { actions.prototype._sys_ondown_paint = function (x, y, px, py) { // 画板 if (core.status.played && (core.status.event || {}).id == 'paint') { - this._ondownPaint(px, py); + core.actions._ondownPaint(px, py); return true; } } @@ -418,7 +418,7 @@ actions.prototype._sys_ondown_lockControl = function (x, y, px, py) { core.doAction(); } else { - this.onclick(x, y, []); + core.actions.onclick(x, y, []); } // --- 长按判定 @@ -456,7 +456,7 @@ actions.prototype.onmove = function (loc) { actions.prototype._sys_onmove_paint = function (x, y, px, py) { // 画板 if (core.status.played && (core.status.event || {}).id == 'paint') { - this._onmovePaint(px, py); + core.actions._onmovePaint(px, py); return true; } } @@ -492,7 +492,7 @@ actions.prototype.onup = function () { actions.prototype._sys_onup_paint = function () { // 画板 if (core.status.played && (core.status.event || {}).id == 'paint') { - this._onupPaint(); + core.actions._onupPaint(); return true; } } @@ -525,11 +525,11 @@ actions.prototype._sys_onup = function () { // 长按 if (!core.status.lockControl && stepPostfix.length == 0 && core.status.downTime != null && new Date() - core.status.downTime >= 1000) { - this.longClick(posx, posy); + core.actions.longClick(posx, posy); } else { //posx,posy是寻路的目标点,stepPostfix是后续的移动 - this.onclick(posx, posy, stepPostfix); + core.actions.onclick(posx, posy, stepPostfix); } core.status.downTime = null; return true; @@ -567,75 +567,75 @@ actions.prototype._sys_onclick_lockControl = function (x, y) { if (!core.status.lockControl) return false; switch (core.status.event.id) { case 'centerFly': - this._clickCenterFly(x, y); + core.actions._clickCenterFly(x, y); break; case 'book': - this._clickBook(x, y); + core.actions._clickBook(x, y); break; case 'book-detail': - this._clickBookDetail(x, y); + core.actions._clickBookDetail(x, y); break; case 'fly': - this._clickFly(x, y); + core.actions._clickFly(x, y); break; case 'viewMaps': - this._clickViewMaps(x, y); + core.actions._clickViewMaps(x, y); break; case 'switchs': - this._clickSwitchs(x, y); + core.actions._clickSwitchs(x, y); break; case 'settings': - this._clickSettings(x, y); + core.actions._clickSettings(x, y); break; case 'shop': - this._clickShop(x, y); + core.actions._clickShop(x, y); break; case 'selectShop': - this._clickQuickShop(x, y); + core.actions._clickQuickShop(x, y); break; case 'equipbox': - this._clickEquipbox(x, y); + core.actions._clickEquipbox(x, y); break; case 'toolbox': - this._clickToolbox(x, y); + core.actions._clickToolbox(x, y); break; case 'save': case 'load': case 'replayLoad': - this._clickSL(x, y); + core.actions._clickSL(x, y); break; case 'confirmBox': - this._clickConfirmBox(x, y); + core.actions._clickConfirmBox(x, y); break; case 'keyBoard': - this._clickKeyBoard(x, y); + core.actions._clickKeyBoard(x, y); break; case 'action': - this._clickAction(x, y); + core.actions._clickAction(x, y); break; case 'text': core.drawText(); break; case 'syncSave': - this._clickSyncSave(x, y); + core.actions._clickSyncSave(x, y); break; case 'syncSelect': - this._clickSyncSelect(x, y); + core.actions._clickSyncSelect(x, y); break; case 'localSaveSelect': - this._clickLocalSaveSelect(x, y); + core.actions._clickLocalSaveSelect(x, y); break; case 'storageRemove': - this._clickStorageRemove(x, y); + core.actions._clickStorageRemove(x, y); break; case 'cursor': - this._clickCursor(x, y); + core.actions._clickCursor(x, y); break; case 'replay': - this._clickReplay(x, y); + core.actions._clickReplay(x, y); break; case 'gameInfo': - this._clickGameInfo(x, y); + core.actions._clickGameInfo(x, y); break; case 'about': case 'help': @@ -668,8 +668,8 @@ actions.prototype._sys_onmousewheel = function (direct) { // 楼层飞行器 if (core.status.lockControl && core.status.event.id == 'fly') { - if (direct == 1) core.ui.drawFly(this._getNextFlyFloor(1)); - if (direct == -1) core.ui.drawFly(this._getNextFlyFloor(-1)); + if (direct == 1) core.ui.drawFly(core.actions._getNextFlyFloor(1)); + if (direct == -1) core.ui.drawFly(core.actions._getNextFlyFloor(-1)); return; } @@ -689,8 +689,8 @@ actions.prototype._sys_onmousewheel = function (direct) { // 浏览地图 if (core.status.lockControl && core.status.event.id == 'viewMaps') { - if (direct == 1) this._clickViewMaps(6, 3); - if (direct == -1) this._clickViewMaps(6, 9); + if (direct == 1) core.actions._clickViewMaps(6, 3); + if (direct == -1) core.actions._clickViewMaps(6, 9); return; } @@ -740,7 +740,7 @@ actions.prototype._sys_longClick_lockControl = function (x, y) { // 长按楼传器的箭头可以快速翻页 if (core.status.event.id == 'fly') { if ((x == 10 || x == 11) && (y == 5 || y == 9)) { - this._clickFly(x, y); + core.actions._clickFly(x, y); return true; } } @@ -774,12 +774,12 @@ actions.prototype._sys_longClick = function (x, y, fromEvent) { actions.prototype._selectChoices = function (length, keycode, callback) { var topIndex = 6 - parseInt((length - 1) / 2); if (keycode == 13 || keycode == 32 || keycode == 67) { - callback(6, topIndex + core.status.event.selection); + callback.apply(this, [6, topIndex + core.status.event.selection]); } if (keycode >= 49 && keycode <= 57) { var index = keycode - 49; if (index < length) { - callback(6, topIndex + index); + callback.apply(this, [6, topIndex + index]); } } } @@ -1754,53 +1754,24 @@ actions.prototype._clickSwitchs = function (x, y) { var topIndex = 6 - parseInt((choices.length - 1) / 2); if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; + core.status.event.selection = selection; switch (selection) { case 0: - core.triggerBgm(); - core.ui.drawSwitchs(); - break; + return this._clickSwitchs_bgm(); case 1: - core.musicStatus.soundStatus = !core.musicStatus.soundStatus; - core.setLocalStorage('soundStatus', core.musicStatus.soundStatus); - core.ui.drawSwitchs(); - break; + return this._clickSwitchs_sound(); case 2: - core.flags.displayEnemyDamage = !core.flags.displayEnemyDamage; - core.updateDamage(); - core.setLocalStorage('enemyDamage', core.flags.displayEnemyDamage); - core.ui.drawSwitchs(); - break; + return this._clickSwitchs_displayEnemyDamage(); case 3: - core.flags.displayCritical = !core.flags.displayCritical; - core.updateDamage(); - core.setLocalStorage('critical', core.flags.displayCritical); - core.ui.drawSwitchs(); - break; + return this._clickSwitchs_displayCritical(); case 4: - core.flags.displayExtraDamage = !core.flags.displayExtraDamage; - core.updateDamage(); - core.setLocalStorage('extraDamage', core.flags.displayExtraDamage); - core.ui.drawSwitchs(); - break; + return this._clickSwitchs_displayExtraDamage(); case 5: - core.platform.useLocalForage = !core.platform.useLocalForage; - core.setLocalStorage('useLocalForage', core.platform.useLocalForage); - core.control.getSaveIndexes(function (indexes) { - core.saves.ids = indexes; - }); - core.ui.drawSwitchs(); - break; + return this._clickSwitchs_localForage(); case 6: - if (core.hasFlag('__noClickMove__')) core.removeFlag('__noClickMove__'); - else core.setFlag('__noClickMove__', true); - core.ui.drawSwitchs(); - break; + return this._clickSwitchs_clickMove(); case 7: - core.platform.extendKeyboard = !core.platform.extendKeyboard; - core.setLocalStorage('extendKeyboard', core.platform.extendKeyboard); - core.updateStatusBar(); - core.ui.drawSwitchs(); - break; + return this._clickSwitchs_ExtendKeyboard(); case 8: core.status.event.selection = 0; core.ui.drawSettings(); @@ -1809,6 +1780,60 @@ actions.prototype._clickSwitchs = function (x, y) { } } +actions.prototype._clickSwitchs_bgm = function () { + core.triggerBgm(); + core.ui.drawSwitchs(); +} + +actions.prototype._clickSwitchs_sound = function () { + core.musicStatus.soundStatus = !core.musicStatus.soundStatus; + core.setLocalStorage('soundStatus', core.musicStatus.soundStatus); + core.ui.drawSwitchs(); +} + +actions.prototype._clickSwitchs_displayEnemyDamage = function () { + core.flags.displayEnemyDamage = !core.flags.displayEnemyDamage; + core.updateDamage(); + core.setLocalStorage('enemyDamage', core.flags.displayEnemyDamage); + core.ui.drawSwitchs(); +} + +actions.prototype._clickSwitchs_displayCritical = function () { + core.flags.displayCritical = !core.flags.displayCritical; + core.updateDamage(); + core.setLocalStorage('critical', core.flags.displayCritical); + core.ui.drawSwitchs(); +} + +actions.prototype._clickSwitchs_displayExtraDamage = function () { + core.flags.displayExtraDamage = !core.flags.displayExtraDamage; + core.updateDamage(); + core.setLocalStorage('extraDamage', core.flags.displayExtraDamage); + core.ui.drawSwitchs(); +} + +actions.prototype._clickSwitchs_localForage = function () { + core.platform.useLocalForage = !core.platform.useLocalForage; + core.setLocalStorage('useLocalForage', core.platform.useLocalForage); + core.control.getSaveIndexes(function (indexes) { + core.saves.ids = indexes; + }); + core.ui.drawSwitchs(); +} + +actions.prototype._clickSwitchs_clickMove = function () { + if (core.hasFlag('__noClickMove__')) core.removeFlag('__noClickMove__'); + else core.setFlag('__noClickMove__', true); + core.ui.drawSwitchs(); +} + +actions.prototype._clickSwitchs_ExtendKeyboard = function () { + core.platform.extendKeyboard = !core.platform.extendKeyboard; + core.setLocalStorage('extendKeyboard', core.platform.extendKeyboard); + core.updateStatusBar(); + core.ui.drawSwitchs(); +} + ////// 系统设置界面时,放开某个键的操作 ////// actions.prototype._keyUpSwitchs = function (keycode) { if (keycode == 27 || keycode == 88) { @@ -1826,7 +1851,7 @@ actions.prototype._clickSettings = function (x, y) { var topIndex = 6 - parseInt((choices.length - 1) / 2); if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; - + core.status.event.selection = selection; switch (selection) { case 0: core.status.event.selection = 0; @@ -1836,11 +1861,11 @@ actions.prototype._clickSettings = function (x, y) { core.ui.drawKeyBoard(); break; case 2: - core.clearLastEvent(); + core.clearSelector(); core.ui.drawMaps(); break; case 3: - core.clearLastEvent(); + core.clearSelector(); core.ui.drawPaint(); break; case 4: @@ -1852,15 +1877,7 @@ actions.prototype._clickSettings = function (x, y) { core.ui.drawGameInfo(); break; case 6: - core.status.event.selection = 1; - core.ui.drawConfirmBox("你确定要返回标题页面吗?", function () { - core.ui.closePanel(); - core.restart(); - }, function () { - core.status.event.selection = 3; - core.ui.drawSettings(); - }); - break; + return core.confirmRestart(true); case 7: core.ui.closePanel(); break; @@ -1885,9 +1902,9 @@ actions.prototype._clickSyncSave = function (x, y) { var topIndex = 6 - parseInt((choices.length - 1) / 2); if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; + core.status.event.selection = selection; switch (selection) { case 0: - // core.syncSave("save"); core.status.event.selection = 0; core.ui.drawSyncSelect(); break; @@ -1899,65 +1916,11 @@ actions.prototype._clickSyncSave = function (x, y) { core.ui.drawLocalSaveSelect(); break; case 3: - core.readFile(function (obj) { - if (obj.name != core.firstData.name) { - alert("存档和游戏不一致!"); - return; - } - if (obj.version != core.firstData.version) { - alert("游戏版本不一致!"); - return; - } - if (!obj.data) { - alert("无效的存档!"); - return; - } - var data = obj.data; - - if (data instanceof Array) { - core.ui.drawConfirmBox("所有本地存档都将被覆盖,确认?", function () { - for (var i = 1; i <= 5 * (main.savePages || 30); i++) { - if (i <= data.length) { - core.setLocalForage("save" + i, data[i - 1]); - } - else { - if (core.saves.ids[i]) - core.removeLocalForage("save" + i); - } - } - core.ui.closePanel(); - core.drawText("读取成功!\n你的本地所有存档均已被覆盖。"); - }, function () { - core.status.event.selection = 0; - core.ui.drawSyncSave(); - }) - } - else { - // core.setLocalStorage("save"+core.saves.saveIndex, data); - core.setLocalForage("save" + core.saves.saveIndex, data, function () { - core.drawText("同步成功!\n单存档已覆盖至存档" + core.saves.saveIndex); - }) - } - }, function () { - - }); - break; + return this._clickSyncSave_readFile(); case 4: - core.status.event.selection = 0; - core.ui.drawReplay(); - break; + return this._clickSyncSave_replay(); case 5: - if (core.hasFlag('debug')) { - core.drawText("\t[系统提示]调试模式下无法下载录像"); - break; - } - core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5route", JSON.stringify({ - 'name': core.firstData.name, - 'hard': core.status.hard, - 'seed': core.getFlag('__seed__'), - 'route': core.encodeRoute(core.status.route) - })); - break; + return this._clickSyncSave_download(); case 6: core.status.event.selection = 0; core.ui.drawStorageRemove(); @@ -1972,6 +1935,38 @@ actions.prototype._clickSyncSave = function (x, y) { return; } +actions.prototype._clickSyncSave_readFile = function () { + core.readFile(function (obj) { + if (obj.name != core.firstData.name) return alert("存档和游戏不一致!"); + if (obj.version != core.firstData.version) return alert("游戏版本不一致!"); + if (!obj.data) return alert("无效的存档!"); + core.control._syncLoad_write(obj.data); + }); +} + +actions.prototype._clickSyncSave_replay = function () { + if (core.hasFlag('debug')) { + core.drawText("\t[系统提示]调试模式下无法回放录像"); + } + else { + core.status.event.selection = 0; + core.ui.drawReplay(); + } +} + +actions.prototype._clickSyncSave_download = function () { + if (core.hasFlag('debug')) { + core.drawText("\t[系统提示]调试模式下无法下载录像"); + return; + } + core.download(core.firstData.name + "_" + core.formatDate2() + ".h5route", JSON.stringify({ + 'name': core.firstData.name, + 'hard': core.status.hard, + 'seed': core.getFlag('__seed__'), + 'route': core.encodeRoute(core.status.route) + })); +} + ////// 同步存档界面时,放开某个键的操作 ////// actions.prototype._keyUpSyncSave = function (keycode) { if (keycode == 27 || keycode == 88) { @@ -1990,6 +1985,7 @@ actions.prototype._clickSyncSelect = function (x, y) { var topIndex = 6 - parseInt((choices.length - 1) / 2); if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; + core.status.event.selection = selection; switch (selection) { case 0: core.syncSave('all'); @@ -2024,6 +2020,7 @@ actions.prototype._clickLocalSaveSelect = function (x, y) { if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; + core.status.event.selection = selection; if (selection < 2) { core.control.getSaves(selection == 0 ? null : core.saves.saveIndex, function (saves) { if (saves) { @@ -2036,10 +2033,10 @@ actions.prototype._clickLocalSaveSelect = function (x, y) { } }) } - } - core.status.event.selection = 2; - core.ui.drawSyncSave(); + core.status.event.selection = 2; + core.ui.drawSyncSave(); + } } ////// 存档下载界面时,放开某个键的操作 ////// @@ -2061,57 +2058,12 @@ actions.prototype._clickStorageRemove = function (x, y) { if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; + core.status.event.selection = selection; switch (selection) { case 0: - 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'); - } - }); - break; + return this._clickStorageRemove_all(); case 1: - 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.drawText("\t[操作成功]当前塔的存档已被清空。"); - core.saves.saveIndex = 1; - core.removeLocalStorage('saveIndex'); - } - break; - }); + return this._clickStorageRemove_current(); case 2: core.status.event.selection = 6; core.ui.drawSyncSave(); @@ -2120,6 +2072,54 @@ actions.prototype._clickStorageRemove = function (x, y) { } } +actions.prototype._clickStorageRemove_all = function () { + core.myconfirm("你确定要清除【全部塔】的所有本地存档?\n此行为不可逆!!!", function () { + var done = function () { + core.saves.autosave.data = null; + core.saves.autosave.updated = false; + core.ui.closePanel(); + core.drawText("\t[操作成功]你的所有存档已被清空。"); + core.saves.saveIndex = 1; + core.removeLocalStorage('saveIndex'); + }; + if (core.platform.useLocalForage) { + core.ui.drawWaiting("正在清空,请稍后..."); + localforage.clear(done); + } + else { + localStorage.clear(); + done(); + } + }); +} + +actions.prototype._clickStorageRemove_current = function () { + core.myconfirm("你确定要清除本塔的所有本地存档?\n此行为不可逆!!!", function () { + var done = function () { + core.saves.autosave.data = null; + core.saves.autosave.updated = false; + core.ui.closePanel(); + core.drawText("\t[操作成功]当前塔的存档已被清空。"); + core.saves.saveIndex = 1; + core.removeLocalStorage('saveIndex'); + } + if (core.platform.useLocalForage) { + core.ui.drawWaiting("正在清空,请稍后..."); + Object.keys(core.saves.ids).forEach(function (v) { + core.removeLocalForage("save" + v); + }); + core.removeLocalForage("autoSave", done); + } + else { + Object.keys(core.saves.ids).forEach(function (v) { + core.removeLocalStorage("save" + v); + }); + core.removeLocalStorage("autoSave"); + done(); + } + }); +} + ////// 存档删除界面时,放开某个键的操作 ////// actions.prototype._keyUpStorageRemove = function (keycode) { if (keycode == 27 || keycode == 88) { @@ -2139,44 +2139,42 @@ actions.prototype._clickReplay = function (x, y) { if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; + core.status.event.selection = selection; switch (selection) { - case 0: { - core.ui.closePanel(); - core.startGame(core.status.hard, core.getFlag('__seed__'), core.clone(core.status.route)); - break; - } - case 1: { - core.status.event.id = 'replayLoad'; - core.status.event.selection = null; - core.ui.clearLastEvent(); - var saveIndex = core.saves.saveIndex; - var page = parseInt((saveIndex - 1) / 5), offset = saveIndex - 5 * page; - core.ui.drawSLPanel(10 * page + offset); - break; - } - case 2: - core.chooseReplayFile(); - break; - case 3: - if (core.hasFlag('debug')) { - core.drawText("\t[系统提示]调试模式下无法下载录像"); - break; - } - core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5route", JSON.stringify({ - 'name': core.firstData.name, - 'hard': core.status.hard, - 'seed': core.getFlag('__seed__'), - 'route': core.encodeRoute(core.status.route) - })); - break; - break; - case 4: - core.ui.closePanel(); - break; + case 0: return this._clickReplay_fromBeginning(); + case 1: return this._clickReplay_fromLoad(); + case 2: return core.chooseReplayFile(); + case 3: return this._clickReplay_download(); + case 4: return core.ui.closePanel(); } } } +actions.prototype._clickReplay_fromBeginning = function () { + core.ui.closePanel(); + core.startGame(core.status.hard, core.getFlag('__seed__'), core.clone(core.status.route)); +} + +actions.prototype._clickReplay_fromLoad = function () { + core.status.event.id = 'replayLoad'; + core.status.event.selection = null; + core.ui.clearSelector(); + var saveIndex = core.saves.saveIndex; + var page = parseInt((saveIndex - 1) / 5), offset = saveIndex - 5 * page; + core.ui.drawSLPanel(10 * page + offset); +} + +actions.prototype._clickReplay_download = function () { + if (core.hasFlag('debug')) return core.drawText("\t[系统提示]调试模式下无法下载录像"); + core.download(core.firstData.name + "_" + core.formatDate2() + ".h5route", JSON.stringify({ + 'name': core.firstData.name, + 'hard': core.status.hard, + 'seed': core.getFlag('__seed__'), + 'route': core.encodeRoute(core.status.route) + })); + +} + ////// 回放选择界面时,放开某个键的操作 ////// actions.prototype._keyUpReplay = function (keycode) { if (keycode == 27 || keycode == 88) { @@ -2195,41 +2193,14 @@ actions.prototype._clickGameInfo = function (x, y) { if (y >= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; + core.status.event.selection = selection; switch (selection) { - case 0: - core.ui.drawStatistics(); - break; - case 1: - if (core.platform.isPC) - window.open("editor.html", "_blank"); - else { - core.myconfirm("即将离开本塔,跳转至本塔工程页面,确认?", function () { - window.location.href = "editor-mobile.html"; - }); - } - break; - case 2: - if (core.platform.isPC) { - window.open("/score.php?name=" + core.firstData.name + "&num=10", "_blank"); - } - else { - core.myconfirm("即将离开本塔,跳转至本塔评论页面,确认?", function () { - window.location.href = "/score.php?name=" + core.firstData.name + "&num=10"; - }); - } - break; - case 3: - core.ui.drawHelp(); - break; - case 4: - core.ui.drawAbout(); - break; - case 5: - if (core.platform.isPC) - window.open(core.firstData.name + ".zip"); - else - window.location.href = core.firstData.name + ".zip"; - break; + case 0: return core.ui.drawStatistics(); + case 1: return this._clickGameInfo_openProject(); + case 2: return this._clickGameInfo_openComments(); + case 3: return core.ui.drawHelp(); + case 4: return core.ui.drawAbout(); + case 5: return this._clickGameInfo_download(); case 6: core.status.event.selection = 5; core.ui.drawSettings(); @@ -2238,6 +2209,34 @@ actions.prototype._clickGameInfo = function (x, y) { } } +actions.prototype._clickGameInfo_openProject = function () { + if (core.platform.isPC) + window.open("editor.html", "_blank"); + else { + core.myconfirm("即将离开本塔,跳转至本塔工程页面,确认?", function () { + window.location.href = "editor-mobile.html"; + }); + } +} + +actions.prototype._clickGameInfo_openComments = function () { + if (core.platform.isPC) { + window.open("/score.php?name=" + core.firstData.name + "&num=10", "_blank"); + } + else { + core.myconfirm("即将离开本塔,跳转至本塔评论页面,确认?", function () { + window.location.href = "/score.php?name=" + core.firstData.name + "&num=10"; + }); + } +} + +actions.prototype._clickGameInfo_download = function () { + if (core.platform.isPC) + window.open(core.firstData.name + ".zip"); + else + window.location.href = core.firstData.name + ".zip"; +} + ////// 游戏信息界面时,放开某个键的操作 ////// actions.prototype._keyUpGameInfo = function (keycode) { if (keycode == 27 || keycode == 88) { diff --git a/libs/control.js b/libs/control.js index ad0ee9cd..3b4ddc2b 100644 --- a/libs/control.js +++ b/libs/control.js @@ -69,7 +69,7 @@ control.prototype._setRequestAnimationFrame = function () { if (b.func) { try { if (core.isPlaying() || !b.needPlaying) - core.doFunc(b.func, timestamp); + core.doFunc(b.func, core.control, timestamp); } catch (e) { main.log(e); @@ -297,7 +297,7 @@ control.prototype._animationFrame_weather_fog = function () { } control.prototype._animationFrame_parallelDo = function (timestamp) { - functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.plugins.parallelDo(timestamp); + core.control.controldata.parallelDo(timestamp); } control.prototype._animationFrame_checkConsoleOpened = function (timestamp) { @@ -357,6 +357,24 @@ control.prototype.restart = function() { core.playBgm(main.startBgm); } +////// 询问是否需要重新开始 ////// +control.prototype.confirmRestart = function (fromSettings) { + core.status.event.selection = 1; + core.ui.drawConfirmBox("你确定要返回标题页面吗?", function () { + core.ui.closePanel(); + core.restart(); + }, function () { + if (fromSettings) { + core.status.event.selection = 3; + core.ui.drawSettings(); + } + else { + core.ui.closePanel(); + } + }); +} + + ////// 清除游戏状态和数据 ////// control.prototype.clearStatus = function() { // 停止各个Timeout和Interval @@ -607,8 +625,6 @@ control.prototype.moveAction = function (callback) { } control.prototype._moveAction_noPass = function (canMove, callback) { - if (core.status.event.id!='ski') - core.status.route.push(core.getHeroLoc('direction')); core.status.automaticRoute.moveStepBeforeStop = []; core.status.automaticRoute.lastDirection = core.getHeroLoc('direction'); if (canMove) core.events._trigger(core.nextX(), core.nextY()); @@ -625,8 +641,6 @@ control.prototype._moveAction_moving = function (callback) { core.setHeroMoveInterval(function () { var direction = core.getHeroLoc('direction'); core.control._moveAction_popAutomaticRoute(); - if (core.status.event.id!='ski') - core.status.route.push(direction); // 无事件的道具(如血瓶)需要优先于阻激夹域判定 var nowx = core.getHeroLoc('x'), nowy = core.getHeroLoc('y'); @@ -639,10 +653,17 @@ control.prototype._moveAction_moving = function (callback) { } // 执行该点的阻激夹域事件 core.checkBlock(); + // 执行该点事件 if (!hasTrigger) core.events._trigger(nowx, nowy); core.updateStatusBar(); + + // 检查该点是否是滑冰 + if (core.getBgFgNumber('bg') == 167) { + core.insertAction("滑冰事件", null, null, null, true); + } + if (callback) callback(); }); } @@ -1239,7 +1260,7 @@ control.prototype.unregisterReplayAction = function (name) { control.prototype._doReplayAction = function (action) { for (var i in this.replayActions) { try { - if (core.doFunc(this.replayActions[i].func, action)) return true; + if (core.doFunc(this.replayActions[i].func, this, action)) return true; } catch (e) { main.log(e); main.log("ERROR in replayActions["+this.replayActions[i].name+"]:已自动注销该项。"); @@ -1411,7 +1432,7 @@ control.prototype._replayAction_shop = function (action) { } control.prototype._replayAction_turn = function (action) { - if (action != 'turn' || action.indexOf('turn:') != 0) return false; + if (action != 'turn' && action.indexOf('turn:') != 0) return false; if (action == 'turn') core.turnHero(); else core.turnHero(action.substring(5)); setTimeout(core.replay); @@ -1558,7 +1579,7 @@ control.prototype._doSL_replayLoad = function (id) { else{ core.getLocalForage(id=='autoSave'?id:"save"+id, null, function(data) { if (id == 'autoSave') core.saves.autosave.data = core.clone(data); - core.control._doSL_replayLoad_afterGet(data); + core.control._doSL_replayLoad_afterGet(id, data); }, function(err) { main.log(err); alert("无效的存档"); @@ -1946,10 +1967,10 @@ control.prototype.setFg = function(color, time, callback) { return; } - this._setFg_animate(core.status.curtainColor, color, callback); + this._setFg_animate(core.status.curtainColor, color, time, callback); } -control.prototype._setFg_animate = function (nowColor, color, callback) { +control.prototype._setFg_animate = function (nowColor, color, time, callback) { var per_time = 10, step = parseInt(time / per_time); var animate = setInterval(function() { nowColor = [ @@ -1962,7 +1983,7 @@ control.prototype._setFg_animate = function (nowColor, color, callback) { core.fillRect('curtain', 0, 0, core.__PIXELS__, core.__PIXELS__, core.arrayToRGBA(nowColor)); step--; if (step <= 0) { - delete core.animate.asyncId[animate]; + delete core.animateFrame.asyncId[animate]; clearInterval(animate); core.status.curtainColor = color; if (core.isset(callback)) callback(); @@ -2375,7 +2396,7 @@ control.prototype.unregisterResize = function (name) { control.prototype._doResize = function (obj) { for (var i in this.resizes) { try { - if (core.doFunc(this.resizes[i].func, obj)) return true; + if (core.doFunc(this.resizes[i].func, this, obj)) return true; } catch (e) { main.log(e); main.log("ERROR in resizes["+this.resizes[i].name+"]:已自动注销该项。"); diff --git a/libs/core.js b/libs/core.js index 61cb7d6d..58d41ec9 100644 --- a/libs/core.js +++ b/libs/core.js @@ -20,7 +20,7 @@ function core() { 'events': {} } this.timeout = { - 'getItemTipTimeout': null, + 'tipTimeout': null, 'turnHeroTimeout': null, 'onDownTimeout': null, 'sleepTimeout': null, @@ -194,7 +194,6 @@ function core() { }, 'curtainColor': null, 'openingDoor': null, - 'isSkiing': false, // 动画 'globalAnimateObjs': [], @@ -242,8 +241,6 @@ core.prototype._init_flags = function () { document.getElementById("startLogo").innerHTML = core.firstData.title; (core.firstData.shops||[]).forEach(function (t) { core.initStatus.shops[t.id] = t; }); core.maps._setFloorSize(); - // 初始化地图 - core.initStatus.maps = core.maps.initMaps(core.floorIds); // 初始化怪物、道具等 core.material.enemys = core.enemys.getEnemys(); core.material.items = core.items.getItems(); @@ -337,17 +334,32 @@ core.prototype._init_others = function () { } core.prototype._afterLoadResources = function (callback) { + // 初始化地图 + core.initStatus.maps = core.maps.initMaps(core.floorIds); core.control._setRequestAnimationFrame(); - - core.plugin = new function () {}; - core.plugin.__init__ = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.plugins.plugin; - core.plugin.__init__(); - core._forwardFunc("plugin"); - + core._initPlugins(); core.showStartAnimate(); if (callback) callback(); } +core.prototype._initPlugins = function () { + core.plugin = new function () {}; + + for (var name in plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1) { + if (plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1[name] instanceof Function) { + try { + plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1[name].apply(core.plugin); + } + catch (e) { + main.log(e); + main.log("无法初始化插件"+name); + } + } + } + + core._forwardFunc("plugin"); +} + core.prototype._forwardFuncs = function () { for (var i = 0; i < main.loadList.length; ++i) { var name = main.loadList[i]; @@ -376,9 +388,12 @@ core.prototype._forwardFunc = function (name, funcname) { eval("core." + funcname + " = function (" + parameters + ") {\n\treturn core." + name + "." + funcname + "(" + parameters + ");\n}"); } -core.prototype.doFunc = function (func) { - if (typeof func == 'string') func = core.plugin[func]; - return func.apply(this, Array.prototype.slice.call(arguments, 1)); +core.prototype.doFunc = function (func, _this) { + if (typeof func == 'string') { + func = core.plugin[func]; + _this = core.plugin; + } + return func.apply(_this, Array.prototype.slice.call(arguments, 2)); } /** diff --git a/libs/events.js b/libs/events.js index cf447186..5aa7f0a4 100644 --- a/libs/events.js +++ b/libs/events.js @@ -247,7 +247,7 @@ events.prototype.unregisterSystemEvent = function (type) { events.prototype.doSystemEvent = function (type, data, callback) { if (this.systemEvents[type]) { try { - return core.doFunc(this.systemEvents[type], data, data, callback); + return core.doFunc(this.systemEvents[type], this, data, data, callback); } catch (e) { main.log(e); @@ -264,14 +264,12 @@ events.prototype._trigger = function (x, y) { // 如果已经死亡,或正处于某事件中,则忽略 if (core.status.gameOver || core.status.event.id) return; - core.status.isSkiing = false; var block = core.getBlock(x, y); if (block == null) return; block = block.block; if (block.event.trigger) { var noPass = block.event.noPass, trigger = block.event.trigger; if (noPass) core.clearAutomaticRouteNode(x, y); - if (trigger == 'ski') core.status.isSkiing = true; // 转换楼层能否穿透 if (trigger == 'changeFloor' && !noPass && this._trigger_ignoreChangeFloor(block)) @@ -346,10 +344,15 @@ events.prototype._sys_openDoor = function (data, callback) { events.prototype.openDoor = function (id, x, y, needKey, callback) { id = id || core.getBlockId(x, y); core.saveAndStopAutomaticRoute(); - if (!this._openDoor_check(id, x, y, needKey)) return false; + if (!this._openDoor_check(id, x, y, needKey)) { + core.waitHeroToStop(function () { + core.unLockControl(); + if (callback) callback(); + }); + return; + } core.playSound("door.mp3"); this._openDoor_animate(id, x, y, callback); - return true; } events.prototype._openDoor_check = function (id, x, y, needKey) { @@ -663,29 +666,7 @@ events.prototype.afterChangeLight = function (x, y) { } events.prototype._sys_ski = function (data, callback) { - this.ski(); - if (callback) callback(); -} - -////// 滑冰 ////// -events.prototype.ski = function (direction) { - if (!direction) - direction = core.status.automaticRoute.lastDirection || core.getHeroLoc('direction'); - if (core.status.event.id != 'ski') { - core.waitHeroToStop(function () { - core.status.event.id = 'ski'; - core.events.ski(direction); - }); - } - else { - core.moveHero(direction, function () { - if (core.status.event.id == 'ski' && !core.status.isSkiing) { - core.status.event.id = null; - core.unLockControl(); - core.replay(); - } - }) - } + core.insertAction(["V2.6后,请将滑冰放在背景层!"], data.x, data.y, callback); } events.prototype._sys_action = function (data, callback) { @@ -722,7 +703,7 @@ events.prototype.doEvent = function (data, x, y, prefix) { var type = data.type; if (this.actions[type]) { try { - return core.doFunc(this.actions[type], data, x, y, prefix); + return core.doFunc(this.actions[type], this, data, x, y, prefix); } catch (e) { main.log(e); @@ -755,7 +736,8 @@ events.prototype.setEvents = function (list, x, y, callback) { if (x != null) data.x = x; if (y != null) data.y = y; if (callback) data.callback = callback; - core.status.event = {id: 'action', data: data}; + core.status.event.id = 'action'; + core.status.event.data = data; } ////// 执行当前自定义事件列表中的下一个事件 ////// @@ -764,12 +746,12 @@ events.prototype.doAction = function () { core.status.boxAnimateObjs = []; clearInterval(core.status.event.interval); core.status.event.interval = null; - core.clearLastEvent(); + core.clearSelector(); // 判定是否执行完毕 if (this._doAction_finishEvents()) return; // 当前点坐标和前缀 var x = core.status.event.data.x, y = core.status.event.data.y; - var prefix = [core.status.floorId || "f", x != null ? x : "x", y != null ? y : "y"].join("@"); + var prefix = [core.status.floorId || ":f", x != null ? x : "x", y != null ? y : "y"].join("@"); var current = core.status.event.data.list[0]; if (this._popEvents(current, prefix)) return; // 当前要执行的事件 @@ -809,7 +791,7 @@ events.prototype._popEvents = function (current, prefix) { } ////// 往当前事件列表之前添加一个或多个事件 ////// -events.prototype.insertAction = function (action, x, y, callback) { +events.prototype.insertAction = function (action, x, y, callback, addToLast) { if (core.hasFlag("__statistics__")) return; if (core.status.gameOver) return; @@ -822,7 +804,10 @@ events.prototype.insertAction = function (action, x, y, callback) { this.doEvents(action, x, y, callback); } else { - core.unshift(core.status.event.data.list[0].todo, action); + if (addToLast) + core.push(core.status.event.data.list[0].todo, action) + else + core.unshift(core.status.event.data.list[0].todo, action); this.setEvents(null, x, y, callback); } } @@ -1104,12 +1089,10 @@ events.prototype._action_openDoor = function (data, x, y, prefix) { var loc = this.__action_getLoc(data.loc, x, y, prefix); var floorId = data.floorId || core.status.floorId; if (floorId == core.status.floorId) { - var _callback = function () { + core.openDoor(null, loc[0], loc[1], data.needKey, function () { core.lockControl(); core.doAction(); - } - if (!core.openDoor(null, loc[0], loc[1], data.needKey, _callback)) - _callback(); + }); } else { core.removeBlock(loc[0], loc[1], floorId); @@ -1117,6 +1100,11 @@ events.prototype._action_openDoor = function (data, x, y, prefix) { } } +events.prototype._action_closeDoor = function (data, x, y, prefix) { + var loc = this.__action_getLoc(data.loc, x, y, prefix); + core.closeDoor(loc[0], loc[1], data.id, core.doAction); +} + events.prototype._action_useItem = function (data, x, y, prefix) { // 考虑到可能覆盖楼传事件的问题,这里不对fly进行检查。 if (data.id != 'book' && core.canUseItem(data.id)) { @@ -1153,13 +1141,14 @@ events.prototype._action_trigger = function (data, x, y, prefix) { if (block != null && block.block.event.trigger) { block = block.block; this.setEvents([], block.x, block.y); + var _callback = function () { + core.lockControl(); + core.doAction(); + } if (block.event.trigger == 'action') this.setEvents(block.event.data); else { - core.doSystemEvent(block.event.trigger, block, function () { - core.lockControl(); - core.doAction(); - }); + core.doSystemEvent(block.event.trigger, block, _callback); return; } } @@ -1593,7 +1582,7 @@ events.prototype.useFly = function (fromUserAction) { } events.prototype.flyTo = function (toId, callback) { - return this.controldata.flyTo(toId, callback); + return this.eventdata.flyTo(toId, callback); } ////// 点击装备栏时的打开操作 ////// @@ -1722,7 +1711,7 @@ events.prototype.setValue = function (name, value, prefix, add) { this._setValue_setStatus(name, value); this._setValue_setItem(name, value); this._setValue_setFlag(name, value); - this._setValue_setSwitch(name, value); + this._setValue_setSwitch(name, value, prefix); core.updateStatusBar(); } @@ -1750,7 +1739,7 @@ events.prototype._setValue_setFlag = function (name, value) { events.prototype._setValue_setSwitch = function (name, value, prefix) { if (name.indexOf("switch:") !== 0) return; - core.setFlag((prefix || "f@x@y") + "@" + data.name.substring(7), value); + core.setFlag((prefix || ":f@x@y") + "@" + name.substring(7), value); } ////// 数值增减 ////// @@ -1799,6 +1788,32 @@ events.prototype.setGlobalFlag = function (name, value) { core.resize(); } +events.prototype.closeDoor = function (x, y, id, callback) { + id = id || ""; + if (!(id.endsWith("Door") || id.endsWith("Wall")) + || !core.material.icons.animates[id] || core.getBlock(x, y) != null) { + if (callback) callback(); + return; + } + // 关门动画 + core.playSound('door.mp3'); + var door = core.material.icons.animates[id]; + var speed = id.endsWith("Door") ? 30 : 70, state = 0; + var animate = window.setInterval(function () { + state++; + if (state == 4) { + clearInterval(animate); + delete core.animateFrame.asyncId[animate]; + core.setBlock(core.getNumberById(id), x, y); + if (callback) callback(); + return; + } + core.clearMap('event', 32 * x, 32 * y, 32, 32); + core.drawImage('event', core.material.images.animates, 32 * (4-state), 32 * door, 32, 32, 32 * x, 32 * y, 32, 32); + }, speed / core.status.replay.speed); + core.animateFrame.asyncId[animate] = true; +} + ////// 显示图片 ////// events.prototype.showImage = function (code, image, x, y, dw, dh, opacityVal, time, callback) { dw /= 100; diff --git a/libs/maps.js b/libs/maps.js index 85b4d216..a457b23b 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -331,13 +331,13 @@ maps.prototype.getMapBlocksObj = function (floorId, showDisable) { } ////// 将背景前景层变成二维数组的形式 ////// -maps.prototype.getBgFgMapArray = function (name, floorId, useCache) { +maps.prototype.getBgFgMapArray = function (name, floorId, noCache) { floorId = floorId || core.status.floorId; if (!floorId) return []; var width = core.floors[floorId].width; var height = core.floors[floorId].height; - if (useCache && core.status[name + "maps"][floorId]) + if (!noCache && core.status[name + "maps"][floorId]) return core.status[name + "maps"][floorId]; var arr = core.clone(core.floors[floorId][name + "map"] || []); @@ -352,23 +352,34 @@ maps.prototype.getBgFgMapArray = function (name, floorId, useCache) { if (main.mode == 'editor') arr[y][x] = arr[y][x].idnum || arr[y][x] || 0; } } - if (useCache) + if (core.status[name + "maps"]) core.status[name + "maps"][floorId] = core.clone(arr); return arr; } +maps.prototype.getBgFgNumber = function (name, x, y, floorId, noCache) { + if (x == null) x = core.getHeroLoc('x'); + if (y == null) y = core.getHeroLoc('y'); + return this.getBgFgMapArray(name, floorId, noCache)[y][x]; +} + // ------ 当前能否朝某方向移动,能否瞬间移动 ------ // ////// 生成全图的当前可移动信息 ////// -maps.prototype.generateMovableArray = function (floorId, x, y) { +maps.prototype.generateMovableArray = function (floorId, x, y, direction) { floorId = floorId || core.status.floorId; if (!floorId) return null; var width = core.floors[floorId].width, height = core.floors[floorId].height; - var bgArray = this.getBgFgMapArray('bg', floorId, true), - fgArray = this.getBgFgMapArray('fg', floorId, true), + var bgArray = this.getBgFgMapArray('bg', floorId), + fgArray = this.getBgFgMapArray('fg', floorId), eventArray = this.getMapArray(floorId); - var generate = function (x, y) { + var generate = function (x, y, direction) { + if (direction != null) { + return core.maps._canMoveHero_checkPoint(x, y, direction, floorId, { + bgArray: bgArray, fgArray: fgArray, eventArray: eventArray + }); + } return ["left", "down", "up", "right"].filter(function (direction) { return core.maps._canMoveHero_checkPoint(x, y, direction, floorId, { bgArray: bgArray, fgArray: fgArray, eventArray: eventArray @@ -376,7 +387,7 @@ maps.prototype.generateMovableArray = function (floorId, x, y) { }); } - if (x != null && y != null) return generate(x, y); + if (x != null && y != null) return generate(x, y, direction); var array = []; for (var x = 0; x < width; x++) { array[x] = []; @@ -392,7 +403,7 @@ maps.prototype.canMoveHero = function (x, y, direction, floorId) { if (x == null) x = core.getHeroLoc('x'); if (y == null) y = core.getHeroLoc('y'); direction = direction || core.getHeroLoc('direction'); - return core.inArray(this.generateMovableArray(floorId, x, y), direction); + return this.generateMovableArray(floorId, x, y, direction); } maps.prototype._canMoveHero_checkPoint = function (x, y, direction, floorId, extraData) { @@ -472,6 +483,8 @@ maps.prototype._canMoveDirectly_checkStartPoint = function (sx, sy) { maps.prototype._canMoveDirectly_bfs = function (sx, sy, ex, ey) { var canMoveArray = this.generateMovableArray(); var blocksObj = this.getMapBlocksObj(core.status.floorId); + // 滑冰 + var bgMap = this.getBgFgMapArray('bg'); var visited = [], queue = []; visited[sx + "," + sy] = 0; @@ -483,6 +496,7 @@ maps.prototype._canMoveDirectly_bfs = function (sx, sy, ex, ey) { if (!core.inArray(canMoveArray[x][y], direction)) continue; var nx = x + core.utils.scan[direction].x, ny = y + core.utils.scan[direction].y, nindex = nx + "," + ny; if (visited[nindex]) continue; + if (bgMap[ny][nx] == 167) continue; if (!this._canMoveDirectly_checkNextPoint(blocksObj, nx, ny)) continue; visited[nindex] = visited[now] + 1; if (nx == ex && ny == ey) return visited[nindex]; @@ -565,7 +579,7 @@ maps.prototype._automaticRoute_deepAdd = function (x, y) { // 绕过血瓶 if (!core.flags.potionWhileRouting && id.endsWith("Potion")) deepAdd += 100; // 绕过传送点 - // if (nextBlock.block.event.trigger == 'changeFloor') deepAdd+=10; + // if (block.block.event.trigger == 'changeFloor') deepAdd+=10; } // 绕过存在伤害的地方 deepAdd += (core.status.checkBlock.damage[x+","+y]||0) * 100; @@ -739,7 +753,7 @@ maps.prototype._drawBgFgMap = function (floorId, ctx, name, onMap) { if (!core.status[name + "maps"]) core.status[name + "maps"] = {}; - var arr = this.getBgFgMapArray(name, floorId); + var arr = this.getBgFgMapArray(name, floorId, true); for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var block = this.initBlock(x, y, arr[y][x], true); @@ -1155,7 +1169,7 @@ maps.prototype.getBlockInfo = function (block) { block = this.initBlock(0, 0, block, true); } var number = block.id, id = block.event.id, cls = block.event.cls, - image = null, posX = 0, posY = 0, + image = null, posX = 0, posY = 0, animate = block.event.animate, height = block.event.height || 32, faceIds = {}; if (id == 'none') return null; @@ -1179,7 +1193,7 @@ maps.prototype.getBlockInfo = function (block) { faceIds = block.event.faceIds || {}; } - return {number: number, id: id, cls: cls, image: image, posX: posX, posY: posY, height: height, faceIds: faceIds}; + return {number: number, id: id, cls: cls, image: image, posX: posX, posY: posY, height: height, faceIds: faceIds, animate: animate}; } ////// 搜索某个图块出现的所有位置 ////// diff --git a/libs/ui.js b/libs/ui.js index 700de21c..4ab8359a 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -8,6 +8,12 @@ function ui() { this._init(); + // for convenience + this.SIZE = core.__SIZE__; + this.HSIZE = core.__HALF_SIZE__; + this.LAST = this.SIZE - 1; + this.PIXEL = core.__PIXELS__; + this.HPIXEL = this.PIX / 2; } // 初始化UI @@ -19,12 +25,12 @@ ui.prototype._init = function () { ui.prototype.getContextByName = function (canvas) { if (typeof canvas == 'string') { - if (core.isset(core.canvas[canvas])) + if (core.canvas[canvas]) canvas = core.canvas[canvas]; - else if (core.isset(core.dymCanvas[canvas])) + else if (core.dymCanvas[canvas]) canvas = core.dymCanvas[canvas]; } - if (core.isset(canvas) && core.isset(canvas.canvas)) { + if (canvas && canvas.canvas) { return canvas; } return null; @@ -47,12 +53,8 @@ ui.prototype.clearMap = function (name, x, y, width, height) { ////// 在某个canvas上绘制一段文字 ////// ui.prototype.fillText = function (name, text, x, y, style, font) { - if (core.isset(style)) { - core.setFillStyle(name, style); - } - if (core.isset(font)) { - core.setFont(name, font); - } + if (style) core.setFillStyle(name, style); + if (font) core.setFont(name, font); var ctx = this.getContextByName(name); if (ctx) ctx.fillText(text, x, y); } @@ -61,8 +63,8 @@ ui.prototype.fillText = function (name, text, x, y, style, font) { ui.prototype.fillBoldText = function (name, text, x, y, style, font) { var ctx = this.getContextByName(name); if (!ctx) return; - if (core.isset(font)) ctx.font = font; - if (!core.isset(style)) style = ctx.fillStyle; + if (font) ctx.font = font; + if (!style) style = ctx.fillStyle; ctx.fillStyle = '#000000'; ctx.fillText(text, x-1, y-1); ctx.fillText(text, x-1, y+1); @@ -74,33 +76,23 @@ ui.prototype.fillBoldText = function (name, text, x, y, style, font) { ////// 在某个canvas上绘制一个矩形 ////// ui.prototype.fillRect = function (name, x, y, width, height, style) { - if (core.isset(style)) { - core.setFillStyle(name, style); - } + if (style) core.setFillStyle(name, style); var ctx = this.getContextByName(name); if (ctx) ctx.fillRect(x, y, width, height); } ////// 在某个canvas上绘制一个矩形的边框 ////// ui.prototype.strokeRect = function (name, x, y, width, height, style, lineWidth) { - if (core.isset(style)) { - core.setStrokeStyle(name, style); - } - if (core.isset(lineWidth)) { - core.setLineWidth(name, lineWidth); - } + if (style) core.setStrokeStyle(name, style); + if (lineWidth) core.setLineWidth(name, lineWidth); var ctx = this.getContextByName(name); if (ctx) ctx.strokeRect(x, y, width, height); } ////// 在某个canvas上绘制一条线 ////// ui.prototype.drawLine = function (name, x1, y1, x2, y2, style, lineWidth) { - if (core.isset(style)) { - core.setStrokeStyle(name, style); - } - if (core.isset(lineWidth)) { - core.setLineWidth(name, lineWidth); - } + if (style) core.setStrokeStyle(name, style); + if (lineWidth != null) core.setLineWidth(name, lineWidth); var ctx = this.getContextByName(name); if (!ctx) return; ctx.beginPath(); @@ -112,12 +104,8 @@ ui.prototype.drawLine = function (name, x1, y1, x2, y2, style, lineWidth) { ////// 在某个canvas上绘制一个箭头 ////// ui.prototype.drawArrow = function (name, x1, y1, x2, y2, style, lineWidth) { if (x1==x2 && y1==y2) return; - if (core.isset(style)) { - core.setStrokeStyle(name, style); - } - if (core.isset(lineWidth)) { - core.setLineWidth(name, lineWidth); - } + if (style) core.setStrokeStyle(name, style); + if (lineWidth != null) core.setLineWidth(name, lineWidth); var ctx = this.getContextByName(name); if (!ctx) return; var head = 10; @@ -186,11 +174,17 @@ ui.prototype.setTextAlign = function (name, align) { if (ctx) ctx.textAlign = align; } +////// 设置某个canvas的baseline ////// +ui.prototype.setTextBaseline = function (name, baseline) { + var ctx = this.getContextByName(name); + if (ctx) ctx.textBaseline = baseline; +} + ////// 计算某段文字的宽度 ////// ui.prototype.calWidth = function (name, text, font) { var ctx = this.getContextByName(name); if (ctx) { - if (core.isset(font)) ctx.font = font; + if (font) ctx.font = font; return ctx.measureText(text).width; } return 0; @@ -202,7 +196,7 @@ ui.prototype.drawImage = function (name, image, x, y, w, h, x1, y1, w1, h1) { if (!ctx) return; if (typeof image == 'string') { image = core.material.images.images[image]; - if (!core.isset(image)) return; + if (!image) return; } // 只能接受2, 4, 8个参数 @@ -226,7 +220,7 @@ ui.prototype.drawImage = function (name, image, x, y, w, h, x1, y1, w1, h1) { ui.prototype.closePanel = function () { core.status.boxAnimateObjs = []; clearInterval(core.status.event.interval); - core.clearLastEvent(); + core.clearSelector(); core.maps.generateGroundPattern(); core.updateStatusBar(); core.unLockControl(); @@ -237,21 +231,20 @@ ui.prototype.closePanel = function () { core.status.event.interval = null; } -////// 一般清除事件 ////// -ui.prototype.clearLastEvent = function () { - if (core.isset(core.dymCanvas._selector)) - core.deleteCanvas("_selector"); +////// 清除光标 ////// +ui.prototype.clearSelector = function () { + if (core.dymCanvas._selector) core.deleteCanvas("_selector"); core.clearMap('ui'); core.setAlpha('ui', 1); } ////// 左上角绘制一段提示 ////// ui.prototype.drawTip = function (text, itemIcon) { - var textX, textY, width, height, hide = false, alpha = 0; + var textX, textY, width, height; clearInterval(core.interval.tipAnimate); core.setFont('data', "16px Arial"); core.setTextAlign('data', 'left'); - if (!core.isset(itemIcon)) { + if (!itemIcon) { textX = 16; textY = 18; width = textX + core.calWidth('data', text) + 16; @@ -263,32 +256,32 @@ ui.prototype.drawTip = function (text, itemIcon) { width = textX + core.calWidth('data', text) + 8; height = 42; } + this._drawTip_animate(text, itemIcon, textX, textY, width, height); +} + +ui.prototype._drawTip_animate = function (text, itemIcon, textX, textY, width, height) { + var alpha = 0, hide = false; core.interval.tipAnimate = window.setInterval(function () { - if (hide) { - alpha -= 0.1; - } - else { - alpha += 0.1; - } - core.clearMap('data', 5, 5, 416, height); + if (hide) alpha -= 0.1; + else alpha += 0.1; + core.clearMap('data', 5, 5, core.ui.PIXEL, height); core.setAlpha('data', alpha); core.fillRect('data', 5, 5, width, height, '#000'); - if (core.isset(itemIcon)) { + if (itemIcon) core.drawImage('data', core.material.images.items, 0, itemIcon * 32, 32, 32, 10, 8, 32, 32); - } core.fillText('data', text, textX + 5, textY + 15, '#fff'); core.setAlpha('data', 1); if (alpha > 0.6 || alpha < 0) { if (hide) { - core.clearMap('data', 5, 5, 416, height); + core.clearMap('data', 5, 5, core.ui.PIXEL, height); clearInterval(core.interval.tipAnimate); return; } else { - if (!core.isset(core.timeout.getItemTipTimeout)) { - core.timeout.getItemTipTimeout = window.setTimeout(function () { + if (!core.timeout.tipTimeout) { + core.timeout.tipTimeout = window.setTimeout(function () { hide = true; - core.timeout.getItemTipTimeout = null; + core.timeout.tipTimeout = null; }, 750); } alpha = 0.6; @@ -299,41 +292,12 @@ ui.prototype.drawTip = function (text, itemIcon) { ////// 地图中间绘制一段文字 ////// ui.prototype.drawText = function (contents, callback) { - if (core.isset(contents)) { - - // 合并 - if ((core.isset(core.status.event)&&core.status.event.id=='action') || core.isReplaying()) { - core.insertAction(contents,null,null,callback); - return; - } - - if (typeof contents == 'string') { - contents = [{'content': contents}]; - } - else if (contents instanceof Object && core.isset(contents.content)) { - contents = [contents]; - } - else if (!(contents instanceof Array)) { - core.drawTip("出错了"); - console.log(contents); - return; - } - - core.status.event = {'id': 'text', 'data': {'list': contents, 'callback': callback}}; - core.lockControl(); - - // wait the hero to stop - core.stopAutomaticRoute(); - setTimeout(function() { - core.drawText(); - }, 30); - return; - } + if (contents != null) return this._drawText_setContent(contents, callback); if (core.status.event.data.list.length==0) { var callback = core.status.event.data.callback; core.ui.closePanel(false); - if (core.isset(callback)) callback(); + if (callback) callback(); return; } @@ -342,7 +306,58 @@ ui.prototype.drawText = function (contents, callback) { core.ui.drawTextBox(data); else core.ui.drawTextBox(data.content, data.id); - // core.drawTextBox(content); +} + +ui.prototype._drawText_setContent = function (contents, callback) { + // 合并进 insertAction + if ((core.status.event && core.status.event.id=='action') || core.isReplaying()) { + core.insertAction(contents,null,null,callback); + return; + } + if (!(contents instanceof Array)) contents = [contents]; + + core.status.event = {'id': 'text', 'data': {'list': contents, 'callback': callback}}; + core.lockControl(); + + core.waitHeroToStop(core.drawText); + return; +} + +////// 正则处理 \t[xx,yy] 问题 +ui.prototype._getTitleAndIcon = function (content) { + var title = null, image = null, icon = null, height = 32, animate = 1; + content = content.replace(/(\t|\\t)\[(([^\],]+),)?([^\],]+)\]/g, function (s0, s1, s2, s3, s4) { + if (s4) { + if (s4 == 'hero') { + title = core.status.hero.name; + image = core.material.images.hero; + icon = 0; + height = core.material.icons.hero.height; + } + else if (/^[-\w.]+\.png$/.test(s4)) + image = core.material.images.images[s4]; + else { + var blockInfo = core.getBlockInfo(s4); + if (blockInfo != null) { + if (core.material.enemys[s4]) title = core.material.enemys[s4].name; + image = blockInfo.image; + icon = blockInfo.posX; + height = blockInfo.height; + animate = blockInfo.animate; + } + } + } + if (s3) title = s3; + return ""; + }); + return { + content: content, + title: title, + image: image, + icon: icon, + height: height, + animate: animate + }; } ui.prototype.getTitleAndIcon = function (content) { @@ -406,8 +421,8 @@ ui.prototype.getTitleAndIcon = function (content) { }; } -// 绘制选择光标 -ui.prototype.drawWindowSelector = function(background,x,y,w,h) { +////// 绘制选择光标 +ui.prototype.drawWindowSelector = function(background, x, y, w, h) { w = Math.round(w), h = Math.round(h); var dstImage = core.ui.createCanvas("_selector", x, y, w, h, 165); core.setOpacity("_selector", 0.8); @@ -425,10 +440,10 @@ ui.prototype.drawWindowSelector = function(background,x,y,w,h) { dstImage.drawImage(background, 158, 66, 2, 28,w-2, 2, 2,h-4); } -// 绘制皮肤 -ui.prototype.drawWindowSkin = function(background,canvas,x,y,w,h,direction,px,py) { +////// 绘制 WindowSkin +ui.prototype.drawWindowSkin = function(background, ctx, x, y, w, h, direction, px, py) { // 仿RM窗口皮肤 ↓ - var dstImage = core.getContextByName(canvas); + var dstImage = core.getContextByName(ctx); if (!dstImage) return; // 绘制背景 dstImage.drawImage(background, 0, 0, 128, 128, x+2, y+2, w-4, h-4); @@ -454,7 +469,7 @@ ui.prototype.drawWindowSkin = function(background,canvas,x,y,w,h,direction,px,py dstImage.drawImage(background, 176,48, 16, 16, x+w-16, y+h-16, 16, 16); // arrow - if(core.isset(px) && core.isset(py)){ + if(px != null && py != null){ if(direction == 'up'){ dstImage.drawImage(background,128,96,32,32,px,y+h-3,32,32); }else if(direction == 'down') { @@ -464,57 +479,198 @@ ui.prototype.drawWindowSkin = function(background,canvas,x,y,w,h,direction,px,py // 仿RM窗口皮肤 ↑ } -// 计算有效文本框的宽度 -ui.prototype.calTextBoxWidth = function (canvas, content, min_width, max_width) { +////// 计算有效文本框的宽度 +ui.prototype.calTextBoxWidth = function (ctx, content, min_width, max_width) { // 无限长度自动换行 - var allLines = core.splitLines(canvas, content); + var allLines = core.splitLines(ctx, content); - // 如果不存在手动换行,则二分自动换行 + // 如果不存在手动换行,尽量调成半行形式 if (allLines.length == 1) { - var w = core.calWidth(canvas, allLines[0]); + var w = core.calWidth(ctx, allLines[0]); if (w