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,62 +59,64 @@ public class ChargeHud
EntityPlayer player = mc.thePlayer;
ItemStack stack = player.getCurrentArmor(2);
ItemStack stack2 = mc.thePlayer.inventory.getCurrentItem();
if(stack2 != null)
if (showHud == true)
{
if ((stack2.getItem() instanceof IElectricItem))
if(stack2 != null)
{
double MaxCharge = ((IElectricItem) stack2.getItem()).getMaxCharge(stack2);
double CurrentCharge = ElectricItem.manager.getCharge(stack2);
Color color = Color.GREEN;
double quarter = MaxCharge / 4;
double half = MaxCharge / 2;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glEnable(32826);
RenderHelper.enableStandardItemLighting();
RenderHelper.enableGUIStandardItemLighting();
RenderItem.getInstance().renderItemAndEffectIntoGUI(mc.fontRenderer, mc.renderEngine, stack2, 0, 20);
RenderItem.getInstance().renderItemOverlayIntoGUI(mc.fontRenderer, mc.renderEngine, stack2, 0, 20);
if(CurrentCharge <= half)
if ((stack2.getItem() instanceof IElectricItem))
{
color = Color.YELLOW;
double MaxCharge = ((IElectricItem) stack2.getItem()).getMaxCharge(stack2);
double CurrentCharge = ElectricItem.manager.getCharge(stack2);
Color color = Color.GREEN;
double quarter = MaxCharge / 4;
double half = MaxCharge / 2;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glEnable(32826);
RenderHelper.enableStandardItemLighting();
RenderHelper.enableGUIStandardItemLighting();
RenderItem.getInstance().renderItemAndEffectIntoGUI(mc.fontRenderer, mc.renderEngine, stack2, 0, 20);
RenderItem.getInstance().renderItemOverlayIntoGUI(mc.fontRenderer, mc.renderEngine, stack2, 0, 20);
if(CurrentCharge <= half)
{
color = Color.YELLOW;
}
if(CurrentCharge <= quarter)
{
color = Color.DARK_RED;
}
mc.fontRenderer.drawString(color + Double.toString(CurrentCharge) + "/" + Double.toString(MaxCharge), 20, 25, 0);
}
if(CurrentCharge <= quarter)
{
color = Color.DARK_RED;
}
mc.fontRenderer.drawString(color + Double.toString(CurrentCharge) + "/" + Double.toString(MaxCharge), 20, 25, 0);
}
}
if(stack != null)
{
if((stack.getItem() instanceof IElectricItem) && ConfigTechReborn.ShowChargeHud)
if(stack != null)
{
double MaxCharge = ((IElectricItem) stack.getItem()).getMaxCharge(stack);
double CurrentCharge = ElectricItem.manager.getCharge(stack);
Color color = Color.GREEN;
double quarter = MaxCharge / 4;
double half = MaxCharge / 2;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glEnable(32826);
RenderHelper.enableStandardItemLighting();
RenderHelper.enableGUIStandardItemLighting();
//Render the stack
RenderItem.getInstance().renderItemAndEffectIntoGUI(mc.fontRenderer, mc.renderEngine, stack, 0, 0);
//Render Overlay
RenderItem.getInstance().renderItemOverlayIntoGUI(mc.fontRenderer, mc.renderEngine, stack, 0, 0);
//Get the color depending on current charge
if(CurrentCharge <= half)
if((stack.getItem() instanceof IElectricItem) && ConfigTechReborn.ShowChargeHud)
{
color = Color.YELLOW;
double MaxCharge = ((IElectricItem) stack.getItem()).getMaxCharge(stack);
double CurrentCharge = ElectricItem.manager.getCharge(stack);
Color color = Color.GREEN;
double quarter = MaxCharge / 4;
double half = MaxCharge / 2;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glEnable(32826);
RenderHelper.enableStandardItemLighting();
RenderHelper.enableGUIStandardItemLighting();
//Render the stack
RenderItem.getInstance().renderItemAndEffectIntoGUI(mc.fontRenderer, mc.renderEngine, stack, 0, 0);
//Render Overlay
RenderItem.getInstance().renderItemOverlayIntoGUI(mc.fontRenderer, mc.renderEngine, stack, 0, 0);
//Get the color depending on current charge
if(CurrentCharge <= half)
{
color = Color.YELLOW;
}
if(CurrentCharge <= quarter)
{
color = Color.DARK_RED;
}
mc.fontRenderer.drawString(color + Double.toString(CurrentCharge) + "/" + Double.toString(MaxCharge), 20, 5, 0);
}
if(CurrentCharge <= quarter)
{
color = Color.DARK_RED;
}
mc.fontRenderer.drawString(color + Double.toString(CurrentCharge) + "/" + Double.toString(MaxCharge), 20, 5, 0);
}
}
}

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);
}
}