com.badlogic.gdx.scenes.scene2d.ui.Button Java Examples

The following examples show how to use com.badlogic.gdx.scenes.scene2d.ui.Button. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignInWindow.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override protected void doShow(String signInReasonKey) {
    Table content = new Table(Config.skin);
    content.setBackground("ui-store-window-background");
    content.defaults().pad(4);

    LocLabel label = new LocLabel(signInReasonKey);
    label.setWrap(true);
    label.setAlignment(Align.center);

    Button button = new Button(Config.skin);
    button.defaults().pad(2);
    button.add(new LocLabel("ui-sign-in")).padTop(1).padLeft(4).expand().right();
    button.add(new Tile("ui/button/services-icon")).padTop(4).padBottom(2).padRight(4).expand().left();
    button.addListener(new ChangeListener() {
        @Override public void changed(ChangeEvent event, Actor actor) {
            signIn = true;
            hide();
        }
    });

    content.add(label).width(130).row();
    content.add(button).width(70).padBottom(8);

    table.add(content);
}
 
Example #2
Source File: TabPanel.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
public void addTab(String name, Actor panel) {
	Button button = new TextButton(name, skin);
	buttonGroup.add(button);
	header.addActor(button);
	tabs.add(new Tab(button, panel));
	
	button.addListener(new ClickListener() {
		
		@Override
		public void clicked (InputEvent event, float x, float y) {
			setTab((Button)event.getListenerActor());
		}
	});
	
	if(tabs.size() == 1)
		setTab(0);
}
 
Example #3
Source File: TabPanel.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
public TabPanel(Skin skin) {
	super(skin);
	this.skin = skin;
	buttonGroup = new ButtonGroup<Button>();
	header = new HorizontalGroup();
	body = new Container<Actor>();
	tabs = new ArrayList<Tab>();
	
	buttonGroup.setMaxCheckCount(1);
	buttonGroup.setMinCheckCount(1);
	buttonGroup.setUncheckLast(true);
	
	header.wrap(true);
	header.rowAlign(Align.left);
	
	add(header).expandX().fillX().left();
	row();
	add(body).expand().fill();

	body.fill();
}
 
Example #4
Source File: PieMenu2.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
public PieMenu2(SceneScreen scr) {
	sceneScreen = scr;
	font = scr.getUI().getSkin().getFont("desc");
	buttons = new Button[NUM_VERBS];
	endPositions = new Vector2[NUM_VERBS];

	for (int i = 0; i < NUM_VERBS; i++) {
		buttons[i] = new Button(scr.getUI().getSkin(), "pie_lookat");
		endPositions[i] = new Vector2();
		addActor(buttons[i]);

		buttons[i].addListener(new ChangeListener() {
			@Override
			public void changed(ChangeEvent event, com.badlogic.gdx.scenes.scene2d.Actor actor) {
				if (iActor != null) {
					sceneScreen.runVerb(iActor, "lookat", null);
				}

				hide();
			}
		});
	}
}
 
Example #5
Source File: LobbyScreen.java    From riiablo with Apache License 2.0 6 votes vote down vote up
TabbedPane(TextureRegion defaultBackground) {
  background.setRegion(this.defaultBackground = defaultBackground);
  setBackground(background);
  buttons.setMinCheckCount(0);
  clickListener = new ClickListener() {
    @Override
    public void clicked(InputEvent event, float x, float y) {
      Button button = (Button) event.getListenerActor();
      TabGroup previous = getActor();
      TabGroup content = map.get(button.getName());
      setActor(content);
      setBackground(content.background);
      content.exited();
      content.entered();
    }
  };
}
 
