长按拖动大地图
This commit is contained in:
parent
60f5b42c79
commit
c07cf7cc6d
@ -317,9 +317,6 @@ status: 只能为 stop, leftFoot 和 rightFoot,不填用stop。
|
|||||||
offset: 相对主角逻辑位置的偏移量,不填视为无偏移。
|
offset: 相对主角逻辑位置的偏移量,不填视为无偏移。
|
||||||
frame: 绘制的第几帧
|
frame: 绘制的第几帧
|
||||||
|
|
||||||
fillPosWithPoint: fn(pos?: ?)
|
|
||||||
显示离散的寻路点
|
|
||||||
|
|
||||||
gatherFollowers: fn()
|
gatherFollowers: fn()
|
||||||
立刻聚集所有的跟随者
|
立刻聚集所有的跟随者
|
||||||
|
|
||||||
|
|||||||
@ -215,7 +215,7 @@ function () {
|
|||||||
```
|
```
|
||||||
registerAction: fn(action: string, name: string, func: string|fn(params: ?), priority?: number)
|
registerAction: fn(action: string, name: string, func: string|fn(params: ?), priority?: number)
|
||||||
此函数将注册一个用户交互行为。
|
此函数将注册一个用户交互行为。
|
||||||
action: 要注册的交互类型,如 ondown, onclick, keyDown 等等。
|
action: 要注册的交互类型,如 ondown, onup, keyDown 等等。
|
||||||
name: 你的自定义名称,可被注销使用;同名重复注册将后者覆盖前者。
|
name: 你的自定义名称,可被注销使用;同名重复注册将后者覆盖前者。
|
||||||
func: 执行函数。
|
func: 执行函数。
|
||||||
如果func返回true,则不会再继续执行其他的交互函数;否则会继续执行其他的交互函数。
|
如果func返回true,则不会再继续执行其他的交互函数;否则会继续执行其他的交互函数。
|
||||||
@ -228,8 +228,8 @@ priority: 优先级;优先级高的将会被执行。此项可不填,默认
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
// 当flag:abc是true时,点击屏幕左上角可以使用道具破墙镐
|
// 当flag:abc是true时,点击屏幕左上角可以使用道具破墙镐
|
||||||
// 注入一个 onclick 事件,名称为 my_pickaxe
|
// 注入一个 ondown 事件,名称为 my_pickaxe
|
||||||
core.registerAction('onclick', 'my_pickaxe', function (x, y, px, py) {
|
core.registerAction('ondown', 'my_pickaxe', function (x, y, px, py) {
|
||||||
// 如果当前正在执行某个事件,则忽略之。
|
// 如果当前正在执行某个事件,则忽略之。
|
||||||
if (core.status.lockControl) return false;
|
if (core.status.lockControl) return false;
|
||||||
// 如果勇士正在行走中,则忽略之。
|
// 如果勇士正在行走中,则忽略之。
|
||||||
@ -251,7 +251,7 @@ core.registerAction('onclick', 'my_pickaxe', function (x, y, px, py) {
|
|||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
// 当你不再需要上述监听时,可以通过下面这一句取消注入。
|
// 当你不再需要上述监听时,可以通过下面这一句取消注入。
|
||||||
// core.unregisterActon('onclick', 'my_pickaxe');
|
// core.unregisterActon('ondown', 'my_pickaxe');
|
||||||
```
|
```
|
||||||
|
|
||||||
下面是另一个例子:
|
下面是另一个例子:
|
||||||
@ -339,12 +339,8 @@ core.registerAction('longClick', 'my_shop', '_my_shop_longClick', 100);
|
|||||||
- 如果是触摸屏,则只有手指按下滑动时才会触发`onmove`(并不存在什么悬浮的说法)。
|
- 如果是触摸屏,则只有手指按下滑动时才会触发`onmove`(并不存在什么悬浮的说法)。
|
||||||
- `onup`: 当屏幕被鼠标或手指放开时
|
- `onup`: 当屏幕被鼠标或手指放开时
|
||||||
- 对应的函数参数:`function (x, y, px, py)`,为此时放开时的格子坐标和像素坐标。
|
- 对应的函数参数:`function (x, y, px, py)`,为此时放开时的格子坐标和像素坐标。
|
||||||
- `onclick`: 当屏幕被鼠标或手机点击时
|
- `onclick` 【已废弃】
|
||||||
- 对应的函数参数:`function (x, y, px, py, stepPostfix)`,为此时点击的格子坐标、像素坐标,和拖动路径
|
- 从V2.8.2起,此交互已被废弃,注册一个`onclick`会被直接转发至`ondown`。
|
||||||
- 此函数会在两种情况下被调用:
|
|
||||||
- 在锁定状态下(即角色不可以自由移动),会在`ondown`时直接触发`onclick`,此时`stepPostfix`为空数组。
|
|
||||||
- 在自由状态下(即角色可以自由移动),会在`onup`时触发`onclick`;此时`stepPostfix`为拖动寻路的路径数组。
|
|
||||||
- 推荐自定义的点击监听都使用`ondown`处理。
|
|
||||||
- `onmousewheel`: 当鼠标滚轮滚动时
|
- `onmousewheel`: 当鼠标滚轮滚动时
|
||||||
- 对应的函数参数:`function (direct)`,为此时滚轮方向。向下滚动是-1,向上滚动是1。
|
- 对应的函数参数:`function (direct)`,为此时滚轮方向。向下滚动是-1,向上滚动是1。
|
||||||
- 目前在楼传、怪物手册、存读档、浏览地图等多个地方绑定了鼠标滚轮事件。
|
- 目前在楼传、怪物手册、存读档、浏览地图等多个地方绑定了鼠标滚轮事件。
|
||||||
|
|||||||
@ -2343,10 +2343,6 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
|
|||||||
"!doc": "连续行走<br/>例如:core.setAutoHeroMove([{direction: \"up\", step: 1}, {direction: \"left\", step: 3}]); // 上左左左<br/>steps: 压缩的步伐数组,每项表示朝某方向走多少步",
|
"!doc": "连续行走<br/>例如:core.setAutoHeroMove([{direction: \"up\", step: 1}, {direction: \"left\", step: 3}]); // 上左左左<br/>steps: 压缩的步伐数组,每项表示朝某方向走多少步",
|
||||||
"!type": "fn(steps: [?])"
|
"!type": "fn(steps: [?])"
|
||||||
},
|
},
|
||||||
"fillPosWithPoint": {
|
|
||||||
"!doc": "显示离散的寻路点",
|
|
||||||
"!type": "fn(pos?: ?)"
|
|
||||||
},
|
|
||||||
"unregisterResize": {
|
"unregisterResize": {
|
||||||
"!doc": "注销一个resize函数",
|
"!doc": "注销一个resize函数",
|
||||||
"!type": "fn(name: string)"
|
"!type": "fn(name: string)"
|
||||||
|
|||||||
404
libs/actions.js
404
libs/actions.js
@ -47,17 +47,13 @@ actions.prototype._init = function () {
|
|||||||
// --- onup注册
|
// --- onup注册
|
||||||
this.registerAction('onup', '_sys_checkReplay', this._sys_checkReplay, 100);
|
this.registerAction('onup', '_sys_checkReplay', this._sys_checkReplay, 100);
|
||||||
this.registerAction('onup', '_sys_onup', this._sys_onup, 0);
|
this.registerAction('onup', '_sys_onup', this._sys_onup, 0);
|
||||||
// --- onclick注册
|
// --- onclick已废弃,将视为ondown
|
||||||
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注册
|
// --- onmousewheel注册
|
||||||
this.registerAction('onmousewheel', '_sys_onmousewheel', this._sys_onmousewheel, 0);
|
this.registerAction('onmousewheel', '_sys_onmousewheel', this._sys_onmousewheel, 0);
|
||||||
// --- keyDownCtrl注册
|
// --- keyDownCtrl注册
|
||||||
this.registerAction('keyDownCtrl', '_sys_keyDownCtrl', this._sys_keyDownCtrl, 0);
|
this.registerAction('keyDownCtrl', '_sys_keyDownCtrl', this._sys_keyDownCtrl, 0);
|
||||||
// --- longClick注册
|
// --- longClick注册
|
||||||
this.registerAction('longClick', '_sys_longClick_lockControl', this._sys_longClick_lockControl, 50);
|
this.registerAction('longClick', '_sys_longClick_lockControl', this._sys_longClick_lockControl, 50);
|
||||||
this.registerAction('longClick', '_sys_longClick', this._sys_longClick, 0);
|
|
||||||
// --- onStatusBarClick注册
|
// --- onStatusBarClick注册
|
||||||
this.registerAction('onStatusBarClick', '_sys_onStatusBarClick', this._sys_onStatusBarClick, 0);
|
this.registerAction('onStatusBarClick', '_sys_onStatusBarClick', this._sys_onStatusBarClick, 0);
|
||||||
|
|
||||||
@ -66,7 +62,7 @@ actions.prototype._init = function () {
|
|||||||
////// 注册一个用户交互行为 //////
|
////// 注册一个用户交互行为 //////
|
||||||
/*
|
/*
|
||||||
* 此函数将注册一个用户交互行为。
|
* 此函数将注册一个用户交互行为。
|
||||||
* action:要注册的交互类型,如 ondown, onclick, keyDown 等等。
|
* action:要注册的交互类型,如 ondown, onup, keyDown 等等。
|
||||||
* name:你的自定义名称,可被注销使用;同名重复注册将后者覆盖前者。
|
* name:你的自定义名称,可被注销使用;同名重复注册将后者覆盖前者。
|
||||||
* func:执行函数。
|
* func:执行函数。
|
||||||
* priority:优先级;优先级高的将会被执行。此项可不填,默认为0。
|
* priority:优先级;优先级高的将会被执行。此项可不填,默认为0。
|
||||||
@ -75,6 +71,8 @@ actions.prototype._init = function () {
|
|||||||
actions.prototype.registerAction = function (action, name, func, priority) {
|
actions.prototype.registerAction = function (action, name, func, priority) {
|
||||||
if (!name || !func)
|
if (!name || !func)
|
||||||
return;
|
return;
|
||||||
|
// 将onclick视为ondown处理
|
||||||
|
if (action == 'onclick') action = 'ondown';
|
||||||
priority = priority || 0;
|
priority = priority || 0;
|
||||||
if (!this.actions[action]) {
|
if (!this.actions[action]) {
|
||||||
this.actions[action] = [];
|
this.actions[action] = [];
|
||||||
@ -90,6 +88,8 @@ actions.prototype.registerAction = function (action, name, func, priority) {
|
|||||||
|
|
||||||
////// 注销一个用户交互行为 //////
|
////// 注销一个用户交互行为 //////
|
||||||
actions.prototype.unregisterAction = function (action, name) {
|
actions.prototype.unregisterAction = function (action, name) {
|
||||||
|
// 将onclick视为ondown处理
|
||||||
|
if (action == 'onclick') action = 'ondown';
|
||||||
if (!this.actions[action]) return;
|
if (!this.actions[action]) return;
|
||||||
this.actions[action] = this.actions[action].filter(function (x) {
|
this.actions[action] = this.actions[action].filter(function (x) {
|
||||||
return x.name != name;
|
return x.name != name;
|
||||||
@ -462,176 +462,6 @@ actions.prototype.ondown = function (loc) {
|
|||||||
actions.prototype._sys_ondown_lockControl = function (x, y, px, py) {
|
actions.prototype._sys_ondown_lockControl = function (x, y, px, py) {
|
||||||
if (core.status.played && !core.status.lockControl) return false;
|
if (core.status.played && !core.status.lockControl) return false;
|
||||||
|
|
||||||
core.actions.onclick(x, y, px, py, []);
|
|
||||||
|
|
||||||
// --- 长按判定
|
|
||||||
if (core.timeout.onDownTimeout == null) {
|
|
||||||
core.timeout.onDownTimeout = setTimeout(function () {
|
|
||||||
if (core.interval.onDownInterval == null) {
|
|
||||||
core.interval.onDownInterval = setInterval(function () {
|
|
||||||
if (!core.actions.longClick(x, y, px, py)) {
|
|
||||||
clearInterval(core.interval.onDownInterval);
|
|
||||||
core.interval.onDownInterval = null;
|
|
||||||
}
|
|
||||||
}, 40)
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
actions.prototype._sys_ondown = function (x, y, px, py) {
|
|
||||||
core.status.downTime = new Date();
|
|
||||||
core.deleteCanvas('route');
|
|
||||||
var pos = {'x': x, 'y': y}
|
|
||||||
core.status.stepPostfix = [];
|
|
||||||
core.status.stepPostfix.push(pos);
|
|
||||||
core.fillPosWithPoint(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
////// 当在触摸屏上滑动时 //////
|
|
||||||
actions.prototype.onmove = function (loc) {
|
|
||||||
var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size);
|
|
||||||
var px = parseInt(loc.x / core.domStyle.scale), py = parseInt(loc.y / core.domStyle.scale);
|
|
||||||
this.doRegisteredAction('onmove', x, y, px, py);
|
|
||||||
}
|
|
||||||
|
|
||||||
actions.prototype._sys_onmove_choices = function (x, y) {
|
|
||||||
if (!core.status.lockControl) return false;
|
|
||||||
|
|
||||||
switch (core.status.event.id) {
|
|
||||||
case 'action':
|
|
||||||
if (core.status.event.data.type == 'choices') {
|
|
||||||
this._onMoveChoices(x, y);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (core.status.event.data.type == 'confirm') {
|
|
||||||
this._onMoveConfirmBox(x, y);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'selectShop':
|
|
||||||
case 'switchs':
|
|
||||||
case 'switchs-sounds':
|
|
||||||
case 'switchs-display':
|
|
||||||
case 'switchs-action':
|
|
||||||
case 'notes':
|
|
||||||
case 'settings':
|
|
||||||
case 'syncSave':
|
|
||||||
case 'syncSelect':
|
|
||||||
case 'localSaveSelect':
|
|
||||||
case 'storageRemove':
|
|
||||||
case 'replay':
|
|
||||||
case 'gameInfo':
|
|
||||||
this._onMoveChoices(x, y);
|
|
||||||
return true;
|
|
||||||
case 'confirmBox':
|
|
||||||
this._onMoveConfirmBox(x, y);
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
actions.prototype._sys_onmove = function (x, y) {
|
|
||||||
if ((core.status.stepPostfix || []).length > 0) {
|
|
||||||
var pos = {'x': x, 'y': y};
|
|
||||||
var pos0 = core.status.stepPostfix[core.status.stepPostfix.length - 1];
|
|
||||||
var directionDistance = [pos.y - pos0.y, pos0.x - pos.x, pos0.y - pos.y, pos.x - pos0.x];
|
|
||||||
var max = 0, index = 4;
|
|
||||||
for (var ii = 0; ii < 4; ii++) {
|
|
||||||
if (directionDistance[ii] > max) {
|
|
||||||
index = ii;
|
|
||||||
max = directionDistance[ii];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pos = [{'x': 0, 'y': 1}, {'x': -1, 'y': 0}, {'x': 0, 'y': -1}, {'x': 1, 'y': 0}, false][index]
|
|
||||||
if (pos) {
|
|
||||||
pos.x += pos0.x;
|
|
||||||
pos.y += pos0.y;
|
|
||||||
core.status.stepPostfix.push(pos);
|
|
||||||
core.fillPosWithPoint(pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
////// 当点击(触摸)事件放开时 //////
|
|
||||||
actions.prototype.onup = function (loc) {
|
|
||||||
var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size);
|
|
||||||
var px = parseInt(loc.x / core.domStyle.scale), py = parseInt(loc.y / core.domStyle.scale);
|
|
||||||
this.doRegisteredAction('onup', x, y, px, py);
|
|
||||||
}
|
|
||||||
|
|
||||||
actions.prototype._sys_onup = function () {
|
|
||||||
clearTimeout(core.timeout.onDownTimeout);
|
|
||||||
core.timeout.onDownTimeout = null;
|
|
||||||
clearInterval(core.interval.onDownInterval);
|
|
||||||
core.interval.onDownInterval = null;
|
|
||||||
|
|
||||||
if ((core.status.stepPostfix || []).length == 0) return false;
|
|
||||||
|
|
||||||
var stepPostfix = [];
|
|
||||||
var direction = {'0': {'1': 'down', '-1': 'up'}, '-1': {'0': 'left'}, '1': {'0': 'right'}};
|
|
||||||
for (var ii = 1; ii < core.status.stepPostfix.length; ii++) {
|
|
||||||
var pos0 = core.status.stepPostfix[ii - 1];
|
|
||||||
var pos = core.status.stepPostfix[ii];
|
|
||||||
stepPostfix.push({
|
|
||||||
'direction': direction[pos.x - pos0.x][pos.y - pos0.y],
|
|
||||||
'x': pos.x + parseInt(core.bigmap.offsetX / 32),
|
|
||||||
'y': pos.y + parseInt(core.bigmap.offsetY / 32)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
var posx = core.status.stepPostfix[0].x;
|
|
||||||
var posy = core.status.stepPostfix[0].y;
|
|
||||||
core.status.stepPostfix = [];
|
|
||||||
if (!core.status.lockControl) {
|
|
||||||
core.clearMap('ui');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 长按
|
|
||||||
if (!core.status.lockControl && stepPostfix.length == 0 && core.status.downTime != null && new Date() - core.status.downTime >= 1000) {
|
|
||||||
core.actions.longClick(posx, posy, 32 * posx + 16, 32 * posy + 16);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//posx,posy是寻路的目标点,stepPostfix是后续的移动
|
|
||||||
core.actions.onclick(posx, posy, 32 * posx + 16, 32 * posy + 16, stepPostfix);
|
|
||||||
}
|
|
||||||
core.status.downTime = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
////// 获得点击事件相对左上角的坐标 //////
|
|
||||||
actions.prototype._getClickLoc = function (x, y) {
|
|
||||||
|
|
||||||
var statusBar = {'x': 0, 'y': 0};
|
|
||||||
var size = 32;
|
|
||||||
size = size * core.domStyle.scale;
|
|
||||||
|
|
||||||
if (core.domStyle.isVertical) {
|
|
||||||
statusBar.x = 3;
|
|
||||||
statusBar.y = core.dom.statusBar.offsetHeight + 3;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
statusBar.x = core.dom.statusBar.offsetWidth + 3;
|
|
||||||
statusBar.y = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
var left = core.dom.gameGroup.offsetLeft + statusBar.x;
|
|
||||||
var top = core.dom.gameGroup.offsetTop + statusBar.y;
|
|
||||||
var loc = {'x': Math.max(x - left), 'y': Math.max(y - top, 0), 'size': size};
|
|
||||||
return loc;
|
|
||||||
}
|
|
||||||
|
|
||||||
////// 具体点击屏幕上(x,y)点时,执行的操作 //////
|
|
||||||
actions.prototype.onclick = function (x, y, px, py, stepPostfix) {
|
|
||||||
// console.log("Click: (" + x + "," + y + ")");
|
|
||||||
return this.doRegisteredAction('onclick', x, y, px, py, stepPostfix || []);
|
|
||||||
}
|
|
||||||
|
|
||||||
actions.prototype._sys_onclick_lockControl = function (x, y, px, py) {
|
|
||||||
if (!core.status.lockControl) return false;
|
|
||||||
switch (core.status.event.id) {
|
switch (core.status.event.id) {
|
||||||
case 'centerFly':
|
case 'centerFly':
|
||||||
this._clickCenterFly(x, y, px, py);
|
this._clickCenterFly(x, y, px, py);
|
||||||
@ -720,15 +550,210 @@ actions.prototype._sys_onclick_lockControl = function (x, y, px, py) {
|
|||||||
core.ui.closePanel();
|
core.ui.closePanel();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- 长按判定
|
||||||
|
if (core.timeout.onDownTimeout == null) {
|
||||||
|
core.timeout.onDownTimeout = setTimeout(function () {
|
||||||
|
if (core.interval.onDownInterval == null) {
|
||||||
|
core.interval.onDownInterval = setInterval(function () {
|
||||||
|
if (!core.actions.longClick(x, y, px, py)) {
|
||||||
|
clearInterval(core.interval.onDownInterval);
|
||||||
|
core.interval.onDownInterval = null;
|
||||||
|
}
|
||||||
|
}, 40)
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.prototype._sys_onclick = function (x, y, px, py, stepPostfix) {
|
actions.prototype._sys_ondown = function (x, y, px, py) {
|
||||||
// 寻路
|
if (core.status.lockControl) return false;
|
||||||
core.setAutomaticRoute(x + parseInt(core.bigmap.offsetX / 32), y + parseInt(core.bigmap.offsetY / 32), stepPostfix);
|
core.status.downTime = new Date();
|
||||||
|
core.deleteCanvas('route');
|
||||||
|
var pos = {'x': parseInt((px + core.bigmap.offsetX) / 32), 'y': parseInt((py + core.bigmap.offsetY) / 32)};
|
||||||
|
core.status.stepPostfix = [];
|
||||||
|
core.status.stepPostfix.push(pos);
|
||||||
|
core.fillRect('ui', pos.x*32+12-core.bigmap.offsetX,pos.y*32+12-core.bigmap.offsetY,8,8, '#bfbfbf');
|
||||||
|
|
||||||
|
clearTimeout(core.timeout.onDownTimeout);
|
||||||
|
core.timeout.onDownTimeout = null;
|
||||||
|
core.status.preview.prepareDragging = false;
|
||||||
|
if (!core.hasFlag('__lockViewport__') && (core.status.thisMap.width > core.__SIZE__ || core.status.thisMap.height > core.__SIZE__)) {
|
||||||
|
core.status.preview.prepareDragging = true;
|
||||||
|
core.status.preview.px = px;
|
||||||
|
core.status.preview.py = py;
|
||||||
|
core.timeout.onDownTimeout = setTimeout(function () {
|
||||||
|
core.clearMap('ui');
|
||||||
|
core.status.preview.prepareDragging = false;
|
||||||
|
core.status.preview.enabled = true;
|
||||||
|
core.status.preview.dragging = true;
|
||||||
|
core.drawTip('已进入预览模式,可直接拖动大地图');
|
||||||
|
console.log('已进入预览模式,可直接拖动大地图');
|
||||||
|
core.status.stepPostfix = [];
|
||||||
|
}, 1200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////// 当在触摸屏上滑动时 //////
|
||||||
|
actions.prototype.onmove = function (loc) {
|
||||||
|
var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size);
|
||||||
|
var px = parseInt(loc.x / core.domStyle.scale), py = parseInt(loc.y / core.domStyle.scale);
|
||||||
|
this.doRegisteredAction('onmove', x, y, px, py);
|
||||||
|
}
|
||||||
|
|
||||||
|
actions.prototype._sys_onmove_choices = function (x, y) {
|
||||||
|
if (!core.status.lockControl) return false;
|
||||||
|
|
||||||
|
switch (core.status.event.id) {
|
||||||
|
case 'action':
|
||||||
|
if (core.status.event.data.type == 'choices') {
|
||||||
|
this._onMoveChoices(x, y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (core.status.event.data.type == 'confirm') {
|
||||||
|
this._onMoveConfirmBox(x, y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'selectShop':
|
||||||
|
case 'switchs':
|
||||||
|
case 'switchs-sounds':
|
||||||
|
case 'switchs-display':
|
||||||
|
case 'switchs-action':
|
||||||
|
case 'notes':
|
||||||
|
case 'settings':
|
||||||
|
case 'syncSave':
|
||||||
|
case 'syncSelect':
|
||||||
|
case 'localSaveSelect':
|
||||||
|
case 'storageRemove':
|
||||||
|
case 'replay':
|
||||||
|
case 'gameInfo':
|
||||||
|
this._onMoveChoices(x, y);
|
||||||
|
return true;
|
||||||
|
case 'confirmBox':
|
||||||
|
this._onMoveConfirmBox(x, y);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
actions.prototype._sys_onmove = function (x, y, px, py) {
|
||||||
|
if (core.status.lockControl) return false;
|
||||||
|
|
||||||
|
if (core.status.preview.dragging) {
|
||||||
|
core.setViewport(core.bigmap.offsetX - px + core.status.preview.px, core.bigmap.offsetY - py + core.status.preview.py);
|
||||||
|
core.status.preview.px = px;
|
||||||
|
core.status.preview.py = py;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (core.status.preview.prepareDragging) {
|
||||||
|
if (Math.abs(px - core.status.preview.px) <= 20 && Math.abs(py - core.status.preview.py) <= 20)
|
||||||
|
return true;
|
||||||
|
else core.status.preview.prepareDragging = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearTimeout(core.timeout.onDownTimeout);
|
||||||
|
core.timeout.onDownTimeout = null;
|
||||||
|
|
||||||
|
if ((core.status.stepPostfix || []).length > 0) {
|
||||||
|
var pos = {'x': parseInt((px + core.bigmap.offsetX) / 32), 'y': parseInt((py + core.bigmap.offsetY) / 32)};
|
||||||
|
var pos0 = core.status.stepPostfix[core.status.stepPostfix.length - 1];
|
||||||
|
var directionDistance = [pos.y - pos0.y, pos0.x - pos.x, pos0.y - pos.y, pos.x - pos0.x];
|
||||||
|
var max = 0, index = 4;
|
||||||
|
for (var ii = 0; ii < 4; ii++) {
|
||||||
|
if (directionDistance[ii] > max) {
|
||||||
|
index = ii;
|
||||||
|
max = directionDistance[ii];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pos = [{'x': 0, 'y': 1}, {'x': -1, 'y': 0}, {'x': 0, 'y': -1}, {'x': 1, 'y': 0}, false][index]
|
||||||
|
if (pos) {
|
||||||
|
pos.x += pos0.x;
|
||||||
|
pos.y += pos0.y;
|
||||||
|
core.status.stepPostfix.push(pos);
|
||||||
|
core.fillRect('ui', pos.x*32+12-core.bigmap.offsetX,pos.y*32+12-core.bigmap.offsetY,8,8, '#bfbfbf');
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////// 当点击(触摸)事件放开时 //////
|
||||||
|
actions.prototype.onup = function (loc) {
|
||||||
|
var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size);
|
||||||
|
var px = parseInt(loc.x / core.domStyle.scale), py = parseInt(loc.y / core.domStyle.scale);
|
||||||
|
this.doRegisteredAction('onup', x, y, px, py);
|
||||||
|
}
|
||||||
|
|
||||||
|
actions.prototype._sys_onup = function (x, y, px, py) {
|
||||||
|
clearTimeout(core.timeout.onDownTimeout);
|
||||||
|
core.timeout.onDownTimeout = null;
|
||||||
|
clearInterval(core.interval.onDownInterval);
|
||||||
|
core.interval.onDownInterval = null;
|
||||||
|
|
||||||
|
core.status.preview.prepareDragging = false;
|
||||||
|
if (core.status.preview.dragging) {
|
||||||
|
core.status.preview.dragging = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((core.status.stepPostfix || []).length == 0) return false;
|
||||||
|
|
||||||
|
var stepPostfix = [];
|
||||||
|
var direction = {'0': {'1': 'down', '-1': 'up'}, '-1': {'0': 'left'}, '1': {'0': 'right'}};
|
||||||
|
for (var ii = 1; ii < core.status.stepPostfix.length; ii++) {
|
||||||
|
var pos0 = core.status.stepPostfix[ii - 1];
|
||||||
|
var pos = core.status.stepPostfix[ii];
|
||||||
|
stepPostfix.push({
|
||||||
|
'direction': direction[pos.x - pos0.x][pos.y - pos0.y],
|
||||||
|
'x': pos.x,
|
||||||
|
'y': pos.y
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var posx = core.status.stepPostfix[0].x;
|
||||||
|
var posy = core.status.stepPostfix[0].y;
|
||||||
|
core.status.stepPostfix = [];
|
||||||
|
if (!core.status.lockControl) {
|
||||||
|
core.clearMap('ui');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 长按
|
||||||
|
if (!core.status.lockControl && stepPostfix.length == 0 && core.status.downTime != null && new Date() - core.status.downTime >= 1000) {
|
||||||
|
core.actions.longClick(x, y, px, py);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//posx,posy是寻路的目标点,stepPostfix是后续的移动
|
||||||
|
core.setAutomaticRoute(posx, posy, stepPostfix);
|
||||||
|
}
|
||||||
|
core.status.downTime = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
////// 获得点击事件相对左上角的坐标 //////
|
||||||
|
actions.prototype._getClickLoc = function (x, y) {
|
||||||
|
|
||||||
|
var statusBar = {'x': 0, 'y': 0};
|
||||||
|
var size = 32;
|
||||||
|
size = size * core.domStyle.scale;
|
||||||
|
|
||||||
|
if (core.domStyle.isVertical) {
|
||||||
|
statusBar.x = 3;
|
||||||
|
statusBar.y = core.dom.statusBar.offsetHeight + 3;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
statusBar.x = core.dom.statusBar.offsetWidth + 3;
|
||||||
|
statusBar.y = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
var left = core.dom.gameGroup.offsetLeft + statusBar.x;
|
||||||
|
var top = core.dom.gameGroup.offsetTop + statusBar.y;
|
||||||
|
var loc = {'x': Math.max(x - left), 'y': Math.max(y - top, 0), 'size': size};
|
||||||
|
return loc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////// 滑动鼠标滚轮时的操作 //////
|
////// 滑动鼠标滚轮时的操作 //////
|
||||||
actions.prototype.onmousewheel = function (direct) {
|
actions.prototype.onmousewheel = function (direct) {
|
||||||
this.doRegisteredAction('onmousewheel', direct);
|
this.doRegisteredAction('onmousewheel', direct);
|
||||||
@ -819,9 +844,9 @@ actions.prototype._sys_keyDownCtrl = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
////// 长按 //////
|
////// 长按 //////
|
||||||
actions.prototype.longClick = function (x, y, px, py, fromEvent) {
|
actions.prototype.longClick = function (x, y, px, py) {
|
||||||
if (!core.isPlaying()) return false;
|
if (!core.isPlaying()) return false;
|
||||||
return this.doRegisteredAction('longClick', x, y, px, py, fromEvent);
|
return this.doRegisteredAction('longClick', x, y, px, py);
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.prototype._sys_longClick_lockControl = function (x, y, px, py) {
|
actions.prototype._sys_longClick_lockControl = function (x, y, px, py) {
|
||||||
@ -861,15 +886,6 @@ actions.prototype._sys_longClick_lockControl = function (x, y, px, py) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.prototype._sys_longClick = function (x, y, px, py, fromEvent) {
|
|
||||||
if (core.status.lockControl) return false;
|
|
||||||
// 虚拟键盘
|
|
||||||
core.waitHeroToStop(function () {
|
|
||||||
core.ui._drawKeyBoard();
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
actions.prototype.onStatusBarClick = function (e) {
|
actions.prototype.onStatusBarClick = function (e) {
|
||||||
if (!core.isPlaying()) return false;
|
if (!core.isPlaying()) return false;
|
||||||
var left = core.dom.gameGroup.offsetLeft + 3;
|
var left = core.dom.gameGroup.offsetLeft + 3;
|
||||||
@ -3098,7 +3114,9 @@ actions.prototype._clickKeyBoard = function (x, y) {
|
|||||||
actions.prototype._clickCursor = function (x, y, px, py) {
|
actions.prototype._clickCursor = function (x, y, px, py) {
|
||||||
if (x == core.status.automaticRoute.cursorX && y == core.status.automaticRoute.cursorY) {
|
if (x == core.status.automaticRoute.cursorX && y == core.status.automaticRoute.cursorY) {
|
||||||
core.ui.closePanel();
|
core.ui.closePanel();
|
||||||
core.onclick(x, y, px, py, []);
|
// 视为按下再放起
|
||||||
|
this.doRegisteredAction('ondown', x, y, px, py);
|
||||||
|
this.doRegisteredAction('onup', x, y, px, py);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
core.status.automaticRoute.cursorX = x;
|
core.status.automaticRoute.cursorX = x;
|
||||||
@ -3146,7 +3164,9 @@ actions.prototype._keyUpCursor = function (keycode) {
|
|||||||
core.ui.closePanel();
|
core.ui.closePanel();
|
||||||
var x = core.status.automaticRoute.cursorX;
|
var x = core.status.automaticRoute.cursorX;
|
||||||
var y = core.status.automaticRoute.cursorY;
|
var y = core.status.automaticRoute.cursorY;
|
||||||
core.onclick(x, y, 32 * x + 16, 32 * y + 16, []);
|
// 视为按下再放起
|
||||||
|
this.doRegisteredAction('ondown', x, y, 32 * x + 16, 32 * y + 16);
|
||||||
|
this.doRegisteredAction('onup', x, y, 32 * x + 16, 32 * y + 16);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -159,7 +159,7 @@ control.prototype._animationFrame_globalAnimate = function (timestamp) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Global hero animate
|
// Global hero animate
|
||||||
if ((core.status.hero || {}).animate && core.status.heroMoving == 0 && main.mode == 'play') {
|
if ((core.status.hero || {}).animate && core.status.heroMoving == 0 && main.mode == 'play' && !core.status.preview.enabled) {
|
||||||
core.drawHero('stop', null, core.status.globalAnimateStatus);
|
core.drawHero('stop', null, core.status.globalAnimateStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -498,11 +498,6 @@ control.prototype.clearContinueAutomaticRoute = function (callback) {
|
|||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
////// 显示离散的寻路点 //////
|
|
||||||
control.prototype.fillPosWithPoint = function (pos) {
|
|
||||||
core.fillRect('ui', pos.x*32+12,pos.y*32+12,8,8, '#bfbfbf');
|
|
||||||
}
|
|
||||||
|
|
||||||
////// 设置自动寻路路线 //////
|
////// 设置自动寻路路线 //////
|
||||||
control.prototype.setAutomaticRoute = function (destX, destY, stepPostfix) {
|
control.prototype.setAutomaticRoute = function (destX, destY, stepPostfix) {
|
||||||
if (!core.status.played || core.status.lockControl) return;
|
if (!core.status.played || core.status.lockControl) return;
|
||||||
@ -834,6 +829,7 @@ control.prototype.drawHero = function (status, offset, frame) {
|
|||||||
core.setGameCanvasTranslate('hero', 0, 0);
|
core.setGameCanvasTranslate('hero', 0, 0);
|
||||||
delete core.canvas.hero._px;
|
delete core.canvas.hero._px;
|
||||||
delete core.canvas.hero._py;
|
delete core.canvas.hero._py;
|
||||||
|
core.status.preview.enabled = false;
|
||||||
if (!core.hasFlag('__lockViewport__')) {
|
if (!core.hasFlag('__lockViewport__')) {
|
||||||
this._drawHero_updateViewport(x, y, offset);
|
this._drawHero_updateViewport(x, y, offset);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -178,6 +178,13 @@ function core() {
|
|||||||
// 按下键的时间:为了判定双击
|
// 按下键的时间:为了判定双击
|
||||||
'downTime': null,
|
'downTime': null,
|
||||||
'ctrlDown': false,
|
'ctrlDown': false,
|
||||||
|
'preview': {
|
||||||
|
'enabled': false,
|
||||||
|
'prepareDragging': false,
|
||||||
|
'dragging': false,
|
||||||
|
'px': 0,
|
||||||
|
'py': 0,
|
||||||
|
},
|
||||||
|
|
||||||
// 路线&回放
|
// 路线&回放
|
||||||
'route': [],
|
'route': [],
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
3
runtime.d.ts
vendored
3
runtime.d.ts
vendored
@ -623,9 +623,6 @@ declare class control {
|
|||||||
/** 清空剩下的自动寻路列表 */
|
/** 清空剩下的自动寻路列表 */
|
||||||
clearContinueAutomaticRoute(callback?: () => any): void
|
clearContinueAutomaticRoute(callback?: () => any): void
|
||||||
|
|
||||||
/** 显示离散的寻路点 */
|
|
||||||
fillPosWithPoint(pos?: any): void
|
|
||||||
|
|
||||||
/** 设置行走的效果动画 */
|
/** 设置行走的效果动画 */
|
||||||
setHeroMoveInterval(callback?: () => any): void
|
setHeroMoveInterval(callback?: () => any): void
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user