Skip to content

Commit

Permalink
Add double click to morph in survival morph menu
Browse files Browse the repository at this point in the history
  • Loading branch information
asanetargoss committed Oct 18, 2020
1 parent 479a4c6 commit ba3f563
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mchorse.mclib.client.gui.framework.elements.input.GuiKeybindElement;
import mchorse.mclib.client.gui.framework.elements.utils.GuiDraw;
import mchorse.mclib.client.gui.utils.Elements;
import mchorse.mclib.client.gui.utils.GuiUtils;
import mchorse.mclib.client.gui.utils.keys.IKey;
import mchorse.metamorph.ClientProxy;
import mchorse.metamorph.Metamorph;
Expand All @@ -25,6 +26,7 @@
import net.minecraft.client.gui.Gui;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;

import org.lwjgl.input.Keyboard;

/**
Expand All @@ -48,6 +50,10 @@ public class GuiSurvivalScreen extends GuiBase

private boolean creative;
private boolean allowed;

AbstractMorph lastMorphSelected = null;
private static final int DOUBLE_CLICK_TIME_MS = 500;
private long lastClickTime = -DOUBLE_CLICK_TIME_MS - 1;

public GuiSurvivalScreen()
{
Expand Down Expand Up @@ -142,6 +148,27 @@ public void checkCurrentMorph()
AbstractMorph currentMorph = cap.getCurrentMorph();
checkCurrentMorph(currentMorph, this.morphs.getSelected());
}

private void checkDoubleClick(AbstractMorph morph)
{
if (morph == null)
{
return;
}

long clickTime = Minecraft.getSystemTime();
long dt = clickTime - lastClickTime;
lastClickTime = clickTime;
if (dt > 0 && dt < DOUBLE_CLICK_TIME_MS && lastMorphSelected.equals(morph))
{
MorphAPI.selectMorph(morph);
GuiUtils.playClick();
// Prevent re-fires
lastClickTime = 0;
this.closeScreen();
}
lastMorphSelected = morph;
}

/**
* Fill the fields with the data from current morph
Expand All @@ -163,6 +190,8 @@ public void fill(AbstractMorph morph)
this.favorite.toggled(morph.favorite);
this.keybind.setKeybind(morph.keybind);
}

checkDoubleClick(morph);
}

/**
Expand Down

0 comments on commit ba3f563

Please sign in to comment.