Skip to content

Commit

Permalink
config refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
frodare committed Oct 4, 2018
1 parent 037ce2e commit 24a7cf4
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 111 deletions.
44 changes: 44 additions & 0 deletions src/main/java/net/torocraft/torohud/conf/HealthBarGuiConf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.torocraft.torohud.conf;

import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Comment;
import net.minecraftforge.common.config.Config.Name;
import net.minecraftforge.common.config.Config.RangeInt;
import net.torocraft.torohud.ToroHUD;
import net.torocraft.torohud.conf.ParticlesConf.Color;

@Config(modid = ToroHUD.MODID, name = ToroHUD.MODID + "/healthBarGui")
@Config.LangKey("healthBarGui.config.title")
public class HealthBarGuiConf {

public enum GuiAnchor {TOP_LEFT, TOP_CENTER, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT}

public enum Skin {NONE, BASIC}

@Name("Show 3D Model of Entity")
public static boolean showEntityModel = true; // config.getBoolean("Show 3D Model of Entity", Configuration.CATEGORY_CLIENT, true, "Shows a 3D model of the entity being targeted");

@Name("Disable GUI")
public static boolean disableGui = false;

@Name("X Offset")
public static int xOffset = 0;

@Name("Y Offset")
public static int yOffset = 0;

@Name("GUI Position")
public static GuiAnchor guiPosition = GuiAnchor.TOP_LEFT;

@Name("Hide Delay")
@Comment("Delays hiding the dialog for the given number of milliseconds")
@RangeInt(min = 50, max = 5000)
public static int hideDelay = 300;

@Name("Background Skin Selection")
public static Skin skin = Skin.BASIC;

@Name("Entity Black List")
public static String[] entityBlacklist = {};

}
28 changes: 28 additions & 0 deletions src/main/java/net/torocraft/torohud/conf/HealthBarsConf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.torocraft.torohud.conf;

import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Comment;
import net.minecraftforge.common.config.Config.Name;
import net.minecraftforge.common.config.Config.RangeInt;
import net.torocraft.torohud.ToroHUD;
import net.torocraft.torohud.conf.ParticlesConf.Color;

@Config(modid = ToroHUD.MODID, name = ToroHUD.MODID + "/healthBars")
@Config.LangKey("healthBars.config.title")
public class HealthBarsConf {

public enum Mode {NONE, WHEN_HOLDING_WEAPON, ALWAYS, WHEN_HURT, WHEN_HURT_TEMP}

public enum NumberType {NONE, LAST, CUMULATIVE}

@Name("Show Bars Above Entities")
public static Mode showBarsAboveEntities = Mode.WHEN_HOLDING_WEAPON;

@Name("Damage Number Type")
public static NumberType numberType = NumberType.LAST;

@Name("Additional Weapons")
@Comment("When using WHEN_HOLDING_WEAPON to show entity bars, more items can be added here to be treated as weapons.")
public static String[] additionalWeaponItems = {};

}
25 changes: 25 additions & 0 deletions src/main/java/net/torocraft/torohud/conf/ParticlesConf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.torocraft.torohud.conf;

import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Name;
import net.torocraft.torohud.ToroHUD;

