public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("KEY_R") && !keyPressed) {} if (name.equals("KEY_F10") && !keyPressed) { showMainMenu(); } if (name.equals("LMB") && !keyPressed) { CollisionResults results = new CollisionResults(); Vector2f click2d = app.getInputManager().getCursorPosition(); Vector3f click3d = app.getCamera().getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f).clone(); Vector3f dir = app.getCamera() .getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 1f) .subtractLocal(click3d); Ray ray = new Ray(click3d, dir); /* Collect intersections between Ray and nodes in results list */ resourceNodes.collideWith(ray, results); farmNodes.collideWith(ray, results); locationNodes.collideWith(ray, results); if (results.size() > 0) { CollisionResult closest = results.getClosestCollision(); Geometry geom = closest.getGeometry(); String geomName = geom.getName(); if (geom.getUserData(geomName) instanceof Farm) { Farm farm = (Farm) geom.getUserData(geomName); setMessageHUD("Clicked on Farm cost: " + farm.getCost()); } if (geom.getUserData(geomName) instanceof Location) { Location loc = (Location) geom.getUserData(geomName); setMessageHUD("Clicked on Location: " + loc.getName()); } if (geom.getUserData(geomName) instanceof Resource) { Resource res = (Resource) geom.getUserData(geomName); Integer cost = null; if (res.getType() == Resource.CHICK) { cost = gm.getResourceManager().getCurrentPriceChicken(); } else if (res.getType() == Resource.LAMB) { cost = gm.getResourceManager().getCurrentPriceLamb(); } else if (res.getType() == Resource.PIGLET) { cost = gm.getResourceManager().getCurrentPricePiglet(); } else if (res.getType() == Resource.CALF) { cost = gm.getResourceManager().getCurrentPriceCalf(); } setMessageHUD("Clicked on " + res.getName() + " cost: " + cost); } } } }
private void displayOpenFarms() { Vector3f startPos = gm.getMapManager().getBoard().getFarmMarker(); List<Farm> farms = gm.getFarmManager().getOpenFarms(); float i = 0; for (Farm farm : farms) { Box b = new Box(Vector3f.ZERO, 1, 1, 1); Geometry geom = new Geometry("Box", b); Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); if (farm.getUsesResourceTypes().get(0) == Resource.CALF) { mat.setColor("Color", ColorRGBA.White); } else if (farm.getUsesResourceTypes().get(0) == Resource.CHICK) { mat.setColor("Color", ColorRGBA.Yellow); } else if (farm.getUsesResourceTypes().get(0) == Resource.LAMB) { mat.setColor("Color", ColorRGBA.Gray); } else if (farm.getUsesResourceTypes().get(0) == Resource.PIGLET) { mat.setColor("Color", ColorRGBA.Pink); } else if (farm.getUsesResourceTypes().get(0) == Resource.WILDLIFE) { mat.setColor("Color", ColorRGBA.Green); } else { mat.setColor("Color", ColorRGBA.Red); } geom.setMaterial(mat); geom.setLocalTranslation(startPos.x + i, 1, startPos.z + 10); String geomName = "FARM_" + farm.getCost().toString(); geom.setName(geomName); geom.setUserData(geomName, farm); openFarmNodes.attachChild(geom); displayLocationName( farm.getCost().toString(), new Vector3f(startPos.x + i, 1, startPos.z + 10)); i += 5; } }