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

Matchmaker Overhaul #190

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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: 0 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;


Brutus5000 marked this conversation as resolved.
Show resolved Hide resolved
@Configuration
@EnableConfigurationProperties(ApplicationProperties.class)
@ComponentScan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ public String isHidden() {
public URL getThumbnailUrlLarge() {
return isMapVersion() ? mapVersion.getThumbnailUrlLarge() : null;
}

public MapTableItemAdapter getThis() {
return this;
}
Comment on lines +65 to +67
Copy link
Member

Choose a reason for hiding this comment

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

Makes no sense, please remove.

Copy link
Author

Choose a reason for hiding this comment

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

This is dumb, i wonder why i did this lol

Copy link
Author

Choose a reason for hiding this comment

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

When I remove this the favorite button breaks. I have no idea why, the getThis method is never called.

	at com.sun.javafx.property.PropertyReference.getProperty(PropertyReference.java:191) ~[javafx-base-21-ea+24-linux.jar:na]
	at javafx.scene.control.cell.TreeItemPropertyValueFactory.getCellDataReflectively(TreeItemPropertyValueFactory.java:184) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.cell.TreeItemPropertyValueFactory.call(TreeItemPropertyValueFactory.java:157) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.cell.TreeItemPropertyValueFactory.call(TreeItemPropertyValueFactory.java:135) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.TreeTableColumn.getCellObservableValue(TreeTableColumn.java:578) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.TreeTableColumn.getCellObservableValue(TreeTableColumn.java:563) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.TreeTableCell.updateItem(TreeTableCell.java:676) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.TreeTableCell.indexChanged(TreeTableCell.java:482) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.IndexedCell$1.invalidated(IndexedCell.java:85) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:113) ~[javafx-base-21-ea+24-linux.jar:na]
	at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:148) ~[javafx-base-21-ea+24-linux.jar:na]
	at javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:130) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.TableRowSkinBase.updateCells(TableRowSkinBase.java:525) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.TreeTableRowSkin.updateCells(TreeTableRowSkin.java:280) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.TableRowSkinBase.<init>(TableRowSkinBase.java:155) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.TreeTableRowSkin.<init>(TreeTableRowSkin.java:90) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.TreeTableRow.createDefaultSkin(TreeTableRow.java:536) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.Control.doProcessCSS(Control.java:910) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.Control$1.doProcessCSS(Control.java:88) ~[javafx-controls-21-ea+24-linux.jar:na]
	at com.sun.javafx.scene.control.ControlHelper.processCSSImpl(ControlHelper.java:68) ~[javafx-controls-21-ea+24-linux.jar:na]
	at com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:147) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at javafx.scene.Node.processCSS(Node.java:9555) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at javafx.scene.Node.applyCss(Node.java:9642) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.VirtualFlow.setCellIndex(VirtualFlow.java:1819) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.VirtualFlow.getCell(VirtualFlow.java:1796) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.VirtualFlow.getOrCreateCellSize(VirtualFlow.java:3068) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.VirtualFlow.getOrCreateCellSize(VirtualFlow.java:3040) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.VirtualFlow.recalculateAndImproveEstimatedSize(VirtualFlow.java:3144) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.VirtualFlow$5.invalidated(VirtualFlow.java:865) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:113) ~[javafx-base-21-ea+24-linux.jar:na]
	at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:148) ~[javafx-base-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.VirtualFlow.setCellCount(VirtualFlow.java:911) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.TreeTableViewSkin.updateItemCount(TreeTableViewSkin.java:354) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.VirtualContainerBase.checkState(VirtualContainerBase.java:183) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.VirtualContainerBase.layoutChildren(VirtualContainerBase.java:158) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.skin.TableViewSkinBase.layoutChildren(TableViewSkinBase.java:432) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.Control.layoutChildren(Control.java:612) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.control.TreeTableView.layoutChildren(TreeTableView.java:1681) ~[javafx-controls-21-ea+24-linux.jar:na]
	at javafx.scene.Parent.layout(Parent.java:1208) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at javafx.scene.Parent.layout(Parent.java:1215) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at javafx.scene.Parent.layout(Parent.java:1215) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at javafx.scene.Parent.layout(Parent.java:1215) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at javafx.scene.Parent.layout(Parent.java:1215) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at javafx.scene.Parent.layout(Parent.java:1215) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at javafx.scene.Parent.layout(Parent.java:1215) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at javafx.scene.Parent.layout(Parent.java:1215) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at javafx.scene.Parent.layout(Parent.java:1215) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at javafx.scene.Scene.doLayoutPass(Scene.java:594) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2600) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at com.sun.javafx.tk.Toolkit.lambda$runPulse$2(Toolkit.java:401) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) ~[na:na]
	at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:400) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:430) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:592) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:572) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:565) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:352) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method) ~[javafx-graphics-21-ea+24-linux.jar:na]
	at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$10(GtkApplication.java:263) ~[javafx-graphics-21-ea+24-linux.jar:na]```

Copy link
Member

Choose a reason for hiding this comment

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

Maybe @Sheikah45 can help here

Copy link
Member

@Sheikah45 Sheikah45 Oct 28, 2023

Choose a reason for hiding this comment

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

It is because of line 1009 in the ViewHelper, you are creating a TreeItemPropertyValueFactory where you specify the property as this. So it is going to look for a getThis method to retrieve the property.

It would be better to change that cell factory to a lambda that provides the value like item -> item.getValue().valueProperty()

Copy link
Member

Choose a reason for hiding this comment

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

Generally for all of those I would use a lambda function rather than relying on the string name of the property to expect a getter. It is better for refactor and type safety

}
41 changes: 40 additions & 1 deletion src/main/java/com/faforever/moderatorclient/ui/ViewHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.faforever.moderatorclient.ui.domain.VotingChoiceFX;
import com.faforever.moderatorclient.ui.domain.VotingQuestionFX;
import com.faforever.moderatorclient.ui.domain.VotingSubjectFX;
import com.faforever.moderatorclient.ui.main_window.LadderMapPoolController;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
Expand All @@ -61,6 +62,7 @@
import javafx.scene.control.TextArea;
import javafx.scene.control.Tooltip;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableCell;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.control.cell.CheckBoxTableCell;
Expand Down Expand Up @@ -990,7 +992,7 @@ protected void updateItem(PlayerFX item, boolean empty) {
};
}

public static void buildMapTreeView(TreeTableView<MapTableItemAdapter> mapTreeView) {
public static void buildMapTreeView(TreeTableView<MapTableItemAdapter> mapTreeView, @Nullable Consumer<MapTableItemAdapter> removeFavorite, @Nullable Consumer<MapTableItemAdapter> addFavorite, LadderMapPoolController ladderMapPoolController) {
TreeTableColumn<MapTableItemAdapter, String> idColumn = new TreeTableColumn<>("ID");
idColumn.setCellValueFactory(new TreeItemPropertyValueFactory<>("id"));
idColumn.setComparator(Comparator.comparingInt(Integer::parseInt));
Expand All @@ -1002,6 +1004,43 @@ public static void buildMapTreeView(TreeTableView<MapTableItemAdapter> mapTreeVi
nameColumn.setMinWidth(300);
mapTreeView.getColumns().add(nameColumn);

TreeTableColumn<MapTableItemAdapter, MapTableItemAdapter> favoriteColumn = new TreeTableColumn<>("Favorite");
favoriteColumn.setMinWidth(100);
favoriteColumn.setCellValueFactory(new TreeItemPropertyValueFactory<>("this"));
Callback<TreeTableColumn<MapTableItemAdapter, MapTableItemAdapter>, TreeTableCell<MapTableItemAdapter, MapTableItemAdapter>> cellFactory = new Callback<TreeTableColumn<MapTableItemAdapter, MapTableItemAdapter>, TreeTableCell<MapTableItemAdapter, MapTableItemAdapter>>() {
@Override
public TreeTableCell<MapTableItemAdapter, MapTableItemAdapter> call(TreeTableColumn<MapTableItemAdapter, MapTableItemAdapter> param) {
return new TreeTableCell<MapTableItemAdapter, MapTableItemAdapter>() {
@Override
public void updateItem(MapTableItemAdapter item, boolean empty) {
super.updateItem(item, empty);
if (!empty && item != null && !item.isMapVersion()) {
if (ladderMapPoolController.isMapFavorite(Integer.parseInt(item.getId()))) {
Button button = new Button("Unfavorite");
button.setOnMouseClicked(event -> removeFavorite.accept(item));
Copy link
Member

Choose a reason for hiding this comment

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

You have removeFavorite marked as nullable but no null check here

Copy link
Author

Choose a reason for hiding this comment

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

Done.

button.setTextFill(Color.rgb(200, 10, 10));

setGraphic(button);
return;
} else {
Button button = new Button("Favorite");
button.setOnMouseClicked(event -> addFavorite.accept(item));
Copy link
Member

Choose a reason for hiding this comment

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

nullability of addFavorite

Copy link
Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

Choose a reason for hiding this comment

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

What was changed here? I don't even know what @Sheikah45 refers to O.o

Copy link
Member

Choose a reason for hiding this comment

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

addFavorite is marked as nullable in the method parameters But there is no check to see if it is nonNull before calling accept on it. @Spikey84 I meant checking for null on addFavorite and removeFavorite not the item

button.setTextFill(Color.rgb(10, 200, 10));

setGraphic(button);
return;
}
}
setGraphic(null);
}
};
}
};

favoriteColumn.setCellFactory(cellFactory);

mapTreeView.getColumns().add(favoriteColumn);

TreeTableColumn<MapTableItemAdapter, ComparableVersion> versionColumn = new TreeTableColumn<>("Version");
versionColumn.setCellValueFactory(new TreeItemPropertyValueFactory<>("version"));
mapTreeView.getColumns().add(versionColumn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.faforever.moderatorclient.ui.Controller;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
Copy link
Member

Choose a reason for hiding this comment

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

You gotta optimize the imports. Since there is no other change to this file it must be unused.

import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,6 +17,7 @@ public class BracketRatingController implements Controller<HBox> {

@FXML HBox root;
@FXML Label ratingLabel;
public Button removeMaps;
Brutus5000 marked this conversation as resolved.
Show resolved Hide resolved

@Override
public HBox getRoot() {
Expand Down
Loading
Loading