From c81da5f07e173ade2328022a45bfa41fb162f378 Mon Sep 17 00:00:00 2001 From: faluhub Date: Mon, 6 May 2024 21:28:05 +0200 Subject: [PATCH] view stats --- gradle.properties | 2 +- .../core/category/PracticeCategory.java | 26 ++++++++++++++++--- .../preferences/CategoryPreferences.java | 3 +++ .../gui/screen/InventoryOptionsScreen.java | 20 ++++++++++++-- .../gui/widget/ThumbnailButtonWidget.java | 4 +-- 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/gradle.properties b/gradle.properties index 875c1f0..91a7670 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=1.16.1+build.21 loader_version=0.15.7 # Mod Properties -mod_version=2.2-pre2 +mod_version=2.2-pre3 maven_group=me.falu archives_base_name=peepopractice diff --git a/src/main/java/me/falu/peepopractice/core/category/PracticeCategory.java b/src/main/java/me/falu/peepopractice/core/category/PracticeCategory.java index 55641b4..0b1f87d 100644 --- a/src/main/java/me/falu/peepopractice/core/category/PracticeCategory.java +++ b/src/main/java/me/falu/peepopractice/core/category/PracticeCategory.java @@ -15,6 +15,9 @@ import me.falu.peepopractice.core.writer.PracticeWriter; import net.minecraft.client.resource.language.I18n; import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.LiteralText; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; import net.minecraft.util.Formatting; import net.minecraft.world.gen.feature.ConfiguredStructureFeature; @@ -189,19 +192,34 @@ public String getName(boolean showPb) { return text.toString(); } - public String getPbText() { + public Text getPbText() { if (this.hasSplitEvent()) { PreferenceTypes.CompareType compareType = CategoryPreferences.COMPARE_TYPE.getValue(); boolean comparePb = compareType.equals(PreferenceTypes.CompareType.PB); boolean hasTime = comparePb ? this.getSplitEvent().hasPb() : this.getSplitEvent().hasCompletedTimes(); if (hasTime) { String timeString = comparePb ? this.getSplitEvent().getPbString() : this.getSplitEvent().getAverageString(); - return (comparePb ? Formatting.GREEN : Formatting.AQUA) + " (" + timeString + ")"; + return new LiteralText("(" + timeString + ")").formatted(comparePb ? Formatting.GREEN : Formatting.AQUA); } else { - return Formatting.GRAY + " " + new TranslatableText("peepopractice.text.no_pb_or_avg", CategoryPreferences.COMPARE_TYPE.getValueLabel(this)).getString(); + return new TranslatableText("peepopractice.text.no_pb_or_avg", CategoryPreferences.COMPARE_TYPE.getValueLabel(this)).formatted(Formatting.GRAY); } } - return ""; + return new LiteralText(""); + } + + public Text getStatsText() { + if (this.hasSplitEvent()) { + SplitEvent event = this.getSplitEvent(); + MutableText text = new LiteralText("(").formatted(Formatting.GRAY); + text.append(new LiteralText("" + event.getAttempts()).formatted(Formatting.WHITE)); + text.append(new LiteralText("/").formatted(Formatting.GRAY)); + text.append(new LiteralText("" + event.getCompletionCount()).formatted(Formatting.GREEN)); + text.append(new LiteralText("/").formatted(Formatting.GRAY)); + text.append(new LiteralText("" + event.getFailCount()).formatted(Formatting.RED)); + text.append(new LiteralText(")").formatted(Formatting.GRAY)); + return text; + } + return new LiteralText(""); } public boolean isAA() { diff --git a/src/main/java/me/falu/peepopractice/core/category/preferences/CategoryPreferences.java b/src/main/java/me/falu/peepopractice/core/category/preferences/CategoryPreferences.java index 2082962..49c14fb 100644 --- a/src/main/java/me/falu/peepopractice/core/category/preferences/CategoryPreferences.java +++ b/src/main/java/me/falu/peepopractice/core/category/preferences/CategoryPreferences.java @@ -86,6 +86,9 @@ public class CategoryPreferences { public static final CategoryPreference SELECTED_INVENTORY = new CategoryPreference() .setId("selected_inventory") .setDefaultValue(PreferenceTypes.SelectedInventoryType.ONE); + public static final CategoryPreference RANDOM_INVENTORY = new CategoryPreference() + .setId("random_inventory") + .setDefaultValue(PreferenceTypes.BooleanType.DISABLED); public static final CategoryPreference SCRAMBLE_INVENTORY = new CategoryPreference() .setId("scramble_inventory") .setDefaultValue(PreferenceTypes.BooleanType.DISABLED); diff --git a/src/main/java/me/falu/peepopractice/gui/screen/InventoryOptionsScreen.java b/src/main/java/me/falu/peepopractice/gui/screen/InventoryOptionsScreen.java index 0546709..fef9989 100644 --- a/src/main/java/me/falu/peepopractice/gui/screen/InventoryOptionsScreen.java +++ b/src/main/java/me/falu/peepopractice/gui/screen/InventoryOptionsScreen.java @@ -96,7 +96,7 @@ protected void init() { b -> this.onClose() ) ); - this.addButton( + ButtonWidget scrambleButton = this.addButton( new LimitlessButtonWidget( null, EGG_TEXTURE, @@ -104,7 +104,7 @@ protected void init() { (this.width - rowWidth) / 2 + rowWidth + paddingX, this.height - containerHeight, otherButtonWidth, - rowButtonSize * 3 + paddingY * 2, + (rowButtonSize * 3 + paddingY * 2) / 2, CategoryPreferencesScreen.getFormattedText(this.category, CategoryPreferences.SCRAMBLE_INVENTORY), b -> { CategoryPreferences.SCRAMBLE_INVENTORY.advanceValue(this.category); @@ -112,6 +112,22 @@ protected void init() { } ) ); + this.addButton( + new LimitlessButtonWidget( + null, + EGG_TEXTURE, + null, + scrambleButton.x, + scrambleButton.y + scrambleButton.getHeight(), + scrambleButton.getWidth(), + scrambleButton.getHeight(), + CategoryPreferencesScreen.getFormattedText(this.category, CategoryPreferences.RANDOM_INVENTORY), + b -> { + CategoryPreferences.RANDOM_INVENTORY.advanceValue(this.category); + b.setMessage(CategoryPreferencesScreen.getFormattedText(this.category, CategoryPreferences.RANDOM_INVENTORY)); + } + ) + ); } @Override diff --git a/src/main/java/me/falu/peepopractice/gui/widget/ThumbnailButtonWidget.java b/src/main/java/me/falu/peepopractice/gui/widget/ThumbnailButtonWidget.java index 3f00658..14a0b4d 100644 --- a/src/main/java/me/falu/peepopractice/gui/widget/ThumbnailButtonWidget.java +++ b/src/main/java/me/falu/peepopractice/gui/widget/ThumbnailButtonWidget.java @@ -69,10 +69,10 @@ public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float del this.y + this.height - this.height / 4 - client.textRenderer.fontHeight - 2 + 4, 0xFFFFFF ); - this.drawCenteredString( + this.drawCenteredText( matrices, client.textRenderer, - this.category.getPbText(), + this.isHovered() ? this.category.getStatsText() : this.category.getPbText(), this.x + this.width / 2, this.y + this.height - this.height / 4 + 4, 0xFFFFFF