-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: expiremental nui replacment
- Loading branch information
Showing
23 changed files
with
358 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id 'java-library' | ||
id 'maven-publish' | ||
} | ||
|
||
apply from: "$rootDir/gradle/common.gradle" | ||
|
||
dependencies { | ||
api group: 'org.terasology.gestalt', name: 'gestalt-module', version: '7.0.3' | ||
api group: 'org.terasology.gestalt', name: 'gestalt-asset-core', version: '7.0.3' | ||
|
||
api ('org.joml:joml') { | ||
version { | ||
require jomlVersion | ||
} | ||
} | ||
|
||
api ('org.terasology.joml-ext:joml-geometry') { | ||
version { | ||
require geomVersion | ||
} | ||
} | ||
|
||
implementation group: 'com.google.guava', name: 'guava', version: '23.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.terasology.nui.core; | ||
|
||
public class UICore { | ||
} |
4 changes: 4 additions & 0 deletions
4
nui-core/src/main/java/org/terasology/nui/core/UIPaintable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.terasology.nui.core; | ||
|
||
public interface UIPaintable { | ||
} |
18 changes: 18 additions & 0 deletions
18
nui-core/src/main/java/org/terasology/nui/core/UISlot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.terasology.nui.core; | ||
|
||
import org.terasology.nui.core.bind.BindingFunction; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
public class UISlot<T extends BindingFunction> { | ||
private WeakReference<UIWidget> reference; | ||
private T handler; | ||
|
||
public UISlot(T handler) { | ||
this.handler = handler; | ||
} | ||
|
||
public Object invoke(Object[] entry) { | ||
return null; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
nui-core/src/main/java/org/terasology/nui/core/UIWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.terasology.nui.core; | ||
|
||
import org.joml.Vector2f; | ||
import org.terasology.nui.core.bind.UIProperty; | ||
import org.terasology.nui.core.bind.UISignal; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class UIWidget implements AutoCloseable { | ||
private UIWidget parent; | ||
private List<UIWidget> children = new ArrayList<>(); | ||
private boolean isFree = false; | ||
|
||
public final UISignal.UISignal0 destroy = new UISignal.UISignal0(); | ||
|
||
public final UIProperty<Float> z = new UIProperty<>(0.0f); | ||
public final UIProperty<Vector2f> pos = new UIProperty<>(new Vector2f()); | ||
public final UIProperty<Vector2f> size = new UIProperty<>(new Vector2f()); | ||
|
||
public UIWidget(UIWidget parent) { | ||
this.parent = parent; | ||
this.parent.children.add(this); | ||
} | ||
|
||
public UIWidget(UIWidget parent, float z) { | ||
this(parent); | ||
this.z.set(z); | ||
} | ||
|
||
public UIWidget(UIWidget parent, Vector2f pos) { | ||
this(parent); | ||
this.pos.set(pos); | ||
} | ||
|
||
public UIWidget(UIWidget parent, Vector2f pos, Vector2f size) { | ||
this(parent); | ||
this.pos.set(pos); | ||
this.size.set(size); | ||
} | ||
|
||
public Collection<UIWidget> children() { | ||
return Collections.unmodifiableList(children); | ||
} | ||
|
||
public boolean isDisposed() { | ||
return isFree; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
this.isFree = true; | ||
destroy.send(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
nui-core/src/main/java/org/terasology/nui/core/bind/Binding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
import org.terasology.nui.core.UIWidget; | ||
|
||
public class Binding { | ||
public static <T1> void bind(UIWidget wid1, UISignal.UISignal1<T1> signal, UIWidget wid2, UISlot.UISlot1<T1> slot) { | ||
BindingPair pair = new BindingPair(wid1, wid2); | ||
signal.register(pair, slot); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
nui-core/src/main/java/org/terasology/nui/core/bind/BindingFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
public interface BindingFunction { | ||
} |
15 changes: 15 additions & 0 deletions
15
nui-core/src/main/java/org/terasology/nui/core/bind/BindingPair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
import org.terasology.nui.core.UIWidget; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
public class BindingPair { | ||
private WeakReference<UIWidget> wid1; | ||
private WeakReference<UIWidget> wid2; | ||
|
||
public BindingPair(UIWidget w1, UIWidget w2) { | ||
this.wid1 = new WeakReference<>(w1); | ||
this.wid2 = new WeakReference<>(w2); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
nui-core/src/main/java/org/terasology/nui/core/bind/Function0.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
|
||
@FunctionalInterface | ||
public interface Function0 extends BindingFunction { | ||
void apply(); | ||
} |
6 changes: 6 additions & 0 deletions
6
nui-core/src/main/java/org/terasology/nui/core/bind/Function1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
@FunctionalInterface | ||
public interface Function1<T1> extends BindingFunction { | ||
void apply(T1 t1); | ||
} |
5 changes: 5 additions & 0 deletions
5
nui-core/src/main/java/org/terasology/nui/core/bind/Function2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
public interface Function2<T1, T2> extends BindingFunction { | ||
void apply(T1 t1, T2 t2); | ||
} |
5 changes: 5 additions & 0 deletions
5
nui-core/src/main/java/org/terasology/nui/core/bind/Function3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
public interface Function3<T1, T2, T3> extends BindingFunction { | ||
void apply(T1 t1, T2 t2, T3 t3); | ||
} |
5 changes: 5 additions & 0 deletions
5
nui-core/src/main/java/org/terasology/nui/core/bind/Function4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
public interface Function4<T1, T2, T3, T4>extends BindingFunction { | ||
void apply(T1 t1, T2 t2, T3 t3, T4 t4); | ||
} |
5 changes: 5 additions & 0 deletions
5
nui-core/src/main/java/org/terasology/nui/core/bind/Function5.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
public interface Function5<T1, T2, T3, T4, T5> extends BindingFunction { | ||
void apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5); | ||
} |
5 changes: 5 additions & 0 deletions
5
nui-core/src/main/java/org/terasology/nui/core/bind/Function6.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
public interface Function6<T1, T2, T3, T4, T5, T6> extends BindingFunction { | ||
void apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6); | ||
} |
5 changes: 5 additions & 0 deletions
5
nui-core/src/main/java/org/terasology/nui/core/bind/Function7.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
public interface Function7<T1, T2, T3, T4, T5, T6, T7>extends BindingFunction { | ||
void apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7); | ||
} |
5 changes: 5 additions & 0 deletions
5
nui-core/src/main/java/org/terasology/nui/core/bind/Function8.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
public interface Function8<T1, T2, T3, T4, T5, T6, T7, T8> extends BindingFunction { | ||
void apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8); | ||
} |
19 changes: 19 additions & 0 deletions
19
nui-core/src/main/java/org/terasology/nui/core/bind/UIProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
public class UIProperty<T1> { | ||
private T1 value; | ||
public final UISignal.UISignal1<T1> propertyChanged = new UISignal.UISignal1(); | ||
|
||
public UIProperty(T1 initial) { | ||
this.value = initial; | ||
} | ||
|
||
public void set(T1 value) { | ||
propertyChanged.send(value); | ||
this.value = value; | ||
} | ||
|
||
public T1 get() { | ||
return value; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
nui-core/src/main/java/org/terasology/nui/core/bind/UISignal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
import com.google.common.collect.Multimap; | ||
import org.terasology.nui.core.UIWidget; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
public class UISignal { | ||
|
||
public static class UISignal0 extends UISignal { | ||
public Multimap<BindingPair, UISlot.UISlot0> bindings; | ||
|
||
public UISignal0() { | ||
} | ||
|
||
protected boolean register(BindingPair pair, UISlot.UISlot0 slot) { | ||
bindings.put(pair, slot); | ||
return true; | ||
} | ||
|
||
public void send() { | ||
for (BindingPair pair : bindings.keys()) { | ||
for (UISlot.UISlot0 slot : bindings.get(pair)) { | ||
slot.invoke(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static class UISignal1<T1> extends UISignal { | ||
public Multimap<BindingPair, UISlot.UISlot1<T1>> bindings; | ||
|
||
public UISignal1() { | ||
} | ||
|
||
protected boolean register(BindingPair pair, UISlot.UISlot1<T1> slot) { | ||
bindings.put(pair, slot); | ||
return true; | ||
} | ||
|
||
public void send(T1 handler) { | ||
for (BindingPair pair : bindings.keys()) { | ||
for (UISlot.UISlot1<T1> slot : bindings.get(pair)) { | ||
slot.invoke(handler); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static class UISignal2<T1, T2> extends UISignal { | ||
private WeakReference<UIWidget> reference; | ||
|
||
public UISignal2() { | ||
} | ||
|
||
|
||
public void send(T1 t1, T2 t2) { | ||
|
||
} | ||
} | ||
|
||
|
||
} | ||
|
||
|
26 changes: 26 additions & 0 deletions
26
nui-core/src/main/java/org/terasology/nui/core/bind/UISlot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.terasology.nui.core.bind; | ||
|
||
public class UISlot { | ||
|
||
public static class UISlot0 extends UISlot { | ||
private Function0 binding; | ||
public UISlot0(Function0 binding) { | ||
this.binding = binding; | ||
} | ||
|
||
public void invoke() { | ||
binding.apply(); | ||
} | ||
} | ||
|
||
public static class UISlot1<T1> extends UISlot { | ||
private Function1<T1> binding; | ||
public UISlot1(Function1<T1> binding) { | ||
this.binding = binding; | ||
} | ||
|
||
public void invoke(T1 t1) { | ||
binding.apply(t1); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
nui-core/src/test/java/org/terasology/nui/core/TestWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.terasology.nui.core; | ||
|
||
|
||
import org.terasology.nui.core.bind.Binding; | ||
import org.terasology.nui.core.bind.UISignal; | ||
import org.terasology.nui.core.bind.UISlot; | ||
import org.terasology.nui.core.bind.Function1; | ||
|
||
public class TestWidget extends UIWidget{ | ||
private UISignal.UISignal1<Integer> a1 = new UISignal.UISignal1<>(); | ||
private TestWidget2 widget2 = new TestWidget2(this); | ||
|
||
public class TestWidget2 extends UIWidget { | ||
private int counter; | ||
public final UISlot.UISlot1<Integer> consumer = new UISlot.UISlot1<>(new Function1<Integer>() { | ||
@Override | ||
public void apply(Integer integer) { | ||
counter += integer; | ||
handle1(); | ||
} | ||
}); | ||
|
||
public void handle1() { | ||
|
||
} | ||
|
||
public TestWidget2(UIWidget parent) { | ||
super(parent); | ||
} | ||
} | ||
|
||
public TestWidget(UIWidget parent) { | ||
super(parent); | ||
Binding.bind(this, a1, widget2, widget2.consumer); | ||
a1.send(10); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id 'java-library' | ||
id 'maven-publish' | ||
} | ||
|
||
apply from: "$rootDir/gradle/common.gradle" | ||
|
||
dependencies { | ||
api group: 'org.terasology.gestalt', name: 'gestalt-module', version: '7.0.3' | ||
api group: 'org.terasology.gestalt', name: 'gestalt-asset-core', version: '7.0.3' | ||
|
||
api ('org.joml:joml') { | ||
version { | ||
require jomlVersion | ||
} | ||
} | ||
|
||
api ('org.terasology.joml-ext:joml-geometry') { | ||
version { | ||
require geomVersion | ||
} | ||
} | ||
|
||
implementation group: 'com.google.guava', name: 'guava', version: '23.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
rootProject.name = 'TeraNUI' | ||
include 'nui-input', 'nui', 'nui-reflect', 'nui-libgdx' | ||
include 'nui-input', 'nui', 'nui-reflect', 'nui-libgdx', 'nui-core' |