ComboBox action based on item id

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Blender+C++
Just popping in
Just popping in
Posts: 16
Joined: Sat Jun 23, 2012 01:40
Location: Brazil

ComboBox action based on item id

Postby Blender+C++ » Sat Jun 23, 2012 18:40

hi Crazy Eddie and people,
sorry for creating another thread with the same subject as the previous one, but i thought that the old post wouldnt be answered anymore..anyways..so i have implemented a combobox list menu, but i want to give life to it, in other words i want to give an action to each item of the combobox, so i cant figure out how to do it..
i have tried this : objectComboBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted, CEGUI::Event::Subscriber(&BasicTutorial7::createNinja, this));
but it doesnt matter what item id is selected , it creates the ninja anyways, i tried to create an if statement but then i realized that it doesnt have anything to do with ogre but with CEGUI..i thought it must have some sort of fucntion to subscribe a specific item from the Item list..
can any of you get me some help regarding the text above?
thx in advance,
Romulo Romero

Blender+C++
Just popping in
Just popping in
Posts: 16
Joined: Sat Jun 23, 2012 01:40
Location: Brazil

Re: ComboBox action based on item id

Postby Blender+C++ » Sat Jun 23, 2012 21:24

hi ,
dude i have tried so many ways but none of the seemed to work...the ones that made much sense to me when they worked but not precisely, like if the if statement seems to be correct it just creates the entity with any of the options from the comboboxlist..ill try to give examples, the text looks a bit confusing but im gonna try to make it clear(sorry English is not my first lang).
ok the things i have tried(wont post some coz they are prolly rediculous lol)

Code: Select all

CEGUI::String valueCombobox = objectComboBox->getText(); // Retrieve the displayed text
   CEGUI::uint idCombobox = objectComboBox->getSelectedItem()->getID(); // Retrieve the ID of the selected combobox item
   if(valueCombobox  == "Ninja")
      {
         objectComboBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted, CEGUI::Event::Subscriber(&BasicTutorial7::createNinja, this));
      
   }
or
if(valueCombobox  == CEGUI::String ("Ninja"))
      {
         objectComboBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted, CEGUI::Event::Subscriber(&BasicTutorial7::createNinja, this));
      
   }



didnt work and the ComboBox didnt even create the ninja with any of the options..

Second :

Code: Select all

CEGUI::String valueCombobox = objectComboBox->getText(); // Retrieve the displayed text
   CEGUI::uint idCombobox = objectComboBox->getSelectedItem()->getID(); // Retrieve the ID of the selected combobox item
  if(idCombobox  == 7)
      {
         objectComboBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted, CEGUI::Event::Subscriber(&BasicTutorial7::createNinja, this));
                    }


didnt work either but if i clicked in any of the option then it creates the ninja..
if i change this idCombobox == 7 to this idCombobox == 8 ( theres no item with id 8 in the list) then all the options dont work at all , no action no ninja is created..

Third :

Code: Select all

  CEGUI::String valueCombobox = objectComboBox->getText(); // Retrieve the displayed text
   CEGUI::uint idCombobox = objectComboBox->getSelectedItem()->getID(); // Retrieve the ID of the selected combobox item
   if(objectComboBox->getSelectedItem()->getText() == CEGUI::String("Ninja"))
      {
         objectComboBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted, CEGUI::Event::Subscriber(&BasicTutorial7::createNinja, this));
      }

it also creates the Ninja with any of the comboBox items, im not sure if im right but the if statement doesnt check whats after the == operator?

fourth:

Code: Select all

CEGUI::String valueCombobox = objectComboBox->getText(); // Retrieve the displayed text
   CEGUI::uint idCombobox = objectComboBox->getSelectedItem()->getID(); // Retrieve the ID of the selected combobox item
      switch(idCombobox)
   {
   case 7:

         objectComboBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted, CEGUI::Event::Subscriber(&BasicTutorial7::createNinja, this))      break;
   case 6:
      objectComboBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted,   CEGUI::Event::Subscriber(&BasicTutorial7::createRobot,this));
      break;

   default:
      return 0;
   }

and the funny thing is that if i put in the first "case" a value of 8(8th item doesnt exist in the combo list), when i run the application it doesnt show anything the buttons and nothing..that is so weird,it looks like the statements are not being processed or checked its going straight to the values...
this one also no matter what choice i make it creates the ninja..
and i also have tried many other similar ways but the behaviors are the same...
i look forward for a reply thx!
Yours,
Romulo Romero

Blender+C++
Just popping in
Just popping in
Posts: 16
Joined: Sat Jun 23, 2012 01:40
Location: Brazil

Re: ComboBox action based on item id

Postby Blender+C++ » Sun Jun 24, 2012 01:08

ok in order to provide more details, i decided to post the class code and the implementation file to see whats wrong with my stuff...i bet lots of things look inconsistent so here it goes:

Header file:

Code: Select all

/*
-----------------------------------------------------------------------------
Filename:    BasicTutorial7.h
-----------------------------------------------------------------------------


This source file is generated by the
   ___                   _              __    __ _                  _
  /___\__ _ _ __ ___    /_\  _ __  _ __/ / /\ \ (_)______ _ _ __ __| |
 //  // _` | '__/ _ \  //_\\| '_ \| '_ \ \/  \/ / |_  / _` | '__/ _` |
/ \_// (_| | | |  __/ /  _  \ |_) | |_) \  /\  /| |/ / (_| | | | (_| |
\___/ \__, |_|  \___| \_/ \_/ .__/| .__/ \/  \/ |_/___\__,_|_|  \__,_|
      |___/                 |_|   |_|                                 
      Ogre 1.7.x Application Wizard for VC10 (July 2011)
      http://code.google.com/p/ogreappwizards/
-----------------------------------------------------------------------------
*/
#ifndef __BasicTutorial7_h_
#define __BasicTutorial7_h_

#include "BaseApplication.h"
#include <cegui.h>
#include <RendererModules/Ogre/CEGUIOgreRenderer.h>




#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../res/resource.h"
#endif


class BasicTutorial7 : public BaseApplication
{
public:
    BasicTutorial7(void);
    virtual ~BasicTutorial7(void);

protected:
   CEGUI::OgreRenderer* mRenderer;
    virtual void createScene(void);
   virtual void createFrameListener(void);
   //Ogre::FrameListener

   virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt);

   //OIS::KeyListener

   virtual bool keyPressed(const OIS::KeyEvent& arg);
   virtual bool keyReleased(const OIS::KeyEvent& arg);

   //OIS::MouseListener

   virtual bool mouseMoved(const OIS::MouseEvent& arg);
   virtual bool mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
   virtual bool mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
   bool createRobot(const CEGUI::EventArgs& e);
   bool createNinja(const CEGUI::EventArgs& e);
   bool quitit(const CEGUI::EventArgs& e);
   bool ComboBox(const CEGUI::EventArgs* e);
   void RTT(void);
   void QuitButton(void);
   CEGUI::Combobox* objectComboBox;
   CEGUI::Window* sheet;
   CEGUI::Window* quit;
   CEGUI::EventArgs* evt;

};

#endif // #ifndef __BasicTutorial7_h_


and the .cpp file here :

Code: Select all

/*
-----------------------------------------------------------------------------
Filename:    BasicTutorial7.cpp
-----------------------------------------------------------------------------


This source file is generated by the
   ___                   _              __    __ _                  _
  /___\__ _ _ __ ___    /_\  _ __  _ __/ / /\ \ (_)______ _ _ __ __| |
 //  // _` | '__/ _ \  //_\\| '_ \| '_ \ \/  \/ / |_  / _` | '__/ _` |
/ \_// (_| | | |  __/ /  _  \ |_) | |_) \  /\  /| |/ / (_| | | | (_| |
\___/ \__, |_|  \___| \_/ \_/ .__/| .__/ \/  \/ |_/___\__,_|_|  \__,_|
      |___/                 |_|   |_|                                 
      Ogre 1.7.x Application Wizard for VC10 (July 2011)
      http://code.google.com/p/ogreappwizards/
-----------------------------------------------------------------------------
*/

#include "BasicTutorial7.h"
CEGUI::MouseButton convertButton(OIS::MouseButtonID buttonID)
{

   switch(buttonID)
   {
   case OIS::MB_Left:
      return CEGUI::LeftButton;
   case OIS::MB_Right:
      return CEGUI::RightButton;
   case OIS::MB_Middle:
      return CEGUI::MiddleButton;
   default:
      return CEGUI::LeftButton;
   }

}

//-------------------------------------------------------------------------------------
BasicTutorial7::BasicTutorial7(void)
{
   
   
}
//-------------------------------------------------------------------------------------
BasicTutorial7::~BasicTutorial7(void)
{
}

//-------------------------------------------------------------------------------------
void BasicTutorial7::createScene(void)
{
   
   mRenderer = &CEGUI::OgreRenderer::bootstrapSystem();
   CEGUI::Imageset::setDefaultResourceGroup("Imagesets");
   CEGUI::Font::setDefaultResourceGroup("Fonts");
   CEGUI::Scheme::setDefaultResourceGroup("Schemes");
   CEGUI::WidgetLookManager::setDefaultResourceGroup("LookNFeel");
   CEGUI::WindowManager::setDefaultResourceGroup("Layouts");
   CEGUI::SchemeManager::getSingleton().create("TaharezLook.scheme");
   CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
   CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();
   sheet = wmgr.createWindow("DefaultWindow", "CEGUIDemo/Sheet");
   
   RTT();
   QuitButton();
   ComboBox(evt);
   
   //dropmenu->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&BasicTutorial7::quit, this));
   mSceneMgr->setAmbientLight(Ogre::ColourValue(1, 1, 1));
   mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
   
   
   CEGUI::System::getSingleton().setGUISheet(sheet);
   

}

void BasicTutorial7::createFrameListener(void)
{
   //BaseApplication::createFrameListener();
   Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
    OIS::ParamList pl;
    size_t windowHnd = 0;
    std::ostringstream windowHndStr;
 
    mWindow->getCustomAttribute("WINDOW", &windowHnd);
    windowHndStr << windowHnd;
    pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
 
    mInputManager = OIS::InputManager::createInputSystem( pl );
 
    mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, true ));
    mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true ));
 
    mMouse->setEventCallback(this);
    mKeyboard->setEventCallback(this);
 
    //Set initial mouse clipping size
    windowResized(mWindow);

 
    //Register as a Window listener
    Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);
 
    mRoot->addFrameListener(this);

}

bool BasicTutorial7::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
   if(mWindow->isClosed())
      return false;
   if(mShutDown)
      return false;
   //Need to capture/update each device
   mKeyboard->capture();
   mMouse->capture();

   //need to inject timestamps to CEGUI System
   CEGUI::System::getSingleton().injectTimePulse(evt.timeSinceLastFrame);
   return true;
   //return BaseApplication::frameRenderingQueued(evt);

}
bool BasicTutorial7::keyPressed(const OIS::KeyEvent& arg)
{
   CEGUI::System &sys = CEGUI::System::getSingleton();
   sys.injectKeyDown(arg.key);
   sys.injectChar(arg.text);
   return true;
   //return BaseApplication::keyPressed(arg);
}
bool BasicTutorial7::keyReleased(const OIS::KeyEvent& arg)
{
   CEGUI::System::getSingleton().injectKeyUp(arg.key);
   return true;
   //return BaseApplication::keyReleased(arg);
}

