Changed detailed summary frame to summarize all equipped items & fix overlapping text issues in detailed summary & module tweak frames

This commit is contained in:
MachineMuse 2015-09-07 17:07:34 -06:00
parent 57bf818dde
commit b11f4e71c8
6 changed files with 176 additions and 9 deletions

View file

@ -149,4 +149,9 @@ gui.tab.tinker=Tinker
gui.tab.keybinds=Keybinds
gui.tab.visual=Visual
gui.equippedTotals=Equipped Totals
gui.energyStorage=Energy Storage
gui.weight=Weight
gui.armor=Armor
nei.jsonShaped=JSON Shaped

View file

@ -39,8 +39,8 @@ public class GuiFieldTinker extends MuseGui {
Colour.LIGHTBLUE.withAlpha(0.8F), Colour.DARKBLUE.withAlpha(0.8F), player);
frames.add(itemSelectFrame);
ItemInfoFrame statsFrame = new ItemInfoFrame(player, new MusePoint2D(absX(0f), absY(-0.9f)), new MusePoint2D(absX(0.9f), absY(-0.05f)),
Colour.LIGHTBLUE.withAlpha(0.8), Colour.DARKBLUE.withAlpha(0.8), itemSelectFrame);
DetailedSummaryFrame statsFrame = new DetailedSummaryFrame(player, new MusePoint2D(absX(0f), absY(-0.9f)), new MusePoint2D(absX(0.9f), absY(-0.05f)),
Colour.LIGHTBLUE.withAlpha(0.8), Colour.DARKBLUE.withAlpha(0.8));
frames.add(statsFrame);
ModuleSelectionFrame moduleSelectFrame = new ModuleSelectionFrame(new MusePoint2D(absX(-0.75F), absY(-0.95f)), new MusePoint2D(absX(-0.05F),

View file

@ -52,8 +52,8 @@ public class GuiTinkerTable extends MuseGui {
Colour.LIGHTBLUE.withAlpha(0.8F), Colour.DARKBLUE.withAlpha(0.8F), player);
frames.add(itemSelectFrame);
ItemInfoFrame statsFrame = new ItemInfoFrame(player, new MusePoint2D(absX(0f), absY(-0.9f)), new MusePoint2D(absX(0.9f), absY(-0.05f)),
Colour.LIGHTBLUE.withAlpha(0.8), Colour.DARKBLUE.withAlpha(0.8), itemSelectFrame);
DetailedSummaryFrame statsFrame = new DetailedSummaryFrame(player, new MusePoint2D(absX(0f), absY(-0.9f)), new MusePoint2D(absX(0.9f), absY(-0.05f)),
Colour.LIGHTBLUE.withAlpha(0.8), Colour.DARKBLUE.withAlpha(0.8));
frames.add(statsFrame);
ModuleSelectionFrame moduleSelectFrame = new ModuleSelectionFrame(new MusePoint2D(absX(-0.75F), absY(-0.95f)), new MusePoint2D(absX(-0.05F),

View file

@ -0,0 +1,112 @@
package net.machinemuse.general.gui.frame;
import net.machinemuse.api.ModuleManager;
import net.machinemuse.numina.geometry.Colour;
import net.machinemuse.numina.geometry.MusePoint2D;
import net.machinemuse.powersuits.common.Config;
import net.machinemuse.powersuits.powermodule.PowerModule;
import net.machinemuse.utils.ElectricItemUtils;
import net.machinemuse.utils.MuseCommonStrings;
import net.machinemuse.utils.MuseItemUtils;
import net.machinemuse.utils.MuseStringUtils;
import net.machinemuse.utils.render.MuseRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import java.util.List;
public class DetailedSummaryFrame extends ScrollableFrame {
public static final double SCALEFACTOR = 1;
protected EntityPlayer player;
protected double weight;
protected double energy;
protected double armor;
public DetailedSummaryFrame(EntityPlayer player, MusePoint2D topleft,
MusePoint2D bottomright,
Colour borderColour, Colour insideColour) {
super(topleft.times(1.0 / SCALEFACTOR), bottomright.times(1.0 / SCALEFACTOR), borderColour, insideColour);
this.player = player;
}
@Override
public void update(double mousex, double mousey) {
weight = MuseItemUtils.getPlayerWeight(player);
energy = 0;
armor = 0;
for(ItemStack stack : MuseItemUtils.modularItemsEquipped(player)) {
energy += ModuleManager.computeModularProperty(stack, ElectricItemUtils.MAXIMUM_ENERGY());
armor += ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_VALUE_PHYSICAL);
armor += ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_VALUE_ENERGY);
}
}
@Override
public void draw() {
if (player != null) {
GL11.glPushMatrix();
GL11.glScaled(SCALEFACTOR, SCALEFACTOR, SCALEFACTOR);
super.draw();
int margin = 4;
int nexty = (int) border.top() + margin;
MuseRenderer.drawCenteredString(StatCollector.translateToLocal("gui.equippedTotals"), (border.left() + border.right())/2, nexty);
nexty += 10;
String formattedValue = MuseStringUtils.formatNumberFromUnits(energy, PowerModule.getUnit(ElectricItemUtils.MAXIMUM_ENERGY()));
String name = StatCollector.translateToLocal("gui.energyStorage");
double valueWidth = MuseRenderer.getStringWidth(formattedValue);
double allowedNameWidth = border.width() - valueWidth - margin * 2;
List<String> namesList = MuseStringUtils.wrapStringToVisualLength(name, allowedNameWidth);
for(int i=0; i<namesList.size();i++) {
MuseRenderer.drawString(namesList.get(i), border.left() + margin, nexty + 9*i);
}
MuseRenderer.drawRightAlignedString(formattedValue, border.right() - margin, nexty + 9 * (namesList.size() - 1) / 2);
nexty += 10*namesList.size()+1;
formattedValue = MuseStringUtils.wrapFormatTags(MuseStringUtils.formatNumberFromUnits(weight, PowerModule.getUnit(MuseCommonStrings.WEIGHT)), weight > Config.getWeightCapacity() ? MuseStringUtils.FormatCodes.Red : MuseStringUtils.FormatCodes.BrightGreen);
name = StatCollector.translateToLocal("gui.weight");
valueWidth = MuseRenderer.getStringWidth(formattedValue);
allowedNameWidth = border.width() - valueWidth - margin * 2;
namesList = MuseStringUtils.wrapStringToVisualLength(name, allowedNameWidth);
for(int i=0; i<namesList.size();i++) {
MuseRenderer.drawString(namesList.get(i), border.left() + margin, nexty + 9*i);
}
MuseRenderer.drawRightAlignedString(formattedValue, border.right() - margin, nexty + 9 * (namesList.size() - 1) / 2);
nexty += 10*namesList.size()+1;
formattedValue = MuseStringUtils.formatNumberFromUnits(armor, "pts");
name = StatCollector.translateToLocal("gui.armor");
valueWidth = MuseRenderer.getStringWidth(formattedValue);
allowedNameWidth = border.width() - valueWidth - margin * 2;
namesList = MuseStringUtils.wrapStringToVisualLength(name, allowedNameWidth);
for(int i=0; i<namesList.size();i++) {
MuseRenderer.drawString(namesList.get(i), border.left() + margin, nexty + 9*i);
}
MuseRenderer.drawRightAlignedString(formattedValue, border.right() - margin, nexty + 9 * (namesList.size() - 1) / 2);
GL11.glPopMatrix();
}
}
@Override
public void onMouseDown(double x, double y, int button) {
// TODO Auto-generated method stub
}
@Override
public void onMouseUp(double x, double y, int button) {
// TODO Auto-generated method stub
}
@Override
public List<String> getToolTip(int x, int y) {
// TODO Auto-generated method stub
return null;
}
}

View file

@ -24,6 +24,7 @@ import java.util.*;
public class ModuleTweakFrame extends ScrollableFrame {
protected static double SCALERATIO = 0.75;
protected static int margin = 4;
protected ItemSelectionFrame itemTarget;
protected ModuleSelectionFrame moduleTarget;
protected List<ClickableTinkerSlider> sliders;
@ -75,12 +76,18 @@ public class ModuleTweakFrame extends ScrollableFrame {
for (ClickableTinkerSlider slider : sliders) {
slider.draw();
}
int nexty = (int) (sliders.size() * 20 + border.top() + 14);
int nexty = (int) (sliders.size() * 20 + border.top() + 23);
for (Map.Entry<String, Double> property : propertyStrings.entrySet()) {
nexty += 9;
String[] str = {property.getKey() + ':',
MuseStringUtils.formatNumberFromUnits(property.getValue(), PowerModule.getUnit(property.getKey()))};
MuseRenderer.drawStringsJustified(Arrays.asList(str), border.left() + 4, border.right() - 4, nexty);
String formattedValue = MuseStringUtils.formatNumberFromUnits(property.getValue(), PowerModule.getUnit(property.getKey()));
String name = property.getKey();
double valueWidth = MuseRenderer.getStringWidth(formattedValue);
double allowedNameWidth = border.width() - valueWidth - margin * 2;
List<String> namesList = MuseStringUtils.wrapStringToVisualLength(name, allowedNameWidth);
for(int i=0; i<namesList.size();i++) {
MuseRenderer.drawString(namesList.get(i), border.left() + margin, nexty + 9*i);
}
MuseRenderer.drawRightAlignedString(formattedValue, border.right() - margin, nexty + 9 * (namesList.size()-1)/2);
nexty += 9*namesList.size()+1;
}
GL11.glPopMatrix();

View file

@ -1,5 +1,6 @@
package net.machinemuse.utils;
import net.machinemuse.utils.render.MuseRenderer;
import net.minecraft.util.ResourceLocation;
import java.text.DecimalFormat;
@ -175,6 +176,48 @@ public abstract class MuseStringUtils {
return strlist;
}
/**
* Takes a string and wraps it to a certain length using MuseRenderer's string length
*
* @param str
* @param length
* @return a list of strings which are no longer than
* <p/>
* <pre>
* length
* </pre>
*
* unless there is a sequence of non-space characters longer than
*
* <pre>
* length
* </pre>
*/
public static List<String> wrapStringToVisualLength(String str, double length) {
List<String> strlist = new ArrayList<String>();
String[] words = str.split(" ");
if(words.length == 0) {
return null;
}
int line = 0;
String currLine = words[0];
for(int i=1; i<words.length;i++) {
String approxLine = currLine + " " + words[i];
if(MuseRenderer.getStringWidth(approxLine) > length) {
strlist.add(currLine);
currLine = " " + words[i];
} else {
currLine = approxLine;
}
}
strlist.add(currLine);
return strlist;
}
public static String extractName(ResourceLocation resource) {
String filename = resource.toString();
int ix = Math.max(filename.lastIndexOf('/'), Math.max(filename.lastIndexOf('\\'), filename.lastIndexOf(':'))) + 1;