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 all 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
2 changes: 1 addition & 1 deletion 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.5"
def mapStructVersion = "1.5.5.Final"
def commonsVersion = "9972c3d"
def commonsVersion = "9bd066eedebf6abef806e908e281631eb4f95766"

annotationProcessor(platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ public void patchBracket(MatchmakerQueueMapPoolFX bracketFX) {
.setMapPool(bracket.getMapPool())
.setMaxRating(bracket.getMaxRating())
.setMinRating(bracket.getMinRating())
.setVetoTokensPerPlayer(bracket.getVetoTokensPerPlayer())
.setMaxTokensPerMap(bracket.getMaxTokensPerMap())
.setMinimumMapsAfterVeto(bracket.getMinimumMapsAfterVeto())
.setId(bracket.getId()));
}

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(double 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,37 @@
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 Spinner<Integer> vetoTokensPerPlayerSpinner;
@FXML Spinner<Integer> maxTokensPerMapSpinner;
@FXML Spinner<Double> minimumMapsAfterVetoSpinner;
@FXML CheckBox dynamicMaxTokensPerMapCheckBox;
@FXML HBox maxTokensPerMapHBox;
@FXML VBox root;
@FXML ListView<MapPoolAssignmentFX> mapListView;

Expand All @@ -35,11 +48,37 @@ 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){
maxTokensPerMapSpinner.setDisable(true);
bracket.setMaxTokensPerMap(0);
} else {
bracket.setMaxTokensPerMap(1);
maxTokensPerMapSpinner.setDisable(false);
}
});

dynamicMaxTokensPerMapCheckBox.setSelected(bracket.getMaxTokensPerMap() == 0);

maxTokensPerMapSpinner.getValueFactory().setValue(bracket.getMaxTokensPerMap());
maxTokensPerMapSpinner.valueProperty().addListener((observable, oldValue, newValue) -> bracket.setMaxTokensPerMap(newValue));

vetoTokensPerPlayerSpinner.getValueFactory().setValue(bracket.getVetoTokensPerPlayer());
vetoTokensPerPlayerSpinner.valueProperty().addListener((observable, oldValue, newValue) -> bracket.setVetoTokensPerPlayer(newValue));

minimumMapsAfterVetoSpinner.getValueFactory().setValue(bracket.getMinimumMapsAfterVeto());
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 @@ -174,6 +177,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 +191,10 @@ private void loadMatchMakerQueue(MatchmakerQueue matchmakerQueue) {
bindSelectedMapPropertyToAddRemoveButtons(bracketAssignments, addBracketController, bracketFX.getMapPool());
}
uploadToDatabaseButton.setOnAction(event -> {
for (MatchmakerQueueMapPoolFX bracketFX : bracketsFX) {
mapService.patchBracket(bracketFX);
}

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>