1.20.4 compatibility
This commit is contained in:
parent
c5132221ae
commit
27627e8404
38 changed files with 2790 additions and 31 deletions
150
remappedSrc/themixray/repeating/mod/widget/RecordListWidget.java
Normal file
150
remappedSrc/themixray/repeating/mod/widget/RecordListWidget.java
Normal file
|
@ -0,0 +1,150 @@
|
|||
package themixray.repeating.mod.widget;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.Drawable;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.Selectable;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
||||
import net.minecraft.client.gui.widget.*;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
import themixray.repeating.mod.Main;
|
||||
import themixray.repeating.mod.RecordState;
|
||||
import themixray.repeating.mod.RepeatingScreen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class RecordListWidget extends ScrollableWidget {
|
||||
private List<RecordWidget> widgets = new ArrayList<>();
|
||||
private boolean focused = false;
|
||||
|
||||
public RecordListWidget(int x, int y, int width, int height) {
|
||||
super(x,y,width,height,Text.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
||||
focused = true;
|
||||
boolean res = super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
|
||||
focused = false;
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double getDeltaYPerScroll() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderContents(DrawContext ctx, int mouseX, int mouseY, float delta) {
|
||||
int y = 0;
|
||||
for (RecordWidget wid: widgets) {
|
||||
wid.method_46419(y);
|
||||
wid.render(ctx, mouseX, (int) (mouseY + this.getScrollY()), delta);
|
||||
|
||||
y += wid.getHeight();
|
||||
y += 2;
|
||||
}
|
||||
}
|
||||
|
||||
public void addWidget(RecordState record) {
|
||||
RecordWidget widget = new RecordWidget(0, 0, width, 55, record, this);
|
||||
widget.init(null);
|
||||
widgets.add(0, widget);
|
||||
}
|
||||
|
||||
public void removeWidget(RecordState record) {
|
||||
widgets.removeIf(i -> i.getRecord().equals(record));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocused(boolean focused) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFocused() {
|
||||
return focused;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getContentsHeight() {
|
||||
return !widgets.isEmpty() ? widgets.size() * 55 + (widgets.size() - 1) * 2 : 0;
|
||||
}
|
||||
|
||||
public void init(RepeatingScreen screen) {
|
||||
for (RecordWidget widget : widgets) {
|
||||
widget.init(screen);
|
||||
}
|
||||
|
||||
screen.addDrawableChild(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendClickableNarrations(NarrationMessageBuilder builder) {
|
||||
|
||||
}
|
||||
|
||||
public RecordWidget getWidget(RecordState record) {
|
||||
for (RecordWidget widget : widgets) {
|
||||
if (widget.getRecord().equals(record)) {
|
||||
return widget;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public interface transport {
|
||||
boolean check(ClickableWidget ch);
|
||||
}
|
||||
|
||||
public boolean checkTransport(transport tr) {
|
||||
for (RecordWidget wid : widgets) {
|
||||
for (ClickableWidget child : wid.getChildren()) {
|
||||
if (tr.check(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean checkTransportNF(transport tr) {
|
||||
for (RecordWidget wid : widgets) {
|
||||
for (ClickableWidget child : wid.getChildren()) {
|
||||
boolean res = tr.check(child);
|
||||
|
||||
if (res) {
|
||||
child.setFocused(true);
|
||||
return true;
|
||||
} else {
|
||||
child.setFocused(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
return checkTransportNF((c) -> c.mouseClicked(mouseX, mouseY + this.getScrollY(), button)) || super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char chr, int modifiers) {
|
||||
return checkTransport((c) -> c.charTyped(chr, modifiers)) || super.charTyped(chr, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
return checkTransport((c) -> c.keyPressed(keyCode, scanCode, modifiers)) || super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
|
||||
return checkTransport((c) -> c.keyReleased(keyCode, scanCode, modifiers)) || super.keyReleased(keyCode, scanCode, modifiers);
|
||||
}
|
||||
}
|
196
remappedSrc/themixray/repeating/mod/widget/RecordWidget.java
Normal file
196
remappedSrc/themixray/repeating/mod/widget/RecordWidget.java
Normal file
|
@ -0,0 +1,196 @@
|
|||
package themixray.repeating.mod.widget;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.Drawable;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
||||
import net.minecraft.client.gui.widget.*;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import themixray.repeating.mod.Main;
|
||||
import themixray.repeating.mod.RecordState;
|
||||
import themixray.repeating.mod.RenderListener;
|
||||
import themixray.repeating.mod.RepeatingScreen;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class RecordWidget implements Drawable, Widget {
|
||||
private RecordState record;
|
||||
|
||||
private List<ClickableWidget> children;
|
||||
|
||||
private RecordListWidget parent;
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public RecordWidget(int x, int y, int width, int height, RecordState record, RecordListWidget parent) {
|
||||
this.parent = parent;
|
||||
this.record = record;
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this.children = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void method_46421(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
public void method_46419(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public List<ClickableWidget> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachChild(Consumer<ClickableWidget> consumer) {
|
||||
children.forEach(consumer);
|
||||
}
|
||||
|
||||
public void init(RepeatingScreen screen) {
|
||||
this.children = new ArrayList<>();
|
||||
|
||||
TextFieldWidget name_widget = new TextFieldWidget(
|
||||
Main.client.textRenderer,
|
||||
parent.getX() + getX() + 5,
|
||||
parent.getY() + getY() + 5,
|
||||
102,
|
||||
10,
|
||||
Text.empty());
|
||||
|
||||
name_widget.setText(record.getName());
|
||||
|
||||
name_widget.setChangedListener((s) -> {
|
||||
record.setName(s);
|
||||
try {
|
||||
record.save();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
children.add(name_widget);
|
||||
|
||||
ButtonWidget delete_button = ButtonWidget.builder(Text.translatable("text.repeating-mod.delete"), (i) -> {
|
||||
record.remove();
|
||||
}).dimensions(parent.getX() + getX() + 110,parent.getY() + getY() + 4, 65, 13).build();
|
||||
|
||||
children.add(delete_button);
|
||||
|
||||
ButtonWidget export_button = ButtonWidget.builder(Text.translatable("text.repeating-mod.export"), (i) -> {
|
||||
if (Desktop.isDesktopSupported()) {
|
||||
Desktop desk = Desktop.getDesktop();
|
||||
try {
|
||||
desk.browseFileDirectory(record.getFile());
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
desk.browse(record.getFile().toURI());
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).dimensions(parent.getX() + getX() + 110,parent.getY() + getY() + 4 + 14, 65, 13).build();
|
||||
|
||||
children.add(export_button);
|
||||
|
||||
ButtonWidget replay_button = ButtonWidget.builder(Text.translatable("text.repeating-mod.start"), (i) -> {
|
||||
if (Main.me.is_replaying) {
|
||||
Main.me.stopReplay();
|
||||
}
|
||||
|
||||
i.setMessage(Text.translatable("text.repeating-mod.stop"));
|
||||
Main.me.now_record = record;
|
||||
Main.me.startReplay();
|
||||
}).dimensions(parent.getX() + getX() + 110,parent.getY() + getY() + 4 + 28, 65, 13)
|
||||
.tooltip(Tooltip.of(Text.translatable("text.repeating-mod.replay_tooltip"))).build();
|
||||
|
||||
children.add(replay_button);
|
||||
}
|
||||
|
||||
public RecordState getRecord() {
|
||||
return record;
|
||||
}
|
||||
|
||||
public void drawText(int x, int y, DrawContext ctx, List<Text> lines, float size, int line_height, boolean shadow) {
|
||||
ctx.getMatrices().push();
|
||||
ctx.getMatrices().scale(size, size, size);
|
||||
|
||||
int now_y = y;
|
||||
|
||||
for (Text line : lines) {
|
||||
ctx.drawText(Main.client.textRenderer, line, (int) (x / size), (int) (now_y / size), line.getStyle().getColor().getRgb(), shadow);
|
||||
now_y += line_height;
|
||||
}
|
||||
|
||||
ctx.getMatrices().pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
|
||||
int color = record.equals(Main.me.now_record) ? 0xFF555555 : 0xFF333333;
|
||||
|
||||
ctx.fill(parent.getX() + getX(),
|
||||
parent.getY() + getY(),
|
||||
parent.getX() + getX() + getWidth(),
|
||||
parent.getY() + getY() + getHeight(),
|
||||
color);
|
||||
|
||||
drawText(
|
||||
parent.getX() + getX() + 5,
|
||||
parent.getY() + getY() + 5 + 12,
|
||||
ctx, List.of(
|
||||
Text.translatable("text.repeating-mod.recorded_at")
|
||||
.append(": ")
|
||||
.styled((s) -> s.withColor(0xbbbbbb)),
|
||||
Text.literal(RecordState.DATE_FORMAT.format(record.getDate())).styled((s) -> s.withColor(0xffffff)),
|
||||
Text.translatable("text.repeating-mod.author")
|
||||
.append(": ")
|
||||
.styled((s) -> s.withColor(0xbbbbbb)),
|
||||
Text.literal(record.getAuthor()).styled((s) -> s.withColor(0xffffff))
|
||||
), 1,
|
||||
9,
|
||||
false);
|
||||
|
||||
if (!children.isEmpty()) {
|
||||
ClickableWidget name_widget = children.get(0);
|
||||
name_widget.setPosition(parent.getX() + getX() + 5, parent.getY() + getY() + 5);
|
||||
|
||||
ClickableWidget delete_button = children.get(1);
|
||||
delete_button.setPosition(parent.getX() + getX() + 110,parent.getY() + getY() + 4);
|
||||
|
||||
ClickableWidget export_button = children.get(2);
|
||||
export_button.setPosition(parent.getX() + getX() + 110,parent.getY() + getY() + 4 + 14);
|
||||
|
||||
ClickableWidget replay_button = children.get(3);
|
||||
replay_button.setPosition(parent.getX() + getX() + 110,parent.getY() + getY() + 4 + 28);
|
||||
}
|
||||
|
||||
for (ClickableWidget child : children) {
|
||||
child.render(ctx, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue