From 25d0e10df08ebdb84201446f1e5874c8c655bfa9 Mon Sep 17 00:00:00 2001 From: oc Date: Sat, 9 Mar 2019 20:19:01 +0800 Subject: [PATCH] actions.js v2.6 --- libs/actions.js | 1550 +++++++++++++++++------------------------- libs/control.js | 4 +- libs/events.js | 58 ++ project/functions.js | 1 + 4 files changed, 675 insertions(+), 938 deletions(-) diff --git a/libs/actions.js b/libs/actions.js index 718d490e..050a555c 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -11,6 +11,91 @@ function actions() { actions.prototype.init = function () { this.actionsdata = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.actions; + this.actions = {}; + // --- onkeyDown注册 + this.registerAction('onkeyDown', '_sys_checkReplay', this._sys_checkReplay, 100); + this.registerAction('onkeyDown', '_sys_onkeyDown', this._sys_onkeyDown, 0); + // --- onkeyUp注册 + this.registerAction('onkeyUp', '_sys_onkeyUp_replay', this._sys_onkeyUp_replay, 100); + this.registerAction('onkeyUp', '_sys_onkeyUp', this._sys_onkeyUp, 0); + // --- pressKey注册 + this.registerAction('pressKey', '_sys_checkReplay', this._sys_checkReplay, 100); + this.registerAction('pressKey', '_sys_pressKey', this._sys_pressKey, 0); + // --- keyDown注册 + this.registerAction('keyDown', '_sys_checkReplay', this._sys_checkReplay, 100); + this.registerAction('keyDown', '_sys_keyDown_lockControl', this._sys_keyDown_lockControl, 50); + this.registerAction('keyDown', '_sys_keyDown', this._sys_keyDown, 0); + // --- keyUp注册 + this.registerAction('keyUp', '_sys_keyUp_replay', this._sys_keyUp_replay, 100); + this.registerAction('keyUp', '_sys_keyUp_lockControl', this._sys_keyUp_lockControl, 50); + this.registerAction('keyUp', '_sys_keyUp', this._sys_keyUp, 0); + // --- ondown注册 + this.registerAction('ondown', '_sys_checkReplay', this._sys_checkReplay, 100); + this.registerAction('ondown', '_sys_ondown_paint', this._sys_ondown_paint, 60); + this.registerAction('ondown', '_sys_ondown_lockControl', this._sys_ondown_lockControl, 30); + this.registerAction('ondown', '_sys_ondown', this._sys_ondown, 0); + // --- onmove注册 + this.registerAction('onmove', '_sys_checkReplay', this._sys_checkReplay, 100); + this.registerAction('onmove', '_sys_onmove_paint', this._sys_onmove_paint, 50); + this.registerAction('onmove', '_sys_onmove', this._sys_onmove, 0); + // --- onup注册 + this.registerAction('onup', '_sys_checkReplay', this._sys_checkReplay, 100); + this.registerAction('onup', '_sys_onup_paint', this._sys_onup_paint, 50); + this.registerAction('onup', '_sys_onup', this._sys_onup, 0); + // --- onclick注册 + this.registerAction('onclick', '_sys_checkReplay', this._sys_checkReplay, 100); + this.registerAction('onclick', '_sys_onclick_lockControl', this._sys_onclick_lockControl, 50); + this.registerAction('onclick', '_sys_onclick', this._sys_onclick, 0); + // --- onmousewheel注册 + this.registerAction('onmousewheel', '_sys_onmousewheel', this._sys_onmousewheel, 0); + // --- keyDownCtrl注册 + this.registerAction('keyDownCtrl', '_sys_keyDownCtrl', this._sys_keyDownCtrl, 0); + // --- longClick注册 + this.registerAction('longClick', '_sys_longClick_lockControl', this._sys_longClick_lockControl, 50); + this.registerAction('longClick', '_sys_longClick', this._sys_longClick, 0); + +} + +////// 注册一个用户交互行为 ////// +/* + * 此函数将注册一个用户交互行为。 + * action:要注册的交互类型,如 ondown, onclick, keyDown 等等。 + * name:你的自定义名称,可被注销使用;同名重复注册将后者覆盖前者。 + * func:执行函数。 + * priority:优先级;优先级高的将会被执行。此项可不填,默认为0。 + * 返回:如果func返回true,则不会再继续执行其他的交互函数;否则会继续执行其他的交互函数。 + */ +actions.prototype.registerAction = function (action, name, func, priority) { + if (!core.isset(name) || !core.isset(func) || !(func instanceof Function)) + return; + priority = priority || 0; + if (!core.isset(this.actions[action])) { + this.actions[action] = []; + } + this.unregisterAction(action, name); + this.actions[action].push( + {"action": action, "name": name, "func": func, "priority": priority} + ); + this.actions[action] = this.actions[action].sort(function (a, b) { + return b.priority - a.priority; + }); +} + +////// 注销一个用户交互行为 ////// +actions.prototype.unregisterAction = function (action, name) { + if (!core.isset(this.actions[action])) return; + this.actions[action] = this.actions[action].filter(function (x) { return x.name != name; }); +} + +////// 执行一个用户交互行为 ////// +actions.prototype.doRegisteredAction = function (action) { + var actions = this.actions[action]; + if (!core.isset(actions)) return false; + for (var i = 0; i < actions.length; ++i) { + if (actions[i].func.apply(this, Array.prototype.slice.call(arguments, 1))) + return true; + } + return false; } actions.prototype.checkReplaying = function () { @@ -20,9 +105,17 @@ actions.prototype.checkReplaying = function () { return false; } +////// 检查是否在录像播放中,如果是,则停止交互 +actions.prototype._sys_checkReplay = function () { + if (this.checkReplaying()) return true; +} + ////// 按下某个键时 ////// actions.prototype.onkeyDown = function (e) { - if (this.checkReplaying()) return; + this.doRegisteredAction('onkeyDown', e); +} + +actions.prototype._sys_onkeyDown = function (e) { if (!core.isset(core.status.holdingKeys))core.status.holdingKeys=[]; var isArrow={37:true,38:true,39:true,40:true}[e.keyCode] if(isArrow && !core.status.lockControl){ @@ -41,6 +134,10 @@ actions.prototype.onkeyDown = function (e) { ////// 放开某个键时 ////// actions.prototype.onkeyUp = function(e) { + this.doRegisteredAction('onkeyUp', e); +} + +actions.prototype._sys_onkeyUp_replay = function (e) { if (this.checkReplaying()) { if (e.keyCode==27) // ESCAPE core.stopReplay(); @@ -66,9 +163,11 @@ actions.prototype.onkeyUp = function(e) { core.setReplaySpeed(12); else if (e.keyCode==54) core.setReplaySpeed(24); - return; + return true; } +} +actions.prototype._sys_onkeyUp = function (e) { var isArrow={37:true,38:true,39:true,40:true}[e.keyCode] if(isArrow && !core.status.lockControl){ for(var ii =0;ii0) { var pos={'x':x,'y':y}; var pos0=core.status.stepPostfix[core.status.stepPostfix.length-1]; @@ -406,49 +477,54 @@ actions.prototype.onmove = function (loc) { core.fillPosWithPoint(pos); } } + return true; } ////// 当点击(触摸)事件放开时 ////// actions.prototype.onup = function () { - if (this.checkReplaying()) return; + this.doRegisteredAction('onup'); +} +actions.prototype._sys_onup_paint = function () { // 画板 - if (core.status.played && (core.status.event||{}).id=='paint') { - this.onupPaint() - return; + if (core.status.played && (core.status.event || {}).id == 'paint') { + this.onupPaint(); + return true; } +} +actions.prototype._sys_onup = function () { clearTimeout(core.timeout.onDownTimeout); core.timeout.onDownTimeout = null; clearInterval(core.interval.onDownInterval); core.interval.onDownInterval = null; - // core.status.holdingPath=0; - if ((core.status.stepPostfix||[]).length>0) { - var stepPostfix = []; - var direction={'0':{'1':'down','-1':'up'},'-1':{'0':'left'},'1':{'0':'right'}}; - for(var ii=1;ii=1000) { - this.longClick(posx, posy); - } - else { - //posx,posy是寻路的目标点,stepPostfix是后续的移动 - this.onclick(posx,posy,stepPostfix); - } - core.status.downTime=null; + var stepPostfix = []; + var direction={'0':{'1':'down','-1':'up'},'-1':{'0':'left'},'1':{'0':'right'}}; + for(var ii=1;ii=1000) { + this.longClick(posx, posy); + } + else { + //posx,posy是寻路的目标点,stepPostfix是后续的移动 + this.onclick(posx,posy,stepPostfix); + } + core.status.downTime=null; + return true; } ////// 获得点击事件相对左上角的坐标(0到12之间) ////// @@ -475,163 +551,104 @@ actions.prototype.getClickLoc = function (x, y) { ////// 具体点击屏幕上(x,y)点时,执行的操作 ////// actions.prototype.onclick = function (x, y, stepPostfix) { - if (this.checkReplaying()) return; // console.log("Click: (" + x + "," + y + ")"); + this.doRegisteredAction('onclick', x, y, stepPostfix || []); +} - stepPostfix=stepPostfix||[]; - - // 非游戏屏幕内 - if (x<0 || y<0 || x>12 || y>12) return; +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); + break; + case 'book': + this._clickBook(x,y); + break; + case 'book-detail': + this._clickBookDetail(x,y); + break; + case 'fly': + this._clickFly(x,y); + break; + case 'viewMaps': + this._clickViewMaps(x,y); + break; + case 'switchs': + this._clickSwitchs(x,y); + break; + case 'settings': + this._clickSettings(x,y); + break; + case 'shop': + this._clickShop(x,y); + break; + case 'selectShop': + this._clickQuickShop(x,y); + break; + case 'equipbox': + this._clickEquipbox(x,y); + break; + case 'toolbox': + this._clickToolbox(x,y); + break; + case 'save': + case 'load': + case 'replayLoad': + this._clickSL(x,y); + break; + case 'confirmBox': + this._clickConfirmBox(x,y); + break; + case 'keyBoard': + this._clickKeyBoard(x,y); + break; + case 'action': + this._clickAction(x,y); + break; + case 'text': + core.drawText(); + break; + case 'syncSave': + this._clickSyncSave(x,y); + break; + case 'syncSelect': + this._clickSyncSelect(x,y); + break; + case 'localSaveSelect': + this._clickLocalSaveSelect(x,y); + break; + case 'storageRemove': + this._clickStorageRemove(x,y); + break; + case 'cursor': + this._clickCursor(x,y); + break; + case 'replay': + this._clickReplay(x,y); + break; + case 'gameInfo': + this._clickGameInfo(x,y); + break; + case 'about': + case 'help': + core.ui.closePanel(); + break; + } + return true; +} +actions.prototype._sys_onclick = function (x, y, stepPostfix) { // 寻路 - if (!core.status.lockControl) { - core.setAutomaticRoute(x+parseInt(core.bigmap.offsetX/32), y+parseInt(core.bigmap.offsetY/32), stepPostfix); - return; - } - - // 中心对称飞行器 - if (core.status.event.id == 'centerFly') { - this.clickCenterFly(x, y); - return; - } - - // 怪物手册 - if (core.status.event.id == 'book') { - this.clickBook(x,y); - return; - } - - // 怪物详细信息 - if (core.status.event.id == 'book-detail') { - this.clickBookDetail(x,y); - return; - } - - // 楼层飞行器 - if (core.status.event.id == 'fly') { - this.clickFly(x,y); - return; - } - - // 查看地图 - if (core.status.event.id == 'viewMaps') { - this.clickViewMaps(x,y); - return; - } - - // 开关 - if (core.status.event.id == 'switchs') { - this.clickSwitchs(x,y); - return; - } - - // 设置 - if (core.status.event.id == 'settings') { - this.clickSettings(x,y); - return; - } - - // 商店 - if (core.status.event.id == 'shop') { - this.clickShop(x,y); - return; - } - - // 快捷商店 - if (core.status.event.id == 'selectShop') { - this.clickQuickShop(x,y); - return; - } - - // 装备栏 - if (core.status.event.id == 'equipbox') { - this.clickEquipbox(x,y); - return; - } - - // 工具栏 - if (core.status.event.id == 'toolbox') { - this.clickToolbox(x,y); - return; - } - - // 存读档 - if (core.status.event.id == 'save' || core.status.event.id == 'load' || core.status.event.id=='replayLoad') { - this.clickSL(x,y); - return; - } - - // 选项 - if (core.status.event.id == 'confirmBox') { - this.clickConfirmBox(x,y); - return; - } - - if (core.status.event.id == 'keyBoard') { - this.clickKeyBoard(x,y); - return; - } - - // 关于 - if (core.status.event.id == 'about') { - this.clickAbout(x,y); - return; - } - - if (core.status.event.id == 'help') { - this.clickHelp(x,y); - return; - } - - if (core.status.event.id == 'action') { - this.clickAction(x,y); - return; - } - - // 纯文本 - if (core.status.event.id == 'text') { - core.drawText(); - return; - } - - // 同步存档 - if (core.status.event.id == 'syncSave') { - this.clickSyncSave(x,y); - return; - } - - if (core.status.event.id == 'syncSelect') { - this.clickSyncSelect(x,y); - return; - } - - if (core.status.event.id == 'localSaveSelect') { - this.clickLocalSaveSelect(x,y); - return; - } - if (core.status.event.id=='storageRemove') { - this.clickStorageRemove(x,y); - return; - } - - if (core.status.event.id == 'cursor') { - this.clickCursor(x,y); - return; - } - - if (core.status.event.id == 'replay') { - this.clickReplay(x,y); - return; - } - - if (core.status.event.id=='gameInfo') { - this.clickGameInfo(x,y); - } - + core.setAutomaticRoute(x+parseInt(core.bigmap.offsetX/32), y+parseInt(core.bigmap.offsetY/32), stepPostfix); + return true; } ////// 滑动鼠标滚轮时的操作 ////// actions.prototype.onmousewheel = function (direct) { + this.doRegisteredAction('onmousewheel', direct); +} + +actions.prototype._sys_onmousewheel = function (direct) { // 向下滚动是 -1 ,向上是 1 if (this.checkReplaying()) { @@ -664,76 +681,115 @@ actions.prototype.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) this._clickViewMaps(6,3); + if (direct==-1) this._clickViewMaps(6,9); return; } + } -/////////////////// 在某个界面时的按键点击效果 /////////////////// - -////// 长按 ////// -actions.prototype.longClick = function (x, y, fromEvent) { - if (!core.isPlaying()) return false; - if (core.status.lockControl) { - if (core.status.event.id=='text') { - core.drawText(); - return true; - } - if (core.status.event.id=='action' && core.status.event.data.type=='text') { - core.doAction(); - return true; - } - // 长按楼传器的箭头可以快速翻页 - if (core.status.event.id=='fly') { - if ((x==10 || x==11) && (y==5 || y==9)) { - this.clickFly(x, y); - return true; - } - } - // 长按可以跳过等待事件 - if (core.status.event.id=='action' && core.status.event.data.type=='sleep' - && !core.status.event.data.current.noSkip) { - if (core.isset(core.timeout.sleepTimeout) && Object.keys(core.animateFrame.asyncId).length==0) { - clearTimeout(core.timeout.sleepTimeout); - core.timeout.sleepTimeout = null; - core.events.doAction(); - return true; - } - } - } - else if (!fromEvent) { - core.waitHeroToStop(function () { - // 绘制快捷键 - core.ui.drawKeyBoard(); - }); - } - return false; -} - -////// 按下Ctrl键时(快捷跳过对话) ////// +////// 长按Ctrl键时 ////// actions.prototype.keyDownCtrl = function () { + this.doRegisteredAction('keyDownCtrl'); +} + +actions.prototype._sys_keyDownCtrl = function () { if (core.status.event.id=='text') { core.drawText(); - return; + return true; } if (core.status.event.id=='action' && core.status.event.data.type=='text') { core.doAction(); - return; + return true; } if (core.status.event.id=='action' && core.status.event.data.type=='sleep' - && !core.status.event.data.current.noSkip) { + && !core.status.event.data.current.noSkip) { if (core.isset(core.timeout.sleepTimeout) && Object.keys(core.animateFrame.asyncId).length==0) { clearTimeout(core.timeout.sleepTimeout); core.timeout.sleepTimeout = null; core.events.doAction(); } - return; + return true; } } -////// -actions.prototype.clickCenterFly = function(x, y) { +////// 长按 ////// +actions.prototype.longClick = function (x, y, fromEvent) { + if (!core.isPlaying()) return false; + return this.doRegisteredAction('longClick', x, y, fromEvent); +} + +actions.prototype._sys_longClick_lockControl = function (x, y) { + if (!core.status.lockControl) return false; + if (core.status.event.id == 'text') { + core.drawText(); + return true; + } + if (core.status.event.id == 'action' && core.status.event.data.type == 'text') { + core.doAction(); + return true; + } + // 长按楼传器的箭头可以快速翻页 + if (core.status.event.id == 'fly') { + if ((x == 10 || x == 11) && (y == 5 || y == 9)) { + this._clickFly(x, y); + return true; + } + } + // 长按可以跳过等待事件 + if (core.status.event.id == 'action' && core.status.event.data.type == 'sleep' + && !core.status.event.data.current.noSkip) { + if (core.isset(core.timeout.sleepTimeout) && Object.keys(core.animateFrame.asyncId).length == 0) { + clearTimeout(core.timeout.sleepTimeout); + core.timeout.sleepTimeout = null; + core.events.doAction(); + return true; + } + } + return false; +} + +actions.prototype._sys_longClick = function (x, y, fromEvent) { + if (!core.status.lockControl && !fromEvent) { + // 虚拟键盘 + core.waitHeroToStop(function () { + core.ui.drawKeyBoard(); + }); + return true; + } + return false; +} + +/////////////////// 在某个界面时的按键点击效果 /////////////////// + +// 数字键快速选择选项 +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); + } + if (keycode>=49 && keycode<=57) { + var index = keycode-49; + if (index < length) { + callback(6, topIndex+index); + } + } +} + +// 上下键调整选项 +actions.prototype._keyDownChoices = function (keycode) { + if (keycode==38) { + core.status.event.selection--; + core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); + } + if (keycode==40) { + core.status.event.selection++; + core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); + } +} + +////// 点击中心对称飞行器时 +actions.prototype._clickCenterFly = function(x, y) { var posX = core.status.event.data.posX, posY = core.status.event.data.posY; core.ui.closePanel(); if (x==posX&& y==posY) { @@ -746,7 +802,7 @@ actions.prototype.clickCenterFly = function(x, y) { } } -actions.prototype.keyUpCenterFly = function (keycode) { +actions.prototype._keyUpCenterFly = function (keycode) { core.ui.closePanel(); if (keycode==51 || keycode==13 || keycode==32 || keycode==67) { if (core.canUseItem('centerFly')) { @@ -758,9 +814,8 @@ actions.prototype.keyUpCenterFly = function (keycode) { } } - ////// 点击确认框时 ////// -actions.prototype.clickConfirmBox = function (x,y) { +actions.prototype._clickConfirmBox = function (x,y) { if ((x == 4 || x == 5) && y == 7 && core.isset(core.status.event.data.yes)) core.status.event.data.yes(); if ((x == 7 || x == 8) && y == 7 && core.isset(core.status.event.data.no)) @@ -768,32 +823,35 @@ actions.prototype.clickConfirmBox = function (x,y) { } ////// 键盘操作确认框时 ////// -actions.prototype.keyUpConfirmBox = function (keycode) { +actions.prototype._keyUpConfirmBox = function (keycode) { if (keycode==37) { core.status.event.selection=0; core.ui.drawConfirmBox(core.status.event.ui, core.status.event.data.yes, core.status.event.data.no); + return; } if (keycode==39) { core.status.event.selection=1; core.ui.drawConfirmBox(core.status.event.ui, core.status.event.data.yes, core.status.event.data.no); + return; } if (keycode==13 || keycode==32 || keycode==67) { if (core.status.event.selection==0 && core.isset(core.status.event.data.yes)) { core.status.event.selection=null; core.status.event.data.yes(); + return; } if (core.status.event.selection==1 && core.isset(core.status.event.data.no)) { core.status.event.selection=null; core.status.event.data.no(); + return; } } } ////// 自定义事件时的点击操作 ////// -actions.prototype.clickAction = function (x,y) { - +actions.prototype._clickAction = function (x,y) { if (core.status.event.data.type=='text') { // 打字机效果显示全部文字 @@ -805,16 +863,6 @@ actions.prototype.clickAction = function (x,y) { core.doAction(); return; } - /* - if (core.status.event.data.type=='wait') { - core.setFlag('type', 1); - core.setFlag('x', x); - core.setFlag('y', y); - core.status.route.push("input:"+(10000+100*x+y)); - core.doAction(); - return; - } - */ if (core.status.event.data.type=='choices') { // 选项 @@ -834,25 +882,14 @@ actions.prototype.clickAction = function (x,y) { } ////// 自定义事件时,按下某个键的操作 ////// -actions.prototype.keyDownAction = function (keycode) { +actions.prototype._keyDownAction = function (keycode) { if (core.status.event.data.type=='choices') { - var data = core.status.event.data.current; - var choices = data.choices; - if (choices.length>0) { - if (keycode==38) { - core.status.event.selection--; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } - if (keycode==40) { - core.status.event.selection++; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } - } + this._keyDownChoices(keycode); } } ////// 自定义事件时,放开某个键的操作 ////// -actions.prototype.keyUpAction = function (keycode) { +actions.prototype._keyUpAction = function (keycode) { if (core.status.event.data.type=='text' && (keycode==13 || keycode==32 || keycode==67)) { // 打字机效果显示全部文字 if (core.status.event.interval!=null) { @@ -872,26 +909,13 @@ actions.prototype.keyUpAction = function (keycode) { var data = core.status.event.data.current; var choices = data.choices; if (choices.length>0) { - if (keycode==13 || keycode==32 || keycode==67) { - core.status.route.push("choices:"+core.status.event.selection); - core.insertAction(choices[core.status.event.selection].action); - core.doAction(); - } - // 数字键快速选择 - if (keycode>=49 && keycode<=57) { - var index = keycode-49; - if (index13) this.clickViewMaps(6,0); - if (keycode==65) this.clickViewMaps(0,6); - if (keycode==83 && mh>13) this.clickViewMaps(6,12); - if (keycode==68) this.clickViewMaps(12,6); + if (keycode==38||keycode==33) this._clickViewMaps(6, 3); + if (keycode==40||keycode==34) this._clickViewMaps(6, 9); + if (keycode==87 && mh>13) this._clickViewMaps(6,0); + if (keycode==65) this._clickViewMaps(0,6); + if (keycode==83 && mh>13) this._clickViewMaps(6,12); + if (keycode==68) this._clickViewMaps(12,6); return; } ////// 查看地图界面时,放开某个键的操作 ////// -actions.prototype.keyUpViewMaps = function (keycode) { +actions.prototype._keyUpViewMaps = function (keycode) { if (!core.isset(core.status.event.data)) { core.ui.drawMaps(core.floorIds.indexOf(core.status.floorId)); return; @@ -1113,122 +1137,35 @@ actions.prototype.keyUpViewMaps = function (keycode) { } ////// 商店界面时的点击操作 ////// -actions.prototype.clickShop = function(x,y) { +actions.prototype._clickShop = function(x,y) { var shop = core.status.event.data.shop; var choices = shop.choices; if (x >= 5 && x <= 7) { var topIndex = 6 - parseInt(choices.length / 2); if (y>=topIndex && y eval(use)) { - core.drawTip("你的"+use_text+"不足"); - return false; - } - - core.status.event.data.actions.push(y-topIndex); - - eval(use+'-='+need); - core.setStatus('money', money); - core.setStatus('experience', experience); - - // 更新属性 - choice.effect.split(";").forEach(function (t) { - core.doEffect(t, need, times); - }); - core.updateStatusBar(); - shop.times++; - if (shop.commonTimes) - core.setFlag('commonTimes', shop.times); - core.events.openShop(core.status.event.data.id); + return core.events._useShop(shop, y-topIndex); } // 离开 else if (y==topIndex+choices.length) { - if (core.status.event.data.actions.length>0) { - core.status.route.push("shop:"+core.status.event.data.id+":"+core.status.event.data.actions.join("")); - } - - core.status.event.data.actions = []; - core.status.boxAnimateObjs = []; - if (core.status.event.data.fromList) - core.ui.drawQuickShop(); - else core.ui.closePanel(); + core.events._exitShop(); } else return false; } return true; } -////// 商店界面时,按下某个键的操作 ////// -actions.prototype.keyDownShop = function (keycode) { - if (keycode==38) { - core.status.event.selection--; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } - if (keycode==40) { - core.status.event.selection++; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } -} - ////// 商店界面时,放开某个键的操作 ////// -actions.prototype.keyUpShop = function (keycode) { +actions.prototype._keyUpShop = function (keycode) { if (keycode==27 || keycode==88) { - if (core.status.event.data.actions.length>0) { - core.status.route.push("shop:"+core.status.event.data.id+":"+core.status.event.data.actions.join("")); - } - - core.status.event.data.actions = []; - - core.status.boxAnimateObjs = []; - - if (core.status.event.data.fromList) - core.ui.drawQuickShop(); - else - core.ui.closePanel(); + core.events._exitShop(); return; } - var shop = core.status.event.data.shop; - var choices = shop.choices; - if (keycode==13 || keycode==32 || keycode==67) { - var topIndex = 6 - parseInt(choices.length / 2); - this.clickShop(6, topIndex+core.status.event.selection); - } - // 数字键快速选择 - if (keycode>=49 && keycode<=57) { - var index = keycode-49; - if (index<=choices.length) { - var topIndex = 6 - parseInt(choices.length / 2); - this.clickShop(6, topIndex+index); - } - } + this._selectChoices(core.status.event.data.shop.choices.length+1, keycode, this._clickShop); return; } ////// 快捷商店界面时的点击操作 ////// -actions.prototype.clickQuickShop = function(x, y) { +actions.prototype._clickQuickShop = function(x, y) { var shopList = core.status.shops, keys = Object.keys(shopList).filter(function (shopId) {return shopList[shopId].visited || !shopList[shopId].mustEnable}); if (x >= 5 && x <= 7) { var topIndex = 6 - parseInt(keys.length / 2); @@ -1248,41 +1185,19 @@ actions.prototype.clickQuickShop = function(x, y) { } } -////// 快捷商店界面时,按下某个键的操作 ////// -actions.prototype.keyDownQuickShop = function (keycode) { - if (keycode==38) { - core.status.event.selection--; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } - if (keycode==40) { - core.status.event.selection++; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } -} - ////// 快捷商店界面时,放开某个键的操作 ////// -actions.prototype.keyUpQuickShop = function (keycode) { +actions.prototype._keyUpQuickShop = function (keycode) { if (keycode==27 || keycode==75 || keycode==88 || keycode==86) { core.ui.closePanel(); return; } var shopList = core.status.shops, keys = Object.keys(shopList).filter(function (shopId) {return shopList[shopId].visited || !shopList[shopId].mustEnable}); - if (keycode==13 || keycode==32 || keycode==67) { - var topIndex = 6 - parseInt(keys.length / 2); - this.clickQuickShop(6, topIndex+core.status.event.selection); - } - if (keycode>=49 && keycode<=57) { - var index = keycode-49; - if (index<=keys.length) { - var topIndex = 6 - parseInt(keys.length / 2); - this.clickQuickShop(6, topIndex+index); - } - } + this._selectChoices(keys.length+1, keycode, this._clickQuickShop); return; } ////// 工具栏界面时的点击操作 ////// -actions.prototype.clickToolbox = function(x,y) { +actions.prototype._clickToolbox = function(x,y) { // 装备栏 if (x>=10 && x<=12 && y==0) { core.ui.closePanel(); @@ -1294,19 +1209,6 @@ actions.prototype.clickToolbox = function(x,y) { core.ui.closePanel(); return; } - /* - if (x>=10 && x<=12 && y<=1) { - if (!core.isset(core.status.event.data)) return; - if (!core.flags.enableDeleteItem) { - core.drawTip("不支持删除道具!"); - return; - } - core.removeItem(core.status.event.data); - core.status.event.data = null; - core.ui.drawToolbox(); - return; - } - */ var toolsPage = core.status.event.data.toolsPage; var constantsPage = core.status.event.data.constantsPage; // 上一页 @@ -1340,11 +1242,11 @@ actions.prototype.clickToolbox = function(x,y) { else index =-1; if (index>=0) - this.clickToolboxIndex(index); + this._clickToolboxIndex(index); } ////// 选择工具栏界面中某个Index后的操作 ////// -actions.prototype.clickToolboxIndex = function(index) { +actions.prototype._clickToolboxIndex = function(index) { var items = null; var select; if (index<12) { @@ -1367,7 +1269,7 @@ actions.prototype.clickToolboxIndex = function(index) { } ////// 工具栏界面时,按下某个键的操作 ////// -actions.prototype.keyDownToolbox = function (keycode) { +actions.prototype._keyDownToolbox = function (keycode) { if (!core.isset(core.status.event.data)) return; var tools = Object.keys(core.status.hero.items.tools).sort(); @@ -1400,7 +1302,7 @@ actions.prototype.keyDownToolbox = function (keycode) { } } else index -= 1 ; - this.clickToolboxIndex(index); + this._clickToolboxIndex(index); return; } if (keycode==38) { // up @@ -1411,7 +1313,7 @@ actions.prototype.keyDownToolbox = function (keycode) { } else if (index<6) return; // 第一行没有向上 else index -= 6; - this.clickToolboxIndex(index); + this._clickToolboxIndex(index); return; } if (keycode==39) { // right @@ -1431,7 +1333,7 @@ actions.prototype.keyDownToolbox = function (keycode) { else if(index==constantsLastIndex) // 一个物品无操作 return; else index++; - this.clickToolboxIndex(index); + this._clickToolboxIndex(index); return; } if (keycode==40) { // down @@ -1448,14 +1350,14 @@ actions.prototype.keyDownToolbox = function (keycode) { if (constantsLastIndex > 17) nextIndex = Math.min(constantsLastIndex, index+6); } if (nextIndex!=null) { - this.clickToolboxIndex(nextIndex); + this._clickToolboxIndex(nextIndex); } return; } } ////// 工具栏界面时,放开某个键的操作 ////// -actions.prototype.keyUpToolbox = function (keycode) { +actions.prototype._keyUpToolbox = function (keycode) { if (keycode==81){ core.ui.closePanel(); core.openEquipbox(); @@ -1468,29 +1370,13 @@ actions.prototype.keyUpToolbox = function (keycode) { if (!core.isset(core.status.event.data)) return; if (keycode==13 || keycode==32 || keycode==67) { - this.clickToolboxIndex(core.status.event.selection); + this._clickToolboxIndex(core.status.event.selection); return; } - - /* - if (keycode==46) { // delete - if (!core.isset(core.status.event.data)) return; - if (!core.flags.enableDeleteItem) { - core.drawTip("不支持删除道具!"); - return; - } - core.removeItem(core.status.event.data); - core.status.event.data = null; - core.ui.drawToolbox(); - return; - } - */ - } - ////// 装备栏界面时的点击操作 ////// -actions.prototype.clickEquipbox = function(x,y) { +actions.prototype._clickEquipbox = function(x,y) { // 道具栏 if (x>=10 && x<=12 && y==0) { core.ui.closePanel(); @@ -1533,12 +1419,12 @@ actions.prototype.clickEquipbox = function(x,y) { if (index>=0) { if (index<12) index = parseInt(index/2); - this.clickEquipboxIndex(index); + this._clickEquipboxIndex(index); } } ////// 选择装备栏界面中某个Index后的操作 ////// -actions.prototype.clickEquipboxIndex = function(index) { +actions.prototype._clickEquipboxIndex = function(index) { if (index<6) { if (index>=core.status.globalAttribute.equipName.length) return; if (index==core.status.event.selection && core.isset(core.status.hero.equipment[index])) { @@ -1558,7 +1444,7 @@ actions.prototype.clickEquipboxIndex = function(index) { } ////// 装备栏界面时,按下某个键的操作 ////// -actions.prototype.keyDownEquipbox = function (keycode) { +actions.prototype._keyDownEquipbox = function (keycode) { if (!core.isset(core.status.event.data)) return; var equipCapacity = core.status.globalAttribute.equipName.length; @@ -1580,7 +1466,7 @@ actions.prototype.keyDownEquipbox = function (keycode) { else return; } else index -= 1; - this.clickEquipboxIndex(index); + this._clickEquipboxIndex(index); return; } if (keycode==38) { // up @@ -1592,7 +1478,7 @@ actions.prototype.keyDownEquipbox = function (keycode) { else index = Math.min(equipCapacity-1, index); } else index -= 6; - this.clickEquipboxIndex(index); + this._clickEquipboxIndex(index); return; } if (keycode==39) { // right @@ -1607,7 +1493,7 @@ actions.prototype.keyDownEquipbox = function (keycode) { else if (index==totalLastIndex) return; else index++; - this.clickEquipboxIndex(index); + this._clickEquipboxIndex(index); return; } if (keycode==40) { // down @@ -1625,13 +1511,13 @@ actions.prototype.keyDownEquipbox = function (keycode) { else if (index < 18) index = Math.min(index+6, totalLastIndex); else return; - this.clickEquipboxIndex(index); + this._clickEquipboxIndex(index); return; } } ////// 装备栏界面时,放开某个键的操作 ////// -actions.prototype.keyUpEquipbox = function (keycode, altKey) { +actions.prototype._keyUpEquipbox = function (keycode, altKey) { if (altKey && keycode>=48 && keycode<=57) { core.items.quickSaveEquip(keycode-48); return; @@ -1648,13 +1534,13 @@ actions.prototype.keyUpEquipbox = function (keycode, altKey) { if (!core.isset(core.status.event.data.selectId)) return; if (keycode==13 || keycode==32 || keycode==67) { - this.clickEquipboxIndex(core.status.event.selection); + this._clickEquipboxIndex(core.status.event.selection); return; } } ////// 存读档界面时的点击操作 ////// -actions.prototype.clickSL = function(x,y) { +actions.prototype._clickSL = function(x,y) { var index=core.status.event.data; var page = parseInt(index/10), offset=index%10; @@ -1728,7 +1614,7 @@ actions.prototype.clickSL = function(x,y) { } ////// 存读档界面时,按下某个键的操作 ////// -actions.prototype.keyDownSL = function(keycode) { +actions.prototype._keyDownSL = function(keycode) { var index=core.status.event.data; var page = parseInt(index/10), offset=index%10; @@ -1780,7 +1666,7 @@ actions.prototype.keyDownSL = function(keycode) { } ////// 存读档界面时,放开某个键的操作 ////// -actions.prototype.keyUpSL = function (keycode) { +actions.prototype._keyUpSL = function (keycode) { var index=core.status.event.data; var page = parseInt(index/10), offset=index%10; @@ -1828,7 +1714,7 @@ actions.prototype.keyUpSL = function (keycode) { } ////// 系统设置界面时的点击操作 ////// -actions.prototype.clickSwitchs = function (x,y) { +actions.prototype._clickSwitchs = function (x,y) { if (x<5 || x>7) return; var choices = core.status.event.ui.choices; var topIndex = 6 - parseInt((choices.length - 1) / 2); @@ -1888,43 +1774,18 @@ actions.prototype.clickSwitchs = function (x,y) { } } -////// 系统设置界面时,按下某个键的操作 ////// -actions.prototype.keyDownSwitchs = function (keycode) { - if (keycode==38) { - core.status.event.selection--; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } - if (keycode==40) { - core.status.event.selection++; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } -} - ////// 系统设置界面时,放开某个键的操作 ////// -actions.prototype.keyUpSwitchs = function (keycode) { +actions.prototype._keyUpSwitchs = function (keycode) { if (keycode==27 || keycode==88) { core.status.event.selection=0; core.ui.drawSettings(); return; } - var choices = core.status.event.ui.choices; - if (keycode==13 || keycode==32 || keycode==67) { - var topIndex = 6 - parseInt((choices.length - 1) / 2); - this.clickSwitchs(6, topIndex+core.status.event.selection); - } - // 数字键快速选择 - if (keycode>=49 && keycode<=57) { - var index = keycode-49; - if (index7) return; var choices = core.status.event.ui.choices; var topIndex = 6 - parseInt((choices.length - 1) / 2); @@ -1973,41 +1834,17 @@ actions.prototype.clickSettings = function (x,y) { return; } -////// 系统菜单栏界面时,按下某个键的操作 ////// -actions.prototype.keyDownSettings = function (keycode) { - if (keycode==38) { - core.status.event.selection--; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } - if (keycode==40) { - core.status.event.selection++; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } -} - ////// 系统菜单栏界面时,放开某个键的操作 ////// -actions.prototype.keyUpSettings = function (keycode) { +actions.prototype._keyUpSettings = function (keycode) { if (keycode==27 || keycode==88) { core.ui.closePanel(); return; } - var choices = core.status.event.ui.choices; - if (keycode==13 || keycode==32 || keycode==67) { - var topIndex = 6 - parseInt((choices.length - 1) / 2); - this.clickSettings(6, topIndex+core.status.event.selection); - } - // 数字键快速选择 - if (keycode>=49 && keycode<=57) { - var index = keycode-49; - if (index7) return; var choices = core.status.event.ui.choices; var topIndex = 6 - parseInt((choices.length - 1) / 2); @@ -2100,42 +1937,18 @@ actions.prototype.clickSyncSave = function (x,y) { return; } -////// 同步存档界面时,按下某个键的操作 ////// -actions.prototype.keyDownSyncSave = function (keycode) { - if (keycode==38) { - core.status.event.selection--; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } - if (keycode==40) { - core.status.event.selection++; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } -} - ////// 同步存档界面时,放开某个键的操作 ////// -actions.prototype.keyUpSyncSave = function (keycode) { +actions.prototype._keyUpSyncSave = function (keycode) { if (keycode==27 || keycode==88) { core.status.event.selection=2; core.ui.drawSettings(); return; } - var choices = core.status.event.ui.choices; - if (keycode==13 || keycode==32 || keycode==67) { - var topIndex = 6 - parseInt((choices.length - 1) / 2); - this.clickSyncSave(6, topIndex+core.status.event.selection); - } - // 数字键快速选择 - if (keycode>=49 && keycode<=57) { - var index = keycode-49; - if (index7) return; var choices = core.status.event.ui.choices; @@ -2157,42 +1970,18 @@ actions.prototype.clickSyncSelect = function (x, y) { } } -////// 同步存档选择界面时,按下某个键的操作 ////// -actions.prototype.keyDownSyncSelect = function (keycode) { - if (keycode==38) { - core.status.event.selection--; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } - if (keycode==40) { - core.status.event.selection++; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } -} - ////// 同步存档选择界面时,放开某个键的操作 ////// -actions.prototype.keyUpSyncSelect = function (keycode) { +actions.prototype._keyUpSyncSelect = function (keycode) { if (keycode==27 || keycode==88) { core.status.event.selection=0; core.ui.drawSettings(); return; } - var choices = core.status.event.ui.choices; - if (keycode==13 || keycode==32 || keycode==67) { - var topIndex = 6 - parseInt((choices.length - 1) / 2); - this.clickSyncSelect(6, topIndex+core.status.event.selection); - } - // 数字键快速选择 - if (keycode>=49 && keycode<=57) { - var index = keycode-49; - if (index7) return; var choices = core.status.event.ui.choices; @@ -2218,42 +2007,18 @@ actions.prototype.clickLocalSaveSelect = function (x,y) { core.ui.drawSyncSave(); } -////// 存档下载界面时,按下某个键的操作 ////// -actions.prototype.keyDownLocalSaveSelect = function (keycode) { - if (keycode==38) { - core.status.event.selection--; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } - if (keycode==40) { - core.status.event.selection++; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } -} - ////// 存档下载界面时,放开某个键的操作 ////// -actions.prototype.keyUpLocalSaveSelect = function (keycode) { +actions.prototype._keyUpLocalSaveSelect = function (keycode) { if (keycode==27 || keycode==88) { core.status.event.selection=0; core.ui.drawSettings(); return; } - var choices = core.status.event.ui.choices; - if (keycode==13 || keycode==32 || keycode==67) { - var topIndex = 6 - parseInt((choices.length - 1) / 2); - this.clickLocalSaveSelect(6, topIndex+core.status.event.selection); - } - // 数字键快速选择 - if (keycode>=49 && keycode<=57) { - var index = keycode-49; - if (index7) return; var choices = core.status.event.ui.choices; @@ -2316,42 +2081,18 @@ actions.prototype.clickStorageRemove = function (x, y) { } } -////// 存档删除界面时,按下某个键的操作 ////// -actions.prototype.keyDownStorageRemove = function (keycode) { - if (keycode==38) { - core.status.event.selection--; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } - if (keycode==40) { - core.status.event.selection++; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } -} - ////// 存档删除界面时,放开某个键的操作 ////// -actions.prototype.keyUpStorageRemove = function (keycode) { +actions.prototype._keyUpStorageRemove = function (keycode) { if (keycode==27 || keycode==88) { core.status.event.selection=5; core.ui.drawSyncSave(); return; } - var choices = core.status.event.ui.choices; - if (keycode==13 || keycode==32 || keycode==67) { - var topIndex = 6 - parseInt((choices.length - 1) / 2); - this.clickStorageRemove(6, topIndex+core.status.event.selection); - } - // 数字键快速选择 - if (keycode>=49 && keycode<=57) { - var index = keycode-49; - if (index7) return; var choices = core.status.event.ui.choices; @@ -2363,14 +2104,14 @@ actions.prototype.clickReplay = function (x, y) { case 0: { core.ui.closePanel(); - var hard=core.status.hard, seed = core.getFlag('__seed__'); - core.startGame(hard, seed, core.clone(core.status.route)); + 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); @@ -2399,42 +2140,17 @@ actions.prototype.clickReplay = function (x, y) { } } -////// 回放选择界面时,按下某个键的操作 ////// -actions.prototype.keyDownReplay = function (keycode) { - if (keycode==38) { - core.status.event.selection--; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } - if (keycode==40) { - core.status.event.selection++; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } -} - ////// 回放选择界面时,放开某个键的操作 ////// -actions.prototype.keyUpReplay = function (keycode) { +actions.prototype._keyUpReplay = function (keycode) { if (keycode==27 || keycode==88) { core.ui.closePanel(); return; } - var choices = core.status.event.ui.choices; - if (keycode==13 || keycode==32 || keycode==67) { - var topIndex = 6 - parseInt((choices.length - 1) / 2); - this.clickReplay(6, topIndex+core.status.event.selection); - } - // 数字键快速选择 - if (keycode>=49 && keycode<=57) { - var index = keycode-49; - if (index7) return; var choices = core.status.event.ui.choices; @@ -2483,41 +2199,17 @@ actions.prototype.clickGameInfo = function (x, y) { } } -////// 游戏信息界面时,按下某个键的操作 ////// -actions.prototype.keyDownGameInfo = function (keycode) { - if (keycode==38) { - core.status.event.selection--; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } - if (keycode==40) { - core.status.event.selection++; - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); - } -} - ////// 游戏信息界面时,放开某个键的操作 ////// -actions.prototype.keyUpGameInfo = function (keycode) { +actions.prototype._keyUpGameInfo = function (keycode) { if (keycode==27 || keycode==88) { core.ui.closePanel(); return; } - var choices = core.status.event.ui.choices; - if (keycode==13 || keycode==32 || keycode==67) { - var topIndex = 6 - parseInt((choices.length - 1) / 2); - this.clickGameInfo(6, topIndex+core.status.event.selection); - } - // 数字键快速选择 - if (keycode>=49 && keycode<=57) { - var index = keycode-49; - if (index=1 && x<=11) { core.ui.closePanel(); core.keyUp(112+x-1); // F1-F12: 112-122 @@ -2585,8 +2277,7 @@ actions.prototype.clickKeyBoard = function (x, y) { } ////// 光标界面时的点击操作 ////// -actions.prototype.clickCursor = function (x,y) { - +actions.prototype._clickCursor = function (x,y) { if (x==core.status.automaticRoute.cursorX && y==core.status.automaticRoute.cursorY) { core.ui.closePanel(); core.onclick(x,y,[]); @@ -2598,7 +2289,7 @@ actions.prototype.clickCursor = function (x,y) { } ////// 光标界面时,按下某个键的操作 ////// -actions.prototype.keyDownCursor = function (keycode) { +actions.prototype._keyDownCursor = function (keycode) { if (keycode==37) { // left core.status.automaticRoute.cursorX--; core.ui.drawCursor(); @@ -2622,7 +2313,7 @@ actions.prototype.keyDownCursor = function (keycode) { } ////// 光标界面时,放开某个键的操作 ////// -actions.prototype.keyUpCursor = function (keycode) { +actions.prototype._keyUpCursor = function (keycode) { if (keycode==27 || keycode==88) { core.ui.closePanel(); return; @@ -2634,19 +2325,6 @@ actions.prototype.keyUpCursor = function (keycode) { } } -////// “关于”界面时的点击操作 ////// -actions.prototype.clickAbout = function () { - if (core.isPlaying()) - core.ui.closePanel(); - else - core.restart(true); -} - -////// “帮助”界面时的点击操作 ////// -actions.prototype.clickHelp = function () { - core.ui.closePanel(); -} - ////// 绘图相关 ////// actions.prototype.ondownPaint = function (x, y) { @@ -2743,7 +2421,7 @@ actions.prototype.exitPaint = function () { core.drawTip("退出绘图模式"); } -actions.prototype.keyUpPaint = function (keycode) { +actions.prototype._keyUpPaint = function (keycode) { if (keycode==27 || keycode==88 || keycode==77 || keycode==13 || keycode==32 || keycode==67) { this.exitPaint(); return; diff --git a/libs/control.js b/libs/control.js index df2efb46..0deffcb2 100644 --- a/libs/control.js +++ b/libs/control.js @@ -1925,7 +1925,7 @@ control.prototype.replay = function () { core.events.openShop(shopId, false); var shopInterval = setInterval(function () { - if (!core.actions.clickShop(6, topIndex+core.status.event.selection)) { + if (!core.actions._clickShop(6, topIndex+core.status.event.selection)) { clearInterval(shopInterval); core.stopReplay(); core.drawTip("录像文件出错"); @@ -1933,7 +1933,7 @@ control.prototype.replay = function () { } if (selections.length==0) { clearInterval(shopInterval); - core.actions.clickShop(6, topIndex+choices.length); + core.actions._clickShop(6, topIndex+choices.length); core.replay(); return; } diff --git a/libs/events.js b/libs/events.js index 776e0580..7a7d6c0d 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1980,6 +1980,64 @@ events.prototype.openShop = function(shopId, needVisited) { core.ui.drawChoices(content, choices); } +events.prototype._useShop = function (shop, index) { + // 检查能否使用快捷商店 + var reason = core.events.canUseQuickShop(shop.id); + if (core.isset(reason)) { + core.drawText(reason); + return false; + } + if (!shop.visited) { + if (shop.times==0) core.drawTip("该商店尚未开启"); + else core.drawTip("该商店已失效"); + return false; + } + + var money = core.getStatus('money'), experience = core.getStatus('experience'); + var times = shop.times, need = core.calValue(shop.need, null, null, times); + var use = shop.use; + var use_text = use=='money'?"金币":"经验"; + + var choice = shop.choices[index]; + if (core.isset(choice.need)) + need = core.calValue(choice.need, null, null, times); + + if (need > eval(use)) { + core.drawTip("你的"+use_text+"不足"); + return false; + } + + core.status.event.selection = index; + core.status.event.data.actions.push(index); + + eval(use+'-='+need); + core.setStatus('money', money); + core.setStatus('experience', experience); + + // 更新属性 + choice.effect.split(";").forEach(function (t) { + core.doEffect(t, need, times); + }); + core.updateStatusBar(); + shop.times++; + if (shop.commonTimes) + core.setFlag('commonTimes', shop.times); + core.events.openShop(shop.id); + return true; +} + +events.prototype._exitShop = function () { + if (core.status.event.data.actions.length>0) { + core.status.route.push("shop:"+core.status.event.data.id+":"+core.status.event.data.actions.join("")); + } + core.status.event.data.actions = []; + core.status.boxAnimateObjs = []; + if (core.status.event.data.fromList) + core.ui.drawQuickShop(); + else + core.ui.closePanel(); +} + ////// 禁用一个全局商店 ////// events.prototype.disableQuickShop = function (shopId) { core.status.shops[shopId].visited = false; diff --git a/project/functions.js b/project/functions.js index 81411901..e67624aa 100644 --- a/project/functions.js +++ b/project/functions.js @@ -1257,6 +1257,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = "drawAbout": function() { // 绘制“关于”界面 core.ui.closePanel(); + core.lockControl(); core.status.event.id = 'about'; var left = 48, top = 36, right = 416 - 2 * left, bottom = 416 - 2 * top;