Skip to content

Commit

Permalink
Fixes #532 by adding a Tab to open channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Schmale authored and 1-alex98 committed Jun 11, 2017
1 parent 63f47fd commit 34af5b8
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 31 deletions.
29 changes: 21 additions & 8 deletions src/main/java/com/faforever/client/chat/ChatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.collections.ListChangeListener;
import javafx.scene.Node;
import javafx.scene.control.Tab;
Expand Down Expand Up @@ -41,8 +40,9 @@ public class ChatController extends AbstractViewController<Node> {
public Node chatRoot;
public TabPane tabPane;
public Pane connectingProgressPane;
public VBox noOpenTabsContainer;
public VBox newChannelJoinRoot;
public TextField channelNameTextField;
private Tab newChannel;

@Inject
public ChatController(ChatService chatService, UiService uiService, UserService userService, EventBus eventBus) {
Expand All @@ -65,19 +65,16 @@ private void onChannelJoined(Channel channel) {
private void onDisconnected() {
connectingProgressPane.setVisible(true);
tabPane.setVisible(false);
noOpenTabsContainer.setVisible(false);
}

private void onConnected() {
connectingProgressPane.setVisible(false);
tabPane.setVisible(true);
noOpenTabsContainer.setVisible(false);
}

private void onConnecting() {
connectingProgressPane.setVisible(true);
tabPane.setVisible(false);
noOpenTabsContainer.setVisible(false);
}

private void onLoggedOut() {
Expand Down Expand Up @@ -106,15 +103,31 @@ private void addTab(String playerOrChannelName, AbstractChatTabController tabCon
JavaFxUtil.assertApplicationThread();
nameToChatTabController.put(playerOrChannelName, tabController);
tabPane.getTabs().add(tabController.getRoot());
tabPane.getTabs().sort((o1, o2) -> {
if (o1.equals(newChannel)) {
return 1;
} else if (o2.equals(newChannel)) {
return -1;
} else {
return 0;
}
});
tabPane.getSelectionModel().select(tabController.getRoot());
}

@Override
public void initialize() {
super.initialize();
eventBus.register(this);

tabPane.getTabs().addListener((InvalidationListener) observable ->
noOpenTabsContainer.setVisible(tabPane.getTabs().isEmpty()));
NewChannelController newChannelController = uiService.loadFxml("theme/chat/newChannel.fxml");
newChannelJoinRoot = (VBox) newChannelController.getRoot();
channelNameTextField = newChannelController.getChannelNameTextField();
channelNameTextField.setOnAction(event -> onJoinChannelButtonClicked());

newChannel = new Tab("+", newChannelJoinRoot);
newChannel.setClosable(false);
tabPane.getTabs().add(newChannel);

chatService.addChannelsListener(change -> {
if (change.wasRemoved()) {
Expand Down Expand Up @@ -240,7 +253,7 @@ private boolean isCurrentUser(ChatUser chatUser) {
@Override
protected void onDisplay() {
super.onDisplay();
if (!tabPane.getTabs().isEmpty()) {
if (tabPane.getTabs().size() > 1) {
Tab tab = tabPane.getSelectionModel().getSelectedItem();
nameToChatTabController.get(tab.getId()).onDisplay();
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/faforever/client/chat/NewChannelController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.faforever.client.chat;


import com.faforever.client.fx.Controller;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class NewChannelController implements Controller {
@FXML
public VBox root;
@FXML
public TextField channelNameTextField;

@Override
public Object getRoot() {
return root;
}

public TextField getChannelNameTextField() {
return channelNameTextField;
}
}
23 changes: 21 additions & 2 deletions src/main/java/com/faforever/client/main/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.faforever.client.fx.AbstractViewController;
import com.faforever.client.fx.Controller;
import com.faforever.client.fx.JavaFxUtil;
import com.faforever.client.fx.PlatformService;
import com.faforever.client.fx.WindowController;
import com.faforever.client.game.GameService;
import com.faforever.client.i18n.I18n;
Expand Down Expand Up @@ -60,6 +61,7 @@
import org.springframework.stereotype.Component;

import javax.inject.Inject;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -91,6 +93,7 @@ public class MainController implements Controller<Node> {
private final EventBus eventBus;
private final String mainWindowTitle;
private final int ratingBeta;
private final PlatformService platformService;
public Pane mainHeaderPane;
public Labeled notificationsBadge;
public Pane contentPane;
Expand All @@ -111,7 +114,7 @@ public class MainController implements Controller<Node> {
@Inject
public MainController(PreferencesService preferencesService, I18n i18n, NotificationService notificationService,
PlayerService playerService, GameService gameService, ClientUpdateService clientUpdateService,
UiService uiService, EventBus eventBus, ClientProperties clientProperties) {
UiService uiService, EventBus eventBus, ClientProperties clientProperties, PlatformService platformService) {
this.preferencesService = preferencesService;
this.i18n = i18n;
this.notificationService = notificationService;
Expand All @@ -123,7 +126,8 @@ public MainController(PreferencesService preferencesService, I18n i18n, Notifica

this.mainWindowTitle = clientProperties.getMainWindowTitle();
this.ratingBeta = clientProperties.getTrueSkill().getBeta();

this.platformService = platformService;

this.viewCache = CacheBuilder.newBuilder().build();
}

Expand Down Expand Up @@ -457,4 +461,19 @@ public void onNavigateEvent(NavigateEvent navigateEvent) {
private AbstractViewController<?> loadView(NavigationItem item) {
return noCatch(() -> viewCache.get(item, () -> uiService.loadFxml(item.getFxmlFile())));
}

public void onRevealMapFolder() {
Path mapPath = preferencesService.getPreferences().getForgedAlliance().getCustomMapsDirectory();
this.platformService.reveal(mapPath);
}

public void onRevealModFolder() {
Path modPath = preferencesService.getPreferences().getForgedAlliance().getModsDirectory();
this.platformService.reveal(modPath);
}

public void onRevealLogFolder() {
Path logPath = preferencesService.getFafLogDirectory();
this.platformService.reveal(logPath);
}
}
3 changes: 3 additions & 0 deletions src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ menu.support=Support
menu.feedback=Feedback
menu.exit=Exit
menu.settings=Settings
menu.revealMapFolder=Reveal map folder
menu.revealLogFolder=Reveal log folder
menu.revealModFolder=Reveal mod folder

main.community.news=News
main.chat=Chat
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/i18n/messages_de_DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ view.table=Tabelle

userMenu.showProfile=Zeige Profil

menu.revealMapFolder=Kartenverzeichnis öffnen
menu.revealLogFolder=Log-Verzeichnis öffnen
menu.revealModFolder=Mod-Verzeichnis öffnen

main.leaderboards=Rangliste
//Still=needs to be translated:
leaderboard.ranked1v1=1v1 Rating
Expand Down
20 changes: 1 addition & 19 deletions src/main/resources/theme/chat/chat.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ProgressIndicator?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" fx:id="chatRoot" xmlns="http://javafx.com/javafx/8.0.40"
Expand All @@ -25,22 +23,6 @@
</Label>
</children>
</VBox>
<VBox fx:id="noOpenTabsContainer" alignment="CENTER" fillWidth="false" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<VBox>
<children>
<Label styleClass="h2" text="%chat.noOpenChats"/>
<Separator prefWidth="300.0"/>
<Label text="%chat.joinAChannel">
<padding>
<Insets top="10.0"/>
</padding>
</Label>
<TextField fx:id="channelNameTextField" onAction="#onJoinChannelButtonClicked" promptText="%chat.channelNamePrompt"/>
</children>
</VBox>
</children>
</VBox>

</children>
</AnchorPane>
19 changes: 19 additions & 0 deletions src/main/resources/theme/chat/newChannel.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.VBox?>
<VBox xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.faforever.client.chat.NewChannelController" fx:id="root"
alignment="CENTER" fillWidth="false">
<children>
<VBox>
<children>
<Label text="%chat.joinAChannel">
<padding>
<Insets top="10.0"/>
</padding>
</Label>
<TextField fx:id="channelNameTextField" promptText="%chat.channelNamePrompt"/>
</children>
</VBox>
</children>
</VBox>
4 changes: 4 additions & 0 deletions src/main/resources/theme/main.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<SeparatorMenuItem mnemonicParsing="false"/>
<MenuItem disable="true" text="%menu.feedback"/>
<SeparatorMenuItem mnemonicParsing="false"/>
<MenuItem onAction="#onRevealLogFolder" text="%menu.revealLogFolder" />
<MenuItem onAction="#onRevealMapFolder" text="%menu.revealMapFolder" />
<MenuItem onAction="#onRevealModFolder" text="%menu.revealModFolder" />
<SeparatorMenuItem mnemonicParsing="false"/>
<MenuItem onAction="#onExitItemSelected" text="%menu.exit"/>
</items>
<styleClass>
Expand Down
34 changes: 32 additions & 2 deletions src/test/java/com/faforever/client/main/MainControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.faforever.client.chat.ChatController;
import com.faforever.client.config.ClientProperties;
import com.faforever.client.fx.PlatformService;
import com.faforever.client.fx.WindowController;
import com.faforever.client.game.GameService;
import com.faforever.client.i18n.I18n;
Expand Down Expand Up @@ -45,6 +46,8 @@
import org.mockito.Mock;
import org.testfx.util.WaitForAsyncUtils;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand All @@ -66,12 +69,13 @@
import static org.mockito.Mockito.when;

public class MainControllerTest extends AbstractPlainJavaFxTest {

@Mock
private PersistentNotificationsController persistentNotificationsController;
@Mock
private PreferencesService preferencesService;
@Mock
private PlatformService platformService;
@Mock
private LeaderboardController leaderboardController;
@Mock
private PlayerService playerService;
Expand Down Expand Up @@ -119,7 +123,7 @@ public void setUp() throws Exception {
.setInitialStandardDeviation(500);

instance = new MainController(preferencesService, i18n, notificationService, playerService, gameService, clientUpdateService,
uiService, eventBus, clientProperties);
uiService, eventBus, clientProperties, platformService);

gameRunningProperty = new SimpleBooleanProperty();

Expand Down Expand Up @@ -308,4 +312,30 @@ public void testWindowOutsideScreensGetsCentered() throws Exception {
Rectangle2D bounds = new Rectangle2D(window.getX(), window.getY(), window.getWidth(), window.getHeight());
assertTrue(Screen.getPrimary().getBounds().contains(bounds));
}

@Test
public void testOnRevealMapFolder() throws Exception {
Path expectedPath = Paths.get("C:\\test\\path_map");
when(forgedAlliancePrefs.getCustomMapsDirectory()).thenReturn(expectedPath);
when(preferences.getForgedAlliance()).thenReturn(forgedAlliancePrefs);
instance.onRevealMapFolder();
verify(platformService).reveal(expectedPath);
}

@Test
public void testOnRevealModFolder() throws Exception {
Path expectedPath = Paths.get("C:\\test\\path_mod");
when(forgedAlliancePrefs.getModsDirectory()).thenReturn(expectedPath);
when(preferences.getForgedAlliance()).thenReturn(forgedAlliancePrefs);
instance.onRevealModFolder();
verify(platformService).reveal(expectedPath);
}

@Test
public void testOnRevealLogFolder() throws Exception {
Path expectedPath = Paths.get("C:\\test\\path_log");
when(preferencesService.getFafLogDirectory()).thenReturn(expectedPath);
instance.onRevealLogFolder();
verify(platformService).reveal(expectedPath);
}
}

0 comments on commit 34af5b8

Please sign in to comment.