Skip to content

Commit

Permalink
Shortcuts config fix (#973)
Browse files Browse the repository at this point in the history
* Fix not being able to add shortcuts when no shortcuts exist

* Clean up shortcuts

* Fix garden warp
  • Loading branch information
kevinthegreat1 authored Nov 23, 2024
1 parent 9265d53 commit 1772577
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
Expand Down Expand Up @@ -59,8 +61,7 @@ protected static void loadShortcuts() {
}
shortcutsLoaded = CompletableFuture.runAsync(() -> {
try (BufferedReader reader = Files.newBufferedReader(SHORTCUTS_FILE)) {
Type shortcutsType = new TypeToken<Map<String, Map<String, String>>>() {
}.getType();
Type shortcutsType = new TypeToken<Map<String, Map<String, String>>>() {}.getType();
Map<String, Map<String, String>> shortcuts = SkyblockerMod.GSON.fromJson(reader, shortcutsType);
commands.clear();
commandArgs.clear();
Expand All @@ -84,6 +85,7 @@ private static void registerDefaultShortcuts() {
commands.put("/s", "/skyblock");
commands.put("/i", "/is");
commands.put("/h", "/hub");
commands.put("/g", "/warp garden");

// Dungeon
commands.put("/d", "/warp dungeon_hub");
Expand Down Expand Up @@ -170,8 +172,7 @@ private static void registerCommands(CommandDispatcher<FabricClientCommandSource
}
if (redirectLocation == null) {
dispatcher.register(literal(set.getKey().substring(1)).then(argument("args", StringArgumentType.greedyString())));
}
else {
} else {
dispatcher.register(literal(set.getKey().substring(1)).redirect(redirectLocation));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.hysky.skyblocker.skyblock.shortcut;

import com.demonwav.mcdev.annotations.Translatable;
import de.hysky.skyblocker.debug.Debug;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
Expand All @@ -20,9 +21,9 @@ public class ShortcutsConfigListWidget extends ElementListWidget<ShortcutsConfig
private final List<Map<String, String>> shortcutMaps = new ArrayList<>();

/**
* @param width the width of the widget
* @param height the height of the widget
* @param y the y coordinate to start rendering/placing the widget from
* @param width the width of the widget
* @param height the height of the widget
* @param y the y coordinate to start rendering/placing the widget from
* @param itemHeight the height of each item
*/
public ShortcutsConfigListWidget(MinecraftClient minecraftClient, ShortcutsConfigScreen screen, int width, int height, int y, int itemHeight) {
Expand Down Expand Up @@ -77,6 +78,11 @@ protected void updatePositions() {
}
}

/**
* Returns true if the client is in debug mode and the entry at the given index is selected.
* <p>
* Used to show the box around the selected entry in debug mode.
*/
@Override
protected boolean isSelectedEntry(int index) {
return Debug.debugEnabled() ? Objects.equals(getSelectedOrNull(), children().get(index)) : super.isSelectedEntry(index);
Expand Down Expand Up @@ -113,15 +119,15 @@ protected class ShortcutCategoryEntry extends AbstractShortcutEntry {
@Nullable
private final Text tooltip;

private ShortcutCategoryEntry(Map<String, String> shortcutsMap, String targetName, String replacementName) {
private ShortcutCategoryEntry(Map<String, String> shortcutsMap, @Translatable String targetName, @Translatable String replacementName) {
this(shortcutsMap, targetName, replacementName, (Text) null);
}

private ShortcutCategoryEntry(Map<String, String> shortcutsMap, String targetName, String replacementName, String tooltip) {
private ShortcutCategoryEntry(Map<String, String> shortcutsMap, @Translatable String targetName, @Translatable String replacementName, @Translatable String tooltip) {
this(shortcutsMap, targetName, replacementName, Text.translatable(tooltip));
}

private ShortcutCategoryEntry(Map<String, String> shortcutsMap, String targetName, String replacementName, @Nullable Text tooltip) {
private ShortcutCategoryEntry(Map<String, String> shortcutsMap, @Translatable String targetName, @Translatable String replacementName, @Nullable Text tooltip) {
this.shortcutsMap = shortcutsMap;
this.targetName = Text.translatable(targetName);
this.replacementName = Text.translatable(replacementName);
Expand Down Expand Up @@ -158,6 +164,14 @@ public void render(DrawContext context, int index, int y, int x, int entryWidth,
screen.setTooltip(tooltip);
}
}

/**
* Returns true so that category entries can be focused and selected, so that we can add shortcut entries after them.
*/
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
return true;
}
}

private class ShortcutLoadingEntry extends AbstractShortcutEntry {
Expand Down

0 comments on commit 1772577

Please sign in to comment.