|
1 | 1 | package gregtech.common.covers.filter; |
2 | 2 |
|
3 | | -import gregtech.api.cover.CoverWithUI; |
4 | | -import gregtech.api.mui.GTGuiTextures; |
5 | | -import gregtech.api.mui.GTGuis; |
6 | 3 | import gregtech.api.unification.OreDictUnifier; |
7 | 4 | import gregtech.api.unification.stack.ItemVariantMap; |
8 | 5 | import gregtech.api.unification.stack.MultiItemVariantMap; |
9 | 6 | import gregtech.api.unification.stack.SingleItemVariantMap; |
10 | | -import gregtech.api.util.oreglob.OreGlobCompileResult; |
11 | 7 | import gregtech.common.covers.filter.readers.OreDictFilterReader; |
12 | | -import gregtech.common.mui.widget.HighlightedTextField; |
13 | | -import gregtech.common.mui.widget.orefilter.OreFilterTestSlot; |
14 | 8 |
|
15 | | -import net.minecraft.client.resources.I18n; |
16 | 9 | import net.minecraft.item.Item; |
17 | 10 | import net.minecraft.item.ItemStack; |
18 | | -import net.minecraft.util.text.TextFormatting; |
19 | 11 |
|
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; |
33 | 12 | import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; |
34 | 13 | import org.jetbrains.annotations.NotNull; |
35 | 14 |
|
36 | | -import java.util.ArrayList; |
37 | | -import java.util.List; |
38 | 15 | import java.util.Map; |
39 | 16 | import java.util.Set; |
40 | 17 |
|
@@ -73,174 +50,6 @@ public void clearCache() { |
73 | 50 | this.noOreDictMatch.clear(); |
74 | 51 | } |
75 | 52 |
|
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 | | - |
244 | 53 | @Override |
245 | 54 | public MatchResult matchItem(ItemStack itemStack) { |
246 | 55 | // "wtf is this system?? i can put any non null object here and it i will work??? $arch" |
|
0 commit comments