jonSS ItemList is just a gui widget, not a data storage. Items cannot hold references to any data other than their displayed strings and an item associated metadata. If the list is meant to represent some other separate data structure, you'll need to manage that connection manually. So if you want to change the order of items in an ItemList as well as in some data structure (array or dictionary) that the list represents, you'll need to do it on both things.
How to get all items in an item list ?
- Edited
the editor plugIN
loads an instance and the EditorInspectorPlugin and creates a costum node
@tool
extends EditorPlugin
const menuScene = preload("res://menu/menu.tscn");
const tileDrawNode = preload("res://test3/tileDrawNode.gd");
const tileDrawIcon = preload("res://test3/icon.png");
#---------//---inspector---//---------
var tlDrawInspector = preload("res://addons/tiledrawtest2/tileDrawInspector.gd");
func _enter_tree():
add_custom_type("TileDraw", "Node2D", tileDrawNode, tileDrawIcon );
dockedScene = menuScene.instantiate();
add_control_to_container(CONTAINER_CANVAS_EDITOR_SIDE_RIGHT, dockedScene );
dockedScene.custom_minimum_size = Vector2(10,0);
tlDrawInspector = tlDrawInspector.new();
tlDrawInspector.PlugInDockedScene = dockedScene;
add_inspector_plugin(tlDrawInspector);
var TileDrawNode;
func _handles(object: Object) -> bool:
#return object is tileDrawNode
if ( object is tileDrawNode ):
TileDrawNode = object;
return true
return false
the costum node 'tileDrawNode' draws all of this stuff in engine editor screen
@tool
extends Node2D
class_name tileDrawX1;
var layers = {
'Lnum': [ {} ]
}
for i in range(0, drawText.get_image().get_size().x,32 ):
for j in range(0, drawText.get_image().get_size().y, 32):
mouseGroup.Fnum.append( { "cords": Vector2(i, j), "img": ImageTexture.create_from_image(drawText.get_image().get_region( Rect2( i, j, 32, 32) ) ) } );
func _draw():
for p in range(0, layerMax ):
for i in layers.Lnum[p]:
if ( layers.Lnum[p].has(i) ):
draw_texture( layers.Lnum[p][i], i );
and the EditorInspectorPlugin adds a menu to the inspector with the itemList and other things
@tool
extends EditorInspectorPlugin
var itemLlist1;
func _can_handle(object):
if object is tileDrawX1:
PlugTileDrawNode = object;
return true
return false
func _parse_end(object):
itemLlist1 = ItemList.new();
itemLlist1.set_custom_minimum_size(Vector2(100, 90));
itemLlist1.set( "theme_override_styles/focus",StyleBoxEmpty.new() );
itemLlist1.select_mode = 1;
for n in 3:
itemLlist1.add_item(" layer " + str(n) );
itemLlist1.select(0, true);
var listSize = itemLlist1.get_item_count();
for n in range( listSize-1 ):
if ( PlugTileDrawNode.layers.Lnum.size() < listSize ):
PlugTileDrawNode.layers.Lnum.append( {} );
func btn_UpLayer_pressed(): # move layers UP
var listSize = itemLlist1.get_item_count();
PlugTileDrawNode.layerMax = listSize;
#PlugTileDrawNode.add_layers();
var itemListSize = itemLlist1.get_item_count();
var itemListSelectedItems = itemLlist1.get_selected_items();
for n in itemListSize:
if ( itemListSelectedItems.has(n) && n >= 1 ):
if ( itemListSelectedItems[0] != 0 ):
#itemLlist1.move_item(n, n - 1);
itemLlist1.move_item(itemListSelectedItems[0], n - 1);
var a1 = PlugTileDrawNode.layers.Lnum[n-1];
var a2 = PlugTileDrawNode.layers.Lnum[n];
PlugTileDrawNode.layers.Lnum[n] = a1;
PlugTileDrawNode.layers.Lnum[n-1] = a2;
This things cant communicate with one an other... I have to pass them on to the other using a var.
If i had an itemList on both sides the result would be the same
EditorInspectorPlugin, doesnt have proccess() nor ready() the user selects the options there...
And putting this layers.Lnum in an itemList i dont know if its possible, i dont know whats going on inside an itemList ?
I dont know if its an array or sometimes its already an array, drawing the list in the draw function could be possible i just dont know how.
- Edited
DaveTheCoder That's nonsense. Just treat ChatGPT as a very knowledgeable person who sometimes provides correct information and sometimes provides incorrect information. I.e., don't trust the information without confirming it.
The irony. You just said yourself that ChatGPT is redundant; Let's not check a reliable source immediately. Let's waste time with a chatbot and then check if what it blurted out is valid at that reliable source. Yeah, totally makes sense.
ChatGPT shouldn't be treated as a "very knowledgeable person". It should be treated like what it is - a statistical linguistic token sequencer.
xyz Yeah, totally makes sense.
If you're going to keep posting nonsense, at least keep it out of this kind of discussion so it doesn't confuse users who need help.
- Edited
DaveTheCoder If you're going to keep posting nonsense
You're not the "nonsense" police around here, Dave. If you proclaim something a nonsense, you'll have to provide some arguments that support that claim. An user cited faulty information gotten from ChatGPT. I said stay away from it. You said that's nonsense. How's what I said a nonsense in this context? The only nonsense here is what ChatGPT "said". And for some reason you proceeded to defend that source of faulty information. I'd really like to understand your motivations here.
- Edited
So the ItemList represents your layers array?
yes
but itemList only returns an array with get_selected_items()
if i could get all the items on itemlist without having them selected maybe it could use it with the array on the other side
[edit] in the func process() also on the other side since EditorInspectorPlugin doesnt have process(), but it leads to a lot of confusion i have buttons to add and remove (layers)
p.s. chatGPT creates a loop
- Edited
xyz
I wanted to get an array from itemList
and set the layers.Lnum array on the other side, to be equal to that array
The problem is i have buttons to move items up or down, and to add or remove items
I dont know how to make an array out of itemList without having to update it on all the buttons, and copy / paste all the layers multiple times, even if its possible it would be a waste to have 2 vars for each item... itemList would only function has a picture
- Edited
jonSS I wanted to get an array from itemList
An array of what? get_selected_items()
will simply return an array of integers containing the indices of selected list items. An array of all items in the list would be equivalent to what is returned by range(0, item_list.item_count)
. That's why I above said that this array is implicit. You always know/have this array.
DaveTheCoder You don't have to agree, but this was a bit uncalled for.
@xyz @DaveTheCoder
Let's stay focused on the OP and not turn this discussion into an argument.
MikeCL argument
Take that up with xyz. He's the who makes ignorant contents about ChatGPT every time someone mentions it. If you don't like my feedback, you're welcome to remove my account (and all my posts).
- Edited
An array of all items in the list would be equivalent to what is returned by range(0, item_list.item_count). That's why I above said that this array is implicit. You always know/have this array.
Ok great,
But how would i do to create this array from the itemList ?
var arr = itemlist1.range(0, item_list.item_count) ?
do the indexes also change in this array when moving layers up and down ?
I think godot cant move values in an array, iam not sure how its moving them in itemList
- Edited
MikeCL Let's stay focused on the OP and not turn this discussion into an argument.
Its fine by me ( sometimes its me being hammered by an admin ) noone is arguing chatGPT most of the times creates a loop mixes java with everthing ( iam no sure )...
but the answers and replies seem to run on a loop until you are forced to ask the same question again... but sometimes it gets it right