[513] | 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 | |
---|
[507] | 28 | #include <string> |
---|
| 29 | #include <vector> |
---|
[164] | 30 | #include <iostream> |
---|
[507] | 31 | #include <algorithm> |
---|
| 32 | #include <iterator> |
---|
[164] | 33 | |
---|
[521] | 34 | #include <OgreOverlayManager.h> |
---|
| 35 | |
---|
[164] | 36 | #include "LevelLoader.h" |
---|
[471] | 37 | #include "tinyxml/tinyxml.h" |
---|
[496] | 38 | #include "orxonox/core/CoreIncludes.h" |
---|
[480] | 39 | #include "orxonox/core/Error.h" |
---|
| 40 | #include "orxonox/objects/BaseObject.h" |
---|
[164] | 41 | |
---|
| 42 | using namespace std; |
---|
| 43 | |
---|
| 44 | namespace loader |
---|
| 45 | { |
---|
| 46 | |
---|
[480] | 47 | LevelLoader::LevelLoader(string file, string path) |
---|
[164] | 48 | { |
---|
[480] | 49 | valid_ = false; |
---|
[513] | 50 | |
---|
[164] | 51 | // Load XML level file |
---|
[480] | 52 | path.append("/"); |
---|
[513] | 53 | path.append(file); |
---|
| 54 | |
---|
[474] | 55 | // Open xml file |
---|
[480] | 56 | doc.LoadFile(path); |
---|
[474] | 57 | |
---|
| 58 | // Check if file was loaded |
---|
| 59 | if (doc.LoadFile()) |
---|
[471] | 60 | { |
---|
[474] | 61 | TiXmlHandle hDoc(&doc); |
---|
[513] | 62 | TiXmlHandle hRoot(0); |
---|
[474] | 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); |
---|
[480] | 71 | rootElement = hRoot.Element(); |
---|
[474] | 72 | |
---|
| 73 | // Set level description |
---|
| 74 | pElem = hRoot.FirstChild("description").Element(); |
---|
| 75 | if (pElem) |
---|
| 76 | { |
---|
[513] | 77 | description_ = pElem->GetText(); |
---|
[474] | 78 | } |
---|
[513] | 79 | |
---|
[474] | 80 | // Set level name |
---|
[480] | 81 | name_ = rootElement->Attribute("name"); |
---|
| 82 | image_ = rootElement->Attribute("image"); |
---|
[513] | 83 | |
---|
[480] | 84 | valid_ = true; |
---|
| 85 | } |
---|
| 86 | else |
---|
| 87 | { |
---|
| 88 | orxonox::Error("Level file has no valid root node"); |
---|
[513] | 89 | } |
---|
[480] | 90 | } |
---|
| 91 | else |
---|
| 92 | { |
---|
| 93 | orxonox::Error("Could not load level file "); |
---|
[513] | 94 | } |
---|
[480] | 95 | } |
---|
| 96 | |
---|
| 97 | void LevelLoader::loadLevel() |
---|
| 98 | { |
---|
| 99 | if (valid_) |
---|
| 100 | { |
---|
| 101 | TiXmlElement* loadElem; |
---|
| 102 | TiXmlElement* worldElem; |
---|
| 103 | TiXmlElement* tElem; |
---|
| 104 | TiXmlNode* tNode; |
---|
[513] | 105 | |
---|
[525] | 106 | Ogre::OverlayManager& omgr = Ogre::OverlayManager::getSingleton(); |
---|
| 107 | Ogre::Overlay* mLoadOverlay; |
---|
[513] | 108 | |
---|
[474] | 109 | // Set loading screen |
---|
[480] | 110 | loadElem = rootElement->FirstChildElement("loading"); |
---|
| 111 | if (loadElem) |
---|
[474] | 112 | { |
---|
| 113 | // Set background |
---|
[480] | 114 | tElem = loadElem->FirstChildElement("background"); |
---|
| 115 | if (tElem) |
---|
[474] | 116 | { |
---|
[480] | 117 | loadingBackgroundColor_ = tElem->Attribute("color"); |
---|
| 118 | loadingBackgroundImage_ = tElem->Attribute("image"); |
---|
[474] | 119 | } |
---|
| 120 | // Set bar |
---|
[480] | 121 | tElem = loadElem->FirstChildElement("bar"); |
---|
| 122 | if (tElem) |
---|
[474] | 123 | { |
---|
[480] | 124 | loadingBarImage_ = tElem->Attribute("image");; |
---|
| 125 | loadingBarTop_ = tElem->Attribute("top"); |
---|
| 126 | loadingBarLeft_ = tElem->Attribute("left"); |
---|
| 127 | loadingBarWidth_ = tElem->Attribute("width"); |
---|
| 128 | loadingBarHeight_ = tElem->Attribute("height"); |
---|
[474] | 129 | } |
---|
[525] | 130 | |
---|
| 131 | |
---|
| 132 | mLoadOverlay = (Ogre::Overlay*)omgr.getByName("Orxonox/LoadingScreenSample"); |
---|
| 133 | mLoadOverlay->show(); |
---|
| 134 | |
---|
| 135 | std::cout << "\n\n\nThis is Orxonox\nthe hottest 3D action shooter ever to exist\n\n\n"; |
---|
| 136 | std::cout << "Level: " << name() << "\nDescription:" << description() << "\nImage:"<<image()<<"\n\n\n"; |
---|
| 137 | std::cout << "Backgroundcolor: " << loadingBackgroundColor_ << "\nBackgroundimage:" << loadingBackgroundImage_ << "\n\n\n"; |
---|
| 138 | |
---|
[474] | 139 | } |
---|
[513] | 140 | |
---|
[480] | 141 | // Load audio |
---|
| 142 | // TODO |
---|
[513] | 143 | |
---|
[480] | 144 | // Load scripts |
---|
| 145 | // TODO |
---|
[513] | 146 | |
---|
[480] | 147 | // Load world |
---|
| 148 | worldElem = rootElement->FirstChildElement("world"); |
---|
| 149 | if (worldElem) |
---|
[513] | 150 | { |
---|
[480] | 151 | tNode = 0; |
---|
| 152 | while( tNode = worldElem->IterateChildren( tNode ) ) |
---|
| 153 | { |
---|
| 154 | tElem = tNode->ToElement(); |
---|
[496] | 155 | orxonox::BaseObject* obj = ID(tElem->Value())->fabricate(); |
---|
[480] | 156 | obj->loadParams(tElem); |
---|
[513] | 157 | } |
---|
[480] | 158 | } |
---|
[525] | 159 | |
---|
| 160 | if (loadElem) |
---|
| 161 | { |
---|
| 162 | mLoadOverlay->hide(); |
---|
| 163 | } |
---|
[513] | 164 | std::cout << "Loading finished!\n\n\n\n\n"; |
---|
[474] | 165 | } |
---|
[471] | 166 | } |
---|
[513] | 167 | |
---|
[507] | 168 | LevelLoader::~LevelLoader() |
---|
| 169 | { |
---|
| 170 | |
---|
| 171 | } |
---|
[513] | 172 | |
---|
| 173 | |
---|
[507] | 174 | string LevelLoader::name() |
---|
[164] | 175 | { |
---|
[507] | 176 | return this->name_; |
---|
[164] | 177 | } |
---|
[513] | 178 | |
---|
[507] | 179 | string LevelLoader::description() |
---|
[164] | 180 | { |
---|
[507] | 181 | return this->description_; |
---|
[164] | 182 | } |
---|
[513] | 183 | |
---|
[507] | 184 | string LevelLoader::image() |
---|
[164] | 185 | { |
---|
[507] | 186 | return this->image_; |
---|
[164] | 187 | } |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | } |
---|
| 191 | |
---|