|
| 1 | +package appeng.client.gui.implementations; |
| 2 | + |
| 3 | +import appeng.client.gui.AEBaseGui; |
| 4 | +import appeng.container.AEBaseContainer; |
| 5 | +import appeng.container.implementations.ContainerOreFilter; |
| 6 | +import appeng.core.AELog; |
| 7 | +import appeng.core.localization.GuiText; |
| 8 | +import appeng.core.sync.GuiBridge; |
| 9 | +import appeng.core.sync.network.NetworkHandler; |
| 10 | +import appeng.core.sync.packets.PacketSwitchGuis; |
| 11 | +import appeng.core.sync.packets.PacketValueConfig; |
| 12 | +import appeng.helpers.IOreFilterable; |
| 13 | +import appeng.parts.automation.PartSharedItemBus; |
| 14 | +import appeng.parts.misc.PartStorageBus; |
| 15 | +import net.minecraft.client.gui.GuiTextField; |
| 16 | +import net.minecraft.entity.player.InventoryPlayer; |
| 17 | + |
| 18 | +import java.io.IOException; |
| 19 | + |
| 20 | +public class GuiOreFilter extends AEBaseGui { |
| 21 | + private GuiTextField filter; |
| 22 | + public GuiOreFilter(InventoryPlayer ip, IOreFilterable obj) { |
| 23 | + super(new ContainerOreFilter(ip, obj)); |
| 24 | + } |
| 25 | + |
| 26 | + @Override |
| 27 | + public void initGui() { |
| 28 | + super.initGui(); |
| 29 | + this.filter = new GuiTextField(this.fontRendererObj, this.guiLeft + 13, this.guiTop + 36, 150, this.fontRendererObj.FONT_HEIGHT); |
| 30 | + this.filter.setEnableBackgroundDrawing(false); |
| 31 | + this.filter.setMaxStringLength(32); |
| 32 | + this.filter.setTextColor(0xFFFFFF); |
| 33 | + this.filter.setVisible(true); |
| 34 | + this.filter.setFocused(true); |
| 35 | + ((ContainerOreFilter) this.inventorySlots).setTextField(this.filter); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { |
| 40 | + this.fontRendererObj.drawString( GuiText.OreFilterLabel.getLocal(), 12, 8, 4210752 ); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { |
| 45 | + this.bindTexture( "guis/renamer.png" ); |
| 46 | + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize ); |
| 47 | + this.filter.drawTextBox(); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + protected void keyTyped(final char character, final int key) { |
| 52 | + if (key == 28) // Enter |
| 53 | + { |
| 54 | + try |
| 55 | + { |
| 56 | + NetworkHandler.instance.sendToServer(new PacketValueConfig("OreFilter", this.filter.getText())); |
| 57 | + } |
| 58 | + catch (IOException e) |
| 59 | + { |
| 60 | + AELog.debug(e); |
| 61 | + } |
| 62 | + final Object target = ( (AEBaseContainer) this.inventorySlots ).getTarget(); |
| 63 | + GuiBridge OriginalGui = null; |
| 64 | + if (target instanceof PartStorageBus) |
| 65 | + OriginalGui = GuiBridge.GUI_STORAGEBUS; |
| 66 | + else if (target instanceof PartSharedItemBus) |
| 67 | + OriginalGui = GuiBridge.GUI_BUS; |
| 68 | + |
| 69 | + if (OriginalGui != null) |
| 70 | + NetworkHandler.instance.sendToServer( new PacketSwitchGuis( OriginalGui ) ); |
| 71 | + else |
| 72 | + this.mc.thePlayer.closeScreen(); |
| 73 | + } |
| 74 | + else if (this.filter.textboxKeyTyped(character, key)) |
| 75 | + { |
| 76 | + ((ContainerOreFilter) this.inventorySlots).setFilter(filter.getText()); |
| 77 | + } |
| 78 | + else |
| 79 | + super.keyTyped(character, key); |
| 80 | + } |
| 81 | +} |
0 commit comments