Skip to content

Commit 4aa6488

Browse files
committed
Schematic Verifier GUI: Add search bar
1 parent bab6de4 commit 4aa6488

3 files changed

Lines changed: 73 additions & 28 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Features:
8989
* Useful for building with multiple people
9090
* Keeps checking for block changes outside render distance
9191
* Schematic Verifier: Addition of cardinal coordinates for entries in Info Hud
92+
* Schematic Verifier GUI: Addition of search bar
9293

9394
Tweaks:
9495
* EasyPlace: Prestocks main hand using a single shift+click packet

src/main/java/fi/dy/masa/litematica/gui/widgets/WidgetListSchematicVerificationResults.java

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package fi.dy.masa.litematica.gui.widgets;
22

33
import java.util.ArrayList;
4+
import java.util.Collection;
45
import java.util.Collections;
56
import java.util.List;
7+
8+
import fi.dy.masa.litematica.gui.Icons;
9+
import fi.dy.masa.malilib.gui.LeftRight;
10+
import fi.dy.masa.malilib.gui.widgets.WidgetSearchBar;
611
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
712
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
813

14+
import net.minecraft.block.Block;
915
import net.minecraft.block.BlockState;
1016
import net.minecraft.client.gui.DrawContext;
1117
import net.minecraft.item.ItemStack;
@@ -20,6 +26,8 @@
2026
import fi.dy.masa.malilib.gui.widgets.WidgetListBase;
2127
import fi.dy.masa.malilib.util.ItemType;
2228
import fi.dy.masa.malilib.util.StringUtils;
29+
import net.minecraft.registry.Registries;
30+
import net.minecraft.util.Identifier;
2331

2432
public class WidgetListSchematicVerificationResults extends WidgetListBase<BlockMismatchEntry, WidgetSchematicVerificationResult>
2533
{
@@ -36,6 +44,8 @@ public WidgetListSchematicVerificationResults(int x, int y, int width, int heigh
3644
this.browserEntryHeight = 22;
3745
this.guiSchematicVerifier = parent;
3846
this.allowMultiSelection = true;
47+
this.widgetSearchBar = new WidgetSearchBar(x + 2, y + 8, width - 16, 14, 0, Icons.FILE_ICON_SEARCH, LeftRight.RIGHT);
48+
this.widgetSearchBar.setZLevel(1);
3949
this.sorter = new VerifierResultSorter(parent.getPlacement().getSchematicVerifier());
4050
}
4151

@@ -53,6 +63,57 @@ protected void offsetSelectionOrScrollbar(int amount, boolean changeSelection)
5363
lastScrollbarPosition = this.scrollBar.getValue();
5464
}
5565

