Initial support for arbitrary types of content in tech tree
This commit is contained in:
@@ -328,21 +328,29 @@ public class TechTree implements ContentList{
|
||||
});
|
||||
}
|
||||
|
||||
private static TechNode node(Block block, Runnable children){
|
||||
ItemStack[] requirements = new ItemStack[block.requirements.length];
|
||||
for(int i = 0; i < requirements.length; i++){
|
||||
requirements[i] = new ItemStack(block.requirements[i].item, 40 + Mathf.round(Mathf.pow(block.requirements[i].amount, 1.25f) * 6, 10));
|
||||
private static TechNode node(UnlockableContent content, Runnable children){
|
||||
ItemStack[] requirements;
|
||||
|
||||
if(content instanceof Block){
|
||||
Block block = (Block)content;
|
||||
|
||||
requirements = new ItemStack[block.requirements.length];
|
||||
for(int i = 0; i < requirements.length; i++){
|
||||
requirements[i] = new ItemStack(block.requirements[i].item, 40 + Mathf.round(Mathf.pow(block.requirements[i].amount, 1.25f) * 6, 10));
|
||||
}
|
||||
}else{
|
||||
requirements = ItemStack.empty;
|
||||
}
|
||||
|
||||
return new TechNode(block, requirements, children);
|
||||
return new TechNode(content, requirements, children);
|
||||
}
|
||||
|
||||
private static TechNode node(Block block){
|
||||
return node(block, () -> {});
|
||||
}
|
||||
|
||||
public static TechNode create(Block parent, Block block){
|
||||
TechNode.context = all.find(t -> t.block == parent);
|
||||
public static TechNode create(UnlockableContent parent, UnlockableContent block){
|
||||
TechNode.context = all.find(t -> t.content == parent);
|
||||
return node(block, () -> {});
|
||||
}
|
||||
|
||||
@@ -350,17 +358,17 @@ public class TechTree implements ContentList{
|
||||
static TechNode context;
|
||||
|
||||
public TechNode parent;
|
||||
public final Block block;
|
||||
public final UnlockableContent content;
|
||||
public final ItemStack[] requirements;
|
||||
public final Array<TechNode> children = new Array<>();
|
||||
|
||||
TechNode(TechNode ccontext, Block block, ItemStack[] requirements, Runnable children){
|
||||
TechNode(TechNode ccontext, UnlockableContent content, ItemStack[] requirements, Runnable children){
|
||||
if(ccontext != null){
|
||||
ccontext.children.add(this);
|
||||
}
|
||||
|
||||
this.parent = ccontext;
|
||||
this.block = block;
|
||||
this.content = content;
|
||||
this.requirements = requirements;
|
||||
|
||||
context = this;
|
||||
@@ -369,8 +377,8 @@ public class TechTree implements ContentList{
|
||||
all.add(this);
|
||||
}
|
||||
|
||||
TechNode(Block block, ItemStack[] requirements, Runnable children){
|
||||
this(context, block, requirements, children);
|
||||
TechNode(UnlockableContent content, ItemStack[] requirements, Runnable children){
|
||||
this(context, content, requirements, children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,8 +242,9 @@ public class ContentParser{
|
||||
|
||||
//add research tech node
|
||||
if(research[0] != null){
|
||||
//TODO only works with blocks
|
||||
Block parent = find(ContentType.block, research[0]);
|
||||
TechNode baseNode = exists && TechTree.all.contains(t -> t.block == block) ? TechTree.all.find(t -> t.block == block) : TechTree.create(parent, block);
|
||||
TechNode baseNode = exists && TechTree.all.contains(t -> t.content == block) ? TechTree.all.find(t -> t.content == block) : TechTree.create(parent, block);
|
||||
LoadedMod cur = currentMod;
|
||||
|
||||
postreads.add(() -> {
|
||||
@@ -254,7 +255,7 @@ public class ContentParser{
|
||||
baseNode.parent.children.remove(baseNode);
|
||||
}
|
||||
|
||||
TechNode parnode = TechTree.all.find(t -> t.block == parent);
|
||||
TechNode parnode = TechTree.all.find(t -> t.content == parent);
|
||||
if(parnode == null){
|
||||
throw new IllegalArgumentException("Block '" + parent.name + "' isn't in the tech tree, but '" + block.name + "' requires it to be researched.");
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ public class PlanetDialog extends FloatingDialog{
|
||||
Tmp.v31.set(selected.tile.v).rotate(Vec3.Y, -planet.getRotation()).scl(-1f).nor();
|
||||
float dot = cam.direction.dot(Tmp.v31);
|
||||
stable.getColor().a = Math.max(dot, 0f)*2f;
|
||||
if(stable.getColor().a <= 0.001f){
|
||||
if(dot*2f <= -0.1f){
|
||||
stable.remove();
|
||||
selected = null;
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public class TechTreeDialog extends FloatingDialog{
|
||||
}
|
||||
|
||||
boolean locked(TechNode node){
|
||||
return node.block.locked();
|
||||
return node.content.locked();
|
||||
}
|
||||
|
||||
class LayoutNode extends TreeNode<LayoutNode>{
|
||||
@@ -224,7 +224,7 @@ public class TechTreeDialog extends FloatingDialog{
|
||||
infoTable.touchable(Touchable.enabled);
|
||||
|
||||
for(TechTreeNode node : nodes){
|
||||
ImageButton button = new ImageButton(node.node.block.icon(Cicon.medium), Styles.nodei);
|
||||
ImageButton button = new ImageButton(node.node.content.icon(Cicon.medium), Styles.nodei);
|
||||
button.visible(() -> node.visible);
|
||||
button.clicked(() -> {
|
||||
if(moved) return;
|
||||
@@ -271,7 +271,7 @@ public class TechTreeDialog extends FloatingDialog{
|
||||
button.setPosition(node.x + panX + width / 2f, node.y + panY + height / 2f + offset, Align.center);
|
||||
button.getStyle().up = !locked(node.node) ? Tex.buttonOver : !data.hasItems(node.node.requirements) ? Tex.buttonRed : Tex.button;
|
||||
((TextureRegionDrawable)button.getStyle().imageUp)
|
||||
.setRegion(node.visible ? node.node.block.icon(Cicon.medium) : Icon.lock.getRegion());
|
||||
.setRegion(node.visible ? node.node.content.icon(Cicon.medium) : Icon.lock.getRegion());
|
||||
button.getImage().setColor(!locked(node.node) ? Color.white : Color.gray);
|
||||
});
|
||||
addChild(button);
|
||||
@@ -305,16 +305,16 @@ public class TechTreeDialog extends FloatingDialog{
|
||||
}
|
||||
|
||||
void unlock(TechNode node){
|
||||
data.unlockContent(node.block);
|
||||
data.unlockContent(node.content);
|
||||
data.removeItems(node.requirements);
|
||||
showToast(Core.bundle.format("researched", node.block.localizedName));
|
||||
showToast(Core.bundle.format("researched", node.content.localizedName));
|
||||
checkNodes(root);
|
||||
hoverNode = null;
|
||||
treeLayout();
|
||||
rebuild();
|
||||
Core.scene.act();
|
||||
Sounds.unlock.play();
|
||||
Events.fire(new ResearchEvent(node.block));
|
||||
Events.fire(new ResearchEvent(node.content));
|
||||
}
|
||||
|
||||
void rebuild(){
|
||||
@@ -343,11 +343,11 @@ public class TechTreeDialog extends FloatingDialog{
|
||||
infoTable.table(b -> {
|
||||
b.margin(0).left().defaults().left();
|
||||
|
||||
b.button(Icon.info, Styles.cleari, () -> ui.content.show(node.block)).growY().width(50f);
|
||||
b.button(Icon.info, Styles.cleari, () -> ui.content.show(node.content)).growY().width(50f);
|
||||
b.add().grow();
|
||||
b.table(desc -> {
|
||||
desc.left().defaults().left();
|
||||
desc.add(node.block.localizedName);
|
||||
desc.add(node.content.localizedName);
|
||||
desc.row();
|
||||
if(locked(node)){
|
||||
desc.table(t -> {
|
||||
@@ -376,8 +376,8 @@ public class TechTreeDialog extends FloatingDialog{
|
||||
});
|
||||
|
||||
infoTable.row();
|
||||
if(node.block.description != null){
|
||||
infoTable.table(t -> t.margin(3f).left().labelWrap(node.block.displayDescription()).color(Color.lightGray).growX()).fillX();
|
||||
if(node.content.description != null){
|
||||
infoTable.table(t -> t.margin(3f).left().labelWrap(node.content.displayDescription()).color(Color.lightGray).growX()).fillX();
|
||||
}
|
||||
|
||||
addChild(infoTable);
|
||||
|
||||
Reference in New Issue
Block a user