stateclose.cpp

00001 #include "stateclose.h"
00002 #include "statemachine.h"
00003 #include "debug.h"
00004 #include "config.h"
00005 
00006 using namespace irr;
00007 using namespace core;
00008 using namespace video;
00009 
00010 extern StateMachine* sm;
00011 extern Debug* dbg;
00012 
00013 StateClose::StateClose(c8* n, IrrlichtDevice* d) : State(n, d)
00014 {
00015     //ctor
00016 }
00017 
00018 StateClose::~StateClose()
00019 {
00020     //dtor
00021 }
00022 
00023 bool StateClose::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_KEY_Q:
00032                 {
00033                     // safe default config file
00034                     Config cfg(device);
00035                     cfg.safeDefaultConfig("defaultConfig.txt");
00036                     return true;
00037                 }
00038                 default:
00039                 {
00040                     // exit app
00041                     exit();
00042                     device->closeDevice();
00043                     return true;
00044                 }
00045             }
00046         }
00047     }
00048 
00049     if (event.EventType == EET_MOUSE_INPUT_EVENT)
00050     {
00051         switch(event.MouseInput.Event)
00052         {
00053             case EMIE_LMOUSE_PRESSED_DOWN:
00054             {
00055                 // exit app
00056                 exit();
00057                 device->closeDevice();
00058                 return true;
00059             }
00060         }
00061     }
00062 
00063     return false;
00064 }
00065 
00066 void StateClose::render(u32 deltaTime)
00067 {
00068     device->getVideoDriver()->beginScene(true, true, SColor(0, 0, 255, 0));
00069     dbg->show("this is CloseState");
00070     dbg->show("press Q to safe game config");
00071     dbg->show("press MOUSE or KEY to exit");
00072     device->getGUIEnvironment()->drawAll();
00073     device->getVideoDriver()->endScene();
00074 }
00075 
00076 void StateClose::entry()
00077 {
00078     dbg->log("State", name, "entry");
00079 
00080     // init members
00081     ITexture* texture = device->getVideoDriver()->getTexture("media/close.png");
00082     if (! texture)
00083     {
00084         dbg->log("StateClose: cannot create texture");
00085         imgClose = NULL;
00086         return;
00087     }
00088     imgClose = device->getGUIEnvironment()->addImage(texture, position2d<s32>(100, 100));
00089 }
00090 
00091 void StateClose::exit()
00092 {
00093     dbg->log("State", name, "exit");
00094 
00095     // deinit members
00096     if (imgClose)
00097     {
00098         imgClose->remove();
00099     }
00100     imgClose = NULL;
00101 }
00102 

Generated on Sun Dec 2 17:09:58 2007 for Swarm by  doxygen 1.4.6-NO