66+
@Override
67+
protected Collection<BlockMismatchEntry> getAllEntries()
68+
{
69+
List<BlockMismatchEntry> listContents = new ArrayList<>();
70+
71+
MismatchType type = this.guiSchematicVerifier.getResultMode();
72+
73+
if (type == MismatchType.ALL)
74+
{
75+
this.addEntriesForType(listContents, MismatchType.WRONG_BLOCK);
76+
if (Configs.Generic.ENABLE_DIFFERENT_BLOCKS.getBooleanValue())
77+
{
78+
this.addEntriesForType(listContents, MismatchType.DIFF_BLOCK);
79+
}
80+
this.addEntriesForType(listContents, MismatchType.WRONG_STATE);
81+
this.addEntriesForType(listContents, MismatchType.EXTRA);
82+
this.addEntriesForType(listContents, MismatchType.MISSING);
83+
}
84+
else
85+
{
86+
this.addEntriesForType(listContents, type);
87+
}
88+
89+
return listContents;
90+
}
91+
92+
@Override
93+
protected List<String> getEntryStringsForFilter(BlockMismatchEntry entry)
94+
{
95+
if (entry.blockMismatch == null)
96+
return Collections.emptyList();
97+
98+
List<String> list = new ArrayList<>();
99+
100+
Block block = entry.blockMismatch.stateExpected.getBlock();
101+
Identifier rl = Registries.ITEM.getId(block.asItem());
102+
103+
list.add(block.getName().getString().toLowerCase());
104+
if (rl != null)
105+
list.add(rl.toString().toLowerCase());
106+
107+
block = entry.blockMismatch.stateFound.getBlock();
108+
rl = Registries.ITEM.getId(block.asItem());
109+
110+
list.add(block.getName().getString().toLowerCase());
111+
if (rl != null)
112+
list.add(rl.toString().toLowerCase());
113+
114+
return list;
115+
}
116+
56117
@Override
57118
protected WidgetSchematicVerificationResult createHeaderWidget(int x, int y, int listIndexStart, int usableHeight, int usedHeight)
58119
{
@@ -83,27 +144,7 @@ protected WidgetSchematicVerificationResult createHeaderWidget(int x, int y, int
83144
@Override
84145
protected void refreshBrowserEntries()
85146
{
86-
this.listContents.clear();
87-
88-
MismatchType type = this.guiSchematicVerifier.getResultMode();
89-
90-
if (type == MismatchType.ALL)
91-
{
92-
this.addEntriesForType(MismatchType.WRONG_BLOCK);
93-
if (Configs.Generic.ENABLE_DIFFERENT_BLOCKS.getBooleanValue())
94-
{
95-
this.addEntriesForType(MismatchType.DIFF_BLOCK);
96-
}
97-
this.addEntriesForType(MismatchType.WRONG_STATE);
98-
this.addEntriesForType(MismatchType.EXTRA);
99-
this.addEntriesForType(MismatchType.MISSING);
100-
}
101-
else
102-
{
103-
this.addEntriesForType(type);
104-
}
105-
106-
this.reCreateListEntryWidgets();
147+
super.refreshBrowserEntries();
107148

108149
if (this.scrollbarRestored == false && lastScrollbarPosition <= this.scrollBar.getMaxValue())
109150
{
@@ -114,10 +155,10 @@ protected void refreshBrowserEntries()
114155
}
115156
}
116157

117-
private void addEntriesForType(MismatchType type)
158+
private void addEntriesForType(Collection<BlockMismatchEntry> listContents, MismatchType type)
118159
{
119160
String title = type.getFormattingCode() + type.getDisplayname() + TXT_RST;
120-
this.listContents.add(new BlockMismatchEntry(type, title));
161+
listContents.add(new BlockMismatchEntry(type, title));
121162
List<BlockMismatch> list;
122163

123164
if (type == MismatchType.CORRECT_STATE)
@@ -162,7 +203,7 @@ private void addEntriesForType(MismatchType type)
162203

163204
for (BlockMismatch mismatch : list)
164205
{
165-
this.listContents.add(new BlockMismatchEntry(type, mismatch));
206+
listContents.add(new BlockMismatchEntry(type, mismatch));
166207
}
167208
}
168209

src/main/java/fi/dy/masa/litematica/gui/widgets/WidgetSchematicVerificationResult.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,14 @@ else if (this.isOdd)
274274

275275
if (this.header1 != null && this.header2 != null)
276276
{
277-
this.drawString(x1, y, color, this.header1, drawContext);
278-
this.drawString(x2, y, color, this.header2, drawContext);
279-
this.drawString(x3, y, color, this.header3, drawContext);
277+
if (this.listWidget.getSearchBarWidget().isSearchOpen() == false)
278+
{
279+
this.drawString(x1, y, color, this.header1, drawContext);
280+
this.drawString(x2, y, color, this.header2, drawContext);
281+
this.drawString(x3, y, color, this.header3, drawContext);
280282

281-
this.renderColumnHeader(mouseX, mouseY, Icons.ARROW_DOWN, Icons.ARROW_UP, drawContext);
283+
this.renderColumnHeader(mouseX, mouseY, Icons.ARROW_DOWN, Icons.ARROW_UP, drawContext);
284+
}
282285
}
283286
else if (this.header1 != null)
284287
{

0 commit comments

Comments
 (0)