Fixed auto-layout

This commit is contained in:
MachineMuse 2013-04-13 17:04:43 -06:00
parent 672af7f551
commit f6a3709a25
7 changed files with 77 additions and 61 deletions

View file

@ -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);
}
}

View file

@ -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) {

View file

@ -20,6 +20,7 @@ public class ModuleSelectionFrame extends ScrollableFrame {
protected List<ClickableModule> 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<ClickableModule>();
categories = new HashMap<String, ModuleSelectionSubFrame>();
}
@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<ClickableModule>();
categories = new HashMap<String, ModuleSelectionSubFrame>();
List<IPowerModule> workingModules = MuseItemUtils.getValidModulesForItem(null, selectedItem.getItem());
@ -105,17 +108,12 @@ public class ModuleSelectionFrame extends ScrollableFrame {
}
if (workingModules.size() > 0) {
List<MusePoint2D> points = MuseRenderer.pointsInLine(
workingModules.size(),
new MusePoint2D(centerx, border.top()),
new MusePoint2D(centerx, border.bottom()));
this.selectedModule = -1;
Iterator<MusePoint2D> 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);

View file

@ -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<ClickableModule> 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<ClickableModule>();
}
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;
}

View file

@ -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

View file

@ -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

View file

@ -38,7 +38,7 @@ public class BlinkDriveModule extends PowerModuleBase implements IRightClickModu
@Override
public String getCategory() {
return MuseCommonStrings.CATEGORY_SPECIAL;
return MuseCommonStrings.CATEGORY_TOOL;
}
@Override