Prevent Number Format Errors in guis.
This commit is contained in:
@@ -3,12 +3,12 @@ package appeng.client.gui.implementations;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.client.gui.widgets.GuiNumberBox;
|
||||
import appeng.client.gui.widgets.GuiTabButton;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.implementations.ContainerCraftAmount;
|
||||
@@ -27,7 +27,7 @@ import appeng.parts.reporting.PartTerminal;
|
||||
public class GuiCraftAmount extends AEBaseGui
|
||||
{
|
||||
|
||||
GuiTextField amountToCraft;
|
||||
GuiNumberBox amountToCraft;
|
||||
GuiTabButton originalGuiBtn;
|
||||
|
||||
GuiButton next;
|
||||
@@ -93,7 +93,7 @@ public class GuiCraftAmount extends AEBaseGui
|
||||
if ( OriginalGui != null )
|
||||
buttonList.add( originalGuiBtn = new GuiTabButton( this.guiLeft + 154, this.guiTop, myIcon, myIcon.getDisplayName(), itemRender ) );
|
||||
|
||||
amountToCraft = new GuiTextField( fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, fontRendererObj.FONT_HEIGHT );
|
||||
amountToCraft = new GuiNumberBox( fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, fontRendererObj.FONT_HEIGHT, Integer.class );
|
||||
amountToCraft.setEnableBackgroundDrawing( false );
|
||||
amountToCraft.setMaxStringLength( 16 );
|
||||
amountToCraft.setTextColor( 0xFFFFFF );
|
||||
@@ -109,6 +109,7 @@ public class GuiCraftAmount extends AEBaseGui
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
if ( btn == originalGuiBtn )
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketSwitchGuis( OriginalGui ) );
|
||||
@@ -121,6 +122,11 @@ public class GuiCraftAmount extends AEBaseGui
|
||||
}
|
||||
|
||||
}
|
||||
catch(NumberFormatException e )
|
||||
{
|
||||
// nope..
|
||||
amountToCraft.setText( "1" );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
@@ -152,7 +158,7 @@ public class GuiCraftAmount extends AEBaseGui
|
||||
if ( Out.length() == 0 )
|
||||
Out = "0";
|
||||
|
||||
long result = Long.parseLong( Out );
|
||||
long result = Integer.parseInt( Out );
|
||||
|
||||
if ( result == 1 && i > 1 )
|
||||
result = 0;
|
||||
@@ -160,8 +166,10 @@ public class GuiCraftAmount extends AEBaseGui
|
||||
result += i;
|
||||
if ( result < 1 )
|
||||
result = 1;
|
||||
|
||||
amountToCraft.setText( Out = Long.toString( result ) );
|
||||
|
||||
Out = Long.toString( result );
|
||||
Integer.parseInt( Out );
|
||||
amountToCraft.setText( Out );
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,6 @@ package appeng.client.gui.implementations;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
@@ -14,6 +13,7 @@ import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.client.gui.widgets.GuiImgButton;
|
||||
import appeng.client.gui.widgets.GuiNumberBox;
|
||||
import appeng.container.implementations.ContainerLevelEmitter;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
@@ -26,7 +26,7 @@ import appeng.parts.automation.PartLevelEmitter;
|
||||
public class GuiLevelEmitter extends GuiUpgradeable
|
||||
{
|
||||
|
||||
GuiTextField level;
|
||||
GuiNumberBox level;
|
||||
|
||||
GuiButton plus1, plus10, plus100, plus1000;
|
||||
GuiButton minus1, minus10, minus100, minus1000;
|
||||
@@ -42,7 +42,7 @@ public class GuiLevelEmitter extends GuiUpgradeable
|
||||
{
|
||||
super.initGui();
|
||||
|
||||
level = new GuiTextField( fontRendererObj, this.guiLeft + 24, this.guiTop + 43, 79, fontRendererObj.FONT_HEIGHT );
|
||||
level = new GuiNumberBox( fontRendererObj, this.guiLeft + 24, this.guiTop + 43, 79, fontRendererObj.FONT_HEIGHT, Long.class );
|
||||
level.setEnableBackgroundDrawing( false );
|
||||
level.setMaxStringLength( 16 );
|
||||
level.setTextColor( 0xFFFFFF );
|
||||
@@ -130,6 +130,11 @@ public class GuiLevelEmitter extends GuiUpgradeable
|
||||
|
||||
NetworkHandler.instance.sendToServer( new PacketValueConfig( "LevelEmitter.Value", Out ) );
|
||||
}
|
||||
catch(NumberFormatException e )
|
||||
{
|
||||
// nope..
|
||||
level.setText( "0" );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
|
||||
@@ -3,11 +3,11 @@ package appeng.client.gui.implementations;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.client.gui.widgets.GuiNumberBox;
|
||||
import appeng.client.gui.widgets.GuiTabButton;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.implementations.ContainerPriority;
|
||||
@@ -29,7 +29,7 @@ import appeng.tile.storage.TileDrive;
|
||||
public class GuiPriority extends AEBaseGui
|
||||
{
|
||||
|
||||
GuiTextField priority;
|
||||
GuiNumberBox priority;
|
||||
GuiTabButton originalGuiBtn;
|
||||
|
||||
GuiButton plus1, plus10, plus100, plus1000;
|
||||
@@ -103,7 +103,7 @@ public class GuiPriority extends AEBaseGui
|
||||
if ( OriginalGui != null )
|
||||
buttonList.add( originalGuiBtn = new GuiTabButton( this.guiLeft + 154, this.guiTop, myIcon, myIcon.getDisplayName(), itemRender ) );
|
||||
|
||||
priority = new GuiTextField( fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, fontRendererObj.FONT_HEIGHT );
|
||||
priority = new GuiNumberBox( fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, fontRendererObj.FONT_HEIGHT, Long.class );
|
||||
priority.setEnableBackgroundDrawing( false );
|
||||
priority.setMaxStringLength( 16 );
|
||||
priority.setTextColor( 0xFFFFFF );
|
||||
@@ -162,6 +162,11 @@ public class GuiPriority extends AEBaseGui
|
||||
|
||||
NetworkHandler.instance.sendToServer( new PacketValueConfig( "PriorityHost.Priority", Out ) );
|
||||
}
|
||||
catch(NumberFormatException e )
|
||||
{
|
||||
// nope..
|
||||
priority.setText( "0" );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package appeng.client.gui.widgets;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
|
||||
public class GuiNumberBox extends GuiTextField
|
||||
{
|
||||
|
||||
final Class type;
|
||||
|
||||
public GuiNumberBox(FontRenderer p_i1032_1_, int p_i1032_2_, int p_i1032_3_, int p_i1032_4_, int p_i1032_5_,Class type) {
|
||||
super( p_i1032_1_, p_i1032_2_, p_i1032_3_, p_i1032_4_, p_i1032_5_ );
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeText(String p_146191_1_)
|
||||
{
|
||||
String original = getText();
|
||||
super.writeText( p_146191_1_ );
|
||||
|
||||
try
|
||||
{
|
||||
if ( type == int.class || type == Integer.class )
|
||||
Integer.parseInt( getText() );
|
||||
else if ( type == long.class || type == Long.class )
|
||||
Long.parseLong( getText() );
|
||||
else if ( type == double.class || type == Double.class )
|
||||
Double.parseDouble( getText() );
|
||||
}
|
||||
catch(NumberFormatException e )
|
||||
{
|
||||
setText( original );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user