|
| 1 | +package drzed.GUI; |
| 2 | + |
| 3 | +import drzed.Configs; |
| 4 | +import drzed.Data.Ability; |
| 5 | +import drzed.Data.Encounter; |
| 6 | +import drzed.MagicParser; |
| 7 | +import drzed.Main; |
| 8 | +import javafx.application.Platform; |
| 9 | +import javafx.beans.property.SimpleDoubleProperty; |
| 10 | +import javafx.beans.property.SimpleIntegerProperty; |
| 11 | +import javafx.beans.property.SimpleStringProperty; |
| 12 | +import javafx.collections.FXCollections; |
| 13 | +import javafx.concurrent.Task; |
| 14 | +import javafx.event.ActionEvent; |
| 15 | +import javafx.fxml.FXML; |
| 16 | +import javafx.scene.control.*; |
| 17 | +import javafx.scene.input.MouseEvent; |
| 18 | +import javafx.stage.FileChooser; |
| 19 | + |
| 20 | +import java.io.File; |
| 21 | +import java.io.IOException; |
| 22 | +import java.text.DecimalFormat; |
| 23 | + |
| 24 | +@SuppressWarnings("all") |
| 25 | +public class CondensedController { |
| 26 | + @FXML public MenuItem fileB; |
| 27 | + @FXML public Menu menuD; |
| 28 | + @FXML public TableView<Ability> statsTbl; |
| 29 | + @FXML public TableColumn<Ability, String> abilityCol; |
| 30 | + @FXML public TableColumn<Ability, Number> damageCol2; |
| 31 | + @FXML public TableColumn<Ability, Number> dpsCol2; |
| 32 | + @FXML public TableColumn<Ability, Number> hitsCol2; |
| 33 | + @FXML public TableColumn<Ability, Number> abilityShareCol; |
| 34 | + |
| 35 | + @FXML |
| 36 | + private void initialize() { |
| 37 | + setFactories(); |
| 38 | + |
| 39 | + Task task = new Task<Void>() { |
| 40 | + @Override public Void call() { |
| 41 | + byte frms = 0; |
| 42 | + while (true) { |
| 43 | + try { |
| 44 | + update(); |
| 45 | + Thread.sleep(Configs.guiPollRate); |
| 46 | + if (frms > 4) { |
| 47 | + frms = 0; |
| 48 | + } |
| 49 | + frms++; |
| 50 | + } catch (InterruptedException e) { |
| 51 | + e.printStackTrace(); |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + }; |
| 56 | + new Thread(task).start(); |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | + private static Encounter current; |
| 61 | + public void update() { |
| 62 | + updateAllData(); |
| 63 | + } |
| 64 | + |
| 65 | + private void updateAllData() { |
| 66 | + if ((current == null && MagicParser.getCurrentEncounter() != null) || current != MagicParser.getCurrentEncounter()) { |
| 67 | + if (MagicParser.getCurrentEncounter() != null) |
| 68 | + resetData(); |
| 69 | + } |
| 70 | + |
| 71 | + if (current != null) { |
| 72 | + updateAbilityData(); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + private void resetData() { |
| 77 | + System.out.println("RESETTING DATA"); |
| 78 | + current = MagicParser.getCurrentEncounter(); |
| 79 | + Platform.runLater(() -> statsTbl.getItems().clear()); |
| 80 | + } |
| 81 | + |
| 82 | + public void loadEncounter(ActionEvent actionEvent) { |
| 83 | + FileChooser chooser = new FileChooser(); |
| 84 | + FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("ENCOUNTERLOG files (CombatLog*.log)", "CombatLog*.log"); |
| 85 | + chooser.getExtensionFilters().add(extFilter); |
| 86 | + chooser.setSelectedExtensionFilter(extFilter); |
| 87 | + chooser.setInitialDirectory(new File("./data/")); |
| 88 | + String enc = chooser.showOpenDialog(Main.stage).getName(); |
| 89 | + if (!enc.isEmpty()) { |
| 90 | + Main.importEnc(enc); |
| 91 | + Platform.runLater(() -> resetData()); |
| 92 | + Platform.runLater(() -> updateAllData()); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + public void quit(ActionEvent actionEvent) { |
| 97 | + Platform.exit(); |
| 98 | + System.exit(0); |
| 99 | + } |
| 100 | + |
| 101 | + public void close(ActionEvent actionEvent) { |
| 102 | + Platform.exit(); |
| 103 | + System.exit(0); |
| 104 | + } |
| 105 | + |
| 106 | + double xOffset, yOffset; |
| 107 | + public void onDrag(MouseEvent mouseEvent) { |
| 108 | + Main.streamStage.setX(mouseEvent.getScreenX() + xOffset); |
| 109 | + Main.streamStage.setY(mouseEvent.getScreenY() + yOffset); |
| 110 | + } |
| 111 | + |
| 112 | + public void onPress(MouseEvent mouseEvent) { |
| 113 | + xOffset = Main.streamStage.getX() - mouseEvent.getScreenX(); |
| 114 | + yOffset = Main.streamStage.getY() - mouseEvent.getScreenY(); |
| 115 | + } |
| 116 | + |
| 117 | + private void setFactories() { |
| 118 | + abilityCol.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().name)); |
| 119 | + damageCol2.setCellValueFactory(cellData -> new SimpleIntegerProperty(cellData.getValue().getTotalDamage())); |
| 120 | + dpsCol2.setCellValueFactory(cellData -> new SimpleIntegerProperty(cellData.getValue().getDPH())); |
| 121 | + abilityShareCol.setCellValueFactory(cellData -> new SimpleDoubleProperty(current != null && current.getFilterEntity() != null ? current.getFilterEntity().getEffectiveness(cellData.getValue().getTotalDamage()) : 0)); |
| 122 | + hitsCol2.setCellValueFactory(cellData -> new SimpleIntegerProperty(cellData.getValue().hits)); |
| 123 | + |
| 124 | + damageCol2.setCellFactory(tc -> new TableCell<Ability, Number>() { |
| 125 | + @Override |
| 126 | + protected void updateItem(Number value, boolean empty) { |
| 127 | + super.updateItem(value, empty); |
| 128 | + if (!empty) setText(DecimalFormat.getNumberInstance().format(value.intValue())); |
| 129 | + } |
| 130 | + }); |
| 131 | + dpsCol2.setCellFactory(tc -> new TableCell<Ability, Number>() { |
| 132 | + @Override |
| 133 | + protected void updateItem(Number value, boolean empty) { |
| 134 | + super.updateItem(value, empty); |
| 135 | + if (!empty) setText(DecimalFormat.getNumberInstance().format(value.intValue())); |
| 136 | + } |
| 137 | + }); |
| 138 | + hitsCol2.setCellFactory(tc -> new TableCell<Ability, Number>() { |
| 139 | + @Override |
| 140 | + protected void updateItem(Number value, boolean empty) { |
| 141 | + super.updateItem(value, empty); |
| 142 | + if (!empty) setText(DecimalFormat.getNumberInstance().format(value.intValue())); |
| 143 | + } |
| 144 | + }); |
| 145 | + abilityShareCol.setCellFactory(tc -> new TableCell<Ability, Number>() { |
| 146 | + @Override |
| 147 | + protected void updateItem(Number value, boolean empty) { |
| 148 | + super.updateItem(value, empty); |
| 149 | + if (!empty) setText(String.format("%1$,.1f", value.doubleValue()) + "%"); |
| 150 | + } |
| 151 | + }); |
| 152 | + } |
| 153 | + |
| 154 | + private void updateAbilityData() { |
| 155 | + if (current.getFilterEntity() != null) { |
| 156 | + Platform.runLater(() -> statsTbl.setItems(FXCollections.observableArrayList(current.getFilterEntity().abilityList))); |
| 157 | + } |
| 158 | + if (current.getFilterEntity() != null && !statsTbl.getItems().isEmpty() && !current.getFilterEntity().abilityList.isEmpty()) { |
| 159 | + for (Ability ability : current.getFilterEntity().abilityList) { |
| 160 | + if (!statsTbl.getItems().contains(ability)) { |
| 161 | + statsTbl.getItems().add(ability); |
| 162 | + } |
| 163 | + } |
| 164 | + statsTbl.getItems().sort((a,b) -> -(a.totalDamage - b.totalDamage)); |
| 165 | + } |
| 166 | + statsTbl.sort(); |
| 167 | + statsTbl.refresh(); |
| 168 | + } |
| 169 | + |
| 170 | + public static String replaceLast(String text, String regex, String replacement) { |
| 171 | + return text.replaceFirst("(?s)"+regex+"(?!.*?"+regex+")", replacement); |
| 172 | + } |
| 173 | + |
| 174 | + public void onClick(MouseEvent mouseEvent) { |
| 175 | + updateAllData(); |
| 176 | + } |
| 177 | +} |
0 commit comments