mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-06-28 13:17:59 +08:00
feat: 换为新存读档界面
This commit is contained in:
parent
a7cdf2c69b
commit
84d93422f7
@ -3,7 +3,7 @@ import { gameKey, HotkeyJSON } from '@motajs/system-action';
|
|||||||
import { hovered, mainUi, tip, openDanmakuPoster } from '@motajs/legacy-ui';
|
import { hovered, mainUi, tip, openDanmakuPoster } from '@motajs/legacy-ui';
|
||||||
import { GameStorage } from '@motajs/legacy-system';
|
import { GameStorage } from '@motajs/legacy-system';
|
||||||
import { openStatistics } from '../render/ui/statistics';
|
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');
|
export const mainScope = Symbol.for('@key_main');
|
||||||
|
|
||||||
@ -488,7 +488,7 @@ gameKey
|
|||||||
core.openBook(true);
|
core.openBook(true);
|
||||||
})
|
})
|
||||||
.realize('save', () => {
|
.realize('save', () => {
|
||||||
core.save(true);
|
saveSave(mainUIController, [0, 0, MAIN_WIDTH, MAIN_HEIGHT]);
|
||||||
})
|
})
|
||||||
.realize('load', () => {
|
.realize('load', () => {
|
||||||
core.load(true);
|
core.load(true);
|
||||||
|
@ -25,9 +25,9 @@ export interface SaveBtnProps extends DefaultProps {
|
|||||||
|
|
||||||
export type SaveEmits = {
|
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;
|
exit: () => void;
|
||||||
};
|
};
|
||||||
@ -289,6 +289,11 @@ export interface SaveValidation {
|
|||||||
readonly message: string;
|
readonly message: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type SaveValidationFunction = (
|
||||||
|
index: number,
|
||||||
|
exist: boolean
|
||||||
|
) => SaveValidation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打开存读档界面并让用户选择一个存档。如果用户手动关闭了存档界面,返回 -2,否则返回用户选择的存档索引。
|
* 打开存读档界面并让用户选择一个存档。如果用户手动关闭了存档界面,返回 -2,否则返回用户选择的存档索引。
|
||||||
* 参数参考 {@link SaveProps},事件不可自定义。
|
* 参数参考 {@link SaveProps},事件不可自定义。
|
||||||
@ -312,20 +317,20 @@ export interface SaveValidation {
|
|||||||
export function selectSave(
|
export function selectSave(
|
||||||
controller: IUIMountable,
|
controller: IUIMountable,
|
||||||
loc: ElementLocator,
|
loc: ElementLocator,
|
||||||
validate?: (index: number) => SaveValidation,
|
validate?: SaveValidationFunction,
|
||||||
props?: SaveProps
|
props?: SaveProps
|
||||||
) {
|
) {
|
||||||
return new Promise<number>(res => {
|
return new Promise<number>(res => {
|
||||||
const instance = controller.open(SaveUI, {
|
const instance = controller.open(SaveUI, {
|
||||||
loc,
|
loc,
|
||||||
...props,
|
...props,
|
||||||
onEmit: (index: number) => {
|
onEmit: (index: number, exist: boolean) => {
|
||||||
if (!validate) {
|
if (!validate) {
|
||||||
controller.close(instance);
|
controller.close(instance);
|
||||||
res(index);
|
res(index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const validation = validate(index);
|
const validation = validate(index, exist);
|
||||||
if (validation.valid) {
|
if (validation.valid) {
|
||||||
controller.close(instance);
|
controller.close(instance);
|
||||||
res(index);
|
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 { Progress } from '../components/misc';
|
||||||
import { generateBinary } from '@motajs/legacy-common';
|
import { generateBinary } from '@motajs/legacy-common';
|
||||||
import { SetupComponentOptions } from '@motajs/system-ui';
|
import { SetupComponentOptions } from '@motajs/system-ui';
|
||||||
import { SaveUI } from './save';
|
import { saveSave } from './save';
|
||||||
import { mainUIController } from '@user/client-modules';
|
import { mainUIController } from '@user/client-modules';
|
||||||
import { MAIN_WIDTH, MAIN_HEIGHT } from '../shared';
|
import { MAIN_WIDTH, MAIN_HEIGHT } from '../shared';
|
||||||
|
|
||||||
@ -87,8 +87,8 @@ export const PlayingToolbar = defineComponent<
|
|||||||
const book = () => core.openBook(true);
|
const book = () => core.openBook(true);
|
||||||
const tool = () => core.openToolbox(true);
|
const tool = () => core.openToolbox(true);
|
||||||
const fly = () => core.useFly(true);
|
const fly = () => core.useFly(true);
|
||||||
const save = async () => {
|
const save = () => {
|
||||||
mainUIController.open(SaveUI, { loc: [0, 0, MAIN_WIDTH, MAIN_HEIGHT] });
|
saveSave(mainUIController, [0, 0, MAIN_WIDTH, MAIN_HEIGHT]);
|
||||||
};
|
};
|
||||||
const load = () => core.load(true);
|
const load = () => core.load(true);
|
||||||
const equip = () => core.openEquipbox(true);
|
const equip = () => core.openEquipbox(true);
|
||||||
|
2
src/types/declaration/control.d.ts
vendored
2
src/types/declaration/control.d.ts
vendored
@ -610,7 +610,7 @@ interface Control {
|
|||||||
/**
|
/**
|
||||||
* 实际进行存读档事件
|
* 实际进行存读档事件
|
||||||
*/
|
*/
|
||||||
doSL(id: string, type: SLType): void;
|
doSL(id: string | number, type: SLType): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步存档到服务器
|
* 同步存档到服务器
|
||||||
|
Loading…
Reference in New Issue
Block a user