Add better key modifier behavior for GUI contexts (#3307)

This commit is contained in:
mezz 2016-10-14 13:14:27 -07:00 committed by LexManos
parent 7bbd3954f5
commit bea5d44273
2 changed files with 53 additions and 6 deletions

View file

@ -53,11 +53,11 @@
public boolean func_151470_d() public boolean func_151470_d()
{ {
- return this.field_74513_e; - return this.field_74513_e;
+ return this.field_74513_e && getKeyConflictContext().isActive() && getKeyModifier().isActive(); + return this.field_74513_e && getKeyConflictContext().isActive() && getKeyModifier().isActive(getKeyConflictContext());
} }
public String func_151466_e() public String func_151466_e()
@@ -158,4 +158,130 @@ @@ -158,4 +158,135 @@
return i; return i;
} }
@ -101,7 +101,7 @@
+ */ + */
+ public boolean isActiveAndMatches(int keyCode) + public boolean isActiveAndMatches(int keyCode)
+ { + {
+ return keyCode != 0 && keyCode == this.func_151463_i() && getKeyConflictContext().isActive() && getKeyModifier().isActive(); + return keyCode != 0 && keyCode == this.func_151463_i() && getKeyConflictContext().isActive() && getKeyModifier().isActive(getKeyConflictContext());
+ } + }
+ +
+ public void setKeyConflictContext(net.minecraftforge.client.settings.IKeyConflictContext keyConflictContext) + public void setKeyConflictContext(net.minecraftforge.client.settings.IKeyConflictContext keyConflictContext)
@ -159,9 +159,14 @@
+ { + {
+ return true; + return true;
+ } + }
+ else if (keyModifier == otherKeyModifier || keyModifier == net.minecraftforge.client.settings.KeyModifier.NONE || otherKeyModifier == net.minecraftforge.client.settings.KeyModifier.NONE) + else if (func_151463_i() == other.func_151463_i())
+ { + {
+ return func_151463_i() == other.func_151463_i(); + return keyModifier == otherKeyModifier ||
+ // IN_GAME key contexts have a conflict when at least one modifier is NONE.
+ // For example: If you hold shift to crouch, you can still press E to open your inventory. This means that a Shift+E hotkey is in conflict with E.
+ // GUI and other key contexts do not have this limitation.
+ (getKeyConflictContext().conflicts(net.minecraftforge.client.settings.KeyConflictContext.IN_GAME) &&
+ (keyModifier == net.minecraftforge.client.settings.KeyModifier.NONE || otherKeyModifier == net.minecraftforge.client.settings.KeyModifier.NONE));
+ } + }
+ } + }
+ return false; + return false;

View file

@ -19,6 +19,8 @@
package net.minecraftforge.client.settings; package net.minecraftforge.client.settings;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
@ -46,6 +48,12 @@ public enum KeyModifier {
return GuiScreen.isCtrlKeyDown(); return GuiScreen.isCtrlKeyDown();
} }
@Override
public boolean isActive(@Nullable IKeyConflictContext conflictContext)
{
return GuiScreen.isCtrlKeyDown();
}
@Override @Override
public String getLocalizedComboName(int keyCode) public String getLocalizedComboName(int keyCode)
{ {
@ -67,6 +75,12 @@ public enum KeyModifier {
return GuiScreen.isShiftKeyDown(); return GuiScreen.isShiftKeyDown();
} }
@Override
public boolean isActive(@Nullable IKeyConflictContext conflictContext)
{
return GuiScreen.isShiftKeyDown();
}
@Override @Override
public String getLocalizedComboName(int keyCode) public String getLocalizedComboName(int keyCode)
{ {
@ -87,6 +101,12 @@ public enum KeyModifier {
return GuiScreen.isAltKeyDown(); return GuiScreen.isAltKeyDown();
} }
@Override
public boolean isActive(@Nullable IKeyConflictContext conflictContext)
{
return GuiScreen.isAltKeyDown();
}
@Override @Override
public String getLocalizedComboName(int keyCode) public String getLocalizedComboName(int keyCode)
{ {
@ -107,6 +127,22 @@ public enum KeyModifier {
return true; return true;
} }
@Override
public boolean isActive(@Nullable IKeyConflictContext conflictContext)
{
if (conflictContext != null && !conflictContext.conflicts(KeyConflictContext.IN_GAME))
{
for (KeyModifier keyModifier : MODIFIER_VALUES)
{
if (keyModifier.isActive(conflictContext))
{
return false;
}
}
}
return true;
}
@Override @Override
public String getLocalizedComboName(int keyCode) public String getLocalizedComboName(int keyCode)
{ {
@ -120,7 +156,7 @@ public enum KeyModifier {
{ {
for (KeyModifier keyModifier : MODIFIER_VALUES) for (KeyModifier keyModifier : MODIFIER_VALUES)
{ {
if (keyModifier.isActive()) if (keyModifier.isActive(null))
{ {
return keyModifier; return keyModifier;
} }
@ -158,7 +194,13 @@ public enum KeyModifier {
public abstract boolean matches(int keyCode); public abstract boolean matches(int keyCode);
/**
* @deprecated use {@link #isActive(IKeyConflictContext)}
*/
@Deprecated
public abstract boolean isActive(); public abstract boolean isActive();
public abstract boolean isActive(@Nullable IKeyConflictContext conflictContext);
public abstract String getLocalizedComboName(int keyCode); public abstract String getLocalizedComboName(int keyCode);
} }