Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:FAForever/downlords-faf-client i…
Browse files Browse the repository at this point in the history
…nto feature/FAForever#3023-replay-card-enhancement
  • Loading branch information
obydog002 committed Jan 5, 2024
2 parents 1e3ba54 + 5067d5e commit 71bbca0
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 135 deletions.
14 changes: 8 additions & 6 deletions src/main/java/com/faforever/client/chat/KittehChatService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.faforever.client.chat;

import com.faforever.client.audio.AudioService;
import com.faforever.client.chat.kitteh.FixedWhoListener;
import com.faforever.client.chat.kitteh.WhoAwayListener;
import com.faforever.client.chat.kitteh.WhoAwayListener.WhoAwayMessageEvent;
import com.faforever.client.config.ClientProperties;
import com.faforever.client.config.ClientProperties.Irc;
import com.faforever.client.domain.PlayerBean;
Expand Down Expand Up @@ -60,7 +61,6 @@
import org.kitteh.irc.client.library.event.channel.ChannelPartEvent;
import org.kitteh.irc.client.library.event.channel.ChannelTagMessageEvent;
import org.kitteh.irc.client.library.event.channel.ChannelTopicEvent;
import org.kitteh.irc.client.library.event.channel.ChannelUsersUpdatedEvent;
import org.kitteh.irc.client.library.event.client.ClientNegotiationCompleteEvent;
import org.kitteh.irc.client.library.event.connection.ClientConnectionEndedEvent;
import org.kitteh.irc.client.library.event.connection.ClientConnectionFailedEvent;
Expand Down Expand Up @@ -332,9 +332,11 @@ public void onChatUserList(ChannelNamesUpdatedEvent event) {
}

