|
| 1 | +package com.glodblock.github.client.gui; |
| 2 | + |
| 3 | +import appeng.client.gui.AEBaseGui; |
| 4 | +import appeng.client.gui.widgets.GuiNumberBox; |
| 5 | +import appeng.client.gui.widgets.GuiTabButton; |
| 6 | +import appeng.container.AEBaseContainer; |
| 7 | +import appeng.container.implementations.ContainerPriority; |
| 8 | +import appeng.core.AEConfig; |
| 9 | +import appeng.core.AELog; |
| 10 | +import appeng.core.localization.GuiText; |
| 11 | +import appeng.core.sync.network.NetworkHandler; |
| 12 | +import appeng.core.sync.packets.PacketValueConfig; |
| 13 | +import appeng.helpers.IPriorityHost; |
| 14 | +import com.glodblock.github.FluidCraft; |
| 15 | +import com.glodblock.github.common.parts.PartFluidInterface; |
| 16 | +import com.glodblock.github.common.tile.TileFluidInterface; |
| 17 | +import com.glodblock.github.inventory.gui.GuiType; |
| 18 | +import com.glodblock.github.loader.ItemAndBlockHolder; |
| 19 | +import com.glodblock.github.network.CPacketSwitchGuis; |
| 20 | +import net.minecraft.client.gui.Gui; |
| 21 | +import net.minecraft.client.gui.GuiButton; |
| 22 | +import net.minecraft.entity.player.InventoryPlayer; |
| 23 | +import net.minecraft.item.ItemStack; |
| 24 | + |
| 25 | +import java.io.IOException; |
| 26 | + |
| 27 | +public class GuiFCPriority extends AEBaseGui |
| 28 | +{ |
| 29 | + |
| 30 | + private GuiNumberBox priority; |
| 31 | + private GuiTabButton originalGuiBtn; |
| 32 | + |
| 33 | + private GuiButton plus1; |
| 34 | + private GuiButton plus10; |
| 35 | + private GuiButton plus100; |
| 36 | + private GuiButton plus1000; |
| 37 | + private GuiButton minus1; |
| 38 | + private GuiButton minus10; |
| 39 | + private GuiButton minus100; |
| 40 | + private GuiButton minus1000; |
| 41 | + |
| 42 | + private GuiType OriginalGui; |
| 43 | + |
| 44 | + public GuiFCPriority( final InventoryPlayer inventoryPlayer, final IPriorityHost te ) |
| 45 | + { |
| 46 | + super( new ContainerPriority( inventoryPlayer, te ) ); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + @SuppressWarnings("unchecked") |
| 51 | + public void initGui() |
| 52 | + { |
| 53 | + super.initGui(); |
| 54 | + |
| 55 | + final int a = AEConfig.instance.priorityByStacksAmounts( 0 ); |
| 56 | + final int b = AEConfig.instance.priorityByStacksAmounts( 1 ); |
| 57 | + final int c = AEConfig.instance.priorityByStacksAmounts( 2 ); |
| 58 | + final int d = AEConfig.instance.priorityByStacksAmounts( 3 ); |
| 59 | + |
| 60 | + this.buttonList.add( this.plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 32, 22, 20, "+" + a ) ); |
| 61 | + this.buttonList.add( this.plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 32, 28, 20, "+" + b ) ); |
| 62 | + this.buttonList.add( this.plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 32, 32, 20, "+" + c ) ); |
| 63 | + this.buttonList.add( this.plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 32, 38, 20, "+" + d ) ); |
| 64 | + |
| 65 | + this.buttonList.add( this.minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 69, 22, 20, "-" + a ) ); |
| 66 | + this.buttonList.add( this.minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 69, 28, 20, "-" + b ) ); |
| 67 | + this.buttonList.add( this.minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 69, 32, 20, "-" + c ) ); |
| 68 | + this.buttonList.add( this.minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 69, 38, 20, "-" + d ) ); |
| 69 | + |
| 70 | + ItemStack myIcon = null; |
| 71 | + final Object target = ( (AEBaseContainer) this.inventorySlots ).getTarget(); |
| 72 | + |
| 73 | + if( target instanceof TileFluidInterface) |
| 74 | + { |
| 75 | + myIcon = ItemAndBlockHolder.INTERFACE.stack(); |
| 76 | + this.OriginalGui = GuiType.DUAL_INTERFACE; |
| 77 | + } |
| 78 | + else if (target instanceof PartFluidInterface) |
| 79 | + { |
| 80 | + myIcon = ItemAndBlockHolder.FLUID_INTERFACE.stack(); |
| 81 | + this.OriginalGui = GuiType.DUAL_INTERFACE_FLUID_PART; |
| 82 | + } |
| 83 | + |
| 84 | + if( this.OriginalGui != null && myIcon != null ) |
| 85 | + { |
| 86 | + this.buttonList.add( this.originalGuiBtn = new GuiTabButton( this.guiLeft + 154, this.guiTop, myIcon, myIcon.getDisplayName(), itemRender ) ); |
| 87 | + } |
| 88 | + |
| 89 | + this.priority = new GuiNumberBox( this.fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, this.fontRendererObj.FONT_HEIGHT, Long.class ); |
| 90 | + this.priority.setEnableBackgroundDrawing( false ); |
| 91 | + this.priority.setMaxStringLength( 16 ); |
| 92 | + this.priority.setTextColor( 0xFFFFFF ); |
| 93 | + this.priority.setVisible( true ); |
| 94 | + this.priority.setFocused( true ); |
| 95 | + ( (ContainerPriority) this.inventorySlots ).setTextField( this.priority ); |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) |
| 100 | + { |
| 101 | + this.fontRendererObj.drawString( GuiText.Priority.getLocal(), 8, 6, 4210752 ); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) |
| 106 | + { |
| 107 | + this.bindTexture( getBackground() ); |
| 108 | + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize ); |
| 109 | + |
| 110 | + this.priority.drawTextBox(); |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + protected void actionPerformed( final GuiButton btn ) |
| 115 | + { |
| 116 | + super.actionPerformed( btn ); |
| 117 | + |
| 118 | + if( btn == this.originalGuiBtn ) |
| 119 | + { |
| 120 | + FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(this.OriginalGui)); |
| 121 | + } |
| 122 | + |
| 123 | + final boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000; |
| 124 | + final boolean isMinus = btn == this.minus1 || btn == this.minus10 || btn == this.minus100 || btn == this.minus1000; |
| 125 | + |
| 126 | + if( isPlus || isMinus ) |
| 127 | + { |
| 128 | + this.addQty( this.getQty( btn ) ); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + private void addQty( final int i ) |
| 133 | + { |
| 134 | + try |
| 135 | + { |
| 136 | + String out = this.priority.getText(); |
| 137 | + |
| 138 | + boolean fixed = false; |
| 139 | + while( out.startsWith( "0" ) && out.length() > 1 ) |
| 140 | + { |
| 141 | + out = out.substring( 1 ); |
| 142 | + fixed = true; |
| 143 | + } |
| 144 | + |
| 145 | + if( fixed ) |
| 146 | + { |
| 147 | + this.priority.setText( out ); |
| 148 | + } |
| 149 | + |
| 150 | + if( out.isEmpty() ) |
| 151 | + { |
| 152 | + out = "0"; |
| 153 | + } |
| 154 | + |
| 155 | + long result = Long.parseLong( out ); |
| 156 | + result += i; |
| 157 | + |
| 158 | + this.priority.setText( out = Long.toString( result ) ); |
| 159 | + |
| 160 | + NetworkHandler.instance.sendToServer( new PacketValueConfig( "PriorityHost.Priority", out ) ); |
| 161 | + } |
| 162 | + catch( final NumberFormatException e ) |
| 163 | + { |
| 164 | + // nope.. |
| 165 | + this.priority.setText( "0" ); |
| 166 | + } |
| 167 | + catch( final IOException e ) |
| 168 | + { |
| 169 | + AELog.debug( e ); |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + @Override |
| 174 | + protected void keyTyped( final char character, final int key ) |
| 175 | + { |
| 176 | + if( !this.checkHotbarKeys( key ) ) |
| 177 | + { |
| 178 | + if( ( key == 211 || key == 205 || key == 203 || key == 14 || character == '-' || Character.isDigit( character ) ) && this.priority.textboxKeyTyped( character, key ) ) |
| 179 | + { |
| 180 | + try |
| 181 | + { |
| 182 | + String out = this.priority.getText(); |
| 183 | + |
| 184 | + boolean fixed = false; |
| 185 | + while( out.startsWith( "0" ) && out.length() > 1 ) |
| 186 | + { |
| 187 | + out = out.substring( 1 ); |
| 188 | + fixed = true; |
| 189 | + } |
| 190 | + |
| 191 | + if( fixed ) |
| 192 | + { |
| 193 | + this.priority.setText( out ); |
| 194 | + } |
| 195 | + |
| 196 | + if( out.isEmpty() ) |
| 197 | + { |
| 198 | + out = "0"; |
| 199 | + } |
| 200 | + |
| 201 | + NetworkHandler.instance.sendToServer( new PacketValueConfig( "PriorityHost.Priority", out ) ); |
| 202 | + } |
| 203 | + catch( final IOException e ) |
| 204 | + { |
| 205 | + AELog.debug( e ); |
| 206 | + } |
| 207 | + } |
| 208 | + else |
| 209 | + { |
| 210 | + super.keyTyped( character, key ); |
| 211 | + } |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + protected String getBackground() |
| 216 | + { |
| 217 | + return "guis/priority.png"; |
| 218 | + } |
| 219 | +} |
0 commit comments