Skip to content

Commit

Permalink
WIP #12: Hover and selection both set full opacity
Browse files Browse the repository at this point in the history
Also refactored picking and appearance update
  • Loading branch information
jacobmaxfrank committed Jan 30, 2016
1 parent 0d4c4db commit ca21ce9
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 49 deletions.
40 changes: 27 additions & 13 deletions src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,27 +269,30 @@ private static Appearance getWireframeAppearance(int line_attributes_pattern) {
// Mouse //
///////////

private InternalSelectable pick(MouseEvent e) {
// TODO: DAMCON > Use pickAll(). Prioritize as follows:
// DAMCON teams, system nodes, non-system nodes, hallways
pickCanvas.setShapeLocation(e);
PickInfo pi = pickCanvas.pickClosest();

return pi == null ? null : nodesToSelectabls.get(pi.getNode());
}

@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == 1) {
pickCanvas.setShapeLocation(e);
PickInfo pi = pickCanvas.pickClosest();

// TODO: DAMCON > Use pickAll(). Prioritize as follows:
// DAMCON teams, system nodes, non-system nodes, hallways
InternalSelectable internal = pick(e);

if (e.getButton() == 1) {
// Clear existing selection state
for (InternalSelectable i : nodesToSelectabls.values()) {
i.setSelected(false);
}

if (pi == null) {
return;
// Set new selection state
if (internal != null) {
internal.setSelected(true);
System.out.println("Selecting " + internal);
}

Node scene_node = pi.getNode();
InternalSelectable internal = nodesToSelectabls.get(scene_node);
internal.setSelected(true);
System.out.println("Selecting " + internal);
}
}

Expand Down Expand Up @@ -403,6 +406,17 @@ private static double clampRotationAxis(double r, double max) {

@Override
public void mouseMoved(MouseEvent e) {
InternalSelectable internal = pick(e);

// Clear existing hover state
for (InternalSelectable i : nodesToSelectabls.values()) {
i.setHovered(internal != null && i.equals(internal));
}

// Set new hover state
/*if (internal != null) {
internal.setHovered(true);
}*/
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public InternalNode(VesselNode vessel_node) {
Vector3f pos = new Vector3f(-vessel_node.getX(), vessel_node.getY(), vessel_node.getZ());
pos.scale(SCALE);

sphere = new Sphere(RADIUS, appearanceFromHealthPercentage(1f, !isSystemNode()));
sphere = new Sphere(RADIUS, appearanceFromHealthPercentage());
sphere.getShape(Sphere.BODY).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

Transform3D transform = new Transform3D();
Expand All @@ -41,16 +41,12 @@ public InternalNode(VesselNode vessel_node) {
@Override
public void updateHealth(float pct) {
super.updateHealth(pct);
sphere.setAppearance(appearanceFromHealthPercentage(pct, !isSystemNode()));
sphere.setAppearance(appearanceFromHealthPercentage());
}

@Override
protected void updateSelection() {
if (!isSystemNode()) {
return;
}

super.updateSelection();
protected boolean visible() {
return isSystemNode();
}

private boolean isSystemNode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,50 @@ public abstract class InternalSelectable extends Internal {
protected static final float SHININESS = 0f;
protected static final Color3f BLACK = new Color3f(0f, 0f, 0f);

protected boolean selected = false;
protected boolean selected = false, hovered = false;
protected float healthPct = 1f;

protected Sphere sphere;
protected BranchGroup branchGroup;

protected Appearance appearanceFromHealthPercentage(float pct, boolean invisible) {
protected Appearance appearanceFromHealthPercentage() {
Appearance app = new Appearance();
app.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
app.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
app.setMaterial(new Material(BLACK, getColorFromHealth(pct), BLACK, BLACK, SHININESS));
app.setMaterial(new Material(BLACK, getColorFromHealth(this.healthPct), BLACK, BLACK, SHININESS));
// TODO: FILE ISSUE > when hovering, make opaque or circle or something
TransparencyAttributes transparency = new TransparencyAttributes(TransparencyAttributes.NICEST, invisible ? 1f : alpha);
app.setTransparencyAttributes(transparency);

if (this.visible()) {
TransparencyAttributes transparency = new TransparencyAttributes(TransparencyAttributes.NICEST, 1f);
app.setTransparencyAttributes(transparency);
} else if (this.selected) {
TransparencyAttributes ta = new TransparencyAttributes(TransparencyAttributes.NICEST, 0f);
app.setTransparencyAttributes(ta);
} else if (this.hovered) {
TransparencyAttributes ta = new TransparencyAttributes(TransparencyAttributes.NICEST, 0f);
app.setTransparencyAttributes(ta);
} else {
TransparencyAttributes transparency = new TransparencyAttributes(TransparencyAttributes.NICEST, alpha);
app.setTransparencyAttributes(transparency);
}
// TODO: > bug here. Transparency of something is jumping on first node selection after launch. Investigate.
// Same if I select a damcon team too, something in depth buffer/render order is changing with pick

return app;
}

protected boolean visible() {
return true;
}

protected void setPickable(Shape3D shape) {
shape.setCapability(Shape3D.ENABLE_PICK_REPORTING);
shape.setPickable(true);
}

public void updateHealth(float pct) {
// Note: subclasses don't need to override this now but they will if I don't resolve the
// genericization of sphere vs. other geometry used for their models
this.healthPct = pct;
}

Expand All @@ -46,22 +67,12 @@ protected Color3f getColorFromHealth(float pct) {

public void setSelected(boolean selected) {
this.selected = selected;
updateSelection();
this.sphere.setAppearance(appearanceFromHealthPercentage());
}

protected void updateSelection() {
// TODO: > bug here. Transparency of something is jumping on first node selection after launch. Investigate.
// Same if I select a damcon team too, soemthing in depth buffer/render order is changing with pick

// It actually looks like the depth of the nodes is being put behind the model for some reason
if (selected) {
Appearance app = appearanceFromHealthPercentage(healthPct, false);
TransparencyAttributes ta = new TransparencyAttributes(TransparencyAttributes.NICEST, 0f);
app.setTransparencyAttributes(ta);
sphere.setAppearance(app);
} else {
updateHealth(healthPct);
}
public void setHovered(boolean hovered) {
this.hovered = hovered;
this.sphere.setAppearance(appearanceFromHealthPercentage());
}

public BranchGroup getBranchGroup() {
Expand All @@ -71,4 +82,4 @@ public BranchGroup getBranchGroup() {
public Shape3D getShape() {
return this.sphere.getShape(Sphere.BODY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public InternalTeam(EngineeringConsoleManager.EnhancedDamconStatus damcon_status

this.branchGroup = new BranchGroup();

this.sphere = new Sphere(RADIUS, appearanceFromHealthPercentage(1f, false));
this.sphere = new Sphere(RADIUS, appearanceFromHealthPercentage());

Shape3D shape = this.sphere.getShape(Sphere.BODY);
shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
Expand All @@ -48,16 +48,16 @@ public void updatePos(float x, float y, float z) {
@Override
public void updateHealth(float pct) {
super.updateHealth(pct);
sphere.setAppearance(appearanceFromHealthPercentage(pct, false));
sphere.setAppearance(appearanceFromHealthPercentage());
}

@Override
public Appearance appearanceFromHealthPercentage(float pct, boolean invisible) {
Appearance app = super.appearanceFromHealthPercentage(pct, invisible);
if (!invisible) {
// TODO: > damcon team coloration?
app.setMaterial(new Material(BLACK, new Color3f(0f, 0f, 1f), BLACK, BLACK, SHININESS));
}
public Appearance appearanceFromHealthPercentage() {
Appearance app = super.appearanceFromHealthPercentage();

// TODO: > damcon team coloration?
app.setMaterial(new Material(BLACK, new Color3f(0f, 0f, 1f), BLACK, BLACK, SHININESS));

return app;
}

Expand Down

0 comments on commit ca21ce9

Please sign in to comment.