private void initButtons() { buttonTexture = new Texture("buttons/button.png"); downButtonTexture = new Texture("buttons/button-down.png"); ImageTextButton.ImageTextButtonStyle style = new ImageTextButton.ImageTextButtonStyle(); style.font = buttonFont; style.up = new SpriteDrawable(new Sprite(buttonTexture)); style.down = new SpriteDrawable(new Sprite(downButtonTexture)); startButton = new ImageTextButton(" Iniciar ", style); stage.addActor(startButton); startButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { // Evento do botão game.setScreen(new GameScreen(game)); } }); }
/** * Erstellt einen ImageTextButtonStyle anhand eines Button Stils. * * @param color * Der Button Stil * @return Das ImageTextButtonStyle Objekt */ private static ImageTextButtonStyle getImageButtonStyle( final ButtonColor color) { Drawable drawable = new TextureRegionDrawable( AssetManager.getTextureRegion("ui", color.getFileName())); ImageTextButtonStyle imageButtonStyle = new ImageTextButton.ImageTextButtonStyle(); imageButtonStyle.down = drawable; imageButtonStyle.up = drawable; imageButtonStyle.font = AssetManager.getTextFont(color.getFontSize()); imageButtonStyle.fontColor = color.getFontColor(); return imageButtonStyle; }
/** * Fügt einen neuen Button für ein Spiel hinzu. * * @param gameObject * Spiel Infos. */ private void addGameButton(final GameObject gameObject) { ImageTextButton imgTextButton = new ButtonLarge(gameObject.getGameTitle(), ButtonColor.LIGHT_BROWN); imgTextButton.addListener(new ChangeListener() { public void changed(final ChangeEvent event, final Actor actor) { Gdx.app.log("DEBUG", "Spiel " + gameObject.getGameTitle() + " soll gestartet werden"); GameManagerFactory.getInstance().navigateToLevel(gameObject.getLevelID()); } }); verticalGroup.addActor(imgTextButton); imgTextButton.setPosition(this.width / 2 - imgTextButton.getWidth() / 2, lastButtonY); lastButtonY = (int) (lastButtonY - imgTextButton.getHeight()); stage.addActor(imgTextButton); imgTextButton.toFront(); }
/** * Erzeugt den LadeButtonText. */ private void createButton() { Drawable drawable = new TextureRegionDrawable((new TextureRegion(new Texture( Gdx.files.internal("splashscreen/buttonBackground.png"))))); FreeTypeFontGenerator gen = new FreeTypeFontGenerator( Gdx.files.internal("fonts/textfont/Grundschrift-Bold.ttf")); FreeTypeFontParameter frontPara = new FreeTypeFontParameter(); frontPara.size = 40; BitmapFont b = gen.generateFont(frontPara); gen.dispose(); ImageTextButtonStyle imageButtonStyle = new ImageTextButton.ImageTextButtonStyle(); imageButtonStyle.down = drawable; imageButtonStyle.up = drawable; imageButtonStyle.font = b; imageButtonStyle.fontColor = Color.valueOf("877E6A"); textContent = new ImageTextButton("Lade... : ", imageButtonStyle); }
public UserPanel(int x, int y, int width, int height) { super(x, y, width, height); userlevelButton = new ImageTextButton("" + GDefence.getInstance().user.getLevel(), GDefence.getInstance().assetLoader.getUserLevelSkin()); //userlevelButton.getLabel().setFontScale(1.5f); int userLevelSize[] = {width/4, width/4}; //userlevelButton.setSize(userLevelSize[0], userLevelSize[1]); //userlevelButton.setPosition(); // userlevelButton.addListener(new InputListener() { // public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { // return true; // } // } // ); int expBarSize[] = {width, height - userLevelSize[1]}; ExpBar bar = new ExpBar(expBarSize[0], expBarSize[1]); //add(new GoldPanel(mainClass)).width(width/6*2).height(height); add(userlevelButton).width(userLevelSize[0]).height(userLevelSize[1]).row(); add(bar); //System.out.println(getY()); }
@Override public void process(final LmlParser parser, final LmlTag tag, final ImageTextButton actor, final String rawAttributeData) { final ImageTextButtonStyle style = new ImageTextButtonStyle(actor.getStyle()); style.imageUp = parser.getData().getDefaultSkin().getDrawable(parser.parseString(rawAttributeData, actor)); actor.setStyle(style); }
@Override protected void handlePlainTextLine(final String plainTextLine) { final ImageTextButton button = (ImageTextButton) getActor(); final String textToAppend = getParser().parseString(plainTextLine, getActor()); if (Strings.isEmpty(button.getText())) { button.setText(textToAppend); } else { if (LmlUtilities.isMultiline(button)) { button.setText(button.getText().toString() + '\n' + textToAppend); } else { button.setText(button.getText().toString() + textToAppend); } } }
/** * erstelle drei Buttons(vor, zurück und ok) setze jeweils die Größe und die * Position fest. srufe die Methode addListener(...) auf füge alle drei in * die erste Stage * */ private void createButtons() { ButtonSmall buttonNext = new ButtonSmall(ButtonType.RIGHT); ButtonSmall buttonPrev = new ButtonSmall(ButtonType.LEFT); Drawable buttonImg = new TextureRegionDrawable( AssetManager.getTextureRegion("ui", "panel_brown")); this.buttonOk = new ButtonOwnTextImage("OK", new ImageTextButton.ImageTextButtonStyle( new TextButton.TextButtonStyle(buttonImg, buttonImg, buttonImg, AssetManager.getTextFont(FontSize.FORTY)))); buttonOk.setHeight(80); buttonOk.setWidth(300); buttonNext.setPosition(width - buttonNext.getWidth() - 5, height / 2); buttonPrev.setPosition(5, height / 2); buttonOk.setPosition(myXPos + myWidth / 2 - buttonOk.getWidth() / 2, myYPos + myHeight + 5); blinc(buttonOk); buttonNext.setName("next"); buttonPrev.setName("prev"); buttonPrev.setName("ok"); addListener(buttonNext, buttonOk, buttonPrev); firststage.addActor(buttonNext); firststage.addActor(buttonPrev); firststage.addActor(buttonOk); }
/** * Erstellt die Buttons. */ private void initButtons() { buttonsSpiel = new ImageTextButton[3]; Map<Integer, String> games = SaveGameManager.getSaveGameList(); Iterator<Integer> gamesIterator = games.keySet().iterator(); ImageTextButton buttonSpiel; String buttonText; int gameID = 0; for (int i = 0; i < 3; i++) { if (gamesIterator.hasNext()) { gameID = gamesIterator.next(); buttonText = games.get(gameID); } else { gameID = (games.containsKey(i)) ? 2 * i : i; buttonText = "Neue Spielerin"; } buttonSpiel = new ButtonLarge(buttonText, ButtonLarge.ButtonColor.LIGHT_BROWN); table.addActor(buttonSpiel); buttonSpiel.toFront(); addButtonSpielListener(buttonSpiel, gameID); buttonsSpiel[i] = buttonSpiel; } // der Credits-Button buttonCredits = new ButtonLarge("Credits", ButtonLarge.ButtonColor.LIGHT_BROWN); table.addActor(buttonCredits); buttonCredits.toFront(); }
private void showCharacterDialog() { Dialog dialog = new Dialog("", skin); Label label = new Label("Choose a character...", skin); dialog.getContentTable().add(label); dialog.getContentTable().row(); Table table = new Table(); ScrollPane scrollPane = new ScrollPane(table, skin); scrollPane.setFadeScrollBars(false); dialog.getContentTable().add(scrollPane).grow(); final ButtonGroup<ImageTextButton> buttons = new ButtonGroup<ImageTextButton>(); for (String name : getCore().getImagePacks().get(DATA_PATH + "/characters")) { Drawable drawable = new TextureRegionDrawable(getCore().getAtlas().findRegion(name)); Image image = new Image(drawable); ImageTextButton imageTextButton = new ImageTextButton(name, skin, "list"); imageTextButton.getImageCell().setActor(image); imageTextButton.getLabelCell().left().expandX(); table.add(imageTextButton).growX(); buttons.add(imageTextButton); table.row(); } dialog.getContentTable().row(); TextButton textButton = new TextButton("OK", skin); dialog.getContentTable().add(textButton); textButton.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { getCore().getAssetManager().get(Core.DATA_PATH + "/sfx/coin.wav", Sound.class).play(); ((GameState)getCore().getStateManager().getState("game")).setSelectedCharacter(buttons.getChecked().getText().toString()); Gdx.input.setInputProcessor(null); Action changeStateAction = new Action() { @Override public boolean act(float delta) { getCore().getStateManager().loadState("game"); return true; } }; root.addAction(new SequenceAction(new DelayAction(.5f), changeStateAction)); } }); dialog.show(stage); dialog.setSize(400.0f, 400.0f); dialog.setPosition(stage.getWidth() / 2.0f, stage.getHeight() / 2.0f, Align.center); stage.setScrollFocus(scrollPane); }
public void resetProperties() { properties.clear(); if (clazz.equals(Button.class)) { newStyleProperties(ButtonStyle.class); } else if (clazz.equals(CheckBox.class)) { newStyleProperties(CheckBoxStyle.class); properties.get("checkboxOn").optional = false; properties.get("checkboxOff").optional = false; properties.get("font").optional = false; } else if (clazz.equals(ImageButton.class)) { newStyleProperties(ImageButtonStyle.class); } else if (clazz.equals(ImageTextButton.class)) { newStyleProperties(ImageTextButtonStyle.class); properties.get("font").optional = false; } else if (clazz.equals(Label.class)) { newStyleProperties(LabelStyle.class); properties.get("font").optional = false; } else if (clazz.equals(List.class)) { newStyleProperties(ListStyle.class); properties.get("font").optional = false; properties.get("fontColorSelected").optional = false; properties.get("fontColorUnselected").optional = false; properties.get("selection").optional = false; } else if (clazz.equals(ProgressBar.class)) { newStyleProperties(ProgressBarStyle.class); //Though specified as optional in the doc, there are bugs without "background" being mandatory properties.get("background").optional = false; } else if (clazz.equals(ScrollPane.class)) { newStyleProperties(ScrollPaneStyle.class); } else if (clazz.equals(SelectBox.class)) { newStyleProperties(SelectBoxStyle.class); properties.get("font").optional = false; properties.get("fontColor").optional = false; properties.get("scrollStyle").optional = false; properties.get("scrollStyle").value = "default"; properties.get("listStyle").optional = false; properties.get("listStyle").value = "default"; } else if (clazz.equals(Slider.class)) { newStyleProperties(SliderStyle.class); //Though specified as optional in the doc, there are bugs without "background" being mandatory properties.get("background").optional = false; } else if (clazz.equals(SplitPane.class)) { newStyleProperties(SplitPaneStyle.class); properties.get("handle").optional = false; } else if (clazz.equals(TextButton.class)) { newStyleProperties(TextButtonStyle.class); properties.get("font").optional = false; } else if (clazz.equals(TextField.class)) { newStyleProperties(TextFieldStyle.class); properties.get("font").optional = false; properties.get("fontColor").optional = false; } else if (clazz.equals(TextTooltip.class)) { newStyleProperties(TextTooltipStyle.class); properties.get("label").optional = false; properties.get("label").value = "default"; } else if (clazz.equals(Touchpad.class)) { newStyleProperties(TouchpadStyle.class); } else if (clazz.equals(Tree.class)) { newStyleProperties(TreeStyle.class); properties.get("plus").optional = false; properties.get("minus").optional = false; } else if (clazz.equals(Window.class)) { newStyleProperties(WindowStyle.class); properties.get("titleFont").optional = false; } }
@Override public Class<ImageTextButton> getHandledType() { return ImageTextButton.class; }
@Override protected Actor getNewInstanceOfActor(final LmlActorBuilder builder) { final TextLmlActorBuilder textBuilder = (TextLmlActorBuilder) builder; return new ImageTextButton(textBuilder.getText(), getSkin(builder), builder.getStyleName()); }
@Override protected Actor[] getComponentActors(final Actor actor) { final ImageTextButton button = (ImageTextButton) actor; return new Actor[] { button.getImage(), button.getLabel() }; }
/** * Diese Methode erzeugt einen Button. * * @param label * Button Text * @param inputListener * {@link ChangeListener} um auf den Button Klick zu reagieren * @return button */ private ImageTextButton createButton(final String label, final ChangeListener inputListener) { ImageTextButton btn = new ButtonLarge(label, inputListener); btn.addListener(inputListener); this.addActor(btn); return btn; }
/** * Diese Methode ermöglicht das erstellen ein Standart Button. Dieses Button * wird zurückgegeben und kann weiter Verändert werden. Es wird z.b. ein * Standart Image gesetzt. * * @param text * Button Text * @return {@link ImageTextButton} */ protected ImageTextButton createButton(final String text) { return new ButtonLarge(text); }
/** * Fügt einen Listener zu dem Button. * * @param button * . * @param saveGameID * . */ private void addButtonSpielListener(final ImageTextButton button, final int saveGameID) { button.addListener(new SavegameButtonListener(saveGameID, overlay)); }