Beispiel #1
0
  private static void loadButtons(Skin skin) {
    TextButtonStyle textButtonStyle;

    for (ColorEnum color : ButtonEnum.colors) {
      for (LabelEnum size : ButtonEnum.sizes) {
        for (ButtonEnum button : ButtonEnum.values()) {
          textButtonStyle = new TextButtonStyle();
          textButtonStyle.font = skin.getFont(size.fontName);
          textButtonStyle.fontColor = color.getColor();
          textButtonStyle.up = skin.getDrawable(button.type + ".up");
          textButtonStyle.over = skin.getDrawable(button.type + ".over");
          textButtonStyle.down = skin.getDrawable(button.type + ".down");
          if (ButtonEnum.defaultColor == color) {
            if (ButtonEnum.defaultSize == size) {
              skin.add(button.type, textButtonStyle);
            }
            skin.add(button.type + "." + size.fontName, textButtonStyle);
          }
          skin.add(button.type + "." + size.fontName + "." + color.colorName, textButtonStyle);
        }
      }
    }

    skin.add("default", skin.get("default.default.black", TextButtonStyle.class));
  }
Beispiel #2
0
    public TextButton getPlayButton() {
      // Generate a 1x1 white texture and store it in the skin named "white".
      playBtnPixmap.setColor(Color.GREEN);
      playBtnPixmap.fill();
      skin.add("white", new Texture(playBtnPixmap));

      // Store the default libgdx font under the name "default".
      BitmapFont bfont = new BitmapFont();
      // bfont.getData().scale(1.0f);;
      skin.add("default", bfont);

      // Configure a TextButtonStyle and name it "default". Skin resources are stored by type, so
      // this doesn't overwrite the font.
      TextButtonStyle textButtonStyle = new TextButtonStyle();
      textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
      textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
      textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
      textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);

      textButtonStyle.font = skin.getFont("default");

      skin.add("default", textButtonStyle);

      TextButton btn = new TextButton("Play game! \nTada", textButtonStyle);
      btn.setX(Gdx.graphics.getWidth() / 2 - btn.getWidth() / 2);
      btn.setY(Gdx.graphics.getHeight() / 2);

      return btn;
    }
Beispiel #3
0
  @Override
  public void show() {
    // TODO Auto-generated method stub
    stage = new Stage();
    font = new BitmapFont(Gdx.files.internal("font.fnt"), false);
    style = new LabelStyle(font, Color.RED);
    label = new Label("Juego de Prueba", style);
    label.setPosition(Gdx.graphics.getWidth() / 3, Gdx.graphics.getHeight() - 100);
    stage.addActor(label);

    skin = new Skin();
    buttonatlas = new TextureAtlas("buttons/button.pack");
    skin.addRegions(buttonatlas);

    buttonstyle = new TextButtonStyle();
    buttonstyle.up = skin.getDrawable("button");
    buttonstyle.over = skin.getDrawable("buttonpress");
    buttonstyle.down = skin.getDrawable("buttonpress");
    buttonstyle.font = font;

    button = new TextButton("Play", buttonstyle);

    stage.addActor(button);

    button.addListener(
        new InputListener() {

          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            // TODO Auto-generated method stub

            game.setScreen(new PlayScreen(game));
            MainMenu.this.dispose();
            return true;
          }
        });

    // ok

    skin2 = new Skin();
    buttonatlas2 = new TextureAtlas("buttons/button2.pack");
    skin2.addRegions(buttonatlas2);

    buttonstyle2 = new TextButtonStyle();
    buttonstyle2.up = skin2.getDrawable("button2");
    buttonstyle2.over = skin2.getDrawable("button2press");
    buttonstyle2.down = skin2.getDrawable("button2press");
    buttonstyle2.font = font;

    button2 = new TextButton("", buttonstyle2);

    button2.setPosition(Gdx.graphics.getWidth() - 250, 0);

    stage.addActor(button2);

    button2.addListener(
        new InputListener() {

          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            // TODO Auto-generated method stub

            game.setScreen(new tablescreen(game));
            MainMenu.this.dispose();
            return true;
          }
        });

    batch = new SpriteBatch();

    Gdx.input.setInputProcessor(stage);
  }
