Sorry, now I can see that I misunderstood your suggestion. Made progress (must fix aspect ratio), but
- mouse event aren’t processed
- and pressing Enter gives
Uncaught exception thrown in Thread[jME3 Main,5,main]
IllegalStateException: Scene graph is not properly updated for rendering.
State was changed after rootNode.updateGeometricState() call.
Make sure you do not modify the scene from another thread!
Problem spatial name: null
Code:
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Quad;
import static com.pesegato.p8s.FullHDApplication.DISPLAY_VERSION;
import com.pesegato.p8s.SaveSlot;
import com.pesegato.p8s.appstates.MainMenuAppState;
import com.simsilica.lemur.ActionButton;
import com.simsilica.lemur.CallMethodAction;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.HAlignment;
import com.simsilica.lemur.Insets3f;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.style.BaseStyles;
import java.io.File;
import java.util.Date;
import org.lwjgl.opengl.Display;
/**
* Sample 1 - how to get started with the most simple JME 3 application. Display
* a blue 3D cube and view from all sides by moving the mouse and pressing the
* WASD keys.
*/
public class HelloJME3 extends SimpleApplication {
private Container mainWindow;
private Container loadWindow;
public Node scaledGuiNode = new Node("ScaledGUINode");
public float getStandardScale() {
int height = getCamera().getHeight();
return height / 720f;
}
public static void main(String[] args) {
HelloJME3 app = new HelloJME3();
app.start(); // start the game
}
@Override
public void simpleInitApp() {
GuiGlobals.initialize(this);
GuiGlobals globals = GuiGlobals.getInstance();
BaseStyles.loadGlassStyle();
globals.getStyles().setDefaultStyle("glass");
myRoot = new Node();
ViewPort myView = renderManager.createPostView("black bars", cam);
float scalingFactor = Display.getWidth() / 1920f;
scaledGuiNode.scale(scalingFactor,scalingFactor,1);
float hOffset = (int) ((Display.getHeight() - (1080f * scalingFactor)) / 2);
/*
if (hOffset != 0) {
Geometry g = new Geometry("blackbg", new Quad(Display.getWidth(), hOffset));
Geometry gtop = new Geometry("blackbg", new Quad(Display.getWidth(), hOffset));
Material matBg = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matBg.setColor("Color", ColorRGBA.Black);
g.setMaterial(matBg);
g.move(0, 0, 50);
guiNode.attachChild(g);
gtop.setMaterial(matBg);
gtop.move(0, Display.getHeight() - hOffset, 50);
guiNode.attachChild(gtop);
scaledGuiNode.setLocalTranslation(0, hOffset, 0);
}
*/
cam.setViewPortBottom(hOffset/Display.getHeight());
cam.setViewPortTop((Display.getHeight()-hOffset)/Display.getHeight());
cam.setFrustumPerspective(40, 16 / 9f, 0.05f, 500f);
myRoot.attachChild(scaledGuiNode);
mainWindow = new Container();
Label title = mainWindow.addChild(new Label("MyApp"));
title.setFontSize(32);
title.setInsets(new Insets3f(10, 10, 0, 10));
Label subtitle = mainWindow.addChild(new Label(DISPLAY_VERSION + " build"));
subtitle.setInsets(new Insets3f(0, 10, 0, 10));
subtitle.setTextHAlignment(HAlignment.Right);
subtitle.setColor(new ColorRGBA(166 / 255f, 107 / 255f, 255 / 255f, 0.85f));
ActionButton play = mainWindow.addChild(new ActionButton(new CallMethodAction("Campaign mode", this, "campaignMode")));
play.setInsets(new Insets3f(10, 10, 10, 10));
// Calculate a standard scale and position from the app's camera
// height
int height = getCamera().getHeight();
Vector3f pref = mainWindow.getPreferredSize().clone();
float standardScale = getStandardScale();
pref.multLocal(1.5f * standardScale);
// With a slight bias toward the top
float y = height * 0.6f + pref.y * 0.5f;
mainWindow.setLocalTranslation(100 * standardScale, y, 0);
mainWindow.setLocalScale(1.5f * standardScale);
loadWindow = new Container();
loadWindow.setLocalTranslation(400 * standardScale, y - 200, 0);
loadWindow.setLocalScale(1.5f * standardScale);
myRoot.attachChild(mainWindow);
GuiGlobals.getInstance().requestFocus(mainWindow);
myView.attachScene(myRoot);
myRoot.setQueueBucket(RenderQueue.Bucket.Gui);
myRoot.updateLogicalState(0);
myRoot.updateGeometricState();
}
Node myRoot;
public void update(float tpf) {
myRoot.updateLogicalState(0);
myRoot.updateGeometricState();
}
public void campaignMode() {
for (int i = 0; i < 3; i++) {
ActionButton load = loadWindow.addChild(new ActionButton(new CallMethodAction("aaa", this, "loadSlot")));
load.setInsets(new Insets3f(10, 10, 10, 10));
}
GuiGlobals.getInstance().getPopupState().showPopup(loadWindow);
//((SimpleApplication) getApplication()).getGuiNode().attachChild(loadWindow);
}
public void loadSlot() {
}
}