1 package com.irtimaled.bbor.client.gui;
3 import net.minecraft.client.Minecraft;
5 import java.util.ArrayList;
8 public class ControlListSection extends ControlListEntry {
9 private static final int TITLE_HEIGHT = 16;
10 private static final int CONTROLS_WIDTH = 310;
11 private final String title;
12 private final List<IControl> controls = new ArrayList<>();
13 private final Minecraft minecraft = Minecraft.getInstance();
14 private final int titleHeight;
17 ControlListSection(String title, CreateControl... createControls) {
19 this.titleHeight = title != null ? TITLE_HEIGHT : 0;
20 this.height = titleHeight;
22 int columnCount = columnCount();
23 int controlWidth = (CONTROLS_WIDTH - ((columnCount - 1) * 4)) / columnCount;
26 for (CreateControl createControl : createControls) {
27 IControl control = createControl.create(0, controlWidth);
28 if(control == null) continue;
30 this.controls.add(control);
32 this.height += control.getControlHeight();
34 column = (column + 1) % columnCount;
38 private int columnCount() {
39 switch (minecraft.getLanguageManager().getCurrentLanguage().getCode()){
42 case "en_gb": return 3;
48 public void render(int mouseX, int mouseY) {
52 if(this.title != null) {
53 this.minecraft.fontRenderer.drawString(this.title, x + 4, y + ((TITLE_HEIGHT - this.minecraft.fontRenderer.FONT_HEIGHT) / 1.5f), 16777215);
59 for(IControl control : controls) {
60 if(!control.getVisible()) continue;
62 control.setX(left + x);
64 control.render(mouseX, mouseY);
66 height = control.getControlHeight();
68 left += control.getControlWidth();
69 if(left >= CONTROLS_WIDTH) {
77 public int getControlHeight() {
82 public int getControlWidth() {
83 return CONTROLS_WIDTH;
87 public boolean mouseClicked(double mouseX, double mouseY, int button) {
88 for (IControl control : controls) {
89 if (control.getVisible() && control.mouseClicked(mouseX, mouseY, button)) {
97 public boolean mouseReleased(double mouseX, double mouseY, int button) {
98 boolean result = false;
99 for (IControl control : controls) {
100 if (control.mouseReleased(mouseX, mouseY, button)) result = true;
106 public void filter(String lowerValue) {
107 if(matchesTitle(lowerValue)) lowerValue = "";
111 for (IControl entry : controls) {
112 entry.filter(lowerValue);
113 if (entry.getVisible()) {
115 height += entry.getControlHeight();
116 left += entry.getControlWidth();
117 if (left >= getControlWidth()) {
122 this.height = height + titleHeight;
123 this.setVisible(height > 0);
126 private boolean matchesTitle(String lowerValue) {
127 if (this.title == null) return false;
129 String lowerString = this.title.toLowerCase();
130 return lowerString.startsWith(lowerValue) ||
131 lowerString.contains(" " + lowerValue);