@Handler
public void onWhoCompleted(ChannelUsersUpdatedEvent event) {
Channel channel = event.getChannel();
channel.getUsers().forEach(user -> updateChatUser(user, channel));
public void onWhoAway(WhoAwayMessageEvent event) {
ChatChannel chatChannel = channels.get(event.channel());
if (chatChannel != null) {
chatChannel.getUser(event.userName()).ifPresent(chatUser -> chatUser.setAway(event.isAway()));
}
}

@Handler
Expand Down Expand Up @@ -592,7 +594,7 @@ public void connect() {
Arrays.stream(DefaultListeners.values())
.filter(listener -> listener != DefaultListeners.WHO)
.forEach(eventListenerSuppliers::add);
eventListenerSuppliers.add(() -> FixedWhoListener::new);
eventListenerSuppliers.add(() -> WhoAwayListener::new);
eventListenerSuppliers.add(() -> DefaultTagmsgListener::new);

client = (DefaultClient) Client.builder()
Expand Down
101 changes: 0 additions & 101 deletions src/main/java/com/faforever/client/chat/kitteh/FixedWhoListener.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.faforever.client.chat.kitteh;

import net.engio.mbassy.listener.Handler;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.kitteh.irc.client.library.Client;
import org.kitteh.irc.client.library.defaults.listener.AbstractDefaultListenerBase;
import org.kitteh.irc.client.library.event.client.ClientReceiveNumericEvent;
import org.kitteh.irc.client.library.event.helper.ClientEvent;
import org.kitteh.irc.client.library.feature.filter.NumericFilter;

// This who listener only sends events marking users as away for a channel
public class WhoAwayListener extends AbstractDefaultListenerBase {

/**
* Constructs the listener.
*
* @param client client
*/
public WhoAwayListener(Client.WithManagement client) {
super(client);
}

@NumericFilter(352) // WHO
@NumericFilter(354) // WHOX
@Handler(priority = Integer.MAX_VALUE - 1)
public void who(ClientReceiveNumericEvent event) {
if (event.getParameters().size() < ((event.getNumeric() == 352) ? 8 : 9)) {
this.trackException(event, "WHO response too short");
return;
}
final String channel = event.getParameters().get(1);

final String nick = event.getParameters().get(5);
final String status = event.getParameters().get(6);
boolean isAway = status.contains("G");

this.fire(new WhoAwayMessageEvent(this.getClient(), channel, nick, isAway));
}

public record WhoAwayMessageEvent(
Client client, String channel, String userName, boolean isAway
) implements ClientEvent {
@Override
public @NonNull Client getClient() {
return client;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,9 @@ public void onRandomMapButtonClicked() {
public void onGenerateMapButtonClicked() {
GenerateMapController generateMapController = uiService.loadFxml("theme/play/generate_map.fxml");
mapGeneratorService.getNewestGenerator()
.thenCompose(aVoid -> mapGeneratorService.getGeneratorStyles())
.thenAccept(generateMapController::setStyles)
.thenCompose(aVoid -> CompletableFuture.allOf(
mapGeneratorService.getGeneratorStyles().thenAccept(generateMapController::setStyles),
mapGeneratorService.getGeneratorBiomes().thenAccept(generateMapController::setBiomes)))
.thenRunAsync(() -> {
Pane root = generateMapController.getRoot();
generateMapController.setCreateGameController(this);
Expand Down
40 changes: 36 additions & 4 deletions src/main/java/com/faforever/client/game/GenerateMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.security.InvalidParameterException;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -68,6 +69,8 @@ public class GenerateMapController extends NodeController<Pane> {
public ComboBox<GenerationType> generationTypeComboBox;
public Label mapStyleLabel;
public ComboBox<String> mapStyleComboBox;
public Label biomeLabel;
public ComboBox<String> biomeComboBox;
public Spinner<Integer> spawnCountSpinner;
public Spinner<Double> mapSizeSpinner;
public Slider waterSlider;
Expand Down Expand Up @@ -108,10 +111,11 @@ public class GenerateMapController extends NodeController<Pane> {

@Override
protected void onInitialize() {
JavaFxUtil.bindManagedToVisible(commandLineLabel, commandLineArgsText, mapStyleComboBox, mapStyleLabel);
JavaFxUtil.bindManagedToVisible(commandLineLabel, commandLineArgsText, mapStyleComboBox, mapStyleLabel, biomeComboBox, biomeLabel);
initCommandlineArgs();
initGenerationTypeComboBox();
initMapStyleComboBox();
initBiomeComboBox();
initNumTeamsSpinner();
initSpawnCountSpinner();
initMapSizeSpinner();
Expand Down Expand Up @@ -236,7 +240,18 @@ private void initMapStyleComboBox() {
mapStyleComboBox.disableProperty()
.bind(previousMapName.textProperty().isNotEmpty()
.or(generationTypeComboBox.valueProperty().isNotEqualTo(GenerationType.CASUAL))
.or(commandLineArgsText.textProperty().isNotEmpty()));
.or(commandLineArgsText.textProperty().isNotEmpty())
.or(biomeComboBox.valueProperty().isNotNull()
.and(biomeComboBox.valueProperty().isNotEqualTo(MapGeneratorService.GENERATOR_RANDOM_BIOME))));
}

private void initBiomeComboBox() {
biomeComboBox.disableProperty()
.bind(previousMapName.textProperty().isNotEmpty()
.or(generationTypeComboBox.valueProperty().isNotEqualTo(GenerationType.CASUAL))
.or(commandLineArgsText.textProperty().isNotEmpty())
.or(mapStyleComboBox.valueProperty().isNotNull()
.and(mapStyleComboBox.valueProperty().isNotEqualTo(MapGeneratorService.GENERATOR_RANDOM_STYLE))));
}

private void initOptionSlider(IntegerProperty valueProperty, BooleanProperty randomProperty, Slider slider,
Expand Down Expand Up @@ -278,6 +293,7 @@ private GeneratorOptions getGeneratorOptions() {
optionsBuilder.numTeams(numTeamsSpinner.getValue());
optionsBuilder.generationType(generationTypeComboBox.getValue());
optionsBuilder.style(mapStyleComboBox.getValue());
optionsBuilder.biome(biomeComboBox.getValue());
getSliderValue(waterSlider, waterRandom).ifPresent(value -> optionsBuilder.landDensity(1 - value));
getSliderValue(plateauSlider, plateauRandom).ifPresent(optionsBuilder::plateauDensity);
getSliderValue(mountainSlider, mountainRandom).ifPresent(optionsBuilder::mountainDensity);
Expand Down Expand Up @@ -345,8 +361,9 @@ protected void setCreateGameController(CreateGameController controller) {
}

protected void setStyles(List<String> styles) {
styles.add(0, MapGeneratorService.GENERATOR_RANDOM_STYLE);
mapStyleComboBox.setItems(FXCollections.observableList(styles));
ArrayList<String> styleList = new ArrayList<>(List.of(MapGeneratorService.GENERATOR_RANDOM_STYLE));
styleList.addAll(styles);
mapStyleComboBox.setItems(FXCollections.observableList(styleList));
String mapStyle = generatorPrefs.getMapStyle();
if (mapStyleComboBox.getItems().contains(mapStyle)) {
mapStyleComboBox.getSelectionModel().select(mapStyle);
Expand All @@ -358,6 +375,21 @@ protected void setStyles(List<String> styles) {
mapStyleLabel.setVisible(true);
}

protected void setBiomes(List<String> biomes) {
ArrayList<String> biomeList = new ArrayList<>(List.of(MapGeneratorService.GENERATOR_RANDOM_BIOME));
biomeList.addAll(biomes);
biomeComboBox.setItems(FXCollections.observableList(biomeList));
String biome = generatorPrefs.getBiome();
if (biomeComboBox.getItems().contains(biome)) {
biomeComboBox.getSelectionModel().select(biome);
} else {
biomeComboBox.getSelectionModel().select(MapGeneratorService.GENERATOR_RANDOM_BIOME);
}
generatorPrefs.biomeProperty().bind(biomeComboBox.valueProperty());
biomeComboBox.setVisible(true);
biomeLabel.setVisible(true);
}

public void onNewLabelClicked(MouseEvent mouseEvent) {
if (mouseEvent.getButton().equals(MouseButton.PRIMARY) && mouseEvent.getClickCount() == 2) {
toggleCommandlineInput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class MapGeneratorService implements DisposableBean {
public static final String GENERATOR_EXECUTABLE_SUB_DIRECTORY = "map_generator";
public static final int GENERATION_TIMEOUT_SECONDS = 60 * 3;
public static final String GENERATOR_RANDOM_STYLE = "RANDOM";
public static final String GENERATOR_RANDOM_BIOME = "RANDOM";
private static final Pattern VERSION_PATTERN = Pattern.compile("\\d\\d?\\d?\\.\\d\\d?\\d?\\.\\d\\d?\\d?");
protected static final Pattern GENERATED_MAP_PATTERN = Pattern.compile("neroxis_map_generator_(" + VERSION_PATTERN + ")_(.*)");

Expand Down Expand Up @@ -189,6 +190,16 @@ public CompletableFuture<List<String>> getGeneratorStyles() {
return taskService.submitTask(generatorOptionsTask).getFuture();
}

public CompletableFuture<List<String>> getGeneratorBiomes() {
Assert.checkNullIllegalState(defaultGeneratorVersion, "Generator version not set");
GeneratorOptionsTask generatorOptionsTask = generatorOptionsTaskFactory.getObject();
Path generatorExecutablePath = getGeneratorExecutablePath(defaultGeneratorVersion);
generatorOptionsTask.setVersion(defaultGeneratorVersion);
generatorOptionsTask.setQuery("--biomes");
generatorOptionsTask.setGeneratorExecutableFile(generatorExecutablePath);
return taskService.submitTask(generatorOptionsTask).getFuture();
}

@NotNull
public Path getGeneratorExecutablePath(ComparableVersion defaultGeneratorVersion) {
return dataPrefs.getMapGeneratorDirectory()
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/faforever/client/preferences/GeneratorPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class GeneratorPrefs {
private final IntegerProperty numTeams = new SimpleIntegerProperty(2);
private final DoubleProperty mapSizeInKm = new SimpleDoubleProperty(10);
private final StringProperty mapStyle = new SimpleStringProperty("");
private final StringProperty biome = new SimpleStringProperty("");
private final IntegerProperty waterDensity = new SimpleIntegerProperty(0);
private final BooleanProperty waterRandom = new SimpleBooleanProperty(true);
private final IntegerProperty plateauDensity = new SimpleIntegerProperty(0);
Expand Down Expand Up @@ -93,6 +94,18 @@ public StringProperty mapStyleProperty() {
return mapStyle;
}

public String getBiome() {
return biome.get();
}

public void setBiome(String biome) {
this.biome.set(biome);
}

public StringProperty biomeProperty() {
return biome;
}

public GenerationType getGenerationType() {
return generationType.get();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@ management.maps.officialMaps = Official maps
management.maps.uninstall.error = cannot uninstall the map
game.generateMap.commandLine = Command Arguments
game.generateMap.style = Map Style
game.generateMap.biome = Biome
game.mapGeneration.options.title = Getting map options (Version\: {0})
game.replayNotAvailable = Replay file not available at this time
game.filter.numberOfPlayers = Number of players
Expand Down

0 comments on commit 71bbca0

Please sign in to comment.