feat: 换为新存读档界面

This commit is contained in:
unanmed 2025-06-21 15:03:06 +08:00
parent a7cdf2c69b
commit 84d93422f7
4 changed files with 44 additions and 11 deletions

View File

@ -3,7 +3,7 @@ import { gameKey, HotkeyJSON } from '@motajs/system-action';
import { hovered, mainUi, tip, openDanmakuPoster } from '@motajs/legacy-ui';
import { GameStorage } from '@motajs/legacy-system';
import { openStatistics } from '../render/ui/statistics';
import { mainUIController } from '../render';
import { MAIN_HEIGHT, MAIN_WIDTH, mainUIController, saveSave } from '../render';
export const mainScope = Symbol.for('@key_main');
@ -488,7 +488,7 @@ gameKey
core.openBook(true);
})
.realize('save', () => {
core.save(true);
saveSave(mainUIController, [0, 0, MAIN_WIDTH, MAIN_HEIGHT]);
})
.realize('load', () => {
core.load(true);

View File

@ -25,9 +25,9 @@ export interface SaveBtnProps extends DefaultProps {
export type SaveEmits = {
/** 点击存档时触发 */
emit: (index: number) => void;
emit: (index: number, exist: boolean) => void;
/** 删除存档时触发 */
delete: (index: number) => void;
delete: (index: number, exist: boolean) => void;
/** 手动点击退出时触发 */
exit: () => void;
};
@ -289,6 +289,11 @@ export interface SaveValidation {
readonly message: string;
}
export type SaveValidationFunction = (
index: number,
exist: boolean
) => SaveValidation;
/**
* -2
* {@link SaveProps}
@ -312,20 +317,20 @@ export interface SaveValidation {
export function selectSave(
controller: IUIMountable,
loc: ElementLocator,
validate?: (index: number) => SaveValidation,
validate?: SaveValidationFunction,
props?: SaveProps
) {
return new Promise<number>(res => {
const instance = controller.open(SaveUI, {
loc,
...props,
onEmit: (index: number) => {
onEmit: (index: number, exist: boolean) => {
if (!validate) {
controller.close(instance);
res(index);
return;
}
const validation = validate(index);
const validation = validate(index, exist);
if (validation.valid) {
controller.close(instance);
res(index);
@ -339,3 +344,31 @@ export function selectSave(
});
});
}
export async function saveSave(
controller: IUIMountable,
loc: ElementLocator,
props?: SaveProps
) {
const validate = (index: number): SaveValidation => {
if (index === -1) {
return { message: '不能存档至自动存档!', valid: false };
} else {
return { message: '', valid: true };
}
};
const index = await selectSave(controller, loc, validate, props);
core.doSL(index, 'save');
}
export async function saveLoad(
controller: IUIMountable,
loc: ElementLocator,
props?: SaveProps
) {
const validate = (_: number, exist: boolean): SaveValidation => {
return { message: '无效的存档!', valid: exist };
};
const index = await selectSave(controller, loc, validate, props);
core.doSL(index, 'load');
}

View File

@ -21,7 +21,7 @@ import { KeyCode } from '@motajs/client-base';
import { Progress } from '../components/misc';
import { generateBinary } from '@motajs/legacy-common';
import { SetupComponentOptions } from '@motajs/system-ui';
import { SaveUI } from './save';
import { saveSave } from './save';
import { mainUIController } from '@user/client-modules';
import { MAIN_WIDTH, MAIN_HEIGHT } from '../shared';
@ -87,8 +87,8 @@ export const PlayingToolbar = defineComponent<
const book = () => core.openBook(true);
const tool = () => core.openToolbox(true);
const fly = () => core.useFly(true);
const save = async () => {
mainUIController.open(SaveUI, { loc: [0, 0, MAIN_WIDTH, MAIN_HEIGHT] });
const save = () => {
saveSave(mainUIController, [0, 0, MAIN_WIDTH, MAIN_HEIGHT]);
};
const load = () => core.load(true);
const equip = () => core.openEquipbox(true);

View File

@ -610,7 +610,7 @@ interface Control {
/**
*
*/
doSL(id: string, type: SLType): void;
doSL(id: string | number, type: SLType): void;
/**
*