Merge pull request #187 from informatik-ag-ngl/f/do_a_barrel_roll
implemented "DO A BARREL ROLL!" - Easteregg
This commit is contained in:
commit
7eefaa3556
@ -6,21 +6,26 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javafx.animation.RotateTransition;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.Alert.AlertType;
|
import javafx.scene.control.Alert.AlertType;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
|
import javafx.util.Duration;
|
||||||
|
|
||||||
import envoy.client.data.*;
|
import envoy.client.data.*;
|
||||||
import envoy.client.data.audio.AudioRecorder;
|
import envoy.client.data.audio.AudioRecorder;
|
||||||
@ -50,6 +55,9 @@ import envoy.util.EnvoyLog;
|
|||||||
*/
|
*/
|
||||||
public final class ChatScene implements Restorable {
|
public final class ChatScene implements Restorable {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private GridPane scene;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label contactLabel;
|
private Label contactLabel;
|
||||||
|
|
||||||
@ -71,6 +79,9 @@ public final class ChatScene implements Restorable {
|
|||||||
@FXML
|
@FXML
|
||||||
private Button settingsButton;
|
private Button settingsButton;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button rotateButton;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextArea messageTextArea;
|
private TextArea messageTextArea;
|
||||||
|
|
||||||
@ -121,6 +132,7 @@ public final class ChatScene implements Restorable {
|
|||||||
voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE)));
|
voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE)));
|
||||||
attachmentButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("attachment", DEFAULT_ICON_SIZE)));
|
attachmentButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("attachment", DEFAULT_ICON_SIZE)));
|
||||||
attachmentView.setImage(DEFAULT_ATTACHMENT_VIEW_IMAGE);
|
attachmentView.setImage(DEFAULT_ATTACHMENT_VIEW_IMAGE);
|
||||||
|
rotateButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("rotate", (int) (DEFAULT_ICON_SIZE * 1.5))));
|
||||||
|
|
||||||
// Listen to received messages
|
// Listen to received messages
|
||||||
eventBus.register(MessageCreationEvent.class, e -> {
|
eventBus.register(MessageCreationEvent.class, e -> {
|
||||||
@ -346,6 +358,28 @@ public final class ChatScene implements Restorable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotates every element in our application by 360° in at most 2.75s.
|
||||||
|
*
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
|
@FXML
|
||||||
|
private void doABarrelRoll() {
|
||||||
|
// 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, userList, voiceButton };
|
||||||
|
final var random = new Random();
|
||||||
|
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);
|
||||||
|
rotateTransition.play();
|
||||||
|
// This is needed as for some strange reason objects could stop before being
|
||||||
|
// rotated back to 0°
|
||||||
|
rotateTransition.setOnFinished(e -> node.setRotate(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the text length of the {@code messageTextArea}, adjusts the
|
* Checks the text length of the {@code messageTextArea}, adjusts the
|
||||||
* {@code remainingChars} label and checks whether to send the message
|
* {@code remainingChars} label and checks whether to send the message
|
||||||
|
@ -15,9 +15,10 @@
|
|||||||
<?import javafx.scene.layout.GridPane?>
|
<?import javafx.scene.layout.GridPane?>
|
||||||
<?import javafx.scene.layout.RowConstraints?>
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
|
|
||||||
<GridPane hgap="5.0" maxHeight="-Infinity" maxWidth="-Infinity"
|
<GridPane fx:id="scene" hgap="5.0" maxHeight="-Infinity"
|
||||||
minHeight="400.0" minWidth="350.0" prefHeight="400.0" prefWidth="600.0"
|
maxWidth="-Infinity" minHeight="400.0" minWidth="350.0"
|
||||||
vgap="2.0" xmlns="http://javafx.com/javafx/11.0.1"
|
prefHeight="400.0" prefWidth="600.0" vgap="2.0"
|
||||||
|
xmlns="http://javafx.com/javafx/11.0.1"
|
||||||
xmlns:fx="http://javafx.com/fxml/1"
|
xmlns:fx="http://javafx.com/fxml/1"
|
||||||
fx:controller="envoy.client.ui.controller.ChatScene">
|
fx:controller="envoy.client.ui.controller.ChatScene">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
@ -99,6 +100,12 @@
|
|||||||
<Insets right="10.0" />
|
<Insets right="10.0" />
|
||||||
</GridPane.margin>
|
</GridPane.margin>
|
||||||
<buttons>
|
<buttons>
|
||||||
|
<Button fx:id="rotateButton" mnemonicParsing="false"
|
||||||
|
onAction="#doABarrelRoll">
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
|
</padding>
|
||||||
|
</Button>
|
||||||
<Button fx:id="attachmentButton" disable="true"
|
<Button fx:id="attachmentButton" disable="true"
|
||||||
mnemonicParsing="false" onAction="#attachmentButtonClicked">
|
mnemonicParsing="false" onAction="#attachmentButtonClicked">
|
||||||
<padding>
|
<padding>
|
||||||
|
BIN
src/main/resources/icons/dark/rotate.png
Normal file
BIN
src/main/resources/icons/dark/rotate.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
BIN
src/main/resources/icons/light/rotate.png
Normal file
BIN
src/main/resources/icons/light/rotate.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
Reference in New Issue
Block a user