Esempio n. 1
0
  @Override
  public void stateDetached(AppStateManager stateManager) {
    System.out.println("LOGIN STATE DETACHED!");

    app.getNifty().removeScreen("LoginScreen");
    nifty.unsubscribeScreen(nifty.getScreen("LoginScreen"));
  }
  public void OpenMenuPopup() {
    CloseMenuPopup();
    Game game = Main.app.getStateManager().getState(Game.class);
    game.Pause(true);

    MenuPopup = nifty.createPopup("MenuPopup");
    nifty.showPopup(screen, MenuPopup.getId(), null);
  }
Esempio n. 3
0
  @Override
  public void simpleInitApp() {
    NiftyJmeDisplay niftyDisplay =
        new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
    Nifty nifty = niftyDisplay.getNifty();
    guiViewPort.addProcessor(niftyDisplay);
    flyCam.setDragToRotate(true);

    nifty.loadStyleFile("nifty-default-styles.xml");
    nifty.loadControlFile("nifty-default-controls.xml");

    // <screen>
    nifty.addScreen(
        "Screen_ID",
        new ScreenBuilder("Hello Nifty Screen") {
          {
            controller(new DefaultScreenController()); // Screen properties

            // <layer>
            layer(
                new LayerBuilder("Layer_ID") {
                  {
                    childLayoutVertical(); // layer properties, add more...

                    // <panel>
                    panel(
                        new PanelBuilder("Panel_ID") {
                          {
                            childLayoutCenter(); // panel properties, add more...

                            // GUI elements
                            control(
                                new ButtonBuilder("Button_ID", "Hello Nifty") {
                                  {
                                    alignCenter();
                                    valignCenter();
                                    height("5%");
                                    width("15%");
                                  }
                                });

                            // .. add more GUI elements here

                          }
                        });
                    // </panel>
                  }
                });
            // </layer>

          }
        }.build(nifty));

    // </screen>

    nifty.gotoScreen("Screen_ID"); // start the screen
  }
Esempio n. 4
0
 public void createGUI() {
   nifty.fromXml(guiLocation, "start", this);
   nifty.addControls();
   nifty.update();
   guiViewPort.addProcessor(niftyDisplay);
   timeControl =
       nifty.getScreen("start").findElementByName("timeControl").getControl(DropDownControl.class);
   setupTimeControl(timeControl);
 }
  public void OpenPopulationPopup() {
    ClosePopulationPopup();
    Game game = Main.app.getStateManager().getState(Game.class);
    game.Pause(true);
    // prevent mouse wheel interfering with scrolling a menu
    // TODO there may be a better way of doing this, e.g. nifty not passing the mousewheel event to
    // the game.
    disableMouseWheel();

    PopulationPopup = nifty.createPopup("PopulationPopup");
    nifty.showPopup(screen, PopulationPopup.getId(), null);
  }
 @Override
 public boolean keyEvent(final NiftyInputEvent inputEvent) {
   if (inputEvent == NiftyInputEvent.ConsoleToggle) {
     if (screen.isActivePopup(consolePopup)) {
       nifty.closePopup(consolePopup.getId());
     } else {
       nifty.showPopup(screen, consolePopup.getId(), null);
     }
     return true;
   }
   return false;
 }
Esempio n. 7
0
 // main display method (overwritten by subclasses) Note: disposal of previous screen already done
 // in HUD_Main class
 public void display(Nifty n) {
   // blank hud
   n.addScreen(
       "start",
       new ScreenBuilder("start") {
         {
           // blank gui screen (e.g. for cutscenes)
         }
       }.build(n));
   // show screen
   n.gotoScreen("start");
 }
