|
1 | 1 | package gregtech.api.cover; |
2 | 2 |
|
3 | | -import gregtech.api.mui.GTGuiTextures; |
4 | 3 | import gregtech.api.mui.GTGuiTheme; |
5 | 4 | import gregtech.api.mui.GregTechGuiScreen; |
6 | 5 | import gregtech.api.mui.factory.CoverGuiFactory; |
|
12 | 11 | import net.minecraftforge.fml.relauncher.SideOnly; |
13 | 12 |
|
14 | 13 | import com.cleanroommc.modularui.api.IGuiHolder; |
15 | | -import com.cleanroommc.modularui.api.drawable.IDrawable; |
16 | 14 | import com.cleanroommc.modularui.api.drawable.IKey; |
17 | 15 | import com.cleanroommc.modularui.drawable.DynamicDrawable; |
18 | 16 | import com.cleanroommc.modularui.drawable.ItemDrawable; |
19 | 17 | import com.cleanroommc.modularui.factory.SidedPosGuiData; |
20 | 18 | import com.cleanroommc.modularui.screen.ModularPanel; |
21 | 19 | import com.cleanroommc.modularui.screen.ModularScreen; |
22 | 20 | import com.cleanroommc.modularui.screen.UISettings; |
23 | | -import com.cleanroommc.modularui.utils.Alignment; |
24 | 21 | import com.cleanroommc.modularui.utils.Color; |
25 | 22 | import com.cleanroommc.modularui.utils.MouseData; |
26 | | -import com.cleanroommc.modularui.value.BoolValue; |
27 | | -import com.cleanroommc.modularui.value.sync.EnumSyncValue; |
28 | | -import com.cleanroommc.modularui.value.sync.IntSyncValue; |
29 | 23 | import com.cleanroommc.modularui.value.sync.PanelSyncManager; |
30 | 24 | import com.cleanroommc.modularui.widget.ParentWidget; |
31 | 25 | import com.cleanroommc.modularui.widget.Widget; |
32 | | -import com.cleanroommc.modularui.widgets.ToggleButton; |
33 | 26 | import com.cleanroommc.modularui.widgets.layout.Flow; |
34 | 27 | import org.jetbrains.annotations.ApiStatus; |
35 | 28 | import org.jetbrains.annotations.NotNull; |
36 | | -import org.jetbrains.annotations.Nullable; |
37 | 29 |
|
38 | | -import java.util.function.BiConsumer; |
39 | 30 | import java.util.function.BooleanSupplier; |
40 | 31 | import java.util.function.Supplier; |
41 | 32 |
|
@@ -174,157 +165,4 @@ default IKey createAdjustOverlay(boolean increment) { |
174 | 165 | .color(Color.WHITE.main) |
175 | 166 | .scale(scale); |
176 | 167 | } |
177 | | - |
178 | | - /** |
179 | | - * Get a BoolValue for use with toggle buttons which are "linked together," |
180 | | - * meaning only one of them can be pressed at a time. |
181 | | - */ |
182 | | - default <T extends Enum<T>> BoolValue.Dynamic boolValueOf(EnumSyncValue<T> syncValue, T value) { |
183 | | - return new BoolValue.Dynamic(() -> syncValue.getValue() == value, $ -> syncValue.setValue(value)); |
184 | | - } |
185 | | - |
186 | | - /** |
187 | | - * Get a BoolValue for use with toggle buttons which are "linked together," |
188 | | - * meaning only one of them can be pressed at a time. |
189 | | - */ |
190 | | - default BoolValue.Dynamic boolValueOf(IntSyncValue syncValue, int value) { |
191 | | - return new BoolValue.Dynamic(() -> syncValue.getValue() == value, $ -> syncValue.setValue(value)); |
192 | | - } |
193 | | - |
194 | | - class EnumRowBuilder<T extends Enum<T>> { |
195 | | - |
196 | | - private EnumSyncValue<T> syncValue; |
197 | | - private final Class<T> enumValue; |
198 | | - @Nullable |
199 | | - private IKey rowDescription; |
200 | | - @Nullable |
201 | | - private IDrawable[] background; |
202 | | - @Nullable |
203 | | - private IDrawable selectedBackground; |
204 | | - @Nullable |
205 | | - private IDrawable[] overlay; |
206 | | - @Nullable |
207 | | - private BiConsumer<T, ToggleButton> widgetExtras; |
208 | | - |
209 | | - public EnumRowBuilder(Class<T> enumValue) { |
210 | | - this.enumValue = enumValue; |
211 | | - } |
212 | | - |
213 | | - public EnumRowBuilder<T> value(EnumSyncValue<T> syncValue) { |
214 | | - this.syncValue = syncValue; |
215 | | - return this; |
216 | | - } |
217 | | - |
218 | | - /** |
219 | | - * Add an {@link IKey} to the row that will be right aligned at the end. |
220 | | - */ |
221 | | - public EnumRowBuilder<T> rowDescription(IKey lang) { |
222 | | - this.rowDescription = lang; |
223 | | - return this; |
224 | | - } |
225 | | - |
226 | | - /** |
227 | | - * Add a background to each {@link ToggleButton} when the button is not selected. |
228 | | - * |
229 | | - * @param background an array of {@link IDrawable}s in the same order as the {@link Enum} used to make this |
230 | | - * {@link EnumRowBuilder} |
231 | | - */ |
232 | | - public EnumRowBuilder<T> background(IDrawable... background) { |
233 | | - this.background = background; |
234 | | - return this; |
235 | | - } |
236 | | - |
237 | | - /** |
238 | | - * Add a background to each {@link ToggleButton} when the button is selected. |
239 | | - * |
240 | | - * @param selectedBackground an array of {@link IDrawable}s in the same order as the {@link Enum} used to make |
241 | | - * this {@link EnumRowBuilder} |
242 | | - */ |
243 | | - public EnumRowBuilder<T> selectedBackground(IDrawable selectedBackground) { |
244 | | - this.selectedBackground = selectedBackground; |
245 | | - return this; |
246 | | - } |
247 | | - |
248 | | - /** |
249 | | - * Add an overlay to each {@link ToggleButton}. |
250 | | - * |
251 | | - * @param overlay an array of {@link IDrawable}s in the same order as the {@link Enum} used to make this |
252 | | - * {@link EnumRowBuilder} |
253 | | - */ |
254 | | - public EnumRowBuilder<T> overlay(IDrawable... overlay) { |
255 | | - this.overlay = overlay; |
256 | | - return this; |
257 | | - } |
258 | | - |
259 | | - /** |
260 | | - * Add an overlay to each {@link ToggleButton} with a specific size. |
261 | | - * |
262 | | - * @param size the size to set the {@link IDrawable} to. |
263 | | - * @param overlay an array of {@link IDrawable}s in the same order as the {@link Enum} used to make this |
264 | | - * {@link EnumRowBuilder} |
265 | | - */ |
266 | | - public EnumRowBuilder<T> overlay(int size, IDrawable... overlay) { |
267 | | - this.overlay = new IDrawable[overlay.length]; |
268 | | - for (int i = 0; i < overlay.length; i++) { |
269 | | - this.overlay[i] = overlay[i].asIcon() |
270 | | - .size(size); |
271 | | - } |
272 | | - return this; |
273 | | - } |
274 | | - |
275 | | - public EnumRowBuilder<T> widgetExtras(BiConsumer<T, ToggleButton> widgetExtras) { |
276 | | - this.widgetExtras = widgetExtras; |
277 | | - return this; |
278 | | - } |
279 | | - |
280 | | - private BoolValue.Dynamic boolValueOf(EnumSyncValue<T> syncValue, T value) { |
281 | | - return new BoolValue.Dynamic(() -> syncValue.getValue() == value, $ -> syncValue.setValue(value)); |
282 | | - } |
283 | | - |
284 | | - public Flow build() { |
285 | | - Flow row = Flow.row() |
286 | | - .marginBottom(2) |
287 | | - .widthRel(1f) |
288 | | - .coverChildrenHeight(); |
289 | | - |
290 | | - if (this.enumValue != null && this.syncValue != null) { |
291 | | - for (T enumVal : enumValue.getEnumConstants()) { |
292 | | - ToggleButton button = new ToggleButton() |
293 | | - .marginRight(2) |
294 | | - .size(18) |
295 | | - .value(boolValueOf(this.syncValue, enumVal)); |
296 | | - |
297 | | - if (this.background != null && this.background.length > 0) { |
298 | | - button.background(this.background); |
299 | | - } else { |
300 | | - button.background(GTGuiTextures.MC_BUTTON); |
301 | | - } |
302 | | - |
303 | | - if (this.selectedBackground != null) { |
304 | | - button.selectedBackground(this.selectedBackground); |
305 | | - } else { |
306 | | - button.selectedBackground(GTGuiTextures.MC_BUTTON_DISABLED); |
307 | | - } |
308 | | - |
309 | | - if (this.overlay != null) { |
310 | | - button.overlay(this.overlay[enumVal.ordinal()]); |
311 | | - } |
312 | | - |
313 | | - if (this.widgetExtras != null) { |
314 | | - this.widgetExtras.accept(enumVal, button); |
315 | | - } |
316 | | - |
317 | | - row.child(button); |
318 | | - } |
319 | | - } |
320 | | - |
321 | | - if (this.rowDescription != null && !this.rowDescription.get().isEmpty()) { |
322 | | - row.child(this.rowDescription.asWidget() |
323 | | - .align(Alignment.CenterRight) |
324 | | - .height(18)); |
325 | | - } |
326 | | - |
327 | | - return row; |
328 | | - } |
329 | | - } |
330 | 168 | } |
0 commit comments