Skip to content

Commit

Permalink
WIP #12: Sort picks
Browse files Browse the repository at this point in the history
- DAMCON teams get first priority
- After that, the nearest node is picked
  • Loading branch information
jacobmaxfrank committed Jan 30, 2016
1 parent a26c9fe commit 2b0c702
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ")";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public Map<GridCoord, Float> getGridHealth() {

@Override
protected List<DamconStatus> 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
Expand Down
53 changes: 34 additions & 19 deletions src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,6 +71,7 @@ public class Damcon implements MouseListener, MouseMotionListener, MouseWheelLis
private Map<Node, InternalSelectable> 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) {
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2b0c702

Please sign in to comment.