Godot: TreeItem add move up/down function

Created on 27 Jun 2019  路  7Comments  路  Source: godotengine/godot

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.

enhancement gui

Most helpful comment

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).

All 7 comments

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).

Either way is fine with me <3

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).

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 :)

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?

@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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SleepProgger picture SleepProgger  路  3Comments

kirilledelman picture kirilledelman  路  3Comments

n-pigeon picture n-pigeon  路  3Comments

testman42 picture testman42  路  3Comments

mefihl picture mefihl  路  3Comments