Example #6
Source File: EventUtils.java    From riiablo with Apache License 2.0 6 votes vote down vote up
public static boolean click(Button button) {
  if (button.isDisabled()) return false;
  InputEvent event = Pools.obtain(InputEvent.class);
  event.setType(InputEvent.Type.touchDown);
  event.setStage(button.getStage());
  event.setStageX(0);
  event.setStageY(0);
  event.setPointer(0);
  event.setButton(Input.Buttons.LEFT);
  event.setListenerActor(button);
  button.fire(event);

  event.setType(InputEvent.Type.touchUp);
  button.fire(event);
  Pools.free(event);
  return true;
}
 
Example #7
Source File: ButtonBar.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
/**
 * Builds and returns {@link VisTable} containing buttons in platform dependant order. Note that calling this multiple
 * times will remove buttons from previous tables.
 */
public VisTable createTable () {
	VisTable table = new VisTable(true);

	table.left();

	boolean spacingValid = false;
	for (int i = 0; i < order.length(); i++) {
		char ch = order.charAt(i);

		if (ignoreSpacing == false && ch == ' ' && spacingValid) {
			table.add().width(sizes.buttonBarSpacing);
			spacingValid = false;
		}

		Button button = buttons.get(ch);

		if (button != null) {
			table.add(button);
			spacingValid = true;
		}
	}

	return table;
}
 
Example #8
Source File: DieSettingsWindow.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
private void updateChangeNameButton(Button button, Params params) {
    final Item coin = Config.items.get("coin");
    button.setDisabled(params.die.renames == 0 && params.userData.getItemCount(coin) == 0);
    button.clearChildren();
    if (params.die.renames == 0) {
        button.add(new LocLabel("ui-change-name-for")).padLeft(4);
        Image image = new Image(Config.skin, "item/coin");
        image.setScaling(Scaling.none);
        button.add(image).padTop(0).padBottom(-4);
        button.add("1").padRight(4);
    } else {
        button.add(new LocLabel("ui-change-name"));
    }
}
 
Example #9
Source File: TabPanel.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public void clear() {
	Array<Button> buttons = buttonGroup.getButtons();
	
	buttons.clear();		
	header.clear();
	tabs.clear();
	body.setActor(null);
	body.clear();
}
 
Example #10
Source File: TabPanel.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
private void setTab(Button b) {		
	for(int i = 0; i < tabs.size(); i++) {
		if(tabs.get(i).button == b) {
			setTab(i);
			break;
		}
	}
}
 
Example #11
Source File: LoadSaveScreen.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a button to represent one slot
 *
 * @param slot
 * @return The button to use for one slot
 */
private Button getSlotButton(String slot) {
	final Skin skin = ui.getSkin();
	final Button button = new Button(new ButtonStyle());
	final ButtonStyle style = button.getStyle();
	style.up = style.down = skin.getDrawable("black");

	String textLabel = ui.getWorld().getI18N().getString("ui.newSlot");
	button.setSize(slotWidth, slotHeight);

	if (slotExists(slot)) {
		button.add(getScreenshot(slot)).maxSize(slotWidth * .95f, slotHeight * .95f);

		try {
			long l = Long.parseLong(slot);

			Date d = new Date(l);
			textLabel = (new SimpleDateFormat()).format(d);
		} catch (Exception e) {
			textLabel = slot;
		}

		button.addListener(loadClickListener);
	} else {
		Image fg = new Image(skin.getDrawable("plus"));
		button.add(fg).maxSize(slotHeight / 2, slotHeight / 2);

		button.addListener(saveClickListener);
	}

	button.row();

	Label label = new Label(textLabel, skin);
	label.setAlignment(Align.center);

	button.add(label).fillX();

	button.setName(slot);
	return button;
}
 
Example #12
Source File: RetroSceneScreen.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void setUI(UI ui) {
	this.ui = ui;

	recorder = ui.getRecorder();
	testerBot = ui.getTesterBot();

	textManagerUI = new TextManagerUI(ui.getSkin(), getWorld());
	menuButton = new Button(ui.getSkin(), "menu");
	dialogUI = new DialogUI(ui.getSkin(), getWorld(), recorder);

	verbUI = new VerbUI(this);

	pointer = new Pointer(ui.getSkin());
}
 
