44import net .minecraft .client .gui .GuiGraphics ;
55import net .minecraft .client .gui .components .Button ;
66import net .minecraft .client .gui .components .EditBox ;
7+ import net .minecraft .client .gui .components .SpriteIconButton ;
8+ import net .minecraft .client .gui .layouts .GridLayout ;
9+ import net .minecraft .client .gui .layouts .Layout ;
710import net .minecraft .client .resources .language .I18n ;
811import net .minecraft .network .chat .Component ;
12+ import net .minecraft .resources .ResourceLocation ;
913import net .minecraft .world .item .ItemStack ;
1014import net .minecraft .world .level .block .Block ;
1115import org .jetbrains .annotations .Nullable ;
16+ import pro .mikey .xray .XRay ;
1217import pro .mikey .xray .core .ScanController ;
1318import pro .mikey .xray .core .scanner .BlockScanType ;
1419import pro .mikey .xray .core .scanner .ScanStore ;
1520import pro .mikey .xray .core .scanner .ScanType ;
1621import pro .mikey .xray .screens .helpers .GuiBase ;
22+ import pro .mikey .xray .screens .helpers .ImageButton ;
1723import pro .mikey .xray .screens .helpers .SliderWidget ;
1824
1925import java .util .Objects ;
2026import java .util .function .Supplier ;
2127
2228public class ScanConfigureScreen extends GuiBase {
29+ private static final ResourceLocation TRASH_ICON = XRay .assetLocation ("gui/trash.png" );
30+
2331 private EditBox oreName ;
2432
2533 private SliderWidget redSlider ;
@@ -60,22 +68,35 @@ public ScanConfigureScreen(ScanType editingType, Supplier<GuiBase> previousScree
6068 @ Override
6169 public void init () {
6270 // Called when the gui should be (re)created
63- addRenderableWidget (Button .builder (Component .translatable (editingType != null ? "xray.title.edit" : "xray.single.add" ), b -> {
64- if (editingType != null ) {
65- editBlock ();
66- } else {
67- addBlock ();
68- }
69- })
70- .pos (getWidth () / 2 - 100 , getHeight () / 2 + 85 )
71- .size (128 , 20 )
71+ GridLayout layout = new GridLayout ();
72+ layout .columnSpacing (3 );
73+ layout .setPosition (getWidth () / 2 - 100 , getHeight () / 2 + 85 );
74+ GridLayout .RowHelper rowHelper = layout .createRowHelper (3 );
75+
76+ rowHelper .addChild (ImageButton .builder (b -> {
77+ removeBlock ();
78+ })
79+ .image (XRay .assetLocation ("gui/trash.png" ), 16 , 16 )
80+ .size (20 , 20 )
7281 .build ());
7382
74- addRenderableWidget (Button .builder (Component .translatable ("xray.single.cancel" ), b -> Minecraft .getInstance ().setScreen (this .previousScreenCallback .get ()))
75- .pos (getWidth () / 2 + 30 , getHeight () / 2 + 85 )
76- .size (72 , 20 )
83+ rowHelper .addChild (Button .builder (Component .translatable ("xray.single.cancel" ), b -> Minecraft .getInstance ().setScreen (this .previousScreenCallback .get ()))
84+ .size (60 , 20 )
7785 .build ());
7886
87+ rowHelper .addChild (Button .builder (Component .translatable (editingType != null ? "xray.title.edit" : "xray.single.add" ), b -> {
88+ if (editingType != null ) {
89+ editBlock ();
90+ } else {
91+ addBlock ();
92+ }
93+ })
94+ .size (117 , 20 )
95+ .build ());
96+
97+ layout .arrangeElements ();
98+ layout .visitWidgets (this ::addRenderableWidget );
99+
79100 int defaultColor = 0x00A8FF ; // Default color (Blue)
80101 if (editingType != null ) {
81102 defaultColor = editingType .colorInt ;
@@ -115,6 +136,17 @@ private void editBlock() {
115136 minecraft .setScreen (this .previousScreenCallback .get ());
116137 }
117138
139+ private void removeBlock () {
140+ if (editingType == null ) {
141+ throw new IllegalStateException ("Editing type is not set" );
142+ }
143+
144+ ScanStore scanStore = ScanController .INSTANCE .scanStore ;
145+ scanStore .removeEntry (editingType );
146+ ScanController .INSTANCE .requestBlockFinder (true );
147+ minecraft .setScreen (this .previousScreenCallback .get ());
148+ }
149+
118150 private void addBlock () {
119151 if (editingType != null ) {
120152 throw new IllegalStateException ("Editing type is already set" );
@@ -140,7 +172,7 @@ public void tick() {
140172
141173 @ Override
142174 public void renderExtra (GuiGraphics graphics , int x , int y , float partialTicks ) {
143- graphics .drawString (font , selectBlock .getName ().getString (), getWidth () / 2 - 100 , getHeight () / 2 - 90 , 0xffffff );
175+ graphics .drawString (font , selectBlock .getName ().getString (), getWidth () / 2 - 100 , getHeight () / 2 - 90 , 0xffffffff );
144176
145177 int color = (255 << 24 ) | ((int ) (this .redSlider .getValue () * 255 ) << 16 ) | ((int ) (this .greenSlider .getValue () * 255 ) << 8 ) | (int ) (this .blueSlider .getValue () * 255 );
146178 graphics .fill (this .getWidth () / 2 - 100 , this .getHeight () / 2 - 45 , (this .getWidth () / 2 + 2 ) + 100 , (this .getHeight () / 2 - 45 ) + 45 , color );
0 commit comments