示例#1
0
  @Override
  public AbstractWidget createWidget(Controller controller) {
    Skin skin = controller.getApplicationAssets().getSkin();
    LinearLayout bottomLayout = new LinearLayout(false);
    label = new Label("Stopped", skin);

    bottomLayout.add(label);

    SelectBox<String> selectBox = new SelectBox<String>(skin);
    selectBox.setItems(
        "Just", "a", "drop", "down", "list", "to", "check", "that", "UI", "doesn't", "freeze");

    TextButton textButton = new TextButton("Run", skin);
    textButton.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            Gdx.app.postRunnable(launchBackgroundProcess);
          }
        });

    bottomLayout.add(selectBox);
    bottomLayout.add(textButton);
    return bottomLayout;
  }
  public void addChapters() {
    WorldDocument w = Ctx.project.getWorld();
    String[] nl = w.getChapters();
    Array<String> array = new Array<String>();

    for (int i = 0; i < nl.length; i++) {
      array.add(nl[i]);
    }

    chapters.setItems(array);
    chapters.setSelected(Ctx.project.getSelectedChapter().getId());
    invalidate();
  }
        @Override
        public void changed(ChangeEvent event, Actor actor) {
          String selChapter = (String) chapters.getSelected();

          if (selChapter != null && !selChapter.equals(Ctx.project.getSelectedChapter().getId())) {

            // Save the project when changing chapter
            try {
              Ctx.project.saveProject();
            } catch (IOException | TransformerException e1) {
              Ctx.msg.show(getStage(), "Error saving project", 3);
              EditorLogger.error(e1.getMessage());
            }

            try {

              if (selChapter != null) Ctx.project.loadChapter(selChapter);

              doc = Ctx.project.getSelectedChapter();

              addElements(doc, doc.getElement(), "scene");
            } catch (ParserConfigurationException | SAXException | IOException e1) {
              e1.printStackTrace();
            }
          }
        }
  public void addProperty(String name, String value, Types type) {

    table.row();
    table.add(new Label(name, skin)).expandX().left();

    if (type == Types.BOOLEAN) {
      SelectBox<String> sb = new SelectBox<String>(skin);
      sb.setItems(BOOLEAN_VALUES);
      if (value != null) sb.setSelected(value);
      sb.setName(name);
      table.add(sb).expandX().left();

      sb.addListener(
          new ChangeListener() {

            @SuppressWarnings("unchecked")
            @Override
            public void changed(ChangeEvent event, Actor actor) {
              updateModel(actor.getName(), ((SelectBox<String>) actor).getSelected());
            }
          });
    } else {
      TextField tf = new TextField(value == null ? "" : value, skin);
      tf.setName(name);
      table.add(tf).expandX().left();

      if (type == Types.INTEGER)
        tf.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());

      tf.setTextFieldListener(
          new TextFieldListener() {
            @Override
            public void keyTyped(TextField actor, char c) {
              updateModel(actor.getName(), ((TextField) actor).getText());
            }
          });

      //			tf.addListener(new FocusListener() {
      //
      //				@Override
      //				public void keyboardFocusChanged (FocusEvent event, Actor actor, boolean focused) {
      //					if(!focused)
      //						updateModel(actor.getName(), ((TextField)actor).getText());
      //				}
      //			});
    }
  }
示例#5
0
  @Override
  public void create() {
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    texture1 = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    texture2 = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    TextureRegion image = new TextureRegion(texture1);
    TextureRegion imageFlipped = new TextureRegion(image);
    imageFlipped.flip(true, true);
    TextureRegion image2 = new TextureRegion(texture2);
    // stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false, new
    // PolygonSpriteBatch());
    stage = new Stage();
    // stage.setViewport(new ExtendViewport(800, 480));
    Gdx.input.setInputProcessor(stage);

    // Group.debug = true;

    ImageButtonStyle style = new ImageButtonStyle(skin.get(ButtonStyle.class));
    style.imageUp = new TextureRegionDrawable(image);
    style.imageDown = new TextureRegionDrawable(imageFlipped);
    ImageButton iconButton = new ImageButton(style);

    Button buttonMulti = new TextButton("Multi\nLine\nToggle", skin, "toggle");
    Button imgButton = new Button(new Image(image), skin);
    Button imgToggleButton = new Button(new Image(image), skin, "toggle");

    Label myLabel = new Label("this is some text.", skin);
    myLabel.setWrap(true);

    Table t = new Table();
    t.row();
    t.add(myLabel);

    t.layout();

    CheckBox checkBox = new CheckBox("Check me", skin);
    final Slider slider = new Slider(0, 10, 1, false, skin);
    TextField textfield = new TextField("", skin);
    textfield.setMessageText("Click here!");
    SelectBox dropdown = new SelectBox(skin);
    dropdown.setItems(
        "Android1",
        "Windows1",
        "Linux1",
        "OSX1",
        "Android2",
        "Windows2",
        "Linux2",
        "OSX2",
        "Android3",
        "Windows3",
        "Linux3",
        "OSX3",
        "Android4",
        "Windows4",
        "Linux4",
        "OSX4",
        "Android5",
        "Windows5",
        "Linux5",
        "OSX5",
        "Android6",
        "Windows6",
        "Linux6",
        "OSX6",
        "Android7",
        "Windows7",
        "Linux7",
        "OSX7");
    dropdown.setSelected("Linux6");
    Image imageActor = new Image(image2);
    ScrollPane scrollPane = new ScrollPane(imageActor);
    List list = new List(skin);
    list.setItems(listEntries);
    list.getSelection().setMultiple(true);
    list.getSelection().setRequired(false);
    // list.getSelection().setToggle(true);
    ScrollPane scrollPane2 = new ScrollPane(list, skin);
    scrollPane2.setFlickScroll(false);
    SplitPane splitPane = new SplitPane(scrollPane, scrollPane2, false, skin, "default-horizontal");
    fpsLabel = new Label("fps:", skin);

    // configures an example of a TextField in password mode.
    final Label passwordLabel = new Label("Textfield in password mode: ", skin);
    final TextField passwordTextField = new TextField("", skin);
    passwordTextField.setMessageText("password");
    passwordTextField.setPasswordCharacter('*');
    passwordTextField.setPasswordMode(true);

    // window.debug();
    Window window = new Window("Dialog", skin);
    window.getButtonTable().add(new TextButton("X", skin)).height(window.getPadTop());
    window.setPosition(0, 0);
    window.defaults().spaceBottom(10);
    window.row().fill().expandX();
    window.add(iconButton);
    window.add(buttonMulti);
    window.add(imgButton);
    window.add(imgToggleButton);
    window.row();
    window.add(checkBox);
    window.add(slider).minWidth(100).fillX().colspan(3);
    window.row();
    window.add(dropdown);
    window.add(textfield).minWidth(100).expandX().fillX().colspan(3);
    window.row();
    window.add(splitPane).fill().expand().colspan(4).maxHeight(200);
    window.row();
    window.add(passwordLabel).colspan(2);
    window.add(passwordTextField).minWidth(100).expandX().fillX().colspan(2);
    window.row();
    window.add(fpsLabel).colspan(4);
    window.pack();

    // stage.addActor(new Button("Behind Window", skin));
    stage.addActor(window);

    textfield.setTextFieldListener(
        new TextFieldListener() {
          public void keyTyped(TextField textField, char key) {
            if (key == '\n') textField.getOnscreenKeyboard().show(false);
          }
        });

    slider.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            Gdx.app.log("UITest", "slider: " + slider.getValue());
          }
        });

    iconButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            new Dialog("Some Dialog", skin, "dialog") {
              protected void result(Object object) {
                System.out.println("Chosen: " + object);
              }
            }.text("Are you enjoying this demo?")
                .button("Yes", true)
                .button("No", false)
                .key(Keys.ENTER, true)
                .key(Keys.ESCAPE, false)
                .show(stage);
          }
        });
  }
