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 | |
| parent | 4563c9d6d6c1576b6fb45899c2b6d6073966d8b8 (diff) | |
| download | guess-market-c67d5ff663b876a15a3831f5a2b564c4002e99b6.tar.gz guess-market-c67d5ff663b876a15a3831f5a2b564c4002e99b6.tar.xz guess-market-c67d5ff663b876a15a3831f5a2b564c4002e99b6.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')
6 files changed, 185 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 | } | ||
diff --git a/ui-fx/src/main/resources/market/guess/ui/desktop/app_view.fxml b/ui-fx/src/main/resources/market/guess/ui/desktop/app_view.fxml index 3a34a7e..8dd7b4c 100644 --- a/ui-fx/src/main/resources/market/guess/ui/desktop/app_view.fxml +++ b/ui-fx/src/main/resources/market/guess/ui/desktop/app_view.fxml | |||
| @@ -131,6 +131,11 @@ | |||
| 131 | <children> | 131 | <children> |
| 132 | <Label fx:id="statusBarLabel" styleClass="gm-text-sm, gm-font-mono, gm-text-ink2" /> | 132 | <Label fx:id="statusBarLabel" styleClass="gm-text-sm, gm-font-mono, gm-text-ink2" /> |
| 133 | <Region HBox.hgrow="ALWAYS" /> | 133 | <Region HBox.hgrow="ALWAYS" /> |
| 134 | <Button fx:id="chatButton" onAction="#handleChatToggled" styleClass="gm-link-button"> | ||
| 135 | <tooltip> | ||
| 136 | <Tooltip text="Chat" /> | ||
| 137 | </tooltip> | ||
| 138 | </Button> | ||
| 134 | <Button fx:id="ejectButton" onAction="#handleEjectFile" styleClass="gm-link-button" text="" visible="false" /> | 139 | <Button fx:id="ejectButton" onAction="#handleEjectFile" styleClass="gm-link-button" text="" visible="false" /> |
| 135 | </children> | 140 | </children> |
| 136 | </HBox> | 141 | </HBox> |
| @@ -138,6 +143,14 @@ | |||
| 138 | </BorderPane> | 143 | </BorderPane> |
| 139 | </content> | 144 | </content> |
| 140 | </ScrollPane> | 145 | </ScrollPane> |
| 146 | <StackPane alignment="BOTTOM_RIGHT" pickOnBounds="false"> | ||
| 147 | <padding> | ||
| 148 | <Insets bottom="30.0" right="14.0" /> | ||
| 149 | </padding> | ||
| 150 | <children> | ||
| 151 | <fx:include fx:id="chatPanel" managed="false" source="controllers/chat_panel.fxml" visible="false" /> | ||
| 152 | </children> | ||
| 153 | </StackPane> | ||
| 141 | <StackPane fx:id="dialogContainer" mouseTransparent="true" visible="false"> | 154 | <StackPane fx:id="dialogContainer" mouseTransparent="true" visible="false"> |
| 142 | <children> | 155 | <children> |
| 143 | <fx:include fx:id="loadDialog" managed="false" source="controllers/dialog_load.fxml" visible="false" /> | 156 | <fx:include fx:id="loadDialog" managed="false" source="controllers/dialog_load.fxml" visible="false" /> |
diff --git a/ui-fx/src/main/resources/market/guess/ui/desktop/controllers/chat_panel.fxml b/ui-fx/src/main/resources/market/guess/ui/desktop/controllers/chat_panel.fxml new file mode 100644 index 0000000..8c65cb1 --- /dev/null +++ b/ui-fx/src/main/resources/market/guess/ui/desktop/controllers/chat_panel.fxml | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | |||
| 3 | <?import javafx.geometry.Insets?> | ||
| 4 | <?import javafx.scene.control.Button?> | ||
| 5 | <?import javafx.scene.control.Label?> | ||
| 6 | <?import javafx.scene.control.ScrollPane?> | ||
| 7 | <?import javafx.scene.control.TextField?> | ||
| 8 | <?import javafx.scene.layout.HBox?> | ||
| 9 | <?import javafx.scene.layout.VBox?> | ||
| 10 | |||
| 11 | <VBox maxHeight="380.0" maxWidth="320.0" minWidth="320.0" pickOnBounds="false" prefHeight="380.0" prefWidth="320.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="market.guess.ui.desktop.controllers.ChatPanelController"> | ||
| 12 | <padding> | ||
| 13 | <Insets bottom="6.0" /> | ||
| 14 | </padding> | ||
| 15 | <children> | ||
| 16 | <VBox pickOnBounds="false" spacing="8.0" styleClass="gm-card, gm-chat-drawer" VBox.vgrow="ALWAYS"> | ||
| 17 | <padding> | ||
| 18 | <Insets bottom="12.0" left="12.0" right="12.0" top="12.0" /> | ||
| 19 | </padding> | ||
| 20 | <children> | ||
| 21 | <Label styleClass="gm-text-base, gm-font-semibold, gm-text-ink" text="Chat" /> | ||
| 22 | <ScrollPane fx:id="scroll" fitToWidth="true" hbarPolicy="NEVER" styleClass="gm-scroll-transparent" VBox.vgrow="ALWAYS"> | ||
| 23 | <content> | ||
| 24 | <VBox fx:id="messages" spacing="9.0" /> | ||
| 25 | </content> | ||
| 26 | </ScrollPane> | ||
| 27 | <HBox spacing="8.0"> | ||
| 28 | <children> | ||
| 29 | <TextField fx:id="input" onAction="#handleSend" promptText="Message everyone" styleClass="gm-textfield" HBox.hgrow="ALWAYS" /> | ||
| 30 | <Button minWidth="-Infinity" onAction="#handleSend" styleClass="gm-btn, gm-btn-primary" text="Send" /> | ||
| 31 | </children> | ||
| 32 | </HBox> | ||
| 33 | </children> | ||
| 34 | </VBox> | ||
| 35 | </children> | ||
| 36 | </VBox> | ||
diff --git a/ui-fx/src/main/resources/market/guess/ui/desktop/theme.css b/ui-fx/src/main/resources/market/guess/ui/desktop/theme.css index 3f5d4b7..2f8246e 100644 --- a/ui-fx/src/main/resources/market/guess/ui/desktop/theme.css +++ b/ui-fx/src/main/resources/market/guess/ui/desktop/theme.css | |||
| @@ -523,6 +523,14 @@ | |||
| 523 | -fx-border-width: 0; | 523 | -fx-border-width: 0; |
| 524 | } | 524 | } |
| 525 | 525 | ||
| 526 | .gm-link-button:selected { | ||
| 527 | -fx-text-fill: -gm-accent; | ||
| 528 | } | ||
| 529 | |||
| 530 | .gm-chat-drawer { | ||
| 531 | -fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.3), 18, 0, 0, 4); | ||
| 532 | } | ||
| 533 | |||
| 526 | .gm-toast { | 534 | .gm-toast { |
| 527 | -fx-background-color: -gm-ink; | 535 | -fx-background-color: -gm-ink; |
| 528 | -fx-text-fill: -gm-bg; | 536 | -fx-text-fill: -gm-bg; |