use of de.gg.game.network.GameServer in project ProjektGG by eskalon.
the class AbstractGameScreen method onConnectionLost.
@Subscribe
public void onConnectionLost(ConnectionLostEvent ev) {
application.setClient(null);
if (application.isHost()) {
final GameServer server = application.getServer();
application.setServer(null);
ThreadHandler.getInstance().executeRunnable(() -> server.stop());
}
application.getScreenManager().pushScreen("server_browser", null, true);
}
use of de.gg.game.network.GameServer in project ProjektGG by eskalon.
the class LobbyCreationScreen method create.
@Override
protected void create() {
super.create();
setImage(backgroundTexture);
BackInputProcessor backInput = new BackInputProcessor() {
@Override
public void onBackAction() {
application.getScreenManager().pushScreen("server_browser", "shortBlendingTransition");
}
};
addInputProcessor(backInput);
mainTable.addListener(new BackInputActorListener() {
@Override
public void onBackAction() {
backInput.onBackAction();
}
});
this.playerStubs = playerStubsJson.getData(new TypeToken<ArrayList<PlayerStub>>() {
}.getType());
Label nameLabel = new Label(Lang.get("screen.lobby_creation.name"), skin);
Label portLabel = new Label(Lang.get("screen.lobby_creation.port"), skin);
nameField = new OffsettableTextField("", skin, 6);
portField = new OffsettableTextField(String.valueOf(BaseGameServer.DEFAULT_PORT), skin, 6);
portField.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
Label difficultyLabel = new Label(Lang.get("screen.lobby_creation.difficulty"), skin);
CheckBox easyDifficultyCheckbox = new CheckBox(Lang.get(GameDifficulty.EASY), skin);
normalDifficultyCheckbox = new CheckBox(Lang.get(GameDifficulty.NORMAL), skin);
CheckBox hardDifficultyCheckbox = new CheckBox(Lang.get(GameDifficulty.HARD), skin);
ButtonGroup<CheckBox> speedGroup = new ButtonGroup<>();
speedGroup.add(easyDifficultyCheckbox);
speedGroup.add(normalDifficultyCheckbox);
speedGroup.add(hardDifficultyCheckbox);
ImageTextButton backButton = new ImageTextButton(Lang.get("ui.generic.back"), skin);
backButton.addListener(new ButtonClickListener(application.getSoundManager()) {
@Override
protected void onClick() {
application.getScreenManager().pushScreen("server_browser", "shortBlendingTransition");
}
});
ImageTextButton createButton = new ImageTextButton(Lang.get("screen.lobby_creation.create"), skin);
createButton.addListener(new ButtonClickListener(application.getSoundManager()) {
@Override
protected void onClick() {
if (!nameField.getText().isEmpty() && !portField.getText().isEmpty()) {
GameDifficulty difficulty = GameDifficulty.NORMAL;
if (speedGroup.getChecked().equals(easyDifficultyCheckbox)) {
difficulty = GameDifficulty.EASY;
} else if (speedGroup.getChecked().equals(normalDifficultyCheckbox)) {
difficulty = GameDifficulty.NORMAL;
} else if (speedGroup.getChecked().equals(hardDifficultyCheckbox)) {
difficulty = GameDifficulty.HARD;
}
// Start Sever & Client
ServerSetup serverSetup = new ServerSetup(nameField.getText(), 7, Integer.valueOf(portField.getText()), true, application.VERSION, true);
GameSessionSetup sessionSetup = new GameSessionSetup(difficulty, GameMap.BAMBERG, System.currentTimeMillis());
application.setServer(new GameServer(serverSetup, sessionSetup, null, playerStubs));
application.getServer().start(new ISuccessCallback() {
@Override
public void onSuccess(Object param) {
// Connect client to server
application.setClient(new GameClient(application.getEventBus()));
application.getClient().connect(new ISuccessCallback() {
public void onSuccess(Object param) {
// wait for
// LobbyDataReceivedEvent
}
public void onFailure(Object param) {
onHostStartingFailed(((Exception) param).getMessage());
}
}, application.VERSION, "localhost", serverSetup.getPort());
}
public void onFailure(Object param) {
onHostStartingFailed(((Exception) param).getMessage());
}
});
connectingDialog = SimpleTextDialog.createAndShow(stage, skin, Lang.get("screen.lobby_creation.starting_server.title"), Lang.get("screen.lobby_creation.starting_server.text"), false, null);
connectingDialog.show(stage);
} else {
SimpleTextDialog.createAndShow(stage, skin, Lang.get("screen.lobby_creation.fields_empty.title"), Lang.get("screen.lobby_creation.fields_empty.text"));
}
}
});
Table titleTable = new Table();
Table settingsTable = new Table();
Table settings2ColTable = new Table();
Table settings3ColTable = new Table();
Table buttonTable = new Table();
titleTable.add(new Label(Lang.get("screen.lobby_creation.title"), skin, "title")).padTop(25);
settings2ColTable.add(nameLabel).padLeft(100).padBottom(20).padRight(10).padTop(30);
settings2ColTable.add(nameField).row();
settings2ColTable.add(portLabel).padLeft(100).padRight(10);
settings2ColTable.add(portField).row();
settings3ColTable.add(difficultyLabel).colspan(3).padLeft(150).row();
settings3ColTable.add(easyDifficultyCheckbox).padLeft(150).padRight(12);
settings3ColTable.add(normalDifficultyCheckbox).padRight(12);
settings3ColTable.add(hardDifficultyCheckbox);
settingsTable.left().top().add(settings2ColTable).padBottom(27).row();
settingsTable.add(settings3ColTable).row();
buttonTable.add(backButton);
buttonTable.add(createButton).padLeft(65);
Table mTable = new Table();
mTable.setWidth(615);
mTable.setHeight(475);
mTable.setBackground(skin.getDrawable("parchment2"));
mTable.add(titleTable).row();
mTable.add(settingsTable).width(580).height(215).row();
mTable.add(buttonTable).height(50).bottom().padBottom(50);
mainTable.add(mTable);
}
use of de.gg.game.network.GameServer in project ProjektGG by eskalon.
the class GameMapScreen method create.
@Override
protected void create() {
super.create();
camera = new CameraWrapper(67, application.getWidth(), application.getHeight());
camera.setPosition(application.getWidth() / 2, application.getHeight() / 2, 0);
postProcessor = new PostProcessingPipeline(application.getWidth(), application.getHeight(), true);
pausePostProcessingEffect = new ColorBlendEffect(application.getUICamera(), new Color(0.4F, 0.4F, 0.4F, 0.4F));
gameRenderer = new GameRenderer(camera.getCamera(), fragmentShader.getString());
selectionInputController = new MapSelectionInputController(application.getEventBus(), camera.getCamera());
addInputProcessor(selectionInputController);
movementInputController = new MapMovementInputController(camera, application.getSettings());
addInputProcessor(movementInputController);
gameSpeedInputProcessor = new GameSpeedInputProcessor(application.getSettings());
addInputProcessor(gameSpeedInputProcessor);
// CHARACTER DIALOG
BasicDialog characterMenuDialog = new BasicDialog(Lang.get("screen.map.character_config"), skin, "big");
ImageTextButton closeCharacterMenuButton = new ImageTextButton(Lang.get("ui.generic.close"), skin);
closeCharacterMenuButton.addListener(new ButtonClickListener(application.getSoundManager()) {
@Override
protected void onClick() {
characterMenuDialog.hide();
}
});
Table characterMenuTable = new Table();
Table changeableCharacterMenuTable = new Table();
ImageTextButton characterMenuTab1Button = new ImageTextButton(Lang.get("screen.map.character_config.character"), skin);
ImageTextButton characterMenuTab2Button = new ImageTextButton(Lang.get("screen.map.character_config.privileges"), skin);
characterMenuTab1Button.addListener(new ButtonClickListener(application.getSoundManager()) {
@Override
protected void onClick() {
// CHARACTER & FAMILY
changeableCharacterMenuTable.clear();
changeableCharacterMenuTable.add(new Label(Lang.get("screen.map.character_config.name"), skin, "dark")).padBottom(50).row();
changeableCharacterMenuTable.add(new Label(Lang.get("screen.map.character_config.family"), skin, "dark")).row();
changeableCharacterMenuTable.add(new Label(Lang.get("screen.map.character_config.find_so"), skin, "dark"));
}
});
characterMenuTab2Button.addListener(new ButtonClickListener(application.getSoundManager()) {
@Override
protected void onClick() {
// PRIVILEGES
changeableCharacterMenuTable.clear();
changeableCharacterMenuTable.add(new Label(Lang.get("screen.map.character_config.privileges_list"), skin, "dark")).row();
if (application.getClient().getLocalPlayerCharacter().getPosition() != null) {
// TODO Position privileges
// TODO Impeachment
ImageTextButton kickButton = new ImageTextButton(Lang.get("screen.map.character_config.privilege.impeach"), skin);
kickButton.addListener(new ButtonClickListener(application.getSoundManager()) {
@Override
protected void onClick() {
short mayor = application.getClient().getSession().getWorld().getPosition(PositionType.MAYOR).getCurrentHolder();
if (mayor != -1)
application.getClient().getActionHandler().arrangeImpeachmentVote(mayor, (param) -> {
if ((Boolean) param == true) {
SimpleTextDialog.createAndShow(stage, skin, Lang.get("screen.map.character_config.privilege.success"), Lang.get("ui.generic.wip"));
} else {
SimpleTextDialog.createAndShow(stage, skin, Lang.get("ui.generic.error"), Lang.get("ui.generic.rmi_error"));
}
});
}
});
changeableCharacterMenuTable.add(kickButton);
}
}
});
Table characterMenuTabTable = new Table();
characterMenuTabTable.add(characterMenuTab1Button).padRight(5);
characterMenuTabTable.add(characterMenuTab2Button);
characterMenuTable.add(characterMenuTabTable).padRight(30).padBottom(15).center().top().row();
characterMenuTable.add(changeableCharacterMenuTable).padBottom(15).top().height(315).row();
characterMenuTable.add(closeCharacterMenuButton).padRight(30).center().top();
characterMenuDialog.add(characterMenuTable).pad(30);
// PLAYER ICON
iconButton = new ImageButton(skin.getDrawable(PlayerIcon.values()[0].getShieldDrawableName()));
iconButton.addListener(new ButtonClickListener(application.getSoundManager()) {
@Override
protected void onClick() {
characterMenuDialog.show(stage);
characterMenuDialog.setPosition(0, 103);
}
});
Table iconTable = new Table();
iconTable.setBackground(skin.getDrawable("icon_background"));
iconTable.add(iconButton).padLeft(8).padRight(10).padBottom(1);
// INFO STUFF
Table infoTable = new Table();
// Gold
Table goldTable = new Table();
goldTable.setBackground(skin.getDrawable("info_background"));
goldTable.add(new Image(skin.getDrawable("icon_gold_coin"))).left().top().padLeft(4).padBottom(2).padRight(4);
goldTable.add(new Label("19 Gulden", skin, "dark")).padBottom(5).expandX().left().top();
// Name
Table nameTable = new Table();
nameTable.setBackground(skin.getDrawable("info_background"));
nameTable.add(new Label("Freiherr Franz von Woyzeck", skin, "big_dark")).padBottom(2).expandX().left();
// Notifications
Table notificationTable = new Table();
infoTable.add(goldTable).row();
infoTable.add(nameTable).left().row();
infoTable.add(notificationTable).left().padLeft(2).padTop(2).row();
// DATE STUFF
Table dateTimeTable = new Table();
// Date
Table dateTable = new Table();
dateLabel = new Label("", skin, "dark");
dateTable.setBackground(skin.getDrawable("date_background"));
dateTable.add(dateLabel).padLeft(9).padBottom(5).expandX().left();
// Clock
Table clockTable = new Table();
clockTable.setBackground(skin.getDrawable("clock_background"));
dateTimeTable.add(dateTable).row();
dateTimeTable.add(clockTable).right();
// MISC
Table miscTable = new Table();
Table misc2Table = new Table();
// Inventory
ImageButton inventoryButton = new ImageButton(skin, "inventory");
// Book
ImageButton bookButton = new ImageButton(skin, "leaning_book");
// Minimap
Table minimapTable = new Table();
minimapTable.setBackground(skin.getDrawable("minimap_test"));
misc2Table.add(inventoryButton).padRight(2);
misc2Table.add(bookButton).padTop(2).row();
miscTable.add(misc2Table).right().row();
miscTable.add(minimapTable);
mainTable.setSkin(skin);
mainTable.setFillParent(true);
mainTable.add(iconTable).top().left();
mainTable.add(infoTable).top().left();
mainTable.add(dateTimeTable).right().expandX().row();
mainTable.add("").fill();
mainTable.add("").expand().fill();
mainTable.add(miscTable).expandY().bottom().right();
// PAUSE DIALOG
pauseDialog = new BasicDialog("", skin) {
@Override
protected void result(Object object) {
pauseShown = false;
postProcessor.removeEffect(pausePostProcessingEffect);
if (object == (Integer) 1) {
application.getScreenManager().pushScreen("settings", "blendingTransition");
} else {
Log.info("Client", "Verbindung wird getrennt");
final GameClient client = application.getClient();
final GameServer server = application.getServer();
// Set stuff to null to stop updates
application.setClient(null);
application.setServer(null);
ThreadHandler.getInstance().executeRunnable(() -> {
client.disconnect();
if (server != null) {
server.stop();
}
});
DiscordGGHandler.getInstance().setMenuPresence();
application.getScreenManager().pushScreen("main_menu", null);
}
}
};
pauseDialog.button(Lang.get("screen.map.pause.settings"), 1).button(Lang.get("screen.map.pause.disconnect"), 2);
houseSelectionDialog = new BasicDialog("", skin);
houseSelectionDialog.button("Test");
stage.addListener(new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {
if (keycode == Keys.ESCAPE) {
if (pauseShown) {
pauseDialog.hide();
postProcessor.removeEffect(pausePostProcessingEffect);
} else {
pauseDialog.show(stage);
postProcessor.addEffect(pausePostProcessingEffect);
}
pauseShown = !pauseShown;
return true;
}
return false;
}
});
}
use of de.gg.game.network.GameServer in project ProjektGG by eskalon.
the class LobbyScreen method create.
@Override
protected void create() {
super.create();
setImage(backgroundTexture);
PlayerLobbyConfigDialog playerConfigDialog = new PlayerLobbyConfigDialog(application, skin);
ImageTextButton playerSettingsButton = new ImageTextButton(Lang.get("screen.lobby.configure"), skin);
playerSettingsButton.addListener(new ButtonClickListener(application.getSoundManager()) {
@Override
protected void onClick() {
playerConfigDialog.initUIValues(application.getClient().getLobbyPlayers(), application.getClient().getLocalLobbyPlayer());
playerConfigDialog.show(stage);
}
});
ImageTextButton leaveButton = new ImageTextButton(Lang.get("screen.lobby.disconnect"), skin);
leaveButton.addListener(new ButtonClickListener(application.getSoundManager()) {
@Override
protected void onClick() {
Log.info("Client", "Disconnecting from Lobby");
final GameClient client = application.getClient();
final GameServer server = application.getServer();
application.setClient(null);
application.setServer(null);
ThreadHandler.getInstance().executeRunnable(() -> {
client.disconnect();
Log.info("Client", "Client disconnected");
if (server != null) {
server.stop();
}
Log.info("Server", "Server stopped");
});
application.getScreenManager().pushScreen("server_browser", null);
}
});
readyUpLobbyButton = new ImageTextButton(Lang.get("screen.lobby.ready"), skin);
readyUpLobbyButton.addListener(new ButtonClickListener(application.getSoundManager()) {
@Override
protected void onClick() {
// TODO warum nicht readyUp(); ?
application.getClient().getLocalLobbyPlayer().toggleReady();
application.getClient().getActionHandler().changeLocalPlayer(application.getClient().getLocalLobbyPlayer());
updateLobbyUI();
}
});
settingsArea = new Label("", skin);
settingsArea.setAlignment(Align.topLeft);
settingsArea.setWrap(true);
Table playerTable = new Table();
Table buttonTable = new Table();
Table chatTable = new Table();
buttonTable.add(playerSettingsButton).bottom().padBottom(18).row();
buttonTable.add(readyUpLobbyButton).padBottom(18).row();
buttonTable.add(leaveButton).padBottom(50);
Table chatInputTable = new Table();
ImageTextButton sendButton = new ImageTextButton(Lang.get("screen.lobby.send"), skin);
chatInputField = new OffsettableTextField("", skin, "large", 8);
chatInputField.setTextFieldListener(new TextFieldListener() {
@Override
public void keyTyped(TextField textField, char key) {
if (!textField.getText().isEmpty() && key == '\n') {
// Enter
application.getSoundManager().playSoundEffect("button_click");
application.getClient().getActionHandler().sendChatmessage(chatInputField.getText());
application.getClient().getChatMessages().add(new ChatMessage(application.getClient().getLocalLobbyPlayer(), chatInputField.getText()));
setUIValues();
chatInputField.setText("");
}
}
});
sendButton.addListener(new ButtonClickListener(application.getSoundManager()) {
@Override
protected void onClick() {
application.getClient().getActionHandler().sendChatmessage(chatInputField.getText());
application.getClient().getChatMessages().add(new ChatMessage(application.getClient().getLocalLobbyPlayer(), chatInputField.getText()));
setUIValues();
chatInputField.setText("");
}
@Override
protected boolean arePreconditionsMet() {
return !chatInputField.getText().isEmpty();
}
});
messagesArea = new Label("", skin, "text");
messagesArea.setWidth(425);
messagesArea.setWrap(true);
Table messagesTable = new Table();
messagesTable.add(messagesArea).padLeft(10).left().top().expand();
messagesPane = new ScrollPane(messagesTable, skin, "with-background");
messagesPane.setForceScroll(false, true);
chatInputTable.add(chatInputField).left().width(325).padRight(15);
chatInputTable.add(sendButton);
chatTable.add(messagesPane).height(135).width(465).top().row();
chatTable.add(chatInputTable).left().padTop(10).width(465).bottom();
playerSlots = new Table[maxPlayerCount];
for (int i = 0; i < playerSlots.length; i++) {
playerSlots[i] = new Table();
playerTable.add(playerSlots[i]).height(29).width(465).row();
}
Table mTable = new Table();
mTable.setWidth(615);
mTable.setHeight(475);
mTable.setBackground(skin.getDrawable("parchment1"));
mTable.add(playerTable).width(465).height(185).padBottom(15);
mTable.add(settingsArea).width(155).height(185).row();
mTable.add(chatTable).height(185).bottom();
mTable.add(buttonTable).height(185);
mainTable.add(mTable);
}
Aggregations