deprecate KeyBindingsNames

This commit is contained in:
Bixilon 2021-09-11 17:57:11 +02:00
parent 898aa31e6b
commit 65744d625f
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
7 changed files with 189 additions and 252 deletions

View File

@ -17,38 +17,12 @@ import de.bixilon.minosoft.config.key.KeyAction
import de.bixilon.minosoft.config.key.KeyBinding
import de.bixilon.minosoft.config.key.KeyCodes
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.util.KUtil.toResourceLocation
@Deprecated(message = "Use new system with providing default key bindings when registering instead of \"pre registering\" the key")
object KeyBindingsNames {
val MOVE_FORWARD = ResourceLocation("minosoft:move_forward")
val MOVE_BACKWARDS = ResourceLocation("minosoft:move_backwards")
val MOVE_LEFT = ResourceLocation("minosoft:move_left")
val MOVE_RIGHT = ResourceLocation("minosoft:move_right")
val MOVE_SPRINT = ResourceLocation("minosoft:move_sprint")
val MOVE_TOGGLE_FLY = ResourceLocation("minosoft:move_toggle_fly")
val MOVE_FLY_UP = ResourceLocation("minosoft:move_fly_up")
val MOVE_FLY_DOWN = ResourceLocation("minosoft:move_fly_down")
val MOVE_SNEAK = ResourceLocation("minosoft:move_sneak")
val MOVE_JUMP = ResourceLocation("minosoft:move_jump")
val DESTROY_BLOCK = ResourceLocation("minosoft:destroy_block")
val DROP_ITEM = "minosoft:drop_item".toResourceLocation()
val DROP_ITEM_STACK = "minosoft:drop_item_stack".toResourceLocation()
val ZOOM = ResourceLocation("minosoft:zoom")
val QUIT_RENDERING = ResourceLocation("minosoft:quit_rendering")
val TOGGLE_DEBUG_SCREEN = ResourceLocation("minosoft:toggle_debug_screen")
val DEBUG_CLEAR_CHUNK_CACHE = ResourceLocation("minosoft:debug_clear_chunk_cache")
val DEBUG_POLYGON = ResourceLocation("minosoft:debug_polygon")
val DEBUG_MOUSE_CATCH = ResourceLocation("minosoft:debug_mouse_catch")
val DEBUG_PAUSE_INCOMING_PACKETS = ResourceLocation("minosoft:pause_incoming_packets")
val DEBUG_PAUSE_OUTGOING_PACKETS = ResourceLocation("minosoft:pause_outgoing_packets")
val TAKE_SCREENSHOT = ResourceLocation("minosoft:take_screenshot")
val TOGGLE_HUD = ResourceLocation("minosoft:toggle_hud")
@ -57,161 +31,12 @@ object KeyBindingsNames {
val CLOSE = ResourceLocation("minosoft:close")
val BLOCK_INTERACT = ResourceLocation("minosoft:interact_block")
val SELECT_HOTBAR_SLOTS = arrayOf(
ResourceLocation("minosoft:select_hotbar_slot_1"),
ResourceLocation("minosoft:select_hotbar_slot_2"),
ResourceLocation("minosoft:select_hotbar_slot_3"),
ResourceLocation("minosoft:select_hotbar_slot_4"),
ResourceLocation("minosoft:select_hotbar_slot_5"),
ResourceLocation("minosoft:select_hotbar_slot_6"),
ResourceLocation("minosoft:select_hotbar_slot_7"),
ResourceLocation("minosoft:select_hotbar_slot_8"),
ResourceLocation("minosoft:select_hotbar_slot_9")
)
val DEFAULT_KEY_BINDINGS: Map<ResourceLocation, KeyBinding> = mapOf(
MOVE_FORWARD to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_W),
),
),
MOVE_LEFT to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_A),
),
),
MOVE_BACKWARDS to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_S),
),
),
MOVE_RIGHT to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_D),
),
),
MOVE_SPRINT to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_LEFT_CONTROL),
),
),
MOVE_FLY_UP to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_SPACE),
),
),
MOVE_JUMP to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_SPACE),
),
),
MOVE_TOGGLE_FLY to KeyBinding(
mutableMapOf(
KeyAction.DOUBLE_PRESS to mutableSetOf(KeyCodes.KEY_SPACE),
),
),
MOVE_FLY_DOWN to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_LEFT_SHIFT),
),
),
MOVE_SNEAK to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_LEFT_SHIFT),
),
),
DESTROY_BLOCK to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.MOUSE_BUTTON_LEFT),
),
),
ZOOM to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_C),
),
),
TOGGLE_DEBUG_SCREEN to KeyBinding(
mutableMapOf(
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_F3),
),
),
DEBUG_POLYGON to KeyBinding(
mutableMapOf(
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_P),
),
),
DEBUG_MOUSE_CATCH to KeyBinding(
mutableMapOf(
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_M),
),
),
QUIT_RENDERING to KeyBinding(
mutableMapOf(
KeyAction.RELEASE to mutableSetOf(KeyCodes.KEY_ESCAPE),
),
),
DEBUG_CLEAR_CHUNK_CACHE to KeyBinding(
mutableMapOf(
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F3),
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_A),
),
),
TAKE_SCREENSHOT to KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_F2),
),
ignoreConsumer = true,
),
SELECT_HOTBAR_SLOTS[0] to KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_1),
),
),
SELECT_HOTBAR_SLOTS[1] to KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_2),
),
),
SELECT_HOTBAR_SLOTS[2] to KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_3),
),
),
SELECT_HOTBAR_SLOTS[3] to KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_4),
),
),
SELECT_HOTBAR_SLOTS[4] to KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_5),
),
),
SELECT_HOTBAR_SLOTS[5] to KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_6),
),
),
SELECT_HOTBAR_SLOTS[6] to KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_7),
),
),
SELECT_HOTBAR_SLOTS[7] to KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_8),
),
),
SELECT_HOTBAR_SLOTS[8] to KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_9),
),
),
TOGGLE_HUD to KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_F1),
@ -228,35 +53,5 @@ object KeyBindingsNames {
),
ignoreConsumer = true,
),
BLOCK_INTERACT to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.MOUSE_BUTTON_RIGHT),
),
),
DEBUG_PAUSE_INCOMING_PACKETS to KeyBinding(
mutableMapOf(
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_I),
),
ignoreConsumer = true,
),
DEBUG_PAUSE_OUTGOING_PACKETS to KeyBinding(
mutableMapOf(
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_O),
),
ignoreConsumer = true,
),
DROP_ITEM to KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_Q),
),
),
DROP_ITEM_STACK to KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_Q),
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_LEFT_CONTROL)
),
),
)
}

