diff --git a/src/com/brindyblitz/artemis/engconsole/EngineeringConsoleManager.java b/src/com/brindyblitz/artemis/engconsole/EngineeringConsoleManager.java index ba490fe..53c3c89 100644 --- a/src/com/brindyblitz/artemis/engconsole/EngineeringConsoleManager.java +++ b/src/com/brindyblitz/artemis/engconsole/EngineeringConsoleManager.java @@ -87,7 +87,7 @@ public float getZ() { @Override public String toString() { - return "Team #" + getTeamNumber() + " (" + getMembers() + ") @ " + + return "Team #" + getTeamNumber() + " (" + getMembers() + " members) @ " + "(" + this.x + "," + this.y + "," + this.z + ")"; } } diff --git a/src/com/brindyblitz/artemis/engconsole/FakeEngineeringConsoleManager.java b/src/com/brindyblitz/artemis/engconsole/FakeEngineeringConsoleManager.java index 6b2d529..99ee153 100644 --- a/src/com/brindyblitz/artemis/engconsole/FakeEngineeringConsoleManager.java +++ b/src/com/brindyblitz/artemis/engconsole/FakeEngineeringConsoleManager.java @@ -75,7 +75,8 @@ public Map getGridHealth() { @Override protected List getRawDamconStatus() { - return Arrays.asList(new DamconStatus(0, 6, 2, 2, 2, 2, 2, 3, 0.3f)); + // return Arrays.asList(new DamconStatus(0, 6, 2, 2, 2, 2, 2, 3, 0.3f)); + return Arrays.asList(new DamconStatus(0, 6, 2, 0, 6, 2, 0, 6, 0f)); } @Override diff --git a/src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java b/src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java index b2f8d77..6f080ea 100644 --- a/src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java +++ b/src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java @@ -29,7 +29,6 @@ import net.dhleong.acl.util.GridCoord; import net.dhleong.acl.vesseldata.VesselNode; import net.dhleong.acl.vesseldata.VesselNodeConnection; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; public class Damcon implements MouseListener, MouseMotionListener, MouseWheelListener { private static final int WIDTH = 400, HEIGHT = 300; @@ -72,6 +71,7 @@ public class Damcon implements MouseListener, MouseMotionListener, MouseWheelLis private Map nodesToSelectables = new HashMap<>(); // TODO: use setUserData() on nodes rather than table lookup? private static final float PICK_TOLERANCE = 0.1f; + private BranchGroup damconBranchGroup; private InternalTeam selected = null; public Damcon(EngineeringConsoleManager engineeringConsoleManager) { @@ -136,9 +136,10 @@ private void loadInternalNodesAndDamconTeams() { this.universe.addBranchGraph(node_branchgroup); - BranchGroup damcon_branchgroup = new BranchGroup(); - damcon_branchgroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); - damcon_branchgroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); + damconBranchGroup = new BranchGroup(); + damconBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); + damconBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); + this.universe.addBranchGraph(damconBranchGroup); this.engineeringConsoleManager.addChangeListener(new EngineeringConsoleManager.EngineeringConsoleChangeListener() { @Override @@ -149,19 +150,19 @@ public void onChange() { } for (EngineeringConsoleManager.EnhancedDamconStatus damconStatus : engineeringConsoleManager.getDamconTeams()) { - InternalTeam it = internalTeams.get(damconStatus.getTeamNumber()); - if (it == null) { - it = new InternalTeam(damconStatus); - internalTeams.put(damconStatus.getTeamNumber(), it); + InternalTeam it = internalTeams.get(damconStatus.getTeamNumber()); + + if (it == null) { + it = new InternalTeam(damconStatus); + internalTeams.put(damconStatus.getTeamNumber(), it); nodesToSelectables.put(it.getShape(), it); - damcon_branchgroup.addChild(it.getBranchGroup()); - } - it.updatePos(damconStatus.getX(), damconStatus.getY(), damconStatus.getZ()); + damconBranchGroup.addChild(it.getBranchGroup()); + } + + it.updatePos(damconStatus.getX(), damconStatus.getY(), damconStatus.getZ()); } } }); - - this.universe.addBranchGraph(damcon_branchgroup); } private void loadCorridors() { @@ -208,7 +209,7 @@ private void addMouseListeners() { this.canvas = universe.getCanvas(); pickCanvas = new PickCanvas(this.canvas, this.universe.getLocale()); - pickCanvas.setMode(PickInfo.PICK_GEOMETRY); // TODO: > needs to be PICK_GEOMETRY_INTERSECT_INFO? see https://community.oracle.com/thread/1276552?start=0&tstart=0 + pickCanvas.setMode(PickInfo.PICK_GEOMETRY); pickCanvas.setFlags(PickInfo.NODE | PickInfo.CLOSEST_INTERSECTION_POINT); pickCanvas.setTolerance(PICK_TOLERANCE); @@ -285,12 +286,26 @@ private static Appearance getWireframeAppearance(int line_attributes_pattern) { /////////// private InternalSelectable pick(MouseEvent e) { - // TODO: DAMCON > Use pickAll(). Prioritize as follows: - // DAMCON teams, system nodes, non-system nodes, hallways (maybe prioritize nodes if DAMCON currently selected) pickCanvas.setShapeLocation(e); - PickInfo pi = pickCanvas.pickClosest(); - - return pi == null ? null : nodesToSelectables.get(pi.getNode()); + PickInfo[] picks = pickCanvas.pickAllSorted(); + if (picks == null) + return null; + + InternalNode nearest_node = null; + for (PickInfo pi : picks) { + InternalSelectable i = nodesToSelectables.get(pi.getNode()); + + if (i == null) { + continue; // TODO: BUG? > skip non-selectable nodes; this is necessary, but should it be? + } else if (i.getClass().equals(InternalTeam.class)) { + return i; // prioritize DAMCON teams + } else { // if (i.getClass().equals(InternalNode.class)) + if (nearest_node == null) { + nearest_node = (InternalNode)i; // store nearest node to camera + } + } + } + return nearest_node; // if we didn't pick a DAMCON team, return picked node closest to camera (or null) } @Override diff --git a/src/com/brindyblitz/artemis/engconsole/ui/damcon/InternalTeam.java b/src/com/brindyblitz/artemis/engconsole/ui/damcon/InternalTeam.java index 853fdd0..76f0a0b 100644 --- a/src/com/brindyblitz/artemis/engconsole/ui/damcon/InternalTeam.java +++ b/src/com/brindyblitz/artemis/engconsole/ui/damcon/InternalTeam.java @@ -30,7 +30,6 @@ public InternalTeam(EngineeringConsoleManager.EnhancedDamconStatus damcon_status setPickable(shape); this.transformGroup = new TransformGroup(); - updatePos(this.status.getX(), this.status.getY(), this.status.getZ()); this.transformGroup.addChild(sphere); this.transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); this.branchGroup.addChild(transformGroup); @@ -59,8 +58,6 @@ public void setSelected(boolean selected) { this.selected = selected; this.sphere.setAppearance(appearanceFromHealthPercentage()); - - // TODO: >>> Track who's selected and issue orders on click of system node when selection != null } @Override