设置勇士不透明度 & 大怪物中下锚点

This commit is contained in:
ckcz123 2021-08-31 17:48:40 +08:00
parent 96477f77d0
commit e1f55d6e72
12 changed files with 65 additions and 94 deletions

View File

@ -610,6 +610,9 @@ noGather: 是否聚集跟随者
setHeroMoveInterval: fn(callback?: fn()) setHeroMoveInterval: fn(callback?: fn())
设置行走的效果动画 设置行走的效果动画
setHeroOpacity: fn(opacity?: number, moveMode?: string, time?: number, callback?: fn())
改变勇士的不透明度
setMusicBtn: fn() setMusicBtn: fn()
设置音乐图标的显隐状态 设置音乐图标的显隐状态
@ -682,9 +685,6 @@ triggerDebuff: fn(action: string, type: string|[string])
action: 要获得还是移除,'get'为获得,'remove'为移除 action: 要获得还是移除,'get'为获得,'remove'为移除
type: 获得或移除的内容poison/weak/curse可以为字符串或数组 type: 获得或移除的内容poison/weak/curse可以为字符串或数组
triggerHero: fn(type?: string, time?: number, callback?: fn())
改变勇士的显隐状态
triggerReplay: fn() triggerReplay: fn()
播放或暂停录像回放 播放或暂停录像回放

View File

@ -581,8 +581,8 @@ core.insertAction({"type": "changeFloor", "floorId": "MT" + core.rand2(20)})
* V2.8.1起,支持暂时锁定视角,视角锁定期间,只有上下楼后才会将视角重置到勇士身上(但依然保持锁定)。 * V2.8.1起,支持暂时锁定视角,视角锁定期间,只有上下楼后才会将视角重置到勇士身上(但依然保持锁定)。
4. **显隐状态栏:**如题,如果隐藏状态栏期间勇士需要恢复行动,则建议不隐藏竖屏工具栏以方便手机玩家。 4. **显隐状态栏:**如题,如果隐藏状态栏期间勇士需要恢复行动,则建议不隐藏竖屏工具栏以方便手机玩家。
* 实际调用`core.showStatusBar()`和`core.hideStatusBar(showToolbox)` * 实际调用`core.showStatusBar()`和`core.hideStatusBar(showToolbox)`
5. **显隐勇士**如题,动画时间为淡入淡出时间,异步勾选框用法如前。 5. **设置勇士不透明度**如题,动画时间为淡入淡出时间,异步勾选框用法如前。
* 实际调用`core.triggerHero(type, time, callback)` * 实际调用`core.setHeroOpacity(opacity, moveMode, time, callback)`
6. **更改画面色调:**色调可以用调色器调配,“动画时间”为渐变的总时间。 6. **更改画面色调:**色调可以用调色器调配,“动画时间”为渐变的总时间。
* 请注意渐变是在RGBA颜色空间中直线运动V2.8.1支持加速度),因此效果可能不好,画面闪烁同理。 * 请注意渐变是在RGBA颜色空间中直线运动V2.8.1支持加速度),因此效果可能不好,画面闪烁同理。
* 如需在勇士自由行动时反复执行,请使用并行脚本或自我回调。 * 如需在勇士自由行动时反复执行,请使用并行脚本或自我回调。

View File

