示例#1
0
 private void handleObjectClick(Node parent) {
   switch (inventoryType) {
     case DragDrop:
       DragElement de = createNewDragElement();
       de.setUserData("worldObject", parent);
       de.setTextureAtlasImage(objIcons, ((InteractiveNode) parent).getIcon());
       String ttt = ((InteractiveNode) parent).getToolTipText();
       de.setToolTipText(
           ttt.substring(0, ttt.indexOf("\n")) + "\n\nDrop me back into\nthe world.");
       parent.removeFromParent();
       ((InteractiveNode) parent).setIsInScene(false);
       screen.forceFocusElementRefresh();
       break;
     case PointClick:
       cursor.setTextureAtlasImage(objIcons, ((InteractiveNode) parent).getIcon());
       cursor.setUserData("worldObject", parent);
       parent.removeFromParent();
       ((InteractiveNode) parent).setIsInScene(false);
       screen.forceFocusElementRefresh();
       break;
   }
 }
示例#2
0
 private void changeInventoryType() {
   switch (inventoryType) {
     case DragDrop:
       if (cursor != null) {
         if (cursor.getUserData("worldObject") != null) {
           InteractiveNode node = cursor.getUserData("worldObject");
           main.getRootNode().attachChild(node);
           cursor.setUserData("worldObject", null);
           cursor.setTextureAtlasImage(objIcons, iconDefault);
         }
         for (ButtonAdapter slot : slots) {
           if (slot.getUserData("worldObject") != null) {
             InteractiveNode node = slot.getUserData("worldObject");
             DragElement de = createNewDragElement();
             de.setUserData("worldObject", node);
             de.setTextureAtlasImage(objIcons, node.getIcon());
             String ttt = node.getToolTipText();
             de.setToolTipText(
                 ttt.substring(0, ttt.indexOf("\n")) + "\n\nDrop me back into\nthe world.");
             de.bindToDroppable(slot);
             de.setEffectZOrder(false);
             slot.setUserData("worldObject", null);
             slot.setButtonIcon(iconSize, iconSize, iconDefault);
           }
         }
       }
       break;
     case PointClick:
       for (ButtonAdapter slot : slots) {
         if (slot.getElementsAsMap().size() > 1) {
           for (Element el : slot.getElementsAsMap().values()) {
             if (el instanceof DragElement) {
               DragElement de = (DragElement) el;
               InteractiveNode n = de.getUserData("worldObject");
               slot.setUserData("worldObject", n);
               slot.setButtonIcon(iconSize, iconSize, n.getIcon());
               slot.removeChild(de);
             }
           }
         }
       }
       break;
   }
 }
示例#3
0
  private DragElement createNewDragElement() {
    DragElement e =
        new DragElement(
            screen,
            new Vector2f(
                screen.getMouseXY().x - (iconSize / 2),
                screen.getHeight() - (screen.getMouseXY().y + (iconSize / 2))),
            new Vector2f(iconSize, iconSize),
            Vector4f.ZERO,
            screen.getStyle("Window").getString("defaultImg")) {
          @Override
          public void onDragStart(MouseButtonEvent evt) {
            if (getElementParent() != null) {
              if (getElementParent() != this.getScreen()) {
                getParentDroppable().bringToFront();
              }
            }
          }

          @Override
          public boolean onDragEnd(MouseButtonEvent evt, Element dropElement) {
            if (dropElement != null) {
              setLockToParentBounds(false);
              if (!dropElement.getDraggableChildren().isEmpty()) {
                if (!dropElement.getDraggableChildren().contains(this)) {
                  DragElement de1 = (DragElement) dropElement.getDraggableChildren().get(0);
                  Element drop1 = null;
                  if (getParentDroppable() != null) {
                    drop1 = getParentDroppable();
                    getParentDroppable().removeChild(this);
                    clearParentDroppable();
                  }

                  if (de1 != null) {
                    de1.getParentDroppable().removeChild(de1);
                    de1.clearParentDroppable();
                  }

                  if (drop1 != null && de1 != null) {
                    de1.bindToDroppable(drop1);
                  } else {
                    Node n = de1.getUserData("worldObject");
                    Node n1 = getUserData("worldObject");
                    if (n != n1) {
                      main.getRootNode().attachChild(n);
                      ((InteractiveNode) n).setIsInScene(true);
                    }
                  }
                  evt.setConsumed();
                  return true;
                } else {
                  return true;
                }
              } else {
                return true;
              }
            } else {
              if (getParentDroppable() != null) {
                getParentDroppable().removeChild(this);
                clearParentDroppable();
              }
              Node n = getUserData("worldObject");
              main.getRootNode().attachChild(n);
              screen.removeElement(this);
              ((InteractiveNode) n).onLoseFocus(null);
              ((InteractiveNode) n).setIsInScene(true);
              ((Screen) screen).forceFocusElementRefresh();
              return false;
            }
          }
        };
    e.setDocking(Docking.SW);
    e.setEffectZOrder(false);
    e.setLockToParentBounds(true);
    e.setUseLockToDropElementCenter(true);
    e.setUseSpringBack(true);
    e.setUseSpringBackEffect(true);
    screen.addElement(e);
    return e;
  }