Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes some ui stuff #349

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package tools.redstone.redstonetools.macros.gui.screen;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ConfirmScreen;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.util.math.MathHelper;
import tools.redstone.redstonetools.macros.Macro;
import tools.redstone.redstonetools.macros.MacroManager;
import tools.redstone.redstonetools.macros.actions.Action;
import tools.redstone.redstonetools.macros.actions.CommandAction;
import tools.redstone.redstonetools.macros.gui.widget.commandlist.CommandEntry;
import tools.redstone.redstonetools.macros.gui.widget.commandlist.CommandListWidget;
import tools.redstone.redstonetools.macros.gui.widget.macrolist.MacroListWidget;
import net.minecraft.client.MinecraftClient;
Expand All @@ -19,7 +17,6 @@
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.InputUtil.Key;
import net.minecraft.client.util.InputUtil.Type;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand Down Expand Up @@ -102,7 +99,7 @@ public void init() {
this.addDrawableChild(keyBindButton);

int widgetWidth = 339;
List<CommandEntry> entries = null;
List<CommandListWidget.CommandEntry> entries = null;
double scrollAmount = 0;
if (commandList != null) {
entries = commandList.children();
Expand All @@ -115,7 +112,7 @@ public void init() {

if (entries != null) {
commandList.children().clear();
for (CommandEntry entry : entries) {
for (CommandListWidget.CommandEntry entry : entries) {
entry.setOwner(commandList);
commandList.children().add(entry);
}
Expand All @@ -136,20 +133,20 @@ private boolean canClickDone() {
}

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
if (overlapped) {
mouseX = -1;
mouseY = -1;
}

this.renderBackgroundTexture(0);
commandList.render(matrices, mouseX, mouseY, delta);
super.render(matrices, mouseX, mouseY, delta);
commandList.render(context, mouseX, mouseY, delta);
super.render(context, mouseX, mouseY, delta);

drawCenteredTextWithShadow(matrices, this.textRenderer, this.title, this.width / 2, 8, 16777215);
drawCenteredTextWithShadow(context, this.textRenderer, this.title, this.width / 2, 8, 16777215);

drawCenteredTextWithShadow(matrices, this.textRenderer, "Key Bind", width / 2 - (99 - textRenderer.getWidth("Key Bind") / 2), 55 + textRenderer.fontHeight / 2, 16777215);
nameField.render(matrices, mouseX, mouseY, delta);
drawCenteredTextWithShadow(context, this.textRenderer, "Key Bind", width / 2 - (99 - textRenderer.getWidth("Key Bind") / 2), 55 + textRenderer.fontHeight / 2, 16777215);
nameField.render(context, mouseX, mouseY, delta);

if (nameField.getText().isEmpty() && !nameField.isFocused()) {
nameField.setSuggestion("Name");
Expand Down Expand Up @@ -244,7 +241,7 @@ private boolean updateKeybinding(Key key) {
detectingKeycodeKey = false;
Text text = key.getLocalizedText();
if (key == InputUtil.UNKNOWN_KEY) text = Text.of("");
if ( KeyBindingUtils.isKeyAlreadyBound(key) ) { text = new LiteralText(text.getString()).formatted(Formatting.RED); }
if ( KeyBindingUtils.isKeyAlreadyBound(key) ) { text = Text.literal(text.getString()).formatted(Formatting.RED); }

keyBindButton.setMessage(text);
macro.setKey(key);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package tools.redstone.redstonetools.macros.gui.widget.commandlist;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.gui.DrawContext;
import tools.redstone.redstonetools.macros.gui.widget.commandlist.CommandListWidget.CommandEntry;

public class CommandEntryPlaceHolder extends CommandEntry{
public class CommandEntryPlaceHolder extends CommandEntry {
public CommandEntryPlaceHolder(MinecraftClient client, CommandListWidget owner, String text) {
super(client, owner, text);
super.deleteButton.visible = false;
}

@Override
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
command.setSuggestion("Add new command");
if (!super.command.getText().isEmpty()) {
super.owner.addCommandFromPlaceHolder(command.getText(),this);
command.setText("");
}

super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, hovered, tickDelta);
super.render(context, index, y, x, entryWidth, entryHeight, mouseX, mouseY, hovered, tickDelta);
}

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package tools.redstone.redstonetools.macros.gui.widget.commandlist;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.text.Text;
import tools.redstone.redstonetools.macros.gui.MacroCommandSuggestor;
import tools.redstone.redstonetools.macros.gui.screen.MacroEditScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.widget.EntryListWidget;
import tools.redstone.redstonetools.macros.gui.widget.IconButtonWidget;

import java.util.ArrayList;
import java.util.List;

public class CommandListWidget extends EntryListWidget<CommandEntry> {
public class CommandListWidget extends EntryListWidget<CommandListWidget.CommandEntry> {

private final MacroEditScreen parent;

public CommandListWidget(MinecraftClient client, MacroEditScreen parent, int width, int height, int top, int bottom, int itemHeight) {
super(client, width, height, top, bottom, itemHeight);
public CommandListWidget(MinecraftClient client, MacroEditScreen parent, int width, int height, int y, int itemHeight) {
super(client, width, height, y, itemHeight);
this.parent = parent;
addEntry(new CommandEntryPlaceHolder(client,this,""));
}
Expand All @@ -27,7 +33,7 @@ public void tick() {


public CommandEntry addCommand(String command) {
CommandEntry entry = new CommandEntry(client,this,command);
CommandEntry entry = new CommandEntry(client, this, command);
List<CommandEntry> entries = children();

entries.add(entries.size()-1,entry);
Expand All @@ -39,8 +45,8 @@ protected void addCommandFromPlaceHolder(String command,CommandEntryPlaceHolder
CommandEntry entry = addCommand(command);
placeHolder.setFocused(false);

entry.command.x = placeHolder.command.x;
entry.command.y = placeHolder.command.y;
entry.command.setX(placeHolder.command.getX());
entry.command.setY(placeHolder.command.getY());
entry.setFocused(true);
}

Expand Down Expand Up @@ -123,5 +129,108 @@ public int getWidth() {
}

@Override
public void appendNarrations(NarrationMessageBuilder builder) {}
protected void appendClickableNarrations(NarrationMessageBuilder builder) {

}

public static class CommandEntry extends EntryListWidget.Entry<CommandEntry> {

protected CommandListWidget owner;

public final TextFieldWidget command;
protected final ButtonWidget deleteButton;


public CommandEntry(MinecraftClient client, CommandListWidget owner, String text) {
this.owner = owner;

command = new TextFieldWidget(client.textRenderer, 0, 0, 300, 20, Text.of(""));
command.setMaxLength(255);
command.setText(text);

deleteButton = new IconButtonWidget(IconButtonWidget.CROSS_ICON,0, 0, 20, 20, Text.of(""), (button) -> {
this.owner.removeCommand(this);
});

MacroCommandSuggestor commandMacroCommandSuggestor = new MacroCommandSuggestor(client, owner.getParent(), command,client.textRenderer,true,false, 0,0,0);
commandMacroCommandSuggestor.setWindowActive(false);
commandMacroCommandSuggestor.refresh();
commandMacroCommandSuggestor.close();
}


@Override
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
command.setX(owner.getParent().width / 2 - owner.getWidth() / 2 + 5);
command.setY(y);
command.render(context,mouseX,mouseY,tickDelta);


deleteButton.setX(command.getX() + command.getWidth() + 5);
deleteButton.setY(y);
deleteButton.render(context,mouseX,mouseY,tickDelta);

if (edit) {
edit = false;
owner.getParent().editCommandField(command);
}
}

public void tick() {
command.tick();
}
private boolean edit = false;

public void setFocused(boolean focused){
command.setFocused(focused);
if (focused){
owner.centerScrollOn(this);
edit = true;
}
owner.focusOn(this);
}

protected String getText() {
return command.getText();
}

public void setOwner(CommandListWidget owner) {
this.owner = owner;
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (command.mouseClicked(mouseX,mouseY,button)) {
owner.centerScrollOn(this);
edit = true;
return true;
}
deleteButton.mouseClicked(mouseX,mouseY,button);

return super.mouseClicked(mouseX, mouseY, button);
}

@Override
public boolean charTyped(char chr, int modifiers) {
if (command.isFocused()) return command.charTyped(chr,modifiers);

return super.charTyped(chr, modifiers);
}

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (command.isFocused()) {
return command.keyPressed(keyCode, scanCode, modifiers);
}

return super.keyPressed(keyCode, scanCode, modifiers);
}

@Override
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
if (command.isFocused()) return command.keyReleased(keyCode, scanCode, modifiers);

return super.keyReleased(keyCode, scanCode, modifiers);
}
}
}
Loading