// First, detach entity (if necessary)
switch (attachState) {
case ATTACHED_TO_ENTITY:
if (parentEntity != null) {
logger.fine("Remove entity " + entity + " from parent entity " + parentEntity);
RenderComponent rc = (RenderComponent) entity.getComponent(RenderComponent.class);
sgChangeAttachPointSetAddEntity(rc, null, null, null);
parentEntity.removeEntity(entity);
parentEntity = null;
}
break;
case ATTACHED_TO_WORLD:
logger.fine("Remove entity " + entity + " from world manager.");
ClientContextJME.getWorldManager().removeEntity(entity);
break;
}
attachState = AttachState.DETACHED;
// Does the geometry node itself need to change?
if ((changeMask & CHANGED_GEOMETRY) != 0) {
if (geometryNode != null) {
// Note: don't need to do in RenderUpdater because we've detached our entity
sgChangeGeometryDetachFromView(viewNode, geometryNode);
if (geometrySelfCreated) {
sgChangeGeometryCleanup(geometryNode);
geometrySelfCreated = false;
}
}
if (newGeometryNode != null) {
geometryNode = newGeometryNode;
newGeometryNode = null;
} else {
geometryNode = new GeometryNodeQuad(this);
geometrySelfCreated = true;
}
// Note: don't need to do in RenderUpdater because we've detached our entity
sgChangeGeometryAttachToView(viewNode, geometryNode);
}
// Uses: window
if ((changeMask & (CHANGED_GEOMETRY | CHANGED_SIZE_APP)) != 0) {
logger.fine("Update texture for view " + this);
if (geometryNode != null) {
DrawingSurface surface = getWindow().getSurface();
if (surface != null) {
sgChangeGeometryTextureSet(geometryNode, getWindow().getTexture(), surface);
windowNeedsValidate = true;
}
}
}
// Now reattach geometry if view should be visible
// Note: MTGame can currently only setOrtho on a visible rc
// Uses: visible, ortho
if (isActuallyVisible()) {
if (ortho) {
logger.fine("View is ortho for view " + this);
entity.getComponent(RenderComponent.class).setOrtho(true);
entity.getComponent(CollisionComponent.class).setCollidable(false);
if (type == Type.PRIMARY || type == Type.UNKNOWN) {
// Attach top level ortho views directly to world
ClientContextJME.getWorldManager().addEntity(entity);
attachState = AttachState.ATTACHED_TO_WORLD;
logger.fine("Attached entity " + entity + " to world manager.");
} else {
parentEntity = getParentEntity();
if (parentEntity == null) {
// Has no Parent; attach directly to world
ClientContextJME.getWorldManager().addEntity(entity);
attachState = AttachState.ATTACHED_TO_WORLD;
logger.fine("Attached parentless entity " + entity + " to world manager.");
} else {
RenderComponent rc = (RenderComponent) entity.getComponent(RenderComponent.class);
// TODO: these two statements appear to be obsolete.
RenderComponent rcParent =
(RenderComponent) parentEntity.getComponent(RenderComponent.class);
Node attachNode = rcParent.getSceneRoot();
// Note: we need to attach non-primaries to the parent geometry node in
// ortho mode, rather than the view node. This way it picks up the parent's
// offset translation, which contains locationOrtho
// TODO: do this cleaner. Convert attach node to a view and get the
// geometry node for this view.
attachNode = (Node) attachNode.getChild(0);
sgChangeAttachPointSetAddEntity(rc, attachNode, parentEntity, entity);
attachState = AttachState.ATTACHED_TO_ENTITY;
logger.fine("Attach ortho entity " + entity + " to geometry node of parent entity " + parentEntity);
}
}
} else {
logger.fine("View is not ortho for view " + this);
parentEntity = getParentEntity();
if (parentEntity == null) {
logger.warning("getParentEntity() returns null; must be non-null");
} else {
logger.fine("Attach entity " + entity + " to parent entity " + parentEntity);
RenderComponent rc = (RenderComponent) entity.getComponent(RenderComponent.class);
RenderComponent rcParent =
(RenderComponent) parentEntity.getComponent(RenderComponent.class);
Node attachNode = rcParent.getSceneRoot();
// SPECIAL NOTE: Here is where special surgery is done on header windows so
// that they are parented to the *geometry node* of their parent view instead of
// the view node, as windows normally are. This way it picks up the offset
// translation in the geometry node and stays in sync with the rest of the frame.