Incomplete zone layout
This commit is contained in:
@@ -292,12 +292,12 @@ public class TreeLayout{
|
|||||||
center, towardsRoot, awayFromRoot
|
center, towardsRoot, awayFromRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TreeNode{
|
public static class TreeNode<T extends TreeNode>{
|
||||||
public float width, height, x, y;
|
public float width, height, x, y;
|
||||||
|
|
||||||
//should be initialized by user
|
//should be initialized by user
|
||||||
public TreeNode[] children;
|
public T[] children;
|
||||||
public TreeNode parent;
|
public T parent;
|
||||||
|
|
||||||
private float mode, prelim, change, shift;
|
private float mode, prelim, change, shift;
|
||||||
private int number = -1;
|
private int number = -1;
|
||||||
|
|||||||
@@ -1,11 +1,23 @@
|
|||||||
package io.anuke.mindustry.ui.dialogs;
|
package io.anuke.mindustry.ui.dialogs;
|
||||||
|
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.collection.ObjectIntMap;
|
import io.anuke.arc.collection.ObjectIntMap;
|
||||||
|
import io.anuke.arc.collection.ObjectSet;
|
||||||
import io.anuke.arc.graphics.Color;
|
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.ScrollPane;
|
||||||
import io.anuke.arc.scene.ui.TextButton;
|
import io.anuke.arc.scene.ui.TextButton;
|
||||||
import io.anuke.arc.scene.ui.layout.Table;
|
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.core.GameState.State;
|
||||||
import io.anuke.mindustry.game.Saves.SaveSlot;
|
import io.anuke.mindustry.game.Saves.SaveSlot;
|
||||||
import io.anuke.mindustry.io.SaveIO.SaveException;
|
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.ItemStack;
|
||||||
import io.anuke.mindustry.type.ItemType;
|
import io.anuke.mindustry.type.ItemType;
|
||||||
import io.anuke.mindustry.type.Zone;
|
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;
|
||||||
import io.anuke.mindustry.world.Block.Icon;
|
import io.anuke.mindustry.world.Block.Icon;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
public class DeployDialog extends FloatingDialog{
|
public class DeployDialog extends FloatingDialog{
|
||||||
|
private static final float nodeSize = 250f;
|
||||||
|
private ZoneNode root;
|
||||||
|
private ObjectSet<ZoneNode> nodes = new ObjectSet<>();
|
||||||
|
|
||||||
public DeployDialog(){
|
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);
|
shown(this::setup);
|
||||||
}
|
}
|
||||||
@@ -204,6 +232,11 @@ public class DeployDialog extends FloatingDialog{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawBackground(float x, float y){
|
||||||
|
drawDefaultBackground(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
boolean canUnlock(Zone zone){
|
boolean canUnlock(Zone zone){
|
||||||
if(data.isUnlocked(zone)){
|
if(data.isUnlocked(zone)){
|
||||||
return true;
|
return true;
|
||||||
@@ -223,4 +256,50 @@ public class DeployDialog extends FloatingDialog{
|
|||||||
|
|
||||||
return data.hasItems(zone.itemRequirements);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,10 @@ import io.anuke.arc.collection.Array;
|
|||||||
import io.anuke.arc.collection.ObjectSet;
|
import io.anuke.arc.collection.ObjectSet;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Lines;
|
import io.anuke.arc.graphics.g2d.Lines;
|
||||||
import io.anuke.arc.input.KeyCode;
|
|
||||||
import io.anuke.arc.math.Interpolation;
|
import io.anuke.arc.math.Interpolation;
|
||||||
import io.anuke.arc.math.geom.Rectangle;
|
|
||||||
import io.anuke.arc.scene.Element;
|
import io.anuke.arc.scene.Element;
|
||||||
import io.anuke.arc.scene.Group;
|
import io.anuke.arc.scene.Group;
|
||||||
import io.anuke.arc.scene.actions.Actions;
|
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.event.Touchable;
|
||||||
import io.anuke.arc.scene.style.TextureRegionDrawable;
|
import io.anuke.arc.scene.style.TextureRegionDrawable;
|
||||||
import io.anuke.arc.scene.ui.ImageButton;
|
import io.anuke.arc.scene.ui.ImageButton;
|
||||||
@@ -39,13 +35,12 @@ public class TechTreeDialog extends FloatingDialog{
|
|||||||
public TechTreeDialog(){
|
public TechTreeDialog(){
|
||||||
super("");
|
super("");
|
||||||
|
|
||||||
cont.setFillParent(true);
|
|
||||||
|
|
||||||
TreeLayout layout = new TreeLayout();
|
TreeLayout layout = new TreeLayout();
|
||||||
layout.gapBetweenLevels = 60f;
|
layout.gapBetweenLevels = 60f;
|
||||||
layout.gapBetweenNodes = 40f;
|
layout.gapBetweenNodes = 40f;
|
||||||
layout.layout(root);
|
layout.layout(root);
|
||||||
|
|
||||||
|
cont.setFillParent(true);
|
||||||
cont.add(new View()).grow();
|
cont.add(new View()).grow();
|
||||||
|
|
||||||
{ //debug code; TODO remove
|
{ //debug code; TODO remove
|
||||||
@@ -74,10 +69,9 @@ public class TechTreeDialog extends FloatingDialog{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void checkNodes(TechTreeNode node){
|
void checkNodes(TechTreeNode node){
|
||||||
boolean locked = locked(node);
|
boolean locked = locked(node.node);
|
||||||
if(!locked) node.visible = true;
|
if(!locked) node.visible = true;
|
||||||
for(TreeNode child : node.children){
|
for(TechTreeNode l : node.children){
|
||||||
TechTreeNode l = (TechTreeNode)child;
|
|
||||||
l.visible = !locked && l.node.block.isVisible();
|
l.visible = !locked && l.node.block.isVisible();
|
||||||
checkNodes(l);
|
checkNodes(l);
|
||||||
}
|
}
|
||||||
@@ -106,19 +100,15 @@ public class TechTreeDialog extends FloatingDialog{
|
|||||||
Core.scene.add(table);
|
Core.scene.add(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean locked(TreeNode node){
|
|
||||||
return locked(((TechTreeNode)node).node);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean locked(TechNode node){
|
boolean locked(TechNode node){
|
||||||
return !data.isUnlocked(node.block);
|
return !data.isUnlocked(node.block);
|
||||||
}
|
}
|
||||||
|
|
||||||
class TechTreeNode extends TreeNode{
|
class TechTreeNode extends TreeNode<TechTreeNode>{
|
||||||
final TechNode node;
|
final TechNode node;
|
||||||
boolean visible = true;
|
boolean visible = true;
|
||||||
|
|
||||||
public TechTreeNode(TechNode node, TreeNode parent){
|
TechTreeNode(TechNode node, TechTreeNode parent){
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.width = this.height = nodeSize;
|
this.width = this.height = nodeSize;
|
||||||
@@ -135,7 +125,6 @@ public class TechTreeDialog extends FloatingDialog{
|
|||||||
class View extends Group{
|
class View extends Group{
|
||||||
float panX = 0, panY = -200;
|
float panX = 0, panY = -200;
|
||||||
boolean moved = false;
|
boolean moved = false;
|
||||||
Rectangle clip = new Rectangle();
|
|
||||||
ImageButton hoverNode;
|
ImageButton hoverNode;
|
||||||
Table infoTable = new Table();
|
Table infoTable = new Table();
|
||||||
|
|
||||||
@@ -148,7 +137,7 @@ public class TechTreeDialog extends FloatingDialog{
|
|||||||
if(mobile){
|
if(mobile){
|
||||||
hoverNode = button;
|
hoverNode = button;
|
||||||
rebuild();
|
rebuild();
|
||||||
}else if(data.hasItems(node.node.requirements) && locked(node)){
|
}else if(data.hasItems(node.node.requirements) && locked(node.node)){
|
||||||
unlock(node.node);
|
unlock(node.node);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -170,31 +159,18 @@ public class TechTreeDialog extends FloatingDialog{
|
|||||||
button.setSize(nodeSize, nodeSize);
|
button.setSize(nodeSize, nodeSize);
|
||||||
button.update(() -> {
|
button.update(() -> {
|
||||||
button.setPosition(node.x + panX + width/2f, node.y + panY + height/2f, Align.center);
|
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)
|
((TextureRegionDrawable)button.getStyle().imageUp)
|
||||||
.setRegion(node.visible ? node.node.block.icon(Icon.medium) : Core.atlas.find("icon-tree-locked"));
|
.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);
|
addChild(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
addListener(new InputListener(){
|
dragged((x, y) -> {
|
||||||
float lastX, lastY;
|
moved = true;
|
||||||
@Override
|
panX += x;
|
||||||
public void touchDragged(InputEvent event, float mx, float my, int pointer){
|
panY += y;
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,9 +247,9 @@ public class TechTreeDialog extends FloatingDialog{
|
|||||||
public void draw(){
|
public void draw(){
|
||||||
float offsetX = panX + width/2f + x, offsetY = panY + height/2f + y;
|
float offsetX = panX + width/2f + x, offsetY = panY + height/2f + y;
|
||||||
|
|
||||||
for(TreeNode node : nodes){
|
for(TechTreeNode node : nodes){
|
||||||
for(TreeNode child : node.children){
|
for(TechTreeNode child : node.children){
|
||||||
Lines.stroke(3f, locked(node) || locked(child) ? Palette.locked : Palette.accent);
|
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);
|
Lines.line(node.x + offsetX, node.y + offsetY, child.x + offsetX, child.y + offsetY);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user