@ -2239,9 +2239,9 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
"!doc": "半自动寻路,用于鼠标或手指拖动<br/>例如core.setAutomaticRoute(0, 0, [{direction: \"right\", x: 4, y: 9}, {direction: \"right\", x: 5, y: 9}]);<br/>destX: 鼠标或手指的起拖点横坐标<br/>destY: 鼠标或手指的起拖点纵坐标<br/>stepPostfix: 拖动轨迹的数组表示,每项为一步的方向和目标点。", "!doc": "半自动寻路,用于鼠标或手指拖动<br/>例如core.setAutomaticRoute(0, 0, [{direction: \"right\", x: 4, y: 9}, {direction: \"right\", x: 5, y: 9}]);<br/>destX: 鼠标或手指的起拖点横坐标<br/>destY: 鼠标或手指的起拖点纵坐标<br/>stepPostfix: 拖动轨迹的数组表示,每项为一步的方向和目标点。",
"!type": "fn(destX: number, destY: number, stepPostfix: [{x: number, y: number, direction: string}])" "!type": "fn(destX: number, destY: number, stepPostfix: [{x: number, y: number, direction: string}])"
}, },
"triggerHero": { "setHeroOpacity": {
"!doc": "改变勇士的显隐状态", "!doc": "改变勇士的不透明度",
"!type": "fn(type?: string, time?: number, callback?: fn())" "!type": "fn(opacity?: number, moveMode?: string, time?: number, callback?: fn())"
}, },
"gatherFollowers": { "gatherFollowers": {
"!doc": "立刻聚集所有的跟随者", "!doc": "立刻聚集所有的跟随者",

View File

@ -847,8 +847,7 @@ action
| update_s | update_s
| showStatusBar_s | showStatusBar_s
| hideStatusBar_s | hideStatusBar_s
| showHero_s | setHeroOpacity_s
| hideHero_s
| sleep_s | sleep_s
| wait_s | wait_s
| waitAsync_s | waitAsync_s
@ -1780,33 +1779,19 @@ var code = '{"type": "hideStatusBar"'+Bool_0+'},\n';
return code; return code;
*/; */;
showHero_s setHeroOpacity_s
: '显示勇士' '动画时间' IntString? '不等待执行完毕' Bool Newline : '设置勇士不透明度' Number '渐变方式' MoveMode_List '动画时间' IntString? '不等待执行完毕' Bool Newline
/* setHeroOpacity_s
/* showHero_s tooltip : setHeroOpacity: 设置勇士不透明度
tooltip : showHero: 显示勇士
helpUrl : /_docs/#/instruction helpUrl : /_docs/#/instruction
default : ['',false] default : [1,'','',false]
colour : this.soundColor colour : this.soundColor
if (Number_0 < 0 || Number_0 > 1) throw new Error('不透明度需要在0~1之间');
MoveMode_List_0 = (MoveMode_List_0!=='') ? (', "moveMode": "'+MoveMode_List_0+'"'):'';
IntString_0 = IntString_0 && (', "time": ' + IntString_0); IntString_0 = IntString_0 && (', "time": ' + IntString_0);
Bool_0 = Bool_0 ? (', "async": true') : ''; Bool_0 = Bool_0 ? (', "async": true') : '';
var code = '{"type": "showHero"'+IntString_0+Bool_0+'},\n'; var code = '{"type": "setHeroOpacity", "opacity": '+Number_0+MoveMode_List_0+IntString_0+Bool_0+'},\n';
return code;
*/;
hideHero_s
: '隐藏勇士' '动画时间' IntString? '不等待执行完毕' Bool Newline
/* hideHero_s
tooltip : hideHero: 隐藏勇士
helpUrl : /_docs/#/instruction
default : ['',false]
colour : this.soundColor
IntString_0 = IntString_0 && (', "time": ' + IntString_0);
Bool_0 = Bool_0 ? (', "async": true') : '';
var code = '{"type": "hideHero"'+IntString_0+Bool_0+'},\n';
return code; return code;
*/; */;

View File

@ -931,13 +931,9 @@ ActionParser.prototype.parseAction = function() {
this.next = MotaActionBlocks['hideStatusBar_s'].xmlText([ this.next = MotaActionBlocks['hideStatusBar_s'].xmlText([
data.toolbox||false,this.next]); data.toolbox||false,this.next]);
break; break;
case "showHero": case "setHeroOpacity":
this.next = MotaActionBlocks['showHero_s'].xmlText([ this.next = MotaActionBlocks['setHeroOpacity_s'].xmlText([
data.time, data.async||false, this.next]); data.opacity, data.moveMode, data.time, data.async||false, this.next]);
break;
case "hideHero":
this.next = MotaActionBlocks['hideHero_s'].xmlText([
data.time, data.async||false, this.next]);
break; break;
case "sleep": // 等待多少毫秒 case "sleep": // 等待多少毫秒
this.next = MotaActionBlocks['sleep_s'].xmlText([ this.next = MotaActionBlocks['sleep_s'].xmlText([

View File

@ -204,8 +204,7 @@ editor_blocklyconfig=(function(){
MotaActionBlocks['lockViewport_s'].xmlText(), MotaActionBlocks['lockViewport_s'].xmlText(),
MotaActionBlocks['showStatusBar_s'].xmlText(), MotaActionBlocks['showStatusBar_s'].xmlText(),
MotaActionBlocks['hideStatusBar_s'].xmlText(), MotaActionBlocks['hideStatusBar_s'].xmlText(),
MotaActionBlocks['showHero_s'].xmlText(), MotaActionBlocks['setHeroOpacity_s'].xmlText(),
MotaActionBlocks['hideHero_s'].xmlText(),
MotaActionBlocks['setCurtain_0_s'].xmlText(), MotaActionBlocks['setCurtain_0_s'].xmlText(),
MotaActionBlocks['setCurtain_1_s'].xmlText(), MotaActionBlocks['setCurtain_1_s'].xmlText(),
MotaActionBlocks['screenFlash_s'].xmlText(), MotaActionBlocks['screenFlash_s'].xmlText(),

View File

@ -38,8 +38,10 @@
fs.deleteFile('_saves/' + name, callback); fs.deleteFile('_saves/' + name, callback);
} }
core.utils.clearLocalForage = function (name, callback) { core.utils.clearLocalForage = function (callback) {
// Nothing to do fs.deleteFile('_saves', function () {
fs.mkdir('_saves', callback);
})
} }
core.utils.iterateLocalForage = function (iter, callback) { core.utils.iterateLocalForage = function (iter, callback) {

View File

@ -2819,6 +2819,7 @@ actions.prototype._clickStorageRemove_all = function () {
core.saves.autosave.data = null; core.saves.autosave.data = null;
core.saves.autosave.updated = false; core.saves.autosave.updated = false;
core.saves.autosave.now = 0; core.saves.autosave.now = 0;
core.saves.cache = {};
core.ui.closePanel(); core.ui.closePanel();
core.saves.saveIndex = 1; core.saves.saveIndex = 1;
core.saves.favorite = []; core.saves.favorite = [];

View File

@ -838,9 +838,7 @@ control.prototype.drawHero = function (status, offset, frame) {
this._drawHero_updateViewport(x, y, offset); this._drawHero_updateViewport(x, y, offset);
} }
if (!core.hasFlag('hideHero')) { this._drawHero_draw(direction, x, y, status, offset, frame);
this._drawHero_draw(direction, x, y, status, offset, frame);
}
} }
control.prototype._drawHero_updateViewport = function (x, y, offset) { control.prototype._drawHero_updateViewport = function (x, y, offset) {
@ -851,11 +849,13 @@ control.prototype._drawHero_updateViewport = function (x, y, offset) {
control.prototype._drawHero_draw = function (direction, x, y, status, offset, frame) { control.prototype._drawHero_draw = function (direction, x, y, status, offset, frame) {
offset = offset || {x: 0, y: 0, offset: 0, px: 0, py: 0}; offset = offset || {x: 0, y: 0, offset: 0, px: 0, py: 0};
var opacity = core.setAlpha('hero', core.getFlag('__heroOpacity__', 1))
this._drawHero_getDrawObjs(direction, x, y, status, offset).forEach(function (block) { this._drawHero_getDrawObjs(direction, x, y, status, offset).forEach(function (block) {
core.drawImage('hero', block.img, (block.heroIcon[block.status] + (frame || 0))%4*block.width, core.drawImage('hero', block.img, (block.heroIcon[block.status] + (frame || 0))%4*block.width,
block.heroIcon.loc * block.height, block.width, block.height, block.heroIcon.loc * block.height, block.width, block.height,
block.posx+(32-block.width)/2, block.posy+32-block.height, block.width, block.height); block.posx+(32-block.width)/2, block.posy+32-block.height, block.width, block.height);
}); });
core.setAlpha('hero', opacity);
} }
control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, offset) { control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, offset) {
@ -889,40 +889,28 @@ control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, off
}); });
} }
control.prototype.triggerHero = function (type, time, callback) { control.prototype.setHeroOpacity = function (opacity, moveMode, time, callback) {
if (type == null) {
type = core.hasFlag('hideHero') ? 'show' : 'hide';
}
if ((core.hasFlag('hideHero') && type != 'show') || (!core.hasFlag('hideHero') && type != 'hide')) {
if (callback) callback();
return;
}
core.removeFlag('hideHero');
var cb = function () {
if (type == 'hide') core.setFlag('hideHero', true);
core.drawHero();
if (callback) callback();
return;
}
time = time || 0; time = time || 0;
if (time == 0) return cb(); if (time == 0) {
time /= Math.max(core.status.replay.speed, 1) core.setFlag('__heroOpacity__', opacity);
this._triggerHero_animate(type, 10 / time, cb);
}
control.prototype._triggerHero_animate = function (type, delta, callback) {
var opacity = type != 'show' ? 1 : 0;
var animate = setInterval(function () {
opacity += type != 'show' ? -delta : delta;
core.setAlpha('hero', opacity);
core.drawHero(); core.drawHero();
core.setAlpha('hero', 1); if (callback) callback();
if (opacity >= 1 || opacity <= 0) { return;
}
time /= Math.max(core.status.replay.speed, 1)
var fromOpacity = core.getFlag('__heroOpacity__', 1);
var step = 0, steps = parseInt(time / 10);
if (steps <= 0) steps = 1;
var moveFunc = core.applyEasing(moveMode);
var animate = setInterval(function () {
step++;
core.setFlag('__heroOpacity__', fromOpacity + (opacity - fromOpacity) * moveFunc(step / steps));
core.drawHero();
if (step == steps) {
delete core.animateFrame.asyncId[animate]; delete core.animateFrame.asyncId[animate];
clearInterval(animate); clearInterval(animate);
core.drawHero();
if (callback) callback(); if (callback) callback();
} }
}, 10); }, 10);

View File

@ -2346,22 +2346,22 @@ events.prototype._action_hideStatusBar = function (data, x, y, prefix) {
} }
events.prototype._action_showHero = function (data, x, y, prefix) { events.prototype._action_showHero = function (data, x, y, prefix) {
data.time = data.time || 0; data.opacity = 1;
if (data.time > 0) { return this._action_setHeroOpacity(data, x, y, prefix);
this.__action_doAsyncFunc(data.async, core.triggerHero, 'show', data.time);
} else {
core.removeFlag('hideHero');
core.drawHero();
core.doAction();
}
} }
events.prototype._action_hideHero = function (data, x, y, prefix) { events.prototype._action_hideHero = function (data, x, y, prefix) {
data.opacity = 0;
return this._action_setHeroOpacity(data, x, y, prefix);
}
events.prototype._action_setHeroOpacity = function (data, x, y, prefix) {
data.time = data.time || 0; data.time = data.time || 0;
if (data.opacity == null) data.opacity = 1;
if (data.time > 0) { if (data.time > 0) {
this.__action_doAsyncFunc(data.async, core.triggerHero, 'hide', data.time); this.__action_doAsyncFunc(data.async, core.setHeroOpacity, data.opacity, data.moveMode, data.time);
} else { } else {
core.setFlag('hideHero', true); core.setFlag('__heroOpacity__', data.opacity);
core.drawHero(); core.drawHero();
core.doAction(); core.doAction();
} }

View File

@ -968,9 +968,9 @@ maps.prototype._getBigImageInfo = function (bigImage, face, animate) {
} }
var dx, dy; var dx, dy;
switch (face) { switch (face) {
case "down": case "up": dx = 16 - per_width / 2; dy = 32 - per_height; break; case "down": case "up": case "left": case "right": dx = 16 - per_width / 2; dy = 32 - per_height; break;
case "left": dx = 0; dy = 32 - per_height; break; // case "left": dx = 0; dy = 32 - per_height; break;
case "right": dx = 32 - per_width; dy = 32 - per_height; break; // case "right": dx = 32 - per_width; dy = 32 - per_height; break;
} }
return {sx: sx, sy: sy, per_width: per_width, per_height: per_height, face: face, dx: dx, dy: dy}; return {sx: sx, sy: sy, per_width: per_width, per_height: per_height, face: face, dx: dx, dy: dy};
@ -1033,7 +1033,7 @@ maps.prototype._drawBlockInfo_bigImage = function (blockInfo, x, y, ctx) {
var dx = bigImageInfo.dx, dy = bigImageInfo.dy; var dx = bigImageInfo.dx, dy = bigImageInfo.dy;
switch (bigImageInfo.face) { switch (bigImageInfo.face) {
case "down": case "up": case "down": case "up": case "left": case "right":
core.createCanvas(header, px + dx, py + dy, per_width, -dy, 51); core.createCanvas(header, px + dx, py + dy, per_width, -dy, 51);
this._drawBlockInfo_drawWithFilter(blockInfo, header, function () { this._drawBlockInfo_drawWithFilter(blockInfo, header, function () {
core.drawImage(header, bigImage, sx, sy, per_width, -dy, 0, 0, per_width, -dy); core.drawImage(header, bigImage, sx, sy, per_width, -dy, 0, 0, per_width, -dy);
@ -1043,7 +1043,7 @@ maps.prototype._drawBlockInfo_bigImage = function (blockInfo, x, y, ctx) {
core.drawImage(body, bigImage, sx, sy - dy, per_width, 32, 0, 0, per_width, 32); core.drawImage(body, bigImage, sx, sy - dy, per_width, 32, 0, 0, per_width, 32);
}) })
break; break;
case "left": /*case "left":
core.createCanvas(header, px + dx, py + dy, per_width, -dy, 51); core.createCanvas(header, px + dx, py + dy, per_width, -dy, 51);
this._drawBlockInfo_drawWithFilter(blockInfo, header, function () { this._drawBlockInfo_drawWithFilter(blockInfo, header, function () {
core.drawImage(header, bigImage, sx, sy, per_width, -dy, 0, 0, per_width, -dy); core.drawImage(header, bigImage, sx, sy, per_width, -dy, 0, 0, per_width, -dy);
@ -1062,7 +1062,7 @@ maps.prototype._drawBlockInfo_bigImage = function (blockInfo, x, y, ctx) {
this._drawBlockInfo_drawWithFilter(blockInfo, body, function () { this._drawBlockInfo_drawWithFilter(blockInfo, body, function () {
core.drawImage(body, bigImage, sx, sy - dy, per_width, 32, 0, 0, per_width, 32); core.drawImage(body, bigImage, sx, sy - dy, per_width, 32, 0, 0, per_width, 32);
}); });
break; break;*/
} }
if (core.dymCanvas[header]) { if (core.dymCanvas[header]) {
core.dymCanvas[header].canvas.setAttribute('_ox', 32 * x + dx); core.dymCanvas[header].canvas.setAttribute('_ox', 32 * x + dx);

4
runtime.d.ts vendored
View File

@ -638,8 +638,8 @@ declare class control {
/** 瞬间移动 */ /** 瞬间移动 */
moveDirectly(destX?: any, destY?: any, ignoreSteps?: any): void moveDirectly(destX?: any, destY?: any, ignoreSteps?: any): void
/** 改变勇士的显隐状态 */ /** 改变勇士的不透明度 */
triggerHero(type?: 'show' | 'hide', time?: any, callback?: () => any): void setHeroOpacity(opacity?: number, moveMode?: string, time?: any, callback?: () => any): void
/** 加减画布偏移 */ /** 加减画布偏移 */
addGameCanvasTranslate(x?: number, y?: number): void addGameCanvasTranslate(x?: number, y?: number): void