Page 1 of 1

Menu System

Posted: Tue Jun 22, 2010 14:25
by rtr_18
Hi!
I've to prepare a menu. In which I've to load four buttons in the initial page. If I click one button(e.g. Play button) the menu has to load with
two image holders and two buttons(back and next buttons). If I click the back button, I should be able to go to the initial page. Similarly next button
should take to the next page. For this purpose I wrote the following code:

Code: Select all

#include "irrlicht.h"
#include "CEGUI.h"
#include "CEGUIIrrlichtRenderer.h"
#include "CEGUIWindowManager.h"
#include "CEGUIExceptions.h"
#include "CEGUIDefaultResourceProvider.h"
#include "CEGUIButtonBase.h"
#include "CEGUIInputEvent.h"
#include "CEGUIEventArgs.h"
#include "CEGUIWindow.h"

using namespace std;
using namespace CEGUI;
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
class InitialMenu
{
 private:
        WindowManager* wmgr;
       Window* myRoot, *playWnd;
       FrameWindow* fWnd;
      DefaultResourceProvider* rp;
     CEGUI::PushButton* play_btn, *options_btn, *credits_btn, *exit_btn;
     CEGUI::Image* playercty_img, *oppcty_img;
     CEGUI::Combobox* playercty_cbo, *oppcty_cbo;
     CEGUI::PushButton* playMnuBack_btn, *playMnuNext_btn;
 public:
      InitialMenu()
      {
                    rp = static_cast<DefaultResourceProvider*>(System::getSingleton().getResourceProvider());
       rp->setResourceGroupDirectory ("schemes", "datafiles/schemes/");
                    rp->setResourceGroupDirectory ("imagesets", "datafiles/imagesets/");
                    rp->setResourceGroupDirectory ("fonts", "datafiles/fonts/");
                    rp->setResourceGroupDirectory ("layouts", "datafiles/layouts/");
                    rp->setResourceGroupDirectory ("looknfeel", "datafiles/looknfeel/");
                    rp->setResourceGroupDirectory ("lua_scripts", "../datafiles/lua_scripts/");
       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","schemes" );
                    FontManager::getSingleton().createFreeTypeFont("DejaVuSans-10.font",10,false, "DejaVuSans.ttf");
                   WidgetLookManager::getSingleton().parseLookNFeelSpecification("TaharezLook.looknfeel", "looknfeel");
                   wmgr = WindowManager::getSingletonPtr();
      myRoot = wmgr->createWindow("DefaultWindow", "root");
      System::getSingleton().setGUISheet(myRoot);
      fWnd = (FrameWindow*)wmgr->createWindow("TaharezLook/FrameWindow", "");
                  fWnd->setPosition(UVector2(UDim(0.25f, 0.0f), UDim(0.25f, 0.0f)));
                 fWnd->setSize(UVector2(UDim(0.5f, 0.5f), UDim(0.5f, 0.5f)));
                 fWnd->setText("Hello World!");
                 myRoot->addChildWindow(fWnd);
                 play_btn = (PushButton*) wmgr->createWindow("TaharezLook/Button", "play_btn");
                 options_btn = (PushButton*) wmgr->createWindow("TaharezLook/Button", "options_btn");
                 credits_btn = (PushButton*) wmgr->createWindow("TaharezLook/Button", "credits_btn");
                 exit_btn = (PushButton*) wmgr->createWindow("TaharezLook/Button", "exit_btn");
                 fWnd->addChildWindow(play_btn);
                 fWnd->addChildWindow(options_btn);
                 fWnd->addChildWindow(credits_btn);
                 fWnd->addChildWindow(exit_btn);
                 play_btn->setPosition(UVector2(UDim(0.25f, 0.25f), UDim(0.25f, 0.25f)));
                play_btn->setSize(UVector2(UDim(0.15f, 0.15f), UDim(0.15f, 0.15f)));
               options_btn->setPosition(UVector2(UDim(0.02f, 11.5f), UDim(0.05f, 11.5f)));
               options_btn->setSize(UVector2(UDim(0.15f, 0.15f), UDim(0.15f, 0.15f)));
               credits_btn->setPosition(UVector2(UDim(0.3f, 0.3f), UDim(0.3f, 0.3f)));
               credits_btn->setSize(UVector2(UDim(0.15f, 0.15f), UDim(0.15f, 0.15f)));
               exit_btn->setPosition(UVector2(UDim(0.39f, 0.6f), UDim(0.39f, 0.6f)));
               exit_btn->setSize(UVector2(UDim(0.15f, 0.15f), UDim(0.15f, 0.15f)));
               System::getSingleton().setDefaultFont("DejaVuSans-10.font");
               System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
               System::getSingleton().setDefaultTooltip("TaharezLook/Tooltip");
               play_btn->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&InitialMenu::playHandler, this));
               options_btn->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&InitialMenu::optionsHandler, this));
                credits_btn->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&InitialMenu::creditsHandler, this));
   exit_btn->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&InitialMenu::exitHandler, this));
   }

      bool playHandler()
      {
       wmgr = WindowManager::getSingletonPtr();
       playWnd = (FrameWindow*)wmgr->createWindow("TaharezLook/FrameWindow", "");
                    playWnd->setPosition(UVector2(UDim(0.25f, 0.0f), UDim(0.25f, 0.0f)));
                    playWnd->setSize(UVector2(UDim(0.5f, 0.5f), UDim(0.5f, 0.5f)));
       System::getSingleton().setGUISheet(playWnd);
       playercty_img = (Image*) wmgr->createWindow("TaharezLook/Image", "playercty_img");
       oppcty_img = (Image*) wmgr->createWindow("TaharezLook/Image", "oppcty_img");
       playercty_cbo = (Combobox*) wmgr->createWindow("TaharezLook/Combobox", "playercty_cbo");
       oppcty_cbo = (Combobox*) wmgr->createWindow("TaharezLook/Combobox", "oppcty_cbo");
       playMnuBack_btn = (PushButton*) wmgr->createWindow("TaharezLook/Button", "playMnuBack_btn");
       playMnuNext_btn = (PushButton*) wmgr->createWindow("TaharezLook/Button", "playMnuNext_btn");
       playWnd->addChildWindow(playercty_img->getName());
       playWnd->addChildWindow(oppcty_img->getName());
       playWnd->addChildWindow(playercty_cbo);
       playWnd->addChildWindow(oppcty_cbo);
       playWnd->addChildWindow(playMnuBack_btn);
       playWnd->addChildWindow(playMnuNext_btn);
       return false;
      }

      bool optionsHandler()
      {
       return false;
      }
      
      bool creditsHandler()
      {
       return false;
      }

      bool exitHandler()
      {
       return false;
      }

};

int main ()
{
 IrrlichtDevice* device = createDevice(EDT_DIRECT3D9, core::dimension2d<u32>(800, 600), 16, false);
 CEGUI::IrrlichtRenderer &myRenderer = CEGUI::IrrlichtRenderer::bootstrapSystem(*device);

 IVideoDriver* driver = device->getVideoDriver();
 ISceneManager* smgr = device->getSceneManager();

InitialMenu* initMenu = new InitialMenu();
 
 while(device->run() && driver)
 {
  if(device->isWindowActive())
  {
   driver->beginScene(true, true, SColor(255, 255, 0, 0));
   smgr->drawAll();
   CEGUI::System::getSingleton().renderGUI();
   driver->endScene();
  }
 }
 
 device->drop();
 return 0;
}



(i)Is this the right way to acheive my task?

(ii)While subscribing to events I got the following errors:

1>------ Build started: Project: CricCEGUI, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>e:\criccegui\main.cpp(75) : error C2661: 'CEGUI::SubscriberSlot::SubscriberSlot' : no overloaded function takes 2 arguments
1>e:\criccegui\main.cpp(76) : error C2661: 'CEGUI::SubscriberSlot::SubscriberSlot' : no overloaded function takes 2 arguments
1>e:\criccegui\main.cpp(77) : error C2661: 'CEGUI::SubscriberSlot::SubscriberSlot' : no overloaded function takes 2 arguments
1>e:\criccegui\main.cpp(78) : error C2661: 'CEGUI::SubscriberSlot::SubscriberSlot' : no overloaded function takes 2 arguments
1>Build log was saved at "file://e:\CricCEGUI\Debug\BuildLog.htm"
1>CricCEGUI - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

What to do to get around these errors?

Re: Menu System

Posted: Tue Jun 29, 2010 23:55
by Jamarr
I can almost guarantee you the reason CE has not bothered to assist you is because you posted this thread in multiple forums. You are only hurting yourself with this behavior, as it is highly frowned upon. Posting in multiple forums will only decrease your chances of receiving help. Your threads will be read, there is no need to pollute/spam the forum with duplicate topics. If you continue to do so, you will be banned. Show respect for the community, and you will be given respect (and answers) in return ;)