diff options
author | Maxim <maxim235@gmx.de> | 2023-02-26 18:26:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-26 18:26:27 +0100 |
commit | 2651ea95e7af46b2d599f9e6eab25345595c9459 (patch) | |
tree | 6a3b063c1562e4387a3769c6284d65a218787b19 /src/main/java/gregtech/api/metatileentity | |
parent | 3175e64e7201fe2f8765e54156f26d684b11276b (diff) | |
download | GT5-Unofficial-2651ea95e7af46b2d599f9e6eab25345595c9459.tar.gz GT5-Unofficial-2651ea95e7af46b2d599f9e6eab25345595c9459.tar.bz2 GT5-Unofficial-2651ea95e7af46b2d599f9e6eab25345595c9459.zip |
Enhanced multiblock GUIs (#1767)
* Added more buttons to multiblock GUI
* Migrated PA to new GUI
* Migrated Nano Forge to new GUI
* Migrated PCB Factory to new GUI
* Reband void protection to void excess to match GTPP logic
* Adjust fusion reactor GUI size
* Added statics for new NBT keys
* Added getters for button status
* Rename methods to reflect that they are about void excess, not the opposite
* Added button textures
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity')
-rw-r--r-- | src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java | 248 |
1 files changed, 240 insertions, 8 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index 80b6723d81..bcdb456ecc 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -1,6 +1,7 @@ package gregtech.api.metatileentity.implementations; import static gregtech.api.enums.GT_Values.*; +import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; import static mcp.mobius.waila.api.SpecialChars.GREEN; import static mcp.mobius.waila.api.SpecialChars.RED; import static mcp.mobius.waila.api.SpecialChars.RESET; @@ -25,13 +26,13 @@ import net.minecraftforge.fluids.FluidStack; import org.lwjgl.input.Keyboard; import com.google.common.collect.Iterables; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.UITexture; +import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; -import com.gtnewhorizons.modularui.common.widget.DrawableWidget; -import com.gtnewhorizons.modularui.common.widget.DynamicPositionedColumn; -import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; -import com.gtnewhorizons.modularui.common.widget.SlotWidget; -import com.gtnewhorizons.modularui.common.widget.TextWidget; +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.common.widget.*; import gregtech.GT_Mod; import gregtech.api.GregTech_API; @@ -41,6 +42,7 @@ import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.modularui.IAddGregtechLogo; import gregtech.api.interfaces.modularui.IAddUIWidgets; +import gregtech.api.interfaces.modularui.IBindPlayerInventoryUI; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.items.GT_MetaGenerated_Tool; import gregtech.api.metatileentity.MetaTileEntity; @@ -53,7 +55,7 @@ import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_DrillerBase import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_LargeTurbine; public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity - implements IAddGregtechLogo, IAddUIWidgets { + implements IAddGregtechLogo, IAddUIWidgets, IBindPlayerInventoryUI { public static boolean disableMaintenance; public boolean mMachine = false, mWrench = false, mScrewdriver = false, mSoftHammer = false, mHardHammer = false, @@ -70,6 +72,12 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity public float damageFactorHigh = 0.6f; public boolean mLockedToSingleRecipe = false; + protected boolean inputSeparation = false; + protected boolean voidExcess = true; + protected boolean batchMode = false; + protected static String INPUT_SEPARATION_NBT_KEY = "inputSeparation"; + protected static String VOID_EXCESS_NBT_KEY = "voidExcess"; + protected static String BATCH_MODE_NBT_KEY = "batchMode"; public GT_Single_Recipe_Check mSingleRecipeCheck = null; public ArrayList<GT_MetaTileEntity_Hatch_Input> mInputHatches = new ArrayList<>(); @@ -205,6 +213,9 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity aNBT.setBoolean("mHardHammer", mHardHammer); aNBT.setBoolean("mSolderingTool", mSolderingTool); aNBT.setBoolean("mCrowbar", mCrowbar); + aNBT.setBoolean(BATCH_MODE_NBT_KEY, batchMode); + aNBT.setBoolean(INPUT_SEPARATION_NBT_KEY, inputSeparation); + aNBT.setBoolean(VOID_EXCESS_NBT_KEY, voidExcess); } @Override @@ -218,6 +229,9 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity mPollution = aNBT.getInteger("mPollution"); mRuntime = aNBT.getInteger("mRuntime"); mLockedToSingleRecipe = aNBT.getBoolean("mLockedToSingleRecipe"); + batchMode = aNBT.getBoolean(BATCH_MODE_NBT_KEY); + inputSeparation = aNBT.getBoolean(INPUT_SEPARATION_NBT_KEY); + voidExcess = aNBT.getBoolean(VOID_EXCESS_NBT_KEY); int aOutputItemsLength = aNBT.getInteger("mOutputItemsLength"); if (aOutputItemsLength > 0) { @@ -1343,15 +1357,99 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity } @Override + public int getGUIWidth() { + return 198; + } + + @Override + public int getGUIHeight() { + return 192; + } + + /** + * @return if the multi supports input separation. If you want to use it you need to use {@link #inputSeparation}. + */ + protected boolean isInputSeparationButtonEnabled() { + return false; + } + + /** + * @return if the multi supports batch mode. If you want to use it you need to use {@link #batchMode}. + */ + protected boolean isBatchModeButtonEnabled() { + return false; + } + + /** + * @return if the multi supports void excess to be toggled. If you want to use it you need to use + * {@link #voidExcess}. + */ + protected boolean isVoidExcessButtonEnabled() { + return false; + } + + /** + * @return true if input separation is enabled, else false. This is getter is used for displaying the icon in the + * GUI + */ + protected boolean isInputSeparationEnabled() { + return inputSeparation; + } + + /** + * @return true if batch mode is enabled, else false. This is getter is used for displaying the icon in the GUI + */ + protected boolean isBatchModeEnabled() { + return batchMode; + } + + /** + * @return true if void excess is enabled, else false. This is getter is used for displaying the icon in the GUI + */ + protected boolean isVoidExcessEnabled() { + return voidExcess; + } + + /** + * @return true if recipe locking is enabled, else false. This is getter is used for displaying the icon in the GUI + */ + protected boolean isRecipeLockingEnabled() { + return mLockedToSingleRecipe; + } + + @Override + public void bindPlayerInventoryUI(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.bindPlayerInventory(buildContext.getPlayer(), new Pos2d(7, 109), getGUITextureSet().getItemSlot()); + } + + @Override public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { builder.widget( - new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK).setPos(7, 4).setSize(143, 75)); + new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK).setPos(4, 4).setSize(190, 85)); final SlotWidget inventorySlot = new SlotWidget(inventoryHandler, 1); - builder.widget(inventorySlot.setPos(151, 4)); + builder.widget(inventorySlot.setPos(173, 167).setBackground(GT_UITextures.SLOT_DARK_GRAY)); final DynamicPositionedColumn screenElements = new DynamicPositionedColumn(); drawTexts(screenElements, inventorySlot); builder.widget(screenElements); + + builder.widget(createPowerSwitchButton()) + .widget(new FakeSyncWidget.BooleanSyncer(() -> getBaseMetaTileEntity().isAllowedToWork(), val -> { + if (val) getBaseMetaTileEntity().enableWorking(); + else getBaseMetaTileEntity().disableWorking(); + })); + + builder.widget(createVoidExcessButton()) + .widget(new FakeSyncWidget.BooleanSyncer(() -> voidExcess, val -> voidExcess = val)); + + builder.widget(createInputSeparationButton()) + .widget(new FakeSyncWidget.BooleanSyncer(() -> inputSeparation, val -> inputSeparation = val)); + + builder.widget(createBatchModeButton()) + .widget(new FakeSyncWidget.BooleanSyncer(() -> batchMode, val -> batchMode = val)); + + builder.widget(createLockToSingleRecipeButton()).widget( + new FakeSyncWidget.BooleanSyncer(() -> mLockedToSingleRecipe, val -> mLockedToSingleRecipe = val)); } @Override @@ -1456,4 +1554,138 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity return false; })); } + + protected ButtonWidget createPowerSwitchButton() { + Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { + if (getBaseMetaTileEntity().isAllowedToWork()) { + getBaseMetaTileEntity().disableWorking(); + } else { + getBaseMetaTileEntity().enableWorking(); + } + }).setPlayClickSound(true).setBackground(() -> { + List<UITexture> ret = new ArrayList<>(); + ret.add(GT_UITextures.BUTTON_STANDARD); + if (getBaseMetaTileEntity().isAllowedToWork()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_POWER_SWITCH_ON); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_POWER_SWITCH_OFF); + } + return ret.toArray(new IDrawable[0]); + }).setPos(174, 148).setSize(16, 16); + button.addTooltip(StatCollector.translateToLocal("GT5U.gui.button.power_switch")) + .setTooltipShowUpDelay(TOOLTIP_DELAY); + return (ButtonWidget) button; + } + + protected ButtonWidget createVoidExcessButton() { + Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { + if (isVoidExcessButtonEnabled()) { + voidExcess = !voidExcess; + } + }).setPlayClickSound(true).setBackground(() -> { + List<UITexture> ret = new ArrayList<>(); + ret.add(GT_UITextures.BUTTON_STANDARD); + if (isVoidExcessButtonEnabled()) { + if (isVoidExcessEnabled()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_VOID_EXCESS_ON); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_VOID_EXCESS_OFF); + } + } else { + if (isVoidExcessEnabled()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_VOID_EXCESS_ON_DISABLED); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_VOID_EXCESS_OFF_DISABLED); + } + } + return ret.toArray(new IDrawable[0]); + }).setPos(8, 91).setSize(16, 16); + button.addTooltip(StatCollector.translateToLocal("GT5U.gui.button.void_excess")) + .setTooltipShowUpDelay(TOOLTIP_DELAY); + return (ButtonWidget) button; + } + + protected ButtonWidget createInputSeparationButton() { + Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { + if (isInputSeparationButtonEnabled()) { + inputSeparation = !inputSeparation; + } + }).setPlayClickSound(true).setBackground(() -> { + List<UITexture> ret = new ArrayList<>(); + ret.add(GT_UITextures.BUTTON_STANDARD); + if (isInputSeparationButtonEnabled()) { + if (isInputSeparationEnabled()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_INPUT_SEPARATION_ON); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_INPUT_SEPARATION_OFF); + } + } else { + if (isInputSeparationEnabled()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_INPUT_SEPARATION_ON_DISABLED); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_INPUT_SEPARATION_OFF_DISABLED); + } + } + return ret.toArray(new IDrawable[0]); + }).setPos(26, 91).setSize(16, 16); + button.addTooltip(StatCollector.translateToLocal("GT5U.gui.button.input_separation")) + .setTooltipShowUpDelay(TOOLTIP_DELAY); + return (ButtonWidget) button; + } + + protected ButtonWidget createBatchModeButton() { + Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { + if (isBatchModeButtonEnabled()) { + batchMode = !batchMode; + } + }).setPlayClickSound(true).setBackground(() -> { + List<UITexture> ret = new ArrayList<>(); + ret.add(GT_UITextures.BUTTON_STANDARD); + if (isBatchModeButtonEnabled()) { + if (isBatchModeEnabled()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_BATCH_MODE_ON); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_BATCH_MODE_OFF); + } + } else { + if (isBatchModeEnabled()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_BATCH_MODE_ON_DISABLED); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_BATCH_MODE_OFF_DISABLED); + } + } + return ret.toArray(new IDrawable[0]); + }).setPos(44, 91).setSize(16, 16); + button.addTooltip(StatCollector.translateToLocal("GT5U.gui.button.batch_mode")) + .setTooltipShowUpDelay(TOOLTIP_DELAY); + return (ButtonWidget) button; + } + + protected ButtonWidget createLockToSingleRecipeButton() { + Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { + if (supportsSingleRecipeLocking()) { + mLockedToSingleRecipe = !mLockedToSingleRecipe; + } + }).setPlayClickSound(true).setBackground(() -> { + List<UITexture> ret = new ArrayList<>(); + ret.add(GT_UITextures.BUTTON_STANDARD); + if (supportsSingleRecipeLocking()) { + if (isRecipeLockingEnabled()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_RECIPE_LOCKED); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_RECIPE_UNLOCKED); + } + } else { + if (isRecipeLockingEnabled()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_RECIPE_LOCKED_DISABLED); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_RECIPE_UNLOCKED_DISABLED); + } + } + return ret.toArray(new IDrawable[0]); + }).setPos(62, 91).setSize(16, 16); + button.addTooltip(StatCollector.translateToLocal("GT5U.gui.button.lock_recipe")) + .setTooltipShowUpDelay(TOOLTIP_DELAY); + return (ButtonWidget) button; + } } |