Java Code Examples for com.badlogic.gdx.scenes.scene2d.Stage#setKeyboardFocus()

The following examples show how to use com.badlogic.gdx.scenes.scene2d.Stage#setKeyboardFocus() . 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: MainMenuScreen.java    From xibalba with MIT License 6 votes vote down vote up
/**
 * Main Menu Screen.
 *
 * @param main Instance of main class
 */
public MainMenuScreen(Main main) {
  stage = new Stage(new FitViewport(960, 540));

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

  ActionButton newGameButton = new ActionButton("N", "New Game");
  newGameButton.setKeys(Input.Keys.N);
  newGameButton.setAction(table, () -> main.setScreen(new YouScreen(main)));

  ActionButton quitButton = new ActionButton("Q", "Quit");
  quitButton.setKeys(Input.Keys.Q);
  quitButton.setAction(table, () -> Gdx.app.exit());

  table.add(new Label("[LIGHT_GRAY]Xibalba v0.1.0[]", Main.skin)).pad(0, 0, 10, 0);
  table.row();

  table.add(newGameButton).pad(0, 0, 10, 0);
  table.row();
  table.add(quitButton);

  Gdx.input.setInputProcessor(stage);
  stage.setKeyboardFocus(table);
}
 
Example 2
Source File: Dialog.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
/** {@link #pack() Packs} the dialog and adds it to the stage, centered. */
public Dialog show (Stage stage) {
	clearActions();
	removeCaptureListener(ignoreTouchDown);

	previousKeyboardFocus = null;
	Actor actor = stage.getKeyboardFocus();
	if (actor != null && !actor.isDescendantOf(this)) previousKeyboardFocus = actor;

	previousScrollFocus = null;
	actor = stage.getScrollFocus();
	if (actor != null && !actor.isDescendantOf(this)) previousScrollFocus = actor;

	// pack();
	setPosition(Math.round((stage.getWidth() - getWidth()) / 2), Math.round((stage.getHeight() - getHeight()) / 2));
	stage.addActor(this);
	stage.setKeyboardFocus(this);
	stage.setScrollFocus(this);
	if (fadeDuration > 0) {
		getColor().a = 0;
		addAction(Actions.fadeIn(fadeDuration, Interpolation.fade));
	}
	return this;
}
 
Example 3
Source File: Dialog.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
/** Hides the dialog. Called automatically when a button is clicked. The default implementation fades out the dialog over
 * {@link #fadeDuration} seconds and then removes it from the stage. */
public void hide () {
	Stage stage = getStage();
	if (stage != null) {
		if (previousKeyboardFocus != null && previousKeyboardFocus.getStage() == null) previousKeyboardFocus = null;
		Actor actor = stage.getKeyboardFocus();
		if (actor == null || actor.isDescendantOf(this)) stage.setKeyboardFocus(previousKeyboardFocus);

		if (previousScrollFocus != null && previousScrollFocus.getStage() == null) previousScrollFocus = null;
		actor = stage.getScrollFocus();
		if (actor == null || actor.isDescendantOf(this)) stage.setScrollFocus(previousScrollFocus);
	}
	if (fadeDuration > 0) {
		addCaptureListener(ignoreTouchDown);
		addAction(sequence(fadeOut(fadeDuration, Interpolation.fade), Actions.removeListener(ignoreTouchDown, true),
			Actions.removeActor()));
	} else
		remove();
}
 
Example 4
Source File: PauseScreen.java    From xibalba with MIT License 5 votes vote down vote up
/**
 * Main Menu Screen.
 *
 * @param main Instance of main class
 */
public PauseScreen(Main main) {
  stage = new Stage(new FitViewport(960, 540));

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

  ActionButton returnToGameButton = new ActionButton("ESC", "Return to Game");
  returnToGameButton.setKeys(Input.Keys.ESCAPE);
  returnToGameButton.setAction(table, () -> main.setScreen(Main.playScreen));

  ActionButton mainMenuButton = new ActionButton("M", "Main Menu");
  mainMenuButton.setKeys(Input.Keys.M);
  mainMenuButton.setAction(table, () -> {
    Main.playScreen.dispose();
    main.setScreen(new MainMenuScreen(main));
  });

  ActionButton quitButton = new ActionButton("Q", "Quit");
  quitButton.setKeys(Input.Keys.Q);
  quitButton.setAction(table, () -> Gdx.app.exit());

  table.add(new Label("[LIGHT_GRAY]PAUSED[]", Main.skin)).pad(0, 0, 10, 0);
  table.row();
  table.add(returnToGameButton).pad(0, 0, 10, 0);
  table.row();
  table.add(mainMenuButton).pad(0, 0, 10, 0);
  table.row();
  table.add(quitButton);

  Gdx.input.setInputProcessor(stage);
  stage.setKeyboardFocus(table);
}
 
