mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 10:25:06 -04:00
rendering: wip: chat blinking, chat background
This commit is contained in:
parent
48fdbd457a
commit
0afe128437
@ -35,6 +35,7 @@ import de.bixilon.minosoft.modding.event.events.ConnectionStateChangeEvent
|
||||
import de.bixilon.minosoft.modding.event.events.PacketReceiveEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketPlayerPositionAndRotation
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import de.bixilon.minosoft.util.CountUpAndDownLatch
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import glm_.vec2.Vec2
|
||||
@ -90,6 +91,10 @@ class RenderWindow(
|
||||
|
||||
lateinit var WHITE_TEXTURE: TextureLike
|
||||
|
||||
|
||||
var tickCount = 0L
|
||||
var lastTickTimer = System.currentTimeMillis()
|
||||
|
||||
var currentKeyConsumer: KeyConsumer?
|
||||
get() = _currentInputConsumer
|
||||
set(value) {
|
||||
@ -419,6 +424,14 @@ class RenderWindow(
|
||||
renderStats.startFrame()
|
||||
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) // clear the framebuffer
|
||||
|
||||
|
||||
val currentTickTime = System.currentTimeMillis()
|
||||
if (currentTickTime - this.lastTickTimer > ProtocolDefinition.TICK_TIME) {
|
||||
tickCount++
|
||||
currentKeyConsumer?.tick(tickCount)
|
||||
this.lastTickTimer = currentTickTime
|
||||
}
|
||||
|
||||
val currentFrame = glfwGetTime()
|
||||
deltaFrameTime = currentFrame - lastFrame
|
||||
lastFrame = currentFrame
|
||||
|
@ -22,4 +22,6 @@ interface KeyConsumer {
|
||||
fun charInput(char: Char) {}
|
||||
|
||||
fun keyInput(keyCodes: KeyCodes) {}
|
||||
|
||||
fun tick(tick: Long) {}
|
||||
}
|
||||
|
@ -15,10 +15,8 @@ package de.bixilon.minosoft.gui.rendering.hud.elements.input
|
||||
|
||||
import de.bixilon.minosoft.config.key.KeyCodes
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.layout.AbsoluteLayout
|
||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.primitive.ImageNode
|
||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.primitive.LabelNode
|
||||
import de.bixilon.minosoft.util.MMath
|
||||
import glm_.vec2.Vec2i
|
||||
@ -44,7 +42,6 @@ open class TextField(
|
||||
|
||||
init {
|
||||
addChild(Vec2i(0, 0), textElement)
|
||||
addChild(Vec2i(0, 0), ImageNode(renderWindow, sizing = sizing, renderWindow.WHITE_TEXTURE, 0, RenderConstants.TEXT_BACKGROUND_COLOR))
|
||||
clearChildrenCache()
|
||||
}
|
||||
|
||||
@ -94,6 +91,14 @@ open class TextField(
|
||||
super.keyInput(keyCodes)
|
||||
}
|
||||
|
||||
override fun tick(tick: Long) {
|
||||
if ((tick / 8) % 2L == 0L && position == text.length) {
|
||||
textElement.sText = "$textBuilder" + "_"
|
||||
} else {
|
||||
textElement.sText = textBuilder.toString()
|
||||
}
|
||||
}
|
||||
|
||||
override fun charInput(char: Char) {
|
||||
if (position >= maxLength) {
|
||||
return
|
||||
|
@ -15,13 +15,20 @@ package de.bixilon.minosoft.gui.rendering.hud.nodes.chat
|
||||
|
||||
|
||||
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
|
||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||
import de.bixilon.minosoft.gui.rendering.font.Font
|
||||
import de.bixilon.minosoft.gui.rendering.hud.HUDRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.hud.elements.input.SubmittableTextField
|
||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.HUDElement
|
||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.primitive.ImageNode
|
||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.properties.NodeSizing
|
||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.properties.Spacing
|
||||
import de.bixilon.minosoft.util.MMath
|
||||
import glm_.vec2.Vec2i
|
||||
|
||||
class ChatBoxHUDElement(hudRenderer: HUDRenderer) : HUDElement(hudRenderer) {
|
||||
private lateinit var inputField: SubmittableTextField
|
||||
private var inputFieldBackground = ImageNode(hudRenderer.renderWindow, sizing = NodeSizing(margin = Spacing(left = 1, right = 1)), textureLike = hudRenderer.renderWindow.WHITE_TEXTURE, z = 0, tintColor = RenderConstants.TEXT_BACKGROUND_COLOR)
|
||||
|
||||
override fun init() {
|
||||
inputField = SubmittableTextField(renderWindow = hudRenderer.renderWindow, maxLength = 256, onSubmit = {
|
||||
@ -42,18 +49,21 @@ class ChatBoxHUDElement(hudRenderer: HUDRenderer) : HUDElement(hudRenderer) {
|
||||
|
||||
override fun screenChangeResizeCallback(screenDimensions: Vec2i) {
|
||||
layout.sizing.minSize.x = screenDimensions.x
|
||||
inputFieldBackground.sizing.forceSize = Vec2i(screenDimensions.x - 2, MMath.clamp(inputField.sizing.currentSize.y, Font.CHAR_HEIGHT, Int.MAX_VALUE)) // 2 pixels for log
|
||||
layout.sizing.maxSize.x = screenDimensions.x
|
||||
layout.sizing.validate()
|
||||
layout.apply()
|
||||
}
|
||||
|
||||
fun openChat() {
|
||||
layout.addChild(Vec2i(0, 0), inputFieldBackground)
|
||||
hudRenderer.renderWindow.currentKeyConsumer = inputField
|
||||
hudRenderer.renderWindow.currentElement.remove(KeyBindingsNames.WHEN_IN_GAME)
|
||||
hudRenderer.renderWindow.currentElement.add(KeyBindingsNames.WHEN_IN_CHAT)
|
||||
}
|
||||
|
||||
fun closeChat() {
|
||||
layout.removeChild(inputFieldBackground)
|
||||
inputField.clearText()
|
||||
hudRenderer.renderWindow.currentKeyConsumer = null
|
||||
hudRenderer.renderWindow.currentElement.remove(KeyBindingsNames.WHEN_IN_CHAT)
|
||||
|
@ -133,4 +133,8 @@ open class AbsoluteLayout(
|
||||
}
|
||||
clearCache()
|
||||
}
|
||||
|
||||
fun removeChild(node: Node) {
|
||||
children.remove(node)
|
||||
}
|
||||
}
|
||||
|
@ -29,4 +29,12 @@ data class NodeSizing(
|
||||
fun validate() {
|
||||
MMath.clamp(currentSize, minSize, maxSize)
|
||||
}
|
||||
|
||||
var forceSize: Vec2i
|
||||
get() = currentSize
|
||||
set(value) {
|
||||
minSize = value
|
||||
maxSize = value
|
||||
validate()
|
||||
}
|
||||
}
|
||||
|
@ -46,11 +46,13 @@ public class PacketSender {
|
||||
|
||||
public void sendChatMessage(String message) {
|
||||
if (message.isBlank()) {
|
||||
throw new IllegalArgumentException(("Chat message is blank!"));
|
||||
// throw new IllegalArgumentException(("Chat message is blank!"));
|
||||
return;
|
||||
}
|
||||
for (char illegalChar : ILLEGAL_CHAT_CHARS) {
|
||||
if (message.indexOf(illegalChar) != -1) {
|
||||
throw new IllegalArgumentException(String.format("%s is not allowed in chat", illegalChar));
|
||||
// throw new IllegalArgumentException(String.format("%s is not allowed in chat", illegalChar));
|
||||
return;
|
||||
}
|
||||
}
|
||||
ChatMessageSendingEvent event = new ChatMessageSendingEvent(this.connection, message);
|
||||
|
Loading…
x
Reference in New Issue
Block a user