Created a debug frame for pipes, improved visuals of debug frames

This commit is contained in:
Robert S 2014-06-15 14:06:10 -04:00
parent 324eb54cd0
commit d7cb8c8a64
7 changed files with 244 additions and 12 deletions

View File

@ -3,17 +3,15 @@ package resonantinduction.mechanical.energy.grid;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.util.Map.Entry;
import javax.swing.AbstractListModel;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import net.minecraftforge.common.ForgeDirection;
import resonant.api.grid.INode;
import resonant.api.grid.INodeProvider;
import resonantinduction.core.debug.FrameNodeDebug;
import resonantinduction.core.debug.UpdatePanel;
import resonantinduction.core.debug.UpdatedLabel;
/** Java GUI used to help debug gear information
@ -31,7 +29,7 @@ public class MechanicalNodeFrame extends FrameNodeDebug
}
@Override
public void buildTop(Panel panel)
public void buildTop(UpdatePanel panel)
{
panel.setLayout(new GridLayout(1, 2, 0, 0));
UpdatedLabel tickLabel = new UpdatedLabel("Node: ")
@ -56,7 +54,7 @@ public class MechanicalNodeFrame extends FrameNodeDebug
}
@Override
public void buildRight(Panel panel)
public void buildRight(UpdatePanel panel)
{
panel.setLayout(new GridLayout(2, 1, 0, 0));
@ -91,7 +89,7 @@ public class MechanicalNodeFrame extends FrameNodeDebug
}
@Override
public void buildLeft(Panel panel)
public void buildLeft(UpdatePanel panel)
{
panel.setLayout(new GridLayout(3, 1, 0, 0));
UpdatedLabel velLabel = new UpdatedLabel("Vel: ")

View File

@ -1,9 +1,12 @@
package resonantinduction.mechanical.fluid.pipe;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
@ -12,6 +15,7 @@ import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import resonant.api.grid.INode;
import resonant.core.ResonantEngine;
import resonant.lib.type.EvictingList;
import resonant.lib.utility.WorldUtility;
import resonantinduction.core.ResonantInduction;
@ -19,12 +23,14 @@ import resonantinduction.core.grid.fluid.FluidPressureNode;
import resonantinduction.core.grid.fluid.IPressureNodeProvider;
import resonantinduction.core.prefab.part.PartFramedNode;
import resonantinduction.mechanical.Mechanical;
import resonantinduction.mechanical.energy.grid.MechanicalNodeFrame;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.IconTransformation;
import codechicken.lib.render.RenderUtils;
import codechicken.lib.vec.Translation;
import codechicken.microblock.IHollowConnect;
import codechicken.multipart.ControlKeyModifer;
import codechicken.multipart.JNormalOcclusion;
import codechicken.multipart.TSlottedPart;
import cpw.mods.fml.relauncher.Side;
@ -39,6 +45,7 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode
/** Computes the average fluid for client to render. */
private EvictingList<Integer> averageTankData = new EvictingList<Integer>(20);
private boolean markPacket = true;
private PipeNodeFrame frame = null;
public PartPipe()
{
@ -81,6 +88,11 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode
{
sendFluidUpdate();
markPacket = false;
}
if (frame != null)
{
frame.update();
}
}
@ -220,4 +232,44 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode
public void onFluidChanged()
{
}
@Override
public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack itemStack)
{
if (ResonantEngine.runningAsDev)
{
if (itemStack != null && !world().isRemote)
{
if (itemStack.getItem().itemID == Item.stick.itemID)
{
//Set the nodes debug mode
if (ControlKeyModifer.isControlDown(player))
{
//Opens a debug GUI
if (frame == null)
{
frame = new PipeNodeFrame(this);
frame.showDebugFrame();
} //Closes the debug GUI
else
{
frame.closeDebugFrame();
frame = null;
}
}
}
}
}
return super.activate(player, hit, itemStack);
}
@Override
public void onWorldSeparate()
{
super.onWorldSeparate();
if (frame != null)
{
frame.closeDebugFrame();
}
}
}

View File

