mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-03-07 17:36:52 +08:00
feat(multiplayer): show token expire time.
This commit is contained in:
parent
0f4a5c26df
commit
4d54c7f6ba
@ -32,6 +32,7 @@ import org.jackhuang.hmcl.util.HMCLService;
|
||||
import org.jackhuang.hmcl.util.TaskCancellationAction;
|
||||
import org.jackhuang.hmcl.util.io.ChecksumMismatchException;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
@ -48,9 +49,11 @@ public class MultiplayerPage extends DecoratorAnimatedPage implements DecoratorP
|
||||
private final ReadOnlyObjectWrapper<MultiplayerManager.HiperSession> session = new ReadOnlyObjectWrapper<>();
|
||||
private final IntegerProperty port = new SimpleIntegerProperty();
|
||||
private final StringProperty address = new SimpleStringProperty();
|
||||
private final ReadOnlyObjectWrapper<Instant> expireTime = new ReadOnlyObjectWrapper<>();
|
||||
|
||||
private Consumer<MultiplayerManager.HiperExitEvent> onExit;
|
||||
private Consumer<MultiplayerManager.HiperIPEvent> onIPAllocated;
|
||||
private Consumer<MultiplayerManager.HiperShowValidAtEvent> onValidAt;
|
||||
|
||||
public MultiplayerPage() {
|
||||
}
|
||||
@ -89,6 +92,18 @@ public class MultiplayerPage extends DecoratorAnimatedPage implements DecoratorP
|
||||
this.address.set(address);
|
||||
}
|
||||
|
||||
public Instant getExpireTime() {
|
||||
return expireTime.get();
|
||||
}
|
||||
|
||||
public ReadOnlyObjectWrapper<Instant> expireTimeProperty() {
|
||||
return expireTime;
|
||||
}
|
||||
|
||||
public void setExpireTime(Instant expireTime) {
|
||||
this.expireTime.set(expireTime);
|
||||
}
|
||||
|
||||
public MultiplayerManager.HiperSession getSession() {
|
||||
return session.get();
|
||||
}
|
||||
@ -180,6 +195,7 @@ public class MultiplayerPage extends DecoratorAnimatedPage implements DecoratorP
|
||||
this.session.set(session);
|
||||
onExit = session.onExit().registerWeak(this::onExit);
|
||||
onIPAllocated = session.onIPAllocated().registerWeak(this::onIPAllocated);
|
||||
onValidAt = session.onValidAt().registerWeak(this::onValidAt);
|
||||
}, Schedulers.javafx())
|
||||
.exceptionally(throwable -> {
|
||||
runInFX(() -> Controllers.dialog(localizeErrorMessage(throwable), null, MessageDialogPane.MessageType.ERROR));
|
||||
@ -198,12 +214,17 @@ public class MultiplayerPage extends DecoratorAnimatedPage implements DecoratorP
|
||||
this.session.set(null);
|
||||
this.onExit = null;
|
||||
this.onIPAllocated = null;
|
||||
this.onValidAt = null;
|
||||
}
|
||||
|
||||
private void onIPAllocated(MultiplayerManager.HiperIPEvent event) {
|
||||
runInFX(() -> this.address.set(event.getIP()));
|
||||
}
|
||||
|
||||
private void onValidAt(MultiplayerManager.HiperShowValidAtEvent event) {
|
||||
runInFX(() -> this.expireTime.set(event.getValidAt()));
|
||||
}
|
||||
|
||||
private void onExit(MultiplayerManager.HiperExitEvent event) {
|
||||
runInFX(() -> {
|
||||
switch (event.getExitCode()) {
|
||||
|
@ -41,6 +41,9 @@ import org.jackhuang.hmcl.ui.versions.Versions;
|
||||
import org.jackhuang.hmcl.util.HMCLService;
|
||||
import org.jackhuang.hmcl.util.Lang;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
|
||||
import static org.jackhuang.hmcl.setting.ConfigHolder.globalConfig;
|
||||
import static org.jackhuang.hmcl.ui.versions.VersionPage.wrap;
|
||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||
@ -132,6 +135,15 @@ public class MultiplayerPageSkin extends DecoratorAnimatedPage.DecoratorAnimated
|
||||
|
||||
ComponentList onPane = new ComponentList();
|
||||
{
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);
|
||||
BorderPane expirationPane = new BorderPane();
|
||||
expirationPane.setLeft(new Label(i18n("multiplayer.session.expiration")));
|
||||
Label expirationLabel = new Label();
|
||||
expirationLabel.textProperty().bind(Bindings.createStringBinding(() ->
|
||||
control.getExpireTime() == null ? "" : formatter.format(control.getExpireTime()),
|
||||
control.expireTimeProperty()));
|
||||
expirationPane.setCenter(expirationLabel);
|
||||
|
||||
GridPane masterPane = new GridPane();
|
||||
masterPane.setVgap(8);
|
||||
masterPane.setHgap(16);
|
||||
@ -193,7 +205,13 @@ public class MultiplayerPageSkin extends DecoratorAnimatedPage.DecoratorAnimated
|
||||
slavePane.getChildren().setAll(new Label(i18n("multiplayer.slave")), slaveHintPane);
|
||||
}
|
||||
|
||||
onPane.getContent().setAll(masterPane, slavePane);
|
||||
FXUtils.onChangeAndOperate(control.expireTimeProperty(), t -> {
|
||||
if (t == null) {
|
||||
onPane.getContent().setAll(masterPane, slavePane);
|
||||
} else {
|
||||
onPane.getContent().setAll(expirationPane, masterPane, slavePane);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
FXUtils.onChangeAndOperate(getSkinnable().sessionProperty(), session -> {
|
||||
|
@ -848,6 +848,7 @@ multiplayer.download.unsupported=Multiplayer dependencies are not supported on c
|
||||
multiplayer.error.failed_get_device=HiPer could not create a network device, maybe HiPer has already started or lacks administrator privileges.
|
||||
multiplayer.error.failed_load_config=HiPer initialization failed, maybe there is a problem with the configuration file or the certificate is invalid.
|
||||
multiplayer.error.file_not_found=The HiPer program could not be found. The program should finish downloading when entering the multiplayer page. Please restart HMCL and try again. \nPlease check if your computer's antivirus software has flagged HiPer as a virus, and if so, restore HiPer.
|
||||
multiplayer.error.session_expired=Current multiplayer session has been expired. Please fetch a new multiplayer token.
|
||||
multiplayer.exit=HiPer exited unexpectedly with exit code %d
|
||||
multiplayer.hint=The multiplayer online function is in the experimental stage, if you have any questions, please go to mcer.cn to give feedback
|
||||
multiplayer.powered_by=This service is provided under the license of (<a href="https://mcer.cn">Matrix Lab</a>)<a href\="https\://hmcl.huangyuhui.net/api/redirect/multiplayer-agreement" >License Agreement</a>
|
||||
@ -871,6 +872,7 @@ multiplayer.master.port=Port number
|
||||
multiplayer.master.port.validate=The port number (0~65535) displayed in the game chat box,when you open the game in LAN.
|
||||
multiplayer.slave=Participant Prompt
|
||||
multiplayer.slave.hint=If you want to join another player's game save to play the game, you need to ask that player to turn on the open mode to the local area network according to the operation prompted by the creator. Then start the game, and select the multiplayer mode, select Add Server. The game will ask you to enter the server address, you only need to create a player to ask for the server address and enter it, and then enter the server.
|
||||
multiplayer.session.expiration=Expire Time
|
||||
|
||||
datapack=Datapacks
|
||||
datapack.add=Install datapack
|
||||
|
@ -696,6 +696,7 @@ multiplayer.download.unsupported=多人聯機依賴不支持當前系統或平
|
||||
multiplayer.error.failed_get_device=HiPer 無法創建網絡設備,可能是HiPer已經啟動或缺少管理員權限。
|
||||
multiplayer.error.failed_load_config=HiPer 初始化失敗,可能是配置文件存在問題或證書已失效。
|
||||
multiplayer.error.file_not_found=找不到 HiPer 程式。該程式應該在進入多人聯機頁面時完成下載。請重啟 HMCL 再試。\n請檢查你電腦的防毒軟體是否將 HiPer 標記為病毒,如果是,請恢復 HiPer。
|
||||
multiplayer.error.session_expired=本次使用時間已結束,若要繼續使用,請更新憑證
|
||||
multiplayer.exit=HiPer 意外退出,退出碼 %d
|
||||
multiplayer.hint=多人聯機功能處於實驗階段,如果有問題請前往 mcer.cn 回饋
|
||||
multiplayer.powered_by=本服務由 (<a href="https://mcer.cn">速聚</a>) 提供。<a href\="https\://hmcl.huangyuhui.net/api/redirect/multiplayer-agreement">授權協議</a>
|
||||
@ -719,6 +720,7 @@ multiplayer.master.port.validate=在遊戲聊天框中出現的埠號 (0~65535)
|
||||
multiplayer.slave=參與者提示
|
||||
multiplayer.slave.hint=1.要求創建方按照上方的 創建方提示 操作\n2.啟動遊戲\n3.選擇多人遊戲模式,選擇添加伺服器\n4.遊戲會要求你輸入伺服器地址,你只需要向創建方索要伺服器地址並輸入,並進入伺服器即可。 \n- 注意:\n1.一般情況下,參與者的遊戲賬戶必須是 微軟賬戶 或 外置登錄賬戶(如 Little Skin),否則加入失敗,具體操作方法詳見左側的 幫助 \n2.一般情況下,參與者的遊戲版本、模組要必須與創建方的一致,否則加入失敗。
|
||||
#(若加回 LocalServerBroadcaster.java,就使用)multiplayer.slave.hint=1.要求創建方按照上方的 創建方提示 操作\n2.啟動遊戲\n3.選擇多人遊戲模式,選擇添加伺服器\n4.遊戲會要求你輸入伺服器地址,你只需要向創建方索要伺服器地址並輸入,並進入伺服器即可。 \n- 注意:\n1.一般情況下,參與者的遊戲賬戶必須是 微軟賬戶 或 外置登錄賬戶(如 Little Skin),否則你需要將伺服器地址輸入至下方的輸入框中並點擊廣播,在遊戲中選擇多人遊戲模式,進入局域網世界方可加入,具體操作方法詳見左側的 幫助 \n2.一般情況下,參與者的遊戲版本、模組要必須與創建方的一致,否則加入失敗。
|
||||
multiplayer.session.expiration=本次使用截止時間
|
||||
|
||||
datapack=資料包
|
||||
datapack.add=加入資料包
|
||||
|
@ -696,6 +696,7 @@ multiplayer.download.unsupported=多人联机依赖不支持当前系统或平
|
||||
multiplayer.error.failed_get_device=HiPer 无法创建网络设备,可能是HiPer已经启动或缺少管理员权限。
|
||||
multiplayer.error.failed_load_config=HiPer 初始化失败,可能是配置文件存在问题或证书已失效。
|
||||
multiplayer.error.file_not_found=找不到 HiPer 程序。该程序应该在进入多人联机页面时完成下载。请重启 HMCL 再试。\n请检查你电脑的杀毒软件是否将 HiPer 标记为病毒,如果是,请恢复 HiPer。
|
||||
multiplayer.error.session_expired=本次使用时间已结束,若要继续使用,请更新凭证
|
||||
multiplayer.exit=HiPer 意外退出,退出码 %d
|
||||
multiplayer.hint=多人联机功能处于实验阶段,如果有问题请前往 mcer.cn 反馈
|
||||
multiplayer.powered_by=本服务由 (<a href="https://mcer.cn">速聚</a>) 授权提供 <a href\="https\://hmcl.huangyuhui.net/api/redirect/multiplayer-agreement">授权协议</a>
|
||||
@ -719,6 +720,7 @@ multiplayer.master.port.validate=在游戏聊天框中出现的端口号 (0~6553
|
||||
multiplayer.slave=参与者提示
|
||||
multiplayer.slave.hint=1.要求创建方按照上方的 创建方提示 操作\n2.启动游戏\n3.选择多人游戏模式,选择添加服务器\n4.游戏会要求你输入服务器地址,你只需要向创建方索要服务器地址并输入,并进入服务器即可。\n- 注意:\n1.一般情况下,参与者的游戏账户必须是 微软账户 或 外置登录账户(如 Little Skin),否则加入失败,具体操作方法详见左侧的 帮助 \n2.一般情况下,参与者的游戏版本、模组要必须与创建方的一致,否则加入失败。
|
||||
#(若加回 LocalServerBroadcaster.java,就使用)multiplayer.slave.hint=1.要求创建方按照上方的 创建方提示 操作\n2.启动游戏\n3.选择多人游戏模式,选择添加服务器\n4.游戏会要求你输入服务器地址,你只需要向创建方索要服务器地址并输入,并进入服务器即可。\n- 注意:\n1.一般情况下,参与者的游戏账户必须是 微软账户 或 外置登录账户(如 Little Skin),否则你需要将服务器地址输入至下方的输入框中并点击广播,在游戏中选择多人游戏模式,进入局域网世界方可加入,具体操作方法详见左侧的 帮助 \n2.一般情况下,参与者的游戏版本、模组要必须与创建方的一致,否则加入失败。
|
||||
multiplayer.session.expiration=本次使用截止时间
|
||||
|
||||
datapack=数据包
|
||||
datapack.add=添加数据包
|
||||
|
Loading…
Reference in New Issue
Block a user