Added SystemCommandsMap in Chatscene and "DABR"-command

This commit is contained in:
delvh 2020-07-23 17:18:53 +02:00
parent 42184c47f7
commit d3c2eb4ff7
1 changed files with 26 additions and 7 deletions

View File

@ -30,6 +30,7 @@ import javafx.util.Duration;
import envoy.client.data.*;
import envoy.client.data.audio.AudioRecorder;
import envoy.client.data.commands.SystemCommandsMap;
import envoy.client.event.MessageCreationEvent;
import envoy.client.net.Client;
import envoy.client.net.WriteProxy;
@ -107,6 +108,8 @@ public final class ChatScene implements Restorable {
private Attachment pendingAttachment;
private boolean postingPermanentlyDisabled;
private final SystemCommandsMap messageTextAreaCommands = new SystemCommandsMap();
private static final Settings settings = Settings.getInstance();
private static final EventBus eventBus = EventBus.getInstance();
private static final Logger logger = EnvoyLog.getLogger(ChatScene.class);
@ -126,6 +129,8 @@ public final class ChatScene implements Restorable {
// Initialize message and user rendering
messageList.setCellFactory(new ListCellFactory<>(MessageControl::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)));
voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE)));
@ -193,7 +198,7 @@ public final class ChatScene implements Restorable {
switch (e.getOperationType()) {
case ADD:
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));
break;
case REMOVE:
@ -382,14 +387,27 @@ public final class ChatScene implements Restorable {
*/
@FXML
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
final var rotatableNodes = new Node[] { attachmentButton, attachmentView, contactLabel, infoLabel, messageList, messageTextArea,
postButton, remainingChars, rotateButton, scene, settingsButton, chatList, voiceButton };
final var random = new Random();
final var rotatableNodes = new Node[] { attachmentButton, attachmentView, contactLabel, infoLabel, messageList, messageTextArea, postButton,
remainingChars, rotateButton, scene, settingsButton, chatList, voiceButton };
for (final var node : rotatableNodes) {
// Defines at most four whole rotation in at most 4s
final var rotateTransition = new RotateTransition(Duration.seconds(random.nextDouble() * 3 + 1), node);
rotateTransition.setByAngle((random.nextInt(3) + 1) * 360);
// Sets the animation duration to {animationTime}
final var rotateTransition = new RotateTransition(Duration.seconds(animationTime), node);
// rotates every element {rotations} times
rotateTransition.setByAngle(rotations * 360);
rotateTransition.play();
// This is needed as for some strange reason objects could stop before being
// rotated back to 0°
@ -481,6 +499,7 @@ public final class ChatScene implements Restorable {
return;
}
final var text = messageTextArea.getText().strip();
messageTextAreaCommands.checkForCommands(text);
try {
// Creating the message and its metadata
final var builder = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator())