XmlTextFile.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include "core/Logger.h"
  16. #include "core/UiManager.h"
  17. #include "core/XmlTextFile.h"
  18. #include "TextHandler.h"
  19. XmlTextFile::XmlTextFile(const Ogre::String& file): XmlFile(file){}
  20. XmlTextFile::~XmlTextFile(){}
  21. void XmlTextFile::LoadTexts(){
  22. TiXmlNode* node = file_.RootElement();
  23. if(node == nullptr || node->ValueStr() != "texts"){
  24. LOG_ERROR(
  25. "Text File: " + file_.ValueStr() + " is not a valid text file! No <texts> in root."
  26. );
  27. return;
  28. }
  29. node = node->FirstChild();
  30. while (node != nullptr){
  31. if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "text"){
  32. Ogre::String name = GetString(node, "name");
  33. TextHandler::getSingleton().AddText(name, node->Clone());
  34. }
  35. else if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "dialog"){
  36. Ogre::String name = GetString(node, "name");
  37. float width = GetFloat(node, "width", 0.0f);
  38. float height = GetFloat(node, "height", 0.0f);
  39. TextHandler::getSingleton().AddDialog(name, node->Clone(), width, height);
  40. }
  41. node = node->NextSibling();
  42. }
  43. }