Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/setting veto system fields #229

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ println "Platform is: ${javafxPlatform}"
dependencies {
def springBootVersion = "3.3.2"
def mapStructVersion = "1.5.5.Final"
def commonsVersion = "763f32222acf0011c6b8b36dac9e0462eb433745"
def commonsVersion = "9bd066eedebf6abef806e908e281631eb4f95766"

annotationProcessor(platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}"))
Expand All @@ -57,8 +57,8 @@ dependencies {
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8")
implementation("com.github.jasminb:jsonapi-converter:0.14")
implementation("com.github.FAForever.faf-java-commons:faf-commons-data:${commonsVersion}")
implementation("com.github.FAForever.faf-java-commons:faf-commons-api:${commonsVersion}")
implementation("com.github.FAForever.faf-java-commons:data:${commonsVersion}")
implementation("com.github.FAForever.faf-java-commons:api:${commonsVersion}")
implementation("org.apache.httpcomponents:httpclient:4.5.14")
implementation("com.github.rutledgepaulv:q-builders:1.6")
implementation("com.google.guava:guava:33.2.1-jre")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package com.faforever.moderatorclient.ui.domain;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.FloatProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleFloatProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

public class MatchmakerQueueMapPoolFX extends AbstractEntityFX {
private final DoubleProperty minRating;
private final DoubleProperty maxRating;
private final IntegerProperty vetoTokensPerPlayer;
private final IntegerProperty maxTokensPerMap;
private final FloatProperty minimumMapsAfterVeto;
private final ObjectProperty<MatchmakerQueueFX> matchmakerQueue;
private final ObjectProperty<MapPoolFX> mapPool;

public MatchmakerQueueMapPoolFX() {
minRating = new SimpleDoubleProperty();
maxRating = new SimpleDoubleProperty();
vetoTokensPerPlayer = new SimpleIntegerProperty();
maxTokensPerMap = new SimpleIntegerProperty();
minimumMapsAfterVeto = new SimpleFloatProperty();
matchmakerQueue = new SimpleObjectProperty<>();
mapPool = new SimpleObjectProperty<>();
}
Expand Down Expand Up @@ -44,6 +52,42 @@ public void setMaxRating(double maxRating) {
this.maxRating.set(maxRating);
}

public int getVetoTokensPerPlayer() {
return vetoTokensPerPlayer.get();
}

public IntegerProperty vetoTokensPerPlayerProperty() {
return vetoTokensPerPlayer;
}

public void setVetoTokensPerPlayer(int vetoTokensPerPlayer) {
this.vetoTokensPerPlayer.set(vetoTokensPerPlayer);
}

public Integer getMaxTokensPerMap() {
return maxTokensPerMap.get();
}

public IntegerProperty maxTokensPerMapProperty() {
return maxTokensPerMap;
}

public void setMaxTokensPerMap(int maxTokensPerMap) {
this.maxTokensPerMap.set(maxTokensPerMap);
}

public float getMinimumMapsAfterVeto() {
return minimumMapsAfterVeto.get();
}

public FloatProperty minimumMapsAfterVetoProperty() {
return minimumMapsAfterVeto;
}

public void setMinimumMapsAfterVeto(float minimumMapsAfterVeto) {
this.minimumMapsAfterVeto.set(minimumMapsAfterVeto);
}

public MatchmakerQueueFX getMatchmakerQueue() {
return matchmakerQueue.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,34 @@
import com.faforever.moderatorclient.ui.caches.SmallThumbnailCache;
import com.faforever.moderatorclient.ui.data_cells.ListViewMapCell;
import com.faforever.moderatorclient.ui.domain.MapPoolAssignmentFX;
import com.faforever.moderatorclient.ui.domain.MapVersionFX;
import com.faforever.moderatorclient.ui.domain.MatchmakerQueueMapPoolFX;
import javafx.beans.binding.Bindings;
import javafx.beans.property.FloatProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.value.ChangeListener;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;

import java.util.Comparator;
import java.util.Locale;
import java.util.Objects;

@Component
@RequiredArgsConstructor
@Slf4j
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class BracketListViewController implements Controller<VBox> {

public TextField vetoTokensPerPlayerInput;
public TextField maxTokensPerMapInput;
public TextField minimumMapsAfterVetoInput;
@FXML VBox root;
@FXML ListView<MapPoolAssignmentFX> mapListView;

Expand All @@ -37,9 +47,118 @@ public void initialize() {
mapListView.setCellFactory(mapListView -> new ListViewMapCell(smallThumbnailCache));
}

private void bindVetoTokensPerPlayer(IntegerProperty property) {
vetoTokensPerPlayerInput.textProperty().addListener((observable, oldValue, newValue) -> {
try {
int value = Integer.parseInt(newValue);
if (value < 0 || value > 255)
throw new NumberFormatException("veto tokens per player must be between 0 and 255");
if (!Objects.equals(property.get(), value)) {
property.set(value);
}
vetoTokensPerPlayerInput.setStyle("");
} catch (NumberFormatException e) {
log.error(e.getMessage());
vetoTokensPerPlayerInput.setStyle("-fx-background-color: rgb(255,100,100)");
}
});
Sheikah45 marked this conversation as resolved.
Show resolved Hide resolved

ChangeListener<Number> listener = (observable, oldValue, newValue) -> {
String stringValue = newValue.toString();
if (!Objects.equals(vetoTokensPerPlayerInput.getText(), stringValue)) {
vetoTokensPerPlayerInput.setText(stringValue);
vetoTokensPerPlayerInput.setStyle("");
}
};

property.addListener(listener);
listener.changed(property, property.get(), property.get());

}

private void bindMaxTokensPerMap(IntegerProperty property) {
maxTokensPerMapInput.textProperty().addListener((observable, oldValue, newValue) -> {
try {
if (Objects.equals(newValue, "D")) {
property.set(0);
maxTokensPerMapInput.setStyle("");
return;
}
int value = Integer.parseInt(newValue);
if (value < 1 || value > 255)
throw new NumberFormatException("max tokens per map must be between 1 and 255, or D (dynamic)");
if (!Objects.equals(property.get(), value)) {
property.set(value);
}
maxTokensPerMapInput.setStyle("");
} catch (NumberFormatException e) {
log.error(e.getMessage());
maxTokensPerMapInput.setStyle("-fx-background-color: rgb(255,100,100)");
}
});
Sheikah45 marked this conversation as resolved.
Show resolved Hide resolved

ChangeListener<Number> listener = (observable, oldValue, newValue) -> {
if (Objects.equals(newValue, 0)) {
if (!Objects.equals(maxTokensPerMapInput.getText(), "D")) {
maxTokensPerMapInput.setStyle("");
maxTokensPerMapInput.setText("D");
}
return;
}

String stringValue = newValue.toString();
if (!Objects.equals(maxTokensPerMapInput.getText(), stringValue)) {
maxTokensPerMapInput.setText(stringValue);
maxTokensPerMapInput.setStyle("");
}
};
property.addListener(listener);
listener.changed(property, property.get(), property.get());
}

private void bindMinimumMapsAfterVeto(FloatProperty property) {
minimumMapsAfterVetoInput.textProperty().addListener((observable, oldValue, newValue) -> {
try {
float value = Float.parseFloat(newValue);

if (value <= 0) {
throw new NumberFormatException("Minimum maps after veto must be greater than 0");
}
String formattedValue = String.format(Locale.US, "%.2f", value);
if (!Objects.equals(minimumMapsAfterVetoInput.getText(), formattedValue)) {
minimumMapsAfterVetoInput.setText(formattedValue);
}
if (!Objects.equals(property.get(), value)) {
property.set(value);
}
minimumMapsAfterVetoInput.setStyle("");
} catch (NumberFormatException e) {
log.error(e.getMessage());
minimumMapsAfterVetoInput.setStyle("-fx-background-color: rgb(255,100,100)");
}
});
Sheikah45 marked this conversation as resolved.
Show resolved Hide resolved

ChangeListener<Number> listener = (observable, oldValue, newValue) -> {
float value = newValue.floatValue();
String formattedValue = String.format(Locale.US, "%.2f", value);
if (!Objects.equals(minimumMapsAfterVetoInput.getText(), formattedValue)) {
minimumMapsAfterVetoInput.setText(formattedValue);
minimumMapsAfterVetoInput.setStyle("");
}
};
property.addListener(listener);
listener.changed(property, property.get(), property.get());
}

public void setMaps(ObservableList<MapPoolAssignmentFX> maps) {
mapListView.prefHeightProperty().bind(Bindings.size(maps).multiply(70));
mapListView.setItems(maps);
// mapListView.setItems(maps.sorted(Comparator.comparing(MapPoolAssignmentFX::getId)));
}

public void bindVetoParams(MatchmakerQueueMapPoolFX bracket) {
bindVetoTokensPerPlayer(bracket.vetoTokensPerPlayerProperty());
bindMaxTokensPerMap(bracket.maxTokensPerMapProperty());
bindMinimumMapsAfterVeto(bracket.minimumMapsAfterVetoProperty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.faforever.commons.api.dto.MatchmakerQueue;
import com.faforever.commons.api.dto.MatchmakerQueueMapPool;
import com.faforever.commons.api.dto.NeroxisGeneratorParams;
import com.faforever.commons.api.elide.ElideNavigator;
import com.faforever.commons.api.elide.ElideNavigatorOnId;
import com.faforever.moderatorclient.api.FafApiCommunicationService;
import com.faforever.moderatorclient.api.domain.MapService;
import com.faforever.moderatorclient.mapstruct.MapPoolAssignmentMapper;
import com.faforever.moderatorclient.mapstruct.MatchmakerQueueMapPoolMapper;
Expand Down Expand Up @@ -64,6 +67,7 @@ public class LadderMapPoolController implements Controller<SplitPane> {
public static final double MIN_MAP_SIZE_STEP = 1.25;
private final MapService mapService;
private final UiService uiService;
private final FafApiCommunicationService apiService;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only need mapService

private final MatchmakerQueueMapPoolMapper matchmakerQueueMapPoolMapper;
private final MapPoolAssignmentMapper mapPoolAssignmentMapper;
private final LargeThumbnailCache largeThumbnailCache;
Expand Down Expand Up @@ -174,6 +178,7 @@ private void loadMatchMakerQueue(MatchmakerQueue matchmakerQueue) {

// create the bracket list views
BracketListViewController listViewController = uiService.loadFxml("ui/main_window/bracketListView.fxml");
listViewController.bindVetoParams(bracketFX);
listViewController.setMaps(bracketAssignments);
listViewController.mapListView.prefWidthProperty().bind((bracketsScrollPane.widthProperty().divide(bracketsFX.size())).subtract(16 / bracketsFX.size()));
bracketListContainer.getChildren().add(listViewController.getRoot());
Expand All @@ -187,6 +192,19 @@ private void loadMatchMakerQueue(MatchmakerQueue matchmakerQueue) {
bindSelectedMapPropertyToAddRemoveButtons(bracketAssignments, addBracketController, bracketFX.getMapPool());
}
uploadToDatabaseButton.setOnAction(event -> {
for (MatchmakerQueueMapPoolFX bracketFX : bracketsFX) {
ElideNavigatorOnId<MatchmakerQueueMapPool> navigator = ElideNavigator.of(MatchmakerQueueMapPool.class)
.id(bracketFX.getId());
MatchmakerQueueMapPool dto = matchmakerQueueMapPoolMapper.mapToDto(bracketFX);
dto.setMapPool(null);
dto.setCreateTime(null);
dto.setMinRating(null);
dto.setMaxRating(null);
dto.setMatchmakerQueue(null);
dto.setUpdateTime(null);
apiService.patch(navigator, dto);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a method inside mapService

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like the changes to mappoolassignments below

}

List<MapPoolAssignment> oldMapPoolAssignments = mapService.getListOfMapsInBrackets(brackets);
List<MapPoolAssignmentFX> oldMapPoolAssignmentsFX = mapPoolAssignmentMapper.mapToFX(oldMapPoolAssignments);
List<MapPoolAssignmentFX> bracketMapPoolAssignments = bracketLists.stream()
Expand Down
21 changes: 21 additions & 0 deletions src/main/resources/ui/main_window/bracketListView.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,29 @@
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.VBox?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<VBox fx:id="root" alignment="TOP_CENTER" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.faforever.moderatorclient.ui.main_window.BracketListViewController">
<children>
<VBox spacing="10">
<padding>
<Insets top="10" right="5" bottom="10" left="5"/>
</padding>
<HBox spacing="10" alignment="CENTER">
<Label prefWidth="120" alignment="CENTER_RIGHT" text="veto tokens per player"/>
<TextField alignment="CENTER" prefWidth="40" fx:id="vetoTokensPerPlayerInput"/>
</HBox>
<HBox spacing="10" alignment="CENTER">
<Label prefWidth="120" alignment="CENTER_RIGHT" text="max tokens per map"/>
<TextField alignment="CENTER" prefWidth="40" fx:id="maxTokensPerMapInput"/>
</HBox>
<HBox spacing="10" alignment="CENTER">
<Label prefWidth="120" alignment="CENTER_RIGHT" text="min. maps after veto"/>
<TextField alignment="CENTER" prefWidth="40" fx:id="minimumMapsAfterVetoInput"/>
</HBox>
</VBox>
<ListView fx:id="mapListView" minWidth="160.0" VBox.vgrow="ALWAYS" />
</children>
</VBox>