Remove all GUI Elements
Remove all GUI Elements
Hi,
is there an easy way to remove all GUI Elements?
Bye,
Rikyoh
is there an easy way to remove all GUI Elements?
Bye,
Rikyoh
I guess you could set a flag to stop calling environment->drawAll(); in your irrlicht loop.
Although this prevents you from showing other gui menus later in your game. The way I do it is just to create seperate functions. Like showmenu() will set all the menu elements visible to true, hidemenu() sets them invisible. showpausemenu() sets the pause menu items visible, hidepausemenu, etc. etc.
Code: Select all
bool removegui = false;
while(device->run())
{
driver->beginScene(true, true, 0);
if(!removegui)
{
guienvironment->drawAll();
}
driver->endScene();
}
//
OnEvent(SEvent event)
{
if(KEY_SPACE)
{
removegui = true;
}
}
I forgot where abouts I found this on the forums, and who the code is by, but it has worked for me thus far. If anyone can tell who the credits goto that would be appriciated.
Code: Select all
bool CApplication::clearGUIElements()
{
irr::core::list<irr::gui::IGUIElement*> hElementList = g_pGlobals->pGUI->getRootGUIElement()->getChildren();
if(hElementList.empty())
{
return false;
}
while(!hElementList.empty())
{
(*(hElementList.getLast()))->remove();
}
return true;
}
if you set drawall off, you can still click the buttons i would say....
Compete or join in irrlichts monthly screenshot competition!
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Hi,
tanks for your replies. In my game I have several gamestates which all need different "setups" of scenenodes and guielements, so when I switch from one state to the other I want to first delete all elements of the old state and then create the elements needed for the new state. Thats no problem with the scene because there is a "clear()" function. Not to draw the gui-elements is no solution for me, because I need gui-elemtents in every gamestate. But the function AlexL posted seems to be what I need.
Update: it doesn't work! The "remove()" removes the gui-element, but the size of the list doesn't decrement and so the list never gets empty and I have endless loop. I think there must some code be added to delete the listmember after removing the gui element. Something with iterator... but I don't get it to work
Bye,
Rikyoh
tanks for your replies. In my game I have several gamestates which all need different "setups" of scenenodes and guielements, so when I switch from one state to the other I want to first delete all elements of the old state and then create the elements needed for the new state. Thats no problem with the scene because there is a "clear()" function. Not to draw the gui-elements is no solution for me, because I need gui-elemtents in every gamestate. But the function AlexL posted seems to be what I need.
Update: it doesn't work! The "remove()" removes the gui-element, but the size of the list doesn't decrement and so the list never gets empty and I have endless loop. I think there must some code be added to delete the listmember after removing the gui element. Something with iterator... but I don't get it to work
Bye,
Rikyoh
It doesn't work because you've made a copy of the list and you're iterating over the copy, but removing from the original. The code should look like this...
If you are going to maintain multiple sets of UI, it may make sense to do something like this...
I would wrap all of that up into a game management class. It allows you to enable/disable an entire game state without needing to rebuild the scene/gui every time the user switches.
Code: Select all
// notice that this is a reference to the list maintained by the root element
const core::list<IGUIElement*>& children = Environment->getRootGUIElement()->getChildren();
while (!children.empty())
(*children.getLast())->remove();
Code: Select all
struct SGameState
{
IGUIElement* UserInterface;
ISceneNode* Scene;
};
enum E_GAME_STATE { EGS_INVENTORY, EGS_PLAYING, EGS_COUNT };
SGameState AvailableGameStates[EGS_COUNT];
SGameState* ActiveGameState = 0;
// somewhere in your init code
u32 s;
for (s = 0; s < EGS_COUNT; ++s)
{
AvailableGameStates[s].UserInterface = new IGUIElement(EGUIET_ELEMENT, Environment, Environment->getRootSceneNode(), -1, FullWindowRect);
AvailableGameStates[s].Scene = SceneManager->addEmptySceneNode();
}
AvailableGameStates[s].UserInterface = 0;
AvailableGameStates[s].Scene = 0;
ActiveGameState = &AvailableGameStates[0];
// add controls to each of the user interfaces...
// method for changing ui
void setActiveGameState(E_GAME_STATE egs)
{
ActiveGameState->UserInterface->setVisible(false);
ActiveGameState->Scene ->setVisible(false);
ActiveGameState = &AvailableGameStates[egs];
ActiveGameState->UserInterface->setVisible(true);
ActiveGameState->Scene ->setVisible(true);
}
Hello,
thanks, the removing of GUI Elements seems to work know. Your idea for maintaining multiple sets of UI and Scenenodes looks very interesting and would fit easy into my actual design, but wouldn't that have an impact on performance? If I have two very complex scenes and only deactivate the visibility of one of them for example?
Bye
Riky
thanks, the removing of GUI Elements seems to work know. Your idea for maintaining multiple sets of UI and Scenenodes looks very interesting and would fit easy into my actual design, but wouldn't that have an impact on performance? If I have two very complex scenes and only deactivate the visibility of one of them for example?
Bye
Riky
-
- Posts: 40
- Joined: Tue Aug 15, 2006 6:01 am
- Location: Hong Kong
- Contact:
how to remove all GUI elements in C# ?? please help .
i opened a thread here :
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=16935
i opened a thread here :
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=16935
Irrlicht.NET user
* * * * * * * * * * * * *
Currently working on:
RPG Turbulence 2
Game Engine Turbulence Engine
* * * * * * * * * * * * *
Currently working on:
RPG Turbulence 2
Game Engine Turbulence Engine
-
- Posts: 40
- Joined: Tue Aug 15, 2006 6:01 am
- Location: Hong Kong
- Contact:
can u translate the code to C# ? i think some functions in C++ does not exist in Irrlicht .NET . true ?vitek wrote:It doesn't work because you've made a copy of the list and you're iterating over the copy, but removing from the original. The code should look like this...
If you are going to maintain multiple sets of UI, it may make sense to do something like this...Code: Select all
// notice that this is a reference to the list maintained by the root element const core::list<IGUIElement*>& children = Environment->getRootGUIElement()->getChildren(); while (!children.empty()) (*children.getLast())->remove();
I would wrap all of that up into a game management class. It allows you to enable/disable an entire game state without needing to rebuild the scene/gui every time the user switches.Code: Select all
struct SGameState { IGUIElement* UserInterface; ISceneNode* Scene; }; enum E_GAME_STATE { EGS_INVENTORY, EGS_PLAYING, EGS_COUNT }; SGameState AvailableGameStates[EGS_COUNT]; SGameState* ActiveGameState = 0; // somewhere in your init code u32 s; for (s = 0; s < EGS_COUNT; ++s) { AvailableGameStates[s].UserInterface = new IGUIElement(EGUIET_ELEMENT, Environment, Environment->getRootSceneNode(), -1, FullWindowRect); AvailableGameStates[s].Scene = SceneManager->addEmptySceneNode(); } AvailableGameStates[s].UserInterface = 0; AvailableGameStates[s].Scene = 0; ActiveGameState = &AvailableGameStates[0]; // add controls to each of the user interfaces... // method for changing ui void setActiveGameState(E_GAME_STATE egs) { ActiveGameState->UserInterface->setVisible(false); ActiveGameState->Scene ->setVisible(false); ActiveGameState = &AvailableGameStates[egs]; ActiveGameState->UserInterface->setVisible(true); ActiveGameState->Scene ->setVisible(true); }
Irrlicht.NET user
* * * * * * * * * * * * *
Currently working on:
RPG Turbulence 2
Game Engine Turbulence Engine
* * * * * * * * * * * * *
Currently working on:
RPG Turbulence 2
Game Engine Turbulence Engine
-
- Posts: 40
- Joined: Tue Aug 15, 2006 6:01 am
- Location: Hong Kong
- Contact:
the constructor of IGUIElement is VERY different from C++ and it cannot be implemented in C# . it cannot follow the code as two libraries are totally differrentvitek wrote:I don't know, can you? Try it and find out, it's only a few lines of code.can u translate the code to C# ? i think some functions in C++ does not exist in Irrlicht .NET . true ?
public IGUIElement(
IGUIElement* element
);
Irrlicht.NET user
* * * * * * * * * * * * *
Currently working on:
RPG Turbulence 2
Game Engine Turbulence Engine
* * * * * * * * * * * * *
Currently working on:
RPG Turbulence 2
Game Engine Turbulence Engine