Skip to content

Commit 517a4a6

Browse files
committed
use copied ui methods from filter ui manager
delete ui code from filter classes delete notifiable from filter classes
1 parent 6d5838e commit 517a4a6

9 files changed

Lines changed: 4 additions & 445 deletions

src/main/java/gregtech/common/covers/CoverFluidFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
173173
.alignX(1f)))
174174
.child(new Rectangle().setColor(UI_TEXT_COLOR).asWidget()
175175
.height(1).widthRel(0.95f).margin(0, 4))
176-
.child(getFilter().createWidgets(guiSyncManager)))
176+
.child(getFilter().getUI().createWidgets(getPickItem(), guiSyncManager)))
177177
.child(SlotGroupWidget.playerInventory(false).bottom(7).left(7));
178178
}
179179

src/main/java/gregtech/common/covers/CoverItemFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
176176
.alignX(1f)))
177177
.child(new Rectangle().setColor(UI_TEXT_COLOR).asWidget()
178178
.height(1).widthRel(0.95f).margin(0, 4))
179-
.child(getFilter().createWidgets(guiSyncManager).left(0)))
179+
.child(getFilter().getUI().createWidgets(getPickItem(), guiSyncManager).left(0)))
180180
.child(SlotGroupWidget.playerInventory(false).bottom(7).left(7));
181181
}
182182

src/main/java/gregtech/common/covers/filter/BaseFilter.java

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
package gregtech.common.covers.filter;
22

3-
import com.cleanroommc.modularui.api.IPanelHandler;
4-
import com.cleanroommc.modularui.value.sync.PanelSyncHandler;
5-
63
import gregtech.api.items.metaitem.MetaItem;
74
import gregtech.api.items.metaitem.stats.IItemComponent;
8-
import gregtech.api.mui.GTGuiTextures;
9-
import gregtech.api.mui.GTGuis;
105
import gregtech.api.util.IDirtyNotifiable;
116
import gregtech.common.covers.filter.readers.BaseFilterReader;
127

@@ -17,16 +12,6 @@
1712
import net.minecraft.network.PacketBuffer;
1813
import net.minecraftforge.fluids.FluidStack;
1914

20-
import com.cleanroommc.modularui.api.drawable.IKey;
21-
import com.cleanroommc.modularui.api.widget.IWidget;
22-
import com.cleanroommc.modularui.screen.ModularPanel;
23-
import com.cleanroommc.modularui.utils.Alignment;
24-
import com.cleanroommc.modularui.value.sync.BooleanSyncValue;
25-
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
26-
import com.cleanroommc.modularui.widget.ParentWidget;
27-
import com.cleanroommc.modularui.widget.Widget;
28-
import com.cleanroommc.modularui.widgets.CycleButtonWidget;
29-
3015
import org.jetbrains.annotations.NotNull;
3116

3217
import java.util.Optional;
@@ -43,29 +28,11 @@ public BaseFilterReader getFilterReader() {
4328
@Override
4429
public void updateFilterReader(ItemStack stack) {}
4530

46-
@Override
47-
public @NotNull ModularPanel createPopupPanel(PanelSyncManager syncManager, String panelName) {
48-
return GTGuis.createPopupPanel(panelName, 100, 100)
49-
.child(createWidgets(syncManager));
50-
}
51-
52-
@Override
53-
public @NotNull ModularPanel createPanel(PanelSyncManager syncManager) {
54-
return GTGuis.createPanel("error", 100, 100)
55-
.child(createWidgets(syncManager));
56-
}
57-
58-
@Override
59-
public @NotNull Widget<?> createWidgets(PanelSyncManager syncManager) {
60-
return IKey.lang("INVALID FILTER").alignment(Alignment.Center).asWidget();
61-
}
62-
6331
@Override
6432
public FilterType getType() {
6533
return FilterType.ERROR;
6634
}
6735
};
68-
protected IDirtyNotifiable dirtyNotifiable;
6936

7037
public abstract BaseFilterReader getFilterReader();
7138

@@ -158,18 +125,6 @@ public final boolean isBlacklistFilter() {
158125
return getFilterReader().isBlacklistFilter();
159126
}
160127

