Make coordinates editable, improve gui
This commit is contained in:
parent
4fa01e6979
commit
441dfb5ffb
@ -20,4 +20,4 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
libgui_version=4.0.0+1.17
|
libgui_version=4.0.0+1.17
|
||||||
|
|
||||||
#https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu/
|
#https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu/
|
||||||
modmenu_version=1.16.9
|
modmenu_version=2.0.2
|
||||||
|
|||||||
@ -101,13 +101,13 @@ class ConfigViewHandler extends ViewHandlerBase<List<IKeyBinding>> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void onBack(Runnable runnable) {
|
void onBackButtonClick(Runnable runnable) {
|
||||||
this.backButton.setOnClick(() -> {
|
this.backButton.setOnClick(() -> {
|
||||||
runnable.run();
|
runnable.run();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void onSave(Runnable runnable) {
|
void onSaveButtonClick(Runnable runnable) {
|
||||||
this.saveButton.setOnClick(() -> {
|
this.saveButton.setOnClick(() -> {
|
||||||
this.shouldNotUpdateBinding = true;
|
this.shouldNotUpdateBinding = true;
|
||||||
if(this.focussingConfig != null) {
|
if(this.focussingConfig != null) {
|
||||||
|
|||||||
@ -39,12 +39,12 @@ public class DIContainer {
|
|||||||
modMenuScreenFactory = (parent) -> {
|
modMenuScreenFactory = (parent) -> {
|
||||||
ConfigViewHandler handler = new ConfigViewHandler();
|
ConfigViewHandler handler = new ConfigViewHandler();
|
||||||
|
|
||||||
handler.onSave(() -> {
|
handler.onSaveButtonClick(() -> {
|
||||||
new SaveConfigsOperation(keyBinds, fileStore, handler::getState).run();
|
new SaveConfigsOperation(keyBinds, fileStore, handler::getState).call();
|
||||||
guiController.closeScreen();
|
guiController.closeScreen();
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.onBack(() -> guiController.closeScreen());
|
handler.onBackButtonClick(() -> guiController.closeScreen());
|
||||||
|
|
||||||
return handler.createView(keyBinds.getAllBinds());
|
return handler.createView(keyBinds.getAllBinds());
|
||||||
};
|
};
|
||||||
@ -54,7 +54,13 @@ public class DIContainer {
|
|||||||
|
|
||||||
public static Runnable getPingPositionOperation() {
|
public static Runnable getPingPositionOperation() {
|
||||||
initialize();
|
initialize();
|
||||||
return pingPositionOperation;
|
return () -> {
|
||||||
|
try {
|
||||||
|
pingPositionOperation.call();
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initialize() {
|
private static void initialize() {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
import io.github.cottonmc.cotton.gui.widget.WButton;
|
import io.github.cottonmc.cotton.gui.widget.WButton;
|
||||||
import io.github.cottonmc.cotton.gui.widget.WLabel;
|
import io.github.cottonmc.cotton.gui.widget.WLabel;
|
||||||
import io.github.cottonmc.cotton.gui.widget.WText;
|
import io.github.cottonmc.cotton.gui.widget.WSprite;
|
||||||
import io.github.cottonmc.cotton.gui.widget.WTextField;
|
import io.github.cottonmc.cotton.gui.widget.WTextField;
|
||||||
import io.github.cottonmc.cotton.gui.widget.WWidget;
|
import io.github.cottonmc.cotton.gui.widget.WWidget;
|
||||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||||
@ -15,6 +15,7 @@ import me.bionicbeanie.mods.savecoords.gui.IRootPanel;
|
|||||||
import me.bionicbeanie.mods.savecoords.model.PlayerPosition;
|
import me.bionicbeanie.mods.savecoords.model.PlayerPosition;
|
||||||
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
|
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
|
||||||
import me.bionicbeanie.mods.savecoords.model.PositionMetadata;
|
import me.bionicbeanie.mods.savecoords.model.PositionMetadata;
|
||||||
|
import me.bionicbeanie.mods.savecoords.util.DimensionKeys;
|
||||||
import me.bionicbeanie.mods.savecoords.util.ResourceUtils;
|
import me.bionicbeanie.mods.savecoords.util.ResourceUtils;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
@ -45,75 +46,117 @@ class DefaultViewHandler extends ViewHandlerBase<PlayerPosition> {
|
|||||||
|
|
||||||
PlayerRawPosition rawPosition = existingPosition == null ? locator.locate() : existingPosition;
|
PlayerRawPosition rawPosition = existingPosition == null ? locator.locate() : existingPosition;
|
||||||
|
|
||||||
WWidget xLabel = CreateLabelForCoorindate("X");
|
WWidget xLabel = CreateLabelForCoordinate("X");
|
||||||
WWidget yLabel = CreateLabelForCoorindate("Y");
|
WWidget yLabel = CreateLabelForCoordinate("Y");
|
||||||
WWidget zLabel = CreateLabelForCoorindate("Z");
|
WWidget zLabel = CreateLabelForCoordinate("Z");
|
||||||
|
|
||||||
WWidget xText = CreateWidgetForCoordinate(rawPosition.getX());
|
WTextField xText = CreateWidgetForCoordinate(rawPosition.getX());
|
||||||
WWidget yText = CreateWidgetForCoordinate(rawPosition.getY());
|
WTextField yText = CreateWidgetForCoordinate(rawPosition.getY());
|
||||||
WWidget zText = CreateWidgetForCoordinate(rawPosition.getZ());
|
WTextField zText = CreateWidgetForCoordinate(rawPosition.getZ());
|
||||||
|
|
||||||
|
root.add(xLabel, 0, 1, 1, 1);
|
||||||
|
root.add(yLabel, 0, 2, 1, 1);
|
||||||
|
root.add(zLabel, 0, 3, 1, 1);
|
||||||
|
|
||||||
root.add(xLabel, 2, 1, 2, 1);
|
root.add(xText, 1, 1, 6, 1);
|
||||||
root.add(yLabel, 2, 2, 2, 1);
|
root.add(yText, 1, 2, 6, 1);
|
||||||
root.add(zLabel, 2, 3, 2, 1);
|
root.add(zText, 1, 3, 6, 1);
|
||||||
|
|
||||||
root.add(xText, 3, 1, 2, 1);
|
WSprite worldIcon = ResourceUtils.createWorldIcon(getDimension(rawPosition));
|
||||||
root.add(yText, 3, 2, 2, 1);
|
root.add(worldIcon, 9, 1, 2, 2);
|
||||||
root.add(zText, 3, 3, 2, 1);
|
|
||||||
|
WWidget worldButton = CreateWorldButton(worldIcon);
|
||||||
WWidget icon = ResourceUtils.CreateWorldIcon(rawPosition.getWorldDimension());
|
root.add(worldButton, 8, 3, 4, 1);
|
||||||
root.add(icon, 8, 1, 2, 2);
|
|
||||||
|
|
||||||
String defaultWorldName = getDefaultWorldName(existingPosition);
|
String defaultWorldName = getDefaultWorldName(existingPosition);
|
||||||
WTextField world = CreateWorldField(defaultWorldName);
|
WTextField world = CreateWorldField(defaultWorldName);
|
||||||
root.add(world, 0, 4, 4, 1);
|
root.add(world, 0, 5, 4, 1);
|
||||||
|
|
||||||
WTextField location = CreateLocationField(existingPosition);
|
WTextField location = CreateLocationField(existingPosition);
|
||||||
root.add(location, 5, 4, 7, 1);
|
root.add(location, 5, 5, 7, 1);
|
||||||
|
|
||||||
WTextField notes = CreateNotesField(existingPosition);
|
WTextField notes = CreateNotesField(existingPosition);
|
||||||
root.add(notes, 0, 6, 12, 1);
|
root.add(notes, 0, 7, 12, 1);
|
||||||
|
|
||||||
root.add(saveButton, 13, 6, 2, 1);
|
root.add(saveButton, 13, 7, 2, 1);
|
||||||
root.add(listButton, 13, 9, 2, 1);
|
root.add(listButton, 13, 9, 2, 1);
|
||||||
root.add(pingButton, 13, 1, 1, 1);
|
root.add(pingButton, 13, 1, 1, 1);
|
||||||
root.add(closeButton, 0, 9, 2, 1);
|
root.add(closeButton, 0, 9, 2, 1);
|
||||||
root.add(configButton, 10, 9, 2, 1);
|
root.add(configButton, 10, 9, 2, 1);
|
||||||
|
|
||||||
return createPlayerPositionSupplier(existingPosition, rawPosition, world, location, notes);
|
return createPlayerPositionSupplier(existingPosition, xText, yText, zText, world, location, notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSave(Runnable runnable) {
|
private WWidget CreateWorldButton(WSprite worldIcon) {
|
||||||
|
WButton button = new WButton(new LiteralText(DimensionKeys.OVERWORLD));
|
||||||
|
button.setOnClick(() -> button.setLabel(new LiteralText(DimensionKeys.NETHER)));
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDimension(PlayerRawPosition rawPosition) {
|
||||||
|
String dimensionIdentifier = rawPosition.getWorldDimension();
|
||||||
|
|
||||||
|
if(isDimension(DimensionKeys.OVERWORLD, dimensionIdentifier)) {
|
||||||
|
return DimensionKeys.OVERWORLD;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isDimension(DimensionKeys.NETHER, dimensionIdentifier)) {
|
||||||
|
return DimensionKeys.NETHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isDimension(DimensionKeys.END, dimensionIdentifier)) {
|
||||||
|
return DimensionKeys.END;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DimensionKeys.UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isDimension(String dimension, String dimensionIdentifier) {
|
||||||
|
return dimensionIdentifier != null && dimensionIdentifier.contains(dimension);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSaveButtonClick(Runnable runnable) {
|
||||||
this.saveButton.setOnClick(runnable);
|
this.saveButton.setOnClick(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClose(Runnable runnable) {
|
public void onCloseButtonClick(Runnable runnable) {
|
||||||
this.closeButton.setOnClick(runnable);
|
this.closeButton.setOnClick(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onList(Runnable runnable) {
|
public void onListButtonClick(Runnable runnable) {
|
||||||
this.listButton.setOnClick(runnable);
|
this.listButton.setOnClick(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPing(Runnable runnable) {
|
public void onPingButtonClick(Runnable runnable) {
|
||||||
this.pingButton.setOnClick(runnable);
|
this.pingButton.setOnClick(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onConfig(Runnable runnable) {
|
public void onConfigButtonClick(Runnable runnable) {
|
||||||
this.configButton.setOnClick(runnable);
|
this.configButton.setOnClick(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Supplier<PlayerPosition> createPlayerPositionSupplier(PlayerPosition existingPosition,
|
private Supplier<PlayerPosition> createPlayerPositionSupplier(PlayerPosition existingPosition,
|
||||||
PlayerRawPosition rawPosition, WTextField world, WTextField location, WTextField notes) {
|
WTextField xText, WTextField yText, WTextField zText, WTextField world,
|
||||||
|
WTextField location, WTextField notes) {
|
||||||
|
|
||||||
return () -> {
|
return () -> {
|
||||||
String id = CreateId(existingPosition);
|
String id = CreateId(existingPosition);
|
||||||
|
long x = parseLong(xText);
|
||||||
|
long y = parseLong(yText);
|
||||||
|
long z = parseLong(zText);
|
||||||
|
|
||||||
|
PlayerRawPosition rawPosition = new PlayerRawPosition(x, y, z, "overworld");
|
||||||
PositionMetadata metadata = CreateMetadata(existingPosition, world, notes);
|
PositionMetadata metadata = CreateMetadata(existingPosition, world, notes);
|
||||||
|
|
||||||
return new PlayerPosition(id, rawPosition, location.getText(), metadata);
|
return new PlayerPosition(id, rawPosition, location.getText(), metadata);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long parseLong(WTextField xText) {
|
||||||
|
String value = xText.getText();
|
||||||
|
return Long.parseLong(value);
|
||||||
|
}
|
||||||
|
|
||||||
private String CreateId(PlayerPosition existingPosition) {
|
private String CreateId(PlayerPosition existingPosition) {
|
||||||
return existingPosition == null ? UUID.randomUUID().toString() : existingPosition.getId();
|
return existingPosition == null ? UUID.randomUUID().toString() : existingPosition.getId();
|
||||||
}
|
}
|
||||||
@ -144,12 +187,19 @@ class DefaultViewHandler extends ViewHandlerBase<PlayerPosition> {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private WWidget CreateLabelForCoorindate(String label) {
|
private WWidget CreateLabelForCoordinate(String label) {
|
||||||
return new WLabel(label, 0xb80000);
|
//return new WLabel(label, 0xb80000);
|
||||||
|
WButton labelButton = new WButton(new LiteralText(label));
|
||||||
|
labelButton.setEnabled(false);
|
||||||
|
return labelButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WWidget CreateWidgetForCoordinate(long l) {
|
private WTextField CreateWidgetForCoordinate(long l) {
|
||||||
return new WText(new LiteralText(String.valueOf(l)), 0x3939ac);
|
WTextField textField = new WTextField();
|
||||||
|
|
||||||
|
textField.setText(String.valueOf(l));
|
||||||
|
|
||||||
|
return textField;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WTextField CreateLocationField(PlayerPosition existingPosition) {
|
private WTextField CreateLocationField(PlayerPosition existingPosition) {
|
||||||
@ -183,7 +233,7 @@ class DefaultViewHandler extends ViewHandlerBase<PlayerPosition> {
|
|||||||
|
|
||||||
private WButton CreatePingButton() {
|
private WButton CreatePingButton() {
|
||||||
WButton button = CreateButton("");
|
WButton button = CreateButton("");
|
||||||
button.setIcon(ResourceUtils.CreatePingIcon());
|
button.setIcon(ResourceUtils.createPingIcon());
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -51,7 +51,7 @@ class ListViewHandler extends ViewHandlerBase<Void> {
|
|||||||
return () -> (Void) null;
|
return () -> (Void) null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBack(Runnable runnable) {
|
public void onBackButtonClick(Runnable runnable) {
|
||||||
this.backButton.setOnClick(runnable);
|
this.backButton.setOnClick(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,8 +123,8 @@ class ListViewHandler extends ViewHandlerBase<Void> {
|
|||||||
this.pingButton = new WButton(new LiteralText(""));
|
this.pingButton = new WButton(new LiteralText(""));
|
||||||
this.detailButton = new WButton(new LiteralText(""));
|
this.detailButton = new WButton(new LiteralText(""));
|
||||||
|
|
||||||
this.pingButton.setIcon(ResourceUtils.CreatePingIcon());
|
this.pingButton.setIcon(ResourceUtils.createPingIcon());
|
||||||
this.detailButton.setIcon(ResourceUtils.CreateDetailsIcon());
|
this.detailButton.setIcon(ResourceUtils.createDetailsIcon());
|
||||||
|
|
||||||
this.add(icon, 0, 0, 1 * 9, 1 * 9);
|
this.add(icon, 0, 0, 1 * 9, 1 * 9);
|
||||||
this.add(world, 1 * 18, 0, 3 * 18, 1 * 18);
|
this.add(world, 1 * 18, 0, 3 * 18, 1 * 18);
|
||||||
@ -147,13 +147,13 @@ class ListViewHandler extends ViewHandlerBase<Void> {
|
|||||||
|
|
||||||
private WButton createDeleteButton() {
|
private WButton createDeleteButton() {
|
||||||
TexturedButton button = new TexturedButton(new LiteralText("x"));
|
TexturedButton button = new TexturedButton(new LiteralText("x"));
|
||||||
button.setTexture(ResourceUtils.CreateIdentifier("close"));
|
button.setTexture(ResourceUtils.getIdentifier("close"));
|
||||||
|
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPosition(PlayerPosition position, IFileStore fileStore) {
|
void setPosition(PlayerPosition position, IFileStore fileStore) {
|
||||||
this.icon.setImage(ResourceUtils.CreateWorldIconIdentifier(position.getWorldDimension()));
|
this.icon.setImage(ResourceUtils.getIdentifier(position.getWorldDimension()));
|
||||||
this.location.setText(new LiteralText(position.getLocationName()));
|
this.location.setText(new LiteralText(position.getLocationName()));
|
||||||
this.location.setColor(0x3939ac);
|
this.location.setColor(0x3939ac);
|
||||||
if (position.getPositionMetadata() != null) {
|
if (position.getPositionMetadata() != null) {
|
||||||
|
|||||||
@ -32,7 +32,6 @@ public class SaveCoordinatesGui implements IModGui {
|
|||||||
this.defaultHandler = CreateDefaultViewHandler();
|
this.defaultHandler = CreateDefaultViewHandler();
|
||||||
this.listHandler = CreateListViewHandler();
|
this.listHandler = CreateListViewHandler();
|
||||||
this.configHandler = CreateConfigHandler();
|
this.configHandler = CreateConfigHandler();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -40,27 +39,23 @@ public class SaveCoordinatesGui implements IModGui {
|
|||||||
showDefaultView(null);
|
showDefaultView(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Screen createConfigScreen() {
|
|
||||||
return this.configHandler.createView(keyBinds.getAllBinds());
|
|
||||||
}
|
|
||||||
|
|
||||||
private IViewHandler<PlayerPosition> CreateDefaultViewHandler() {
|
private IViewHandler<PlayerPosition> CreateDefaultViewHandler() {
|
||||||
DefaultViewHandler handler = new DefaultViewHandler(fileStore, locator);
|
DefaultViewHandler handler = new DefaultViewHandler(fileStore, locator);
|
||||||
|
|
||||||
handler.onSave(this::onSavePosition);
|
handler.onSaveButtonClick(this::savePosition);
|
||||||
handler.onList(this::showListView);
|
handler.onListButtonClick(this::showListView);
|
||||||
handler.onConfig(this::showConfigView);
|
handler.onConfigButtonClick(this::showConfigView);
|
||||||
handler.onPing(new PingPositionOperation(fileStore, locator::locate));
|
handler.onPingButtonClick(this::pingPosition);
|
||||||
handler.onClose(screenController::closeScreen);
|
handler.onCloseButtonClick(screenController::closeScreen);
|
||||||
|
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IViewHandler<Void> CreateListViewHandler() {
|
private IViewHandler<Void> CreateListViewHandler() {
|
||||||
ListViewHandler handler = new ListViewHandler(fileStore, this::onDeletePosition, this::onEditPosition,
|
ListViewHandler handler = new ListViewHandler(fileStore, this::onDeletePosition, this::onEditPosition,
|
||||||
this::onPingPosition);
|
this::pingPosition);
|
||||||
|
|
||||||
handler.onBack(() -> showDefaultView(null));
|
handler.onBackButtonClick(() -> showDefaultView(null));
|
||||||
|
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
@ -68,19 +63,21 @@ public class SaveCoordinatesGui implements IModGui {
|
|||||||
private IViewHandler<List<IKeyBinding>> CreateConfigHandler() {
|
private IViewHandler<List<IKeyBinding>> CreateConfigHandler() {
|
||||||
ConfigViewHandler handler = new ConfigViewHandler();
|
ConfigViewHandler handler = new ConfigViewHandler();
|
||||||
|
|
||||||
handler.onBack(() -> showDefaultView(null));
|
handler.onBackButtonClick(() -> showDefaultView(null));
|
||||||
handler.onSave(this::onSaveConfigs);
|
handler.onSaveButtonClick(this::saveConfigs);
|
||||||
|
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSavePosition() {
|
private void savePosition() {
|
||||||
new SavePositionOperation(fileStore, defaultHandler::getState).run();
|
ErrorResponse response = new SavePositionOperation(fileStore, defaultHandler::getState).call();
|
||||||
showListView();
|
if (!response.isFailed()) {
|
||||||
|
showListView();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onDeletePosition(PlayerPosition position) {
|
private void onDeletePosition(PlayerPosition position) {
|
||||||
new DeletePositionOperation(fileStore, () -> position.getId()).run();
|
new DeletePositionOperation(fileStore, position::getId).call();
|
||||||
showListView();
|
showListView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,12 +85,16 @@ public class SaveCoordinatesGui implements IModGui {
|
|||||||
showDefaultView(position);
|
showDefaultView(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPingPosition(PlayerRawPosition position) {
|
private void pingPosition() {
|
||||||
new PingPositionOperation(fileStore, () -> position).run();
|
new PingPositionOperation(fileStore, locator::locate).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSaveConfigs() {
|
private void pingPosition(PlayerRawPosition position) {
|
||||||
new SaveConfigsOperation(keyBinds, fileStore, configHandler::getState).run();
|
new PingPositionOperation(fileStore, () -> position).call();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveConfigs() {
|
||||||
|
new SaveConfigsOperation(keyBinds, fileStore, configHandler::getState).call();
|
||||||
showDefaultView(null);
|
showDefaultView(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,4 +110,7 @@ public class SaveCoordinatesGui implements IModGui {
|
|||||||
screenController.openScreen(createConfigScreen());
|
screenController.openScreen(createConfigScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Screen createConfigScreen() {
|
||||||
|
return this.configHandler.createView(keyBinds.getAllBinds());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
package me.bionicbeanie.mods.savecoords.gui.impl;
|
package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||||
|
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||||
|
|
||||||
abstract class ViewOperationBase<T> implements Runnable {
|
abstract class ViewOperationBase<T> implements Callable<ErrorResponse> {
|
||||||
|
|
||||||
private IFileStore fileStore;
|
private IFileStore fileStore;
|
||||||
private Supplier<T> stateSupplier;
|
private Supplier<T> stateSupplier;
|
||||||
@ -15,13 +16,48 @@ abstract class ViewOperationBase<T> implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public ErrorResponse call() {
|
||||||
try {
|
try {
|
||||||
executeOperation(fileStore, stateSupplier.get());
|
executeOperation(fileStore, stateSupplier.get());
|
||||||
|
return ErrorResponse.CreateSuccess();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return ErrorResponse.CreateFailure(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void executeOperation(IFileStore fileStore, T state) throws Exception;
|
protected abstract void executeOperation(IFileStore fileStore, T state) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ErrorResponse {
|
||||||
|
|
||||||
|
private static ErrorResponse SUCCESS = new ErrorResponse(false);
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
private boolean failed;
|
||||||
|
|
||||||
|
public static ErrorResponse CreateSuccess() {
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ErrorResponse CreateFailure(String code) {
|
||||||
|
return new ErrorResponse(true, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ErrorResponse(boolean failed) {
|
||||||
|
this(failed, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ErrorResponse(boolean failed, String code) {
|
||||||
|
this.failed = failed;
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode(){
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFailed() {
|
||||||
|
return failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -0,0 +1,9 @@
|
|||||||
|
package me.bionicbeanie.mods.savecoords.util;
|
||||||
|
|
||||||
|
public class DimensionKeys {
|
||||||
|
|
||||||
|
public static String OVERWORLD = "overworld";
|
||||||
|
public static String NETHER = "nether";
|
||||||
|
public static String END = "end";
|
||||||
|
public static String UNKNOWN = "unknown";
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
package me.bionicbeanie.mods.savecoords.util;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
public class IdentifiersCache {
|
||||||
|
|
||||||
|
private String DEFAULT = "nonexistent";
|
||||||
|
private Map<String, Identifier> cache = new HashMap<>();
|
||||||
|
|
||||||
|
public IdentifiersCache() {
|
||||||
|
add(DEFAULT, cache);
|
||||||
|
add("overworld", cache);
|
||||||
|
add("nether", cache);
|
||||||
|
add("end", cache);
|
||||||
|
add("ping", cache);
|
||||||
|
add("close", cache);
|
||||||
|
add("more", cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Identifier get(String resourceName) {
|
||||||
|
return cache.getOrDefault(resourceName, cache.get(DEFAULT));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void add(String resourceName, Map<String, Identifier> cache) {
|
||||||
|
cache.put(resourceName, createIdentifier(resourceName));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Identifier createIdentifier(String file) {
|
||||||
|
return new Identifier("savecoords", "textures/gui/" + file + ".png");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,45 +1,31 @@
|
|||||||
package me.bionicbeanie.mods.savecoords.util;
|
package me.bionicbeanie.mods.savecoords.util;
|
||||||
|
|
||||||
import io.github.cottonmc.cotton.gui.widget.WSprite;
|
import io.github.cottonmc.cotton.gui.widget.WSprite;
|
||||||
import io.github.cottonmc.cotton.gui.widget.WWidget;
|
|
||||||
import io.github.cottonmc.cotton.gui.widget.icon.Icon;
|
import io.github.cottonmc.cotton.gui.widget.icon.Icon;
|
||||||
import io.github.cottonmc.cotton.gui.widget.icon.TextureIcon;
|
import io.github.cottonmc.cotton.gui.widget.icon.TextureIcon;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class ResourceUtils {
|
public class ResourceUtils {
|
||||||
|
|
||||||
public static WWidget CreateWorldIcon(String dimension) {
|
private static IdentifiersCache cache = new IdentifiersCache();
|
||||||
return new WSprite(CreateWorldIconIdentifier(dimension));
|
|
||||||
|
public static WSprite createWorldIcon(String dimension) {
|
||||||
|
return new WSprite(getIdentifier(dimension));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Identifier CreateWorldIconIdentifier(String dimension) {
|
public static Identifier getIdentifier(String resourceName) {
|
||||||
|
return cache.get(resourceName);
|
||||||
if (dimension == null)
|
|
||||||
return CreateIdentifier("nonexistent");
|
|
||||||
if (dimension.contains("overworld"))
|
|
||||||
return CreateIdentifier("overworld");
|
|
||||||
if (dimension.contains("nether"))
|
|
||||||
return CreateIdentifier("nether");
|
|
||||||
if (dimension.contains("end"))
|
|
||||||
return CreateIdentifier("end");
|
|
||||||
|
|
||||||
return CreateIdentifier("nonexistent");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Icon CreatePingIcon() {
|
public static Icon createPingIcon() {
|
||||||
return new TextureIcon(CreateIdentifier("ping"));
|
return new TextureIcon(cache.get("ping"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Icon CreateCloseIcon() {
|
public static Icon createCloseIcon() {
|
||||||
return new TextureIcon(CreateIdentifier("close"));
|
return new TextureIcon(cache.get("close"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Icon CreateDetailsIcon() {
|
public static Icon createDetailsIcon() {
|
||||||
return new TextureIcon(CreateIdentifier("more"));
|
return new TextureIcon(cache.get("more"));
|
||||||
}
|
|
||||||
|
|
||||||
public static Identifier CreateIdentifier(String file) {
|
|
||||||
return new Identifier("savecoords", "textures/gui/" + file + ".png");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user