diff --git a/src/minecraft/net/machinemuse/general/geometry/MuseRect.java b/src/minecraft/net/machinemuse/general/geometry/MuseRect.java index 31f6477..9c73aa6 100644 --- a/src/minecraft/net/machinemuse/general/geometry/MuseRect.java +++ b/src/minecraft/net/machinemuse/general/geometry/MuseRect.java @@ -2,15 +2,15 @@ package net.machinemuse.general.geometry; public class MuseRect { MusePoint2D ul; - MusePoint2D br; + MusePoint2D wh; public MuseRect(double left, double top, double right, double bottom, boolean growFromMiddle) { ul = new MusePoint2D(left, top); - br = new MusePoint2D(right, bottom); + wh = new MusePoint2D(right - left, bottom - top); if (growFromMiddle) { - MusePoint2D center = ul.plus(br).times(0.5); + MusePoint2D center = ul.plus(wh.times(0.5)); this.ul = new FlyFromPointToPoint2D(center, ul, 200); - this.br = new FlyFromPointToPoint2D(center, br, 200); + this.wh = new FlyFromPointToPoint2D(new MusePoint2D(0, 0), wh, 200); } } @@ -20,7 +20,7 @@ public class MuseRect { public MuseRect(MusePoint2D ul, MusePoint2D br) { this.ul = ul; - this.br = br; + this.wh = br.minus(ul); } public double left() { @@ -28,7 +28,7 @@ public class MuseRect { } public double right() { - return br.x(); + return ul.x() + wh.x(); } public double top() { @@ -36,15 +36,15 @@ public class MuseRect { } public double bottom() { - return br.y(); + return ul.y() + wh.y(); } public double width() { - return br.x() - ul.x(); + return wh.x(); } public double height() { - return br.y() - ul.y(); + return wh.y(); } public MuseRect setLeft(double value) { @@ -53,7 +53,7 @@ public class MuseRect { } public MuseRect setRight(double value) { - br.x = value; + wh.x = value - ul.x(); return this; } @@ -63,11 +63,21 @@ public class MuseRect { } public MuseRect setBottom(double value) { - br.y = value; + wh.y = value - ul.y(); + return this; + } + + public MuseRect setWidth(double value) { + wh.x = value; + return this; + } + + public MuseRect setHeight(double value) { + wh.y = value; return this; } public boolean equals(MuseRect other) { - return ul.equals(other.ul) && br.equals(other.br); + return ul.equals(other.ul) && wh.equals(other.wh); } } diff --git a/src/minecraft/net/machinemuse/general/geometry/MuseRelativeRect.java b/src/minecraft/net/machinemuse/general/geometry/MuseRelativeRect.java index 2fe8aa2..19af784 100644 --- a/src/minecraft/net/machinemuse/general/geometry/MuseRelativeRect.java +++ b/src/minecraft/net/machinemuse/general/geometry/MuseRelativeRect.java @@ -29,7 +29,7 @@ public class MuseRelativeRect extends MuseRect { if (leftofme != null) { return leftofme.left(); } - return br.x(); + return left() + wh.x(); } public double top() { @@ -43,7 +43,7 @@ public class MuseRelativeRect extends MuseRect { if (aboveme != null) { return aboveme.top(); } - return br.y(); + return top() + wh.y(); } public MuseRelativeRect setBelow(MuseRect belowme) { diff --git a/src/minecraft/net/machinemuse/general/gui/frame/ModuleSelectionFrame.java b/src/minecraft/net/machinemuse/general/gui/frame/ModuleSelectionFrame.java index 624a7f1..36b2cde 100644 --- a/src/minecraft/net/machinemuse/general/gui/frame/ModuleSelectionFrame.java +++ b/src/minecraft/net/machinemuse/general/gui/frame/ModuleSelectionFrame.java @@ -20,6 +20,7 @@ public class ModuleSelectionFrame extends ScrollableFrame { protected List moduleButtons; protected int selectedModule = -1; protected IPowerModule prevSelection; + protected ClickableItem lastItem; protected MuseRect lastPosition; public ModuleSelectionFrame(MusePoint2D topleft, MusePoint2D bottomright, @@ -27,8 +28,8 @@ public class ModuleSelectionFrame extends ScrollableFrame { super(topleft, bottomright, borderColour, insideColour); this.target = target; - moduleButtons = new ArrayList(); - categories = new HashMap(); + moduleButtons = new ArrayList(); + categories = new HashMap(); } @Override @@ -38,8 +39,13 @@ public class ModuleSelectionFrame extends ScrollableFrame { @Override public void draw() { + for (ModuleSelectionSubFrame frame : categories.values()) { + frame.refreshButtonPositions(); + } if (target.getSelectedItem() != null) { - loadModules(); + if (lastItem != target.getSelectedItem()) { + loadModules(); + } for (ModuleSelectionSubFrame frame : categories.values()) { totalsize = (int) Math.max(frame.border.bottom() - this.border.top(), totalsize); } @@ -86,11 +92,8 @@ public class ModuleSelectionFrame extends ScrollableFrame { this.lastPosition = null; ClickableItem selectedItem = target.getSelectedItem(); if (selectedItem != null) { - double centerx = (border.left() + border.right()) / 2; - double centery = (border.top() + border.bottom()) / 2; - - moduleButtons = new ArrayList(); - categories = new HashMap(); + moduleButtons = new ArrayList(); + categories = new HashMap(); List workingModules = MuseItemUtils.getValidModulesForItem(null, selectedItem.getItem()); @@ -105,17 +108,12 @@ public class ModuleSelectionFrame extends ScrollableFrame { } if (workingModules.size() > 0) { - List points = MuseRenderer.pointsInLine( - workingModules.size(), - new MusePoint2D(centerx, border.top()), - new MusePoint2D(centerx, border.bottom())); this.selectedModule = -1; - Iterator pointiter = points.iterator(); for (IPowerModule module : workingModules) { ModuleSelectionSubFrame frame = getOrCreateCategory(module.getCategory()); ClickableModule moduleClickable = frame.addModule(module); // Indicate installed modules - if (module.isAllowed() == false) { + if (!module.isAllowed()) { // If a disallowed module made it to the list, indicate // it as disallowed moduleClickable.setAllowed(false); @@ -128,6 +126,9 @@ public class ModuleSelectionFrame extends ScrollableFrame { moduleButtons.add(moduleClickable); } } + for (ModuleSelectionSubFrame frame : categories.values()) { + frame.refreshButtonPositions(); + } } } @@ -137,14 +138,11 @@ public class ModuleSelectionFrame extends ScrollableFrame { } else { MuseRelativeRect position = new MuseRelativeRect( border.left() + 4, - border.top() + 4 + 30 * categories.size(), + border.top() + 4, border.right() - 4, - border.top() + 34 + 30 * categories.size()); - if (!categories.isEmpty()) { - position.setBelow(lastPosition); - lastPosition = position; - } - + border.top() + 32); + position.setBelow(lastPosition); + lastPosition = position; ModuleSelectionSubFrame frame = new ModuleSelectionSubFrame( category, position); diff --git a/src/minecraft/net/machinemuse/general/gui/frame/ModuleSelectionSubFrame.java b/src/minecraft/net/machinemuse/general/gui/frame/ModuleSelectionSubFrame.java index 0fad312..5524893 100644 --- a/src/minecraft/net/machinemuse/general/gui/frame/ModuleSelectionSubFrame.java +++ b/src/minecraft/net/machinemuse/general/gui/frame/ModuleSelectionSubFrame.java @@ -7,45 +7,59 @@ import net.machinemuse.api.IPowerModule; import net.machinemuse.general.MuseRenderer; import net.machinemuse.general.geometry.MusePoint2D; import net.machinemuse.general.geometry.MuseRect; +import net.machinemuse.general.geometry.MuseRelativeRect; import net.machinemuse.general.gui.clickable.ClickableModule; public class ModuleSelectionSubFrame { protected List moduleButtons; - protected MuseRect border; + protected MuseRelativeRect border; protected String category; - public ModuleSelectionSubFrame(String category, MuseRect border) { + public ModuleSelectionSubFrame(String category, MuseRelativeRect border) { this.category = category; this.border = border; this.moduleButtons = new ArrayList(); } - public void draw() { - MuseRenderer.drawString(this.category, border.left(), border.top()); - for (ClickableModule clickie : moduleButtons) { - clickie.draw(); - } - } + // public void draw() { + // MuseRenderer.drawString(this.category, border.left(), border.top()); + // for (ClickableModule clickie : moduleButtons) { + // clickie.draw(); + // } + // } public ClickableModule addModule(IPowerModule module) { - double x = border.left() + 8 + 16 * (moduleButtons.size() % 5); - double y = border.top() + 16 + 16 * (moduleButtons.size() / 5); - border.setBottom(border.top() + 28 + 16 * (moduleButtons.size() / 5)); - ClickableModule clickie = new ClickableModule(module, new MusePoint2D(x, y)); + ClickableModule clickie = new ClickableModule(module, new MusePoint2D(0, 0)); this.moduleButtons.add(clickie); + // refreshButtonPositions(); return clickie; - } public void drawPartial(int min, int max) { - if (min < border.top() + 2 && max > border.top() - 2) { - MuseRenderer.drawString(this.category, border.left(), border.top()); + refreshButtonPositions(); + double top = border.top(); + if (min < top + 2 && max > top - 2) { + MuseRenderer.drawString(this.category, border.left(), top); } for (ClickableModule clickie : moduleButtons) { clickie.drawPartial(border.left(), min, border.right(), max); } } + public void refreshButtonPositions() { + int i = 0, j = 0; + for (ClickableModule clickie : moduleButtons) { + double x = border.left() + 8 + 16 * i; + double y = border.top() + 16 + 16 * j; + clickie.move(x, y); + if (++i > 4) { + i = 0; + j++; + } + } + border.setHeight(28 + 16 * j); + } + public MuseRect getBorder() { return border; } diff --git a/src/minecraft/net/machinemuse/powersuits/powermodule/misc/HazmatModule.java b/src/minecraft/net/machinemuse/powersuits/powermodule/misc/HazmatModule.java index 2b7c2c1..338c095 100644 --- a/src/minecraft/net/machinemuse/powersuits/powermodule/misc/HazmatModule.java +++ b/src/minecraft/net/machinemuse/powersuits/powermodule/misc/HazmatModule.java @@ -1,19 +1,12 @@ package net.machinemuse.powersuits.powermodule.misc; -import java.util.Collection; import java.util.List; import net.machinemuse.api.IModularItem; import net.machinemuse.api.MuseCommonStrings; -import net.machinemuse.api.MuseItemUtils; -import net.machinemuse.api.electricity.ElectricItemUtils; import net.machinemuse.powersuits.common.Config; import net.machinemuse.powersuits.item.ItemComponent; import net.machinemuse.powersuits.powermodule.PowerModuleBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionEffect; public class HazmatModule extends PowerModuleBase { public static final String MODULE_HAZMAT = "Radiation Shielding"; @@ -25,7 +18,7 @@ public class HazmatModule extends PowerModuleBase { @Override public String getCategory() { - return MuseCommonStrings.CATEGORY_ARMOR; + return MuseCommonStrings.CATEGORY_ENVIRONMENTAL; } @Override diff --git a/src/minecraft/net/machinemuse/powersuits/powermodule/misc/TintModule.java b/src/minecraft/net/machinemuse/powersuits/powermodule/misc/TintModule.java index c60db15..5b55830 100644 --- a/src/minecraft/net/machinemuse/powersuits/powermodule/misc/TintModule.java +++ b/src/minecraft/net/machinemuse/powersuits/powermodule/misc/TintModule.java @@ -3,6 +3,7 @@ package net.machinemuse.powersuits.powermodule.misc; import java.util.List; import net.machinemuse.api.IModularItem; +import net.machinemuse.api.MuseCommonStrings; import net.machinemuse.api.MuseItemUtils; import net.machinemuse.powersuits.item.ItemComponent; import net.machinemuse.powersuits.powermodule.PowerModuleBase; @@ -28,8 +29,8 @@ public class TintModule extends PowerModuleBase { @Override public String getCategory() { - return "Blah"; - // return MuseCommonStrings.CATEGORY_COSMETIC; + // return "Blah"; + return MuseCommonStrings.CATEGORY_COSMETIC; } @Override diff --git a/src/minecraft/net/machinemuse/powersuits/powermodule/movement/BlinkDriveModule.java b/src/minecraft/net/machinemuse/powersuits/powermodule/movement/BlinkDriveModule.java index 16286d5..022a9b2 100644 --- a/src/minecraft/net/machinemuse/powersuits/powermodule/movement/BlinkDriveModule.java +++ b/src/minecraft/net/machinemuse/powersuits/powermodule/movement/BlinkDriveModule.java @@ -38,7 +38,7 @@ public class BlinkDriveModule extends PowerModuleBase implements IRightClickModu @Override public String getCategory() { - return MuseCommonStrings.CATEGORY_SPECIAL; + return MuseCommonStrings.CATEGORY_TOOL; } @Override