Beispiel #4
0
  @Override
  public void show() {
    // Creates an stage that contains all the GUI elements
    stage = new Stage();
    stage.clear();
    Gdx.input.setInputProcessor(stage);

    // Title label
    font100orange = new BitmapFont(Gdx.files.internal("fonts/prehistorik100orange.fnt"));
    titleLabel = new Label(this.title, new LabelStyle(font100orange, Color.WHITE));
    titleLabel.setPosition(
        Gdx.graphics.getWidth() / 2.0f - titleLabel.getWidth() / 2,
        7.1f * Gdx.graphics.getHeight() / 9.0f);

    // Textbox label
    white30boldFont = new BitmapFont(Gdx.files.internal("fonts/white30bold.fnt"));
    label1 = new Label("IP adress of game creator:", new LabelStyle(white30boldFont, Color.WHITE));
    label1.setPosition(
        Gdx.graphics.getWidth() / 2.0f - label1.getWidth() / 2,
        6 * Gdx.graphics.getHeight() / 9.0f);

    // Username
    Label usernameLabel = ScreenUtils.createLabel("Username:"******"", 0, 0);
    usernameInput.setPosition(
        Gdx.graphics.getWidth() / 2f - usernameInput.getWidth() / 2f,
        3 * Gdx.graphics.getHeight() / 9.0f);

    // Atlas of the GUI
    atlas = new TextureAtlas("gui/gui.pack");
    skin = new Skin(atlas);

    // Buttons
    font60 = new BitmapFont(Gdx.files.internal("fonts/prehistorik60black.fnt"), false);
    TextButtonStyle buttonStyle = new TextButtonStyle();
    buttonStyle.up = skin.getDrawable("button1");
    buttonStyle.over = skin.getDrawable("button1-over");
    buttonStyle.down = skin.getDrawable("button1-down");
    buttonStyle.font = font60;

    joinButton = new TextButton("Join Game", buttonStyle);
    joinButton.setHeight(100f);
    joinButton.setWidth(500f);
    joinButton.setPosition(
        Gdx.graphics.getWidth() / 2.0f - joinButton.getWidth() / 2,
        1.5f * Gdx.graphics.getHeight() / 9.0f);

    menuButton = new TextButton("Main Menu", buttonStyle);
    menuButton.setHeight(100f);
    menuButton.setWidth(500f);
    menuButton.setPosition(
        Gdx.graphics.getWidth() / 2.0f - joinButton.getWidth() / 2,
        0f * Gdx.graphics.getHeight() / 9.0f);

    // TextField
    white36nonoFont = new BitmapFont(Gdx.files.internal("fonts/white36mono.fnt"));
    TextFieldStyle tfs = new TextFieldStyle();
    tfs.font = white36nonoFont;
    tfs.cursor = skin.getDrawable("cursor");
    tfs.background = skin.getDrawable("textField");
    tfs.fontColor = Color.WHITE;
    inputAddress = new TextField("localhost", tfs);
    inputAddress.setHeight(50);
    inputAddress.setWidth(300);
    inputAddress.setPosition(
        Gdx.graphics.getWidth() / 2.0f - inputAddress.getWidth() / 2,
        5 * Gdx.graphics.getHeight() / 9.0f);

    // add actors
    stage.addActor(joinButton);
    stage.addActor(menuButton);
    stage.addActor(inputAddress);
    stage.addActor(titleLabel);
    stage.addActor(usernameLabel);
    stage.addActor(usernameInput);
    stage.addActor(titleLabel);
    stage.addActor(label1);

    joinButton.addListener(
        new ChangeListener() {

          @Override
          public void changed(ChangeEvent event, Actor actor) {
            System.out.println(inputAddress.getText());

            GameScreen.createInstance(game, false, inputAddress.getText(), usernameInput.getText());
            game.setScreen(GameScreen.getInstance());
            //						game.initInputListeners();

          }
        });

    menuButton.addListener(
        new ChangeListener() {

          @Override
          public void changed(ChangeEvent event, Actor actor) {
            game.setScreen(new MenuScreen(game));
          }
        });
  }
  @Override
  public void show() {
    openingtheme.play();
    openingtheme.setLooping(true);
    // openingtheme.setVolume(game.state.volume);
    batch = new SpriteBatch();

    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    // Straight up stolen from https://www.pinterest.comore
    //        img = new Texture("menubackground1.png");
    img = new Texture("menu_background_fix.png");
    titleimg = new Texture("SlashHeroesTitle.png");
    img.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    // change these numbers around so it looks good on the presentation phone
    TextureRegion region = new TextureRegion(img, 0, 0, 600, 400);
    sprite = new Sprite(region);
    sprite.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    sprite.setOrigin(0, 0);

    skin = new Skin();
    // Generate a 1x1 white texture and store it in the skin named "white".
    Pixmap pixmap = new Pixmap(320, 75, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.GREEN);
    pixmap.fill();
    skin.add("white", new Texture(pixmap));

    // create the custom font
    FreeTypeFontGenerator generator =
        new FreeTypeFontGenerator(Gdx.files.internal("fonts/slkscre.ttf"));
    FreeTypeFontGenerator.FreeTypeFontParameter parameter =
        new FreeTypeFontGenerator.FreeTypeFontParameter();
    parameter.size = 80;
    BitmapFont OurFont = generator.generateFont(parameter);
    generator.dispose(); // don't forget to dispose to avoid memory leaks!

    // add ourfont to the skin for our buttons.
    skin.add("default", OurFont);

    // textbuttonstyle wont overwrite the font
    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
    textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
    textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
    textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
    textButtonStyle.font = skin.getFont("default");

    skin.add("default", textButtonStyle);

    // Create a button with the "default" TextButtonStyle.
    final TextButton PlayButton = new TextButton("PLAY", textButtonStyle);
    // final TextButton ContinueButton = new TextButton("Continue",textButtonStyle);
    final TextButton SettingsButton = new TextButton("Mute", textButtonStyle);
    final TextButton QuitButton = new TextButton("Quit", textButtonStyle);
    PlayButton.setPosition(Gdx.graphics.getWidth() / 2 - 160, Gdx.graphics.getHeight() / 2 - 150);
    // ContinueButton.setPosition(Gdx.graphics.getWidth()/2 - 160, Gdx.graphics.getHeight()/2 - 85);
    //        SettingsButton.setPosition(Gdx.graphics.getWidth()/2 - 160, Gdx.graphics.getHeight()/2
    // - 165);
    SettingsButton.setPosition(
        Gdx.graphics.getWidth() / 2 - 160, Gdx.graphics.getHeight() / 2 - 300);
    //        QuitButton.setPosition(Gdx.graphics.getWidth()/2 - 160, Gdx.graphics.getHeight()/2 -
    // 245);
    QuitButton.setPosition(Gdx.graphics.getWidth() / 2 - 160, Gdx.graphics.getHeight() / 2 - 450);
    stage.addActor(PlayButton);
    // stage.addActor(ContinueButton);
    stage.addActor(SettingsButton);
    stage.addActor(QuitButton);

    PlayButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            select.play();
            PlayButton.setText("Starting new game");
            openingtheme.stop();
            game.setScreen(game.introscreen);
          }
        });
    SettingsButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            // System.out.println("Clicked! Is checked: " + button.isChecked());
            select.play();
            if (game.state.volume == 0f) {
              game.state.volume = .7f;
              openingtheme.play();
              openingtheme.setVolume(game.state.volume);
              SettingsButton.setText("Mute");
            } else {
              game.state.volume = 0f;
              openingtheme.stop();
              SettingsButton.setText("Unmute");
            }

            // TODO make this mute and unmute the non existant sound
            // mute and unmute;
          }
        });
    QuitButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            select.play();
            openingtheme.stop();
            QuitButton.setText("Quitting");
            // TODO make this quit the correct way
            System.exit(0);
          }
        });
  }