示例#1
0
文件: GUI.java 项目: w4ll3/ppioo-1
  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));
  }
示例#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;
    }
示例#3
0
  private void loadHUD() {
    Skin skin = new Skin();
    TextButtonStyle style = new TextButton.TextButtonStyle();
    skin.add("default", new BitmapFont());
    style.font = skin.getFont("default");
    skin.add("default", style);

    TextButton button1 = new TextButton("HUD-Label1", skin);
    uiStage.addActor(button1);
    button1.setPosition(camera.viewportWidth / 2 - 100, 0);
    button1.setBounds(button1.getX(), button1.getY(), button1.getWidth(), button1.getHeight());

    uiStage.addActor(new TextButton("HUD-Label2", skin));
  }
示例#4
0
  public void init() {
    assetManager.load(ATLAS_UI, TextureAtlas.class);
    assetManager.load(SKIN_UI, Skin.class);

    assetManager.load(ATLAS_UI_BUTTONS, TextureAtlas.class);
    // assetManager.load(SKIN_UI_BUTTONS, Skin.class);
    // TODO: load game graphics atlas here
    assetManager.finishLoading();

    skinUI = assetManager.get(SKIN_UI);
    textureAtlasUI = assetManager.get(ATLAS_UI);

    textureAtlasButtons = assetManager.get(ATLAS_UI_BUTTONS, TextureAtlas.class);

    // Stopped loading the skinButton skin in the Assetmanager to generate font size on the fly
    skinButton = new Skin();
    skinButton.add(
        "default-font",
        this.fonts.getLemonMilk(Helpers.getFontSize(20, 720.0f, Gdx.graphics.getHeight())));
    skinButton.addRegions(new TextureAtlas(Gdx.files.internal("ui/9patch_buttons.atlas")));
    skinButton.load(Gdx.files.internal("ui/9patch_buttons.json"));

    // this.assetManager = assetManager;

    // assetManager.load(Constants.ATLAS_GAME, TextureAtlas.class);
    // assetManager.finishLoading();
    // TextureAtlas atlas = assetManager.get(Constants.ATLAS_GAME);

    // initAssets(atlas);
  }
示例#5
0
文件: GUI.java 项目: w4ll3/ppioo-1
  private static void loadLabels(Skin skin) {
    Label.LabelStyle labelStyle;

    for (ColorEnum color : LabelEnum.colors) {
      for (LabelEnum label : LabelEnum.values()) {
        labelStyle = new Label.LabelStyle();
        labelStyle.font = skin.getFont(label.fontName);
        labelStyle.fontColor = color.getColor();
        labelStyle.background = skin.getDrawable("transparent");
        if (LabelEnum.defaultColor == color) {
          skin.add(label.fontName, labelStyle);
        }
        skin.add(label.fontName + "." + color.colorName, labelStyle);
      }
    }

    skin.add("default", skin.get("default.black", LabelStyle.class));
  }
示例#6
0
  public static void createSkin() {
    /// Create a font
    BitmapFont font = new BitmapFont();
    skin = new Skin();
    skin.add("default", font);

    /// Create a texture
    Pixmap pixmap =
        new Pixmap(
            (int) Gdx.graphics.getWidth() / 4,
            (int) Gdx.graphics.getHeight() / 10,
            Pixmap.Format.RGB888);
    pixmap.setColor(Color.RED);
    pixmap.fill();
    skin.add("background", new Texture(pixmap));

    /// Create a button style
    TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("background", Color.GRAY);
    textButtonStyle.down = skin.newDrawable("background", Color.DARK_GRAY);
    textButtonStyle.checked = skin.newDrawable("background", Color.DARK_GRAY);
    textButtonStyle.over = skin.newDrawable("background", Color.LIGHT_GRAY);
    textButtonStyle.font = skin.getFont("default");
    skin.add("default", textButtonStyle);

    /// Create Title Style
    Label.LabelStyle labelStyle = new Label.LabelStyle();
    labelStyle.fontColor = Color.RED;
    Pixmap titlePixmap =
        new Pixmap(
            (int) Gdx.graphics.getWidth() / 4,
            (int) Gdx.graphics.getHeight() / 10,
            Pixmap.Format.RGB888);
    titlePixmap.setColor(Color.CLEAR);
    titlePixmap.fill();
    skin.add("titleBackground", new Texture(titlePixmap));
    labelStyle.background = skin.newDrawable("titleBackground", Color.CLEAR);
    labelStyle.font = skin.getFont("default");
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Nearest);
    skin.add("default", labelStyle);
  }
  public void loadTouchpad() {
    touchpadSkin = new Skin();
    // Set background image
    touchpadSkin.add("touchBackground", new Texture("data/joystick_background.png"));
    // Set knob image
    touchpadSkin.add("touchKnob", new Texture("data/joystick_ball.png"));

    TouchpadStyle touchpadStyle = new TouchpadStyle();

    Drawable touchBackground = touchpadSkin.getDrawable("touchBackground");
    Drawable touchKnob = touchpadSkin.getDrawable("touchKnob");

    touchpadStyle.background = touchBackground;
    touchpadStyle.knob = touchKnob;
    // Create new TouchPad with the created style
    touchpad = new Touchpad(5, touchpadStyle);
    // setBounds(x,y,width,height)

    float width = Gdx.graphics.getWidth();
    touchpad.setPosition((float) .15 * width, (float) (.15 * width));
    touchpad.setBounds(15, 15, (float) .2 * width, (float) .2 * width);
    stage.addActor(touchpad);
  }
