mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-10 07:48:29 -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.abilities.Gamemodes
|
||||||
import de.bixilon.minosoft.data.player.PlayerProperty
|
import de.bixilon.minosoft.data.player.PlayerProperty
|
||||||
import de.bixilon.minosoft.data.scoreboard.Team
|
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.ChatComponent
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
|
||||||
import de.bixilon.minosoft.util.KUtil.nullCompare
|
import de.bixilon.minosoft.util.KUtil.nullCompare
|
||||||
|
|
||||||
data class TabListItem(
|
data class TabListItem(
|
||||||
@ -30,23 +28,7 @@ data class TabListItem(
|
|||||||
var team: Team? = null,
|
var team: Team? = null,
|
||||||
) : Comparable<TabListItem> {
|
) : Comparable<TabListItem> {
|
||||||
val tabDisplayName: ChatComponent
|
val tabDisplayName: ChatComponent
|
||||||
get() {
|
get() = team?.decorateName(displayName) ?: displayName
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
fun merge(data: TabListItemData) {
|
fun merge(data: TabListItemData) {
|
||||||
specialMerge(data)
|
specialMerge(data)
|
||||||
|
@ -17,4 +17,27 @@ class ScoreboardScore(
|
|||||||
var objective: ScoreboardObjective,
|
var objective: ScoreboardObjective,
|
||||||
val teams: MutableSet<Team>,
|
val teams: MutableSet<Team>,
|
||||||
var value: Int,
|
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
|
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.ChatCode
|
||||||
import de.bixilon.minosoft.data.text.ChatComponent
|
import de.bixilon.minosoft.data.text.ChatComponent
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
|
||||||
data class Team(
|
data class Team(
|
||||||
val name: String,
|
val name: String,
|
||||||
@ -30,4 +32,18 @@ data class Team(
|
|||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return name
|
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)
|
currentFormatting.add(it)
|
||||||
}
|
}
|
||||||
} ?: let {
|
} ?: let {
|
||||||
// just append it as special char
|
// ignore and ignore next char
|
||||||
currentText.append(char)
|
char = iterator.next()
|
||||||
currentText.append(formattingChar)
|
}
|
||||||
|
// check because of above
|
||||||
|
if (char == CharacterIterator.DONE) {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
char = iterator.next()
|
char = iterator.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.gui.hud.elements.scoreboard
|
package de.bixilon.minosoft.gui.rendering.gui.hud.elements.scoreboard
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.scoreboard.ScoreboardScore
|
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.ChatColors
|
||||||
|
import de.bixilon.minosoft.data.text.ChatComponent
|
||||||
import de.bixilon.minosoft.data.text.TextComponent
|
import de.bixilon.minosoft.data.text.TextComponent
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
|
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments
|
import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments
|
||||||
@ -42,20 +43,16 @@ class ScoreboardScoreElement(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun forceSilentApply() {
|
override fun forceSilentApply() {
|
||||||
val name = BaseComponent()
|
|
||||||
|
|
||||||
// ToDo: Can a score (entity; whatever) can have multiple teams?
|
// ToDo: Can a score (entity; whatever) can have multiple teams?
|
||||||
|
var team: Team? = null
|
||||||
score.teams.iterator().apply {
|
score.teams.iterator().apply {
|
||||||
if (!hasNext()) {
|
if (!hasNext()) {
|
||||||
return@apply
|
return@apply
|
||||||
}
|
}
|
||||||
val team = next()
|
team = next()
|
||||||
name += team.prefix
|
|
||||||
name += team.suffix
|
|
||||||
}
|
}
|
||||||
name += score.entity
|
val entityName = ChatComponent.of(score.entity)
|
||||||
|
nameElement.text = team?.decorateName(entityName) ?: entityName
|
||||||
nameElement.text = name
|
|
||||||
|
|
||||||
scoreElement.text = TextComponent(score.value).color(ChatColors.RED)
|
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)
|
nameElement.render(offset + Vec2i(HorizontalAlignments.CENTER.getOffset(size.x, nameElement.size.x), 0), z + 2, consumer, options)
|
||||||
offset.y += Font.TOTAL_CHAR_HEIGHT
|
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) {
|
for ((_, score) in scores) {
|
||||||
score.render(offset, z + 2, consumer, options)
|
score.render(offset, z + 2, consumer, options)
|
||||||
offset.y += score.size.y
|
offset.y += score.size.y
|
||||||
|
|
||||||
|
if (++index >= MAX_SCORES) {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TextElement.LAYERS + 2 // 2 backgrounds
|
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.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 {
|
companion object {
|
||||||
|
const val MAX_SCORES = 15
|
||||||
const val MIN_WIDTH = 30
|
const val MIN_WIDTH = 30
|
||||||
const val SCORE_HEIGHT = Font.TOTAL_CHAR_HEIGHT
|
const val SCORE_HEIGHT = Font.TOTAL_CHAR_HEIGHT
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user