Example #13
Source File: ButtonBar.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
public void setButton (ButtonType type, Button button, ChangeListener listener) {
	if (type == null) throw new IllegalArgumentException("type can't be null");
	if (button == null) throw new IllegalArgumentException("button can't be null");
	if (buttons.containsKey(type.id)) buttons.remove(type.id);
	buttons.put(type.id, button);
	if (listener != null) button.addListener(listener);
}
 
Example #14
Source File: MainListener.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public void customPropertyValueChanged(CustomProperty customProperty,
        Actor styleActor) {
    if (null != customProperty.getType()) switch (customProperty.getType()) {
        case DRAWABLE:
            dialogFactory.showDialogDrawables(customProperty, dialogListener);
            break;
        case COLOR:
            dialogFactory.showDialogColors(customProperty, dialogListener);
            break;
        case FONT:
            dialogFactory.showDialogFonts(customProperty, dialogListener);
            break;
        case NUMBER:
            main.getUndoableManager().addUndoable(new UndoableManager.CustomDoubleUndoable(main, customProperty, ((Spinner) styleActor).getValue()), false);
            break;
        case TEXT:
        case RAW_TEXT:
            main.getUndoableManager().addUndoable(new UndoableManager.CustomTextUndoable(main, customProperty, ((TextField) styleActor).getText()), false);
            break;
        case BOOL:
            main.getUndoableManager().addUndoable(new UndoableManager.CustomBoolUndoable(main, customProperty, ((Button) styleActor).isChecked()), false);
            break;
        case STYLE:
            dialogFactory.showDialogCustomStyleSelection(customProperty, dialogListener);
            break;
        default:
            break;
    }  
}
 
Example #15
Source File: OptionDialog.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
/**
 * This is improved version of {@link ButtonBar#createTable()} with customized layout.
 */
public VisTable createButtonTable() {
    String order = buttonBar.getOrder();
    boolean ignoreSpacing = buttonBar.isIgnoreSpacing();

    VisTable table = new VisTable(true);
    table.defaults().fillX().uniformX();
    table.right();

    boolean spacingValid = false;
    for (int i = 0; i < order.length(); i++) {
        char ch = order.charAt(i);

        if (ignoreSpacing == false && ch == ' ' && spacingValid) {
            table.add().width(4f);
            spacingValid = false;
        }

        ButtonBar.ButtonType buttonType = findButtonTypeForId(ch);
        if (buttonType == null) {
            continue;
        }

        Button button = buttonBar.getButton(buttonType);

        if (button != null) {
            ((VisTextButton)button).setFocusBorderEnabled(false);
            table.add(button);
            spacingValid = true;
        }
    }

    return table;
}
 
Example #16
Source File: MainController.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@LmlAction("onScalesBtnClick") void onScalesBtnClick(Button scalesButton) {
    if (!viewShown) return;

    PackModel pack = getSelectedPack();
    if (pack == null) return;

    scaleFactorsDialogController.setPackModel(pack);
    interfaceService.showDialog(scaleFactorsDialogController.getClass());
}
 
Example #17
Source File: ProcessingNodeListViewItem.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public void showLogWindow() {
        final String log = node.getLog();
        if (Strings.isEmpty(log)) return;

        VisDialog dialog = (VisDialog)App.inst().getInterfaceService().getParser().parseTemplate(Gdx.files.internal("lml/dialogPackingLog.lml")).first();
        Container containerLog = dialog.findActor("containerLog");
        final VisScrollPane scrLog = dialog.findActor("scrLog");
        final Button btnCopyToClipboard = dialog.findActor("btnCopyToClipboard");

        VisLabel lblLog = new VisLabel("", "small") {
//            @Override
//            protected void sizeChanged() {
//                super.sizeChanged();
//                // Scroll down scroller
//                scrLog.setScrollPercentY(1f);
//            }
        };
        lblLog.setAlignment(Align.topLeft);
        lblLog.setWrap(true);
        lblLog.setText(log);
        containerLog.setActor(lblLog);

        btnCopyToClipboard.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeEvent event, Actor actor) {
                Gdx.app.getClipboard().setContents(log);
            }
        });

        dialog.getTitleLabel().setText(App.inst().getI18n().format("dialogTitlePackLog", node.getPack().getName()));
        dialog.show(getStage());
        getStage().setScrollFocus(scrLog);
    }
 