161-
public IWidget createBlacklistUI() {
162-
return new ParentWidget<>().coverChildren()
163-
.child(new CycleButtonWidget()
164-
.value(new BooleanSyncValue(
165-
this::isBlacklistFilter,
166-
this::setBlacklistFilter))
167-
.stateBackground(0, GTGuiTextures.BUTTON_BLACKLIST[0])
168-
.stateBackground(1, GTGuiTextures.BUTTON_BLACKLIST[1])
169-
.addTooltip(0, IKey.lang("cover.filter.blacklist.disabled"))
170-
.addTooltip(1, IKey.lang("cover.filter.blacklist.enabled")));
171-
}
172-
173128
public final int getMaxTransferSize() {
174129
return this.getFilterReader().getMaxTransferRate();
175130
}
@@ -183,43 +138,17 @@ public boolean showGlobalTransferLimitSlider() {
183138
}
184139

185140
public final void setDirtyNotifiable(IDirtyNotifiable dirtyNotifiable) {
186-
this.dirtyNotifiable = dirtyNotifiable;
187141
this.getFilterReader().setDirtyNotifiable(dirtyNotifiable);
188142
}
189143

190-
public final void markDirty() {
191-
if (dirtyNotifiable != null) {
192-
dirtyNotifiable.markAsDirty();
193-
}
194-
}
195-
196144
public void readFromNBT(NBTTagCompound tag) {
197145
this.getFilterReader().deserializeNBT(tag);
198-
markDirty();
199146
}
200147

201148
public void writeInitialSyncData(PacketBuffer packetBuffer) {}
202149

203150
public void readInitialSyncData(@NotNull PacketBuffer packetBuffer) {}
204151

205-
public abstract @NotNull ModularPanel createPopupPanel(PanelSyncManager syncManager, String panelName);
206-
207-
@NotNull
208-
public abstract ModularPanel createPanel(PanelSyncManager syncManager);
209-
210-
/** Creates the widgets standalone so that they can be put into their own panel */
211-
212-
@NotNull
213-
public abstract Widget<?> createWidgets(PanelSyncManager syncManager);
214-
215-
public IPanelHandler createPanelHandler(PanelSyncManager syncManager, int id) {
216-
String translationKey = getContainerStack().getTranslationKey();
217-
return syncManager.getOrCreateSyncHandler(translationKey, id, PanelSyncHandler.class, () -> {
218-
String key = PanelSyncManager.makeSyncKey(translationKey, id);
219-
return (PanelSyncHandler) syncManager.panel(key, (psm, $) -> createPopupPanel(psm, key), true);
220-
});
221-
}
222-
223152
public abstract FilterType getType();
224153

