Skip to content

Commit 4c04b0b

Browse files
Merge pull request #763 from xiaoxustudio/feat/textbox-max-text-line
feat: add max_line and max_lineHeight config settings
2 parents b397439 + 0f6fda0 commit 4c04b0b

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

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

Lines changed: 8 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,11 @@ 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 textLineHeight = userDataState.globalGameVar.LineHeight;
193+
const finalTextLineHeight = textLineHeight ? Number(textLineHeight) : lineHeightValue;
194+
const lineHeightCssStr = `line-height: ${finalTextLineHeight}em`;
189195
const lhCss = css(lineHeightCssStr);
190196

191197
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 = Number(userDataState.globalGameVar.Max_line); // congfig定义字体行数
37+
const lineLimit = Number.isNaN(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)