Esempio n. 8
0
  private void initNifty() {
    flyCam.setDragToRotate(true);

    loginController = new LoginController();
    loginController.initialize(app.getStateManager(), app);
    nifty.registerScreenController(loginController);
    loginScreenBuilder.buildLoginScreen(nifty, loginController);
    nifty
        .getScreen("LoginScreen")
        .findNiftyControl("PasswordTextField", TextField.class)
        .enablePasswordChar('*');
  }
  @Override
  public void bind(final Nifty nifty, final Screen screen) {
    this.nifty = nifty;
    this.screen = screen;

    this.consolePopup = nifty.createPopup("consolePopup");
    this.console = this.consolePopup.findNiftyControl("console", Console.class);

    consoleCommands = new ConsoleCommands(nifty, console);

    ConsoleCommand showCommand = new ShowCommand();

    consoleCommands.registerCommand("show DropDown", showCommand);

    NiftyCommand niftyCommand = new NiftyCommand();
    consoleCommands.registerCommand("nifty screen", niftyCommand);

    ConsoleCommand helpCommand = new HelpCommand();
    consoleCommands.registerCommand("help", helpCommand);

    ConsoleCommand clearCommand = new ClearCommand();
    consoleCommands.registerCommand("clear", clearCommand);

    ConsoleCommand exitCommand = new ExitCommand();
    consoleCommands.registerCommand("exit", exitCommand);

    // enable the nifty command line completion
    consoleCommands.enableCommandCompletion(true);

    // get all resolutions available into the resolutions drop down
    fillResolutionDropDown(screen);
  }
Esempio n. 10
0
 public void update(String speed) {
   nifty
       .getCurrentScreen()
       .findElementByName("speedDisplay")
       .getRenderer(TextRenderer.class)
       .setText(speed + "km/h");
 }
  @SuppressWarnings("unchecked")
  @Override
  public void onEvent(final String topic, final ListBoxSelectionChangedEvent data) {
    final Object selectedItem = getSelectedItem(data.getSelection());

    ListBoxControl listBoxControl = (ListBoxControl) listBox;
    listBoxControl
        .getViewConverter()
        .display(dropDown.getElement().findElementByName("#text"), selectedItem);

    final int selectedItemIndex = getSelectedIndex(data);
    if (screen.isActivePopup(popupInstance)) {
      dropDown
          .getElement()
          .getControl(DropDownControl.class)
          .close(
              new EndNotify() {
                @Override
                public void perform() {
                  nifty.publishEvent(
                      dropDown.getId(),
                      new DropDownSelectionChangedEvent(dropDown, selectedItem, selectedItemIndex));
                }
              });
    } else {
      nifty.publishEvent(
          dropDown.getId(),
          new DropDownSelectionChangedEvent(dropDown, selectedItem, selectedItemIndex));
    }
  }
  private void setMessageHUD(String text) {
    Element el = nifty.getCurrentScreen().findElementByName("messages");

    if (text != null && el != null) {
      el.getRenderer(TextRenderer.class).setText(text);
    }
  }
Esempio n. 13
0
 public void ClosePopulationPopup() {
   if (PopulationPopup != null) {
     nifty.closePopup(PopulationPopup.getId());
     PopulationPopup = null;
   }
   enableMouseWheel();
 }
 @Override
 public boolean keyEvent(final NiftyInputEvent inputEvent) {
   if (inputEvent == NiftyStandardInputEvent.Escape) {
     nifty.gotoScreen("login");
     return true;
   }
   return false;
 }
  public void simpleInitApp() {
    NiftyJmeDisplay niftyDisplay =
        new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
    nifty = niftyDisplay.getNifty();
    nifty.loadStyleFile("nifty-default-styles.xml");
    nifty.loadControlFile("nifty-default-controls.xml");
    // create nifty
    nifty.registerEffect("customHint", "rpgTest.ui.test.CustomHint");

    nifty.addScreen("start", makeScreen1(nifty));
    nifty.gotoScreen("start");

    // attach the nifty display to the gui view port as a processor
    guiViewPort.addProcessor(niftyDisplay);

    // disable the fly cam
    flyCam.setEnabled(false);
  }
  @NiftyEventSubscriber(id = "startGameButton")
  public void onTestButton1Click(final String id, final ButtonClickedEvent clickedEvent) {
    Boolean isKeyBindingValid = KeyBindingController.isKeyBindingValid();
    if (isKeyBindingValid) {
      nifty.exit();
    } else {

    }
  }
