I have a few helper/wrapper classes to make my work easier, following some walaber samples. If I load the layout from a file, it works fine but if I create them through code, when I show the BasicDialog all hard coded created buttons are not clickable anymore. What could I be doing wrong?
GuiObj.h
Code: Select all
#ifndef __GUIOBJ_H__
#define __GUIOBJ_H__
#include <CEGUI.h>
#include "GameState.h"
///////////////////////////////////////////////////////////
// class StandardButton
// definition: use this class to create standart buttons
// with the playsound function already subscribed
class StandardButton
{
CEGUI::PushButton* mButton;
public:
StandardButton(GameState* state, CEGUI::Window* parentwin,
CEGUI::String layout, CEGUI::String name, CEGUI::String text,
CEGUI::UVector2 pos, CEGUI::UVector2 size)
{
using namespace CEGUI;
mButton = (PushButton*)WindowManager::getSingleton().createWindow(layout + (utf8*)"/Button", name );
mButton->setText( text );
mButton->setPosition(pos);
mButton->setSize(size);
mButton->setVisible(true);
_owner = state;
assignPlayClickSound();
parentwin->addChildWindow(mButton);
}
StandardButton(GameState* state, CEGUI::String name)
{
using namespace CEGUI;
_owner = state;
mButton = (PushButton*)state->GetCEGUIControlByName(name);
assignPlayClickSound();
}
~StandardButton()
{
using namespace CEGUI;
WindowManager::getSingleton().destroyWindow( mButton );
}
CEGUI::PushButton* getButton() { return mButton; }
void setText(CEGUI::String text) { mButton->setText(text); }
bool playClickSound( const CEGUI::EventArgs& e )
{
return _owner->playClickSound(e);
}
void assignPlayClickSound()
{
using namespace CEGUI;
mButton->subscribeEvent( PushButton::EventClicked,
Event::Subscriber( &StandardButton::playClickSound, this));
}
GameState *_owner;
};
///////////////////////////////////////////////////////////
// class BasicDialog
// definition: this is the base for any dialog for the game
class BasicDialog
{
public:
BasicDialog(GameState* state, CEGUI::Window* parentwin, CEGUI::String& layout,
CEGUI::String& basename, CEGUI::String labelOK, CEGUI::String labelCancel,
bool bSizeable, bool bCloseButton)
{
using namespace CEGUI;
// vars
mWasOkClicked = false;
_owner = state;
// create the window
mWindow = (FrameWindow*)WindowManager::getSingleton().createWindow(layout + (utf8*)"/FrameWindow", basename+"/Window" );
parentwin->addChildWindow( mWindow );
mWindow->setCloseButtonEnabled(bCloseButton);
mWindow->setSizingEnabled(bSizeable);
mWindow->setPosition(UVector2(UDim(0.3, 0.0), UDim(0.35, 0)));
mWindow->setSize(UVector2(UDim(0.4, 0.0), UDim(0.3, 0)));
mButtonOK = new StandardButton(state, mWindow, layout, basename + "/OK",
"OK", UVector2(UDim(0.0, 0.0), UDim(0.35, 0)), UVector2(UDim(0.2, 0.0), UDim(0.3, 0)));
mButtonCancel = new StandardButton(state, mWindow, layout, basename + "/Cancel",
"Cancel", UVector2(UDim(0.3, 0.0), UDim(0.35, 0)), UVector2(UDim(0.2, 0.0), UDim(0.3, 0)));
mButtonOK->getButton()->subscribeEvent( PushButton::EventClicked, Event::Subscriber(&BasicDialog::okClicked, this) );
mButtonCancel->getButton()->subscribeEvent( PushButton::EventClicked, Event::Subscriber(&BasicDialog::cancelClicked, this) );
hide();
}
BasicDialog(GameState *state, CEGUI::String name,
CEGUI::String OKname, CEGUI::String CancelName)
{
using namespace CEGUI;
_owner = state;
mWindow = (FrameWindow*)state->GetCEGUIControlByName(name);
mButtonCancel = new StandardButton(state, CancelName);
mButtonOK = new StandardButton(state, OKname);
}
virtual ~BasicDialog()
{
// cleanup.
using namespace CEGUI;
delete mButtonOK;
delete mButtonCancel;
WindowManager::getSingleton().destroyWindow( mWindow );
}
void setButtonText(Ogre::String &ok, Ogre::String &cancel)
{
mButtonOK->setText(ok);
mButtonCancel->setText(cancel);
}
virtual void show( Ogre::String& text, Ogre::String& msg )
{
mWasOkClicked = false;
mWindow->setText( (std::string)text );
mWindow->show();
}
virtual void hide()
{
mWindow->hide();
}
bool wasOkClicked() { return mWasOkClicked; }
CEGUI::FrameWindow* getCEGUIWindow() { return mWindow; }
private:
bool okClicked( const CEGUI::EventArgs& e )
{
mWasOkClicked = true;
hide();
return true;
}
bool cancelClicked( const CEGUI::EventArgs& e )
{
hide();
return true;
}
public:
bool mWasOkClicked;
bool mPlaySounds;
CEGUI::FrameWindow* mWindow;
StandardButton* mButtonOK;
StandardButton* mButtonCancel;
GameState *_owner;
};
#endif
IntroState.cpp
Code: Select all
void IntroState::createGUI()
{
// create gui interface
loadGUIxml("OceanDemoLayout.xml");
// create manual buttons
btnQuitMe = new StandardButton(this, mEditorGuiSheet,
"TaharezLook", "QuitMe", "Quit Me Now !",
CEGUI::UVector2(CEGUI::UDim(0.8, -1.0), CEGUI::UDim(0.9, -0.5)),
CEGUI::UVector2(CEGUI::UDim(0.2, -1.0), CEGUI::UDim(0.1, -0.5)));
dlgQuit = new BasicDialog(this, mEditorGuiSheet, CEGUI::String("TaharezLook"),
CEGUI::String("DlgQuit"), CEGUI::String("OK"), CEGUI::String("Cancel"),
false, false);
btnExitGame = new StandardButton(this, (CEGUI::utf8*)"ExitDemoBtn");
}
void IntroState::setupGUIhandlers()
{
// assign methods
btnExitGame->getButton()->subscribeEvent( CEGUI::PushButton::EventClicked,
CEGUI::Event::Subscriber( &IntroState::handleExitGameClicked, this));
}
bool IntroState::handleExitGameClicked( const CEGUI::EventArgs& e )
{
dlgQuit->show(Ogre::String("teste"), Ogre::String("Do you really wanna quit?"));
return true;
}
[code]