1 package com.irtimaled.bbor.client.gui;
3 import com.irtimaled.bbor.client.interop.ClientInterop;
4 import net.minecraft.client.gui.IGuiEventListener;
5 import net.minecraft.client.gui.screen.Screen;
6 import net.minecraft.client.resources.I18n;
7 import net.minecraft.util.text.StringTextComponent;
9 public abstract class ListScreen extends Screen {
10 private final Screen lastScreen;
12 private AbstractButton doneButton;
13 private ControlList controlList;
14 private SearchField searchField;
16 ListScreen(Screen lastScreen) {
17 super(new StringTextComponent("Bounding Box Outline Reloaded"));
18 this.lastScreen = lastScreen;
25 protected void onDoneClicked() {
26 ClientInterop.displayScreen(lastScreen);
30 protected void init() {
31 this.controlList = this.buildList(48, this.height - 28);
32 this.searchField = new SearchField(this.font, this.width / 2 - 100, 22, 200, 20, this.controlList);
33 this.doneButton = new AbstractButton(this.width / 2 - 100, this.height - 24, 200, I18n.format("gui.done")) {
35 public void onPressed() {
40 this.children.add(this.searchField);
41 this.children.add(this.controlList);
42 this.children.add(this.doneButton);
45 protected abstract ControlList buildList(int top, int bottom);
48 public void render(int mouseX, int mouseY, float unknown) {
49 render(mouseX, mouseY);
52 protected void render(int mouseX, int mouseY) {
53 this.controlList.render(mouseX, mouseY);
55 this.drawCenteredString(this.font, this.title.getUnformattedComponentText(), this.width / 2, 8, 16777215);
56 this.searchField.render(mouseX, mouseY);
57 this.doneButton.render(mouseX, mouseY);
62 this.searchField.tick();
66 public boolean keyPressed(int key, int scanCode, int modifiers) {
67 return super.keyPressed(key, scanCode, modifiers) || this.searchField.keyPressed(key, scanCode, modifiers);
71 public boolean charTyped(char character, int modifiers) {
72 return this.searchField.charTyped(character, modifiers);
76 public boolean mouseScrolled(double mouseX, double mouseY, double scrollAmount) {
77 return this.controlList.mouseScrolled(mouseX, mouseY, scrollAmount);
81 public void removed() {
82 this.controlList.close();
85 protected void setCanExit(boolean canExit) {
86 this.doneButton.active = canExit;
90 public boolean mouseClicked(double mouseX, double mouseY, int button) {
91 for (IGuiEventListener control : this.children()) {
92 if (control.mouseClicked(mouseX, mouseY, button)) {
93 IGuiEventListener focused = getFocused();
94 if (focused instanceof IFocusableControl && focused != control) {
95 ((IFocusableControl) focused).clearFocus();
97 this.setFocused(control);
98 if (button == 0) this.setDragging(true);