Implemented item dragging and transferring
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package io.anuke.mindustry.entities;
|
||||
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.TimedEntity;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class ItemAnimationEffect extends TimedEntity {
|
||||
private static final float size = 5f;
|
||||
|
||||
private final Vector2 vec = new Vector2();
|
||||
private final Vector2 from = new Vector2();
|
||||
private final Vector2 to = new Vector2();
|
||||
private final Item item;
|
||||
|
||||
public ItemAnimationEffect(Item item, float x, float y, float tox, float toy) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.item = item;
|
||||
from.set(x, y);
|
||||
to.set(tox, toy);
|
||||
lifetime = 40f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
|
||||
vec.set(from).interpolate(to, fin(), Interpolation.fade);
|
||||
x = vec.x;
|
||||
y = vec.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
float s = size * Mathf.curve(fout(), 0.1f);
|
||||
Draw.rect(item.region, x, y, s, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Entity> T add() {
|
||||
return super.add(Vars.effectGroup);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import io.anuke.mindustry.content.fx.Fx;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Mech;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
@@ -46,6 +47,7 @@ public class Player extends Unit{
|
||||
|
||||
public float targetAngle = 0f;
|
||||
public boolean dashing = false;
|
||||
public boolean selectingItem;
|
||||
|
||||
public int clientid = -1;
|
||||
public boolean isLocal = false;
|
||||
@@ -182,6 +184,15 @@ public class Player extends Unit{
|
||||
Draw.rect(weapon.name + "-equip", x + tr.x, y + tr.y, w, 8, rotation - 90);
|
||||
}
|
||||
|
||||
float backTrns = 4f, itemSize = 5f;
|
||||
if(inventory.hasItem() && !control.input().isDroppingItem()){
|
||||
ItemStack stack = inventory.getItem();
|
||||
Draw.rect(stack.item.region, x + Angles.trnsx(rotation + 180f, backTrns), y + Angles.trnsy(rotation + 180f, backTrns), itemSize, itemSize, rotation);
|
||||
//Draw.tint(Color.WHITE);
|
||||
//Lines.circle(x + Angles.trnsx(rotation + 180f, backTrns), y + Angles.trnsy(rotation + 180f, backTrns), 3f + Mathf.absin(Timers.time(), 3f, 0.8f));
|
||||
//Draw.tint(Color.WHITE);
|
||||
}
|
||||
|
||||
Draw.alpha(1f);
|
||||
|
||||
x = px;
|
||||
@@ -239,8 +250,7 @@ public class Player extends Unit{
|
||||
movement.y += ya*speed;
|
||||
movement.x += xa*speed;
|
||||
|
||||
boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shoot") && control.input().recipe == null
|
||||
&& !ui.hasMouse() && !control.input().onConfigurable();
|
||||
boolean shooting = control.input().canShoot() && control.input().isShooting();
|
||||
|
||||
if(shooting){
|
||||
weaponLeft.update(player, true);
|
||||
|
||||
@@ -3,14 +3,51 @@ package io.anuke.mindustry.entities;
|
||||
import io.anuke.mindustry.resource.*;
|
||||
|
||||
public class UnitInventory {
|
||||
public final AmmoEntry ammo = new AmmoEntry(AmmoType.getByID(0), 0);
|
||||
public final ItemStack item = new ItemStack(Item.getByID(0), 0);
|
||||
public final LiquidStack liquid = new LiquidStack(Liquid.getByID(0), 0);
|
||||
public float power = 0f;
|
||||
private final AmmoEntry ammo = new AmmoEntry(AmmoType.getByID(0), 0);
|
||||
|
||||
private CarryItem item;
|
||||
|
||||
public void clear(){
|
||||
item = null;
|
||||
}
|
||||
|
||||
public boolean hasAnything(){
|
||||
return item != null;
|
||||
}
|
||||
|
||||
public boolean hasLiquid(){
|
||||
return item instanceof LiquidStack;
|
||||
}
|
||||
|
||||
public boolean hasItem(){
|
||||
return item instanceof ItemStack;
|
||||
}
|
||||
|
||||
public void addItem(Item item, int amount){
|
||||
if(this.item.item != item) this.item.amount = 0;
|
||||
this.item.item = item;
|
||||
this.item.amount += amount;
|
||||
if(hasItem()){
|
||||
getItem().amount = getItem().item == item ? getItem().amount + amount : amount;
|
||||
getItem().item = item;
|
||||
}else{
|
||||
this.item = new ItemStack(item, amount);
|
||||
}
|
||||
}
|
||||
|
||||
public void addLiquid(Liquid liquid, float amount){
|
||||
if(hasItem()){
|
||||
getLiquid().liquid = liquid;
|
||||
getLiquid().amount = amount;
|
||||
}else{
|
||||
this.item = new LiquidStack(liquid, amount);
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getItem(){
|
||||
if(!hasItem()) throw new RuntimeException("This inventory has no item! Check hasItem() first.");
|
||||
return (ItemStack)item;
|
||||
}
|
||||
|
||||
public LiquidStack getLiquid(){
|
||||
if(!hasItem()) throw new RuntimeException("This inventory has no item! Check hasItem() first.");
|
||||
return (LiquidStack)item;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user