View File

@ -15,7 +15,9 @@ package de.bixilon.minosoft.gui.rendering
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.StaticConfiguration
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
import de.bixilon.minosoft.config.key.KeyAction
import de.bixilon.minosoft.config.key.KeyBinding
import de.bixilon.minosoft.config.key.KeyCodes
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.gui.rendering.block.WorldRenderer
import de.bixilon.minosoft.gui.rendering.block.chunk.ChunkBorderRenderer
@ -46,6 +48,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.CountUpAndDownLatch
import de.bixilon.minosoft.util.KUtil.decide
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.bixilon.minosoft.util.MMath.round10
import de.bixilon.minosoft.util.Queue
import de.bixilon.minosoft.util.Stopwatch
@ -216,20 +219,48 @@ class RenderWindow(
}
private fun registerGlobalKeyCombinations() {
inputHandler.registerKeyCallback(KeyBindingsNames.DEBUG_POLYGON) {
inputHandler.registerKeyCallback("minosoft:debug_polygon".toResourceLocation(), KeyBinding(
mutableMapOf(
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_P),
),
)) {
val nextMode = it.decide(PolygonModes.LINE, PolygonModes.FILL)
renderSystem.polygonMode = nextMode
sendDebugMessage("Set polygon to: $nextMode")
}
inputHandler.registerKeyCallback(KeyBindingsNames.QUIT_RENDERING) { window.close() }
inputHandler.registerKeyCallback(KeyBindingsNames.TAKE_SCREENSHOT) { screenshotTaker.takeScreenshot() }
inputHandler.registerKeyCallback("minosoft:quit_rendering".toResourceLocation(), KeyBinding(
mutableMapOf(
KeyAction.RELEASE to mutableSetOf(KeyCodes.KEY_ESCAPE),
),
)) { window.close() }
inputHandler.registerKeyCallback(KeyBindingsNames.DEBUG_PAUSE_INCOMING_PACKETS) {
inputHandler.registerKeyCallback("minosoft:take_screenshot".toResourceLocation(), KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_F2),
),
ignoreConsumer = true,
)) { screenshotTaker.takeScreenshot() }
inputHandler.registerKeyCallback("minosoft:pause_incoming_packets".toResourceLocation(), KeyBinding(
mutableMapOf(
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_I),
),
ignoreConsumer = true,
)) {
sendDebugMessage("Pausing incoming packets: $it")
connection.network.pauseReceiving(it)
}
inputHandler.registerKeyCallback(KeyBindingsNames.DEBUG_PAUSE_OUTGOING_PACKETS) {
inputHandler.registerKeyCallback("minosoft:pause_outgoing_packets".toResourceLocation(), KeyBinding(
mutableMapOf(
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_O),
),
ignoreConsumer = true,
)) {
sendDebugMessage("Pausing outgoing packets: $it")
connection.network.pauseSending(it)
}

