Skip to content

Commit

Permalink
Merge pull request #362 from MiranCZ/rewrite
Browse files Browse the repository at this point in the history
Ported macro GUI
  • Loading branch information
MiranCZ authored Jan 26, 2024
2 parents ecc4e85 + 5379733 commit 09f0109
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@ public CommandEditScreen(Screen parent, GameOptions gameOptions, TextFieldWidget
commandMacroCommandSuggestor.refresh();
}

@Override
public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
}

public void render(DrawContext context, int mouseX, int mouseY, float delta) {
parent.render(context, mouseX, mouseY, delta);
context.getMatrices().translate(0,0,0.03F);

//this.fillGradient(context, 0, 0, this.width, this.height, -1072689136, -804253680);
context.fillGradient( 0, 0, this.width, this.height, -1072689136, -804253680);

commandField.render(context, mouseX, mouseY, delta);

commandMacroCommandSuggestor.render(context, mouseX, mouseY);
commandMacroCommandSuggestor.tryRenderWindow(context,mouseX,mouseY);

if (changed) {
commandMacroCommandSuggestor.refresh();
changed = false;
Expand All @@ -45,11 +52,6 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {

}

@Override
public void tick() {
super.tick();
}

@Override
public void resize(MinecraftClient client, int width, int height) {
parent.resize(client,width,height);
Expand Down Expand Up @@ -78,8 +80,8 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
return super.mouseClicked(mouseX, mouseY, button);
}

public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
return commandMacroCommandSuggestor.mouseScrolled(amount);
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
return commandMacroCommandSuggestor.mouseScrolled(verticalAmount);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public void init() {
scrollAmount = commandList.getScrollAmount();
}

commandList = new CommandListWidget(client, this, widgetWidth, height, 85, 24);
//commandList.setLeftPos(width / 2 - widgetWidth / 2);
commandList = new CommandListWidget(client, this, widgetWidth, this.height / 4 + 144 + 5 - 10-85, 85, 24);
commandList.setX(width / 2 - widgetWidth / 2);


if (entries != null) {
Expand All @@ -128,6 +128,10 @@ public void init() {
this.addSelectableChild(commandList);
}

@Override
public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
}

private boolean canClickDone() {
return !nameField.getText().trim().isEmpty() && macroListWidget.canAdd(macro);
}
Expand Down Expand Up @@ -155,14 +159,6 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
}
}

@Override
public void tick() {
//nameField.tick();
//commandList.tick();

super.tick();
}