Example 5
Source File: FileChooser.java    From gdx-soundboard with MIT License 5 votes vote down vote up
@Override
public Dialog show(Stage stage, Action action) {
    final Table content = getContentTable();
    content.add(fileListLabel).top().left().expandX().fillX().row();
    content.add(new ScrollPane(fileList, skin)).size(300, 150).fill().expand().row();

    if (fileNameEnabled) {
        content.add(fileNameLabel).fillX().expandX().row();
        content.add(fileNameInput).fillX().expandX().row();
        stage.setKeyboardFocus(fileNameInput);
    }

    if (newFolderEnabled) {
        content.add(newFolderButton).fillX().expandX().row();
    }
    
    if(directoryBrowsingEnabled){
        fileList.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                final FileListItem selected = fileList.getSelected();
                if (selected.file.isDirectory()) {
                    changeDirectory(selected.file);
                }
            }
        });
    }

    this.stage = stage;
    changeDirectory(baseDir);
    return super.show(stage, action);
}
 
Example 6
Source File: DialogCustomProperty.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public Dialog show(Stage stage) {
    Dialog dialog = super.show(stage);
    
    stage.setKeyboardFocus(nameField);
    
    return dialog;
}
 
Example 7
Source File: FocusManager.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/**
 * Takes focus from current focused widget (if any), and sets focus to provided widget
 * @param stage if passed stage is not null then stage keyboard focus will be set to null
 * @param widget that will acquire focus
 */
public static void switchFocus (Stage stage, Focusable widget) {
	if (focusedWidget == widget) return;
	if (focusedWidget != null) focusedWidget.focusLost();
	focusedWidget = null;
	if (stage != null) stage.setKeyboardFocus(null);
	focusedWidget = widget;
	focusedWidget.focusGained();
}
 
Example 8
Source File: MenuBarX.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public void setCurrentMenu(Menu newMenu) {
    super.setCurrentMenu(newMenu);

    Stage stage = mainTable.getStage();
    if (newMenu != null) {
        stage.setKeyboardFocus(mainTable);
    } else {
        stage.setKeyboardFocus(null);
    }
}
 
Example 9
Source File: FilteredSelectBox.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
public void show(Stage stage) {
	if (list.isTouchable())
		return;

	stage.removeCaptureListener(hideListener);
	stage.addCaptureListener(hideListener);
	stage.addActor(this);
	stage.addActor(filterField);

	selectBox.localToStageCoordinates(screenPosition.set(0, 0));

	// Show the list above or below the select box, limited to a number of items and
	// the available height in the stage.
	float itemHeight = list.getItemHeight();
	float height = itemHeight
			* (maxListCount <= 0 ? selectBox.items.size : Math.min(maxListCount, selectBox.items.size));
	Drawable scrollPaneBackground = getStyle().background;
	if (scrollPaneBackground != null)
		height += scrollPaneBackground.getTopHeight() + scrollPaneBackground.getBottomHeight();
	Drawable listBackground = list.getStyle().background;
	if (listBackground != null)
		height += listBackground.getTopHeight() + listBackground.getBottomHeight();

	float heightBelow = screenPosition.y - itemHeight;
	float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight();
	boolean below = true;
	if (height > heightBelow) {
		if (heightAbove > heightBelow) {
			below = false;
			height = Math.min(height, heightAbove);
		} else
			height = heightBelow;
	}

	if (below)
		setY(screenPosition.y - height);
	else
		setY(screenPosition.y + selectBox.getHeight());
	setX(screenPosition.x);
	setHeight(height);
	validate();
	float width = Math.max(getPrefWidth(), selectBox.getWidth());
	if (getPrefHeight() > height && !isScrollingDisabledY())
		width += getScrollBarWidth();
	setWidth(width);

	filterField.setX(getX());
	filterField.setWidth(getWidth());
	filterField.setHeight(filterField.getPrefHeight());
	filterField.setY(getY() + getHeight() - filterField.getHeight());
	stage.setKeyboardFocus(filterField);
	filterField.validate();
	setY(getY() - filterField.getHeight());

	validate();
	scrollTo(0, list.getHeight() - selectBox.getSelectedIndex() * itemHeight - itemHeight / 2, 0, 0, true,
			true);
	updateVisualScroll();

	previousScrollFocus = null;
	Actor actor = stage.getScrollFocus();
	if (actor != null && !actor.isDescendantOf(this))
		previousScrollFocus = actor;
	stage.setScrollFocus(this);

	list.getSelection().set(selectBox.getSelected());
	list.setTouchable(Touchable.enabled);
	clearActions();
	selectBox.onShow(this, below);

	filterField.setText("");
	setListItems(items.toArray());
}
 
Example 10
Source File: HudRenderer.java    From xibalba with MIT License 4 votes vote down vote up
/**
 * Renders the HUD.
 *
 * @param main  Instance of Main class
 * @param batch The sprite batch to use (set in PlayScreen)
 */
public HudRenderer(Main main, SpriteBatch batch) {
  this.main = main;

  viewport = new FitViewport(960, 540, new OrthographicCamera());
  stage = new Stage(viewport, batch);

  player = WorldManager.player;
  playerDetails = ComponentMappers.player.get(player);
  playerAttributes = ComponentMappers.attributes.get(player);
  playerPosition = ComponentMappers.position.get(player);
  god = ComponentMappers.god.get(WorldManager.god);

  Table topTable = new Table();
  topTable.top().left();
  topTable.setFillParent(true);
  stage.addActor(topTable);

  playerInfo = new VerticalGroup().top().left().columnLeft();
  enemyInfo = new VerticalGroup().top().center().columnCenter();
  gameInfo = new VerticalGroup().top().right().columnRight();

  int width = Gdx.graphics.getWidth() / 3 - 20;

  topTable.add(playerInfo).pad(10, 10, 10, 10).width(width).top();
  topTable.add(enemyInfo).pad(10, 10, 10, 10).width(width).top();
  topTable.add(gameInfo).pad(10, 10, 10, 10).width(width).top();

  bottomTable = new Table();
  bottomTable.bottom().left();
  bottomTable.setFillParent(true);
  stage.addActor(bottomTable);

  actionLog = new VerticalGroup().top().left().columnLeft();
  focusedTable = new Table().top().center();
  buttonsAndAreaDetails = new VerticalGroup().top().right().columnRight();

  areaDetails = new VerticalGroup().top().right().columnRight().pad(0, 0, 5, 0);
  buttonsAndAreaDetails.addActor(areaDetails);

  menuButtons = new Table().right();
  setupMenuButtons();

  bottomTable.add(actionLog).pad(10, 10, 10, 10).width(width).bottom();
  bottomTable.add(focusedTable).pad(10, 10, 10, 10).width(width).top();
  bottomTable.add(buttonsAndAreaDetails).pad(10, 10, 10, 10).width(width).bottom();

  setupDeathDialog();

  stage.setKeyboardFocus(bottomTable);
}
 
