public void onMouseButtonEvent(MouseButtonEvent evt) { if (evt.getButtonIndex() == 0 && evt.isPressed()) { if (inventoryType == InventoryType.PointClick) { if (cursor.getUserData("worldObject") != null) { InteractiveNode node = cursor.getUserData("worldObject"); main.getRootNode().attachChild(node); node.setIsInScene(true); cursor.setUserData("worldObject", null); cursor.setTextureAtlasImage(objIcons, iconDefault); } } } }
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; } }
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; } }
@Override public void cleanupState() { main.getTests().removeCtrlPanel(cPanel); if (obj1Node.getIsInScene()) obj1Node.removeFromParent(); if (obj2Node.getIsInScene()) obj2Node.removeFromParent(); if (obj3Node.getIsInScene()) obj3Node.removeFromParent(); screen.removeElement(cursor); screen.setUse3DSceneSupport(false); main.getInputManager().removeRawInputListener(this); }
@Override protected void initState() { main.getInputManager().addRawInputListener(this); if (!init) { main.getInputManager().deleteMapping("FLYCAM_RotateDrag"); main.getInputManager() .addMapping("FLYCAM_RotateDrag", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT)); main.getInputManager().addListener(main.getFlyByCamera(), "FLYCAM_RotateDrag"); objIcons = main.getAssetManager().loadTexture("Textures/Spatials/ObjIcons.png"); initCtrlPanel(); obj1Node = new InteractiveNode(screen) { @Override public void onSpatialMouseDown(MouseButtonEvent evt) { handleObjectClick(this); evt.setConsumed(); } @Override public void onSpatialMouseUp(MouseButtonEvent evt) { evt.setConsumed(); } }; obj1Node.setName("Box"); Box obj1 = new Box(1, 1, 1); Geometry obj1Geom = new Geometry(); obj1Geom.setMesh(obj1); obj1Node.attachChild(obj1Geom); obj1Node.setIcon("x=0|y=0|w=64|h=64"); obj1Node.setDefaultMaterial(getMaterial(ColorRGBA.Blue)); obj1Node.setHighlightMaterial(getMaterial(new ColorRGBA(0.5f, 0.5f, 1f, 1f))); obj1Node.setToolTipText("I'm a Box\n\nPick me up and put\nme in your inventory."); obj1Node.setLocalTranslation(-3, 0, 0); obj2Node = new InteractiveNode(screen) { @Override public void onSpatialMouseDown(MouseButtonEvent evt) { handleObjectClick(this); evt.setConsumed(); } @Override public void onSpatialMouseUp(MouseButtonEvent evt) { evt.setConsumed(); } }; obj2Node.setName("Sphere"); Sphere obj2 = new Sphere(8, 8, 1f); Geometry obj2Geom = new Geometry(); obj2Geom.setMesh(obj2); obj2Node.attachChild(obj2Geom); obj2Node.setIcon("x=64|y=0|w=64|h=64"); obj2Node.setDefaultMaterial(getMaterial(ColorRGBA.Red)); obj2Node.setHighlightMaterial(getMaterial(new ColorRGBA(1f, 0.5f, 0.5f, 1f))); obj2Node.setToolTipText("I'm a Sphere\n\nPick me up and put\nme in your inventory."); obj2Node.setLocalTranslation(0, 0, 0); obj3Node = new InteractiveNode(screen) { @Override public void onSpatialMouseDown(MouseButtonEvent evt) { handleObjectClick(this); evt.setConsumed(); } @Override public void onSpatialMouseUp(MouseButtonEvent evt) { evt.setConsumed(); } }; obj3Node.setName("Torus"); Torus obj3 = new Torus(8, 8, 0.5f, 1f); Geometry obj3Geom = new Geometry(); obj3Geom.setMesh(obj3); obj3Node.attachChild(obj3Geom); obj3Node.setIcon("x=0|y=64|w=64|h=64"); obj3Node.setDefaultMaterial(getMaterial(ColorRGBA.Green)); obj3Node.setHighlightMaterial(getMaterial(new ColorRGBA(0.5f, 1f, 0.5f, 1f))); obj3Node.setToolTipText("I'm a Torus\n\nPick me up and put\nme in your inventory."); obj3Node.setLocalTranslation(3, 0, 0); cursor = new ButtonAdapter( screen, UIDUtil.getUID(), Vector2f.ZERO, new Vector2f(iconSize, iconSize), Vector4f.ZERO, null) { @Override public void update(float tpf) { setPosition(screen.getMouseXY().x + 25, screen.getMouseXY().y - 50); } }; cursor.setIsEnabled(false); cursor.setInterval(1); cursor.setTextureAtlasImage(objIcons, iconDefault); cursor.setIsModal(true); cursor.setIsGlobalModal(true); cursor.setEffectZOrder(false); cursor.setIgnoreMouse(true); init = true; } screen.setUse3DSceneSupport(true); main.getTests().addCtrlPanel(cPanel); if (obj1Node.getIsInScene()) main.getRootNode().attachChild(obj1Node); if (obj2Node.getIsInScene()) main.getRootNode().attachChild(obj2Node); if (obj3Node.getIsInScene()) main.getRootNode().attachChild(obj3Node); screen.addElement(cursor); cursor.move(0, 0, 20); main.addSceneLights(); }