@ -0,0 +1,150 @@
package resonantinduction.mechanical.fluid.pipe;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
import net.minecraftforge.common.ForgeDirection;
import resonant.api.grid.INode;
import resonant.api.grid.INodeProvider;
import resonantinduction.core.debug.FrameNodeDebug;
import resonantinduction.core.debug.UpdatePanel;
import resonantinduction.core.debug.UpdatedLabel;
/** Java GUI used to help debug pipe information
*
* @author Darkguardsman */
@SuppressWarnings("serial")
public class PipeNodeFrame extends FrameNodeDebug
{
public PipeNodeFrame(INodeProvider node)
{
super(node, PipePressureNode.class);
}
@Override
public void buildTop(UpdatePanel panel)
{
panel.setLayout(new GridLayout(1, 2, 0, 0));
UpdatedLabel tickLabel = new UpdatedLabel("Node: ")
{
@Override
public String buildLabel()
{
return super.buildLabel() + PipeNodeFrame.this.getNode();
}
};
panel.add(tickLabel);
UpdatedLabel xLabel = new UpdatedLabel("Parent: ")
{
@Override
public String buildLabel()
{
return super.buildLabel() + (PipeNodeFrame.this.getNode() != null ? PipeNodeFrame.this.getNode().pipe() : "null");
}
};
panel.add(xLabel);
}
@Override
public void buildRight(UpdatePanel panel)
{
TableModel dataModel = new AbstractTableModel()
{
@Override
public int getColumnCount()
{
return 3;
}
@Override
public String getColumnName(int column)
{
switch (column)
{
case 0:
return "Direction";
case 1:
return "Tile";
case 2:
return "Pressure";
}
return "---";
}
@Override
public int getRowCount()
{
if (getNode() != null && getNode().getConnections() != null)
{
return getNode().getConnections().size();
}
return 10;
}
@Override
public Object getValueAt(int row, int col)
{
if (getNode() != null && getNode().getConnections() != null)
{
ForgeDirection dir = (ForgeDirection) getNode().getConnections().values().toArray()[row];
switch(col)
{
case 0: return dir;
case 1: return getNode().getConnections().keySet().toArray()[row];
case 2: return getNode().getPressure(dir);
}
}
return "00000";
}
};
JTable table = new JTable(dataModel);
table.setAutoCreateRowSorter(true);
JScrollPane tableScroll = new JScrollPane(table);
Dimension tablePreferred = tableScroll.getPreferredSize();
tableScroll.setPreferredSize(new Dimension(tablePreferred.width, tablePreferred.height / 3));
panel.add(tableScroll);
}
@Override
public void buildLeft(UpdatePanel panel)
{
panel.setLayout(new GridLayout(2, 1, 0, 0));
UpdatedLabel velLabel = new UpdatedLabel("Fluid: ")
{
@Override
public String buildLabel()
{
return super.buildLabel() + PipeNodeFrame.this.getNode().pipe().tank.getFluid();
}
};
panel.add(velLabel);
UpdatedLabel angleLabel = new UpdatedLabel("Volume: ")
{
@Override
public String buildLabel()
{
return super.buildLabel() + PipeNodeFrame.this.getNode().pipe().tank.getFluidAmount() + "mb";
}
};
panel.add(angleLabel);
}
@Override
public PipePressureNode getNode()
{
INode node = super.getNode();
if (node instanceof PipePressureNode)
{
return (PipePressureNode) node;
}
return null;
}
}

View File

@ -103,4 +103,10 @@ public class PipePressureNode extends FluidPressureNode
return false;
}
@Override
public String toString()
{
return this.getClass().getSimpleName() + this.hashCode();
}
}

View File

@ -4,10 +4,15 @@ import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.Panel;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.api.vector.IVectorWorld;
@ -36,12 +41,16 @@ public class FrameDebug extends Frame implements IVectorWorld
/** Called to build the base of the GUI */
protected void buildGUI()
{
Border loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
UpdatePanel topPanel = new UpdatePanel();
UpdatePanel botPanel = new UpdatePanel();
UpdatePanel leftPanel = new UpdatePanel();
UpdatePanel rightPanel = new UpdatePanel();
setLayout(new BorderLayout());
topPanel.setBorder(loweredetched);
botPanel.setBorder(loweredetched);
leftPanel.setBorder(loweredetched);
rightPanel.setBorder(loweredetched);
buildTop(topPanel);
buildBottom(botPanel);
@ -66,7 +75,7 @@ public class FrameDebug extends Frame implements IVectorWorld
}
/** Top are of the Frame */
public void buildTop(Panel panel)
public void buildTop(UpdatePanel panel)
{
panel.setLayout(new GridLayout(1, 2, 0, 0));
UpdatedLabel tickLabel = new UpdatedLabel("Tile: ")
@ -81,7 +90,7 @@ public class FrameDebug extends Frame implements IVectorWorld
}
/** Bottom are of the Frame */
public void buildBottom(Panel panel)
public void buildBottom(UpdatePanel panel)
{
panel.setLayout(new GridLayout(1, 4, 0, 0));
UpdatedLabel tickLabel = new UpdatedLabel("Tick: ")
@ -126,7 +135,7 @@ public class FrameDebug extends Frame implements IVectorWorld
}
/** Left are of the Frame */
public void buildRight(Panel panel)
public void buildRight(UpdatePanel panel)
{
panel.setLayout(new GridLayout(1, 2, 0, 0));
UpdatedLabel tickLabel = new UpdatedLabel("Valid: ")
@ -141,7 +150,7 @@ public class FrameDebug extends Frame implements IVectorWorld
}
/** Right are of the Frame */
public void buildLeft(Panel panel)
public void buildLeft(UpdatePanel panel)
{
panel.setLayout(new GridLayout(4, 1, 0, 0));
UpdatedLabel block_label = new UpdatedLabel("BLOCK: ")

View File

@ -1,13 +1,24 @@
package resonantinduction.core.debug;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Panel;
import javax.swing.JPanel;
/** @author Darkguardsman */
@SuppressWarnings("serial")
public class UpdatePanel extends Panel implements IUpdate
public class UpdatePanel extends JPanel implements IUpdate
{
public UpdatePanel()
{
}
public UpdatePanel(BorderLayout borderLayout)
{
super(borderLayout);
}
@Override
public void update()
{

View File

@ -308,4 +308,10 @@ public abstract class PartFramedNode<M extends Enum, N extends Node, T extends I
super.load(nbt);
node.load(nbt);
}
@Override
public String toString()
{
return this.getClass().getSimpleName() + this.hashCode();
}
}