Allow locking beam location operation, update gui
This commit is contained in:
parent
39ca71bc63
commit
d9c32390a6
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -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";
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -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() {
|
||||
@ -64,6 +64,10 @@ public class DIContainer {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static boolean togglePingBehavior() {
|
||||
return pingPositionOperation.toggleEnabled();
|
||||
}
|
||||
|
||||
private static void initialize() {
|
||||
if (!initialized) {
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
@ -39,53 +40,4 @@ public class DimensionButton extends WButton {
|
||||
public IDimension getDimension() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,7 @@ import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
class PingPositionOperation extends ViewOperationBase<PlayerRawPosition>{
|
||||
class PingPositionOperation extends ViewOperationBase<PlayerRawPosition> {
|
||||
|
||||
public PingPositionOperation(IFileStore fileStore, Supplier<PlayerRawPosition> stateSupplier) {
|
||||
super(fileStore, stateSupplier);
|
||||
|
||||
@ -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,9 +41,10 @@ class KeyBinds implements IKeyBinds {
|
||||
|
||||
add(DEFAULT);
|
||||
add(PING);
|
||||
add(PING_LOCK);
|
||||
|
||||
initialize();
|
||||
|
||||
|
||||
this.unmodifiableList = Collections.unmodifiableList(new ArrayList<>(keyBinds.values()));
|
||||
}
|
||||
|
||||
@ -84,17 +88,17 @@ class KeyBinds implements IKeyBinds {
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Type getDefaultType() {
|
||||
return defaultType;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getDefaultCode() {
|
||||
return defaultCode;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean wasPressed() {
|
||||
return super.wasPressed();
|
||||
@ -109,17 +113,17 @@ class KeyBinds implements IKeyBinds {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Text getNameLocalizedText() {
|
||||
return new TranslatableText(getTranslationKey());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Text getBoundKeyLocalizedText() {
|
||||
return super.getBoundKeyLocalizedText();
|
||||
}
|
||||
|
||||
|
||||
void setBoundKey(Type type, int code) {
|
||||
super.setBoundKey(type.createFromCode(code));
|
||||
|
||||
@ -131,7 +135,7 @@ class KeyBinds implements IKeyBinds {
|
||||
private void initialize() {
|
||||
try {
|
||||
ConfigData configData = fileStore.readConfigData();
|
||||
|
||||
|
||||
Config[] configs = configData.getKeyConfigs();
|
||||
|
||||
if (configs == null) {
|
||||
@ -150,15 +154,14 @@ class KeyBinds implements IKeyBinds {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private Type parseType(String type) {
|
||||
if("KEYSYM".equalsIgnoreCase(type)) {
|
||||
if ("KEYSYM".equalsIgnoreCase(type)) {
|
||||
return Type.KEYSYM;
|
||||
}
|
||||
|
||||
|
||||
return Type.MOUSE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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 |
Loading…
x
Reference in New Issue
Block a user