示例#6
0
  /**
   * by which menu Screen this option screen was called
   *
   * @param pScreen
   */
  public OptionsScreen(MenuScreen pScreen) {
    screen = pScreen;
    game = screen.game;
    stage = new Stage();
    stage.setViewport(800, 480, false);
    skin = new Skin(Gdx.files.internal("ui/myskin.json"));

    Table table = new Table();
    table.setSize(800, 480);

    Label title = new Label("options", skin);
    title.setFontScale(2f);
    table.add(title).colspan(2).align(Align.center);
    table.row();

    Label namel = new Label("name:", skin);
    table.add(namel);

    TextField name = new TextField("", skin);
    table.add(name);
    table.row();

    Label graphicl = new Label("graphic:", skin);
    table.add(graphicl);

    CheckBox graphic = new CheckBox("", skin);
    table.add(graphic);
    table.row();

    Label soundl = new Label("sound:", skin);
    table.add(soundl);

    final Slider sound = new Slider(0, 100, 1, false, skin);
    sound.setValue(game.preferences.getInteger("volume", 100));
    table.add(sound);
    table.row();

    Label themel = new Label("theme:", skin);
    table.add(themel);

    String[] items = {"cool", "mega", "awesome"};
    SelectBox theme = new SelectBox(items, skin);

    theme.getSelection();
    table.add(theme);
    table.row();

    TextButton back = new TextButton("back to menu", skin);
    back.addListener(
        new ClickListener() {
          public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
            stage.addAction(
                Actions.sequence(
                    Actions.moveTo(800, 0, 0.5f),
                    new Action() {

                      @Override
                      public boolean act(float delta) {

                        game.preferences.putInteger("volume", (int) sound.getValue());
                        game.preferences.flush();

                        Resources.page_turn.play();
                        screen.game.setScreen(screen);
                        return false;
                      }
                    }));
          }
        });
    table.add(back).colspan(2).align(Align.center).padTop(20);

    stage.addActor(table);
    stage.addAction(Actions.moveTo(800, 0));
    stage.addAction(Actions.moveTo(0, 0, 0.5f));

    Gdx.input.setInputProcessor(stage);
  }
 protected void setAnimation() {
   ((SpriterPlayer) this.playerGroup.player).setAnimation(box.getSelection(), 1, 10);
 }
  public SceneList(Skin skin) {
    super(skin, true);

    HorizontalGroup chapterPanel = new HorizontalGroup();
    chapters = new SelectBox<String>(skin);
    chapters.setFillParent(true);

    chapterPanel.addActor(new Label("CHAPTER ", skin, "big"));
    chapterPanel.addActor(chapters);

    clearChildren();

    add(chapterPanel).expandX().fillX();
    row();
    add(toolbar).expandX().fillX();
    row().fill();
    add(container).expandY().fill();

    initBtn = new ImageButton(skin);
    toolbar.addToolBarButton(initBtn, "ic_check", "Set init scene", "Set init scene");

    initBtn.setDisabled(true);

    list.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            int pos = list.getSelectedIndex();

            if (pos == -1) {
              Ctx.project.setSelectedScene(null);
            } else {
              Element a = list.getItems().get(pos);
              Ctx.project.setSelectedScene(a);
            }

            toolbar.disableEdit(pos == -1);
            initBtn.setDisabled(pos == -1);
          }
        });

    list.setCellRenderer(listCellRenderer);

    initBtn.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            setDefault();
          }
        });

    Ctx.project.addPropertyChangeListener(
        Project.NOTIFY_PROJECT_LOADED,
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent arg0) {
            toolbar.disableCreate(Ctx.project.getProjectDir() == null);

            disposeBgCache = true;
            addChapters();
          }
        });

    chapters.addListener(chapterListener);

    Ctx.project
        .getWorld()
        .addPropertyChangeListener(
            new PropertyChangeListener() {
              @Override
              public void propertyChange(PropertyChangeEvent evt) {
                EditorLogger.debug(
                    evt.getPropertyName()
                        + " NEW:"
                        + evt.getNewValue()
                        + " OLD:"
                        + evt.getOldValue());

                if (evt.getPropertyName().equals(XMLConstants.CHAPTER_TAG)) {
                  addChapters();
                } else if (evt.getPropertyName().equals("ELEMENT_DELETED")) {
                  Element e = (Element) evt.getNewValue();

                  if (e.getTagName().equals(XMLConstants.CHAPTER_TAG)) {
                    addChapters();
                  }
                }
              }
            });
  }