Config drawing
This commit is contained in:
@@ -68,6 +68,7 @@ public class UI implements ApplicationListener, Loadable{
|
||||
public DeployDialog deploy;
|
||||
public TechTreeDialog tech;
|
||||
public MinimapDialog minimap;
|
||||
public SchematicsDialog schematics;
|
||||
public ModsDialog mods;
|
||||
|
||||
public Cursor drillCursor, unloadCursor;
|
||||
@@ -225,6 +226,7 @@ public class UI implements ApplicationListener, Loadable{
|
||||
tech = new TechTreeDialog();
|
||||
minimap = new MinimapDialog();
|
||||
mods = new ModsDialog();
|
||||
schematics = new SchematicsDialog();
|
||||
|
||||
Group group = Core.scene.root;
|
||||
|
||||
|
||||
@@ -27,18 +27,17 @@ public class Schematics{
|
||||
private static final byte[] header = {'m', 's', 'c', 'h'};
|
||||
private static final byte version = 0;
|
||||
|
||||
private static final int resolution = 64;
|
||||
private static final int padding = 2;
|
||||
private static final int maxSize = 64;
|
||||
|
||||
private OptimizedByteArrayOutputStream out = new OptimizedByteArrayOutputStream(1024);
|
||||
private Array<Schematic> all = new Array<>();
|
||||
private OrderedMap<Schematic, FrameBuffer> previews = new OrderedMap<>();
|
||||
private OrderedMap<Schematic, ObjectMap<PreviewRes, FrameBuffer>> previews = new OrderedMap<>();
|
||||
private FrameBuffer shadowBuffer;
|
||||
|
||||
public Schematics(){
|
||||
Events.on(DisposeEvent.class, e -> {
|
||||
previews.each((schem, buffer) -> buffer.dispose());
|
||||
previews.each((schem, m) -> m.each((res, buffer) -> buffer.dispose()));
|
||||
previews.clear();
|
||||
shadowBuffer.dispose();
|
||||
});
|
||||
@@ -62,8 +61,13 @@ public class Schematics{
|
||||
});
|
||||
}
|
||||
|
||||
public Texture getPreview(Schematic schematic){
|
||||
if(!previews.containsKey(schematic)){
|
||||
public Array<Schematic> all(){
|
||||
return all;
|
||||
}
|
||||
|
||||
public Texture getPreview(Schematic schematic, PreviewRes res){
|
||||
if(!previews.getOr(schematic, ObjectMap::new).containsKey(res)){
|
||||
int resolution = res.resolution;
|
||||
Draw.blend();
|
||||
Draw.color();
|
||||
Time.mark();
|
||||
@@ -92,7 +96,7 @@ public class Schematics{
|
||||
|
||||
buffer.beginDraw(Color.orange);
|
||||
|
||||
Draw.proj().setOrtho(0, 0, buffer.getWidth(), buffer.getHeight());
|
||||
Draw.proj().setOrtho(0, buffer.getHeight(), buffer.getWidth(), -buffer.getHeight());
|
||||
for(int x = 0; x < schematic.width + padding; x++){
|
||||
for(int y = 0; y < schematic.height + padding; y++){
|
||||
Draw.rect("dark-panel-4", x * resolution + resolution/2f, y * resolution + resolution/2f, resolution, resolution);
|
||||
@@ -101,28 +105,37 @@ public class Schematics{
|
||||
|
||||
Tmp.tr1.set(shadowBuffer.getTexture(), 0, 0, schematic.width + padding, schematic.height + padding);
|
||||
Draw.color(0f, 0f, 0f, 1f);
|
||||
Draw.rect(Tmp.tr1, buffer.getWidth()/2f, buffer.getHeight()/2f, buffer.getWidth(), buffer.getHeight());
|
||||
Draw.rect(Tmp.tr1, buffer.getWidth()/2f, buffer.getHeight()/2f, buffer.getWidth(), -buffer.getHeight());
|
||||
Draw.color();
|
||||
|
||||
Array<BuildRequest> requests = schematic.tiles.map(t -> new BuildRequest(t.x, t.y, t.rotation, t.block).configure(t.config));
|
||||
Array<BuildRequest> requests = schematic.tiles.map(t -> new BuildRequest(t.x, t.y, t.rotation, t.block){
|
||||
@Override
|
||||
public float drawx(){
|
||||
float offset = (t.block.size + 1) % 2 / 2f;
|
||||
return (t.x + 0.5f + padding/2f + offset) * resolution;
|
||||
}
|
||||
|
||||
schematic.tiles.each(t -> {
|
||||
float offset = (t.block.size + 1) % 2 / 2f;
|
||||
Draw.rect(t.block.icon(Cicon.full),
|
||||
(t.x + 0.5f + padding/2f + offset) * resolution,
|
||||
buffer.getHeight() - 1 - (t.y + 0.5f + padding/2f + offset) * resolution,
|
||||
resolution * t.block.size, -resolution * t.block.size, t.block.rotate ? t.rotation * 90 : 0);
|
||||
@Override
|
||||
public float drawy(){
|
||||
float offset = (t.block.size + 1) % 2 / 2f;
|
||||
return (t.y + 0.5f + padding/2f + offset) * resolution;
|
||||
}
|
||||
}.configure(t.config));
|
||||
|
||||
requests.each(req -> {
|
||||
req.animScale = 4f;
|
||||
req.block.drawRequestRegion(req, requests::each);
|
||||
});
|
||||
|
||||
buffer.endDraw();
|
||||
|
||||
Draw.proj(Tmp.m3);
|
||||
|
||||
previews.put(schematic, buffer);
|
||||
previews.getOr(schematic, ObjectMap::new).put(res, buffer);
|
||||
Log.info("Time taken: {0}", Time.elapsed());
|
||||
}
|
||||
|
||||
return previews.get(schematic).getTexture();
|
||||
return previews.get(schematic).get(res).getTexture();
|
||||
}
|
||||
|
||||
/** Creates an array of build requests from a schematic's data, centered on the provided x+y coordinates. */
|
||||
@@ -146,6 +159,32 @@ public class Schematics{
|
||||
|
||||
Array<Stile> tiles = new Array<>();
|
||||
|
||||
int minx = x2, miny = y2, maxx = x, maxy = y;
|
||||
boolean found = false;
|
||||
for(int cx = x; cx <= x2; cx++){
|
||||
for(int cy = y; cy <= y2; cy++){
|
||||
Tile tile = world.tile(cx, cy);
|
||||
Tile linked = world.ltile(cx, cy);
|
||||
|
||||
if(linked != null && linked.entity != null){
|
||||
minx = Math.min(tile.x, minx);
|
||||
miny = Math.min(tile.y, miny);
|
||||
maxx = Math.max(tile.x, maxx);
|
||||
maxy = Math.max(tile.y, maxy);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(found){
|
||||
x = minx;
|
||||
y = miny;
|
||||
x2 = maxx;
|
||||
y2 = maxy;
|
||||
}else{
|
||||
return new Schematic(new Array<>(), 1, 1);
|
||||
}
|
||||
|
||||
int width = x2 - x + 1, height = y2 - y + 1;
|
||||
int offsetX = -x, offsetY = -y;
|
||||
for(int cx = x; cx <= x2; cx++){
|
||||
@@ -260,4 +299,14 @@ public class Schematics{
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
public enum PreviewRes{
|
||||
low(8), high(32);
|
||||
|
||||
public final int resolution;
|
||||
|
||||
PreviewRes(int resolution){
|
||||
this.resolution = resolution;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import io.anuke.mindustry.core.GameState.*;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait.*;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.game.Schematics.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.graphics.*;
|
||||
import io.anuke.mindustry.ui.*;
|
||||
@@ -111,9 +112,9 @@ public class DesktopInput extends InputHandler{
|
||||
Draw.reset();
|
||||
|
||||
if(__REMOVE__ != null){
|
||||
Texture tex = schematics.getPreview(__REMOVE__);
|
||||
Texture tex = schematics.getPreview(__REMOVE__, PreviewRes.high);
|
||||
Draw.blend(Blending.disabled);
|
||||
Draw.rect(Draw.wrap(tex), Core.camera.position.x, Core.camera.position.y, tex.getWidth() / 8f, tex.getHeight() / 8f);
|
||||
Draw.rect(Draw.wrap(tex), Core.camera.position.x, Core.camera.position.y, tex.getWidth() / 4f, tex.getHeight() / 4f);
|
||||
Draw.blend();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.scene.style.*;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.game.Schematics.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.schematics;
|
||||
|
||||
public class SchematicsDialog extends FloatingDialog{
|
||||
|
||||
public SchematicsDialog(){
|
||||
@@ -10,5 +17,18 @@ public class SchematicsDialog extends FloatingDialog{
|
||||
|
||||
void setup(){
|
||||
cont.clear();
|
||||
|
||||
cont.pane(t -> {
|
||||
int i = 0;
|
||||
for(Schematic s : schematics.all()){
|
||||
addImageButton(new TextureRegionDrawable(new TextureRegion(schematics.getPreview(s, PreviewRes.low))), 100f, () -> {
|
||||
|
||||
}).size(110f).pad(4);
|
||||
|
||||
if(++i % 3 == 0){
|
||||
t.row();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,8 +681,28 @@ public class Block extends BlockStorage{
|
||||
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list){
|
||||
TextureRegion reg = icon(Cicon.full);
|
||||
Draw.rect(icon(Cicon.full), req.drawx(), req.drawy(),
|
||||
reg.getWidth() * req.animScale * Draw.scl, reg.getHeight() * req.animScale * Draw.scl,
|
||||
!rotate ? 0 : req.rotation * 90);
|
||||
reg.getWidth() * req.animScale * Draw.scl,
|
||||
reg.getHeight() * req.animScale * Draw.scl,
|
||||
!rotate ? 0 : req.rotation * 90);
|
||||
|
||||
if(req.hasConfig){
|
||||
drawRequestConfig(req, list);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawRequestConfig(BuildRequest req, Eachable<BuildRequest> list){
|
||||
|
||||
}
|
||||
|
||||
public void drawRequestConfigCenter(BuildRequest req, Content content, String region){
|
||||
Color color = content instanceof Item ? ((Item)content).color : content instanceof Liquid ? ((Liquid)content).color : null;
|
||||
if(color == null) return;
|
||||
|
||||
Draw.color(color);
|
||||
Draw.scl *= req.animScale;
|
||||
Draw.rect(region, req.drawx(), req.drawy());
|
||||
Draw.scl /= req.animScale;
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -52,11 +52,13 @@ public class Conduit extends LiquidBlock implements Autotiler{
|
||||
|
||||
Draw.colorl(0.34f);
|
||||
Draw.alpha(0.5f);
|
||||
Draw.rect(botRegions[bits[0]], req.drawx(), req.drawy(), req.rotation * 90);
|
||||
Draw.rect(botRegions[bits[0]], req.drawx(), req.drawy(),
|
||||
botRegions[bits[0]].getWidth() * Draw.scl * req.animScale, botRegions[bits[0]].getHeight() * Draw.scl * req.animScale,
|
||||
req.rotation * 90);
|
||||
Draw.color();
|
||||
|
||||
|
||||
Draw.rect(topRegions[bits[0]], req.drawx(), req.drawy(), req.rotation * 90);
|
||||
Draw.rect(topRegions[bits[0]], req.drawx(), req.drawy(), topRegions[bits[0]].getWidth() * Draw.scl * req.animScale, topRegions[bits[0]].getHeight() * Draw.scl * req.animScale, req.rotation * 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -107,7 +107,7 @@ public class Conveyor extends Block implements Autotiler{
|
||||
if(bits == null) return;
|
||||
|
||||
TextureRegion region = regions[bits[0]][0];
|
||||
Draw.rect(region, req.drawx(), req.drawy(), region.getWidth() * bits[1] * Draw.scl, region.getHeight() * bits[2] * Draw.scl, req.rotation * 90);
|
||||
Draw.rect(region, req.drawx(), req.drawy(), region.getWidth() * bits[1] * Draw.scl * req.animScale, region.getHeight() * bits[2] * Draw.scl * req.animScale, req.rotation * 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package io.anuke.mindustry.world.blocks.distribution;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.arc.util.ArcAnnotate.*;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait.*;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
@@ -46,6 +48,11 @@ public class Sorter extends Block{
|
||||
tile.<SorterEntity>entity().sortItem = content.item(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRequestConfig(BuildRequest req, Eachable<BuildRequest> list){
|
||||
drawRequestConfigCenter(req, content.item(req.config), "center");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
@@ -33,53 +33,6 @@ public class PowerNode extends PowerBlock{
|
||||
consumesPower = false;
|
||||
outputsPower = false;
|
||||
}
|
||||
/*
|
||||
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
||||
public static void linkPowerNodes(Player player, Tile tile, Tile other){
|
||||
if(tile.entity == null || other == null || tile.entity.power == null || !((PowerNode)tile.block()).linkValid(tile, other)
|
||||
|| tile.entity.power.links.size >= ((PowerNode)tile.block()).maxNodes) return;
|
||||
if(!Units.canInteract(player, tile)) return;
|
||||
|
||||
TileEntity entity = tile.entity();
|
||||
|
||||
if(!entity.power.links.contains(other.pos())){
|
||||
entity.power.links.add(other.pos());
|
||||
}
|
||||
|
||||
if(other.getTeamID() == tile.getTeamID()){
|
||||
|
||||
if(!other.entity.power.links.contains(tile.pos())){
|
||||
other.entity.power.links.add(tile.pos());
|
||||
}
|
||||
}
|
||||
|
||||
entity.power.graph.add(other.entity.power.graph);
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
||||
public static void unlinkPowerNodes(Player player, Tile tile, Tile other){
|
||||
if(tile.entity.power == null || other.entity == null || other.entity.power == null) return;
|
||||
if(!Units.canInteract(player, tile)) return;
|
||||
|
||||
TileEntity entity = tile.entity();
|
||||
|
||||
entity.power.links.removeValue(other.pos());
|
||||
other.entity.power.links.removeValue(tile.pos());
|
||||
|
||||
PowerGraph newgraph = new PowerGraph();
|
||||
|
||||
//reflow from this point, covering all tiles on this side
|
||||
newgraph.reflow(tile);
|
||||
|
||||
if(other.entity.power.graph != newgraph){
|
||||
//create new graph for other end
|
||||
PowerGraph og = new PowerGraph();
|
||||
//reflow from other end
|
||||
og.reflow(other);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void configured(Tile tile, Player player, int value){
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package io.anuke.mindustry.world.blocks.sandbox;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait.*;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
@@ -43,6 +45,11 @@ public class ItemSource extends Block{
|
||||
bars.remove("items");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRequestConfig(BuildRequest req, Eachable<BuildRequest> list){
|
||||
drawRequestConfigCenter(req, content.item(req.config), "center");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outputsItems(){
|
||||
return true;
|
||||
|
||||
@@ -2,11 +2,13 @@ package io.anuke.mindustry.world.blocks.sandbox;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.scene.style.*;
|
||||
import io.anuke.arc.scene.ui.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.arc.util.ArcAnnotate.*;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait.*;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
@@ -57,6 +59,11 @@ public class LiquidSource extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRequestConfig(BuildRequest req, Eachable<BuildRequest> list){
|
||||
drawRequestConfigCenter(req, content.liquid(req.config), "center");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package io.anuke.mindustry.world.blocks.storage;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait.*;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
@@ -28,6 +30,11 @@ public class Unloader extends Block{
|
||||
configurable = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRequestConfig(BuildRequest req, Eachable<BuildRequest> list){
|
||||
drawRequestConfigCenter(req, content.item(req.config), "unloader-center");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDump(Tile tile, Tile to, Item item){
|
||||
return !(to.block() instanceof StorageBlock);
|
||||
@@ -109,7 +116,7 @@ public class Unloader extends Block{
|
||||
UnloaderEntity entity = tile.entity();
|
||||
|
||||
Draw.color(entity.sortItem == null ? Color.clear : entity.sortItem.color);
|
||||
Fill.square(tile.worldx(), tile.worldy(), 1f);
|
||||
Draw.rect("unloader-center", tile.worldx(), tile.worldy());
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user