View File

@ -13,7 +13,9 @@
package de.bixilon.minosoft.gui.rendering.block
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
import de.bixilon.minosoft.config.key.KeyAction
import de.bixilon.minosoft.config.key.KeyBinding
import de.bixilon.minosoft.config.key.KeyCodes
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.direction.FakeDirection
import de.bixilon.minosoft.data.registries.ResourceLocation
@ -47,6 +49,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.KUtil.nullCast
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
import de.bixilon.minosoft.util.KUtil.synchronizedSetOf
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.bixilon.minosoft.util.KUtil.toSynchronizedMap
import de.bixilon.minosoft.util.collections.SynchronizedMap
import de.bixilon.minosoft.util.task.pool.DefaultThreadPool
@ -145,7 +148,12 @@ class WorldRenderer(
// register keybindings
renderWindow.inputHandler.registerKeyCallback(KeyBindingsNames.DEBUG_CLEAR_CHUNK_CACHE) {
renderWindow.inputHandler.registerKeyCallback("minosoft:debug_clear_chunk_cache".toResourceLocation(), KeyBinding(
mutableMapOf(
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F3),
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_A),
),
)) {
clearChunkCache()
renderWindow.sendDebugMessage("Cleared chunk cache!")
prepareWorld(world)

View File

@ -13,7 +13,9 @@
package de.bixilon.minosoft.gui.rendering.input
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
import de.bixilon.minosoft.config.key.KeyAction
import de.bixilon.minosoft.config.key.KeyBinding
import de.bixilon.minosoft.config.key.KeyCodes
import de.bixilon.minosoft.data.abilities.Gamemodes
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.inventory.ItemStack
@ -30,6 +32,7 @@ import de.bixilon.minosoft.protocol.packets.c2s.play.ArmSwingC2SP
import de.bixilon.minosoft.protocol.packets.c2s.play.BlockBreakC2SP
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import glm_.pow
import glm_.vec3.Vec3i
@ -243,7 +246,11 @@ class LeftClickHandler(
}
fun init() {
renderWindow.inputHandler.registerCheckCallback(KeyBindingsNames.DESTROY_BLOCK)
renderWindow.inputHandler.registerCheckCallback(DESTROY_BLOCK_KEYBINDING to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.MOUSE_BUTTON_LEFT),
),
))
connection.registerEvent(CallbackEventInvoker.of<BlockBreakAckEvent> {
when (it.breakType) {
@ -269,7 +276,7 @@ class LeftClickHandler(
}
fun draw(deltaTime: Double) {
val isKeyDown = renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.DESTROY_BLOCK)
val isKeyDown = renderWindow.inputHandler.isKeyBindingDown(DESTROY_BLOCK_KEYBINDING)
// ToDo: Entity attacking
val consumed = checkBreaking(isKeyDown, deltaTime)
@ -281,4 +288,8 @@ class LeftClickHandler(
}
swingArm()
}
companion object {
private val DESTROY_BLOCK_KEYBINDING = "minosoft:destroy_block".toResourceLocation()
}
}

View File

@ -13,7 +13,9 @@
package de.bixilon.minosoft.gui.rendering.input
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
import de.bixilon.minosoft.config.key.KeyAction
import de.bixilon.minosoft.config.key.KeyBinding
import de.bixilon.minosoft.config.key.KeyCodes
import de.bixilon.minosoft.data.abilities.Gamemodes
import de.bixilon.minosoft.data.player.Hands
import de.bixilon.minosoft.data.registries.blocks.BlockUsages
@ -22,6 +24,7 @@ import de.bixilon.minosoft.protocol.packets.c2s.play.ArmSwingC2SP
import de.bixilon.minosoft.protocol.packets.c2s.play.BlockPlaceC2SP
import de.bixilon.minosoft.protocol.packets.c2s.play.ItemUseC2SP
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import glm_.vec3.Vec3
class RightClickHandler(
@ -32,7 +35,11 @@ class RightClickHandler(
private var lastInteractionSent = 0L
fun init() {
renderWindow.inputHandler.registerCheckCallback(KeyBindingsNames.BLOCK_INTERACT)
renderWindow.inputHandler.registerCheckCallback(BLOCK_INTERACT_KEYBINDING to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.MOUSE_BUTTON_RIGHT),
),
))
}
private fun checkInteraction(isKeyDown: Boolean) {
@ -132,6 +139,10 @@ class RightClickHandler(
fun draw(deltaTime: Double) {
// ToDo: Entity interaction, shield/sword blocking, etc
checkInteraction(renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.BLOCK_INTERACT))
checkInteraction(renderWindow.inputHandler.isKeyBindingDown(BLOCK_INTERACT_KEYBINDING))
}
companion object {
private val BLOCK_INTERACT_KEYBINDING = "minosoft:interact_block".toResourceLocation()
}
}

