List of usage examples for com.badlogic.gdx.scenes.scene2d.ui VerticalGroup VerticalGroup
public VerticalGroup()
From source file:com.agateau.ui.UiBuilder.java
License:Apache License
protected VerticalGroup createVerticalGroup(XmlReader.Element element) { VerticalGroup group = new VerticalGroup(); group.space(element.getFloatAttribute("spacing", 0)); int align = parseAlign(element); if (align != -1) { group.align(align);/*from ww w .j av a 2 s .co m*/ } return group; }
From source file:com.bladecoder.engineeditor.ui.DialogOptionTree.java
License:Apache License
private Node createNode(Element e) { Label textLbl = new Label(null, skin); Label infoLbl = new Label(null, skin); String text = e.getAttribute("text"); textLbl.setText(Ctx.project.getSelectedChapter().getTranslation(text)); StringBuilder sb = new StringBuilder(); // if(!actor.isEmpty()) // sb.append(" actor '").append(actor).append("'"); NamedNodeMap attr = e.getAttributes(); String response = e.getAttribute("response_text"); if (!response.isEmpty()) sb.append("R: ").append(Ctx.project.getSelectedChapter().getTranslation(response)).append(' '); for (int i = 0; i < attr.getLength(); i++) { org.w3c.dom.Node n = attr.item(i); String name = n.getNodeName(); if (name.equals("text") || name.equals("response_text")) continue; String v = n.getNodeValue(); sb.append(name).append(':').append(Ctx.project.getSelectedChapter().getTranslation(v)).append(' '); }// w ww.j av a 2s . c om infoLbl.setText(sb.toString()); VerticalGroup vg = new VerticalGroup(); vg.left(); vg.addActor(textLbl); vg.addActor(infoLbl); Node node = new Node(vg); node.setObject(e); NodeList childs = e.getChildNodes(); int n = childs.getLength(); for (int i = 0; i < n; i++) { if (childs.item(i) instanceof Element) { node.add(createNode((Element) childs.item(i))); } } return node; }
From source file:com.eightpuzzle.game.EightPuzzle.java
License:Apache License
@Override public void create() { gameFont = new BitmapFont(); solvedFont = new BitmapFont(); batch = new SpriteBatch(); aspectRatio = (float) Gdx.graphics.getHeight() / (float) Gdx.graphics.getWidth(); OrthographicCamera camera = new OrthographicCamera(GAME_WIDTH * aspectRatio, GAME_HEIGHT * aspectRatio); //camera.position.set(GAME_WIDTH/2, GAME_HEIGHT/2, 0) camera.setToOrtho(false, GAME_WIDTH * aspectRatio, GAME_HEIGHT * aspectRatio); //camera.setToOrtho(false,GAME_WIDTH,GAME_HEIGHT); stage = new Stage(new ExtendViewport(GAME_WIDTH * aspectRatio, GAME_HEIGHT * aspectRatio, camera));//Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera)); Gdx.input.setInputProcessor(stage);/*from ww w .j a v a 2 s . c o m*/ // A skin can be loaded via JSON or defined programmatically, either is fine. Using a skin is optional but strongly // recommended solely for the convenience of getting a texture, region, etc as a drawable, tinted drawable, etc. skin = new Skin(); // Generate a 1x1 white texture and store it in the skin named "white". Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888); pixmap.setColor(Color.WHITE); pixmap.fill(); skin.add("white", new Texture(pixmap)); // Store the default libgdx font under the name "default". skin.add("default", new BitmapFont()); // 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); Label.LabelStyle labelSty = new Label.LabelStyle(); labelSty.font = skin.getFont("default"); //labelSty.fontColor = Color.GREEN; skin.add("default", labelSty); WindowStyle ws = new Window.WindowStyle(); ws.titleFont = new BitmapFont(); ws.background = skin.newDrawable("white", Color.BLACK); skin.add("default", ws); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/Zig.ttf")); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); parameter.size = 25; gameFont = generator.generateFont(parameter); FreeTypeFontParameter parameter2 = new FreeTypeFontParameter(); parameter2.size = 100; parameter2.color = Color.GREEN; solvedFont = generator.generateFont(parameter2); generator.dispose(); FileHandle blue, n1, n2, n3, n4, n5, n6, n7, n8, solveUp, solveDown; if (Gdx.app.getType() == ApplicationType.Desktop) { blue = Gdx.files.internal("icons64px/blue-square.png"); n1 = Gdx.files.internal("icons64px/Number-1-icon.png"); n2 = Gdx.files.internal("icons64px/Number-2-icon.png"); n3 = Gdx.files.internal("icons64px/Number-3-icon.png"); n4 = Gdx.files.internal("icons64px/Number-4-icon.png"); n5 = Gdx.files.internal("icons64px/Number-5-icon.png"); n6 = Gdx.files.internal("icons64px/Number-6-icon.png"); n7 = Gdx.files.internal("icons64px/Number-7-icon.png"); n8 = Gdx.files.internal("icons64px/Number-8-icon.png"); solveUp = blue; solveDown = blue; } else { blue = Gdx.files.internal("icons256px/blue-circle.png"); n1 = Gdx.files.internal("icons256px/Number-1-icon.png"); n2 = Gdx.files.internal("icons256px/Number-2-icon.png"); n3 = Gdx.files.internal("icons256px/Number-3-icon.png"); n4 = Gdx.files.internal("icons256px/Number-4-icon.png"); n5 = Gdx.files.internal("icons256px/Number-5-icon.png"); n6 = Gdx.files.internal("icons256px/Number-6-icon.png"); n7 = Gdx.files.internal("icons256px/Number-7-icon.png"); n8 = Gdx.files.internal("icons256px/Number-8-icon.png"); solveUp = Gdx.files.internal("icons256px/Box_Green.png"); solveDown = Gdx.files.internal("icons256px/rectangle_green.png"); } Texture bSquare = new Texture(blue); Texture n1T = new Texture(n1); Texture n2T = new Texture(n2); Texture n3T = new Texture(n3); Texture n4T = new Texture(n4); Texture n5T = new Texture(n5); Texture n6T = new Texture(n6); Texture n7T = new Texture(n7); Texture n8T = new Texture(n8); TextureRegion bSquareReg = new TextureRegion(bSquare); TextureRegion n1Reg = new TextureRegion(n1T); TextureRegion n2Reg = new TextureRegion(n2T); TextureRegion n3Reg = new TextureRegion(n3T); TextureRegion n4Reg = new TextureRegion(n4T); TextureRegion n5Reg = new TextureRegion(n5T); TextureRegion n6Reg = new TextureRegion(n6T); TextureRegion n7Reg = new TextureRegion(n7T); TextureRegion n8Reg = new TextureRegion(n8T); TextureRegionDrawable solveDUp = new TextureRegionDrawable(new TextureRegion(new Texture(solveUp))); TextureRegionDrawable solveDDown = new TextureRegionDrawable(new TextureRegion(new Texture(solveDown))); ImageTextButton.ImageTextButtonStyle tbSty = new ImageTextButton.ImageTextButtonStyle(solveDUp, solveDDown, solveDUp, gameFont); skin.add("default", tbSty); ImageButtonStyle bSquareSty = new ImageButtonStyle(); bSquareSty.imageUp = new TextureRegionDrawable(bSquareReg); bSquareSty.imageDown = new TextureRegionDrawable(bSquareReg); ImageButtonStyle n1Sty = new ImageButtonStyle(); n1Sty.imageUp = new TextureRegionDrawable(n1Reg); n1Sty.imageDown = new TextureRegionDrawable(n1Reg); ImageButtonStyle n2Sty = new ImageButtonStyle(); n2Sty.imageUp = new TextureRegionDrawable(n2Reg); n2Sty.imageDown = new TextureRegionDrawable(n2Reg); ImageButtonStyle n3Sty = new ImageButtonStyle(); n3Sty.imageUp = new TextureRegionDrawable(n3Reg); n3Sty.imageDown = new TextureRegionDrawable(n3Reg); ImageButtonStyle n4Sty = new ImageButtonStyle(); n4Sty.imageUp = new TextureRegionDrawable(n4Reg); n4Sty.imageDown = new TextureRegionDrawable(n4Reg); ImageButtonStyle n5Sty = new ImageButtonStyle(); n5Sty.imageUp = new TextureRegionDrawable(n5Reg); n5Sty.imageDown = new TextureRegionDrawable(n5Reg); ImageButtonStyle n6Sty = new ImageButtonStyle(); n6Sty.imageUp = new TextureRegionDrawable(n6Reg); n6Sty.imageDown = new TextureRegionDrawable(n6Reg); ImageButtonStyle n7Sty = new ImageButtonStyle(); n7Sty.imageUp = new TextureRegionDrawable(n7Reg); n7Sty.imageDown = new TextureRegionDrawable(n7Reg); ImageButtonStyle n8Sty = new ImageButtonStyle(); n8Sty.imageUp = new TextureRegionDrawable(n8Reg); n8Sty.imageDown = new TextureRegionDrawable(n8Reg); ImageButton b1 = new ImageButton(n1Sty); b1.addListener(new MyChangeListener(1)); map.put(1, b1); ImageButton holeB = new ImageButton(bSquareSty); map.put(0, holeB); ImageButton ib = new ImageButton(n2Sty); ib.addListener(new MyChangeListener(2)); map.put(2, ib); ImageButton b4 = new ImageButton(n3Sty); b4.addListener(new MyChangeListener(3)); ImageButton b5 = new ImageButton(n4Sty); b5.addListener(new MyChangeListener(4)); ImageButton b6 = new ImageButton(n5Sty); b6.addListener(new MyChangeListener(5)); map.put(3, b4); map.put(4, b5); map.put(5, b6); ImageButton b7 = new ImageButton(n6Sty); b7.addListener(new MyChangeListener(6)); ImageButton b8 = new ImageButton(n7Sty); b8.addListener(new MyChangeListener(7)); ImageButton b9 = new ImageButton(n8Sty); b9.addListener(new MyChangeListener(8)); map.put(6, b7); map.put(7, b8); map.put(8, b9); newGameB = new ImageTextButton("New Game", skin); newGameB.addListener(new NewGameListener()); solveB = new ImageTextButton("Solve", skin); solveB.addListener(new MySolveListener()); newGameBoard(); //table.padTop(50); //table.padBottom(20); VerticalGroup vg = new VerticalGroup(); //vg.padTop(50); vg.setFillParent(true); vg.addActor(newGameB); vg.addActor(table); vg.addActor(solveB); stage.addActor(vg); }
From source file:com.forerunnergames.peril.client.ui.screens.menus.modes.classic.creategame.ClassicGameModeCreateGameMenuScreen.java
License:Open Source License
public ClassicGameModeCreateGameMenuScreen(final MenuScreenWidgetFactory widgetFactory, final ScreenChanger screenChanger, final ScreenSize screenSize, final MouseInput mouseInput, final Batch batch, final CountryCounter countryCounter, final MBassador<Event> eventBus) { super(widgetFactory, screenChanger, screenSize, mouseInput, batch, eventBus); Arguments.checkIsNotNull(widgetFactory, "widgetFactory"); Arguments.checkIsNotNull(countryCounter, "countryCounter"); this.widgetFactory = widgetFactory; this.countryCounter = countryCounter; errorDialog = createErrorDialog();/*w w w. j av a 2s . c o m*/ addTitle(TITLE_TEXT, Align.bottomLeft, 40); addSubTitle(SUBTITLE_TEXT); playerNameTextField = widgetFactory.createPlayerNameTextField(); clanAcronymTextField = widgetFactory.createClanAcronymTextField(); serverNameTextField = widgetFactory.createServerNameTextField(); clanAcronymCheckBox = widgetFactory.createClanAcronymCheckBox(new ChangeListener() { @Override public void changed(final ChangeEvent event, final Actor actor) { clanAcronymTextField.setText(clanAcronymCheckBox.isChecked() ? clanAcronymTextField.getText() : ""); clanAcronymTextField.setDisabled(!clanAcronymCheckBox.isChecked()); } }); clanAcronymCheckBox.setChecked(!clanAcronymTextField.getText().isEmpty()); clanAcronymTextField.setDisabled(!clanAcronymCheckBox.isChecked()); // @formatter:off humanPlayerLimitLabel = widgetFactory .createPlayerLimitLabel(String.valueOf(InputSettings.INITIAL_CLASSIC_MODE_HUMAN_PLAYER_LIMIT)); aiPlayerLimitLabel = widgetFactory .createPlayerLimitLabel(String.valueOf(InputSettings.INITIAL_CLASSIC_MODE_AI_PLAYER_LIMIT)); playMapNameLabel = widgetFactory.createPlayMapNameLabel(); totalCountryCount = calculateCurrentPlayMapTotalCountryCount(); // @formatter:on customizeHumanPlayersButton = widgetFactory .createCustomizePlayersButton(new ClickListener(Input.Buttons.LEFT) { @Override public void clicked(final InputEvent event, final float x, final float y) { // TODO Show Players Dialog. updateHumanPlayerLimit(); updateWinPercentSelectBoxItems(); } }); customizeAiPlayersButton = widgetFactory .createCustomizePlayersButton(new ClickListener(Input.Buttons.LEFT) { @Override public void clicked(final InputEvent event, final float x, final float y) { // TODO Show Players Dialog. updateAiPlayerLimit(); updateWinPercentSelectBoxItems(); } }); customizePlayMapButton = widgetFactory.createCustomizePlayMapButton(new ClickListener(Input.Buttons.LEFT) { @Override public void clicked(final InputEvent event, final float x, final float y) { // TODO Show Play Map Dialog. // TODO Add refresh button to Play Map Dialog to re-load play maps. playMaps = loadPlayMaps(); currentPlayMap = nextPlayMap(); playMapNameLabel.setText(currentPlayMap.getName()); totalCountryCount = calculateCurrentPlayMapTotalCountryCount(); updateWinPercentSelectBoxItems(); } }); // @formatter:off spectatorLimitSelectBox = widgetFactory.createSpectatorsSelectBox(); final Array<Integer> spectatorLimits = new Array<>( ClassicGameRules.MAX_SPECTATORS - ClassicGameRules.MIN_SPECTATORS + 1); for (int i = ClassicGameRules.MIN_SPECTATORS; i <= ClassicGameRules.MAX_SPECTATORS; ++i) { spectatorLimits.add(i); } spectatorLimitSelectBox.setItems(spectatorLimits); spectatorLimitSelectBox.setSelected(InputSettings.INITIAL_SPECTATOR_LIMIT); // @formatter:off // @formatter:on initialCountryAssignmentSelectBox = widgetFactory.createInitialCountryAssignmentSelectBox(); final Array<String> initialCountryAssignments = new Array<>(InitialCountryAssignment.count()); for (final InitialCountryAssignment initialCountryAssignment : InitialCountryAssignment.values()) { initialCountryAssignments.add(Strings.toProperCase(initialCountryAssignment.name())); } initialCountryAssignmentSelectBox.setItems(initialCountryAssignments); initialCountryAssignmentSelectBox .setSelected(Strings.toProperCase(InputSettings.INITIAL_CLASSIC_MODE_COUNTRY_ASSIGNMENT.name())); // @formatter:on winPercentSelectBox = widgetFactory.createWinPercentSelectBox(); updateWinPercentSelectBoxItems(); selectInitialWinPercentItem(); // @formatter:off playerSettingsSectionTitleLabel = widgetFactory.createPlayerSettingsSectionTitleLabel(); playerNameSettingLabel = widgetFactory.createPlayerNameSettingLabel(); clanTagSettingLabel = widgetFactory.createClanTagSettingLabel(); gameSettingsSectionTitleLabel = widgetFactory.createGameSettingsSectionTitleLabel(); serverNameSettingLabel = widgetFactory.createMenuSettingLabel(SERVER_NAME_SETTING_LABEL_TEXT); humanPlayerLimitSettingLabel = widgetFactory.createMenuSettingLabel(HUMAN_PLAYERS_SETTING_LABEL_TEXT); aiPlayerLimitSettingLabel = widgetFactory.createMenuSettingLabel(AI_PLAYERS_SETTING_LABEL_TEXT); spectatorLimitSettingLabel = widgetFactory.createMenuSettingLabel(SPECTATORS_SETTING_SETTING_LABEL_TEXT); playMapSettingLabel = widgetFactory.createMenuSettingLabel(PLAY_MAP_SETTING_LABEL_TEXT); winPercentSettingLabel = widgetFactory.createMenuSettingLabel(WIN_PERCENT_SETTING_LABEL_TEXT); initialCountryAssignmentSettingLabel = widgetFactory .createMenuSettingLabel(INITIAL_COUNTRY_ASSIGNMENT_SETTING_LABEL_TEXT); // @formatter:on final VerticalGroup verticalGroup = new VerticalGroup(); verticalGroup.align(Align.topLeft); final Table playerSettingsTable = new Table().top().left(); playerSettingsTable.add().height(23); playerSettingsTable.row(); playerSettingsTable.add(playerSettingsSectionTitleLabel).size(540, 40).fill().padLeft(60).left(); playerSettingsTable.row(); final Table playerNameTable = new Table(); playerNameTable.add(playerNameSettingLabel).size(150, 40).fill().padLeft(90).left().spaceRight(10); playerNameTable.add(playerNameTextField).size(270, 28).fill().left().spaceLeft(10); playerSettingsTable.add(playerNameTable).left(); playerSettingsTable.row(); final Table clanTable = new Table(); clanTable.add(clanTagSettingLabel).size(150, 40).fill().padLeft(90).left().spaceRight(10); clanTable.add(clanAcronymCheckBox).size(20, 20).fill().left().spaceLeft(10).spaceRight(8); clanTable.add(clanAcronymTextField).size(80, 28).fill().left().spaceLeft(8); playerSettingsTable.add(clanTable).left(); verticalGroup.addActor(playerSettingsTable); final Table gameSettingsTable = new Table().top().left(); gameSettingsTable.row(); gameSettingsTable.add().height(20); gameSettingsTable.row(); gameSettingsTable.add(gameSettingsSectionTitleLabel).size(540, 40).fill().padLeft(60).left(); gameSettingsTable.row(); final Table serverNameTable = new Table(); serverNameTable.add(serverNameSettingLabel).size(150, 40).fill().padLeft(90).left().spaceRight(10); serverNameTable.add(serverNameTextField).size(270, 28).fill().left().spaceLeft(10); gameSettingsTable.add(serverNameTable).left(); gameSettingsTable.row(); final Table playMapTable = new Table(); playMapTable.add(playMapSettingLabel).size(150, 40).fill().padLeft(90).left().spaceRight(10); playMapTable.add(playMapNameLabel).size(238, 28).fill().left().spaceLeft(10).spaceRight(4); playMapTable.add(customizePlayMapButton).size(28, 28).fill().left().spaceLeft(4); gameSettingsTable.add(playMapTable).left(); gameSettingsTable.row(); final Table humanPlayersTable = new Table(); humanPlayersTable.add(humanPlayerLimitSettingLabel).size(150, 40).fill().padLeft(90).left().spaceRight(10); humanPlayersTable.add(humanPlayerLimitLabel).size(76, 28).fill().left().spaceLeft(10).spaceRight(4); humanPlayersTable.add(customizeHumanPlayersButton).size(28, 28).fill().left().spaceLeft(4); gameSettingsTable.add(humanPlayersTable).left(); gameSettingsTable.row(); final Table aiPlayersTable = new Table(); aiPlayersTable.add(aiPlayerLimitSettingLabel).size(150, 40).fill().padLeft(90).left().spaceRight(10); aiPlayersTable.add(aiPlayerLimitLabel).size(76, 28).fill().left().spaceLeft(10).spaceRight(4); aiPlayersTable.add(customizeAiPlayersButton).size(28, 28).fill().left().spaceLeft(4); gameSettingsTable.add(aiPlayersTable).left(); gameSettingsTable.row(); final Table spectatorsTable = new Table(); spectatorsTable.add(spectatorLimitSettingLabel).size(150, 40).fill().padLeft(90).left().spaceRight(10); spectatorsTable.add(spectatorLimitSelectBox).size(108, 28).fill().left().spaceLeft(10); gameSettingsTable.add(spectatorsTable).left(); gameSettingsTable.row(); final Table winPercentTable = new Table(); winPercentTable.add(winPercentSettingLabel).size(150, 40).fill().padLeft(90).left().spaceRight(10); winPercentTable.add(winPercentSelectBox).size(108, 28).fill().left().spaceLeft(10); gameSettingsTable.add(winPercentTable).left(); gameSettingsTable.row(); // @formatter:off final Table initialCountryAssignmentTable = new Table(); initialCountryAssignmentTable.add(initialCountryAssignmentSettingLabel).size(150, 40).fill().padLeft(90) .left().spaceRight(10); initialCountryAssignmentTable.add(initialCountryAssignmentSelectBox).size(108, 28).fill().left() .spaceLeft(10); gameSettingsTable.add(initialCountryAssignmentTable).left(); // @formatter:on verticalGroup.addActor(gameSettingsTable); addContent(verticalGroup); addBackButton(new ClickListener(Input.Buttons.LEFT) { @Override public void clicked(final InputEvent event, final float x, final float y) { contractMenuBar(new Runnable() { @Override public void run() { toScreen(ScreenId.CLASSIC_GAME_MODE_MENU); } }); } }); forwardButton = addForwardButton(FORWARD_BUTTON_TEXT, new ChangeListener() { @Override public void changed(final ChangeEvent event, final Actor actor) { if (currentPlayMap.equals(PlayMapMetadata.NULL)) { errorDialog.setMessage(new DefaultMessage("Please select a valid map before continuing.")); errorDialog.show(); return; } final String playerName = playerNameTextField.getText(); if (!GameSettings.isValidPlayerNameWithoutClanTag(playerName)) { errorDialog.setMessage(new DefaultMessage( Strings.format("Invalid player name: \'{}\'\n\nValid player name rules:\n\n{}", playerName, GameSettings.VALID_PLAYER_NAME_DESCRIPTION))); errorDialog.show(); return; } final String clanAcronym = clanAcronymTextField.getText(); if (!clanAcronymTextField.isDisabled() && !GameSettings.isValidHumanClanAcronym(clanAcronym)) { errorDialog.setMessage(new DefaultMessage( Strings.format("Invalid clan tag: \'{}\'\n\nValid clan tag rules:\n\n{}", clanAcronym, GameSettings.VALID_CLAN_ACRONYM_DESCRIPTION))); errorDialog.show(); return; } final String playerNameWithOptionalClanTag = GameSettings .getHumanPlayerNameWithOptionalClanTag(playerName, clanAcronym); final int humanPlayerLimit = getHumanPlayerLimit(); final int aiPlayerLimit = getAiPlayerLimit(); final int spectatorLimit = getSpectatorLimit(); final int winPercent = winPercentSelectBox.getSelected(); final InitialCountryAssignment initialCountryAssignment = InitialCountryAssignment .valueOf(Strings.toCase(initialCountryAssignmentSelectBox.getSelected(), LetterCase.UPPER)); final PersonLimits personLimits = PersonLimits.builder().humanPlayers(humanPlayerLimit) .aiPlayers(aiPlayerLimit).spectators(spectatorLimit).build(); final GameRules gameRules = GameRulesFactory.create(GameMode.CLASSIC, personLimits, winPercent, totalCountryCount, initialCountryAssignment); final GameConfiguration gameConfig = new DefaultGameConfiguration(GameMode.CLASSIC, currentPlayMap, gameRules); final String serverName = serverNameTextField.getText(); if (!NetworkSettings.isValidServerName(serverName)) { errorDialog.setMessage(new DefaultMessage( Strings.format("Invalid server name: \'{}\'\n\nValid server name rules:\n\n{}", serverName, NetworkSettings.VALID_SERVER_NAME_DESCRIPTION))); errorDialog.show(); return; } toScreen(ScreenId.MENU_TO_PLAY_LOADING); // The menu-to-play loading screen is now active & can therefore receive events. publishAsync(new CreateGameEvent(serverName, gameConfig, playerNameWithOptionalClanTag)); } }); }
From source file:com.forerunnergames.peril.client.ui.screens.menus.modes.classic.joingame.ClassicGameModeJoinGameMenuScreen.java
License:Open Source License
public ClassicGameModeJoinGameMenuScreen(final MenuScreenWidgetFactory widgetFactory, final ScreenChanger screenChanger, final ScreenSize screenSize, final MouseInput mouseInput, final Batch batch, final MBassador<Event> eventBus) { super(widgetFactory, screenChanger, screenSize, mouseInput, batch, eventBus); Arguments.checkIsNotNull(widgetFactory, "widgetFactory"); this.widgetFactory = widgetFactory; errorDialog = createErrorDialog();/* w w w .j a v a2 s .c o m*/ addTitle("JOIN GAME", Align.bottomLeft, 40); addSubTitle("CLASSIC MODE"); playerNameTextField = widgetFactory.createPlayerNameTextField(); clanAcronymTextField = widgetFactory.createClanAcronymTextField(); serverAddressTextField = widgetFactory.createServerAddressTextField(); clanAcronymCheckBox = widgetFactory.createClanAcronymCheckBox(new ChangeListener() { @Override public void changed(final ChangeEvent event, final Actor actor) { clanAcronymTextField.setText(clanAcronymCheckBox.isChecked() ? clanAcronymTextField.getText() : ""); clanAcronymTextField.setDisabled(!clanAcronymCheckBox.isChecked()); } }); clanAcronymCheckBox.setChecked(!clanAcronymTextField.getText().isEmpty()); clanAcronymTextField.setDisabled(!clanAcronymCheckBox.isChecked()); playerSettingsSectionTitleLabel = widgetFactory.createPlayerSettingsSectionTitleLabel(); playerNameSettingLabel = widgetFactory.createPlayerNameSettingLabel(); clanTagSettingLabel = widgetFactory.createClanTagSettingLabel(); gameSettingsSectionTitleLabel = widgetFactory.createGameSettingsSectionTitleLabel(); serverAddressSettingLabel = widgetFactory.createMenuSettingLabel("Server Address"); final VerticalGroup verticalGroup = new VerticalGroup(); verticalGroup.align(Align.topLeft); // @formatter:off final Table playerSettingsTable = new Table().top().left(); playerSettingsTable.add().height(23).colspan(5); playerSettingsTable.row(); playerSettingsTable.add(playerSettingsSectionTitleLabel).size(538, 42).fill().padLeft(60).padRight(60) .left().colspan(5); playerSettingsTable.row(); playerSettingsTable.add(playerNameSettingLabel).size(150, 40).fill().padLeft(90).left().spaceRight(10); playerSettingsTable.add(playerNameTextField).size(204, 28).fill().left().colspan(3).spaceLeft(10); playerSettingsTable.add().expandX().fill(); playerSettingsTable.row(); playerSettingsTable.add(clanTagSettingLabel).size(150, 40).fill().padLeft(90).left().spaceRight(10); playerSettingsTable.add(clanAcronymCheckBox).size(18, 18).fill().left().spaceLeft(10).spaceRight(10); playerSettingsTable.add(clanAcronymTextField).size(74, 28).fill().left().spaceLeft(10); playerSettingsTable.add().width(102).fill(); playerSettingsTable.add().expandX().fill(); verticalGroup.addActor(playerSettingsTable); // @formatter:on // @formatter:off final Table gameSettingsTable = new Table().top().left(); gameSettingsTable.row(); gameSettingsTable.add().height(18).colspan(3); gameSettingsTable.row(); gameSettingsTable.add(gameSettingsSectionTitleLabel).size(538, 42).fill().padLeft(60).padRight(60).left() .colspan(3); gameSettingsTable.row(); gameSettingsTable.add(serverAddressSettingLabel).size(150, 40).fill().padLeft(90).left().spaceRight(10); gameSettingsTable.add(serverAddressTextField).size(204, 28).fill().left().spaceLeft(10); gameSettingsTable.add().expandX().fill(); verticalGroup.addActor(gameSettingsTable); // @formatter:on addContent(verticalGroup); addBackButton(new ClickListener(Input.Buttons.LEFT) { @Override public void clicked(final InputEvent event, final float x, final float y) { contractMenuBar(new Runnable() { @Override public void run() { toScreen(ScreenId.CLASSIC_GAME_MODE_MENU); } }); } }); forwardButton = addForwardButton("JOIN GAME", new ChangeListener() { @Override public void changed(final ChangeEvent event, final Actor actor) { final String playerName = playerNameTextField.getText(); if (!GameSettings.isValidPlayerNameWithoutClanTag(playerName)) { errorDialog.setMessage(new DefaultMessage( Strings.format("Invalid player name: \'{}\'\n\nValid player name rules:\n\n{}", playerName, GameSettings.VALID_PLAYER_NAME_DESCRIPTION))); errorDialog.show(); return; } final String clanAcronym = clanAcronymTextField.getText(); if (!clanAcronymTextField.isDisabled() && !GameSettings.isValidHumanClanAcronym(clanAcronym)) { errorDialog.setMessage(new DefaultMessage( Strings.format("Invalid clan tag: \'{}\'\n\nValid clan tag rules:\n\n{}", clanAcronym, GameSettings.VALID_CLAN_ACRONYM_DESCRIPTION))); errorDialog.show(); return; } final String playerNameWithOptionalClanTag = GameSettings .getHumanPlayerNameWithOptionalClanTag(playerName, clanAcronym); final String serverAddress = serverAddressTextField.getText(); if (!NetworkSettings.isValidServerAddress(serverAddress)) { errorDialog.setMessage(new DefaultMessage( Strings.format("Invalid server address: \'{}\'\n\nValid server address rules:\n\n{}", serverAddress, NetworkSettings.VALID_SERVER_ADDRESS_DESCRIPTION))); errorDialog.show(); return; } toScreen(ScreenId.MENU_TO_PLAY_LOADING); // The menu-to-play loading screen is now active & can therefore receive events. publishAsync(new JoinGameEvent(playerNameWithOptionalClanTag, serverAddress)); } }); }
From source file:com.gdx.extension.ui.Console.java
License:Apache License
/** * Create a console with specified style. * // w ww. ja va 2s .c o m * @param maxEntries the max lines to display in the console * @param style the style to use */ public Console(int maxEntries, ConsoleStyle style) { this.maxEntries = maxEntries; this.style = style; commandsHistory = new Array<String>(); commands = new ObjectMap<String, Command>(); body = new VerticalGroup(); body.left(); consoleContainer = new Container<VerticalGroup>(body); consoleContainer.setBackground(style.consoleBackground); consoleContainer.left().top(); consoleContainer.pad(10f); consoleScroll = new ScrollPane(consoleContainer); consoleScroll.setScrollingDisabled(true, false); consoleScroll.setFlickScroll(false); textfield = new TextField("", style.textfieldStyle); textfield.addCaptureListener(new InputListener() { @Override public boolean keyDown(InputEvent event, int keycode) { switch (keycode) { case Keys.ENTER: String _inputs = textfield.getText(); if (_inputs.length() > 0) { textfield.setText(""); String[] _split = _inputs.split(" "); if (_split.length == 0) { break; } if (commandsHistory.size == 0 || !(commandsHistory.peek().equals(_inputs))) { commandsHistory.add(_inputs); } currentHistory = commandsHistory.size; Command _commandAction = commands.get(_split[0]); if (_commandAction == null) { addEntry("Command " + _split[0] + " not found"); } else { String[] _args = null; if (_split.length > 1) { _args = Arrays.copyOfRange(_split, 1, _split.length); } _commandAction.executeInternal(Console.this, _args); } } break; case Keys.UP: if (currentHistory > 0) { currentHistory--; String _historyCmd = commandsHistory.get(currentHistory); textfield.setText(_historyCmd); textfield.setCursorPosition(_historyCmd.length()); } break; case Keys.DOWN: if (currentHistory < commandsHistory.size - 1) { currentHistory++; String _historyCmd = commandsHistory.get(currentHistory); textfield.setText(_historyCmd); textfield.setCursorPosition(_historyCmd.length()); } break; default: return false; } return true; } }); add(consoleScroll).expand().fill().row(); add(textfield).fillX(); }
From source file:com.gdx.extension.ui.grid.GridSelection.java
License:Apache License
/** * Add a column to the {@link GridSelection grid}. * The {@link GridSelection grid} must be in vertical mode. * //from ww w .j a v a 2 s. c om * @return the added row * @throws OptimizationException if try to add column in horizontal mode */ public VerticalGroup addColumn() { if (!isVertical) throw new OptimizationException("GridSelection is set to horizontal, so you cannot add columns."); VerticalGroup _group = new VerticalGroup(); columns.add(_group); super.add(_group).top(); itemCount++; return _group; }
From source file:com.gdx.extension.ui.slide.SlideShow.java
License:Apache License
public SlideShow(boolean isVertical, Skin skin, String styleName) { super(skin);/*from w w w . j ava 2 s.c om*/ setStyle(skin.get(styleName, SlideShowStyle.class)); this.isVertical = isVertical; content = (isVertical) ? new VerticalGroup() : new HorizontalGroup(); ScrollPaneStyle _scrollStyle = new ScrollPaneStyle(); contentScroll = new ScrollPane(content, _scrollStyle); contentScroll.setScrollingDisabled(isVertical, !isVertical); contentScroll.setOverscroll(false, false); setBackground(style.background); previousScrollButton = new ImageButton(getStyle().previousScroll); previousScrollButtonCell = add(previousScrollButton); if (isVertical) previousScrollButtonCell.row(); Cell<ScrollPane> _contentCell = add(contentScroll); if (isVertical) _contentCell.row(); nextScrollButton = new ImageButton(getStyle().nextScroll); nextScrollButtonCell = add(nextScrollButton); previousScrollButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { if (SlideShow.this.isVertical) contentScroll.setScrollPercentY(contentScroll.getScrollPercentY() - 0.1f); else contentScroll.setScrollPercentX(contentScroll.getScrollPercentX() - 0.1f); } }); nextScrollButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { if (SlideShow.this.isVertical) contentScroll.setScrollPercentY(contentScroll.getScrollPercentY() + 0.1f); else contentScroll.setScrollPercentX(contentScroll.getScrollPercentX() + 0.1f); } }); }
From source file:com.gdx.extension.ui.tab.TabPane.java
License:Apache License
/** * Create a {@link TabPane} with the specified style. * /* www. j ava 2 s. c om*/ * @param isHorizontal set tabs * @param skin the skin to use for style * @param styleName the name of the style to use */ public TabPane(TabPosition tabPos, Skin skin, String styleName) { super(skin); tabs = new Array<Tab>(); setStyle(skin.get(styleName, TabPaneStyle.class)); buttonGroup = new ButtonGroup(); if (tabPos == TabPosition.TOP || tabPos == TabPosition.BOTTOM) { tabGroup = new HorizontalGroup(); } else { tabGroup = new VerticalGroup().fill(); } container = new Container<TabContainer>(); container.fill(); this.left().top(); if (tabPos == TabPosition.TOP) { addTabs(tabPos); this.row(); addBody(); } else if (tabPos == TabPosition.BOTTOM) { addBody(); this.row(); addTabs(tabPos); } else if (tabPos == TabPosition.LEFT) { addTabs(tabPos); addBody(); } else if (tabPos == TabPosition.RIGHT) { addBody(); addTabs(tabPos); } }
From source file:com.kotcrab.vis.ui.layout.DragPane.java
License:Apache License
/** @param vertical if true, actors will be stored vertically, if false - horizontally. */ public DragPane(final boolean vertical) { this(vertical ? new VerticalGroup() : new HorizontalGroup()); }