Aller au contenu

Photo

Add/ModifyListBoxRow


  • Veuillez vous connecter pour répondre
9 réponses à ce sujet

#1
MasterChanger

MasterChanger
  • Members
  • 686 messages
Does anyone have some information on how to use these functions to dynamically add controls to a listbox? For example, if I'd like to add a certain number of buttons based on variables stored on a PC (spell indices, say), how would I actually implement that?

I've looked at the code for both functions but I'm left less than completely enlightened.

#2
MasterChanger

MasterChanger
  • Members
  • 686 messages
Through looking through some XML's and their associated scripts in the Tome of Battle, and looking at OEI's quickspell.xml, I think I've figured some stuff out. Basically, if the element contained by the UIListBox has prototype=true, then you can AddListBoxRow to the ListBox and it will keep the same events and everything as the prototype row.

What I'm trying to do is be able to have multiple textures per row, and be able to distinguish which ones was clicked on. If I can get the position of the cursor within the row (maybe as 0100010 mentions?) I should be able to figure out which member of the row the user clicks on.

My end-goal, by the way, is a replacement for the Quickspell GUI for a custom magic environment.

#3
MasterChanger

MasterChanger
  • Members
  • 686 messages
For some reason this didn't quickly show up in generic Google searches, but Sunjammer has a Dynamic UIListbox Guide! :D

#4
The Fred

The Fred
  • Members
  • 2 516 messages
The listbox functions are especially useful - they're what I used for my resting GUI, amongst other things. You needn't use the mouse cursor to find which one was clicked, as you can set a local variable on each row and then have it be returned to a script when that row is selected. Or, you can in fact just send the currently selected row to a script when a button is pressed, I believe.



The tutorial you linked to is fairly old, but if I recall, pretty good (I don't think much has changed since v1.13 or whatever it was). Another good source is Rich Taylor's blog - he talks about listbox callbacks and functions on there.

#5
MasterChanger

MasterChanger
  • Members
  • 686 messages

The Fred wrote...

The listbox functions are especially useful - they're what I used for my resting GUI, amongst other things. You needn't use the mouse cursor to find which one was clicked, as you can set a local variable on each row and then have it be returned to a script when that row is selected. Or, you can in fact just send the currently selected row to a script when a button is pressed, I believe.


Yes, I learned from the tutorial that if you set selectonleftclick=true in the listbox, you can use listboxrow:[Name of your listbox] in function calls such as ExecuteServerScript or ExtractData.

The tutorial you linked to is fairly old, but if I recall, pretty good (I don't think much has changed since v1.13 or whatever it was). Another good source is Rich Taylor's blog - he talks about listbox callbacks and functions on there.


Yes, I've been going through that blog extensively. It's a very good reference, though it doesn't explain everything and it's better if you already know what you're looking for. I was remiss in not linking it here; a big part of why I'm continuing to post even if I'm answering my own questions is to potentially help people down the line.

So I'll also note some of my experience with trying to use ListBoxes to build 2d image arrays, since none of the examples I've seen explicitly deal with this. What I've found is that it's quite easy to add or modify rows based on the prototype one sets in the .XML, and you can tell which row has been clicked on or extract other data as we discussed above. However, you can't easily add columns (at least I haven't figured out how).

So, this means that if you have one dimension that's dynamic and one that's static and has a discrete order, it makes sense to make your dynamic stuff vertical and the static info horizontal. I learned the trick of making each column a listbox one button wide from Drammel's Quick-strike menu.

#6
The Fred

The Fred
  • Members
  • 2 516 messages
Yes, I think you would have to make a static number of columns. However, because you can place rows in each dynamically, you would be able to have a custom grid however you'd like, so long as it didn't need to be widened or narrowed.



That said, depending on what you want to do, you could just create a grid object and handle each element individually. Through script you'd be able to set each square to have its own texture etc. The drawback of this is that if you want a large number of rows, you will have to hand-create the XML file rather than being able to use an NWScript loop (though I guess you might be able to use Excell or write a little program or something).

#7
MasterChanger

MasterChanger
  • Members
  • 686 messages

The Fred wrote...

That said, depending on what you want to do, you could just create a grid object and handle each element individually. Through script you'd be able to set each square to have its own texture etc. The drawback of this is that if you want a large number of rows, you will have to hand-create the XML file rather than being able to use an NWScript loop (though I guess you might be able to use Excell or write a little program or something).


Well, the grid won't work for the bit I'm working on, but I may want to use it for other aspects. I couldn't find any nwscript functions for UIGrid, though. I suspect they use prototypes as well...

#8
The Fred

The Fred
  • Members
  • 2 516 messages
You wouldn't be able to dynamically populate a grid, but if you just made object for every square, you'd be able to set each one's texture etc through script. This would probably be quite a bit more work, though, since if you had a grid of, say, 10x10, you'd need 100 objects. Creating 10 listboxes would probably be easier.

#9
Sunjammer

Sunjammer
  • Members
  • 925 messages
Oops: I posted a link to my guide and only then noticed you'd already found it.

Modifié par Sunjammer, 27 janvier 2011 - 01:43 .


#10
MasterChanger

MasterChanger
  • Members
  • 686 messages

Sunjammer wrote...

Oops: I posted a link to my guide and only then noticed you'd already found it.


Thanks, Sunjammer. That guide was exactly what I needed!