Skip to content

Commit

Permalink
Merge pull request #101 from ds306e18/html-overlay
Browse files Browse the repository at this point in the history
Added more data to current_match.json and added an example html overlay.
  • Loading branch information
NicEastvillage authored Apr 29, 2020
2 parents 8608e2b + bcdfe72 commit 8806d8b
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 50 deletions.
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies {
compile 'com.google.guava:guava:23.0'

// Using GSON for serializing objects for transfer and storage
compile 'com.google.code.gson:gson:2.8.5'
compile 'com.google.code.gson:gson:2.8.6'

// Use JUnit test framework
testCompile 'junit:junit:4.12'
Expand All @@ -36,8 +36,6 @@ dependencies {

// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}

Expand Down
7 changes: 5 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Changelog

#### Unreleased
#### Version 1.7 - 26. April 2020
- Added option to use RLBotPack Python installation if available (default: true). - NicEastvillage
- Added option for using random standard map. - Darxeal
- Added series (best of X) functionality. #56 - NicEastvillage
- A default series length can be set for each stage, but length of individual series can also be changed once the bracket is generated.

- Updated the data exposed to overlays (or other programs) in the `current_match.json`. - NicEastvillage
- Exposed data includes team names, all bot details, and scores of current series
- Added functionality to choose where the `current_match.json` is located in the RLBotSettingsTab
- Clicking "modify config" will now also update the `current_match.json`

#### Version 1.6 - 17. October 2019
- Now writes overlay data to a json next to the cleopetra.jar. This can be disabled in RLBotSettings tab. - NicEastvillage
Expand Down
Binary file added overlay/images/overlaybg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added overlay/images/sponsors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 122 additions & 0 deletions overlay/overlay.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
.top {
position: fixed;
top: 0;
left: 50%;
transform: translate(-50%, 0);
}

.bottom {
position: fixed;
top: 100%;
left: 50%;
transform: translate(-50%, -100%);
}

.bottom-right {
position: fixed;
top: 100%;
left: 100%;
transform: translate(-100%, -100%);
}

.team-name {
left: 30%;
font-size: 1.8em;
font-weight: bold;
font-family: "Helvetica", "Verdana", sans-serif;
color: white;
float: left;
text-align: center;
width: 370px;
}

#ladder-div {
margin-top: 35px;
margin-left: 35px;
display: inline-block;
float: left;
}

#message {
display: inline-block;
font-size: 1.6em;
font-weight: bold;
font-family: "Consolas", "Courier New", monospace;
width: 1000px;
margin-left: 100px;
margin-top: 100px;
color: white;
text-shadow: 0 0 12px rgb(0, 0, 0)
}

p.bot {
border: solid 1px gray;
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.51);
padding: 4px;
margin-bottom: 3px;
margin-top: 8px;
width: 200px;
font-family: "Consolas", "Courier New", monospace;
font-weight: bold;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
background-color: black;
color: lightgray;
}

.date {
font-size: 0.8em;
font-weight: normal;
}

p.bot.round-robin.evaluating {
background-color: #255c47;
}

p.bot.round-robin.evaluating.playing {
background-color: #255c47;
}

p.bot.round-robin {
background-color: #1c3d3e;
}

div.inactive-division {
border: solid 1px rgba(85, 85, 85, 0.52);
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.51);
padding: 4px;
margin-bottom: 3px;
margin-top: 4px;
width: 200px;
font-family: "Consolas", "Courier New", monospace;
font-weight: bold;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
background-color: rgba(89, 89, 89, 0.4);
color: lightgray;
}

div.active-division {
margin-bottom: 30px;
margin-top: 20px;
}

.division-header {
color: #ffffff;
font-family: "Consolas", "Courier New", monospace;
font-weight: bold;
font-size: 1.5em;
text-shadow: 0 0 6px rgb(0, 0, 0)
}

.rr_record {
float:right;
}

.rr_win {
color: #a4cc98;
}

