-
Notifications
You must be signed in to change notification settings - Fork 8
Add: 為單人回檔新增-gui-詳細信息 #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7f7342d
Add restore info GUI for singleplayer
whats2000 a39ea55
Add: 為單人回檔新增-gui-詳細信息
whats2000 30c9c1b
fix for 1.21.5
zly2006 30bfa3e
feat(gui): show restore progress and reopen button
whats2000 fbb7e04
Add: 新增進度條與重新打開按鈕
whats2000 7736a28
fix
zly2006 02e5559
fix: add compatibility for 1.20.1 GUI
whats2000 13f180b
Fix: 處理1.20.1版本gui兼容性問題
whats2000 05a4377
fix
zly2006 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/main/kotlin/com/github/zly2006/xbackup/gui/RestoreInfoScreen.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package com.github.zly2006.xbackup.gui | ||
|
|
||
| import com.github.zly2006.xbackup.XBackup | ||
| import com.github.zly2006.xbackup.api.IBackup | ||
| import net.minecraft.client.MinecraftClient | ||
| import net.minecraft.client.gui.DrawContext | ||
| import net.minecraft.client.gui.screen.Screen | ||
| import net.minecraft.client.gui.widget.ButtonWidget | ||
| import net.minecraft.text.Text | ||
| import java.nio.file.Path | ||
| import kotlin.io.path.name | ||
|
|
||
| class RestoreInfoScreen(private val backup: IBackup, private val worldRoot: Path) : Screen(Text.translatable("xb.gui.restore.title")) { | ||
| private lateinit var reopenButton: ButtonWidget | ||
|
|
||
| override fun init() { | ||
| reopenButton = addDrawableChild( | ||
| ButtonWidget.builder(Text.translatable("xb.gui.restore.reopen")) { | ||
| reopenWorld() | ||
| }.dimensions(width / 2 - 75, height - 52, 150, 20).build() | ||
| ) | ||
| addDrawableChild( | ||
| ButtonWidget.builder(Text.translatable("xb.gui.restore.close")) { | ||
| client?.setScreen(null) | ||
| }.dimensions(width / 2 - 75, height - 28, 150, 20).build() | ||
| ) | ||
| } | ||
|
|
||
| override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) { | ||
| //? if >= 1.20.4 { | ||
| renderBackground(context, mouseX, mouseY, delta) | ||
| //?} else { | ||
| /*renderBackground(context) | ||
| *///?} | ||
| super.render(context, mouseX, mouseY, delta) | ||
| context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 20, 0xFFFFFF) | ||
| var y = height / 2 - 20 | ||
| val idText = Text.translatable("xb.gui.restore.id", backup.id) | ||
| context.drawCenteredTextWithShadow(textRenderer, idText, width / 2, y, 0xFFFFFF) | ||
| y += 12 | ||
| if (backup.comment.isNotEmpty()) { | ||
| val comment = Text.translatable("xb.gui.restore.comment", backup.comment) | ||
| context.drawCenteredTextWithShadow(textRenderer, comment, width / 2, y, 0xFFFFFF) | ||
| } | ||
|
|
||
| val progress = XBackup.service.activeTaskProgress | ||
| if (progress in 0..100) { | ||
| val barWidth = 150 | ||
| val barHeight = 8 | ||
| val x = (width - barWidth) / 2 | ||
| val yBar = height / 2 + 20 | ||
| context.fill(x, yBar, x + barWidth, yBar + barHeight, 0xFF555555.toInt()) | ||
| val w = (barWidth * progress) / 100 | ||
| if (w > 0) { | ||
| context.fill(x + 1, yBar + 1, x + w - 1, yBar + barHeight - 1, 0xFF00FF00.toInt()) | ||
| } | ||
| context.drawCenteredTextWithShadow(textRenderer, Text.literal("$progress%"), width / 2, yBar - 10, 0xFFFFFF) | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| fun open(backup: IBackup, worldRoot: Path) { | ||
| val client = MinecraftClient.getInstance() | ||
| client.execute { client.setScreen(RestoreInfoScreen(backup, worldRoot)) } | ||
| } | ||
| } | ||
|
|
||
| private fun reopenWorld() { | ||
| val client = MinecraftClient.getInstance() | ||
| client.setScreen(null) | ||
| runCatching { | ||
| val loader = client.createIntegratedServerLoader() | ||
| //? if >= 1.20.4 { | ||
| loader.start(worldRoot.normalize().name) { | ||
| this.close() | ||
| } | ||
| //?} else { | ||
| /*loader.start(this, worldRoot.normalize().name) | ||
| *///?} | ||
| }.onFailure { XBackup.log.error("Failed to reopen world", it) } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the non-force-stop branch,
it.finishRestore()is never called, so cleanup and notifications may not run. Consider moving or duplicating theit.finishRestore()call before opening the GUI to ensure the restore finalization always happens.