1 package com.irtimaled.bbor.client.gui;
3 import net.minecraft.client.MinecraftClient;
4 import net.minecraft.client.util.math.MatrixStack;
6 import java.util.ArrayList;
9 public class ControlListSection extends ControlListEntry implements IControlSet {
10 private static final int TITLE_HEIGHT = 16;
11 private final String title;
12 private final List<AbstractControl> controls = new ArrayList<>();
13 private final MinecraftClient minecraft = MinecraftClient.getInstance();
14 private final int titleHeight;
16 private IControl focused;
17 private boolean dragging;
19 ControlListSection(String title, CreateControl... createControls) {
21 this.titleHeight = title != null ? TITLE_HEIGHT : 0;
22 this.height = titleHeight;
24 int columnCount = columnCount();
25 int controlWidth = (ControlList.CONTROLS_WIDTH - ((columnCount - 1) * 4)) / columnCount;
28 for (CreateControl createControl : createControls) {
29 AbstractControl control = createControl.create(controlWidth);
30 if (control == null) continue;
32 this.controls.add(control);
34 this.height += control.getControlHeight();
36 column = (column + 1) % columnCount;
40 private int columnCount() {
41 switch (minecraft.getLanguageManager().getLanguage().getCode()) {
51 public void render(MatrixStack matrixStack, int mouseX, int mouseY) {
55 if (this.title != null) {
56 this.minecraft.textRenderer.draw(matrixStack, this.title, x + 4, y + ((TITLE_HEIGHT - this.minecraft.textRenderer.fontHeight) / 1.5f), 16777215);
62 for (AbstractControl control : controls) {
63 if (!control.isVisible()) continue;
65 control.setX(left + x);
67 control.render(matrixStack, mouseX, mouseY);
69 height = control.getControlHeight();
71 left += control.getControlWidth();
72 if (left >= ControlList.CONTROLS_WIDTH) {
80 public void clearFocus() {
81 IControlSet.super.clearFocus();
85 public int getControlHeight() {
89 public int getControlWidth() {
90 return ControlList.CONTROLS_WIDTH;
93 public void filter(String lowerValue) {
94 if (matchesTitle(lowerValue)) lowerValue = "";
98 for (AbstractControl entry : controls) {
99 entry.filter(lowerValue);
100 if (entry.isVisible()) {
102 height += entry.getControlHeight();
103 left += entry.getControlWidth();
104 if (left >= getControlWidth()) {
107 } else if (entry == focused) {
112 this.height = height + titleHeight;
113 this.setVisible(height > 0);
116 private boolean matchesTitle(String lowerValue) {
117 if (this.title == null) return false;
119 String lowerString = this.title.toLowerCase();
120 return lowerString.startsWith(lowerValue) ||
121 lowerString.contains(" " + lowerValue);
125 public List<? extends IControl> controls() {
126 return this.controls;
130 public IControl getFocused() {
135 public void setFocused(IControl focused) {
136 this.focused = focused;
140 public boolean isDragging() {
145 public void setDragging(boolean dragging) {
146 this.dragging = dragging;