use of org.spongepowered.api.advancement.TreeLayoutElement in project SpongeCommon by SpongePowered.
the class AdvancementTest method onGenerateTreeLayout.
@Listener
public void onGenerateTreeLayout(AdvancementTreeEvent.GenerateLayout event) {
if (event.getTree() != this.advancementTree) {
return;
}
this.logger.info("Updating advancement tree layout...");
// Make the tree start at y 0, for every level within the tree
// The min y position mapped by the used x positions
// For example:
// |- y
// x -|- z
// |- w
// to
// x -|- y
// |- z
// |- w
final Map<Double, Double> values = new HashMap<>();
for (TreeLayoutElement element : event.getLayout().getElements()) {
final Vector2d pos = element.getPosition();
if (!values.containsKey(pos.getX()) || pos.getY() < values.get(pos.getX())) {
values.put(pos.getX(), pos.getY());
}
}
for (TreeLayoutElement element : event.getLayout().getElements()) {
final Vector2d pos = element.getPosition();
element.setPosition(pos.getX(), pos.getY() - values.get(pos.getX()));
}
/*
// Rotate the advancement tree
// The lines are currently drawn wrongly, that might be something
// for later as it involves "tricking" the client
double maxY = 0;
for (TreeLayoutElement element : event.getLayout().getElements()) {
maxY = Math.max(maxY, element.getPosition().getY());
}
for (TreeLayoutElement element : event.getLayout().getElements()) {
final Vector2d pos = element.getPosition();
element.setPosition(maxY - pos.getY(), pos.getX());
}
*/
}
use of org.spongepowered.api.advancement.TreeLayoutElement in project LanternServer by LanternPowered.
the class LanternPlayerAdvancements method createAdvancement.
@SuppressWarnings("ConstantConditions")
private static MessagePlayOutAdvancements.AdvStruct createAdvancement(Locale locale, Advancement advancement) {
final String parentId = advancement.getParent().map(Advancement::getId).orElse(null);
final String background = parentId == null ? advancement.getTree().get().getBackgroundPath() : null;
final DisplayInfo displayInfo = advancement.getDisplayInfo().orElse(null);
final TreeLayoutElement layoutElement = ((LanternAdvancement) advancement).getLayoutElement();
final String[][] criteriaRequirements = ((LanternAdvancement) advancement).clientCriteria.getSecond();
final Set<String> criteria = new HashSet<>();
for (String[] array : criteriaRequirements) {
Collections.addAll(criteria, array);
}
return new MessagePlayOutAdvancements.AdvStruct(advancement.getId(), parentId, displayInfo == null ? null : createDisplay(locale, displayInfo, layoutElement, background), criteria, criteriaRequirements);
}
use of org.spongepowered.api.advancement.TreeLayoutElement in project LanternServer by LanternPowered.
the class AdvancementTest method onGenerateTreeLayout.
@Listener
public void onGenerateTreeLayout(AdvancementTreeEvent.GenerateLayout event) {
if (event.getTree() != this.advancementTree) {
return;
}
this.logger.info("Updating advancement tree layout...");
// Make the tree start at y 0, for every level within the tree
// The min y position mapped by the used x positions
// For example:
// |- y
// x -|- z
// |- w
// to
// x -|- y
// |- z
// |- w
final Map<Double, Double> values = new HashMap<>();
for (TreeLayoutElement element : event.getLayout().getElements()) {
final Vector2d pos = element.getPosition();
if (!values.containsKey(pos.getX()) || pos.getY() < values.get(pos.getX())) {
values.put(pos.getX(), pos.getY());
}
}
for (TreeLayoutElement element : event.getLayout().getElements()) {
final Vector2d pos = element.getPosition();
element.setPosition(pos.getX(), pos.getY() - values.get(pos.getX()));
}
/*
// Rotate the advancement tree
// The lines are currently drawn wrongly, that might be something
// for later as it involves "tricking" the client
double maxY = 0;
for (TreeLayoutElement element : event.getLayout().getElements()) {
maxY = Math.max(maxY, element.getPosition().getY());
}
for (TreeLayoutElement element : event.getLayout().getElements()) {
final Vector2d pos = element.getPosition();
element.setPosition(maxY - pos.getY(), pos.getX());
}
*/
}
use of org.spongepowered.api.advancement.TreeLayoutElement in project LanternServer by LanternPowered.
the class LanternTreeLayout method generateNode.
private static TreeNode generateNode(Advancement advancement, TreeLayoutElement element, int column) {
final TreeNode treeNode = new TreeNode(element, (double) column * HORIZONTAL_OFFSET);
TreeNode previous = null;
for (Advancement child : advancement.getChildren()) {
final TreeLayoutElement childElement = ((LanternAdvancement) child).getLayoutElement();
if (childElement != null) {
final TreeNode childNode = generateNode(child, childElement, column + 1);
childNode.previous = previous;
childNode.parent = treeNode;
if (previous != null) {
previous.next = childNode;
}
treeNode.children.add(childNode);
previous = childNode;
}
}
return treeNode;
}
Aggregations