Key config gui rough draft
This commit is contained in:
parent
44656c1e84
commit
aecd7c44f2
15 changed files with 387 additions and 16 deletions
|
@ -8,6 +8,7 @@ import java.util.List;
|
|||
|
||||
import net.machinemuse.general.gui.MuseGui;
|
||||
import net.machinemuse.general.gui.MuseIcon;
|
||||
import net.machinemuse.general.gui.clickable.IClickable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.model.PositionTextureVertex;
|
||||
|
@ -722,4 +723,32 @@ public abstract class MuseRenderer {
|
|||
}
|
||||
return renderItem;
|
||||
}
|
||||
|
||||
public static void drawLineBetween(IClickable firstClickable, IClickable secondClickable, Colour gradientColour) {
|
||||
long varia = System.currentTimeMillis() % 2000 - 1000; // ranges from -1000 to 1000 and around, period = 2 seconds
|
||||
double gradientRatio = 1.0 - ((varia + 1000) % 1000)/1000.0;
|
||||
Point2D midpoint = (firstClickable.getPosition().minus(secondClickable.getPosition()).times(Math.abs(varia/1000.0)).plus(secondClickable.getPosition()));
|
||||
Point2D firstpoint, secondpoint;
|
||||
if(varia < 0) {
|
||||
firstpoint = secondClickable.getPosition();
|
||||
secondpoint = firstClickable.getPosition();
|
||||
} else {
|
||||
firstpoint = firstClickable.getPosition();
|
||||
secondpoint = secondClickable.getPosition();
|
||||
}
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glBegin(GL11.GL_LINES);
|
||||
gradientColour.withAlpha(gradientRatio).doGL();
|
||||
GL11.glVertex3d(midpoint.x(), midpoint.y(), 1);
|
||||
gradientColour.withAlpha(0.0).doGL();
|
||||
GL11.glVertex3d(firstpoint.x(), firstpoint.y(), 1);
|
||||
|
||||
gradientColour.withAlpha(gradientRatio).doGL();
|
||||
GL11.glVertex3d(secondpoint.x(), secondpoint.y(), 1);
|
||||
Colour.WHITE.withAlpha(1.0).doGL();
|
||||
GL11.glVertex3d(midpoint.x(), midpoint.y(), 1);
|
||||
GL11.glEnd();
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,4 +49,27 @@ public class Point2D {
|
|||
public Point2D times(double scalefactor) {
|
||||
return new Point2D(x * scalefactor, y * scalefactor);
|
||||
}
|
||||
|
||||
public double distance() {
|
||||
return Math.sqrt(x*x + y*y);
|
||||
}
|
||||
|
||||
public double distanceTo(Point2D position) {
|
||||
return Math.sqrt(distanceSq(position));
|
||||
}
|
||||
|
||||
public double distanceSq(Point2D position) {
|
||||
double xdist = position.x - this.x;
|
||||
double ydist = position.y - this.y;
|
||||
return xdist*xdist+ydist*ydist;
|
||||
}
|
||||
|
||||
public Point2D normalize() {
|
||||
double distance = distance();
|
||||
return new Point2D(x/distance, y/distance);
|
||||
}
|
||||
|
||||
public Point2D midpoint(Point2D target) {
|
||||
return new Point2D((this.x + target.x)/2, (this.y + target.y)/2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,25 @@
|
|||
package net.machinemuse.general.gui;
|
||||
|
||||
public class KeyConfigGui extends MuseGui {
|
||||
import net.machinemuse.general.geometry.Point2D;
|
||||
import net.machinemuse.general.gui.frame.KeybindConfigFrame;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class KeyConfigGui extends MuseGui {
|
||||
private EntityPlayer player;
|
||||
|
||||
public KeyConfigGui(EntityPlayer player) {
|
||||
super();
|
||||
this.player = player;
|
||||
this.xSize = 256;
|
||||
this.ySize = 226;
|
||||
}
|
||||
/**
|
||||
* Add the buttons (and other controls) to the screen.
|
||||
*/
|
||||
@Override public void initGui() {
|
||||
super.initGui();
|
||||
frames.add(new KeybindConfigFrame(
|
||||
new Point2D(absX(-0.95F), absY(-0.95F)),
|
||||
new Point2D(absX(0.95F), absY(0.95F)), player));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,4 +25,8 @@ public abstract class Clickable implements IClickable {
|
|||
public void setPosition(Point2D position) {
|
||||
this.position = position;
|
||||
}
|
||||
public void move(double x, double y) {
|
||||
this.position.setX(x);
|
||||
this.position.setY(y);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package net.machinemuse.general.gui.clickable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.machinemuse.general.geometry.Colour;
|
||||
import net.machinemuse.general.geometry.MuseRenderer;
|
||||
import net.machinemuse.general.geometry.Point2D;
|
||||
|
||||
public class ClickableKeybinding extends Clickable {
|
||||
protected List<ClickableModule> boundModules;
|
||||
protected String label;
|
||||
|
||||
public ClickableKeybinding(String label, Point2D position) {
|
||||
this.label = label;
|
||||
this.position = position;
|
||||
this.boundModules = new ArrayList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
MuseRenderer.drawCircleAround(position.x(), position.y(), 8);
|
||||
MuseRenderer.drawCenteredString(label, position.x(), position.y() - 4);
|
||||
for (ClickableModule module : boundModules) {
|
||||
MuseRenderer.drawLineBetween(this, module, Colour.LIGHTBLUE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hitBox(double x, double y) {
|
||||
return position.minus(new Point2D(x, y)).distance() < 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getToolTip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void bindModule(ClickableModule module) {
|
||||
boundModules.add(module);
|
||||
}
|
||||
|
||||
public void unbindModule(ClickableModule module) {
|
||||
boundModules.remove(module);
|
||||
}
|
||||
|
||||
public void unbindFarModules() {
|
||||
Iterator<ClickableModule> iterator = boundModules.iterator();
|
||||
ClickableModule module;
|
||||
while (iterator.hasNext()) {
|
||||
module = iterator.next();
|
||||
int maxDistance = getTargetDistance()*2;
|
||||
double distanceSq = module.getPosition().distanceSq(this.getPosition());
|
||||
if (distanceSq > maxDistance * maxDistance) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getTargetDistance() {
|
||||
int targetDistance = 16;
|
||||
if(boundModules.size() > 6) {
|
||||
targetDistance += (boundModules.size()-6)*3;
|
||||
}
|
||||
return targetDistance;
|
||||
}
|
||||
|
||||
public void attractBoundModules(IClickable exception) {
|
||||
for (ClickableModule module : boundModules) {
|
||||
if (module != exception) {
|
||||
Point2D euclideanDistance = module.getPosition().minus(this.getPosition());
|
||||
Point2D directionVector = euclideanDistance.normalize();
|
||||
Point2D tangentTarget = directionVector.times(getTargetDistance()).plus(this.getPosition());
|
||||
Point2D midpointTangent = module.getPosition().midpoint(tangentTarget);
|
||||
module.move(midpointTangent.x(), midpointTangent.y());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -42,4 +42,15 @@ public class ClickableLabel implements IClickable {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(double x, double y) {
|
||||
this.position.setX(x);
|
||||
this.position.setY(y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point2D getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import net.machinemuse.powersuits.powermodule.PowerModule;
|
|||
* @author MachineMuse
|
||||
*/
|
||||
public class ClickableModule extends Clickable {
|
||||
private PowerModule module;
|
||||
protected PowerModule module;
|
||||
|
||||
/**
|
||||
* @param vaug
|
||||
|
|
|
@ -2,10 +2,16 @@ package net.machinemuse.general.gui.clickable;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import net.machinemuse.general.geometry.Point2D;
|
||||
|
||||
public interface IClickable {
|
||||
|
||||
public abstract void draw();
|
||||
|
||||
public abstract void move(double x, double y);
|
||||
|
||||
public abstract Point2D getPosition();
|
||||
|
||||
public abstract boolean hitBox(double x, double y);
|
||||
|
||||
public abstract List<String> getToolTip();
|
||||
|
|
|
@ -0,0 +1,168 @@
|
|||
package net.machinemuse.general.gui.frame;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.machinemuse.general.geometry.Colour;
|
||||
import net.machinemuse.general.geometry.MuseRenderer;
|
||||
import net.machinemuse.general.geometry.Point2D;
|
||||
import net.machinemuse.general.gui.clickable.ClickableKeybinding;
|
||||
import net.machinemuse.general.gui.clickable.ClickableModule;
|
||||
import net.machinemuse.general.gui.clickable.IClickable;
|
||||
import net.machinemuse.powersuits.item.ItemUtils;
|
||||
import net.machinemuse.powersuits.powermodule.PowerModule;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class KeybindConfigFrame implements IGuiFrame {
|
||||
protected List<ClickableModule> modules;
|
||||
protected List<ClickableKeybinding> keybinds;
|
||||
protected IClickable selectedClickie;
|
||||
protected ClickableKeybinding closestKeybind;
|
||||
protected EntityPlayer player;
|
||||
protected Point2D ul;
|
||||
protected Point2D br;
|
||||
|
||||
public KeybindConfigFrame(Point2D ul, Point2D br, EntityPlayer player) {
|
||||
modules = new ArrayList();
|
||||
keybinds = new ArrayList();
|
||||
this.ul = ul;
|
||||
this.br = br;
|
||||
List<PowerModule> installedModules = ItemUtils.getPlayerInstalledModules(player);
|
||||
List<Point2D> points = MuseRenderer.pointsInLine(
|
||||
installedModules.size(),
|
||||
new Point2D(ul.x() + 10, ul.y() + 10),
|
||||
new Point2D(ul.x() + 10, br.y() - 10));
|
||||
Iterator<Point2D> pointIterator = points.iterator();
|
||||
for (PowerModule module : installedModules) {
|
||||
if (module.isToggleable()) {
|
||||
modules.add(new ClickableModule(module, pointIterator.next()));
|
||||
}
|
||||
}
|
||||
keybinds.add(new ClickableKeybinding("B", new Point2D(br.x() - 10, br.y() - 10)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseDown(double x, double y, int button) {
|
||||
if (button == 0) {
|
||||
if (selectedClickie == null) {
|
||||
for (ClickableModule module : modules) {
|
||||
if (module.hitBox(x, y)) {
|
||||
selectedClickie = module;
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (ClickableKeybinding keybind : keybinds) {
|
||||
if (keybind.hitBox(x, y)) {
|
||||
selectedClickie = keybind;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseUp(double x, double y, int button) {
|
||||
if (button == 0) {
|
||||
if (selectedClickie != null && closestKeybind != null && selectedClickie instanceof ClickableModule) {
|
||||
closestKeybind.bindModule((ClickableModule) selectedClickie);
|
||||
}
|
||||
selectedClickie = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(double mousex, double mousey) {
|
||||
this.closestKeybind = null;
|
||||
double closestDistance = Double.MAX_VALUE;
|
||||
if (this.selectedClickie != null) {
|
||||
this.selectedClickie.move(mousex, mousey);
|
||||
if (this.selectedClickie instanceof ClickableModule) {
|
||||
ClickableModule selectedModule = ((ClickableModule) this.selectedClickie);
|
||||
for (ClickableKeybinding keybind : this.keybinds) {
|
||||
double distance = keybind.getPosition().minus(selectedModule.getPosition()).distance();
|
||||
if (distance < closestDistance) {
|
||||
closestDistance = distance;
|
||||
if (closestDistance < 32) {
|
||||
this.closestKeybind = keybind;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ClickableKeybinding keybind : this.keybinds) {
|
||||
if (keybind != selectedClickie) {
|
||||
keybind.unbindFarModules();
|
||||
}
|
||||
keybind.attractBoundModules(selectedClickie);
|
||||
}
|
||||
for (ClickableModule module : modules) {
|
||||
if (module != selectedClickie) {
|
||||
repelOtherModules(module);
|
||||
}
|
||||
}
|
||||
for (ClickableModule module : modules) {
|
||||
clampModulePosition(module);
|
||||
}
|
||||
}
|
||||
|
||||
private void clampModulePosition(ClickableModule module) {
|
||||
Point2D position = module.getPosition();
|
||||
position.setX(clampDouble(position.x(), ul.x(), br.x()));
|
||||
position.setY(clampDouble(position.y(), ul.y(), br.y()));
|
||||
}
|
||||
|
||||
private double clampDouble(double x, double lower, double upper) {
|
||||
if (x < lower) {
|
||||
return lower;
|
||||
} else if (x > upper) {
|
||||
return upper;
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
private void repelOtherModules(ClickableModule module) {
|
||||
Point2D modulePosition = module.getPosition();
|
||||
for (ClickableModule otherModule : modules) {
|
||||
if (otherModule != selectedClickie && otherModule != module && otherModule.getPosition().distanceTo(modulePosition) < 16) {
|
||||
Point2D euclideanDistance = otherModule.getPosition().minus(module.getPosition());
|
||||
Point2D directionVector = euclideanDistance.normalize();
|
||||
Point2D tangentTarget = directionVector.times(16).plus(module.getPosition());
|
||||
Point2D midpointTangent = otherModule.getPosition().midpoint(tangentTarget);
|
||||
if (midpointTangent.distanceTo(module.getPosition()) > 2) {
|
||||
otherModule.move(midpointTangent.x(), midpointTangent.y());
|
||||
}
|
||||
// Point2D away = directionVector.times(0).plus(modulePosition);
|
||||
// module.move(away.x(), away.y());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
for (ClickableModule module : modules) {
|
||||
module.draw();
|
||||
}
|
||||
for (ClickableKeybinding keybind : keybinds) {
|
||||
keybind.draw();
|
||||
}
|
||||
if (selectedClickie != null && closestKeybind != null) {
|
||||
MuseRenderer.drawLineBetween(selectedClickie, closestKeybind, Colour.YELLOW);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getToolTip(int x, int y) {
|
||||
for(ClickableModule module : modules) {
|
||||
if(module.hitBox(x, y)) {
|
||||
return module.getToolTip();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package net.machinemuse.general.gui.frame;
|
||||
|
||||
public class NewTrashConfigFrame {
|
||||
|
||||
}
|
|
@ -6,7 +6,6 @@ import net.machinemuse.powersuits.common.CommonProxy;
|
|||
import net.machinemuse.powersuits.common.Config;
|
||||
import net.machinemuse.powersuits.common.ModCompatability;
|
||||
import net.machinemuse.powersuits.common.PowersuitsMod;
|
||||
import net.machinemuse.powersuits.event.MovementManager;
|
||||
import net.machinemuse.powersuits.event.ThaumRenderEventHandler;
|
||||
import net.machinemuse.powersuits.network.MusePacketHandler;
|
||||
import net.machinemuse.powersuits.tick.PlayerTickHandlerClient;
|
||||
|
@ -14,6 +13,7 @@ import net.machinemuse.powersuits.tick.RenderTickHandler;
|
|||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.client.registry.KeyBindingRegistry;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.common.registry.TickRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
@ -57,6 +57,7 @@ public class ClientProxy extends CommonProxy {
|
|||
@Override
|
||||
public void registerHandlers() {
|
||||
keybindHandler = new KeybindKeyHandler();
|
||||
KeyBindingRegistry.registerKeyBinding(keybindHandler);
|
||||
|
||||
playerTickHandler = new PlayerTickHandlerClient();
|
||||
TickRegistry.registerTickHandler(playerTickHandler, Side.CLIENT);
|
||||
|
|
|
@ -2,9 +2,15 @@ package net.machinemuse.powersuits.client;
|
|||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.machinemuse.powersuits.common.MuseLogger;
|
||||
import net.machinemuse.powersuits.common.PowersuitsMod;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
@ -15,7 +21,7 @@ public class KeybindKeyHandler extends KeyHandler {
|
|||
public static KeyBinding openKeybindGUI = new KeyBinding("Open Muse Keybind GUI", Keyboard.KEY_K);
|
||||
|
||||
public KeybindKeyHandler() {
|
||||
super(new KeyBinding[]{openKeybindGUI}, new boolean[]{false});
|
||||
super(new KeyBinding[] { openKeybindGUI }, new boolean[] { false });
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,8 +31,12 @@ public class KeybindKeyHandler extends KeyHandler {
|
|||
|
||||
@Override
|
||||
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) {
|
||||
if(kb.equals(openKeybindGUI)) {
|
||||
|
||||
MuseLogger.logDebug("Key " + kb + " Pressed");
|
||||
if (kb.equals(openKeybindGUI)) {
|
||||
MuseLogger.logDebug("Opening KB Gui");
|
||||
EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
|
||||
World world = Minecraft.getMinecraft().theWorld;
|
||||
player.openGui(PowersuitsMod.instance, 1, world, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,8 +48,7 @@ public class KeybindKeyHandler extends KeyHandler {
|
|||
|
||||
@Override
|
||||
public EnumSet<TickType> ticks() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return EnumSet.of(TickType.CLIENT);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.machinemuse.powersuits.common;
|
||||
|
||||
import net.machinemuse.general.gui.KeyConfigGui;
|
||||
import net.machinemuse.powersuits.block.GuiTinkerTable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
|
@ -31,6 +32,8 @@ public class GuiHandler implements IGuiHandler {
|
|||
Minecraft.getMinecraft().thePlayer.addStat(
|
||||
AchievementList.openInventory, 1);
|
||||
return new GuiTinkerTable((EntityClientPlayerMP) player);
|
||||
case 1:
|
||||
return new KeyConfigGui(player);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -469,4 +469,17 @@ public class ItemUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<PowerModule> getPlayerInstalledModules(EntityPlayer player) {
|
||||
List<PowerModule> installedModules = new ArrayList();
|
||||
for (ItemStack stack : ItemUtils.getModularItemsInInventory(player)) {
|
||||
NBTTagCompound itemTag = ItemUtils.getMuseItemTag(stack);
|
||||
for(PowerModule module : ItemUtils.getValidModulesForItem(player, stack)) {
|
||||
if(tagHasModule(itemTag, module.getName())) {
|
||||
installedModules.add(module);
|
||||
}
|
||||
}
|
||||
}
|
||||
return installedModules;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ public class PowerModule {
|
|||
protected NBTTagCompound defaultTag;
|
||||
protected Map<String, List<IPropertyModifier>> propertyModifiers;
|
||||
protected static Map<String, String> units = new HashMap();
|
||||
protected boolean toggleable = true;
|
||||
|
||||
public PowerModule(String name, boolean[] validSlots, MuseIcon icon, String category) {
|
||||
this.name = name;
|
||||
|
@ -54,6 +55,14 @@ public class PowerModule {
|
|||
return icon;
|
||||
}
|
||||
|
||||
public boolean isToggleable() {
|
||||
return toggleable;
|
||||
}
|
||||
public PowerModule setToggleable(boolean value) {
|
||||
this.toggleable = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PowerModule addTradeoffProperty(String tradeoffName, String propertyName, double multiplier) {
|
||||
return addPropertyModifier(propertyName, new PropertyModifierLinearAdditive(tradeoffName, multiplier));
|
||||
}
|
||||
|
@ -158,6 +167,6 @@ public class PowerModule {
|
|||
}
|
||||
|
||||
public boolean equals(PowerModule other) {
|
||||
return other == this;
|
||||
return other != null && other.name == this.name;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue