functions.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. #ifndef FUNC_INCLUDED
  17. #define FUNC_INCLUDED
  18. #include <afx.h>
  19. #include <memory>
  20. #include <array>
  21. bool deleteFile(const std::string& u8FilePath);
  22. // set the status bar text in the main dialog
  23. void SetMainStatusBar(const char* text);
  24. // set the status bar text in the main dialog to ready
  25. void SetMainStatusBarReady();
  26. // change all %n (where n is an int) in an string, to another specified string
  27. CString TranslateStringVariables(int n, const char* originaltext, const char* inserttext);
  28. // Alliance->Korea etc...
  29. CString TranslateHouse(CString original, BOOL bToUI=FALSE);
  30. // show options dialog
  31. void ShowOptionsDialog();
  32. // repairs a trigger (sets flags correctly)
  33. void RepairTrigger(CString& triggerdata);
  34. // coordinate functions
  35. void PosToXY(const char* pos, int* X, int* Y);
  36. // HSV -> RGB
  37. void HSVToRGB(const unsigned char hsv[3], unsigned char rgb[3]);
  38. std::array<unsigned char, 3> HSVToRGB(float h, float s, float v);
  39. std::array<unsigned char, 3> HSVToRGB(const unsigned char hsv[3]);
  40. void GetDrawBorder(const BYTE* data, int width, int line, int& left, int& right, unsigned int flags, BOOL* TranspInside = NULL);
  41. // String conversion
  42. std::wstring utf8ToUtf16(const char* utf8);
  43. std::wstring utf8ToUtf16(const std::string& utf8);
  44. std::string utf16ToUtf8(const std::wstring& utf16);
  45. std::string utf16ToACP(const std::wstring& utf16);
  46. // map functions
  47. int GetNodeAt(string& owner, string& type, int x, int y);
  48. int SetNodeAt(string owner, string type, int x, int y);
  49. void ClearNode(int n, string owner);
  50. CString GetFreeID();
  51. void HandleParamList(CComboBox &cb, int type);
  52. // sets 0 if there is a space in the string, so truncates it at the first space occupation
  53. void TruncSpace(string& str);
  54. void TruncSpace(CString& str);
  55. // checks if a file exists
  56. BOOL DoesFileExist(LPCSTR szFile);
  57. // Lists some things
  58. void ListHouses(CComboBox &cb, BOOL bNumbers=FALSE, BOOL bCountries=FALSE, BOOL bPlayers=FALSE);
  59. void ListTeamTypes(CComboBox &cb, BOOL bListNone=FALSE);
  60. void ListWaypoints(CComboBox &cb);
  61. void ListTargets(CComboBox& cb);
  62. void ListTags(CComboBox& cb, BOOL bListNone);
  63. void ListMovies(CComboBox& cb, BOOL bListNone, BOOL bListParam=FALSE);
  64. void ListBuildings(CComboBox& cb, BOOL bININame=FALSE);
  65. void ListUnits(CComboBox& cb);
  66. void ListAircraft(CComboBox& cb);
  67. void ListInfantry(CComboBox& cb);
  68. void ListTutorial(CComboBox& cb);
  69. void ListTriggers(CComboBox& cb);
  70. void ListYesNo(CComboBox& cb);
  71. void ListSounds(CComboBox& cb);
  72. void ListThemes(CComboBox& cb);
  73. void ListSpeeches(CComboBox& cb);
  74. void ListSpecialWeapons(CComboBox& cb);
  75. void ListAnimations(CComboBox& cb);
  76. void ListParticles(CComboBox& cb);
  77. void ListCrateTypes(CComboBox& cb);
  78. void ListSpeechBubbleTypes(CComboBox& cb);
  79. void ListGlobals(CComboBox& cb);
  80. void ListRulesGlobals(CComboBox& cb);
  81. void ListTechtypes(CComboBox& cb);
  82. // some easy-to-use functions
  83. CString GetText(CWnd* wnd);
  84. CString GetText(CComboBox* wnd);
  85. CString GetText(CSliderCtrl* wnd);
  86. CString GetHouseSectionName(CString lpHouse);
  87. // fix bug
  88. int RepairRulesHouses();
  89. // strcpy_safe allows overlapping of source & destination. strcpy may be faster though!
  90. char *strcpy_safe( char *strDestination, const char *strSource );
  91. /****************************************
  92. language support functions [12/18/1999]
  93. ****************************************/
  94. // retrieve the string name in the correct language (name is an ID).
  95. // the returned string is in the active codepage (UTF-8 on Windows 10 1909+)
  96. CString GetLanguageStringACP(CString name);
  97. // tranlate a string/word by using the table from english to the current language
  98. // the returned string is in the active codepage (UTF-8 on Windows 10 1909+)
  99. CString TranslateStringACP(CString u8EnglishString);
  100. // tranlate a string/word by using the table from english to the current language
  101. // the returned string is in the active codepage (UTF-8 on Windows 10 1909+)
  102. CString TranslateStringACP(WCHAR* u16EnglishString);
  103. /****************************************
  104. sound functions [03/16/2001]
  105. ****************************************/
  106. // general play sound function. uses parameter in defines.h. Does only play if user has not deactivated sounds
  107. void Sound(int ID);
  108. class BitmapNotFound : std::runtime_error
  109. {
  110. public:
  111. BitmapNotFound(): std::runtime_error("Bitmap not found") {}
  112. };
  113. std::unique_ptr<CBitmap> BitmapFromResource(int resource_id);
  114. std::unique_ptr<CBitmap> BitmapFromFile(const CString& filepath);
  115. CComPtr<IDirectDrawSurface4> BitmapToSurface(IDirectDraw4 * pDD, const CBitmap& bitmap);
  116. #endif