Merge pull request #190 from yueh/feature-progress-provider

Moving the handling of progress to GuiProgressBar
This commit is contained in:
thatsIch 2014-09-29 21:57:20 +02:00
commit 2688548479
10 changed files with 142 additions and 44 deletions

View file

@ -26,7 +26,8 @@ public class GuiCondenser extends AEBaseGui
GuiProgressBar pb;
GuiImgButton mode;
public GuiCondenser(InventoryPlayer inventoryPlayer, TileCondenser te) {
public GuiCondenser(InventoryPlayer inventoryPlayer, TileCondenser te)
{
super( new ContainerCondenser( inventoryPlayer, te ) );
cvc = (ContainerCondenser) inventorySlots;
this.ySize = 197;
@ -57,8 +58,7 @@ public class GuiCondenser extends AEBaseGui
{
super.initGui();
pb = new GuiProgressBar( "guis/condenser.png", 120 + guiLeft, 25 + guiTop, 178, 25, 6, 18, Direction.VERTICAL );
pb.TitleName = GuiText.StoredEnergy.getLocal();
pb = new GuiProgressBar( cvc, "guis/condenser.png", 120 + guiLeft, 25 + guiTop, 178, 25, 6, 18, Direction.VERTICAL, GuiText.StoredEnergy.getLocal() );
mode = new GuiImgButton( 128 + guiLeft, 52 + guiTop, Settings.CONDENSER_OUTPUT, cvc.output );
@ -83,8 +83,6 @@ public class GuiCondenser extends AEBaseGui
mode.set( cvc.output );
mode.FillVar = "" + cvc.output.requiredPower;
pb.max = (int) cvc.requiredEnergy;
pb.current = (int) cvc.storedPower;
}
}

View file

@ -15,7 +15,8 @@ public class GuiInscriber extends AEBaseGui
ContainerInscriber cvc;
GuiProgressBar pb;
public GuiInscriber(InventoryPlayer inventoryPlayer, TileInscriber te) {
public GuiInscriber(InventoryPlayer inventoryPlayer, TileInscriber te)
{
super( new ContainerInscriber( inventoryPlayer, te ) );
cvc = (ContainerInscriber) inventorySlots;
this.ySize = 176;
@ -27,7 +28,7 @@ public class GuiInscriber extends AEBaseGui
{
super.initGui();
pb = new GuiProgressBar( "guis/inscriber.png", 135, 39, 135, 177, 6, 18, Direction.VERTICAL );
pb = new GuiProgressBar( cvc, "guis/inscriber.png", 135, 39, 135, 177, 6, 18, Direction.VERTICAL );
this.buttonList.add( pb );
}
@ -49,9 +50,7 @@ public class GuiInscriber extends AEBaseGui
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
{
pb.max = cvc.maxProcessingTime;
pb.current = cvc.processingTime;
pb.FullMsg = (pb.current * 100 / pb.max) + "%";
pb.setFullMsg( cvc.getCurrentProgress() * 100 / cvc.getMaxProgress() + "%" );
fontRendererObj.drawString( getGuiDisplayName( GuiText.Inscriber.getLocal() ), 8, 6, 4210752 );
fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 );

View file

@ -21,7 +21,7 @@ public class GuiMAC extends GuiUpgradeable
{
super.initGui();
pb = new GuiProgressBar( "guis/mac.png", 139, 36, 148, 201, 6, 18, Direction.VERTICAL );
pb = new GuiProgressBar( container, "guis/mac.png", 139, 36, 148, 201, 6, 18, Direction.VERTICAL );
this.buttonList.add( pb );
}
@ -36,10 +36,7 @@ public class GuiMAC extends GuiUpgradeable
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
{
pb.max = 100;
pb.current = container.craftProgress;
pb.FullMsg = pb.current + "%";
pb.setFullMsg( container.getCurrentProgress() + "%" );
super.drawFG( offsetX, offsetY, mouseX, mouseY );
}
@ -56,7 +53,8 @@ public class GuiMAC extends GuiUpgradeable
return "guis/mac.png";
}
public GuiMAC(InventoryPlayer inventoryPlayer, TileMolecularAssembler te) {
public GuiMAC(InventoryPlayer inventoryPlayer, TileMolecularAssembler te)
{
super( new ContainerMAC( inventoryPlayer, te ) );
this.ySize = 197;
this.container = (ContainerMAC) this.inventorySlots;

View file

@ -17,7 +17,8 @@ public class GuiVibrationChamber extends AEBaseGui
ContainerVibrationChamber cvc;
GuiProgressBar pb;
public GuiVibrationChamber(InventoryPlayer inventoryPlayer, TileVibrationChamber te) {
public GuiVibrationChamber(InventoryPlayer inventoryPlayer, TileVibrationChamber te)
{
super( new ContainerVibrationChamber( inventoryPlayer, te ) );
cvc = (ContainerVibrationChamber) inventorySlots;
this.ySize = 166;
@ -28,7 +29,7 @@ public class GuiVibrationChamber extends AEBaseGui
{
super.initGui();
pb = new GuiProgressBar( "guis/vibchamber.png", 99, 36, 176, 14, 6, 18, Direction.VERTICAL );
pb = new GuiProgressBar( cvc, "guis/vibchamber.png", 99, 36, 176, 14, 6, 18, Direction.VERTICAL );
this.buttonList.add( pb );
}
@ -50,13 +51,11 @@ public class GuiVibrationChamber extends AEBaseGui
int k = 25;
int l = -15;
pb.max = 200;
pb.current = cvc.burnProgress > 0 ? cvc.burnSpeed : 0;
pb.FullMsg = (cvc.aePerTick * pb.current / 100) + " ae/t";
pb.setFullMsg( cvc.aePerTick * cvc.getCurrentProgress() / 100 + " ae/t" );
if ( cvc.burnProgress > 0 )
if ( cvc.getCurrentProgress() > 0 )
{
int i1 = cvc.burnProgress;
int i1 = cvc.getCurrentProgress();
bindTexture( "guis/vibchamber.png" );
GL11.glColor3f( 1, 1, 1 );
this.drawTexturedModalRect( k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2 );

View file

@ -3,6 +3,7 @@ package appeng.client.gui.widgets;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.ResourceLocation;
import appeng.container.interfaces.IProgressProvider;
import appeng.core.localization.GuiText;
public class GuiProgressBar extends GuiButton implements ITooltip
@ -13,29 +14,33 @@ public class GuiProgressBar extends GuiButton implements ITooltip
HORIZONTAL, VERTICAL
}
private IProgressProvider source;
private ResourceLocation texture;
private int fill_u;
private int fill_v;
private Direction layout;
public String FullMsg;
private String fullMsg;
private final String titleName;
public String TitleName;
public int current;
public int max;
public GuiProgressBar(IProgressProvider source, String texture, int posX, int posY, int u, int y, int _width, int _height, Direction dir)
{
this( source, texture, posX, posY, u, y, _width, _height, dir, null );
}
public GuiProgressBar(String string, int posX, int posY, int u, int y, int _width, int _height, Direction dir) {
public GuiProgressBar(IProgressProvider source, String texture, int posX, int posY, int u, int y, int _width, int _height, Direction dir, String title)
{
super( posX, posY, _width, "" );
this.source = source;
this.xPosition = posX;
this.yPosition = posY;
texture = new ResourceLocation( "appliedenergistics2", "textures/" + string );
this.texture = new ResourceLocation( "appliedenergistics2", "textures/" + texture );
width = _width;
height = _height;
fill_u = u;
fill_v = y;
current = 0;
max = 100;
layout = dir;
titleName = title;
}
@Override
@ -44,6 +49,8 @@ public class GuiProgressBar extends GuiButton implements ITooltip
if ( this.visible )
{
par1Minecraft.getTextureManager().bindTexture( texture );
int max = source.getMaxProgress();
int current = source.getCurrentProgress();
if ( layout == Direction.VERTICAL )
{
@ -60,13 +67,18 @@ public class GuiProgressBar extends GuiButton implements ITooltip
}
}
public void setFullMsg(String msg)
{
this.fullMsg = msg;
}
@Override
public String getMsg()
{
if ( FullMsg != null )
return FullMsg;
if ( fullMsg != null )
return fullMsg;
return (TitleName != null ? TitleName : "") + "\n" + current + " " + GuiText.Of.getLocal() + " " + max;
return (titleName != null ? titleName : "") + "\n" + source.getCurrentProgress() + " " + GuiText.Of.getLocal() + " " + source.getMaxProgress();
}
@Override

View file

@ -5,12 +5,13 @@ import appeng.api.config.CondenserOutput;
import appeng.api.config.Settings;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.interfaces.IProgressProvider;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.misc.TileCondenser;
import appeng.util.Platform;
public class ContainerCondenser extends AEBaseContainer
public class ContainerCondenser extends AEBaseContainer implements IProgressProvider
{
TileCondenser condenser;
@ -52,4 +53,16 @@ public class ContainerCondenser extends AEBaseContainer
@GuiSync(2)
public CondenserOutput output = CondenserOutput.TRASH;
@Override
public int getCurrentProgress()
{
return (int) storedPower;
}
@Override
public int getMaxProgress()
{
return (int) requiredEnergy;
}
}

View file

@ -5,6 +5,7 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.container.guisync.GuiSync;
import appeng.container.interfaces.IProgressProvider;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.recipes.handlers.Inscribe;
@ -12,7 +13,7 @@ import appeng.recipes.handlers.Inscribe.InscriberRecipe;
import appeng.tile.misc.TileInscriber;
import appeng.util.Platform;
public class ContainerInscriber extends ContainerUpgradeable
public class ContainerInscriber extends ContainerUpgradeable implements IProgressProvider
{
TileInscriber ti;
@ -157,4 +158,16 @@ public class ContainerInscriber extends ContainerUpgradeable
this.processingTime = ti.processingTime;
}
}
@Override
public int getCurrentProgress()
{
return processingTime;
}
@Override
public int getMaxProgress()
{
return maxProcessingTime;
}
}

View file

@ -9,6 +9,7 @@ import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.container.guisync.GuiSync;
import appeng.container.interfaces.IProgressProvider;
import appeng.container.slot.SlotMACPattern;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
@ -16,12 +17,14 @@ import appeng.items.misc.ItemEncodedPattern;
import appeng.tile.crafting.TileMolecularAssembler;
import appeng.util.Platform;
public class ContainerMAC extends ContainerUpgradeable
public class ContainerMAC extends ContainerUpgradeable implements IProgressProvider
{
TileMolecularAssembler tma;
private static final int MAX_CRAFT_PROGRESS = 100;
public ContainerMAC(InventoryPlayer ip, TileMolecularAssembler te) {
public ContainerMAC(InventoryPlayer ip, TileMolecularAssembler te)
{
super( ip, te );
tma = te;
}
@ -92,11 +95,16 @@ public class ContainerMAC extends ContainerUpgradeable
offY = 17;
IInventory upgrades = upgradeable.getInventoryByName( "upgrades" );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0, invPlayer ))
.setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1, invPlayer ))
.setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, invPlayer ))
.setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, invPlayer ))
.setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, invPlayer ))
.setNotDraggable() );
}
@Override
@ -114,4 +122,16 @@ public class ContainerMAC extends ContainerUpgradeable
standardDetectAndSendChanges();
}
@Override
public int getCurrentProgress()
{
return craftProgress;
}
@Override
public int getMaxProgress()
{
return MAX_CRAFT_PROGRESS;
}
}

