is a window allready present?

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

Ninja
Quite a regular
Quite a regular
Posts: 86
Joined: Sun Aug 20, 2006 11:42

is a window allready present?

Postby Ninja » Sun Sep 10, 2006 15:29

Hi guys

how can i make it so that if a button has been pressed and a window opened that if i then repress the button i wont get an exception error

like this one

(Error) Exception: GUILayout_xmlHandler::startElement - layout loading has been aborted since Window named 'setup1' already exists.


i,ve tried editing the line in the layout so no name is present but that just opens new windows and isnt what i need

TIA

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Sun Sep 10, 2006 16:04

do you need the button to open a new window? (a "clone", but with different internal name) then the loadWindowLayout has a parameter for prepending a prefix to the names.

If you want the button to do nothing if the window exists, I suggest using WindowManager to check if it exists. isWindowPresent IIRC

HTH

Ninja
Quite a regular
Quite a regular
Posts: 86
Joined: Sun Aug 20, 2006 11:42

Postby Ninja » Sun Sep 10, 2006 16:07

heya Lindquist

i would like the button to do nothing if the window is allready opened

from my button i have at the moment

Code: Select all

bool HandleButtonSetUp(const CEGUI::EventArgs& e)
{   
   using namespace CEGUI;
   
// Retrieve the window manager
  WindowManager& winMgr = WindowManager::getSingleton();   
 
  // Load the layout
   Window* setup = winMgr.loadWindowLayout("art/Common/SetUp.layout");
  // call the close button to close the window :P
  setup->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(handleCloseButton));
  if (winMgr.isWindowPresent("background_wnd"))
  {    
    Window* background = (winMgr.getWindow("background_wnd"));
    background->addChildWindow(setup);    
   
  }
  return true;   
}


do i need to add a class or something ?

TIA

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Sun Sep 10, 2006 16:19

use winMgr.isWindowPresent on the name of the window created by your SetUp.layout. if this exists do nothing

HTH

Ninja
Quite a regular
Quite a regular
Posts: 86
Joined: Sun Aug 20, 2006 11:42

Postby Ninja » Sun Sep 10, 2006 16:31

heya

Sorry not sure i understand here in the layout file i have

Code: Select all

<?xml version="1.0" ?>
<GUILayout>
             <Window Type="TaharezLook/FrameWindow" Name="setup1">
            <Property Name="RelativeMinSize" Value="w:0.2 h:0.2" />
            <Property Name="RelativeMaxSize" Value="w:0.8 h:0.8" />
            <Property Name="Position" Value="x:0.2 y:0.2" />
            <Property Name="Size" Value="w:0.5 h:0.5" />
            <Property Name="Text" Value="Setup" />
            <Property Name="CloseButtonEnabled" Value="True"  />
            <Property Name="Alpha" Value="0.8" />
    </Window>

</GUILayout>


so in name i would add winMgr.isWindowPresent ?

TIA

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 » Sun Sep 10, 2006 16:53

No,

your code need to become like this:

Code: Select all

// Only load the layout with "setup1" when not already done
if (!winMgr.isWindowPresent("setup1"))
  // Load the layout
  Window* setup = winMgr.loadWindowLayout("art/Common/SetUp.layout");


HTH

Ninja
Quite a regular
Quite a regular
Posts: 86
Joined: Sun Aug 20, 2006 11:42

Postby Ninja » Sun Sep 10, 2006 17:19

heya ScripKid

so the code becomes

Code: Select all

bool HandleButtonSetUp(const CEGUI::EventArgs& e)
{   
   using namespace CEGUI;
// Retrieve the window manager
  WindowManager& winMgr = WindowManager::getSingleton();
 
 // Only load the layout with "setup1" when not already done
if (!winMgr.isWindowPresent("setup1"))
  // Load the layout
  Window* setup = winMgr.loadWindowLayout("art/Common/setup.layout"); 
 
  // call the close button to close the window :P
  setup->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(handleCloseButton));
  if (winMgr.isWindowPresent("background_wnd"))
  {
    Window* background = (winMgr.getWindow("background_wnd"));
    background->addChildWindow(setup);
  }

  return true;   
}


TIA

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Sun Sep 10, 2006 18:07

this code is still not good as the FrameWindow::EventCloseClicked event will be subscribed every time the button is clicked, resulting in multiple subscriptions.

Code: Select all

bool HandleButtonSetUp(const CEGUI::EventArgs& e)
{   
   using namespace CEGUI;
// Retrieve the window manager
  WindowManager& winMgr = WindowManager::getSingleton();
 
 // Only load the layout with "setup1" when not already done
  if (winMgr.isWindowPresent("setup1"))
    return false;

  // Load the layout
  Window* setup = winMgr.loadWindowLayout("art/Common/setup.layout");
 
  // call the close button to close the window :P
  setup->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(handleCloseButton));
  if (winMgr.isWindowPresent("background_wnd"))
  {
    Window* background = (winMgr.getWindow("background_wnd"));
    background->addChildWindow(setup);
  }

  return true;   
}

Ninja
Quite a regular
Quite a regular
Posts: 86
Joined: Sun Aug 20, 2006 11:42

Postby Ninja » Mon Sep 11, 2006 00:04

Thanks guys

i now have

Code: Select all

  WindowManager& winMgr = WindowManager::getSingleton();
if (!winMgr.isWindowPresent("setupwindow"))
  // Load the layout
  Window* setup = winMgr.loadWindowLayout("art/common/setup.layout");
  // call the close button to close the window
WindowManager::getSingleton().getWindow("setupwindow")->
  subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(handleCloseButton));
  if (winMgr.isWindowPresent("background_wnd"))
  {
    Window* background = (winMgr.getWindow("background_wnd"));
    background->addChildWindow("setupwindow");
  }

  return true;   
}


and it works like a charm :P

just need to work out a way that if a diffrrent window is called with another allready opened that the first window stays active aswell as at the present if two windows open then the first window thats called all its functions disapear ie nothing works on it cant even drag it

Thanks again


Return to “Help”

Who is online

Users browsing this forum: No registered users and 33 guests