mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 23:42:35 -04:00
fix some scoreboard bugs, fix bug in ChatComponent API (legacy string reading)
This commit is contained in:
parent
5f28cceb49
commit
3529ece9ea
@ -16,9 +16,7 @@ package de.bixilon.minosoft.data.player.tab
|
||||
import de.bixilon.minosoft.data.abilities.Gamemodes
|
||||
import de.bixilon.minosoft.data.player.PlayerProperty
|
||||
import de.bixilon.minosoft.data.scoreboard.Team
|
||||
import de.bixilon.minosoft.data.text.BaseComponent
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.data.text.RGBColor
|
||||
import de.bixilon.minosoft.util.KUtil.nullCompare
|
||||
|
||||
data class TabListItem(
|
||||
@ -30,23 +28,7 @@ data class TabListItem(
|
||||
var team: Team? = null,
|
||||
) : Comparable<TabListItem> {
|
||||
val tabDisplayName: ChatComponent
|
||||
get() {
|
||||
val displayName = BaseComponent()
|
||||
team?.prefix?.let {
|
||||
displayName += it
|
||||
}
|
||||
displayName += this.displayName.apply {
|
||||
// ToDo: Set correct formatting code
|
||||
val color = team?.formattingCode
|
||||
if (color is RGBColor) {
|
||||
applyDefaultColor(color)
|
||||
}
|
||||
}
|
||||
team?.suffix?.let {
|
||||
displayName += it
|
||||
}
|
||||
return displayName
|
||||
}
|
||||
get() = team?.decorateName(displayName) ?: displayName
|
||||
|
||||
fun merge(data: TabListItemData) {
|
||||
specialMerge(data)
|
||||
|
@ -17,4 +17,27 @@ class ScoreboardScore(
|
||||
var objective: ScoreboardObjective,
|
||||
val teams: MutableSet<Team>,
|
||||
var value: Int,
|
||||
)
|
||||
) : Comparable<ScoreboardScore> {
|
||||
override fun toString(): String {
|
||||
return "$entity=$value"
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return entity.hashCode()
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is ScoreboardScore) {
|
||||
return false
|
||||
}
|
||||
return entity == other.entity // ToDo: Compare all?
|
||||
}
|
||||
|
||||
override fun compareTo(other: ScoreboardScore): Int {
|
||||
val difference = other.value - value
|
||||
if (difference != 0) {
|
||||
return difference
|
||||
}
|
||||
return entity.compareTo(other.entity) // ToDo
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,10 @@
|
||||
*/
|
||||
package de.bixilon.minosoft.data.scoreboard
|
||||
|
||||
import de.bixilon.minosoft.data.text.BaseComponent
|
||||
import de.bixilon.minosoft.data.text.ChatCode
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.data.text.RGBColor
|
||||
|
||||
data class Team(
|
||||
val name: String,
|
||||
@ -30,4 +32,18 @@ data class Team(
|
||||
override fun toString(): String {
|
||||
return name
|
||||
}
|
||||
|
||||
fun decorateName(name: ChatComponent): ChatComponent {
|
||||
val displayName = BaseComponent()
|
||||
prefix.let { displayName += it }
|
||||
displayName += name.apply {
|
||||
// ToDo: Set correct formatting code
|
||||
val color = formattingCode
|
||||
if (color is RGBColor) {
|
||||
applyDefaultColor(color)
|
||||
}
|
||||
}
|
||||
suffix.let { displayName += it }
|
||||
return displayName
|
||||
}
|
||||
}
|
||||
|
@ -121,11 +121,13 @@ class BaseComponent : ChatComponent {
|
||||
currentFormatting.add(it)
|
||||
}
|
||||
} ?: let {
|
||||
// just append it as special char
|
||||
currentText.append(char)
|
||||
currentText.append(formattingChar)
|
||||
// ignore and ignore next char
|
||||
char = iterator.next()
|
||||
}
|
||||
// check because of above
|
||||
if (char == CharacterIterator.DONE) {
|
||||
break
|
||||
}
|
||||
|
||||
char = iterator.next()
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
package de.bixilon.minosoft.gui.rendering.gui.hud.elements.scoreboard
|
||||
|
||||
import de.bixilon.minosoft.data.scoreboard.ScoreboardScore
|
||||
import de.bixilon.minosoft.data.text.BaseComponent
|
||||
import de.bixilon.minosoft.data.scoreboard.Team
|
||||
import de.bixilon.minosoft.data.text.ChatColors
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.data.text.TextComponent
|
||||
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
|
||||
import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments
|
||||
@ -42,20 +43,16 @@ class ScoreboardScoreElement(
|
||||
}
|
||||
|
||||
override fun forceSilentApply() {
|
||||
val name = BaseComponent()
|
||||
|
||||
// ToDo: Can a score (entity; whatever) can have multiple teams?
|
||||
var team: Team? = null
|
||||
score.teams.iterator().apply {
|
||||
if (!hasNext()) {
|
||||
return@apply
|
||||
}
|
||||
val team = next()
|
||||
name += team.prefix
|
||||
name += team.suffix
|
||||
team = next()
|
||||
}
|
||||
name += score.entity
|
||||
|
||||
nameElement.text = name
|
||||
val entityName = ChatComponent.of(score.entity)
|
||||
nameElement.text = team?.decorateName(entityName) ?: entityName
|
||||
|
||||
scoreElement.text = TextComponent(score.value).color(ChatColors.RED)
|
||||
|
||||
|
@ -42,10 +42,15 @@ class ScoreboardSideElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
|
||||
nameElement.render(offset + Vec2i(HorizontalAlignments.CENTER.getOffset(size.x, nameElement.size.x), 0), z + 2, consumer, options)
|
||||
offset.y += Font.TOTAL_CHAR_HEIGHT
|
||||
|
||||
val scores = scores.toSynchronizedMap().toSortedMap { a, b -> b.value - a.value }
|
||||
val scores = scores.toSynchronizedMap().entries.sortedWith { a, b -> a.key.compareTo(b.key) }
|
||||
var index = 0
|
||||
for ((_, score) in scores) {
|
||||
score.render(offset, z + 2, consumer, options)
|
||||
offset.y += score.size.y
|
||||
|
||||
if (++index >= MAX_SCORES) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return TextElement.LAYERS + 2 // 2 backgrounds
|
||||
@ -77,7 +82,7 @@ class ScoreboardSideElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
|
||||
size.x = maxOf(size.x, element.prefSize.x)
|
||||
}
|
||||
|
||||
size.y += SCORE_HEIGHT * scores.size
|
||||
size.y += SCORE_HEIGHT * minOf(MAX_SCORES, scores.size)
|
||||
|
||||
|
||||
|
||||
@ -112,6 +117,7 @@ class ScoreboardSideElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val MAX_SCORES = 15
|
||||
const val MIN_WIDTH = 30
|
||||
const val SCORE_HEIGHT = Font.TOTAL_CHAR_HEIGHT
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user