diff --git a/src/main/java/tennox/customselectionbox/CSB.java b/src/main/java/tennox/customselectionbox/CSB.java index 13aa83d..2da5ee4 100644 --- a/src/main/java/tennox/customselectionbox/CSB.java +++ b/src/main/java/tennox/customselectionbox/CSB.java @@ -54,13 +54,13 @@ public class CSB { public static CSBCommonProxy proxy; private static Configuration config; public static Logger logger; - public static float red; - public static float green; - public static float blue; - public static float alpha; - public static float thickness; - public static float blinkalpha; - public static float blinkspeed; + public static CSBFloat red = new CSBFloat("Red", 255, 0f, 0f); + public static CSBFloat green = new CSBFloat("Green", 255, 0f, 0f); + public static CSBFloat blue = new CSBFloat("Blue", 255, 0f, 0f); + public static CSBFloat alpha = new CSBFloat("Alpha", 255, 0.4f, 1.0f); + public static CSBFloat thickness = new CSBFloat("Thickness", 7, 2f, 4f).setMinMax(0.1f, 7f); + public static CSBFloat blinkalpha = new CSBFloat("Blink Alpha", 255, 0f, 0.4f); + public static CSBFloat blinkspeed = new CSBFloat("Blink Speed", 100, 0f, 0.2f); public static boolean diffButtonLoc; public static boolean disableDepthBuffer; public static int breakAnimation; @@ -91,44 +91,53 @@ public void preInit(FMLPreInitializationEvent event) { int bra = config.get("general", "break_animation", 0).getInt(); config.save(); - setRed(r / 255.0F); - setGreen(g / 255.0F); - setBlue(b / 255.0F); - setAlpha(a / 255.0F); - setThickness(t); - setBlinkAlpha(ba / 255.0F); - setBlinkSpeed(bs / 100.0F); + red.setFromInt(r); + green.setFromInt(g); + blue.setFromInt(b); + alpha.setFromInt(a); + thickness.setFromInt(t); + blinkalpha.setFromInt(ba); + blinkspeed.setFromInt(bs); setBreakAnimation(bra); - logger.info("red=" + getRed() + " green=" + getGreen() + " blue=" + getBlue() + " alpha=" + getAlpha()); - logger.info("thickness=" + getThickness() + " diffbuttonloc=" + diffButtonLoc); - logger.info("blinkalpha=" + getBlinkAlpha() + " blinkspeed=" + getBlinkSpeed()); + logger.info("SAVED: red=" + red.get() + " green=" + green.get() + " blue=" + blue.get() + " alpha=" + alpha.get()); + logger.info("SAVED: thickness=" + thickness.get() + " diffbuttonloc=" + diffButtonLoc + " blinkalpha=" + blinkalpha.get() + " blinkspeed=" + blinkspeed.get()); } public static void save() { config.load(); - config.get("general", "red", 0).set(getRedInt()); - config.get("general", "green", 0).set(getGreenInt()); - config.get("general", "blue", 0).set(getBlueInt()); - config.get("general", "alpha", 255).set(getAlphaInt()); - config.get("general", "thickness", 4).set(getThicknessInt()); - config.get("general", "blink_alpha", 100).set(getBlinkAlphaInt()); - config.get("general", "blink_speed", 30).set(getBlinkSpeedInt()); + config.get("general", "red", 0).set(red.getAsInt()); + config.get("general", "green", 0).set(green.getAsInt()); + config.get("general", "blue", 0).set(blue.getAsInt()); + config.get("general", "alpha", 255).set(alpha.getAsInt()); + config.get("general", "thickness", 4).set(thickness.getAsInt()); + config.get("general", "blink_alpha", 100).set(blinkalpha.getAsInt()); + config.get("general", "blink_speed", 30).set(blinkspeed.getAsInt()); config.get("general", "disable_depth", false).set(disableDepthBuffer); config.get("general", "break_animation", 0).set(breakAnimation); config.save(); - logger.info("SAVED: red=" + getRed() + " green=" + getGreen() + " blue=" + getBlue() + " alpha=" + getAlpha()); - logger.info("SAVED: thickness=" + getThickness() + " blinkalpha=" + getBlinkAlpha() + " blinkspeed=" + getBlinkSpeed()); + logger.info("SAVED: red=" + red.get() + " green=" + green.get() + " blue=" + blue.get() + " alpha=" + alpha.get()); + logger.info("SAVED: thickness=" + thickness.get() + " blinkalpha=" + blinkalpha.get() + " blinkspeed=" + blinkspeed.get()); } public static void reset(boolean mc) { - setRed(0.0F); - setGreen(0.0F); - setBlue(0.0F); - setAlpha(mc ? 0.4F : 1.0F); - setThickness(mc ? 2.0F : 4.0F); - setBlinkAlpha(mc ? 0.0F : 0.390625F); - setBlinkSpeed(0.2F); + if (mc) { + red.mcDefault(); + green.mcDefault(); + blue.mcDefault(); + alpha.mcDefault(); + thickness.mcDefault(); + blinkalpha.mcDefault(); + blinkspeed.mcDefault(); + } else { + red.csbDefault(); + green.csbDefault(); + blue.csbDefault(); + alpha.csbDefault(); + thickness.csbDefault(); + blinkalpha.csbDefault(); + blinkspeed.csbDefault(); + } disableDepthBuffer = false; setBreakAnimation(0); save(); @@ -162,7 +171,7 @@ public static void drawSelectionBox(EntityPlayer player, MovingObjectPosition mo GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F); - GL11.glLineWidth(getThickness()); + GL11.glLineWidth(thickness.get()); GlStateManager.disableTexture2D(); GlStateManager.depthMask(false); float f1 = 0.002F; @@ -185,10 +194,10 @@ public static void drawSelectionBox(EntityPlayer player, MovingObjectPosition mo bb = bb.expand(-breakProgress / 2, -breakProgress / 2, -breakProgress / 2); // draw blinking block - drawBlinkingBlock(bb, (breakAnimation == ALPHA) ? breakProgress : getBlinkAlpha()); + drawBlinkingBlock(bb, (breakAnimation == ALPHA) ? breakProgress : blinkalpha.get()); // set the color back to original and draw outline - GL11.glColor4f(getRed(), getGreen(), getBlue(), getAlpha()); + GL11.glColor4f(red.get(), green.get(), blue.get(), alpha.get()); drawOutlinedBoundingBox(bb, -1); // draw the blockplace indicator // @@ -199,7 +208,7 @@ public static void drawSelectionBox(EntityPlayer player, MovingObjectPosition mo if (bb != null) { bb = bb.expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2); - GL11.glColor4f(getRed(), getGreen(), getBlue(), getAlpha() / 3); + GL11.glColor4f(red.get(), green.get(), blue.get(), alpha.get() / 3); drawOutlinedBoundingBox(bb, -1); } } @@ -241,7 +250,7 @@ private static AxisAlignedBB getBlockSpecificBB(World world, EntityPlayer player } catch (Exception e) { // if (!(block instanceof BlockSnow) && !(block instanceof BlockAnvil) && !(block instanceof BlockVine) && !(block instanceof BlockButton) // && !(block instanceof BlockLever)) -// logger.catching(e); + // logger.catching(e); } if (block instanceof BlockLadder) { // Ladder @@ -489,10 +498,10 @@ private static void drawBlinkingBlock(AxisAlignedBB par1AxisAlignedBB, float alp Tessellator tessellator = Tessellator.getInstance(); if (alpha > 0.0F) { - if (getBlinkSpeed() > 0 && CSB.breakAnimation != ALPHA) - alpha *= (float) Math.abs(Math.sin(Minecraft.getSystemTime() / 100.0D * getBlinkSpeed())); + if (blinkspeed.get() > 0 && CSB.breakAnimation != ALPHA) + alpha *= (float) Math.abs(Math.sin(Minecraft.getSystemTime() / 100.0D * blinkspeed.get())); - GL11.glColor4f(getRed(), getGreen(), getBlue(), alpha); + GL11.glColor4f(red.get(), green.get(), blue.get(), alpha); renderDown(par1AxisAlignedBB); renderUp(par1AxisAlignedBB); renderNorth(par1AxisAlignedBB); @@ -581,105 +590,10 @@ public static void renderEast(AxisAlignedBB par1AxisAlignedBB) { tessellator.draw(); } - public static void renderBlock() { - } - - public static float getRed() { - return between(red, 0.0F, 1.0F); - } - - public static float getGreen() { - return between(green, 0.0F, 1.0F); - } - - public static float getBlue() { - return between(blue, 0.0F, 1.0F); - } - - public static float getAlpha() { - return between(alpha, 0.0F, 1.0F); - } - - public static float getThickness() { - return between(thickness, 0.1F, 7.0F); - } - - public static float getBlinkAlpha() { - return between(blinkalpha, 0.0F, 1.0F); - } - - public static float getBlinkSpeed() { - return between(blinkspeed, 0.0F, 1.0F); - } - - public static void setRed(float r) { - red = between(r, 0.0F, 1.0F); - } - - public static void setGreen(float g) { - green = between(g, 0.0F, 1.0F); - } - - public static void setBlue(float b) { - blue = between(b, 0.0F, 1.0F); - } - - public static void setAlpha(float a) { - alpha = between(a, 0.0F, 1.0F); - } - - public static void setThickness(float t) { - thickness = between(t, 0.1F, 7.0F); - } - - public static void setBlinkAlpha(float ba) { - blinkalpha = between(ba, 0.0F, 1.0F); - } - - public static void setBlinkSpeed(float s) { - blinkspeed = between(s, 0.0F, 1.0F); - } - public static void setBreakAnimation(int index) { breakAnimation = between(index, 0, LASTANIMATION_INDEX); } - public static int getRedInt() { - return Math.round(getRed() * 256.0F); - } - - public static int getGreenInt() { - return Math.round(getGreen() * 256.0F); - } - - public static int getBlueInt() { - return Math.round(getBlue() * 256.0F); - } - - public static int getAlphaInt() { - return Math.round(getAlpha() * 256.0F); - } - - public static int getThicknessInt() { - return Math.round(getThickness()); - } - - public static int getBlinkAlphaInt() { - return Math.round(getBlinkAlpha() * 256.0F); - } - - public static int getBlinkSpeedInt() { - return Math.round(getBlinkSpeed() * 100.0F); - } - - private static float between(float i, float x, float y) { - if (i < x) - i = x; - if (i > y) - i = y; - return i; - } - private static int between(int i, int x, int y) { if (i < x) i = x; diff --git a/src/main/java/tennox/customselectionbox/CSBFloat.java b/src/main/java/tennox/customselectionbox/CSBFloat.java new file mode 100644 index 0000000..b0306a7 --- /dev/null +++ b/src/main/java/tennox/customselectionbox/CSBFloat.java @@ -0,0 +1,78 @@ +package tennox.customselectionbox; + +public class CSBFloat { + + private float value; + private float min, max; + private float mcDefault, csbDefault; + + private String name; + private float maxInt; + + public CSBFloat(String name, float maxInt, float mcDefault, float csbDefault) { + this.name = name; + this.mcDefault = mcDefault; + this.csbDefault = csbDefault; + this.maxInt = maxInt; + this.min = 0f; + this.max = 1f; + validate(); + } + + public String displayString() { + return name + ": " + getAsInt(); + } + + public float sliderVal() { + validate(); + return (get() - min) / (max - min); + } + + public void setFromSlider(float sliderValue) { + set(sliderValue * (max - min) + min); + } + + private void validate() { + if (value < min) + value = min; + if (value > max) + value = max; + } + + public CSBFloat setMinMax(float min, float max) { + this.min = min; + this.max = max; + validate(); + return this; + } + + public int getAsInt() { + return Math.round(get() * (maxInt / max)); + } + + public void setFromInt(int val) { + set((float) val / ((float) maxInt / max)); + } + + public float get() { + validate(); + return value; + } + + public void set(float val) { + value = val; + validate(); + } + + public void mcDefault() { + this.set(mcDefault); + } + + public void csbDefault() { + this.set(csbDefault); + } + + public String toString() { + return name + "[" + get() + ", min=" + min + ", max=" + max + "|" + maxInt + " mc=" + mcDefault + " csb=" + csbDefault + "]"; + } +} diff --git a/src/main/java/tennox/customselectionbox/CSBSettingsGUI.java b/src/main/java/tennox/customselectionbox/CSBSettingsGUI.java index 3e27680..cc910aa 100644 --- a/src/main/java/tennox/customselectionbox/CSBSettingsGUI.java +++ b/src/main/java/tennox/customselectionbox/CSBSettingsGUI.java @@ -6,6 +6,7 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.settings.GameSettings; +import net.minecraft.util.ResourceLocation; public class CSBSettingsGUI extends GuiScreen { GuiScreen parent; @@ -17,19 +18,22 @@ public CSBSettingsGUI(GuiScreen p) { @SuppressWarnings("unchecked") public void initGui() { this.buttonList.clear(); - + + int between = 22; + // left - this.buttonList.add(new CSBSlider(1, 4, this.height / 2 + -62, CSB.getRed())); - this.buttonList.add(new CSBSlider(2, 4, this.height / 2 + -38, CSB.getGreen())); - this.buttonList.add(new CSBSlider(3, 4, this.height / 2 + -14, CSB.getBlue())); - this.buttonList.add(new CSBSlider(4, 4, this.height / 2 + 10, CSB.getAlpha())); - this.buttonList.add(new CSBSlider(5, 4, this.height / 2 + 34, CSB.getThickness() / 7.0F)); + int top = (int) (this.height / 2 - 4 - (6 * between / 2f)); + this.buttonList.add(new CSBSlider(1, 2, top + between * 1, CSB.red)); + this.buttonList.add(new CSBSlider(2, 2, top + between * 2, CSB.green)); + this.buttonList.add(new CSBSlider(3, 2, top + between * 3, CSB.blue)); + this.buttonList.add(new CSBSlider(4, 2, top + between * 4, CSB.alpha)); + this.buttonList.add(new CSBSlider(5, 2, top + between * 5, CSB.thickness)); // right this.buttonList.add(new CSBButton(9, this.width - 154, this.height / 2 - 52, 150, 20, "Disable Depth: " + (CSB.disableDepthBuffer ? "ON" : "OFF"))); this.buttonList.add(new CSBButton(10, this.width - 154, this.height / 2 - 30, 150, 20, "Break Animation: " + getBreakAnimationName())); - this.buttonList.add(new CSBSlider(7, this.width - 154, this.height / 2 + 2, CSB.getBlinkAlpha())); - this.buttonList.add(new CSBSlider(8, this.width - 154, this.height / 2 + 26, CSB.getBlinkSpeed())); + this.buttonList.add(new CSBSlider(7, this.width - 154, this.height / 2 + 2, CSB.blinkalpha)); + this.buttonList.add(new CSBSlider(8, this.width - 154, this.height / 2 + 26, CSB.blinkspeed)); this.buttonList.add(new CSBButton(20, this.width / 2 - 100, this.height - 48, "Done")); this.buttonList.add(new CSBButton(21, this.width / 2 - 100, this.height - 24, 95, 20, "CSB defaults")); @@ -77,7 +81,12 @@ protected void keyTyped(char par1, int par2) { public void drawScreen(int par1, int par2, float par3) { drawGradientRect(0, 0, this.width, 48 - 4, -1072689136, -804253680); // top - drawGradientRect(0, this.height / 2 - 67, 158, this.height / 2 + 59, -1072689136, -804253680); // left + + // left + int top = (int) (this.height / 2 - 4 - ((6f * 22f) / 2f)); + int bottom = top + 22 * 6; + drawGradientRect(0, top - 2, 154, bottom + 2, -1072689136, -804253680); + drawGradientRect(this.width - 158, this.height / 2 - 56, this.width, this.height / 2 + 50, -1072689136, -804253680); // right drawGradientRect(0, this.height - 48 - 4, this.width, this.height, -1072689136, -804253680); // bottom diff --git a/src/main/java/tennox/customselectionbox/CSBSlider.java b/src/main/java/tennox/customselectionbox/CSBSlider.java index 2faacc9..b18de82 100644 --- a/src/main/java/tennox/customselectionbox/CSBSlider.java +++ b/src/main/java/tennox/customselectionbox/CSBSlider.java @@ -9,14 +9,15 @@ public class CSBSlider extends GuiButton { private float sliderValue; - public boolean dragging; - private static final String __OBFID = "CL_00000680"; + private boolean dragging; + private CSBFloat property; // GuiOptionSlider - public CSBSlider(int i, int x, int y, float f) { + public CSBSlider(int i, int x, int y, CSBFloat property) { super(i, x, y, 150, 20, ""); - this.sliderValue = f; - this.displayString = getDisplayString(i); + this.property = property; + this.sliderValue = property.sliderVal(); + this.displayString = property.displayString(); } @Override @@ -36,17 +37,13 @@ protected void mouseDragged(Minecraft par1Minecraft, int par2, int par3) { this.sliderValue = 1.0F; } - updateValue(this.id); - this.displayString = getDisplayString(this.id); + updateValue(); + this.displayString = property.displayString(); } GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - drawTexturedModalRect(this.xPosition - + (int) (this.sliderValue * (this.width - 8)), - this.yPosition, 0, 66, 4, 20); - drawTexturedModalRect(this.xPosition - + (int) (this.sliderValue * (this.width - 8)) + 4, - this.yPosition, 196, 66, 4, 20); + drawTexturedModalRect(this.xPosition + (int) (this.sliderValue * (this.width - 8)), this.yPosition, 0, 66, 4, 20); + drawTexturedModalRect(this.xPosition + (int) (this.sliderValue * (this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20); } } @@ -62,56 +59,16 @@ public boolean mousePressed(Minecraft mc, int par2, int par3) { this.sliderValue = 1.0F; } - this.displayString = getDisplayString(this.id); + this.displayString = property.displayString(); this.dragging = true; return true; } return false; } - private void updateValue(int id) { - switch (id) { - case 1: - CSB.setRed(this.sliderValue); - break; - case 2: - CSB.setGreen(this.sliderValue); - break; - case 3: - CSB.setBlue(this.sliderValue); - break; - case 4: - CSB.setAlpha(this.sliderValue); - break; - case 5: - CSB.setThickness(this.sliderValue * 7.0F); - break; - case 7: - CSB.setBlinkAlpha(this.sliderValue); - break; - case 8: - CSB.setBlinkSpeed(this.sliderValue); - } - } - - private String getDisplayString(int id) { - switch (id) { - case 1: - return "Red: " + Math.round(this.sliderValue * 255.0F); - case 2: - return "Green: " + Math.round(this.sliderValue * 255.0F); - case 3: - return "Blue: " + Math.round(this.sliderValue * 255.0F); - case 4: - return "Alpha: " + Math.round(this.sliderValue * 255.0F); - case 5: - return "Thickness: " + Math.round(this.sliderValue * 7.0F); - case 7: - return "Blink Alpha: " + Math.round(this.sliderValue * 255.0F); - case 8: - return "Blink Speed: " + Math.round(this.sliderValue * 100.0F); - } - return "option error?! (" + id + ")"; + private void updateValue() { + property.setFromSlider(sliderValue); + System.out.println("Updated Value " + property + " to " + property.get() + " (in=" + sliderValue + ")"); } public void mouseReleased(int p_146118_1_, int p_146118_2_) {