Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waypoints #713

Merged
merged 10 commits into from
Jun 13, 2024
2 changes: 2 additions & 0 deletions src/main/java/de/hysky/skyblocker/SkyblockerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import de.hysky.skyblocker.skyblock.waypoint.MythologicalRitual;
import de.hysky.skyblocker.skyblock.waypoint.OrderedWaypoints;
import de.hysky.skyblocker.skyblock.waypoint.Relics;
import de.hysky.skyblocker.skyblock.waypoint.Waypoints;
import de.hysky.skyblocker.utils.*;
import de.hysky.skyblocker.utils.chat.ChatMessageListener;
import de.hysky.skyblocker.utils.discord.DiscordRPCManager;
Expand Down Expand Up @@ -112,6 +113,7 @@ public void onInitializeClient() {
ItemTooltip.init();
AccessoriesHelper.init();
WikiLookup.init();
Waypoints.init();
FairySouls.init();
Relics.init();
MythologicalRitual.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.hysky.skyblocker.config.ConfigUtils;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.skyblock.fancybars.StatusBarsConfigScreen;
import de.hysky.skyblocker.skyblock.waypoint.WaypointsScreen;
import de.hysky.skyblocker.utils.render.title.TitleContainerConfigScreen;
import de.hysky.skyblocker.config.configs.UIAndVisualsConfig;
import de.hysky.skyblocker.utils.waypoint.Waypoint;
Expand Down Expand Up @@ -226,12 +227,17 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.option(Option.<Waypoint.Type>createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.waypoints.waypointType"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.uiAndVisuals.waypoints.waypointType.@Tooltip"),
Text.translatable("skyblocker.config.uiAndVisuals.waypoints.waypointType")))
Text.translatable("skyblocker.config.uiAndVisuals.waypoints.waypointType.generalNote")))
.binding(defaults.uiAndVisuals.waypoints.waypointType,
() -> config.uiAndVisuals.waypoints.waypointType,
newValue -> config.uiAndVisuals.waypoints.waypointType = newValue)
.controller(ConfigUtils::createEnumCyclingListController)
.build())
.option(ButtonOption.createBuilder()
.name(Text.translatable("skyblocker.waypoints.config"))
.text(Text.translatable("text.skyblocker.open"))
.action((screen, opt) -> MinecraftClient.getInstance().setScreen(new WaypointsScreen(screen)))
.build())
.build())

//Teleport Overlays
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.hysky.skyblocker.mixins.accessors;