@Override
public void resize(MinecraftClient client, int width, int height) {
super.resize(client, width, height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {

context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 8, 16777215);
super.render(context, mouseX, mouseY, delta);

}

public void openEditScreen(MacroEntry entry) {
client.setScreen(new MacroEditScreen(this,gameOptions,Text.of("Edit Macro"), macroList, entry.macro));
}

@Override
public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ public IconButtonWidget(Identifier texture ,int x, int y, int width, int height,
this.texture = texture;
}

public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) {
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
super.renderWidget(context, mouseX, mouseY, delta);


RenderSystem.setShaderTexture(0, texture);
RenderSystem.enableDepthTest();

RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
context.drawGuiTexture(this.texture,this.getX(), this.getY(), 0,0, 20, this.height, 20, 20);
context.drawTexture(this.texture,this.getX(), this.getY(), 0,0, 20, this.height, 20, 20);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;
import tools.redstone.redstonetools.macros.gui.MacroCommandSuggestor;
import tools.redstone.redstonetools.macros.gui.screen.MacroEditScreen;
import net.minecraft.client.MinecraftClient;
Expand All @@ -24,13 +25,11 @@ public CommandListWidget(MinecraftClient client, MacroEditScreen parent, int wid
addEntry(new CommandEntryPlaceHolder(client,this,""));
}

// public void tick() {
// for (CommandEntry entry : children()) {
// entry.tick();
// }
// }


@Override
public void setSelected(@Nullable CommandListWidget.CommandEntry entry) {
}

public CommandEntry addCommand(String command) {
CommandEntry entry = new CommandEntry(client, this, command);
Expand Down Expand Up @@ -148,10 +147,9 @@ public CommandEntry(MinecraftClient client, CommandListWidget owner, String text
command.setMaxLength(255);
command.setText(text);


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

MacroCommandSuggestor commandMacroCommandSuggestor = new MacroCommandSuggestor(client, owner.getParent(), command,client.textRenderer,true,false, 0,0,0);
commandMacroCommandSuggestor.setWindowActive(false);
Expand All @@ -177,9 +175,6 @@ public void render(DrawContext context, int index, int y, int x, int entryWidth,
}
}

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

public void setFocused(boolean focused){
Expand All @@ -188,7 +183,6 @@ public void setFocused(boolean focused){
owner.centerScrollOn(this);
edit = true;
}
owner.focusOn(this);
}

protected String getText() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tools.redstone.redstonetools.macros.gui.widget.macrolist;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ConfirmScreen;
import net.minecraft.client.gui.widget.*;
Expand All @@ -23,14 +24,18 @@ public MacroEntry(Macro macro, MacroListWidget owner) {
this.macro = macro;
this.owner = owner;

buttonWidget = CheckboxWidget.builder(null, null).build();
buttonWidget.setDimensionsAndPosition(20,20,0,0);
deleteButton = IconButtonWidget.builder(Text.of(""), (button) -> {
buttonWidget = CheckboxWidget.builder(Text.empty(), MinecraftClient.getInstance().textRenderer).build();

if (buttonWidget.isChecked() != macro.enabled) {
buttonWidget.onPress();
}

deleteButton = new IconButtonWidget(IconButtonWidget.CROSS_ICON,0, 0, 20, 20 ,Text.of(""), (button) -> {
deleteIfConfirmed();
}).dimensions(0, 0, 20, 20).build();
editButton = IconButtonWidget.builder(Text.of(""), (button) -> {
},null);
editButton = new IconButtonWidget(IconButtonWidget.PENCIL_ICON,0, 0, 20, 20, Text.of(""), (button) -> {
owner.parent.openEditScreen(this);
}).dimensions(0, 0, 20, 20).build();
},null);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tools.redstone.redstonetools.macros.gui.widget.macrolist;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget;
import tools.redstone.redstonetools.macros.Macro;
import tools.redstone.redstonetools.macros.MacroManager;
Expand All @@ -19,6 +18,8 @@ public class MacroListWidget extends AlwaysSelectedEntryListWidget<MacroEntry> {

public MacroListWidget(MacroSelectScreen parent, MinecraftClient client) {
super(client, parent.width, parent.height, 20, 20);
setHeight(parent.height - 62);

this.parent = parent;
this.client = client;

Expand Down Expand Up @@ -48,9 +49,6 @@ protected int getScrollbarPositionX() {
}


protected void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
parent.renderBackground(context, mouseX, mouseY, delta);
}

public boolean isFocused() {
return parent.getFocused() == this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package tools.redstone.redstonetools.mixin.macros;

import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.ControlsOptionsScreen;
import net.minecraft.client.gui.screen.option.GameOptionsScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.option.GameOptions;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import tools.redstone.redstonetools.macros.gui.screen.MacroSelectScreen;

Expand All @@ -22,7 +26,21 @@ public AddMacroButtonMixin(Screen parent, GameOptions gameOptions, Text title) {
public void init(CallbackInfo ci) {
ButtonWidget buttonWidget = ButtonWidget.builder(Text.of("Macros..."), (button) -> {
this.client.setScreen(new MacroSelectScreen(this,super.gameOptions,Text.of("Macros")));
}).dimensions(this.width / 2 + 5, this.height / 6 + 36, 150, 20).build();
}).dimensions(this.width / 2 - 155, this.height / 6 + 36+24, 150, 20).build();
this.addDrawableChild(buttonWidget);

moveDoneButton();
}


//TODO refactor this into mixin instead
@Unique
private void moveDoneButton() {
for (Element e : this.children()) {
if (!(e instanceof ButtonWidget button)) continue;
if (((ButtonWidget) e).getMessage() == ScreenTexts.DONE) {
button.setY(button.getY()+24);
}
}
}
}
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 09f0109

Please sign in to comment.