package mcjty.rftools.blocks.spaceprojector;
import mcjty.lib.container.GenericGuiContainer;
import mcjty.lib.gui.Window;
import mcjty.lib.gui.events.ButtonEvent;
import mcjty.lib.gui.events.ChoiceEvent;
import mcjty.lib.gui.layout.PositionalLayout;
import mcjty.lib.gui.widgets.Button;
import mcjty.lib.gui.widgets.*;
import mcjty.lib.gui.widgets.Panel;
import mcjty.lib.network.Argument;
import mcjty.rftools.RFTools;
import mcjty.rftools.blocks.RedstoneMode;
import mcjty.rftools.network.RFToolsMessages;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import java.awt.*;
public class GuiSpaceProjector extends GenericGuiContainer<SpaceProjectorTileEntity> {
public static final int PROJECTOR_WIDTH = 180;
public static final int PROJECTOR_HEIGHT = 152;
private EnergyBar energyBar;
private ImageChoiceLabel redstoneMode;
private Button projectButton;
private static final ResourceLocation iconLocation = new ResourceLocation(RFTools.MODID, "textures/gui/spaceprojector.png");
private static final ResourceLocation iconGuiElements = new ResourceLocation(RFTools.MODID, "textures/gui/guielements.png");
public GuiSpaceProjector(SpaceProjectorTileEntity spaceProjectorTileEntity, SpaceProjectorContainer container) {
super(RFTools.instance, RFToolsMessages.INSTANCE, spaceProjectorTileEntity, container, RFTools.GUI_MANUAL_MAIN, null);
spaceProjectorTileEntity.setCurrentRF(spaceProjectorTileEntity.getEnergyStored(ForgeDirection.DOWN));
xSize = PROJECTOR_WIDTH;
ySize = PROJECTOR_HEIGHT;
}
@Override
public void initGui() {
super.initGui();
int maxEnergyStored = tileEntity.getMaxEnergyStored(ForgeDirection.DOWN);
energyBar = new EnergyBar(mc, this).setVertical().setMaxValue(maxEnergyStored).setLayoutHint(new PositionalLayout.PositionalHint(10, 7, 8, 54)).setShowText(false);
energyBar.setValue(tileEntity.getCurrentRF());
projectButton = new Button(mc, this).setText("Update").setLayoutHint(new PositionalLayout.PositionalHint(100, 7, 70, 16)).addButtonEvent(new ButtonEvent() {
@Override
public void buttonClicked(Widget parent) {
updateProjection();
}
});
initRedstoneMode();
Widget toplevel = new Panel(mc, this).setBackground(iconLocation).setLayout(new PositionalLayout()).addChild(energyBar).
addChild(redstoneMode).addChild(projectButton);
toplevel.setBounds(new Rectangle(guiLeft, guiTop, xSize, ySize));
window = new Window(this, toplevel);
tileEntity.requestRfFromServer(RFToolsMessages.INSTANCE);
}
private void updateProjection() {
sendServerCommand(RFToolsMessages.INSTANCE, SpaceProjectorTileEntity.CMD_PROJECT);
}
private void initRedstoneMode() {
redstoneMode = new ImageChoiceLabel(mc, this).
addChoiceEvent(new ChoiceEvent() {
@Override
public void choiceChanged(Widget parent, String newChoice) {
changeRedstoneMode();
}
}).
addChoice(RedstoneMode.REDSTONE_IGNORED.getDescription(), "Redstone mode:\nIgnored", iconGuiElements, 0, 0).
addChoice(RedstoneMode.REDSTONE_OFFREQUIRED.getDescription(), "Redstone mode:\nOff to activate", iconGuiElements, 16, 0).
addChoice(RedstoneMode.REDSTONE_ONREQUIRED.getDescription(), "Redstone mode:\nOn to activate", iconGuiElements, 32, 0);
redstoneMode.setLayoutHint(new PositionalLayout.PositionalHint(150, 46, 16, 16));
redstoneMode.setCurrentChoice(tileEntity.getRedstoneMode().ordinal());
}
private void changeRedstoneMode() {
tileEntity.setRedstoneMode(RedstoneMode.values()[redstoneMode.getCurrentChoiceIndex()]);
sendServerCommand(RFToolsMessages.INSTANCE, SpaceProjectorTileEntity.CMD_RSMODE, new Argument("rs", RedstoneMode.values()[redstoneMode.getCurrentChoiceIndex()].getDescription()));
}
@Override
protected void drawGuiContainerBackgroundLayer(float v, int i, int i2) {
drawWindow();
energyBar.setValue(tileEntity.getCurrentRF());
tileEntity.requestRfFromServer(RFToolsMessages.INSTANCE);
}
}