Highly improved multimeter gui and redstone control logic
This commit is contained in:
parent
3e20c039bb
commit
a4fdf17a64
8 changed files with 106 additions and 75 deletions
|
@ -13,6 +13,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
*/
|
||||
public abstract class Graph<V extends Comparable<V>>
|
||||
{
|
||||
public final String name;
|
||||
|
||||
private final int maxPoints;
|
||||
|
||||
/**
|
||||
|
@ -26,8 +28,9 @@ public abstract class Graph<V extends Comparable<V>>
|
|||
*/
|
||||
protected V queue = getDefault();
|
||||
|
||||
public Graph(int maxPoints)
|
||||
public Graph(String name, int maxPoints)
|
||||
{
|
||||
this.name = name;
|
||||
this.maxPoints = maxPoints;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ import net.minecraft.nbt.NBTTagList;
|
|||
|
||||
public class GraphF extends Graph<Float>
|
||||
{
|
||||
public GraphF(int maxPoints)
|
||||
public GraphF(String name, int maxPoints)
|
||||
{
|
||||
super(maxPoints);
|
||||
super(name, maxPoints);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,9 +5,9 @@ import net.minecraft.nbt.NBTTagList;
|
|||
|
||||
public class GraphI extends Graph<Integer>
|
||||
{
|
||||
public GraphI(int maxPoints)
|
||||
public GraphI(String name,int maxPoints)
|
||||
{
|
||||
super(maxPoints);
|
||||
super(name,maxPoints);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,9 +5,9 @@ import net.minecraft.nbt.NBTTagList;
|
|||
|
||||
public class GraphL extends Graph<Long>
|
||||
{
|
||||
public GraphL(int maxPoints)
|
||||
public GraphL(String name,int maxPoints)
|
||||
{
|
||||
super(maxPoints);
|
||||
super(name,maxPoints);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,17 +32,18 @@ public class GuiMultimeter extends GuiContainerBase
|
|||
super(new ContainerMultimeter(inventoryPlayer, tileEntity));
|
||||
this.multimeter = tileEntity;
|
||||
this.ySize = 217;
|
||||
this.baseTexture = new ResourceLocation(Reference.DOMAIN, Reference.GUI_DIRECTORY + "gui_multimeter.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
this.buttonList.add(new GuiButton(0, this.width / 2 + 20, this.height / 2 - 30, 50, 20, LanguageUtility.getLocal("gui.resonantinduction.multimeter.toggle")));
|
||||
this.textFieldLimit = new GuiTextField(fontRenderer, 35, 82, 65, 12);
|
||||
this.buttonList.add(new GuiButton(0, this.width / 2 + 20, this.height / 2 - 23, 50, 20, LanguageUtility.getLocal("gui.resonantinduction.multimeter.toggle")));
|
||||
this.buttonList.add(new GuiButton(1, this.width / 2 - 80, this.height / 2 - 75, 100, 20, "Toggle Detection"));
|
||||
this.buttonList.add(new GuiButton(2, this.width / 2 - 80, this.height / 2 + 0, 80, 20, "Toggle Graph"));
|
||||
this.textFieldLimit = new GuiTextField(fontRenderer, 9, 90, 90, 12);
|
||||
this.textFieldLimit.setMaxStringLength(8);
|
||||
this.textFieldLimit.setText("" + this.multimeter.getLimit());
|
||||
this.textFieldLimit.setText("" + this.multimeter.redstoneTriggerLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,7 +54,8 @@ public class GuiMultimeter extends GuiContainerBase
|
|||
|
||||
try
|
||||
{
|
||||
this.multimeter.getWriteStream().writeByte(1).writeLong(Long.parseLong(this.textFieldLimit.getText()));
|
||||
multimeter.redstoneTriggerLimit = Integer.parseInt(this.textFieldLimit.getText());
|
||||
multimeter.updateServer();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -67,20 +69,29 @@ public class GuiMultimeter extends GuiContainerBase
|
|||
this.textFieldLimit.mouseClicked(par1 - this.containerWidth, par2 - this.containerHeight, par3);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
switch (button.id)
|
||||
{
|
||||
case 0:
|
||||
multimeter.toggleMode();
|
||||
break;
|
||||
case 1:
|
||||
multimeter.toggleDetectionValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
|
||||
{
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
String s = LanguageUtility.getLocal("tile.resonantinduction:multimeter.name");
|
||||
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 15, 4210752);
|
||||
this.fontRenderer.drawString(EnumColor.INDIGO + LanguageUtility.getLocal("gui.resonantinduction.multimeter.energy"), 35, 15, 4210752);
|
||||
this.renderUniversalDisplay(35, 25, this.multimeter.getNetwork().energyGraph.get(0), mouseX, mouseY, Unit.JOULES);
|
||||
this.fontRenderer.drawString(EnumColor.INDIGO + LanguageUtility.getLocal("gui.resonantinduction.multimeter.capacity"), 35, 35, 4210752);
|
||||
this.renderUniversalDisplay(35, 45, this.multimeter.getNetwork().energyGraph.getPeak(), mouseX, mouseY, Unit.JOULES);
|
||||
this.fontRenderer.drawString(EnumColor.ORANGE + LanguageUtility.getLocal("gui.resonantinduction.multimeter.redstone"), 35, 58, 4210752);
|
||||
this.fontRenderer.drawString(EnumColor.RED + LanguageUtility.getLocal("gui.resonantinduction.multimeter." + this.multimeter.getMode().display), 35, 68, 4210752);
|
||||
this.fontRenderer.drawString(Unit.JOULES.name + "(s)", 35, 100, 4210752);
|
||||
|
||||
String s = LanguageUtility.getLocal("item.resonantinduction:multimeter.name");
|
||||
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752);
|
||||
this.fontRenderer.drawString(EnumColor.INDIGO + "Detection Type", 9, 20, 4210752);
|
||||
this.fontRenderer.drawString(multimeter.getNetwork().getDisplay(multimeter.detectionValueType), 9, 60, 4210752);
|
||||
this.fontRenderer.drawString("Logic: " + EnumColor.RED + LanguageUtility.getLocal("gui.resonantinduction.multimeter." + this.multimeter.getMode().display), 9, 75, 4210752);
|
||||
this.textFieldLimit.drawTextBox();
|
||||
}
|
||||
|
||||
|
@ -90,10 +101,4 @@ public class GuiMultimeter extends GuiContainerBase
|
|||
super.drawGuiContainerBackgroundLayer(f, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
this.multimeter.toggleMode();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import java.util.List;
|
|||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import universalelectricity.api.energy.UnitDisplay;
|
||||
import universalelectricity.api.energy.UnitDisplay.Unit;
|
||||
import universalelectricity.api.net.IUpdate;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import universalelectricity.core.net.Network;
|
||||
|
@ -19,19 +21,17 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
* The available graphs to be handled.
|
||||
*/
|
||||
private int maxData = 20 * 10;
|
||||
private final List<Graph> graphs = new ArrayList<Graph>();
|
||||
public final List<Graph> graphs = new ArrayList<Graph>();
|
||||
/**
|
||||
* Energy Related
|
||||
*/
|
||||
public final GraphL energyGraph = new GraphL(maxData);
|
||||
public final GraphL energyCapacityGraph = new GraphL(1);
|
||||
public final GraphL voltageGraph = new GraphL(maxData);
|
||||
public final GraphL torqueGraph = new GraphL(maxData);
|
||||
public final GraphF angularVelocityGraph = new GraphF(maxData);
|
||||
|
||||
public final GraphI fluidGraph = new GraphI(maxData);
|
||||
|
||||
public final GraphF thermalGraph = new GraphF(maxData);
|
||||
public final GraphL energyGraph = new GraphL("Energy", maxData);
|
||||
public final GraphL energyCapacityGraph = new GraphL("Max", 1);
|
||||
public final GraphL voltageGraph = new GraphL("Voltage", maxData);
|
||||
public final GraphL torqueGraph = new GraphL("Torque", maxData);
|
||||
public final GraphF angularVelocityGraph = new GraphF("Speed", maxData);
|
||||
public final GraphI fluidGraph = new GraphI("Fluid", maxData);
|
||||
public final GraphF thermalGraph = new GraphF("Temperature", maxData);
|
||||
|
||||
/**
|
||||
* The absolute center of the multimeter screens.
|
||||
|
@ -70,6 +70,37 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
graphs.add(thermalGraph);
|
||||
}
|
||||
|
||||
public String getDisplay(int graphID)
|
||||
{
|
||||
Graph graph = graphs.get(graphID);
|
||||
|
||||
String graphValue = "";
|
||||
|
||||
if (graph == energyGraph)
|
||||
graphValue = UnitDisplay.getDisplay(energyGraph.get(), Unit.JOULES);
|
||||
|
||||
if (graph == energyCapacityGraph)
|
||||
graphValue = UnitDisplay.getDisplay(energyCapacityGraph.get(), Unit.JOULES);
|
||||
|
||||
if (graph == voltageGraph)
|
||||
graphValue = UnitDisplay.getDisplay(voltageGraph.get(), Unit.VOLTAGE);
|
||||
|
||||
if (graph == torqueGraph)
|
||||
graphValue = UnitDisplay.getDisplayShort(torqueGraph.get(), Unit.NEWTON_METER);
|
||||
|
||||
if (graph == angularVelocityGraph)
|
||||
graphValue = UnitDisplay.roundDecimals(angularVelocityGraph.get()) + "";
|
||||
|
||||
if (graph == fluidGraph)
|
||||
graphValue = UnitDisplay.getDisplay(fluidGraph.get(), Unit.LITER);
|
||||
|
||||
if (graph == thermalGraph)
|
||||
graphValue = UnitDisplay.roundDecimals(thermalGraph.get()) + "";
|
||||
|
||||
return graph.name + ": " + graphValue;
|
||||
|
||||
}
|
||||
|
||||
public boolean isPrimary(PartMultimeter check)
|
||||
{
|
||||
return primaryMultimeter == check;
|
||||
|
|
|
@ -59,11 +59,13 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
|
||||
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
||||
|
||||
public double redstoneTriggerLimit;
|
||||
public int detectionValueType = 0;
|
||||
private DetectMode detectMode = DetectMode.NONE;
|
||||
private long redstoneTriggerLimit;
|
||||
|
||||
// TODO: Move warn settings over.
|
||||
public boolean redstoneOn;
|
||||
|
||||
public boolean isPrimary;
|
||||
|
||||
private MultimeterNetwork network;
|
||||
|
@ -363,7 +365,9 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
@Override
|
||||
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
|
||||
{
|
||||
toggleMode();
|
||||
detectMode = DetectMode.values()[data.readInt()];
|
||||
detectionValueType = data.readInt();
|
||||
redstoneTriggerLimit = data.readDouble();
|
||||
}
|
||||
|
||||
public TileEntity getDetectedTile()
|
||||
|
@ -412,14 +416,19 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
|
||||
public void toggleMode()
|
||||
{
|
||||
if (!this.world().isRemote)
|
||||
{
|
||||
detectMode = DetectMode.values()[(detectMode.ordinal() + 1) % DetectMode.values().length];
|
||||
}
|
||||
else
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_MULTIPART.getPacket(new universalelectricity.api.vector.Vector3(x(), y(), z()), placementSide.ordinal()));
|
||||
}
|
||||
detectMode = DetectMode.values()[(detectMode.ordinal() + 1) % DetectMode.values().length];
|
||||
updateServer();
|
||||
}
|
||||
|
||||
public void toggleDetectionValue()
|
||||
{
|
||||
detectionValueType = (detectionValueType + 1) % getNetwork().graphs.size();
|
||||
updateServer();
|
||||
}
|
||||
|
||||
public void updateServer()
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_MULTIPART.getPacket(new universalelectricity.api.vector.Vector3(x(), y(), z()), placementSide.ordinal(), detectMode.ordinal(), detectionValueType, redstoneTriggerLimit));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -428,7 +437,7 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
super.load(nbt);
|
||||
placementSide = ForgeDirection.getOrientation(nbt.getByte("side"));
|
||||
detectMode = DetectMode.values()[nbt.getByte("detectMode")];
|
||||
redstoneTriggerLimit = nbt.getLong("energyLimit");
|
||||
redstoneTriggerLimit = nbt.getDouble("triggerLimit");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -437,7 +446,7 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
super.save(nbt);
|
||||
nbt.setByte("side", (byte) placementSide.ordinal());
|
||||
nbt.setByte("detectMode", (byte) detectMode.ordinal());
|
||||
nbt.setLong("energyLimit", redstoneTriggerLimit);
|
||||
nbt.setDouble("triggerLimit", redstoneTriggerLimit);
|
||||
}
|
||||
|
||||
public DetectMode getMode()
|
||||
|
@ -445,11 +454,6 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
return detectMode;
|
||||
}
|
||||
|
||||
public float getLimit()
|
||||
{
|
||||
return redstoneTriggerLimit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
{
|
||||
|
|
|
@ -184,15 +184,13 @@ public class RenderMultimeter implements ISimpleItemRenderer
|
|||
GL11.glRotatef(90, 0, 1, 0);
|
||||
RenderUtility.rotateBlockBasedOnDirection(part.getFacing());
|
||||
}
|
||||
|
||||
|
||||
GL11.glTranslated(0, 0.07, 0);
|
||||
|
||||
List<String> information = new ArrayList<String>();
|
||||
|
||||
if (part.getNetwork().energyGraph.get(0) > 0 && part.getNetwork().energyGraph.points.size() > 0)
|
||||
{
|
||||
information.add(UnitDisplay.getDisplay(part.getNetwork().energyGraph.get(0), Unit.JOULES));
|
||||
|
||||
/**
|
||||
* Compute power
|
||||
*/
|
||||
|
@ -209,23 +207,13 @@ public class RenderMultimeter implements ISimpleItemRenderer
|
|||
information.add("Power: " + UnitDisplay.getDisplay(power * 20, Unit.WATT));
|
||||
}
|
||||
|
||||
if (part.getNetwork().energyCapacityGraph.get(0) > 0)
|
||||
information.add("Max: " + UnitDisplay.getDisplay(part.getNetwork().energyCapacityGraph.get(0), Unit.JOULES));
|
||||
|
||||
if (part.getNetwork().voltageGraph.get(0) > 0)
|
||||
information.add(UnitDisplay.getDisplay(part.getNetwork().voltageGraph.get(0), Unit.VOLTAGE));
|
||||
|
||||
if (part.getNetwork().torqueGraph.get(0) != 0)
|
||||
information.add("Torque: " + UnitDisplay.getDisplayShort(part.getNetwork().torqueGraph.get(0), Unit.NEWTON_METER));
|
||||
|
||||
if (part.getNetwork().angularVelocityGraph.get(0) != 0)
|
||||
information.add("Speed: " + UnitDisplay.roundDecimals(part.getNetwork().angularVelocityGraph.get(0)));
|
||||
|
||||
if (part.getNetwork().fluidGraph.get(0) != 0)
|
||||
information.add("Fluid: " + UnitDisplay.getDisplay(part.getNetwork().fluidGraph.get(0), Unit.LITER));
|
||||
|
||||
if (part.getNetwork().thermalGraph.get(0) != 0)
|
||||
information.add("Temperature: " + UnitDisplay.roundDecimals(part.getNetwork().thermalGraph.get(0) - 273) + " C");
|
||||
for (int i = 0; i < part.getNetwork().graphs.size(); i++)
|
||||
{
|
||||
if (part.getNetwork().graphs.get(i).get() != null && !part.getNetwork().graphs.get(i).get().equals(part.getNetwork().graphs.get(i).getDefault()))
|
||||
{
|
||||
information.add(part.getNetwork().getDisplay(i));
|
||||
}
|
||||
}
|
||||
|
||||
if (information.size() <= 0)
|
||||
information.add("No information");
|
||||
|
|
Loading…
Reference in a new issue