Added keybinding to toggle if hud is shown

This commit is contained in:
Gig 2015-06-14 20:53:05 +01:00
parent 59d4199260
commit 98c8f43b84
6 changed files with 118 additions and 48 deletions

View file

@ -3,6 +3,7 @@ package techreborn.client.hud;
import org.lwjgl.opengl.GL11;
import codechicken.lib.colour.ColourARGB;
import techreborn.client.keybindings.KeyBindings;
import techreborn.config.ConfigTechReborn;
import techreborn.util.Color;
import ic2.api.item.ElectricItem;
@ -28,11 +29,24 @@ public class ChargeHud
{
public static final ChargeHud instance = new ChargeHud();
private static Minecraft mc = Minecraft.getMinecraft();
public static KeyBindings key;
public static boolean showHud = true;
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.LOW)
public void onRenderExperienceBar(RenderGameOverlayEvent event)
{
if (key.config.isPressed())
{
if (showHud == true)
{
showHud = false;
}
else if (showHud == false)
showHud = true;
}
if (event.isCancelable() || event.type != ElementType.ALL)
return;
@ -45,7 +59,8 @@ public class ChargeHud
EntityPlayer player = mc.thePlayer;
ItemStack stack = player.getCurrentArmor(2);
ItemStack stack2 = mc.thePlayer.inventory.getCurrentItem();
if (showHud == true)
{
if(stack2 != null)
{
if ((stack2.getItem() instanceof IElectricItem))
@ -104,4 +119,5 @@ public class ChargeHud
}
}
}
}
}

View file

@ -0,0 +1,14 @@
package techreborn.client.keybindings;
import net.minecraft.client.settings.KeyBinding;
import org.lwjgl.input.Keyboard;
import techreborn.lib.ModInfo;
public class KeyBindings {
public static KeyBinding config = new KeyBinding(ModInfo.Keys.CONFIG,
Keyboard.KEY_P, ModInfo.Keys.CATEGORY);
}

View file

@ -0,0 +1,25 @@
package techreborn.client.keybindings;
import techreborn.lib.Key;
import techreborn.util.LogHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
public class KeyInputEventHandler
{
private static Key getPressedKeybinding()
{
if (KeyBindings.config.isPressed()) {
return Key.CONFIG;
}
return Key.UNKNOWN;
}
@SubscribeEvent
public void handleKeyInputEvent(InputEvent.KeyInputEvent event)
{
LogHelper.info(getPressedKeybinding());
}
}

View file

@ -0,0 +1,6 @@
package techreborn.lib;
public enum Key {
UNKNOWN, CONFIG;
}

View file

@ -8,4 +8,10 @@ public class ModInfo {
public static final String SERVER_PROXY_CLASS = "techreborn.proxies.CommonProxy";
public static final String CLIENT_PROXY_CLASS = "techreborn.proxies.ClientProxy";
public static final String GUI_FACTORY_CLASS = "techreborn.config.TechRebornGUIFactory";
public static final class Keys
{
public static final String CATEGORY = "keys.techreborn.category";
public static final String CONFIG = "keys.techreborn.config";
}
}

View file

@ -1,8 +1,10 @@
package techreborn.proxies;
import cpw.mods.fml.client.registry.ClientRegistry;
import net.minecraftforge.common.MinecraftForge;
import techreborn.client.IconSupplier;
import techreborn.client.hud.ChargeHud;
import techreborn.client.keybindings.KeyBindings;
public class ClientProxy extends CommonProxy {
@ -12,5 +14,6 @@ public class ClientProxy extends CommonProxy {
super.init();
MinecraftForge.EVENT_BUS.register(new IconSupplier());
MinecraftForge.EVENT_BUS.register(new ChargeHud());
ClientRegistry.registerKeyBinding(KeyBindings.config);
}
}