widgetMgr.cpp

Go to the documentation of this file.
00001 /*
00002  * widgetMgr.cpp
00003  *
00004  *  Created on: Jan 7, 2013
00005  *      Author: sushil
00006  */
00007 
00008 
00009 #include <OISEvents.h>
00010 #include <OISInputManager.h>
00011 #include <OISKeyboard.h>
00012 #include <OISMouse.h>
00013 #include "DEBUG.h"
00014 
00015 
00016 #include <widgetMgr.h>
00017 
00018 #include <GraphicsInteractionManager.h>
00019 
00020 OgreGFX::WidgetMgr::WidgetMgr(GraphicsInteractionManager *gim) : GFXMgr(gim), Ogre::FrameListener(), Ogre::WindowEventListener(), OIS::KeyListener(), OIS::MouseListener()
00021 {
00022     DEBUG(std::cout << "Creating Widget Manager" << std::endl;)
00023     nextId = 0;
00024 
00025     //Defaults
00026     this->gfx->mWindow->getWidth();
00027     POS = Ogre::Vector2(0, 0);
00028     LABEL_SIZE = Ogre::Vector2(100, 20);
00029     PANEL_SIZE = Ogre::Vector2(100, 20);
00030     MENU_ITEM_SIZE = Ogre::Vector2(100, 20);
00031     BUTTON_SIZE = Ogre::Vector2(0.0417f, 0.0417f);
00032     COMMANDPANEL_POS = Ogre::Vector2(0.7614583f, 0.825f);
00033     MENU_SIZE = Ogre::Vector2(0.2083f, 0.125f);
00034 
00035     WIDTH = 100;
00036     HEIGHT = 20;
00037     LABEL_X_OFFSET = 5;
00038     LABEL_Y_OFFSET = 5;
00039 
00040     LABEL_TEXT_COLOR = Ogre::ColourValue(1.0, 1.0, 0.7, 1.0);
00041     BUTTON_OFF_TEXT_COLOR = Ogre::ColourValue(1.0, 1.0, 0.0, 1.0);
00042     BUTTON_ON_TEXT_COLOR = Ogre::ColourValue(0.0, 0.0, 0.5, 1.0);
00043     MENU_DEFAULT_TEXT_COLOR = Ogre::ColourValue(1.0, 1.0, 0.0, 1.0);
00044     MENU_SELECTED_TEXT_COLOR = Ogre::ColourValue(0.0, 0.0, 0.5, 1.0);
00045 
00046 
00047     PANEL_MATERIAL = "ECSLENT/navy/material/shipInfo/overlay";
00048     LINE_SEP_MATERIAL = "ECSLENT/line";
00049     MENU_MATERIAL = "ECSLENT/navy/material/rmenu";
00050 
00051     uiBase = 0;
00052     currMenu = NULL;
00053     //uiBase->show();
00054 
00055 
00056 
00057     DEBUG(std::cout << "Finished  Widget Manager: " << getNextId("Test") << std::endl;)
00058 }
00059 
00060 OgreGFX::WidgetMgr::~WidgetMgr()
00061 {
00062 }
00063 
00064 void OgreGFX::WidgetMgr::activateMenu(FastEcslent::EntityType type)
00065 {
00066     this->deactivateMenu();
00067     switch (type)
00068     {
00069     case FastEcslent::SCV:
00070         currMenu = scvMenu;
00071         break;
00072     case FastEcslent::COMMANDCENTER:
00073         currMenu = cmdcMenu;
00074         break;
00075     case FastEcslent::BARRACKS:
00076         currMenu = barracksMenu;
00077         break;
00078     case FastEcslent::NENTITYTYPES:
00079         currMenu = multiMenu;
00080         break;
00081     default:
00082         this->deactivateMenu();
00083         break;
00084     }
00085     //assign new menu to curmenu
00086 
00087     if (currMenu)
00088     {
00089         currMenu->show();
00090     }
00091 
00092 }
00093 
00094 void OgreGFX::WidgetMgr::deactivateMenu()
00095 {
00096     if (currMenu)
00097     {
00098         currMenu->hide();
00099     }
00100     currMenu = NULL;
00101 }
00102 
00103 void OgreGFX::WidgetMgr::initialize()
00104 {
00105     uiBase = new UIOutline(this->gfx);
00106     uiBase->show();
00107     //uiBase->hide();
00108 
00109     testPanel = new OgreGFX::FEPanel(this->gfx, "TestPanel", (Widget*) 0, POS, PANEL_SIZE, PANEL_MATERIAL, Ogre::GMM_PIXELS);
00110 
00111     buttonInfo = new OgreGFX::FEPanel(this->gfx, "ButtonInfo", (Widget*) 0, Ogre::Vector2(0.7614583f, 0.6666), MENU_SIZE, MENU_MATERIAL, Ogre::GMM_RELATIVE);
00112     scvMenu = new OgreGFX::FEPanel(this->gfx, "SCVMenu", (Widget*) 0, COMMANDPANEL_POS, MENU_SIZE, MENU_MATERIAL, Ogre::GMM_RELATIVE);
00113     cmdcMenu = new OgreGFX::FEPanel(this->gfx, "CmdcMenu", (Widget*) 0, COMMANDPANEL_POS, MENU_SIZE, MENU_MATERIAL, Ogre::GMM_RELATIVE);
00114     barracksMenu = new OgreGFX::FEPanel(this->gfx, "barracksMenu", (Widget*) 0, COMMANDPANEL_POS, MENU_SIZE, MENU_MATERIAL, Ogre::GMM_RELATIVE);
00115     multiMenu = new OgreGFX::FEPanel(this->gfx, "MultiMenu", (Widget*) 0, COMMANDPANEL_POS, MENU_SIZE, MENU_MATERIAL, Ogre::GMM_RELATIVE);
00116     std::set<OIS::KeyCode> *creationMods = new std::set<OIS::KeyCode > ();
00117     scvAtk = new OgreGFX::FEButton(this->gfx, creationMods, OIS::MB_Left, "ATK",
00118                                    scvMenu, LABEL_TEXT_COLOR, POS, BUTTON_SIZE, NULL, "Attack", "test5", Ogre::GMM_RELATIVE);
00119     scvMove = new OgreGFX::FEButton(this->gfx, creationMods, OIS::MB_Left, "MV",
00120                                     scvMenu, LABEL_TEXT_COLOR, POS, BUTTON_SIZE, NULL, "Move", "Test1", Ogre::GMM_RELATIVE);
00121     scvGather = new OgreGFX::FEButton(this->gfx, creationMods, OIS::MB_Left, "GTH",
00122                                       scvMenu, LABEL_TEXT_COLOR, POS, BUTTON_SIZE, NULL, "Gather", "Test2",Ogre::GMM_RELATIVE);
00123     cmdcBuildSCV = new OgreGFX::FESCVButton(this->gfx, creationMods, OIS::MB_Left, "SCV",
00124                                             cmdcMenu, LABEL_TEXT_COLOR, POS, BUTTON_SIZE, Ogre::GMM_RELATIVE);
00125     multiAtk = new OgreGFX::FEButton(this->gfx, creationMods, OIS::MB_Left, "ATK",
00126                                      multiMenu, LABEL_TEXT_COLOR, POS, BUTTON_SIZE, NULL, "Attack","Test3",Ogre::GMM_RELATIVE);
00127     multiMove = new OgreGFX::FEButton(this->gfx, creationMods, OIS::MB_Left, "MV",
00128                                       multiMenu, LABEL_TEXT_COLOR, POS, BUTTON_SIZE, NULL, "Move","Test4",Ogre::GMM_RELATIVE);
00129     barracksMarine = new OgreGFX::FEMarineButton(this->gfx, creationMods, OIS::MB_Left, "MRN",
00130                                                  cmdcMenu, LABEL_TEXT_COLOR, POS, BUTTON_SIZE, Ogre::GMM_RELATIVE);
00131     this->gfx->uiMgr->registerMouseHandler(creationMods, OIS::MB_Left, scvAtk);
00132     this->gfx->uiMgr->registerMouseHandler(creationMods, OIS::MB_Left, scvMove);
00133     this->gfx->uiMgr->registerMouseHandler(creationMods, OIS::MB_Left, scvGather);
00134     this->gfx->uiMgr->registerMouseHandler(creationMods, OIS::MB_Left, cmdcBuildSCV);
00135     this->gfx->uiMgr->registerMouseHandler(creationMods, OIS::MB_Left, multiAtk);
00136     this->gfx->uiMgr->registerMouseHandler(creationMods, OIS::MB_Left, multiMove);
00137     this->gfx->uiMgr->registerMouseHandler(creationMods, OIS::MB_Left, barracksMarine);
00138 
00139     scvMenu->addItem(scvAtk, Below);
00140     scvMenu->addItem(scvMove, Right);
00141     scvMenu->addItem(scvGather, Right);
00142     cmdcMenu->addItem(cmdcBuildSCV, Below);
00143     multiMenu->addItem(multiAtk, Below);
00144     multiMenu->addItem(multiMove, Right);
00145     barracksMenu->addItem(barracksMarine, Below);
00146 
00147 
00148     testLabel = new OgreGFX::FELabel(this->gfx, "TestLabel", testPanel, LABEL_TEXT_COLOR, POS, LABEL_SIZE, Ogre::GMM_PIXELS);
00149     testLabel2 = new OgreGFX::FELabel(this->gfx, "SecondRow", testPanel, LABEL_TEXT_COLOR, POS, LABEL_SIZE, Ogre::GMM_PIXELS);
00150     buttonDesc = new OgreGFX::FELabel(this->gfx, "ButtonDesc", buttonInfo, LABEL_TEXT_COLOR, POS, MENU_SIZE, Ogre::GMM_RELATIVE);
00151     testPanel->addItem(testLabel, Below);
00152     testPanel->addItem(testLabel2, Below);
00153     buttonDesc->setCaption("Test");
00154     buttonInfo->addItem(buttonDesc,Below);
00155     buttonDesc->show();
00156     testLabel2->show();
00157     testLabel->show();
00158     testPanel->show();
00159     buttonInfo->hide();
00160     scvMenu->hide();
00161     cmdcMenu->hide();
00162     multiMenu->hide();
00163     barracksMenu->hide();
00164 
00165     testLabelPair = new OgreGFX::FELabelPair(this->gfx, "NewKey", "NewValue", testPanel,
00166                                              LABEL_TEXT_COLOR,
00167                                              Ogre::Vector2(1000, 0), Ogre::Vector2(100, 200), 20, PANEL_MATERIAL, Ogre::GMM_PIXELS);
00168     testLabelPair2 = new OgreGFX::FELabelPair(this->gfx, "Name", "Value2", testPanel,
00169                                               LABEL_TEXT_COLOR,
00170                                               Ogre::Vector2(1000, 0), Ogre::Vector2(100, 200), 20, PANEL_MATERIAL, Ogre::GMM_PIXELS);
00171     testPanel->addItem(testLabelPair, Below);
00172     testPanel->addItem(testLabelPair2, Below);
00173     testLabelPair->show();
00174     first = true;
00175     //creationMods->insert(OIS::KC_LCONTROL);
00176 }
00177 
00178 bool OgreGFX::WidgetMgr::frameStarted(const Ogre::FrameEvent& evt)
00179 {
00180     return true;
00181 }
00182 
00183 bool OgreGFX::WidgetMgr::frameEnded(const Ogre::FrameEvent& evt)
00184 {
00185     return true;
00186 }
00187 
00188 bool OgreGFX::WidgetMgr::frameRenderingQueued(const Ogre::FrameEvent& evt)
00189 {
00190     std::string gasLabel = "     Gas: ";
00191     std::string mineralsLabel = "Minerals: ";
00192     DEBUG(std::cout << "Setting caption" << std::endl;)
00193     if (first)
00194     {
00195         //first = false;
00196         //--------------------------------------------------------------------------
00197         //testLabel->textArea->setCaption(testLabel->caption);
00198         gasLabel.append(boost::lexical_cast<std::string > (this->gfx->engine->gameMgr->resources[FastEcslent::ONE].gas));
00199         mineralsLabel.append(boost::lexical_cast<std::string > (this->gfx->engine->gameMgr->resources[FastEcslent::ONE].minerals));
00200         testLabel->textArea->setCaption(gasLabel);
00201         testLabel2->textArea->setCaption(mineralsLabel);
00202         testLabelPair->setLeft(testLabelPair->left->caption);
00203         testLabelPair->setRight(testLabelPair->right->caption);
00204 
00205         testLabelPair2->setLeft(testLabelPair2->left->caption);
00206         testLabelPair2->setRight(testLabelPair2->right->caption);
00207         buttonDesc->textArea->setCaption(buttonDesc->caption);
00208 //        scvAtk->textArea->setCaption(scvAtk->caption);
00209 //        scvMove->textArea->setCaption(scvMove->caption);
00210 //        scvGather->textArea->setCaption(scvGather->caption);
00211 //        cmdcBuildSCV->textArea->setCaption(cmdcBuildSCV->caption);
00212 //        multiAtk->textArea->setCaption(multiAtk->caption);
00213 //        multiMove->textArea->setCaption(multiMove->caption);
00214 //        barracksMarine->textArea->setCaption(barracksMarine->caption);
00215         //--------------------------------------------------------------------------
00216     }
00217     return true;
00218 }
00219 
00220 bool OgreGFX::WidgetMgr::keyPressed(const OIS::KeyEvent &arg)
00221 {
00222     DEBUG(std::cout << "Widget Manager key pressed: " << arg.key << std::endl;)
00223     return true;
00224 }
00225 
00226 bool OgreGFX::WidgetMgr::keyReleased(const OIS::KeyEvent &arg)
00227 {
00228     return true;
00229 }
00230 
00231 bool OgreGFX::WidgetMgr::mouseMoved(const OIS::MouseEvent &arg)
00232 {
00233     return true;
00234 }
00235 
00236 bool OgreGFX::WidgetMgr::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
00237 {
00238     return true;
00239 }
00240 
00241 bool OgreGFX::WidgetMgr::mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
00242 {
00243     return true;
00244 }
00245 
00246 std::string OgreGFX::WidgetMgr::getNextId(std::string base)
00247 {
00248     std::stringstream idStream;
00249     this->nextId++;
00250     idStream << base << "_" << nextId;
00251     return idStream.str();
00252 }
00253 
00254 bool OgreGFX::WidgetMgr::mouseOverOverlay(const OIS::MouseEvent& arg)
00255 {
00256     if (scvMenu->cursonInMe(Ogre::Vector2(arg.state.X.abs, arg.state.Y.abs)))
00257         return true;
00258     return false;
00259 }
00260 
00261 bool OgreGFX::WidgetMgr::mouseOverButton(const OIS::MouseEvent& arg)
00262 {
00263     if (currMenu)
00264     {
00265         for(std::list<Widget*>::iterator it = currMenu->items.begin(); it != currMenu->items.end(); it++)
00266         {
00267             if((*it)->cursonInMe(Ogre::Vector2(arg.state.X.abs, arg.state.Y.abs)))
00268             {
00269                 buttonDesc->setCaption((*it)->desc);
00270                 buttonDesc->textArea->setCaption(buttonDesc->caption);
00271                 buttonInfo->show();
00272                 return true;
00273             }
00274         }
00275     }
00276     buttonInfo->hide();
00277     buttonDesc->setCaption("ERROR");
00278     buttonDesc->textArea->setCaption(buttonDesc->caption);
00279     return false;
00280 }

Generated on Fri Dec 13 14:54:18 2013 for FastECSLent by  doxygen 1.5.4