1919
2020import com .viaversion .nbt .tag .CompoundTag ;
2121import com .viaversion .nbt .tag .Tag ;
22+ import com .viaversion .viabackwards .ViaBackwards ;
23+ import com .viaversion .viabackwards .api .DialogStyleConfig ;
2224import com .viaversion .viabackwards .protocol .v1_21_6to1_21_5 .Protocol1_21_6To1_21_5 ;
2325import com .viaversion .viabackwards .protocol .v1_21_6to1_21_5 .data .Button ;
2426import com .viaversion .viabackwards .protocol .v1_21_6to1_21_5 .data .Dialog ;
5254import org .checkerframework .checker .nullness .qual .Nullable ;
5355
5456import static com .viaversion .viabackwards .utils .ChatUtil .fixStyle ;
55- import static com .viaversion .viabackwards .utils .ChatUtil .text ;
5657import static com .viaversion .viabackwards .utils .ChatUtil .translate ;
5758
5859/**
@@ -225,12 +226,14 @@ public void updateDialog(final UserConnection connection, final Dialog dialog) {
225226 }
226227
227228 protected Item createPageNavigationItem () {
229+ final DialogStyleConfig config = ViaBackwards .getConfig ().dialogStyleConfig ();
230+
228231 return createItem (
229232 "minecraft:arrow" ,
230- text ( "§9§lPage navigation" ),
233+ translate ( config . pageNavigationTitle () ),
231234
232- "§9Left click: §6Go to next page" ,
233- "§9Right click: §6Go to previous page"
235+ config . pageNavigationNext () ,
236+ config . pageNavigationPrevious ()
234237 );
235238 }
236239
@@ -251,7 +254,7 @@ protected Item getItemWidget(final UserConnection connection, final ItemWidget i
251254 final String identifier = itemWidget .item ().getString ("id" );
252255 final int count = itemWidget .item ().getInt ("count" , 1 );
253256
254- final Tag label = text (Key .stripMinecraftNamespace (identifier ));
257+ final Tag label = translate (Key .stripMinecraftNamespace (identifier ));
255258 final Item item = createItem (identifier , label );
256259 item .setAmount (count );
257260 if (itemWidget .description () != null ) {
@@ -282,6 +285,8 @@ protected Item getMultiTextWidget(final UserConnection connection, final MultiTe
282285 }
283286
284287 protected Item getBooleanInput (final UserConnection connection , final BooleanInput booleanInput ) {
288+ final DialogStyleConfig config = ViaBackwards .getConfig ().dialogStyleConfig ();
289+
285290 final String item = booleanInput .value () ? "minecraft:lime_dye" : "minecraft:gray_dye" ;
286291 final Tag [] label = ChatUtil .split (booleanInput .label (), "\n " );
287292
@@ -290,14 +295,14 @@ protected Item getBooleanInput(final UserConnection connection, final BooleanInp
290295 return createItem (
291296 item ,
292297 handleTag (connection , booleanInput .label ()),
293- text ( "§9Left click: §6Toggle value" )
298+ translate ( config . toggleValue () )
294299 );
295300 } else {
296301 final Tag [] lore = new Tag [label .length ];
297302 for (int i = 1 ; i < label .length ; i ++) {
298303 lore [i - 1 ] = handleTag (connection , fixStyle (label [i ]));
299304 }
300- lore [lore .length - 1 ] = text ( "§9Left click: §6Toggle value" );
305+ lore [lore .length - 1 ] = translate ( config . toggleValue () );
301306 return createItem (
302307 item ,
303308 handleTag (connection , label [0 ]),
@@ -311,14 +316,16 @@ protected void clickBooleanInput(final BooleanInput booleanInput) {
311316 }
312317
313318 protected Item getNumberRangeInput (final UserConnection connection , final NumberRangeInput numberRangeInput ) {
319+ final DialogStyleConfig config = ViaBackwards .getConfig ().dialogStyleConfig ();
320+
314321 final Tag label = handleTag (connection , numberRangeInput .displayName ());
315322 return createItem (
316323 "minecraft:clock" ,
317324 label ,
318325
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 ())
322329 );
323330 }
324331
@@ -333,21 +340,25 @@ protected void clickNumberRangeInput(final NumberRangeInput numberRangeInput, fi
333340 }
334341
335342 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 ()));
337346 if (textInput .label () == null ) {
338347 return createItem ("minecraft:writable_book" , currentValue );
339348 } else {
340349 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 () ));
342351 }
343352 }
344353
345354 protected void clickTextInput (final UserConnection connection , final TextInput textInput ) {
346355 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 );
348357 }
349358
350359 protected Item getSingleOptionInput (final UserConnection connection , final SingleOptionInput singleOptionInput ) {
360+ final DialogStyleConfig config = ViaBackwards .getConfig ().dialogStyleConfig ();
361+
351362 final Tag displayName = singleOptionInput .options ()[singleOptionInput .value ()].computeDisplay ();
352363 final Tag label ;
353364 if (singleOptionInput .label () != null ) {
@@ -358,8 +369,8 @@ protected Item getSingleOptionInput(final UserConnection connection, final Singl
358369 return createItem (
359370 "minecraft:bookshelf" ,
360371 handleTag (connection , label ),
361- "§9Left click: §6Go to next option" ,
362- "§9Right click: §6Go to previous option"
372+ config . nextOption () ,
373+ config . previousOption ()
363374 );
364375 }
365376
@@ -388,7 +399,7 @@ public void clickButton(final UserConnection connection, final Dialog.AfterActio
388399 case "open_url" -> {
389400 // We can't open a URL for the client, so roughly emulate by opening an Anvil containing the URL.
390401 final String url = clickEvent .getString ("url" );
391- openAnvilView (connection , storage , text ("Open URL" ), url , null );
402+ openAnvilView (connection , storage , translate ("Open URL" ), url , null );
392403 }
393404 case "run_command" -> {
394405 // 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
404415 case "copy_to_clipboard" -> {
405416 // Same as above, we can't access the clipboard
406417 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 );
408419 }
409420 }
410421
411422 ClickEvents .handleClickEvent (connection , clickEvent ); // Handle show_dialog and custom
412423 }
413424
414425 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 ());
416428 }
417429
418430 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 ());
420433 }
421434
422435 private void openAnvilView (
@@ -589,7 +602,7 @@ protected Item createItem(final String identifier, final Tag name, final String.
589602 if (description .length > 0 ) {
590603 final List <Tag > lore = new ArrayList <>();
591604 for (final String s : description ) {
592- lore .add (text (s ));
605+ lore .add (translate (s ));
593606 }
594607 data .set (StructuredDataKey .LORE , lore .toArray (new Tag [0 ]));
595608 }
0 commit comments