Compare commits

..

6 Commits

10 changed files with 150 additions and 58 deletions

View File

@ -489,9 +489,6 @@ gameKey
.realize('fly', () => {
core.useFly(true);
})
.realize('replay', () => {
core.ui._drawReplay();
})
.realize('shop', () => {
core.openQuickShop(true);
})

View File

@ -5,7 +5,8 @@ import {
mainUIController,
openStatistics,
saveLoad,
openSettings
openSettings,
ReplaySettingsUI
} from './ui';
export function createAction() {
@ -21,5 +22,10 @@ export function createAction() {
})
.realize('menu', () => {
openSettings(mainUIController, [420, 240, 240, 400, 0.5, 0.5]);
})
.realize('replay', () => {
mainUIController.open(ReplaySettingsUI, {
loc: [420, 240, void 0, void 0, 0.5, 0.5]
});
});
}

View File

@ -8,7 +8,7 @@ import {
VNode,
watch
} from 'vue';
import { clamp } from 'lodash-es';
import { clamp, isNil } from 'lodash-es';
import { DefaultProps, ElementLocator, Font } from '@motajs/render';
import { SetupComponentOptions } from '@motajs/system-ui';
@ -177,6 +177,18 @@ export const Page = defineComponent<
updateRectAndText();
}
);
watch(
() => props.page,
page => {
if (!isNil(page)) {
const target = clamp(page, 0, props.pages - 1);
if (nowPage.value !== target) {
nowPage.value = target;
emit('pageChange', target);
}
}
}
);
/**
*

View File

@ -1,7 +1,7 @@
import { createApp, Font } from '@motajs/render';
import { defineComponent } from 'vue';
import { MAIN_HEIGHT, MAIN_WIDTH } from './shared';
import { loading } from '@user/data-base';
import { hook, loading } from '@user/data-base';
import { createLoopMap } from './loopMap';
import { createElements } from './elements';
import { mainRenderer } from './renderer';
@ -38,6 +38,11 @@ export function createRender() {
mainRenderer.show();
});
hook.on('restart', () => {
sceneController.closeAll();
sceneController.open(GameTitleUI, {});
});
Font.setDefaults(new Font('normal', 18));
}

View File

@ -76,7 +76,10 @@ export const SaveItem = defineComponent<SaveItemProps>(props => {
if (!props.data) return '';
else {
const hero = props.data.data.hero;
return `${hero.hp}/${hero.atk}/${hero.def}`;
const hp = core.formatBigNumber(hero.hp);
const atk = core.formatBigNumber(hero.atk);
const def = core.formatBigNumber(hero.def);
return `${hp}/${atk}/${def}`;
}
});
@ -183,6 +186,8 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
return [right, height.value - 13, void 0, void 0, 1, 1];
});
//#region 数据信息
/**
* 0 pageCap-1
*/
@ -204,10 +209,9 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
const index = getIndex(i, page);
promises.push(getSave(index + 1));
}
const before = now.value;
const before = page;
const data = await Promise.all(promises);
if (before !== now.value) return;
if (now.value !== before) return;
data.forEach((v, i) => {
if (v) {
saveData[i] = v;
@ -217,6 +221,17 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
});
};
onMounted(() => {
const startIndex = getPosIndex(core.saves.saveIndex);
selected.value = startIndex - 1;
pageRef.value?.changePage(
Math.floor(core.saves.saveIndex / (grid.value.count - 1))
);
updateDataList(now.value);
});
//#region 逻辑操作
const exist = (index: number) => {
return saveData[index] !== null;
};
@ -225,15 +240,6 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
saveData[index] = null;
};
onMounted(() => {
const startIndex = getPosIndex(core.saves.saveIndex);
selected.value = startIndex;
pageRef.value?.changePage(
Math.floor(core.saves.saveIndex / (grid.value.count - 1))
);
updateDataList(now.value);
});
const emitSave = async (index: number) => {
const posIndex = getPosIndex(index);
if (inDelete.value) {
@ -258,15 +264,6 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
}
};
const wheel = (ev: IWheelEvent) => {
const delta = Math.sign(ev.wheelY);
if (ev.ctrlKey) {
pageRef.value?.movePage(delta * 10);
} else {
pageRef.value?.movePage(delta);
}
};
const toggleDelete = () => {
inDelete.value = !inDelete.value;
};
@ -374,6 +371,16 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
{ type: 'down-repeat' }
);
//#region 事件监听
const wheel = (ev: IWheelEvent) => {
const delta = Math.sign(ev.wheelY);
if (ev.ctrlKey) {
pageRef.value?.movePage(delta * 10);
} else {
pageRef.value?.movePage(delta);
}
};
return () => (
<container loc={props.loc}>
<Page
@ -393,6 +400,7 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
const index = i === 0 ? 0 : rawIndex;
return (
<SaveItem
key={index}
loc={v}
index={index}
selected={selected.value === i}
@ -531,7 +539,6 @@ export async function saveSave(
props
);
if (index === -2) return false;
core.saves.saveIndex = index;
core.doSL(index + 1, 'save');
return true;
}
@ -559,3 +566,21 @@ export async function saveLoad(
}
return true;
}
export async function saveWithExist(
controller: IUIMountable,
loc: ElementLocator,
props?: SaveProps
) {
const validate = (_: number, exist: boolean): SaveValidation => {
return { message: '无效的存档!', valid: exist };
};
const index = await selectSave(
controller,
loc,
SaveMode.Load,
validate,
props
);
return index;
}

