Skip to content

Commit

Permalink
Added a keybinding to turn on or off.
Browse files Browse the repository at this point in the history
  • Loading branch information
samvbeckmann committed Dec 22, 2014
1 parent efffb5a commit ca9c49c
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 12 deletions.
65 changes: 65 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Created by .gitignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml

# Gradle:
# .idea/gradle.xml
# .idea/libraries

# Mongo Explorer plugin:
# .idea/mongoSettings.xml

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties


### Java template
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*


17 changes: 15 additions & 2 deletions src/main/java/com/qkninja/clockhud/ClockHUD.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.qkninja.clockhud;

import com.qkninja.clockhud.client.handler.KeyInputEventHandler;
import com.qkninja.clockhud.proxy.IProxy;
import com.qkninja.clockhud.reference.Reference;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

/**
* Created by Sam on 2014-12-20.
* A simple clock GUI to make telling the time easier.
* @author QKninja
* @version 1.7.10-1.0
*/
@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)
public class ClockHUD
Expand All @@ -20,9 +25,17 @@ public class ClockHUD
public static IProxy proxy;

@Mod.EventHandler
public void Init(FMLInitializationEvent event)
public void preInit(FMLPreInitializationEvent event)
{
proxy.registerKeyBindings();
}

@Mod.EventHandler
public void init(FMLInitializationEvent event)
{
proxy.registerRenderers();

FMLCommonHandler.instance().bus().register(new KeyInputEventHandler());
}

}
3 changes: 2 additions & 1 deletion src/main/java/com/qkninja/clockhud/client/gui/GuiClock.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.qkninja.clockhud.client.gui;

import com.qkninja.clockhud.reference.ConfigValues;
import com.qkninja.clockhud.reference.Textures;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
Expand Down Expand Up @@ -39,7 +40,7 @@ public GuiClock(Minecraft mc)
public void onRenderExperienceBar(RenderGameOverlayEvent.Post event)
{

if(event.isCancelable() || event.type != RenderGameOverlayEvent.ElementType.EXPERIENCE)
if(event.isCancelable() || event.type != RenderGameOverlayEvent.ElementType.EXPERIENCE || !ConfigValues.guiActive)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.qkninja.clockhud.client.handler;

import com.qkninja.clockhud.client.settings.KeyBindings;
import com.qkninja.clockhud.reference.ConfigValues;
import com.qkninja.clockhud.reference.Key;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;

public class KeyInputEventHandler
{

private static Key getPressedKeyBinding()
{
if (KeyBindings.toggle.isPressed())
return Key.TOGGLE;
else return Key.UNKNOWN;
}

@SubscribeEvent
public void handleKeyInputEvent(InputEvent.KeyInputEvent event)
{
if (getPressedKeyBinding() == Key.TOGGLE)
{
if (ConfigValues.guiActive)
ConfigValues.guiActive = false;
else
ConfigValues.guiActive = true;
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.qkninja.clockhud.client.settings;

import com.qkninja.clockhud.reference.Names;
import net.minecraft.client.settings.KeyBinding;
import org.lwjgl.input.Keyboard;

public class KeyBindings
{
public static KeyBinding toggle = new KeyBinding(Names.Keys.TOGGLE, Keyboard.KEY_COMMA, Names.Keys.CATEGORY);
}
10 changes: 7 additions & 3 deletions src/main/java/com/qkninja/clockhud/proxy/ClientProxy.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.qkninja.clockhud.proxy;

import com.qkninja.clockhud.client.gui.GuiClock;
import com.qkninja.clockhud.client.settings.KeyBindings;
import cpw.mods.fml.client.registry.ClientRegistry;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;

/**
* Created by Sam on 2014-12-20.
*/
public class ClientProxy extends CommonProxy
{

Expand All @@ -17,4 +16,9 @@ public void registerRenderers()
{
MinecraftForge.EVENT_BUS.register(new GuiClock(mc));
}

public void registerKeyBindings()
{
ClientRegistry.registerKeyBinding(KeyBindings.toggle);
}
}
5 changes: 2 additions & 3 deletions src/main/java/com/qkninja/clockhud/proxy/IProxy.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.qkninja.clockhud.proxy;

/**
* Created by Sam on 2014-12-20.
*/
public interface IProxy
{

public void registerRenderers();

public void registerKeyBindings();

}
5 changes: 2 additions & 3 deletions src/main/java/com/qkninja/clockhud/proxy/ServerProxy.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.qkninja.clockhud.proxy;

/**
* Created by Sam on 2014-12-20.
*/
public class ServerProxy extends CommonProxy
{
public void registerRenderers() {}

public void registerKeyBindings() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.qkninja.clockhud.reference;

public class ConfigValues
{
public static boolean guiActive = true;
}
9 changes: 9 additions & 0 deletions src/main/java/com/qkninja/clockhud/reference/Key.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.qkninja.clockhud.reference;

/**
* Enum to see what key is pressed.
*/
public enum Key
{
UNKNOWN, TOGGLE
}
10 changes: 10 additions & 0 deletions src/main/java/com/qkninja/clockhud/reference/Names.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.qkninja.clockhud.reference;

public final class Names
{
public static final class Keys
{
public static final String CATEGORY = "keys.clockhud.category";
public static final String TOGGLE = "keys.clockhud.toggle";
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/clockhud/lang/en_US.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Keys
keys.clockhud.category=Clock HUD
keys.clockhud.toggle=Toggle
17 changes: 17 additions & 0 deletions src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"modid": "ClockHUD",
"name": "Clock HUD",
"description": "A simple clock GUI to check the time.",
"version": "1.7.0-1.0",
"mcversion": "1.7.10",
"url": "",
"updateUrl": "",
"authorList": [ "QKninja" ],
"credits": "Created by QKninja",
"logoFile": "",
"parent":"",
"screenshots": [],
"dependencies": []
}
]

0 comments on commit ca9c49c

Please sign in to comment.