Skip to content

Commit

Permalink
fix translatable names/descriptions and descriptions not shown in too…
Browse files Browse the repository at this point in the history
…ltip
  • Loading branch information
MelanX committed Apr 12, 2024
1 parent bd7b966 commit c925d20
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -19,7 +19,7 @@ dependencies {
annotationProcessor "org.moddingx:LibX:1.20.1-5.0.5"

implementation fg.deobf("org.moddingx:LibX:1.20.1-5.0.5")
implementation fg.deobf("de.melanx:SkyblockBuilder:1.20.1-5.0.19")
implementation fg.deobf("de.melanx:SkyblockBuilder:1.20.1-5.0.20")

runtimeOnly fg.deobf("mezz.jei:jei-1.20.1-forge:15.0.0.12")
}
28 changes: 18 additions & 10 deletions src/main/java/de/melanx/skyguis/client/screen/CreateTeamScreen.java
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;

import javax.annotation.Nonnull;
import java.awt.Color;
Expand Down Expand Up @@ -63,21 +64,27 @@ protected void init() {
return;
}

String shortened = this.setCurrentTemplateAndGetShortenedName();
Button templateButton = Button.builder(Component.literal(shortened), button -> {
Component shortened = this.setCurrentTemplateAndGetShortenedName();
Button templateButton = Button.builder(shortened, button -> {
this.currIndex++;
if (this.currIndex >= this.templates.size()) {
this.currIndex = 0;
}

String s = this.setCurrentTemplateAndGetShortenedName();
button.setMessage(Component.literal(s));
Component s = this.setCurrentTemplateAndGetShortenedName();
button.setMessage(s);
})
.bounds(this.x(65), this.y(60), 122, 20)
.tooltip(Tooltip.create(Component.literal(this.currTemplate)))
.build();
if (this.enableTooltip) {
templateButton.setTooltip(Tooltip.create(Component.literal(this.currTemplate)));
ConfiguredTemplate configuredTemplate = TemplateLoader.getConfiguredTemplate(this.currTemplate);
if (configuredTemplate == null) {
throw new IllegalStateException("Template does not exist: " + this.currTemplate);
}

MutableComponent nameComponent = configuredTemplate.getNameComponent().copy();
MutableComponent descComponent = configuredTemplate.getDescriptionComponent().copy().withStyle(ChatFormatting.ITALIC, ChatFormatting.GRAY);
templateButton.setTooltip(Tooltip.create(nameComponent.append("\n").append(descComponent)));
}
if (this.templates.size() == 1) {
templateButton.active = false;
Expand All @@ -98,19 +105,20 @@ protected void init() {
this.addRenderableWidget(Button.builder(ABORT, button -> this.onClose()).bounds(this.x(106), this.y(92), 60, 20).build());
}

private String setCurrentTemplateAndGetShortenedName() {
private Component setCurrentTemplateAndGetShortenedName() {
String orig = this.templates.get(this.currIndex);
String s = TextHelper.shorten(this.font, orig, 110);
ConfiguredTemplate configuredTemplate = TemplateLoader.getConfiguredTemplate(orig);
if (configuredTemplate == null) {
throw new IllegalStateException("Templates not synced between client and server: " + orig);
}

Component nameComponent = configuredTemplate.getNameComponent();
String s = TextHelper.shorten(this.font, nameComponent.getString(), 110);
String desc = configuredTemplate.getDescriptionComponent().getString();
this.enableTooltip = !s.equals(orig) || !desc.isBlank();
this.enableTooltip = !s.equals(nameComponent.getString()) || !desc.isBlank();
this.currTemplate = orig;

return s;
return Component.literal(s).setStyle(nameComponent.getStyle());
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Expand Up @@ -31,7 +31,7 @@ An addon for Skyblock Builder which provides GUIs to easily modify and view team
[[dependencies.skyguis]]
modId="skyblockbuilder"
mandatory=true
versionRange="[1.20.1-5.0.19,)"
versionRange="[1.20.1-5.0.20,)"
ordering="NONE"
side="BOTH"

Expand Down

0 comments on commit c925d20

Please sign in to comment.