]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/gui/ListScreen.java
Add version to config screens
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / gui / ListScreen.java
1 package com.irtimaled.bbor.client.gui;
2
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;
9
10 public abstract class ListScreen extends Screen {
11     private final Screen lastScreen;
12     private static final String version = Versions.build;
13
14     private AbstractButton doneButton;
15     private ControlList controlList;
16     private SearchField searchField;
17
18     ListScreen(Screen lastScreen) {
19         super(new StringTextComponent("Bounding Box Outline Reloaded"));
20         this.lastScreen = lastScreen;
21     }
22
23     ListScreen() {
24         this(null);
25     }
26
27     protected void onDoneClicked() {
28         ClientInterop.displayScreen(lastScreen);
29     }
30
31     @Override
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")) {
36             @Override
37             public void onPressed() {
38                 onDoneClicked();
39             }
40         };
41
42         this.children.add(this.searchField);
43         this.children.add(this.controlList);
44         this.children.add(this.doneButton);
45     }
46
47     protected abstract ControlList buildList(int top, int bottom);
48
49     @Override
50     public void render(int mouseX, int mouseY, float unknown) {
51         render(mouseX, mouseY);
52     }
53
54     protected void render(int mouseX, int mouseY) {
55         this.controlList.render(mouseX, mouseY);
56
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);
60
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);
64     }
65
66     @Override
67     public void tick() {
68         this.searchField.tick();
69     }
70
71     @Override
72     public boolean keyPressed(int key, int scanCode, int modifiers) {
73         return super.keyPressed(key, scanCode, modifiers) || this.searchField.keyPressed(key, scanCode, modifiers);
74     }
75
76     @Override
77     public boolean charTyped(char character, int modifiers) {
78         return this.searchField.charTyped(character, modifiers);
79     }
80
81     @Override
82     public boolean mouseScrolled(double mouseX, double mouseY, double scrollAmount) {
83         return this.controlList.mouseScrolled(mouseX, mouseY, scrollAmount);
84     }
85
86     @Override
87     public void removed() {
88         this.controlList.close();
89     }
90
91     protected void setCanExit(boolean canExit) {
92         this.doneButton.active = canExit;
93     }
94
95     @Override
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();
102                 }
103                 this.setFocused(control);
104                 if (button == 0) this.setDragging(true);
105                 return true;
106             }
107         }
108         return false;
109     }
110 }