1 package com.irtimaled.bbor.client.gui;
3 import com.irtimaled.bbor.Versions;
4 import com.irtimaled.bbor.client.interop.ClientInterop;
5 import net.minecraft.client.gui.Element;
6 import net.minecraft.client.gui.screen.Screen;
7 import net.minecraft.client.resource.language.I18n;
8 import net.minecraft.client.util.math.MatrixStack;
9 import net.minecraft.text.LiteralText;
11 import java.util.List;
13 public abstract class ListScreen extends Screen {
14 private final Screen lastScreen;
15 private static final String version = Versions.build;
17 private AbstractButton doneButton;
18 private ControlList controlList;
19 private SearchField searchField;
21 ListScreen(Screen lastScreen) {
22 super(new LiteralText("Bounding Box Outline Reloaded"));
23 this.lastScreen = lastScreen;
30 protected void onDoneClicked() {
31 ClientInterop.displayScreen(lastScreen);
35 protected void init() {
36 this.controlList = this.buildList(48, this.height - 28);
37 this.searchField = new SearchField(this.textRenderer, this.width / 2 - 100, 22, 200, 20, this.controlList);
38 this.doneButton = new AbstractButton(this.width / 2 - 100, this.height - 24, 200, I18n.translate("gui.done")) {
40 public void onPressed() {
45 this.addDrawableChild(this.searchField);
46 ((List<Element>)this.children()).add(controlList);
47 this.addDrawableChild(this.doneButton);
50 protected abstract ControlList buildList(int top, int bottom);
53 public void render(MatrixStack matrixStack, int mouseX, int mouseY, float unknown) {
54 render(matrixStack, mouseX, mouseY);
57 protected void render(MatrixStack matrixStack, int mouseX, int mouseY) {
58 this.controlList.render(matrixStack, mouseX, mouseY);
60 this.drawCenteredText(matrixStack, this.textRenderer, this.title.asString(), this.width / 2, 8, 16777215);
61 this.searchField.render(matrixStack, mouseX, mouseY);
62 this.doneButton.render(matrixStack, mouseX, mouseY);
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);