|
7 | 7 | import gregtech.api.capability.impl.EnergyContainerHandler; |
8 | 8 | import gregtech.api.capability.impl.NotifiableItemStackHandler; |
9 | 9 | import gregtech.api.capability.impl.miner.MinerLogic; |
10 | | -import gregtech.api.gui.GuiTextures; |
11 | | -import gregtech.api.gui.ModularUI; |
12 | | -import gregtech.api.gui.widgets.AdvancedTextWidget; |
13 | | -import gregtech.api.gui.widgets.SlotWidget; |
14 | 10 | import gregtech.api.items.itemhandlers.GTItemStackHandler; |
15 | 11 | import gregtech.api.metatileentity.IDataInfoProvider; |
16 | 12 | import gregtech.api.metatileentity.MetaTileEntity; |
17 | 13 | import gregtech.api.metatileentity.TieredMetaTileEntity; |
18 | 14 | import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; |
| 15 | +import gregtech.api.mui.GTGuiTextures; |
| 16 | +import gregtech.api.mui.GTGuis; |
| 17 | +import gregtech.api.mui.TextStandards; |
| 18 | +import gregtech.api.util.KeyUtil; |
19 | 19 | import gregtech.client.renderer.texture.Textures; |
20 | 20 | import gregtech.core.sound.GTSoundEvents; |
21 | 21 |
|
|
26 | 26 | import net.minecraft.network.PacketBuffer; |
27 | 27 | import net.minecraft.util.*; |
28 | 28 | import net.minecraft.util.text.ITextComponent; |
29 | | -import net.minecraft.util.text.Style; |
30 | 29 | import net.minecraft.util.text.TextComponentTranslation; |
31 | 30 | import net.minecraft.util.text.TextFormatting; |
32 | 31 | import net.minecraft.world.World; |
|
40 | 39 | import codechicken.lib.render.CCRenderState; |
41 | 40 | import codechicken.lib.render.pipeline.IVertexOperation; |
42 | 41 | import codechicken.lib.vec.Matrix4; |
| 42 | +import com.cleanroommc.modularui.api.drawable.IKey; |
| 43 | +import com.cleanroommc.modularui.factory.PosGuiData; |
| 44 | +import com.cleanroommc.modularui.screen.ModularPanel; |
| 45 | +import com.cleanroommc.modularui.screen.UISettings; |
| 46 | +import com.cleanroommc.modularui.value.sync.BooleanSyncValue; |
| 47 | +import com.cleanroommc.modularui.value.sync.IntSyncValue; |
| 48 | +import com.cleanroommc.modularui.value.sync.PanelSyncManager; |
| 49 | +import com.cleanroommc.modularui.widgets.SlotGroupWidget; |
| 50 | +import com.cleanroommc.modularui.widgets.slot.ItemSlot; |
43 | 51 | import org.jetbrains.annotations.NotNull; |
44 | 52 | import org.jetbrains.annotations.Nullable; |
45 | 53 |
|
@@ -96,69 +104,85 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, |
96 | 104 | } |
97 | 105 |
|
98 | 106 | @Override |
99 | | - protected ModularUI createUI(@NotNull EntityPlayer entityPlayer) { |
100 | | - int rowSize = (int) Math.sqrt(inventorySize); |
101 | | - ModularUI.Builder builder = new ModularUI.Builder(GuiTextures.BACKGROUND, 195, 176); |
102 | | - builder.bindPlayerInventory(entityPlayer.inventory, 94); |
103 | | - |
104 | | - if (getTier() == GTValues.HV) { |
105 | | - for (int y = 0; y < rowSize; y++) { |
106 | | - for (int x = 0; x < rowSize; x++) { |
107 | | - int index = y * rowSize + x; |
108 | | - builder.widget( |
109 | | - new SlotWidget(exportItems, index, 151 - rowSize * 9 + x * 18, 18 + y * 18, true, false) |
110 | | - .setBackgroundTexture(GuiTextures.SLOT)); |
111 | | - } |
112 | | - } |
113 | | - } else { |
114 | | - for (int y = 0; y < rowSize; y++) { |
115 | | - for (int x = 0; x < rowSize; x++) { |
116 | | - int index = y * rowSize + x; |
117 | | - builder.widget( |
118 | | - new SlotWidget(exportItems, index, 142 - rowSize * 9 + x * 18, 18 + y * 18, true, false) |
119 | | - .setBackgroundTexture(GuiTextures.SLOT)); |
120 | | - } |
121 | | - } |
122 | | - } |
123 | | - |
124 | | - builder.image(7, 16, 105, 75, GuiTextures.DISPLAY) |
125 | | - .label(6, 6, getMetaFullName()); |
126 | | - builder.widget(new AdvancedTextWidget(10, 19, this::addDisplayText, 0xFFFFFF) |
127 | | - .setMaxWidthLimit(84)); |
128 | | - builder.widget(new AdvancedTextWidget(70, 19, this::addDisplayText2, 0xFFFFFF) |
129 | | - .setMaxWidthLimit(84)); |
130 | | - builder.widget(new SlotWidget(chargerInventory, 0, 171, 152) |
131 | | - .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.CHARGER_OVERLAY)); |
132 | | - |
133 | | - return builder.build(getHolder(), entityPlayer); |
134 | | - } |
135 | | - |
136 | | - private void addDisplayText(@NotNull List<ITextComponent> textList) { |
137 | | - int workingArea = getWorkingArea(minerLogic.getCurrentRadius()); |
138 | | - textList.add(new TextComponentTranslation("gregtech.machine.miner.startx", this.minerLogic.getX().get())); |
139 | | - textList.add(new TextComponentTranslation("gregtech.machine.miner.starty", this.minerLogic.getY().get())); |
140 | | - textList.add(new TextComponentTranslation("gregtech.machine.miner.startz", this.minerLogic.getZ().get())); |
141 | | - textList.add(new TextComponentTranslation("gregtech.machine.miner.working_area", workingArea, workingArea)); |
142 | | - if (this.minerLogic.isDone()) |
143 | | - textList.add(new TextComponentTranslation("gregtech.machine.miner.done") |
144 | | - .setStyle(new Style().setColor(TextFormatting.GREEN))); |
145 | | - else if (this.minerLogic.isWorking()) |
146 | | - textList.add(new TextComponentTranslation("gregtech.machine.miner.working") |
147 | | - .setStyle(new Style().setColor(TextFormatting.GOLD))); |
148 | | - else if (!this.isWorkingEnabled()) |
149 | | - textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused")); |
150 | | - if (isInventoryFull) |
151 | | - textList.add(new TextComponentTranslation("gregtech.machine.miner.invfull") |
152 | | - .setStyle(new Style().setColor(TextFormatting.RED))); |
153 | | - if (!drainEnergy(true)) |
154 | | - textList.add(new TextComponentTranslation("gregtech.machine.miner.needspower") |
155 | | - .setStyle(new Style().setColor(TextFormatting.RED))); |
| 107 | + public boolean usesMui2() { |
| 108 | + return true; |
156 | 109 | } |
157 | 110 |
|
158 | | - private void addDisplayText2(@NotNull List<ITextComponent> textList) { |
159 | | - textList.add(new TextComponentTranslation("gregtech.machine.miner.minex", this.minerLogic.getMineX().get())); |
160 | | - textList.add(new TextComponentTranslation("gregtech.machine.miner.miney", this.minerLogic.getMineY().get())); |
161 | | - textList.add(new TextComponentTranslation("gregtech.machine.miner.minez", this.minerLogic.getMineZ().get())); |
| 111 | + @SuppressWarnings("DuplicatedCode") |
| 112 | + @Override |
| 113 | + public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager panelSyncManager, UISettings settings) { |
| 114 | + IntSyncValue radiusSync = new IntSyncValue(() -> getWorkingArea(minerLogic.getCurrentRadius())); |
| 115 | + BooleanSyncValue isDoneSync = new BooleanSyncValue(minerLogic::isDone); |
| 116 | + BooleanSyncValue isWorkingSync = new BooleanSyncValue(minerLogic::isWorking); |
| 117 | + BooleanSyncValue isWorkingEnabledSync = new BooleanSyncValue(minerLogic::isWorkingEnabled); |
| 118 | + BooleanSyncValue isInventoryFullSync = new BooleanSyncValue(() -> isInventoryFull); |
| 119 | + BooleanSyncValue hasEnoughEnergySync = new BooleanSyncValue(() -> drainEnergy(true)); |
| 120 | + panelSyncManager.syncValue("radius", 0, radiusSync); |
| 121 | + panelSyncManager.syncValue("done", 0, isDoneSync); |
| 122 | + panelSyncManager.syncValue("working", 0, isWorkingSync); |
| 123 | + panelSyncManager.syncValue("workingEnabled", 0, isWorkingEnabledSync); |
| 124 | + panelSyncManager.syncValue("inventoryFull", 0, isInventoryFullSync); |
| 125 | + panelSyncManager.syncValue("enoughEnergy", 0, hasEnoughEnergySync); |
| 126 | + |
| 127 | + IntSyncValue xPosSync = new IntSyncValue(() -> minerLogic.getMineX().get()); |
| 128 | + IntSyncValue yPosSync = new IntSyncValue(() -> minerLogic.getMineY().get()); |
| 129 | + IntSyncValue zPosSync = new IntSyncValue(() -> minerLogic.getMineZ().get()); |
| 130 | + panelSyncManager.syncValue("xPos", 0, xPosSync); |
| 131 | + panelSyncManager.syncValue("yPos", 0, yPosSync); |
| 132 | + panelSyncManager.syncValue("zPos", 0, zPosSync); |
| 133 | + |
| 134 | + return GTGuis.createPanel(this, 197, 176) |
| 135 | + .child(IKey.lang(getMetaFullName()) |
| 136 | + .asWidget() |
| 137 | + .pos(5, 5)) |
| 138 | + .child(createMinerWidgets(panelSyncManager, exportItems, inventorySize, GTGuiTextures.DISPLAY, text -> { |
| 139 | + boolean isDone = isDoneSync.getBoolValue(); |
| 140 | + boolean isWorking = isWorkingSync.getBoolValue(); |
| 141 | + boolean isWorkingEnabled = isWorkingEnabledSync.getBoolValue(); |
| 142 | + boolean isInventoryFull = isInventoryFullSync.getBoolValue(); |
| 143 | + boolean hasEnoughEnergy = hasEnoughEnergySync.getBoolValue(); |
| 144 | + |
| 145 | + if (isWorking) { |
| 146 | + text.addLine(KeyUtil.lang(TextFormatting.WHITE, "gregtech.machine.miner.mining_at")); |
| 147 | + text.addLine(KeyUtil.lang(TextFormatting.WHITE, "gregtech.machine.miner.mining_pos_x", |
| 148 | + xPosSync.getIntValue())); |
| 149 | + text.addLine(KeyUtil.lang(TextFormatting.WHITE, "gregtech.machine.miner.mining_pos_y", |
| 150 | + yPosSync.getIntValue())); |
| 151 | + text.addLine(KeyUtil.lang(TextFormatting.WHITE, "gregtech.machine.miner.mining_pos_z", |
| 152 | + zPosSync.getIntValue())); |
| 153 | + } |
| 154 | + |
| 155 | + text.addLine(KeyUtil.lang(TextFormatting.WHITE, "gregtech.machine.miner.working_area", |
| 156 | + radiusSync.getIntValue(), radiusSync.getIntValue())); |
| 157 | + |
| 158 | + if (isDone) { |
| 159 | + text.addLine(KeyUtil.lang(TextStandards.Colors.MACHINE_DONE, "gregtech.machine.miner.done")); |
| 160 | + } else if (isWorking) { |
| 161 | + text.addLine(KeyUtil.lang(TextStandards.Colors.MACHINE_WORKING, |
| 162 | + "gregtech.machine.miner.working")); |
| 163 | + } else if (!isWorkingEnabled) { |
| 164 | + text.addLine(TextStandards.Keys.MACHINE_PAUSED); |
| 165 | + } |
| 166 | + |
| 167 | + if (isInventoryFull) { |
| 168 | + text.addLine(KeyUtil.lang(TextStandards.Colors.NO_OUTPUT_SPACE, |
| 169 | + "gregtech.machine.miner.invfull")); |
| 170 | + } |
| 171 | + |
| 172 | + if (!hasEnoughEnergy) { |
| 173 | + text.addLine(KeyUtil.lang(TextStandards.Colors.NO_POWER, "gregtech.machine.miner.needspower")); |
| 174 | + } |
| 175 | + }) |
| 176 | + .left(10) |
| 177 | + .top(18)) |
| 178 | + .child(SlotGroupWidget.playerInventory(false) |
| 179 | + .left(7) |
| 180 | + .bottom(7)) |
| 181 | + .child(new ItemSlot() |
| 182 | + .right(7) |
| 183 | + .bottom(7) |
| 184 | + .slot(chargerInventory, 0) |
| 185 | + .background(GTGuiTextures.SLOT, GTGuiTextures.CHARGER_OVERLAY)); |
162 | 186 | } |
163 | 187 |
|
164 | 188 | @Override |
|
0 commit comments