Skip to content

Commit

Permalink
Resolve #2855 and #2856
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan <v23620@gmail.com>
  • Loading branch information
Marc-Spector and IvanPavilionG7 committed Dec 18, 2022
1 parent 602d75d commit f3c1f1c
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 27 deletions.
Expand Up @@ -212,10 +212,15 @@ private void setChannelTopic(String content) {

private void updateChannelTopic() {
String oldTopicContent = topicContent;
ChannelTopic topic = chatChannel.getTopic();
setChannelTopic(topic.getContent());
if (StringUtils.isNotBlank(topic.getAuthor())) {
onChatMessage(new ChatMessage(channelName, Instant.now(), topic.getAuthor(), i18n.get("chat.topicUpdated", oldTopicContent, topic.getContent())));
String newTopicContent = chatChannel.getTopic().getContent();
if (StringUtils.equals(oldTopicContent, newTopicContent)) {
return;
}

setChannelTopic(newTopicContent);
String username = chatChannel.getTopic().getAuthor();
if (StringUtils.isNotBlank(username) && chatChannel.getUser(username) != null) {
onChatMessage(new ChatMessage(channelName, Instant.now(), username, i18n.get("chat.topicUpdated", oldTopicContent, newTopicContent)));
}

if (topicPane.isDisable()) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/faforever/client/chat/ChatChannel.java
Expand Up @@ -8,6 +8,7 @@
import javafx.collections.ObservableMap;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -72,6 +73,7 @@ public int getUserCount() {
return users.size();
}

@Nullable
public ChatChannelUser getUser(String username) {
return users.get(username);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/faforever/client/fx/PlatformService.java
Expand Up @@ -104,10 +104,11 @@ public void reveal(Path path) {
}
}


/**
* Show a Window, restore it to it's state before minimizing (normal/restored or maximized) and move it to foreground
* will only work on windows systems
* Note: An application cannot force a window to the foreground while the user is working with another window.
* Instead, Windows flashes the taskbar button of the window to notify the user.
*/
public void focusWindow(String windowTitle) {
focusWindow(windowTitle, null);
Expand All @@ -118,6 +119,7 @@ public void focusWindow(String windowTitle, @Nullable Long processId) {
if (!isWindows) {
return;
}
log.debug("Focus '{}' window", windowTitle);
focusWindow(getWindow(windowTitle, processId));
}

Expand Down
Expand Up @@ -152,8 +152,6 @@ public TilesSortingOrder fromString(String string) {
JavaFxUtil.bind(gameDetailPane.visibleProperty(), toggleGameDetailPaneButton.selectedProperty());
JavaFxUtil.bind(gameDetailPane.managedProperty(), gameDetailPane.visibleProperty());

setSelectedGame(null);

toggleGameDetailPaneButton.selectedProperty().addListener(observable -> {
preferences.setShowGameDetailsSidePane(toggleGameDetailPaneButton.isSelected());
preferencesService.storeInBackground();
Expand Down Expand Up @@ -265,7 +263,6 @@ private void disposeGamesContainer() {

@VisibleForTesting
void setSelectedGame(GameBean game) {
gameDetailController.getRoot().setVisible(true);
gameDetailController.setGame(game);
}

Expand Down
Expand Up @@ -65,7 +65,7 @@ public class GameDetailController implements Controller<Pane> {
private final NotificationService notificationService;
private final EventBus eventBus;

public Pane gameDetailRoot;
public Pane root;
public Label gameTypeLabel;
public Label mapLabel;
public Label numberOfPlayersLabel;
Expand Down Expand Up @@ -93,14 +93,14 @@ public class GameDetailController implements Controller<Pane> {
public void initialize() {
imageViewHelper.setDefaultPlaceholderImage(mapImageView, true);
contextMenuBuilder.addCopyLabelContextMenu(gameTitleLabel, mapLabel, gameTypeLabel);
JavaFxUtil.bindManagedToVisible(joinButton, watchButton, gameTitleLabel, hostLabel, mapLabel, numberOfPlayersLabel,
JavaFxUtil.bindManagedToVisible(root, joinButton, watchButton, gameTitleLabel, hostLabel, mapLabel, numberOfPlayersLabel,
mapPreviewContainer, gameTypeLabel, playtimeLabel, generateMapButton);
JavaFxUtil.bind(mapPreviewContainer.visibleProperty(), mapImageView.imageProperty().isNotNull());
gameDetailRoot.parentProperty().addListener(observable -> {
if (!(gameDetailRoot.getParent() instanceof Pane)) {
root.parentProperty().addListener(observable -> {
if (!(root.getParent() instanceof Pane)) {
return;
}
gameDetailRoot.maxWidthProperty().bind(((Pane) gameDetailRoot.getParent()).widthProperty());
root.maxWidthProperty().bind(((Pane) root.getParent()).widthProperty());
});

eventBus.register(this);
Expand Down Expand Up @@ -266,7 +266,7 @@ public void setPlaytimeVisible(boolean visible) {

@Override
public Pane getRoot() {
return gameDetailRoot;
return root;
}

public void onJoinButtonClicked() {
Expand Down
Expand Up @@ -162,9 +162,7 @@ public void initializeGameTable(ObservableList<GameBean> games, Function<String,
}

private void selectFirstGame() {
if (!gamesTable.getItems().isEmpty()) {
gamesTable.getSelectionModel().selectFirst();
}
gamesTable.getSelectionModel().selectFirst();
}

private void applyLastSorting(TableView<GameBean> gamesTable) {
Expand Down
Expand Up @@ -357,7 +357,7 @@ public CompletableFuture<Void> onLoginButtonClicked() {

return oAuthValuesReceiver.receiveValues(redirectUriCandidates, state, verifier)
.thenCompose(values -> {
platformService.focusWindow(clientProperties.getMainWindowTitle());
platformService.focusWindow(i18n.get("login.title"));
String actualState = values.getState();
if (!state.equals(actualState)) {
handleInvalidSate(actualState, state);
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/theme/play/game_detail.fxml
Expand Up @@ -11,7 +11,8 @@
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<GridPane fx:id="gameDetailRoot" maxHeight="1.7976931348623157E308" maxWidth="-Infinity" minWidth="50.0"

<GridPane fx:id="root" maxHeight="1.7976931348623157E308" maxWidth="-Infinity" minWidth="50.0"
styleClass="game-detail" vgap="10.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.faforever.client.game.GameDetailController">
<columnConstraints>
Expand Down
Expand Up @@ -21,7 +21,6 @@
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.testfx.util.WaitForAsyncUtils;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -91,7 +90,6 @@ public void setUp() throws Exception {
}
return instance;
});
verify(gameDetailController).setGame(null);
}

@Test
Expand All @@ -110,16 +108,14 @@ public void testSetSelectedGameDoesNotShowDetailPaneIfDisabled() {
}

@Test
public void testTiles() {
instance.tilesButton.fire();
WaitForAsyncUtils.waitForFxEvents();
public void testDisplayTiles() {
runOnFxThreadAndWait(() -> instance.tilesButton.fire());
verify(gamesTilesContainerController).createTiledFlowPane(games, instance.chooseSortingTypeChoiceBox);
}

@Test
public void testHideSidePane() {
instance.toggleGameDetailPaneButton.fire();
WaitForAsyncUtils.waitForFxEvents();
runOnFxThreadAndWait(() -> instance.toggleGameDetailPaneButton.fire());

assertFalse(preferencesService.getPreferences().isShowGameDetailsSidePane());
verify(preferencesService, atLeast(2)).storeInBackground();
Expand Down
Expand Up @@ -190,7 +190,7 @@ public void testTeamListener() {

@Test
public void testGetRoot() {
assertEquals(instance.gameDetailRoot, instance.getRoot());
assertEquals(instance.root, instance.getRoot());
}

@Test
Expand Down

0 comments on commit f3c1f1c

Please sign in to comment.