Skip to content

Commit

Permalink
✨ Backport to 1.19.2.
Browse files Browse the repository at this point in the history
Signed-off-by: 秋雨落 <[email protected]>
  • Loading branch information
qyl27 committed Sep 24, 2023
1 parent 156d32f commit ca92540
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 142 deletions.
22 changes: 8 additions & 14 deletions common/src/main/java/cx/rain/mc/nbtedit/gui/NBTEditGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,36 +177,30 @@ private void addButtons() {
int xLoc = 18;
int yLoc = 4;

copyButton = new NBTOperatorButton(17, xLoc, yLoc, this, this::onCopyButtonClick,
componentSupplier -> componentSupplier.get().append(Component.translatable(Constants.GUI_NARRATION_BUTTON_COPY))); // Copy Button.
copyButton = new NBTOperatorButton(17, xLoc, yLoc, this, this::onCopyButtonClick, Component.translatable(Constants.GUI_NARRATION_BUTTON_COPY)); // Copy Button.
addButton(copyButton);

xLoc += 15;
cutButton = new NBTOperatorButton(16, xLoc, yLoc, this, this::onCutButtonClick,
componentSupplier -> componentSupplier.get().append(Component.translatable(Constants.GUI_NARRATION_BUTTON_CUT))); // Cut Button.
cutButton = new NBTOperatorButton(16, xLoc, yLoc, this, this::onCutButtonClick, Component.translatable(Constants.GUI_NARRATION_BUTTON_CUT)); // Cut Button.
addButton(cutButton);

xLoc += 15;
pasteButton = new NBTOperatorButton(15, xLoc, yLoc, this, this::onPasteButtonClick,
componentSupplier -> componentSupplier.get().append(Component.translatable(Constants.GUI_NARRATION_BUTTON_PASTE))); // Paste Button.
pasteButton = new NBTOperatorButton(15, xLoc, yLoc, this, this::onPasteButtonClick, Component.translatable(Constants.GUI_NARRATION_BUTTON_PASTE)); // Paste Button.
addButton(pasteButton);

xLoc += 45;
editButton = new NBTOperatorButton(13, xLoc, yLoc, this, this::onEditButtonClick,
componentSupplier -> componentSupplier.get().append(Component.translatable(Constants.GUI_NARRATION_BUTTON_EDIT))); // Edit Button.
editButton = new NBTOperatorButton(13, xLoc, yLoc, this, this::onEditButtonClick, Component.translatable(Constants.GUI_NARRATION_BUTTON_EDIT)); // Edit Button.
addButton(editButton);

xLoc += 15;
deleteButton = new NBTOperatorButton(14, xLoc, yLoc, this, this::onDeleteButtonClick,
componentSupplier -> componentSupplier.get().append(Component.translatable(Constants.GUI_NARRATION_BUTTON_DELETE))); // Delete Button.
deleteButton = new NBTOperatorButton(14, xLoc, yLoc, this, this::onDeleteButtonClick, Component.translatable(Constants.GUI_NARRATION_BUTTON_DELETE)); // Delete Button.
addButton(deleteButton);

// Add nbt type buttons.
xLoc = 18;
yLoc = 17;
for (var i = 1; i < 13; i++) {
var button = new NBTOperatorButton(i, xLoc, yLoc, this, this::onAddButtonsClick,
componentSupplier -> componentSupplier.get().append(Component.translatable(Constants.GUI_NARRATION_BUTTON_ADD)));
var button = new NBTOperatorButton(i, xLoc, yLoc, this, this::onAddButtonsClick);
addButtons[i - 1] = button;
addButton(button);
xLoc += 9;
Expand Down Expand Up @@ -434,7 +428,7 @@ private void shiftToFocus(NBTTree.Node<?> focused) {
var index = getIndexOf(focused);
if (index != -1) {
var component = nodes.get(index);
shiftY((bottom + START_Y + 1) / 2 - (component.getY() + component.getHeight()));
shiftY((bottom + START_Y + 1) / 2 - (component.y + component.getHeight()));
}
}

Expand Down Expand Up @@ -561,7 +555,7 @@ public boolean onMouseClicked(int mouseX, int mouseY, int partialTick) {
if (node.spoilerClicked(mouseX, mouseY)) { // Check hide/show children buttons
shouldUpdate = true;
if (node.shouldShowChildren()) {
heightOffset = (START_Y + 1) - (node.getY()) + heightOffset;
heightOffset = (START_Y + 1) - (node.y) + heightOffset;
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ protected void update() {
}

public boolean isMouseInsideText(int mouseX, int mouseY) {
return mouseX >= getX() && mouseY >= getY() && mouseX < width + getX() && mouseY < height + getY();
return mouseX >= x && mouseY >= y && mouseX < width + x && mouseY < height + y;
}

public boolean isMouseInsideSpoiler(int mouseX, int mouseY) {
return mouseX >= getX() - 9 && mouseY >= getY() && mouseX < getX() && mouseY < getY() + height;
return mouseX >= x - 9 && mouseY >= y && mouseX < x && mouseY < y + height;
}

public boolean shouldShowChildren() {
Expand All @@ -76,16 +76,11 @@ public boolean spoilerClicked(int mouseX, int mouseY) {
}

public void shiftY(int offsetY) {
setY(getY() + offsetY);
y += offsetY;
}

public boolean shouldRender(int top, int bottom) {
return getY() + height >= top && getY() <= bottom;
}

@Override
protected void updateWidgetNarration(NarrationElementOutput narration) {
narration.add(NarratedElementType.TITLE, text);
return y + height >= top && y <= bottom;
}

@Override
Expand All @@ -96,7 +91,7 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTic
var color = isSelected ? 0xff : isTextHover ? 16777120 : (node.hasParent()) ? 14737632 : -6250336;

if (isSelected) {
fill(poseStack, getX() + 11, getY(), getX() + width, getY() + height, Integer.MIN_VALUE);
fill(poseStack, x + 11, y, x + width, y + height, Integer.MIN_VALUE);
}

var w = 18;
Expand All @@ -118,11 +113,16 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTic

if (node.hasChild()) {
RenderSystem.setShaderTexture(0, WIDGET_TEXTURE);
blit(poseStack, getX() - 9, getY(), 9, height, u, 16, w, h, 512, 512);
blit(poseStack, x - 9, y, 9, height, u, 16, w, h, 512, 512);
}

RenderSystem.setShaderTexture(0, WIDGET_TEXTURE);
blit(poseStack, getX() + 1, getY(), 9, height, (node.getTag().getId() - 1) * 16, 0, 16, 16, 512, 512);
getMinecraft().font.draw(poseStack, text, getX() + 11, getY() + (this.height - 8) / 2, color);
blit(poseStack, x + 1, y, 9, height, (node.getTag().getId() - 1) * 16, 0, 16, 16, 512, 512);
getMinecraft().font.draw(poseStack, text, x + 11, y + (this.height - 8) / 2, color);
}

@Override
public void updateNarration(NarrationElementOutput narrationElementOutput) {
narrationElementOutput.add(NarratedElementType.TITLE, text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;

Expand All @@ -21,8 +22,12 @@ public class NBTOperatorButton extends Button {

private NBTEditGui gui;

public NBTOperatorButton(int id, int x, int y, NBTEditGui parent, OnPress onPressed, CreateNarration createNarration) {
super(x, y, 9, 9, Component.literal(NBTHelper.getNameByButton((byte) id)), onPressed, createNarration);
public NBTOperatorButton(int id, int x, int y, NBTEditGui parent, OnPress onPressed) {
this(id, x, y, parent, onPressed, Component.literal(NBTHelper.getNameByButton((byte) id)));
}

public NBTOperatorButton(int id, int x, int y, NBTEditGui parent, OnPress onPressed, Component title) {
super(x, y, 9, 9, title, onPressed);

buttonId = id;
gui = parent;
Expand All @@ -33,7 +38,7 @@ protected Minecraft getMinecraft() {
}

public boolean isMouseInside(int mouseX, int mouseY) {
return isActive() && mouseX >= getX() && mouseY >= getY() && mouseX < getX() + width && mouseY < getY() + height;
return isActive() && mouseX >= x && mouseY >= y && mouseX < x + width && mouseY < y + height;
}

public byte getButtonId() {
Expand All @@ -43,7 +48,7 @@ public byte getButtonId() {
@Override
public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) {
if (isMouseInside(mouseX, mouseY)) { // checks if the mouse is over the button
fill(poseStack, getX(), getY(), getX() + width, getY() + height, 0x80ffffff); // draw a grayish background
fill(poseStack, x, y, x + width, y + height, 0x80ffffff); // draw a grayish background
if (hoverTime == -1) {
hoverTime = System.currentTimeMillis();
}
Expand All @@ -53,7 +58,7 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTic

if (isActive()) {
RenderSystem.setShaderTexture(0, BUTTONS_TEXTURE);
blit(poseStack, getX(), getY(), width, height, (buttonId - 1) * 16, 0, 16, 16, 512, 512); //Draw the texture
blit(poseStack, x, y, width, height, (buttonId - 1) * 16, 0, 16, 16, 512, 512); //Draw the texture
}

if (hoverTime != -1 && System.currentTimeMillis() - hoverTime > 300) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import cx.rain.mc.nbtedit.NBTEdit;
import cx.rain.mc.nbtedit.gui.NBTEditGui;
import cx.rain.mc.nbtedit.gui.component.IWidgetHolder;
import cx.rain.mc.nbtedit.gui.component.button.SpecialCharacterButton;
import cx.rain.mc.nbtedit.nbt.NBTTree;
import cx.rain.mc.nbtedit.utility.Constants;
import cx.rain.mc.nbtedit.nbt.NBTHelper;
Expand Down Expand Up @@ -43,9 +42,6 @@ public class EditValueSubWindow extends SubWindowComponent implements IWidgetHol
protected Button saveButton;
protected Button cancelButton;

protected SpecialCharacterButton colorButton;
protected SpecialCharacterButton newLineButton;

protected String nameError;
protected String valueError;

Expand All @@ -61,18 +57,18 @@ public EditValueSubWindow(NBTEditGui parent, NBTTree.Node<?> nodeIn,
}

public void init(int xLoc, int yLoc) {
setX(getX() + xLoc);
setY(getY() + yLoc);
x += xLoc;
y += yLoc;

// Todo: newline and color button.

String name = (nameField == null) ? node.getName() : nameField.getValue();
String value = (valueField == null) ? getValue(nbt) : valueField.getValue();

nameField = new EditBox(getMinecraft().font, getX() + 46, getY() + 18, 116, 15, Component.literal("Name"));
nameField = new EditBox(getMinecraft().font, x + 46, y + 18, 116, 15, Component.literal("Name"));
addWidget(nameField);

valueField = new EditBox(getMinecraft().font, getX() + 46, getY() + 44, 116, 15, Component.literal("Value"));
valueField = new EditBox(getMinecraft().font, x + 46, y + 44, 116, 15, Component.literal("Value"));
addWidget(valueField);

nameField.setValue(name);
Expand All @@ -94,29 +90,23 @@ public void init(int xLoc, int yLoc) {

// Todo: newline and color button.

saveButton = Button.builder(Component.translatable(Constants.GUI_BUTTON_SAVE), this::onSaveButtonClicked)
.pos(getX() + 9, getY() + 62)
.size(75, 20)
.build();
saveButton = new Button(x + 9, y + 62, 75, 20, Component.translatable(Constants.GUI_BUTTON_SAVE), this::onSaveButtonClicked);
addWidget(saveButton);

cancelButton = Button.builder(Component.translatable(Constants.GUI_BUTTON_CANCEL), this::onCancelButtonClicked)
.pos(getX() + 93, getY() + 62)
.size(75, 20)
.build();
cancelButton = new Button(x + 93, y + 62, 75, 20, Component.translatable(Constants.GUI_BUTTON_CANCEL), this::onCancelButtonClicked);
addWidget(cancelButton);
}

protected void onSaveButtonClicked(Button button) {
nameField.mouseClicked(button.getX(), button.getY(), 0);
valueField.mouseClicked(button.getX(), button.getY(), 0);
nameField.mouseClicked(button.x, button.y, 0);
valueField.mouseClicked(button.x, button.y, 0);
save();
quit();
}

protected void onCancelButtonClicked(Button button) {
nameField.mouseClicked(button.getX(), button.getY(), 0);
valueField.mouseClicked(button.getX(), button.getY(), 0);
nameField.mouseClicked(button.x, button.y, 0);
valueField.mouseClicked(button.x, button.y, 0);
quit();
}

Expand Down Expand Up @@ -149,23 +139,23 @@ protected Minecraft getMinecraft() {
@Override
public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) {
RenderSystem.setShaderTexture(0, WINDOW_TEXTURE);
blit(poseStack, getX(), getY(), 0, 0, width, height);
blit(poseStack, x, y, 0, 0, width, height);

if (!canEditName) {
fill(poseStack, getX() + 42, getY() + 15, getX() + 169, getY() + 31, 0x80000000);
fill(poseStack, x + 42, y + 15, x + 169, y + 31, 0x80000000);
}

if (!canEditValue) {
fill(poseStack, getX() + 42, getY() + 41, getX() + 169, getY() + 57, 0x80000000);
fill(poseStack, x + 42, y + 41, x + 169, y + 57, 0x80000000);
}

renderWidgets(poseStack, mouseX, mouseY, partialTick);

if (nameError != null) {
getMinecraft().font.draw(poseStack, nameError, getX() + width / 2, getY() + 4, 0xFF0000);
getMinecraft().font.draw(poseStack, nameError, x + width / 2, y + 4, 0xFF0000);
}
if (valueError != null) {
getMinecraft().font.draw(poseStack, nameError, getX() + width / 2, getY() + 32, 0xFF0000);
getMinecraft().font.draw(poseStack, nameError, x + width / 2, y + 32, 0xFF0000);
}

// Todo: newline and color button.
Expand Down Expand Up @@ -216,11 +206,6 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
return false;
}

@Override
public void updateWidgetNarration(NarrationElementOutput narration) {
narration.add(NarratedElementType.HINT, Component.translatable(Constants.GUI_NARRATION_SUB_WINDOW_VALUE_EDITOR));
}

private void isValidInput() {
boolean isValid = true;
nameError = null;
Expand Down Expand Up @@ -371,4 +356,9 @@ public void addWidget(AbstractWidget widget) {
public void clearWidgets() {
widgets.clear();
}

@Override
public void updateNarration(NarrationElementOutput narrationElementOutput) {
narrationElementOutput.add(NarratedElementType.HINT, Component.translatable(Constants.GUI_NARRATION_SUB_WINDOW_VALUE_EDITOR));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public void inactive() {
protected void onDrag(double startX, double startY, double dragX, double dragY) {
super.onDrag(startX, startY, dragX, dragY);

setX(getX() + (int) (startX + dragX));
setY(getY() + (int) (startY + dragY));
x += (int) (startX + dragX);
y += (int) (startY + dragY);
}

public void tick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,9 @@ protected void init() {

gui.init(width, height, height - 35);

addRenderableWidget(Button.builder(Component.translatable(Constants.GUI_BUTTON_SAVE), this::onSaveClicked)
.pos(width / 4 - 100, height - 27)
.size(200, 20)
.build());

addRenderableWidget(Button.builder(Component.translatable(Constants.GUI_BUTTON_QUIT), this::onQuitClicked)
.pos(width * 3 / 4 - 100, height - 27)
.size(200, 20)
.build());
addRenderableWidget(new Button(width / 4 - 100, height - 27, 200, 20, Component.translatable(Constants.GUI_BUTTON_SAVE), this::onSaveClicked));

addRenderableWidget(new Button(width * 3 / 4 - 100, height - 27, 200, 20, Component.translatable(Constants.GUI_BUTTON_QUIT), this::onQuitClicked));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ public class DataGen {
@SubscribeEvent
public static void onGatherData(GatherDataEvent event) {
DataGenerator generator = event.getGenerator();
var exHelper = event.getExistingFileHelper();
var packOutput = generator.getPackOutput();

if (event.includeClient()) {
}

if (event.includeServer()) {
generator.addProvider(true, new LanguageProviderENUS(packOutput));
generator.addProvider(true, new LanguageProviderZHCN(packOutput));
generator.addProvider(true, new LanguageProviderENUS(generator));
generator.addProvider(true, new LanguageProviderZHCN(generator));
}
}
}
Loading

0 comments on commit ca92540

Please sign in to comment.