Example #18
Source File: TabbedPane.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public TabbedPane() {
  clickListener = new ClickListener() {
    @Override
    public void clicked(InputEvent event, float x, float y) {
      Button button = (Button) event.getListenerActor();
      contentPanel.setActor(map.get(button.getName()));
      notifyTabSwitched(buttons.getChecked().getName(), button.getName());
    }
  };

  add(tabs = new VisTable()).growX().row();
  add(new Image(VisUI.getSkin().getDrawable("list-selection"))).growX().row();
  add(contentPanel = new Container<>()).align(Align.top).row();
}
 
Example #19
Source File: TrackListPanel.java    From gdx-soundboard with MIT License 4 votes vote down vote up
private void enableDisable(List<Track> trackList, Button add, Button remove){
    add.setDisabled(state == null);
    remove.setDisabled(trackList.getSelected() == null || trackList.getItems().size == 0);
}
 
Example #20
Source File: TabbedPane.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public TabbedPane (TabbedPaneStyle style, Sizes sizes) {
	this.style = style;
	this.sizes = sizes;
	listeners = new Array<TabbedPaneListener>();

	sharedCloseActiveButtonStyle = VisUI.getSkin().get("close-active-tab", VisImageButtonStyle.class);

	group = new ButtonGroup<Button>();

	mainTable = new TabbedPaneTable(this);
	tabsPane = new DragPane(style.vertical ? new VerticalFlowGroup() : new HorizontalFlowGroup());
	configureDragPane(style);

	mainTable.setBackground(style.background);

	tabs = new Array<Tab>();
	tabsButtonMap = new IdentityMap<Tab, TabButtonTable>();

	Cell<DragPane> tabsPaneCell = mainTable.add(tabsPane);
	Cell<Image> separatorCell = null;

	if (style.vertical) {
		tabsPaneCell.top().growY().minSize(0, 0);
	} else {
		tabsPaneCell.left().growX().minSize(0, 0);
	}

	//note: if separatorBar height/width is not set explicitly it may sometimes disappear
	if (style.separatorBar != null) {
		if (style.vertical) {
			separatorCell = mainTable.add(new Image(style.separatorBar)).growY().width(style.separatorBar.getMinWidth());
		} else {
			mainTable.row();
			separatorCell = mainTable.add(new Image(style.separatorBar)).growX().height(style.separatorBar.getMinHeight());
		}
	} else {
		//make sure that tab will fill available space even when there is no separatorBar image set
		if (style.vertical) {
			mainTable.add().growY();
		} else {
			mainTable.add().growX();
		}
	}

	mainTable.setPaneCells(tabsPaneCell, separatorCell);
}
 
Example #21
Source File: TransitionOutPanel.java    From gdx-soundboard with MIT License 4 votes vote down vote up
public Button getAddButton() {
    return add;
}
 
Example #22
Source File: TransitionInPanel.java    From gdx-soundboard with MIT License 4 votes vote down vote up
public Button getAddButton() {
    return add;
}
 
Example #23
Source File: TabPanel.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
public Tab(Button b, Actor c) {
	button = b;
	content = c;
}
 
Example #24
Source File: DefaultSceneScreen.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
public Button getMenuButton() {
	return menuButton;
}
 