View file

@ -3,14 +3,16 @@ package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.interfaces.IProgressProvider;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.misc.TileVibrationChamber;
import appeng.util.Platform;
public class ContainerVibrationChamber extends AEBaseContainer
public class ContainerVibrationChamber extends AEBaseContainer implements IProgressProvider
{
TileVibrationChamber vibrationChamber;
private static final int MAX_BURN_TIME = 200;
public ContainerVibrationChamber(InventoryPlayer ip, TileVibrationChamber vibrationChamber) {
super( ip, vibrationChamber, null );
@ -41,4 +43,16 @@ public class ContainerVibrationChamber extends AEBaseContainer
super.detectAndSendChanges();
}
@Override
public int getCurrentProgress()
{
return burnProgress > 0 ? burnSpeed : 0;
}
@Override
public int getMaxProgress()
{
return MAX_BURN_TIME;
}
}

View file

@ -0,0 +1,32 @@
package appeng.container.interfaces;
import appeng.client.gui.widgets.GuiProgressBar;
/**
* This interface provides the data for anything simulating a progress.
*
* Its main use is in combination with the {@link GuiProgressBar}, which ensures to scale it to a percentage of 0 to
* 100.
*
*/
public interface IProgressProvider
{
/**
* The current value of the progress. It should cover a range from 0 to the max progress
*
* @return An int representing the current progress
*/
int getCurrentProgress();
/**
* The max value the progress.
*
* It is not limited to a value of 100 and can be scaled to fit the current needs. For example scaled down to
* decrease or scaled up to increase the precision.
*
* @return An int representing the max progress
*/
int getMaxProgress();
}