Ejemplo n.º 1
0
  private void cleanup(boolean initiator) {
    cleanedUp = true;

    active = false;

    if (children != null) {
      for (UIContainer c : children) {
        c.cleanup(false);
      }
      children.clear(); // Set to null later as it is checked in removeFromParent()
    }
    if (initiator) {
      removeFromParent();
    }
    if (displayNode != null) {
      displayNode.detachAllChildren();
      displayNode = null;
    }

    name = null;
    children = null;
    parentContainer = null;
    targetEventQueue = null;
    onClickEventType = null;
    blX = 0;
    blY = 0;
    proportionalPosition = false;
    percentageX = 0;
    percentageY = 0;
    width = 0;
    height = 0;
    zPos = 0;
    hovered = false;
  }
Ejemplo n.º 2
0
 public void detachChild(UIContainer child) {
   if (child == null) return;
   if (!children.contains(child)) return;
   getDisplayNode().detachChild(child.getDisplayNode());
   children.remove(child);
   child.setParent(null);
 }
Ejemplo n.º 3
0
  /**
   * Attaches the physical representation of this container to a supplied node rather than creating
   * one. Note - this will change the parent of the supplied node to the display node of this
   * container's parent, if it has one.
   */
  public void setDisplayNode(Node n) {
    if (n == null) return;

    displayNode = n;
    if (parentContainer != null) {
      parentContainer.getDisplayNode().attachChild(n);
    }
    for (UIContainer c : children) {
      n.attachChild(c.getDisplayNode());
    }
  }
Ejemplo n.º 4
0
  /** Just to ensure that updateGeometricState is only called once. */
  private void updatePosition(boolean initiator) {
    if (cleanedUp) return;

    recalculatePosition();
    displayNode.setLocalTranslation(blX, blY, 0);

    for (UIContainer c : children) {
      c.updatePosition(false);
    }
    if (initiator) displayNode.updateGeometricState(0, true);
  }
Ejemplo n.º 5
0
  public void checkMouseActions(float mouseX, float mouseY, boolean leftClick) {

    if (active) {
      UIContainer containerWithFocus = checkForMouseFocus(mouseX, mouseY);
      if (containerWithFocus != null) {
        containerWithFocus.hoverCheck();
        if (leftClick) {
          containerWithFocus.onClick();
        }
      }
    }
  }
Ejemplo n.º 6
0
  /**
   * Adds a child container, which will be processed whenever this container is. Does nothing if the
   * child parameter is null. Does nothing if the supplied parameter is already in the child list.
   */
  public void attachChild(UIContainer child) {
    if (child == null) return;
    if (children.contains(child)) return;

    child.removeFromParent();
    if (child.isActive()) {
      getDisplayNode().attachChild(child.getDisplayNode());
    }
    children.add(child);
    child.setParent(this);
    // child.updatePosition(true);	// Removed as setParent does an updatePosition.
  }
Ejemplo n.º 7
0
  /**
   * Looks up a component with a given name. This is a crude implementation which walks through all
   * children until it finds the first match. Intended for occasional use eg. Collecting a set of
   * information from a screen when it is completed. Not going to be ideal performance for frequent
   * calls in complicated systems.
   */
  public UIContainer getChild(String searchName) {
    if (name.equals(searchName)) return this;

    UIContainer searchResult = null;
    for (UIContainer c : children) {
      searchResult = c.getChild(searchName);
      if ((searchResult != null) && (searchResult.getName().equals(searchName))) {
        break;
      }
    }
    return searchResult;
  }
Ejemplo n.º 8
0
 /**
  * Processes a left click on this container. First handleClick is invoked. If that returns false,
  * the event is passed to the parent container if not null, or the targetEventQueue
  *
  * @see handleClick()
  */
 protected void onClick() {
   if (handleClick()) return;
   if (parentContainer != null) {
     parentContainer.onChildEvent(new GameEvent(onClickEventType, this, onClickEventParameters));
   } else {
     GameWorldInfo.getGameWorldInfo()
         .getEventHandler()
         .addEvent(onClickEventType, targetEventQueue, this, onClickEventParameters);
   }
 }
Ejemplo n.º 9
0
 /** Returns the world coordinates (in UI space) of the bottom left corner. */
 public Vector2f getWorldPosition() {
   Vector2f worldPos = null;
   if (parentContainer == null) {
     worldPos = new Vector2f(blX, blY);
   } else {
     worldPos = parentContainer.getWorldPosition();
     worldPos.x += blX;
     worldPos.y += blY;
   }
   return worldPos;
 }
Ejemplo n.º 10
0
  /**
   * Recursively passes an event back up through the parent hierarchy giving parent containers the
   * chance to handle it. This class should not normally be overridden, as this may prevent the
   * event from being registered.
   *
   * @see handleChildEvent() - Override this method to act on a child event.
   */
  protected void onChildEvent(GameEvent event) {
    // TODO: All events currently get passed right back up the tree to the root container before
    // being broadcast. This is inefficient default behavior since the vast majority will be.
    // Consider making is optional.
    if (handleChildEvent(event)) return;

    if (parentContainer != null) {
      parentContainer.onChildEvent(event);
    } else {
      GameWorldInfo.getGameWorldInfo().getEventHandler().addEvent(event, targetEventQueue);
    }
  }
Ejemplo n.º 11
0
  /** If mouse is inside the component's area then this will return it's depth. -1 otherwise. */
  public UIContainer checkForMouseFocus(float mouseX, float mouseY) {
    UIContainer currentTopFocus = null;

    if (active) {
      if ((mouseX > blX)
          && (mouseX < (blX + width))
          && (mouseY > blY)
          && (mouseY < (blY + height))) {
        currentTopFocus = this;
      } else {
        if (hovered) {
          hovered = false;
          onHoverOff();
        }
      }

      UIContainer childFocus = null;
      for (UIContainer c : children) {
        childFocus = c.checkForMouseFocus(mouseX - blX, mouseY - blY);

        if (childFocus != null) {
          if (currentTopFocus == null) {
            currentTopFocus = childFocus;
          } else {
            if (childFocus.getZOrder() <= currentTopFocus.getZOrder()) {
              currentTopFocus = childFocus;
            }
          }
        }
      }
    }

    return currentTopFocus;
  }
Ejemplo n.º 12
0
 /**
  * Setting active to false will prevent the user from seeing or interacting with it.
  *
  * @see setSuspended()
  */
 public void setActive(boolean a) {
   if (a) {
     if ((parentContainer != null) && (displayNode != null)) {
       parentContainer.getDisplayNode().attachChild(displayNode);
     }
   } else {
     if (displayNode != null) {
       if (displayNode.getParent() != null) {
         displayNode.removeFromParent();
       }
     }
   }
   updatePosition(true);
   active = a;
 }
Ejemplo n.º 13
0
 public UITextureContainer(
     String name, int sizeX, int sizeY, int posX, int posY, int zOrder, UIContainer parent) {
   this(name, sizeX, sizeY, posX, posY, zOrder);
   if (parent != null) parent.attachChild(this); // TODO: Don't pass parent to the constructor.
 }
Ejemplo n.º 14
0
 public void removeFromParent() {
   if (parentContainer != null) {
     parentContainer.detachChild(this);
   }
 }
Ejemplo n.º 15
0
 private void updateSize() {
   recalculateSize();
   for (UIContainer c : children) {
     c.updateSize();
   }
 }