1 package com.irtimaled.bbor.client.gui;
3 import net.minecraft.client.MinecraftClient;
5 import java.util.ArrayList;
8 public class ControlListSection extends ControlListEntry implements IControlSet {
9 private static final int TITLE_HEIGHT = 16;
10 private final String title;
11 private final List<AbstractControl> controls = new ArrayList<>();
12 private final MinecraftClient minecraft = MinecraftClient.getInstance();
13 private final int titleHeight;
15 private IControl focused;
16 private boolean dragging;
18 ControlListSection(String title, CreateControl... createControls) {
20 this.titleHeight = title != null ? TITLE_HEIGHT : 0;
21 this.height = titleHeight;
23 int columnCount = columnCount();
24 int controlWidth = (ControlList.CONTROLS_WIDTH - ((columnCount - 1) * 4)) / columnCount;
27 for (CreateControl createControl : createControls) {
28 AbstractControl control = createControl.create(controlWidth);
29 if (control == null) continue;
31 this.controls.add(control);
33 this.height += control.getControlHeight();
35 column = (column + 1) % columnCount;
39 private int columnCount() {
40 switch (minecraft.getLanguageManager().getLanguage().getCode()) {
50 public void render(int mouseX, int mouseY) {
54 if (this.title != null) {
55 this.minecraft.textRenderer.draw(this.title, x + 4, y + ((TITLE_HEIGHT - this.minecraft.textRenderer.fontHeight) / 1.5f), 16777215);
61 for (AbstractControl control : controls) {
62 if (!control.isVisible()) continue;
64 control.setX(left + x);
66 control.render(mouseX, mouseY);
68 height = control.getControlHeight();
70 left += control.getControlWidth();
71 if (left >= ControlList.CONTROLS_WIDTH) {
79 public void clearFocus() {
80 IControlSet.super.clearFocus();
84 public int getControlHeight() {
88 public int getControlWidth() {
89 return ControlList.CONTROLS_WIDTH;
92 public void filter(String lowerValue) {
93 if (matchesTitle(lowerValue)) lowerValue = "";
97 for (AbstractControl entry : controls) {
98 entry.filter(lowerValue);
99 if (entry.isVisible()) {
101 height += entry.getControlHeight();
102 left += entry.getControlWidth();
103 if (left >= getControlWidth()) {
106 } else if (entry == focused) {
111 this.height = height + titleHeight;
112 this.setVisible(height > 0);
115 private boolean matchesTitle(String lowerValue) {
116 if (this.title == null) return false;
118 String lowerString = this.title.toLowerCase();
119 return lowerString.startsWith(lowerValue) ||
120 lowerString.contains(" " + lowerValue);
124 public List<? extends IControl> controls() {
125 return this.controls;
129 public IControl getFocused() {
134 public void setFocused(IControl focused) {
135 this.focused = focused;
139 public boolean isDragging() {
144 public void setDragging(boolean dragging) {
145 this.dragging = dragging;