rendering: fix chat position, fix bug with size faking in hud

This commit is contained in:
Bixilon 2021-04-13 00:07:56 +02:00
parent 3abd906829
commit 84cfc5603f
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 11 additions and 4 deletions

View File

@ -6,6 +6,7 @@ Minosoft is an open source minecraft client, written from scratch in java. It ai
[![](https://jitpack.io/v/de.bixilon.gitlab.bixilon/minosoft.svg)](https://jitpack.io/#de.bixilon.gitlab.bixilon/minosoft)
<h2><span style="color:red">Notice: I am not responsible for anti cheat banned accounts, this project is heavily in development!</span></h2>
## Feature overview
- Rendering

View File

@ -94,16 +94,17 @@ class HUDRenderer(val connection: PlayConnection, val renderWindow: RenderWindow
enabled = false,
))
addElement(ElementsNames.CHAT_RESOURCE_LOCATION, ChatBoxHUDElement(this), HUDElementProperties(
position = Vec2(0f, -1.0f),
position = Vec2(0.0f, -1.0f),
xBinding = HUDElementProperties.PositionBindings.CENTER,
))
}
fun addElement(resourceLocation: ResourceLocation, hudElement: HUDElement, defaultProperties: HUDElementProperties) {
var needToSafeConfig = false
val properties = Minosoft.getConfig().config.game.elements.entries.getOrPut(resourceLocation, {
val properties = Minosoft.getConfig().config.game.elements.entries.getOrPut(resourceLocation) {
needToSafeConfig = true
defaultProperties
})
}
if (needToSafeConfig) {
Minosoft.getConfig().saveToFile()
}
@ -182,7 +183,7 @@ class HUDRenderer(val connection: PlayConnection, val renderWindow: RenderWindow
if (forcePrepare || needsUpdate) {
for ((elementProperties, hudElement) in enabledHUDElement.values) {
val realScaleFactor = elementProperties.scale * Minosoft.getConfig().config.game.hud.scale
val realSize = Vec2i(hudElement.layout.fakeX ?: hudElement.layout.size.x, hudElement.layout.fakeY ?: hudElement.layout.size.y) * realScaleFactor
val realSize = Vec2i(hudElement.layout.fakeX ?: (hudElement.layout.size.x * realScaleFactor), hudElement.layout.fakeY ?: (hudElement.layout.size.y * realScaleFactor))
val elementStart = getRealPosition(realSize, elementProperties, renderWindow.screenDimensions)

View File

@ -17,6 +17,7 @@ import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
import de.bixilon.minosoft.gui.rendering.hud.HUDRenderer
import de.bixilon.minosoft.gui.rendering.hud.elements.HUDElement
import de.bixilon.minosoft.gui.rendering.hud.elements.input.SubmittableTextField
import glm_.vec2.Vec2i
class ChatBoxHUDElement(hudRenderer: HUDRenderer) : HUDElement(hudRenderer) {
private lateinit var inputField: SubmittableTextField
@ -43,6 +44,10 @@ class ChatBoxHUDElement(hudRenderer: HUDRenderer) : HUDElement(hudRenderer) {
}
}
override fun screenChangeResizeCallback(screenDimensions: Vec2i) {
layout.fakeX = screenDimensions.x
}
fun openChat() {
hudRenderer.renderWindow.currentKeyConsumer = inputField
hudRenderer.renderWindow.currentElement.remove(KeyBindingsNames.WHEN_IN_GAME)