Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.cottonlesergal.nubot.app.controllers;
- import com.cottonlesergal.nubot.bot.BotRunner;
- import com.cottonlesergal.nubot.bot.modules.PropertyChange;
- import com.cottonlesergal.nubot.main.modules.DebugPrinter;
- import javafx.application.Platform;
- import javafx.beans.property.SimpleStringProperty;
- import javafx.beans.property.StringProperty;
- import javafx.collections.ObservableList;
- import javafx.concurrent.Task;
- import javafx.geometry.Rectangle2D;
- import javafx.scene.control.Label;
- import javafx.scene.control.ProgressBar;
- import javafx.scene.effect.BlurType;
- import javafx.scene.effect.DropShadow;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- import javafx.scene.input.MouseEvent;
- import javafx.scene.layout.AnchorPane;
- import javafx.scene.paint.Color;
- import javafx.scene.paint.ImagePattern;
- import javafx.scene.shape.Circle;
- import javafx.stage.Screen;
- import javafx.stage.Stage;
- import net.dv8tion.jda.api.JDA;
- import net.dv8tion.jda.api.events.ReadyEvent;
- import net.dv8tion.jda.api.hooks.EventListener;
- import net.dv8tion.jda.api.hooks.ListenerAdapter;
- import com.jfoenix.controls.JFXButton;
- import java.beans.PropertyChangeListener;
- import java.beans.PropertyChangeSupport;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.ResourceBundle;
- import java.util.concurrent.Executors;
- import java.util.concurrent.ScheduledExecutorService;
- import java.util.concurrent.TimeUnit;
- import javafx.fxml.FXML;
- public class Menu extends ListenerAdapter {
- @FXML
- private ResourceBundle resources;
- @FXML
- private URL location;
- @FXML
- private AnchorPane moveablePane;
- @FXML
- private AnchorPane profileCard;
- @FXML
- private JFXButton loginManageButton;
- @FXML
- private AnchorPane usernameAndDiscriminatorPane;
- @FXML
- private Label discriminatorLabel;
- @FXML
- private Label usernameLabel;
- @FXML
- private Circle userAvatar;
- @FXML
- private AnchorPane userStats;
- @FXML
- private AnchorPane signInText;
- @FXML
- private JFXButton profileSettingButton;
- @FXML
- private ImageView close;
- @FXML
- private ImageView maximize;
- @FXML
- private ImageView minimize;
- @FXML
- private Label ShardInfoLabel;
- @FXML
- private Label PingLabel;
- private DebugPrinter debug = new DebugPrinter();
- private double[] scale = new double[4];
- private boolean avatarDynamicBackdropIsOn = true;
- private double xOffset = 0;
- private double yOffset = 0;
- @FXML
- private StringProperty ShardStatus = new SimpleStringProperty();
- private String TestText = "";
- PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
- @FXML
- void initialize() {
- assert moveablePane != null : "fx:id=\"moveablePane\" was not injected: check your FXML file 'Menu.fxml'.";
- assert profileCard != null : "fx:id=\"profileCard\" was not injected: check your FXML file 'Menu.fxml'.";
- assert loginManageButton != null : "fx:id=\"loginManageButton\" was not injected: check your FXML file 'Menu.fxml'.";
- assert usernameAndDiscriminatorPane != null : "fx:id=\"usernameAndDiscriminatorPane\" was not injected: check your FXML file 'Menu.fxml'.";
- assert discriminatorLabel != null : "fx:id=\"discriminatorLabel\" was not injected: check your FXML file 'Menu.fxml'.";
- assert usernameLabel != null : "fx:id=\"usernameLabel\" was not injected: check your FXML file 'Menu.fxml'.";
- assert userAvatar != null : "fx:id=\"userAvatar\" was not injected: check your FXML file 'Menu.fxml'.";
- assert userStats != null : "fx:id=\"userStats\" was not injected: check your FXML file 'Menu.fxml'.";
- assert signInText != null : "fx:id=\"signInText\" was not injected: check your FXML file 'Menu.fxml'.";
- assert profileSettingButton != null : "fx:id=\"profileSettingButton\" was not injected: check your FXML file 'Menu.fxml'.";
- assert close != null : "fx:id=\"close\" was not injected: check your FXML file 'Menu.fxml'.";
- assert maximize != null : "fx:id=\"maximize\" was not injected: check your FXML file 'Menu.fxml'.";
- assert minimize != null : "fx:id=\"minimize\" was not injected: check your FXML file 'Menu.fxml'.";
- assert ShardInfoLabel != null : "fx:id=\"ShardInfoLabel\" was not injected: check your FXML file 'Menu.fxml'.";
- assert PingLabel != null : "fx:id=\"PingLabel\" was not injected: check your FXML file 'Menu.fxml'.";
- ShardInfoLabel.setText("Loading...");
- //ShardInfoLabel.textProperty().bind(ShardStatus);
- setUserAvatar("/media/images/CottonIconFixed.png");
- //userStats.setVisible(false);
- //profileSettingButton.setVisible(false);
- loginManageButton.setText("Log Out");
- usernameAndDiscriminatorPane.setEffect(new DropShadow(+15d, 0d, +1d, Color.rgb(22, 30, 45, 0.46)));
- /*setShardInfoLabelText("Yo, wtf");*/
- ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
- exec.scheduleAtFixedRate(() -> {
- System.out.println("BoundEntity2: " + TestText);
- ShardInfoLabel.setText(ShardStatus.toString().replace("StringProperty [value:", "").replace("]", ""));
- }, 0, 5, TimeUnit.SECONDS);
- }
- @FXML
- @Override
- public void onReady(ReadyEvent event) {
- super.onReady(event);
- //System.out.println((event.getJDA().getShardInfo().getShardId() + 1) + " of " + event.getJDA().getShardInfo().getShardTotal() + " shards online");
- new Thread(() -> {
- System.out.println("Running a new Thread!!!!");
- Platform.runLater(() -> {
- //ShardInfoLabel.setText((event.getJDA().getShardInfo().getShardId() + 1) + " of " + event.getJDA().getShardInfo().getShardTotal() + " shards online");
- if(!((event.getJDA().getShardInfo().getShardId() + 1) + " of " + event.getJDA().getShardInfo().getShardTotal() + " shards online").toLowerCase().equals("StringProperty [value: null]")) {
- ShardStatus.set((event.getJDA().getShardInfo().getShardId() + 1) + " of " + event.getJDA().getShardInfo().getShardTotal() + " shards online");
- TestText = ShardStatus.toString().replace("StringProperty [value:", "").replace("]", "");
- System.out.println("THIS IS WHAT TEXT SHOULD BE: " + TestText);
- }
- //System.out.println("Running a new Thread!!!! 222222222222222222");
- });
- }).start();
- System.out.println("BoundEntity1: " + ShardStatus);
- }
- @FXML
- void setShardInfoLabelText(ReadyEvent event){
- ShardInfoLabel.setText((event.getJDA().getShardInfo().getShardId() + 1) + " of " + event.getJDA().getShardInfo().getShardTotal() + " shards online");
- }
- @FXML
- void closeApplication(MouseEvent event) {
- System.exit(0);
- Stage stage = (Stage) close.getScene().getWindow();
- stage.close();
- }
- @FXML
- void minimizeApplication(MouseEvent event) {
- Stage stage = (Stage) minimize.getScene().getWindow();
- stage.setIconified(true);
- }
- @FXML
- void maximizeApplication(MouseEvent event){
- Stage stage = (Stage) maximize.getScene().getWindow();
- ObservableList<Screen> screens = Screen.getScreensForRectangle(new Rectangle2D(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()));
- Rectangle2D bounds = screens.get(0).getVisualBounds();
- if((stage.getX() != bounds.getMinX()) && (stage.getY() != bounds.getMinY()) && (stage.getWidth() != bounds.getWidth()) && (stage.getHeight() != bounds.getHeight())) {
- this.scale[0] = stage.getX();
- this.scale[1] = stage.getY();
- this.scale[2] = stage.getWidth();
- this.scale[3] = stage.getHeight();
- stage.setX(bounds.getMinX());
- stage.setY(bounds.getMinY());
- stage.setWidth(bounds.getWidth());
- stage.setHeight(bounds.getHeight());
- }else {
- stage.setX(this.scale[0]);
- stage.setY(this.scale[1]);
- stage.setWidth(this.scale[2]);
- stage.setHeight(this.scale[3]);
- }
- }
- @FXML
- void getScene(MouseEvent event) {
- xOffset = event.getSceneX();
- yOffset = event.getSceneY();
- }
- @FXML
- void moveScene(MouseEvent event) {
- Stage stage = (Stage) moveablePane.getScene().getWindow();
- stage.setX(event.getScreenX() - xOffset);
- stage.setY(event.getScreenY() - yOffset);
- }
- public String getShardInfoLabelText() {
- return this.ShardInfoLabel.getText();
- }
- public void setShardInfoLabelText(String text) {
- changeSupport.firePropertyChange("ShardInfo", this.ShardInfoLabel.getText(), text);
- this.ShardInfoLabel.setText(text);
- }
- /*public String getCity() {
- return city;
- }
- public void setCity(String city) {
- changeSupport.firePropertyChange("city", this.city, city);
- this.city = city;
- }*/
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- changeSupport.addPropertyChangeListener(listener);
- }
- public void toggleDynamicBackground(){
- avatarDynamicBackdropIsOn = !avatarDynamicBackdropIsOn;
- }
- public void setUserAvatar(String url){
- userAvatar.setStroke(Color.rgb(240, 64, 192));
- String image = getClass().getResource(url).toExternalForm();
- Image avatar = new Image(image);
- double size = (avatar.getHeight() > avatar.getWidth()) ? avatar.getHeight() : avatar.getWidth();
- double newHeight = avatar.getHeight();
- double newWidth = avatar.getWidth();
- debug.print("Image size is: " + avatar.getHeight() + "x" + avatar.getWidth());
- debug.println(" with the " + ((avatar.getHeight() > avatar.getWidth()) ? "height " : "width ") + "being the largest at: " + size + "px.");
- debug.println("Image is " + ((size/100)) + " times the size it should be... " + ((size/100 > 0) ? "resizing" : "not resizing"));
- if(avatar.getWidth()/100 > 0 && avatar.getHeight()/100 > 0){
- newHeight = avatar.getHeight()/((avatar.getHeight()/100));
- newWidth = avatar.getWidth()/((avatar.getWidth()/100));
- debug.println("Image has been resized to the following: " + Math.floor(newHeight) + "x" + Math.floor(newWidth) + "px.");
- }
- Image im = new Image(image, Math.floor(newWidth), Math.floor(newHeight), true, true, false);
- debug.println("Actual image size is: " + im.getHeight() + "x" + im.getWidth() + "px.");
- userAvatar.styleProperty().setValue("-fx-background-size: cover;");
- userAvatar.setFill(new ImagePattern(im));
- if(avatarDynamicBackdropIsOn) {
- ArrayList<ArrayList<Double>> rgbValues = new ArrayList<>();
- for (int heightIndex = 0; heightIndex < avatar.getHeight(); heightIndex++) {
- for (int widthIndex = 0; widthIndex < avatar.getWidth(); widthIndex++) {
- double red = avatar.getPixelReader().getColor(widthIndex, heightIndex).getRed();
- double green = avatar.getPixelReader().getColor(widthIndex, heightIndex).getGreen();
- double blue = avatar.getPixelReader().getColor(widthIndex, heightIndex).getBlue();
- ArrayList<Double> colorVals = new ArrayList<>();
- colorVals.add(red*255);
- colorVals.add(green*255);
- colorVals.add(blue*255);
- rgbValues.add(colorVals);
- }
- }
- int newRed = 0;
- int newGreen = 0;
- int newBlue = 0;
- int sumOfColors = 0;
- for (ArrayList<Double> rgbValue : rgbValues) {
- if(!((rgbValue.get(0) > 220 || rgbValue.get(0) < 30) && (rgbValue.get(1) > 220 || rgbValue.get(1) < 30) && (rgbValue.get(2) > 220 || rgbValue.get(2) < 30))){
- sumOfColors++;
- newRed += rgbValue.get(0);
- newGreen += rgbValue.get(1);
- newBlue += rgbValue.get(2);
- }
- }
- newRed = newRed/((sumOfColors != 0)? sumOfColors : 1);
- newGreen = newGreen/((sumOfColors != 0)? sumOfColors : 1);
- newBlue = newBlue/((sumOfColors != 0)? sumOfColors : 1);
- userAvatar.setStroke(Color.rgb(newRed, newGreen, newBlue));
- userAvatar.setEffect(new DropShadow(+15d, 0d, +1d, Color.rgb(newRed, newGreen, newBlue)));
- userAvatar.setEffect(new DropShadow(BlurType.GAUSSIAN, Color.rgb(newRed, newGreen, newBlue), +18d, 0.5, 0d, 0d));
- /*userAvatar.setEffect(new DropShadow(+45d, +15d, 0d, Color.rgb(newRed, newGreen, newBlue)));*/
- }
- }
- public void setShardStatus(String shardStatus) {
- this.ShardStatus.set(shardStatus);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement