Skip to content

Commit efc8546

Browse files
authored
Adding external unit databases + etfreeman-db support (#3477)
* external database support * moved styles to better place * microfix * opening external database on the tab click * requested changes
1 parent 039675c commit efc8546

File tree

9 files changed

+143
-15
lines changed

9 files changed

+143
-15
lines changed

src/main/java/com/faforever/client/config/ClientProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public void updateFromEndpoint(ServerEndpoints serverEndpoints) {
181181
public static class UnitDatabase {
182182
private String spookiesUrl;
183183
private String rackOversUrl;
184+
private String etfreemanUrl;
184185
}
185186

186187
@Data

src/main/java/com/faforever/client/preferences/Preferences.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.faforever.client.preferences;
22

3+
import com.faforever.client.config.ClientProperties.UnitDatabase;
34
import com.faforever.client.game.GamesTilesContainerController.TilesSortingOrder;
45
import com.fasterxml.jackson.annotation.JsonMerge;
56
import javafx.beans.property.BooleanProperty;
@@ -257,14 +258,18 @@ public BooleanProperty mapAndModAutoUpdateProperty() {
257258
}
258259

259260
public enum UnitDataBaseType {
260-
SPOOKY("unitDatabase.spooky"),
261-
RACKOVER("unitDatabase.rackover");
261+
SPOOKY("unitDatabase.spooky", false),
262+
RACKOVER("unitDatabase.rackover", false),
263+
ETFREEMAN("unitDatabase.etfreeman", true);
262264

263265
@Getter
264266
private final String i18nKey;
267+
@Getter
268+
private final boolean external;
265269

266-
UnitDataBaseType(String i18nKey) {
270+
UnitDataBaseType(String i18nKey, boolean external) {
267271
this.i18nKey = i18nKey;
272+
this.external = external;
268273
}
269274
}
270275
}

src/main/java/com/faforever/client/units/UnitsController.java

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
package com.faforever.client.units;
22

33
import com.faforever.client.config.ClientProperties;
4-
import com.faforever.client.config.ClientProperties.UnitDatabase;
54
import com.faforever.client.fx.NodeController;
5+
import com.faforever.client.fx.PlatformService;
6+
import com.faforever.client.fx.JavaFxUtil;
7+
import com.faforever.client.i18n.I18n;
68
import com.faforever.client.preferences.Preferences;
79
import com.faforever.client.preferences.Preferences.UnitDataBaseType;
8-
import javafx.scene.Node;
10+
import com.faforever.client.theme.ThemeService;
11+
import javafx.scene.control.Label;
12+
import javafx.scene.image.Image;
13+
import javafx.scene.layout.Background;
14+
import javafx.scene.layout.BackgroundImage;
15+
import javafx.scene.layout.BackgroundPosition;
16+
import javafx.scene.layout.BackgroundRepeat;
17+
import javafx.scene.layout.BackgroundSize;
18+
import javafx.scene.layout.StackPane;
19+
import javafx.scene.layout.VBox;
920
import javafx.scene.web.WebView;
1021
import lombok.RequiredArgsConstructor;
1122
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@@ -15,24 +26,83 @@
1526
@Component
1627
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
1728
@RequiredArgsConstructor
18-
public class UnitsController extends NodeController<Node> {
29+
public class UnitsController extends NodeController<StackPane> {
30+
private static final String UNIT_DB_IMAGES_PATH = "theme/images/unit_databases/";
31+
1932
private final ClientProperties clientProperties;
2033
private final Preferences preferences;
34+
private final PlatformService platformService;
35+
private final I18n i18n;
36+
private final ThemeService themeService;
2137

22-
public WebView unitsRoot;
38+
public StackPane unitsRoot;
39+
public WebView webView;
40+
public StackPane externalBrowserPane;
41+
public VBox contentBox;
42+
public Label titleLabel;
2343

2444
@Override
2545
protected void onInitialize() {
46+
JavaFxUtil.bindManagedToVisible(webView, externalBrowserPane);
47+
contentBox.translateYProperty().bind(externalBrowserPane.heightProperty().multiply(0.15));
2648
preferences.unitDataBaseTypeProperty().when(showing).subscribe(this::loadUnitDataBase);
2749
}
2850

29-
private void loadUnitDataBase(UnitDataBaseType newValue) {
30-
UnitDatabase unitDatabase = clientProperties.getUnitDatabase();
31-
unitsRoot.getEngine().load(newValue == UnitDataBaseType.SPOOKY ? unitDatabase.getSpookiesUrl() : unitDatabase.getRackOversUrl());
51+
private void loadUnitDataBase(UnitDataBaseType type) {
52+
boolean isExternal = type.isExternal();
53+
54+
webView.setVisible(!isExternal);
55+
externalBrowserPane.setVisible(isExternal);
56+
57+
if (isExternal) {
58+
platformService.showDocument(getUnitDbUrl(type));
59+
String dbName = i18n.get(type.getI18nKey());
60+
titleLabel.setText(i18n.get("unitDatabase.external.message", dbName));
61+
loadBackgroundImage(type);
62+
} else {
63+
String url = getUnitDbUrl(type);
64+
webView.getEngine().load(url);
65+
}
66+
}
67+
68+
private void loadBackgroundImage(UnitDataBaseType type) {
69+
String imagePath = UNIT_DB_IMAGES_PATH + type.name().toLowerCase() + ".png";
70+
Image image = themeService.getThemeImage(imagePath);
71+
72+
if (image == null || image.isError()) {
73+
externalBrowserPane.setBackground(null);
74+
return;
75+
}
76+
77+
BackgroundImage bgImage = new BackgroundImage(
78+
image,
79+
BackgroundRepeat.NO_REPEAT,
80+
BackgroundRepeat.NO_REPEAT,
81+
BackgroundPosition.CENTER,
82+
new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, false, false, true, true)
83+
);
84+
externalBrowserPane.setBackground(new Background(bgImage));
85+
}
86+
87+
public void onOpenExternalBrowserClicked() {
88+
UnitDataBaseType type = preferences.getUnitDataBaseType();
89+
if (!type.isExternal()) {
90+
return;
91+
}
92+
platformService.showDocument(getUnitDbUrl(type));
93+
}
94+
95+
private String getUnitDbUrl(UnitDataBaseType type) {
96+
ClientProperties.UnitDatabase db = clientProperties.getUnitDatabase();
97+
return switch (type) {
98+
case SPOOKY -> db.getSpookiesUrl();
99+
case RACKOVER -> db.getRackOversUrl();
100+
case ETFREEMAN -> db.getEtfreemanUrl();
101+
};
32102
}
33103

34104
@Override
35-
public Node getRoot() {
105+
public StackPane getRoot() {
36106
return unitsRoot;
37107
}
38108

src/main/resources/application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ faf-client:
4141
unit-database:
4242
spookiesUrl: https://faforever.github.io/spooky-db/#/
4343
rackOversUrl: https://unitdb.faforever.com?settings64=eyJwcmV2aWV3Q29ybmVyIjoiTm9uZSJ9
44+
etfreemanUrl: https://faforever.github.io/etfreeman-db/#/
4445

4546
vanillaGameHashes:
4647
- 1AFBCD0CA85546470660FA8AC09B230E870EC65C8D1B33FEB6731BB5D4C366C5

src/main/resources/i18n/messages.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ userInfo.statistics.errorLoading = Could not load statistics
596596
settings.general.unitDatabase = Unit Database
597597
unitDatabase.rackover = Rackover
598598
unitDatabase.spooky = Spooky
599+
unitDatabase.etfreeman = ETFreeman
600+
unitDatabase.external.message = Unit Database by {0}
601+
unitDatabase.external.description = This database is best experienced using an external browser
602+
unitDatabase.external.openButton = Open in Browser
599603
game.player.rating = One of the player's ratings
600604
mapVault.ladder = Ladder maps
601605
news.showLadderMaps = Show ladder maps

src/main/resources/i18n/messages_ru.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,10 @@ userInfo.statistics.errorLoading = Статистка не загрузилас
619619
settings.general.unitDatabase = Информация о юнитах
620620
unitDatabase.rackover = Rackover
621621
unitDatabase.spooky = Spooky
622+
unitDatabase.etfreeman = ETFreeman
623+
unitDatabase.external.message = База юнитов от {0}
624+
unitDatabase.external.description = Эта база лучше работает во внешнем браузере
625+
unitDatabase.external.openButton = Открыть в браузере
622626
# the overall and average rating of all players in the match?
623627
game.player.rating = Один из рейтингов игрока
624628
mapVault.ladder = Рейтинговые карты
562 KB
Loading

src/main/resources/theme/style.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,30 @@
946946
-fx-stroke: transparent;
947947
}
948948

949+
/***************** Unit Database External *****************/
950+
951+
.unit-database-overlay {
952+
-fx-background-color: rgba(0, 0, 0, 0.75);
953+
}
954+
955+
.unit-database-content {
956+
-fx-background-color: -fx-base;
957+
-fx-border-radius: 3;
958+
-fx-border-color: -fx-box-border;
959+
-fx-padding: 15 0 0 0;
960+
}
961+
962+
.unit-database-title {
963+
-fx-font-size: 28px;
964+
-fx-padding: 0 0 10 0;
965+
-fx-text-fill: white;
966+
}
967+
968+
.unit-database-subtitle {
969+
-fx-padding: 0 0 20 0;
970+
-fx-text-fill: #eee;
971+
}
972+
949973
/***************** Match maker *****************/
950974

951975
.tmm {
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
3+
<?import javafx.scene.control.Button?>
4+
<?import javafx.scene.control.Label?>
5+
<?import javafx.scene.layout.Region?>
6+
<?import javafx.scene.layout.StackPane?>
7+
<?import javafx.scene.layout.VBox?>
48
<?import javafx.scene.web.WebView?>
5-
<WebView xmlns:fx="http://javafx.com/fxml/1" fx:id="unitsRoot"
6-
fx:controller="com.faforever.client.units.UnitsController" minHeight="200.0" minWidth="200.0" prefHeight="-1.0"
7-
prefWidth="-1.0" xmlns="http://javafx.com/javafx/8.0.60"/>
9+
<StackPane xmlns:fx="http://javafx.com/fxml/1" fx:id="unitsRoot"
10+
fx:controller="com.faforever.client.units.UnitsController" minHeight="200.0" minWidth="200.0"
11+
xmlns="http://javafx.com/javafx/8.0.60">
12+
13+
<WebView fx:id="webView" prefHeight="-1.0" prefWidth="-1.0"/>
14+
15+
<StackPane fx:id="externalBrowserPane" visible="false">
16+
<Region styleClass="unit-database-overlay"/>
17+
<VBox fx:id="contentBox" alignment="TOP_CENTER" StackPane.alignment="TOP_CENTER"
18+
styleClass="unit-database-content" maxWidth="450" maxHeight="160">
19+
<Label fx:id="titleLabel" styleClass="unit-database-title" wrapText="true"/>
20+
<Label text="%unitDatabase.external.description" styleClass="unit-database-subtitle" wrapText="true"/>
21+
<Button text="%unitDatabase.external.openButton" onAction="#onOpenExternalBrowserClicked"
22+
styleClass="primary-button" maxWidth="300"/>
23+
</VBox>
24+
</StackPane>
25+
26+
</StackPane>

0 commit comments

Comments
 (0)