Skip to content

Commit

Permalink
Merge branch '1.21' into 1.21.3
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
  • Loading branch information
Sollace committed Nov 20, 2024
2 parents 731b5bf + 32c5bbe commit d682c80
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static Tooltip createFeatureTooltip(Tooltip originalTooltip, BooleanSuppl
MinecraftClient.getInstance().getSession().getAccessToken(),
SkinUpload.Session.validator((session, serverId) -> {
// join the session server
//client.getSessionService().joinServer(session.profile().getId(), session.accessToken(), serverId);
client.getSessionService().joinServer(session.profile().getId(), session.accessToken(), serverId);
})
);

Expand Down Expand Up @@ -240,13 +240,18 @@ protected void initLocalPreviewButtons(Bounds area) {
}

protected void initServerPreviewButtons(Bounds area) {
area = addButton(new Button(area.right() - 20, area.bottom() + 5, 20, 20))
area = addButton(new Button(area.right() - 16, area.bottom() + 5, 16, 20))
.onClick(sender -> {
uploader.cycleGateway();
playSound(SoundEvents.ENTITY_VILLAGER_YES);
sender.getStyle().setTooltip(uploader.getGatewayText());
})
.styled(s -> s.setIcon(createIcon(80, 0)).setTooltip(uploader.getGatewayText(), 0, 10))
.styled(s -> s.setIcon(createIcon(81, 16)).setTooltip(Tooltip.of(uploader.getGatewayText(), 400)).setTooltipOffset(0, 10))
.getBounds();

area = addButton(new Button(area.left - 19, area.top, 20, 20))
.onClick(sender -> client.setScreen(new SettingsScreen(this, panorama)))
.styled(s -> s.setIcon(createIcon(80, 0)).setTooltip("options.title", 0, 10))
.getBounds();

area = addButton(new Button(area.left - 25, area.top, 20, 20))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package com.minelittlepony.hdskins.client.gui;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.jetbrains.annotations.Nullable;

import com.minelittlepony.common.client.gui.GameGui;
import com.minelittlepony.common.client.gui.ScrollContainer;
import com.minelittlepony.common.client.gui.Tooltip;
import com.minelittlepony.common.client.gui.element.Button;
import com.minelittlepony.common.client.gui.element.EnumSlider;
import com.minelittlepony.common.client.gui.element.Label;
import com.minelittlepony.common.client.gui.element.Toggle;
import com.minelittlepony.common.util.GamePaths;
import com.minelittlepony.hdskins.HDSkinsServer;
import com.minelittlepony.hdskins.client.HDConfig;
import com.minelittlepony.hdskins.client.HDSkins;
import com.minelittlepony.hdskins.server.Gateway;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.RotatingCubeMapRenderer;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Util;

public class SettingsScreen extends GameGui {

private final ScrollContainer content = new ScrollContainer();

private final RotatingCubeMapRenderer panorama;

private final HDConfig config = HDSkins.getInstance().getConfig();

public SettingsScreen(@Nullable Screen parent, RotatingCubeMapRenderer panorama) {
super(Text.translatable("options.title"), parent);
this.panorama = panorama;

content.margin.setVertical(30);
content.getContentPadding().setHorizontal(10);
content.getContentPadding().top = 10;
content.getContentPadding().bottom = 20;
}

@Override
public void init() {
content.init(this::rebuildContent);
}

private void rebuildContent() {
int LEFT = content.width / 2 - 105;

getChildElements().add(content);

int row = -20;

addButton(new Label(width / 2, 5).setCentered()).getStyle().setText(getTitle());
addButton(new Button(width / 2 - 100, height - 25))
.onClick(sender -> finish())
.getStyle()
.setText("gui.done");

content.addButton(new EnumSlider<>(LEFT, row += 20, config.pantsButtonVisibility))
.onChange(config.pantsButtonVisibility)
.setTextFormat(slider -> Text.translatable("hdskins.settings.main_screen_button", slider.getValue().name()))
.getStyle().setText(Text.translatable("hdskins.settings.main_screen_button", config.pantsButtonVisibility.get().name()));

content.addButton(new Button(LEFT, row += 25, 200, 20))
.onClick(sender -> {
try {
Path path = GamePaths.getAssetsDirectory().resolve("hd");
Files.createDirectories(path);
Util.getOperatingSystem().open(path);
} catch (IOException e) {
HDSkins.LOGGER.error("Could not create cache folder", e);
}
})
.getStyle()
.setText("hdskins.options.open_cache_folder");

content.addButton(new Label(width / 2, row += 40).setCentered()).getStyle().setText("hdskins.settings.category.compatibility");

content.addButton(new Toggle(LEFT, row += 20, config.useNativeFileChooser))
.onChange(config.useNativeFileChooser)
.getStyle().setText("hdskins.compatibility.native_file_picker");
content.addButton(new Toggle(LEFT, row += 20, config.enableSandboxingCheck))
.onChange(config.enableSandboxingCheck)
.getStyle().setText("hdskins.compatibility.sandboxing");

content.addButton(new Label(width / 2, row += 20).setCentered()).getStyle().setText("hdskins.settings.category.experiments");

content.addButton(new Toggle(LEFT, row += 20, config.useBatchLoading))
.onChange(config.useBatchLoading)
.getStyle().setText("hdskins.experiments.batches");

content.addButton(new Label(width / 2, row += 20).setCentered()).getStyle().setText("hdskins.settings.category.servers");
row += 10;
int index = 1;
for (Gateway gateway : HDSkinsServer.getInstance().getServers().getGateways()) {
content.addButton(new Label(LEFT, row += getFont().fontHeight))
.getStyle()
.setText("#" + (index++));
for (Text line : Tooltip.of(Text.literal(gateway.getServer().toString()), 300).getLines()) {
content.addButton(new Label(LEFT, row += getFont().fontHeight))
.getStyle()
.setText(line);
}
Set<Map.Entry<Text, Text>> buttons = new HashSet<>();

for (var metadata : gateway.getServer().getMetadata().entrySet()) {

if (metadata.getValue().getStyle().getClickEvent() != null) {
buttons.add(metadata);
} else {
for (Text line : Tooltip.of(metadata.getKey().copy().formatted(Formatting.YELLOW).append(": ").append(metadata.getValue()), 300).getLines()) {
content.addButton(new Label(LEFT + 7, row += getFont().fontHeight))
.getStyle()
.setText(line);
}
}
}
row += 20;

int left = LEFT + 7;
for (var metadata : buttons) {
int width = getFont().getWidth(metadata.getKey()) + 10;
content.addButton(new Button(left, row, width, 20))
.onClick(sender -> handleTextClick(metadata.getValue().getStyle()))
.getStyle().setText(metadata.getKey());
left += width + 2;
}

row += 20;
}
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) {
super.render(context, mouseX, mouseY, tickDelta);
content.render(context, mouseX, mouseY, tickDelta);
}

@Override
protected void renderPanoramaBackground(DrawContext context, float delta) {
panorama.render(context, this.width, this.height, 1.0F, delta);
}

@Override
public void removed() {
config.save();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void render(DrawContext context, float deltaTime, int width, int height)
MatrixStack matrices = context.getMatrices();

matrices.push();
matrices.translate(0, 0, 900);
int opacity = (Math.min(180, (int)(msgFadeOpacity * 180)) & 255) << 24;

context.fill(0, 0, width, height, opacity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.mojang.authlib.exceptions.AuthenticationException;
import com.mojang.authlib.minecraft.MinecraftSessionService;

import net.minecraft.text.Text;

import java.io.IOException;
import java.util.*;
import java.util.stream.Stream;
Expand All @@ -16,6 +18,13 @@ public interface SkinServer {
*/
Set<Feature> getFeatures();

/**
* Gets optional metadata that should be displayed to the user for this server.
*/
default Map<Text, Text> getMetadata() {
return Map.of();
}

/**
* Determines whether this server is the source of the provided url.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -140,6 +141,10 @@ public Iterator<Gateway> getCycler() {
return Iterators.cycle(skinServers);
}

public Iterable<Gateway> getGateways() {
return new ArrayList<>(skinServers);
}

private static <T> void addAllStart(List<T> list, List<T> toAdd) {
list.addAll(0, toAdd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
import com.minelittlepony.hdskins.util.net.*;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.exceptions.AuthenticationException;

import net.minecraft.text.ClickEvent;
import net.minecraft.text.ClickEvent.Action;
import net.minecraft.text.Text;
import net.minecraft.util.Colors;
import net.minecraft.util.Formatting;
import net.minecraft.util.Util;

import java.io.IOException;
Expand All @@ -20,6 +26,7 @@
public class ValhallaSkinServer implements SkinServer {

private static final String API_PREFIX = "/api/v1";
private static final String SRC = "https://github.com/MineLittlePony/ValhallaSkinServer";

private static final Set<Feature> FEATURES = Sets.newHashSet(
Feature.DOWNLOAD_USER_SKIN,
Expand Down Expand Up @@ -247,6 +254,19 @@ public String toString() {
.toString();
}

@Override
public Map<Text, Text> getMetadata() {
return Map.of(
Text.translatable("hdskins.label.documentation"), Text.literal(address + "/docs").formatted(Formatting.UNDERLINE).withColor(Colors.BLUE).styled(style -> {
return style.withClickEvent(new ClickEvent(Action.OPEN_URL, address + "/docs"));
}),
Text.translatable("hdskins.label.source"), Text.literal(SRC).formatted(Formatting.UNDERLINE).withColor(Colors.BLUE).styled(style -> {
return style.withClickEvent(new ClickEvent(Action.OPEN_URL, SRC));
}),
Text.translatable("hdskins.label.author"), Text.literal("Killjoy")
);
}

private record AuthHandshake(boolean offline, String serverId, long verifyToken) {}
private record AuthResponse(String accessToken, UUID userId) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.authlib.yggdrasil.ProfileResult;

import net.minecraft.text.ClickEvent;
import net.minecraft.text.Text;
import net.minecraft.text.ClickEvent.Action;
import net.minecraft.util.Colors;
import net.minecraft.util.Formatting;
import net.minecraft.util.Util;

@ServerType("mojang")
Expand Down Expand Up @@ -171,6 +176,16 @@ public String toString() {
.toString();
}

@Override
public Map<Text, Text> getMetadata() {
return Map.of(
Text.translatable("hdskins.label.website"), Text.literal("https://www.minecraft.net/en-us/login").formatted(Formatting.UNDERLINE).withColor(Colors.BLUE).styled(style -> {
return style.withClickEvent(new ClickEvent(Action.OPEN_URL, "https://www.minecraft.net/en-us/login"));
}),
Text.translatable("hdskins.label.author"), Text.literal("Mojang")
);
}

class ErrorResponse {
String error;
String errorMessage;
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/assets/hdskins/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
"hdskins.options.browse": "Browse",
"hdskins.options.skindrops": "Experimental Skin Drop",
"hdskins.options.cache": "Clear Skin Cache",
"hdskins.options.open_cache_folder": "Open Cache Folder",
"hdskins.settings.category.experiments": "Experiments",
"hdskins.settings.category.compatibility": "Compatibility",
"hdskins.settings.category.servers": "Skin Server List",
"hdskins.settings.main_screen_button": "Main Screen Button: %s",
"hdskins.compatibility.native_file_picker": "Use Native File Picker",
"hdskins.compatibility.sandboxing": "Sandboxing (LINUX :: Flatpak)",
"hdskins.experiments.batches": "Fetch skins in batches",
"hdskins.label.documentation": "Web API Docs",
"hdskins.label.source": "Source",
"hdskins.label.website": "Website",
"hdskins.label.author": "Author",
"hdskins.warning.experimental": "§6WARNING: This feature is §4experimental§6, meaning things may break or derp or even slurp. Enabling this means you accept responsibility for what may happen to your chickens.",
"hdskins.warning.disabled.title": "§c%s %s",
"hdskins.warning.disabled.description": "§4(DISABLED)\n§7This feature is not supported by your current skin server.\n§7Please choose a different one to proceed."
Expand Down

0 comments on commit d682c80

Please sign in to comment.