change: reformat

This commit is contained in:
ZtereoHYPE 2023-06-25 23:13:57 +02:00
parent 2642875f12
commit e1fcbf9029
17 changed files with 320 additions and 232 deletions

View file

@ -9,39 +9,39 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
public class Microcraft implements ClientModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final String MOD_ID = "microcraft";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static Logger VERBOSELOGGER = LoggerFactory.getLogger(MOD_ID + " - VERBOSE LOGGER");
public static final String MOD_ID = "microcraft";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static Logger VERBOSELOGGER = LoggerFactory.getLogger(MOD_ID + " - VERBOSE LOGGER");
public static boolean enabled = true;
public static boolean enabled = true;
public static void toggle() {
enabled = !enabled;
}
public static void toggle() {
enabled = !enabled;
}
@Override
public void onInitializeClient() {
//message from mod to confirm that it has been loaded
LOGGER.info("Microcraft Initialized!");
@Override
public void onInitializeClient() {
//message from mod to confirm that it has been loaded
LOGGER.info("Microcraft Initialized!");
// register configs
ModConfigs.registerConfigs();
// register configs
ModConfigs.registerConfigs();
//blink LED on startup
//blink LED on startup
/*try {
LedBlink.initialisation();
} catch (InterruptedException e) {
LOGGER.info("Failed to make Arduino LED blink. ARDUINO NOT CONNECTED!");
}*/
try {
ProfileConfig.uwu();
} catch (IOException e) {
LOGGER.error("AHHHHHHHHHHHHHHHHHHHHH IO");
System.out.print(e);
}
}
try {
ProfileConfig.uwu();
} catch (IOException e) {
LOGGER.error("AHHHHHHHHHHHHHHHHHHHHH IO");
System.out.print(e);
}
}
}

View file

@ -2,4 +2,6 @@ package me.jonasjones.microcraft.board;
import net.minecraft.resources.ResourceLocation;
public record MicrocontrollerBoardIcon(ResourceLocation boardTextureHorizontal, ResourceLocation boardTextureVertical, int width, int height) {}
public record MicrocontrollerBoardIcon(ResourceLocation boardTextureHorizontal, ResourceLocation boardTextureVertical,
int width, int height) {
}

View file

@ -13,67 +13,68 @@ import java.io.InputStreamReader;
public class BoardsConfig {
public BoardsConfig() {
}
// DON'T TOUCH THE FOLLOWING CODE
private static BoardsConfig instance;
// DON'T TOUCH THE FOLLOWING CODE
private static BoardsConfig instance;
public BoardsConfig() {
}
public static BoardsConfig getInstance() {
if (instance == null) {
instance = fromDefaults();
}
return instance;
}
public static BoardsConfig getInstance() {
if (instance == null) {
instance = fromDefaults();
}
return instance;
}
public static void load(File file) {
instance = fromFile(file);
public static void load(File file) {
instance = fromFile(file);
// no config file found
if (instance == null) {
instance = fromDefaults();
}
}
// no config file found
if (instance == null) {
instance = fromDefaults();
}
}
public static void load(String file) {
load(new File(file));
}
public static void load(String file) {
load(new File(file));
}
private static BoardsConfig fromDefaults() {
BoardsConfig config = new BoardsConfig();
return config;
}
private static BoardsConfig fromDefaults() {
BoardsConfig config = new BoardsConfig();
return config;
}
public void toFile(String file) {
toFile(new File(file));
}
private static BoardsConfig fromFile(File configFile) {
try {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile)));
return gson.fromJson(reader, BoardsConfig.class);
} catch (FileNotFoundException e) {
return null;
}
}
public void toFile(File file) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String jsonConfig = gson.toJson(this);
FileWriter writer;
try {
writer = new FileWriter(file);
writer.write(jsonConfig);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void toFile(String file) {
toFile(new File(file));
}
private static BoardsConfig fromFile(File configFile) {
try {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile)));
return gson.fromJson(reader, BoardsConfig.class);
} catch (FileNotFoundException e) {
return null;
}
}
public void toFile(File file) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String jsonConfig = gson.toJson(this);
FileWriter writer;
try {
writer = new FileWriter(file);
writer.write(jsonConfig);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public String toString() {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
return gson.toJson(this);
}}
@Override
public String toString() {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
return gson.toJson(this);
}
}

View file