示例#8
0
 private Touchpad getTouchPad(
     String backgroundTexturePath, String knobTexturePath, float xPos, float yPos) {
   Skin skin = new Skin();
   Texture padbgTex = new Texture(Gdx.files.internal(backgroundTexturePath));
   Texture knobTex = new Texture(Gdx.files.internal(knobTexturePath));
   padbgTex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
   knobTex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
   Sprite padSprite = new Sprite(padbgTex);
   padSprite.setSize(30, 30);
   Sprite knobSprite = new Sprite(knobTex);
   knobSprite.setSize(20, 20);
   skin.add("padbg", padSprite);
   skin.add("knob", knobSprite);
   TouchpadStyle touchpadStyle =
       new TouchpadStyle(skin.getDrawable("padbg"), skin.getDrawable("knob"));
   Touchpad touchpad = new Touchpad(3, touchpadStyle);
   touchpad.setPosition(xPos, yPos);
   return touchpad;
 }
  @Override
  public void show() {

    // BackButton Handeling

    Drawable menuDrawable =
        new TextureRegionDrawable(
            new TextureRegion(new Texture(Gdx.files.internal("images/backgroundlevel.png"))));

    backGImage = new Image(menuDrawable, Scaling.stretch);
    backGImage.setFillParent(true);

    stage.addActor(backGImage);

    skin = new Skin(Gdx.files.internal("ui/JsonFiles/uiskin.json"));
    skin.add(
        "top",
        new TextureRegionDrawable(
            new TextureRegion(
                new Texture(Gdx.files.internal("images/levelscreen.png")), 153, 88, 150, 150)),
        Drawable.class);
    skin.add(
        "lockedlevel",
        new TextureRegionDrawable(
            new TextureRegion(
                new Texture(Gdx.files.internal("images/levelscreen.png")), 1, 88, 150, 150)),
        Drawable.class);

    skin.add(
        "star-filled",
        new TextureRegionDrawable(
            new TextureRegion(
                new Texture(Gdx.files.internal("images/levelscreen.png")), 1, 1, 90, 85)),
        Drawable.class);
    skin.add(
        "star-unfilled",
        new TextureRegionDrawable(
            new TextureRegion(
                new Texture(Gdx.files.internal("images/levelscreen.png")), 93, 1, 90, 85)),
        Drawable.class);

    // skin.add("star-filled", skin.newDrawable("white", Color.YELLOW),
    // Drawable.class);
    // skin.add("star-unfilled", skin.newDrawable("white", Color.GRAY),
    // Drawable.class);
    Gdx.input.setInputProcessor(stage);

    container = new Table();
    stage.addActor(container);
    container.setFillParent(true);

    PagedScrollPane scroll = new PagedScrollPane();

    scroll.setFlingTime(0.4f);
    scroll.setPageSpacing(80);
    int c = 1;
    for (int l = 0; l < 2; l++) {
      Table levels = new Table().pad(0);
      levels.defaults().pad(0, 20, 0, 15);
      for (int y = 0; y < 2; y++) {
        levels.row();
        for (int x = 0; x < 3; x++) {
          levels.add(getLevelButton(c++)).fill().expand().size(63, 88);
        }
      }
      scroll.addPage(levels);
    }
    container.add(scroll).expand().fill();

    // backGImage.addAction(parallel(moveTo(250, 250, 2, bounceOut),
    // color(Color.RED, 6), delay(0.5f), rotateTo(180, 5, swing)));
    backGImage.addAction(
        repeat(1, (sequence(scaleTo(2, 2, 0.8f), scaleTo(1, 1, 0.8f), delay(1.9f)))));

    InputProcessor backProcessor =
        new InputAdapter() {
          @Override
          public boolean keyDown(int keycode) {

            if ((keycode == Keys.ESCAPE) || (keycode == Keys.BACK))
              game.setScreen(game.getMenuScreen());
            return false;
          }
        };

    InputMultiplexer multiplexer = new InputMultiplexer(stage, backProcessor);
    Gdx.input.setInputProcessor(multiplexer);
    Gdx.input.setCatchBackKey(true);
  }
示例#10
0
文件: GUI.java 项目: w4ll3/ppioo-1
  private static void loadResources(Skin skin) {
    FreeTypeFontGenerator gen = new FreeTypeFontGenerator(Gdx.files.internal("graduate.ttf"));
    FreeTypeFontGenerator.FreeTypeFontParameter param =
        new FreeTypeFontGenerator.FreeTypeFontParameter();
    param.size = 12;
    skin.add("x-small", gen.generateFont(param));
    param.size = 16;
    skin.add("small", gen.generateFont(param));
    param.size = 20;
    skin.add("default", gen.generateFont(param));
    param.size = 24;
    skin.add("medium", gen.generateFont(param));
    param.size = 32;
    skin.add("big", gen.generateFont(param));
    param.size = 48;
    skin.add("huge", gen.generateFont(param));
    param.size = 72;
    skin.add("x-huge", gen.generateFont(param));

    skin.add(
        "default.up",
        new NinePatch(new Texture(Gdx.files.internal("button.up.default.9.png")), 16, 16, 16, 16));
    skin.add(
        "default.over",
        new NinePatch(
            new Texture(Gdx.files.internal("button.over.default.9.png")), 16, 16, 16, 16));
    skin.add(
        "default.down",
        new NinePatch(
            new Texture(Gdx.files.internal("button.down.default.9.png")), 16, 16, 16, 16));

    skin.add(
        "success.up",
        new NinePatch(new Texture(Gdx.files.internal("button.up.success.9.png")), 16, 16, 16, 16));
    skin.add(
        "success.over",
        new NinePatch(
            new Texture(Gdx.files.internal("button.over.success.9.png")), 16, 16, 16, 16));
    skin.add(
        "success.down",
        new NinePatch(
            new Texture(Gdx.files.internal("button.down.success.9.png")), 16, 16, 16, 16));

    skin.add(
        "warning.up",
        new NinePatch(new Texture(Gdx.files.internal("button.up.warning.9.png")), 16, 16, 16, 16));
    skin.add(
        "warning.over",
        new NinePatch(
            new Texture(Gdx.files.internal("button.over.warning.9.png")), 16, 16, 16, 16));
    skin.add(
        "warning.down",
        new NinePatch(
            new Texture(Gdx.files.internal("button.down.warning.9.png")), 16, 16, 16, 16));

    skin.add(
        "error.up",
        new NinePatch(new Texture(Gdx.files.internal("button.up.error.9.png")), 16, 16, 16, 16));
    skin.add(
        "error.over",
        new NinePatch(new Texture(Gdx.files.internal("button.over.error.9.png")), 16, 16, 16, 16));
    skin.add(
        "error.down",
        new NinePatch(new Texture(Gdx.files.internal("button.down.error.9.png")), 16, 16, 16, 16));

    skin.add(
        "window", new NinePatch(new Texture(Gdx.files.internal("window.9.png")), 32, 32, 32, 32));

    skin.add("checkbox.on", new Texture(Gdx.files.internal("checkbox.on.default.png")));
    skin.add("checkbox.off", new Texture(Gdx.files.internal("checkbox.off.default.png")));
    skin.add("checkbox.on.disabled", new Texture(Gdx.files.internal("checkbox.on.disabled.png")));
    skin.add("checkbox.off.disabled", new Texture(Gdx.files.internal("checkbox.off.disabled.png")));

    skin.add(
        "checkbox.on.slider.horizontal",
        new Texture(Gdx.files.internal("checkbox.on.slider.horizontal.png")));
    skin.add(
        "checkbox.off.slider.horizontal",
        new Texture(Gdx.files.internal("checkbox.off.slider.horizontal.png")));

    skin.add("radiobutton.on", new Texture(Gdx.files.internal("radiobutton.on.default.png")));
    skin.add(
        "radiobutton.on.over", new Texture(Gdx.files.internal("radiobutton.on.over.default.png")));
    skin.add("radiobutton.off", new Texture(Gdx.files.internal("radiobutton.off.default.png")));
    skin.add(
        "radiobutton.off.over",
        new Texture(Gdx.files.internal("radiobutton.off.over.default.png")));
    skin.add(
        "radiobutton.disabled",
        new Texture(Gdx.files.internal("radiobutton.disabled.default.png")));

    skin.add("arrow.up", new Texture(Gdx.files.internal("arrow.up.default.png")));
    skin.add("arrow.up.disabled", new Texture(Gdx.files.internal("arrow.up.disabled.png")));
    skin.add("arrow.down", new Texture(Gdx.files.internal("arrow.down.default.png")));
    skin.add("arrow.down.disabled", new Texture(Gdx.files.internal("arrow.down.disabled.png")));
    skin.add("arrow.left", new Texture(Gdx.files.internal("arrow.left.default.png")));
    skin.add("arrow.left.disabled", new Texture(Gdx.files.internal("arrow.left.disabled.png")));
    skin.add("arrow.right", new Texture(Gdx.files.internal("arrow.right.default.png")));
    skin.add("arrow.right.disabled", new Texture(Gdx.files.internal("arrow.right.disabled.png")));

    for (ColorEnum color : ColorEnum.values()) {
      skin.add(color.colorName, color.getColor());
    }

    Pixmap pixmap;

    pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    pixmap.setColor(skin.getColor("white"));
    pixmap.fill();
    skin.add("white", new Texture(pixmap));

    pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    pixmap.setColor(skin.getColor("transparent"));
    pixmap.fill();
    skin.add("transparent", new Texture(pixmap));

    pixmap = new Pixmap(8, 1, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add("white1x8", new Texture(pixmap));

    pixmap = new Pixmap(1, 8, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add("white8x1", new Texture(pixmap));

    pixmap = new Pixmap(32, 32, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add("white32s", new Texture(pixmap));
  }
示例#11
0
文件: GUI.java 项目: w4ll3/ppioo-1
  public static void configureSkin(Skin skin) {
    if (skin == null) {
      return;
    }

    loadResources(skin);
    loadLabels(skin);
    loadButtons(skin);

    ScrollPane.ScrollPaneStyle scrollPaneStyle = new ScrollPane.ScrollPaneStyle();
    scrollPaneStyle.background = skin.newDrawable("white", Color.BLACK);
    scrollPaneStyle.hScroll = skin.newDrawable("white8x1", Color.GRAY);
    scrollPaneStyle.hScrollKnob = skin.newDrawable("white8x1", Color.WHITE);
    scrollPaneStyle.vScroll = skin.newDrawable("white1x8", Color.GRAY);
    scrollPaneStyle.vScrollKnob = skin.newDrawable("white1x8", Color.WHITE);
    scrollPaneStyle.corner = skin.newDrawable("white", Color.GRAY);
    skin.add("default", scrollPaneStyle);

    CheckBox.CheckBoxStyle checkBoxStyle = new CheckBox.CheckBoxStyle();
    checkBoxStyle.font = skin.getFont("default");
    checkBoxStyle.fontColor = Color.BLACK;
    checkBoxStyle.checkboxOn = skin.getDrawable("checkbox.on");
    checkBoxStyle.checkboxOnDisabled = skin.getDrawable("checkbox.on.disabled");
    checkBoxStyle.checkboxOff = skin.getDrawable("checkbox.off");
    checkBoxStyle.checkboxOffDisabled = skin.getDrawable("checkbox.off.disabled");
    skin.add("default", checkBoxStyle);

    checkBoxStyle = new CheckBox.CheckBoxStyle();
    checkBoxStyle.font = skin.getFont("default");
    checkBoxStyle.fontColor = Color.BLACK;
    checkBoxStyle.checkboxOn = skin.getDrawable("checkbox.on.slider.horizontal");
    // checkBoxStyle.checkboxOnDisabled = skin.getDrawable("checkbox.on.disabled");
    checkBoxStyle.checkboxOff = skin.getDrawable("checkbox.off.slider.horizontal");
    // checkBoxStyle.checkboxOffDisabled = skin.getDrawable("checkbox.off.disabled");
    skin.add("slider.horizontal", checkBoxStyle);

    Window.WindowStyle dialogStyle = new Window.WindowStyle();
    dialogStyle.background = skin.newDrawable("window");
    dialogStyle.stageBackground = skin.newDrawable("white", Color.valueOf("00000080"));
    dialogStyle.titleFont = skin.getFont("medium");
    dialogStyle.titleFontColor = Color.BLACK;
    skin.add("default", dialogStyle);

    ImageButton.ImageButtonStyle upButtonStyle = new ImageButton.ImageButtonStyle();
    upButtonStyle.imageUp = skin.getDrawable("arrow.up");
    upButtonStyle.imageDown = skin.getDrawable("arrow.up");
    upButtonStyle.imageDisabled = skin.getDrawable("arrow.up.disabled");
    skin.add("arrow.up", upButtonStyle);

    ImageButton.ImageButtonStyle downButtonStyle = new ImageButton.ImageButtonStyle();
    downButtonStyle.imageUp = skin.getDrawable("arrow.down");
    downButtonStyle.imageDown = skin.getDrawable("arrow.down");
    downButtonStyle.imageDisabled = skin.getDrawable("arrow.down.disabled");
    skin.add("arrow.down", downButtonStyle);

    ImageButton.ImageButtonStyle radioButtonStyle = new ImageButton.ImageButtonStyle();
    radioButtonStyle.imageUp = skin.getDrawable("radiobutton.off");
    radioButtonStyle.imageOver = skin.getDrawable("radiobutton.off.over");
    radioButtonStyle.imageChecked = skin.getDrawable("radiobutton.on");
    radioButtonStyle.imageCheckedOver = skin.getDrawable("radiobutton.on.over");
    radioButtonStyle.imageDisabled = skin.getDrawable("radiobutton.disabled");
    skin.add("radiobutton", radioButtonStyle);
  }
示例#12
0
  @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);
          }
        });
  }
