Revision: 2372 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2372&view=rev Author: rorthomas Date: 2012-01-28 03:08:06 +0000 (Sat, 28 Jan 2012) Log Message: ----------- new gui working :)
Modified Paths: -------------- trunk/source/main/framework/ContentManager.cpp trunk/source/main/gameplay/RoRFrameListener.cpp trunk/source/main/gui/DashBoardManager.cpp trunk/source/main/gui/DashBoardManager.h trunk/source/main/gui/OverlayWrapper.cpp trunk/source/main/gui/OverlayWrapper.h trunk/source/main/gui/gui_inputmanager.cpp trunk/source/main/gui/gui_manager.cpp trunk/source/main/physics/Beam.cpp trunk/source/main/physics/Beam.h trunk/source/main/physics/BeamFactory.cpp trunk/source/main/physics/BeamFactory.h Added Paths: ----------- trunk/bin/resources/dashboards.zip Added: trunk/bin/resources/dashboards.zip =================================================================== (Binary files differ) Property changes on: trunk/bin/resources/dashboards.zip ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/source/main/framework/ContentManager.cpp =================================================================== --- trunk/source/main/framework/ContentManager.cpp 2012-01-28 01:14:01 UTC (rev 2371) +++ trunk/source/main/framework/ContentManager.cpp 2012-01-28 03:08:06 UTC (rev 2372) @@ -121,7 +121,10 @@ loadMainResource("meshes"); loadMainResource("overlays"); loadMainResource("particles"); +#ifdef USE_MYGUI loadMainResource("mygui"); + loadMainResource("dashboards"); +#endif // USE_MYGUI loadMainResource("scripts"); loadMainResource("textures"); loadMainResource("flags"); Modified: trunk/source/main/gameplay/RoRFrameListener.cpp =================================================================== --- trunk/source/main/gameplay/RoRFrameListener.cpp 2012-01-28 01:14:01 UTC (rev 2371) +++ trunk/source/main/gameplay/RoRFrameListener.cpp 2012-01-28 03:08:06 UTC (rev 2372) @@ -35,6 +35,7 @@ #include "GlowMaterialListener.h" #include "MeshObject.h" #include "SceneMouse.h" +#include "DashBoardManager.h" #include "RigsOfRods.h" @@ -3072,7 +3073,7 @@ camRotX=pushcamRotX; camRotY=pushcamRotY; curr_truck->prepareInside(false); - if(ow) ow->showDashboardOverlays(true, curr_truck->driveable); + if(ow) ow->showDashboardOverlays(true, curr_truck); curr_truck->currentcamera=-1; //if(bigMap) bigMap->setVisibility(true); curr_truck->changedCamera(); @@ -3091,9 +3092,9 @@ if(ow) { if(curr_truck->driveable == AIRPLANE) - ow->showDashboardOverlays(true, curr_truck->driveable); + ow->showDashboardOverlays(true, curr_truck); else - ow->showDashboardOverlays(false, 0); + ow->showDashboardOverlays(false); } curr_truck->currentcamera=0; curr_truck->changedCamera(); @@ -5440,6 +5441,9 @@ { previousTruck->prepareInside(false); + if(previousTruck->dash) + previousTruck->dash->setVisible(false); + // this workaround enables trucks to spawn that have no cinecam. required for cmdline options if(previousTruck->cinecameranodepos[0] != -1) { @@ -5457,7 +5461,7 @@ // position.y=hfinder->getHeightAt(position.x,position.z); if(position != Vector3::ZERO) person->setPosition(position); //person->setVisible(true); - if(ow) ow->showDashboardOverlays(false,0); + if(ow) ow->showDashboardOverlays(false); if(ow) ow->showEditorOverlay(false); #ifdef USE_OPENAL if(ssm) ssm->trigStop(previousTruck, SS_TRIG_AIR); @@ -5489,7 +5493,7 @@ //person->setVisible(false); if(ow &&!hidegui) { - ow->showDashboardOverlays(true, currentTruck->driveable); + ow->showDashboardOverlays(true, currentTruck); ow->showEditorOverlay(currentTruck->editorId>=0); } @@ -5573,7 +5577,7 @@ if (cameramode==CAMERA_INT) { currentTruck->prepareInside(true); - if(ow) ow->showDashboardOverlays(false, 0); + if(ow) ow->showDashboardOverlays(false); camRotY=DEFAULT_INTERNAL_CAM_PITCH; //if(bigMap) bigMap->setVisibility(false); } @@ -6004,7 +6008,7 @@ camRotX=pushcamRotX; camRotY=pushcamRotY; curr_truck->prepareInside(false); - if(ow) ow->showDashboardOverlays(true, curr_truck->driveable); + if(ow) ow->showDashboardOverlays(true, curr_truck); } if(mDOF) @@ -6463,7 +6467,7 @@ if(visible) { - if(ow) ow->showDashboardOverlays(false,0); + if(ow) ow->showDashboardOverlays(false); if(ow) ow->showEditorOverlay(false); if(ow) ow->truckhud->show(false); //if(bigMap) bigMap->setVisibility(false); @@ -6477,7 +6481,7 @@ { if(curr_truck && cameramode!=CAMERA_INT) { - if(ow) ow->showDashboardOverlays(true, curr_truck->driveable); + if(ow) ow->showDashboardOverlays(true, curr_truck); //if(bigMap) bigMap->setVisibility(true); } #ifdef USE_SOCKETW Modified: trunk/source/main/gui/DashBoardManager.cpp =================================================================== --- trunk/source/main/gui/DashBoardManager.cpp 2012-01-28 01:14:01 UTC (rev 2371) +++ trunk/source/main/gui/DashBoardManager.cpp 2012-01-28 03:08:06 UTC (rev 2372) @@ -185,10 +185,20 @@ } } +void DashBoardManager::windowResized() +{ + for(int i=0; i < free_dashboard; i++) + { + dashboards[i]->windowResized(); + } +} + // DASHBOARD class below -DashBoard::DashBoard(DashBoardManager *manager, Ogre::String filename) : manager(manager), filename(filename), free_controls(0), visible(false) +DashBoard::DashBoard(DashBoardManager *manager, Ogre::String filename) : manager(manager), filename(filename), free_controls(0), visible(false), mainWidget(0) { + // use 'this' class pointer to make layout unique + prefix = MyGUI::utility::toString(this, "_"); memset(&controls, 0, sizeof(controls)); loadLayout(filename); } @@ -323,24 +333,59 @@ controls[i].txt->setCaption(s); } - + else if(controls[i].animationType == ANIM_TEXT2) + { + char *val = manager->getChar(controls[i].linkID); + controls[i].txt->setCaption(MyGUI::UString(val)); + } } } -void DashBoard::loadLayout( Ogre::String filename ) +void DashBoard::windowResized() { - // use 'this' class pointer to make layout unique - std::string prefix = MyGUI::utility::toString(this, "_"); - widgets = MyGUI::LayoutManager::getInstance().loadLayout(filename, prefix, nullptr); // never has a parent + MyGUI::IntSize screenSize = MyGUI::RenderManager::getInstance().getViewSize(); + if(mainWidget) mainWidget->setSize(screenSize); +} - for (MyGUI::VectorWidgetPtr::iterator iter = widgets.begin(); iter != widgets.end(); ++iter) +void DashBoard::loadLayoutRecursive(MyGUI::WidgetPtr w) +{ + std::string name = w->getName(); + std::string anim = w->getUserString("anim"); + std::string debug = w->getUserString("debug"); + + // make it unclickable + w->setUserString("interactive", "0"); + + if(!debug.empty()) { - MyGUI::Widget *w = (*iter); - std::string name = w->getName(); - std::string anim = w->getUserString("anim"); - - if(anim.empty()) continue; // non-animated control, ignore + w->setVisible(false); + return; + } + // find the root widget and ignore debug widgets + if(name.size() > prefix.size()) + { + std::string prefixLessName = name.substr(prefix.size()); + if(prefixLessName == "_Main") + { + mainWidget = w; + // resize it + windowResized(); + } + + // ignore debug widgets + if(prefixLessName == "DEBUG") + { + w->setVisible(false); + return; + } + } + + + // animations for this control? + if(!anim.empty()) + { + layoutLink_t ctrl; memset(&ctrl, 0, sizeof(ctrl)); @@ -360,7 +405,7 @@ if(linkArgs.empty()) { LOG("Dashboard ("+filename+"/"+name+"): empty Link"); - continue; + return; } // conditional checks // TODO: improve the logic, this is crap ... @@ -375,7 +420,7 @@ } else { LOG("Dashboard ("+filename+"/"+name+"): error in conditional Link: " + linkArgs); - continue; + return; } } else if(linkArgs.find("<") != linkArgs.npos ) { @@ -388,7 +433,7 @@ } else { LOG("Dashboard ("+filename+"/"+name+"): error in conditional Link: " + linkArgs); - continue; + return; } } else { @@ -402,7 +447,7 @@ if(linkID < 0) { LOG("Dashboard ("+filename+"/"+name+"): unknown Link: " + linkName); - continue; + return; } ctrl.linkID = linkID; } @@ -427,7 +472,7 @@ else if(!direction.empty()) { LOG("Dashboard ("+filename+"/"+name+"): unknown direction: " + direction); - continue; + return; } // then specializations @@ -452,12 +497,12 @@ catch (...) { LOG("Dashboard ("+filename+"/"+name+"): Rotating controls must use the RotatingSkin"); - continue; + return; } if(!ctrl.rotImg) { LOG("Dashboard ("+filename+"/"+name+"): error loading rotation control"); - continue; + return; } // special: set rotation center now into the middle @@ -470,7 +515,7 @@ if(ctrl.direction == DIRECTION_NONE) { LOG("Dashboard ("+filename+"/"+name+"): direction empty: scale needs a direction"); - continue; + return; } } else if(anim == "translate") @@ -479,7 +524,7 @@ if(ctrl.direction == DIRECTION_NONE) { LOG("Dashboard ("+filename+"/"+name+"): direction empty: translate needs a direction"); - continue; + return; } } else if(anim == "series") @@ -489,7 +534,7 @@ if(!ctrl.img) { LOG("Dashboard ("+filename+"/"+name+"): error loading series control"); - continue; + return; } } else if(anim == "text") @@ -502,10 +547,24 @@ catch (...) { LOG("Dashboard ("+filename+"/"+name+"): Lamp controls must use the ImageBox Control"); - continue; + return; } ctrl.animationType = ANIM_TEXT; } + else if(anim == "text2") + { + // try to cast, will throw + try + { + ctrl.txt = (MyGUI::TextBox *)w; // w->getSubWidgetMain()->castType<MyGUI::TextBox>(); + } + catch (...) + { + LOG("Dashboard ("+filename+"/"+name+"): Lamp controls must use the ImageBox Control"); + return; + } + ctrl.animationType = ANIM_TEXT2; + } else if(anim == "lamp") { // try to cast, will throw @@ -527,7 +586,7 @@ if(!ctrl.img) { LOG("Dashboard ("+filename+"/"+name+"): error loading Lamp control"); - continue; + return; } } @@ -537,26 +596,34 @@ if(free_controls >= MAX_CONTROLS) { LOG("maximum amount of controls reached, discarding the rest: " + TOSTRING(MAX_CONTROLS)); - break; + return; } } + // walk the children now + MyGUI::EnumeratorWidgetPtr e = w->getEnumerator(); + while (e.next()) + { + loadLayoutRecursive(e.current()); + } } -void DashBoard::setVisible(bool v) +void DashBoard::loadLayout( Ogre::String filename ) { - visible = v; + widgets = MyGUI::LayoutManager::getInstance().loadLayout(filename, prefix, nullptr); // never has a parent + for (MyGUI::VectorWidgetPtr::iterator iter = widgets.begin(); iter != widgets.end(); ++iter) { - if((*iter)->getUserString("DEBUG") == "1") - { - (*iter)->setVisible(false); - continue; - } + loadLayoutRecursive(*iter); + } - (*iter)->setVisible(v); - } } +void DashBoard::setVisible(bool v) +{ + visible = v; + if(mainWidget) mainWidget->setVisible(v); +} + #endif // USE_MYGUI Modified: trunk/source/main/gui/DashBoardManager.h =================================================================== --- trunk/source/main/gui/DashBoardManager.h 2012-01-28 01:14:01 UTC (rev 2371) +++ trunk/source/main/gui/DashBoardManager.h 2012-01-28 03:08:06 UTC (rev 2372) @@ -187,8 +187,11 @@ void update(float &dt); + bool wasLoaded() { return (free_dashboard > 0); }; + void setVisible(bool visible); bool getVisible() { return visible; }; + void windowResized(); protected: bool visible; @@ -208,13 +211,18 @@ bool getVisible() { return visible; }; void update(float &dt); + + void windowResized(); + protected: DashBoardManager *manager; Ogre::String filename; MyGUI::VectorWidgetPtr widgets; + MyGUI::WidgetPtr mainWidget; bool visible; + std::string prefix; - enum {ANIM_NONE, ANIM_ROTATE, ANIM_SCALE, ANIM_TEXT, ANIM_LAMP, ANIM_SERIES, ANIM_TRANSLATE }; + enum {ANIM_NONE, ANIM_ROTATE, ANIM_SCALE, ANIM_TEXT, ANIM_TEXT2, ANIM_LAMP, ANIM_SERIES, ANIM_TRANSLATE }; enum {DIRECTION_NONE, DIRECTION_UP, DIRECTION_RIGHT, DIRECTION_DOWN, DIRECTION_LEFT }; enum {CONDITION_NONE, CONDITION_GREATER, CONDITION_LESSER}; @@ -224,7 +232,7 @@ int linkID; // DD_* char animationType; // ANIM_* - float wmin; // rotation/offeset whatever (widget min/max) + float wmin; // rotation/offset whatever (widget min/max) float wmax; float vmin; // value min/max float vmax; @@ -248,7 +256,7 @@ } layoutLink_t; void loadLayout(Ogre::String filename); - + void loadLayoutRecursive(MyGUI::WidgetPtr ptr); layoutLink_t controls[MAX_CONTROLS]; int free_controls; }; Modified: trunk/source/main/gui/OverlayWrapper.cpp =================================================================== --- trunk/source/main/gui/OverlayWrapper.cpp 2012-01-28 01:14:01 UTC (rev 2371) +++ trunk/source/main/gui/OverlayWrapper.cpp 2012-01-28 03:08:06 UTC (rev 2372) @@ -30,6 +30,7 @@ #include "OgreFontManager.h" #include "RoRVersion.h" #include "Console.h" +#include "DashBoardManager.h" #include "autopilot.h" #include "aeroengine.h" @@ -496,53 +497,62 @@ } } -void OverlayWrapper::showDashboardOverlays(bool show, int mode) +void OverlayWrapper::showDashboardOverlays(bool show, Beam *truck) { - if (needlesOverlay && dashboardOverlay) + if (!needlesOverlay || !dashboardOverlay) return; + int mode = -1; + if(truck) + mode = truck->driveable; + + // check if we use the new style dashboards + if(truck && truck->dash && truck->dash->wasLoaded()) { - if (show) + truck->dash->setVisible(show); + return; + } + + if (show) + { + if (mode==TRUCK) { - if (mode==TRUCK) - { - needlesMaskOverlay->show(); - needlesOverlay->show(); - dashboardOverlay->show(); - }; - if (mode==AIRPLANE) - { - airneedlesOverlay->show(); - airdashboardOverlay->show(); - //mouseOverlay->show(); - }; - if (mode==BOAT) - { - boatneedlesOverlay->show(); - boatdashboardOverlay->show(); - }; - if (mode==BOAT) - { - boatneedlesOverlay->show(); - boatdashboardOverlay->show(); - }; - if (mode==MACHINE) - { - machinedashboardOverlay->show(); - }; - } - else + needlesMaskOverlay->show(); + needlesOverlay->show(); + dashboardOverlay->show(); + }; + if (mode==AIRPLANE) { - machinedashboardOverlay->hide(); - needlesMaskOverlay->hide(); - needlesOverlay->hide(); - dashboardOverlay->hide(); - //for the airplane - airneedlesOverlay->hide(); - airdashboardOverlay->hide(); - //mouseOverlay->hide(); - boatneedlesOverlay->hide(); - boatdashboardOverlay->hide(); - } + airneedlesOverlay->show(); + airdashboardOverlay->show(); + //mouseOverlay->show(); + }; + if (mode==BOAT) + { + boatneedlesOverlay->show(); + boatdashboardOverlay->show(); + }; + if (mode==BOAT) + { + boatneedlesOverlay->show(); + boatdashboardOverlay->show(); + }; + if (mode==MACHINE) + { + machinedashboardOverlay->show(); + }; } + else + { + machinedashboardOverlay->hide(); + needlesMaskOverlay->hide(); + needlesOverlay->hide(); + dashboardOverlay->hide(); + //for the airplane + airneedlesOverlay->hide(); + airdashboardOverlay->hide(); + //mouseOverlay->hide(); + boatneedlesOverlay->hide(); + boatdashboardOverlay->hide(); + } } void OverlayWrapper::updateStats(bool detailed) @@ -802,6 +812,7 @@ bool OverlayWrapper::mouseMoved(const OIS::MouseEvent& _arg) { + if(!airneedlesOverlay->isVisible()) return false; bool res = false; const OIS::MouseState ms = _arg.state; Beam **trucks = BeamFactory::getSingleton().getTrucks(); Modified: trunk/source/main/gui/OverlayWrapper.h =================================================================== --- trunk/source/main/gui/OverlayWrapper.h 2012-01-28 01:14:01 UTC (rev 2371) +++ trunk/source/main/gui/OverlayWrapper.h 2012-01-28 03:08:06 UTC (rev 2372) @@ -51,7 +51,7 @@ ~OverlayWrapper(); // functions - void showDashboardOverlays(bool show, int mode); + void showDashboardOverlays(bool show, Beam *truck = 0); void showDebugOverlay(int mode); void showPressureOverlay(bool show); void showEditorOverlay(bool show); Modified: trunk/source/main/gui/gui_inputmanager.cpp =================================================================== --- trunk/source/main/gui/gui_inputmanager.cpp 2012-01-28 01:14:01 UTC (rev 2371) +++ trunk/source/main/gui/gui_inputmanager.cpp 2012-01-28 03:08:06 UTC (rev 2372) @@ -119,6 +119,8 @@ // hack for console, we want to use the mouse through that control if(w && w->getName().substr(0, 7) == "Console") handled = false; + if(w && w->getUserString("interactive") == "0") + handled = false; } if(!handled) @@ -173,6 +175,8 @@ // hack for console, we want to use the mouse through that control if(w && w->getName().substr(0, 7) == "Console") handled = false; + if(w && w->getUserString("interactive") == "0") + handled = false; } if(!handled) @@ -203,6 +207,8 @@ // hack for console, we want to use the mouse through that control if(w && w->getName().substr(0, 7) == "Console") handled = false; + if(w && w->getUserString("interactive") == "0") + handled = false; } if(!handled) Modified: trunk/source/main/gui/gui_manager.cpp =================================================================== --- trunk/source/main/gui/gui_manager.cpp 2012-01-28 01:14:01 UTC (rev 2371) +++ trunk/source/main/gui/gui_manager.cpp 2012-01-28 03:08:06 UTC (rev 2372) @@ -28,6 +28,7 @@ #include <MyGUI_LanguageManager.h> #include "Console.h" +#include "BeamFactory.h" #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 # include <windows.h> @@ -165,7 +166,10 @@ int width = (int)_rw->getWidth(); int height = (int)_rw->getHeight(); setInputViewSize(width, height); - + + BeamFactory *bf = BeamFactory::getSingletonPtr(); + if(bf) bf->windowResized(); + Console *c = Console::getInstancePtrNoCreation(); if(c) c->resized(); } Modified: trunk/source/main/physics/Beam.cpp =================================================================== --- trunk/source/main/physics/Beam.cpp 2012-01-28 01:14:01 UTC (rev 2371) +++ trunk/source/main/physics/Beam.cpp 2012-01-28 03:08:06 UTC (rev 2372) @@ -5516,7 +5516,9 @@ // now load any dashboards if(dashBoardLayout.empty()) { - // TODO: defaults? + // load default for a truck + if(driveable == TRUCK) + dash->loadDashBoard("default_dashboard.layout"); } else { dash->loadDashBoard(dashBoardLayout); @@ -5652,7 +5654,7 @@ else str = String("R"); - dash->setInt(DD_ENGINE_GEAR_STRING, numGears); + dash->setChar(DD_ENGINE_GEAR_STRING, str.c_str()); // autogears int autoGear = engine->getAutoShift(); @@ -5693,7 +5695,7 @@ dash->setFloat(DD_BRAKE, dash_brake); // speedo - float speed_kph = WheelSpeed; + float speed_kph = WheelSpeed * 3.6f; // m/s to mk/h dash->setFloat(DD_ENGINE_SPEEDO_KPH, speed_kph); float speed_mph = speed_kph * 0.621371192f; // 1 kph = 0.621371192 mph dash->setFloat(DD_ENGINE_SPEEDO_MPH, speed_mph); Modified: trunk/source/main/physics/Beam.h =================================================================== --- trunk/source/main/physics/Beam.h 2012-01-28 01:14:01 UTC (rev 2371) +++ trunk/source/main/physics/Beam.h 2012-01-28 03:08:06 UTC (rev 2372) @@ -337,6 +337,10 @@ Ogre::SceneNode *getSceneNode() { return parentNode; }; +#ifdef USE_MYGUI + DashBoardManager *dash; +#endif // USE_MYGUI + protected: void updateDashBoards(float &dt); void updateSimpleSkeleton(); @@ -347,9 +351,6 @@ Vector3 lastlastposition; Real minCameraRadius; -#ifdef USE_MYGUI - DashBoardManager *dash; -#endif // USE_MYGUI Real replayTimer; Real replayPrecision; Modified: trunk/source/main/physics/BeamFactory.cpp =================================================================== --- trunk/source/main/physics/BeamFactory.cpp 2012-01-28 01:14:01 UTC (rev 2371) +++ trunk/source/main/physics/BeamFactory.cpp 2012-01-28 03:08:06 UTC (rev 2372) @@ -33,6 +33,7 @@ #ifdef USE_MYGUI #include "gui_mp.h" #include "gui_menu.h" +#include "DashBoardManager.h" #endif // USE_MYGUI using namespace Ogre; @@ -770,10 +771,21 @@ } else { - // find the stream machting the streamid + // find the stream matching the streamid it_beam = it_stream->second.find(del->streamid); if (it_beam != it_stream->second.end()) removeInstance(it_beam->second); } // unlockStreams(); -} \ No newline at end of file +} + +void BeamFactory::windowResized() +{ +#ifdef USE_MYGUI + for(int t=0; t < free_truck; t++) + { + if(!trucks[t]) continue; + trucks[t]->dash->windowResized(); + } +#endif // USE_MYGUI +} Modified: trunk/source/main/physics/BeamFactory.h =================================================================== --- trunk/source/main/physics/BeamFactory.h 2012-01-28 01:14:01 UTC (rev 2371) +++ trunk/source/main/physics/BeamFactory.h 2012-01-28 03:08:06 UTC (rev 2372) @@ -78,6 +78,8 @@ void _waitForSync(); + void windowResized(); + protected: Ogre::SceneManager *manager; Ogre::SceneNode *parent; @@ -113,7 +115,6 @@ void removeInstance(stream_del_t *del); void _deleteTruck(Beam *b); - pthread_mutex_t done_count_mutex; pthread_cond_t done_count_cv; pthread_mutex_t work_mutex; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 _______________________________________________ Rigsofrods-devel mailing list Rigsofrods-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel