blob: 16eb0a4a8439de108f83737cecec34816048e7f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
package moe.nea.firmament.gui.config
import io.github.notenoughupdates.moulconfig.observer.ObservableList
import io.github.notenoughupdates.moulconfig.xml.Bind
import net.minecraft.client.gui.screen.Screen
import net.minecraft.text.Text
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.MoulConfigUtils
import moe.nea.firmament.util.ScreenUtil.setScreenLater
object AllConfigsGui {
//
// val allConfigs
// get() = listOf(
// RepoManager.Config
// ) + FeatureManager.allFeatures.mapNotNull { it.config }
object ConfigConfig : ManagedConfig("configconfig", Category.META) {
val enableYacl by toggle("enable-yacl") { false }
val enableMoulConfig by toggle("enable-moulconfig") { false }
}
fun <T> List<T>.toObservableList(): ObservableList<T> = ObservableList(this)
class CategoryMapping(val category: ManagedConfig.Category) {
@get:Bind("configs")
val configs = category.configs.map { EntryMapping(it) }.toObservableList()
@Bind
fun name() = category.labelText.string
@Bind
fun close() {
MC.screen?.close()
}
class EntryMapping(val config: ManagedConfig) {
@Bind
fun name() = Text.translatable("firmament.config.${config.name}").string
@Bind
fun openEditor() {
config.showConfigEditor(MC.screen)
}
}
}
class CategoryView {
@get:Bind("categories")
val categories = ManagedConfig.Category.entries
.map { CategoryEntry(it) }
.toObservableList()
class CategoryEntry(val category: ManagedConfig.Category) {
@Bind
fun name() = category.labelText.string
@Bind
fun open() {
MC.screen = MoulConfigUtils.loadScreen("config/category", CategoryMapping(category), MC.screen)
}
}
}
fun makeBuiltInScreen(parent: Screen? = null): Screen {
return MoulConfigUtils.loadScreen("config/main", CategoryView(), parent)
}
fun makeScreen(parent: Screen? = null): Screen {
val wantedKey = when {
ConfigConfig.enableMoulConfig -> "moulconfig"
ConfigConfig.enableYacl -> "yacl"
else -> "builtin"
}
val provider = FirmamentConfigScreenProvider.providers.find { it.key == wantedKey }
?: FirmamentConfigScreenProvider.providers.first()
return provider.open(parent)
}
fun showAllGuis() {
setScreenLater(makeScreen())
}
}
|