import net.minecraft.client.gui.widget.CheckboxWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(CheckboxWidget.class)
public interface CheckboxWidgetAccessor {
@Accessor
void setChecked(boolean checked);
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private void addCustomWaypoint(SecretWaypoint relativeWaypoint) {
protected void removeCustomWaypoint(CommandContext<FabricClientCommandSource> context, BlockPos pos) {
SecretWaypoint waypoint = removeCustomWaypoint(pos);
if (waypoint != null) {
context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.stringifiedTranslatable("skyblocker.dungeons.secrets.customWaypointRemoved", pos.getX(), pos.getY(), pos.getZ(), name, waypoint.secretIndex, waypoint.category, waypoint.name)));
context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.customWaypointRemoved", pos.getX(), pos.getY(), pos.getZ(), name, waypoint.secretIndex, waypoint.category.asString(), waypoint.getName())));
} else {
context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.customWaypointNotFound", pos.getX(), pos.getY(), pos.getZ(), name)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.JsonOps;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.config.configs.DungeonsConfig;
import de.hysky.skyblocker.utils.render.RenderHelper;
import de.hysky.skyblocker.utils.waypoint.NamedWaypoint;
import de.hysky.skyblocker.utils.waypoint.Waypoint;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.client.MinecraftClient;
Expand All @@ -29,7 +29,7 @@
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;

public class SecretWaypoint extends Waypoint {
public class SecretWaypoint extends NamedWaypoint {
private static final Logger LOGGER = LoggerFactory.getLogger(SecretWaypoint.class);
public static final Codec<SecretWaypoint> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.INT.fieldOf("secretIndex").forGetter(secretWaypoint -> secretWaypoint.secretIndex),
Expand All @@ -43,8 +43,6 @@ public class SecretWaypoint extends Waypoint {
static final Supplier<Type> TYPE_SUPPLIER = () -> CONFIG.get().waypointType;
final int secretIndex;
final Category category;
final Text name;
private final Vec3d centerPos;

SecretWaypoint(int secretIndex, JsonObject waypoint, String name, BlockPos pos) {
this(secretIndex, Category.get(waypoint), name, pos);
Expand All @@ -55,11 +53,9 @@ public class SecretWaypoint extends Waypoint {
}

SecretWaypoint(int secretIndex, Category category, Text name, BlockPos pos) {
super(pos, TYPE_SUPPLIER, category.colorComponents);
super(pos, name, TYPE_SUPPLIER, category.colorComponents);
this.secretIndex = secretIndex;
this.category = category;
this.name = name;
this.centerPos = pos.toCenterPos();
}

static ToDoubleFunction<SecretWaypoint> getSquaredDistanceToFunction(Entity entity) {
Expand Down Expand Up @@ -96,6 +92,11 @@ public boolean equals(Object obj) {
return super.equals(obj) || obj instanceof SecretWaypoint other && secretIndex == other.secretIndex && category == other.category && name.equals(other.name) && pos.equals(other.pos);
}

@Override
protected boolean shouldRenderName() {
return CONFIG.get().showSecretText;
}

/**
* Renders the secret waypoint, including a waypoint through {@link Waypoint#render(WorldRenderContext)}, the name, and the distance from the player.
*/
Expand All @@ -106,7 +107,6 @@ public void render(WorldRenderContext context) {

if (CONFIG.get().showSecretText) {
Vec3d posUp = centerPos.add(0, 1, 0);
RenderHelper.renderText(context, name, posUp, true);
double distance = context.camera().getPos().distanceTo(centerPos);
RenderHelper.renderText(context, Text.literal(Math.round(distance) + "m").formatted(Formatting.YELLOW), posUp, 1, MinecraftClient.getInstance().textRenderer.fontHeight + 1, true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.hysky.skyblocker.skyblock.shortcut;

import de.hysky.skyblocker.debug.Debug;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.Element;
Expand Down Expand Up @@ -76,6 +77,11 @@ protected void updatePositions() {
}
}

@Override
protected boolean isSelectedEntry(int index) {
return Debug.debugEnabled() ? Objects.equals(getSelectedOrNull(), children().get(index)) : super.isSelectedEntry(index);
}

@Override
protected boolean removeEntry(AbstractShortcutEntry entry) {
return super.removeEntry(entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.text.Text;

public class ShortcutsConfigScreen extends Screen {

private ShortcutsConfigListWidget shortcutsConfigListWidget;
private ButtonWidget buttonDelete;
private ButtonWidget buttonNew;
Expand Down Expand Up @@ -41,14 +40,14 @@ protected void init() {
shortcutsConfigListWidget.setDimensions(width, height - 96);
shortcutsConfigListWidget.updatePositions();
} else {
shortcutsConfigListWidget = new ShortcutsConfigListWidget(client, this, width, height - 96, 32, 25);
shortcutsConfigListWidget = new ShortcutsConfigListWidget(client, this, width, height - 96, 32, 24);
initialized = true;
}
addDrawableChild(shortcutsConfigListWidget);
GridWidget gridWidget = new GridWidget();
gridWidget.getMainPositioner().marginX(5).marginY(2);
GridWidget.Adder adder = gridWidget.createAdder(2);
buttonDelete = ButtonWidget.builder(Text.translatable("selectServer.delete"), button -> {
buttonDelete = ButtonWidget.builder(Text.translatable("selectServer.deleteButton"), button -> {
if (client != null && shortcutsConfigListWidget.getSelectedOrNull() instanceof ShortcutsConfigListWidget.ShortcutEntry shortcutEntry) {
scrollAmount = shortcutsConfigListWidget.getScrollAmount();
client.setScreen(new ConfirmScreen(this::deleteEntry, Text.translatable("skyblocker.shortcuts.deleteQuestion"), Text.stringifiedTranslatable("skyblocker.shortcuts.deleteWarning", shortcutEntry), Text.translatable("selectServer.deleteButton"), ScreenTexts.CANCEL));
Expand All @@ -57,16 +56,10 @@ protected void init() {
adder.add(buttonDelete);
buttonNew = ButtonWidget.builder(Text.translatable("skyblocker.shortcuts.new"), buttonNew -> shortcutsConfigListWidget.addShortcutAfterSelected()).build();
adder.add(buttonNew);
adder.add(ButtonWidget.builder(ScreenTexts.CANCEL, button -> {
if (client != null) {
close();
}
}).build());
adder.add(ButtonWidget.builder(ScreenTexts.CANCEL, button -> close()).build());
buttonDone = ButtonWidget.builder(ScreenTexts.DONE, button -> {
shortcutsConfigListWidget.saveShortcuts();
if (client != null) {
close();
}
close();
}).tooltip(Tooltip.of(Text.translatable("skyblocker.shortcuts.commandSuggestionTooltip"))).build();
adder.add(buttonDone);
gridWidget.refreshPositions();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package de.hysky.skyblocker.skyblock.waypoint;

import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;
import de.hysky.skyblocker.utils.Location;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.waypoint.NamedWaypoint;
import de.hysky.skyblocker.utils.waypoint.WaypointCategory;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;

import java.util.Arrays;

public abstract class AbstractWaypointsScreen<T extends Screen> extends Screen {
protected final T parent;
protected final Multimap<String, WaypointCategory> waypoints;
protected String island;
protected WaypointsListWidget waypointsListWidget;
protected DropdownWidget<Location> islandWidget;

public AbstractWaypointsScreen(Text title, T parent) {
this(title, parent, MultimapBuilder.hashKeys().arrayListValues().build());
}

public AbstractWaypointsScreen(Text title, T parent, Multimap<String, WaypointCategory> waypoints) {
this(title, parent, waypoints, Utils.getLocationRaw());
}

public AbstractWaypointsScreen(Text title, T parent, Multimap<String, WaypointCategory> waypoints, String island) {
super(title);
this.parent = parent;
this.waypoints = waypoints;
this.island = island;
}

@Override
protected void init() {
super.init();
waypointsListWidget = addDrawableChild(new WaypointsListWidget(client, this, width, height - 96, 32, 24));
islandWidget = addDrawableChild(new DropdownWidget<>(client, width - 160, 8, 150, height - 8, Arrays.asList(Location.values()), this::islandChanged, Location.from(island)));
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (islandWidget.mouseClicked(mouseX, mouseY, button)) {
return true;
}
boolean mouseClicked = super.mouseClicked(mouseX, mouseY, button);
updateButtons();
return mouseClicked;
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
if (islandWidget.isMouseOver(mouseX, mouseY) && islandWidget.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) {
return true;
}
return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
}

protected void islandChanged(Location location) {
island = location.id();
waypointsListWidget.setIsland(island);
}

protected abstract boolean isEnabled(NamedWaypoint waypoint);

protected abstract void enabledChanged(NamedWaypoint waypoint, boolean enabled);

protected void updateButtons() {
waypointsListWidget.updateButtons();
}
}
Loading