Skip to content

Commit 7b346e7

Browse files
authored
Merge pull request #17 from Avanatiker/feature/renderer
GUI Rewrite
2 parents cf31ae6 + 6d65b57 commit 7b346e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+930
-1522
lines changed

common/src/main/java/com/lambda/mixin/input/KeyboardMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public class KeyboardMixin {
1414
void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) {
1515
if (key <= 0) return;
1616
if (action != 1) return;
17-
EventFlow.post(new KeyPressEvent(key));
17+
EventFlow.post(new KeyPressEvent(key, scancode, action, modifiers));
1818
}
1919
}

common/src/main/kotlin/com/lambda/config/AbstractSetting.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ abstract class AbstractSetting<T : Any>(
5656
val description: String,
5757
val visibility: () -> Boolean,
5858
) : Jsonable, Nameable {
59-
private val listeners = mutableListOf<(from: T, to: T) -> Unit>()
59+
private val listeners = mutableListOf<ValueListener<T>>()
6060

6161
var value: T by Delegates.observable(defaultValue) { _, from, to ->
62-
if (from == to) return@observable
63-
listeners.forEach { it(from, to) }
62+
listeners.forEach {
63+
if (it.requiresValueChange && from == to) return@forEach
64+
it.execute(from, to)
65+
}
6466
}
6567

6668
private val isVisible get() = visibility()
@@ -79,18 +81,24 @@ abstract class AbstractSetting<T : Any>(
7981
}
8082

8183
fun onValueChange(block: SafeContext.(from: T, to: T) -> Unit) {
82-
listeners.add { from, to ->
84+
listeners.add(ValueListener(true) { from, to ->
8385
runSafe {
8486
block(from, to)
8587
}
86-
}
88+
})
8789
}
8890

8991
fun onValueChangeUnsafe(block: (from: T, to: T) -> Unit) {
90-
listeners.add(block)
92+
listeners.add(ValueListener(true, block))
93+
}
94+
95+
fun onValueSet(block: (from: T, to: T) -> Unit) {
96+
listeners.add(ValueListener(false, block))
9197
}
9298

9399
private fun reset() {
94100
value = defaultValue
95101
}
102+
103+
class ValueListener <T> (val requiresValueChange: Boolean, val execute: (from: T, to: T) -> Unit)
96104
}

common/src/main/kotlin/com/lambda/config/serializer/KeyCodeSerializer.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ import com.google.gson.*
44
import com.lambda.util.KeyCode
55
import java.lang.reflect.Type
66

7-
// ToDo: Use key lookup table to store actual key names
87
object KeyCodeSerializer : JsonSerializer<KeyCode>, JsonDeserializer<KeyCode> {
98
override fun serialize(
109
src: KeyCode?,
1110
typeOfSrc: Type?,
1211
context: JsonSerializationContext?,
1312
): JsonElement =
1413
src?.let {
15-
JsonPrimitive(it.key)
14+
JsonPrimitive(it.name)
1615
} ?: JsonNull.INSTANCE
1716

1817
override fun deserialize(
1918
json: JsonElement?,
2019
typeOfT: Type?,
2120
context: JsonDeserializationContext?,
2221
): KeyCode =
23-
json?.asInt?.let { KeyCode(it) } ?: throw JsonParseException("Invalid key code format")
22+
json?.asString?.let(KeyCode::fromKeyName) ?: throw JsonParseException("Invalid key code format")
2423
}

common/src/main/kotlin/com/lambda/config/settings/comparable/EnumSetting.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.lambda.config.settings.comparable
22

33
import com.lambda.config.AbstractSetting
4-
import com.lambda.util.Nameable
5-
import java.util.*
64

75
class EnumSetting<T : Enum<T>>(
86
override val name: String,
@@ -14,12 +12,6 @@ class EnumSetting<T : Enum<T>>(
1412
description,
1513
visibility,
1614
) {
17-
val displayValue get() = (value as? Nameable)?.name ?: value.name.split('_').joinToString(" ") { low ->
18-
low.lowercase().replaceFirstChar {
19-
if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString()
20-
}
21-
}
22-
2315
val enumValues: Array<T> = defaultValue.declaringJavaClass.enumConstants
2416

2517
fun next() {

common/src/main/kotlin/com/lambda/event/events/KeyPressEvent.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@ package com.lambda.event.events
33
import com.lambda.event.EventFlow
44
import com.lambda.event.callback.Cancellable
55
import com.lambda.event.callback.ICancellable
6+
import com.lambda.util.KeyCode
67

78
/**
89
* A class representing a [KeyPressEvent] in the event system ([EventFlow]).
910
*
1011
* A [KeyPressEvent] is a type of event that is triggered when a key is pressed.
1112
* It implements [ICancellable] interface, which means the event can be cancelled.
1213
*
13-
* @property key The key code of the key that was pressed.
14+
* @property keyCode The key code of the key that was pressed.
15+
* @property scanCode The scan code of the key that was pressed.
16+
* @property action The action that was performed on the key.
17+
* @property modifiers The modifiers that were active when the key was pressed.
1418
*/
15-
class KeyPressEvent(val key: Int) : ICancellable by Cancellable()
19+
data class KeyPressEvent(
20+
val keyCode: Int,
21+
val scanCode: Int,
22+
val action: Int,
23+
val modifiers: Int,
24+
) : ICancellable by Cancellable() {
25+
val translated: KeyCode
26+
get() = KeyCode.virtualMapUS(keyCode, scanCode)
27+
}

common/src/main/kotlin/com/lambda/graphics/animation/Animation.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class Animation(initialValue: Double, val update: (Double) -> Double) {
1313
operator fun getValue(thisRef: Any?, property: KProperty<*>) =
1414
lerp(prevValue, currValue, mc.partialTicks)
1515

16-
operator fun setValue(thisRef: Any?, property: KProperty<*>, valueIn: Double) {
16+
operator fun setValue(thisRef: Any?, property: KProperty<*>, valueIn: Double) = setValue(valueIn)
17+
18+
fun setValue(valueIn: Double) {
1719
prevValue = valueIn
1820
currValue = valueIn
1921
}

common/src/main/kotlin/com/lambda/graphics/buffer/vao/VAO.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class VAO(
197197
indicesCount = 0
198198
}
199199

200-
fun destroy() {
200+
protected fun finalize() {
201201
runOnGameThread {
202202
glDeleteBuffers(ibo)
203203
glDeleteBuffers(vbo)

common/src/main/kotlin/com/lambda/graphics/gl/Matrices.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ object Matrices {
1515
stack.last().translate(x, y, z)
1616
}
1717

18+
fun scale(x: Double, y: Double, z: Double) {
19+
stack.last().scale(x.toFloat(), y.toFloat(), z.toFloat())
20+
}
21+
1822
fun scale(x: Float, y: Float, z: Float) {
1923
stack.last().scale(x, y, z)
2024
}
@@ -32,6 +36,12 @@ object Matrices {
3236
stack.addLast(Matrix4f(entry))
3337
}
3438

39+
fun push(block: Matrices.() -> Unit) {
40+
push()
41+
this.block()
42+
pop()
43+
}
44+
3545
fun pop() {
3646
stack.removeLast()
3747
}

common/src/main/kotlin/com/lambda/graphics/renderer/IRenderEntry.kt

Lines changed: 0 additions & 31 deletions
This file was deleted.

common/src/main/kotlin/com/lambda/graphics/renderer/IRenderer.kt

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)