Using listbox to select a model

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Clone256
Posts: 11
Joined: Thu Oct 13, 2005 9:20 pm

Using listbox to select a model

Post by Clone256 »

I'm trying to select a model with a listbox, but I can't get this working for some reason.

This is the structure I'm using to hold the model info:

Code: Select all

struct OBJECT
{
        scene::IAnimatedMeshSceneNode* Model;
        wchar_t model_name[1024];
        core::vector3df scale;
        s32 listID;
};

OBJECT object[10];
Then load the model.

After loading a model, I have this part:

Code: Select all

object[model_count].listID = lbox->addItem(object[model_count].model_name);
	model_count++;

Here's part of the event reciever:

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		if (event.EventType == EET_GUI_EVENT)
		{
			s32 id = event.GUIEvent.Caller->getID();
			IGUIEnvironment* env = Device->getGUIEnvironment();

			switch(event.GUIEvent.EventType)
			{
			case EGET_MENU_ITEM_SELECTED:
				{
					// a menu item was clicked

					IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
					s32 id = menu->getItemCommandId(menu->getSelectedItem());
					
					switch(id)
					{
					case 100: // File -> Open Model
						env->addFileOpenDialog(L"Please select a model file to open");
						break;
					case 200: // File -> Quit
						Device->closeDevice();
						break;
					case 300: // View -> Skybox
						SkyBox->setVisible(!SkyBox->isVisible());
						break;
					case 400: // View -> Debug Information
						if (object[model_number].Model)
							object[model_number].Model->setDebugDataVisible(!object[model_number].Model->isDebugDataVisible());
						break;
					case 500: // Help->About
						showAboutText();
						break;
					case 610: // View -> Material -> Solid
						if (object[model_number].Model)
							object[model_number].Model->setMaterialType(video::EMT_SOLID);
						break;
					case 620: // View -> Material -> Transparent
						if (object[model_number].Model)
							object[model_number].Model->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
						break;
					case 630: // View -> Material -> Reflection
						if (object[model_number].Model)
							object[model_number].Model->setMaterialType(video::EMT_SPHERE_MAP);
						break;
					}
                    break;
				}


            case EGET_LISTBOX_CHANGED:
                 
                      if(id == 150)
                      {
                                s32 id = lbox->getSelected();
                                int item_count = 0;
                      
                                while(item_count < lbox->getItemCount())
                                {
                                     if(object[item_count].listID == id)
                                     {
                                          model_number = item_count;
                                     }
                                     item_count++;
                                }
                      }			    
                 break;
I stored (or tried to store) the id of the listbox item and then use that to select the model by going through this while loop and finding the number of the model with the same id stored in listID.
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

Your code looks pretty solid, I can't detect a problem. What is it doing wrong?
Clone256
Posts: 11
Joined: Thu Oct 13, 2005 9:20 pm

Post by Clone256 »

Thanks for the reply.

What it's supposed to do is just change which model is selected to match the selection in the listbox.

It doesn't seem to do anything though. It just keeps the last one I loaded selected.

When I load 2 or more models and I select the first one in the list it won't let me change the scale anymore, until I select a different one, but that's the only thing I've noticed that happens.
Clone256
Posts: 11
Joined: Thu Oct 13, 2005 9:20 pm

Post by Clone256 »

Here is the complete cpp file if anyone wants to take a look. It's the file from one of the tutorials, but I've changed it and added to it.

I still havent found the problem.

http://www.angelfire.com/pro/clone256/cpp.html


-Clone
Post Reply