Example #25
Source File: onScreenControls.java    From killingspree with MIT License 4 votes vote down vote up
public onScreenControls() {
    stage = new Stage();

    skin = new Skin();
    skin.add("buttonA", new Texture("controls/buttonA.png"));
    skin.add("buttonB", new Texture("controls/buttonB.png"));
    skin.add("buttonX", new Texture("controls/buttonX.png"));
    skin.add("buttonLeft", new Texture("controls/buttonLeft.png"));
    skin.add("buttonRight", new Texture("controls/buttonRight.png"));
    skin.add("buttonUp", new Texture("controls/buttonUp.png"));
    skin.add("closeButton", new Texture("controls/closeButton.png"));
    

    Drawable button;


    button = skin.getDrawable("buttonLeft");
    leftButton = new Button(button);
    leftButton.setColor(leftButton.getColor().r, leftButton.getColor().g,
            leftButton.getColor().b, leftButton.getColor().a / 5);
    
    button = skin.getDrawable("buttonRight");
    rightButton = new Button(button);
    rightButton.setColor(rightButton.getColor().r, rightButton.getColor().g,
            rightButton.getColor().b, rightButton.getColor().a / 5);
    
    button = skin.getDrawable("buttonUp");
    upButton = new Button(button);
    upButton.setColor(upButton.getColor().r, upButton.getColor().g,
            upButton.getColor().b, upButton.getColor().a / 5);
    
    button = skin.getDrawable("buttonA");
    jumpButton = new Button(button);
    jumpButton.setColor(jumpButton.getColor().r, jumpButton.getColor().g,
            jumpButton.getColor().b, jumpButton.getColor().a / 5);

    button = skin.getDrawable("buttonX");
    shootButton = new Button(button);
    shootButton.setColor(shootButton.getColor().r,
            shootButton.getColor().g, shootButton.getColor().b,
            shootButton.getColor().a / 5);

    button = skin.getDrawable("buttonB");
    throwBombButton = new Button(button);
    throwBombButton.setColor(throwBombButton.getColor().r,
            throwBombButton.getColor().g,
            throwBombButton.getColor().b,
            throwBombButton.getColor().a / 5);
    
    button = skin.getDrawable("closeButton");
    closeButton = new Button(button);
    closeButton.setColor(closeButton.getColor().r,
            closeButton.getColor().g,
            closeButton.getColor().b,
            closeButton.getColor().a / 5);

    this.stage.addActor(jumpButton);
    this.stage.addActor(shootButton);
    this.stage.addActor(throwBombButton);
    this.stage.addActor(closeButton);
    this.stage.addActor(upButton);
    this.stage.addActor(rightButton);
    this.stage.addActor(leftButton);
    Gdx.input.setInputProcessor(stage);
    resize();
}
 
Example #26
Source File: SimpleFormValidator.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
/** Validates if given button (usually checkbox) is checked. Use VisCheckBox to additionally support error border around it. */
public void checked (Button button, String errorMsg) {
	buttons.add(new CheckedButtonWrapper(button, true, errorMsg));
	button.addListener(changeListener);
	validate();
}
 
Example #27
Source File: SimpleFormValidator.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
/** Validates if given button (usually checkbox) is unchecked. Use VisCheckBox to additionally support error border around it. */
public void unchecked (Button button, String errorMsg) {
	buttons.add(new CheckedButtonWrapper(button, false, errorMsg));
	button.addListener(changeListener);
	validate();
}
 
Example #28
Source File: ButtonBar.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public Button getButton (ButtonType type) {
	return buttons.get(type.getId());
}
 
Example #29
Source File: SimpleFormValidator.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public CheckedButtonWrapper (Button button, boolean mustBeChecked, String errorMsg) {
	this.button = button;
	this.mustBeChecked = mustBeChecked;
	this.errorMsg = errorMsg;
}
 
Example #30
Source File: ButtonBar.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public void setButton (ButtonType type, Button button) {
	setButton(type, button, null);
}