Page 1 of 1

[solved]Message box

Posted: Sat Jul 05, 2008 13:45
by K0h4n
i try to create a dialog box or error box or message box (whatever you like to call)

this is a snippet of my code

Code: Select all

//Handle Game GUI
   void GUI(){
      CEGUI::WindowManager *wmgr = CEGUI::WindowManager::getSingletonPtr();
      MainMenuSheet = wmgr->loadWindowLayout((CEGUI::utf8*)"MainMenu.layout");
      OptionMenuSheet  = wmgr->loadWindowLayout( "Option.layout" );
      CreditMenuSheet  = wmgr->loadWindowLayout( "Credit.layout" );
      NewGameMenuSheet  = wmgr->loadWindowLayout( "NewGame.layout" );

      //Window Listener Initialize
      CEGUI::Window *newgame = wmgr->getWindow((CEGUI::utf8*)"MainMenu/NewGameButton");
      CEGUI::Window *option = wmgr->getWindow((CEGUI::utf8*)"MainMenu/OptionButton");
      CEGUI::Window *credit = wmgr->getWindow((CEGUI::utf8*)"MainMenu/CreditButton");
      CEGUI::Window *quit = wmgr->getWindow((CEGUI::utf8*)"MainMenu/QuitButton");
      CEGUI::Window *back = wmgr->getWindow((CEGUI::utf8*)"Option/MenuBack");
      CEGUI::Window *back2 = wmgr->getWindow((CEGUI::utf8*)"Credit/MenuBack");
      CEGUI::Window *back3 = wmgr->getWindow((CEGUI::utf8*)"NewGame/MenuBack");
      CEGUI::Window *william = wmgr->getWindow((CEGUI::utf8*)"NewGame/William");
      CEGUI::Window *balthasar = wmgr->getWindow((CEGUI::utf8*)"NewGame/Balthasar");
      CEGUI::Window *creategame = wmgr->getWindow((CEGUI::utf8*)"NewGame/CreateGame");
      CEGUI::Window *messagebutton = wmgr->getWindow((CEGUI::utf8*)"NewGame/MessageBox/Button");

      //Window Listener Event
      newgame->subscribeEvent(CEGUI::PushButton::EventClicked,
         CEGUI::Event::Subscriber(&TutorialListener::handle_NewGame, this));

      option->subscribeEvent(CEGUI::PushButton::EventClicked,
         CEGUI::Event::Subscriber(&TutorialListener::handle_Option, this));

      credit->subscribeEvent(CEGUI::PushButton::EventClicked,
         CEGUI::Event::Subscriber(&TutorialListener::handle_Credit, this));

      quit->subscribeEvent(CEGUI::PushButton::EventClicked,
          CEGUI::Event::Subscriber(&TutorialListener::quit, this));

      back->subscribeEvent(CEGUI::PushButton::EventClicked,
          CEGUI::Event::Subscriber(&TutorialListener::handle_SubMenuBack, this));

      back2->subscribeEvent(CEGUI::PushButton::EventClicked,
          CEGUI::Event::Subscriber(&TutorialListener::handle_SubMenuBack, this));

      back3->subscribeEvent(CEGUI::PushButton::EventClicked,
          CEGUI::Event::Subscriber(&TutorialListener::handle_SubMenuBack, this));

      william->subscribeEvent(CEGUI::PushButton::EventClicked,
          CEGUI::Event::Subscriber(&TutorialListener::handle_William, this));

      balthasar->subscribeEvent(CEGUI::PushButton::EventClicked,
          CEGUI::Event::Subscriber(&TutorialListener::handle_Balthasar, this));

      creategame->subscribeEvent(CEGUI::PushButton::EventClicked,
          CEGUI::Event::Subscriber(&TutorialListener::handle_CreateGame, this));

      messagebutton->subscribeEvent(CEGUI::PushButton::EventClicked,
          CEGUI::Event::Subscriber(&TutorialListener::handle_MessageBox, this));

      CEGUI::System::getSingleton().setGUISheet(MainMenuSheet);
   }

   bool handle_NewGame(const CEGUI::EventArgs& args){
      CEGUI::System::getSingleton().setGUISheet(NewGameMenuSheet);

      return true;
   }

   bool handle_Option(const CEGUI::EventArgs& args){
      CEGUI::System::getSingleton().setGUISheet(OptionMenuSheet);

      return true;
   }

   bool handle_Credit(const CEGUI::EventArgs& args){
      CEGUI::System::getSingleton().setGUISheet(CreditMenuSheet);

      return true;
   }

   bool handle_SubMenuBack(const CEGUI::EventArgs& args){
      CEGUI::System::getSingleton().setGUISheet(MainMenuSheet);

      return true;
   }

   bool handle_William(const CEGUI::EventArgs& args){
      CEGUI::WindowManager *wmgr = CEGUI::WindowManager::getSingletonPtr();
      CEGUI::Window *william = wmgr->getWindow((CEGUI::utf8*)"NewGame/CharacterName");
      william->setText("William ArmStrong");

      CEGUI::Window *WilliamPic = wmgr->getWindow((CEGUI::utf8*)"NewGame/CharacterView");
      WilliamPic->setProperty("Image", "set:SWTH image:WilliamPic");

      return true;
   }

   bool handle_Balthasar(const CEGUI::EventArgs& args){
      CEGUI::WindowManager *wmgr = CEGUI::WindowManager::getSingletonPtr();
      CEGUI::Window *balthasar = wmgr->getWindow((CEGUI::utf8*)"NewGame/CharacterName");
      balthasar->setText("Balthasar Hond");
      
      CEGUI::Window *balthasarPic = wmgr->getWindow((CEGUI::utf8*)"NewGame/CharacterView");
      balthasarPic->setProperty("Image", "set:SWTH image:BalthasarPic");

      return true;
   }

   bool handle_CreateGame(const CEGUI::EventArgs& args){
      CEGUI::WindowManager *wmgr = CEGUI::WindowManager::getSingletonPtr();
      CEGUI::Window *playername = wmgr->getWindow((CEGUI::utf8*)"NewGame/PlayerName");

      if(playername->getText().empty()){
         CEGUI::Window *messagebox = wmgr->getWindow((CEGUI::utf8*)"NewGame/MessageBox");
         messagebox->activate();
         messagebox->setProperty("Visible","True");
         CEGUI::Window *message = wmgr->getWindow((CEGUI::utf8*)"NewGame/MessageBox/Message");
         message->setText("Please input the player name");
      }

      return true;
   }
   
   bool handle_MessageBox(const CEGUI::EventArgs& args){
      CEGUI::WindowManager *wmgr = CEGUI::WindowManager::getSingletonPtr();
      CEGUI::Window *messagebox = wmgr->getWindow((CEGUI::utf8*)"NewGame/MessageBox");
      messagebox->setProperty("Visible", "False");

      return true;
   }