.rr_loss {
color: #c1846f;
}
40 changes: 40 additions & 0 deletions overlay/overlay.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha384-vk5WoKIaW/vJyUAd9n/wmopsmNhiy+L2Z+SBxGYnUkunIxVxAv/UtMOhba/xskxh" crossorigin="anonymous"></script>
<link rel="stylesheet" href="overlay.css"/>
</head>
<body>
<div class="top">
<img src="images/overlaybg.png"/>
</div>
<div class="top" style="top: 3px; display: block; width: 1174px">
<p id="team-name-blue" class="team-name">TBD</p>
<p id="team-name-orange" class="team-name" style="float:right;">TBD</p>
</div>
<div class="bottom">
<img src="images/sponsors.png"/>
</div>

<script>
const blueTeamName = $("#team-name-blue");
const orangeTeamName = $("#team-name-orange");
let previousData = null;
let x = 0;

setInterval(function () {
$.get("current_match.json", function (json) {
if (json !== previousData) {
data = JSON.parse(json);
blueTeamName.text(data.blue_team_name);
orangeTeamName.text(data.orange_team_name);
previousData = json;
}
});
}, 1000);
</script>

</body>
</html>
24 changes: 14 additions & 10 deletions src/dk/aau/cs/ds306e18/tournament/rlbot/MatchRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,6 @@ public static boolean startMatch(MatchConfig matchConfig, Series series) {
return false;
}

// Write overlay data to current_match.json
if (Tournament.get().getRlBotSettings().writeOverlayDataEnabled()) {
try {
OverlayData.write(series);
} catch (IOException e) {
Alerts.errorNotification("Could not write overlay data", "Failed to write overlay data to " + OverlayData.CURRENT_MATCH_PATH);
e.printStackTrace();
}
}

return sendCommandToRLBot(Command.START, true);
}

Expand Down Expand Up @@ -225,6 +215,20 @@ public static boolean prepareMatch(MatchConfig matchConfig, Series series) {
} catch (IOException e) {
Alerts.errorNotification("IO error occurred while configuring match", e.getMessage());
}

// Write overlay data
RLBotSettings settings = Tournament.get().getRlBotSettings();
if (settings.writeOverlayDataEnabled()) {
try {
OverlayData overlayData = new OverlayData(series);
overlayData.write();
} catch (IOException e) {
Path path = new File(settings.getOverlayPath(), OverlayData.CURRENT_MATCH_FILE_NAME).toPath();
Alerts.errorNotification("Could not write overlay data", "Failed to write overlay data to " + path.toString());
e.printStackTrace();
}
}

return false;
}

