use of com.badlogic.gdx.scenes.scene2d.InputEvent in project ProjektGG by eskalon.
the class LobbyScreen method initUI.
@Override
protected void initUI() {
// backgroundTexture = assetManager.get(BACKGROUND_IMAGE_PATH);
Sound clickSound = assetManager.get(BUTTON_SOUND);
// mainTable.setBackground(skin.getDrawable("parchment-small"));
ImageTextButton leaveButton = new ImageTextButton("Verlassen", skin);
leaveButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
clickSound.play(1F);
game.getNetworkHandler().disconnect();
game.pushScreen("mainMenu");
return true;
}
});
NetworkHandler netHandler = game.getNetworkHandler();
readyUpLobbyButton = new ImageTextButton("Bereit", skin);
if (netHandler.isHost()) {
readyUpLobbyButton.setDisabled(true);
readyUpLobbyButton.setText("Spiel starten");
}
readyUpLobbyButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
clickSound.play(1F);
getLocalPlayer().toggleReady();
netHandler.onLocalPlayerChange(getLocalPlayer());
updateLobbyUI();
return true;
}
});
Table playerTable = new Table();
Table settingsTable = new Table();
Table buttonTable = new Table();
Table chatTable = new Table();
// settings table + player table
buttonTable.add(readyUpLobbyButton).bottom().padBottom(20).row();
buttonTable.add(leaveButton);
Table chatInputTable = new Table();
ImageTextButton sendButton = new ImageTextButton("Senden", skin);
TextField chatInputField = new TextField("", skin);
chatInputField.setTextFieldListener(new TextFieldListener() {
@Override
public void keyTyped(TextField textField, char key) {
if (!textField.getText().isEmpty() && (key == (char) 13)) {
// Enter
clickSound.play(1F);
netHandler.sendChatMessage(chatInputField.getText());
onNewChatMessage(new NewChatMessagEvent(localNetworkId, chatInputField.getText()));
chatInputField.setText("");
}
}
});
sendButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
if (!chatInputField.getText().isEmpty()) {
clickSound.play(1F);
netHandler.sendChatMessage(chatInputField.getText());
onNewChatMessage(new NewChatMessagEvent(localNetworkId, chatInputField.getText()));
chatInputField.setText("");
}
return true;
}
});
messagesArea = new TextArea("", skin);
messagesArea.setDisabled(true);
ScrollPane messagesPane = new ScrollPane(messagesArea);
chatInputTable.add(chatInputField).left().width(325).padRight(15);
chatInputTable.add(sendButton);
chatTable.debug();
chatTable.add(messagesPane).height(125).width(425).top().row();
chatTable.add(chatInputTable).left().padTop(10).width(425).bottom();
playerSlots = new Table[6];
playerSlots[0] = new Table();
playerSlots[1] = new Table();
playerSlots[2] = new Table();
playerSlots[3] = new Table();
playerSlots[4] = new Table();
playerSlots[5] = new Table();
playerTable.add(playerSlots[0]).height(25).width(425).row();
playerTable.add(playerSlots[1]).height(25).width(425).row();
playerTable.add(playerSlots[2]).height(25).width(425).row();
playerTable.add(playerSlots[3]).height(25).width(425).row();
playerTable.add(playerSlots[4]).height(25).width(425).row();
playerTable.add(playerSlots[5]).height(25).width(425).row();
mainTable.add(playerTable).width(425).height(155);
mainTable.add(settingsTable).width(155).row();
mainTable.add(chatTable).height(165).bottom();
mainTable.add(buttonTable).height(165);
mainTable.setDebug(true);
// updateLobbyUI();
}
use of com.badlogic.gdx.scenes.scene2d.InputEvent in project ProjektGG by eskalon.
the class MainMenuScreen method initUI.
@Override
protected void initUI() {
backgroundTexture = assetManager.get(BACKGROUND_IMAGE_PATH);
Sound clickSound = assetManager.get(BUTTON_SOUND);
ImageTextButton multiplayerButton = new ImageTextButton("Multiplayer", skin);
multiplayerButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
clickSound.play(1F);
game.pushScreen("serverBrowser");
return true;
}
});
ImageTextButton settingsButton = new ImageTextButton("Einstellungen", skin);
settingsButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
clickSound.play(1F);
// Gdx.app.exit();
return true;
}
});
ImageTextButton exitButton = new ImageTextButton("Beenden", skin);
exitButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
clickSound.play(1F);
Gdx.app.exit();
return true;
}
});
Image logoImage = new Image((Texture) assetManager.get(LOGO_IMAGE_PATH));
/*
* multiplayerButton .addListener(new TextTooltip("You can press this",
* skin));
*/
mainTable.add(logoImage).padBottom(25f).padTop(-120f);
mainTable.row();
mainTable.add(multiplayerButton).padBottom(11f);
mainTable.row();
mainTable.add(settingsButton).padBottom(11f);
mainTable.row();
mainTable.add(exitButton);
}
use of com.badlogic.gdx.scenes.scene2d.InputEvent in project ProjektGG by eskalon.
the class ServerBrowserScreen method initUI.
@Override
protected void initUI() {
backgroundTexture = assetManager.get(BACKGROUND_IMAGE_PATH);
Sound clickSound = assetManager.get(BUTTON_SOUND);
// mainTable.setBackground(skin.getDrawable("parchment-small"));
Table serverTable = new Table();
ScrollPane pane = new ScrollPane(serverTable);
// TODO gegen echte Server-Daten austauschen
String ip = "127.0.0.1";
int port = 12345;
ImageTextButton joinButton = new ImageTextButton("Beitreten", skin);
joinButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
clickSound.play(1F);
game.getNetworkHandler().setUpConnectionAsClient(ip, port);
connectingDialog = new Dialog("Verbinden...", skin);
connectingDialog.text("Spiel beitreten...");
connectingDialog.show(stage);
return true;
}
});
ImageTextButton backButton = new ImageTextButton("Zur�ck", skin);
backButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
clickSound.play(1F);
game.pushScreen("mainMenu");
return true;
}
});
ImageTextButton createLobbyButton = new ImageTextButton("Spiel erstellen", skin);
createLobbyButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
clickSound.play(1F);
game.pushScreen("lobbyCreation");
return true;
}
});
ImageTextButton directConnectButton = new ImageTextButton("Direkt verbinden", skin);
directConnectButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
clickSound.play(1F);
TextField portInputField = new TextField("55789", skin);
portInputField.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
TextField ipInputField = new TextField("127.0.0.1", skin);
Dialog dialog = new Dialog("Direkt verbinden", skin) {
public void result(Object obj) {
if ((Boolean) obj) {
game.getNetworkHandler().setUpConnectionAsClient(ipInputField.getText(), Integer.valueOf(portInputField.getText()));
connectingDialog = new Dialog("Verbinden...", skin);
connectingDialog.text("Spiel beitreten...");
connectingDialog.show(stage);
}
}
};
dialog.text("IP: ").button("Zur�ck", false).button("Verbinden", true).key(Keys.ENTER, true).key(Keys.ESCAPE, false);
dialog.getContentTable().add(ipInputField).width(170).row();
dialog.getContentTable().add(new Label("Port:", skin));
dialog.getContentTable().add(portInputField).width(90).left();
dialog.show(stage);
return true;
}
});
Table buttonTable = new Table();
buttonTable.add(backButton);
buttonTable.add(createLobbyButton).padLeft(55);
buttonTable.add(directConnectButton).padLeft(55);
serverTable.left().top().add(new Image((Texture) assetManager.get(TICK_IMAGE_PATH))).padRight(15).padLeft(12);
serverTable.add(new Label("Spiel 2", skin)).expandX();
serverTable.add(joinButton).padRight(12);
serverTable.row().padTop(20);
mainTable.add(serverTable).width(580).height(405).row();
mainTable.add(buttonTable).height(50).bottom();
}
use of com.badlogic.gdx.scenes.scene2d.InputEvent in project Rebleyama by dhbw-stginf16a.
the class ClientUI method createXButton.
/**
* method to create X button for window
*
* @param window in which a X button shall be created
*/
private void createXButton(Window window) {
// create button
final TextButton buttonX = new TextButton("X", skin);
// ad butto to top bar of window
window.getTitleTable().add(buttonX).height(window.getPadTop());
// setup event listener for X button
buttonX.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
window.setVisible(false);
}
});
}
use of com.badlogic.gdx.scenes.scene2d.InputEvent in project Rebleyama by dhbw-stginf16a.
the class ClientUI method createMinimap.
/**
* Creates a windows with a minimap in it
*/
private void createMinimap() {
// create window
miniMapWindow = new Window("Minimap", skin);
// set postion of window (-size)
miniMapWindow.setPosition((float) (Gdx.graphics.getWidth() - 200), (float) (Gdx.graphics.getHeight() - 200));
// set size of window
miniMapWindow.setSize(256, 256);
// create image
minimap = new Image();
// add Xbuton in top bar of minimap with extras
final TextButton buttonX = new TextButton("X", skin);
// ad butto to top bar of window
miniMapWindow.getTitleTable().add(buttonX).height(miniMapWindow.getPadTop());
// setup event listener for X button
buttonX.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
miniMapWindow.setVisible(false);
// close render
endcalcThread();
}
});
// aspect ratio button
final TextButton buttonScale = new TextButton("+", skin);
// listener with logic inside
buttonScale.addListener(new DragListener() {
float oldY;
float oldX;
float oldWidth;
float newwidth;
@Override
public void drag(InputEvent event, float x, float y, int pointer) {
oldY = miniMapWindow.getY();
oldX = miniMapWindow.getX();
oldWidth = miniMapWindow.getWidth();
// logic for minimap resizing
if ((x > 0) && (y > 0) && (oldWidth > 128)) {
if (oldWidth - x < 128) {
newwidth = 128;
} else {
newwidth = oldWidth - x;
}
} else if ((x < 0) && (y < 0) && (oldWidth < 512)) {
if (oldWidth - x > 512) {
newwidth = 512;
} else {
newwidth = oldWidth - x;
}
}
miniMapWindow.setPosition(oldX + oldWidth - newwidth, oldY + oldWidth - newwidth);
miniMapWindow.setSize(newwidth, newwidth);
}
});
// stack actor over each other
Stack stack = new Stack();
Table overlay = new Table();
stack.add(minimap);
overlay.add(buttonScale).expand().bottom().left();
stack.add(overlay);
miniMapWindow.add(stack);
// add minimap to ui stage
stage.addActor(miniMapWindow);
}
Aggregations