Remove all GUI Elements
Posted: Mon Sep 11, 2006 9:37 pm
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
Official forum of the Irrlicht Engine
https://irrlicht.sourceforge.io/forum/
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;
}
}
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;
}
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);
}
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); }
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 ?
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 ?