View File

@ -14,7 +14,9 @@
package de.bixilon.minosoft.gui.rendering.input.camera
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
import de.bixilon.minosoft.config.key.KeyAction
import de.bixilon.minosoft.config.key.KeyBinding
import de.bixilon.minosoft.config.key.KeyCodes
import de.bixilon.minosoft.data.entities.EntityRotation
import de.bixilon.minosoft.data.player.LocalPlayerEntity
import de.bixilon.minosoft.data.registries.VoxelShape
@ -40,6 +42,7 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.BlockBreakC2SP
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.KUtil.decide
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.bixilon.minosoft.util.Previous
import glm_.func.cos
import glm_.func.rad
@ -149,17 +152,61 @@ class Camera(
fun init(renderWindow: RenderWindow) {
renderWindow.inputHandler.registerCheckCallback(
KeyBindingsNames.MOVE_SPRINT,
KeyBindingsNames.MOVE_FORWARD,
KeyBindingsNames.MOVE_BACKWARDS,
KeyBindingsNames.MOVE_LEFT,
KeyBindingsNames.MOVE_RIGHT,
KeyBindingsNames.MOVE_FLY_UP,
KeyBindingsNames.MOVE_FLY_DOWN,
KeyBindingsNames.ZOOM,
KeyBindingsNames.MOVE_JUMP,
KeyBindingsNames.MOVE_SNEAK,
KeyBindingsNames.MOVE_TOGGLE_FLY,
MOVE_SPRINT_KEYBINDING to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_LEFT_CONTROL),
),
),
MOVE_FORWARDS_KEYBINDING to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_W),
),
),
MOVE_BACKWARDS_KEYBINDING to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_S),
),
),
MOVE_LEFT_KEYBINDING to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_A),
),
),
MOVE_RIGHT_KEYBINDING to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_D),
),
),
FLY_UP_KEYBINDING to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_SPACE),
),
),
FLY_DOWN_KEYBINDING to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_LEFT_SHIFT),
),
),
ZOOM_KEYBINDING to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_C),
),
),
JUMP_KEYBINDING to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_SPACE),
),
),
SNEAK_KEYBINDING to KeyBinding(
mutableMapOf(
KeyAction.CHANGE to mutableSetOf(KeyCodes.KEY_LEFT_SHIFT),
),
),
TOGGLE_FLY_KEYBINDING to KeyBinding(
mutableMapOf(
KeyAction.DOUBLE_PRESS to mutableSetOf(KeyCodes.KEY_SPACE),
),
),
)
connection.registerEvent(CallbackEventInvoker.of<ResizeWindowEvent> { recalculateViewProjectionMatrix() })
@ -173,8 +220,18 @@ class Camera(
lastDropPacketSent = time
}
renderWindow.inputHandler.registerKeyCallback(KeyBindingsNames.DROP_ITEM) { dropItem(BlockBreakC2SP.BreakType.DROP_ITEM) }
renderWindow.inputHandler.registerKeyCallback(KeyBindingsNames.DROP_ITEM_STACK) { dropItem(BlockBreakC2SP.BreakType.DROP_ITEM_STACK) }
// ToDo: This has nothing todo with the camera, should be in the interaction manager
renderWindow.inputHandler.registerKeyCallback(DROP_ITEM_KEYBINDING, KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_Q),
),
)) { dropItem(BlockBreakC2SP.BreakType.DROP_ITEM) }
renderWindow.inputHandler.registerKeyCallback(DROP_ITEM_STACK_KEYBINDING, KeyBinding(
mutableMapOf(
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_Q),
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_LEFT_CONTROL)
),
)) { dropItem(BlockBreakC2SP.BreakType.DROP_ITEM_STACK) }
frustum.recalculate()
connection.fireEvent(FrustumChangeEvent(renderWindow, frustum))
}
@ -251,16 +308,16 @@ class Camera(
}
//val input = if (renderWindow.inputHandler.currentKeyConsumer == null) {
val input = MovementInput(
pressingForward = renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.MOVE_FORWARD),
pressingBack = renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.MOVE_BACKWARDS),
pressingLeft = renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.MOVE_LEFT),
pressingRight = renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.MOVE_RIGHT),
jumping = renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.MOVE_JUMP),
sneaking = renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.MOVE_SNEAK),
sprinting = renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.MOVE_SPRINT),
flyDown = renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.MOVE_FLY_DOWN),
flyUp = renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.MOVE_FLY_UP),
toggleFlyDown = renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.MOVE_TOGGLE_FLY),
pressingForward = renderWindow.inputHandler.isKeyBindingDown(MOVE_FORWARDS_KEYBINDING),
pressingBack = renderWindow.inputHandler.isKeyBindingDown(MOVE_BACKWARDS_KEYBINDING),
pressingLeft = renderWindow.inputHandler.isKeyBindingDown(MOVE_LEFT_KEYBINDING),
pressingRight = renderWindow.inputHandler.isKeyBindingDown(MOVE_RIGHT_KEYBINDING),
jumping = renderWindow.inputHandler.isKeyBindingDown(JUMP_KEYBINDING),
sneaking = renderWindow.inputHandler.isKeyBindingDown(SNEAK_KEYBINDING),
sprinting = renderWindow.inputHandler.isKeyBindingDown(MOVE_SPRINT_KEYBINDING),
flyDown = renderWindow.inputHandler.isKeyBindingDown(FLY_DOWN_KEYBINDING),
flyUp = renderWindow.inputHandler.isKeyBindingDown(FLY_UP_KEYBINDING),
toggleFlyDown = renderWindow.inputHandler.isKeyBindingDown(TOGGLE_FLY_KEYBINDING),
)
//} else {
// MovementInput()
@ -268,7 +325,7 @@ class Camera(
connection.player.input = input
connection.player.tick() // The thread pool might be busy, we force a tick here to avoid lagging
zoom = if (renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.ZOOM)) {
zoom = if (renderWindow.inputHandler.isKeyBindingDown(ZOOM_KEYBINDING)) {
2f
} else {
0.0f
@ -375,5 +432,24 @@ class Camera(
val CAMERA_UP_VEC3 = Vec3d(0.0, 1.0, 0.0)
private const val RAYCAST_MAX_STEPS = 100
private val MOVE_SPRINT_KEYBINDING = "minosoft:move_sprint".toResourceLocation()
private val MOVE_FORWARDS_KEYBINDING = "minosoft:move_forward".toResourceLocation()
private val MOVE_BACKWARDS_KEYBINDING = "minosoft:move_backwards".toResourceLocation()
private val MOVE_LEFT_KEYBINDING = "minosoft:move_left".toResourceLocation()
private val MOVE_RIGHT_KEYBINDING = "minosoft:move_right".toResourceLocation()
private val SNEAK_KEYBINDING = "minosoft:move_sneak".toResourceLocation()
private val JUMP_KEYBINDING = "minosoft:move_jump".toResourceLocation()
private val TOGGLE_FLY_KEYBINDING = "minosoft:move_toggle_fly".toResourceLocation()
private val FLY_UP_KEYBINDING = "minosoft:move_fly_up".toResourceLocation()
private val FLY_DOWN_KEYBINDING = "minosoft:move_fly_down".toResourceLocation()
private val ZOOM_KEYBINDING = "minosoft:zoom".toResourceLocation()
private val DROP_ITEM_KEYBINDING = "minosoft:drop_item".toResourceLocation()
private val DROP_ITEM_STACK_KEYBINDING = "minosoft:drop_item_stack".toResourceLocation()
}
}

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.input.key
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
import de.bixilon.minosoft.config.key.KeyAction
import de.bixilon.minosoft.config.key.KeyBinding
import de.bixilon.minosoft.config.key.KeyCodes
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.gui.rendering.RenderConstants
@ -49,7 +50,12 @@ class RenderWindowInputHandler(
val leftClickHandler = LeftClickHandler(renderWindow)
init {
registerKeyCallback(KeyBindingsNames.DEBUG_MOUSE_CATCH) {
registerKeyCallback(KeyBindingsNames.DEBUG_MOUSE_CATCH, KeyBinding(
mutableMapOf(
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_M),
),
)) {
renderWindow.window.cursorMode = it.decide(CursorModes.DISABLED, CursorModes.NORMAL)
renderWindow.sendDebugMessage("Toggled mouse catch!")
}
@ -220,8 +226,8 @@ class RenderWindowInputHandler(
//currentKeyConsumer?.charInput(char.toChar())
}
fun registerKeyCallback(resourceLocation: ResourceLocation, callback: ((keyDown: Boolean) -> Unit)) {
val keyBinding = Minosoft.config.config.game.controls.keyBindings.entries[resourceLocation] ?: return
fun registerKeyCallback(resourceLocation: ResourceLocation, defaultKeyBinding: KeyBinding, callback: ((keyDown: Boolean) -> Unit)) {
val keyBinding = Minosoft.config.config.game.controls.keyBindings.entries.getOrPut(resourceLocation) { defaultKeyBinding } // ToDo (Performance): Should the defaultKeyBinding be a lambda parameter?
val callbackPair = keyBindingCallbacks.getOrPut(resourceLocation) { KeyBindingCallbackPair(keyBinding) }
if (keyBinding.ignoreConsumer) {
callbackPair.callback += callback
@ -235,10 +241,9 @@ class RenderWindowInputHandler(
}
}
fun registerCheckCallback(vararg resourceLocations: ResourceLocation) {
for (resourceLocation in resourceLocations) {
val keyBinding = Minosoft.config.config.game.controls.keyBindings.entries[resourceLocation] ?: return
keyBindingCallbacks.getOrPut(resourceLocation) { KeyBindingCallbackPair(keyBinding) }
fun registerCheckCallback(vararg checks: Pair<ResourceLocation, KeyBinding>) {
for ((resourceLocation, defaultKeyBinding) in checks) {
keyBindingCallbacks.getOrPut(resourceLocation) { KeyBindingCallbackPair(Minosoft.config.config.game.controls.keyBindings.entries.getOrPut(resourceLocation) { defaultKeyBinding }) }
}
}