mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-11 07:54:30 +08:00
feat: 换为新存读档界面
This commit is contained in:
1 parent
a7cdf2c69b
commit
84d93422f7
4 files changed
+44
-11
No files matched your search
@@ -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');
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user