Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeItem add move up/down function #30116

Open
TheDuriel opened this issue Jun 27, 2019 · 9 comments
Open

TreeItem add move up/down function #30116

TheDuriel opened this issue Jun 27, 2019 · 9 comments

Comments

@TheDuriel
Copy link
Contributor

Godot version:

3.1

Issue description:

Right now TreeItem implements move_to_top() and move_to_bottom() to move the item to the first or last position among its siblings.

I would like the ability to move an Item by an arbitrary amount. I am currently building a modding system ala skyrim, and need to ability to move tree items to arbitrary positions in the list.

@akien-mga
Copy link
Member

Makes sense, though I'm not sure if that can be added to TreeItem itself, I guess it would have to be a method of Tree? E.g. Tree.move_item(int p_item, int p_new_position). Or maybe it is possible in TreeItem, with something like TreeItem.move_up/down(int p_amount), as long as it's able to gracefully handle out of bound moves (e.g. you're moving TreeItem idx 3 up by 6, it should become the first item (0) as if you only moved it by 3).

@TheDuriel
Copy link
Contributor Author

Either way is fine with me <3

@Anutrix
Copy link
Contributor

Anutrix commented Jun 27, 2019

Any comments on which one of these is better? Polls on github would be nice.

Makes sense, though I'm not sure if that can be added to TreeItem itself, I guess it would have to be a method of Tree? E.g. Tree.move_item(int p_item, int p_new_position). Or maybe it is possible in TreeItem, with something like TreeItem.move_up/down(int p_amount), as long as it's able to gracefully handle out of bound moves (e.g. you're moving TreeItem idx 3 up by 6, it should become the first item (0) as if you only moved it by 3).

@akien-mga
Copy link
Member

Well it's not a matter of polling, but of checking the actual implementations of Tree, TreeItem and their interactions, to see what is possible / makes sense given their design.

The Tree/TreeItem APIs are a bit peculiar, and it seems item management mainly goes through TreeItem (where a TreeItem can give you a reference to its previous or next TreeItem in the parent Tree), so I suppose that's where the move methods would have to go, even if it stays a slightly unintuitive API.

But again I haven't checked the code, those are just some comments to point interested contributors in possible directions :)

@girng
Copy link

girng commented Jun 28, 2019

forgive me if i am mistaken, but since the node scene list in the editor lets you drag to any position, this should be possible already?

@TheDuriel
Copy link
Contributor Author

@girng
The editor implementation is not as straightforward. The entire drag and drop system for it is a custom implementation. Remember that it actually modifies a Scene Tree, the dock simply displays it after a change happens. This works because the tree structure itself is not actually managed using the Tree class.

https://github.com/godotengine/godot/blob/master/editor/scene_tree_dock.cpp

@girng
Copy link

girng commented Jun 28, 2019

@TheDuriel interesting, TIL. nvm my prev comment then :p. ty

@marzecdawid
Copy link
Contributor

Is it still valid proposal after #46773?
TreeItem.move_up/down(int p_amount) may still be more practical in some cases than move_before/after.

@TheDuriel
Copy link
Contributor Author

I think that #46773 functionally solves this, though it's very awkward.

Say you want to move a node one down in the tree:

self.move_after(self.get_next())

And move it two up.

for i in 2:
    self.move_before(self)

A dedicated move_up(x) move_down(x) and raise() would be preferable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants