Fixed some tech tree layout issues
This commit is contained in:
@@ -23,6 +23,17 @@ public class TechTree implements ContentList{
|
|||||||
map = new ObjectMap<>();
|
map = new ObjectMap<>();
|
||||||
all = new Seq<>();
|
all = new Seq<>();
|
||||||
|
|
||||||
|
root = node(coreShard, () -> {
|
||||||
|
node(Items.lead, () -> {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
node(Items.copper, () -> {
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if(false)
|
||||||
root = node(coreShard, () -> {
|
root = node(coreShard, () -> {
|
||||||
|
|
||||||
node(conveyor, () -> {
|
node(conveyor, () -> {
|
||||||
@@ -338,7 +349,7 @@ public class TechTree implements ContentList{
|
|||||||
/** Extra objectives needed to research this. TODO implement */
|
/** Extra objectives needed to research this. TODO implement */
|
||||||
public Objective[] objectives = {};
|
public Objective[] objectives = {};
|
||||||
/** Time required to research this content, in seconds. */
|
/** Time required to research this content, in seconds. */
|
||||||
public float time = 60; //TODO implement
|
public float time = 60;
|
||||||
/** Nodes that depend on this node. */
|
/** Nodes that depend on this node. */
|
||||||
public final Seq<TechNode> children = new Seq<>();
|
public final Seq<TechNode> children = new Seq<>();
|
||||||
/** Research progress, in seconds. */
|
/** Research progress, in seconds. */
|
||||||
|
|||||||
@@ -130,17 +130,25 @@ public class TechTreeDialog extends BaseDialog{
|
|||||||
LayoutNode[] children = node.children;
|
LayoutNode[] children = node.children;
|
||||||
LayoutNode[] leftHalf = Arrays.copyOfRange(node.children, 0, Mathf.ceil(node.children.length/2f));
|
LayoutNode[] leftHalf = Arrays.copyOfRange(node.children, 0, Mathf.ceil(node.children.length/2f));
|
||||||
LayoutNode[] rightHalf = Arrays.copyOfRange(node.children, Mathf.ceil(node.children.length/2f), node.children.length);
|
LayoutNode[] rightHalf = Arrays.copyOfRange(node.children, Mathf.ceil(node.children.length/2f), node.children.length);
|
||||||
|
|
||||||
node.children = leftHalf;
|
node.children = leftHalf;
|
||||||
new BranchTreeLayout(){{
|
new BranchTreeLayout(){{
|
||||||
gapBetweenLevels = gapBetweenNodes = spacing;
|
gapBetweenLevels = gapBetweenNodes = spacing;
|
||||||
rootLocation = TreeLocation.top;
|
rootLocation = TreeLocation.top;
|
||||||
}}.layout(node);
|
}}.layout(node);
|
||||||
node.children = rightHalf;
|
|
||||||
|
|
||||||
new BranchTreeLayout(){{
|
float lastY = node.y;
|
||||||
gapBetweenLevels = gapBetweenNodes = spacing;
|
|
||||||
rootLocation = TreeLocation.bottom;
|
if(rightHalf.length > 0){
|
||||||
}}.layout(node);
|
|
||||||
|
node.children = rightHalf;
|
||||||
|
new BranchTreeLayout(){{
|
||||||
|
gapBetweenLevels = gapBetweenNodes = spacing;
|
||||||
|
rootLocation = TreeLocation.bottom;
|
||||||
|
}}.layout(node);
|
||||||
|
|
||||||
|
shift(leftHalf, node.y - lastY);
|
||||||
|
}
|
||||||
|
|
||||||
node.children = children;
|
node.children = children;
|
||||||
|
|
||||||
@@ -158,6 +166,13 @@ public class TechTreeDialog extends BaseDialog{
|
|||||||
bounds.y += nodeSize*1.5f;
|
bounds.y += nodeSize*1.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void shift(LayoutNode[] children, float amount){
|
||||||
|
for(LayoutNode node : children){
|
||||||
|
node.y += amount;
|
||||||
|
if(node.children != null && node.children.length > 0) shift(node.children, amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void copyInfo(LayoutNode node){
|
void copyInfo(LayoutNode node){
|
||||||
node.node.x = node.x;
|
node.node.x = node.x;
|
||||||
node.node.y = node.y;
|
node.node.y = node.y;
|
||||||
|
|||||||
@@ -229,8 +229,7 @@ public class BranchTreeLayout implements TreeLayout{
|
|||||||
TreeNode previousChild = null;
|
TreeNode previousChild = null;
|
||||||
for(TreeNode w : v.children){
|
for(TreeNode w : v.children){
|
||||||
firstWalk(w, previousChild);
|
firstWalk(w, previousChild);
|
||||||
defaultAncestor = apportion(w, defaultAncestor, previousChild,
|
defaultAncestor = apportion(w, defaultAncestor, previousChild, v);
|
||||||
v);
|
|
||||||
previousChild = w;
|
previousChild = w;
|
||||||
}
|
}
|
||||||
executeShifts(v);
|
executeShifts(v);
|
||||||
@@ -257,8 +256,7 @@ public class BranchTreeLayout implements TreeLayout{
|
|||||||
}else if(alignment == TreeAlignment.towardsRoot){
|
}else if(alignment == TreeAlignment.towardsRoot){
|
||||||
y = levelStart + levelChangeSign * (getNodeThickness(v) / 2);
|
y = levelStart + levelChangeSign * (getNodeThickness(v) / 2);
|
||||||
}else{
|
}else{
|
||||||
y = levelStart + levelSize - levelChangeSign
|
y = levelStart + levelSize - levelChangeSign * (getNodeThickness(v) / 2);
|
||||||
* (getNodeThickness(v) / 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!levelChangeOnYAxis){
|
if(!levelChangeOnYAxis){
|
||||||
|
|||||||
Reference in New Issue
Block a user