19
19
20
20
import com .viaversion .nbt .tag .CompoundTag ;
21
21
import com .viaversion .nbt .tag .Tag ;
22
+ import com .viaversion .viabackwards .ViaBackwards ;
23
+ import com .viaversion .viabackwards .api .DialogStyleConfig ;
22
24
import com .viaversion .viabackwards .protocol .v1_21_6to1_21_5 .Protocol1_21_6To1_21_5 ;
23
25
import com .viaversion .viabackwards .protocol .v1_21_6to1_21_5 .data .Button ;
24
26
import com .viaversion .viabackwards .protocol .v1_21_6to1_21_5 .data .Dialog ;
52
54
import org .checkerframework .checker .nullness .qual .Nullable ;
53
55
54
56
import static com .viaversion .viabackwards .utils .ChatUtil .fixStyle ;
55
- import static com .viaversion .viabackwards .utils .ChatUtil .text ;
56
57
import static com .viaversion .viabackwards .utils .ChatUtil .translate ;
57
58
58
59
/**
@@ -225,12 +226,14 @@ public void updateDialog(final UserConnection connection, final Dialog dialog) {
225
226
}
226
227
227
228
protected Item createPageNavigationItem () {
229
+ final DialogStyleConfig config = ViaBackwards .getConfig ().dialogStyleConfig ();
230
+
228
231
return createItem (
229
232
"minecraft:arrow" ,
230
- text ( "§9§lPage navigation" ),
233
+ translate ( config . pageNavigationTitle () ),
231
234
232
- "§9Left click: §6Go to next page" ,
233
- "§9Right click: §6Go to previous page"
235
+ config . pageNavigationNext () ,
236
+ config . pageNavigationPrevious ()
234
237
);
235
238
}
236
239
@@ -251,7 +254,7 @@ protected Item getItemWidget(final UserConnection connection, final ItemWidget i
251
254
final String identifier = itemWidget .item ().getString ("id" );
252
255
final int count = itemWidget .item ().getInt ("count" , 1 );
253
256
254
- final Tag label = text (Key .stripMinecraftNamespace (identifier ));
257
+ final Tag label = translate (Key .stripMinecraftNamespace (identifier ));
255
258
final Item item = createItem (identifier , label );
256
259
item .setAmount (count );
257
260
if (itemWidget .description () != null ) {
@@ -282,6 +285,8 @@ protected Item getMultiTextWidget(final UserConnection connection, final MultiTe
282
285
}
283
286
284
287
protected Item getBooleanInput (final UserConnection connection , final BooleanInput booleanInput ) {
288
+ final DialogStyleConfig config = ViaBackwards .getConfig ().dialogStyleConfig ();
289
+
285
290
final String item = booleanInput .value () ? "minecraft:lime_dye" : "minecraft:gray_dye" ;
286
291
final Tag [] label = ChatUtil .split (booleanInput .label (), "\n " );
287
292
@@ -290,14 +295,14 @@ protected Item getBooleanInput(final UserConnection connection, final BooleanInp
290
295
return createItem (
291
296
item ,
292
297
handleTag (connection , booleanInput .label ()),
293
- text ( "§9Left click: §6Toggle value" )
298
+ translate ( config . toggleValue () )
294
299
);
295
300
} else {
296
301
final Tag [] lore = new Tag [label .length ];
297
302
for (int i = 1 ; i < label .length ; i ++) {
298
303
lore [i - 1 ] = handleTag (connection , fixStyle (label [i ]));
299
304
}
300
- lore [lore .length - 1 ] = text ( "§9Left click: §6Toggle value" );
305
+ lore [lore .length - 1 ] = translate ( config . toggleValue () );
301
306
return createItem (
302
307
item ,
303
308
handleTag (connection , label [0 ]),
@@ -311,14 +316,16 @@ protected void clickBooleanInput(final BooleanInput booleanInput) {
311
316
}
312
317
313
318
protected Item getNumberRangeInput (final UserConnection connection , final NumberRangeInput numberRangeInput ) {
319
+ final DialogStyleConfig config = ViaBackwards .getConfig ().dialogStyleConfig ();
320
+
314
321
final Tag label = handleTag (connection , numberRangeInput .displayName ());
315
322
return createItem (
316
323
"minecraft:clock" ,
317
324
label ,
318
325
319
- "§9Left click: §6Increase value by " + numberRangeInput .step (),
320
- "§9Right click: §6Decrease value by " + numberRangeInput .step (),
321
- "§7(Value between §a" + numberRangeInput .start () + " §7and §a" + numberRangeInput .end () + "§7)"
326
+ String . format ( config . increaseValue (), numberRangeInput .step () ),
327
+ String . format ( config . decreaseValue (), numberRangeInput .step () ),
328
+ String . format ( config . valueRange (), numberRangeInput .start (), numberRangeInput .end ())
322
329
);
323
330
}
324
331
@@ -333,21 +340,25 @@ protected void clickNumberRangeInput(final NumberRangeInput numberRangeInput, fi
333
340
}
334
341
335
342
protected Item getTextInput (final UserConnection connection , final TextInput textInput ) {
336
- final Tag currentValue = text ("§7Current value: §a" + textInput .value ());
343
+ final DialogStyleConfig config = ViaBackwards .getConfig ().dialogStyleConfig ();
344
+
345
+ final Tag currentValue = translate (String .format (config .currentValue (), textInput .value ()));
337
346
if (textInput .label () == null ) {
338
347
return createItem ("minecraft:writable_book" , currentValue );
339
348
} else {
340
349
final Tag label = handleTag (connection , textInput .label ());
341
- return createItem ("minecraft:writable_book" , label , currentValue , text ( "§9Left click: §6Edit text" ));
350
+ return createItem ("minecraft:writable_book" , label , currentValue , translate ( config . editValue () ));
342
351
}
343
352
}
344
353
345
354
protected void clickTextInput (final UserConnection connection , final TextInput textInput ) {
346
355
final ChestDialogStorage storage = connection .get (ChestDialogStorage .class );
347
- openAnvilView (connection , storage , text ("§7Edit text" ), textInput .value (), textInput );
356
+ openAnvilView (connection , storage , translate ("§7Edit text" ), textInput .value (), textInput );
348
357
}
349
358
350
359
protected Item getSingleOptionInput (final UserConnection connection , final SingleOptionInput singleOptionInput ) {
360
+ final DialogStyleConfig config = ViaBackwards .getConfig ().dialogStyleConfig ();
361
+
351
362
final Tag displayName = singleOptionInput .options ()[singleOptionInput .value ()].computeDisplay ();
352
363
final Tag label ;
353
364
if (singleOptionInput .label () != null ) {
@@ -358,8 +369,8 @@ protected Item getSingleOptionInput(final UserConnection connection, final Singl
358
369
return createItem (
359
370
"minecraft:bookshelf" ,
360
371
handleTag (connection , label ),
361
- "§9Left click: §6Go to next option" ,
362
- "§9Right click: §6Go to previous option"
372
+ config . nextOption () ,
373
+ config . previousOption ()
363
374
);
364
375
}
365
376
@@ -388,7 +399,7 @@ public void clickButton(final UserConnection connection, final Dialog.AfterActio
388
399
case "open_url" -> {
389
400
// We can't open a URL for the client, so roughly emulate by opening an Anvil containing the URL.
390
401
final String url = clickEvent .getString ("url" );
391
- openAnvilView (connection , storage , text ("Open URL" ), url , null );
402
+ openAnvilView (connection , storage , translate ("Open URL" ), url , null );
392
403
}
393
404
case "run_command" -> {
394
405
// The vanilla client validates for signed argument types and has more requirements for this click event,
@@ -404,19 +415,21 @@ public void clickButton(final UserConnection connection, final Dialog.AfterActio
404
415
case "copy_to_clipboard" -> {
405
416
// Same as above, we can't access the clipboard
406
417
final String value = clickEvent .getString ("value" );
407
- openAnvilView (connection , storage , text ("Copy to clipboard" ), value , null );
418
+ openAnvilView (connection , storage , translate ("Copy to clipboard" ), value , null );
408
419
}
409
420
}
410
421
411
422
ClickEvents .handleClickEvent (connection , clickEvent ); // Handle show_dialog and custom
412
423
}
413
424
414
425
protected Item createTextInputItem (final String value ) {
415
- return createItem ("minecraft:paper" , text (value ), "§9Left click/close: §6Set text" );
426
+ final DialogStyleConfig config = ViaBackwards .getConfig ().dialogStyleConfig ();
427
+ return createItem ("minecraft:paper" , translate (value ), config .setText ());
416
428
}
417
429
418
430
protected Item createTextCopyItem (final String value ) {
419
- return createItem ("minecraft:paper" , text (value ), "§9Left click: §6Close" );
431
+ final DialogStyleConfig config = ViaBackwards .getConfig ().dialogStyleConfig ();
432
+ return createItem ("minecraft:paper" , translate (value ), config .close ());
420
433
}
421
434
422
435
private void openAnvilView (
@@ -589,7 +602,7 @@ protected Item createItem(final String identifier, final Tag name, final String.
589
602
if (description .length > 0 ) {
590
603
final List <Tag > lore = new ArrayList <>();
591
604
for (final String s : description ) {
592
- lore .add (text (s ));
605
+ lore .add (translate (s ));
593
606
}
594
607
data .set (StructuredDataKey .LORE , lore .toArray (new Tag [0 ]));
595
608
}
0 commit comments