Esempio n. 17
0
  public static void main(final String[] args) throws Exception {
    if (!LwjglInitHelper.initSubSystems("Nifty HTML Test")) {
      System.exit(0);
    }

    // create nifty
    Nifty nifty =
        new Nifty(
            new LwjglRenderDevice(),
            new NullSoundDevice(),
            LwjglInitHelper.getInputSystem(),
            new AccurateTimeProvider());
    nifty.fromXml("src/test/resources/test.xml", "start");

    // that's the standard render loop for LWJGL as used in every standard nifty example
    LwjglInitHelper.renderLoop(nifty, null);
    LwjglInitHelper.destroy();
  }
Esempio n. 18
0
 public void onEndScreen() {
   MenuPopup = null;
   PopulationPopup = null;
   // close any open windows
   for (Element tempElement : windows.getElements()) {
     nifty.removeElement(screen, tempElement);
   }
   updatables.clear();
   System.out.println("onEndScreen");
 }
  public EnergyDisplay(Nifty nifty) {
    mainEnergyBar = nifty.getCurrentScreen().findControl("mainEnergyBar", EnergyBar.class);
    engineEnergyBar = nifty.getCurrentScreen().findControl("engineEnergyBar", EnergyBar.class);
    scannerEnergyBar = nifty.getCurrentScreen().findControl("scannerEnergyBar", EnergyBar.class);
    gunnerEnergyBar = nifty.getCurrentScreen().findControl("gunnerEnergyBar", EnergyBar.class);
    shieldsEnergyBar = nifty.getCurrentScreen().findControl("shieldsEnergyBar", EnergyBar.class);
    transferEnergyBar = nifty.getCurrentScreen().findControl("transferEnergyBar", EnergyBar.class);
    cloakEnergyBar = nifty.getCurrentScreen().findControl("cloakEnergyBar", EnergyBar.class);
    builderEnergyBar = nifty.getCurrentScreen().findControl("builderEnergyBar", EnergyBar.class);

    mainEnergyBar.setMaxValue(645);
    mainEnergyBar.setCurrentValue(432);
  }
  @Override
  public void initialize(AppStateManager stateManager, Application app) {
    super.initialize(stateManager, app);
    this.app = (SimpleApplication) app;
    this.assetManager = this.app.getAssetManager();
    this.inputManager = this.app.getInputManager();
    this.cam = this.app.getCamera();
    this.stateManager = stateManager;
    this.guiNode = this.app.getGuiNode();
    this.rootNode = this.app.getRootNode();
    this.audioRenderer = this.app.getAudioRenderer();
    this.viewPort = this.app.getViewPort();
    this.space = this.stateManager.getState(BulletAppState.class).getPhysicsSpace();
    this.guiViewPort = this.app.getGuiViewPort();

    rootNode.attachChild(localRootNode);

    factory = new GameFactory();
    gameState = new RaceObjects();

    niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, viewPort);
    nifty = niftyDisplay.getNifty();
    nifty.fromXml("Interface/Nifty/startscreen.xml", "start", this);
    guiViewPort.addProcessor(niftyDisplay);

    audio = new AudioNode(this.app.getAssetManager(), "Sounds/default.wav");
    audio.play();
    audio.setLooping(true);

    textfield = nifty.getScreen("name").findNiftyControl("name", TextField.class);

    settingsList = nifty.getScreen("settings").findNiftyControl("resolutions", ListBox.class);
    settingsList.addItem("640*480 32bpp");
    settingsList.addItem("800*600 32bpp");
    settingsList.addItem("864*648 32bpp");
    settingsList.addItem("960*720 32bpp");
    settingsList.addItem("1024*768 32bpp");

    popup = nifty.createPopup("popupExit");
  }
  private void showHUD() {
    NiftyJmeDisplay niftyDisplay =
        new NiftyJmeDisplay(
            app.getAssetManager(),
            app.getInputManager(),
            app.getAudioRenderer(),
            app.getGuiViewPort());

    nifty = niftyDisplay.getNifty();
    nifty.fromXml("Interface/gameHudScreen.xml", "hud");

    app.getGuiViewPort().addProcessor(niftyDisplay);
  }
  public static void main(final String[] args) {
    if (!LwjglInitHelper.initSubSystems("Hello Nifty Builder World")) {
      System.exit(0);
    }

    // create nifty
    Nifty nifty =
        new Nifty(
            new LwjglRenderDevice(),
            new OpenALSoundDevice(),
            LwjglInitHelper.getInputSystem(),
            new AccurateTimeProvider());

    HelloNiftyBuilderExampleMain screenController = new HelloNiftyBuilderExampleMain();
    screenController.prepareStart(nifty);

    nifty.gotoScreen("start");

    // render
    LwjglInitHelper.renderLoop(nifty, null);
    LwjglInitHelper.destroy();
  }