@ -8,14 +8,13 @@ import java.util.List;
public class ModConfigProvider implements DefaultConfig {
private final List<Pair> configsList = new ArrayList<>();
private String configContents = "";
public List<Pair> getConfigsList() {
return configsList;
}
private final List<Pair> configsList = new ArrayList<>();
public void addKeyValuePair(Pair<String, ?> keyValuePair, String comment) {
configsList.add(keyValuePair);
configContents += keyValuePair.getFirst() + "=" + keyValuePair.getSecond() + " #"

View file

@ -7,18 +7,15 @@ import me.jonasjones.microcraft.util.VerboseLogger;
public class ModConfigs {
public static SimpleConfig CONFIGMAIN;
public static SimpleConfig CONFIGLISTS;
private static ModConfigProvider configMain;
private static ModConfigProvider configLists;
//configMain
public static Boolean ISENABLED;
public static String DEFAULTBOARDFALLBACK;
public static int LOOPINTERVAL;
public static Boolean BOARDMELTING;
public static Boolean VERBOSE = false; //needs to be set to false since the verbose logger is called before config file is fully loaded
public static Boolean VERBOSE = false; //needs to be set to false since the verbose logger is called before
// config file is fully loaded
public static String EDITOR;
public static String CUSTOMEDITOR;
//configList
public static Boolean DISPLAYENTRYALL;
public static Boolean DISPLAYENTRYPLAYERJUMP;
@ -36,7 +33,8 @@ public class ModConfigs {
public static Boolean DISPLAYENTRYISPLAYERWALKRIGHT;
public static Boolean DISPLAYENTRYISPLAYERWALKLEFT;
public static Boolean DISPLAYENTRYISPLAYERSNEAK;
private static ModConfigProvider configMain;
private static ModConfigProvider configLists;
public static void registerConfigs() {
configMain = new ModConfigProvider();
@ -51,37 +49,58 @@ public class ModConfigs {
//make verbose logger show that it is active and print configs to logger
VerboseLogger.info("Verbose Logger is now logging.");
VerboseLogger.info("Loaded config file CONFIGMAIN successfully: " + configMain.getConfigsList().size() + " configurations have been set properly");
VerboseLogger.info("Loaded config file CONFIGMAIN successfully: " + configLists.getConfigsList().size() + " configurations have been set properly");
VerboseLogger.info("Loaded config file CONFIGMAIN successfully: " + configMain.getConfigsList().size() + " " +
"configurations have been set properly");
VerboseLogger.info("Loaded config file CONFIGMAIN successfully: " + configLists.getConfigsList().size() + " " +
"configurations have been set properly");
}
private static void createConfigs() {
//configMain
configMain.addKeyValuePair(new Pair<>("basic.isEnabled", true), "whether or not the mod is enabled");
configMain.addKeyValuePair(new Pair<>("basic.defaultBoardFallback", "A-nano"), "The board to automatically be selected if failed to detect automatically. All valid ID's can be found at: https://github.com/J-onasJones/MicrocontrollerMC/wiki/Microcontroller-Boards#supported-boards");
configMain.addKeyValuePair(new Pair<>("basic.defaultBoardFallback", "A-nano"), "The board to automatically be" +
" selected if failed to detect automatically. All valid ID's can be found at: https://github" +
".com/J-onasJones/MicrocontrollerMC/wiki/Microcontroller-Boards#supported-boards");
configMain.addKeyValuePair(new Pair<>("advanced.loopInterval", 50), "The Delay in ms between each check.");
configMain.addKeyValuePair(new Pair<>("fun.boardMelting", false), "Whether or not the board should have a flame overlay instead of being greyed out when not connected.");
configMain.addKeyValuePair(new Pair<>("fun.boardMelting", false), "Whether or not the board should have a " +
"flame overlay instead of being greyed out when not connected.");
configMain.addKeyValuePair(new Pair<>("debug.verbose", false), "Toggle verbose console output.");
configMain.addKeyValuePair(new Pair<>("editor.default", "ingame"), "The default editor for the board program. All valid default Editors can be found at: https://github.com/J-onasJones/MicrocontrollerMC/wiki/Board-Program-Editors#available-editors");
configMain.addKeyValuePair(new Pair<>("editor.custom", "None"), "The editor to choose if 'editor.default' is set to 'custom'.");
configMain.addKeyValuePair(new Pair<>("editor.default", "ingame"), "The default editor for the board program." +
" All valid default Editors can be found at: https://github" +
".com/J-onasJones/MicrocontrollerMC/wiki/Board-Program-Editors#available-editors");
configMain.addKeyValuePair(new Pair<>("editor.custom", "None"), "The editor to choose if 'editor.default' is " +
"set to 'custom'.");
//configLists
configLists.addKeyValuePair(new Pair<>("displayEntry.all", false), "Whether or not to display all entries. This overrides all other states except for debug and experimental entries. More infos can be found at: https://github.com/J-onasJones/MicrocontrollerMC/wiki/Pin-Map-Entries#list-of-all-entries");
configLists.addKeyValuePair(new Pair<>("displayEntry.all", false), "Whether or not to display all entries. " +
"This overrides all other states except for debug and experimental entries. More infos can be found " +
"at: https://github.com/J-onasJones/MicrocontrollerMC/wiki/Pin-Map-Entries#list-of-all-entries");
configLists.addKeyValuePair(new Pair<>("displayEntry.playerJump", true), "Display Player Jump Entry");
configLists.addKeyValuePair(new Pair<>("displayEntry.playerSprint", true), "Display Player Sprint Entry");
configLists.addKeyValuePair(new Pair<>("displayEntry.playerWalkForwards", true), "Display Player Walk Forwards Entry");
configLists.addKeyValuePair(new Pair<>("displayEntry.playerWalkBackwards", true), "Display Player Walk Backwards Entry");
configLists.addKeyValuePair(new Pair<>("displayEntry.playerWalkRight", true), "Display Player Walk Right Entry");
configLists.addKeyValuePair(new Pair<>("displayEntry.playerWalkForwards", true), "Display Player Walk " +
"Forwards Entry");
configLists.addKeyValuePair(new Pair<>("displayEntry.playerWalkBackwards", true), "Display Player Walk " +
"Backwards Entry");
configLists.addKeyValuePair(new Pair<>("displayEntry.playerWalkRight", true), "Display Player Walk Right " +
"Entry");
configLists.addKeyValuePair(new Pair<>("displayEntry.playerWalkLeft", true), "Display Player Walk Left Entry");
configLists.addKeyValuePair(new Pair<>("displayEntry.playerSneak", true), "Display Player Sneak Entry");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.all", false), "Whether or not to display all 'Is' entries. This overrides all other states except for debug and experimental entries. More infos can be found at: https://github.com/J-onasJones/MicrocontrollerMC/wiki/Pin-Map-Entries#list-of-all-entries");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.all", false), "Whether or not to display all 'Is' " +
"entries. This overrides all other states except for debug and experimental entries. More infos can " +
"be found at: https://github.com/J-onasJones/MicrocontrollerMC/wiki/Pin-Map-Entries#list-of-all" +
"-entries");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerJump", true), "Display Is Player Jumping Entry");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerSprint", true), "Display Is Player Sprinting Entry");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerWalkForwards", true), "Display Is Player Walking Forwards Entry");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerWalkBackwards", true), "Display Is Player Walking Backwards Entry");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerWalkRight", true), "Display Is Player Walking Right Entry");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerWalkLeft", true), "Display Is Player Walking Left Entry");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerSprint", true), "Display Is Player Sprinting " +
"Entry");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerWalkForwards", true), "Display Is Player Walking" +
" Forwards Entry");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerWalkBackwards", true), "Display Is Player " +
"Walking Backwards Entry");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerWalkRight", true), "Display Is Player Walking " +
"Right Entry");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerWalkLeft", true), "Display Is Player Walking " +
"Left Entry");
configLists.addKeyValuePair(new Pair<>("displayEntryIs.playerSneak", true), "Display Is Player Sneaking Entry");
}

