Game Development Reference
In-Depth Information
comes in handy is in console games when the controller becomes disconnected. Other uses
could be to notify that a game was successfully saved, to confirm some action, such as de-
leting a saved game, etc.
The goal of the message box code is to be straightforward to use, a reasonable approach is
to construct the message box by passing in the configuration settings and calling a Show
function that waits for the message box to return with some result value from the user, un-
fortunately, it is rarely this simple. Usually in games we can't simply stop the execution of
the game code and wait in some loop for some action to occur, the situation is more delic-
ate if the game update loop is running in a different thread than the rendering loop.
The message box that we will design is modal, meaning that the user is required to interact
with it before the game can return to its previous state. This means that when we open a
message box, we will have to pause the game. The pausing mechanic is specific to each
game, though usually, it involves a function we can call to request the game to pause, or in
some cases it is a message we broadcast or in more frightening cases, it's a global boolean
variable we toggle.
void save_system::DeleteSavedGame(const std::wstring& saveGameURI)
{
game::RequestGamePause();
ui::MessageBox msg(L”Are you sure you wish to delete this saved game?”, ui::MessageBox::YesNo, saveGameURI,
&save_system::OnConfirmDelete);
msg.Show();
}
...
void save_system::OnComfirmDelete(const MessageBox<const std::wstring&>& msgBox)
{
if ( msgBox.Result() == ui::MessageBox::Yes )
{
const std::wstring& saveGameURI = msgBox.Data();
Delete(saveGameURI);
}
game::RequestResume();
}
From a usability perspective, message boxes should not spawn new message boxes,
however should that be necessary, it's important to keep a stack of any modal message
boxes opened.
Remember that a stack is a last-in, first-out operation. This means that as each modal mes-
sage box is opened it will be pushed to the stack when the user closest the top-most mes-
sage box, it will be popped from the stack until there are no more open message boxes.
Search WWH ::




Custom Search