Incomplete zone layout

This commit is contained in:
Anuken
2019-01-25 14:09:08 -05:00
parent 058db5d5d0
commit 89e29bce62
3 changed files with 98 additions and 43 deletions

View File

@ -292,12 +292,12 @@ public class TreeLayout{
center, towardsRoot, awayFromRoot
}
public static class TreeNode{
public static class TreeNode<T extends TreeNode>{
public float width, height, x, y;
//should be initialized by user
public TreeNode[] children;
public TreeNode parent;
public T[] children;
public T parent;
private float mode, prelim, change, shift;
private int number = -1;

View File

@ -1,11 +1,23 @@
package io.anuke.mindustry.ui.dialogs;
import io.anuke.arc.Core;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.ObjectIntMap;
import io.anuke.arc.collection.ObjectSet;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.input.KeyCode;
import io.anuke.arc.scene.Group;
import io.anuke.arc.scene.event.InputEvent;
import io.anuke.arc.scene.event.InputListener;
import io.anuke.arc.scene.event.Touchable;
import io.anuke.arc.scene.style.TextureRegionDrawable;
import io.anuke.arc.scene.ui.ImageButton;
import io.anuke.arc.scene.ui.ScrollPane;
import io.anuke.arc.scene.ui.TextButton;
import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.arc.util.Align;
import io.anuke.arc.util.Structs;
import io.anuke.mindustry.content.Zones;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.game.Saves.SaveSlot;
import io.anuke.mindustry.io.SaveIO.SaveException;
@ -13,15 +25,31 @@ import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.type.ItemType;
import io.anuke.mindustry.type.Zone;
import io.anuke.mindustry.ui.TreeLayout;
import io.anuke.mindustry.ui.TreeLayout.TreeNode;
import io.anuke.mindustry.ui.dialogs.TechTreeDialog.TechTreeNode;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Block.Icon;
import static io.anuke.mindustry.Vars.*;
public class DeployDialog extends FloatingDialog{
private static final float nodeSize = 250f;
private ZoneNode root;
private ObjectSet<ZoneNode> nodes = new ObjectSet<>();
public DeployDialog(){
super("$play");
super("");
root = new ZoneNode(Zones.groundZero, null);
TreeLayout layout = new TreeLayout();
layout.gapBetweenLevels = 40f;
layout.gapBetweenNodes = 40f;
layout.layout(root);
cont.setFillParent(true);
cont.add(new View()).grow();
shown(this::setup);
}
@ -204,6 +232,11 @@ public class DeployDialog extends FloatingDialog{
return false;
}
@Override
protected void drawBackground(float x, float y){
drawDefaultBackground(x, y);
}
boolean canUnlock(Zone zone){
if(data.isUnlocked(zone)){
return true;
@ -223,4 +256,50 @@ public class DeployDialog extends FloatingDialog{
return data.hasItems(zone.itemRequirements);
}
static Array<Zone> arr = new Array<>();
class View extends Group{
float panX = 0, panY = -200;
{
for(ZoneNode node : nodes){
ImageButton button = new ImageButton("", "node");
button.setSize(nodeSize, nodeSize);
button.update(() -> {
button.setPosition(node.x + panX + width/2f, node.y + panY + height/2f, Align.center);
button.getStyle().up = Core.scene.skin.getDrawable(!locked(node.node) ? "content-background" : "content-background-locked");
((TextureRegionDrawable)button.getStyle().imageUp)
.setRegion(node.visible ? node.node.block.icon(Icon.medium) : Core.atlas.find("icon-tree-locked"));
button.getImage().setColor(!locked(node.node) ? Color.WHITE : Color.GRAY);
});
addChild(button);
}
dragged((x, y) -> {
panX += x;
panY += y;
});
}
}
class ZoneNode extends TreeNode<ZoneNode>{
final Zone zone;
ZoneNode(Zone zone, ZoneNode parent){
this.zone = zone;
this.parent = parent;
this.width = this.height = nodeSize;
nodes.add(this);
arr.selectFrom(content.zones(), other -> Structs.contains(other.zoneRequirements, zone));
children = new ZoneNode[arr.size];
for(int i = 0; i < children.length; i++){
children[i] = new ZoneNode(arr.get(i), this);
}
}
}
}

View File

@ -5,14 +5,10 @@ import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.ObjectSet;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Lines;
import io.anuke.arc.input.KeyCode;
import io.anuke.arc.math.Interpolation;
import io.anuke.arc.math.geom.Rectangle;
import io.anuke.arc.scene.Element;
import io.anuke.arc.scene.Group;
import io.anuke.arc.scene.actions.Actions;
import io.anuke.arc.scene.event.InputEvent;
import io.anuke.arc.scene.event.InputListener;
import io.anuke.arc.scene.event.Touchable;
import io.anuke.arc.scene.style.TextureRegionDrawable;
import io.anuke.arc.scene.ui.ImageButton;
@ -39,13 +35,12 @@ public class TechTreeDialog extends FloatingDialog{
public TechTreeDialog(){
super("");
cont.setFillParent(true);
TreeLayout layout = new TreeLayout();
layout.gapBetweenLevels = 60f;
layout.gapBetweenNodes = 40f;
layout.layout(root);
cont.setFillParent(true);
cont.add(new View()).grow();
{ //debug code; TODO remove
@ -74,10 +69,9 @@ public class TechTreeDialog extends FloatingDialog{
}
void checkNodes(TechTreeNode node){
boolean locked = locked(node);
boolean locked = locked(node.node);
if(!locked) node.visible = true;
for(TreeNode child : node.children){
TechTreeNode l = (TechTreeNode)child;
for(TechTreeNode l : node.children){
l.visible = !locked && l.node.block.isVisible();
checkNodes(l);
}
@ -106,19 +100,15 @@ public class TechTreeDialog extends FloatingDialog{
Core.scene.add(table);
}
boolean locked(TreeNode node){
return locked(((TechTreeNode)node).node);
}
boolean locked(TechNode node){
return !data.isUnlocked(node.block);
}
class TechTreeNode extends TreeNode{
class TechTreeNode extends TreeNode<TechTreeNode>{
final TechNode node;
boolean visible = true;
public TechTreeNode(TechNode node, TreeNode parent){
TechTreeNode(TechNode node, TechTreeNode parent){
this.node = node;
this.parent = parent;
this.width = this.height = nodeSize;
@ -135,7 +125,6 @@ public class TechTreeDialog extends FloatingDialog{
class View extends Group{
float panX = 0, panY = -200;
boolean moved = false;
Rectangle clip = new Rectangle();
ImageButton hoverNode;
Table infoTable = new Table();
@ -148,7 +137,7 @@ public class TechTreeDialog extends FloatingDialog{
if(mobile){
hoverNode = button;
rebuild();
}else if(data.hasItems(node.node.requirements) && locked(node)){
}else if(data.hasItems(node.node.requirements) && locked(node.node)){
unlock(node.node);
}
});
@ -170,31 +159,18 @@ public class TechTreeDialog extends FloatingDialog{
button.setSize(nodeSize, nodeSize);
button.update(() -> {
button.setPosition(node.x + panX + width/2f, node.y + panY + height/2f, Align.center);
button.getStyle().up = Core.scene.skin.getDrawable(!locked(node) ? "content-background" : "content-background-locked");
button.getStyle().up = Core.scene.skin.getDrawable(!locked(node.node) ? "content-background" : "content-background-locked");
((TextureRegionDrawable)button.getStyle().imageUp)
.setRegion(node.visible ? node.node.block.icon(Icon.medium) : Core.atlas.find("icon-tree-locked"));
button.getImage().setColor(!locked(node) ? Color.WHITE : Color.GRAY);
button.getImage().setColor(!locked(node.node) ? Color.WHITE : Color.GRAY);
});
addChild(button);
}
addListener(new InputListener(){
float lastX, lastY;
@Override
public void touchDragged(InputEvent event, float mx, float my, int pointer){
panX -= lastX - mx;
panY -= lastY - my;
lastX = mx;
lastY = my;
moved = true;
}
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){
lastX = x;
lastY = y;
return true;
}
dragged((x, y) -> {
moved = true;
panX += x;
panY += y;
});
}
@ -271,9 +247,9 @@ public class TechTreeDialog extends FloatingDialog{
public void draw(){
float offsetX = panX + width/2f + x, offsetY = panY + height/2f + y;
for(TreeNode node : nodes){
for(TreeNode child : node.children){
Lines.stroke(3f, locked(node) || locked(child) ? Palette.locked : Palette.accent);
for(TechTreeNode node : nodes){
for(TechTreeNode child : node.children){
Lines.stroke(3f, locked(node.node) || locked(child.node) ? Palette.locked : Palette.accent);
Lines.line(node.x + offsetX, node.y + offsetY, child.x + offsetX, child.y + offsetY);
}