Updated item transfer visuals, centered block inventory

This commit is contained in:
Anuken 2018-05-21 12:03:49 -04:00
parent 8f137eadf0
commit 241b86d704
6 changed files with 173 additions and 151 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 B

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 107 KiB

View File

@ -1,5 +1,6 @@
package io.anuke.mindustry.entities; package io.anuke.mindustry.entities;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Pools; import com.badlogic.gdx.utils.Pools;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
@ -7,6 +8,10 @@ import io.anuke.mindustry.type.Item;
import io.anuke.ucore.entities.Entity; import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.TimedEntity; import io.anuke.ucore.entities.TimedEntity;
import io.anuke.ucore.function.Callable; import io.anuke.ucore.function.Callable;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Position; import io.anuke.ucore.util.Position;
public class ItemTransfer extends TimedEntity{ public class ItemTransfer extends TimedEntity{
@ -14,6 +19,7 @@ public class ItemTransfer extends TimedEntity{
private Vector2 current = new Vector2(); private Vector2 current = new Vector2();
private Vector2 tovec = new Vector2(); private Vector2 tovec = new Vector2();
private Item item; private Item item;
private float seed;
private Position to; private Position to;
private Callable done; private Callable done;
@ -24,6 +30,7 @@ public class ItemTransfer extends TimedEntity{
tr.to = to; tr.to = to;
tr.done = done; tr.done = done;
tr.lifetime = 60f; tr.lifetime = 60f;
tr.seed = Mathf.range(1f);
tr.add(); tr.add();
} }
@ -42,19 +49,33 @@ public class ItemTransfer extends TimedEntity{
@Override @Override
public void removed() { public void removed() {
done.run();
Pools.free(this); Pools.free(this);
} }
@Override @Override
public void update() { public void update() {
super.update(); super.update();
current.set(from).lerp(tovec.set(to.getX(), to.getY()), fin()); current.set(from).interpolate(tovec.set(to.getX(), to.getY()), fin(), Interpolation.pow3);
current.add(tovec.set(to.getX(), to.getY()).sub(from).nor().rotate90(1).scl(seed * fslope() * 10f));
set(current.x, current.y); set(current.x, current.y);
} }
@Override @Override
public void draw() { public void draw() {
float length = fslope()*6f;
float angle = current.set(x, y).sub(from).angle();
Draw.color("accent");
Lines.stroke(fslope()*2f);
Lines.circle(x, y, fslope()*2f);
Lines.lineAngleCenter(x, y, angle, length);
Lines.lineAngle(x, y, angle, fout()*6f);
Draw.color(item.color);
Fill.circle(x, y, fslope()*1.5f);
Draw.reset();
} }
@Override @Override

View File

@ -15,7 +15,6 @@ import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Inputs; import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.function.BooleanProvider; import io.anuke.ucore.function.BooleanProvider;
import io.anuke.ucore.function.Callable;
import io.anuke.ucore.scene.Group; import io.anuke.ucore.scene.Group;
import io.anuke.ucore.scene.event.HandCursorListener; import io.anuke.ucore.scene.event.HandCursorListener;
import io.anuke.ucore.scene.event.Touchable; import io.anuke.ucore.scene.event.Touchable;
@ -24,7 +23,6 @@ import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings; import io.anuke.ucore.util.Strings;
import static io.anuke.mindustry.Vars.state; import static io.anuke.mindustry.Vars.state;
import static io.anuke.mindustry.Vars.tilesize;
public class BlockInventoryFragment implements Fragment { public class BlockInventoryFragment implements Fragment {
private Table table; private Table table;
@ -122,10 +120,9 @@ public class BlockInventoryFragment implements Fragment {
int sent = Mathf.clamp(amount/3, 1, 8); int sent = Mathf.clamp(amount/3, 1, 8);
int per = Math.min(amount/sent, 5); int per = Math.min(amount/sent, 5);
int[] soFar = {amount}; int[] soFar = {amount};
Vector2 v = image.localToStageCoordinates(new Vector2(image.getWidth() / 2f, image.getHeight() / 2f));
for(int j = 0; j < sent; j ++){ for(int j = 0; j < sent; j ++){
boolean all = j == sent-1; boolean all = j == sent-1;
Timers.run(j*5, () -> move(item, tile, () -> { Timers.run(j*5, () -> ItemTransfer.create(item, tile.drawx(), tile.drawy(), player, () -> {
player.inventory.addItem(item, all ? soFar[0] : per); player.inventory.addItem(item, all ? soFar[0] : per);
soFar[0] -= per; soFar[0] -= per;
})); }));
@ -139,16 +136,12 @@ public class BlockInventoryFragment implements Fragment {
} }
if(row == 0){ if(row == 0){
table.add("[LIGHT_GRAY]<empty>"); table.addImage("icon-items-none").color(Color.LIGHT_GRAY);
} }
updateTablePosition(); updateTablePosition();
} }
private void move(Item item, Tile tile, Callable c){
ItemTransfer.create(item, tile.drawx(), tile.drawy(), input.player, c);
}
private String round(float f){ private String round(float f){
f = (int)f; f = (int)f;
if(f >= 1000){ if(f >= 1000){
@ -159,9 +152,9 @@ public class BlockInventoryFragment implements Fragment {
} }
private void updateTablePosition(){ private void updateTablePosition(){
Vector2 v = Graphics.screen(tile.drawx() + tile.block().size*tilesize/2f, tile.drawy() + tile.block().size*tilesize/2f); Vector2 v = Graphics.screen(tile.drawx(), tile.drawy());
table.pack(); table.pack();
table.setPosition(v.x, v.y, Align.topLeft); table.setPosition(v.x, v.y, Align.center);
} }
} }

View File

@ -1,6 +1,7 @@
package io.anuke.mindustry.world.blocks.types.storage; package io.anuke.mindustry.world.blocks.types.storage;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import io.anuke.mindustry.entities.ItemTransfer;
import io.anuke.mindustry.entities.Unit; import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.Units; import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
@ -83,7 +84,7 @@ public class CoreBlock extends StorageBlock {
if(tile.entity.items.items[i] > 0 && unit.acceptsAmmo(item)){ if(tile.entity.items.items[i] > 0 && unit.acceptsAmmo(item)){
tile.entity.items.items[i] --; tile.entity.items.items[i] --;
unit.addAmmo(item); unit.addAmmo(item);
//new ItemTransferEffect(item, tile.drawx(), tile.drawy(), unit).add(); ItemTransfer.create(item, tile.drawx(), tile.drawy(), unit, () -> {});
return; return;
} }
} }