Skip to content

Commit d31bf89

Browse files
committed
feature: expiremental nui replacment
1 parent c94e662 commit d31bf89

23 files changed

Lines changed: 358 additions & 1 deletion

nui-core/build.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
plugins {
2+
id 'java-library'
3+
id 'maven-publish'
4+
}
5+
6+
apply from: "$rootDir/gradle/common.gradle"
7+
8+
dependencies {
9+
api group: 'org.terasology.gestalt', name: 'gestalt-module', version: '7.0.3'
10+
api group: 'org.terasology.gestalt', name: 'gestalt-asset-core', version: '7.0.3'
11+
12+
api ('org.joml:joml') {
13+
version {
14+
require jomlVersion
15+
}
16+
}
17+
18+
api ('org.terasology.joml-ext:joml-geometry') {
19+
version {
20+
require geomVersion
21+
}
22+
}
23+
24+
implementation group: 'com.google.guava', name: 'guava', version: '23.0'
25+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.terasology.nui.core;
2+
3+
public class UICore {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.terasology.nui.core;
2+
3+
public interface UIPaintable {
4+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.terasology.nui.core;
2+
3+
import org.terasology.nui.core.bind.BindingFunction;
4+
5+
import java.lang.ref.WeakReference;
6+
7+
public class UISlot<T extends BindingFunction> {
8+
private WeakReference<UIWidget> reference;
9+
private T handler;
10+
11+
public UISlot(T handler) {
12+
this.handler = handler;
13+
}
14+
15+
public Object invoke(Object[] entry) {
16+
return null;
17+
}
18+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.terasology.nui.core;
2+
3+
import org.joml.Vector2f;
4+
import org.terasology.nui.core.bind.UIProperty;
5+
import org.terasology.nui.core.bind.UISignal;
6+
7+
import java.util.ArrayList;
8+
import java.util.Collection;
9+
import java.util.Collections;
10+
import java.util.List;
11+
12+
public class UIWidget implements AutoCloseable {
13+
private UIWidget parent;
14+
private List<UIWidget> children = new ArrayList<>();
15+
private boolean isFree = false;
16+
17+
public final UISignal.UISignal0 destroy = new UISignal.UISignal0();
18+
19+
public final UIProperty<Float> z = new UIProperty<>(0.0f);
20+
public final UIProperty<Vector2f> pos = new UIProperty<>(new Vector2f());
21+
public final UIProperty<Vector2f> size = new UIProperty<>(new Vector2f());
22+
23+
public UIWidget(UIWidget parent) {
24+
this.parent = parent;
25+
this.parent.children.add(this);
26+
}
27+
28+
public UIWidget(UIWidget parent, float z) {
29+
this(parent);
30+
this.z.set(z);
31+
}
32+
33+
public UIWidget(UIWidget parent, Vector2f pos) {
34+
this(parent);
35+
this.pos.set(pos);
36+
}
37+
38+
public UIWidget(UIWidget parent, Vector2f pos, Vector2f size) {
39+
this(parent);
40+
this.pos.set(pos);
41+
this.size.set(size);
42+
}
43+
44+
public Collection<UIWidget> children() {
45+
return Collections.unmodifiableList(children);
46+
}
47+
48+
public boolean isDisposed() {
49+
return isFree;
50+
}
51+
52+
@Override
53+
public void close() {
54+
this.isFree = true;
55+
destroy.send();
56+
}
57+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.terasology.nui.core.bind;
2+
3+
import org.terasology.nui.core.UIWidget;
4+
5+
public class Binding {
6+
public static <T1> void bind(UIWidget wid1, UISignal.UISignal1<T1> signal, UIWidget wid2, UISlot.UISlot1<T1> slot) {
7+
BindingPair pair = new BindingPair(wid1, wid2);
8+
signal.register(pair, slot);
9+
}
10+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.terasology.nui.core.bind;
2+
3+
public interface BindingFunction {
4+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.terasology.nui.core.bind;
2+
3+
import org.terasology.nui.core.UIWidget;
4+
5+
import java.lang.ref.WeakReference;
6+
7+
public class BindingPair {
8+
private WeakReference<UIWidget> wid1;
9+
private WeakReference<UIWidget> wid2;
10+
11+
public BindingPair(UIWidget w1, UIWidget w2) {
12+
this.wid1 = new WeakReference<>(w1);
13+
this.wid2 = new WeakReference<>(w2);
14+
}
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.terasology.nui.core.bind;
2+
3+
4+
@FunctionalInterface
5+
public interface Function0 extends BindingFunction {
6+
void apply();
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.terasology.nui.core.bind;
2+
3+
@FunctionalInterface
4+
public interface Function1<T1> extends BindingFunction {
5+
void apply(T1 t1);
6+
}

0 commit comments

Comments
 (0)