Added GUI screens and did some cleanup

This commit is contained in:
Jonas_Jones 2022-06-24 20:31:00 +02:00
parent 2b803f7608
commit 36f0eeb701
32 changed files with 288 additions and 12 deletions

Binary file not shown.

View file

@ -6,7 +6,8 @@
"mixins": [
],
"client": [
"ArduinoMixin"
"ArduinoMixin",
"GameMenuScreenMixin"
],
"injectors": {
"defaultRequire": 1

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 566 B

View file

Before

Width:  |  Height:  |  Size: 453 B

After

Width:  |  Height:  |  Size: 453 B

Before After
Before After

View file

@ -21,7 +21,16 @@ public class ArduinoControls implements ModInitializer {
try {
LedBlink.initialisation();
} catch (InterruptedException e) {
throw new RuntimeException(e);
LOGGER.info("Failed to make Arduino LED blink. ARDUINO NOT CONNECTED!");
}
}
}
/*
//TODO:
- Full control over all programmable pins of all known raspberry pi's
- system to flash program onto arduino with ingame editor
- scratch system that allows for multiple event triggering when something happens
- cry because mojang UI system sucks ass
- make own library that allows for easy UI implementation
*/

View file

@ -0,0 +1,40 @@
package me.jonasjones.arduinoctrls.gui;
import me.jonasjones.arduinoctrls.gui.screens.ModSettings;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
import net.minecraft.client.util.math.MatrixStack;
@Environment(EnvType.CLIENT)
public class GuiHome extends Screen {
private final Screen parent;
public GuiHome (Screen parent) {
super(Text.of("MicrocontrollerMC Controls"));
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.client.setScreen(new SelectDevice(this));
}));
this.addDrawableChild(new ButtonWidget(this.width / 2 + 5, this.height / 6 + 12, 150, 20, Text.of("Settings"), (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.client.setScreen(this.parent);
}));
}
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackground(matrices);
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 16777215);
super.render(matrices, mouseX, mouseY, delta);
}
}

View file

@ -0,0 +1,127 @@
package me.jonasjones.arduinoctrls.gui;
import com.mojang.logging.LogUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.world.CreateWorldScreen;
import net.minecraft.client.gui.screen.world.SelectWorldScreen;
import net.minecraft.client.gui.screen.world.WorldListWidget;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import java.util.List;
import java.util.function.Supplier;
@Environment(EnvType.CLIENT)
public class SelectDevice extends Screen {
private static final Logger LOGGER = LogUtils.getLogger();
protected final Screen parent;
@Nullable
private List<OrderedText> tooltip;
private ButtonWidget deleteButton;
private ButtonWidget selectButton;
private ButtonWidget editButton;
private ButtonWidget recreateButton;
protected TextFieldWidget searchBox;
private WorldListWidget levelList;
public SelectDevice(Screen parent) {
super(Text.translatable("selectWorld.title"));
this.parent = parent;
}
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
return super.mouseScrolled(mouseX, mouseY, amount);
}
public void tick() {
this.searchBox.tick();
}
protected void init() {
this.client.keyboard.setRepeatEvents(true);
this.searchBox = new TextFieldWidget(this.textRenderer, this.width / 2 - 100, 22, 200, 20, this.searchBox, Text.translatable("selectWorld.search"));
this.searchBox.setChangedListener((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.addSelectableChild(this.searchBox);
this.addSelectableChild(this.levelList);
this.selectButton = (ButtonWidget)this.addDrawableChild(new ButtonWidget(this.width / 2 - 154, this.height - 52, 150, 20, Text.translatable("selectWorld.select"), (button) -> {
this.levelList.getSelectedAsOptional().ifPresent(WorldListWidget.WorldEntry::play);
}));
this.addDrawableChild(new ButtonWidget(this.width / 2 + 4, this.height - 52, 150, 20, Text.translatable("selectWorld.create"), (button) -> {
CreateWorldScreen.create(this.client, this);
}));
this.editButton = (ButtonWidget)this.addDrawableChild(new ButtonWidget(this.width / 2 - 154, this.height - 28, 72, 20, Text.translatable("selectWorld.edit"), (button) -> {
this.levelList.getSelectedAsOptional().ifPresent(WorldListWidget.WorldEntry::edit);
}));
this.deleteButton = (ButtonWidget)this.addDrawableChild(new ButtonWidget(this.width / 2 - 76, this.height - 28, 72, 20, Text.translatable("selectWorld.delete"), (button) -> {
this.levelList.getSelectedAsOptional().ifPresent(WorldListWidget.WorldEntry::deleteIfConfirmed);
}));
this.recreateButton = (ButtonWidget)this.addDrawableChild(new ButtonWidget(this.width / 2 + 4, this.height - 28, 72, 20, Text.translatable("selectWorld.recreate"), (button) -> {
this.levelList.getSelectedAsOptional().ifPresent(WorldListWidget.WorldEntry::recreate);
}));
this.addDrawableChild(new ButtonWidget(this.width / 2 + 82, this.height - 28, 72, 20, ScreenTexts.CANCEL, (button) -> {
this.client.setScreen(this.parent);
}));
this.worldSelected(false);
this.setInitialFocus(this.searchBox);
}
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return super.keyPressed(keyCode, scanCode, modifiers) ? true : this.searchBox.keyPressed(keyCode, scanCode, modifiers);
}
public void close() {
this.client.setScreen(this.parent);
}
public boolean charTyped(char chr, int modifiers) {
return this.searchBox.charTyped(chr, modifiers);
}
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.tooltip = null;
this.levelList.render(matrices, mouseX, mouseY, delta);
this.searchBox.render(matrices, mouseX, mouseY, delta);
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 8, 16777215);
super.render(matrices, mouseX, mouseY, delta);
if (this.tooltip != null) {
this.renderOrderedTooltip(matrices, this.tooltip, mouseX, mouseY);
}
}
public void setTooltip(List<OrderedText> tooltip) {
this.tooltip = tooltip;
}
public void worldSelected(boolean active) {
this.selectButton.active = active;
this.deleteButton.active = active;
this.editButton.active = active;
this.recreateButton.active = active;
}
public void removed() {
if (this.levelList != null) {
this.levelList.children().forEach(WorldListWidget.Entry::close);
}
}
public Supplier<String> getSearchFilter() {
return () -> {
return this.searchBox.getText();
};
}
}

