tweaks to keyboard handling
This commit is contained in:
parent
26dab07419
commit
7db99e2195
|
|
@ -153,26 +153,28 @@ public class GuiKeyboard extends WDScreen {
|
|||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
if(quitOnEscape && keyCode == GLFW.GLFW_KEY_ESCAPE)
|
||||
Minecraft.getInstance().setScreen(null);
|
||||
evStack.add(new TypeData(TypeData.Action.PRESS, keyCode, modifiers));
|
||||
if (!evStack.isEmpty() && !syncRequested())
|
||||
requestSync();
|
||||
addKey(new TypeData(TypeData.Action.PRESS, keyCode, modifiers));
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char codePoint, int modifiers) {
|
||||
evStack.add(new TypeData(TypeData.Action.TYPE, codePoint, modifiers));
|
||||
if (!evStack.isEmpty() && !syncRequested())
|
||||
requestSync();
|
||||
addKey(new TypeData(TypeData.Action.TYPE, codePoint, modifiers));
|
||||
return super.charTyped(codePoint, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
|
||||
evStack.add(new TypeData(TypeData.Action.RELEASE, keyCode, modifiers));
|
||||
addKey(new TypeData(TypeData.Action.RELEASE, keyCode, modifiers));
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
void addKey(TypeData data) {
|
||||
tes.type(side, "[" + WebDisplays.GSON.toJson(data) + "]", kbPos);
|
||||
|
||||
evStack.add(data);
|
||||
if (!evStack.isEmpty() && !syncRequested())
|
||||
requestSync();
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class KeyTypedControl extends ScreenControl {
|
|||
@Override
|
||||
public void handleServer(BlockPos pos, BlockSide side, TileEntityScreen tes, NetworkEvent.Context ctx, Function<Integer, Boolean> permissionChecker) throws MissingPermissionException {
|
||||
checkPerms(ScreenRights.INTERACT, permissionChecker, ctx.getSender());
|
||||
tes.type(side, text, soundPos);
|
||||
tes.type(side, text, soundPos, ctx.getSender());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -851,6 +851,10 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
public void type(BlockSide side, String text, BlockPos soundPos) {
|
||||
type(side, text, soundPos, null);
|
||||
}
|
||||
|
||||
public void type(BlockSide side, String text, BlockPos soundPos, @Nullable ServerPlayer sender) {
|
||||
Screen scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Tried to type on invalid screen on side %s", side.toString());
|
||||
|
|
@ -877,7 +881,8 @@ public class TileEntityScreen extends BlockEntity {
|
|||
scr.browser.injectKeyPressedByKeyCode(ev.getKeyCode(), (char) ev.getKeyCode(), ev.getModifier());
|
||||
case RELEASE ->
|
||||
scr.browser.injectKeyReleasedByKeyCode(ev.getKeyCode(), (char) ev.getKeyCode(), ev.getModifier());
|
||||
case TYPE -> scr.browser.injectKeyTyped(ev.getKeyCode(), ev.getModifier());
|
||||
case TYPE ->
|
||||
scr.browser.injectKeyTyped(ev.getKeyCode(), ev.getModifier());
|
||||
default -> throw new RuntimeException("Invalid type action '" + ev.getAction() + '\'');
|
||||
}
|
||||
}
|
||||
|
|
@ -887,7 +892,11 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.type(this, side, text));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(
|
||||
sender != null ?
|
||||
() -> point(sender, level, getBlockPos()) :
|
||||
() -> point(level, getBlockPos())
|
||||
), S2CMessageScreenUpdate.type(this, side, text));
|
||||
|
||||
if (soundPos != null)
|
||||
playSoundAt(WebDisplays.INSTANCE.soundTyping, soundPos, 0.25f, 1.f);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package net.montoyo.wd.utilities;
|
|||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class TypeData {
|
||||
|
||||
public enum Action {
|
||||
@SerializedName("i")
|
||||
INVALID,
|
||||
|
|
@ -22,9 +21,9 @@ public class TypeData {
|
|||
TYPE
|
||||
}
|
||||
|
||||
private Action a;
|
||||
private int k;
|
||||
private int m;
|
||||
private final Action a;
|
||||
private final int k;
|
||||
private final int m;
|
||||
|
||||
public TypeData() {
|
||||
a = Action.INVALID;
|
||||
|
|
@ -49,5 +48,4 @@ public class TypeData {
|
|||
public int getModifier() {
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user