Skip to content

Commit af35372

Browse files
committed
external database support
1 parent 411b3c1 commit af35372

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: 16 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,26 @@ 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;
273+
}
274+
275+
public String getUrl(UnitDatabase db) {
276+
return switch (this) {
277+
case SPOOKY -> db.getSpookiesUrl();
278+
case RACKOVER -> db.getRackOversUrl();
279+
case ETFREEMAN -> db.getEtfreemanUrl();
280+
};
268281
}
269282
}
270283
}

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

Lines changed: 70 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,75 @@
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;
37+
38+
private UnitDataBaseType currentType;
2139

22-
public WebView unitsRoot;
40+
public StackPane unitsRoot;
41+
public WebView webView;
42+
public StackPane externalBrowserPane;
43+
public VBox contentBox;
44+
public Label titleLabel;
2345

2446
@Override
2547
protected void onInitialize() {
48+
JavaFxUtil.bindManagedToVisible(webView, externalBrowserPane);
49+
contentBox.translateYProperty().bind(externalBrowserPane.heightProperty().multiply(0.15));
2650
preferences.unitDataBaseTypeProperty().when(showing).subscribe(this::loadUnitDataBase);
2751
}
2852

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

3496
@Override
35-
public Node getRoot() {
97+
public StackPane getRoot() {
3698
return unitsRoot;
3799
}
38100

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
@@ -141,6 +141,30 @@
141141
-fx-border-color: -fx-box-border;
142142
}
143143

144+
/***************** Unit Database External *****************/
145+
146+
.unit-database-overlay {
147+
-fx-background-color: rgba(0, 0, 0, 0.75);
148+
}
149+
150+
.unit-database-content {
151+
-fx-background-color: -fx-base;
152+
-fx-border-radius: 3;
153+
-fx-border-color: -fx-box-border;
154+
-fx-padding: 15 0 0 0;
155+
}
156+
157+
.unit-database-title {
158+
-fx-font-size: 28px;
159+
-fx-padding: 0 0 10 0;
160+
-fx-text-fill: white;
161+
}
162+
163+
.unit-database-subtitle {
164+
-fx-padding: 0 0 20 0;
165+
-fx-text-fill: #eee;
166+
}
167+
144168
/*******************************************************************************
145169
* *
146170
* Pagination *
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)