Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TODO.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Color should go back to transparent when unselected without needing to click elsewhere (check color updater)
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[versions]
minecraft = "1.21.8"
quilt_mappings = "1.21.8+build.1"
fabric_loader = "0.16.14"
minecraft = "1.21.10"
quilt_mappings = "1.21.10+build.4"
fabric_loader = "0.17.3"

fabric_api = "0.130.0+1.21.8"
fabric_api = "0.136.0+1.21.10"

# Other mods
recursive_resources = "2.7.2+1.21.7"
Expand All @@ -18,6 +18,6 @@ fabric_api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fab
recursive_resources = { module = "nl.enjarai:recursive-resources", version.ref = "recursive_resources" }

[plugins]
fabric_loom = { id = "fabric-loom", version = "1.10-SNAPSHOT" }
minotaur = { id = "com.modrinth.minotaur", version = "2.8.7" }
fabric_loom = { id = "fabric-loom", version = "1.13.6" }
minotaur = { id = "com.modrinth.minotaur", version = "2.8.10" }
cursegradle = { id = "com.matthewprenger.cursegradle", version = "1.4.0" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
53 changes: 42 additions & 11 deletions src/main/java/me/bymartrixx/vtd/gui/UnsavedPackWarningScreen.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,70 @@
package me.bymartrixx.vtd.gui;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.WarningScreen;
import net.minecraft.client.gui.widget.button.ButtonWidget;
import net.minecraft.client.gui.widget.layout.LayoutWidget;
import net.minecraft.client.gui.widget.layout.LinearLayoutWidget;
import net.minecraft.text.CommonTexts;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import me.bymartrixx.vtd.util.Util;

public class UnsavedPackWarningScreen extends WarningScreen {
import java.util.List;

public class UnsavedPackWarningScreen extends Screen {
private static final Text HEADER = Text.translatable("vtd.unsavedPackWarning.header").formatted(Formatting.BOLD);
private static final Text MESSAGE = Text.translatable("vtd.unsavedPackWarning.text");
private static final Text CONFIRM = HEADER.copy().append("\n").append(MESSAGE);

private final VTDownloadScreen parent;
private final Screen next;
private List<OrderedText> messageLines;

protected UnsavedPackWarningScreen(VTDownloadScreen parent, Screen next) {
super(HEADER, MESSAGE, CONFIRM);
super(HEADER);
this.parent = parent;
this.next = next;
}

@Override
protected LayoutWidget initContent() {
LinearLayoutWidget layout = LinearLayoutWidget.createHorizontal().setSpacing(8);
layout.add(ButtonWidget.builder(CommonTexts.PROCEED, button -> this.client.setScreen(this.next)).build());
layout.add(ButtonWidget.builder(CommonTexts.BACK, button -> this.closeScreen()).build());
protected void init() {
this.messageLines = Util.getMultilineTextLines(this.textRenderer, MESSAGE, 10, 300);

int buttonWidth = 150;
int buttonHeight = 20;
int spacing = 8;
int totalWidth = buttonWidth * 2 + spacing;
int startX = (this.width - totalWidth) / 2;
int buttonY = this.height / 2 + 40;

return layout;
this.addDrawableSelectableElement(
ButtonWidget.builder(CommonTexts.PROCEED, button -> this.client.setScreen(this.next))
.position(startX, buttonY)
.size(buttonWidth, buttonHeight)
.build());

this.addDrawableSelectableElement(ButtonWidget.builder(CommonTexts.BACK, button -> this.closeScreen())
.position(startX + buttonWidth + spacing, buttonY)
.size(buttonWidth, buttonHeight)
.build());
}

@Override
public void closeScreen() {
this.client.setScreen(this.parent);
}

@Override
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
super.render(graphics, mouseX, mouseY, delta);

graphics.drawCenteredShadowedText(this.textRenderer, HEADER, this.width / 2, this.height / 2 - 50, 0xFFFFFFFF);

if (this.messageLines != null) {
int y = this.height / 2 - 20;
for (OrderedText line : this.messageLines) {
graphics.drawCenteredShadowedText(this.textRenderer, line, this.width / 2, y, 0xFFFFFFFF);
y += this.textRenderer.fontHeight + 2;
}
}
}
}
60 changes: 42 additions & 18 deletions src/main/java/me/bymartrixx/vtd/gui/VTDownloadScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,12 @@ private void download() {
}

private void share() {
if (!this.selectionHelper.hasSelection()) {
return;
}
SharePackRequestData data = new SharePackRequestData("resourcepacks", VTDMod.VT_VERSION,
this.selectionHelper.getSelectedPacksPrimitive());
if (data.equals(this.lastShareData)) {
if (data.equals(this.lastShareData) && this.lastShareCode != null) {
this.showSharePopup(this.lastShareCode);
return;
}
Expand All @@ -233,25 +236,29 @@ private void share() {
return;
}

VTDMod.executeShare(data).whenCompleteAsync((code, throwable) -> {
if (throwable != null) {
VTDMod.LOGGER.error("Failed to get resource pack share code", throwable);
this.errorPopup.show(ERROR_MESSAGE_TIME, SHARE_FAILED_TEXT.copy()
.append("\n").append(throwable.getLocalizedMessage()));
return;
}
VTDMod.executeShare(data).whenComplete((code, throwable) -> {
// Execute on render thread since showSharePopup needs to access render system
this.client.execute(() -> {
if (throwable != null) {
VTDMod.LOGGER.error("Failed to get resource pack share code", throwable);
this.errorPopup.show(ERROR_MESSAGE_TIME, SHARE_FAILED_TEXT.copy()
.append("\n").append(throwable.getLocalizedMessage()));
return;
}

this.lastShareData = data;
this.lastShareCode = code;
this.lastShareData = data;
this.lastShareCode = code;

this.showSharePopup(code);
this.showSharePopup(code);
});
});
}

private void showSharePopup(String code) {
if (code != null && this.sharePopup != null) {
String url = VTDMod.BASE_URL + "/share#" + code;
this.sharePopup.show(SHARE_MESSAGE_TIME, SHARE_CODE_TEXT.apply(Util.urlText(url)));
Text message = SHARE_CODE_TEXT.apply(Util.urlText(url));
this.sharePopup.show(SHARE_MESSAGE_TIME, message);
}
}

Expand Down Expand Up @@ -387,17 +394,19 @@ protected void init() {
// Render over everything else
this.progressBar = this.addDrawable(new ProgressBarScreenPopup(this.client, this.width / 2, this.height / 2,
PROGRESS_BAR_WIDTH, PROGRESS_BAR_HEIGHT, PROGRESS_BAR_COLOR));
this.addDrawable(this.sharePopup);
this.addDrawable(this.errorPopup);
if (this.debugPopup != null) this.addDrawable(this.debugPopup);
// Don't add popups as drawables - we render them explicitly in render() method
// this.addDrawable(this.sharePopup);
// this.addDrawable(this.errorPopup);
// if (this.debugPopup != null) this.addDrawable(this.debugPopup);

this.updateButtons();
this.readResourcePack();
}

private void updateButtons() {
if (this.shareButton != null) {
this.shareButton.active = this.selectionHelper.hasSelection();
boolean hasSelection = this.selectionHelper.hasSelection();
this.shareButton.active = hasSelection;
}
if (this.downloadButton != null) {
this.downloadButton.active = this.selectionHelper.hasSelection() && this.packNameField.canUseName();
Expand All @@ -411,8 +420,13 @@ private void toggleSelectedPacksListExtended() {
this.categorySelector.updateScreenWidth();
this.packSelector.updateScreenWidth();

this.shareButton.visible = extended;
this.shareButton.setX(this.leftWidth + SELECTED_PACKS_CENTER_X - SHARE_BUTTON_CENTER_X);
if (this.shareButton != null) {
this.shareButton.visible = extended;
this.shareButton.setX(this.leftWidth + SELECTED_PACKS_CENTER_X - SHARE_BUTTON_CENTER_X);
if (extended) {
this.updateButtons();
}
}
}

public boolean isCoveredByPopup(int mouseX, int mouseY) {
Expand All @@ -431,6 +445,16 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
super.render(graphics, mouseX, mouseY, delta);
graphics.drawCenteredShadowedText(this.textRenderer, this.title, this.width / 2, TITLE_Y, 0xFFFFFFFF);
graphics.drawCenteredShadowedText(this.textRenderer, this.subtitle, this.width / 2, SUBTITLE_Y, 0xFFFFFFFF);
// Render popups explicitly after everything else to ensure they're on top
if (this.sharePopup != null && this.sharePopup.shouldShow()) {
this.sharePopup.render(graphics, mouseX, mouseY, delta);
}
if (this.errorPopup != null && this.errorPopup.shouldShow()) {
this.errorPopup.render(graphics, mouseX, mouseY, delta);
}
if (this.debugPopup != null && this.debugPopup.shouldShow()) {
this.debugPopup.render(graphics, mouseX, mouseY, delta);
}

this.renderDebugInfo(graphics, mouseX, mouseY);
this.packSelector.renderTooltips(graphics, mouseX, mouseY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public AbstractScreenPopup(MinecraftClient client, int centerX, int centerY, int
protected void show(float time) {
this.show = true;
this.shownTime = time;
this.fadeTime = 0.0F;
}

public boolean shouldShow() {
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/me/bymartrixx/vtd/gui/popup/MessageScreenPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.screen.narration.NarrationPart;
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Style;
Expand Down Expand Up @@ -54,7 +55,8 @@ public void show(float time, Text message) {
this.messageLines = Util.getMultilineTextLines(this.client.textRenderer, message, maxLines, this.maxWidth);
this.message = Util.createMultilineText(this.client.textRenderer, message, maxLines, this.maxWidth);

this.updateSize(this.maxWidth, this.getHeight(this.message.count()));
int height = this.getHeight(this.message.count());
this.updateSize(this.maxWidth, height);
this.show(time);
}

Expand All @@ -64,13 +66,19 @@ protected void renderContent(GuiGraphics graphics, int mouseX, int mouseY, float
int color = 0xFFFFFF | this.getFadeAlpha() << 24;
graphics.drawCenteredShadowedText(textRenderer, this.title, this.centerX, this.getTop() + TITLE_MARGIN, color);

this.message.drawCenteredWithShadow(graphics,
this.centerX, this.getTop() + TITLE_MARGIN * 2 + textRenderer.fontHeight, textRenderer.fontHeight, color);
int y = this.getTop() + TITLE_MARGIN * 2 + textRenderer.fontHeight;
for (OrderedText line : this.messageLines) {
int lineWidth = textRenderer.getWidth(line);
graphics.drawShadowedText(textRenderer, line, this.centerX - lineWidth / 2, y, color);
y += textRenderer.fontHeight;
}
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (this.shouldShow() && button == GLFW.GLFW_MOUSE_BUTTON_1
public boolean mouseClicked(MouseButtonEvent event, boolean bl) {
double mouseX = this.client.mouse.getX() * this.client.getWindow().getScaledWidth() / this.client.getWindow().getWidth();
double mouseY = this.client.mouse.getY() * this.client.getWindow().getScaledHeight() / this.client.getWindow().getHeight();
if (this.shouldShow()
&& mouseX >= this.getLeft() && mouseX < this.getRight()
&& mouseY >= this.getTop() && mouseY < this.getBottom()) {
double clickedY = mouseY - this.getTop();
Expand Down Expand Up @@ -105,7 +113,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
}
}

return Element.super.mouseClicked(mouseX, mouseY, button);
return false;
}

// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import net.minecraft.client.gui.screen.narration.NarrationPart;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.gui.widget.ClickableWidgetStateTextures;
import net.minecraft.client.input.KeyEvent;
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.client.render.RenderPipelines;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.sound.SoundManager;
Expand Down Expand Up @@ -60,7 +62,7 @@ public void renderButton(GuiGraphics graphics, int x, int y) {
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
public boolean mouseClicked(MouseButtonEvent event, boolean bl) {
if (this.hovered && !this.selected) {
this.playDownSound(MinecraftClient.getInstance().getSoundManager());
return this.screen.selectCategory(this.category);
Expand All @@ -70,7 +72,8 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
}

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
public boolean keyPressed(KeyEvent event) {
int keyCode = event.key();
if (this.selected) {
return false;
}
Expand All @@ -80,7 +83,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return this.screen.selectCategory(this.category);
}

return Element.super.keyPressed(keyCode, scanCode, modifiers);
return false;
}

// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.render.RenderPipelines;
import net.minecraft.text.Text;
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import org.joml.Matrix3x2fStack;
Expand Down Expand Up @@ -187,22 +188,25 @@ private void ensureVisible(CategoryButtonWidget button) {

// region input callbacks
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
this.updateScrollingState(mouseX, mouseY, button);
public boolean mouseClicked(MouseButtonEvent event, boolean bl) {
MinecraftClient client = MinecraftClient.getInstance();
double mouseX = client.mouse.getX() * client.getWindow().getScaledWidth() / client.getWindow().getWidth();
double mouseY = client.mouse.getY() * client.getWindow().getScaledHeight() / client.getWindow().getHeight();
// Assume left button for scrolling state
this.updateScrollingState(mouseX, mouseY, GLFW.GLFW_MOUSE_BUTTON_1);

if (!this.isMouseOver(mouseX, mouseY)) {
return false;
} else {
return super.mouseClicked(mouseX, mouseY, button) || this.scrolling;
return super.mouseClicked(event, bl) || this.scrolling;
}
}

@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
return super.mouseReleased(mouseX, mouseY, button);
public boolean mouseReleased(MouseButtonEvent event) {
return super.mouseReleased(event);
}

@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
if (button == GLFW.GLFW_MOUSE_BUTTON_1 && this.scrolling) {
// Dragging scrollbar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.Selectable;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.client.render.RenderPipelines;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;
Expand Down Expand Up @@ -41,14 +42,17 @@ private int getRight() {
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (this.isMouseOver(mouseX, mouseY) && button == GLFW.GLFW_MOUSE_BUTTON_1) {
public boolean mouseClicked(MouseButtonEvent event, boolean bl) {
net.minecraft.client.MinecraftClient client = net.minecraft.client.MinecraftClient.getInstance();
double mouseX = client.mouse.getX() * client.getWindow().getScaledWidth() / client.getWindow().getWidth();
double mouseY = client.mouse.getY() * client.getWindow().getScaledHeight() / client.getWindow().getHeight();
if (this.isMouseOver(mouseX, mouseY)) {
this.extended = !this.extended;
this.callback.accept(this.extended);
return true;
}

return Element.super.mouseClicked(mouseX, mouseY, button);
return false;
}

// TODO
Expand Down
Loading