Esempio n. 23
0
  // refresh/build method:
  public void refresh(Nifty panel) {
    if (!visible) {
      return;
    }

    // disable other existing layers
    for (Element l : panel.getScreen("start").getLayerElements()) {
      l.disable();
    }

    Element layer =
        new LayerBuilder("journal layer") {
          {
            childLayoutAbsolute();
            width("100%");
            height("100%");
          }
        }.build(panel, panel.getScreen("start"), panel.getScreen("start").getRootElement());

    // make overall panel
    Element back =
        new PanelBuilder("back") {
          {
            childLayoutHorizontal();
            x(Integer.toString(screen_x) + "px");
            y(Integer.toString(screen_y) + "px");
            width("50%");
            height("60%");
            style("nifty-panel");
          }
        }.build(panel, panel.getScreen("start"), layer);

    // arc selection panel
    // make frame
    Element arcpanel =
        new PanelBuilder() {
          {
            childLayoutVertical();
            width("40%");
            height("100%");
            style("nifty-panel");
          }
        }.build(panel, panel.getScreen("start"), back);
    // fill with arc select panel
    panel_arc_select.refresh(panel, arcpanel, true);

    // make arc/segment edit panel
    Element arceditpanel =
        new PanelBuilder() {
          {
            childLayoutVertical();
            width("60%");
            height("100%");
          }
        }.build(panel, panel.getScreen("start"), back);

    // fill panel
    panel_arc_edit.refresh(panel, arceditpanel);
  }
Esempio n. 24
0
  /**
   * Main method.
   *
   * @param args arguments
   */
  public static void main(final String[] args) throws IOException {
    if (!LwjglInitHelper.initSubSystems("Nifty Hello World")) {
      System.exit(0);
    }

    // create nifty
    Nifty nifty =
        new Nifty(
            new LwjglRenderDevice(),
            new OpenALSoundDevice(),
            LwjglInitHelper.getInputSystem(),
            new AccurateTimeProvider());

    final HelloWorldStartScreen screen = new HelloWorldStartScreen();
    nifty.registerScreenController(screen);

    screen.prepareStart(nifty);

    nifty.fromXml("src/main/resources/helloworld/helloworld.xml", "start");

    LwjglInitHelper.renderLoop(nifty, null);
    LwjglInitHelper.destroy();
  }
  @Override
  public void cleanup() {
    localRootNode.removeLight(ai);
    localRootNode.removeLight(dl);

    this.app.getTimer().reset();
    rootNode.detachChild(localRootNode);
    viewPort.removeProcessor(niftyDisplay);
    audio.stop();
    nifty.exit();
    cam.setRotation(Quaternion.IDENTITY);
    cam.setLocation(Vector3f.ZERO);
    cam.setViewPort(0, 1, 0, 1);
    super.cleanup();
  }
