From d9272bf34f060498d24a3cf1c0ca20466297bd5c Mon Sep 17 00:00:00 2001 From: MachineMuse Date: Sun, 13 Jan 2013 21:37:35 -0700 Subject: [PATCH] Added units to the tinker display frame --- .../machinemuse/general/MuseStringUtils.java | 18 +++++++ .../net/machinemuse/general/gui/MuseIcon.java | 11 +++- .../general/gui/frame/ModuleTweakFrame.java | 3 +- .../machinemuse/powersuits/common/Config.java | 52 +++++++++---------- .../powersuits/powermodule/ModuleManager.java | 5 +- .../powersuits/powermodule/PowerModule.java | 21 ++++++++ 6 files changed, 78 insertions(+), 32 deletions(-) diff --git a/src/minecraft/net/machinemuse/general/MuseStringUtils.java b/src/minecraft/net/machinemuse/general/MuseStringUtils.java index b3cf9c5..c1dc21b 100644 --- a/src/minecraft/net/machinemuse/general/MuseStringUtils.java +++ b/src/minecraft/net/machinemuse/general/MuseStringUtils.java @@ -34,6 +34,24 @@ public abstract class MuseStringUtils { return retval; } + public static String formatNumberPercent(double number) { + DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(); + format.setMinimumIntegerDigits(1); + format.setMaximumFractionDigits(2); + format.applyPattern("##0.##"); + + String formattedNumber = format.format(number * 100); + return formattedNumber; + } + + public static String formatNumberFromUnits(double number, String units) { + if (units.equals("%")) { + return formatNumberPercent(number) + "%"; + } else { + return formatNumberShort(number) + units; + } + } + public static String prependFormatTag(String str, char format) { return "\u00a7" + format + str; } diff --git a/src/minecraft/net/machinemuse/general/gui/MuseIcon.java b/src/minecraft/net/machinemuse/general/gui/MuseIcon.java index d9b287c..e116488 100644 --- a/src/minecraft/net/machinemuse/general/gui/MuseIcon.java +++ b/src/minecraft/net/machinemuse/general/gui/MuseIcon.java @@ -42,8 +42,15 @@ public class MuseIcon { public static final MuseIcon SPRINT_ASSIST = new MuseIcon(WC_ICON_PATH, 4); public static final MuseIcon JUMP_ASSIST = new MuseIcon(WC_ICON_PATH, 5); public static final MuseIcon ENERGY_SHIELD = new MuseIcon(WC_ICON_PATH, 6); - public static final MuseIcon DIAMOND_PICK_UPGRADE = new MuseIcon(WC_ICON_PATH, 7); - public static final MuseIcon BATTERY_UPGRADE = new MuseIcon(WC_ICON_PATH, 8); + public static final MuseIcon IRON_PLATING = new MuseIcon(WC_ICON_PATH, 7); + public static final MuseIcon DIAMOND_PLATING = new MuseIcon(WC_ICON_PATH, 8); + public static final MuseIcon HEART = new MuseIcon(WC_ICON_PATH, 13); + public static final MuseIcon BATTERY_FULL = new MuseIcon(WC_ICON_PATH, 14); + public static final MuseIcon BATTERY_EMPTY = new MuseIcon(WC_ICON_PATH, 15); + public static final MuseIcon SHOCK_ABSORBER = new MuseIcon(WC_ICON_PATH, 16); + public static final MuseIcon PARACHUTE_MODULE = new MuseIcon(WC_ICON_PATH, 18); + public static final MuseIcon SHIELD = new MuseIcon(WC_ICON_PATH, 20); + public static final MuseIcon GO_FAST = new MuseIcon(WC_ICON_PATH, 21); // Component icons public static final MuseIcon COMPONENT_WIRING = new MuseIcon(MUSE_ICON_PATH, 0); diff --git a/src/minecraft/net/machinemuse/general/gui/frame/ModuleTweakFrame.java b/src/minecraft/net/machinemuse/general/gui/frame/ModuleTweakFrame.java index bc7fd2d..77b93f1 100644 --- a/src/minecraft/net/machinemuse/general/gui/frame/ModuleTweakFrame.java +++ b/src/minecraft/net/machinemuse/general/gui/frame/ModuleTweakFrame.java @@ -84,7 +84,8 @@ public class ModuleTweakFrame extends ScrollableFrame { int nexty = (int) (sliders.size() * 24 + topleft.y() + 24); for (Map.Entry property : propertyStrings.entrySet()) { nexty += 8; - String[] str = { property.getKey() + ":", MuseStringUtils.formatNumberShort(property.getValue()) }; + String[] str = { property.getKey() + ":", + MuseStringUtils.formatNumberFromUnits(property.getValue(), PowerModule.getUnit(property.getKey())) }; MuseRenderer.drawStringsJustified(Arrays.asList(str), topleft.x() + 4, bottomright.x() - 4, nexty); } diff --git a/src/minecraft/net/machinemuse/powersuits/common/Config.java b/src/minecraft/net/machinemuse/powersuits/common/Config.java index 8798a12..e16b4eb 100644 --- a/src/minecraft/net/machinemuse/powersuits/common/Config.java +++ b/src/minecraft/net/machinemuse/powersuits/common/Config.java @@ -149,33 +149,33 @@ public class Config extends Configuration { boolean[] ALLITEMS = { true, true, true, true, true }; PowerModule module; - module = new PowerModule(ModularCommon.MODULE_IRON_PLATING, ARMORONLY, MuseIcon.ORB_1_GREEN, ModularCommon.CATEGORY_ARMOR) + module = new PowerModule(ModularCommon.MODULE_IRON_PLATING, ARMORONLY, MuseIcon.IRON_PLATING, ModularCommon.CATEGORY_ARMOR) .setDescription("Iron plating is heavy but protective.") .addInstallCost(new ItemStack(Item.ingotIron, 5)) - .addTradeoffProperty("Plating Thickness", ModularCommon.ARMOR_VALUE_PHYSICAL, 5) - .addTradeoffProperty("Plating Thickness", ModularCommon.WEIGHT, 10000); + .addTradeoffProperty("Plating Thickness", ModularCommon.ARMOR_VALUE_PHYSICAL, 5, " Points") + .addTradeoffProperty("Plating Thickness", ModularCommon.WEIGHT, 10000, "g"); ModuleManager.addModule(module); - module = new PowerModule(ModularCommon.MODULE_DIAMOND_PLATING, ARMORONLY, MuseIcon.ORB_1_BLUE, ModularCommon.CATEGORY_ARMOR) + module = new PowerModule(ModularCommon.MODULE_DIAMOND_PLATING, ARMORONLY, MuseIcon.DIAMOND_PLATING, ModularCommon.CATEGORY_ARMOR) .setDescription("Diamonds are lighter, harder, and more protective than Iron but much harder to find.") .addInstallCost(new ItemStack(Item.diamond, 5)) - .addTradeoffProperty("Plating Thickness", ModularCommon.ARMOR_VALUE_PHYSICAL, 6) - .addTradeoffProperty("Plating Thickness", ModularCommon.WEIGHT, 6000); + .addTradeoffProperty("Plating Thickness", ModularCommon.ARMOR_VALUE_PHYSICAL, 6, " Points") + .addTradeoffProperty("Plating Thickness", ModularCommon.WEIGHT, 6000, "g"); ModuleManager.addModule(module); module = new PowerModule(ModularCommon.MODULE_ENERGY_SHIELD, ARMORONLY, MuseIcon.ENERGY_SHIELD, ModularCommon.CATEGORY_ARMOR) .setDescription("Energy shields are much lighter than plating, but consume energy.") .addInstallCost(copyAndResize(ItemComponent.solenoid, 4)) - .addTradeoffProperty("Field Strength", ModularCommon.ARMOR_VALUE_ENERGY, 6) - .addTradeoffProperty("Field Strength", ModularCommon.ARMOR_ENERGY_CONSUMPTION, 500); + .addTradeoffProperty("Field Strength", ModularCommon.ARMOR_VALUE_ENERGY, 6, " Points") + .addTradeoffProperty("Field Strength", ModularCommon.ARMOR_ENERGY_CONSUMPTION, 500, "J"); ModuleManager.addModule(module); module = new PowerModule(ModularCommon.MODULE_SHOVEL, TOOLONLY, MuseIcon.TOOL_SHOVEL, ModularCommon.CATEGORY_TOOL) .setDescription("Shovels are good for soft materials like dirt and sand.") .addInstallCost(new ItemStack(Item.ingotIron, 3)) .addInstallCost(copyAndResize(ItemComponent.solenoid, 1)) - .addBaseProperty(ModularCommon.SHOVEL_ENERGY_CONSUMPTION, 10) - .addBaseProperty(ModularCommon.SHOVEL_HARVEST_SPEED, 2) + .addBaseProperty(ModularCommon.SHOVEL_ENERGY_CONSUMPTION, 10, "J") + .addBaseProperty(ModularCommon.SHOVEL_HARVEST_SPEED, 2, "%") .addTradeoffProperty("Overclock", ModularCommon.SHOVEL_ENERGY_CONSUMPTION, 990) .addTradeoffProperty("Overclock", ModularCommon.SHOVEL_HARVEST_SPEED, 18); ModuleManager.addModule(module); @@ -184,8 +184,8 @@ public class Config extends Configuration { .setDescription("Axes are mostly for chopping trees.") .addInstallCost(new ItemStack(Item.ingotIron, 3)) .addInstallCost(copyAndResize(ItemComponent.solenoid, 1)) - .addBaseProperty(ModularCommon.AXE_ENERGY_CONSUMPTION, 10) - .addBaseProperty(ModularCommon.AXE_HARVEST_SPEED, 2) + .addBaseProperty(ModularCommon.AXE_ENERGY_CONSUMPTION, 10, "J") + .addBaseProperty(ModularCommon.AXE_HARVEST_SPEED, 2, "%") .addTradeoffProperty("Overclock", ModularCommon.AXE_ENERGY_CONSUMPTION, 990) .addTradeoffProperty("Overclock", ModularCommon.AXE_HARVEST_SPEED, 18); ModuleManager.addModule(module); @@ -194,28 +194,28 @@ public class Config extends Configuration { .setDescription("Picks are good for harder materials like stone and ore.") .addInstallCost(new ItemStack(Item.ingotIron, 3)) .addInstallCost(copyAndResize(ItemComponent.solenoid, 1)) - .addBaseProperty(ModularCommon.PICKAXE_ENERGY_CONSUMPTION, 10) - .addBaseProperty(ModularCommon.PICKAXE_HARVEST_SPEED, 2) + .addBaseProperty(ModularCommon.PICKAXE_ENERGY_CONSUMPTION, 10, "J") + .addBaseProperty(ModularCommon.PICKAXE_HARVEST_SPEED, 2, "%") .addTradeoffProperty("Overclock", ModularCommon.PICKAXE_ENERGY_CONSUMPTION, 990) .addTradeoffProperty("Overclock", ModularCommon.PICKAXE_HARVEST_SPEED, 18); ModuleManager.addModule(module); - module = new PowerModule(ModularCommon.MODULE_BATTERY_BASIC, ALLITEMS, MuseIcon.NEXUS_1_GREEN, ModularCommon.CATEGORY_ENERGY) + module = new PowerModule(ModularCommon.MODULE_BATTERY_BASIC, ALLITEMS, MuseIcon.BATTERY_EMPTY, ModularCommon.CATEGORY_ENERGY) .setDescription("Integrate a battery to allow the item to store energy.") .addInstallCost(new ItemStack(BasicComponents.itemBattery, 1)) - .addBaseProperty(ModularCommon.MAXIMUM_ENERGY, 20000) - .addBaseProperty(ModularCommon.WEIGHT, 2000) + .addBaseProperty(ModularCommon.MAXIMUM_ENERGY, 20000, "J") + .addBaseProperty(ModularCommon.WEIGHT, 2000, "g") .addTradeoffProperty("Battery Size", ModularCommon.MAXIMUM_ENERGY, 80000) .addTradeoffProperty("Battery Size", ModularCommon.WEIGHT, 8000); ModuleManager.addModule(module); module = new PowerModule(ModularCommon.MODULE_DIAMOND_PICK_UPGRADE, TOOLONLY, MuseIcon.INDICATOR_1_BLUE, ModularCommon.CATEGORY_TOOL) - .setDescription("Add diamonds to allow your pickaxe module to mine Obsidian.") + .setDescription("Add diamonds to allow your pickaxe module to mine Obsidian. *REQUIRES PICKAXE MODULE TO WORK*") .addInstallCost(copyAndResize(ItemComponent.solenoid, 1)) .addInstallCost(new ItemStack(Item.diamond, 3)); ModuleManager.addModule(module); - module = new PowerModule(ModularCommon.MODULE_TRANSPARENT_ARMOR, ARMORONLY, MuseIcon.PLATE_2_GREEN, ModularCommon.CATEGORY_COSMETIC) + module = new PowerModule(ModularCommon.MODULE_TRANSPARENT_ARMOR, ARMORONLY, MuseIcon.SHIELD, ModularCommon.CATEGORY_COSMETIC) .setDescription("Make the item transparent, so you can show off your skin without losing armor.") .addInstallCost(new ItemStack(Block.glass, 3)); ModuleManager.addModule(module); @@ -226,11 +226,11 @@ public class Config extends Configuration { ModuleManager.addSimpleTradeoff( module, "Power", ModularCommon.SPRINT_ENERGY_CONSUMPTION, "J", 0, 5, - ModularCommon.SPRINT_SPEED_MULTIPLIER, "x", 1, 2); + ModularCommon.SPRINT_SPEED_MULTIPLIER, "%", 1, 2); ModuleManager.addSimpleTradeoff( module, "Compensation", ModularCommon.SPRINT_ENERGY_CONSUMPTION, "J", 0, 1, - ModularCommon.SPRINT_FOOD_COMPENSATION, "x", 0, 1); + ModularCommon.SPRINT_FOOD_COMPENSATION, "%", 0, 1); ModuleManager.addModule(module); module = new PowerModule(ModularCommon.MODULE_JUMP_ASSIST, LEGSONLY, MuseIcon.JUMP_ASSIST, ModularCommon.CATEGORY_MOVEMENT) @@ -239,17 +239,17 @@ public class Config extends Configuration { ModuleManager.addSimpleTradeoff( module, "Power", ModularCommon.JUMP_ENERGY_CONSUMPTION, "J", 0, 100, - ModularCommon.JUMP_MULTIPLIER, "x", 1, 2); + ModularCommon.JUMP_MULTIPLIER, "%", 1, 2); ModuleManager.addModule(module); - module = new PowerModule(ModularCommon.MODULE_SHOCK_ABSORBER, FEETONLY, MuseIcon.PLATE_1_RED, ModularCommon.CATEGORY_MOVEMENT) + module = new PowerModule(ModularCommon.MODULE_SHOCK_ABSORBER, FEETONLY, MuseIcon.SHOCK_ABSORBER, ModularCommon.CATEGORY_MOVEMENT) .setDescription("With some servos, springs, and padding, you should be able to negate a portion of fall damage.") .addInstallCost(copyAndResize(ItemComponent.servoMotor, 2)) .addInstallCost(new ItemStack(Block.cloth, 2)); ModuleManager.addSimpleTradeoff( module, "Power", ModularCommon.SHOCK_ABSORB_ENERGY_CONSUMPTION, "J", 0, 10, - ModularCommon.SHOCK_ABSORB_MULTIPLIER, "x", 0, 1); + ModularCommon.SHOCK_ABSORB_MULTIPLIER, "%", 0, 1); ModuleManager.addModule(module); module = new PowerModule(ModularCommon.MODULE_GLIDER, TORSOONLY, MuseIcon.GLIDER, ModularCommon.CATEGORY_MOVEMENT) @@ -265,8 +265,8 @@ public class Config extends Configuration { module = new PowerModule(ModularCommon.MODULE_JETPACK, TORSOONLY, MuseIcon.JETPACK, ModularCommon.CATEGORY_MOVEMENT) .setDescription("A jetpack should allow you to jump indefinitely, or at least until you run out of power.") .addInstallCost(copyAndResize(ItemComponent.ionThruster, 4)) - .addBaseProperty(ModularCommon.JET_ENERGY_CONSUMPTION, 0) - .addBaseProperty(ModularCommon.JET_THRUST, 0) + .addBaseProperty(ModularCommon.JET_ENERGY_CONSUMPTION, 0, "J/s") + .addBaseProperty(ModularCommon.JET_THRUST, 0, "m/s\u00B2") .addTradeoffProperty("Thrust", ModularCommon.JET_ENERGY_CONSUMPTION, 16) .addTradeoffProperty("Thrust", ModularCommon.JET_THRUST, 0.16); ModuleManager.addModule(module); diff --git a/src/minecraft/net/machinemuse/powersuits/powermodule/ModuleManager.java b/src/minecraft/net/machinemuse/powersuits/powermodule/ModuleManager.java index 6e3c2de..ee6a0d9 100644 --- a/src/minecraft/net/machinemuse/powersuits/powermodule/ModuleManager.java +++ b/src/minecraft/net/machinemuse/powersuits/powermodule/ModuleManager.java @@ -36,10 +36,9 @@ public class ModuleManager { PowerModule module, String tradeoffName, String firstPropertyName, String firstUnits, double firstPropertyBase, double firstPropertyMultiplier, String secondPropertyName, String secondUnits, double secondPropertyBase, double secondPropertyMultiplier) { - module.addBaseProperty(firstPropertyName, firstPropertyBase); + module.addBaseProperty(firstPropertyName, firstPropertyBase, firstUnits); module.addTradeoffProperty(tradeoffName, firstPropertyName, firstPropertyMultiplier); - module.addBaseProperty(secondPropertyName, secondPropertyBase); + module.addBaseProperty(secondPropertyName, secondPropertyBase, secondUnits); module.addTradeoffProperty(tradeoffName, secondPropertyName, secondPropertyMultiplier); } - } diff --git a/src/minecraft/net/machinemuse/powersuits/powermodule/PowerModule.java b/src/minecraft/net/machinemuse/powersuits/powermodule/PowerModule.java index 5ab7239..cb0556f 100644 --- a/src/minecraft/net/machinemuse/powersuits/powermodule/PowerModule.java +++ b/src/minecraft/net/machinemuse/powersuits/powermodule/PowerModule.java @@ -9,6 +9,7 @@ import java.util.Map; import java.util.Set; import net.machinemuse.general.gui.MuseIcon; +import net.machinemuse.powersuits.common.MuseLogger; import net.machinemuse.powersuits.powermodule.property.IPropertyModifier; import net.machinemuse.powersuits.powermodule.property.PropertyModifierFlatAdditive; import net.machinemuse.powersuits.powermodule.property.PropertyModifierLinearAdditive; @@ -25,6 +26,7 @@ public class PowerModule { protected List installCost; protected NBTTagCompound defaultTag; protected Map> propertyModifiers; + protected static Map units = new HashMap(); public PowerModule(String name, boolean[] validSlots, MuseIcon icon, String category) { this.name = name; @@ -57,10 +59,29 @@ public class PowerModule { return addPropertyModifier(propertyName, new PropertyModifierLinearAdditive(tradeoffName, multiplier)); } + public PowerModule addTradeoffProperty(String tradeoffName, String propertyName, double multiplier, String unit) { + units.put(propertyName, unit); + return addPropertyModifier(propertyName, new PropertyModifierLinearAdditive(tradeoffName, multiplier)); + } + + public static String getUnit(String propertyName) { + if (units.containsKey(propertyName)) { + return units.get(propertyName); + } else { + return ""; + } + } + public PowerModule addBaseProperty(String propertyName, double baseVal) { return addPropertyModifier(propertyName, new PropertyModifierFlatAdditive(baseVal)); } + public PowerModule addBaseProperty(String propertyName, double baseVal, String unit) { + MuseLogger.logDebug("Adding unit: " + propertyName + " maps to " + unit); + units.put(propertyName, unit); + return addPropertyModifier(propertyName, new PropertyModifierFlatAdditive(baseVal)); + } + public PowerModule addPropertyModifier(String propertyName, IPropertyModifier modifier) { List modifiers; if (propertyModifiers.containsKey(propertyName)) {