Skip to content

Commit 58a0488

Browse files
committed
feat(bottom-bar): styling for round time and cast time counters
1 parent dce7ead commit 58a0488

File tree

1 file changed

+72
-67
lines changed

1 file changed

+72
-67
lines changed

electron/renderer/components/game/game-roundtime.tsx

+72-67
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,11 @@
1-
import { useEuiTheme } from '@elastic/eui';
1+
import { EuiToolTip, useEuiTheme } from '@elastic/eui';
2+
import type { ReactNode } from 'react';
23
import { useCallback, useEffect, useRef, useState } from 'react';
34
import type { GameEvent } from '../../../common/game/types.js';
45
import { GameEventType } from '../../../common/game/types.js';
56
import { useSubscribe } from '../../hooks/pubsub.jsx';
67

7-
interface GameTimeDisplayProps {
8-
currentTime: number;
9-
initialTime: number;
10-
fillColor: string;
11-
textColor: string;
12-
type: 'RoundTime' | 'CastTime';
13-
}
14-
15-
const GameTimeDisplay: React.FC<GameTimeDisplayProps> = (
16-
options: GameTimeDisplayProps
17-
) => {
18-
const { currentTime, initialTime, type } = options;
19-
20-
const { euiTheme } = useEuiTheme();
21-
22-
const typeAbbrev = type === 'RoundTime' ? 'RT' : 'CT';
23-
const typeLabel = type === 'RoundTime' ? 'Round Time' : 'Cast Time';
24-
25-
const fillColor = currentTime > 0 ? options.fillColor : 'inherit';
26-
const textColor = currentTime > 0 ? options.textColor : 'inherit';
27-
28-
const fillWidth = (currentTime / initialTime) * 100 || 0;
29-
30-
return (
31-
<div
32-
style={{
33-
position: 'relative',
34-
width: '100%',
35-
height: '25px',
36-
margin: 0,
37-
padding: 0,
38-
border: '1px solid',
39-
borderRadius: '5px',
40-
borderColor: euiTheme.border.color,
41-
}}
42-
>
43-
<div
44-
style={{
45-
position: 'absolute',
46-
left: 0,
47-
width: `${fillWidth}%`,
48-
height: '100%',
49-
backgroundColor: fillColor,
50-
}}
51-
/>
52-
<div
53-
style={{
54-
position: 'absolute',
55-
width: '100%',
56-
height: '100%',
57-
textAlign: 'center',
58-
lineHeight: euiTheme.size.l,
59-
fontSize: euiTheme.size.m,
60-
color: textColor,
61-
}}
62-
>
63-
{currentTime > 0 && currentTime}
64-
{currentTime <= 0 && <span title={typeLabel}>{typeAbbrev}</span>}
65-
</div>
66-
</div>
67-
);
68-
};
69-
70-
GameTimeDisplay.displayName = 'GameTimeDisplay';
71-
72-
export const GameRoundTime: React.FC = () => {
8+
export const GameRoundTime: React.FC = (): ReactNode => {
739
const { euiTheme } = useEuiTheme();
7410

7511
const nowInSeconds = useCallback(() => {
@@ -141,8 +77,11 @@ export const GameRoundTime: React.FC = () => {
14177
style={{
14278
display: 'flex',
14379
flexDirection: 'column',
80+
alignContent: 'center',
81+
justifyContent: 'center',
14482
gap: '5px',
14583
width: '50px',
84+
margin: '5px',
14685
}}
14786
>
14887
<GameTimeDisplay
@@ -164,3 +103,69 @@ export const GameRoundTime: React.FC = () => {
164103
};
165104

166105
GameRoundTime.displayName = 'GameRoundTime';
106+
107+
interface GameTimeDisplayProps {
108+
currentTime: number;
109+
initialTime: number;
110+
fillColor: string;
111+
textColor: string;
112+
type: 'RoundTime' | 'CastTime';
113+
}
114+
115+
const GameTimeDisplay: React.FC<GameTimeDisplayProps> = (
116+
options: GameTimeDisplayProps
117+
): ReactNode => {
118+
const { currentTime, initialTime, type } = options;
119+
120+
const { euiTheme } = useEuiTheme();
121+
122+
const typeAbbrev = type === 'RoundTime' ? 'RT' : 'CT';
123+
const typeTooltip = type === 'RoundTime' ? 'Round Time' : 'Cast Time';
124+
125+
const fillColor = currentTime > 0 ? options.fillColor : 'inherit';
126+
const textColor = currentTime > 0 ? options.textColor : 'inherit';
127+
128+
const fillWidth = (currentTime / initialTime) * 100 || 0;
129+
130+
return (
131+
<EuiToolTip content={typeTooltip} position="top">
132+
<div
133+
style={{
134+
position: 'relative',
135+
width: '100%',
136+
height: '25px',
137+
border: '1px solid',
138+
borderColor: euiTheme.border.color,
139+
borderRadius: '5px',
140+
userSelect: 'none',
141+
}}
142+
>
143+
<div
144+
style={{
145+
position: 'absolute',
146+
left: 0,
147+
width: `${fillWidth}%`,
148+
height: '100%',
149+
backgroundColor: fillColor,
150+
}}
151+
/>
152+
<div
153+
style={{
154+
position: 'absolute',
155+
width: '100%',
156+
height: '100%',
157+
textAlign: 'center',
158+
lineHeight: euiTheme.size.l,
159+
fontSize: euiTheme.size.m,
160+
color: textColor,
161+
}}
162+
>
163+
{currentTime > 0 && currentTime}
164+
{currentTime <= 0 && typeAbbrev}
165+
</div>
166+
</div>
167+
</EuiToolTip>
168+
);
169+
};
170+
171+
GameTimeDisplay.displayName = 'GameTimeDisplay';

0 commit comments

Comments
 (0)