Skip to content

Commit 10c1ee1

Browse files
committed
Streamer Mode... kinda
1 parent 187e4c6 commit 10c1ee1

File tree

6 files changed

+224
-0
lines changed

6 files changed

+224
-0
lines changed
+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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+
}

src/drzed/GUI/ML_Condensed.fxml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.scene.control.Button?>
4+
<?import javafx.scene.control.Menu?>
5+
<?import javafx.scene.control.MenuBar?>
6+
<?import javafx.scene.control.TableColumn?>
7+
<?import javafx.scene.control.TableView?>
8+
<?import javafx.scene.layout.AnchorPane?>
9+
10+
<AnchorPane maxHeight="320.0" maxWidth="390.0" minHeight="320.0" minWidth="390.0" onMouseClicked="#onClick" onMouseDragged="#onDrag" onMousePressed="#onPress" prefHeight="320.0" prefWidth="390.0" stylesheets="@dark.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="drzed.GUI.CondensedController">
11+
<children>
12+
<MenuBar layoutY="2.0" onMouseClicked="#onClick" onMouseDragged="#onDrag" onMousePressed="#onPress" prefHeight="25.0" prefWidth="390.0" stylesheets="@dark.css" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
13+
<menus>
14+
<Menu fx:id="menuD" mnemonicParsing="false" text="Streamer DPS Tracker" />
15+
</menus>
16+
</MenuBar>
17+
<TableView fx:id="statsTbl" layoutX="8.0" layoutY="25.0" onMouseClicked="#onClick" onMouseDragged="#onDrag" onMousePressed="#onPress" prefHeight="299.0" prefWidth="391.0" stylesheets="@dark.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="25.0">
18+
<columns>
19+
<TableColumn fx:id="abilityCol" maxWidth="170.0" minWidth="80.0" prefWidth="130.0" text="Ability" />
20+
<TableColumn id="dmg" fx:id="damageCol2" maxWidth="160.0" minWidth="80.0" prefWidth="86.0" sortType="DESCENDING" text="Damage" />
21+
<TableColumn id="dph" fx:id="dpsCol2" maxWidth="100.0" minWidth="60.0" prefWidth="68.0" sortType="DESCENDING" text="DPH" />
22+
<TableColumn id="hts" fx:id="hitsCol2" maxWidth="80.0" minWidth="35.0" prefWidth="48.0" sortType="DESCENDING" text="Hits" />
23+
<TableColumn id="pct" fx:id="abilityShareCol" maxWidth="68.0" minWidth="35.0" prefWidth="40.0" sortType="DESCENDING" text="\%" />
24+
</columns>
25+
</TableView>
26+
<Button mnemonicParsing="false" onAction="#quit" text="Quit" AnchorPane.leftAnchor="350.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
27+
</children>
28+
</AnchorPane>

src/drzed/GUI/ML_ParserGUI.fxml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<MenuItem mnemonicParsing="false" onAction="#onFile" text="File.." />
2020
<MenuItem mnemonicParsing="false" onAction="#loadEncounter" text="Open Past Encounter" />
2121
<MenuItem mnemonicParsing="false" onAction="#closeEncounter" text="Close Encounter" />
22+
<MenuItem mnemonicParsing="false" onAction="#openStrMode" text="Open Streamer GUI" />
2223
</items>
2324
</Menu>
2425
</menus>

src/drzed/GUI/MainController.java

+16
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@ public void openMini(ActionEvent actionEvent) {
208208
e.printStackTrace();
209209
}
210210
}
211+
public void openStrMode(ActionEvent actionEvent) {
212+
try {
213+
Parent root = FXMLLoader.load(getClass().getResource("ML_Condensed.fxml"));
214+
Stage secondStage = new Stage();
215+
secondStage.setTitle("Magic Legends Condensed DPS Tracker");
216+
secondStage.setScene(new Scene(root, 390, 320));
217+
secondStage.initStyle(StageStyle.TRANSPARENT);
218+
// secondStage.setAlwaysOnTop(true);
219+
secondStage.setX(0);
220+
secondStage.setY(0);
221+
Main.streamStage = secondStage;
222+
secondStage.show();
223+
} catch (IOException e) {
224+
e.printStackTrace();
225+
}
226+
}
211227

212228
private void setFactories() {
213229
/* SET CELL VALUE FACTORY TO SPECIFIED DATA TYPES */

src/drzed/GUI/dark.css

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
-fx-focus-color: #036E83;
1717
-fx-faint-focus-color: #036E8322;
1818
}
19+
1920
/*
2021
2122
.default-color0.chart-pie { -fx-pie-color: rgba(255, 8, 0, 0.47); }

src/drzed/Main.java

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class Main extends Application {
2626
private static final String TITLE = "Magic Parser v2.0.7";
2727
public static Stage stage = null;
2828
public static Stage miniStage = null;
29+
public static Stage streamStage = null;
2930
public static File Directory;
3031
private static HxCConfig config;
3132
public static boolean DEBUG_MODE = false;

0 commit comments

Comments
 (0)