Esempio n. 1
0
  @Override
  public void onAttached(GuiComponent oparent) {
    this.setSize(oparent.getWidth(), oparent.getHeight());
    this.attachComponent(new DefaultBackground("bg"));
    ButtonList list =
        new ButtonList("languages", 0, 0, this.getWidth(), (int) (this.getHeight() * 0.8f));
    list.setCallback(
        new ButtonListCallback() {
          @Override
          public void onButtonListClick(ButtonList list, Button button) {
            String code =
                button
                    .getText()
                    .substring(button.getText().indexOf('(') + 1, button.getText().indexOf(')'));
            OpenClassic.getGame().getConfig().setValue("options.language", code);
            OpenClassic.getClient().setActiveComponent(new LanguageScreen(parent));
            OpenClassic.getGame().getConfig().save();
          }
        });

    this.attachComponent(list);
    this.attachComponent(
        new Button(
                "back",
                this.getWidth() / 2 - 150,
                (int) (this.getHeight() * 0.8f),
                300,
                40,
                OpenClassic.getGame().getTranslator().translate("gui.back"))
            .setCallback(
                new ButtonCallback() {
                  @Override
                  public void onButtonClick(Button button) {
                    OpenClassic.getClient().setActiveComponent(parent);
                  }
                }));

    this.attachComponent(
        new Label(
            "title",
            this.getWidth() / 2,
            this.getHeight() / 4 - 80,
            OpenClassic.getGame().getTranslator().translate("gui.language.select"),
            true));

    String text =
        String.format(
            OpenClassic.getGame().getTranslator().translate("gui.language.current"),
            OpenClassic.getGame().getConfig().getString("options.language"));
    this.attachComponent(
        new Label(
            "current", this.getWidth() / 2, (int) (this.getHeight() * 0.8f) - 56, text, true));

    List<String> languages = new ArrayList<String>();
    for (Language language : OpenClassic.getGame().getTranslator().getLanguages()) {
      languages.add(language.getName() + " (" + language.getLangCode() + ")");
    }

    this.getComponent("languages", ButtonList.class).setContents(languages);
  }
Esempio n. 2
0
  @Override
  public void onAttached(GuiComponent oparent) {
    this.setSize(oparent.getWidth(), oparent.getHeight());
    this.attachComponent(new TranslucentBackground("bg"));
    this.attachComponent(
        new TextBox("name", this.getWidth() / 2 - 200, this.getHeight() / 2 - 60, 30));
    this.attachComponent(
        new Button(
                "save",
                this.getWidth() / 2 - 200,
                (int) (this.getHeight() * 0.75f),
                OpenClassic.getGame().getTranslator().translate("gui.level-dump.dump"))
            .setCallback(
                new ButtonCallback() {
                  @Override
                  public void onButtonClick(Button button) {
                    OpenClassic.getClient()
                        .saveLevel(getComponent("name", TextBox.class).getText());
                    OpenClassic.getClient().setActiveComponent(parent);
                  }
                }));

    this.attachComponent(
        new Button(
                "back",
                this.getWidth() / 2 - 200,
                (int) (this.getHeight() * 0.75f) + 48,
                OpenClassic.getGame().getTranslator().translate("gui.cancel"))
            .setCallback(
                new ButtonCallback() {
                  @Override
                  public void onButtonClick(Button button) {
                    OpenClassic.getClient().setActiveComponent(parent);
                  }
                }));

    this.attachComponent(
        new Label(
            "title",
            this.getWidth() / 2,
            this.getHeight() / 4 - 60,
            OpenClassic.getGame().getTranslator().translate("gui.level-dump.name"),
            true));
    this.getComponent("save", Button.class).setActive(false);
  }
