feat: add colour config options
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
package moe.nea.firmament.features.items
|
||||
|
||||
import io.github.notenoughupdates.moulconfig.ChromaColour
|
||||
import me.shedaniel.math.Color
|
||||
import net.minecraft.util.hit.BlockHitResult
|
||||
import moe.nea.firmament.annotations.Subscribe
|
||||
import moe.nea.firmament.events.WorldRenderLastEvent
|
||||
import moe.nea.firmament.features.FirmamentFeature
|
||||
import moe.nea.firmament.gui.config.ManagedConfig
|
||||
import moe.nea.firmament.util.MC
|
||||
import net.minecraft.util.hit.BlockHitResult
|
||||
import moe.nea.firmament.events.WorldRenderLastEvent
|
||||
import moe.nea.firmament.util.extraAttributes
|
||||
import moe.nea.firmament.util.render.RenderInWorldContext
|
||||
import moe.nea.firmament.util.skyBlockId
|
||||
@@ -19,6 +20,7 @@ object EtherwarpOverlay : FirmamentFeature {
|
||||
object TConfig : ManagedConfig(identifier, Category.ITEMS) {
|
||||
var etherwarpOverlay by toggle("etherwarp-overlay") { false }
|
||||
var cube by toggle("cube") { true }
|
||||
val cubeColour by colour("cube-colour") { ChromaColour.fromStaticRGB(172, 0, 255, 60) }
|
||||
var wireframe by toggle("wireframe") { false }
|
||||
}
|
||||
|
||||
@@ -44,7 +46,7 @@ object EtherwarpOverlay : FirmamentFeature {
|
||||
if (!world.getBlockState(blockPos.up()).isAir) return
|
||||
if (!world.getBlockState(blockPos.up(2)).isAir) return
|
||||
RenderInWorldContext.renderInWorld(event) {
|
||||
if (TConfig.cube) block(blockPos, Color.ofRGBA(172, 0, 255, 60).color)
|
||||
if (TConfig.cube) block(blockPos, TConfig.cubeColour.getEffectiveColourRGB())
|
||||
if (TConfig.wireframe) wireframeCube(blockPos, 10f)
|
||||
}
|
||||
}
|
||||
|
||||
82
src/main/kotlin/gui/config/ColourHandler.kt
Normal file
82
src/main/kotlin/gui/config/ColourHandler.kt
Normal file
@@ -0,0 +1,82 @@
|
||||
package moe.nea.firmament.gui.config
|
||||
|
||||
import io.github.notenoughupdates.moulconfig.ChromaColour
|
||||
import io.github.notenoughupdates.moulconfig.gui.component.ColorSelectComponent
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
|
||||
class ColourHandler(val config: ManagedConfig) :
|
||||
ManagedConfig.OptionHandler<ChromaColour> {
|
||||
@Serializable
|
||||
data class ChromaDelegate(
|
||||
@SerialName("h")
|
||||
val hue: Float,
|
||||
@SerialName("s")
|
||||
val saturation: Float,
|
||||
@SerialName("b")
|
||||
val brightness: Float,
|
||||
@SerialName("a")
|
||||
val alpha: Int,
|
||||
@SerialName("c")
|
||||
val timeForFullRotationInMillis: Int,
|
||||
) {
|
||||
constructor(delegate: ChromaColour) : this(
|
||||
delegate.hue,
|
||||
delegate.saturation,
|
||||
delegate.brightness,
|
||||
delegate.alpha,
|
||||
delegate.timeForFullRotationInMillis
|
||||
)
|
||||
|
||||
fun into(): ChromaColour = ChromaColour(hue, saturation, brightness, alpha, timeForFullRotationInMillis)
|
||||
}
|
||||
|
||||
object ChromaSerializer : KSerializer<ChromaColour> {
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = SerialDescriptor("FirmChromaColour", ChromaDelegate.serializer().descriptor)
|
||||
|
||||
override fun serialize(
|
||||
encoder: Encoder,
|
||||
value: ChromaColour
|
||||
) {
|
||||
encoder.encodeSerializableValue(ChromaDelegate.serializer(), ChromaDelegate(value))
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): ChromaColour {
|
||||
return decoder.decodeSerializableValue(ChromaDelegate.serializer()).into()
|
||||
}
|
||||
}
|
||||
|
||||
override fun toJson(element: ChromaColour): JsonElement? {
|
||||
return Json.encodeToJsonElement(ChromaSerializer, element)
|
||||
}
|
||||
|
||||
override fun fromJson(element: JsonElement): ChromaColour {
|
||||
return Json.decodeFromJsonElement(ChromaSerializer, element)
|
||||
}
|
||||
|
||||
override fun emitGuiElements(
|
||||
opt: ManagedOption<ChromaColour>,
|
||||
guiAppender: GuiAppender
|
||||
) {
|
||||
guiAppender.appendLabeledRow(
|
||||
opt.labelText,
|
||||
ColorSelectComponent(
|
||||
0,
|
||||
0,
|
||||
opt.value.toLegacyString(),
|
||||
{
|
||||
opt.value = ChromaColour.forLegacyString(it)
|
||||
config.save()
|
||||
},
|
||||
{ }
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package moe.nea.firmament.gui.config
|
||||
|
||||
import com.mojang.serialization.Codec
|
||||
import io.github.notenoughupdates.moulconfig.ChromaColour
|
||||
import io.github.notenoughupdates.moulconfig.gui.CloseEventListener
|
||||
import io.github.notenoughupdates.moulconfig.gui.GuiComponentWrapper
|
||||
import io.github.notenoughupdates.moulconfig.gui.GuiContext
|
||||
@@ -118,6 +119,10 @@ abstract class ManagedConfig(
|
||||
return option(propertyName, default, BooleanHandler(this))
|
||||
}
|
||||
|
||||
protected fun colour(propertyName: String, default: ()-> ChromaColour) : ManagedOption<ChromaColour> {
|
||||
return option(propertyName, default, ColourHandler(this))
|
||||
}
|
||||
|
||||
protected fun <E> choice(
|
||||
propertyName: String,
|
||||
enumClass: Class<E>,
|
||||
|
||||
10
src/main/kotlin/util/ChromaColourUtil.kt
Normal file
10
src/main/kotlin/util/ChromaColourUtil.kt
Normal file
@@ -0,0 +1,10 @@
|
||||
package moe.nea.firmament.util
|
||||
|
||||
import io.github.notenoughupdates.moulconfig.ChromaColour
|
||||
import java.awt.Color
|
||||
|
||||
fun ChromaColour.getRGBAWithoutAnimation() =
|
||||
Color(ChromaColour.specialToSimpleRGB(toLegacyString()), true)
|
||||
|
||||
fun Color.toChromaWithoutAnimation(timeForFullRotationInMillis: Int = 0) =
|
||||
ChromaColour.fromRGB(red, green, blue, timeForFullRotationInMillis, alpha)
|
||||
Reference in New Issue
Block a user