225154
public boolean isItem() {

src/main/java/gregtech/common/covers/filter/OreDictionaryItemFilter.java

Lines changed: 0 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
11
package gregtech.common.covers.filter;
22

3-
import gregtech.api.cover.CoverWithUI;
4-
import gregtech.api.mui.GTGuiTextures;
5-
import gregtech.api.mui.GTGuis;
63
import gregtech.api.unification.OreDictUnifier;
74
import gregtech.api.unification.stack.ItemVariantMap;
85
import gregtech.api.unification.stack.MultiItemVariantMap;
96
import gregtech.api.unification.stack.SingleItemVariantMap;
10-
import gregtech.api.util.oreglob.OreGlobCompileResult;
117
import gregtech.common.covers.filter.readers.OreDictFilterReader;
12-
import gregtech.common.mui.widget.HighlightedTextField;
13-
import gregtech.common.mui.widget.orefilter.OreFilterTestSlot;
148

15-
import net.minecraft.client.resources.I18n;
169
import net.minecraft.item.Item;
1710
import net.minecraft.item.ItemStack;
18-
import net.minecraft.util.text.TextFormatting;
1911

20-
import com.cleanroommc.modularui.api.drawable.IKey;
21-
import com.cleanroommc.modularui.drawable.UITexture;
22-
import com.cleanroommc.modularui.screen.ModularPanel;
23-
import com.cleanroommc.modularui.screen.RichTooltip;
24-
import com.cleanroommc.modularui.utils.BooleanConsumer;
25-
import com.cleanroommc.modularui.utils.Color;
26-
import com.cleanroommc.modularui.value.sync.BooleanSyncValue;
27-
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
28-
import com.cleanroommc.modularui.value.sync.StringSyncValue;
29-
import com.cleanroommc.modularui.widget.Widget;
30-
import com.cleanroommc.modularui.widgets.CycleButtonWidget;
31-
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
32-
import com.cleanroommc.modularui.widgets.layout.Flow;
3312
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
3413
import org.jetbrains.annotations.NotNull;
3514

36-
import java.util.ArrayList;
37-
import java.util.List;
3815
import java.util.Map;
3916
import java.util.Set;
4017

@@ -73,174 +50,6 @@ public void clearCache() {
7350
this.noOreDictMatch.clear();
7451
}
7552

76-
@Override
77-
public @NotNull ModularPanel createPopupPanel(PanelSyncManager syncManager, String panelName) {
78-
return GTGuis.createPopupPanel(panelName, 188, 76, false)
79-
.padding(7)
80-
.child(CoverWithUI.createTitleRow(getContainerStack()))
81-
.child(createWidgets(syncManager).top(22));
82-
}
83-
84-
@Override
85-
public @NotNull ModularPanel createPanel(PanelSyncManager syncManager) {
86-
return GTGuis.createPanel("ore_dict_filter", 100, 100);
87-
}
88-
89-
@Override
90-
public @NotNull Widget<?> createWidgets(PanelSyncManager syncManager) {
91-
List<OreFilterTestSlot> oreSlots = new ArrayList<>();
92-
var expression = new StringSyncValue(this.filterReader::getExpression, this.filterReader::setExpression);
93-
94-
BooleanConsumer setCaseSensitive = b -> {
95-
this.filterReader.setCaseSensitive(b);
96-
if (!syncManager.isClient()) return;
97-
for (var slot : oreSlots) {
98-
slot.updatePreview();
99-
}
100-
};
101-
102-
BooleanConsumer setMatchAll = b -> {
103-
this.clearCache();
104-
this.filterReader.setMatchAll(b);
105-
if (!syncManager.isClient()) return;
106-
for (var slot : oreSlots) {
107-
slot.setMatchAll(b);
108-
}
109-
};
110-
111-
var caseSensitive = new BooleanSyncValue(this.filterReader::isCaseSensitive, setCaseSensitive);
112-
var matchAll = new BooleanSyncValue(this.filterReader::shouldMatchAll, setMatchAll);
113-
114-
return Flow.column().widthRel(1f).coverChildrenHeight()
115-
.child(new HighlightedTextField()
116-
.setHighlightRule(this::highlightRule)
117-
.onUnfocus(() -> {
118-
for (var slot : oreSlots) {
119-
slot.updatePreview();
120-
}
121-
})
122-
.setTextColor(Color.WHITE.darker(1))
123-
.value(expression).marginBottom(4)
124-
.height(18).widthRel(1f))
125-
.child(Flow.row().coverChildrenHeight()
126-
.widthRel(1f)
127-
.child(Flow.column().height(18)
128-
.coverChildrenWidth().marginRight(2)
129-
.child(GTGuiTextures.OREDICT_INFO.asWidget()
130-
.size(8).top(0)
131-
.addTooltipLine(IKey.lang("cover.ore_dictionary_filter.info")))
132-
.child(new Widget<>()
133-
.size(8).bottom(0)
134-
.onUpdateListener(this::getStatusIcon)
135-
.tooltipBuilder(this::createStatusTooltip)
136-
.tooltip(tooltip -> tooltip.setAutoUpdate(true))))
137-
.child(SlotGroupWidget.builder()
138-
.row("XXXXX")
139-
.key('X', i -> {
140-
var slot = new OreFilterTestSlot()
141-
.setGlobSupplier(this.filterReader::getGlob);
142-
slot.setMatchAll(this.filterReader.shouldMatchAll());
143-
oreSlots.add(slot);
144-
return slot;
145-
})
146-
.build().marginRight(2))
147-
.child(new CycleButtonWidget()
148-
.size(18).value(caseSensitive)
149-
.marginRight(2)
150-
.stateBackground(0, GTGuiTextures.BUTTON_CASE_SENSITIVE[0])
151-
.stateBackground(1, GTGuiTextures.BUTTON_CASE_SENSITIVE[1])
152-
.addTooltip(0,
153-
IKey.lang("cover.ore_dictionary_filter.button.case_sensitive.disabled"))
154-
.addTooltip(1,
155-
IKey.lang("cover.ore_dictionary_filter.button.case_sensitive.enabled")))
156-
.child(new CycleButtonWidget()
157-
.size(18).value(matchAll)
158-
.marginRight(2)
159-
.stateBackground(0, GTGuiTextures.BUTTON_MATCH_ALL[0])
160-
.stateBackground(1, GTGuiTextures.BUTTON_MATCH_ALL[1])
161-
.addTooltip(0,
162-
IKey.lang("cover.ore_dictionary_filter.button.match_all.disabled"))
163-
.addTooltip(1,
164-
IKey.lang("cover.ore_dictionary_filter.button.match_all.enabled")))
165-
.child(createBlacklistUI()));
166-
}
167-
168-
protected void getStatusIcon(Widget<?> widget) {
169-
UITexture texture;
170-
var result = this.filterReader.getResult();
171-
172-
if (result == null) {
173-
texture = GTGuiTextures.OREDICT_WAITING;
174-
} else if (result.getReports().length == 0) {
175-
texture = GTGuiTextures.OREDICT_SUCCESS;
176-
} else if (result.hasError()) {
177-
texture = GTGuiTextures.OREDICT_ERROR;
178-
} else {
179-
texture = GTGuiTextures.OREDICT_WARN;
180-
}
181-
widget.background(texture);
182-
}
183-
184-
protected void createStatusTooltip(RichTooltip tooltip) {
185-
var result = this.filterReader.getResult();
186-
if (result == null) return;
187-
List<String> list = new ArrayList<>();
188-
189-
int error = 0, warn = 0;
190-
for (OreGlobCompileResult.Report report : result.getReports()) {
191-
if (report.isError()) error++;
192-
else warn++;
193-
list.add((report.isError() ? TextFormatting.RED : TextFormatting.GOLD) + report.toString());
194-
}
195-
if (error > 0) {
196-
if (warn > 0) {
197-
list.add(0, I18n.format("cover.ore_dictionary_filter.status.err_warn", error, warn));
198-
} else {
199-
list.add(0, I18n.format("cover.ore_dictionary_filter.status.err", error));
200-
}
201-
} else {
202-
if (warn > 0) {
203-
list.add(0, I18n.format("cover.ore_dictionary_filter.status.warn", warn));
204-
} else {
205-
list.add(I18n.format("cover.ore_dictionary_filter.status.no_issues"));
206-
}
207-
list.add("");
208-
list.add(I18n.format("cover.ore_dictionary_filter.status.explain"));
209-
list.add("");
210-
list.addAll(result.getInstance().toFormattedString());
211-
}
212-
tooltip.addStringLines(list);
213-
}
214-
215-
protected String highlightRule(String text) {
216-
StringBuilder builder = new StringBuilder(text);
217-
for (int i = 0; i < builder.length(); i++) {
218-
switch (builder.charAt(i)) {
219-
case '|', '&', '^', '(', ')' -> {
220-
builder.insert(i, TextFormatting.GOLD);
221-
i += 2;
222-
}
223-
case '*', '?' -> {
224-
builder.insert(i, TextFormatting.GREEN);
225-
i += 2;
226-
}
227-
case '!' -> {
228-
builder.insert(i, TextFormatting.RED);
229-
i += 2;
230-
}
231-
case '\\' -> {
232-
builder.insert(i++, TextFormatting.YELLOW);
233-
i += 2;
234-
}
235-
default -> {
236-
continue;
237-
}
238-
}
239-
builder.insert(i + 1, TextFormatting.RESET);
240-
}
241-
return builder.toString();
242-
}
243-
24453
@Override
24554
public MatchResult matchItem(ItemStack itemStack) {
24655
// "wtf is this system?? i can put any non null object here and it i will work??? $arch"

0 commit comments

Comments
 (0)