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 8d91b85 commit 36caa2d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 27 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;
}
}
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>

0 comments on commit 36caa2d

Please sign in to comment.