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 5 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.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
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 DoubleProperty 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 SimpleDoubleProperty();
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 double getMinimumMapsAfterVeto() {
return minimumMapsAfterVeto.get();
}

public DoubleProperty 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,26 +4,41 @@
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.CheckBox;
import javafx.scene.control.ListView;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.util.converter.NumberStringConverter;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.Comparator;
import lombok.extern.slf4j.Slf4j;

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

@FXML VBox root;
@FXML ListView<MapPoolAssignmentFX> mapListView;
public Spinner<Integer> vetoTokensPerPlayerSpinner;
public Spinner<Integer> maxTokensPerMapSpinner;
public Spinner<Double> minimumMapsAfterVetoSpinner;
public CheckBox dynamicMaxTokensPerMapCheckBox;
public HBox maxTokensPerMapHBox;
Copy link
Member

Choose a reason for hiding this comment

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

I would follow convention and make these not public and use @FXML

@FXML
VBox root;
@FXML
ListView<MapPoolAssignmentFX> mapListView;

private final SmallThumbnailCache smallThumbnailCache;

Expand All @@ -35,11 +50,38 @@ public VBox getRoot() {
@FXML
public void initialize() {
mapListView.setCellFactory(mapListView -> new ListViewMapCell(smallThumbnailCache));
vetoTokensPerPlayerSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 255, 0, 1));
maxTokensPerMapSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1,255,1,1));
minimumMapsAfterVetoSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.001, 255, 1, 0.5));
}

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) {
dynamicMaxTokensPerMapCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (newValue){
log.debug(String.valueOf(bracket.maxTokensPerMapProperty().get()));
Copy link
Member

Choose a reason for hiding this comment

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

This log statement isn't needed anymore

maxTokensPerMapSpinner.setDisable(true);
bracket.maxTokensPerMapProperty().set(0);
} else {
bracket.maxTokensPerMapProperty().set(1);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bracket.maxTokensPerMapProperty().set(0);
} else {
bracket.maxTokensPerMapProperty().set(1);
bracket.setMaxTokensPerMap(0);
} else {
bracket.setMaxTokensPerMap(1);

maxTokensPerMapSpinner.setDisable(false);
}
});

dynamicMaxTokensPerMapCheckBox.setSelected(bracket.maxTokensPerMapProperty().get() == 0);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dynamicMaxTokensPerMapCheckBox.setSelected(bracket.maxTokensPerMapProperty().get() == 0);
dynamicMaxTokensPerMapCheckBox.setSelected(bracket.getMaxTokensPerMap() == 0);


maxTokensPerMapSpinner.getValueFactory().setValue(bracket.maxTokensPerMapProperty().get());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
maxTokensPerMapSpinner.getValueFactory().setValue(bracket.maxTokensPerMapProperty().get());
maxTokensPerMapSpinner.getValueFactory().setValue(bracket.getMaxTokensPerMap());

maxTokensPerMapSpinner.valueProperty().addListener((observable, oldValue, newValue) -> bracket.maxTokensPerMapProperty().set(newValue));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
maxTokensPerMapSpinner.valueProperty().addListener((observable, oldValue, newValue) -> bracket.maxTokensPerMapProperty().set(newValue));
maxTokensPerMapSpinner.valueProperty().addListener((observable, oldValue, newValue) -> bracket.setMaxTokensPerMap(newValue));


vetoTokensPerPlayerSpinner.getValueFactory().setValue(bracket.vetoTokensPerPlayerProperty().get());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
vetoTokensPerPlayerSpinner.getValueFactory().setValue(bracket.vetoTokensPerPlayerProperty().get());
vetoTokensPerPlayerSpinner.getValueFactory().setValue(bracket.getVetoTokensPerPlayer());

vetoTokensPerPlayerSpinner.valueProperty().addListener((observable, oldValue, newValue) -> bracket.vetoTokensPerPlayerProperty().set(newValue));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
vetoTokensPerPlayerSpinner.valueProperty().addListener((observable, oldValue, newValue) -> bracket.vetoTokensPerPlayerProperty().set(newValue));
vetoTokensPerPlayerSpinner.valueProperty().addListener((observable, oldValue, newValue) -> bracket.setVetoTokensPerPlayer(newValue));


minimumMapsAfterVetoSpinner.getValueFactory().setValue(bracket.minimumMapsAfterVetoProperty().get());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
minimumMapsAfterVetoSpinner.getValueFactory().setValue(bracket.minimumMapsAfterVetoProperty().get());
minimumMapsAfterVetoSpinner.getValueFactory().setValue(bracket.getMinimumMapsAfterVeto());

minimumMapsAfterVetoSpinner.valueProperty().addListener((observable, oldValue, newValue) -> bracket.minimumMapsAfterVetoProperty().set(newValue));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
minimumMapsAfterVetoSpinner.valueProperty().addListener((observable, oldValue, newValue) -> bracket.minimumMapsAfterVetoProperty().set(newValue));
minimumMapsAfterVetoSpinner.valueProperty().addListener((observable, oldValue, newValue) -> bracket.setMinimumMapsAfterVeto(newValue));

}
}
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
33 changes: 29 additions & 4 deletions src/main/resources/ui/main_window/bracketListView.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,33 @@
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.VBox?>

<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>
<ListView fx:id="mapListView" minWidth="160.0" VBox.vgrow="ALWAYS" />
</children>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.CheckBox?>
<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>
<CheckBox fx:id="dynamicMaxTokensPerMapCheckBox" text="Use Dynamic max tokens per map"/>
<HBox spacing="10" alignment="CENTER" fx:id="maxTokensPerMapHBox">
<Label prefWidth="120" alignment="CENTER_RIGHT" text="max tokens per map"/>
<Spinner editable="true" fx:id="maxTokensPerMapSpinner" prefWidth="55"/>
</HBox>
<HBox spacing="10" alignment="CENTER">
<Label prefWidth="120" alignment="CENTER_RIGHT" text="min. maps after veto"/>
<Spinner editable="true" fx:id="minimumMapsAfterVetoSpinner" prefWidth="55"/>
</HBox>
<HBox spacing="10" alignment="CENTER">
<Label prefWidth="120" alignment="CENTER_RIGHT" text="veto tokens per player"/>
<Spinner editable="true" fx:id="vetoTokensPerPlayerSpinner" prefWidth="55"/>
</HBox>
</VBox>
<ListView fx:id="mapListView" minWidth="160.0" VBox.vgrow="ALWAYS"/>
</children>
</VBox>