Example 11
Source File: Editor.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void create() {

	if (EditorLogger.debugMode()) {
		EngineLogger.setDebug();
	}

	Gdx.graphics.setWindowedMode(Math.max((int) (Gdx.graphics.getDisplayMode().width * 0.9), 1920 / 2),
			Math.max((int) (Gdx.graphics.getDisplayMode().height * 0.9), 1080 / 2));

	skin = new BladeSkin(Gdx.files.internal(SKIN));
	VisUI.load();
	FileChooser.setDefaultPrefsName("com.bladecoder.engineeditor.filechooser");

	/*** STAGE SETUP ***/
	stage = new Stage(new ScreenViewport());
	Gdx.input.setInputProcessor(stage);

	setCtx();

	Message.init(skin);

	scnEditor = new ScnEditor(skin);
	scnEditor.setBackground("background");
	skin.getFont("default-font").getData().markupEnabled = true;

	// RIGHT PANEL
	ScenePanel scenePanel = new ScenePanel(skin);
	ActorPanel actorPanel = new ActorPanel(skin);

	Table rightPanel = new Table(skin);
	rightPanel.top().left();
	rightPanel.add(actorPanel).expand().fill().left();
	rightPanel.setBackground("background");

	SplitPane splitPaneRight = new SplitPane(scnEditor, rightPanel, false, skin);

	splitPaneRight.setSplitAmount(0.75f);

	// LEFT PANEL
	ProjectPanel projectPanel = new ProjectPanel(skin);
	Image img = new Image(Ctx.assetManager.getIcon("title"));
	img.setScaling(Scaling.none);
	img.setAlign(Align.left);

	Table leftPanel = new Table(skin);
	leftPanel.top().left().padLeft(10);
	leftPanel.add(img).expand().fill().padBottom(20).padTop(20).padLeft(0).left();
	leftPanel.row();
	leftPanel.add(new ProjectToolbar(skin)).expandX().fill().left();
	leftPanel.row();
	leftPanel.add(projectPanel).expand().fill().left();
	leftPanel.row();
	leftPanel.add(scenePanel).expand().fill().left();
	leftPanel.setBackground("background");

	SplitPane splitPaneLeft = new SplitPane(leftPanel, splitPaneRight, false, skin);
	splitPaneLeft.setFillParent(true);
	splitPaneLeft.setSplitAmount(0.25f);
	stage.addActor(splitPaneLeft);

	// LOAD LAST OPEN PROJECT
	String lastProject = Ctx.project.getEditorConfig().getProperty(Project.LAST_PROJECT_PROP, "");
	final File lastProjectFile = new File(lastProject);

	if (!lastProject.isEmpty() && lastProjectFile.exists()) {
		EditorLogger.debug("Loading previous project: " + lastProject);

		try {
			EditorUtils.checkVersionAndLoadProject(lastProjectFile, stage, skin);
		} catch (Exception e) {
			EditorLogger.error("Error loading previous project.", e);
			Ctx.project.closeProject();
		}
	}

	stage.setScrollFocus(scnEditor.getScnWidget());
	stage.setKeyboardFocus(scnEditor.getScnWidget());

	// TooltipManager.getInstance().instant();
	TooltipManager.getInstance().initialTime = 0.2f;
	TooltipManager.getInstance().hideAll();
	TooltipManager.getInstance().subsequentTime = 0.2f;
}
 
Example 12
Source File: FocusManager.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
/**
 * Takes focus from current focused widget (if any), and sets current focused widget to null
 * @param stage if passed stage is not null then stage keyboard focus will be set to null only if current
 * focus owner is passed actor
 */
public static void resetFocus (Stage stage, Actor caller) {
	if (focusedWidget != null) focusedWidget.focusLost();
	if (stage != null && stage.getKeyboardFocus() == caller) stage.setKeyboardFocus(null);
	focusedWidget = null;
}
 
Example 13
Source File: DialogFactory.java    From skin-composer with MIT License 4 votes vote down vote up
public void showCustomDrawableDialog(Skin skin, Stage stage, DrawableData modifyDrawable, CustomDrawableListener customDrawableListener) {
    final TextField textField = new TextField("", skin);
    Dialog dialog = new Dialog("New Custom Drawable", skin, "bg") {
        @Override
        protected void result(Object object) {
            if ((Boolean) object) {
                customDrawableListener.run(textField.getText());
            }
        }
    };
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("OK", true).button("Cancel", false);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    final TextButton okButton = (TextButton) dialog.getButtonTable().getCells().get(0).getActor();

    textField.setTextFieldListener((TextField textField1, char c) -> {
        if (c == '\n') {
            if (!okButton.isDisabled()) {
                customDrawableListener.run(textField.getText());
                
                dialog.hide();
            }
            main.getStage().setKeyboardFocus(textField1);
        }
    });

    textField.addListener(main.getIbeamListener());
    if (modifyDrawable != null) {
        textField.setText(modifyDrawable.name);
    }

    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    if (modifyDrawable == null) {
        dialog.text("Enter the name for the custom drawable.\nUse to reference custom classes that inherit from Drawable.");
    } else {
        dialog.text("Enter the new name for the custom drawable.\nUse to reference custom classes that inherit from Drawable.");
    }
    ((Label)dialog.getContentTable().getCells().first().getActor()).setAlignment(Align.center);
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getContentTable().row();
    dialog.getContentTable().add(textField).growX();
    okButton.setDisabled(true);

    textField.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !StyleData.validate(textField.getText());

            if (main.getAtlasData().getDrawable(textField.getText()) != null) {
                disable = true;
            }

            okButton.setDisabled(disable);
        }
    });

    dialog.key(Input.Keys.ESCAPE, false);

    dialog.show(stage);
    stage.setKeyboardFocus(textField);
    textField.selectAll();
    textField.setFocusTraversal(false);
}
 