View file

@ -39,51 +39,30 @@ public class SimpleConfig {
private final ConfigRequest request;
private boolean broken = false;
public interface DefaultConfig {
String get(String namespace);
private SimpleConfig(ConfigRequest request) {
this.request = request;
String identifier = "Config '" + request.filename + "'";
static String empty(String namespace) {
return "";
}
}
if (!request.file.exists()) {
Microcraft.LOGGER.info(identifier + " is missing, generating default one...");
public static class ConfigRequest {
private final File file;
private final String filename;
private DefaultConfig provider;
private ConfigRequest(File file, String filename) {
this.file = file;
this.filename = filename;
this.provider = DefaultConfig::empty;
try {
createConfig();
} catch (IOException e) {
Microcraft.LOGGER.error(identifier + " failed to generate!");
Microcraft.LOGGER.trace(String.valueOf(e));
broken = true;
}
}
/**
* Sets the default config provider, used to generate the
* config if it's missing.
*
* @param provider default config provider
* @return current config request object
* @see DefaultConfig
*/
public ConfigRequest provider(DefaultConfig provider) {
this.provider = provider;
return this;
}
/**
* Loads the config from the filesystem.
*
* @return config object
* @see SimpleConfig
*/
public SimpleConfig request() {
return new SimpleConfig(this);
}
private String getConfig() {
return provider.get(filename) + "\n";
if (!broken) {
try {
loadConfig();
} catch (Exception e) {
Microcraft.LOGGER.error(identifier + " failed to load!");
Microcraft.LOGGER.trace(String.valueOf(e));
broken = true;
}
}
}
@ -133,34 +112,6 @@ public class SimpleConfig {
}
}
private SimpleConfig(ConfigRequest request) {
this.request = request;
String identifier = "Config '" + request.filename + "'";
if (!request.file.exists()) {
Microcraft.LOGGER.info(identifier + " is missing, generating default one...");
try {
createConfig();
} catch (IOException e) {
Microcraft.LOGGER.error(identifier + " failed to generate!");
Microcraft.LOGGER.trace(String.valueOf(e));
broken = true;
}
}
if (!broken) {
try {
loadConfig();
} catch (Exception e) {
Microcraft.LOGGER.error(identifier + " failed to load!");
Microcraft.LOGGER.trace(String.valueOf(e));
broken = true;
}
}
}
/**
* Queries a value from config, returns `null` if the
* key does not exist.
@ -244,8 +195,58 @@ public class SimpleConfig {
* @return true if the operation was successful
*/
public boolean delete() {
VerboseLogger.warn("Config '" + request.filename + "' was removed from existence! Restart the game to regenerate it.");
VerboseLogger.warn("Config '" + request.filename + "' was removed from existence! Restart the game to " +
"regenerate it.");
return request.file.delete();
}
public interface DefaultConfig {
static String empty(String namespace) {
return "";
}
String get(String namespace);
}
public static class ConfigRequest {
private final File file;
private final String filename;
private DefaultConfig provider;
private ConfigRequest(File file, String filename) {
this.file = file;
this.filename = filename;
this.provider = DefaultConfig::empty;
}
/**
* Sets the default config provider, used to generate the
* config if it's missing.
*
* @param provider default config provider
* @return current config request object
* @see DefaultConfig
*/
public ConfigRequest provider(DefaultConfig provider) {
this.provider = provider;
return this;
}
/**
* Loads the config from the filesystem.
*
* @return config object
* @see SimpleConfig
*/
public SimpleConfig request() {
return new SimpleConfig(this);
}
private String getConfig() {
return provider.get(filename) + "\n";
}
}
}

View file

@ -13,10 +13,11 @@ import net.minecraft.network.chat.Component;
public class BoardScreen extends Screen {
private final Screen parent;
public BoardScreen (Screen parent) {
public BoardScreen(Screen parent) {
super(Component.nullToEmpty("Microcraft Configuration"));
this.parent = parent;
}
protected void init() {

View file

@ -12,14 +12,15 @@ import net.minecraft.network.chat.Component;
public class GuiHome extends Screen {
private final Screen parent;
public GuiHome (Screen parent) {
public GuiHome(Screen parent) {
super(Component.nullToEmpty("Microcraft Configuration"));
this.parent = parent;
}
protected void init() {
this.addRenderableWidget(Button.builder(Component.nullToEmpty("Configure Microcontrollers"), (button) -> {
this.minecraft.setScreen(new SelectDevice(this));
}).bounds( this.width / 2 - 155, this.height / 6 + 12, 150, 20).build());
}).bounds(this.width / 2 - 155, this.height / 6 + 12, 150, 20).build());
this.addRenderableWidget(Button.builder(Component.nullToEmpty("Configure Microcraft"), (button) -> {
this.minecraft.setScreen(new ModSettings(this));
}).bounds(this.width / 2 + 5, this.height / 6 + 12, 150, 20).build());
@ -27,7 +28,9 @@ public class GuiHome extends Screen {
this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, (button) -> {
this.minecraft.setScreen(this.parent);
}).bounds(this.width / 2 - 100, this.height / 6 + 168, 200, 20).build());
this.addRenderableWidget(new net.minecraft.client.gui.components.Checkbox(50, 50, 100, 20, Component.nullToEmpty("uwu checkbox"), false));
this.addRenderableWidget(new net.minecraft.client.gui.components.Checkbox(50, 50, 100, 20,
Component.nullToEmpty("uwu checkbox"
), false));
}
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {

View file

@ -13,10 +13,11 @@ import net.minecraft.network.chat.Component;
public class ModSettings extends Screen {
private final Screen parent;
public ModSettings (Screen parent) {
public ModSettings(Screen parent) {
super(Component.nullToEmpty("MicrocontrollerMC Controls"));
this.parent = parent;
}
protected void init() {

View file

@ -3,5 +3,6 @@ package me.jonasjones.microcraft.gui.screens;
import java.awt.List;
public class ObjectSelectionList {
public static void display(int x, int y, int width, int height, List objects) {}
public static void display(int x, int y, int width, int height, List objects) {
}
}

View file

@ -23,13 +23,13 @@ import java.util.function.Supplier;
public class SelectDevice extends Screen {
private static final Logger LOGGER = LogUtils.getLogger();
protected final Screen parent;
protected EditBox searchBox;
@Nullable
private List<FormattedCharSequence> tooltip;
private Button deleteButton;
private Button selectButton;
private Button editButton;
private Button recreateButton;
protected EditBox searchBox;
private WorldSelectionList levelList;
public SelectDevice(Screen parent) {
@ -47,27 +47,30 @@ public class SelectDevice extends Screen {
protected void init() {
//this.client.keyboard.setRepeatEvents(true);
this.searchBox = new EditBox(this.font, this.width / 2 - 100, 22, 200, 20, this.searchBox, Component.translatable("selectWorld.search"));
this.searchBox = new EditBox(this.font, this.width / 2 - 100, 22, 200, 20, this.searchBox,
Component.translatable("selectWorld.search"));
this.searchBox.setResponder((search) -> {
//this.levelList.filter(search);
});
SelectWorldScreen uwu = new SelectWorldScreen(this);
//this.levelList = new WorldListWidget(uwu, this.client, this.width, this.height, 48, this.height - 64, 36, this.getSearchFilter(), this.levelList);
//this.levelList = new WorldListWidget(uwu, this.client, this.width, this.height, 48, this.height - 64, 36,
// this.getSearchFilter(), this.levelList);
this.addWidget(this.searchBox);
this.addWidget(this.levelList);
this.selectButton = (Button)this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.select"), (button) -> {
this.selectButton = (Button) this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.select"), (button) -> {
this.levelList.getSelectedOpt().ifPresent(WorldSelectionList.WorldListEntry::joinWorld);
}).bounds(this.width / 2 - 154, this.height - 52, 150, 20).build());
this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.create"), (button) -> {
CreateWorldScreen.openFresh(this.minecraft, this);
}).bounds(this.width / 2 + 4, this.height - 52, 150, 20).build());
this.editButton = (Button)this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.edit"), (button) -> {
this.editButton = (Button) this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.edit")
, (button) -> {
this.levelList.getSelectedOpt().ifPresent(WorldSelectionList.WorldListEntry::editWorld);
}).bounds(this.width / 2 - 154, this.height - 28, 72, 20).build());
this.deleteButton = (Button)this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.delete"), (button) -> {
this.deleteButton = (Button) this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.delete"), (button) -> {
this.levelList.getSelectedOpt().ifPresent(WorldSelectionList.WorldListEntry::deleteWorld);
}).bounds(this.width / 2 - 76, this.height - 28, 72, 20).build());
this.recreateButton = (Button)this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.recreate"), (button) -> {
this.recreateButton = (Button) this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.recreate"), (button) -> {
this.levelList.getSelectedOpt().ifPresent(WorldSelectionList.WorldListEntry::recreateWorld);
}).bounds(this.width / 2 + 4, this.height - 28, 72, 20).build());
this.addRenderableWidget(Button.builder(CommonComponents.GUI_CANCEL, (button) -> {
@ -78,7 +81,8 @@ public class SelectDevice extends Screen {
}
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return super.keyPressed(keyCode, scanCode, modifiers) ? true : this.searchBox.keyPressed(keyCode, scanCode, modifiers);
return super.keyPressed(keyCode, scanCode, modifiers) ? true : this.searchBox.keyPressed(keyCode, scanCode,
modifiers);
}
public void onClose() {

View file

@ -15,9 +15,18 @@ public class BoardIconSelectionScreen extends Screen {
private final Screen parent;
private final MicrocontrollerBoardIcon NANO_BOARD_TEXTURE = new MicrocontrollerBoardIcon(new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-nano-sideways.png"), new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-nano.png"), 128, 52);
private final MicrocontrollerBoardIcon UNO_BOARD_TEXTURE = new MicrocontrollerBoardIcon(new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-uno-sideways.png"), new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-uno.png"), 128, 90);
private final MicrocontrollerBoardIcon PROMINI_BOARD_TEXTURE = new MicrocontrollerBoardIcon(new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-pro_mini-sideways.png"), new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-pro_mini.png"), 97, 52);
private final MicrocontrollerBoardIcon NANO_BOARD_TEXTURE =
new MicrocontrollerBoardIcon(new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-nano" +
"-sideways.png"), new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-nano.png"),
128, 52);
private final MicrocontrollerBoardIcon UNO_BOARD_TEXTURE =
new MicrocontrollerBoardIcon(new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-uno" +
"-sideways.png"), new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-uno.png"), 128
, 90);
private final MicrocontrollerBoardIcon PROMINI_BOARD_TEXTURE =
new MicrocontrollerBoardIcon(new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-pro_mini" +
"-sideways.png"), new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-pro_mini.png")
, 97, 52);
public BoardIconSelectionScreen(Screen parent) {
super(Component.nullToEmpty("Select Board Icon"));
@ -25,15 +34,27 @@ public class BoardIconSelectionScreen extends Screen {
}
protected void init() {
this.addRenderableWidget(new ImageButton(this.width / 2 - 138, this.height / 2 - 85, NANO_BOARD_TEXTURE.width(), NANO_BOARD_TEXTURE.height(), 0, 0, 0, NANO_BOARD_TEXTURE.boardTextureHorizontal(), NANO_BOARD_TEXTURE.width(), NANO_BOARD_TEXTURE.height(), (buttonWidget) -> {
this.addRenderableWidget(new ImageButton(this.width / 2 - 138, this.height / 2 - 85,
NANO_BOARD_TEXTURE.width(), NANO_BOARD_TEXTURE.height(), 0, 0, 0,
NANO_BOARD_TEXTURE.boardTextureHorizontal(),
NANO_BOARD_TEXTURE.width(), NANO_BOARD_TEXTURE.height(),
(buttonWidget) -> {
BOARD_TEXTURE = NANO_BOARD_TEXTURE;
this.minecraft.setScreen(this.parent);
}));
this.addRenderableWidget(new ImageButton(this.width / 2 - 138, this.height / 2 - 20, UNO_BOARD_TEXTURE.width(), UNO_BOARD_TEXTURE.height(), 0, 0, 0, UNO_BOARD_TEXTURE.boardTextureHorizontal(), UNO_BOARD_TEXTURE.width(), UNO_BOARD_TEXTURE.height(), (buttonWidget) -> {
this.addRenderableWidget(new ImageButton(this.width / 2 - 138, this.height / 2 - 20,
UNO_BOARD_TEXTURE.width(), UNO_BOARD_TEXTURE.height(), 0, 0, 0,
UNO_BOARD_TEXTURE.boardTextureHorizontal(),
UNO_BOARD_TEXTURE.width(), UNO_BOARD_TEXTURE.height(),
(buttonWidget) -> {
BOARD_TEXTURE = UNO_BOARD_TEXTURE;
this.minecraft.setScreen(this.parent);
}));
this.addRenderableWidget(new ImageButton(this.width / 2 + 10, this.height / 2 - 85, PROMINI_BOARD_TEXTURE.width(), PROMINI_BOARD_TEXTURE.height(), 0, 0, 0, PROMINI_BOARD_TEXTURE.boardTextureHorizontal(), PROMINI_BOARD_TEXTURE.width(), PROMINI_BOARD_TEXTURE.height(), (buttonWidget) -> {
this.addRenderableWidget(new ImageButton(this.width / 2 + 10, this.height / 2 - 85,
PROMINI_BOARD_TEXTURE.width(), PROMINI_BOARD_TEXTURE.height(), 0, 0,
0, PROMINI_BOARD_TEXTURE.boardTextureHorizontal(),
PROMINI_BOARD_TEXTURE.width(), PROMINI_BOARD_TEXTURE.height(),
(buttonWidget) -> {
BOARD_TEXTURE = PROMINI_BOARD_TEXTURE;
this.minecraft.setScreen(this.parent);
}));

View file

@ -18,22 +18,27 @@ public class TextureSelectScreen extends Screen {
super(Component.nullToEmpty("Microcraft Configuration"));
this.parent = parent;
}
protected void init() {
/*this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 12, 150, 20, Text.of("Configure Microcontrollers"), (button) -> {
/*this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 12, 150, 20, Text.of
("Configure Microcontrollers"), (button) -> {
this.client.setScreen(new SelectDevice(this));
}));
this.addDrawableChild(new ButtonWidget(this.width / 2 + 5, this.height / 6 + 12, 150, 20, Text.of("Configure Microcraft"), (button) -> {
this.addDrawableChild(new ButtonWidget(this.width / 2 + 5, this.height / 6 + 12, 150, 20, Text.of("Configure
Microcraft"), (button) -> {
this.client.setScreen(new ModSettings(this));
}));
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, ScreenTexts.DONE, (button) -> {
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, ScreenTexts
.DONE, (button) -> {
this.client.setScreen(this.parent);
}));
this.addDrawableChild(new net.minecraft.client.gui.widget.CheckboxWidget(50, 50, 100, 20, Text.of("uwu checkbox"), false));*/
this.addDrawableChild(new net.minecraft.client.gui.widget.CheckboxWidget(50, 50, 100, 20, Text.of("uwu
checkbox"), false));*/
this.addRenderableWidget(Button.builder(Component.nullToEmpty("Configure Microcontrollers"),(button) -> {
this.addRenderableWidget(Button.builder(Component.nullToEmpty("Configure Microcontrollers"), (button) -> {
this.minecraft.setScreen(new SelectDevice(this));
}).bounds(this.width / 2 - 155, this.height / 6 + 12, 150, 20).build());
this.addRenderableWidget(Button.builder(Component.nullToEmpty("Configure Microcraft"), (button) -> {
@ -43,7 +48,9 @@ public class TextureSelectScreen extends Screen {
this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, (button) -> {
this.minecraft.setScreen(this.parent);
}).bounds(this.width / 2 - 100, this.height / 6 + 168, 200, 20).build());
this.addRenderableWidget(new net.minecraft.client.gui.components.Checkbox(50, 50, 100, 20, Component.nullToEmpty("uwu checkbox"), false));
this.addRenderableWidget(new net.minecraft.client.gui.components.Checkbox(50, 50, 100, 20,
Component.nullToEmpty("uwu checkbox"
), false));
}

View file

@ -25,43 +25,67 @@ import net.minecraft.resources.ResourceLocation;
@Environment(EnvType.CLIENT)
public class BoardConfigwidget extends Screen {
private final Screen parent;
public static MicrocontrollerBoardIcon BOARD_TEXTURE =
new MicrocontrollerBoardIcon(new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-nano" +
"-sideways.png"), new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-nano.png"),
128, 52);
//public static Identifier BOARD_TEXTURE = new Identifier(Microcraft.MOD_ID, "textures/boards/arduino-nano.png");
public static MicrocontrollerBoardIcon BOARD_TEXTURE = new MicrocontrollerBoardIcon(new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-nano-sideways.png"), new ResourceLocation(Microcraft.MOD_ID, "textures/boards/arduino-nano.png"), 128, 52);
private final Screen parent;
public BoardConfigwidget(Screen parent) {
super(Component.literal("Microcraft Configuration"));
this.parent = parent;
}
protected void init() {
//TODO: get current profile
addRenderableWidget(new Button.Builder(Component.literal("[Profile]"), (buttonWidget) -> this.minecraft.setScreen(new ProfileSelectionScreen(this))).bounds(this.width / 2 - 50, this.height - 52, 100, 20).build());
addRenderableWidget(new Button.Builder(Component.literal("[Profile]"),
(buttonWidget) -> this.minecraft.setScreen(new ProfileSelectionScreen(this))).bounds(this.width / 2 - 50, this.height - 52, 100, 20).build());
//TODO: make Board texture clickable to select different texture.
this.addRenderableWidget(new ImageButton(this.width / 2 - (BOARD_TEXTURE.height() / 2), this.height / 2 - (BOARD_TEXTURE.height() / 2) - 45, BOARD_TEXTURE.height(), BOARD_TEXTURE.width(), 0, 0, 0, BOARD_TEXTURE.boardTextureVertical(), BOARD_TEXTURE.height(), BOARD_TEXTURE.width(), (buttonWidget) -> this.minecraft.setScreen(new BoardIconSelectionScreen(this))));
this.addRenderableWidget(new ImageButton(this.width / 2 - (BOARD_TEXTURE.height() / 2),
this.height / 2 - (BOARD_TEXTURE.height() / 2) - 45,
BOARD_TEXTURE.height(), BOARD_TEXTURE.width(), 0, 0, 0,
BOARD_TEXTURE.boardTextureVertical(), BOARD_TEXTURE.height(),
BOARD_TEXTURE.width(),
(buttonWidget) -> this.minecraft.setScreen(new BoardIconSelectionScreen(this))));
/*this.addRenderableWidget(ButtonWidget.builder(Component.literal("About Microcraft"), (buttonWidget) -> this.minecraft.setScreen(new ModCreditsScreen(this))).dimensions(10, this.height - 30, 200, 20).build());
this.addRenderableWidget(ButtonWidget.builder(Component.literal("Advanced Pin Mapping"), (buttonWidget) -> this.minecraft.setScreen(new AdvancedPinMappingScreen(this))).dimensions(this.width / 2 - 100, this.height - 55, 200, 20).build());
this.addRenderableWidget(ButtonWidget.builder(Component.literal("Advanced Board Settings"), (buttonWidget) -> this.minecraft.setScreen(new AdvancedSettingsScreen(this))).dimensions(this.width / 2 - 100, this.height - 80, 200, 20).build());
this.addRenderableWidget(ButtonWidget.builder(Component.literal("Done"), (buttonWidget) -> this.minecraft.setScreen(this.parent)).dimensions(this.width - 60, this.height - 30, 50, 20).build());
this.addRenderableWidget(ButtonWidget.builder(Component.literal("Write to Board and Quit"), (buttonWidget) -> this.minecraft.setScreen(this.parent)).dimensions(this.width - 210, this.height - 30, 140, 20).build());
this.addRenderableWidget(ButtonWidget.builder(Component.literal("Microcraft Settings"), (buttonWidget) -> this.minecraft.setScreen(new ModSettings(this))).dimensions(this.width - 210, this.height - 55, 200, 20).build());*/
/*this.addRenderableWidget(ButtonWidget.builder(Component.literal("About Microcraft"), (buttonWidget) -> this
.minecraft.setScreen(new ModCreditsScreen(this))).dimensions(10, this.height - 30, 200, 20).build());
this.addRenderableWidget(ButtonWidget.builder(Component.literal("Advanced Pin Mapping"), (buttonWidget) ->
this.minecraft.setScreen(new AdvancedPinMappingScreen(this))).dimensions(this.width / 2 - 100, this.height -
55, 200, 20).build());
this.addRenderableWidget(ButtonWidget.builder(Component.literal("Advanced Board Settings"), (buttonWidget) ->
this.minecraft.setScreen(new AdvancedSettingsScreen(this))).dimensions(this.width / 2 - 100, this.height -
80, 200, 20).build());
this.addRenderableWidget(ButtonWidget.builder(Component.literal("Done"), (buttonWidget) -> this.minecraft
.setScreen(this.parent)).dimensions(this.width - 60, this.height - 30, 50, 20).build());
this.addRenderableWidget(ButtonWidget.builder(Component.literal("Write to Board and Quit"), (buttonWidget) ->
this.minecraft.setScreen(this.parent)).dimensions(this.width - 210, this.height - 30, 140, 20).build());
this.addRenderableWidget(ButtonWidget.builder(Component.literal("Microcraft Settings"), (buttonWidget) ->
this.minecraft.setScreen(new ModSettings(this))).dimensions(this.width - 210, this.height - 55, 200, 20)
.build());*/
this.addRenderableWidget(new Button.Builder(Component.literal("About"), (buttonWidget) -> this.minecraft.setScreen(new ModCreditsScreen(this)))
.bounds(this.width / 2 - 154, this.height - 28, 75, 20).build());
this.addRenderableWidget(new Button.Builder(Component.literal("Pin Mapping"), (buttonWidget) -> this.minecraft.setScreen(new AdvancedPinMappingScreen(this)))
.bounds(this.width / 2 + 4 + 50, this.height - 52, 100, 20).build());
this.addRenderableWidget(new Button.Builder(Component.literal("Board Settings"), (buttonWidget) -> this.minecraft.setScreen(new AdvancedSettingsScreen(this)))
.bounds(this.width / 2 - 154, this.height - 52, 100, 20).build());
this.addRenderableWidget(new Button.Builder(Component.literal("Done"), (buttonWidget) -> this.minecraft.setScreen(this.parent))
.bounds(this.width / 2 + 4 + 76, this.height - 28, 75, 20).build());
Button upload = this.addRenderableWidget(new Button.Builder(Component.literal("Upload"), (buttonWidget) -> this.minecraft.setScreen(this.parent))
.bounds(this.width / 2, this.height - 28, 75, 20).build());
this.addRenderableWidget(new Button.Builder(Component.literal("About"),
(buttonWidget) -> this.minecraft.setScreen(new ModCreditsScreen(this)))
.bounds(this.width / 2 - 154, this.height - 28, 75, 20).build());
this.addRenderableWidget(new Button.Builder(Component.literal("Pin Mapping"),
(buttonWidget) -> this.minecraft.setScreen(new AdvancedPinMappingScreen(this)))
.bounds(this.width / 2 + 4 + 50, this.height - 52, 100, 20).build());
this.addRenderableWidget(new Button.Builder(Component.literal("Board Settings"),
(buttonWidget) -> this.minecraft.setScreen(new AdvancedSettingsScreen(this)))
.bounds(this.width / 2 - 154, this.height - 52, 100, 20).build());
this.addRenderableWidget(new Button.Builder(Component.literal("Done"),
(buttonWidget) -> this.minecraft.setScreen(this.parent))
.bounds(this.width / 2 + 4 + 76, this.height - 28, 75, 20).build());
Button upload = this.addRenderableWidget(new Button.Builder(Component.literal("Upload"),
(buttonWidget) -> this.minecraft.setScreen(this.parent))
.bounds(this.width / 2, this.height - 28, 75, 20).build());
upload.active = false;
this.addRenderableWidget(new Button.Builder(Component.literal("Settings"), (buttonWidget) -> this.minecraft.setScreen(new ModSettings(this)))
.bounds(this.width / 2 - 75, this.height - 28, 70, 20).build());
this.addRenderableWidget(new Button.Builder(Component.literal("Settings"),
(buttonWidget) -> this.minecraft.setScreen(new ModSettings(this)))
.bounds(this.width / 2 - 75, this.height - 28, 70, 20).build());
}
@ -73,5 +97,4 @@ public class BoardConfigwidget extends Screen {
}
}

View file

@ -30,6 +30,7 @@ package me.jonasjones.microcraft.mixin;
// this.addDrawableChild(ButtonWidget.builder( Text.of(""), (button) -> {
// this.client.setScreen(new BoardScreen(this));
// }).dimensions(buttonX, buttonY, 20, 20).build());
// this.addDrawableChild( new TexturedButtonWidget(buttonX, buttonY, 20, 20, 0, 0, 0, ICON_TEXTURE, 20, 20, (buttonWidget) -> this.client.setScreen(new BoardScreen(this))));
// this.addDrawableChild( new TexturedButtonWidget(buttonX, buttonY, 20, 20, 0, 0, 0, ICON_TEXTURE, 20, 20,
// (buttonWidget) -> this.client.setScreen(new BoardScreen(this))));
// }
//}

View file

@ -1,4 +1,4 @@
package me.jonasjones.microcraft.object;
public class PinMap {
}
}

View file

@ -9,24 +9,28 @@ public class VerboseLogger {
Microcraft.VERBOSELOGGER.info(message);
}
}
public void debug(String message) {
if (ModConfigs.VERBOSE) {
Microcraft.VERBOSELOGGER.debug(message);
}
}
public static void error(String message) {
if (ModConfigs.VERBOSE) {
Microcraft.VERBOSELOGGER.error(message);
}
}
public static void trace( String message) {
public static void trace(String message) {
if (ModConfigs.VERBOSE) {
Microcraft.VERBOSELOGGER.trace(message);
}
}
public static void warn( String message) {
public static void warn(String message) {
if (ModConfigs.VERBOSE) {
Microcraft.VERBOSELOGGER.warn(message);
}
}
public void debug(String message) {
if (ModConfigs.VERBOSE) {
Microcraft.VERBOSELOGGER.debug(message);
}
}
}