View file

@ -0,0 +1,4 @@
package me.jonasjones.arduinoctrls.gui.boards;
public class ArduinoNano {
}

View file

@ -0,0 +1,4 @@
package me.jonasjones.arduinoctrls.gui.boards;
public class ArduinoProMini {
}

View file

@ -0,0 +1,4 @@
package me.jonasjones.arduinoctrls.gui.boards;
public class ArduinoUno {
}

View file

@ -0,0 +1,39 @@
package me.jonasjones.arduinoctrls.gui.screens;
import me.jonasjones.arduinoctrls.gui.SelectDevice;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.SoundOptionsScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
@Environment(EnvType.CLIENT)
public class ModSettings extends Screen {
private final Screen parent;
public ModSettings (Screen parent) {
super(Text.of("MicrocontrollerMC Controls"));
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.client.setScreen(new SelectDevice(this));
}));
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, ScreenTexts.DONE, (button) -> {
this.client.setScreen(this.parent);
}));
}
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackground(matrices);
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 16777215);
super.render(matrices, mouseX, mouseY, delta);
}
}

View file

@ -0,0 +1,7 @@
package me.jonasjones.arduinoctrls.gui.screens;
import java.awt.*;
public class ObjectSelectionList {
public static void display(int x, int y, int width, int height, List objects) {}
}

View file

@ -1,10 +1,13 @@
package me.jonasjones.arduinoctrls.mixin;
import me.jonasjones.arduinoctrls.ArduinoControls;
import me.jonasjones.arduinoctrls.gui.GuiHome;
import me.jonasjones.arduinoctrls.gui.SelectDevice;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -16,15 +19,17 @@ public abstract class ArduinoMixin extends Screen {
super(title);
}
@Inject(at = @At("HEAD"), method = "init()V")
private void init(CallbackInfo info) {
ArduinoControls.LOGGER.info("This line is printed by an example mod mixin!");
}
@Inject(at = @At("RETURN"), method = "initWidgetsNormal")
private void ledToggleButton(int y, int spacingY, CallbackInfo ci) {
this.addDrawableChild(new ButtonWidget(50, 50, 20, 20,Text.of("LED"), (button) -> {
this.client.scheduleStop();
private void titleScreenButton(int y, int spacingY, CallbackInfo ci) {
final Identifier ICON_TEXTURE = new Identifier("arduinoctrls", "gui/button_icon.png");
int buttonX = this.width / 2 + 104;
int buttonY = y + spacingY * 2;
this.addDrawableChild(new ButtonWidget(buttonX, buttonY, 20, 20, Text.of(""), (button) -> {
this.client.setScreen(new GuiHome(this));
}));
this.addDrawableChild( new TexturedButtonWidget(buttonX, buttonY, 20, 20, 0, 0, 0, ICON_TEXTURE, 20, 20, (buttonWidget) -> this.client.setScreen(new GuiHome(this))));
}
}

View file

@ -0,0 +1,35 @@
package me.jonasjones.arduinoctrls.mixin;
import me.jonasjones.arduinoctrls.gui.GuiHome;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GameMenuScreen.class)
public class GameMenuScreenMixin extends Screen {
final Identifier ICON_TEXTURE = new Identifier("arduinoctrls", "logo_16x9.png");
protected GameMenuScreenMixin(Text title) {super(title);}
@Inject(at = @At("HEAD"),method = "initWidgets")
private void gameMenuScreenButton(CallbackInfo ci) {
final Identifier ICON_TEXTURE = new Identifier("arduinoctrls", "gui/button_icon.png");
int buttonX = this.width / 2 + 108;
int buttonY = this.height / 4 + 8;
this.addDrawableChild(new ButtonWidget(buttonX, buttonY, 20, 20, Text.of(""), (button) -> {
this.client.setScreen(new GuiHome(this));
}));
this.addDrawableChild( new TexturedButtonWidget(buttonX, buttonY, 20, 20, 0, 0, 0, ICON_TEXTURE, 20, 20, (buttonWidget) -> this.client.setScreen(new GuiHome(this))));
}
}

View file

@ -6,7 +6,8 @@
"mixins": [
],
"client": [
"ArduinoMixin"
"ArduinoMixin",
"GameMenuScreenMixin"
],
"injectors": {
"defaultRequire": 1

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 566 B

View file

Before

Width:  |  Height:  |  Size: 453 B

After

Width:  |  Height:  |  Size: 453 B

Before After
Before After