Jump to content
Sign in to follow this  
LOzan

Need Help Disabling Drag and Drop in GUI Listbox

Recommended Posts

Hello all,

I got some fantastic help for my last dialog question so I figured I'd ask another that I have. I have a dialog with several Listboxes for assembling squads of units and I am using drag and drop to simplify the deal so there aren't tons of buttons for moving troops around. The problem is that I want to impose a limit on how big a squad can get to force the player to make compromises in their squad lineups. So far, I have no problem seeing how the canDrag = 1 line in the dialogs.hpp works but as far as I can tell it can't be disabled through a script. Is there any way to disable the dragging operation when the list has a certain number of units in it?

Thanks,

LOzan

EDIT: Another possibility I just thought of but would still be outside my current GUI skill level, I could cap the list length by using the OnLBDrag and OnLBDrop event handlers and check the list's length; if it is already at maximum capacity, I could return the dragged entry to its original position. Actually I realized that this would have to be the way to do it because disabling the drag operation for the entire listbox would mean entries can't be dragged out of it to open up space. Any thoughts?

Edited by LOzan

Share this post


Link to post
Share on other sites
I could cap the list length by using the OnLBDrag and OnLBDrop event handlers and check the list's length; if it is already at maximum capacity, I could return the dragged entry to its original position.

This is exactly what I would do if I was in this situation. Try these functions:

//It is assumed that data has been saved to each listbox element to indicate what it is.
//ASSUMED DATA: " ["Element Title", (Number) Original Control, (Number) Original Index, "Other data"] "

listboxDrag =
{
#define GRAY_COLOR [1,1,1,0.5]

_this select 0; //LB control
_this select 1; //LB index

lbSetColor [_this select 0, _this select 1, GRAY_COLOR]; //makes the dragged element gray
dialogTemp = call compile (lbData [_this select 0, _this select 1]); //it is assumed that you have some data saved to the entry

};

listboxDrop =
{
#define ORIGINAL_COLOR [1,1,1,1] //Generic color of opaque white, change as neccessary
#define MAX_UNITS 20 //Generic number of 20 units

_this select 0; //LB control

if (lbSize (_this select 0) < MAX_UNITS) then
{
	lbDelete [dialogTemp select 1, dialogTemp select 2]; //delete old element from old listbox
	_index = lbAdd [_this select 0, dialogTemp select 0]; //add new element in new listbox and save index number into memory

	lbSetData [_this select 0, _index, str [dialogTemp select 0, _this select 0, _index, dialogTemp select 3]];
	//re-set old data to the new element in the new listbox but update new control and new index number
}else
{
	lbSetColor [dialogTemp select 1, dialogTemp select 2, ORIGINAL_COLOR]; //Since the operation failed, change the color back to the original
};
};

This was an awesome exercise, so thank you for that, I only wish I had an immediate use for it.

EDIT: Forgot to tell you how to use them:

onLBDrag = "_this call listboxDrag";
onLBDrop = "_this call listBoxDrop";
/*copy and paste this into the listbox definitions, underneath all the
x = blah
y = blah
w = blah
h = blah

that code here
*/

Furthermore, it would be quite useful to compile these using the functions library, but I don't know if you know how to do that (just read all of that)

Edited by DreadedEntity

Share this post


Link to post
Share on other sites

You just called in a tactical carpet bombing where I was running in with a sharpened spoon. Thanks so much!

Share this post


Link to post
Share on other sites

I'm still working on the other scripts needed to get the dialong functional but I will let you know when I start it up.

One question though, in line 12 why do you call compile all of that?

Share this post


Link to post
Share on other sites

lbData returns a string, so compiling it will turn it into code, which is then called which returns a value which is then stored into the variable.

Share this post


Link to post
Share on other sites

JShock is right. For some reason (probably by a design farce) data can only be saved as strings in dialog elements. But we want the array itself and not the string, otherwise we'll have to write a string parser (which will suck). Luckily "code" variable types will always return the data in the last command, and since the last command in this case is the only command, we can just compile and run it to return the array itself and save that into a variable.

Also, I was reading over it this morning and I saw a mistake, so I made an edit to it and it should actually work now.

Lastly, I don't know how comfortable you are with scripting yet, so you can edit my data layout and the functions if you want, but if you're not that comfortable and plan on using those 2 functions as-is make sure you lbSetData the proper data to each listbox element. In fact, any time you have lbAdd, the very next command should be lbSetData.

Hope all that gets you in the right direction

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×