From f88a160064cdf1807081dde68ae33d0ddfae21f9 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Tue, 26 Dec 2017 16:48:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E9=94=AE=E7=9B=98=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/core.js | 235 ++++++++++-------- libs/data.js | 2 +- libs/events.js | 650 +++++++++++++++++++++++++++++++++++++++++-------- libs/ui.js | 173 +++++++------ main.js | 4 +- 快捷键说明.txt | 47 ++++ 更新说明.txt | 4 + 7 files changed, 822 insertions(+), 293 deletions(-) create mode 100644 快捷键说明.txt create mode 100644 更新说明.txt diff --git a/libs/core.js b/libs/core.js index 6c6cfc0d..2dbc5322 100644 --- a/libs/core.js +++ b/libs/core.js @@ -77,15 +77,17 @@ function core() { 'moveStepBeforeStop': [], // 勇士状态;中心对称飞行器 - 'usingCenterFly':false, // event事件 - 'savePage': null, + 'saveIndex': null, 'shops': {}, 'event': { 'id': null, - 'data': null + 'data': null, + 'selection': null, + 'ui': null, }, + 'usingCenterFly':false, 'openingDoor': null, // 动画 @@ -300,7 +302,7 @@ core.prototype.clearStatus = function() { core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight); } -core.prototype.resetStatus = function(hero, hard, floorId, flags, maps) { +core.prototype.resetStatus = function(hero, hard, floorId, maps) { // 停止各个Timeout和Interval for (var i in core.interval) { @@ -318,19 +320,16 @@ core.prototype.resetStatus = function(hero, hard, floorId, flags, maps) { // 初始化人物属性 core.status.hero = core.clone(hero); core.status.hard = hard; - if (core.isset(flags)) - core.flags = core.clone(flags); - // 保存页面 - core.status.savePage = core.getLocalStorage('savePage', 0); + // 保存的Index + core.status.saveIndex = core.getLocalStorage('saveIndex', 1); core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight); - } core.prototype.startGame = function (hard, callback) { console.log('开始游戏'); - core.resetStatus(core.firstData.hero, hard, core.firstData.floorId, core.flags, core.initStatus.maps); + core.resetStatus(core.firstData.hero, hard, core.firstData.floorId, core.initStatus.maps); core.changeFloor(core.status.floorId, null, core.firstData.hero.loc, null, function() { core.setHeroMoveTriggerInterval(); @@ -353,7 +352,7 @@ core.prototype.restart = function() { core.prototype.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){ + if(isArrow && !core.status.lockControl){ for(var ii =0;ii=4 && x<=8) { - if (y==5) { - core.syncSave("save"); - } - if (y==6) { - core.syncSave("load"); - } - } - if (x>=5 && x<=7) { - if (y==7) { - core.ui.drawConfirmBox("你确定要清空所有本地存档吗?", function() { - localStorage.clear(); - core.drawText("\t[操作成功]你的本地所有存档已被清空。"); - }, function() { - core.ui.drawSettings(false); - }) - } - if (y==8) - core.ui.drawSettings(false); - } + core.events.clickSyncSave(x,y); + return; } } @@ -819,8 +853,8 @@ core.prototype.onmousewheel = function (direct) { // 存读档 if (core.status.lockControl && (core.status.event.id == 'save' || core.status.event.id == 'load')) { - if (direct==1) core.ui.drawSLPanel(core.status.event.data - 1); - if (direct==-1) core.ui.drawSLPanel(core.status.event.data + 1); + if (direct==1) core.ui.drawSLPanel(core.status.event.data - 6); + if (direct==-1) core.ui.drawSLPanel(core.status.event.data + 6); return; } } @@ -2900,7 +2934,7 @@ core.prototype.openToolbox = function (need) { core.prototype.save = function(need) { if (!core.checkStatus('save', need)) return; - core.ui.drawSLPanel(core.status.savePage); + core.ui.drawSLPanel(core.status.saveIndex); } core.prototype.load = function (need) { @@ -2910,22 +2944,22 @@ core.prototype.load = function (need) { core.status.event = {'id': 'load', 'data': null}; core.status.lockControl = true; core.dom.startPanel.style.display = 'none'; - var page = core.getLocalStorage('savePage', 0); - core.ui.drawSLPanel(page); + core.ui.drawSLPanel(core.getLocalStorage('saveIndex', 1)); return; } if (!core.checkStatus('load', need)) return; - core.ui.drawSLPanel(core.status.savePage); + core.ui.drawSLPanel(core.status.saveIndex); } core.prototype.doSL = function (id, type) { + core.status.saveIndex=id; if (type=='save') { if (core.saveData("save"+id)) { core.ui.closePanel(); core.drawTip('存档成功!'); - core.setLocalStorage('savePage', core.status.savePage); + core.setLocalStorage('saveIndex', core.status.saveIndex); } else { core.drawTip('存储空间不足,请覆盖已有的存档或在菜单栏中进行清理'); @@ -2944,7 +2978,8 @@ core.prototype.doSL = function (id, type) { } core.ui.closePanel(); core.loadData(data, function() { - core.setLocalStorage('savePage', core.status.savePage); + core.status.saveIndex=id; + core.setLocalStorage('saveIndex', core.status.saveIndex); core.drawTip("读档成功"); }); return; @@ -2953,6 +2988,7 @@ core.prototype.doSL = function (id, type) { core.prototype.syncSave = function(type) { if (type=='save') { + core.status.event.selection=1; core.ui.drawConfirmBox("你确定要将本地存档同步到服务器吗?", function(){ // console.log("同步存档..."); core.ui.drawWaiting("正在同步,请稍后..."); @@ -2999,11 +3035,12 @@ core.prototype.syncSave = function(type) { } xhr.send(formData); }, function() { + core.status.event.selection=0; core.ui.drawSyncSave(); }) } else if (type=='load') { - + core.status.event.selection=1; core.ui.drawConfirmBox("你确定要从服务器加载存档吗?\n该操作将覆盖所有本地存档且不可逆!", function(){ var id = prompt("请输入存档编号:"); if (id==null || id=="") { @@ -3070,6 +3107,7 @@ core.prototype.syncSave = function(type) { } xhr.send(formData); }, function() { + core.status.event.selection=1; core.ui.drawSyncSave(); }) } @@ -3083,7 +3121,6 @@ core.prototype.saveData = function(dataId) { 'hard': core.status.hard, 'maps': core.maps.save(core.status.maps), 'shops': {}, - 'flags': core.flags, 'version': core.firstData.version, "time": new Date().getTime() }; @@ -3101,7 +3138,7 @@ core.prototype.saveData = function(dataId) { core.prototype.loadData = function (data, callback) { - core.resetStatus(data.hero, data.hard, data.floorId, data.flags, core.maps.load(data.maps)); + core.resetStatus(data.hero, data.hard, data.floorId, core.maps.load(data.maps)); // load shop times for (var shop in core.status.shops) { diff --git a/libs/data.js b/libs/data.js index d91af1c6..da1901b6 100644 --- a/libs/data.js +++ b/libs/data.js @@ -78,7 +78,7 @@ data.prototype.init = function() { {"text": "攻击+5", "need": "30", "effect": "status:atk+=5"}, {"text": "防御+5", "need": "30", "effect": "status:def+=5"}, ] - } + }, }, } // 各种数值;一些数值可以在这里设置 diff --git a/libs/events.js b/libs/events.js index 74f6a00e..6963086b 100644 --- a/libs/events.js +++ b/libs/events.js @@ -66,22 +66,36 @@ events.prototype.startGame = function (hard) { core.hideStartAnimate(function() { core.drawText(core.clone(core.firstData.startText), function() { - core.startGame(hard); - if (hard=='Easy') { // 简单难度 - core.setFlag('hard', 1); // 可以用flag:hard来获得当前难度 - // 可以在此设置一些初始福利,比如设置初始生命值可以调用: - // core.setStatus("hp", 10000); - } - if (hard=='Normal') { // 普通难度 - core.setFlag('hard', 2); // 可以用flag:hard来获得当前难度 - } - if (hard=='Hard') { // 困难难度 - core.setFlag('hard', 3); // 可以用flag:hard来获得当前难度 - } + core.status.event.selection = core.flags.battleAnimate?0:1; + core.ui.drawConfirmBox("你想开启战斗动画吗?\n之后可以在菜单栏中开启或关闭。\n(强烈建议新手开启此项)", function() { + console.log("1234"); + core.flags.battleAnimate=true; + core.startGame(hard); + core.events.setInitData(hard); + }, function() { + core.flags.battleAnimate=false; + core.startGame(hard); + core.events.setInitData(hard); + }); }); }) } +////// 简单难度设置初始福利 ////// +events.prototype.setInitData = function (hard) { + if (hard=='Easy') { // 简单难度 + core.setFlag('hard', 1); // 可以用flag:hard来获得当前难度 + // 可以在此设置一些初始福利,比如设置初始生命值可以调用: + // core.setStatus("hp", 10000); + } + if (hard=='Normal') { // 普通难度 + core.setFlag('hard', 2); // 可以用flag:hard来获得当前难度 + } + if (hard=='Hard') { // 困难难度 + core.setFlag('hard', 3); // 可以用flag:hard来获得当前难度 + } +} + ////// 游戏结束事件 ////// events.prototype.win = function(reason) { // 获胜 @@ -166,6 +180,7 @@ events.prototype.doAction = function() { case "tip": core.drawTip(core.replaceText(data.text)); core.events.doAction(); + break; case "show": // 显示 if (core.isset(data.time) && data.time>0 && (!core.isset(data.floorId) || data.floorId==core.status.floorId)) { core.animateBlock(data.loc[0],data.loc[1],'show', data.time, function () { @@ -361,7 +376,7 @@ events.prototype.doAction = function() { break; default: core.status.event.data.type='text'; - core.ui.drawTextBox("\t[警告,]出错啦!\n"+data.type+" 事件不被支持..."); + core.ui.drawTextBox("\t[警告]出错啦!\n"+data.type+" 事件不被支持..."); } return; } @@ -383,9 +398,14 @@ events.prototype.openShop = function(shopId, needVisited) { } shop.visited = true; + var selection = core.status.event.selection; core.ui.closePanel(); core.lockControl(); - core.status.event = {'id': 'shop', 'data': {'id': shopId, 'shop': shop}}; + // core.status.event = {'id': 'shop', 'data': {'id': shopId, 'shop': shop}}; + core.status.event.id = 'shop'; + core.status.event.data = {'id': shopId, 'shop': shop}; + core.status.event.selection = selection; + // 拼词 var content = "\t["+shop.name+","+shop.icon+"]"; var times = shop.times, need=eval(shop.need); @@ -402,9 +422,9 @@ events.prototype.openShop = function(shopId, needVisited) { var text = choice.text; if (core.isset(choice.need)) text += "("+eval(choice.need)+use+")" - choices.push({"text": text}); + choices.push(text); } - choices.push({"text": "离开"}); + choices.push("离开"); core.ui.drawChoices(content, choices); } @@ -462,6 +482,7 @@ events.prototype.useItem = function(itemId) { var fillstyle = 'rgba(255,0,0,0.5)'; if (core.canUseItem('centerFly')) fillstyle = 'rgba(0,255,0,0.5)'; core.fillRect('ui',(12-core.getHeroLoc('x'))*32,(12-core.getHeroLoc('y'))*32,32,32,fillstyle); + core.drawTip("请确认当前中心对称飞行器的位置"); return; } @@ -602,6 +623,46 @@ events.prototype.afterLoadData = function(data) { /*********** 界面上的点击事件 ***************/ /******************************************/ +events.prototype.keyDownCtrl = function () { + if (core.status.event.id=='text') { + core.drawText(); + return; + } + if (core.status.event.id=='action' && core.status.event.data.type=='text') { + this.doAction(); + return; + } +} + +events.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); + } + + 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); + } + + if (keycode==13 || keycode==32) { + if (core.status.event.selection==0 && core.isset(core.status.event.data.yes)) { + core.status.event.selection=null; + core.status.event.data.yes(); + } + if (core.status.event.selection==1 && core.isset(core.status.event.data.no)) { + core.status.event.selection=null; + core.status.event.data.no(); + } + } +} +events.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)) + core.status.event.data.no(); +} + // 正在处理事件时的点击操作... events.prototype.clickAction = function (x,y) { @@ -625,6 +686,42 @@ events.prototype.clickAction = function (x,y) { } } +events.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--; + if (core.status.event.selection<0) core.status.event.selection=0; + core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); + } + if (keycode==40) { + core.status.event.selection++; + if (core.status.event.selection>=choices.length) core.status.event.selection=choices.length-1; + core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); + } + } + } +} + +events.prototype.keyUpAction = function (keycode) { + if (core.status.event.data.type=='text' && (keycode==13 || keycode==32)) { + this.doAction(); + return; + } + if (core.status.event.data.type=='choices') { + var data = core.status.event.data.current; + var choices = data.choices; + if (choices.length>0) { + if (keycode==13 || keycode==32) { + this.insertAction(choices[core.status.event.selection].action); + this.doAction(); + } + } + } +} + // 怪物手册 events.prototype.clickBook = function(x,y) { // 上一页 @@ -642,6 +739,12 @@ events.prototype.clickBook = function(x,y) { return; } +events.prototype.keyDownBook = function (keycode) { + if (keycode==37 || keycode==38) core.ui.drawEnemyBook(core.status.event.data - 1); + else if (keycode==39 || keycode==40) core.ui.drawEnemyBook(core.status.event.data + 1); + return; +} + // 飞行器 events.prototype.clickFly = function(x,y) { if ((x==10 || x==11) && y==9) core.ui.drawFly(core.status.event.data-1); @@ -657,6 +760,27 @@ events.prototype.clickFly = function(x,y) { return; } +events.prototype.keyDownFly = function (keycode) { + if (keycode==37 || keycode==38) core.ui.drawFly(core.status.event.data+1); + else if (keycode==39 || keycode==40) core.ui.drawFly(core.status.event.data-1); + return; +} + +events.prototype.keyUpFly = function (keycode) { + if (keycode==71 || keycode==27) + core.ui.closePanel(); + if (keycode==13 || keycode==32) + this.clickFly(5,5); + return; +} + +events.prototype.keyUpBook = function (keycode) { + if (keycode==27 || keycode==88) { + core.ui.closePanel(true); + return; + } +} + // 商店 events.prototype.clickShop = function(x,y) { var shop = core.status.event.data.shop; @@ -709,14 +833,47 @@ events.prototype.clickShop = function(x,y) { } } +events.prototype.keyDownShop = function (keycode) { + var shop = core.status.event.data.shop; + var choices = shop.choices; + if (keycode==38) { + core.status.event.selection--; + if (core.status.event.selection<0) core.status.event.selection=0; + core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); + } + if (keycode==40) { + core.status.event.selection++; + if (core.status.event.selection>choices.length) core.status.event.selection=choices.length; + core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); + } +} + +events.prototype.keyUpShop = function (keycode) { + if (keycode==27) { + if (core.status.event.data.fromList) { + core.status.boxAnimateObjs = []; + core.setBoxAnimate(); + core.ui.drawQuickShop(); + } + else + core.ui.closePanel(); + return; + } + var shop = core.status.event.data.shop; + var choices = shop.choices; + if (keycode==13 || keycode==32) { + var topIndex = 6 - parseInt(choices.length / 2); + this.clickShop(6, topIndex+core.status.event.selection); + } + return; +} + // 快捷商店 events.prototype.clickQuickShop = function(x, y) { + var shopList = core.status.shops, keys = Object.keys(shopList); if (x >= 5 && x <= 7) { - var shopList = core.status.shops, keys = Object.keys(shopList); - var topIndex = 6 - parseInt((keys.length + 1) / 2); - var exitIndex = 6 + parseInt((keys.length + 1) / 2); - - if (y >= topIndex && y - topIndex < keys.length) { + var topIndex = 6 - parseInt(keys.length / 2); + if (y>=topIndex && ykeys.length) core.status.event.selection=keys.length; + core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); + } +} + +events.prototype.keyUpQuickShop = function (keycode) { + if (keycode==27 || keycode==75) { + core.ui.closePanel(); + return; + } + var shopList = core.status.shops, keys = Object.keys(shopList); + if (keycode==13 || keycode==32) { + var topIndex = 6 - parseInt(keys.length / 2); + this.clickQuickShop(6, topIndex+core.status.event.selection); + } + return; +} + // 工具栏 events.prototype.clickToolbox = function(x,y) { - // 返回 if (x>=10 && x<=12 && y==12) { core.ui.closePanel(false); return; } - - var items = null; - - if (y>=4 && y<=7 && x!=12) - items = Object.keys(core.status.hero.items.tools).sort(); - - if (y>=9 && y<=12 && x!=12) - items = Object.keys(core.status.hero.items.constants).sort(); - - if (items==null) return; var index=0; if (y==4||y==5||y==9||y==10) index=parseInt(x/2); else index=6+parseInt(x/2); + if (y>=9) index+=100; + this.clickToolboxIndex(index); +} - if (index>=items.length) return; - itemId=items[index]; - +events.prototype.clickToolboxIndex = function(index) { + var items = null; + var ii=index; + if (ii<100) + items = Object.keys(core.status.hero.items.tools).sort(); + else { + ii-=100; + items = Object.keys(core.status.hero.items.constants).sort(); + } + if (items==null) return; + if (ii>=items.length) return; + var itemId=items[ii]; if (itemId==core.status.event.data) { core.events.useItem(itemId); } else { - core.ui.drawToolbox(itemId); + core.ui.drawToolbox(index); + } +} + +events.prototype.keyDownToolbox = function (keycode) { + if (!core.isset(core.status.event.data)) return; + + var tools = Object.keys(core.status.hero.items.tools).sort(); + var constants = Object.keys(core.status.hero.items.constants).sort(); + var index=core.status.event.selection; + + if (keycode==37) { // left + if ((index>0 && index<100) || index>100) { + this.clickToolboxIndex(index-1); + return; + } + if (index==100 && tools.length>0) { + this.clickToolboxIndex(tools.length-1); + return; + } + } + if (keycode==38) { // up + if ((index>5 && index<100) || index>105) { + this.clickToolboxIndex(index-6); + return; + } + if (index>=100 && index<=105) { + if (tools.length>6) { + this.clickToolboxIndex(Math.min(tools.length-1, index-100+6)); + } + else if (tools.length>0) { + this.clickToolboxIndex(Math.min(tools.length-1, index-100)); + } + return; + } + } + if (keycode==39) { // right + if ((index=100 && index0) { + this.clickToolboxIndex(100); + return; + } + } + if (keycode==40) { // down + if (index<=5) { + if (tools.length>6) { + this.clickToolboxIndex(Math.min(tools.length-1, index+6)); + } + else if (constants.length>0) { + this.clickToolboxIndex(100+Math.min(constants.length-1, index)); + } + return; + } + if (index>5 && index<100 && constants.length>0) { + this.clickToolboxIndex(100+Math.min(constants.length-1, index-6)); + return; + } + if (index>=100 && index<=105 && constants.length>6) { + this.clickToolboxIndex(Math.min(100+constants.length-1, index+6)); + return; + } + } +} + +events.prototype.keyUpToolbox = function (keycode) { + if (keycode==84 || keycode==27) { + core.ui.closePanel(); + return; + } + if (!core.isset(core.status.event.data)) return; + + if (keycode==13 || keycode==32) { + this.clickToolboxIndex(core.status.event.selection); + return; } } @@ -769,11 +1030,11 @@ events.prototype.clickToolbox = function(x,y) { events.prototype.clickSL = function(x,y) { // 上一页 if ((x == 3 || x == 4) && y == 12) { - core.ui.drawSLPanel(core.status.event.data - 1); + core.ui.drawSLPanel(core.status.event.data - 6); } // 下一页 if ((x == 8 || x == 9) && y == 12) { - core.ui.drawSLPanel(core.status.event.data + 1); + core.ui.drawSLPanel(core.status.event.data + 6); } // 返回 if (x>=10 && x<=12 && y==12) { @@ -784,7 +1045,8 @@ events.prototype.clickSL = function(x,y) { return; } - var index=6*core.status.event.data+1; + var page=parseInt((core.status.event.data-1)/6); + var index=6*page+1; if (y>=1 && y<=4) { if (x>=1 && x<=3) core.doSL(index, core.status.event.id); if (x>=5 && x<=7) core.doSL(index+1, core.status.event.id); @@ -797,78 +1059,264 @@ events.prototype.clickSL = function(x,y) { } } -events.prototype.clickSwitchs = function (x,y) { - if (x<5 || x>7) return; - if (y==4) { - if (core.musicStatus.isIOS) { - core.drawTip("iOS设备不支持播放音乐"); - return; - } - core.changeSoundStatus(); - core.ui.drawSwitchs(); +events.prototype.keyDownSL = function(keycode) { + if (keycode==37) { // left + core.ui.drawSLPanel(core.status.event.data - 1); + return; } - if (y==5) { - core.flags.battleAnimate=!core.flags.battleAnimate; - core.ui.drawSwitchs(); + if (keycode==38) { // up + if ((core.status.event.data-1)%6>=3) + core.ui.drawSLPanel(core.status.event.data - 3); + return; } - if (y==6) { - core.flags.displayEnemyDamage=!core.flags.displayEnemyDamage; - core.updateFg(); - core.ui.drawSwitchs(); + if (keycode==39) { // right + core.ui.drawSLPanel(core.status.event.data + 1); + return; } - if (y==7) { - core.flags.displayExtraDamage=!core.flags.displayExtraDamage; - core.updateFg(); - core.ui.drawSwitchs(); + if (keycode==40) { // down + if ((core.status.event.data-1)%6<3) + core.ui.drawSLPanel(core.status.event.data + 3); + return; } - if (y==8) { - core.ui.drawSettings(false); + if (keycode==33) { // PAGEUP + core.ui.drawSLPanel(core.status.event.data - 6); + return; + } + if (keycode==34) { // PAGEDOWN + core.ui.drawSLPanel(core.status.event.data + 6); + return; } } +events.prototype.keyUpSL = function (keycode) { + if (keycode==27 || (core.status.event.id == 'save' && keycode==83) || (core.status.event.id == 'load' && keycode==68)) { + core.ui.closePanel(); + return; + } + if (keycode==13 || keycode==32) { + core.doSL(core.status.event.data, core.status.event.id); + return; + } +} + +events.prototype.clickSwitchs = function (x,y) { + if (x<5 || x>7) return; + var choices = [ + "背景音乐", "战斗动画", "怪物显伤", "领域显伤", "返回主菜单" + ]; + var topIndex = 6 - parseInt((choices.length - 1) / 2); + if (y>=topIndex && y=choices.length) core.status.event.selection=choices.length; + core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); + } +} + +events.prototype.keyUpSwitchs = function (keycode) { + if (keycode==27) { + core.status.event.selection=0; + core.ui.drawSettings(false); + return; + } + var choices = [ + "背景音乐", "战斗动画", "怪物显伤", "领域显伤", "返回主菜单" + ]; + if (keycode==13 || keycode==32) { + var topIndex = 6 - parseInt((choices.length - 1) / 2); + this.clickSwitchs(6, topIndex+core.status.event.selection); + } +} + + // 菜单栏 events.prototype.clickSettings = function (x,y) { if (x<5 || x>7) return; - if (y == 3) { - core.ui.drawSwitchs(); + var choices = [ + "系统设置", "快捷商店", "同步存档", "重新开始", "关于本塔", "返回游戏" + ]; + var topIndex = 6 - parseInt((choices.length - 1) / 2); + if (y>=topIndex && y=choices.length) core.status.event.selection=choices.length; + core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); + } +} + +events.prototype.keyUpSettings = function (keycode) { + if (keycode==27) { + core.ui.closePanel(); + return; + } + var choices = [ + "系统设置", "快捷商店", "同步存档", "重新开始", "关于本塔", "返回游戏" + ]; + if (keycode==13 || keycode==32) { + var topIndex = 6 - parseInt((choices.length - 1) / 2); + this.clickSettings(6, topIndex+core.status.event.selection); + } +} + +events.prototype.clickSyncSave = function (x,y) { + if (x<5 || x>7) return; + var choices = [ + "同步存档到服务器", "从服务器加载存档", "清空本地存档", "返回主菜单" + ]; + var topIndex = 6 - parseInt((choices.length - 1) / 2); + if (y>=topIndex && y=choices.length) core.status.event.selection=choices.length; + core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); + } +} + +events.prototype.keyUpSyncSave = function (keycode) { + if (keycode==27) { + core.status.event.selection=2; + core.ui.drawSettings(false); + return; + } + var choices = [ + "同步存档到服务器", "从服务器加载存档", "清空本地存档", "返回主菜单" + ]; + if (keycode==13 || keycode==32) { + var topIndex = 6 - parseInt((choices.length - 1) / 2); + this.clickSyncSave(6, topIndex+core.status.event.selection); + } +} + +events.prototype.clickAbout = function () { + if (core.isPlaying()) + core.ui.closePanel(false); + else + core.showStartAnimate(); +} + /*********** 点击事件 END ***************/ diff --git a/libs/ui.js b/libs/ui.js index 0acbb2b3..eca0c3eb 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -26,6 +26,8 @@ ui.prototype.closePanel = function (clearData) { core.unLockControl(); core.status.event.data = null; core.status.event.id = null; + core.status.event.selection = null; + core.status.event.ui = null; } @@ -144,6 +146,8 @@ ui.prototype.drawChoices = function(content, choices) { core.setAlpha('ui', 1); core.setFillStyle('ui', background); + core.status.event.ui = {"text": content, "choices": choices}; + // Step 1: 计算长宽高 var length = choices.length; var left=85, width = 416-2*left; // 宽度 @@ -258,10 +262,15 @@ ui.prototype.drawChoices = function(content, choices) { // 选项 core.canvas.ui.textAlign = "center"; for (var i = 0; i < choices.length; i++) { - core.fillText('ui', core.replaceText(choices[i].text), 208, choice_top + 32 * i, "#FFFFFF", "bold 17px Verdana"); + core.fillText('ui', core.replaceText(choices[i].text || choices[i]), 208, choice_top + 32 * i, "#FFFFFF", "bold 17px Verdana"); + } + + if (choices.length>0) { + if (!core.isset(core.status.event.selection)) core.status.event.selection=0; + var len = core.canvas.ui.measureText(core.replaceText(choices[core.status.event.selection].text || choices[core.status.event.selection])).width; + core.strokeRect('ui', 208-len/2-5, choice_top + 32 * core.status.event.selection - 20, len+10, 28, "#FFD700", 2); } return; - } /** @@ -271,8 +280,13 @@ ui.prototype.drawChoices = function(content, choices) { * @param noCallback */ ui.prototype.drawConfirmBox = function (text, yesCallback, noCallback) { + core.lockControl(); + core.status.event.id = 'confirmBox'; core.status.event.data = {'yes': yesCallback, 'no': noCallback}; + core.status.event.ui = text; + + if (!core.isset(core.status.event.selection)) core.status.event.selection=1; var background = core.canvas.ui.createPattern(core.material.ground, "repeat"); core.clearMap('ui', 0, 0, 416, 416); @@ -291,8 +305,10 @@ ui.prototype.drawConfirmBox = function (text, yesCallback, noCallback) { var top = 140 - (lines-1)*30; var right = 416 - 2 * left, bottom = 416 - 140 - top; - core.fillRect('ui', left, top, right, bottom, background); - core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2); + if (core.isPlaying()) + core.fillRect('ui', left, top, right, bottom, background); + if (core.isPlaying()) + core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2); core.canvas.ui.textAlign = "center"; for (var i in contents) { core.fillText('ui', contents[i], 208, top + 50 + i*30, "#FFFFFF"); @@ -300,6 +316,15 @@ ui.prototype.drawConfirmBox = function (text, yesCallback, noCallback) { core.fillText('ui', "确定", 208 - 38, top + bottom - 35, "#FFFFFF", "bold 17px Verdana"); core.fillText('ui', "取消", 208 + 38, top + bottom - 35); + + var len=core.canvas.ui.measureText("确定").width; + if (core.status.event.selection==0) { + core.strokeRect('ui', 208-38-len/2-5, top+bottom-35-20, len+10, 28, "#FFD700", 2); + } + if (core.status.event.selection==1) { + core.strokeRect('ui', 208+38-len/2-5, top+bottom-35-20, len+10, 28, "#FFD700", 2); + } + } ////// 绘制开关界面 ////// @@ -308,22 +333,15 @@ ui.prototype.drawSwitchs = function() { core.status.event.id = 'switchs'; - var background = core.canvas.ui.createPattern(core.material.ground, "repeat"); - core.clearMap('ui', 0, 0, 416, 416); - core.setAlpha('ui', 1); - core.setFillStyle('ui', background); - var left = 97, top = 64 + 32, right = 416 - 2 * left, bottom = 416 - 2 * top; - core.fillRect('ui', left, top, right, bottom, background); - core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2); + var choices = [ + "背景音乐:"+(core.musicStatus.soundStatus ? "[ON]" : "[OFF]"), + "战斗动画: " + (core.flags.battleAnimate ? "[ON]" : "[OFF]"), + "怪物显伤: " + (core.flags.displayEnemyDamage ? "[ON]" : "[OFF]"), + "领域显伤: " + (core.flags.displayExtraDamage ? "[ON]" : "[OFF]"), + "返回主菜单" + ]; + this.drawChoices(null, choices); - core.canvas.ui.textAlign = "center"; - core.fillText('ui', "背景音乐: " + (core.musicStatus.soundStatus ? "[ON]" : "[OFF]"), 208, top + 56, "#FFFFFF", "bold 17px Verdana"); - // core.fillText('ui', "背景音效" + (core.musicStatus.soundStatus ? "[ON]" : "[OFF]"), 208, top + 88, "#FFFFFF", "bold 17px Verdana") - core.fillText('ui', "战斗动画: " + (core.flags.battleAnimate ? "[ON]" : "[OFF]"), 208, top + 88, "#FFFFFF", "bold 17px Verdana") - core.fillText('ui', "怪物显伤: " + (core.flags.displayEnemyDamage ? "[ON]" : "[OFF]"), 208, top + 120, "#FFFFFF", "bold 17px Verdana") - core.fillText('ui', "领域显伤: " + (core.flags.displayExtraDamage ? "[ON]" : "[OFF]"), 208, top + 152, "#FFFFFF", "bold 17px Verdana") - - core.fillText('ui', "返回上级菜单", 208, top + 184, "#FFFFFF", "bold 17px Verdana"); } /** @@ -334,57 +352,28 @@ ui.prototype.drawSettings = function (need) { if (!core.checkStatus('settings', need)) return; - var background = core.canvas.ui.createPattern(core.material.ground, "repeat"); - core.clearMap('ui', 0, 0, 416, 416); - core.setAlpha('ui', 1); - core.setFillStyle('ui', background); - var left = 97, top = 64, right = 416 - 2 * left, bottom = 416 - 2 * top; - core.fillRect('ui', left, top, right, bottom, background); - core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2); - - core.canvas.ui.textAlign = "center"; - core.fillText('ui', "系统设置", 208, top + 56, "#FFFFFF", "bold 17px Verdana"); - core.fillText('ui', "降低难度", 208, top + 88, "#FFFFFF", "bold 17px Verdana") - core.fillText('ui', "快捷商店", 208, top + 120, "#FFFFFF", "bold 17px Verdana"); - core.fillText('ui', "同步存档", 208, top + 152, "#FFFFFF", "bold 17px Verdana"); - // core.fillText('ui', "清空存档", 208, top + 152, "#FFFFFF", "bold 17px Verdana"); - core.fillText('ui', "重新开始", 208, top + 184, "#FFFFFF", "bold 17px Verdana"); - core.fillText('ui', "关于本塔", 208, top + 216, "#FFFFFF", "bold 17px Verdana"); - core.fillText('ui', "返回游戏", 208, top + 248, "#FFFFFF", "bold 17px Verdana"); - + this.drawChoices(null, [ + "系统设置", "快捷商店", "同步存档", "重新开始", "关于本塔", "返回游戏" + ]); } -/** - * 绘制“选择商店”窗口 - * @param need - */ ui.prototype.drawQuickShop = function (need) { - if (core.isset(need) && !core.checkStatus('selectShop', need)) return; core.status.event.id = 'selectShop'; - var background = core.canvas.ui.createPattern(core.material.ground, "repeat"); - core.clearMap('ui', 0, 0, 416, 416); - core.setAlpha('ui', 1); - core.setFillStyle('ui', background); var shopList = core.status.shops, keys = Object.keys(shopList); - var len = keys.length + 1; - if (len % 2 == 0) len++; - var left = 97, top = 208 - 32 - 16 * len, right = 416 - 2 * left, bottom = 416 - 2 * top; - core.fillRect('ui', left, top, right, bottom, background); - core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2); - - core.canvas.ui.textAlign = "center"; - for (var i = 0; i < keys.length; i++) { - core.fillText('ui', shopList[keys[i]].textInList, 208, top + 56 + 32 * i, "#FFFFFF", "bold 17px Verdana"); + var choices = []; + for (var i=0;i0) index=0; + else if (constants.length>0) index=100; + else index=0; + } + + core.status.event.selection=index; + + var selectId; + if (index<100) + selectId = tools[index]; + else + selectId = constants[index-100]; + + if (!core.hasItem(selectId)) selectId=null; core.status.event.data=selectId; core.clearMap('ui', 0, 0, 416, 416); @@ -937,7 +929,7 @@ ui.prototype.drawToolbox = function(selectId) { core.canvas.ui.textAlign = 'right'; var images = core.material.images.items; // 消耗道具 - var tools = Object.keys(core.status.hero.items.tools).sort(); + for (var i=0;i=30) page=29; - core.status.event.data = page; - core.status.savePage = page; +ui.prototype.drawSLPanel = function(index) { + if (!core.isset(index)) index=1; + if (index<=0) index=1; + if (index>180) index=180; + + core.status.event.data=index; + + var page=parseInt((index-1)/6); + + // core.status.event.data = page; + // core.status.savePage = page; core.clearMap('ui', 0, 0, 416, 416); core.setAlpha('ui', 0.85); @@ -1007,7 +1001,7 @@ ui.prototype.drawSLPanel = function(page) { if (i<3) { core.fillText('ui', name+id, (2*i+1)*u, 35, '#FFFFFF', "bold 17px Verdana"); - core.strokeRect('ui', (2*i+1)*u-size/2, 50, size, size, '#FFFFFF', 2); + core.strokeRect('ui', (2*i+1)*u-size/2, 50, size, size, id==index?'#FFD700':'#FFFFFF', id==index?6:2); if (core.isset(data) && core.isset(data.floorId)) { this.drawThumbnail('ui', core.maps.load(data.maps, data.floorId).blocks, (2*i+1)*u-size/2, 50, size, data.hero.loc); core.fillText('ui', core.formatDate(new Date(data.time)), (2*i+1)*u, 65+size, '#FFFFFF', '10px Verdana'); @@ -1019,7 +1013,7 @@ ui.prototype.drawSLPanel = function(page) { } else { core.fillText('ui', name+id, (2*i-5)*u, 230, '#FFFFFF', "bold 17px Verdana"); - core.strokeRect('ui', (2*i-5)*u-size/2, 245, size, size, '#FFFFFF', 2); + core.strokeRect('ui', (2*i-5)*u-size/2, 245, size, size, id==index?'#FFD700':'#FFFFFF', id==index?6:2); if (core.isset(data) && core.isset(data.floorId)) { this.drawThumbnail('ui', core.maps.load(data.maps, data.floorId).blocks, (2*i-5)*u-size/2, 245, size, data.hero.loc); core.fillText('ui', core.formatDate(new Date(data.time)), (2*i-5)*u, 260+size, '#FFFFFF', '10px Verdana'); @@ -1031,7 +1025,6 @@ ui.prototype.drawSLPanel = function(page) { } } this.drawPagination(page+1, 30); - } ui.prototype.drawThumbnail = function(canvas, blocks, x, y, size, heroLoc) { diff --git a/main.js b/main.js index 2305a77f..f173fa80 100644 --- a/main.js +++ b/main.js @@ -193,14 +193,14 @@ window.onresize = function () { main.dom.body.onkeydown = function(e) { try { - if (main.core.isPlaying()) + if (main.core.isPlaying() || main.core.status.lockControl) main.core.onkeyDown(e); } catch (ee) {} } main.dom.body.onkeyup = function(e) { try { - if (main.core.isPlaying()) + if (main.core.isPlaying() || main.core.status.lockControl) main.core.onkeyUp(e); } catch (ee) {} } diff --git a/快捷键说明.txt b/快捷键说明.txt new file mode 100644 index 00000000..5d1d2c4d --- /dev/null +++ b/快捷键说明.txt @@ -0,0 +1,47 @@ +快捷键说明: + +=== 全局 === +[↑][↓][←][→] 移动勇士 +[X] 打开/关闭怪物手册 +[G] 打开/关闭楼层传送器 +[S] 打开/关闭存档页面 +[D] 打开/关闭读档页面 +[K] 打开/关闭快捷商店选择列表 +[T] 打开/关闭工具栏 +[ESC] 打开/关闭系统菜单 +[SPACE] 轻按(仅在轻按开关打开时有效) +[1] 快捷使用破墙镐 +[2] 快捷使用炸弹/圣锤(先检测有没有炸弹,没有再检测圣锤) +[3] 快捷使用中心对称飞行器 + +=== 文本显示界面 === +[SPACE]/[ENTER] 继续 + +=== 选项列表 === +[↑][↓] 移动当前选择项 +[ESC] 返回 +[SPACE]/[ENTER] 确认该选项 + +=== 怪物手册页面 === +[↑][↓][←][→] 翻页 +[ESC]/[X] 关闭怪物手册 + +=== 楼传器页面 === +[↑][↓][←][→] 更改楼层 +[SPACE]/[ENTER] 确认传送 +[ESC]/[G] 关闭楼传器 + +=== 道具栏页面 === +[↑][↓][←][→] 更改当前道具 +[SPACE]/[ENTER] 确认使用道具 +[ESC]/[T] 关闭道具栏 + +=== 存读档页面 === +[↑][↓][←][→] 更改当前存读档位置 +[PAGEUP][PAGEDOWN] 存读档翻页 +[SPACE]/[ENTER] 确认存读档 +[ESC]/[S]/[D] 关闭存读档界面 + +=== 正在使用中心对称飞行器时 === +[3]/[SPACE]/[ENTER] 确认飞行 +其他键 取消飞行 diff --git a/更新说明.txt b/更新说明.txt new file mode 100644 index 00000000..44740094 --- /dev/null +++ b/更新说明.txt @@ -0,0 +1,4 @@ +全键盘操作 √ +自动定位到上次存/读档位置 √ +开始界面显示难度选择 √ +Ctrl快速跳过对话 √