Skip to content

Commit e43a938

Browse files
committed
Update dialog preview to 1.21.6-pre1
1 parent 624d479 commit e43a938

File tree

3 files changed

+27
-39
lines changed

3 files changed

+27
-39
lines changed

spyglass.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"env": {
3+
"dependencies": [
4+
"@vanilla-mcdoc"
5+
],
6+
"exclude": [
7+
".*/**",
8+
"**/node_modules/**",
9+
"**/dist/**"
10+
]
11+
}
12+
}

src/app/components/previews/DialogPreview.tsx

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const DialogPreview = ({ docAndNode }: PreviewProps) => {
1212
const text = docAndNode.doc.getText()
1313
const dialog = safeJsonParse(text) ?? {}
1414
const type = dialog.type?.replace(/^minecraft:/, '')
15-
const footerHeight = type === 'multi_action_input_form' ? 5 : 33
15+
const footerHeight = (type === 'dialog_list' || type == 'multi_action' || type == 'server_links') && dialog.exit_action == undefined ? 5 : 33
1616

1717
useEffect(() => {
1818
function resizeHandler() {
@@ -30,9 +30,10 @@ export const DialogPreview = ({ docAndNode }: PreviewProps) => {
3030
<img src="/images/dialog/background.webp" alt="" draggable={false} />
3131
<div style={'top: 0; left: 0; width: 100%; height: 100%;'}>
3232
<DialogTitle title={dialog.title} />
33-
<div style={`display: flex; flex-direction: column; gap: ${px(10)}; align-items: center; padding-right: ${px(10)} /* MC-297972 */; overflow-y: auto; height: calc(100% - ${px(33 + footerHeight)})`}>
33+
<div style={`display: flex; flex-direction: column; gap: ${px(10)}; align-items: center; overflow-y: auto; height: calc(100% - ${px(33 + footerHeight)})`}>
3434
<DialogBody body={dialog.body} />
35-
<DialogContent dialog={dialog} />
35+
<DialogInputs inputs={dialog.inputs} />
36+
<DialogActions dialog={dialog} />
3637
</div>
3738
<div style={`bottom: 0; left: 0; width: 100%; height: ${px(footerHeight)}; display: flex; justify-content: center; align-items: center;`}>
3839
<DialogFooter dialog={dialog} />
@@ -43,7 +44,6 @@ export const DialogPreview = ({ docAndNode }: PreviewProps) => {
4344
}
4445

4546
function DialogTitle({ title }: { title: any }) {
46-
// TODO: add warning button tooltip
4747
return <div style={`height: ${px(33)}; display: flex; gap: ${px(10)}; justify-content: center; align-items: center`}>
4848
<TextComponent component={title} />
4949
<WithTooltip tooltip="This is a custom screen. Click here to learn more.">
@@ -85,7 +85,13 @@ function DialogBody({ body }: { body: any }) {
8585
</>
8686
}
8787

88-
function DialogContent({ dialog }: { dialog: any }) {
88+
function DialogInputs({ inputs }: { inputs: any[] | undefined }) {
89+
return <>
90+
{inputs?.map((i: any) => <InputControl input={i} />)}
91+
</>
92+
}
93+
94+
function DialogActions({ dialog }: { dialog: any }) {
8995
const type = dialog.type?.replace(/^minecraft:/, '')
9096

9197
if (type === 'dialog_list') {
@@ -116,17 +122,6 @@ function DialogContent({ dialog }: { dialog: any }) {
116122
</ColumnsGrid>
117123
}
118124

119-
if (type === 'multi_action_input_form') {
120-
return <>
121-
{dialog.inputs?.map((i: any) => <InputControl input={i} />)}
122-
<ColumnsGrid columns={dialog.columns ?? 2}>
123-
{dialog.actions?.map((a: any) =>
124-
<Button label={a.label} width={a.width ?? 150} tooltip={a.tooltip} />
125-
) ?? []}
126-
</ColumnsGrid>
127-
</>
128-
}
129-
130125
if (type === 'server_links') {
131126
const links = ['Server link 1', 'Server link 2', 'Server link 3']
132127
return <ColumnsGrid columns={dialog.columns ?? 2}>
@@ -136,12 +131,6 @@ function DialogContent({ dialog }: { dialog: any }) {
136131
</ColumnsGrid>
137132
}
138133

139-
if (type === 'simple_input_form') {
140-
return <>
141-
{dialog.inputs?.map((i: any) => <InputControl input={i} />)}
142-
</>
143-
}
144-
145134
return <></>
146135
}
147136

@@ -155,12 +144,8 @@ function DialogFooter({ dialog }: { dialog: any }) {
155144
</div>
156145
}
157146

158-
if (type === 'dialog_list') {
159-
return <Button label={{translate: dialog.on_cancel ? 'gui.cancel' : 'gui.back'}} width={200} />
160-
}
161-
162-
if (type === 'multi_action') {
163-
return <Button label={{translate: dialog.on_cancel ? 'gui.cancel' : 'gui.back'}} width={200} />
147+
if ((type === 'dialog_list' || type == 'multi_action' || type == 'server_links') && dialog.exit_action) {
148+
return <Button label={dialog.exit_action.label} width={200} />
164149
}
165150

166151
if (type === 'notice') {
@@ -169,16 +154,6 @@ function DialogFooter({ dialog }: { dialog: any }) {
169154
</div>
170155
}
171156

172-
if (type === 'server_links') {
173-
return <Button label={{translate: dialog.on_cancel ? 'gui.cancel' : 'gui.back'}} width={200} />
174-
}
175-
176-
if (type === 'simple_input_form') {
177-
return <div style={`display: flex; gap: ${px(8)}; justify-content: center;`}>
178-
<Button label={dialog.action?.label} width={dialog.action?.width ?? 150} tooltip={dialog.action?.tooltip} />
179-
</div>
180-
}
181-
182157
return <></>
183158
}
184159

src/styles/global.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,8 @@ hr {
19411941
border-image-slice: 1 fill;
19421942
border-image-repeat: repeat;
19431943
display: flex;
1944-
align-items: center;
1944+
align-items: flex-start;
1945+
padding-top: calc(var(--dialog-px) * 4);
19451946
padding-left: calc(var(--dialog-px) * 4);
19461947
}
19471948

0 commit comments

Comments
 (0)