Example 14
Source File: DialogFactory.java    From skin-composer with MIT License 4 votes vote down vote up
public void showRenameStyleDialog(Skin skin, Stage stage) {
    Class selectedClass = main.getRootTable().getSelectedClass();

    final TextField textField = new TextField(main.getRootTable().getSelectedStyle().name, skin);
    Dialog dialog = new Dialog("Rename Style", skin, "bg") {
        @Override
        protected void result(Object object) {
            if ((Boolean) object) {
                main.getUndoableManager().addUndoable(new UndoableManager.RenameStyleUndoable(main.getRootTable().getSelectedStyle(), main, textField.getText()), true);
            }
        }
    };
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("OK", true).button("Cancel", false);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    final TextButton okButton = (TextButton) dialog.getButtonTable().getCells().get(0).getActor();

    textField.setTextFieldListener((TextField textField1, char c) -> {
        if (c == '\n') {
            if (!okButton.isDisabled()) {
                main.getUndoableManager().addUndoable(new UndoableManager.RenameStyleUndoable(main.getRootTable().getSelectedStyle(), main, textField1.getText()), true);
                dialog.hide();
            }
            main.getStage().setKeyboardFocus(textField1);
        }
    });

    textField.addListener(main.getIbeamListener());

    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    dialog.text("What would you like to rename the style \"" + main.getRootTable().getSelectedStyle().name + "\" to?");
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getContentTable().row();
    dialog.getContentTable().add(textField).growX();
    okButton.setDisabled(true);

    Array<StyleData> currentStyles = main.getProjectData().getJsonData().getClassStyleMap().get(selectedClass);
    textField.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !StyleData.validate(textField.getText());

            if (!disable) {
                for (StyleData data : currentStyles) {
                    if (data.name.equals(textField.getText())) {
                        disable = true;
                        break;
                    }
                }
            }

            okButton.setDisabled(disable);
        }
    });

    dialog.key(Input.Keys.ESCAPE, false);

    dialog.show(stage);
    stage.setKeyboardFocus(textField);
    textField.selectAll();
    textField.setFocusTraversal(false);
}
 
Example 15
Source File: DialogFactory.java    From skin-composer with MIT License 4 votes vote down vote up
public void showDuplicateStyleDialog(Skin skin, Stage stage) {
    Class selectedClass = main.getRootTable().getSelectedClass();
    StyleData originalStyle = main.getRootTable().getSelectedStyle();

    final TextField textField = new TextField("", skin);
    Dialog dialog = new Dialog("Duplicate Style", skin, "bg") {
        @Override
        protected void result(Object object) {
            if ((Boolean) object) {
                main.getUndoableManager().addUndoable(new DuplicateStyleUndoable(originalStyle, textField.getText(), main), true);
            }
        }
    };

    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("OK", true).button("Cancel", false);
    final TextButton okButton = (TextButton) dialog.getButtonTable().getCells().get(0).getActor();
    okButton.addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());

    textField.setTextFieldListener((TextField textField1, char c) -> {
        if (c == '\n') {
            if (!okButton.isDisabled()) {
                main.getUndoableManager().addUndoable(new DuplicateStyleUndoable(originalStyle, textField.getText(), main), true);
                dialog.hide();
            }
            main.getStage().setKeyboardFocus(textField1);
        }
    });

    textField.addListener(main.getIbeamListener());

    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    dialog.text("What is the name of the new, duplicated style?");
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getContentTable().row();
    dialog.getContentTable().add(textField).growX();
    okButton.setDisabled(true);

    Array<StyleData> currentStyles = main.getProjectData().getJsonData().getClassStyleMap().get(selectedClass);
    textField.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !StyleData.validate(textField.getText());

            if (!disable) {
                for (StyleData data : currentStyles) {
                    if (data.name.equals(textField.getText())) {
                        disable = true;
                        break;
                    }
                }
            }

            okButton.setDisabled(disable);
        }
    });

    dialog.key(Input.Keys.ESCAPE, false);

    dialog.show(stage);
    stage.setKeyboardFocus(textField);

    textField.setFocusTraversal(false);
}
 
