Skip to content

Commit 0ba5ba5

Browse files
committed
WIP Add support waiting for N seconds or frames during text dialogue (currently buggy when using variable width fonts)
1 parent 1810fcb commit 0ba5ba5

File tree

10 files changed

+373
-82
lines changed

10 files changed

+373
-82
lines changed

src/components/forms/TextWaitInputSelect.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import InputPicker from "components/forms/InputPicker";
22
import React, { useEffect, useRef } from "react";
33
import { useCallback } from "react";
4+
import l10n from "shared/lib/lang/l10n";
45
import styled from "styled-components";
5-
import { FormRow } from "ui/form/layout/FormLayout";
6+
import { FormField, FormRow } from "ui/form/layout/FormLayout";
67

78
interface TextWaitInputSelectProps {
89
value: string[];
@@ -59,13 +60,18 @@ export const TextWaitInputSelect = ({
5960
return (
6061
<Form onFocus={onFocus} onBlur={onFocusOut}>
6162
<FormRow>
62-
<InputPicker
63-
id="replaceInput"
64-
value={value}
65-
onChange={onChange}
66-
autoFocus
67-
multiple
68-
/>
63+
<FormField
64+
name="replaceInput"
65+
label={l10n("FIELD_WAIT_UNTIL_BUTTON_PRESSED")}
66+
>
67+
<InputPicker
68+
id="replaceInput"
69+
value={value}
70+
onChange={onChange}
71+
autoFocus
72+
multiple
73+
/>
74+
</FormField>
6975
</FormRow>
7076
</Form>
7177
);
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { UnitSelectLabelButton } from "components/forms/UnitsSelectLabelButton";
2+
import React, { useEffect, useRef } from "react";
3+
import { useCallback } from "react";
4+
import { TimeUnitType } from "shared/lib/entities/entitiesTypes";
5+
import l10n from "shared/lib/lang/l10n";
6+
import { ensureNumber } from "shared/types";
7+
import styled from "styled-components";
8+
import { FormField, FormRow } from "ui/form/layout/FormLayout";
9+
import { NumberInput } from "ui/form/NumberInput";
10+
11+
interface TextWaitTimeSelectProps {
12+
value: number;
13+
units: "frames" | "time";
14+
onChange: (newValue: number) => void;
15+
onChangeUnits: (newUnits: "frames" | "time") => void;
16+
onBlur: () => void;
17+
}
18+
19+
const Form = styled.form`
20+
min-width: 200px;
21+
padding-top: 5px;
22+
`;
23+
24+
export const TextWaitTimeSelect = ({
25+
value,
26+
units,
27+
onChange,
28+
onChangeUnits,
29+
onBlur,
30+
}: TextWaitTimeSelectProps) => {
31+
const timerRef = useRef<ReturnType<typeof setTimeout>>();
32+
33+
const debouncedLeave = useCallback(() => {
34+
if (timerRef.current) {
35+
clearTimeout(timerRef.current);
36+
}
37+
timerRef.current = setTimeout(() => {
38+
onBlur();
39+
}, 250);
40+
}, [onBlur]);
41+
42+
useEffect(() => {
43+
return () => {
44+
// Cleanup timer
45+
if (timerRef.current) {
46+
clearTimeout(timerRef.current);
47+
}
48+
};
49+
}, []);
50+
51+
const onFocus = useCallback(() => {
52+
if (timerRef.current) {
53+
clearTimeout(timerRef.current);
54+
}
55+
}, []);
56+
57+
const onFocusOut = useCallback(
58+
(event: React.FocusEvent<HTMLFormElement, Element>) => {
59+
if (event.currentTarget.contains(event.relatedTarget)) {
60+
return;
61+
}
62+
debouncedLeave();
63+
},
64+
[debouncedLeave]
65+
);
66+
67+
return (
68+
<Form onFocus={onFocus} onBlur={onFocusOut}>
69+
<FormRow>
70+
<FormField
71+
name="replaceWaitTime"
72+
label={
73+
<>
74+
{l10n("EVENT_WAIT")}
75+
<UnitSelectLabelButton
76+
value={units}
77+
allowedValues={["time", "frames"]}
78+
onChange={(value) => {
79+
onChangeUnits(value as TimeUnitType);
80+
}}
81+
/>
82+
</>
83+
}
84+
>
85+
<NumberInput
86+
id="replaceWaitTime"
87+
value={value}
88+
onChange={(e) => {
89+
const value = ensureNumber(parseFloat(e.currentTarget.value), 0);
90+
onChange(value);
91+
}}
92+
autoFocus
93+
/>
94+
</FormField>
95+
</FormRow>
96+
</Form>
97+
);
98+
};

src/components/forms/UnitsSelectLabelButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const UnitSelectLabelButton = ({
7070
showArrow={false}
7171
size="small"
7272
variant="transparent"
73+
type="button"
7374
>
7475
{allValues.map((item) => (
7576
<MenuItem
@@ -82,7 +83,7 @@ export const UnitSelectLabelButton = ({
8283
))}
8384
</DropdownButton>
8485
) : (
85-
<Button size="small" variant="transparent">
86+
<Button size="small" variant="transparent" type="button">
8687
{currentValue}
8788
</Button>
8889
)}

src/components/script/ScriptEditorEventHelper.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const ScriptEditorEventHelper: FC<ScriptEditorEventHelperProps> = ({
9494
0
9595
);
9696
return (
97-
<RelativePortal offsetX={-10} offsetY={10} pin="top-right">
97+
<RelativePortal offsetX={-10} offsetY={10} pin="top-right" zIndex={-1}>
9898
<PreviewWrapper>
9999
{Array.isArray(text) ? (
100100
text.map((text: string, index) => (
@@ -146,7 +146,7 @@ export const ScriptEditorEventHelper: FC<ScriptEditorEventHelperProps> = ({
146146
0
147147
);
148148
return (
149-
<RelativePortal offsetX={-10} offsetY={10} pin="top-right">
149+
<RelativePortal offsetX={-10} offsetY={10} pin="top-right" zIndex={-1}>
150150
<PreviewWrapper>
151151
<DialoguePreview
152152
text={text}
@@ -175,7 +175,7 @@ export const ScriptEditorEventHelper: FC<ScriptEditorEventHelperProps> = ({
175175
].splice(0, toInt(event.args?.items));
176176

177177
return (
178-
<RelativePortal offsetX={-10} offsetY={10} pin="top-right">
178+
<RelativePortal offsetX={-10} offsetY={10} pin="top-right" zIndex={-1}>
179179
<MenuPreview
180180
items={items}
181181
layout={event.args?.layout === "dialogue" ? "dialogue" : "menu"}
@@ -191,7 +191,7 @@ export const ScriptEditorEventHelper: FC<ScriptEditorEventHelperProps> = ({
191191
];
192192

193193
return (
194-
<RelativePortal offsetX={-10} offsetY={10} pin="top-right">
194+
<RelativePortal offsetX={-10} offsetY={10} pin="top-right" zIndex={-1}>
195195
<MenuPreview items={items} layout="dialogue" />
196196
</RelativePortal>
197197
);

src/components/ui/buttons/DropdownButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ export const DropdownButton: FC<DropdownButtonProps & ButtonProps> = React.memo(
533533
tabIndex={0}
534534
ref={buttonRef}
535535
role={"button"}
536+
type="button"
536537
aria-haspopup={true}
537538
aria-expanded={isOpen}
538539
onMouseDown={onMouseDown}

0 commit comments

Comments
 (0)