示例#13
0
  public MainMenuScreen(final SpaceLord2Game game, final ActionResolver resolver) {
    this.game = game;
    this.resolver = resolver;

    this.game.font = new BitmapFont();
    this.game.font.getData().scale(3);
    this.game
        .font
        .getRegion()
        .getTexture()
        .setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

    title = new Texture(Gdx.files.internal("space_lord_2_title.png"));

    backGround = new BackGround();

    table = new Table();
    table.defaults().width(600).padBottom(100);

    stage = new Stage(new FitViewport(GameConstants.GAME_WIDTH, GameConstants.GAME_HEIGHT));

    Gdx.input.setInputProcessor(stage);

    launchSound = Gdx.audio.newSound(Gdx.files.internal("sounds/space.mp3"));

    buttonClick = Gdx.audio.newSound(Gdx.files.internal("sounds/button_click.mp3"));

    skin = new Skin();
    skin.add("default", game.font);
    Pixmap pixmap = new Pixmap(100, 100, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.GRAY);
    pixmap.fill();
    skin.add("white", new Texture(pixmap));

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

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

    skin.add("default", textButtonStyle);

    // Create a button with the "default" TextButtonStyle. A 3rd parameter can be used to specify a
    // name other than "default".
    final TextButton playButton = new TextButton("Play", textButtonStyle);
    table.add(playButton);
    table.row();

    final TextButton leaderboardButton = new TextButton("Leaderboard", textButtonStyle);
    table.add(leaderboardButton);
    table.row();

    final TextButton achievementButton = new TextButton("Achievements", textButtonStyle);
    table.add(achievementButton);
    table.row();

    signInButton = new TextButton("Sign In", textButtonStyle);

    table.add(signInButton);
    table.row();

    table.setPosition(GameConstants.GAME_WIDTH / 3, (GameConstants.GAME_HEIGHT / 5) * 2);

    stage.addActor(table);

    playButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            buttonClick.play();
            game.setScreen(new SpaceLord2(game, resolver));
            dispose();
          }
        });

    leaderboardButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            resolver.showLeaderboard();
          }
        });

    achievementButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            resolver.showAchievements();
          }
        });

    signInButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            buttonClick.play();
            resolver.signIn();
          }
        });

    camera = new OrthographicCamera();
    viewport = new FitViewport(GameConstants.GAME_WIDTH, GameConstants.GAME_HEIGHT, camera);
    viewport.apply();
    camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0);
  }