Added a ctrl+toggle for the jumping and sneaking actions on the skins gui

This commit is contained in:
Sollace 2018-10-12 13:39:36 +02:00
parent 323db09017
commit 7a1b77ccdf
2 changed files with 92 additions and 8 deletions

View file

@ -13,6 +13,7 @@ import com.voxelmodpack.hdskins.SkinUploader.ISkinUploadHandler;
import com.voxelmodpack.hdskins.server.SkinServer; import com.voxelmodpack.hdskins.server.SkinServer;
import com.voxelmodpack.hdskins.upload.GLWindow; import com.voxelmodpack.hdskins.upload.GLWindow;
import com.voxelmodpack.hdskins.util.CallableFutures; import com.voxelmodpack.hdskins.util.CallableFutures;
import com.voxelmodpack.hdskins.util.Edge;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
@ -59,11 +60,33 @@ public class GuiSkins extends GameGui implements ISkinUploadHandler {
private int lastMouseX = 0; private int lastMouseX = 0;
private boolean jumpState = false;
private boolean sneakState = false;
protected final SkinUploader uploader; protected final SkinUploader uploader;
protected final SkinChooser chooser; protected final SkinChooser chooser;
protected final CubeMap panorama; protected final CubeMap panorama;
private final Edge ctrlKey = new Edge(this::ctrlToggled) {
@Override
protected boolean nextState() {
return Keyboard.isKeyDown(Keyboard.KEY_FUNCTION) || Keyboard.isKeyDown(Keyboard.KEY_LCONTROL);
}
};
private final Edge jumpKey = new Edge(this::jumpToggled) {
@Override
protected boolean nextState() {
return Keyboard.isKeyDown(Keyboard.KEY_SPACE);
}
};
private final Edge sneakKey = new Edge(this::sneakToggled) {
@Override
protected boolean nextState() {
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
}
};
public GuiSkins(List<SkinServer> servers) { public GuiSkins(List<SkinServer> servers) {
mc = Minecraft.getMinecraft(); mc = Minecraft.getMinecraft();
GameProfile profile = mc.getSession().getProfile(); GameProfile profile = mc.getSession().getProfile();
@ -254,16 +277,45 @@ public class GuiSkins extends GameGui implements ISkinUploadHandler {
} }
} }
private void jumpToggled(boolean jumping) {
if (jumping && ctrlKey.getState()) {
jumpState = !jumpState;
}
jumping |= jumpState;
localPlayer.setJumping(jumping);
remotePlayer.setJumping(jumping);
}
private void sneakToggled(boolean sneaking) {
if (sneaking && ctrlKey.getState()) {
sneakState = !sneakState;
}
sneaking |= sneakState;
localPlayer.setSneaking(sneaking);
remotePlayer.setSneaking(sneaking);
}
private void ctrlToggled(boolean ctrl) {
if (ctrl) {
if (sneakKey.getState()) {
sneakState = !sneakState;
}
if (jumpKey.getState()) {
jumpState = !jumpState;
}
}
}
@Override @Override
protected void drawContents(int mouseX, int mouseY, float partialTick) { protected void drawContents(int mouseX, int mouseY, float partialTick) {
boolean sneak = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); ctrlKey.update();
jumpKey.update();
localPlayer.setSneaking(sneak); sneakKey.update();
remotePlayer.setSneaking(sneak);
boolean jump = Keyboard.isKeyDown(Keyboard.KEY_SPACE);
localPlayer.setJumping(jump);
remotePlayer.setJumping(jump);
float deltaTime = panorama.getDelta(partialTick); float deltaTime = panorama.getDelta(partialTick);
panorama.render(partialTick, zLevel); panorama.render(partialTick, zLevel);

View file

@ -0,0 +1,32 @@
package com.voxelmodpack.hdskins.util;
public abstract class Edge {
private boolean previousState;
private Callback callback;
public Edge(Callback callback) {
this.callback = callback;
}
public void update() {
boolean state = nextState();
if (state != previousState) {
previousState = state;
callback.call(state);
}
}
public boolean getState() {
return previousState;
}
protected abstract boolean nextState();
@FunctionalInterface
public interface Callback {
void call(boolean state);
}
}