mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-17 19:15:24 +00:00
Fix some gui crashes
This commit is contained in:
1 parent
5ecfb694c5
commit
bdcefcb5be
5 files changed
+14
-6
No files matched your search
@@ -2,8 +2,11 @@ package binnie.craftgui.controls.core;
|
||||
|
||||
import binnie.craftgui.core.IWidget;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface IControlValue<T> extends IWidget {
|
||||
@Nullable
|
||||
T getValue();
|
||||
|
||||
void setValue(final T value);
|
||||
void setValue(@Nullable final T value);
|
||||
}
|
||||
@@ -14,7 +14,9 @@ import java.util.Map;
|
||||
|
||||
public class ControlList<T> extends Control implements IControlValue<T> {
|
||||
ControlListBox<T> parent;
|
||||
@Nullable
|
||||
private T defaultValue;
|
||||
@Nullable
|
||||
private T value;
|
||||
Map<T, IWidget> allOptions;
|
||||
Map<T, IWidget> optionWidgets;
|
||||
@@ -22,7 +24,7 @@ public class ControlList<T> extends Control implements IControlValue<T> {
|
||||
@Nullable
|
||||
IValidator<IWidget> validator;
|
||||
|
||||
protected ControlList(final ControlListBox<T> parent, final int x, final int y, final int w, final int h, final T defaultValue) {
|
||||
protected ControlList(final ControlListBox<T> parent, final int x, final int y, final int w, final int h, @Nullable final T defaultValue) {
|
||||
super(parent, x, y, w, h);
|
||||
this.value = defaultValue;
|
||||
this.defaultValue = defaultValue;
|
||||
@@ -33,16 +35,18 @@ public class ControlList<T> extends Control implements IControlValue<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(final T value) {
|
||||
public void setValue(@Nullable final T value) {
|
||||
if (value == this.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class ControlListBox<T> extends ControlScrollableContent<ControlList<T>>
|
||||
@Override
|
||||
public void initialise() {
|
||||
ControlList<T> content = this.getContent();
|
||||
T defaultValue = content.getDefaultValue();
|
||||
T defaultValue = content == null ? null : content.getDefaultValue();
|
||||
ControlList<T> child = new ControlList<>(this, 1, 1, this.w() - 2 - this.scrollBarSize, this.h() - 2, defaultValue);
|
||||
this.setScrollableContent(child);
|
||||
this.addEventHandler(new EventKey.Down.Handler() {
|
||||
|
||||
@@ -253,7 +253,8 @@ public class Widget implements IWidget {
|
||||
((EventHandler<Event>)handler).onEvent(event);
|
||||
}
|
||||
}
|
||||
for (final IWidget child : this.getWidgets()) {
|
||||
List<IWidget> widgets = new ArrayList<>(this.getWidgets());
|
||||
for (final IWidget child : widgets) {
|
||||
child.recieveEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,8 +247,8 @@ public abstract class Window extends TopLevelWidget implements INetwork.ReceiveG
|
||||
return this.player.inventory.getItemStack();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public IInventory getInventory() {
|
||||
Preconditions.checkState(this.entityInventory != null, "This window has no inventory.");
|
||||
return this.entityInventory;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user