|
1 | 1 | package gregtech.common.covers;
|
2 | 2 |
|
| 3 | +import com.cleanroommc.modularui.api.drawable.IKey; |
| 4 | +import com.cleanroommc.modularui.api.widget.Interactable; |
3 | 5 | import com.cleanroommc.modularui.factory.SidedPosGuiData;
|
4 | 6 | import com.cleanroommc.modularui.screen.ModularPanel;
|
| 7 | +import com.cleanroommc.modularui.utils.Alignment; |
| 8 | +import com.cleanroommc.modularui.utils.MouseData; |
| 9 | +import com.cleanroommc.modularui.value.sync.EnumSyncValue; |
5 | 10 | import com.cleanroommc.modularui.value.sync.GuiSyncManager;
|
6 | 11 |
|
| 12 | +import com.cleanroommc.modularui.value.sync.IntSyncValue; |
| 13 | +import com.cleanroommc.modularui.widget.ParentWidget; |
| 14 | + |
| 15 | +import com.cleanroommc.modularui.widget.Widget; |
| 16 | +import com.cleanroommc.modularui.widgets.ButtonWidget; |
| 17 | +import com.cleanroommc.modularui.widgets.ToggleButton; |
| 18 | +import com.cleanroommc.modularui.widgets.layout.Column; |
| 19 | +import com.cleanroommc.modularui.widgets.layout.Row; |
| 20 | +import com.cleanroommc.modularui.widgets.textfield.TextFieldWidget; |
| 21 | + |
7 | 22 | import gregtech.api.GTValues;
|
8 | 23 | import gregtech.api.capability.GregtechDataCodes;
|
9 | 24 | import gregtech.api.capability.GregtechTileCapabilities;
|
|
21 | 36 | import gregtech.api.gui.widgets.LabelWidget;
|
22 | 37 | import gregtech.api.gui.widgets.TextFieldWidget2;
|
23 | 38 | import gregtech.api.gui.widgets.WidgetGroup;
|
| 39 | +import gregtech.api.mui.GTGuiTextures; |
24 | 40 | import gregtech.api.mui.GTGuis;
|
25 | 41 | import gregtech.api.util.GTTransferUtils;
|
26 | 42 | import gregtech.client.renderer.texture.Textures;
|
|
30 | 46 | import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
31 | 47 | import net.minecraft.entity.player.EntityPlayer;
|
32 | 48 | import net.minecraft.entity.player.EntityPlayerMP;
|
| 49 | +import net.minecraft.item.EnumDyeColor; |
33 | 50 | import net.minecraft.nbt.NBTTagCompound;
|
34 | 51 | import net.minecraft.network.PacketBuffer;
|
35 | 52 | import net.minecraft.tileentity.TileEntity;
|
@@ -242,8 +259,107 @@ public boolean usesMui2() {
|
242 | 259 |
|
243 | 260 | @Override
|
244 | 261 | public ModularPanel buildUI(SidedPosGuiData guiData, GuiSyncManager guiSyncManager) {
|
245 |
| - return GTGuis.createPanel(this, 100, 100) |
246 |
| - .child(CoverWithUI.createTitleRow(getPickItem())); |
| 262 | + var panel = GTGuis.createPanel(this, 176,192); |
| 263 | + |
| 264 | + //todo set fluid filter stuffs here |
| 265 | + |
| 266 | + return panel.child(CoverWithUI.createTitleRow(getPickItem())) |
| 267 | + .child(createUI(panel, guiSyncManager)) |
| 268 | + .bindPlayerInventory(); |
| 269 | + } |
| 270 | + |
| 271 | + protected ParentWidget<?> createUI(ModularPanel mainPanel, GuiSyncManager syncManager) { |
| 272 | + EnumSyncValue<ManualImportExportMode> manualIOmode = new EnumSyncValue<>(ManualImportExportMode.class, |
| 273 | + this::getManualImportExportMode, this::setManualImportExportMode); |
| 274 | + |
| 275 | + IntSyncValue throughput = new IntSyncValue(this::getTransferRate, this::setTransferRate); |
| 276 | + |
| 277 | + syncManager.syncValue("manual_io", manualIOmode); |
| 278 | + |
| 279 | + return new Column().top(24).margin(7, 0) |
| 280 | + .widthRel(1f).coverChildrenHeight() |
| 281 | + .child(new Row().coverChildrenHeight() |
| 282 | + .marginBottom(2).widthRel(1f) |
| 283 | + .child(new ButtonWidget<>() |
| 284 | + .left(0).width(18) |
| 285 | + .onMousePressed(mouseButton -> { |
| 286 | + throughput.updateCacheFromSource(false); |
| 287 | + int val = throughput.getValue() - getIncrementValue(MouseData.create(mouseButton)); |
| 288 | + throughput.setValue(val, true, true); |
| 289 | + Interactable.playButtonClickSound(); |
| 290 | + return true; |
| 291 | + }) |
| 292 | + .onUpdateListener(w -> w.overlay(createAdjustOverlay(false)))) |
| 293 | + .child(new TextFieldWidget() |
| 294 | + .left(18).right(18) |
| 295 | + .setTextColor(EnumDyeColor.WHITE.getColorValue()) |
| 296 | + .setNumbers(1, maxFluidTransferRate) |
| 297 | + .value(throughput) |
| 298 | + .background(GTGuiTextures.DISPLAY) |
| 299 | + .onUpdateListener(w -> { |
| 300 | + if (throughput.updateCacheFromSource(false)) { |
| 301 | + w.setText(throughput.getStringValue()); |
| 302 | + } |
| 303 | + })) |
| 304 | + .child(new ButtonWidget<>() |
| 305 | + .right(0).width(18) |
| 306 | + .onMousePressed(mouseButton -> { |
| 307 | + throughput.updateCacheFromSource(false); |
| 308 | + int val = throughput.getValue() + getIncrementValue(MouseData.create(mouseButton)); |
| 309 | + throughput.setValue(val, true, true); |
| 310 | + Interactable.playButtonClickSound(); |
| 311 | + return true; |
| 312 | + }) |
| 313 | + .onUpdateListener(w -> w.overlay(createAdjustOverlay(true))))) |
| 314 | + .child(getFluidFilterContainer() |
| 315 | + .initUI(mainPanel, syncManager)) |
| 316 | + .child(new Row().coverChildrenHeight() |
| 317 | + .marginBottom(2).widthRel(1f) |
| 318 | + .child(createManualIoButton(manualIOmode, ManualImportExportMode.DISABLED)) |
| 319 | + .child(createManualIoButton(manualIOmode, ManualImportExportMode.UNFILTERED)) |
| 320 | + .child(createManualIoButton(manualIOmode, ManualImportExportMode.FILTERED)) |
| 321 | + .child(IKey.lang("Manual IO Mode") |
| 322 | + .asWidget() |
| 323 | + .align(Alignment.CenterRight) |
| 324 | + .height(18))); |
| 325 | + } |
| 326 | + |
| 327 | + private Widget<ToggleButton> createManualIoButton(EnumSyncValue<ManualImportExportMode> value, ManualImportExportMode mode) { |
| 328 | + return new ToggleButton().size(18) |
| 329 | + .value(boolValueOf(value, mode)) |
| 330 | + .background(GTGuiTextures.MC_BUTTON_DISABLED) |
| 331 | + .selectedBackground(GTGuiTextures.MC_BUTTON) |
| 332 | + .overlay(GTGuiTextures.MANUAL_IO_OVERLAY[mode.ordinal()]) |
| 333 | + .addTooltipLine(switch (mode) { |
| 334 | + case DISABLED -> IKey.lang("cover.universal.manual_import_export.mode.disabled"); |
| 335 | + case UNFILTERED -> IKey.lang("cover.universal.manual_import_export.mode.unfiltered"); |
| 336 | + case FILTERED -> IKey.lang("cover.universal.manual_import_export.mode.filtered"); |
| 337 | + }); |
| 338 | + } |
| 339 | + |
| 340 | + protected int getIncrementValue(MouseData data) { |
| 341 | + int adjust = 1; |
| 342 | + if (data.shift) adjust *= 4; |
| 343 | + if (data.ctrl) adjust *= 16; |
| 344 | + if (data.alt) adjust *= 64; |
| 345 | + return adjust; |
| 346 | + } |
| 347 | + |
| 348 | + protected IKey createAdjustOverlay(boolean increment) { |
| 349 | + final StringBuilder builder = new StringBuilder(); |
| 350 | + builder.append(increment ? '+' : '-'); |
| 351 | + builder.append(getIncrementValue(MouseData.create(-1))); |
| 352 | + |
| 353 | + float scale = 1f; |
| 354 | + if (builder.length() == 3) { |
| 355 | + scale = 0.8f; |
| 356 | + } else if (builder.length() == 4) { |
| 357 | + scale = 0.6f; |
| 358 | + } else if (builder.length() > 4) { |
| 359 | + scale = 0.5f; |
| 360 | + } |
| 361 | + return IKey.str(builder.toString()) |
| 362 | + .scale(scale); |
247 | 363 | }
|
248 | 364 |
|
249 | 365 | public static Function<String, String> getTextFieldValidator(IntSupplier maxSupplier) {
|
@@ -291,12 +407,14 @@ public void readCustomData(int discriminator, @NotNull PacketBuffer buf) {
|
291 | 407 | public void writeInitialSyncData(@NotNull PacketBuffer packetBuffer) {
|
292 | 408 | super.writeInitialSyncData(packetBuffer);
|
293 | 409 | packetBuffer.writeEnumValue(pumpMode);
|
| 410 | + getFluidFilterContainer().writeInitialSyncData(packetBuffer); |
294 | 411 | }
|
295 | 412 |
|
296 | 413 | @Override
|
297 | 414 | public void readInitialSyncData(@NotNull PacketBuffer packetBuffer) {
|
298 | 415 | super.readInitialSyncData(packetBuffer);
|
299 | 416 | this.pumpMode = packetBuffer.readEnumValue(PumpMode.class);
|
| 417 | + getFluidFilterContainer().readInitialSyncData(packetBuffer); |
300 | 418 | }
|
301 | 419 |
|
302 | 420 | @Override
|
|
0 commit comments