MyGUI and Game States

razali2k5

14-05-2010 22:44:18

The game I am working on has several different "states" (as part of a Finite State Automaton). Transitions between states are controlled via a Game Manager whose internal structure is simply a stack. For example, pressing "Play" in the MenuState would pop a PlayState on the stack. Anyway, I am having trouble integrating MyGUI into this architecture.

When I was using QuickGUI, I basically created a new QuickGUIManager in each state I wanted to display GUI components. However, this idea doesn't work well with MyGUI.

In my MenuState, this is how I initialize GUI:
mPlatform = new MyGUI::OgrePlatform();
mPlatform->initialise(mRoot->getAutoCreatedWindow(), mSceneMgr, "General", getWriteDir()+"\\MyGUI.log");
mGUI = new MyGUI::Gui();
mGUI->initialise("core.xml",getWriteDir()+"\\MyGUI.log");


Adding the above code to the PlayState does not work. I have tried this approach for PlayState:
MyGUI::OgreRenderManager * renderManager = MyGUI::OgreRenderManager::getInstancePtr();
renderManager->setRenderWindow(mWindow);
renderManager->setSceneManager(mSceneMgr);


How can I integrate MyGUI so I can have different GUI layouts loaded and displayed depending on the state? I do not want to do any manual hiding of windows. I just want to have something equivalent to having different GUI managers working so each can display its own thing whenever in its state.

kamaliang

15-05-2010 02:23:13

Maybe you can make a Panel widget as the parent of other widgets for each gamestate , you can just hide the Panel when you change a gamestate and show the next gamestate's panel... :oops:

razali2k5

15-05-2010 19:43:40

Maybe you can make a Panel widget as the parent of other widgets for each gamestate , you can just hide the Panel when you change a gamestate and show the next gamestate's panel... :oops:

Each game state has its own camera and viewport. Namely, the game states are truly independent from each other. I cannot simply use a MyGUI singleton unless I can change all the necessary info which I tried in my second solution above, but that doesn't work. Thanks for the suggestion though.

shmafoozius

16-05-2010 07:40:57

You should just load layouts and assign the scene manager to mygui on state creation and when changing unload the layout.
I do something like this
[Intro State]
@Startup
* tell mygui which scene manager to use (MyGUI::OgreRenderManager::getInstance().setSceneManager())
* load a layout (MyGUI::LayoutManager::getInstance().load())
* update/handle the layout as wanted while state is running

@Shutdown of the state:
* Either assign the new scene manager to mygui or temporarily set another "fake" scene manager (otherwise it may crash)
* unload the layout (MyGUI::LayoutManager::getInstance().unloadLayout())
* If there were widgets created in runtime, remove them as well
* Start the new state and do the same @Startup as with the [Intro State]

I'm sure there are better ways to handle this (I'm a bloody noob), but I hope this helps.

razali2k5

20-05-2010 01:03:18

You should just load layouts and assign the scene manager to mygui on state creation and when changing unload the layout.
I do something like this
[Intro State]
@Startup
* tell mygui which scene manager to use (MyGUI::OgreRenderManager::getInstance().setSceneManager())
* load a layout (MyGUI::LayoutManager::getInstance().load())
* update/handle the layout as wanted while state is running

@Shutdown of the state:
* Either assign the new scene manager to mygui or temporarily set another "fake" scene manager (otherwise it may crash)
* unload the layout (MyGUI::LayoutManager::getInstance().unloadLayout())
* If there were widgets created in runtime, remove them as well
* Start the new state and do the same @Startup as with the [Intro State]

I'm sure there are better ways to handle this (I'm a bloody noob), but I hope this helps.


Shmafoozius,

Many thanks for that! Your solution works well. However, like you said, a temporary scene manager must be set or else it crashes. Is there a way to get around that? The way it is being handled right now, the MainMenuState is never destroyed and its SceneManager is publicly available as a temporary placeholder between states. However, this looks bad and I would like to avoid it.

How do I create a "fake" scene manager which lives even after a state is destroyed but before the other state sets its own scene manager?

Altren

20-05-2010 12:28:30

You can use nullptr instead of fake scene manager, so set no scene manager.
MyGUI::OgreRenderManager::getInstance().setSceneManager(nullprt);