TextHandlerCommands.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 "ConfigCmdHandler.h"
  16. #include "Console.h"
  17. #include "Logger.h"
  18. #include "XmlTextsFile.h"
  19. /**
  20. * Sets the language for texts.
  21. *
  22. * @param[in] params Command parameters. Exactly three are required. The first
  23. * one is the command name and it's not evaluated here. The second one must be
  24. * the language to set. If less than three parameter are passed, a usage string
  25. * will be printed instead, and nothing will be done.
  26. */
  27. void CmdSetLanguage(const Ogre::StringVector& params){
  28. if (params.size() < 2){
  29. Console::getSingleton().AddTextToOutput("Usage: /set_language <language>");
  30. return;
  31. }
  32. TextHandler::getSingleton().SetLanguage(params[1]);
  33. LOG_TRIVIAL("Set game language to \"" + params[1] + "\".");
  34. }
  35. /**
  36. * Loads a list of every available language identifiers.
  37. *
  38. * To do so, it uses the folders in data/texts.
  39. *
  40. * @param[out] complete_params The list of languages will be saved here.
  41. */
  42. void CmdSetLanguageCompletition(Ogre::StringVector& complete_params){
  43. XmlTextsFile texts( "./data/texts.xml" );
  44. texts.GetAvailableLanguages(complete_params);
  45. }
  46. void TextHandler::InitCmd(){
  47. ConfigCmdHandler::getSingleton().AddCommand(
  48. "set_language", "Change language of texts and dialogs", "",
  49. CmdSetLanguage, CmdSetLanguageCompletition
  50. );
  51. }