Expand Down
11 changes: 10 additions & 1 deletion src/dk/aau/cs/ds306e18/tournament/rlbot/RLBotSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
public class RLBotSettings {

private MatchConfig matchConfig = new MatchConfig();
private boolean writeOverlayData = true;
private boolean writeOverlayData = false;
private String overlayPath = "";
private boolean useBotPackPythonIfAvailable = true;

public RLBotSettings() {
Expand All @@ -37,6 +38,14 @@ public void setWriteOverlayData(boolean writeOverlayData) {
this.writeOverlayData = writeOverlayData;
}

public String getOverlayPath() {
return overlayPath;
}

public void setOverlayPath(String overlayPath) {
this.overlayPath = overlayPath;
}

public boolean useBotPackPythonIfAvailable() {
return useBotPackPythonIfAvailable;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package dk.aau.cs.ds306e18.tournament.ui;

import dk.aau.cs.ds306e18.tournament.Main;
import dk.aau.cs.ds306e18.tournament.model.Tournament;
import dk.aau.cs.ds306e18.tournament.rlbot.MatchRunner;
import dk.aau.cs.ds306e18.tournament.rlbot.RLBotSettings;
import dk.aau.cs.ds306e18.tournament.rlbot.configuration.MatchConfig;
import dk.aau.cs.ds306e18.tournament.rlbot.configuration.MatchConfigOptions.*;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.stage.DirectoryChooser;
import javafx.stage.Window;

import java.io.File;
import java.util.function.BiConsumer;

public class RLBotSettingsTabController {
Expand All @@ -24,6 +31,8 @@ public class RLBotSettingsTabController {
public RadioButton skipReplaysRadioButton;
public RadioButton instantStartRadioButton;
public RadioButton writeOverlayDataRadioButton;
public TextField overlayPathTextField;
public Button chooseOverlayPathButton;
public RadioButton useRLBotPackPythonRadioButton;
public Button rlbotRunnerOpenButton;
public Button rlbotRunnerCloseButton;
Expand Down Expand Up @@ -83,10 +92,22 @@ private void initialize() {
setupChoiceBox(respawnTimeChoiceBox, RespawnTime.values(), matchConfig.getRespawnTime(), MatchConfig::setRespawnTime);

// Other settings
writeOverlayDataRadioButton.setSelected(settings.writeOverlayDataEnabled());
boolean writeOverlay = settings.writeOverlayDataEnabled();
writeOverlayDataRadioButton.setSelected(writeOverlay);
writeOverlayDataRadioButton.selectedProperty().addListener((observable, oldValue, newValue) -> {
Tournament.get().getRlBotSettings().setWriteOverlayData(newValue);
overlayPathTextField.setDisable(!newValue);
chooseOverlayPathButton.setDisable(!newValue);
});
chooseOverlayPathButton.setDisable(!writeOverlay);
overlayPathTextField.setDisable(!writeOverlay);
overlayPathTextField.focusedProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue) {
String path = overlayPathTextField.textProperty().get();
settings.setOverlayPath(path);
}
});

useRLBotPackPythonRadioButton.setSelected(settings.useBotPackPythonIfAvailable());
useRLBotPackPythonRadioButton.selectedProperty().addListener((observable, oldValue, newValue) -> {
Tournament.get().getRlBotSettings().setUseBotPackPythonIfAvailable(newValue);
Expand Down Expand Up @@ -155,4 +176,18 @@ public void onActionRLBotRunnerClose(ActionEvent actionEvent) {
public void onActionRLBotRunnerStopMatch(ActionEvent actionEvent) {
MatchRunner.stopMatch();
}

public void onActionChooseOverlayPath(ActionEvent actionEvent) {
DirectoryChooser dirChooser = new DirectoryChooser();
dirChooser.setTitle("Choose overlay folder");
dirChooser.setInitialDirectory(Main.lastSavedDirectory);
Window window = chooseOverlayPathButton.getScene().getWindow();
File folder = dirChooser.showDialog(window);

if (folder != null) {
String path = folder.toString();
overlayPathTextField.setText(path);
Tournament.get().getRlBotSettings().setOverlayPath(path);
}
}
}
20 changes: 20 additions & 0 deletions src/dk/aau/cs/ds306e18/tournament/ui/layout/RLBotSettingsTab.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
Expand Down Expand Up @@ -126,6 +127,25 @@
<RadioButton fx:id="writeOverlayDataRadioButton" layoutX="494.0" layoutY="13.0" mnemonicParsing="false" GridPane.columnIndex="1" />
</children>
</GridPane>
<GridPane layoutX="30.0" layoutY="324.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="208.0" minWidth="10.0" prefWidth="160.0" />
<ColumnConstraints halignment="RIGHT" hgrow="ALWAYS" maxWidth="263.0" minWidth="10.0" prefWidth="262.0" />
<ColumnConstraints halignment="RIGHT" hgrow="NEVER" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Write overlay data to:">
<font>
<Font size="16.0" />
</font>
</Text>
<TextField fx:id="overlayPathTextField" prefHeight="25.0" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" />
<Button fx:id="chooseOverlayPathButton" mnemonicParsing="false" onAction="#onActionChooseOverlayPath" text="..." GridPane.columnIndex="2" />
</children>
</GridPane>
<GridPane layoutX="30.0" layoutY="324.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
Expand Down
Loading

0 comments on commit 8806d8b

Please sign in to comment.