Skip to content

Commit 7fbb973

Browse files
Merge pull request #675 from xiaoxustudio/feat-getUserInput-default-value
feat: getUserinput add default value
2 parents 44ff93d + 5040394 commit 7fbb973

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/webgal/public/game/scene/demo_zh_cn.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ WebGAL:新版本添加了特性:获取用户输入,你要尝试一下吗?
3030
choose:尝试一下:userInput|算了吧:toNextPart;
3131

3232
label:userInput;
33-
getUserInput:name -title=如何称呼你 -buttonText=确认;
33+
getUserInput:name -title=如何称呼你 -buttonText=确认 -defaultValue=WebGALPlayer;
3434
WebGAL:很高兴遇见你,{name}!
3535
jumpLabel:toNextPart;
3636

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const getUserInput = (sentence: ISentence): IPerform => {
2424
const title = (titleFromArgs === 0 ? 'Please Input' : titleFromArgs) ?? 'Please Input';
2525
const buttonTextFromArgs = getSentenceArgByKey(sentence, 'buttonText');
2626
const buttonText = (buttonTextFromArgs === 0 ? 'OK' : buttonTextFromArgs) ?? 'OK';
27+
const defaultValueFromArgs = getSentenceArgByKey(sentence, 'defaultValue');
2728
const fontFamily = webgalStore.getState().userData.optionData.textboxFont;
2829
const font = fontFamily === textFont.song ? '"思源宋体", serif' : '"WebgalUI", serif';
2930
const { playSeEnter, playSeClick } = useSEByWebgalStore();
@@ -38,7 +39,10 @@ export const getUserInput = (sentence: ISentence): IPerform => {
3839
const userInput: HTMLInputElement = document.getElementById('user-input') as HTMLInputElement;
3940
if (userInput) {
4041
webgalStore.dispatch(
41-
setStageVar({ key: varKey, value: (userInput?.value ?? '') === '' ? ' ' : userInput?.value ?? '' }),
42+
setStageVar({
43+
key: varKey,
44+
value: userInput?.value || defaultValueFromArgs || ' ',
45+
}),
4246
);
4347
}
4448
playSeClick();

0 commit comments

Comments
 (0)