diff options
| author | miozune <miozune@gmail.com> | 2022-11-26 01:45:28 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-25 17:45:28 +0100 |
| commit | 9a2741128a78bb52eba50a631126e090a5a2abd8 (patch) | |
| tree | a90f47aa94951acb4050e45dc3ed60698e79cf32 /src/main/java/gregtech/common/items | |
| parent | 51537482fefc4f9c6d3fbd93d119c333a63dcd7b (diff) | |
| download | GT5-Unofficial-9a2741128a78bb52eba50a631126e090a5a2abd8.tar.gz GT5-Unofficial-9a2741128a78bb52eba50a631126e090a5a2abd8.tar.bz2 GT5-Unofficial-9a2741128a78bb52eba50a631126e090a5a2abd8.zip | |
Rewrite GUIs with ModularUI (#1381)
* Base work for ModularUI compat
* Remove useless interface
* Add almost all the widgets
* Invert method
* Refactor NEI stack placement positions
* NEI handlers on ModularUI
* Add some more docs
* AdvDebugStructureWriter
* Fix NEI progressbar not working
* PrimitiveBlastFurnace
* clean
* derp
* clean
* spotlessApply
* Boilers
* Buffers
* clean
* N by N slots containers
* Fix boilers not having bucket interaction
Put opening UI to individual MetaTEs
* Maintenance Hatch
* clean
* spotlessApply
* Add dependency
* IndustrialApiary
* Adapt to ModularUI change
* Base work for covers & fix crash with MP
* Fix crash with server
* Rewrite base work for covers
* Send initial cover data on cover GUI open
so that the time of showing incorrect data will be eliminated
* Covers part 1
* Rename package: ModularUI -> modularui
* Rename class: GT_UIInfo -> GT_UIInfos
* Fix build
* Covers part2
* Fix missing client check with tile UI & fix title overlap
* CoverTabLine
* Move cover window creators to inner class
* Fix crash with null base TE
* Close GUI when tile is broken
* Color cover window with tile colorization
* Change signature of addUIWidgets
* FluidFilter cover, FluidDisplaySlotWidget, BasicTank, BasicGenerator, Output Hatch, MicrowaveEnergyTransmitter, Teleporter, DigitalChest, DigitalTank
* Add title tab
* Move package: modularui -> modularui/widget
* Programmed circuit + IConfigurationCircuitSupport
* clean
* VolumetricFlask
* Remove integrated circuit overlay from recipe input slots
* Input Hatch & Quadruple Input Hatch
* Multiblock
* Deprecate old cover GUI
* BasicMachines
* Finish BasicMachine & NEI
* Expand DTPF NEI to 9 slots
* Fix ME input bus on MP
* Move AESlotWidget to public class
* Move GT_Recipe_Map constructors with mNEIUnificateOutput to setter method
* Move SteamTexture.Variant to outer enum
* Switch to remote repository
* oops
* Update MUI
* Update MUI
* Minor refactor for change amount buttons
* Display items and fluids that exceed usual count
* blah
* use +=, why didn't I do this
* Update MUI
* Move ModularUI to Base (#1510)
* Move ModularUI to Base
* Move most of the ModularUI functionality to `BaseTileEntity` (and `CoverableTileEntity`)
* `CommonMetaTileEntity` delegates ato the MetaTileEntity
* Added several interfaces (with defaults) to indicate if a tile/metatile override/implement certain behaviors.
* Moved `IConfigurationCircuitSupport` interface such that it will work with BaseTileEntity or a MetaTileEntity
* Address reviews
Co-authored-by: miozune <miozune@gmail.com>
* Update MUI
* Minor changes to NEI
* Return :facepalm:
* IGetTabIconSet override
* Some more changes to NEI
* Merge texture getter interfaces to new class GUITextureSet
* Remove BBF structure picture as it's auto-buildable now
* Make unified title tab style of texture angular
* Expose some boiler texture getters for addon
* Fix crash with cover GUI on pipe
* Lower the number of recipe per page for DTPF & update MUI
* Update MUI
* Fix crash with middle-clicking slot on circuit selection GUI
* Fix circuit selection window not syncing item from base machine
* Merge GT_NEI_AssLineHandler into GT_NEI_DefaultHandler
* Update MUI
* Add in TecTech multi message
* Allow changing the way of binding player inventory
* Update MUI
* Update MUI
* Update MUI
* Update MUI
* Update MUI
* Make MUI non-transitive to allow addons to use their own version
* Force enable mixin
* Format fluid amount tooltip
* Add GUITextureSet.STEAM
* Add guard against null ModularWindow creation
* Add constructors for Muffler Hatch with inventory
* Fix output slot on digital chest and tank allowing insertion
* Don't log null ModularWindow
* Add default implementation for IHasWorldObjectAndCoords#openGUI
* Make openGTTileEntityUI accept MultiTE & cleanup
Co-authored-by: Jason Mitchell <mitchej@gmail.com>
Diffstat (limited to 'src/main/java/gregtech/common/items')
| -rw-r--r-- | src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java | 15 | ||||
| -rw-r--r-- | src/main/java/gregtech/common/items/GT_VolumetricFlask.java | 105 |
2 files changed, 101 insertions, 19 deletions
diff --git a/src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java b/src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java index d82d307ee8..a5842bb9c1 100644 --- a/src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java +++ b/src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java @@ -3,7 +3,7 @@ package gregtech.common.items; import static gregtech.GT_Mod.GT_FML_LOGGER; import static gregtech.api.enums.GT_Values.RES_PATH_ITEM; -import cpw.mods.fml.common.FMLCommonHandler; +import com.gtnewhorizons.modularui.api.UIInfos; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.GregTech_API; @@ -11,7 +11,6 @@ import gregtech.api.enums.GT_Values; import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; -import gregtech.api.gui.GT_GUIDialogSelectItem; import gregtech.api.interfaces.INetworkUpdatableItem; import gregtech.api.items.GT_Generic_Item; import gregtech.api.net.GT_Packet_UpdateItem; @@ -21,6 +20,7 @@ import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Utility; +import gregtech.common.gui.modularui.uifactory.SelectItemUIFactory; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -270,20 +270,19 @@ public class GT_IntegratedCircuit_Item extends GT_Generic_Item implements INetwo } configuratorStack = player.inventory.mainInventory[configurator.getKey()]; } - openSelectorGui(configuratorStack, stack.getItemDamage()); + openSelectorGui(configuratorStack, stack.getItemDamage(), player); return stack; } - private void openSelectorGui(ItemStack configurator, int meta) { - FMLCommonHandler.instance() - .showGuiScreen(new GT_GUIDialogSelectItem( + private void openSelectorGui(ItemStack configurator, int meta, EntityPlayer player) { + UIInfos.openClientUI(player, buildContext -> new SelectItemUIFactory( StatCollector.translateToLocal("GT5U.item.programmed_circuit.select.header"), configurator, - null, GT_IntegratedCircuit_Item::onConfigured, ALL_VARIANTS, meta, - true)); + true) + .createWindow(buildContext)); } private static void onConfigured(ItemStack stack) { diff --git a/src/main/java/gregtech/common/items/GT_VolumetricFlask.java b/src/main/java/gregtech/common/items/GT_VolumetricFlask.java index f4ee8a7c85..0d7d503690 100644 --- a/src/main/java/gregtech/common/items/GT_VolumetricFlask.java +++ b/src/main/java/gregtech/common/items/GT_VolumetricFlask.java @@ -6,19 +6,31 @@ import static ic2.core.util.LiquidUtil.drainContainerStack; import static ic2.core.util.LiquidUtil.fillContainerStack; import static ic2.core.util.LiquidUtil.placeFluid; +import com.gtnewhorizons.modularui.api.ModularUITextures; +import com.gtnewhorizons.modularui.api.math.Alignment; +import com.gtnewhorizons.modularui.api.math.Color; +import com.gtnewhorizons.modularui.api.math.MathExpression; +import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.api.math.Size; +import com.gtnewhorizons.modularui.api.screen.IItemWithModularUI; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.VanillaButtonWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.BaseTextFieldWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.enums.GT_Values; -import gregtech.api.interfaces.INetworkUpdatableItem; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.items.GT_Generic_Item; import gregtech.api.util.GT_Utility; import ic2.core.util.LiquidUtil; import java.util.List; +import java.util.function.Function; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -37,7 +49,7 @@ import net.minecraftforge.fluids.IFluidBlock; import net.minecraftforge.fluids.IFluidContainerItem; import net.minecraftforge.fluids.IFluidHandler; -public class GT_VolumetricFlask extends GT_Generic_Item implements IFluidContainerItem, INetworkUpdatableItem { +public class GT_VolumetricFlask extends GT_Generic_Item implements IFluidContainerItem, IItemWithModularUI { private final int maxCapacity; private final String unlocalFlaskName; @@ -55,7 +67,7 @@ public class GT_VolumetricFlask extends GT_Generic_Item implements IFluidContain @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (!world.isRemote && isEmpty(stack) && getMovingObjectPositionFromPlayer(world, player, true) == null) - player.openGui(GT_Values.GT, 1010, world, 0, 0, 0); + GT_UIInfos.openPlayerHeldItemUI(player); return super.onItemRightClick(stack, world, player); } @@ -300,12 +312,83 @@ public class GT_VolumetricFlask extends GT_Generic_Item implements IFluidContain } @Override - public boolean receive(ItemStack stack, EntityPlayerMP player, NBTTagCompound tag) { - if (stack != null && stack.stackSize > 0) { - Item item = stack.getItem(); - if (item == this) setCapacity(stack, tag.getInteger("cap")); - return true; + public ModularWindow createWindow(UIBuildContext buildContext, ItemStack stack) { + if (!(stack.getItem() instanceof GT_VolumetricFlask)) return null; + return new VolumetricFlaskUIFactory(buildContext, stack).createWindow(); + } + + private class VolumetricFlaskUIFactory { + + private final UIBuildContext buildContext; + private final int maxCapacity; + private TextFieldWidget textField; + + public VolumetricFlaskUIFactory(UIBuildContext buildContext, ItemStack flask) { + this.buildContext = buildContext; + this.maxCapacity = ((GT_VolumetricFlask) flask.getItem()).getMaxCapacity(); + } + + public ModularWindow createWindow() { + ModularWindow.Builder builder = ModularWindow.builder(176, 107); + builder.setBackground(ModularUITextures.VANILLA_BACKGROUND); + + textField = new TextFieldWidget() { + @Override + public void onDestroy() { + if (isClient()) return; + setCapacity(getCurrentItem(), (int) MathExpression.parseMathExpression(getText(), 1)); + getContext().onWidgetUpdate(); + } + }; + textField.setText( + String.valueOf(((GT_VolumetricFlask) getCurrentItem().getItem()).getCapacity(getCurrentItem()))); + builder.widget(textField + .setNumbers(() -> 1, () -> maxCapacity) + .setPattern(BaseTextFieldWidget.NATURAL_NUMS) + .setTextAlignment(Alignment.CenterLeft) + .setTextColor(Color.WHITE.dark(1)) + .setFocusOnGuiOpen(true) + .setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD_LIGHT_GRAY.withOffset(-1, -1, 2, 2)) + .setPos(60, 55) + .setSize(59, 12)); + + addChangeAmountButton(builder, "+1", new Pos2d(20, 26), new Size(22, 20), val -> val + 1); + addChangeAmountButton(builder, "+10", new Pos2d(48, 26), new Size(28, 20), val -> val + 10); + addChangeAmountButton(builder, "+100", new Pos2d(82, 26), new Size(32, 20), val -> val + 100); + addChangeAmountButton(builder, "+1000", new Pos2d(120, 26), new Size(38, 20), val -> val + 1000); + addChangeAmountButton(builder, "-1", new Pos2d(20, 75), new Size(22, 20), val -> val - 1); + addChangeAmountButton(builder, "-10", new Pos2d(48, 75), new Size(28, 20), val -> val - 10); + addChangeAmountButton(builder, "-100", new Pos2d(82, 75), new Size(32, 20), val -> val - 100); + addChangeAmountButton(builder, "-1000", new Pos2d(120, 75), new Size(38, 20), val -> val - 1000); + builder.widget(new VanillaButtonWidget() + .setDisplayString("Accept") + .setClickableGetter(() -> MathExpression.parseMathExpression(textField.getText()) > 0) + .setOnClick((clickData, widget) -> { + textField.onRemoveFocus(); + widget.getWindow().tryClose(); + }) + .setPos(128, 51) + .setSize(38, 20)); + + return builder.build(); + } + + private void addChangeAmountButton( + ModularWindow.Builder builder, String text, Pos2d pos, Size size, Function<Integer, Integer> function) { + builder.widget(new VanillaButtonWidget() + .setDisplayString(text) + .setOnClick((clickData, widget) -> { + String currentText = textField.getText(); + int amount = (int) MathExpression.parseMathExpression(currentText, 1); + amount = Math.min(maxCapacity, Math.max(1, function.apply(amount))); + textField.setText(String.valueOf(amount)); + }) + .setPos(pos) + .setSize(size)); + } + + private ItemStack getCurrentItem() { + return buildContext.getPlayer().inventory.getCurrentItem(); } - return false; } } |