bool BasicTutorial7::mouseMoved(const OIS::MouseEvent& arg)
{   
   CEGUI::System &sys = CEGUI::System::getSingleton();
   sys.injectMouseMove(arg.state.X.rel, arg.state.Y.rel);
   //Scroll wheel

   if(arg.state.Z.rel)
      sys.injectMouseWheelChange(arg.state.Z.rel / 120.0f);
   
   return true;
   //return BaseApplication::mouseMoved(arg);
}
bool BasicTutorial7::mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id)
{
   CEGUI::System::getSingleton().injectMouseButtonDown(convertButton(id));
   return true;
   //return BaseApplication::mousePressed(arg, id);
}
bool BasicTutorial7::mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id)
{
   CEGUI::System::getSingleton().injectMouseButtonUp(convertButton(id));
   return true;
   //return BaseApplication::mouseReleased(arg, id);
}
bool BasicTutorial7::quitit(const CEGUI::EventArgs& e)
{
   mShutDown = true;
   return true;
}
bool BasicTutorial7::createRobot(const CEGUI::EventArgs& e)
{
   Ogre::Entity* robotEnt = mSceneMgr->createEntity("Robot", "robot.mesh");
   Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, -100, -300));
   node->attachObject(robotEnt);
   return true;

}
bool BasicTutorial7::ComboBox(const CEGUI::EventArgs* e)
{
   
   CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();   
   objectComboBox = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"TaharezLook/Combobox", (CEGUI::utf8*)"CEGUIDemo/Menu");
   objectComboBox = static_cast<CEGUI::Combobox*>(wmgr.getWindow("CEGUIDemo/Menu"));
   
   objectComboBox->setReadOnly(true);


   CEGUI::ListboxTextItem* itemCombobox = new CEGUI::ListboxTextItem("Fighter", 1);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   itemCombobox = new CEGUI::ListboxTextItem("Knight", 2);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   itemCombobox = new CEGUI::ListboxTextItem("Pikeman", 3);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   itemCombobox = new CEGUI::ListboxTextItem("Mage", 4);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   itemCombobox = new CEGUI::ListboxTextItem("Priest", 5);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   itemCombobox = new CEGUI::ListboxTextItem("Mechanic", 6);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   itemCombobox = new CEGUI::ListboxTextItem("Ninja", 7);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   itemCombobox->setSelected(true); // Select this item
   objectComboBox->setText(itemCombobox->getText()); // Copy the item's text into the Editbox


   objectComboBox->setSize(CEGUI::UVector2(CEGUI::UDim(0.18, 0), CEGUI::UDim(0.5, 0)));
   objectComboBox->setPosition(CEGUI::UVector2(CEGUI::UDim(0.2f, 0), CEGUI::UDim(0.1f, 0)));
   objectComboBox->setText("SelectCharater");
   sheet->addChildWindow(objectComboBox);
   //objectComboBox->setAlwaysOnTop(true);
   CEGUI::String valueCombobox = objectComboBox->getText(); // Retrieve the displayed text
   CEGUI::uint idCombobox = objectComboBox->getSelectedItem()->getID(); // Retrieve the ID of the selected combobox item
        if(idCombobox == 7)
     {
        objectComboBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted, CEGUI::Event::Subscriber(&BasicTutorial7::createNinja, this));
     }

   //ComboBox();
   //
   //switch(idCombobox)
   //{
   //case 7:
     //   

       //  objectComboBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted, CEGUI::Event::Subscriber(&BasicTutorial7::createNinja, this));
       //// objectComboBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted,   CEGUI::Event::Subscriber(&BasicTutorial7::createRobot,this));
       //  break;
   //case 6:
     // objectComboBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted,   CEGUI::Event::Subscriber(&BasicTutorial7::createRobot,this));
     // break;

   //default:
     // return 0;
   //}
 
      

   return true;
   
      


}
bool BasicTutorial7::createNinja(const CEGUI::EventArgs& e)
{
   Ogre::Entity* ninjaEnt = mSceneMgr->createEntity("Ninja", "ninja.mesh");
   Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, -100, -300));
   node->attachObject(ninjaEnt);
   return true;
}
void BasicTutorial7::RTT(void)
{
      
   Ogre::TexturePtr tex = mRoot->getTextureManager()->createManual(
      "RTT",
      Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
      Ogre::TEX_TYPE_2D,
      512,
      512,
      0,
      Ogre::PF_R8G8B8,
      Ogre::TU_RENDERTARGET);
   Ogre::RenderTexture* rtex = tex->getBuffer()->getRenderTarget();
   Ogre::Camera* cam = mSceneMgr->createCamera("RTTCam");
   cam->setPosition(100, -100, -400);
   cam->lookAt(0, 0, -300);
   Ogre::Viewport *v = rtex->addViewport(cam);
   v->setOverlaysEnabled(false);
   v->setClearEveryFrame(true);
   v->setBackgroundColour(Ogre::ColourValue::Black);
   CEGUI::Texture &guiTex = mRenderer->createTexture(tex);
   CEGUI::Imageset &imgSet =
      CEGUI::ImagesetManager::getSingleton().create("RTTImageset", guiTex);
   imgSet.defineImage("RTTImage",
      CEGUI::Point(0.0f, 0.0f),
      CEGUI::Size(guiTex.getSize().d_width,
      guiTex.getSize().d_height),
      CEGUI::Point(0.0f, 0.0f));
   CEGUI::Window* si = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticImage", "RTTWindow");
   si->setSize(CEGUI::UVector2(CEGUI::UDim(0.2f, 0),
      CEGUI::UDim(0.2f, 0)));
   si->setPosition(CEGUI::UVector2(CEGUI::UDim(0.8f, 0),
      CEGUI::UDim(0.0f, 0)));
   si->setProperty("Image", CEGUI::PropertyHelper::imageToString(&imgSet.getImage("RTTImage")));
   sheet->addChildWindow(si);
}
void BasicTutorial7::QuitButton(void)
{
   CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();

   quit = wmgr.createWindow("TaharezLook/Button", "CEGUIDemo/QuitButton");
   quit->setText("Quit it!");
   quit->setSize(CEGUI::UVector2(CEGUI::UDim(0.15, 0), CEGUI::UDim(0.05, 0)));
   sheet->addChildWindow(quit);
   quit->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&BasicTutorial7::quitit, this));
}


