You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
import { Node, sys, UITransform, Widget } from 'cc';
|
|
import { UILayer } from '../../mx/module/ui/UIManager';
|
|
import type { IGmHost } from '../../mx/module/gm';
|
|
import { sdkConfig } from '../sdk/sdkConfig';
|
|
|
|
/**
|
|
* 本项目 GM 宿主:toast / 存档 / Debug 层挂载。
|
|
*/
|
|
export class ProjectGmHost implements IGmHost {
|
|
/** @inheritdoc */
|
|
toast(msg: string): void {
|
|
gg.ui.showToast(msg);
|
|
}
|
|
|
|
/** @inheritdoc */
|
|
saveLocal(): void {
|
|
gg.data.saveLocal();
|
|
}
|
|
|
|
/** @inheritdoc */
|
|
saveServer(): void {
|
|
gg.data.saveToServer();
|
|
}
|
|
|
|
/** @inheritdoc */
|
|
isEnabled(): boolean {
|
|
return sys.isBrowser || sdkConfig.isOpenGM;
|
|
}
|
|
|
|
/** @inheritdoc */
|
|
attachOverlay(node: Node): void {
|
|
gg.ui.showNode(node, UILayer.DeBug);
|
|
const parent = node.parent;
|
|
const put = parent?.getComponent(UITransform);
|
|
if (put && put.width > 1 && put.height > 1) {
|
|
node.getComponent(UITransform)?.setContentSize(put.width, put.height);
|
|
} else {
|
|
node.getComponent(UITransform)?.setContentSize(gg.ui.width, gg.ui.height);
|
|
}
|
|
const w = node.getComponent(Widget);
|
|
if (w) {
|
|
w.left = w.right = w.top = w.bottom = 0;
|
|
w.updateAlignment();
|
|
}
|
|
node.setSiblingIndex(-1);
|
|
}
|
|
}
|
|
|