Skip to content

Commit 60d62cf

Browse files
committed
feat: add max_line and max_lineHeight config settings
1 parent e1d6ca9 commit 60d62cf

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

packages/webgal/public/game/config.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ Title_img:WebGAL_New_Enter_Image.webp;
44
Title_bgm:s_Title.mp3;
55
Game_Logo:WebGalEnter.webp;
66
Enable_Appreciation:true;
7+
Max_line:4;
8+
Max_lineHeight:0.25;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
WebGAL:我是第一行文本|我是第二行哈哈|第三行在这里|第四行是这个内容;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
setVar:heroine=WebGAL;
22
setVar:egine=WebGAL;
3-
choose:简体中文:demo_zh_cn.txt|日本語:demo_ja.txt|English:demo_en.txt|Test:function_test.txt;
3+
choose:多行测试:demo_max_line_test.txt|简体中文:demo_zh_cn.txt|日本語:demo_ja.txt|English:demo_en.txt|Test:function_test.txt;

packages/webgal/src/Stage/TextBox/IMSSTextbox.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import styles from './textbox.module.scss';
2-
import { ReactNode, useEffect } from 'react';
2+
import { useEffect } from 'react';
33
import { WebGAL } from '@/Core/WebGAL';
44
import { ITextboxProps } from './types';
55
import useApplyStyle from '@/hooks/useApplyStyle';
66
import { css } from '@emotion/css';
77
import { textSize } from '@/store/userDataInterface';
8+
import { useSelector } from 'react-redux';
9+
import { RootState } from '@/store/store';
810

911
export default function IMSSTextbox(props: ITextboxProps) {
1012
const {
@@ -185,7 +187,15 @@ export default function IMSSTextbox(props: ITextboxProps) {
185187
);
186188
});
187189

188-
const lineHeightCssStr = `line-height: ${textSizeState === textSize.medium ? '2.2em' : '2em'}`;
190+
const userDataState = useSelector((state: RootState) => state.userData);
191+
const lineHeightValue = textSizeState === textSize.medium ? 2.2 : 2;
192+
const MaxTextLine = userDataState.globalGameVar.Max_line as number; // config定义字体行数
193+
const MaxTextLineHeight = userDataState.globalGameVar.Max_lineHeight as number; // config 定义字体行数高度
194+
const totalHeight = !Number.isNaN(Number(MaxTextLine))
195+
? (Number.isNaN(Number(MaxTextLineHeight)) ? lineHeightValue : MaxTextLineHeight) * MaxTextLine
196+
: lineHeightValue; // Max_LineHeight和Max_Line必定为数字,否则使用默认值
197+
198+
const lineHeightCssStr = `line-height: ${totalHeight}em`;
189199
const lhCss = css(lineHeightCssStr);
190200

191201
return (

packages/webgal/src/Stage/TextBox/TextBox.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ export const TextBox = () => {
3333
size = getTextSize(stageState.showTextSize) + '%';
3434
textSizeState = stageState.showTextSize;
3535
}
36-
const lineLimit = match(textSizeState)
37-
.with(textSize.small, () => 3)
38-
.with(textSize.medium, () => 2)
39-
.with(textSize.large, () => 2)
40-
.default(() => 2);
36+
const MaxTextLine = userDataState.globalGameVar.Max_line as number; // congfig定义字体行数
37+
const lineLimit = Number.isNaN(Number(MaxTextLine))
38+
? match(textSizeState)
39+
.with(textSize.small, () => 3)
40+
.with(textSize.medium, () => 2)
41+
.with(textSize.large, () => 2)
42+
.default(() => 2)
43+
: MaxTextLine;
4144
// 拆字
4245
const textArray = compileSentence(stageState.showText, lineLimit);
4346
const isHasName = stageState.showName !== '';

0 commit comments

Comments
 (0)