Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.21.x' into 1.21.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	changelog.md
#	common/src/main/java/earth/terrarium/olympus/client/ui/modals/DeleteConfirmModal.java
#	gradle.properties
  • Loading branch information
ThatGravyBoat committed Jan 6, 2025
2 parents c16f5c5 + 53a2ba9 commit 8c6884d
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.teamresourceful.resourcefullib.client.CloseablePoseStack;
import earth.terrarium.olympus.client.components.base.BaseWidget;
import earth.terrarium.olympus.client.ui.UIConstants;
import earth.terrarium.olympus.client.ui.UITexts;
import earth.terrarium.olympus.client.utils.State;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
Expand All @@ -30,7 +31,7 @@ public MapWidget(State<MapRenderer> state) {

private void renderLoading(GuiGraphics graphics) {
var font = Minecraft.getInstance().font;
graphics.drawCenteredString(font, UIConstants.LOADING, (int) (getX() + getWidth() / 2f), (int) (getY() + getHeight() / 2f), 0xFFFFFF);
graphics.drawCenteredString(font, UITexts.LOADING, (int) (getX() + getWidth() / 2f), (int) (getY() + getHeight() / 2f), 0xFFFFFF);
}

public MapWidget withTexture(ResourceLocation texture) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package earth.terrarium.olympus.client.components.renderers;

import com.mojang.blaze3d.systems.RenderSystem;
import com.teamresourceful.resourcefullib.common.color.Color;
import earth.terrarium.olympus.client.components.base.renderer.WidgetRenderer;
import earth.terrarium.olympus.client.components.base.renderer.WidgetRendererContext;
Expand All @@ -9,6 +8,7 @@
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ARGB;

public class IconWidgetRenderer<T extends AbstractWidget> implements WidgetRenderer<T>, ColorableWidget {

Expand All @@ -29,14 +29,22 @@ public void render(GuiGraphics graphics, WidgetRendererContext<T> context, float
if (alpha == 0f) alpha = 1f;

if (drawShadow) {
RenderSystem.setShaderColor(red / 3f, green / 3f, blue / 3f, alpha);
graphics.blitSprite(RenderType::guiTextured, icon, context.getX() + 1, context.getY() + 1, context.getWidth(), context.getHeight());
graphics.blitSprite(
RenderType::guiTextured,
icon,
context.getX() + 1, context.getY() + 1,
context.getWidth(), context.getHeight(),
ARGB.colorFromFloat(alpha, red / 3f, green / 3f, blue / 3f)
);
}

RenderSystem.setShaderColor(red, green, blue, alpha);
graphics.blitSprite(RenderType::guiTextured, icon, context.getX(), context.getY(), context.getWidth(), context.getHeight());

RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
graphics.blitSprite(
RenderType::guiTextured,
icon,
context.getX(), context.getY(),
context.getWidth(), context.getHeight(),
ARGB.colorFromFloat(alpha, red, green, blue)
);
}

public IconWidgetRenderer<T> withShadow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import earth.terrarium.olympus.client.components.base.renderer.WidgetRenderer;
import earth.terrarium.olympus.client.components.base.renderer.WidgetRendererContext;
import earth.terrarium.olympus.client.constants.MinecraftColors;
import earth.terrarium.olympus.client.utils.UIHelper;
import earth.terrarium.olympus.client.utils.OlympusUtils;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
Expand Down Expand Up @@ -37,11 +37,11 @@ public void render(GuiGraphics graphics, WidgetRendererContext<T> context, float
double f = Math.sin(Mth.HALF_PI * Math.cos(Mth.TWO_PI * seconds / e)) / 2.0 + 0.5;
double g = Mth.lerp(f, 0.0, overhang);
graphics.enableScissor(context.getLeft(), context.getTop(), context.getRight(), context.getBottom());
graphics.drawString(this.font, this.text, context.getX() - (int) g, centerY, UIHelper.getEnsureAlpha(color), this.drawShadow);
graphics.drawString(this.font, this.text, context.getX() - (int) g, centerY, OlympusUtils.getEnsureAlpha(color), this.drawShadow);
graphics.disableScissor();
} else {
int centerX = context.getX() + Math.round(context.getWidth() * alignX);
graphics.drawString(this.font, this.text, centerX - Math.round(textWidth * alignX), centerY, UIHelper.getEnsureAlpha(color), this.drawShadow);
graphics.drawString(this.font, this.text, centerX - Math.round(textWidth * alignX), centerY, OlympusUtils.getEnsureAlpha(color), this.drawShadow);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ public class UIConstants {
id("lists/buttons/down/hovered")
);

public static final Component BACK = Component.translatable("olympus.ui.back");
public static final Component CANCEL = Component.translatable("olympus.ui.cancel");
public static final Component DELETE = Component.translatable("olympus.ui.delete");
public static final Component REFRESH = Component.translatable("olympus.ui.refresh");
public static final Component LOADING = Component.translatable("olympus.ui.loading");
// Use UITexts.<the component>
@Deprecated public static final Component BACK = UITexts.BACK;
@Deprecated public static final Component CANCEL = UITexts.CANCEL;
@Deprecated public static final Component DELETE = UITexts.DELETE;
@Deprecated public static final Component REFRESH = UITexts.REFRESH;
@Deprecated public static final Component LOADING = UITexts.LOADING;

public static ResourceLocation id(String path) {
return ResourceLocation.fromNamespaceAndPath(MOD_ID, path);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package earth.terrarium.olympus.client.ui;

import net.minecraft.network.chat.Component;

public class UITexts {

public static final Component BACK = Component.translatable("olympus.ui.back");
public static final Component CANCEL = Component.translatable("olympus.ui.cancel");
public static final Component DELETE = Component.translatable("olympus.ui.delete");
public static final Component REFRESH = Component.translatable("olympus.ui.refresh");
public static final Component OPEN = Component.translatable("olympus.ui.open");
public static final Component LOADING = Component.translatable("olympus.ui.loading");
public static final Component OPEN_LINK = Component.translatable("olympus.ui.open_link");
public static final Component OPEN_DESC = Component.translatable("olympus.ui.open_link.desc");
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import earth.terrarium.olympus.client.layouts.Layouts;
import earth.terrarium.olympus.client.ui.Overlay;
import earth.terrarium.olympus.client.ui.UIConstants;
import earth.terrarium.olympus.client.ui.UITexts;
import earth.terrarium.olympus.client.utils.Orientation;
import it.unimi.dsi.fastutil.ints.Int2ObjectFunction;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -61,7 +62,7 @@ protected void init() {
.withTexture(null)
.withRenderer(WidgetRenderers.sprite(UIConstants.MODAL_CLOSE))
.withCallback(this::onClose)
.withTooltip(UIConstants.BACK)
.withTooltip(UITexts.BACK)
.withSize(11, 11);

var contentLayout = Layouts.column().withGap(CONTENT_GAP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import earth.terrarium.olympus.client.ui.Overlay;
import earth.terrarium.olympus.client.ui.UIConstants;
import earth.terrarium.olympus.client.ui.UITexts;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.components.Tooltip;
Expand Down Expand Up @@ -58,9 +59,9 @@ protected GridLayout initButtons(int position) {
GridLayout layout = new GridLayout().columnSpacing(INNER_PADDING);

layout.addChild(
new ImageButton(11, 11, UIConstants.MODAL_CLOSE, b -> this.onClose(), UIConstants.BACK),
new ImageButton(11, 11, UIConstants.MODAL_CLOSE, b -> this.onClose(), UITexts.BACK),
0, position
).setTooltip(Tooltip.create(UIConstants.BACK));
).setTooltip(Tooltip.create(UITexts.BACK));
return layout;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import earth.terrarium.olympus.client.components.renderers.WidgetRenderers;
import earth.terrarium.olympus.client.constants.MinecraftColors;
import earth.terrarium.olympus.client.ui.UIConstants;
import earth.terrarium.olympus.client.ui.UITexts;
import earth.terrarium.olympus.client.utils.OlympusUtils;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
Expand All @@ -25,12 +29,12 @@ public static ActionModal.Builder delete(Component title, Component description,
.withTitle(title)
.withContent(description)
.withAction(Widgets.button()
.withRenderer(WidgetRenderers.text(UIConstants.CANCEL))
.withRenderer(WidgetRenderers.text(UITexts.CANCEL))
.withSize(80, 24)
.withCallback(Modals::closeScreen)
)
.withAction(Widgets.button()
.withRenderer(WidgetRenderers.text(UIConstants.DELETE).withColor(MinecraftColors.WHITE))
.withRenderer(WidgetRenderers.text(UITexts.DELETE).withColor(MinecraftColors.WHITE))
.withSize(80, 24)
.withTexture(UIConstants.DANGER_BUTTON)
.withCallback(() -> {
Expand All @@ -39,4 +43,30 @@ public static ActionModal.Builder delete(Component title, Component description,
})
);
}

public static ActionModal.Builder link(String link) {
var displayLink = OlympusUtils.removePrefix(link, "https://", "http://");
var description = Component.empty()
.append(UITexts.OPEN_DESC)
.append("\n\n")
.append(Component.literal(displayLink).withStyle(ChatFormatting.BLUE));

return ActionModal.builder()
.withTitle(UITexts.OPEN_LINK)
.withContent(description)
.withAction(Widgets.button()
.withRenderer(WidgetRenderers.text(UITexts.CANCEL))
.withSize(80, 24)
.withCallback(Modals::closeScreen)
)
.withAction(Widgets.button()
.withRenderer(WidgetRenderers.text(UITexts.OPEN).withColor(MinecraftColors.WHITE))
.withSize(80, 24)
.withTexture(UIConstants.PRIMARY_BUTTON)
.withCallback(() -> {
Util.getPlatform().openUri(link);
closeScreen();
})
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package earth.terrarium.olympus.client.utils;

import com.teamresourceful.resourcefullib.common.color.Color;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
public class OlympusUtils {

public static int getEnsureAlpha(Color color) {
int value = color.getValue();
int alpha = value >> 24 & 255;
return alpha == 0 ? value | 0xff000000 : value;
}

public static String removePrefix(String text, String... prefixes) {
for (String prefix : prefixes) {
if (text.startsWith(prefix)) {
text = text.substring(prefix.length());
break;
}
}

return text;
}
}

This file was deleted.

6 changes: 5 additions & 1 deletion common/src/main/resources/assets/olympus/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"olympus.ui.delete": "Delete",
"olympus.ui.cancel": "Cancel",
"olympus.ui.refresh": "Refresh",
"olympus.ui.open": "Open",
"olympus.ui.loading": "Loading...",

"olympus.ui.tristate.true": "True",
Expand All @@ -11,5 +12,8 @@

"olympus.color.preset.recents": "Recents",
"olympus.color.preset.defaults": "Defaults",
"olympus.color.preset.mc_colors": "Chat Colors"
"olympus.color.preset.mc_colors": "Chat Colors",

"olympus.ui.open_link": "Open Link",
"olympus.ui.open_link.desc": "Are you sure you want to open this link?"
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ protected void init() {
() -> System.out.println("Item deleted")
);

ActionModal.Builder linkModal = Modals.link("https://github.com/terrarium-earth/olympus");

FrameLayout.centerInRectangle(
Layouts.layout()
.withGap(10)
Expand All @@ -65,6 +67,10 @@ protected void init() {
Widgets.button()
.withCallback(deleteModal::open)
.withRenderer(WidgetRenderers.text(Component.literal("Open Delete modal")))
.withSize(100, 20),
Widgets.button()
.withCallback(linkModal::open)
.withRenderer(WidgetRenderers.text(Component.literal("Open Link modal")))
.withSize(100, 20)
)
.build(this::addRenderableWidget),
Expand Down

0 comments on commit 8c6884d

Please sign in to comment.