TextManagerCommands.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 "ConfigCmdManager.h"
  16. #include "Console.h"
  17. #include "Logger.h"
  18. #include "XmlTextsFile.h"
  19. /**
  20. * Sets the language for texts.
  21. *
  22. * @param params[in] 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(
  30. "Usage: /set_language <language>"
  31. );
  32. return;
  33. }
  34. TextManager::getSingleton().SetLanguage(params[1]);
  35. LOG_TRIVIAL("Set game language to \"" + params[1] + "\".");
  36. }
  37. /**
  38. * Loads a list of every available language identifiers.
  39. *
  40. * To do so, it uses the folders in data/texts.
  41. *
  42. * @param complete_params[out] The list of languages will be saved here.
  43. */
  44. void CmdSetLanguageCompletition(Ogre::StringVector& complete_params){
  45. XmlTextsFile texts( "./data/texts.xml" );
  46. texts.GetAvailableLanguages(complete_params);
  47. }
  48. void TextManager::InitCmd(){
  49. ConfigCmdManager::getSingleton().AddCommand(
  50. "set_language", "Change language of texts and dialogs", "",
  51. CmdSetLanguage, CmdSetLanguageCompletition
  52. );
  53. }