| 1 |
// NS_MenuManager.cpp: implementation of the NS_MenuManager class. |
| 2 |
// |
| 3 |
////////////////////////////////////////////////////////////////////// |
| 4 |
|
| 5 |
#include "NS_MenuManager.h" |
| 6 |
#include "NS_MenuGeneric.h" |
| 7 |
#include "NS_Menu_Main.h" |
| 8 |
#include "NS_Menu_Credits.h" |
| 9 |
#include "NS_Menu_Play.h" |
| 10 |
#include "NS_Menu_Game.h" |
| 11 |
|
| 12 |
#include <iostream> |
| 13 |
|
| 14 |
// needed for mouse hack :(( |
| 15 |
#include <ClanLib/display.h> |
| 16 |
#include <ClanLib/core.h> |
| 17 |
|
| 18 |
////////////////////////////////////////////////////////////////////// |
| 19 |
// Construction/Destruction |
| 20 |
////////////////////////////////////////////////////////////////////// |
| 21 |
|
| 22 |
NS_MenuManager::NS_MenuManager(CL_ResourceManager & resource, |
| 23 |
CL_StyleManager & style_manager) |
| 24 |
: resource(resource), |
| 25 |
style_manager(style_manager), |
| 26 |
running(false), |
| 27 |
current_menu(0) |
| 28 |
{ |
| 29 |
menus["menu_main"] = new NS_Menu_Main(*this, style_manager, "Graphics/menu_main.xml"); |
| 30 |
menus["menu_credits"] = new NS_Menu_Credits(*this, style_manager, "Graphics/menu_credits.xml"); |
| 31 |
menus["menu_play"] = new NS_Menu_Play(*this, style_manager, "Graphics/menu_play.xml"); |
| 32 |
menus["menu_game"] = new NS_Menu_Game(*this, style_manager, "Graphics/menu_game.xml"); |
| 33 |
|
| 34 |
for(MCont_t::iterator it = menus.begin(); it != menus.end(); ++it) |
| 35 |
it->second->disable_input(); |
| 36 |
|
| 37 |
current_menu = menus["menu_main"]; |
| 38 |
current_menu->enable_input(); |
| 39 |
} |
| 40 |
|
| 41 |
NS_MenuManager::~NS_MenuManager() |
| 42 |
{ |
| 43 |
for(MCont_t::iterator it = menus.begin(); it != menus.end(); ++it) |
| 44 |
delete it->second; |
| 45 |
} |
| 46 |
|
| 47 |
void NS_MenuManager::run() |
| 48 |
{ |
| 49 |
running = true; |
| 50 |
while(running) |
| 51 |
{ |
| 52 |
current_menu->run(); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
CL_ResourceManager & NS_MenuManager::get_resource_manager() |
| 57 |
{ |
| 58 |
return resource; |
| 59 |
} |
| 60 |
|
| 61 |
void NS_MenuManager::switch_to(std::string const & menu_name) |
| 62 |
{ |
| 63 |
MCont_t::iterator new_menu = menus.find(menu_name); |
| 64 |
if (new_menu != menus.end()) |
| 65 |
{ |
| 66 |
current_menu->disable_input(); |
| 67 |
current_menu = new_menu->second; |
| 68 |
current_menu->enable_input(); |
| 69 |
|
| 70 |
// anti buttons stuck hack |
| 71 |
CL_InputEvent key; |
| 72 |
key.device = CL_Mouse::get_device(); |
| 73 |
key.mouse_pos = CL_Point(CL_Mouse::get_x(), CL_Mouse::get_y()); |
| 74 |
key.type = CL_InputEvent::moved; |
| 75 |
CL_Mouse::get_device().sig_move().call(key); |
| 76 |
|
| 77 |
std::cout << "NS_MenuManager::switch to (\"" << menu_name |
| 78 |
<< "\") success\n"; |
| 79 |
} |
| 80 |
else |
| 81 |
std::cout << "NS_MenuManager::switch to (\"" << menu_name |
| 82 |
<< "\") failed\n"; |
| 83 |
} |
| 84 |
|
| 85 |
void NS_MenuManager::quit() |
| 86 |
{ |
| 87 |
running = false; |
| 88 |
} |