Esempio n. 3
0
  @Override
  public void update(int mouseX, int mouseY) {
    String text =
        String.format(
            OpenClassic.getGame().getTranslator().translate("gui.language.current"),
            OpenClassic.getGame().getConfig().getString("options.language"));
    Label label = this.getComponent("current", Label.class);
    if (!label.getText().equals(text)) {
      label.setText(text);
    }

    super.update(mouseX, mouseY);
  }
  @Override
  public void onAttached(GuiComponent oparent) {
    this.setSize(oparent.getWidth(), oparent.getHeight());
    List<String> contents = new ArrayList<String>();
    for (Server server : ServerDataStore.getServers()) {
      contents.add(server.name);
    }

    this.attachComponent(new DefaultBackground("bg"));
    ButtonList list =
        new ButtonList("servers", 0, 0, this.getWidth(), (int) (this.getHeight() * 0.8f), true);
    list.setCallback(
        new ButtonListCallback() {
          @Override
          public void onButtonListClick(ButtonList list, Button button) {
            String text = button.getText();
            int index = 0;
            for (String t : list.getContents()) {
              if (text.equals(t)) {
                break;
              }

              index++;
            }

            Server server = ServerDataStore.getServers().get(index);
            if (select) {
              getComponent("title", Label.class)
                  .setText(OpenClassic.getGame().getTranslator().translate("gui.favorites.select"));
              select = false;
              ServerDataStore.addFavorite(server.name, server.getUrl());
              ServerDataStore.saveFavorites();
            } else {
              OpenClassic.getClient().joinServer(server.getUrl());
            }
          }
        });

    this.attachComponent(list);
    this.attachComponent(
        new Button(
                "favorites",
                this.getWidth() / 2 - 412,
                (int) (this.getHeight() * 0.8f),
                200,
                40,
                OpenClassic.getGame().getTranslator().translate("gui.servers.favorites"))
            .setCallback(
                new ButtonCallback() {
                  @Override
                  public void onButtonClick(Button button) {
                    OpenClassic.getClient()
                        .setActiveComponent(new FavoriteServersScreen(ServerListScreen.this));
                  }
                }));

    this.attachComponent(
        new Button(
                "addfavorite",
                this.getWidth() / 2 - 204,
                (int) (this.getHeight() * 0.8f),
                200,
                40,
                OpenClassic.getGame().getTranslator().translate("gui.add-favorite.add"))
            .setCallback(
                new ButtonCallback() {
                  @Override
                  public void onButtonClick(Button button) {
                    Label label = getComponent("title", Label.class);
                    if (select) {
                      label.setText(
                          OpenClassic.getGame().getTranslator().translate("gui.favorites.select"));
                      select = false;
                    } else {
                      label.setText(
                          Color.GREEN
                              + OpenClassic.getGame()
                                  .getTranslator()
                                  .translate("gui.servers.select-fav"));
                      select = true;
                    }
                  }
                }));

    this.attachComponent(
        new Button(
                "url",
                this.getWidth() / 2 + 4,
                (int) (this.getHeight() * 0.8f),
                200,
                40,
                OpenClassic.getGame().getTranslator().translate("gui.servers.enter-url"))
            .setCallback(
                new ButtonCallback() {
                  @Override
                  public void onButtonClick(Button button) {
                    OpenClassic.getClient()
                        .setActiveComponent(new ServerURLScreen(ServerListScreen.this));
                  }
                }));

    this.attachComponent(
        new Button(
                "back",
                this.getWidth() / 2 + 212,
                (int) (this.getHeight() * 0.8f),
                200,
                40,
                OpenClassic.getGame().getTranslator().translate("gui.back"))
            .setCallback(
                new ButtonCallback() {
                  @Override
                  public void onButtonClick(Button button) {
                    OpenClassic.getClient().setActiveComponent(parent);
                  }
                }));

    this.attachComponent(
        new Label(
            "title",
            this.getWidth() / 2,
            this.getHeight() / 4 - 80,
            OpenClassic.getGame().getTranslator().translate("gui.favorites.select"),
            true));
    this.getComponent("servers", ButtonList.class).setContents(contents);
  }
Esempio n. 5
0
 @Override
 public void onKeyPress(char c, int key) {
   super.onKeyPress(c, key);
   this.getComponent("save", Button.class)
       .setActive(this.getComponent("name", TextBox.class).getText().trim().length() > 0);
 }