com.badlogic.gdx.scenes.scene2d.ui.Tree.Node Java Examples

The following examples show how to use com.badlogic.gdx.scenes.scene2d.ui.Tree.Node. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MPQViewer.java    From riiablo with Apache License 2.0 6 votes vote down vote up
private void treeify(Trie<String, Node> nodes, Node root, String path) {
  Node parent = root;
  String[] parts = path.split("\\\\");
  StringBuilder builder = new StringBuilder(path.length());
  for (String part : parts) {
    if (part.isEmpty()) {
      break;
    }

    builder.append(part).append("\\");
    String partPath = builder.toString();
    Node node = nodes.get(partPath);
    if (node == null) {
      node = new BaseNode(new VisLabel(part));
      nodes.put(partPath, node);
      parent.add(node);
    }

    parent = node;
  }
}
 
Example #2
Source File: DialogSceneComposerJavaBuilder.java    From skin-composer with MIT License 5 votes vote down vote up
private static TypeSpec basicNodeType() {
    return TypeSpec.classBuilder("BasicNode")
            .superclass(Node.class)
            .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
            .addMethod(MethodSpec.constructorBuilder()
                    .addModifiers(Modifier.PUBLIC)
                    .addParameter(Actor.class, "actor")
                    .addStatement("super(actor)")
                    .build())
            .build();
}
 
Example #3
Source File: MPQViewer.java    From riiablo with Apache License 2.0 5 votes vote down vote up
private void sort(Node root) {
  if (root.getChildren().size == 0) {
    return;
  }

  root.getChildren().sort(new Comparator<Node>() {
    @Override
    public int compare(Node o1, Node o2) {
      boolean o1Empty = o1.getChildren().size == 0;
      boolean o2Empty = o2.getChildren().size == 0;
      if (!o1Empty && o2Empty) {
        return -1;
      } else if (o1Empty && !o2Empty) {
        return 1;
      }

      VisLabel l1 = (VisLabel) o1.getActor();
      VisLabel l2 = (VisLabel) o2.getActor();
      return StringUtils.compare(l1.getText().toString().toLowerCase(), l2.getText().toString().toLowerCase());
    }
  });

  root.updateChildren();
  for (Node child : (Array<Node>) root.getChildren()) {
    sort(child);
  }
}
 
Example #4
Source File: EditTree.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public Array<Node> getSiblings() {
	Selection<Node> selection = tree.getSelection();
	Node nodeSel = selection.first();
	
	int level = nodeSel.getLevel();
	Array<Node> siblings = (level == 1) ? tree.getRootNodes(): nodeSel.getParent().getChildren(); 
	
	return siblings;
}
 
Example #5
Source File: MPQViewer.java    From riiablo with Apache License 2.0 4 votes vote down vote up
private void readMPQs() {
  if (fileTreeNodes == null) {
    fileTreeNodes = new PatriciaTrie<>();
    fileTreeCofNodes = new PatriciaTrie<>();
  } else {
    fileTreeNodes.clear();
    fileTreeCofNodes.clear();
  }

  BufferedReader reader = null;
  try {
    //if (options_useExternalList.isChecked()) {
      reader = Gdx.files.internal(ASSETS + "(listfile)").reader(4096);
    //} else {
    //  try {
    //    reader = new BufferedReader(new InputStreamReader((new ByteArrayInputStream(mpq.readBytes("(listfile)")))));
    //  } catch (Throwable t) {
    //    reader = Gdx.files.internal(ASSETS + "(listfile)").reader(4096);
    //  }
    //}

    Node<Node, Object, Actor> root = new BaseNode(new VisLabel("root"));
    final boolean checkExisting = options_checkExisting.isChecked();

    String fileName;
    while ((fileName = reader.readLine()) != null) {
      if (checkExisting && !Riiablo.mpqs.contains(fileName)) {
        continue;
      }

      String path = FilenameUtils.getPathNoEndSeparator(fileName).toLowerCase();
      treeify(fileTreeNodes, root, path);

      final MPQFileHandle handle = (MPQFileHandle) Riiablo.mpqs.resolve(fileName);
      VisLabel label = new VisLabel(FilenameUtils.getName(fileName));
      final Node node = new BaseNode(label);
      node.setValue(handle);
      label.addListener(new ClickListener(Input.Buttons.RIGHT) {
        @Override
        public void clicked(InputEvent event, float x, float y) {
          showPopmenu(node, handle);
        }
      });

      String key = fileName.toLowerCase();
      fileTreeNodes.put(key, node);
      if (FilenameUtils.isExtension(key, "cof")) {
        key = FilenameUtils.getBaseName(key);
        fileTreeCofNodes.put(key, node);
      }
      if (path.isEmpty()) {
        root.add(node);
      } else {
        fileTreeNodes.get(path + "\\").add(node);
      }
    }

    sort(root);
    fileTree.clearChildren();
    for (Node child : root.getChildren()) {
      fileTree.add(child);
    }

    fileTree.layout();
    fileTreeFilter.clearText();
  } catch (IOException e) {
    throw new GdxRuntimeException("Failed to read list file.", e);
  } finally {
    StreamUtils.closeQuietly(reader);
  }
}
 
Example #6
Source File: BehaviorTreeViewer.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
private void fill (IntArray taskSteps, TaskNode taskNode) {
	taskSteps.add(taskNode.step);
	for (Node child : taskNode.getChildren()) {
		fill(taskSteps, (TaskNode)child);
	}
}