mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-06-28 05:07:59 +08:00
feat: selectSave 函数
This commit is contained in:
parent
55c7afd66a
commit
091a1c76e9
@ -1,6 +1,11 @@
|
||||
import { ElementLocator, IWheelEvent } from '@motajs/render-core';
|
||||
import { DefaultProps } from '@motajs/render-vue';
|
||||
import { SetupComponentOptions, UIComponentProps } from '@motajs/system-ui';
|
||||
import {
|
||||
GameUI,
|
||||
IUIMountable,
|
||||
SetupComponentOptions,
|
||||
UIComponentProps
|
||||
} from '@motajs/system-ui';
|
||||
import { defineComponent } from 'vue';
|
||||
import { Page } from '../components';
|
||||
import { useKey } from '../use';
|
||||
@ -12,6 +17,8 @@ export interface SaveProps extends UIComponentProps, DefaultProps {
|
||||
export type SaveEmits = {
|
||||
/** 点击存档时触发 */
|
||||
emit: (index: number) => void;
|
||||
/** 手动点击退出时触发 */
|
||||
exit: () => void;
|
||||
};
|
||||
|
||||
const saveProps = {
|
||||
@ -42,3 +49,43 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
|
||||
},
|
||||
saveProps
|
||||
);
|
||||
|
||||
export const SaveUI = new GameUI('save', Save);
|
||||
|
||||
/**
|
||||
* 打开存读档界面并让用户选择一个存档。如果用户手动关闭了存档界面,返回 -1,否则返回用户选择的存档索引。
|
||||
* 参数参考 {@link SaveProps},事件不可自定义。
|
||||
*
|
||||
* 使用示例:
|
||||
* ```ts
|
||||
* const index = await selectSave(props.controller, [0, 0, 416, 416]);
|
||||
* if (index === -1) {
|
||||
* // 如果用户未选择存档,而是关闭了存档。
|
||||
* } else {
|
||||
* // 用户选择了一个存档。
|
||||
* }
|
||||
* ```
|
||||
* @param controller 在哪个控制器上打开
|
||||
* @param loc 存读档界面的坐标
|
||||
* @param props 传递给存读档界面的参数
|
||||
* @returns
|
||||
*/
|
||||
export function selectSave(
|
||||
controller: IUIMountable,
|
||||
loc: ElementLocator,
|
||||
props?: SaveProps
|
||||
) {
|
||||
return new Promise<number>(res => {
|
||||
const instance = controller.open(SaveUI, {
|
||||
loc,
|
||||
...props,
|
||||
onEmit: index => {
|
||||
controller.close(instance);
|
||||
res(index);
|
||||
},
|
||||
onExit: () => {
|
||||
res(-1);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user