forked from CleverNucleus/data-attributes
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat/semver] Stage new beta and add all ui changes
- Loading branch information
1 parent
b82a84b
commit d9d91a1
Showing
14 changed files
with
517 additions
and
394 deletions.
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
## Fixes 🍋 | ||
- Fixed attribute functions not being able to be edited (and that were default). | ||
## Additions 🍎 | ||
- Added saved state for collapsed entries (session based, saved until game relaunch) | ||
## Changes 🍐 | ||
- Applied a different method to updating UI components. | ||
- Most entries sync, but there is still some work to do, so it will stay as beta until the rest of the issues are figured out. |
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
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
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
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
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
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/com/bibireden/data_attributes/ui/components/config/ConfigDockComponent.kt
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,28 @@ | ||
package com.bibireden.data_attributes.ui.components.config | ||
|
||
import com.bibireden.data_attributes.ui.components.buttons.ButtonComponents | ||
import com.bibireden.data_attributes.ui.renderers.ButtonRenderers | ||
import io.wispforest.owo.ui.component.ButtonComponent | ||
import io.wispforest.owo.ui.component.Components | ||
import io.wispforest.owo.ui.container.FlowLayout | ||
import io.wispforest.owo.ui.core.Sizing | ||
import io.wispforest.owo.ui.core.VerticalAlignment | ||
import net.minecraft.text.Text | ||
import org.jetbrains.annotations.ApiStatus | ||
|
||
@ApiStatus.Internal | ||
@Suppress("UnstableApiUsage") | ||
class ConfigDockComponent(private val defaultProperties: ConfigDefaultProperties) : FlowLayout(Sizing.fill(100), Sizing.fixed(15), Algorithm.HORIZONTAL) { | ||
class ConfigDefaultProperties(val onRemoveToggled: (ConfigDockComponent, ButtonComponent) -> Unit, val onEditToggled: (ConfigDockComponent, ButtonComponent) -> Unit) | ||
|
||
init { | ||
verticalAlignment(VerticalAlignment.BOTTOM) | ||
gap(10) | ||
id("dock") | ||
|
||
child(ButtonComponents.remove { defaultProperties.onRemoveToggled(this, it) } | ||
.renderer(ButtonRenderers.STANDARD)) | ||
child(Components.button(Text.translatable("text.config.data_attributes.data_entry.edit")) { defaultProperties.onEditToggled(this, it) } | ||
.renderer(ButtonRenderers.STANDARD)) | ||
} | ||
} |
147 changes: 147 additions & 0 deletions
147
...otlin/com/bibireden/data_attributes/ui/components/config/entities/EntityTypesComponent.kt
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,147 @@ | ||
package com.bibireden.data_attributes.ui.components.config.entities | ||
|
||
import com.bibireden.data_attributes.DataAttributesClient | ||
import com.bibireden.data_attributes.api.DataAttributesAPI | ||
import com.bibireden.data_attributes.config.DataAttributesConfigProviders.registryEntryToText | ||
import com.bibireden.data_attributes.config.DataAttributesConfigProviders.textBoxComponent | ||
import com.bibireden.data_attributes.config.Validators | ||
import com.bibireden.data_attributes.config.entities.EntityTypeData | ||
import com.bibireden.data_attributes.config.entities.EntityTypeEntry | ||
import com.bibireden.data_attributes.ext.round | ||
import com.bibireden.data_attributes.ui.components.buttons.ButtonComponents | ||
import com.bibireden.data_attributes.ui.components.config.AttributeConfigComponent | ||
import com.bibireden.data_attributes.ui.components.config.ConfigDockComponent | ||
import com.bibireden.data_attributes.ui.components.entries.DataEntryComponent | ||
import com.bibireden.data_attributes.ui.components.entries.EntryComponents | ||
import com.bibireden.data_attributes.ui.components.fields.FieldComponents | ||
import com.bibireden.data_attributes.ui.config.providers.EntityTypesProviderV2 | ||
import com.bibireden.data_attributes.ui.renderers.ButtonRenderers | ||
import io.wispforest.owo.config.Option | ||
import io.wispforest.owo.config.ui.component.SearchAnchorComponent | ||
import io.wispforest.owo.ui.component.Components | ||
import io.wispforest.owo.ui.component.LabelComponent | ||
import io.wispforest.owo.ui.component.TextBoxComponent | ||
import io.wispforest.owo.ui.container.CollapsibleContainer | ||
import io.wispforest.owo.ui.container.Containers | ||
import io.wispforest.owo.ui.container.FlowLayout | ||
import io.wispforest.owo.ui.core.Sizing | ||
import io.wispforest.owo.ui.core.VerticalAlignment | ||
import net.minecraft.entity.EntityType | ||
import net.minecraft.entity.LivingEntity | ||
import net.minecraft.entity.attribute.ClampedEntityAttribute | ||
import net.minecraft.entity.attribute.DefaultAttributeRegistry | ||
import net.minecraft.entity.attribute.EntityAttribute | ||
import net.minecraft.registry.Registries | ||
import net.minecraft.registry.Registry | ||
import net.minecraft.text.Text | ||
import net.minecraft.util.Identifier | ||
|
||
class EntityTypesComponent(override var identifier: Identifier, private var parentId: Identifier, private var entry: EntityTypeEntry, private val provider: EntityTypesProviderV2) | ||
: CollapsibleContainer(Sizing.content(), Sizing.content(), Text.of("<n/a>"), DataAttributesClient.UI_STATE.collapsible.entityTypeEntries[parentId.toString()]?.get(identifier.toString()) ?: true), AttributeConfigComponent<EntityAttribute> { | ||
|
||
override val registry: Registry<EntityAttribute> = Registries.ATTRIBUTE | ||
|
||
override val isDefault: Boolean | ||
get() = provider.backing[parentId]?.data?.get(identifier) == null | ||
|
||
private fun updateSearchAnchor() { | ||
childById(SearchAnchorComponent::class.java, "search-anchor")?.remove() | ||
child(SearchAnchorComponent(titleLayout(), Option.Key.ROOT, { identifier.toString() }, { Text.translatable(identifier.toTranslationKey()).toString() }).id("search-anchor")) | ||
} | ||
|
||
private fun updateTextLabel() { | ||
titleLayout().children().filterIsInstance<LabelComponent>().first().text(registryEntryToText(identifier, registry, { it.translationKey }, isDefault)) | ||
} | ||
|
||
override fun update() { | ||
titleLayout().tooltip(null) | ||
when { | ||
!isRegistered -> titleLayout().tooltip(Text.translatable("text.config.data_attributes.data_entry.invalid")) | ||
isDefault -> titleLayout().tooltip(Text.translatable("text.config.data_attributes_data_entry.default")) | ||
} | ||
|
||
// find fallback | ||
try { | ||
entry.fallback = Registries.ENTITY_TYPE.get(parentId) | ||
?.let { entityType -> registry.get(identifier)?.let(DefaultAttributeRegistry.get(entityType as EntityType<LivingEntity>)::getBaseValue) } | ||
?.round(2) | ||
} | ||
catch (_: IllegalArgumentException) { | ||
entry.fallback = 0.0 | ||
} | ||
|
||
val fallback = entry.fallback | ||
if (fallback != null) { | ||
childById(FlowLayout::class.java, "fallback")?.remove() | ||
child(textBoxComponent(Text.translatable("text.config.data_attributes.data_entry.fallback"), fallback, Validators::isNumeric).id("fallback")) | ||
} | ||
|
||
updateTextLabel() | ||
updateSearchAnchor() | ||
} | ||
|
||
|
||
private val valueEntry: DataEntryComponent<Double> = EntryComponents.double(Text.translatable("text.config.data_attributes.data_entry.entity_types.value"), DataEntryComponent.Properties({ updateEntryToBacking(entry.copy(value = it)) }), entry.value.toString()).also { | ||
val attribute = registryEntry | ||
if (attribute is ClampedEntityAttribute) { | ||
it.tooltip(Text.translatable("text.config.data_attributes.data_entry.entity_type_value", identifier, attribute.minValue, attribute.maxValue)) | ||
} | ||
} | ||
|
||
private fun updateEntryToBacking(entry: EntityTypeEntry) { | ||
val etd = provider.backing[parentId] ?: return | ||
val mapping = etd.data.toMutableMap() | ||
mapping[identifier] = entry | ||
provider.backing[parentId] = EntityTypeData(mapping) | ||
|
||
update() | ||
} | ||
|
||
fun updateParent(parentId: Identifier) { this.parentId = parentId } | ||
|
||
|
||
init { | ||
onToggled().subscribe { DataAttributesClient.UI_STATE.collapsible.entityTypeEntries.computeIfAbsent(parentId.toString()) { mutableMapOf() } [identifier.toString()] = it } | ||
|
||
child(ConfigDockComponent(ConfigDockComponent.ConfigDefaultProperties({ _, _ -> | ||
val entry = provider.backing[parentId]?.data?.toMutableMap() ?: return@ConfigDefaultProperties | ||
if (entry.remove(identifier) != null) { | ||
val defaultEntry = DataAttributesAPI.serverManager.defaults.types.entries[parentId]?.get(identifier) | ||
if (defaultEntry != null) { | ||
valueEntry.textbox.text = defaultEntry.value.toString() | ||
} | ||
else remove() | ||
|
||
provider.backing[parentId] = EntityTypeData(entry) | ||
|
||
update() | ||
} | ||
}, {_, _ -> | ||
if (childById(FlowLayout::class.java, "edit-field") == null) { | ||
val field = FieldComponents.identifier( | ||
{ newId, _ -> | ||
val entry = provider.backing[parentId]?.data?.toMutableMap() ?: return@identifier | ||
if (entry.containsKey(newId) || !registry.containsId(newId)) return@identifier | ||
|
||
entry[newId] = entry.remove(identifier) ?: return@identifier | ||
provider.backing[parentId] = EntityTypeData(entry) | ||
|
||
identifier = newId | ||
|
||
update() | ||
}, | ||
autocomplete = Registries.ATTRIBUTE.ids | ||
) | ||
|
||
field.textBox.predicate = { provider.backing[parentId]?.data?.get(it) == null && registry.containsId(it) } | ||
|
||
child(0, field) | ||
} | ||
} | ||
))) | ||
|
||
valueEntry.also(::child) | ||
|
||
update() | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
...com/bibireden/data_attributes/ui/components/config/entities/EntityTypesHeaderComponent.kt
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,126 @@ | ||
package com.bibireden.data_attributes.ui.components.config.entities | ||
|
||
import com.bibireden.data_attributes.DataAttributesClient | ||
import com.bibireden.data_attributes.api.DataAttributesAPI | ||
import com.bibireden.data_attributes.config.DataAttributesConfigProviders.registryEntryToText | ||
import com.bibireden.data_attributes.config.entities.EntityTypeData | ||
import com.bibireden.data_attributes.config.entities.EntityTypeEntry | ||
import com.bibireden.data_attributes.ui.components.CollapsibleFoldableContainer | ||
import com.bibireden.data_attributes.ui.components.buttons.ButtonComponents | ||
import com.bibireden.data_attributes.ui.components.config.AttributeConfigComponent | ||
import com.bibireden.data_attributes.ui.components.config.ConfigDockComponent | ||
import com.bibireden.data_attributes.ui.components.config.function.AttributeFunctionComponent | ||
import com.bibireden.data_attributes.ui.components.fields.FieldComponents | ||
import com.bibireden.data_attributes.ui.config.providers.EntityTypesProviderV2 | ||
import com.bibireden.data_attributes.ui.renderers.ButtonRenderers | ||
import io.wispforest.owo.config.Option | ||
import io.wispforest.owo.config.ui.component.SearchAnchorComponent | ||
import io.wispforest.owo.ui.component.Components | ||
import io.wispforest.owo.ui.component.LabelComponent | ||
import io.wispforest.owo.ui.container.Containers | ||
import io.wispforest.owo.ui.container.FlowLayout | ||
import io.wispforest.owo.ui.core.Sizing | ||
import io.wispforest.owo.ui.core.VerticalAlignment | ||
import net.minecraft.entity.EntityType | ||
import net.minecraft.entity.attribute.EntityAttribute | ||
import net.minecraft.registry.Registries | ||
import net.minecraft.registry.Registry | ||
import net.minecraft.text.Text | ||
import net.minecraft.util.Identifier | ||
|
||
class EntityTypesHeaderComponent(override var identifier: Identifier, private val entityTypes: MutableMap<Identifier, EntityTypeEntry>, private val provider: EntityTypesProviderV2) | ||
: CollapsibleFoldableContainer(Sizing.content(), Sizing.content(), Text.of("<n/a>"), DataAttributesClient.UI_STATE.collapsible.entityTypeHeaders[identifier.toString()] ?: true), AttributeConfigComponent<EntityType<*>> { | ||
|
||
override val registry: Registry<EntityType<*>> = Registries.ENTITY_TYPE | ||
|
||
override val isDefault: Boolean | ||
get() = !provider.backing.containsKey(identifier) | ||
|
||
private fun updateSearchAnchor() { | ||
childById(SearchAnchorComponent::class.java, "search-anchor")?.remove() | ||
child(SearchAnchorComponent(titleLayout(), Option.Key.ROOT, { identifier.toString() }, { Text.translatable(identifier.toTranslationKey()).toString() }).id("search-anchor")) | ||
} | ||
|
||
private fun updateTextLabel() { | ||
titleLayout().children().filterIsInstance<LabelComponent>().first().text(registryEntryToText(identifier, registry, { it.translationKey }, isDefault)) | ||
} | ||
|
||
private fun createEntry(entryId: Identifier, entry: EntityTypeEntry): EntityTypesComponent = childById(EntityTypesComponent::class.java, "entry#$entryId") ?: EntityTypesComponent(entryId, identifier, entry, provider).also { it.id("entry#$entryId")}.also(::child) | ||
|
||
override fun update() { | ||
titleLayout().tooltip(null) | ||
when { | ||
!isRegistered -> { | ||
titleLayout().tooltip(Text.translatable("text.config.data_attributes.data_entry.invalid")) | ||
} | ||
isDefault -> { | ||
titleLayout().tooltip(Text.translatable("text.config.data_attributes_data_entry.default")) | ||
} | ||
} | ||
updateTextLabel() | ||
updateSearchAnchor() | ||
} | ||
|
||
fun addEntityTypes(entityTypes: MutableMap<Identifier, EntityTypeEntry>) { | ||
for ((id, types) in entityTypes) createEntry(id, types) | ||
} | ||
|
||
init { | ||
onToggled().subscribe { DataAttributesClient.UI_STATE.collapsible.entityTypeHeaders[identifier.toString()] = it } | ||
|
||
child( | ||
ConfigDockComponent(ConfigDockComponent.ConfigDefaultProperties({ _, _ -> | ||
provider.backing.remove(identifier) | ||
|
||
val entries = DataAttributesAPI.serverManager.defaults.types.entries[identifier] | ||
|
||
if (entries != null) { | ||
forEachDescendant { if (it is EntityTypesComponent) { if (entries.containsKey(it.identifier)) it.update() else it.remove() } } | ||
update() | ||
} | ||
else remove() | ||
}) | ||
{ _, _ -> | ||
if (childById(FlowLayout::class.java, "edit-field") == null) { | ||
val field = FieldComponents.identifier( | ||
{ newId, _ -> | ||
if (provider.backing.containsKey(newId) || !registry.containsId(newId)) return@identifier | ||
|
||
provider.backing.remove(identifier)?.let { provider.backing[newId] = it } | ||
|
||
identifier = newId | ||
|
||
children().filterIsInstance<EntityTypesComponent>().forEach { it.updateParent(identifier) } | ||
|
||
update() | ||
}, | ||
autocomplete = registry.ids | ||
) | ||
|
||
field.textBox.predicate = { provider.backing[identifier]?.data?.get(it) == null && registry.containsId(it) } | ||
|
||
child(0, field) | ||
} | ||
}).child( | ||
Components.button(Text.translatable("text.config.data_attributes.buttons.add")) { | ||
val map = provider.backing[identifier]?.data?.toMutableMap() ?: mutableMapOf() | ||
val childId = Identifier("unknown") | ||
val entry = EntityTypeEntry() | ||
map[childId] = entry | ||
provider.backing[identifier] = EntityTypeData(map) | ||
|
||
child(1, EntityTypesComponent(childId, identifier, entry, provider)) | ||
|
||
update() | ||
} | ||
.renderer(ButtonRenderers.STANDARD) | ||
.horizontalSizing(Sizing.content()) | ||
.verticalSizing(Sizing.fixed(20)) | ||
) | ||
) | ||
|
||
addEntityTypes(this.entityTypes) | ||
|
||
update() | ||
} | ||
} |
Oops, something went wrong.