00001 #include "statemenu.h"
00002 #include "statemachine.h"
00003 #include "debug.h"
00004
00005 using namespace irr;
00006 using namespace core;
00007 using namespace video;
00008 using namespace gui;
00009
00010 extern StateMachine* sm;
00011 extern Debug* dbg;
00012
00013 StateMenu::StateMenu(c8* n, IrrlichtDevice* d) : State(n, d)
00014 {
00015
00016 }
00017
00018 StateMenu::~StateMenu()
00019 {
00020
00021 }
00022
00023 bool StateMenu::OnEvent(SEvent event)
00024 {
00025 if (event.EventType == EET_KEY_INPUT_EVENT)
00026 {
00027 if (event.KeyInput.PressedDown)
00028 {
00029 switch(event.KeyInput.Key)
00030 {
00031 case KEY_ESCAPE:
00032 {
00033 if (gui->isVisible())
00034 {
00035 gui->setVisible(false);
00036 }
00037 else
00038 {
00039 gui->setVisible(true);
00040 }
00041 return true;
00042 }
00043 }
00044 }
00045 }
00046
00047 if (event.EventType == EET_GUI_EVENT)
00048 {
00049 switch(event.GUIEvent.EventType)
00050 {
00051 case EGET_BUTTON_CLICKED:
00052 {
00053 s32 id = event.GUIEvent.Caller->getID();
00054 switch (id)
00055 {
00056 case 100:
00057 {
00058 sm->pushEvent("STATE_FLOCKSIMULATION");
00059 return true;
00060 }
00061 case 101:
00062 {
00063 sm->pushEvent("STATE_TERRAIN");
00064 return true;
00065 }
00066 case 199:
00067 {
00068 sm->pushEvent("STATE_CLOSE");
00069 return true;
00070 }
00071 }
00072 }
00073 }
00074 }
00075 return false;
00076 }
00077
00078 void StateMenu::render(u32 deltaTime)
00079 {
00080 device->getVideoDriver()->beginScene(true, true, SColor(0, 255, 255, 0));
00081 dbg->show("this is MenuState");
00082 device->getGUIEnvironment()->drawAll();
00083 device->getVideoDriver()->endScene();
00084 }
00085
00086 void StateMenu::entry()
00087 {
00088 dbg->log("State", name, "entry");
00089
00090
00091
00092
00093 if (workingDirectory == "")
00094 {
00095 stringc tmp(device->getFileSystem()->getWorkingDirectory());
00096 workingDirectory = tmp;
00097 }
00098 else
00099 {
00100 device->getFileSystem()->changeWorkingDirectoryTo(workingDirectory.c_str());
00101 }
00102
00103
00104 device->getCursorControl()->setVisible(true);
00105
00106
00107 gui = new Gui(device, stringc("Menu"), rect<s32>(300, 200, 500, 280));
00108 gui->addButton(100, "start flock simulation");
00109 gui->addButton(101, "start terrain test");
00110 gui->addButton(199, "exit");
00111
00112
00113 ITexture* texture = device->getVideoDriver()->getTexture("media/menu.png");
00114 if (! texture)
00115 {
00116 dbg->log("StateMenu: cannot get texture");
00117 imgMenu = NULL;
00118 return;
00119 }
00120
00121 imgMenu = device->getGUIEnvironment()->addImage(texture, position2d<s32>(100, 100));
00122 gui->bringToFront();
00123 }
00124
00125 void StateMenu::exit()
00126 {
00127 dbg->log("State", name, "exit");
00128
00129
00130 if (imgMenu)
00131 {
00132 imgMenu->remove();
00133 }
00134 imgMenu = NULL;
00135
00136 delete gui;
00137 }