Skip to content

Commit 952cc5d

Browse files
CalbootGlavo3gf8jv4dv
authored
[Feature] 允许设置游戏内容默认下载源 (#5781)
Resolves #5594 Co-authored-by: Glavo <zjx001202@gmail.com> Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com>
1 parent 356df5d commit 952cc5d

6 files changed

Lines changed: 44 additions & 7 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,21 @@ public void setVersionListSource(String versionListSource) {
567567
this.versionListSource.set(versionListSource);
568568
}
569569

570+
@SerializedName("defaultAddonSource")
571+
private final StringProperty defaultAddonSource = new SimpleStringProperty("modrinth");
572+
573+
public StringProperty defaultAddonSourceProperty() {
574+
return defaultAddonSource;
575+
}
576+
577+
public String getDefaultAddonSource() {
578+
return defaultAddonSource.get();
579+
}
580+
581+
public void setDefaultAddonSource(String defaultAddonSource) {
582+
this.defaultAddonSource.set(defaultAddonSource);
583+
}
584+
570585
@SerializedName("hasProxy")
571586
private final BooleanProperty hasProxy = new SimpleBooleanProperty();
572587

HMCL/src/main/java/org/jackhuang/hmcl/ui/main/DownloadSettingsPage.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,13 @@ public DownloadSettingsPage() {
8585
downloadSourcePane.setItems(DownloadProviders.DIRECT_PROVIDERS.keySet());
8686
downloadSourcePane.valueProperty().bindBidirectional(config().downloadTypeProperty());
8787

88-
downloadSource.getContent().setAll(autoChooseDownloadSource, versionListSourcePane, downloadSourcePane);
88+
var defaultAddonSourcePane = new LineSelectButton<String>();
89+
defaultAddonSourcePane.setTitle(i18n("settings.launcher.default_addon_source"));
90+
defaultAddonSourcePane.setConverter(key -> I18n.i18n("mods." + key));
91+
defaultAddonSourcePane.setItems("modrinth", "curseforge");
92+
defaultAddonSourcePane.valueProperty().bindBidirectional(config().defaultAddonSourceProperty());
93+
94+
downloadSource.getContent().setAll(autoChooseDownloadSource, versionListSourcePane, downloadSourcePane, defaultAddonSourcePane);
8995
}
9096

9197
content.getChildren().addAll(ComponentList.createComponentListTitle(i18n("settings.launcher.download_source")), downloadSource);

HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/HMCLLocalizedDownloadListPage.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.util.MissingResourceException;
2727

28+
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
2829
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
2930
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
3031

@@ -62,17 +63,29 @@ private HMCLLocalizedDownloadListPage(DownloadPage.DownloadCallback callback, bo
6263

6364
supportChinese.set(true);
6465

66+
boolean supportedCurseForge = CurseForgeRemoteModRepository.isAvailable() && curseForge != null;
67+
6568
downloadSources.setAll("mods.modrinth");
66-
if (CurseForgeRemoteModRepository.isAvailable()) {
69+
if (supportedCurseForge) {
6770
downloadSources.add("mods.curseforge");
6871
}
6972

70-
if (modrinth != null) {
71-
downloadSource.set("mods.modrinth");
72-
} else if (curseForge != null) {
73-
downloadSource.set("mods.curseforge");
73+
if ("curseforge".equalsIgnoreCase(config().getDefaultAddonSource())) {
74+
if (supportedCurseForge) {
75+
downloadSource.set("mods.curseforge");
76+
} else if (modrinth != null) {
77+
downloadSource.set("mods.modrinth");
78+
} else {
79+
throw new AssertionError("Should not be here.");
80+
}
7481
} else {
75-
throw new AssertionError("Should not be here.");
82+
if (modrinth != null) {
83+
downloadSource.set("mods.modrinth");
84+
} else if (supportedCurseForge) {
85+
downloadSource.set("mods.curseforge");
86+
} else {
87+
throw new AssertionError("Should not be here.");
88+
}
7689
}
7790
}
7891

HMCL/src/main/resources/assets/lang/I18N.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,7 @@ settings.launcher.download.threads.auto=Automatically Determine
14411441
settings.launcher.download.threads.hint=Too many threads may cause your system to freeze, and your download speed may be affected by your ISP and download servers. It is not always the case that more threads increase your download speed.
14421442
settings.launcher.download_source=Download Source
14431443
settings.launcher.download_source.auto=Automatically Choose Download Sources
1444+
settings.launcher.default_addon_source=Default Addon Source
14441445
settings.launcher.enable_game_list=Show instance list in homepage
14451446
settings.launcher.font=Font
14461447
settings.launcher.font.anti_aliasing=Anti-aliasing

HMCL/src/main/resources/assets/lang/I18N_zh.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,7 @@ settings.launcher.download.threads.auto=自動選取執行緒數
12261226
settings.launcher.download.threads.hint=執行緒數過高可能導致系統卡頓。你的下載速度會受到網際網路運營商、下載來源伺服器等方面的影響。調高下載執行緒數不一定能大幅提升總下載速度。
12271227
settings.launcher.download_source=下載來源
12281228
settings.launcher.download_source.auto=自動選取下載來源
1229+
settings.launcher.default_addon_source=遊戲內容預設下載來源
12291230
settings.launcher.enable_game_list=在首頁內顯示遊戲清單
12301231
settings.launcher.font=字體
12311232
settings.launcher.font.anti_aliasing=反鋸齒

HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@ settings.launcher.download.threads.auto=自动选择线程数
12311231
settings.launcher.download.threads.hint=线程数过高可能导致系统卡顿。你的下载速度会受到互联网运营商、下载源服务器等方面的影响。调高下载线程数不一定能大幅提升总下载速度。
12321232
settings.launcher.download_source=下载源
12331233
settings.launcher.download_source.auto=自动选择下载源
1234+
settings.launcher.default_addon_source=游戏内容默认下载源
12341235
settings.launcher.enable_game_list=在主页内显示版本列表
12351236
settings.launcher.font=字体
12361237
settings.launcher.font.anti_aliasing=抗锯齿

0 commit comments

Comments
 (0)