import java.util.ArrayList;
import java.util.List;
-public class ControlListSection extends ControlListEntry {
+public class ControlListSection extends ControlListEntry implements IControlSet {
private static final int TITLE_HEIGHT = 16;
- private static final int CONTROLS_WIDTH = 310;
private final String title;
- private final List<IControl> controls = new ArrayList<>();
+ private final List<AbstractControl> controls = new ArrayList<>();
private final Minecraft minecraft = Minecraft.getInstance();
private final int titleHeight;
private int height;
+ private IControl focused;
+ private boolean dragging;
ControlListSection(String title, CreateControl... createControls) {
this.title = title;
this.height = titleHeight;
int columnCount = columnCount();
- int controlWidth = (CONTROLS_WIDTH - ((columnCount - 1) * 4)) / columnCount;
+ int controlWidth = (ControlList.CONTROLS_WIDTH - ((columnCount - 1) * 4)) / columnCount;
int column = 0;
for (CreateControl createControl : createControls) {
- IControl control = createControl.create(0, controlWidth);
- if(control == null) continue;
+ AbstractControl control = createControl.create(controlWidth);
+ if (control == null) continue;
this.controls.add(control);
if (column == 0) {
}
private int columnCount() {
- switch (minecraft.getLanguageManager().getCurrentLanguage().getCode()){
+ switch (minecraft.getLanguageManager().getCurrentLanguage().getCode()) {
case "en_au":
case "en_us":
- case "en_gb": return 3;
+ case "en_gb":
+ return 3;
}
return 2;
}
int x = this.getX();
int y = this.getY();
int top = y;
- if(this.title != null) {
+ if (this.title != null) {
this.minecraft.fontRenderer.drawString(this.title, x + 4, y + ((TITLE_HEIGHT - this.minecraft.fontRenderer.FONT_HEIGHT) / 1.5f), 16777215);
top += titleHeight;
}
int left = 0;
int height = 0;
- for(IControl control : controls) {
- if(!control.getVisible()) continue;
+ for (AbstractControl control : controls) {
+ if (!control.isVisible()) continue;
control.setX(left + x);
control.setY(top);
control.render(mouseX, mouseY);
- if(left == 0) {
+ if (left == 0) {
height = control.getControlHeight();
}
left += control.getControlWidth();
- if(left >= CONTROLS_WIDTH) {
+ if (left >= ControlList.CONTROLS_WIDTH) {
left = 0;
top += height;
}
}
@Override
- public int getControlHeight() {
- return this.height;
- }
-
- @Override
- public int getControlWidth() {
- return CONTROLS_WIDTH;
+ public void clearFocus() {
+ IControlSet.super.clearFocus();
}
@Override
- public boolean mouseClicked(double mouseX, double mouseY, int button) {
- for (IControl control : controls) {
- if (control.getVisible() && control.mouseClicked(mouseX, mouseY, button)) {
- return true;
- }
- }
- return false;
+ public int getControlHeight() {
+ return this.height;
}
- @Override
- public boolean mouseReleased(double mouseX, double mouseY, int button) {
- boolean result = false;
- for (IControl control : controls) {
- if (control.mouseReleased(mouseX, mouseY, button)) result = true;
- }
- return result;
+ public int getControlWidth() {
+ return ControlList.CONTROLS_WIDTH;
}
- @Override
public void filter(String lowerValue) {
- if(matchesTitle(lowerValue)) lowerValue = "";
+ if (matchesTitle(lowerValue)) lowerValue = "";
int height = 0;
int left = 0;
- for (IControl entry : controls) {
+ for (AbstractControl entry : controls) {
entry.filter(lowerValue);
- if (entry.getVisible()) {
+ if (entry.isVisible()) {
if (left == 0)
height += entry.getControlHeight();
left += entry.getControlWidth();
if (left >= getControlWidth()) {
left = 0;
}
+ } else if (entry == focused) {
+ entry.clearFocus();
+ focused = null;
}
}
this.height = height + titleHeight;
return lowerString.startsWith(lowerValue) ||
lowerString.contains(" " + lowerValue);
}
+
+ @Override
+ public List<? extends IControl> controls() {
+ return this.controls;
+ }
+
+ @Override
+ public IControl getFocused() {
+ return this.focused;
+ }
+
+ @Override
+ public void setFocused(IControl focused) {
+ this.focused = focused;
+ }
+
+ @Override
+ public boolean isDragging() {
+ return dragging;
+ }
+
+ @Override
+ public void setDragging(boolean dragging) {
+ this.dragging = dragging;
+ }
}