mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 07:20:04 -04:00
hud: add more hud text inserts to do the left side of the debug screen
This commit is contained in:
parent
284dd9835a
commit
aed1ed0ff5
@ -45,7 +45,7 @@ class HUDRenderer(val connection: PlayConnection, val renderWindow: RenderWindow
|
||||
var orthographicMatrix: Mat4 = Mat4()
|
||||
private set
|
||||
|
||||
val hudTextTranslator = HUDTextTranslator(connection)
|
||||
val hudTextTranslator = HUDTextTranslator(this)
|
||||
|
||||
var hudEnabled = true
|
||||
var currentMenus = mutableSetOf<HUDMenus>()
|
||||
|
@ -14,19 +14,27 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.hud.elements.text
|
||||
|
||||
import de.bixilon.minosoft.data.Directions
|
||||
import de.bixilon.minosoft.data.locale.minecraft.Translator
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.data.text.TextComponent
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.WorldRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.hud.HUDRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.blockPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.chunkPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.round
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.util.MMath.nanosToMillis
|
||||
import de.bixilon.minosoft.util.MMath.rotationFormatted
|
||||
import de.bixilon.minosoft.util.MMath.round
|
||||
import de.bixilon.minosoft.util.MMath.unitFormatted
|
||||
import java.util.*
|
||||
|
||||
|
||||
class HUDTextTranslator(private val connection: PlayConnection) : Translator {
|
||||
class HUDTextTranslator(private val hudRenderer: HUDRenderer) : Translator {
|
||||
private lateinit var worldRenderer: WorldRenderer
|
||||
private val connection = hudRenderer.connection
|
||||
|
||||
override fun translate(key: String?, parent: TextComponent?, vararg data: Any?): ChatComponent {
|
||||
if (key == null) {
|
||||
@ -40,52 +48,80 @@ class HUDTextTranslator(private val connection: PlayConnection) : Translator {
|
||||
return ChatComponent.of(key)
|
||||
}
|
||||
val runnable = insertRunnables[resourceLocation]!! // checked before
|
||||
return ChatComponent.of(runnable.invoke(connection, worldRenderer))
|
||||
return ChatComponent.of(runnable.invoke(connection, worldRenderer, hudRenderer))
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val insertRunnables = mutableMapOf<ResourceLocation, (PlayConnection, WorldRenderer) -> String>()
|
||||
private val insertRunnables = mutableMapOf<ResourceLocation, (PlayConnection, WorldRenderer, HUDRenderer) -> String>()
|
||||
|
||||
init {
|
||||
//position
|
||||
insertRunnables[ResourceLocation("minosoft:playerPosition_x")] = { connection, _ ->
|
||||
connection.player.position.x.round(ROUND_DIGITS).toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:playerPosition_y")] = { connection, _ ->
|
||||
connection.player.position.y.round(ROUND_DIGITS).toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:playerPosition_z")] = { connection, _ ->
|
||||
connection.player.position.z.round(ROUND_DIGITS).toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:playerPosition_x")] = { connection, _ ->
|
||||
insertRunnables[ResourceLocation("minosoft:player_position")] = { connection, _, _ ->
|
||||
connection.player.position.round(ROUND_DIGITS).toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:player_block_position")] = { connection, _, _ ->
|
||||
connection.player.position.blockPosition.toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:player_chunk_position")] = { connection, _, _ ->
|
||||
connection.player.position.blockPosition.chunkPosition.toString()
|
||||
}
|
||||
// timings
|
||||
insertRunnables[ResourceLocation("minosoft:fps")] = { connection, _ ->
|
||||
insertRunnables[ResourceLocation("minosoft:fps")] = { connection, _, _ ->
|
||||
connection.rendering!!.renderWindow.renderStats.fpsLastSecond.toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:average_frame_time")] = { connection, _ ->
|
||||
insertRunnables[ResourceLocation("minosoft:average_frame_time")] = { connection, _, _ ->
|
||||
connection.rendering!!.renderWindow.renderStats.avgFrameTime.nanosToMillis.round(1).toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:min_frame_time")] = { connection, _ ->
|
||||
insertRunnables[ResourceLocation("minosoft:min_frame_time")] = { connection, _, _ ->
|
||||
connection.rendering!!.renderWindow.renderStats.minFrameTime.nanosToMillis.round(1).toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:max_frame_time")] = { connection, _ ->
|
||||
insertRunnables[ResourceLocation("minosoft:max_frame_time")] = { connection, _, _ ->
|
||||
connection.rendering!!.renderWindow.renderStats.maxFrameTime.nanosToMillis.round(1).toString()
|
||||
}
|
||||
// chunk data
|
||||
insertRunnables[ResourceLocation("minosoft:queued_chunks_count")] = { _, worldRenderer ->
|
||||
insertRunnables[ResourceLocation("minosoft:queued_chunks_count")] = { _, worldRenderer, _ ->
|
||||
worldRenderer.queuedChunks.size.toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:visible_chunks_count")] = { _, worldRenderer ->
|
||||
insertRunnables[ResourceLocation("minosoft:visible_chunks_count")] = { _, worldRenderer, _ ->
|
||||
worldRenderer.visibleChunks.size.toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:all_chunk_secions_count")] = { _, worldRenderer ->
|
||||
insertRunnables[ResourceLocation("minosoft:all_chunk_sections_count")] = { _, worldRenderer, _ ->
|
||||
worldRenderer.allChunkSections.size.toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:triangle_count")] = { _, worldRenderer ->
|
||||
insertRunnables[ResourceLocation("minosoft:triangle_count")] = { _, worldRenderer, _ ->
|
||||
worldRenderer.triangles.toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:meshes_count")] = { _, worldRenderer, _ ->
|
||||
worldRenderer.meshes.unitFormatted
|
||||
}
|
||||
|
||||
insertRunnables[ResourceLocation("minosoft:game_mode")] = { connection, _, _ ->
|
||||
connection.player.gamemode.name
|
||||
}
|
||||
|
||||
insertRunnables[ResourceLocation("minosoft:game_mode")] = { connection, _, _ ->
|
||||
connection.player.gamemode.name
|
||||
}
|
||||
|
||||
insertRunnables[ResourceLocation("minosoft:direction")] = { _, _, hudRenderer ->
|
||||
Directions.byDirection(hudRenderer.renderWindow.inputHandler.camera.cameraFront).name.lowercase(Locale.getDefault())
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:pitch")] = { _, _, hudRenderer ->
|
||||
hudRenderer.renderWindow.inputHandler.camera.entity.rotation.pitch.rotationFormatted
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:yaw")] = { _, _, hudRenderer ->
|
||||
hudRenderer.renderWindow.inputHandler.camera.entity.rotation.headYaw.rotationFormatted
|
||||
}
|
||||
|
||||
insertRunnables[ResourceLocation("minosoft:biome")] = { connection, _, _ ->
|
||||
connection.player.positionInfo.biome.toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:dimension")] = { connection, _, _ ->
|
||||
connection.world.dimension.toString()
|
||||
}
|
||||
insertRunnables[ResourceLocation("minosoft:difficulty")] = { connection, _, _ ->
|
||||
connection.world.difficulty?.name ?: ""
|
||||
}
|
||||
}
|
||||
|
||||
const val ROUND_DIGITS = 2
|
||||
|
@ -113,4 +113,10 @@ object MMath {
|
||||
}
|
||||
|
||||
val Long.nanosToMillis: Float get() = this / 1E6f
|
||||
|
||||
val Int.unitFormatted get() = UnitFormatter.formatNumber(this)
|
||||
|
||||
val Float.rotationFormatted get() = "%.1f".format(this)
|
||||
|
||||
val Double.rotationFormatted get() = "%.1f".format(this)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user