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.LiteralText;
11 import net.minecraft.text.TranslatableText;
13 import java.util.List;
15 public abstract class ListScreen extends Screen {
16 private final Screen lastScreen;
17 private static final String version = Versions.build;
19 private ButtonWidget doneButton;
20 private ControlList controlList;
21 private SearchField searchField;
23 ListScreen(Screen lastScreen) {
24 super(new LiteralText("Bounding Box Outline Reloaded"));
25 this.lastScreen = lastScreen;
32 protected void onDoneClicked() {
33 ClientInterop.displayScreen(lastScreen);
37 protected void init() {
38 this.controlList = this.buildList(48, this.height - 28);
39 this.searchField = new SearchField(this.textRenderer, this.width / 2 - 100, 22, 200, 20, this.controlList);
40 this.doneButton = new ButtonWidget(this.width / 2 - 100, this.height - 24, 200, 20, new TranslatableText("gui.done"), buttonWidget -> onDoneClicked());
42 this.addDrawableChild(this.searchField);
43 ((List<Element>) this.children()).add(this.controlList);
44 this.addDrawableChild(this.doneButton);
47 protected abstract ControlList buildList(int top, int bottom);
50 public void render(MatrixStack matrixStack, int mouseX, int mouseY, float unknown) {
51 render(matrixStack, mouseX, mouseY);
54 protected void render(MatrixStack matrixStack, int mouseX, int mouseY) {
55 RenderSystem.assertThread(RenderSystem::isOnRenderThread);
56 this.renderBackground(matrixStack);
57 this.controlList.render(matrixStack, mouseX, mouseY);
59 this.drawCenteredText(matrixStack, this.textRenderer, this.title.asString(), this.width / 2, 8, 16777215);
60 this.searchField.render(matrixStack, mouseX, mouseY);
61 this.doneButton.render(matrixStack, mouseX, mouseY, 0f);
63 int left = this.width - this.textRenderer.getWidth(version) - 2;
64 int top = this.height - 10;
65 this.drawStringWithShadow(matrixStack, this.textRenderer, version, left, top, -10658467);
70 this.searchField.tick();
74 public boolean keyPressed(int key, int scanCode, int modifiers) {
75 return super.keyPressed(key, scanCode, modifiers) || this.searchField.keyPressed(key, scanCode, modifiers);
79 public boolean charTyped(char character, int modifiers) {
80 return this.searchField.charTyped(character, modifiers);
84 public boolean mouseScrolled(double mouseX, double mouseY, double scrollAmount) {
85 return this.controlList.mouseScrolled(mouseX, mouseY, scrollAmount);
89 public void removed() {
90 this.controlList.close();
93 protected void setCanExit(boolean canExit) {
94 this.doneButton.active = canExit;
98 public boolean mouseClicked(double mouseX, double mouseY, int button) {
99 for (Element control : this.children()) {
100 if (control.mouseClicked(mouseX, mouseY, button)) {
101 Element focused = getFocused();
102 if (focused instanceof IFocusableControl && focused != control) {
103 ((IFocusableControl) focused).clearFocus();
105 this.setFocused(control);
106 if (button == 0) this.setDragging(true);