Ejemplo n.º 1
0
  public MenuItem(Menu parentMenu, String text, Skin skin) {
    this.parentMenu = parentMenu;
    style = skin.get(MenuItemStyle.class);
    labelStyle = new LabelStyle();
    labelStyle.font = style.font;
    labelStyle.fontColor = style.fontColor;
    this.label = new Label(text, labelStyle);

    contextMenu = new ContextMenu(skin);
    contextMenu.setVisible(false);

    addActor(this.label);
    addActor(contextMenu);

    addListener(
        new ClickListener() {
          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (contextMenu.isVisible()) {
              MenuItem.this.parentMenu.selected(null, true);
            } else {
              MenuItem.this.parentMenu.selected(MenuItem.this, true);
            }
            event.stop();
            return false;
          }

          @Override
          public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
            MenuItem.this.parentMenu.selected(MenuItem.this, false);
          }
        });
  }
Ejemplo n.º 2
0
 public void addScore() {
   LabelStyle style = new LabelStyle();
   style.font =
       new BitmapFont(
           Gdx.files.internal("data/flappyfont.fnt"),
           Gdx.files.internal("data/flappyfont.png"),
           false);
   labelScore = new Label("0", style);
   labelScore.setPosition(
       Flappybird.VIEWPORT.x / 2 - labelScore.getWidth() / 2,
       Flappybird.VIEWPORT.y - labelScore.getHeight());
   stage.addActor(labelScore);
 }
Ejemplo n.º 3
0
 @Override
 public void setStyle(ButtonStyle style) {
   if (!(style instanceof MenuItemStyle))
     throw new IllegalArgumentException("style must be a MenuItemStyle.");
   super.setStyle(style);
   this.style = (MenuItemStyle) style;
   if (label != null) {
     TextButtonStyle textButtonStyle = (TextButtonStyle) style;
     LabelStyle labelStyle = label.getStyle();
     labelStyle.font = textButtonStyle.font;
     labelStyle.fontColor = textButtonStyle.fontColor;
     label.setStyle(labelStyle);
   }
 }
Ejemplo n.º 4
0
 public void setStyle(ButtonStyle style) {
   if (!(style instanceof ImageTextButtonStyle))
     throw new IllegalArgumentException("style must be a ImageTextButtonStyle.");
   super.setStyle(style);
   this.style = (ImageTextButtonStyle) style;
   if (image != null) updateImage();
   if (label != null) {
     ImageTextButtonStyle textButtonStyle = (ImageTextButtonStyle) style;
     LabelStyle labelStyle = label.getStyle();
     labelStyle.font = textButtonStyle.font;
     labelStyle.fontColor = textButtonStyle.fontColor;
     label.setStyle(labelStyle);
   }
 }
Ejemplo n.º 5
0
  @Override
  public void resize(int width, int height) {
    if (stage == null) {
      stage = new Stage(width, height, true);
    }
    stage.clear();

    Gdx.input.setInputProcessor(stage);

    TextButtonStyle butStyle = new TextButtonStyle();
    butStyle.up = butSkin.getDrawable("butdown");
    butStyle.down = butSkin.getDrawable("butup");
    butStyle.font = font1;

    LabelStyle labelStyle = new LabelStyle();
    labelStyle.font = font1;

    mainButton = new TextButton("Start Game!", butStyle);
    closeButton = new TextButton("Do nothing", butStyle);

    mainButton.setWidth(400);
    mainButton.setHeight(100);
    mainButton.setX(Gdx.graphics.getWidth() / 2 - mainButton.getWidth() / 2);
    mainButton.setY(Gdx.graphics.getHeight() / 2 - 2 * (mainButton.getHeight() / 1.2f));

    closeButton.setWidth(400);
    closeButton.setHeight(100);
    closeButton.setX(Gdx.graphics.getWidth() / 2 - closeButton.getWidth() / 2);
    closeButton.setY(
        Gdx.graphics.getHeight() / 2
            - 2 * (closeButton.getHeight() / 1.2f)
            - (closeButton.getHeight() + 5));

    mainButton.addListener(
        new InputListener() {
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("down");
            return true;
          }

          public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            golf.setCall(false); // disable splash screen after first use
            golf.setScreen(golf.hole, 1);
          }
        });

    stage.addActor(mainButton);
    stage.addActor(closeButton);
  }
Ejemplo n.º 6
0
  @Override
  public void create() {

    w = Gdx.graphics.getWidth();
    h = Gdx.graphics.getHeight();
    margin = 10;
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);

    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));

    FreeTypeFontGenerator generator =
        new FreeTypeFontGenerator(Gdx.files.internal("data/arial.ttf"));
    BitmapFont font15 = generator.generateFont(15);
    generator.dispose();

    LabelStyle lblStyle = new LabelStyle(skin.get(LabelStyle.class));
    lblStyle.font = font15;
    lblStyle.fontColor = Color.BLACK;
    lblStyle.background = null;

    LabelStyle lblOutStyle = new LabelStyle(skin.get(LabelStyle.class));
    lblOutStyle.font = font15;
    lblOutStyle.fontColor = Color.BLACK;
    lblOutStyle.background = new ColorDrawable(new HSV_Color(Color.WHITE));

    TextButtonStyle btnStyle = skin.get(TextButtonStyle.class);
    btnStyle.font = font15;
    btnStyle.fontColor = Color.BLACK;

    lblMsg = new Label(Msg, lblStyle);
    stage.addActor(lblMsg);

    lblOut = new Label("", lblOutStyle);
    // lblOut = new Label("", lblStyle);
    lblOut.setText(" ");
    stage.addActor(lblOut);

    btnRunLibGdx = new TextButton("", btnStyle);
    stage.addActor(btnRunLibGdx);

    btnRunTranslations = new TextButton("download and copy latest translations", btnStyle);
    btnRunTranslations.addListener(runListenerTranslations);
    stage.addActor(btnRunTranslations);

    btnRunTexturePacker = new TextButton("Pack and copy Texture Images", btnStyle);
    btnRunTexturePacker.addListener(runListenerTexture);
    stage.addActor(btnRunTexturePacker);

    TeePrintStream tee = new TeePrintStream(System.out);
    System.setOut(tee);

    chkSource();

    layout();
  }
