port to forestry 4.2

This commit is contained in:
marcin212 committed 2016-10-20 02:56:31 +02:00
1 parent dbc5c1a564
commit f969f63b66
3697 files changed
+78372

No files matched your search

@@ -0,0 +1,72 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls;
import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.core.CraftGUI;
import binnie.craftgui.resource.minecraft.CraftGUITexture;
import binnie.craftgui.events.EventValueChanged;
import binnie.craftgui.events.EventHandler;
import binnie.craftgui.events.EventMouse;
import binnie.craftgui.core.Attribute;
import binnie.craftgui.core.geometry.TextJustification;
import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.controls.core.IControlValue;
import binnie.craftgui.controls.core.Control;
public class ControlCheckbox extends Control implements IControlValue<Boolean>
{
boolean value;
String text;
public ControlCheckbox(final IWidget parent, final float x, final float y, final boolean bool) {
this(parent, x, y, 0.0f, "", bool);
}
public ControlCheckbox(final IWidget parent, final float x, final float y, final float w, final String text, final boolean bool) {
super(parent, x, y, (w > 16.0f) ? w : 16.0f, 16.0f);
this.text = text;
this.value = bool;
if (w > 16.0f) {
new ControlText(this, new IArea(16.0f, 1.0f, w - 16.0f, 16.0f), text, TextJustification.MiddleCenter).setColour(4473924);
}
this.addAttribute(Attribute.MouseOver);
this.addEventHandler(new EventMouse.Down.Handler() {
@Override
public void onEvent(final EventMouse.Down event) {
ControlCheckbox.this.toggleValue();
}
}.setOrigin(EventHandler.Origin.Self, this));
}
protected void onValueChanged(final boolean value) {
}
@Override
public Boolean getValue() {
return this.value;
}
@Override
public void setValue(final Boolean value) {
this.value = value;
this.onValueChanged(value);
this.callEvent(new EventValueChanged<Object>(this, value));
}
public void toggleValue() {
this.setValue(Boolean.valueOf(!this.getValue()));
}
@Override
public void onRenderBackground() {
Object texture = this.getValue() ? CraftGUITexture.CheckboxChecked : CraftGUITexture.Checkbox;
if (this.isMouseOver()) {
texture = (this.getValue() ? CraftGUITexture.CheckboxCheckedHighlighted : CraftGUITexture.CheckboxHighlighted);
}
CraftGUI.Render.texture(texture, IPoint.ZERO);
}
}
@@ -0,0 +1,48 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls;
import binnie.craftgui.core.CraftGUI;
import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.core.geometry.TextJustification;
import binnie.craftgui.controls.core.IControlValue;
import binnie.craftgui.controls.core.Control;
public class ControlText extends Control implements IControlValue<String>
{
private String text;
private TextJustification align;
public ControlText(final IWidget parent, final IPoint pos, final String text) {
this(parent, new IArea(pos, new IPoint(500.0f, 0.0f)), text, TextJustification.TopLeft);
}
public ControlText(final IWidget parent, final String text, final TextJustification align) {
this(parent, parent.getArea(), text, align);
}
public ControlText(final IWidget parent, final IArea area, final String text, final TextJustification align) {
super(parent, area.pos().x(), area.pos().y(), area.size().x(), area.size().y());
this.setValue(text);
this.align = align;
}
@Override
public void onRenderBackground() {
CraftGUI.Render.text(this.getArea(), this.align, this.text, this.getColour());
}
@Override
public void setValue(final String text) {
this.text = text;
}
@Override
public String getValue() {
return this.text;
}
}
@@ -0,0 +1,17 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls;
import binnie.craftgui.core.geometry.TextJustification;
import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.core.IWidget;
public class ControlTextCentered extends ControlText
{
public ControlTextCentered(final IWidget parent, final float y, final String text) {
super(parent, new IArea(new IPoint(0.0f, y), new IPoint(parent.size().x(), 0.0f)), text, TextJustification.TopCenter);
}
}
@@ -0,0 +1,97 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls;
import binnie.craftgui.resource.minecraft.CraftGUITexture;
import binnie.craftgui.core.CraftGUI;
import binnie.craftgui.events.EventWidget;
import binnie.craftgui.events.EventMouse;
import binnie.craftgui.events.EventHandler;
import binnie.craftgui.events.EventTextEdit;
import binnie.craftgui.events.EventKey;
import binnie.craftgui.core.Attribute;
import binnie.craftgui.core.IWidget;
import net.minecraft.client.gui.GuiTextField;
import binnie.craftgui.controls.core.IControlValue;
import binnie.craftgui.controls.core.Control;
public class ControlTextEdit extends Control implements IControlValue<String>
{
GuiTextField field;
private String cachedValue;
public ControlTextEdit(final IWidget parent, final float x, final float y, final float width, final float height) {
super(parent, x, y, width, height);
this.cachedValue = "";
this.field = new GuiTextField(this.getWindow().getGui().getFontRenderer(), 0, 0, 10, 10);
this.addAttribute(Attribute.CanFocus);
this.addAttribute(Attribute.MouseOver);
this.field.setEnableBackgroundDrawing(false);
this.addEventHandler(new EventKey.Down.Handler() {
@Override
public void onEvent(final EventKey.Down event) {
ControlTextEdit.this.field.textboxKeyTyped(event.getCharacter(), event.getKey());
final String text = ControlTextEdit.this.getValue();
if (!text.equals(ControlTextEdit.this.cachedValue)) {
ControlTextEdit.this.cachedValue = text;
ControlTextEdit.this.callEvent(new EventTextEdit(ControlTextEdit.this, ControlTextEdit.this.cachedValue));
ControlTextEdit.this.onTextEdit(ControlTextEdit.this.cachedValue);
}
}
}.setOrigin(EventHandler.Origin.Self, this));
this.addEventHandler(new EventMouse.Down.Handler() {
@Override
public void onEvent(final EventMouse.Down event) {
ControlTextEdit.this.field.mouseClicked((int) ControlTextEdit.this.getRelativeMousePosition().x(), (int) ControlTextEdit.this.getRelativeMousePosition().y(), event.getButton());
}
}.setOrigin(EventHandler.Origin.Self, this));
this.addEventHandler(new EventWidget.GainFocus.Handler() {
@Override
public void onEvent(final EventWidget.GainFocus event) {
ControlTextEdit.this.field.setFocused(true);
}
}.setOrigin(EventHandler.Origin.Self, this));
this.addEventHandler(new EventWidget.LoseFocus.Handler() {
@Override
public void onEvent(final EventWidget.LoseFocus event) {
ControlTextEdit.this.field.setFocused(false);
}
}.setOrigin(EventHandler.Origin.Self, this));
}
@Override
public String getValue() {
return (this.field.getText() == null) ? "" : this.field.getText();
}
@Override
public void setValue(final String value) {
if (!this.getValue().equals(value)) {
this.field.setText(value);
this.field.setCursorPosition(0);
}
}
@Override
public void onUpdateClient() {
}
protected void onTextEdit(final String value) {
}
@Override
public void onRenderBackground() {
CraftGUI.Render.texture(CraftGUITexture.Slot, this.getArea());
this.renderTextField();
}
protected void renderTextField() {
this.field.width = (int) this.w();
this.field.height = (int) this.h();
this.field.xPosition = (int) ((this.h() - 8.0f) / 2.0f);
this.field.yPosition = (int) ((this.h() - 8.0f) / 2.0f);
this.field.drawTextBox();
}
}
@@ -0,0 +1,14 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls;
public interface IControlSelection<T>
{
T getSelectedValue();
void setSelectedValue(final T p0);
boolean isSelected(final IControlSelectionOption<T> p0);
}
@@ -0,0 +1,10 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls;
public interface IControlSelectionOption<T>
{
T getValue();
}
@@ -0,0 +1,66 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.button;
import binnie.craftgui.core.CraftGUI;
import binnie.craftgui.resource.minecraft.CraftGUITexture;
import binnie.craftgui.core.geometry.TextJustification;
import binnie.craftgui.events.EventHandler;
import binnie.craftgui.events.EventButtonClicked;
import binnie.craftgui.events.EventMouse;
import binnie.craftgui.core.Attribute;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.controls.ControlText;
import binnie.craftgui.controls.core.Control;
public class ControlButton extends Control
{
private ControlText textWidget;
private String text;
public ControlButton(final IWidget parent, final float x, final float y, final float width, final float height) {
super(parent, x, y, width, height);
this.addAttribute(Attribute.MouseOver);
this.addEventHandler(new EventMouse.Down.Handler() {
@Override
public void onEvent(final EventMouse.Down event) {
ControlButton.this.callEvent(new EventButtonClicked(ControlButton.this.getWidget()));
ControlButton.this.onMouseClick(event);
}
}.setOrigin(EventHandler.Origin.Self, this));
}
protected void onMouseClick(final EventMouse.Down event) {
}
public ControlButton(final IWidget parent, final float x, final float y, final float width, final float height, final String text) {
this(parent, x, y, width, height);
this.text = text;
this.textWidget = new ControlText(this, this.getArea(), text, TextJustification.MiddleCenter);
}
@Override
public void onUpdateClient() {
if (this.textWidget != null) {
this.textWidget.setValue(this.getText());
}
}
public String getText() {
return this.text;
}
@Override
public void onRenderBackground() {
Object texture = CraftGUITexture.ButtonDisabled;
if (this.isMouseOver()) {
texture = CraftGUITexture.ButtonHighlighted;
}
else if (this.isEnabled()) {
texture = CraftGUITexture.Button;
}
CraftGUI.Render.texture(texture, this.getArea());
}
}
@@ -0,0 +1,61 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.button;
import java.util.ArrayList;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.events.EventValueChanged;
import binnie.craftgui.events.EventMouse;
import java.util.List;
import binnie.craftgui.controls.core.IControlValue;
public class ControlEnumButton<T> extends ControlButton implements IControlValue<T>
{
public static final String eventEnumChanged = "eventEnumButtonChanged";
private T currentSelection;
private List<T> enumConstants;
@Override
public String getText() {
return this.currentSelection.toString();
}
@Override
public void onMouseClick(final EventMouse.Down event) {
int index = this.enumConstants.indexOf(this.currentSelection);
if (index < this.enumConstants.size() - 1) {
++index;
}
else {
index = 0;
}
final T newEnum = this.enumConstants.get(index);
this.setValue(newEnum);
}
@Override
public void setValue(final T selection) {
if (this.currentSelection != selection) {
this.currentSelection = selection;
this.callEvent(new EventValueChanged<Object>(this, this.getValue()));
}
}
public ControlEnumButton(final IWidget parent, final float x, final float y, final float width, final float height, final T[] values) {
super(parent, x, y, width, height, "");
this.enumConstants = new ArrayList<T>();
for (final T value : values) {
this.enumConstants.add(value);
}
if (values.length > 0) {
this.currentSelection = values[0];
}
}
@Override
public T getValue() {
return this.currentSelection;
}
}
@@ -0,0 +1,23 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.button;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.events.EventToggleButtonClicked;
import binnie.craftgui.events.EventMouse;
public class ControlToggleButton extends ControlButton
{
boolean toggled;
@Override
public void onMouseClick(final EventMouse.Down event) {
this.callEvent(new EventToggleButtonClicked(this, this.toggled));
}
public ControlToggleButton(final IWidget parent, final int x, final int y, final int width, final int height) {
super(parent, x, y, width, height);
}
}
@@ -0,0 +1,85 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.core;
import binnie.craftgui.minecraft.Window;
import binnie.craftgui.core.Tooltip;
import binnie.craftgui.core.Attribute;
import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.core.geometry.IPoint;
import java.util.ArrayList;
import binnie.craftgui.core.IWidget;
import java.util.List;
import binnie.craftgui.core.ITooltip;
import binnie.craftgui.core.ITooltipHelp;
import binnie.craftgui.core.Widget;
public class Control extends Widget implements ITooltipHelp, ITooltip
{
List<String> helpStrings;
List<String> tooltipStrings;
public int extraLevel;
public Control(final IWidget parent, final float x, final float y, final float w, final float h) {
super(parent);
this.helpStrings = new ArrayList<String>();
this.tooltipStrings = new ArrayList<String>();
this.extraLevel = 0;
this.setPosition(new IPoint(x, y));
this.setSize(new IPoint(w, h));
this.initialise();
}
public Control(final IWidget parent, final IArea area) {
this(parent, area.x(), area.y(), area.w(), area.h());
}
protected void initialise() {
}
@Override
public void onUpdateClient() {
}
public void addHelp(final String string) {
this.helpStrings.add(string);
}
public void addHelp(final String[] strings) {
for (final String string : strings) {
this.addHelp(string);
}
}
public void addTooltip(final String string) {
this.addAttribute(Attribute.MouseOver);
this.tooltipStrings.add(string);
}
public void addTooltip(final String[] strings) {
for (final String string : strings) {
this.addTooltip(string);
}
}
@Override
public int getLevel() {
return this.extraLevel + super.getLevel();
}
@Override
public void getHelpTooltip(final Tooltip tooltip) {
tooltip.add(this.helpStrings);
}
@Override
public void getTooltip(final Tooltip tooltip) {
tooltip.add(this.tooltipStrings);
}
public Window getWindow() {
return (Window) this.getSuperParent();
}
}
@@ -0,0 +1,12 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.core;
public interface IControlIndexed
{
int getIndex();
void setIndex(final int p0);
}
@@ -0,0 +1,14 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.core;
import binnie.craftgui.core.IWidget;
public interface IControlValue<T> extends IWidget
{
T getValue();
void setValue(final T p0);
}
@@ -0,0 +1,14 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.core;
import java.util.Collection;
public interface IControlValues<T> extends IControlValue<T>
{
Collection<T> getValues();
void setValues(final Collection<T> p0);
}
@@ -0,0 +1,131 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.listbox;
import binnie.craftgui.core.geometry.IPoint;
import java.util.Collection;
import binnie.craftgui.events.EventValueChanged;
import java.util.LinkedHashMap;
import binnie.core.util.IValidator;
import binnie.craftgui.core.IWidget;
import java.util.Map;
import binnie.craftgui.controls.core.IControlValue;
import binnie.craftgui.controls.core.Control;
public class ControlList<T> extends Control implements IControlValue<T>
{
ControlListBox<T> parent;
T value;
Map<T, IWidget> allOptions;
Map<T, IWidget> optionWidgets;
boolean creating;
IValidator<IWidget> validator;
protected ControlList(final ControlListBox<T> parent, final float x, final float y, final float w, final float h) {
super(parent, x, y, w, h);
this.value = null;
this.allOptions = new LinkedHashMap<T, IWidget>();
this.optionWidgets = new LinkedHashMap<T, IWidget>();
this.creating = false;
this.parent = parent;
}
@Override
public T getValue() {
return this.value;
}
@Override
public void setValue(final T value) {
if (value == this.value) {
return;
}
this.value = value;
if (value != null && this.optionWidgets.containsKey(value)) {
final IWidget child = this.optionWidgets.get(value);
this.parent.ensureVisible(child.y(), child.y() + child.h(), this.h());
}
this.getParent().callEvent(new EventValueChanged<Object>(this.getParent(), value));
}
public void setOptions(final Collection<T> options) {
this.deleteAllChildren();
this.allOptions.clear();
int i = 0;
for (final T option : options) {
final IWidget optionWidget = ((ControlListBox) this.getParent()).createOption(option, 0);
if (optionWidget != null) {
this.allOptions.put(option, optionWidget);
}
++i;
}
this.filterOptions();
}
public void filterOptions() {
int height = 0;
this.optionWidgets.clear();
for (final Map.Entry<T, IWidget> entry : this.allOptions.entrySet()) {
if (this.isValidOption(entry.getValue())) {
entry.getValue().show();
this.optionWidgets.put(entry.getKey(), entry.getValue());
entry.getValue().setPosition(new IPoint(0.0f, height));
height += (int) entry.getValue().getSize().y();
}
else {
entry.getValue().hide();
}
}
this.creating = true;
this.setValue(this.getValue());
this.setSize(new IPoint(this.getSize().x(), height));
}
public Collection<T> getOptions() {
return this.optionWidgets.keySet();
}
public Collection<T> getAllOptions() {
return this.allOptions.keySet();
}
public int getIndexOf(final T value) {
int index = 0;
for (final T option : this.getOptions()) {
if (option.equals(value)) {
return index;
}
++index;
}
return -1;
}
public int getCurrentIndex() {
return this.getIndexOf(this.getValue());
}
public void setIndex(final int currentIndex) {
int index = 0;
for (final T option : this.getOptions()) {
if (index == currentIndex) {
this.setValue(option);
return;
}
++index;
}
this.setValue(null);
}
private boolean isValidOption(final IWidget widget) {
return this.validator == null || this.validator.isValid(widget);
}
public void setValidator(final IValidator<IWidget> validator) {
if (this.validator != validator) {
this.validator = validator;
this.filterOptions();
}
}
}
@@ -0,0 +1,63 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.listbox;
import binnie.core.util.IValidator;
import java.util.Collection;
import binnie.craftgui.events.EventKey;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.controls.core.IControlValue;
import binnie.craftgui.controls.scroll.ControlScrollableContent;
public class ControlListBox<T> extends ControlScrollableContent<ControlList<T>> implements IControlValue<T>
{
public ControlListBox(final IWidget parent, final float x, final float y, final float w, final float h, final float scrollBarSize) {
super(parent, x, y, w, h, scrollBarSize);
}
@Override
public void initialise() {
this.setScrollableContent(new ControlList<T>(this, 1.0f, 1.0f, this.w() - 2.0f - this.scrollBarSize, this.h() - 2.0f));
this.addEventHandler(new EventKey.Down.Handler() {
@Override
public void onEvent(final EventKey.Down event) {
if (ControlListBox.this.calculateIsMouseOver()) {
int currentIndex = ControlListBox.this.getContent().getCurrentIndex();
if (event.getKey() == 208) {
if (++currentIndex >= ControlListBox.this.getContent().getOptions().size()) {
currentIndex = 0;
}
}
else if (event.getKey() == 200 && --currentIndex < 0) {
currentIndex = ControlListBox.this.getContent().getOptions().size() - 1;
}
ControlListBox.this.getContent().setIndex(currentIndex);
}
}
});
}
@Override
public final T getValue() {
return this.getContent().getValue();
}
@Override
public final void setValue(final T value) {
this.getContent().setValue(value);
}
public void setOptions(final Collection<T> options) {
this.getContent().setOptions(options);
}
public IWidget createOption(final T value, final int y) {
return new ControlOption<T>(this.getContent(), value, y);
}
public void setValidator(final IValidator<IWidget> validator) {
this.getContent().setValidator(validator);
}
}
@@ -0,0 +1,68 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.listbox;
import binnie.craftgui.resource.minecraft.CraftGUITexture;
import binnie.craftgui.core.CraftGUI;
import binnie.craftgui.events.EventMouse;
import binnie.craftgui.core.Attribute;
import binnie.craftgui.controls.core.IControlValue;
import binnie.craftgui.controls.core.Control;
public class ControlOption<T> extends Control implements IControlValue<T>
{
T value;
@Override
public void onUpdateClient() {
if (this.getValue() == null) {
return;
}
int colour = 10526880;
if (this.isCurrentSelection()) {
colour = 16777215;
}
this.setColour(colour);
}
public ControlOption(final ControlList<T> controlList, final T option) {
this(controlList, option, 16);
}
public ControlOption(final ControlList<T> controlList, final T option, final int height) {
super(controlList, 0.0f, height, controlList.getSize().x(), 20.0f);
this.value = option;
if (this.value != null) {
this.addAttribute(Attribute.MouseOver);
}
this.addSelfEventHandler(new EventMouse.Down.Handler() {
@Override
public void onEvent(final EventMouse.Down event) {
((IControlValue) ControlOption.this.getParent()).setValue(ControlOption.this.getValue());
}
});
}
@Override
public T getValue() {
return this.value;
}
@Override
public void setValue(final T value) {
this.value = value;
}
public boolean isCurrentSelection() {
return this.getValue() != null && this.getValue().equals(((IControlValue) this.getParent()).getValue());
}
@Override
public void onRenderForeground() {
if (this.isCurrentSelection()) {
CraftGUI.Render.texture(CraftGUITexture.Outline, this.getArea());
}
}
}
@@ -0,0 +1,35 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.listbox;
import binnie.craftgui.events.EventHandler;
import binnie.craftgui.events.EventWidget;
import binnie.craftgui.core.geometry.TextJustification;
import binnie.craftgui.controls.ControlText;
public class ControlTextOption<T> extends ControlOption<T>
{
protected ControlText textWidget;
public ControlTextOption(final ControlList<T> controlList, final T option, final String optionName, final int y) {
super(controlList, option, y);
this.textWidget = null;
this.textWidget = new ControlText(this, this.getArea(), optionName, TextJustification.MiddleCenter);
this.addEventHandler(new EventWidget.ChangeColour.Handler() {
@Override
public void onEvent(final EventWidget.ChangeColour event) {
ControlTextOption.this.textWidget.setColour(ControlTextOption.this.getColour());
}
}.setOrigin(EventHandler.Origin.Self, this));
}
public ControlTextOption(final ControlList<T> controlList, final T option, final int y) {
this(controlList, option, option.toString(), y);
}
public String getText() {
return this.textWidget.getValue();
}
}
@@ -0,0 +1,36 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.page;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.controls.core.IControlValue;
import binnie.craftgui.controls.core.Control;
public class ControlPage<T> extends Control implements IControlValue<T>
{
T value;
public ControlPage(final IWidget parent, final T value) {
this(parent, 0.0f, 0.0f, parent.w(), parent.h(), value);
}
public ControlPage(final IWidget parent, final float x, final float y, final float w, final float h, final T value) {
super(parent, x, y, w, h);
this.setValue(value);
if (parent instanceof IControlValue && ((IControlValue) parent).getValue() == null) {
((IControlValue) parent).setValue(value);
}
}
@Override
public T getValue() {
return this.value;
}
@Override
public void setValue(final T value) {
this.value = value;
}
}
@@ -0,0 +1,59 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.page;
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
import binnie.craftgui.events.EventValueChanged;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.controls.core.IControlValue;
import binnie.craftgui.controls.core.IControlValues;
import binnie.craftgui.controls.core.Control;
public class ControlPages<T> extends Control implements IControlValues<T>, IControlValue<T>
{
T value;
@Override
public boolean isChildVisible(final IWidget child) {
return child != null && this.value == ((IControlValue) child).getValue();
}
public ControlPages(final IWidget parent, final float x, final float y, final float w, final float h) {
super(parent, x, y, w, h);
this.value = null;
}
@Override
public void onAddChild(final IWidget widget) {
}
@Override
public T getValue() {
return this.value;
}
@Override
public void setValue(final T value) {
if (this.value != value) {
this.value = value;
this.callEvent(new EventValueChanged<Object>(this, value));
}
}
@Override
public Collection<T> getValues() {
final List<T> list = new ArrayList<T>();
for (final IWidget child : this.getWidgets()) {
list.add((T) ((IControlValue) child).getValue());
}
return list;
}
@Override
public void setValues(final Collection<T> values) {
}
}
@@ -0,0 +1,23 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.scroll;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.controls.core.Control;
public class ControlScroll extends Control
{
private IControlScrollable scrollWidget;
public ControlScroll(final IWidget parent, final float x, final float y, final float width, final float height, final IControlScrollable scrollWidget) {
super(parent, x, y, width, height);
this.scrollWidget = scrollWidget;
new ControlScrollBar(this);
}
public IControlScrollable getScrollableWidget() {
return this.scrollWidget;
}
}
@@ -0,0 +1,86 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.scroll;
import binnie.craftgui.core.CraftGUI;
import binnie.craftgui.resource.minecraft.CraftGUITexture;
import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.events.EventMouse;
import binnie.craftgui.core.Attribute;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.controls.core.Control;
public class ControlScrollBar extends Control
{
protected final IControlScrollable scrollable;
public ControlScrollBar(final ControlScroll parent) {
this(parent, 0.0f, 0.0f, parent.getSize().x(), parent.getSize().y(), parent.getScrollableWidget());
}
public ControlScrollBar(final IWidget parent, final float x, final float y, final float w, final float h, final IControlScrollable scrollable2) {
super(parent, x, y, w, h);
this.scrollable = scrollable2;
this.addAttribute(Attribute.MouseOver);
this.addSelfEventHandler(new EventMouse.Drag.Handler() {
@Override
public void onEvent(final EventMouse.Drag event) {
ControlScrollBar.this.scrollable.movePercentage(event.getDy() / (ControlScrollBar.this.h() - ControlScrollBar.this.getBarHeight()));
}
});
this.addSelfEventHandler(new EventMouse.Down.Handler() {
@Override
public void onEvent(final EventMouse.Down event) {
final float shownPercentage = ControlScrollBar.this.scrollable.getPercentageShown();
final float percentageIndex = ControlScrollBar.this.scrollable.getPercentageIndex();
final float minPercent = (1.0f - shownPercentage) * percentageIndex;
final float maxPercent = minPercent + shownPercentage;
float clickedPercentage = ControlScrollBar.this.getRelativeMousePosition().y() / (ControlScrollBar.this.h() - 2.0f);
clickedPercentage = Math.max(Math.min(clickedPercentage, 1.0f), 0.0f);
if (clickedPercentage > maxPercent) {
ControlScrollBar.this.scrollable.setPercentageIndex((clickedPercentage - shownPercentage) / (1.0f - shownPercentage));
}
if (clickedPercentage < minPercent) {
ControlScrollBar.this.scrollable.setPercentageIndex(clickedPercentage / (1.0f - shownPercentage));
}
}
});
}
@Override
public void onUpdateClient() {
}
@Override
public boolean isEnabled() {
return this.scrollable.getPercentageShown() < 0.99f;
}
public float getBarHeight() {
return this.h() * this.scrollable.getPercentageShown();
}
protected IArea getRenderArea() {
float height = this.getBarHeight();
if (height < 6.0f) {
height = 6.0f;
}
final float yOffset = ((int) this.h() - (int) this.getBarHeight()) * this.scrollable.getPercentageIndex();
return new IArea(0.0f, yOffset, this.getSize().x(), height);
}
@Override
public void onRenderBackground() {
final IArea renderArea = this.getRenderArea();
Object texture = CraftGUITexture.ScrollDisabled;
if (this.isMouseOver()) {
texture = CraftGUITexture.ScrollHighlighted;
}
else if (this.isEnabled()) {
texture = CraftGUITexture.Scroll;
}
CraftGUI.Render.texture(texture, renderArea);
}
}
@@ -0,0 +1,129 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.scroll;
import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.events.EventWidget;
import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.events.EventMouse;
import binnie.craftgui.controls.core.Control;
import binnie.craftgui.core.IWidget;
public class ControlScrollableContent<T extends IWidget> extends Control implements IControlScrollable
{
protected T controlChild;
protected float scrollBarSize;
float percentageIndex;
public ControlScrollableContent(final IWidget parent, final float x, final float y, final float w, final float h, final float scrollBarSize) {
super(parent, x, y, w, h);
this.percentageIndex = 0.0f;
if (scrollBarSize != 0.0f) {
new ControlScroll(this, this.getSize().x() - scrollBarSize, 0.0f, scrollBarSize, this.getSize().y(), this);
}
this.addEventHandler(new EventMouse.Wheel.Handler() {
@Override
public void onEvent(final EventMouse.Wheel event) {
if (ControlScrollableContent.this.getRelativeMousePosition().x() > 0.0f && ControlScrollableContent.this.getRelativeMousePosition().y() > 0.0f && ControlScrollableContent.this.getRelativeMousePosition().x() < ControlScrollableContent.this.getSize().x() && ControlScrollableContent.this.getRelativeMousePosition().y() < ControlScrollableContent.this.getSize().y()) {
if (ControlScrollableContent.this.getMovementRange() == 0.0f) {
return;
}
final float percentageMove = 0.8f / ControlScrollableContent.this.getMovementRange();
ControlScrollableContent.this.movePercentage(percentageMove * -event.getDWheel());
}
}
});
this.scrollBarSize = scrollBarSize;
}
public void setScrollableContent(final T child) {
this.controlChild = child;
if (child == null) {
return;
}
child.setCroppedZone(this, new IArea(1.0F, 1.0F, getSize().x() - 2.0F - this.scrollBarSize, getSize().y() - 2.0F));
child.addSelfEventHandler(new EventWidget.ChangeSize.Handler() {
@Override
public void onEvent(final EventWidget.ChangeSize event) {
ControlScrollableContent.this.controlChild.setOffset(new IPoint(0.0f, -ControlScrollableContent.this.percentageIndex * ControlScrollableContent.this.getMovementRange()));
if (ControlScrollableContent.this.getMovementRange() == 0.0f) {
ControlScrollableContent.this.percentageIndex = 0.0f;
}
}
});
}
public T getContent() {
return this.controlChild;
}
@Override
public float getPercentageShown() {
if (this.controlChild == null || this.controlChild.getSize().y() == 0.0f) {
return 1.0f;
}
final float shown = this.getSize().y() / this.controlChild.getSize().y();
return Math.min(shown, 1.0f);
}
@Override
public float getPercentageIndex() {
return this.percentageIndex;
}
@Override
public void movePercentage(final float percentage) {
if (this.controlChild == null) {
return;
}
this.percentageIndex += percentage;
if (this.percentageIndex > 1.0f) {
this.percentageIndex = 1.0f;
}
else if (this.percentageIndex < 0.0f) {
this.percentageIndex = 0.0f;
}
if (this.getMovementRange() == 0.0f) {
this.percentageIndex = 0.0f;
}
this.controlChild.setOffset(new IPoint(0.0f, -this.percentageIndex * this.getMovementRange()));
}
@Override
public void setPercentageIndex(final float index) {
this.movePercentage(index - this.percentageIndex);
}
@Override
public float getMovementRange() {
if (this.controlChild == null) {
return 0.0f;
}
final float range = this.controlChild.getSize().y() - this.getSize().y();
return Math.max(range, 0.0f);
}
@Override
public void onUpdateClient() {
this.setPercentageIndex(this.getPercentageIndex());
}
public void ensureVisible(float minY, float maxY, final float totalY) {
minY /= totalY;
maxY /= totalY;
final float shownPercentage = this.getPercentageShown();
final float percentageIndex = this.getPercentageIndex();
final float minPercent = (1.0f - shownPercentage) * percentageIndex;
final float maxPercent = minPercent + shownPercentage;
if (maxY > maxPercent) {
this.setPercentageIndex((maxY - shownPercentage) / (1.0f - shownPercentage));
}
if (minY < minPercent) {
this.setPercentageIndex(minY / (1.0f - shownPercentage));
}
}
}
@@ -0,0 +1,20 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.scroll;
import binnie.craftgui.core.IWidget;
public interface IControlScrollable extends IWidget
{
float getPercentageShown();
float getPercentageIndex();
void movePercentage(final float p0);
void setPercentageIndex(final float p0);
float getMovementRange();
}
@@ -0,0 +1,114 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.tab;
import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.resource.Texture;
import binnie.craftgui.minecraft.control.ControlItemDisplay;
import binnie.craftgui.minecraft.control.ControlTabIcon;
import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.core.CraftGUI;
import binnie.craftgui.resource.minecraft.CraftGUITexture;
import binnie.craftgui.core.geometry.Position;
import binnie.craftgui.core.Tooltip;
import binnie.craftgui.events.EventValueChanged;
import binnie.craftgui.events.EventMouse;
import binnie.craftgui.core.Attribute;
import binnie.craftgui.controls.core.IControlValue;
import binnie.craftgui.core.ITooltip;
import binnie.craftgui.controls.core.Control;
public class ControlTab<T> extends Control implements ITooltip, IControlValue<T>
{
private ControlTabBar<T> tabBar;
protected T value;
public ControlTab(final ControlTabBar<T> parent, final float x, final float y, final float w, final float h, final T value) {
super(parent, x, y, w, h);
this.setValue(value);
this.tabBar = parent;
this.addAttribute(Attribute.MouseOver);
this.addSelfEventHandler(new EventMouse.Down.Handler() {
@Override
public void onEvent(final EventMouse.Down event) {
ControlTab.this.callEvent(new EventValueChanged<Object>(ControlTab.this.getWidget(), ControlTab.this.getValue()));
}
});
}
@Override
public void getTooltip(final Tooltip tooltip) {
final String name = this.getName();
if (name != null && !name.isEmpty()) {
tooltip.add(this.getName());
}
if (this.value instanceof ITooltip) {
((ITooltip) this.value).getTooltip(tooltip);
}
}
@Override
public T getValue() {
return this.value;
}
@Override
public void setValue(final T value) {
this.value = value;
}
public boolean isCurrentSelection() {
return this.getValue() != null && this.getValue().equals(this.tabBar.getValue());
}
public Position getTabPosition() {
return this.tabBar.position;
}
public String getName() {
return this.value.toString();
}
@Override
public void onRenderBackground() {
Object texture = CraftGUITexture.TabDisabled;
if (this.isMouseOver()) {
texture = CraftGUITexture.TabHighlighted;
}
else if (this.isCurrentSelection()) {
texture = CraftGUITexture.Tab;
}
final Texture lTexture = CraftGUI.Render.getTexture(texture);
final Position position = this.getTabPosition();
Texture iTexture = lTexture.crop(position, 8.0f);
final IArea area = this.getArea();
if (texture == CraftGUITexture.TabDisabled) {
if (position == Position.Top || position == Position.Left) {
area.setPosition(area.getPosition().sub(new IPoint(4 * position.x(), 4 * position.y())));
area.setSize(area.getSize().add(new IPoint(4 * position.x(), 4 * position.y())));
}
else {
area.setSize(area.getSize().sub(new IPoint(4 * position.x(), 4 * position.y())));
}
}
CraftGUI.Render.texture(iTexture, area);
if (this instanceof ControlTabIcon) {
final ControlTabIcon icon = (ControlTabIcon) this;
final ControlItemDisplay item = (ControlItemDisplay) this.getWidgets().get(0);
if (texture == CraftGUITexture.TabDisabled) {
item.setColour(-1431655766);
}
else {
item.setColour(-1);
}
if (icon.hasOutline()) {
iTexture = CraftGUI.Render.getTexture(CraftGUITexture.TabOutline);
iTexture = iTexture.crop(position, 8.0f);
CraftGUI.Render.colour(icon.getOutlineColour());
CraftGUI.Render.texture(iTexture, area.inset(2));
}
}
}
}
@@ -0,0 +1,77 @@
//
// Decompiled by Procyon v0.5.30
//
package binnie.craftgui.controls.tab;
import java.util.Collection;
import binnie.craftgui.events.EventHandler;
import binnie.craftgui.events.EventValueChanged;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.core.geometry.Position;
import binnie.craftgui.controls.core.IControlValue;
import binnie.craftgui.controls.core.Control;
public class ControlTabBar<T> extends Control implements IControlValue<T>
{
T value;
Position position;
public ControlTabBar(final IWidget parent, final float x, final float y, final float width, final float height, final Position position) {
super(parent, x, y, width, height);
this.position = position;
this.addEventHandler(new EventValueChanged.Handler() {
@Override
public void onEvent(final EventValueChanged event) {
ControlTabBar.this.setValue((T) event.getValue());
}
}.setOrigin(EventHandler.Origin.DirectChild, this));
}
public void setValues(final Collection<T> values) {
final int i = 0;
while (i < this.getWidgets().size()) {
this.deleteChild(this.getWidgets().get(0));
}
final float length = values.size();
int tabDimension = (int) (this.getSize().y() / length);
if (this.position == Position.Top || this.position == Position.Bottom) {
tabDimension = (int) (this.getSize().x() / length);
}
int j = 0;
for (final T value : values) {
if (this.position == Position.Top || this.position == Position.Bottom) {
final IWidget tab = this.createTab(j * tabDimension, 0.0f, tabDimension, this.getSize().y(), value);
}
else {
final IWidget tab = this.createTab(0.0f, j * tabDimension, this.getSize().x(), tabDimension, value);
}
++j;
}
if (this.value == null && !values.isEmpty()) {
this.setValue(values.iterator().next());
}
}
public ControlTab<T> createTab(final float x, final float y, final float w, final float h, final T value) {
return new ControlTab<T>(this, x, y, w, h, value);
}
@Override
public T getValue() {
return this.value;
}
@Override
public void setValue(final T value) {
final boolean change = this.value != value;
this.value = value;
if (change) {
this.callEvent(new EventValueChanged<Object>(this, value));
}
}
public Position getDirection() {
return this.position;
}
}