1 package com.irtimaled.bbor.client.gui;
3 import com.irtimaled.bbor.Versions;
4 import com.irtimaled.bbor.client.interop.ClientInterop;
5 import com.mojang.blaze3d.systems.RenderSystem;
6 import net.minecraft.client.gui.Element;
7 import net.minecraft.client.gui.screen.Screen;
8 import net.minecraft.client.gui.widget.ButtonWidget;
9 import net.minecraft.client.util.math.MatrixStack;
10 import net.minecraft.text.LiteralTextContent;
11 import net.minecraft.text.MutableText;
12 import net.minecraft.text.TranslatableTextContent;
14 import java.util.List;
16 public abstract class ListScreen extends Screen {
17 private final Screen lastScreen;
18 private static final String version = Versions.build;
20 private ButtonWidget doneButton;
21 private ControlList controlList;
22 private SearchField searchField;
24 ListScreen(Screen lastScreen) {
25 super(MutableText.of(new LiteralTextContent("Bounding Box Outline Reloaded")));
26 this.lastScreen = lastScreen;
33 protected void onDoneClicked() {
34 ClientInterop.displayScreen(lastScreen);
38 protected void init() {
39 this.controlList = this.buildList(48, this.height - 28);
40 this.searchField = new SearchField(this.textRenderer, this.width / 2 - 100, 22, 200, 20, this.controlList);
41 this.doneButton = new ButtonWidget(this.width / 2 - 100, this.height - 24, 200, 20, MutableText.of(new TranslatableTextContent("gui.done")), buttonWidget -> onDoneClicked());
43 this.addDrawableChild(this.searchField);
44 ((List<Element>) this.children()).add(this.controlList);
45 this.addDrawableChild(this.doneButton);
48 protected abstract ControlList buildList(int top, int bottom);
51 public void render(MatrixStack matrixStack, int mouseX, int mouseY, float unknown) {
52 render(matrixStack, mouseX, mouseY);
55 protected void render(MatrixStack matrixStack, int mouseX, int mouseY) {
56 RenderSystem.assertOnRenderThread();
57 this.renderBackground(matrixStack);
58 this.controlList.render(matrixStack, mouseX, mouseY);
60 this.drawCenteredText(matrixStack, this.textRenderer, this.title.asTruncatedString(256), this.width / 2, 8, 16777215);
61 this.searchField.render(matrixStack, mouseX, mouseY);
62 this.doneButton.render(matrixStack, mouseX, mouseY, 0f);
64 int left = this.width - this.textRenderer.getWidth(version) - 2;
65 int top = this.height - 10;
66 this.drawStringWithShadow(matrixStack, this.textRenderer, version, left, top, -10658467);
71 this.searchField.tick();
75 public boolean keyPressed(int key, int scanCode, int modifiers) {
76 return super.keyPressed(key, scanCode, modifiers) || this.searchField.keyPressed(key, scanCode, modifiers);
80 public boolean charTyped(char character, int modifiers) {
81 return this.searchField.charTyped(character, modifiers);
85 public boolean mouseScrolled(double mouseX, double mouseY, double scrollAmount) {
86 return this.controlList.mouseScrolled(mouseX, mouseY, scrollAmount);
90 public void removed() {
91 this.controlList.close();
94 protected void setCanExit(boolean canExit) {
95 this.doneButton.active = canExit;
99 public boolean mouseClicked(double mouseX, double mouseY, int button) {
100 for (Element control : this.children()) {
101 if (control.mouseClicked(mouseX, mouseY, button)) {
102 Element focused = getFocused();
103 if (focused instanceof IFocusableControl && focused != control) {
104 ((IFocusableControl) focused).clearFocus();
106 this.setFocused(control);
107 if (button == 0) this.setDragging(true);