Ejemplo n.º 7
0
  public OptionScreen(Anvil anvil) {
    super(anvil);

    Skin skin = new Skin(Gdx.files.internal(Systems.Skin));

    back = new Texture(Gdx.files.internal(Locale.SYSTEM_UI_PATH + "marble.png"));
    background = new Image(back);

    FreeTypeFontGenerator gen =
        new FreeTypeFontGenerator(Gdx.files.internal(Locale.FONT_BASE + "Canted Comic.ttf"));
    FreeTypeFontParameter par = new FreeTypeFontParameter();
    par.size = 20;
    par.borderColor = Color.BLACK;
    par.color = Color.WHITE;
    par.borderWidth = 2;
    BitmapFont font = gen.generateFont(par);

    LabelStyle ls = new LabelStyle();
    ls.font = font;

    CheckBox vsync = new CheckBox("VSync", skin);
    vsync.setChecked(getBool("Graphics", "useVsync"));
    vsync.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            bVsync = vsync.isChecked();
            vsync.setChecked(vsync.isChecked() ? false : true);
          }
        });

    Separator sep = new Separator();

    CheckBox controller = new CheckBox("Use Controller", skin);
    controller.setChecked(getBool("Controls", "useController"));
    controller.addListener(
        new ClickListener() {
          public void clicked(InputEvent event, float x, float y) {}
        });

    TextButton okay = new TextButton("Apply", skin);
    okay.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            save();
            anvil.setScreen(new MenuScreen(anvil));
          }
        });

    Table opt = new Table(skin);
    opt.setFillParent(true);
    opt.setBackground(background.getDrawable());

    opt.add(new Label("Graphics", ls)).row();
    opt.add(sep);
    opt.add(vsync).row();
    opt.add().row();
    opt.add().row();
    opt.add().row();

    opt.add(okay).align(Align.bottomLeft);

    stage.addActor(opt);
    Gdx.input.setInputProcessor(stage);
  }
Ejemplo n.º 8
0
 @Override
 public void setDisabled(boolean isDisabled) {
   this.disabled = isDisabled;
   labelStyle.fontColor =
       disabled && style.fontColorDisabled != null ? style.fontColorDisabled : style.fontColor;
 }
Ejemplo n.º 9
0
  @Override
  public void start() {
    super.start();
    if (this.type == FinalStage.TYPE_GAME_OVER) {
      StageScreen.getInstance().getTracker().trackScreen("gameOverScreen");
    } else {
      StageScreen.getInstance().getTracker().trackScreen("gameWinScreen");
    }
    this.music = Manager.getInstance().get(musicFile, Music.class);
    this.music.setVolume(Settings.getInstance().getMusicVolume());
    this.music.play();

    TextureAtlas atlas = Manager.getInstance().get("img/menu.pack", TextureAtlas.class);
    LabelStyle headerStyle = new LabelStyle();
    headerStyle.font = Config.getInstance().headerFont;
    headerStyle.fontColor = Config.getInstance().textColor;

    String labelText = (type == FinalStage.TYPE_GAME_OVER) ? "game.over" : "game.win";
    Label text = new Label(Translator.getInstance().translate(labelText), headerStyle);
    text.setBounds(
        50, 150, Config.getInstance().gameWidth - 100, Config.getInstance().gameHeight - 150);
    text.setAlignment(Align.center);
    text.setWrap(true);
    text.getColor().a = 0;
    text.addAction(fadeIn(2f));
    this.addActor(text);

    AtlasRegion btnBg = atlas.findRegion("btn-bg");
    AtlasRegion btnBgTouched = atlas.findRegion("btn-bg-touched");
    Color btnColor = new Color(1, 1, 1, 1);
    Color btnColorTouched = new Color(0.5f, 0.5f, 0.5f, 1);

    TextButton newGame =
        new TextButton(
            btnBg,
            btnBgTouched,
            Translator.getInstance().translate("btn.new.game"),
            Config.getInstance().bigFont,
            btnColor,
            btnColorTouched);
    newGame.setHeight(btnHeight);
    newGame.setPosition(50, 50);
    newGame.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            StageScreen.getInstance().setStage(new SlideStage(SlideStage.TYPE_INTRO));
          }
        });
    this.addActor(newGame);

    TextButton exit =
        new TextButton(
            btnBg,
            btnBgTouched,
            Translator.getInstance().translate("btn.exit"),
            Config.getInstance().bigFont,
            btnColor,
            btnColorTouched);
    exit.setHeight(btnHeight);
    exit.setPosition(Config.getInstance().gameWidth - exit.getWidth() - 50, 50);
    exit.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            StageScreen.getInstance().setStage(new MenuStage());
          }
        });
    this.addActor(exit);
  }