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.IGuiEventListener;
6 import net.minecraft.client.gui.screen.Screen;
7 import net.minecraft.client.resources.I18n;
8 import net.minecraft.util.text.StringTextComponent;
10 public abstract class ListScreen extends Screen {
11 private final Screen lastScreen;
12 private static final String version = Versions.build;
14 private AbstractButton doneButton;
15 private ControlList controlList;
16 private SearchField searchField;
18 ListScreen(Screen lastScreen) {
19 super(new StringTextComponent("Bounding Box Outline Reloaded"));
20 this.lastScreen = lastScreen;
27 protected void onDoneClicked() {
28 ClientInterop.displayScreen(lastScreen);
32 protected void init() {
33 this.controlList = this.buildList(48, this.height - 28);
34 this.searchField = new SearchField(this.font, this.width / 2 - 100, 22, 200, 20, this.controlList);
35 this.doneButton = new AbstractButton(this.width / 2 - 100, this.height - 24, 200, I18n.format("gui.done")) {
37 public void onPressed() {
42 this.children.add(this.searchField);
43 this.children.add(this.controlList);
44 this.children.add(this.doneButton);
47 protected abstract ControlList buildList(int top, int bottom);
50 public void render(int mouseX, int mouseY, float unknown) {
51 render(mouseX, mouseY);
54 protected void render(int mouseX, int mouseY) {
55 this.controlList.render(mouseX, mouseY);
57 this.drawCenteredString(this.font, this.title.getUnformattedComponentText(), this.width / 2, 8, 16777215);
58 this.searchField.render(mouseX, mouseY);
59 this.doneButton.render(mouseX, mouseY);
61 int left = this.width - this.font.getStringWidth(version) - 2;
62 int top = this.height - 10;
63 this.drawString(this.font, version, left, top, -10658467);
68 this.searchField.tick();
72 public boolean keyPressed(int key, int scanCode, int modifiers) {
73 return super.keyPressed(key, scanCode, modifiers) || this.searchField.keyPressed(key, scanCode, modifiers);
77 public boolean charTyped(char character, int modifiers) {
78 return this.searchField.charTyped(character, modifiers);
82 public boolean mouseScrolled(double mouseX, double mouseY, double scrollAmount) {
83 return this.controlList.mouseScrolled(mouseX, mouseY, scrollAmount);
87 public void removed() {
88 this.controlList.close();
91 protected void setCanExit(boolean canExit) {
92 this.doneButton.active = canExit;
96 public boolean mouseClicked(double mouseX, double mouseY, int button) {
97 for (IGuiEventListener control : this.children()) {
98 if (control.mouseClicked(mouseX, mouseY, button)) {
99 IGuiEventListener focused = getFocused();
100 if (focused instanceof IFocusableControl && focused != control) {
101 ((IFocusableControl) focused).clearFocus();
103 this.setFocused(control);
104 if (button == 0) this.setDragging(true);