Skip to content

Commit

Permalink
Don't show game join menu item when game mode is ladder
Browse files Browse the repository at this point in the history
Fixes #936
  • Loading branch information
Askaholic authored and FreZha committed Jul 5, 2020
1 parent 7747d29 commit 9d7d541
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.faforever.client.fx.JavaFxUtil;
import com.faforever.client.fx.StringListCell;
import com.faforever.client.game.JoinGameHelper;
import com.faforever.client.game.KnownFeaturedMod;
import com.faforever.client.game.PlayerStatus;
import com.faforever.client.i18n.I18n;
import com.faforever.client.main.event.ShowUserReplaysEvent;
Expand Down Expand Up @@ -193,12 +194,21 @@ public void setChatUser(ChatChannelUser chatUser) {
addFoeItem.visibleProperty().bind(newValue.socialStatusProperty().isNotEqualTo(FOE).and(newValue.socialStatusProperty().isNotEqualTo(SELF)));
removeFoeItem.visibleProperty().bind(newValue.socialStatusProperty().isEqualTo(FOE));

// TODO: Make this ignore TMM games too and not just ladder
// https://github.com/FAForever/downlords-faf-client/issues/1770
joinGameItem.visibleProperty().bind(newValue.socialStatusProperty().isNotEqualTo(SELF)
.and(newValue.statusProperty().isEqualTo(PlayerStatus.LOBBYING)
.or(newValue.statusProperty().isEqualTo(PlayerStatus.HOSTING))));
.or(newValue.statusProperty().isEqualTo(PlayerStatus.HOSTING)))
.and(Bindings.createBooleanBinding(() -> {
return newValue.getGame() != null
&& newValue.getGame().getFeaturedMod() != null
&& !newValue.getGame().getFeaturedMod().equals(KnownFeaturedMod.LADDER_1V1.getTechnicalName());
}, newValue.gameProperty())
));
watchGameItem.visibleProperty().bind(newValue.statusProperty().isEqualTo(PlayerStatus.PLAYING));
inviteItem.visibleProperty().bind(newValue.socialStatusProperty().isNotEqualTo(SELF)
.and(newValue.statusProperty().isNotEqualTo(PlayerStatus.PLAYING)));

};
JavaFxUtil.addListener(chatUser.playerProperty(), new WeakChangeListener<>(playerChangeListener));
playerChangeListener.changed(chatUser.playerProperty(), null, chatUser.getPlayer().orElse(null));
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/faforever/client/player/PlayerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.faforever.client.game.GameAddedEvent;
import com.faforever.client.game.GameRemovedEvent;
import com.faforever.client.game.GameUpdatedEvent;
import com.faforever.client.game.KnownFeaturedMod;
import com.faforever.client.player.event.CurrentPlayerInfo;
import com.faforever.client.player.event.FriendJoinedGameEvent;
import com.faforever.client.remote.FafService;
Expand Down Expand Up @@ -192,7 +193,9 @@ private void updateGameDataForPlayer(Game game, Player player) {
if (!playersByGame.get(game.getId()).contains(player)) {
player.setGame(game);
playersByGame.get(game.getId()).add(player);
if (player.getSocialStatus() == FRIEND && game.getStatus() == GameStatus.OPEN) {
if (player.getSocialStatus() == FRIEND
&& game.getStatus() == GameStatus.OPEN
&& !game.getFeaturedMod().equals(KnownFeaturedMod.LADDER_1V1.getTechnicalName())) {
eventBus.post(new FriendJoinedGameEvent(player, game));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.faforever.client.chat.avatar.AvatarService;
import com.faforever.client.game.Game;
import com.faforever.client.game.JoinGameHelper;
import com.faforever.client.game.KnownFeaturedMod;
import com.faforever.client.game.PlayerStatus;
import com.faforever.client.i18n.I18n;
import com.faforever.client.moderator.ModeratorService;
import com.faforever.client.notification.ImmediateNotification;
Expand All @@ -15,6 +17,7 @@
import com.faforever.client.preferences.ChatPrefs;
import com.faforever.client.preferences.Preferences;
import com.faforever.client.preferences.PreferencesService;
import com.faforever.client.remote.domain.GameStatus;
import com.faforever.client.replay.ReplayService;
import com.faforever.client.test.AbstractPlainJavaFxTest;
import com.faforever.client.theme.UiService;
Expand All @@ -41,6 +44,7 @@
import static com.faforever.client.player.SocialStatus.SELF;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -161,6 +165,44 @@ public void testBanContextMenuShownForMod() {
assertTrue(instance.moderatorActionSeparator.isVisible());
}

@Test
public void testJoinGameContextMenuNotShownForIdleUser() {
instance.setChatUser(chatUser);
player.setSocialStatus(OTHER);

assertFalse(instance.joinGameItem.isVisible());
}

@Test
public void testJoinGameContextMenuShownForHostingUser() {
Game game = new Game();
game.setFeaturedMod(KnownFeaturedMod.FAF.getTechnicalName());
game.setStatus(GameStatus.OPEN);
game.setHost(player.getUsername());

player.setSocialStatus(OTHER);
player.setGame(game);
instance.setChatUser(chatUser);

assertEquals(player.getStatus(), PlayerStatus.HOSTING);
assertTrue(instance.joinGameItem.isVisible());
}

@Test
public void testJoinGameContextMenuNotShownForLadderUser() {
Game game = new Game();
game.setFeaturedMod(KnownFeaturedMod.LADDER_1V1.getTechnicalName());
game.setStatus(GameStatus.OPEN);
game.setHost(player.getUsername());

player.setSocialStatus(OTHER);
player.setGame(game);
instance.setChatUser(chatUser);

assertEquals(player.getStatus(), PlayerStatus.HOSTING);
assertFalse(instance.joinGameItem.isVisible());
}

@Test
public void testOnSendPrivateMessage() {
instance.setChatUser(chatUser);
Expand Down

0 comments on commit 9d7d541

Please sign in to comment.