#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
    int main(int argc, char *argv[])
#endif
    {
        // Create application object
        BasicTutorial7 app;

        try {
            app.go();
        } catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
            std::cerr << "An exception has occured: " <<
                e.getFullDescription().c_str() << std::endl;
#endif
        }

        return 0;
    }

#ifdef __cplusplus
}
#endif

again any help is greatly appreciated!
kind regards,
Romulo Romero

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: ComboBox action based on item id

Postby CrazyEddie » Sun Jun 24, 2012 08:17

HI,

Your idea of how things work are somewhat skewed ;)

Basically what you need to do is to listen for the event (EventListSelectionAccepted or whichever), and then within the event handler decide which object to create. I will post a real simple example of how that might look - I will add that the large switch construct is pretty horrible, and there are some OO approaches to avoid that as well as some other advanced hacks, but judging from your posts here, you may not be ready to know about those :mrgreen:

Code: Select all

...
// this is the subscription: it calls the function handleListSelectionChanged when the list selection is changed.
objectComboBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted, CEGUI::Event::Subscriber(&BasicTutorial7::handleListSelectionChanged, this));
...


bool BasicTutorial7::handleListSelectionChanged(const CEGUI::EventArgs& e)
{
    CEGUI::WindowEventArgs& wea(static_cast<const CEGUI::WindowEventArgs&>(e);
    CEGUI::Combobox* combobox = static_cast<CEGUI::Combobox*>(wea.window);
    CEGUI::ListboxTextItem* selectedItem = combobox->getSelectedItem();

    if (!selectedItem)
        return false;

    switch(selectedItem->getID())
    {
    case 1:
        createFighter();
        break;

    case 2:
        createKnight();
        break;

    case 3:
        createPikeman();
        break;

    case 4:
        createMage();
        break;

    case 5:
        createPriest();
        break;

    case 6:
        createMechanic();
        break;

    case 7:
        createNinja();
        break;

    case 8:
        createRobot();
        break;
    }

    return true;
}


I hope this points you in the right direction.

CE.

Blender+C++
Just popping in
Just popping in
Posts: 16
Joined: Sat Jun 23, 2012 01:40
Location: Brazil

Re: ComboBox action based on item id

Postby Blender+C++ » Sun Jun 24, 2012 15:54

Hi CrazzyEddie,
first of all thx for replying to my thread..and yeah i kindof thought the way you did, but this lines :

Code: Select all

CEGUI::WindowEventArgs& wea(static_cast<const CEGUI::WindowEventArgs&>(e);
    CEGUI::Combobox* combobox = static_cast<CEGUI::Combobox*>(wea.window);
    CEGUI::ListboxTextItem* selectedItem = combobox->getSelectedItem();

i would never know it LOL..

I will post a real simple example of how that might look - I will add that the large switch construct is pretty horrible, and there are some OO approaches to avoid that as well as some other advanced hacks, but judging from your posts here, you may not be ready to know about those


well i know that im still a newbie but im pretty sure that im able to absorb some extra information ,i'd be more than glad to hear from you some other approaches,i aint gonna be scared at all :D
thx for sharing the solution and it obviously worked,i just had to change a couple of things but thats the rule nº 1 for a future programmer :d

i look forward for a reply!
All the best,
Romulo Romero

Blender+C++
Just popping in
Just popping in
Posts: 16
Joined: Sat Jun 23, 2012 01:40
Location: Brazil

Re: ComboBox action based on item id

Postby Blender+C++ » Sun Jun 24, 2012 23:28

Hi CrazzyEddie here i am again but this time i have solved what i needed to have as a result however everything i created look like workarounds, hacks and i dont want to leave it like that, it looks bad and ugly, poor coding...i prefer to learn the right way if u know what i mean...i had to improvise lots of things in order to avoid errors , for example if i click in the same item again, instead of throwing an error i wanted it to do nothing, and also when i change the item , i wanted to remove the entity or dettach the node and attach the new one...
for the part of clicking in the same item again, i have tried the mSceneMgr->hasEntity(name)...and it didnt work...so i decided to use the switch statement to solve the issue..ok thats too much talking so i ll paste the entire implementation file here so u can have a better ideia of what i trying to describe with my limited vocab..
by the way, i hate to sound dumb and stupid but its inevitable im still a noob and noobs sound dumb indeed and im confortable with that but i bet ur not lol..so please consider that :D( and i hate to post everytime ,i try to avoid that, but u seem to be a nice guy and patient ^^,i am trying my best believe me )..that being said..here it goes :
.cpp file

Code: Select all

/*
-----------------------------------------------------------------------------
Filename:    BasicTutorial7.cpp
-----------------------------------------------------------------------------


This source file is generated by the
   ___                   _              __    __ _                  _
  /___\__ _ _ __ ___    /_\  _ __  _ __/ / /\ \ (_)______ _ _ __ __| |
 //  // _` | '__/ _ \  //_\\| '_ \| '_ \ \/  \/ / |_  / _` | '__/ _` |
/ \_// (_| | | |  __/ /  _  \ |_) | |_) \  /\  /| |/ / (_| | | | (_| |
\___/ \__, |_|  \___| \_/ \_/ .__/| .__/ \/  \/ |_/___\__,_|_|  \__,_|
      |___/                 |_|   |_|                                 
      Ogre 1.7.x Application Wizard for VC10 (July 2011)
      http://code.google.com/p/ogreappwizards/
-----------------------------------------------------------------------------
*/

#include "BasicTutorial7.h"
CEGUI::MouseButton convertButton(OIS::MouseButtonID buttonID)
{

   switch(buttonID)
   {
   case OIS::MB_Left:
      return CEGUI::LeftButton;
   case OIS::MB_Right:
      return CEGUI::RightButton;
   case OIS::MB_Middle:
      return CEGUI::MiddleButton;
   default:
      return CEGUI::LeftButton;
   }

}

//-------------------------------------------------------------------------------------
BasicTutorial7::BasicTutorial7(void)
{
   
   
}
//-------------------------------------------------------------------------------------
BasicTutorial7::~BasicTutorial7(void)
{
}

//-------------------------------------------------------------------------------------
void BasicTutorial7::createScene(void)
{
   
   mRenderer = &CEGUI::OgreRenderer::bootstrapSystem();
   CEGUI::Imageset::setDefaultResourceGroup("Imagesets");
   CEGUI::Font::setDefaultResourceGroup("Fonts");
   CEGUI::Scheme::setDefaultResourceGroup("Schemes");
   CEGUI::WidgetLookManager::setDefaultResourceGroup("LookNFeel");
   CEGUI::WindowManager::setDefaultResourceGroup("Layouts");
   CEGUI::SchemeManager::getSingleton().create("TaharezLook.scheme");
   CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
   CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();
   sheet = wmgr.createWindow("DefaultWindow", "CEGUIDemo/Sheet");
   /*sprintf(name, "Robot%d", mCount++);
   Ogre::Entity* robotEnt = mSceneMgr->createEntity(name, "robot.mesh");
   node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, -100, -300));
   node->attachObject(robotEnt);*/
   RTT();
   QuitButton();
   ComboBox(evt);
   
   //dropmenu->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&BasicTutorial7::quit, this));
   mSceneMgr->setAmbientLight(Ogre::ColourValue(1, 1, 1));
   mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
   
   
   CEGUI::System::getSingleton().setGUISheet(sheet);
   

}

void BasicTutorial7::createFrameListener(void)
{
   //BaseApplication::createFrameListener();
   Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
    OIS::ParamList pl;
    size_t windowHnd = 0;
    std::ostringstream windowHndStr;
 
    mWindow->getCustomAttribute("WINDOW", &windowHnd);
    windowHndStr << windowHnd;
    pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
 
    mInputManager = OIS::InputManager::createInputSystem( pl );
 
    mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, true ));
    mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true ));
 
    mMouse->setEventCallback(this);
    mKeyboard->setEventCallback(this);
 
    //Set initial mouse clipping size
    windowResized(mWindow);

 
    //Register as a Window listener
    Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);
 
    mRoot->addFrameListener(this);

}

bool BasicTutorial7::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
   if(mWindow->isClosed())
      return false;
   if(mShutDown)
      return false;
   //Need to capture/update each device
   mKeyboard->capture();
   mMouse->capture();

   //need to inject timestamps to CEGUI System
   CEGUI::System::getSingleton().injectTimePulse(evt.timeSinceLastFrame);
   return true;
   //return BaseApplication::frameRenderingQueued(evt);

}
bool BasicTutorial7::keyPressed(const OIS::KeyEvent& arg)
{
   CEGUI::System &sys = CEGUI::System::getSingleton();
   sys.injectKeyDown(arg.key);
   sys.injectChar(arg.text);
   return true;
   //return BaseApplication::keyPressed(arg);
}
bool BasicTutorial7::keyReleased(const OIS::KeyEvent& arg)
{
   CEGUI::System::getSingleton().injectKeyUp(arg.key);
   return true;
   //return BaseApplication::keyReleased(arg);
}

bool BasicTutorial7::mouseMoved(const OIS::MouseEvent& arg)
{   
   CEGUI::System &sys = CEGUI::System::getSingleton();
   sys.injectMouseMove(arg.state.X.rel, arg.state.Y.rel);
   //Scroll wheel

   if(arg.state.Z.rel)
      sys.injectMouseWheelChange(arg.state.Z.rel / 120.0f);
   
   return true;
   //return BaseApplication::mouseMoved(arg);
}
bool BasicTutorial7::mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id)
{
   CEGUI::System::getSingleton().injectMouseButtonDown(convertButton(id));
   return true;
   //return BaseApplication::mousePressed(arg, id);
}
bool BasicTutorial7::mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id)
{
   CEGUI::System::getSingleton().injectMouseButtonUp(convertButton(id));
   return true;
   //return BaseApplication::mouseReleased(arg, id);
}
bool BasicTutorial7::quitit(const CEGUI::EventArgs& e)
{
   mShutDown = true;
   return true;
}
bool BasicTutorial7::createRobot(const CEGUI::EventArgs& e)
{
   
   sprintf(name, "Robot");
   ent = mSceneMgr->createEntity(name, "robot.mesh");
   if(mSceneMgr->getEntity(name))
   {
      mSceneMgr->destroyAllEntities();
   }
   sprintf(name, "Robot");
   ent = mSceneMgr->createEntity(name, "robot.mesh");

   node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, -100, -300));
   node->attachObject(ent);
   node->scale(3,3,3);
      

   
   return true;

}

bool BasicTutorial7::createNinja(const CEGUI::EventArgs& e)
{
   sprintf(name, "Ninja");
   ent = mSceneMgr->createEntity(name, "ninja.mesh");
   if(mSceneMgr->getEntity(name))
   {
      mSceneMgr->destroyAllEntities();
   }
   sprintf(name, "Ninja");
   ent = mSceneMgr->createEntity(name, "ninja.mesh");
   node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, -100, -300));
   node->attachObject(ent);
   
   return true;
}
bool BasicTutorial7::createFighter(const CEGUI::EventArgs& e)
{
   sprintf(name, "Fighter");
   ent = mSceneMgr->createEntity(name, "penguin.mesh");
   if(mSceneMgr->getEntity(name))
   {
      mSceneMgr->destroyAllEntities();
   }
   sprintf(name, "Fighter");
   ent = mSceneMgr->createEntity(name, "penguin.mesh");
   node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, -100, -300));
   node->attachObject(ent);
   node->scale(4,4,4);
   
   return true;
}
bool BasicTutorial7::createKnight(const CEGUI::EventArgs& e)
{
   sprintf(name, "Knight");
   ent = mSceneMgr->createEntity(name, "jaiqua.mesh");
   if(mSceneMgr->getEntity(name))
   {
      mSceneMgr->destroyAllEntities();
   }
   sprintf(name, "knight");
   ent = mSceneMgr->createEntity(name, "jaiqua.mesh");
   node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, -100, -300));
   node->attachObject(ent);
   node->scale(15,15,15);
   
   return true;
}
bool BasicTutorial7::createMage(const CEGUI::EventArgs& e)
{
   sprintf(name, "Mage");
   ent = mSceneMgr->createEntity(name, "ogrehead.mesh");
   if(mSceneMgr->getEntity(name))
   {
      mSceneMgr->destroyAllEntities();
   }
   sprintf(name, "Mage");
   ent = mSceneMgr->createEntity(name, "ogrehead.mesh");
   node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, -100, -300));
   node->attachObject(ent);
   node->scale(4,4,4);
   
   return true;
}
bool BasicTutorial7::createPikeman(const CEGUI::EventArgs& e)
{
   
   sprintf(name, "Pike");
   ent = mSceneMgr->createEntity(name, "fish.mesh");
   if(mSceneMgr->getEntity(name))
   {
      mSceneMgr->destroyAllEntities();
   }
      
   //if(mSceneMgr->hasEntity("Pike"))
   //{
   //   sprintf(name, "Mech");
   //
   //   ninjaEnt = mSceneMgr->createEntity(name, "mech.mesh");;
   //}
   
   sprintf(name, "Pike");
   ent = mSceneMgr->createEntity(name, "fish.mesh");
   node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, -100, -300));
   node->attachObject(ent);
   node->scale(15,15,15);
   
   return true;
}
bool BasicTutorial7::createPriest(const CEGUI::EventArgs& e)
{
   sprintf(name, "Priest");
   ent = mSceneMgr->createEntity(name, "Mech.mesh");
   if(mSceneMgr->getEntity(name))
   {
      mSceneMgr->destroyAllEntities();
   }
   sprintf(name, "Priest");
   ent = mSceneMgr->createEntity(name, "Mech.mesh");
   node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, -100, -300));
   node->attachObject(ent);
   node->scale(6,6,6);
   
   return true;
}
bool BasicTutorial7::ComboBox(const CEGUI::EventArgs& e)
{
   
   CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();   
   objectComboBox = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"TaharezLook/Combobox", (CEGUI::utf8*)"CEGUIDemo/Menu");
   objectComboBox = static_cast<CEGUI::Combobox*>(wmgr.getWindow("CEGUIDemo/Menu"));
   
   objectComboBox->setReadOnly(true);


   CEGUI::ListboxTextItem* itemCombobox = new CEGUI::ListboxTextItem("Fighter", 1);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   itemCombobox = new CEGUI::ListboxTextItem("Knight", 2);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   itemCombobox->setSelected(true);// Select this item
    objectComboBox->setText(itemCombobox->getText()); // Copy the item's text into the Editbox
   itemCombobox = new CEGUI::ListboxTextItem("Pikeman", 3);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   itemCombobox = new CEGUI::ListboxTextItem("Mage", 4);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   itemCombobox = new CEGUI::ListboxTextItem("Priest", 5);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   itemCombobox = new CEGUI::ListboxTextItem("Mechanic", 6);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   itemCombobox = new CEGUI::ListboxTextItem("Ninja", 7);
   itemCombobox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   objectComboBox->addItem(itemCombobox);
   
 
 
   objectComboBox->setSize(CEGUI::UVector2(CEGUI::UDim(0.18, 0), CEGUI::UDim(0.5, 0)));
   objectComboBox->setPosition(CEGUI::UVector2(CEGUI::UDim(0.2f, 0), CEGUI::UDim(0.1f, 0)));
   objectComboBox->setText("SelectCharacter");
   sheet->addChildWindow(objectComboBox);
   //objectComboBox->setAlwaysOnTop(true);
   CEGUI::String valueCombobox = objectComboBox->getText(); // Retrieve the displayed text
   CEGUI::uint idCombobox = objectComboBox->getSelectedItem()->getID(); // Retrieve the ID of the selected combobox it
   objectComboBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted, CEGUI::Event::Subscriber(&BasicTutorial7::handleListSelectionChanged, this));
      

   return true;
   
      


}

void BasicTutorial7::RTT(void)
{
      
   Ogre::TexturePtr tex = mRoot->getTextureManager()->createManual(
      "RTT",
      Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
      Ogre::TEX_TYPE_2D,
      512,
      512,
      0,
      Ogre::PF_R8G8B8,
      Ogre::TU_RENDERTARGET);
   Ogre::RenderTexture* rtex = tex->getBuffer()->getRenderTarget();
   Ogre::Camera* cam = mSceneMgr->createCamera("RTTCam");
   cam->setPosition(100, -100, -400);
   cam->lookAt(0, 0, -300);
   Ogre::Viewport *v = rtex->addViewport(cam);
   v->setOverlaysEnabled(false);
   v->setClearEveryFrame(true);
   v->setBackgroundColour(Ogre::ColourValue::Black);
   CEGUI::Texture &guiTex = mRenderer->createTexture(tex);
   CEGUI::Imageset &imgSet =
      CEGUI::ImagesetManager::getSingleton().create("RTTImageset", guiTex);
   imgSet.defineImage("RTTImage",
      CEGUI::Point(0.0f, 0.0f),
      CEGUI::Size(guiTex.getSize().d_width,
      guiTex.getSize().d_height),
      CEGUI::Point(0.0f, 0.0f));
   CEGUI::Window* si = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticImage", "RTTWindow");
   si->setSize(CEGUI::UVector2(CEGUI::UDim(0.2f, 0),
      CEGUI::UDim(0.2f, 0)));
   si->setPosition(CEGUI::UVector2(CEGUI::UDim(0.8f, 0),
      CEGUI::UDim(0.0f, 0)));
   si->setProperty("Image", CEGUI::PropertyHelper::imageToString(&imgSet.getImage("RTTImage")));
   sheet->addChildWindow(si);
}
void BasicTutorial7::QuitButton(void)
{
   CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();

   quit = wmgr.createWindow("TaharezLook/Button", "CEGUIDemo/QuitButton");
   quit->setText("Quit it!");
   quit->setSize(CEGUI::UVector2(CEGUI::UDim(0.15, 0), CEGUI::UDim(0.05, 0)));
   sheet->addChildWindow(quit);
   quit->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&BasicTutorial7::quitit, this));
}
bool BasicTutorial7::handleListSelectionChanged(const CEGUI::EventArgs& e)
{
   CEGUI::WindowEventArgs wea( static_cast<const CEGUI::WindowEventArgs& >(e));
   CEGUI::Combobox* combobox = static_cast<CEGUI::Combobox*>(wea.window);
   CEGUI::ListboxItem* selectedItem = combobox->getSelectedItem();
   if (!selectedItem)
        return false;

    switch(selectedItem->getID())
    {
  case 1:
      if(combobox->isActive())
     {
        createKnight(evt);
     }
        createFighter(evt);
   
        break;

    case 2:
      if(combobox->isActive())
     {
        createKnight(evt);
     }
        createKnight(evt);
        break;

    case 3:
      if(combobox->isActive())
     {
        createKnight(evt);
     }
        createPikeman(evt);
        break;

    case 4:
      if(combobox->isActive())
     {
        createKnight(evt);
     }
        createMage(evt);
        break;

    case 5:
      if(combobox->isActive())
     {
        createKnight(evt);
     }
        createPriest(evt);
        break;

    case 6:
      if(combobox->isActive())
     {
        createKnight(evt);
     }
        createRobot(evt);
        break;

    case 7:
      if(combobox->isActive())
     {
        createKnight(evt);
     }
      createNinja(evt);
        break;
      
      
    }

    return true;


   
}

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
    int main(int argc, char *argv[])
#endif
    {
        // Create application object
        BasicTutorial7 app;

        try {
            app.go();
        } catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
            std::cerr << "An exception has occured: " <<
                e.getFullDescription().c_str() << std::endl;
#endif
        }

        return 0;
    }

#ifdef __cplusplus
}
#endif


.H file :

Code: Select all

/*
-----------------------------------------------------------------------------
Filename:    BasicTutorial7.h
-----------------------------------------------------------------------------


This source file is generated by the
   ___                   _              __    __ _                  _
  /___\__ _ _ __ ___    /_\  _ __  _ __/ / /\ \ (_)______ _ _ __ __| |
 //  // _` | '__/ _ \  //_\\| '_ \| '_ \ \/  \/ / |_  / _` | '__/ _` |
/ \_// (_| | | |  __/ /  _  \ |_) | |_) \  /\  /| |/ / (_| | | | (_| |
\___/ \__, |_|  \___| \_/ \_/ .__/| .__/ \/  \/ |_/___\__,_|_|  \__,_|
      |___/                 |_|   |_|                                 
      Ogre 1.7.x Application Wizard for VC10 (July 2011)
      http://code.google.com/p/ogreappwizards/
-----------------------------------------------------------------------------
*/
#ifndef __BasicTutorial7_h_
#define __BasicTutorial7_h_

#include "BaseApplication.h"
#include <cegui.h>
#include <RendererModules/Ogre/CEGUIOgreRenderer.h>




#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../res/resource.h"
#endif


class BasicTutorial7 : public BaseApplication
{
public:
    BasicTutorial7(void);
    virtual ~BasicTutorial7(void);

protected:
   CEGUI::OgreRenderer* mRenderer;
    virtual void createScene(void);
   virtual void createFrameListener(void);
   //Ogre::FrameListener

   virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt);

   //OIS::KeyListener

   virtual bool keyPressed(const OIS::KeyEvent& arg);
   virtual bool keyReleased(const OIS::KeyEvent& arg);

   //OIS::MouseListener

   virtual bool mouseMoved(const OIS::MouseEvent& arg);
   virtual bool mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
   virtual bool mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
   bool createRobot(const CEGUI::EventArgs& e);
   bool createNinja(const CEGUI::EventArgs& e);
   bool createFighter(const CEGUI::EventArgs& e);
   bool createKnight(const CEGUI::EventArgs& e);
   bool createPikeman(const CEGUI::EventArgs& e);
   bool createMage(const CEGUI::EventArgs& e);
   bool createPriest(const CEGUI::EventArgs& e);

   
   bool quitit(const CEGUI::EventArgs& e);
   bool ComboBox(const CEGUI::EventArgs& e);
   void RTT(void);
   void QuitButton(void);
   CEGUI::Combobox* objectComboBox;
   CEGUI::Window* sheet;
   CEGUI::Window* quit;
   CEGUI::EventArgs evt;
   bool handleListSelectionChanged(const CEGUI::EventArgs& e);
   Ogre::SceneNode* node;
   char name[16];
   Ogre::Entity* ent;
   
};

#endif // #ifndef __BasicTutorial7_h_



whenever u get time to reply i appreciate in advance :D
Romulo Romero

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: ComboBox action based on item id

Postby CrazyEddie » Mon Jun 25, 2012 06:58

I understand that you are new to all this, and I ask in return that you understand that most of the questions you are asking are not CEGUI specific and would likely be better answered on other forums. It's not that we prohibit such questions here, but as you can see, the number of people on the CEGUI forum answering questions can be counted on one hand, while other forums have many more people answering questions. I know it all seems harmless enough, but it's all time, and time is valuable ;)

On the issue of the switch and approaches to eliminate that, one of the cleanest alternatives is to subclass CEGUI::ListboxTextItem and have the subclass hold a pointer to a handler function to call (or a functor - you can likely reuse CEGUI::Event::Subscriber here). You would subscribe the Combobox event in the same way as before, but rather than having a switch statement, you simply extract the function or functor from the selected item and call it. This is one of the most generic solutions, and will be useful to many people in many scenarios - which is why I've mentioned it. It is possible that, given some exact requirements, other solutions may be better suited (I'm not going to list all the alternatives, though).

As far as the management of which object is active and should be shown, the approach to use really depends on the eventual intended use. If it is only ever going to show a choice of a set number of mesh objects then it might suggest that pre-loading all the objects you might need to show, and then simply attaching / detaching them from the scene could be the way to go there. You could hold some pointer or reference to the current active object - in order to make that easy to find - and if that is the same as the newly selected object then you would simply do nothing, otherwise detach the current object and attach the newly selected one.

For Ogre specific questions such as why SceneManager::hasEntity does not do what you want, questions about how to specifically attach or detach objects from the scene and other such questions, you would have to ask on the Ogre forums. I know nothing about that side of Ogre at all.

CE.

Blender+C++
Just popping in
Just popping in
Posts: 16
Joined: Sat Jun 23, 2012 01:40
Location: Brazil

Re: ComboBox action based on item id

Postby Blender+C++ » Mon Jun 25, 2012 21:37

hi CrazyEddie,
i appreciate ur patience and for ur time to answer my thread and yeah i know time must be a valueable thing,i bet u work hard tho!! and yeah i completely forgot to post that on the ogre forums,all u said make sense(OFC :D)..but i just realized what i posted was kind of stupid...well my code still remains a little hacky but better than the ungly switch statement was when i last posted here!!
this is what i did :

Code: Select all

bool BasicTutorial7::createPriest(const CEGUI::EventArgs& e)
{
   if(mSceneMgr->hasEntity("Priest"))
   {
      mSceneMgr->destroyAllEntities();
   }
   sprintf(name, "Priest");
   ent = mSceneMgr->createEntity(name, "Mech.mesh");
   if(mSceneMgr->getEntity(name))
   {
      mSceneMgr->destroyAllEntities();
   }
   sprintf(name, "Priest");
   ent = mSceneMgr->createEntity(name, "Mech.mesh");
   node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, -100, -300));
   node->attachObject(ent);
   node->scale(6,6,6);
   
   return true;
}

just added an if statement at the beginning to check again if the entity exists..
but ill defentely try to use the methods u have just described above!
thx for sharing ur ideas tho, as i said ill read it more carefully later and try something new and see if it looks a bit more decent hehe!
well thats it for now, ill see ya next time hopefully asking something about CEGUi LOL ;)( i already have other questions about cegui but ill hold it for later so it wont look like i want everything to be easy hehe and dont wanna sound like i ask thousands of questions at the same time :D..ill try it myself first and then if i dont achieve the desired results ill bug u a little more later or some other day LOL!
Kind regards,
Romulo Romero


Return to “Help”

Who is online

Users browsing this forum: No registered users and 33 guests