diff options
| author | Kostya <mail@sartin.in> | 2026-10-15 15:18:30 +0300 |
|---|---|---|
| committer | Kostya <mail@sartin.in> | 2026-10-15 15:18:55 +0300 |
| commit | c67d5ff663b876a15a3831f5a2b564c4002e99b6 (patch) | |
| tree | 98dcbbd1b8b21c5e88865ae0ebd8b270ff80d9a9 /ui-fx/src/main/java/market/guess/ui | |
| parent | 4563c9d6d6c1576b6fb45899c2b6d6073966d8b8 (diff) | |
| download | guess-market-3.0.tar.gz guess-market-3.0.tar.xz guess-market-3.0.zip | |
ui: add chat drawer to the desktop client
3.0
ServerClient fetches new chat lines on the same one-second poll as the
market and hands them over separately from market changes.
The shared UI gets a chat icon in the status bar, beside the eject
button, shown only against a server. It opens a drawer above the status
bar with everyone's lines and a field to send one, laid over the
content so the window keeps its size. While the drawer is closed the
icon counts unread lines. A line the server refuses is reported in the
drawer itself.
Diffstat (limited to 'ui-fx/src/main/java/market/guess/ui')
3 files changed, 128 insertions, 0 deletions
diff --git a/ui-fx/src/main/java/market/guess/ui/desktop/AppState.java b/ui-fx/src/main/java/market/guess/ui/desktop/AppState.java index 5c73e1f..095a188 100644 --- a/ui-fx/src/main/java/market/guess/ui/desktop/AppState.java +++ b/ui-fx/src/main/java/market/guess/ui/desktop/AppState.java | |||
| @@ -8,6 +8,7 @@ import java.time.format.DateTimeFormatter; | |||
| 8 | import java.util.ArrayList; | 8 | import java.util.ArrayList; |
| 9 | import java.util.Collections; | 9 | import java.util.Collections; |
| 10 | import java.util.List; | 10 | import java.util.List; |
| 11 | import java.util.function.Consumer; | ||
| 11 | import javafx.beans.property.BooleanProperty; | 12 | import javafx.beans.property.BooleanProperty; |
| 12 | import javafx.beans.property.ObjectProperty; | 13 | import javafx.beans.property.ObjectProperty; |
| 13 | import javafx.beans.property.SimpleBooleanProperty; | 14 | import javafx.beans.property.SimpleBooleanProperty; |
| @@ -20,6 +21,7 @@ import javafx.collections.ObservableList; | |||
| 20 | import market.guess.api.AccountContext; | 21 | import market.guess.api.AccountContext; |
| 21 | import market.guess.api.CatalogContext; | 22 | import market.guess.api.CatalogContext; |
| 22 | import market.guess.api.GuessMarketContext; | 23 | import market.guess.api.GuessMarketContext; |
| 24 | import market.guess.model.chat.ChatMessageDTO; | ||
| 23 | import market.guess.model.event.EventDetailDTO; | 25 | import market.guess.model.event.EventDetailDTO; |
| 24 | import market.guess.model.event.EventStatus; | 26 | import market.guess.model.event.EventStatus; |
| 25 | import market.guess.model.event.EventSummaryDTO; | 27 | import market.guess.model.event.EventSummaryDTO; |
| @@ -52,6 +54,10 @@ public final class AppState { | |||
| 52 | public final ObservableList<EventData> events = FXCollections.observableArrayList(); | 54 | public final ObservableList<EventData> events = FXCollections.observableArrayList(); |
| 53 | public final ObservableList<UserData> users = FXCollections.observableArrayList(); | 55 | public final ObservableList<UserData> users = FXCollections.observableArrayList(); |
| 54 | 56 | ||
| 57 | private final ObservableList<ChatMessageDTO> chat = FXCollections.observableArrayList(); | ||
| 58 | private final BooleanProperty chatOpen = new SimpleBooleanProperty(false); | ||
| 59 | private Consumer<String> chatSender = text -> {}; | ||
| 60 | |||
| 55 | private final StringProperty selectedEventId = new SimpleStringProperty(null); | 61 | private final StringProperty selectedEventId = new SimpleStringProperty(null); |
| 56 | private final ObjectProperty<EventData> selectedEvent = new SimpleObjectProperty<>(); | 62 | private final ObjectProperty<EventData> selectedEvent = new SimpleObjectProperty<>(); |
| 57 | 63 | ||
| @@ -459,6 +465,26 @@ public final class AppState { | |||
| 459 | actingUser.set(u); | 465 | actingUser.set(u); |
| 460 | } | 466 | } |
| 461 | 467 | ||
| 468 | public ObservableList<ChatMessageDTO> getChat() { | ||
| 469 | return chat; | ||
| 470 | } | ||
| 471 | |||
| 472 | public BooleanProperty chatOpenProperty() { | ||
| 473 | return chatOpen; | ||
| 474 | } | ||
| 475 | |||
| 476 | public void setChatSender(Consumer<String> chatSender) { | ||
| 477 | this.chatSender = chatSender; | ||
| 478 | } | ||
| 479 | |||
| 480 | public void sendChat(String text) { | ||
| 481 | chatSender.accept(text); | ||
| 482 | } | ||
| 483 | |||
| 484 | public String getSessionUser() { | ||
| 485 | return sessionUser; | ||
| 486 | } | ||
| 487 | |||
| 462 | public boolean isRemote() { | 488 | public boolean isRemote() { |
| 463 | return sessionUser != null; | 489 | return sessionUser != null; |
| 464 | } | 490 | } |
diff --git a/ui-fx/src/main/java/market/guess/ui/desktop/controllers/AppController.java b/ui-fx/src/main/java/market/guess/ui/desktop/controllers/AppController.java index e544200..97d31d6 100644 --- a/ui-fx/src/main/java/market/guess/ui/desktop/controllers/AppController.java +++ b/ui-fx/src/main/java/market/guess/ui/desktop/controllers/AppController.java | |||
| @@ -25,6 +25,7 @@ import javafx.stage.FileChooser; | |||
| 25 | import javafx.stage.FileChooser.ExtensionFilter; | 25 | import javafx.stage.FileChooser.ExtensionFilter; |
| 26 | import javafx.util.Duration; | 26 | import javafx.util.Duration; |
| 27 | import market.guess.api.Result; | 27 | import market.guess.api.Result; |
| 28 | import market.guess.model.chat.ChatMessageDTO; | ||
| 28 | import market.guess.model.event.CreateEventRequest; | 29 | import market.guess.model.event.CreateEventRequest; |
| 29 | import market.guess.model.event.EventStatus; | 30 | import market.guess.model.event.EventStatus; |
| 30 | import market.guess.model.event.MechanismType; | 31 | import market.guess.model.event.MechanismType; |
| @@ -47,6 +48,7 @@ public class AppController { | |||
| 47 | private static final PseudoClass SKIN_CATPPUCCIN = PseudoClass.getPseudoClass("skin-catppuccin"); | 48 | private static final PseudoClass SKIN_CATPPUCCIN = PseudoClass.getPseudoClass("skin-catppuccin"); |
| 48 | private static final PseudoClass SKIN_GRUVBOX = PseudoClass.getPseudoClass("skin-gruvbox"); | 49 | private static final PseudoClass SKIN_GRUVBOX = PseudoClass.getPseudoClass("skin-gruvbox"); |
| 49 | 50 | ||
| 51 | private static final String CHAT_GLYPH = ""; // nf-md-chat | ||
| 50 | private static final Duration TOAST_DURATION = Duration.millis(2500); | 52 | private static final Duration TOAST_DURATION = Duration.millis(2500); |
| 51 | private static final Duration FADE_AWAY_DURATION = Duration.millis(500); | 53 | private static final Duration FADE_AWAY_DURATION = Duration.millis(500); |
| 52 | private AppView appView; | 54 | private AppView appView; |
| @@ -63,6 +65,10 @@ public class AppController { | |||
| 63 | @FXML private Label loadedFilePathLabel; | 65 | @FXML private Label loadedFilePathLabel; |
| 64 | @FXML private ComboBox<String> skinComboBox; | 66 | @FXML private ComboBox<String> skinComboBox; |
| 65 | @FXML private Button animationsButton; | 67 | @FXML private Button animationsButton; |
| 68 | @FXML private Button chatButton; | ||
| 69 | @FXML private Node chatPanel; | ||
| 70 | @FXML private ChatPanelController chatPanelController; | ||
| 71 | private int unreadChat; | ||
| 66 | @FXML private Label balanceValueLabel; | 72 | @FXML private Label balanceValueLabel; |
| 67 | @FXML private Label actingAsLabel; | 73 | @FXML private Label actingAsLabel; |
| 68 | @FXML private StackPane centerContainer; | 74 | @FXML private StackPane centerContainer; |
| @@ -155,6 +161,32 @@ public class AppController { | |||
| 155 | usersTabController.setOnToast(this::toast); | 161 | usersTabController.setOnToast(this::toast); |
| 156 | usersTabController.setOnPlaceOrder(this::placeOrder); | 162 | usersTabController.setOnPlaceOrder(this::placeOrder); |
| 157 | usersTabController.setOnDeposit(this::openDepositDialog); | 163 | usersTabController.setOnDeposit(this::openDepositDialog); |
| 164 | |||
| 165 | chatPanelController.init(state); | ||
| 166 | chatButton.setVisible(state.isRemote()); | ||
| 167 | chatButton.setManaged(state.isRemote()); | ||
| 168 | chatPanel.visibleProperty().bind(state.chatOpenProperty()); | ||
| 169 | chatPanel.managedProperty().bind(state.chatOpenProperty()); | ||
| 170 | state | ||
| 171 | .getChat() | ||
| 172 | .addListener( | ||
| 173 | (ListChangeListener<ChatMessageDTO>) | ||
| 174 | c -> { | ||
| 175 | while (c.next()) { | ||
| 176 | if (!state.chatOpenProperty().get()) { | ||
| 177 | unreadChat += c.getAddedSize(); | ||
| 178 | } | ||
| 179 | } | ||
| 180 | updateChatButton(); | ||
| 181 | }); | ||
| 182 | state | ||
| 183 | .chatOpenProperty() | ||
| 184 | .addListener( | ||
| 185 | (obs, was, open) -> { | ||
| 186 | unreadChat = 0; | ||
| 187 | updateChatButton(); | ||
| 188 | }); | ||
| 189 | updateChatButton(); | ||
| 158 | } | 190 | } |
| 159 | 191 | ||
| 160 | private void setupStateBindings() { | 192 | private void setupStateBindings() { |
| @@ -408,6 +440,17 @@ public class AppController { | |||
| 408 | } | 440 | } |
| 409 | 441 | ||
| 410 | @FXML | 442 | @FXML |
| 443 | private void handleChatToggled() { | ||
| 444 | var open = appView.getState().chatOpenProperty(); | ||
| 445 | open.set(!open.get()); | ||
| 446 | } | ||
| 447 | |||
| 448 | private void updateChatButton() { | ||
| 449 | chatButton.setText(CHAT_GLYPH + " " + (unreadChat == 0 ? "" : unreadChat)); | ||
| 450 | Views.setSelected(chatButton, appView.getState().chatOpenProperty().get()); | ||
| 451 | } | ||
| 452 | |||
| 453 | @FXML | ||
| 411 | private void handleLoadFile() { | 454 | private void handleLoadFile() { |
| 412 | startLoad(); | 455 | startLoad(); |
| 413 | } | 456 | } |
diff --git a/ui-fx/src/main/java/market/guess/ui/desktop/controllers/ChatPanelController.java b/ui-fx/src/main/java/market/guess/ui/desktop/controllers/ChatPanelController.java new file mode 100644 index 0000000..7c98692 --- /dev/null +++ b/ui-fx/src/main/java/market/guess/ui/desktop/controllers/ChatPanelController.java | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | package market.guess.ui.desktop.controllers; | ||
| 2 | |||
| 3 | import javafx.application.Platform; | ||
| 4 | import javafx.collections.ListChangeListener; | ||
| 5 | import javafx.fxml.FXML; | ||
| 6 | import javafx.scene.Node; | ||
| 7 | import javafx.scene.control.Label; | ||
| 8 | import javafx.scene.control.ScrollPane; | ||
| 9 | import javafx.scene.control.TextField; | ||
| 10 | import javafx.scene.layout.VBox; | ||
| 11 | import market.guess.model.chat.ChatMessageDTO; | ||
| 12 | import market.guess.ui.desktop.AppState; | ||
| 13 | |||
| 14 | public class ChatPanelController { | ||
| 15 | private static final int MAX_LENGTH = 500; | ||
| 16 | |||
| 17 | private AppState state; | ||
| 18 | |||
| 19 | @FXML private ScrollPane scroll; | ||
| 20 | @FXML private VBox messages; | ||
| 21 | @FXML private TextField input; | ||
| 22 | |||
| 23 | public void init(AppState state) { | ||
| 24 | this.state = state; | ||
| 25 | state | ||
| 26 | .getChat() | ||
| 27 | .addListener( | ||
| 28 | (ListChangeListener<ChatMessageDTO>) | ||
| 29 | c -> { | ||
| 30 | while (c.next()) { | ||
| 31 | for (var message : c.getAddedSubList()) { | ||
| 32 | messages.getChildren().add(row(message)); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | Platform.runLater(() -> scroll.setVvalue(1.0)); | ||
| 36 | }); | ||
| 37 | } | ||
| 38 | |||
| 39 | private Node row(ChatMessageDTO message) { | ||
| 40 | var mine = message.sender().equalsIgnoreCase(state.getSessionUser()); | ||
| 41 | var head = new Label(message.sender() + " " + message.at()); | ||
| 42 | head.getStyleClass() | ||
| 43 | .addAll("gm-text-xs", "gm-font-semibold", mine ? "gm-text-accent" : "gm-text-ink2"); | ||
| 44 | var text = new Label(message.text()); | ||
| 45 | text.setWrapText(true); | ||
| 46 | text.getStyleClass().addAll("gm-text-base", "gm-text-ink"); | ||
| 47 | return new VBox(2, head, text); | ||
| 48 | } | ||
| 49 | |||
| 50 | @FXML | ||
| 51 | private void handleSend() { | ||
| 52 | var text = input.getText().trim(); | ||
| 53 | if (text.isEmpty()) { | ||
| 54 | return; | ||
| 55 | } | ||
| 56 | state.sendChat(text.length() > MAX_LENGTH ? text.substring(0, MAX_LENGTH) : text); | ||
| 57 | input.clear(); | ||
| 58 | } | ||
| 59 | } | ||