Added SystemCommandsMap in Chatscene and "DABR"-command
This commit is contained in:
parent
a013802d11
commit
85cfa2c789
@ -30,6 +30,7 @@ import javafx.util.Duration;
|
|||||||
|
|
||||||
import envoy.client.data.*;
|
import envoy.client.data.*;
|
||||||
import envoy.client.data.audio.AudioRecorder;
|
import envoy.client.data.audio.AudioRecorder;
|
||||||
|
import envoy.client.data.commands.SystemCommandsMap;
|
||||||
import envoy.client.event.MessageCreationEvent;
|
import envoy.client.event.MessageCreationEvent;
|
||||||
import envoy.client.net.Client;
|
import envoy.client.net.Client;
|
||||||
import envoy.client.net.WriteProxy;
|
import envoy.client.net.WriteProxy;
|
||||||
@ -107,6 +108,8 @@ public final class ChatScene implements Restorable {
|
|||||||
private Attachment pendingAttachment;
|
private Attachment pendingAttachment;
|
||||||
private boolean postingPermanentlyDisabled;
|
private boolean postingPermanentlyDisabled;
|
||||||
|
|
||||||
|
private final SystemCommandsMap messageTextAreaCommands = new SystemCommandsMap();
|
||||||
|
|
||||||
private static final Settings settings = Settings.getInstance();
|
private static final Settings settings = Settings.getInstance();
|
||||||
private static final EventBus eventBus = EventBus.getInstance();
|
private static final EventBus eventBus = EventBus.getInstance();
|
||||||
private static final Logger logger = EnvoyLog.getLogger(ChatScene.class);
|
private static final Logger logger = EnvoyLog.getLogger(ChatScene.class);
|
||||||
@ -126,6 +129,8 @@ public final class ChatScene implements Restorable {
|
|||||||
// Initialize message and user rendering
|
// Initialize message and user rendering
|
||||||
messageList.setCellFactory(new ListCellFactory<>(MessageControl::new));
|
messageList.setCellFactory(new ListCellFactory<>(MessageControl::new));
|
||||||
chatList.setCellFactory(new ListCellFactory<>(ChatControl::new));
|
chatList.setCellFactory(new ListCellFactory<>(ChatControl::new));
|
||||||
|
messageTextAreaCommands.addNoArgCommand("DABR", text -> { doABarrelRoll(); return null; });
|
||||||
|
messageTextAreaCommands.addNoArgCommand("DoABarrelRoll", text -> { doABarrelRoll(); return null; });
|
||||||
|
|
||||||
settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", DEFAULT_ICON_SIZE)));
|
settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", DEFAULT_ICON_SIZE)));
|
||||||
voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE)));
|
voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE)));
|
||||||
@ -193,7 +198,7 @@ public final class ChatScene implements Restorable {
|
|||||||
switch (e.getOperationType()) {
|
switch (e.getOperationType()) {
|
||||||
case ADD:
|
case ADD:
|
||||||
if (contact instanceof User) localDB.getUsers().put(contact.getName(), (User) contact);
|
if (contact instanceof User) localDB.getUsers().put(contact.getName(), (User) contact);
|
||||||
Chat chat = contact instanceof User ? new Chat(contact) : new GroupChat(client.getSender(), contact);
|
final Chat chat = contact instanceof User ? new Chat(contact) : new GroupChat(client.getSender(), contact);
|
||||||
Platform.runLater(() -> chatList.getItems().add(chat));
|
Platform.runLater(() -> chatList.getItems().add(chat));
|
||||||
break;
|
break;
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
@ -382,14 +387,27 @@ public final class ChatScene implements Restorable {
|
|||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
private void doABarrelRoll() {
|
private void doABarrelRoll() {
|
||||||
|
final var random = new Random();
|
||||||
|
doABarrelRoll(random.nextInt(3) + 1, random.nextDouble() * 3 + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotates every element in our application by {@code rotations}*360° in
|
||||||
|
* {@code an}.
|
||||||
|
*
|
||||||
|
* @param rotations the amount of times the scene is rotated by 360°
|
||||||
|
* @param animationTime the time in seconds that this animation lasts
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
|
private void doABarrelRoll(int rotations, double animationTime) {
|
||||||
// contains all Node objects in ChatScene in alphabetical order
|
// contains all Node objects in ChatScene in alphabetical order
|
||||||
final var rotatableNodes = new Node[] { attachmentButton, attachmentView, contactLabel, infoLabel, messageList, messageTextArea,
|
final var rotatableNodes = new Node[] { attachmentButton, attachmentView, contactLabel, infoLabel, messageList, messageTextArea, postButton,
|
||||||
postButton, remainingChars, rotateButton, scene, settingsButton, chatList, voiceButton };
|
remainingChars, rotateButton, scene, settingsButton, chatList, voiceButton };
|
||||||
final var random = new Random();
|
|
||||||
for (final var node : rotatableNodes) {
|
for (final var node : rotatableNodes) {
|
||||||
// Defines at most four whole rotation in at most 4s
|
// Sets the animation duration to {animationTime}
|
||||||
final var rotateTransition = new RotateTransition(Duration.seconds(random.nextDouble() * 3 + 1), node);
|
final var rotateTransition = new RotateTransition(Duration.seconds(animationTime), node);
|
||||||
rotateTransition.setByAngle((random.nextInt(3) + 1) * 360);
|
// rotates every element {rotations} times
|
||||||
|
rotateTransition.setByAngle(rotations * 360);
|
||||||
rotateTransition.play();
|
rotateTransition.play();
|
||||||
// This is needed as for some strange reason objects could stop before being
|
// This is needed as for some strange reason objects could stop before being
|
||||||
// rotated back to 0°
|
// rotated back to 0°
|
||||||
@ -481,6 +499,7 @@ public final class ChatScene implements Restorable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final var text = messageTextArea.getText().strip();
|
final var text = messageTextArea.getText().strip();
|
||||||
|
messageTextAreaCommands.checkForCommands(text);
|
||||||
try {
|
try {
|
||||||
// Creating the message and its metadata
|
// Creating the message and its metadata
|
||||||
final var builder = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator())
|
final var builder = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator())
|
||||||
|
Reference in New Issue
Block a user