Skip to content

Commit

Permalink
Server multiplayer: Add passphrase share button to lobby screen
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStahlfelge committed Feb 25, 2021
1 parent e08968d commit c93b1a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions core/src/de/golfgl/lightblocks/menu/ShareButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ public ShareButton(LightBlocksGame app, String shareMessage) {
this(app);
this.shareText = shareMessage;
}

public String getShareText() {
return shareText;
}

public void setShareText(String shareText) {
this.shareText = shareText;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import de.golfgl.lightblocks.menu.AbstractFullScreenDialog;
import de.golfgl.lightblocks.menu.AbstractMenuDialog;
import de.golfgl.lightblocks.menu.PlayButton;
import de.golfgl.lightblocks.menu.ShareButton;
import de.golfgl.lightblocks.multiplayer.ServerModels;
import de.golfgl.lightblocks.multiplayer.ServerMultiplayerManager;
import de.golfgl.lightblocks.scene2d.FaRadioButton;
Expand Down Expand Up @@ -153,7 +154,7 @@ public LobbyTable() {
Actions.fadeOut(.4f, Interpolation.fade), Actions.fadeIn(.4f, Interpolation.fade)));
Table serverInfoTable = new Table(app.skin);

ServerModels.ServerInfo serverInfo = serverMultiplayerManager.getServerInfo();
final ServerModels.ServerInfo serverInfo = serverMultiplayerManager.getServerInfo();

serverInfoTable.defaults().padRight(5).padLeft(5);
serverInfoTable.add("Server: ").right();
Expand Down Expand Up @@ -205,13 +206,18 @@ public LobbyTable() {
final String title = "Set private room passphrase";
FaTextButton privateRoomButton = new FaTextButton(title, app.skin,
LightBlocksGame.SKIN_BUTTON_CHECKBOX);
final ShareButton sharePrivateRoom = new ShareButton(app);
sharePrivateRoom.setVisible(false);
privateRoomButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
TextInputDialog.getTextInput(new Input.TextInputListener() {
@Override
public void input(final String text) {
serverMultiplayerManager.setRoomName(text);
sharePrivateRoom.setVisible(text != null && !text.isEmpty());
sharePrivateRoom.setShareText("I am on server " + serverInfo.name + ", room passphrase: " +
serverMultiplayerManager.getRoomName());
}

@Override
Expand All @@ -224,9 +230,14 @@ public void canceled() {
});
privateRoomButton.getLabel().setFontScale(.55f);

row().padBottom(30);
row();
add(privateRoomButton);
addFocusableActor(privateRoomButton);
addFocusableActor(sharePrivateRoom);

row().padBottom(30);
add(sharePrivateRoom);

}

playButton = new PlayButton(app);
Expand Down

0 comments on commit c93b1a6

Please sign in to comment.