Skip to content

Commit 9019e85

Browse files
committed
chore: use local built-in component to show text
1 parent 37e06ab commit 9019e85

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

packages/webgal/src/Core/gameScripts/getUserInput/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { setStageVar } from '@/store/stageReducer';
1515
import { getCurrentFontFamily } from '@/hooks/useFontFamily';
1616
import { logger } from '@/Core/util/logger';
1717
import { tryToRegex } from '@/Core/util/global';
18+
import { showGlogalDialog } from '@/UI/GlobalDialog/GlobalDialog';
1819

1920
/**
2021
* 显示选择枝
@@ -47,7 +48,11 @@ export const getUserInput = (sentence: ISentence): IPerform => {
4748
if (rule) {
4849
const reg = tryToRegex(rule, ruleFlag);
4950
if (reg && !reg.test(userInput.value)) {
50-
if (ruleText) alert(ruleText.replaceAll(/\$0/g, userInput.value));
51+
if (ruleText)
52+
showGlogalDialog({
53+
title: ruleText.replaceAll(/\$0/g, userInput.value),
54+
leftText: 'OK',
55+
});
5156
return;
5257
}
5358
if (!reg) {

packages/webgal/src/UI/GlobalDialog/GlobalDialog.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ export default function GlobalDialog() {
1212

1313
interface IShowGlobalDialogProps {
1414
title: string;
15-
leftText: string;
16-
rightText: string;
17-
leftFunc: Function;
18-
rightFunc: Function;
15+
leftText?: string;
16+
rightText?: string;
17+
leftFunc?: Function;
18+
rightFunc?: Function;
1919
}
2020

2121
export function showGlogalDialog(props: IShowGlobalDialogProps) {
2222
const { playSeClick, playSeEnter } = useSEByWebgalStore();
2323
webgalStore.dispatch(setVisibility({ component: 'showGlobalDialog', visibility: true }));
2424
const handleLeft = () => {
2525
playSeClick();
26-
props.leftFunc();
26+
props.leftFunc?.();
2727
hideGlobalDialog();
2828
};
2929
const handleRight = () => {
3030
playSeClick();
31-
props.rightFunc();
31+
props.rightFunc?.();
3232
hideGlobalDialog();
3333
};
3434
const renderElement = (
@@ -37,12 +37,16 @@ export function showGlogalDialog(props: IShowGlobalDialogProps) {
3737
<div className={styles.glabalDialog_container_inner}>
3838
<div className={styles.title}>{props.title}</div>
3939
<div className={styles.button_list}>
40-
<div className={styles.button} onClick={handleLeft} onMouseEnter={playSeEnter}>
41-
{props.leftText}
42-
</div>
43-
<div className={styles.button} onClick={handleRight} onMouseEnter={playSeEnter}>
44-
{props.rightText}
45-
</div>
40+
{props.leftText && (
41+
<div className={styles.button} onClick={handleLeft} onMouseEnter={playSeEnter}>
42+
{props.leftText}
43+
</div>
44+
)}
45+
{props.rightText && (
46+
<div className={styles.button} onClick={handleRight} onMouseEnter={playSeEnter}>
47+
{props.rightText}
48+
</div>
49+
)}
4650
</div>
4751
</div>
4852
</div>

0 commit comments

Comments
 (0)