GameGUI.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // GameGUI.cpp : Defines the entry point for the DLL application.
  13. //
  14. #include "stdafx.h"
  15. #ifdef _DEBUG
  16. #define GAMEGUI_DLL_NAME "GameGUIMPD.dll"
  17. #else
  18. #define GAMEGUI_DLL_NAME "GameGUIMP.dll"
  19. #endif
  20. extern CGame *_pGame = NULL;
  21. // global game object
  22. CGameGUI _GameGUI;
  23. static struct GameGUI_interface _Interface;
  24. // initialize game and load settings
  25. void Initialize(const CTFileName &fnGameSettings)
  26. {
  27. try {
  28. #ifndef NDEBUG
  29. #define GAMEDLL "Bin\\Debug\\GameMPD.dll"
  30. #else
  31. #define GAMEDLL "Bin\\GameMP.dll"
  32. #endif
  33. CTFileName fnmExpanded;
  34. ExpandFilePath(EFP_READ, CTString(GAMEDLL), fnmExpanded);
  35. HMODULE hGame = LoadLibraryA(fnmExpanded);
  36. if (hGame==NULL) {
  37. ThrowF_t("%s", GetWindowsError(GetLastError()));
  38. }
  39. CGame* (*GAME_Create)(void) = (CGame* (*)(void))GetProcAddress(hGame, "GAME_Create");
  40. if (GAME_Create==NULL) {
  41. ThrowF_t("%s", GetWindowsError(GetLastError()));
  42. }
  43. _pGame = GAME_Create();
  44. } catch (char *strError) {
  45. FatalError("%s", strError);
  46. }
  47. // init game - this will load persistent symbols
  48. _pGame->Initialize(fnGameSettings);
  49. }
  50. // save settings and cleanup
  51. void End(void)
  52. {
  53. _pGame->End();
  54. }
  55. // run a quicktest game from within editor
  56. void QuickTest(const CTFileName &fnMapName, CDrawPort *pdpDrawport, CViewPort *pvpViewport)
  57. {
  58. _pGame->QuickTest(fnMapName, pdpDrawport, pvpViewport);
  59. }
  60. // show console window
  61. void OnInvokeConsole(void)
  62. {
  63. _GameGUI.OnInvokeConsole();
  64. }
  65. // adjust players and controls
  66. void OnPlayerSettings(void)
  67. {
  68. _GameGUI.OnPlayerSettings();
  69. }
  70. // adjust audio settings
  71. void OnAudioQuality(void)
  72. {
  73. _GameGUI.OnAudioQuality();
  74. }
  75. // adjust video settings
  76. void OnVideoQuality(void)
  77. {
  78. _GameGUI.OnVideoQuality();
  79. }
  80. // select current active player and controls
  81. void OnSelectPlayerAndControls(void)
  82. {
  83. _GameGUI.OnSelectPlayerAndControls();
  84. }
  85. extern "C" _declspec(dllexport) struct GameGUI_interface *GAMEGUI_Create(void)
  86. {
  87. _Interface.Initialize = ::Initialize ;
  88. _Interface.End = ::End ;
  89. _Interface.QuickTest = ::QuickTest ;
  90. _Interface.OnInvokeConsole = ::OnInvokeConsole ;
  91. _Interface.OnPlayerSettings = ::OnPlayerSettings ;
  92. _Interface.OnAudioQuality = ::OnAudioQuality ;
  93. _Interface.OnVideoQuality = ::OnVideoQuality ;
  94. _Interface.OnSelectPlayerAndControls = ::OnSelectPlayerAndControls ;
  95. return &_Interface;
  96. }
  97. static int iDialogResult;
  98. #define CALL_DIALOG( class_name, dlg_name) \
  99. try { \
  100. _pGame->Load_t(); \
  101. } \
  102. catch( char *pError) { \
  103. (void) pError; \
  104. } \
  105. HANDLE hOldResource = AfxGetResourceHandle(); \
  106. class_name dlg_name; \
  107. AfxSetResourceHandle( GetModuleHandleA(GAMEGUI_DLL_NAME) ); \
  108. iDialogResult = dlg_name.DoModal(); \
  109. AfxSetResourceHandle( (HINSTANCE) hOldResource); \
  110. if( iDialogResult == IDOK) \
  111. try { \
  112. _pGame->Save_t(); \
  113. } \
  114. catch( char *pError) { \
  115. AfxMessageBox( CString(pError)); \
  116. iDialogResult = IDCANCEL; \
  117. }
  118. /*
  119. We cannot use dllmain if using MFC.
  120. See MSDN article "Regular DLLs Dynamically Linked to MFC" if initialization is needed.
  121. BOOL APIENTRY DllMain( HANDLE hModule,
  122. DWORD ul_reason_for_call,
  123. LPVOID lpReserved
  124. )
  125. {
  126. switch (ul_reason_for_call)
  127. {
  128. case DLL_PROCESS_ATTACH:
  129. case DLL_THREAD_ATTACH:
  130. case DLL_THREAD_DETACH:
  131. case DLL_PROCESS_DETACH:
  132. break;
  133. }
  134. return TRUE;
  135. }
  136. */
  137. /////////////////////////////////////////////////////////////////////////////
  138. // global routines called trough game's application menu
  139. void CGameGUI::OnInvokeConsole(void)
  140. {
  141. CALL_DIALOG( CDlgConsole, dlgConsole);
  142. }
  143. void CGameGUI::OnPlayerSettings(void)
  144. {
  145. //CALL_DIALOG( CDlgPlayerSettings, dlgPlayerSettings);
  146. }
  147. void CGameGUI::OnAudioQuality(void)
  148. {
  149. CALL_DIALOG( CDlgAudioQuality, dlgAudioQuality);
  150. }
  151. void CGameGUI::OnVideoQuality(void)
  152. {
  153. CALL_DIALOG( CDlgVideoQuality, dlgVideoQuality);
  154. }
  155. void CGameGUI::OnSelectPlayerAndControls(void)
  156. {
  157. //CALL_DIALOG( CDlgSelectPlayer, dlgSelectPlayerAndControls);
  158. }