now in handle_CreateGame function, i want the function to check either the player name has been filled in or not once the player click "create game" button
but i never get the correct "if" statement and always end up with the false statement
i try
playername->getText().empty()
playername->getText().size()
playername->getText().length() == 0
but none of it are working correctly

the button for the window is working fine
the window disappear once i click the button (i make it visible through overlay)
is there any easiest way to create the message button
and make all the other window freeze for a moment (unable to click the other window until the ok button or any button from message box are pressed)

this is the example of window that i want to achive (not the skin but the structure)
link taken from project xenocide screenshot
http://www.cegui.org.uk/gallery/albums/userpics/10158/screenshot_01302006_221507732.jpg

any help is appreciated
thank you

Posted: Sat Jul 05, 2008 16:26
by K0h4n
Oh silly me... :oops:
after a few testing i found the culprit
i think i have a day dreaming while creating this code :roll:
but i still haven't figure it out how to create other window to freeze or cant response to the event until the dialog window is clicked

any help still appreciated
thank you

Posted: Sat Jul 05, 2008 16:37
by K0h4n
well another silly me... :oops:
after a few searching from the website i found out about modal
i just need to add:
messagebox->setModalState(true);
to my code

thank you for any one who read this post
and sorry for wasting your time 8)

Posted: Sun Jul 06, 2008 09:28
by CrazyEddie
Glad you managed to solve your own issues - the 'setModalState' is probably not a well known part of the system :)