1313public class Gui extends Screen {
1414 private static final int buttonWidth = 150 ;
1515 private static final int buttonHeight = 20 ;
16+ private static final int COLOR_RED = 0xFF0000 ;
17+ private static final int COLOR_WHITE = 0xFFFFFF ;
1618 private final Component updateWarnings = Component .translatable ("* %s\n * %s" ,
1719 Component .translatable ("config_manager.warning.lose_some_config" ),
1820 Component .translatable ("config_manager.warning.game_restart" )
@@ -30,43 +32,43 @@ public Gui(Screen screen) {
3032 super (Component .translatable ("config_manager.title" ));
3133 }
3234
35+ private Button createConfigButton (Component label , Runnable flagSetter , boolean isFirstClick , java .util .function .Consumer <Boolean > firstClickUpdater ) {
36+ return Button .builder (label , (btn ) -> {
37+ if (isFirstClick ) {
38+ btn .setMessage (Component .translatable ("config_manager.confirmation" ).withStyle (style -> style .withColor (COLOR_RED )));
39+ firstClickUpdater .accept (false );
40+ } else {
41+ try {
42+ flagSetter .run ();
43+ btn .setMessage (Component .translatable ("config_manager.success" ).withStyle (style -> style .withColor (COLOR_WHITE )));
44+ btn .active = false ;
45+ } catch (Exception e ) {
46+ Constants .LOGGER .error ("Failed to set flag" , e );
47+ btn .setMessage (Component .translatable ("config_manager.error" ).withStyle (style -> style .withColor (COLOR_RED )));
48+ }
49+ }
50+ })
51+ .size (buttonWidth , buttonHeight )
52+ .build ();
53+ }
54+
3355 @ Override
3456 protected void init () {
35- Button updateButton = Button .builder (Component .translatable ("config_manager.update_config" ), (btn ) -> {
36- if (updateFirstClick ) {
37- btn .setMessage (Component .translatable ("config_manager.confirmation" ).withStyle (style -> style .withColor (0xFF0000 ))); // Red
38- updateFirstClick = false ;
39- } else {
40- try {
41- AddFlagsUtil .setUpdateFlag (true );
42- btn .setMessage (Component .translatable ("config_manager.success" ).withStyle (style -> style .withColor (0xFFFFFF )));
43- btn .active = false ;
44- } catch (Exception e ) {
45- Constants .LOGGER .error ("Failed to set update flag" , e );
46- btn .setMessage (Component .translatable ("config_manager.error" ).withStyle (style -> style .withColor (0xFF0000 )));
47- }
48- }
49- }).pos ((int ) ((this .width - buttonWidth ) * 0.15 ), (int ) ((this .height - buttonHeight ) * 0.7 ))
50- .size (buttonWidth , buttonHeight )
51- .build ();
52-
53- Button resetButton = Button .builder (Component .translatable ("config_manager.reset_config" ), (btn ) -> {
54- if (resetFirstClick ) {
55- btn .setMessage (Component .translatable ("config_manager.confirmation" ).withStyle (style -> style .withColor (0xFF0000 ))); // Red
56- resetFirstClick = false ;
57- } else {
58- try {
59- AddFlagsUtil .setOverwriteFlag (true );
60- btn .setMessage (Component .translatable ("config_manager.success" ).withStyle (style -> style .withColor (0xFFFFFF )));
61- btn .active = false ;
62- } catch (Exception e ) {
63- Constants .LOGGER .error ("Failed to set overwrite flag" , e );
64- btn .setMessage (Component .translatable ("config_manager.error" ).withStyle (style -> style .withColor (0xFF0000 )));
65- }
66- }
67- }).pos ((int ) ((this .width - buttonWidth ) * 0.9 ), (int ) ((this .height - buttonHeight ) * 0.7 ))
68- .size (buttonWidth , buttonHeight )
69- .build ();
57+ Button updateButton = createConfigButton (
58+ Component .translatable ("config_manager.update_config" ),
59+ () -> AddFlagsUtil .setUpdateFlag (true ),
60+ updateFirstClick ,
61+ (val ) -> updateFirstClick = val
62+ );
63+ updateButton .setPosition ((int ) ((this .width - buttonWidth ) * 0.15 ), (int ) ((this .height - buttonHeight ) * 0.7 ));
64+
65+ Button resetButton = createConfigButton (
66+ Component .translatable ("config_manager.reset_config" ),
67+ () -> AddFlagsUtil .setOverwriteFlag (true ),
68+ resetFirstClick ,
69+ (val ) -> resetFirstClick = val
70+ );
71+ resetButton .setPosition ((int ) ((this .width - buttonWidth ) * 0.7 ), (int ) ((this .height - buttonHeight ) * 0.7 ));
7072
7173 Button closeButton = Button .builder (Component .translatable ("config_manager.close" ), (btn ) -> {
7274 this .onClose ();
@@ -88,7 +90,7 @@ protected void init() {
8890 l2 = new MultilineLabelWidget (
8991 this .font ,
9092 resetWarnings ,
91- (int ) ((this .width - buttonWidth ) * 0.9 ),
93+ (int ) ((this .width - buttonWidth ) * 0.7 ),
9294 (int ) ((this .height - buttonHeight ) * 0.7 ) - 90 ,
9395 buttonWidth ,
9496 true
0 commit comments