Esempio n. 26
0
  public GUIPlayerMain(SimpleApplication app) {

    this.assetManager = app.getAssetManager();

    // GUI Menu
    NiftyJmeDisplay niftyDisplay =
        new NiftyJmeDisplay(
            assetManager, app.getInputManager(), app.getAudioRenderer(), app.getGuiViewPort());
    nifty = niftyDisplay.getNifty();

    nifty.fromXml("Interface/RunningGame/GUIrunningGame.xml", "start", this);
    app.getGuiViewPort().addProcessor(niftyDisplay);

    this.screen.startScreen();
    guiPlayer = new GUIPlayer(this.screen);
  }
  public void nextScreen(String name) {
    if (name.equals("controls")) {
      nifty.gotoScreen(name);
    }
    if (name.equals("name")) {
      nifty.gotoScreen(name);
    }
    if (name.equals("start")) {
      nifty.gotoScreen(name);
      space.remove(car_con[index]);
      localRootNode.detachChild(cars[index]);
      localRootNode.removeLight(ai);
      localRootNode.removeLight(dl);
      localRootNode.detachChild(floor);
    }
    if (name.equals("settings")) {
      nifty.gotoScreen(name);
    }
    if (name.equals("credits")) {
      nifty.gotoScreen(name);
    }
    if (name.equals("startMenu")) {
      nifty.gotoScreen("start");
    }
    if (name.equals("carSelect")) {
      playerName = textfield.getText();

      if (!"".equals(playerName)) {
        nifty.gotoScreen(name);
        showCar();
      }
    }
    if (name.equals("startSettings")) {
      int res = settingsList.getFocusItemIndex();
      boolean fullScreen = true;
      boolean vSync = true;
      AppSettings settings = new AppSettings(true);
      settings.setFullscreen(fullScreen);
      settings.setVSync(vSync);
      settings.setResolution(width[res], height[res]);
      app.setSettings(settings);
      nifty.gotoScreen("start");
    }
  }
Esempio n. 28
0
  // Initialize Nifty
  public void initNifty() {
    NiftyJmeDisplay niftyDisplay =
        new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
    Nifty nifty = niftyDisplay.getNifty();
    guiViewPort.addProcessor(niftyDisplay);

    // Add all XML files to Nifty
    nifty.addXml("Interface/XML/LogoSplash.xml");
    nifty.addXml("Interface/XML/TitleSplash.xml");
    nifty.addXml("Interface/XML/MainMenu.xml");
    nifty.addXml("Interface/XML/GameState.xml");
    nifty.addXml("Interface/XML/SettingsMenu.xml");
    nifty.addXml("Interface/XML/Loading.xml");

    // Going to the first Screen
    nifty.gotoScreen("start");

    // Setting the controller and attaching the state to the stateManager
    // logoSplash = (LogoSplashState) nifty.getScreen("start").getScreenController();
    MasterClass.mainMenu = (MainMenuState) nifty.getScreen("start").getScreenController();
    stateManager.attach(MasterClass.mainMenu);
  }
  @Override
  public void cleanup() {
    initialized = false;

    if (app != null) {
      app.getRootNode().detachAllChildren();
      app.getRootNode().removeLight(sun);
      app.getGuiViewPort().clearScenes();

      /* Otherwise after every reset the mapping triggers extra for every reset */
      app.getInputManager().deleteMapping("LMB");
      app.getInputManager().deleteMapping("KEY_R");
      app.getInputManager().deleteMapping("KEY_F10");
    }

    if (nifty != null) {
      nifty.exit();
    }
  }
  @Override
  public void simpleInitApp() {
    Box b = new Box(Vector3f.ZERO, 1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Textures/contenedorMadera.jpg"));
    geom.setMaterial(mat);
    rootNode.attachChild(geom);

    NiftyJmeDisplay niftyDisplay =
        new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
    nifty = niftyDisplay.getNifty();
    nifty.fromXml("Interface/Nifty/Probando-NiftyGUI.xml", "start", this);

    // attach the nifty display to the gui view port as a processor
    guiViewPort.addProcessor(niftyDisplay);

    // disable the fly cam
    //        flyCam.setEnabled(false);
    //        flyCam.setDragToRotate(true);
    inputManager.setCursorVisible(true);
  }