Skip to content

Commit a516060

Browse files
committed
many misc things
1 parent b476148 commit a516060

File tree

13 files changed

+210
-99
lines changed

13 files changed

+210
-99
lines changed

common/src/main/kotlin/com/lambda/core/Loader.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.lambda.interaction.PlayerPacketManager
1212
import com.lambda.interaction.RotationManager
1313
import com.lambda.interaction.material.ContainerManager
1414
import com.lambda.module.ModuleRegistry
15+
import com.lambda.newgui.GuiManager
1516
import com.lambda.sound.SoundRegistry
1617
import com.lambda.util.Communication.ascii
1718
import kotlin.system.measureTimeMillis
@@ -25,6 +26,7 @@ object Loader {
2526
get() = "${(System.currentTimeMillis() - started).toDuration(DurationUnit.MILLISECONDS)}"
2627

2728
private val loadables = listOf(
29+
GuiManager,
2830
ModuleRegistry,
2931
CommandRegistry,
3032
RotationManager,

common/src/main/kotlin/com/lambda/module/modules/client/GuiSettings.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ object GuiSettings : Module(
3030
val backgroundColor by setting("Background Color", Color(50, 50, 50, 150), visibility = { page == Page.Colors })
3131
val shade by setting("Shade", true, visibility = { page == Page.Colors })
3232
val shadeBackground by setting("Shade Background", true, visibility = { page == Page.Colors })
33-
val colorWidth by setting("Shade Width", 400.0, 10.0..1000.0, 10.0, visibility = { page == Page.Colors })
34-
val colorHeight by setting("Shade Height", 400.0, 10.0..1000.0, 10.0, visibility = { page == Page.Colors })
33+
val colorWidth by setting("Shade Width", 200.0, 10.0..1000.0, 10.0, visibility = { page == Page.Colors })
34+
val colorHeight by setting("Shade Height", 200.0, 10.0..1000.0, 10.0, visibility = { page == Page.Colors })
3535
val colorSpeed by setting("Color Speed", 1.0, 0.1..10.0, 0.1, visibility = { page == Page.Colors })
3636

3737
val mainColor: Color get() = if (shade) Color.WHITE else primaryColor

common/src/main/kotlin/com/lambda/module/modules/client/NewCGui.kt

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ package com.lambda.module.modules.client
33
import com.lambda.module.Module
44
import com.lambda.module.ModuleRegistry
55
import com.lambda.module.tag.ModuleTag
6-
import com.lambda.newgui.LambdaScreen.Companion.gui
7-
import com.lambda.newgui.LambdaScreen.Companion.toScreen
8-
import com.lambda.newgui.component.window.Window
9-
import com.lambda.newgui.component.window.Window.Companion.window
6+
import com.lambda.newgui.ScreenLayout.Companion.gui
107
import com.lambda.newgui.impl.clickgui.ModuleLayout.Companion.moduleLayout
8+
import com.lambda.newgui.impl.clickgui.ModuleWindow.Companion.moduleWindow
119
import com.lambda.util.math.Vec2d
1210
import com.lambda.util.math.setAlpha
1311
import java.awt.Color
@@ -25,36 +23,35 @@ object NewCGui : Module(
2523
val roundRadius by setting("Round Radius", 2.0, 0.0..10.0, 0.1)
2624

2725
val titleBackgroundColor by setting("Title Background Color", Color.WHITE.setAlpha(0.4))
28-
val backgroundColor by setting("Background Color", Color.WHITE.setAlpha(0.2))
26+
val backgroundColor by setting("Background Color", Color.WHITE.setAlpha(0.25))
2927
val backgroundShade by setting("Background Shade", true)
3028

3129
val outline by setting("Outline", true)
3230
val outlineWidth by setting("Outline Width", 10.0, 1.0..10.0, 0.1) { outline }
3331
val outlineColor by setting("Outline Color", Color.WHITE.setAlpha(0.6)) { outline }
3432
val outlineShade by setting("Outline Shade", true) { outline }
3533

36-
private val SCREEN by lazy {
37-
gui {
38-
val tags = ModuleTag.defaults
39-
val modules = ModuleRegistry.modules
34+
private val SCREEN get() = gui("New Click Gui") {
35+
val tags = ModuleTag.defaults
36+
val modules = ModuleRegistry.modules
4037

41-
tags.forEachIndexed { i, tag ->
42-
val windowPosition = Vec2d.ONE * 20.0 + Vec2d.RIGHT * ((115.0 * i) + (i + 1) * 4)
38+
tags.forEachIndexed { i, tag ->
39+
val windowPosition = Vec2d.ONE * 20.0 + Vec2d.RIGHT * ((115.0 * i) + (i + 1) * 4)
4340

44-
window(position = windowPosition, title = tag.name, autoResize = Window.AutoResize.ByConfig) {
45-
val tagModules = modules.filter { it.defaultTags.first() == tag }
41+
moduleWindow(tag, windowPosition) {
42+
val tagModules = modules.filter { it.defaultTags.first() == tag }
4643

47-
tagModules.forEach { module ->
48-
moduleLayout(module)
49-
}
44+
tagModules.forEach { module ->
45+
moduleLayout(module)
5046
}
5147
}
52-
}.toScreen("New Click Gui")
48+
}
5349
}
5450

5551
init {
5652
onEnable {
5753
SCREEN.show()
54+
toggle()
5855
}
5956
}
6057
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.lambda.newgui
2+
3+
import com.lambda.core.Loadable
4+
import com.lambda.module.Module
5+
import com.lambda.newgui.component.core.UIBuilder
6+
import com.lambda.newgui.component.layout.Layout
7+
import com.lambda.newgui.impl.clickgui.ModuleLayout.Companion.moduleLayout
8+
9+
object GuiManager : Loadable {
10+
val typeMap = mutableMapOf<Class<*>, (owner: Layout, converted: Any) -> Layout>()
11+
12+
private inline fun <reified T> typeAdapter(noinline block: (Layout, T) -> Layout) {
13+
typeMap[T::class.java] = { owner, converted -> block(owner, converted as T) }
14+
}
15+
16+
override fun load(): String {
17+
// Example, not meant to be used
18+
typeAdapter<Module> { owner, ref ->
19+
owner.moduleLayout(ref)
20+
}
21+
22+
return super.load()
23+
}
24+
25+
/**
26+
* Attempts to convert the given [reference] to the [Layout]
27+
*
28+
* Or throws [IllegalStateException] if there's no registered ui adapter for the type of the [reference]
29+
*/
30+
@UIBuilder
31+
inline fun <reified T : Any> Layout.layoutOf(reference: T, block: Layout.() -> Unit = {}): Layout {
32+
val clazz = T::class.java
33+
val adapter = typeMap[clazz] ?: throw IllegalArgumentException("Unable to convert ${clazz.simpleName} to a layout")
34+
return adapter(this, reference).apply(children::add).apply(block)
35+
}
36+
}

common/src/main/kotlin/com/lambda/newgui/LambdaScreen.kt

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import net.minecraft.text.Text
2424
*/
2525
class LambdaScreen(
2626
override val name: String,
27-
val layout: Layout
27+
val layout: ScreenLayout
2828
) : Screen(Text.of(name)), Nameable, Muteable {
2929
override val isMuted: Boolean get() = !isOpen
3030

@@ -111,22 +111,4 @@ class LambdaScreen(
111111
val uv = mcMouse / mcWindow
112112
return uv * screenSize
113113
}
114-
115-
companion object {
116-
/**
117-
* Creates gui layout
118-
*/
119-
@UIBuilder
120-
fun gui(block: Layout.() -> Unit) =
121-
Layout(owner = null, useBatching = false, batchChildren = true).apply {
122-
onRender {
123-
size = RenderMain.screenSize
124-
}
125-
}.apply(block)
126-
127-
/**
128-
* Converts this [Layout] to a minecraft-typed [Screen] represented by the [LambdaScreen] class
129-
*/
130-
fun Layout.toScreen(name: String) = LambdaScreen(name, this)
131-
}
132114
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.lambda.newgui
2+
3+
import com.lambda.graphics.RenderMain
4+
import com.lambda.newgui.component.core.UIBuilder
5+
import com.lambda.newgui.component.layout.Layout
6+
7+
class ScreenLayout : Layout(owner = null, useBatching = false, batchChildren = true) {
8+
init {
9+
onRender {
10+
size = RenderMain.screenSize
11+
}
12+
}
13+
14+
companion object {
15+
/**
16+
* Creates gui layout
17+
*/
18+
@UIBuilder
19+
fun gui(name: String, block: ScreenLayout.() -> Unit) =
20+
LambdaScreen(name, ScreenLayout().apply(block))
21+
}
22+
}

common/src/main/kotlin/com/lambda/newgui/component/layout/Layout.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ open class Layout(
120120

121121
// Structure
122122
val children = mutableListOf<Layout>()
123-
protected var selectedChild: Layout? = null
123+
var selectedChild: Layout? = null
124124

125125
// Inputs
126126
protected var mousePosition = Vec2d.ZERO

common/src/main/kotlin/com/lambda/newgui/component/window/TitleBar.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class TitleBar(
3434
private var dragOffset: Vec2d? = null
3535

3636
init {
37+
overrideSize(
38+
owner::renderWidth,
39+
NewCGui::titleBarHeight
40+
)
41+
3742
onShow {
3843
dragOffset = null
3944
}

0 commit comments

Comments
 (0)