Example 16
Source File: DialogFactory.java    From skin-composer with MIT License 4 votes vote down vote up
public void showNewStyleDialog(Skin skin, Stage stage) {
    Class selectedClass = main.getRootTable().getSelectedClass();

    final TextField textField = new TextField("", skin);
    Dialog dialog = new Dialog("New Style", skin, "bg") {
        @Override
        protected void result(Object object) {
            if ((Boolean) object) {
                main.getUndoableManager().addUndoable(new NewStyleUndoable(selectedClass, textField.getText(), main), true);
            }
        }
    };
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("OK", true).button("Cancel", false);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    final TextButton okButton = (TextButton) dialog.getButtonTable().getCells().get(0).getActor();

    textField.setTextFieldListener((TextField textField1, char c) -> {
        if (c == '\n') {
            if (!okButton.isDisabled()) {
                main.getUndoableManager().addUndoable(new NewStyleUndoable(selectedClass, textField1.getText(), main), true);
                dialog.hide();
            }
            main.getStage().setKeyboardFocus(textField1);
        }
    });

    textField.addListener(main.getIbeamListener());

    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    dialog.text("What is the name of the new style?");
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getContentTable().row();
    dialog.getContentTable().add(textField).growX();
    okButton.setDisabled(true);

    Array<StyleData> currentStyles = main.getProjectData().getJsonData().getClassStyleMap().get(selectedClass);
    textField.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !StyleData.validate(textField.getText());

            if (!disable) {
                for (StyleData data : currentStyles) {
                    if (data.name.equals(textField.getText())) {
                        disable = true;
                        break;
                    }
                }
            }

            okButton.setDisabled(disable);
        }
    });

    dialog.key(Input.Keys.ESCAPE, false);

    dialog.show(stage);
    stage.setKeyboardFocus(textField);
    textField.setFocusTraversal(false);
}
 
Example 17
Source File: CraftScreen.java    From xibalba with MIT License 4 votes vote down vote up
/**
 * Craft screen.
 *
 * @param main Instance of Main
 */
public CraftScreen(Main main) {
  stage = new Stage(new FitViewport(960, 540));

  Constructor constructor = new Constructor(ItemData.class);
  constructor.addTypeDescription(new TypeDescription(Bleed.class, "!Bleed"));
  constructor.addTypeDescription(new TypeDescription(Charm.class, "!Charm"));
  constructor.addTypeDescription(new TypeDescription(DealDamage.class, "!DealDamage"));
  constructor.addTypeDescription(new TypeDescription(Poison.class, "!Poison"));
  constructor.addTypeDescription(new TypeDescription(RaiseHealth.class, "!RaiseHealth"));
  constructor.addTypeDescription(new TypeDescription(StartFire.class, "!StartFire"));
  TypeDescription itemDescription = new TypeDescription(ItemData.class);
  itemDescription.putListPropertyType("requiredComponent", ItemRequiredComponentData.class);
  constructor.addTypeDescription(itemDescription);
  Yaml yaml = new Yaml(constructor);
  recipes = new HashMap<>();

  for (Map.Entry<String, String> entry : Main.itemsData.entrySet()) {
    ItemData data = (ItemData) yaml.load(entry.getValue());

    if (data.requiredComponents != null) {
      recipes.put(entry.getKey(), data);
    }
  }

  table = new Table();
  table.setFillParent(true);
  table.left().top();
  stage.addActor(table);

  Table titleTable = new Table();

  HorizontalGroup titleGroup = new HorizontalGroup();
  titleGroup.space(10);
  titleTable.add(titleGroup).pad(10).width(Gdx.graphics.getWidth() - 20);

  ActionButton closeButton = new ActionButton("Q", null);
  closeButton.setKeys(Input.Keys.Q);
  closeButton.setAction(table, () -> main.setScreen(Main.playScreen));
  titleGroup.addActor(closeButton);

  Label title = new Label("Craft", Main.skin);
  titleGroup.addActor(title);

  recipeGroup = new VerticalGroup().top().left().columnLeft();

  Table craftTable = new Table();
  craftTable.add(recipeGroup).pad(10).top().left().width(Gdx.graphics.getWidth() / 2);

  table.add(titleTable);
  table.row();
  table.add(craftTable).left();

  setupRecipes();

  Gdx.input.setInputProcessor(stage);
  stage.setKeyboardFocus(table);
}
 
