Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit a5a8173

Browse files
Fixes alerts and skillmenu
1 parent b30262a commit a5a8173

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

tgui/packages/tgui/interfaces/AlertModal.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,39 @@ export class AlertModal extends Component {
6767
const { current } = this.state;
6868
const focusCurrentButton = () => this.setCurrent(current, false);
6969

70+
// Stolen wholesale from fontcode
71+
const textWidth = (text, font, fontsize) => {
72+
// default font height is 12 in tgui
73+
font = fontsize + 'x ' + font;
74+
const c = document.createElement('canvas');
75+
const ctx = c.getContext('2d');
76+
ctx.font = font;
77+
return ctx.measureText(text).width;
78+
};
79+
80+
// At least one of the buttons has a long text message
81+
const isVerbose = buttons.some(
82+
(button) =>
83+
textWidth(button, '', 12) >
84+
windowWidth / buttons.length - paddingMagicNumber,
85+
);
86+
87+
const windowWidth = 345 + (buttons.length > 2 ? 55 : 0);
88+
89+
// very accurate estimate of padding for each num of buttons
90+
const paddingMagicNumber = 67 / buttons.length + 23;
91+
92+
// Dynamically sets window dimensions
93+
const windowHeight =
94+
120 +
95+
(isVerbose ? 15 * buttons.length : 0) +
96+
(message.length > 30 ? Math.ceil(message.length / 4) : 0);
97+
7098
return (
7199
<Window
72100
title={title}
73-
width={350}
74-
height={150}>
101+
width={windowWidth}
102+
height={windowHeight}>
75103
{timeout && <Loader value={timeout} />}
76104
<Window.Content
77105
onFocus={focusCurrentButton}

tgui/packages/tgui/interfaces/SkillMenu.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export const SkillMenu = (props, context) => {
1010
return (
1111
<Window
1212
title="Skills"
13-
width={320}
14-
height={262}
13+
width={225}
14+
height={345}
1515
>
1616
<Window.Content>
1717
<Section title={"Points Available: " + (skill_points - allocated_points)}>
@@ -88,7 +88,7 @@ const AdjustSkill = (props, context) => {
8888
className={classes(['crafting32x32', skill.replace(/ /g, '')])}
8989
/>
9090
<LabeledList.Item label={name}>
91-
<Box textAlign="right" ml={-5} mr={40}>
91+
<Box textAlign="right">
9292
<Tooltip content={tooltip}>
9393
<Icon name="question-circle" width="12px" mr="6px" />
9494
</Tooltip>

0 commit comments

Comments
 (0)