@Config(modid = ToroHUD.MODID, name = ToroHUD.MODID + "/particles")
@Config.LangKey("particles.config.title")
public class ParticlesConf {

public enum Color {RED, GREEN, BLUE, YELLOW, ORANGE, BLACK, PURPLE}

@Name("Show Damage Particles")
public static boolean showDamageParticles = true;

@Name("Heal Color")
public static Color healColor = Color.GREEN;

@Name("Damage Color")
public static Color damageColor = Color.RED;

@Name("Visible Throw Walls")
public static boolean visibleThroughWalls = false;

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraftforge.common.config.Config.Name;
import net.torocraft.torohud.ToroHUD;

@Config(modid = ToroHUD.MODID, name = "Entity Display Settings")
public class EntityDisplay implements IDisplay {

private static final int RENDER_HEIGHT = 30;
Expand All @@ -37,9 +36,6 @@ public class EntityDisplay implements IDisplay {
private float prevPrevYahHead;
private int scale = 1;

@Name("Show 3D Model of Entity")
public static boolean showEntityModel = true; // config.getBoolean("Show 3D Model of Entity", Configuration.CATEGORY_CLIENT, true, "Shows a 3D model of the entity being targeted");

public EntityDisplay(Minecraft mc) {
}

Expand Down
58 changes: 12 additions & 46 deletions src/main/java/net/torocraft/torohud/gui/GuiEntityStatus.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.torocraft.torohud.gui;

import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
Expand All @@ -10,12 +8,9 @@
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Comment;
import net.minecraftforge.common.config.Config.Name;
import net.minecraftforge.common.config.Config.RangeInt;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.torocraft.torohud.ToroHUD;
import net.torocraft.torohud.conf.HealthBarGuiConf;
import net.torocraft.torohud.display.BarDisplay;
import net.torocraft.torohud.display.EntityDisplay;
import net.torocraft.torohud.display.IDisplay;
Expand All @@ -24,36 +19,6 @@

public class GuiEntityStatus extends Gui {

@Config(modid = ToroHUD.MODID, name = "GUI Settings")
public static class Conf {
public enum GuiAnchor {TOP_LEFT, TOP_CENTER, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT}
public enum Skin {NONE, BASIC}

@Name("Disable GUI")
public static boolean disableGui = false;

@Name("X Offset")
public static int xOffset = 0;

@Name("Y Offset")
public static int yOffset = 0;

@Name("GUI Position")
public static GuiAnchor guiPosition = GuiAnchor.TOP_LEFT;

@Name("Hide Delay")
@Comment("Delays hiding the dialog for the given number of milliseconds")
@RangeInt(min = 50, max = 5000)
public static int hideDelay = 300;

@Name("Background Skin Selection")
public static Skin skin = Skin.BASIC;

@Name("Entity Black List")
public static String[] entityBlacklist = {};

}

private static final int PADDING_FROM_EDGE = 3;
private static final ResourceLocation SKIN_BASIC = new ResourceLocation(ToroHUD.MODID, "textures/gui/default_skin_basic.png");
private static final ResourceLocation SKIN_HEAVY = new ResourceLocation(ToroHUD.MODID, "textures/gui/default_skin_heavy.png");
Expand Down Expand Up @@ -88,7 +53,7 @@ public GuiEntityStatus(Minecraft mc) {

@SubscribeEvent
public void drawHealthBar(RenderGameOverlayEvent.Pre event) {
if (Conf.disableGui || !showHealthBar || event.getType() != ElementType.CHAT) {
if (HealthBarGuiConf.disableGui || !showHealthBar || event.getType() != ElementType.CHAT) {
return;
}
updateGuiAge();
Expand All @@ -98,7 +63,7 @@ public void drawHealthBar(RenderGameOverlayEvent.Pre event) {
}

private void drawSkin() {
if (Conf.skin.equals(Conf.Skin.NONE) || !EntityDisplay.showEntityModel) {
if (HealthBarGuiConf.skin.equals(HealthBarGuiConf.Skin.NONE) || !HealthBarGuiConf.showEntityModel) {
return;
}
mc.getTextureManager().bindTexture(SKIN_BASIC);
Expand All @@ -108,7 +73,7 @@ private void drawSkin() {

private void updateGuiAge() {
age = age + 15;
if (age > Conf.hideDelay) {
if (age > HealthBarGuiConf.hideDelay) {
hideHealthBar();
}
}
Expand All @@ -119,12 +84,13 @@ private void updatePositions() {
x = screenX;
y = screenY;

if (EntityDisplay.showEntityModel) {
if (HealthBarGuiConf.showEntityModel) {
entityDisplay.setPosition(x, y);
x += 40;
}

if (Conf.guiPosition.equals(Conf.GuiAnchor.BOTTOM_LEFT) || Conf.guiPosition.equals(Conf.GuiAnchor.BOTTOM_RIGHT)) {
if (HealthBarGuiConf.guiPosition.equals(HealthBarGuiConf.GuiAnchor.BOTTOM_LEFT) || HealthBarGuiConf.guiPosition
.equals(HealthBarGuiConf.GuiAnchor.BOTTOM_RIGHT)) {
y += 6;
}

Expand All @@ -133,7 +99,7 @@ private void updatePositions() {
}

private void draw() {
if (EntityDisplay.showEntityModel) {
if (HealthBarGuiConf.showEntityModel) {
entityDisplay.draw();
}
barDisplay.draw();
Expand All @@ -142,7 +108,7 @@ private void draw() {

private void adjustForDisplayPositionSetting() {

if (EntityDisplay.showEntityModel) {
if (HealthBarGuiConf.showEntityModel) {
displayHeight = 40;
displayWidth = 140;
} else {
Expand All @@ -151,7 +117,7 @@ private void adjustForDisplayPositionSetting() {
}

ScaledResolution viewport = new ScaledResolution(mc);
String displayPosition = Conf.guiPosition.toString();
String displayPosition = HealthBarGuiConf.guiPosition.toString();

int sh = viewport.getScaledHeight();
int sw = viewport.getScaledWidth();
Expand All @@ -176,8 +142,8 @@ private void adjustForDisplayPositionSetting() {
screenX = (sw - displayWidth) / 2;
}

screenX += Conf.xOffset;
screenY += Conf.yOffset;
screenX += HealthBarGuiConf.xOffset;
screenY += HealthBarGuiConf.yOffset;
}

private void showHealthBar() {
Expand Down
41 changes: 9 additions & 32 deletions src/main/java/net/torocraft/torohud/gui/HealthBars.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Comment;
import net.minecraftforge.common.config.Config.Name;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.torocraft.torohud.ToroHUD;
import net.torocraft.torohud.conf.HealthBarsConf;
import net.torocraft.torohud.display.AbstractEntityDisplay;
import net.torocraft.torohud.gui.HealthBars.Conf.Mode;
import net.torocraft.torohud.gui.HealthBars.Conf.NumberType;
import net.torocraft.torohud.util.EntityUtil;
import org.apache.commons.lang3.ArrayUtils;
import org.lwjgl.opengl.GL11;
Expand Down Expand Up @@ -71,25 +67,6 @@ public class HealthBars {
private static boolean holdingWeapon = false;
private static long tickCount = 0;

@Config(modid = ToroHUD.MODID, name = "Health Bar Settings")
public static class Conf {

public enum Mode {NONE, WHEN_HOLDING_WEAPON, ALWAYS, WHEN_HURT, WHEN_HURT_TEMP}

public enum NumberType {NONE, LAST, CUMULATIVE}

@Name("Show Bars Above Entities")
public static Mode showBarsAboveEntities = Mode.WHEN_HOLDING_WEAPON;

@Name("Damage Number Type")
public static NumberType numberType = NumberType.LAST;

@Name("Additional Weapons")
@Comment("When using WHEN_HOLDING_WEAPON to show entity bars, more items can be added here to be treated as weapons.")
public static String[] additionalWeaponItems = {};

}

@SubscribeEvent
public static void onRenderWorldLast(RenderWorldLastEvent event) {
if (!barsAreCurrentlyDisabled()) {
Expand All @@ -103,10 +80,10 @@ public static void onRenderWorldLast(RenderWorldLastEvent event) {
}

public static boolean barsAreCurrentlyDisabled() {
if (Conf.showBarsAboveEntities.equals(Mode.ALWAYS)) {
if (HealthBarsConf.showBarsAboveEntities.equals(HealthBarsConf.Mode.ALWAYS)) {
return false;
}
if (Conf.showBarsAboveEntities.equals(Mode.WHEN_HOLDING_WEAPON)) {
if (HealthBarsConf.showBarsAboveEntities.equals(HealthBarsConf.Mode.WHEN_HOLDING_WEAPON)) {
return !holdingWeapon;
}
return false;
Expand Down Expand Up @@ -139,7 +116,7 @@ public static void cleanup(ClientTickEvent event) {
states.entrySet().removeIf(e -> stateExpired(world, e.getKey(), e.getValue()));
}

if (Conf.showBarsAboveEntities.equals(Mode.WHEN_HOLDING_WEAPON) && tickCount % 10 == 0) {
if (HealthBarsConf.showBarsAboveEntities.equals(HealthBarsConf.Mode.WHEN_HOLDING_WEAPON) && tickCount % 10 == 0) {
updateEquipment();
}

Expand All @@ -166,7 +143,7 @@ private static boolean isWeapon(ItemStack item) {

private static boolean isInWeaponWhiteList(ItemStack item) {
String itemName = item.getItem().getUnlocalizedName();
return ArrayUtils.contains(Conf.additionalWeaponItems, itemName);
return ArrayUtils.contains(HealthBarsConf.additionalWeaponItems, itemName);
}

private static boolean stateExpired(World world, int id, State state) {
Expand Down Expand Up @@ -201,7 +178,7 @@ public static void drawEntityHealthBarInWorld(EntityLivingBase entity, float par
if (!EntityUtil.whiteListedEntity(entity) || entity == Minecraft.getMinecraft().player) {
return;
}
if (Conf.showBarsAboveEntities.equals(Mode.WHEN_HURT) && entity.getHealth() >= entity.getMaxHealth()) {
if (HealthBarsConf.showBarsAboveEntities.equals(HealthBarsConf.Mode.WHEN_HURT) && entity.getHealth() >= entity.getMaxHealth()) {
return;
}
double x = entity.lastTickPosX + ((entity.posX - entity.lastTickPosX) * partialTicks);
Expand Down Expand Up @@ -241,7 +218,7 @@ private static void drawEntityHealthBar(EntityLivingBase entity, double x, doubl
state.previousHealthDelay = HEALTH_INDICATOR_DELAY;
}

if (Conf.showBarsAboveEntities.equals(Mode.WHEN_HURT_TEMP) && gui == null && state.lastDmg == 0) {
if (HealthBarsConf.showBarsAboveEntities.equals(HealthBarsConf.Mode.WHEN_HURT_TEMP) && gui == null && state.lastDmg == 0) {
return;
}

Expand All @@ -256,9 +233,9 @@ private static void drawEntityHealthBar(EntityLivingBase entity, double x, doubl
drawBar(gui, x, y, z, 1, DARK_GRAY, zOffset++);
drawBar(gui, x, y, z, percent2, color2, zOffset++);
drawBar(gui, x, y, z, percent, color, zOffset++);
if (Conf.numberType.equals(NumberType.CUMULATIVE)) {
if (HealthBarsConf.numberType.equals(HealthBarsConf.NumberType.CUMULATIVE)) {
drawDamageNumber(state.previousHealth - entity.getHealth(), entity, gui, x, y, z, zOffset);
} else if (Conf.numberType.equals(NumberType.LAST)) {
} else if (HealthBarsConf.numberType.equals(HealthBarsConf.NumberType.LAST)) {
drawDamageNumber(state.lastDmg, entity, gui, x, y, z, zOffset);
}
}
Expand Down
Loading

0 comments on commit 24a7cf4

Please sign in to comment.