Example 18
Source File: NameScreen.java    From xibalba with MIT License 4 votes vote down vote up
/**
 * Character Creation: Review Screen.
 *
 * @param main Instance of main class
 */
public NameScreen(Main main, PlayerSetup playerSetup) {
  this.main = main;
  this.playerSetup = playerSetup;

  stage = new Stage(new FitViewport(960, 540));
  worldSeed = System.currentTimeMillis();

  Table table = new Table();
  table.setFillParent(true);
  table.left().top();
  table.pad(10);
  stage.addActor(table);

  ActionButton backButton = new ActionButton("Q", "Back");
  backButton.setKeys(Input.Keys.Q);
  backButton.setAction(table, () -> main.setScreen(new YouScreen(main)));
  table.add(backButton).pad(0, 0, 10, 0).left();

  table.row();

  Label worldSeedLabel = new Label("World Seed", Main.skin);
  table.add(worldSeedLabel).pad(0, 0, 10, 0).width(Gdx.graphics.getWidth() / 2);
  table.row();
  worldSeedField = new TextField(worldSeed + "", Main.skin);
  table.add(worldSeedField).pad(0, 0, 10, 0).width(Gdx.graphics.getWidth() / 2);

  table.row();
  Label playerNameLabel = new Label("Name", Main.skin);
  table.add(playerNameLabel).pad(0, 0, 10, 0).width(Gdx.graphics.getWidth() / 2);
  table.row();
  playerNameField = new TextField(playerSetup.name, Main.skin);
  table.add(playerNameField).pad(0, 0, 10, 0).width(Gdx.graphics.getWidth() / 2);

  table.row();
  Label playerColorLabel = new Label("Color", Main.skin);
  table.add(playerColorLabel).pad(0, 0, 10, 0).width(Gdx.graphics.getWidth() / 2);
  table.row();
  playerColorField = new TextField(playerSetup.color, Main.skin);
  playerColorField.setMaxLength(6);
  table.add(playerColorField).pad(0, 0, 10, 0).width(Gdx.graphics.getWidth() / 2);

  ActionButton continueButton = new ActionButton("ENTER", "Begin Your Journey");
  continueButton.setKeys(Input.Keys.ENTER);
  continueButton.setAction(table, this::startGame);

  table.row();
  table.add(continueButton).left();

  Gdx.input.setInputProcessor(stage);
  stage.setKeyboardFocus(table);
}
 
Example 19
Source File: AbilitiesScreen.java    From xibalba with MIT License 4 votes vote down vote up
/**
 * View and use your abilities.
 *
 * @param main Instance of Main
 */
public AbilitiesScreen(Main main) {
  this.main = main;

  abilities = ComponentMappers.abilities.get(WorldManager.player).abilities;
  playerDetails = ComponentMappers.player.get(WorldManager.player);

  stage = new Stage(new FitViewport(960, 540));

  table = new Table();
  table.setFillParent(true);
  table.left().top();
  stage.addActor(table);

  Table titleTable = new Table();

  HorizontalGroup titleGroup = new HorizontalGroup();
  titleGroup.space(10);
  titleTable.add(titleGroup).pad(10).width(Gdx.graphics.getWidth() - 20);

  ActionButton closeButton = new ActionButton("Q", null);
  closeButton.setKeys(Input.Keys.Q);
  closeButton.setAction(table, () -> main.setScreen(Main.playScreen));
  titleGroup.addActor(closeButton);

  Label title = new Label("Abilities", Main.skin);
  titleGroup.addActor(title);

  abilitiesGroup = new VerticalGroup().top().left().columnLeft();

  Table abilitiesTable = new Table();
  abilitiesTable.add(abilitiesGroup).pad(10).top().left().width(Gdx.graphics.getWidth() / 2);

  table.add(titleTable);
  table.row();
  table.add(abilitiesTable).left();

  setupAbilities();

  Gdx.input.setInputProcessor(stage);
  stage.setKeyboardFocus(table);
}
 
Example 20
Source File: NewFileDialog.java    From gdx-soundboard with MIT License 4 votes vote down vote up
@Override
public Dialog show(Stage stage, Action action) {
    super.show(stage, action);
    stage.setKeyboardFocus(fileName);
    return this;
}