Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/loader/LevelLoader.cc @ 521

Last change on this file since 521 was 521, checked in by nicolape, 16 years ago

Fixed bug for assf texture, added loading overlay (its now working, used some code from the ogre forums, no error but my overlay doesnt pop up… anyone an idea (code is in levelloader.cc

File size: 4.1 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      ...
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include <string>
29#include <vector>
30#include <iostream>
31#include <algorithm>
32#include <iterator>
33
34#include <OgreOverlayManager.h>
35
36#include "LevelLoader.h"
37#include "tinyxml/tinyxml.h"
38#include "orxonox/core/CoreIncludes.h"
39#include "orxonox/core/Error.h"
40#include "orxonox/objects/BaseObject.h"
41
42using namespace std;
43
44namespace loader
45{
46
47LevelLoader::LevelLoader(string file, string path)
48{
49        valid_ = false;
50
51        // Load XML level file
52        path.append("/");
53        path.append(file);
54
55        // Open xml file
56        doc.LoadFile(path);
57
58        // Check if file was loaded
59        if (doc.LoadFile())
60        {
61                TiXmlHandle hDoc(&doc);
62                TiXmlHandle hRoot(0);
63                TiXmlElement* pElem;
64
65                // Check for root element
66                pElem = hDoc.FirstChildElement("orxonoxworld").Element();
67                if (pElem)
68                {
69                        // Set root element
70                        hRoot = TiXmlHandle(pElem);
71                        rootElement = hRoot.Element();
72
73                        // Set level description
74                        pElem = hRoot.FirstChild("description").Element();
75                        if (pElem)
76                        {
77                                description_ = pElem->GetText();
78                        }
79
80                        // Set level name
81                        name_ = rootElement->Attribute("name");
82                        image_ = rootElement->Attribute("image");
83
84                        valid_ = true;
85                }
86                else
87                {
88                        orxonox::Error("Level file has no valid root node");
89                }
90        }
91        else
92        {
93                orxonox::Error("Could not load level file ");
94        }
95}
96
97        void LevelLoader::loadLevel()
98        {
99                if (valid_)
100                {
101                        TiXmlElement* loadElem;
102                        TiXmlElement* worldElem;
103                        TiXmlElement* tElem;
104                        TiXmlNode* tNode;
105
106
107                        // Set loading screen
108                        loadElem = rootElement->FirstChildElement("loading");
109                        if (loadElem)
110                        {
111                                // Set background
112                                tElem = loadElem->FirstChildElement("background");
113                                if (tElem)
114                                {
115                                        loadingBackgroundColor_ = tElem->Attribute("color");
116                                        loadingBackgroundImage_ = tElem->Attribute("image");
117                                }
118                                // Set bar
119                                tElem = loadElem->FirstChildElement("bar");
120                                if (tElem)
121                                {
122                                        loadingBarImage_ = tElem->Attribute("image");;
123                                        loadingBarTop_ = tElem->Attribute("top");
124                                        loadingBarLeft_ = tElem->Attribute("left");
125                                        loadingBarWidth_ = tElem->Attribute("width");
126                                        loadingBarHeight_ = tElem->Attribute("height");
127                                }
128                                showLoadingScreen();
129                        }
130
131                        // Load audio
132                        // TODO
133
134                        // Load scripts
135                        // TODO
136
137                        // Load world
138                        worldElem = rootElement->FirstChildElement("world");
139                        if (worldElem)
140                        {
141                                tNode = 0;
142                                while( tNode = worldElem->IterateChildren( tNode ) )
143                                {
144                                        tElem = tNode->ToElement();
145                                        orxonox::BaseObject* obj = ID(tElem->Value())->fabricate();
146                                        obj->loadParams(tElem);
147                                }
148                        }
149
150                        std::cout << "Loading finished!\n\n\n\n\n";
151                }
152        }
153
154        void LevelLoader::showLoadingScreen()
155        {
156               
157                Ogre::OverlayManager& omgr = Ogre::OverlayManager::getSingleton();
158    Ogre::Overlay* mLoadOverlay = (Ogre::Overlay*)omgr.getByName("Orxonox/LoadingScreenSample");
159    mLoadOverlay->show(); 
160               
161                std::cout << "\n\n\nThis is Orxonox\nthe hottest 3D action shooter ever to exist\n\n\n";
162                std::cout << "Level: " << name() << "\nDescription:" << description() << "\nImage:"<<image()<<"\n\n\n";
163                std::cout << "Backgroundcolor: " << loadingBackgroundColor_ << "\nBackgroundimage:" << loadingBackgroundImage_ << "\n\n\n";
164        }
165
166        LevelLoader::~LevelLoader()
167        {
168
169        }
170
171
172        string LevelLoader::name()
173        {
174                return this->name_;
175        }
176
177        string LevelLoader::description()
178        {
179                return this->description_;
180        }
181
182        string LevelLoader::image()
183        {
184                return this->image_;
185        }
186
187
188}
189
Note: See TracBrowser for help on using the repository browser.