Alloy furnace - Search box
This commit is contained in:
parent
1970cfe84d
commit
10a0b6cb86
4 changed files with 138 additions and 30 deletions
1
TODO.txt
1
TODO.txt
|
@ -41,7 +41,6 @@ materials.ores No Tin
|
|||
materials.ores No Zinc
|
||||
-------------------------------------------------------------------------------------------------------
|
||||
tech.base No Alloy furnace
|
||||
-> search recipe
|
||||
-> XP
|
||||
-> let output hoppers take empty buckets / invalid input
|
||||
(make that configurable)
|
||||
|
|
|
@ -135,12 +135,19 @@ public class TBAlloyFurnaceContainer
|
|||
|
||||
public void setCurrentRecipe( final ResourceLocation name , final boolean confirm )
|
||||
{
|
||||
final MAlloyRecipe recipe = MAlloyRecipe.REGISTRY.getRecipe( name );
|
||||
if ( recipe == null ) {
|
||||
return;
|
||||
final MAlloyRecipe recipe;
|
||||
if ( name == null ) {
|
||||
recipe = null;
|
||||
} else {
|
||||
recipe = MAlloyRecipe.REGISTRY.getRecipe( name );
|
||||
}
|
||||
|
||||
this.recipe.clear( );
|
||||
if ( recipe == null ) {
|
||||
// XXX log if confirm is set
|
||||
return;
|
||||
}
|
||||
|
||||
for ( int i = 0 ; i < recipe.inputs.length ; i++ ) {
|
||||
this.recipe.setInventorySlotContents( i , recipe.inputs[ i ] );
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import mmm.materials.MAlloyRecipe;
|
|||
import mmm.utils.URegistry;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
@ -99,11 +100,16 @@ public class TBAlloyFurnaceGui
|
|||
private static final int TAB_ICON_HEIGHT = 16;
|
||||
|
||||
private final TBAlloyFurnaceContainer container;
|
||||
|
||||
private TBAlloyFurnaceGui.Tab selectedTab = Tab.MAIN;
|
||||
|
||||
private ArrowButton bPrevious;
|
||||
private ArrowButton bNext;
|
||||
private GuiButton bConfirm;
|
||||
private TBAlloyFurnaceGui.Tab selectedTab = Tab.MAIN;
|
||||
private GuiTextField tfSearch;
|
||||
private ArrayList< MAlloyRecipe > recipes;
|
||||
private int currentRecipe = 0;
|
||||
private String searchString = "";
|
||||
|
||||
|
||||
public TBAlloyFurnaceGui( final InventoryPlayer inventoryPlayer , final TBAlloyFurnaceTileEntity tileEntity )
|
||||
|
@ -119,7 +125,8 @@ public class TBAlloyFurnaceGui
|
|||
}
|
||||
}
|
||||
|
||||
this.setRecipe( getRecipeIndex( tileEntity.recipe ) );
|
||||
this.recipes = MAlloyRecipe.REGISTRY.getRecipes( );
|
||||
this.setRecipe( this.getRecipeIndex( tileEntity.recipe ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -134,7 +141,15 @@ public class TBAlloyFurnaceGui
|
|||
this.bPrevious = new ArrowButton( 1 , 8 + x , 47 + y , false );
|
||||
this.bNext = new ArrowButton( 2 , 156 + x , 47 + y , true );
|
||||
this.bConfirm = new GuiButton( 3 , 24 + x , 84 + y , 128 , 20 , I18n.format( "gui.mmm.select_recipe" ) );
|
||||
|
||||
this.tfSearch = new GuiTextField( 4 , this.fontRendererObj , 24 + x , 9 + y , 128 , 20 );
|
||||
this.tfSearch.setTextColor( 0xffffff );
|
||||
this.tfSearch.setDisabledTextColour( 0x7f7f7f );
|
||||
this.tfSearch.setEnableBackgroundDrawing( true );
|
||||
this.tfSearch.setMaxStringLength( 30 );
|
||||
|
||||
this.bPrevious.visible = this.bNext.visible = this.bConfirm.visible = false;
|
||||
this.tfSearch.setVisible( false );
|
||||
|
||||
this.buttonList.add( this.bNext );
|
||||
this.buttonList.add( this.bPrevious );
|
||||
|
@ -144,34 +159,56 @@ public class TBAlloyFurnaceGui
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen( final int mouseX , final int mouseY , final float partialTicks )
|
||||
{
|
||||
super.drawScreen( mouseX , mouseY , partialTicks );
|
||||
}
|
||||
|
||||
|
||||
private void enableConfigButtons( )
|
||||
{
|
||||
if ( this.bNext != null ) {
|
||||
boolean visible = ( this.selectedTab == Tab.CONFIG );
|
||||
final boolean visible = this.selectedTab == Tab.CONFIG;
|
||||
this.bNext.visible = this.bPrevious.visible = this.bConfirm.visible = visible;
|
||||
this.tfSearch.setVisible( visible );
|
||||
|
||||
this.bNext.enabled = this.currentRecipe < MAlloyRecipe.REGISTRY.getRecipes( ).size( ) - 1;
|
||||
if ( this.recipes.isEmpty( ) ) {
|
||||
this.bNext.enabled = this.bPrevious.enabled = this.bConfirm.enabled = false;
|
||||
} else {
|
||||
this.bNext.enabled = this.currentRecipe < this.recipes.size( ) - 1;
|
||||
this.bPrevious.enabled = this.currentRecipe > 0;
|
||||
this.bConfirm.enabled = ( this.currentRecipe != getRecipeIndex( this.container.tileEntity.recipe ) );
|
||||
this.bConfirm.enabled = this.currentRecipe != this.getRecipeIndex( this.container.tileEntity.recipe );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void setRecipe( final int index )
|
||||
private void setRecipe( int index )
|
||||
{
|
||||
ArrayList< MAlloyRecipe > list = MAlloyRecipe.REGISTRY.getRecipes( );
|
||||
MAlloyRecipe recipe = list.get( index );
|
||||
this.container.setCurrentRecipe( recipe.name , false );
|
||||
URegistry.network.sendToServer( new TBAlloyFurnaceMessage(
|
||||
( (TBAlloyFurnaceContainer) this.inventorySlots ).position , recipe.name , false ) );
|
||||
if ( index == -1 && !this.recipes.isEmpty( ) ) {
|
||||
index = 0;
|
||||
}
|
||||
this.currentRecipe = index;
|
||||
|
||||
ResourceLocation rName;
|
||||
if ( index != -1 ) {
|
||||
final MAlloyRecipe recipe = this.recipes.get( index );
|
||||
rName = recipe.name;
|
||||
} else {
|
||||
rName = null;
|
||||
}
|
||||
|
||||
this.container.setCurrentRecipe( rName , false );
|
||||
URegistry.network.sendToServer( //
|
||||
new TBAlloyFurnaceMessage( this.container.position , rName , false ) );
|
||||
this.enableConfigButtons( );
|
||||
}
|
||||
|
||||
|
||||
private static int getRecipeIndex( MAlloyRecipe recipe )
|
||||
private int getRecipeIndex( final MAlloyRecipe recipe )
|
||||
{
|
||||
return MAlloyRecipe.REGISTRY.getRecipes( ).indexOf( recipe );
|
||||
return this.recipes.indexOf( recipe );
|
||||
}
|
||||
|
||||
|
||||
|
@ -181,7 +218,6 @@ public class TBAlloyFurnaceGui
|
|||
GlStateManager.color( 1f , 1f , 1f , 1f );
|
||||
GlStateManager.enableBlend( );
|
||||
GlStateManager.disableLighting( );
|
||||
// RenderHelper.enableGUIStandardItemLighting( );
|
||||
|
||||
// Inactive tab
|
||||
this.mc.getTextureManager( ).bindTexture( TBAlloyFurnaceGui.TEXTURES[ 0 ] );
|
||||
|
@ -196,24 +232,29 @@ public class TBAlloyFurnaceGui
|
|||
this.drawTexturedModalRect( this.guiLeft , this.guiTop , 0 , 0 , this.xSize , this.ySize );
|
||||
|
||||
if ( this.selectedTab == Tab.MAIN ) {
|
||||
int x = ( this.width - this.xSize ) / 2;
|
||||
int y = ( this.height - this.ySize ) / 2;
|
||||
final int x = ( this.width - this.xSize ) / 2;
|
||||
final int y = ( this.height - this.ySize ) / 2;
|
||||
|
||||
TileEntity atPos = this.container.world.getTileEntity( this.container.position );
|
||||
final TileEntity atPos = this.container.world.getTileEntity( this.container.position );
|
||||
if ( atPos instanceof TBAlloyFurnaceTileEntity ) {
|
||||
TBAlloyFurnaceTileEntity te = (TBAlloyFurnaceTileEntity) atPos;
|
||||
final TBAlloyFurnaceTileEntity te = (TBAlloyFurnaceTileEntity) atPos;
|
||||
// Burn
|
||||
if ( te.isBurning( ) ) {
|
||||
int burn = te.getBurnProgress( 13 );
|
||||
final int burn = te.getBurnProgress( 13 );
|
||||
this.drawTexturedModalRect( x + 89 , y + 38 + 13 - burn , 176 , 28 - burn , 14 , burn + 1 );
|
||||
}
|
||||
|
||||
// Alloying progress
|
||||
if ( te.isAlloying( ) ) {
|
||||
int alloy = te.getAlloyingProgress( 47 );
|
||||
final int alloy = te.getAlloyingProgress( 47 );
|
||||
this.drawTexturedModalRect( x + 73 , y + 17 , 176 , 29 , alloy + 1 , 16 );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
GlStateManager.disableBlend( );
|
||||
this.tfSearch.drawTextBox( );
|
||||
GlStateManager.enableBlend( );
|
||||
GlStateManager.color( 1f , 1f , 1f , 1f );
|
||||
}
|
||||
|
||||
// Active tab
|
||||
|
@ -243,6 +284,60 @@ public class TBAlloyFurnaceGui
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( this.selectedTab == Tab.CONFIG ) {
|
||||
this.tfSearch.mouseClicked( mouseX , mouseY , mouseButton );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void keyTyped( final char typedChar , final int keyCode )
|
||||
throws IOException
|
||||
{
|
||||
if ( this.tfSearch.getVisible( ) && this.tfSearch.textboxKeyTyped( typedChar , keyCode ) ) {
|
||||
this.handleFiltering( );
|
||||
} else {
|
||||
super.keyTyped( typedChar , keyCode );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void handleFiltering( )
|
||||
{
|
||||
final String newText = this.tfSearch.getText( ).trim( ).toLowerCase( );
|
||||
if ( this.searchString.equals( newText ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
MAlloyRecipe selected = this.currentRecipe == -1 ? null : this.recipes.get( this.currentRecipe );
|
||||
final ArrayList< MAlloyRecipe > fullList = MAlloyRecipe.REGISTRY.getRecipes( );
|
||||
this.searchString = newText;
|
||||
if ( "".equals( newText ) ) {
|
||||
this.recipes = fullList;
|
||||
} else {
|
||||
if ( this.recipes == fullList ) {
|
||||
this.recipes = new ArrayList<>( );
|
||||
} else {
|
||||
this.recipes.clear( );
|
||||
}
|
||||
|
||||
final int nRecipes = fullList.size( );
|
||||
for ( int i = 0 ; i < nRecipes ; i++ ) {
|
||||
final MAlloyRecipe recipe = fullList.get( i );
|
||||
if ( recipe.getLocalizedName( ).toLowerCase( ).contains( newText ) ) {
|
||||
this.recipes.add( recipe );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( selected == null && !this.recipes.isEmpty( ) ) {
|
||||
this.setRecipe( 0 );
|
||||
} else if ( selected != null ) {
|
||||
this.setRecipe( this.getRecipeIndex( selected ) );
|
||||
} else {
|
||||
this.setRecipe( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -255,8 +350,7 @@ public class TBAlloyFurnaceGui
|
|||
} else if ( button == this.bPrevious ) {
|
||||
this.setRecipe( this.currentRecipe - 1 );
|
||||
} else if ( button == this.bConfirm ) {
|
||||
ArrayList< MAlloyRecipe > list = MAlloyRecipe.REGISTRY.getRecipes( );
|
||||
MAlloyRecipe recipe = list.get( this.currentRecipe );
|
||||
final MAlloyRecipe recipe = this.recipes.get( this.currentRecipe );
|
||||
URegistry.network.sendToServer(
|
||||
new TBAlloyFurnaceMessage( this.container.tileEntity.getPos( ) , recipe.name , true ) );
|
||||
this.container.tileEntity.recipe = recipe;
|
||||
|
|
|
@ -37,7 +37,12 @@ public class TBAlloyFurnaceMessage
|
|||
public void fromBytes( final ByteBuf buf )
|
||||
{
|
||||
this.blockPos = new BlockPos( buf.readInt( ) , buf.readInt( ) , buf.readInt( ) );
|
||||
this.selected = new ResourceLocation( ByteBufUtils.readUTF8String( buf ) , ByteBufUtils.readUTF8String( buf ) );
|
||||
if ( buf.readBoolean( ) ) {
|
||||
this.selected = new ResourceLocation( ByteBufUtils.readUTF8String( buf ) ,
|
||||
ByteBufUtils.readUTF8String( buf ) );
|
||||
} else {
|
||||
this.selected = null;
|
||||
}
|
||||
this.confirm = buf.readBoolean( );
|
||||
}
|
||||
|
||||
|
@ -48,8 +53,11 @@ public class TBAlloyFurnaceMessage
|
|||
buf.writeInt( this.blockPos.getX( ) );
|
||||
buf.writeInt( this.blockPos.getY( ) );
|
||||
buf.writeInt( this.blockPos.getZ( ) );
|
||||
buf.writeBoolean( this.selected != null );
|
||||
if ( this.selected != null ) {
|
||||
ByteBufUtils.writeUTF8String( buf , this.selected.getResourceDomain( ) );
|
||||
ByteBufUtils.writeUTF8String( buf , this.selected.getResourcePath( ) );
|
||||
}
|
||||
buf.writeBoolean( this.confirm );
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue