[Solved] Disable button

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

Dirso
Not too shy to talk
Not too shy to talk
Posts: 25
Joined: Sun Dec 31, 2006 15:49

[Solved] Disable button

Postby Dirso » Sun Apr 15, 2007 17:23

Hi,

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]
Last edited by Dirso on Sun Apr 29, 2007 01:31, edited 1 time in total.

Pompei2
Home away from home
Home away from home
Posts: 489
Joined: Tue May 23, 2006 16:31

Postby Pompei2 » Sun Apr 15, 2007 22:47

Have you tryed to enable it using the ->setEnabled function ?

Dirso
Not too shy to talk
Not too shy to talk
Posts: 25
Joined: Sun Dec 31, 2006 15:49

Postby Dirso » Sun Apr 15, 2007 23:19

Pompei2 wrote:Have you tryed to enable it using the ->setEnabled function ?

It didn't work :(
It's really weird, because the buttons loaded from .layout work fine.

Dirso

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Mon Apr 16, 2007 08:09

Hi,

i think i ran into the same issue a while ago with showing a window from its hidden state. Can you add 'mWindow->activate()' below this line:

Code: Select all

mWindow->show();


I think the focus is not set correctly when you only show it.

HTH.

Dirso
Not too shy to talk
Not too shy to talk
Posts: 25
Joined: Sun Dec 31, 2006 15:49

Postby Dirso » Sun Apr 29, 2007 01:30

Haha!!!!!

It worked!!! Thank you very very very much!!!!

Dirso.

BTW: Sorry for reposting this question in the advanced forum, I'll flag it as solved as well


Return to “Help”

Who is online

Users browsing this forum: No registered users and 8 guests