View File

@ -21,6 +21,8 @@ import { getVitualKeyOnce } from '@motajs/legacy-ui';
import { getAllSavesData, getSaveData, syncFromServer } from '../utils';
import { getInput } from '../components/input';
import { openStatistics } from './statistics';
import { saveWithExist } from './save';
import { compressToBase64 } from 'lz-string';
export interface MainSettingsProps
extends Partial<ChoicesProps>,
@ -58,7 +60,7 @@ export const MainSettings = defineComponent<MainSettingsProps>(props => {
[MainChoice.Back, '返回游戏']
];
const choose = (key: ChoiceKey) => {
const choose = async (key: ChoiceKey) => {
switch (key) {
case MainChoice.SystemSetting: {
mainUi.open('settings');
@ -92,8 +94,16 @@ export const MainSettings = defineComponent<MainSettingsProps>(props => {
break;
}
case MainChoice.Restart: {
const confirm = await getConfirm(
props.controller,
'确认要返回标题吗?',
[420, 240, void 0, void 0, 0.5, 0.5],
240
);
if (confirm) {
props.controller.closeAll();
core.restart();
}
break;
}
case MainChoice.Back: {
@ -136,7 +146,7 @@ export const ReplaySettings = defineComponent<MainSettingsProps>(props => {
[ReplayChoice.Back, '返回游戏']
];
const choose = (key: ChoiceKey) => {
const choose = async (key: ChoiceKey) => {
switch (key) {
case ReplayChoice.Start: {
props.controller.closeAll();
@ -147,15 +157,59 @@ export const ReplaySettings = defineComponent<MainSettingsProps>(props => {
break;
}
case ReplayChoice.StartFromSave: {
// todo
const index = await saveWithExist(
props.controller,
[0, 0, 840, 480]
);
if (index === -2) break;
if (index === -1) {
core.doSL('autoSave', 'replayLoad');
} else {
core.doSL(index + 1, 'replayLoad');
}
props.controller.closeAll();
break;
}
case ReplayChoice.ResumeReplay: {
// todo
const index = await saveWithExist(
props.controller,
[0, 0, 840, 480]
);
if (index === -2) break;
const name = index === -1 ? 'autoSave' : index + 1;
const success = core.doSL(name, 'replayRemain');
if (!success) {
props.controller.closeAll();
break;
}
await getConfirm(
props.controller,
'[步骤2]请选择第二个存档。\n\r[yellow]该存档必须是前一个存档的后续。\r\n将尝试播放到此存档。',
[420, 240, void 0, void 0, 0.5, 0.5],
240
);
const index2 = await saveWithExist(
props.controller,
[0, 0, 840, 480]
);
if (index2 === -2) break;
const name2 = index2 === -1 ? 'autoSave' : index2 + 1;
core.doSL(name2, 'replayRemain');
props.controller.closeAll();
break;
}
case ReplayChoice.ReplayRest: {
// todo
const index = await saveWithExist(
props.controller,
[0, 0, 840, 480]
);
if (index === -2) break;
if (index === -1) {
core.doSL('autoSave', 'replaySince');
} else {
core.doSL(index + 1, 'replaySince');
}
props.controller.closeAll();
break;
}
case ReplayChoice.ChooseReplay: {
@ -166,8 +220,7 @@ export const ReplaySettings = defineComponent<MainSettingsProps>(props => {
case ReplayChoice.Download: {
core.download(
core.firstData.name + '_' + core.formatDate2() + '.h5route',
// @ts-expect-error 暂时无法推导
LZString.compressToBase64(
compressToBase64(
JSON.stringify({
name: core.firstData.name,
hard: core.status.hard,

View File

@ -237,7 +237,8 @@ export class UIController
closeAll(ui?: IGameUI): void {
if (!ui) {
this.stack.splice(0);
const list = this.stack.slice();
list.forEach(v => this.close(v));
} else {
const list = this.stack.filter(v => v.ui === ui);
list.forEach(v => this.close(v));

View File

@ -2019,7 +2019,7 @@ control.prototype.doSL = function (id, type) {
this._doSL_load(id, this._doSL_replayLoad_afterGet);
break;
case 'replayRemain':
this._doSL_load(id, this._doSL_replayRemain_afterGet);
return this._doSL_load(id, this._doSL_replayRemain_afterGet);
break;
case 'replaySince':
this._doSL_load(id, this._doSL_replaySince_afterGet);
@ -2186,7 +2186,8 @@ control.prototype._doSL_replayLoad_afterGet = function (id, data) {
control.prototype._doSL_replayRemain_afterGet = function (id, data) {
if (!data) {
core.playSound('操作失败');
return core.drawTip('无效的存档');
core.drawTip('无效的存档');
return false;
}
var route = core.decodeRoute(data.route);
if (core.status.tempRoute) {
@ -2199,27 +2200,18 @@ control.prototype._doSL_replayRemain_afterGet = function (id, data) {
core.ui.closePanel();
core.startReplay(remainRoute);
core.drawTip('接续播放录像');
return;
return true;
} else if (
data.floorId != core.status.floorId ||
data.hero.loc.x != core.getHeroLoc('x') ||
data.hero.loc.y != core.getHeroLoc('y')
)
return alert('楼层或坐标不一致!');
) {
alert('楼层或坐标不一致!');
return false;
}
core.status.tempRoute = route;
core.ui.closePanel();
core.drawText(
'\t[步骤2]请选择第二个存档。\n\r[yellow]该存档必须是前一个存档的后续。\r\n将尝试播放到此存档。',
function () {
core.status.event.id = 'replayRemain';
core.lockControl();
var saveIndex = core.saves.saveIndex;
var page = Math.floor((saveIndex - 1) / 5),
offset = saveIndex - 5 * page;
core.ui._drawSLPanel(10 * page + offset);
}
);
return true;
};
control.prototype._doSL_replaySince_afterGet = function (id, data) {

View File

@ -3408,7 +3408,7 @@ events.prototype.openToolbox = function (fromUserAction) {
////// 点击快捷商店按钮时的打开操作 //////
events.prototype.openQuickShop = function (fromUserAction) {
if (core.isReplaying()) return;
const shop = Mota.require('@user/data-state');
const shop = Mota.require('@user/legacy-plugin-data');
if (Object.keys(core.status.shops).length == 0) {
core.playSound('操作失败');

View File

@ -610,7 +610,8 @@ interface Control {
/**
*
*/
doSL(id: string | number, type: SLType): void;
doSL(id: string | number, type: Exclude<SLType, 'replayRemain'>): void;
doSL(id: string | number, type: 'replayRemain'): boolean;
/**
*