Allow locking beam location operation, update gui

This commit is contained in:
Surya 2021-10-30 16:22:30 +05:30
parent 39ca71bc63
commit d9c32390a6
12 changed files with 141 additions and 69 deletions

View File

@ -16,7 +16,12 @@ Minecraft|[Fabric API](https://www.curseforge.com/minecraft/mc-mods/fabric-api/f
- Press `H` to open menu
- Press `B` to beam location
- Press `N` to lock beaming
- Select `SAVE` to save the coordinate
- Select `PING` to ping the coordinate to other players
- Select `LIST` to view saved coordinates
- Select `CONF` to update configs. Reachable through mod menu as well when available
## Discord
https://discord.gg/9xnv2gQbJt

View File

@ -8,6 +8,7 @@ import net.minecraft.text.Text;
public interface IKeyBinds {
public static String DEFAULT = "default";
public static String PING = "ping";
public static String PING_LOCK = "ping_lock";
public List<IKeyBinding> getAllBinds();
public IKeyBinding getKeyBind(String name);

View File

@ -4,12 +4,16 @@ import me.bionicbeanie.mods.savecoords.IKeyBinds.IKeyBinding;
import me.bionicbeanie.mods.savecoords.gui.impl.DIContainer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.TranslatableText;
public class SaveCoordinatesClient implements ClientModInitializer {
private static IKeyBinding defaultKeyBinding = getKeyBinding(IKeyBinds.DEFAULT);
private static IKeyBinding pingKeyBinding = getKeyBinding(IKeyBinds.PING);
private static IKeyBinding pingLockBinding = getKeyBinding(IKeyBinds.PING_LOCK);
@SuppressWarnings("resource")
@Override
public void onInitializeClient() {
@ -18,6 +22,16 @@ public class SaveCoordinatesClient implements ClientModInitializer {
DIContainer.getModGui().open();
}
while(pingLockBinding.wasPressed()) {
boolean enabled = DIContainer.togglePingBehavior();
String translationKey = TranslationKeys.TOOLTIP_PING_DISABLED;
if(enabled) {
translationKey = TranslationKeys.TOOLTIP_PING_ENABLED;
}
MinecraftClient.getInstance().player.sendMessage(new TranslatableText(translationKey), true);
}
while(pingKeyBinding.wasPressed()) {
DIContainer.getPingPositionOperation().run();
}

View File

@ -3,6 +3,7 @@ package me.bionicbeanie.mods.savecoords;
public interface TranslationKeys {
public static String KEYBIND_DEFAULT = "key.savecoords.default";
public static String KEYBIND_PING = "key.savecoords.ping";
public static String KEYBIND_PING_LOCK = "key.savecoords.ping_lock";
public static String CATEGORY_GENERIC = "category.savecoords.default";
public static String MENU_SAVE = "menu.savecoords.save";
public static String MENU_BACK = "menu.savecoords.back";
@ -13,4 +14,7 @@ public interface TranslationKeys {
public static String MENU_LOCATION = "menu.savecoords.location";
public static String MENU_NOTES = "menu.savecoords.notes";
public static String MENU_WORLD_NAME = "menu.savecoords.world_name";
public static String TOOLTIP_PING_LOCK = "tooltip.savecoords.ping_lock";
public static String TOOLTIP_PING_ENABLED = "tooltip.savecoords.ping_enabled";
public static String TOOLTIP_PING_DISABLED = "tooltip.savecoords.ping_disabled";
}

View File

@ -0,0 +1,36 @@
package me.bionicbeanie.mods.savecoords.gui.impl;
import java.util.function.Supplier;
import me.bionicbeanie.mods.savecoords.IFileStore;
import me.bionicbeanie.mods.savecoords.TranslationKeys;
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.TranslatableText;
public class CurrentPositionPingOperation extends PingPositionOperation{
private boolean enabled = false;
public CurrentPositionPingOperation(IFileStore fileStore, Supplier<PlayerRawPosition> stateSupplier) {
super(fileStore, stateSupplier);
}
public boolean toggleEnabled() {
this.enabled = !this.enabled;
return this.enabled;
}
@SuppressWarnings("resource")
@Override
protected void executeOperation(IFileStore fileStore, PlayerRawPosition position) throws Exception {
if (enabled) {
super.executeOperation(fileStore, position);
} else {
MinecraftClient.getInstance().player.sendMessage(new TranslatableText(TranslationKeys.TOOLTIP_PING_LOCK),
true);
}
}
}

View File

@ -21,7 +21,7 @@ public class DIContainer {
private static IModGui modGui;
private static IKeyBinds keyBinds;
private static ConfigScreenFactory<Screen> modMenuScreenFactory;
private static PingPositionOperation pingPositionOperation;
private static CurrentPositionPingOperation pingPositionOperation;
private static IDimensionAware dimensionAware;
public static IModGui getModGui() {
@ -65,6 +65,10 @@ public class DIContainer {
};
}
public static boolean togglePingBehavior() {
return pingPositionOperation.toggleEnabled();
}
private static void initialize() {
if (!initialized) {
initialized = true;
@ -77,7 +81,7 @@ public class DIContainer {
dimensionAware = Factory.CreateDimensionAware(minecraftClient);
modGui = new SaveCoordinatesGui(fileStore, playerLocator, dimensionAware, keyBinds, guiController);
pingPositionOperation = new PingPositionOperation(fileStore, () -> playerLocator.locate());
pingPositionOperation = new CurrentPositionPingOperation(fileStore, () -> playerLocator.locate());
}
}
}

View File

@ -5,14 +5,15 @@ import io.github.cottonmc.cotton.gui.widget.WSprite;
import me.bionicbeanie.mods.savecoords.IDimensionAware;
import me.bionicbeanie.mods.savecoords.IDimensionAware.IDimension;
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
import me.bionicbeanie.mods.savecoords.util.PartialCircularList;
import net.minecraft.text.LiteralText;
public class DimensionButton extends WButton {
private CircularList<IDimension> allDimensions;
private PartialCircularList<IDimension> allDimensions;
public DimensionButton(WSprite sprite, IDimensionAware dimensionAware, PlayerRawPosition existingPosition) {
allDimensions = new CircularList<IDimension>();
allDimensions = new PartialCircularList<IDimension>();
for (IDimension dimension : dimensionAware.getDimensions()) {
allDimensions.add(dimension);
}
@ -40,52 +41,3 @@ public class DimensionButton extends WButton {
return allDimensions.current();
}
}
// TODO : Probably move ad-hoc circular list elsewhere
class Node<T> {
T value;
Node<T> next;
Node(T t) {
this.value = t;
}
}
class CircularList<T> {
Node<T> head = null;
Node<T> tail = null;
Node<T> current = null;
void add(T t) {
if (head == null) {
head = new Node<T>(t);
tail = head;
head.next = tail;
tail.next = head;
return;
}
Node<T> temp = new Node<T>(t);
temp.next = head;
tail.next = temp;
tail = temp;
}
T next() {
if (current == null) {
current = head;
} else {
current = current.next;
}
return current.value;
}
T current() {
if (current == null) {
return null;
}
return current.value;
}
}

View File

@ -28,6 +28,9 @@ class KeyBinds implements IKeyBinds {
KeyBindingEx PING = new KeyBindingEx(IKeyBinds.PING, TranslationKeys.KEYBIND_PING, InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_B, TranslationKeys.CATEGORY_GENERIC);
KeyBindingEx PING_LOCK = new KeyBindingEx(IKeyBinds.PING_LOCK, TranslationKeys.KEYBIND_PING_LOCK,
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_N, TranslationKeys.CATEGORY_GENERIC);
private IFileStore fileStore;
private Map<String, KeyBindingEx> keyBinds;
private List<IKeyBinding> unmodifiableList;
@ -38,6 +41,7 @@ class KeyBinds implements IKeyBinds {
add(DEFAULT);
add(PING);
add(PING_LOCK);
initialize();
@ -151,7 +155,6 @@ class KeyBinds implements IKeyBinds {
e.printStackTrace();
}
}
private Type parseType(String type) {

View File

@ -0,0 +1,49 @@
package me.bionicbeanie.mods.savecoords.util;
public class PartialCircularList<T> {
public static class Node<V> {
V value;
Node<V> next;
Node(V v) {
this.value = v;
}
}
Node<T> head = null;
Node<T> tail = null;
Node<T> current = null;
public void add(T t) {
if (head == null) {
head = new Node<T>(t);
tail = head;
head.next = tail;
tail.next = head;
return;
}
Node<T> temp = new Node<T>(t);
temp.next = head;
tail.next = temp;
tail = temp;
}
public T next() {
if (current == null) {
current = head;
} else {
current = current.next;
}
return current.value;
}
public T current() {
if (current == null) {
return null;
}
return current.value;
}
}

View File

@ -1,6 +1,7 @@
{
"key.savecoords.default": "Open GUI",
"key.savecoords.ping": "Beam Location",
"key.savecoords.ping_lock": "Lock Beaming",
"category.savecoords.default": "Generic",
"menu.savecoords.save": "SAVE",
"menu.savecoords.reset": "RESET",
@ -10,5 +11,8 @@
"menu.savecoords.conf": "CONF",
"menu.savecoords.location": "location name",
"menu.savecoords.notes": "additional notes",
"menu.savecoords.world_name": "world name"
"menu.savecoords.world_name": "world name",
"tooltip.savecoords.ping_lock": "You must first enable beaming current location",
"tooltip.savecoords.ping_enabled": "Beaming current location is now enabled",
"tooltip.savecoords.ping_disabled": "Beaming current location is now disabled"
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB