changeset 2554:f2a8ed07e921

Game Main Menu separated from Game logic
author a.parshin
date Wed, 13 May 2015 11:31:58 +0200
parents 48708da03b7f
children 67d837007a4c 5d6fb8eb023c
files Build/Visual Studio 2013/World of Might and Magic.vcxproj Build/Visual Studio 2013/World of Might and Magic.vcxproj.filters Build/Visual Studio 2013/World of Might and Magic.vcxproj.user Engine/Engine.cpp Engine/Objects/Player.cpp Engine/Spells/CastSpellInfo.cpp GUI/GUIButton.cpp GUI/GUIWindow.h GUI/UI/UICharacter.cpp GUI/UI/UiGame.cpp Game/Game.cpp Game/GameMenu.cpp Game/GameMenu.h
diffstat 13 files changed, 907 insertions(+), 486 deletions(-) [+]
line wrap: on
line diff
--- a/Build/Visual Studio 2013/World of Might and Magic.vcxproj	Wed May 13 02:20:05 2015 +0200
+++ b/Build/Visual Studio 2013/World of Might and Magic.vcxproj	Wed May 13 11:31:58 2015 +0200
@@ -153,6 +153,7 @@
     <ClCompile Include="..\..\Engine\ZlibWrapper.cpp" />
     <ClCompile Include="..\..\Game\CreateParty.cpp" />
     <ClCompile Include="..\..\Game\Game.cpp" />
+    <ClCompile Include="..\..\Game\GameMenu.cpp" />
     <ClCompile Include="..\..\Game\GameOver.cpp" />
     <ClCompile Include="..\..\Game\MainMenu.cpp" />
     <ClCompile Include="..\..\Game\MainMenuLoad.cpp" />
@@ -334,6 +335,7 @@
     <ClInclude Include="..\..\Engine\ZlibWrapper.h" />
     <ClInclude Include="..\..\Game\CreateParty.h" />
     <ClInclude Include="..\..\Game\Game.h" />
+    <ClInclude Include="..\..\Game\GameMenu.h" />
     <ClInclude Include="..\..\Game\GameOver.h" />
     <ClInclude Include="..\..\Game\MainMenu.h" />
     <ClInclude Include="..\..\Game\MainMenuLoad.h" />
--- a/Build/Visual Studio 2013/World of Might and Magic.vcxproj.filters	Wed May 13 02:20:05 2015 +0200
+++ b/Build/Visual Studio 2013/World of Might and Magic.vcxproj.filters	Wed May 13 11:31:58 2015 +0200
@@ -607,6 +607,9 @@
     <ClCompile Include="..\..\Game\CreateParty.cpp">
       <Filter>Game</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\Game\GameMenu.cpp">
+      <Filter>Game</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\lib\libavcodec\avcodec.h">
@@ -1381,6 +1384,9 @@
     <ClInclude Include="..\..\Game\CreateParty.h">
       <Filter>Game</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\Game\GameMenu.h">
+      <Filter>Game</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\lib\OpenAL\lib\x86\avcodec-55.def">
--- a/Build/Visual Studio 2013/World of Might and Magic.vcxproj.user	Wed May 13 02:20:05 2015 +0200
+++ b/Build/Visual Studio 2013/World of Might and Magic.vcxproj.user	Wed May 13 11:31:58 2015 +0200
@@ -4,6 +4,6 @@
     <LocalDebuggerCommand>$(OutDir)$(TargetName)$(TargetExt)</LocalDebuggerCommand>
     <LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
     <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
-    <LocalDebuggerCommandArguments>-nomarg -window -nointro -nologo</LocalDebuggerCommandArguments>
+    <LocalDebuggerCommandArguments>-nomarg -window -nointro -nologo -nocd</LocalDebuggerCommandArguments>
   </PropertyGroup>
 </Project>
\ No newline at end of file
--- a/Engine/Engine.cpp	Wed May 13 02:20:05 2015 +0200
+++ b/Engine/Engine.cpp	Wed May 13 11:31:58 2015 +0200
@@ -2445,7 +2445,7 @@
 
     if (pGUIWindow_ScrollWindow)
         free_book_subwindow();
-    if (!current_screen_type && !pGUIWindow_Settings)
+    if (!current_screen_type && !pGUIWindow_CastTargetedSpell)
         pEventTimer->Resume();
     viewparams->bRedrawGameUI = 1;
 }
--- a/Engine/Objects/Player.cpp	Wed May 13 02:20:05 2015 +0200
+++ b/Engine/Objects/Player.cpp	Wed May 13 11:31:58 2015 +0200
@@ -7604,11 +7604,11 @@
         enchantedItemPos = this->GetItemIDAtInventoryIndex(&invMatrixIndex);
         if ( enchantedItemPos )
         {
-         /* *((char *)pGUIWindow_Settings->ptr_1C + 8) &= 0x7Fu;
-          *((short *)pGUIWindow_Settings->ptr_1C + 2) = uActiveCharacter - 1;
-          *((int *)pGUIWindow_Settings->ptr_1C + 3) = enchantedItemPos - 1;
-          *((short *)pGUIWindow_Settings->ptr_1C + 3) = invMatrixIndex;*/
-          pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+         /* *((char *)pGUIWindow_CastTargetedSpell->ptr_1C + 8) &= 0x7Fu;
+          *((short *)pGUIWindow_CastTargetedSpell->ptr_1C + 2) = uActiveCharacter - 1;
+          *((int *)pGUIWindow_CastTargetedSpell->ptr_1C + 3) = enchantedItemPos - 1;
+          *((short *)pGUIWindow_CastTargetedSpell->ptr_1C + 3) = invMatrixIndex;*/
+          pSpellInfo = (CastSpellInfo *)pGUIWindow_CastTargetedSpell->ptr_1C;
           pSpellInfo->uFlags &= 0x7F;
           pSpellInfo->uPlayerID_2 = uActiveCharacter - 1;
           pSpellInfo->spell_target_pid = enchantedItemPos - 1;
--- a/Engine/Spells/CastSpellInfo.cpp	Wed May 13 02:20:05 2015 +0200
+++ b/Engine/Spells/CastSpellInfo.cpp	Wed May 13 11:31:58 2015 +0200
@@ -3284,8 +3284,8 @@
     if (pCastSpellInfo[i].uSpellID && pCastSpellInfo[i].uFlags & 0x3CA)
     {
       pCastSpellInfo[i].uSpellID = 0;
-      pGUIWindow_Settings->Release();
-      pGUIWindow_Settings = 0;
+      pGUIWindow_CastTargetedSpell->Release();
+      pGUIWindow_CastTargetedSpell = nullptr;
       pMouse->SetCursorBitmap("MICON1");
       GameUI_Footer_TimeLeft = 0;
       _50C9A0_IsEnchantingInProgress = 0;
@@ -3487,8 +3487,8 @@
       spell->uSpellID = 0;
       if (spell->uFlags & 0x3CA)
       {
-        pGUIWindow_Settings->Release();
-        pGUIWindow_Settings = nullptr;
+        pGUIWindow_CastTargetedSpell->Release();
+        pGUIWindow_CastTargetedSpell = nullptr;
         pMouse->SetCursorBitmap("MICON1");
         GameUI_Footer_TimeLeft = 0;
         _50C9A0_IsEnchantingInProgress = 0;
@@ -3501,44 +3501,44 @@
     {
       if ( a5 & 2 )
       {
-        if ( pGUIWindow_Settings )
+        if ( pGUIWindow_CastTargetedSpell )
           return;
-        pGUIWindow_Settings = new OnCastTargetedSpell(0, 0, window->GetWidth(), window->GetHeight(), (int)&pCastSpellInfo[result], 0);
-        pGUIWindow_Settings->CreateButton(52, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 0, 49, "", 0);
-        pGUIWindow_Settings->CreateButton(165, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 1, 50, "", 0);
-        pGUIWindow_Settings->CreateButton(280, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 2, 51, "", 0);
-        pGUIWindow_Settings->CreateButton(390, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 3, 52, "", 0);
+        pGUIWindow_CastTargetedSpell = new OnCastTargetedSpell(0, 0, window->GetWidth(), window->GetHeight(), (int)&pCastSpellInfo[result], 0);
+        pGUIWindow_CastTargetedSpell->CreateButton(52, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 0, 49, "", 0);
+        pGUIWindow_CastTargetedSpell->CreateButton(165, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 1, 50, "", 0);
+        pGUIWindow_CastTargetedSpell->CreateButton(280, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 2, 51, "", 0);
+        pGUIWindow_CastTargetedSpell->CreateButton(390, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 3, 52, "", 0);
         pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
         return;
       }
       if ( a5 & 8 )
       {
-        if ( pGUIWindow_Settings )
+        if ( pGUIWindow_CastTargetedSpell )
           return;
 
-        pGUIWindow_Settings = new OnCastTargetedSpell(0, 0, window->GetWidth(), window->GetHeight(), (int)&pCastSpellInfo[result], 0);
-        pGUIWindow_Settings->CreateButton(game_viewport_x, game_viewport_y, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_Shoot_Monster, 0, 0, "", 0);
+        pGUIWindow_CastTargetedSpell = new OnCastTargetedSpell(0, 0, window->GetWidth(), window->GetHeight(), (int)&pCastSpellInfo[result], 0);
+        pGUIWindow_CastTargetedSpell->CreateButton(game_viewport_x, game_viewport_y, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_Shoot_Monster, 0, 0, "", 0);
         pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
         return;
       }
       if ( a5 & 0x40 )
       {
-        if ( pGUIWindow_Settings )
+        if ( pGUIWindow_CastTargetedSpell )
           return;
 
-        pGUIWindow_Settings = new OnCastTargetedSpell(0, 0, window->GetWidth(), window->GetHeight(), (int)&pCastSpellInfo[result], 0);
-        pGUIWindow_Settings->CreateButton(game_viewport_x, game_viewport_y, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_Telekinesis, 0, 0, "", 0);
+        pGUIWindow_CastTargetedSpell = new OnCastTargetedSpell(0, 0, window->GetWidth(), window->GetHeight(), (int)&pCastSpellInfo[result], 0);
+        pGUIWindow_CastTargetedSpell->CreateButton(game_viewport_x, game_viewport_y, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_Telekinesis, 0, 0, "", 0);
         pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
         return;
       }
       if ( (char)a5 < 0 )
       {
-        if ( pGUIWindow_Settings )
+        if ( pGUIWindow_CastTargetedSpell )
           return;
         ++pIcons_LOD->uTexturePacksCount;
         if ( !pIcons_LOD->uNumPrevLoadedFiles )
           pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
-        pGUIWindow_Settings = pCastSpellInfo[result].GetCastSpellInInventoryWindow();
+        pGUIWindow_CastTargetedSpell = pCastSpellInfo[result].GetCastSpellInInventoryWindow();
         _50C9A0_IsEnchantingInProgress = 1;
         some_active_character = uActiveCharacter;
         pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
@@ -3546,31 +3546,31 @@
       }
       if ( HIBYTE(a5) & 1 )
       {
-        if ( pGUIWindow_Settings )
+        if ( pGUIWindow_CastTargetedSpell )
           return;
-        pGUIWindow_Settings = new OnCastTargetedSpell(0, 0, window->GetWidth(), window->GetHeight(), (int)&pCastSpellInfo[result], 0);
-        pGUIWindow_Settings->CreateButton(0x34u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 0, 0x31u, "", 0);
-        pGUIWindow_Settings->CreateButton(0xA5u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 1, 0x32u, "", 0);
-        pGUIWindow_Settings->CreateButton(0x118u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 2, 0x33u, "", 0);
-        pGUIWindow_Settings->CreateButton(0x186u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 3, 0x34u, "", 0);
-        pGUIWindow_Settings->CreateButton(8, 8, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_Monster_Improvement, 0, 0, "", NULL);
+        pGUIWindow_CastTargetedSpell = new OnCastTargetedSpell(0, 0, window->GetWidth(), window->GetHeight(), (int)&pCastSpellInfo[result], 0);
+        pGUIWindow_CastTargetedSpell->CreateButton(0x34u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 0, 0x31u, "", 0);
+        pGUIWindow_CastTargetedSpell->CreateButton(0xA5u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 1, 0x32u, "", 0);
+        pGUIWindow_CastTargetedSpell->CreateButton(0x118u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 2, 0x33u, "", 0);
+        pGUIWindow_CastTargetedSpell->CreateButton(0x186u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 3, 0x34u, "", 0);
+        pGUIWindow_CastTargetedSpell->CreateButton(8, 8, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_Monster_Improvement, 0, 0, "", NULL);
         pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
       }
-      if ( HIBYTE(a5) & 2 && !pGUIWindow_Settings )
+      if ( HIBYTE(a5) & 2 && !pGUIWindow_CastTargetedSpell )
       {
-          pGUIWindow_Settings = new OnCastTargetedSpell(0, 0, window->GetWidth(), window->GetHeight(), (int)&pCastSpellInfo[result], 0);
-        pBtn_NPCLeft = pGUIWindow_Settings->CreateButton(469, 178,
+          pGUIWindow_CastTargetedSpell = new OnCastTargetedSpell(0, 0, window->GetWidth(), window->GetHeight(), (int)&pCastSpellInfo[result], 0);
+        pBtn_NPCLeft = pGUIWindow_CastTargetedSpell->CreateButton(469, 178,
                        pIcons_LOD->GetTexture(uTextureID_Btn_NPCLeft)->uTextureWidth,
                        pIcons_LOD->GetTexture(uTextureID_Btn_NPCLeft)->uTextureHeight,
                        1, 0, UIMSG_ScrollNPCPanel, 0, 0, "",
                        pIcons_LOD->GetTexture(uTextureID_Btn_NPCLeft), 0);
-        pBtn_NPCRight = pGUIWindow_Settings->CreateButton(626, 178,
+        pBtn_NPCRight = pGUIWindow_CastTargetedSpell->CreateButton(626, 178,
                        pIcons_LOD->GetTexture(uTextureID_Btn_NPCRight)->uTextureWidth,
                        pIcons_LOD->GetTexture(uTextureID_Btn_NPCRight)->uTextureHeight,
                        1, 0, UIMSG_ScrollNPCPanel, 1, 0, "",
                        pIcons_LOD->GetTexture(uTextureID_Btn_NPCRight), 0);
-        pGUIWindow_Settings->CreateButton(491, 149, 64, 74, 1, 0, UIMSG_HiredNPC_CastSpell, 4, 0x35u, "", 0);
-        pGUIWindow_Settings->CreateButton(561, 149, 64, 74, 1, 0, UIMSG_HiredNPC_CastSpell, 5, 0x36u, "", 0);
+        pGUIWindow_CastTargetedSpell->CreateButton(491, 149, 64, 74, 1, 0, UIMSG_HiredNPC_CastSpell, 4, 0x35u, "", 0);
+        pGUIWindow_CastTargetedSpell->CreateButton(561, 149, 64, 74, 1, 0, UIMSG_HiredNPC_CastSpell, 5, 0x36u, "", 0);
       }
     }
 }
--- a/GUI/GUIButton.cpp	Wed May 13 02:20:05 2015 +0200
+++ b/GUI/GUIButton.cpp	Wed May 13 11:31:58 2015 +0200
@@ -85,7 +85,7 @@
 struct GUIWindow *ptr_507BC8;
 struct GUIWindow *pGUIWindow_CurrentMenu;
 struct GUIWindow *ptr_507BD0;
-struct GUIWindow *pGUIWindow_Settings;
+struct GUIWindow *pGUIWindow_CastTargetedSpell;
 struct GUIWindow *pModalWindow;
 struct GUIWindow *pGUIWindow_EscMessageWindow;
 struct GUIWindow *pBooksButtonOverlay;
--- a/GUI/GUIWindow.h	Wed May 13 02:20:05 2015 +0200
+++ b/GUI/GUIWindow.h	Wed May 13 11:31:58 2015 +0200
@@ -830,7 +830,7 @@
 extern struct GUIWindow *ptr_507BC8;
 extern struct GUIWindow *pGUIWindow_CurrentMenu;
 extern struct GUIWindow *ptr_507BD0;
-extern struct GUIWindow *pGUIWindow_Settings;
+extern struct GUIWindow *pGUIWindow_CastTargetedSpell;
 extern struct GUIWindow *pModalWindow;
 extern struct GUIWindow *pGUIWindow_EscMessageWindow;
 extern struct GUIWindow *pBooksButtonOverlay;
--- a/GUI/UI/UICharacter.cpp	Wed May 13 02:20:05 2015 +0200
+++ b/GUI/UI/UICharacter.cpp	Wed May 13 11:31:58 2015 +0200
@@ -2743,11 +2743,11 @@
     }
     if ( _50C9A0_IsEnchantingInProgress )//наложить закл на экипировку
     {
-      /* *((char *)pGUIWindow_Settings->ptr_1C + 8) &= 0x7Fu;//CastSpellInfo
-      *((short *)pGUIWindow_Settings->ptr_1C + 2) = uActiveCharacter - 1;
-      *((int *)pGUIWindow_Settings->ptr_1C + 3) = v36;
-      *((short *)pGUIWindow_Settings->ptr_1C + 3) = pEquipType;*/
-      pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+      /* *((char *)pGUIWindow_CastTargetedSpell->ptr_1C + 8) &= 0x7Fu;//CastSpellInfo
+      *((short *)pGUIWindow_CastTargetedSpell->ptr_1C + 2) = uActiveCharacter - 1;
+      *((int *)pGUIWindow_CastTargetedSpell->ptr_1C + 3) = v36;
+      *((short *)pGUIWindow_CastTargetedSpell->ptr_1C + 3) = pEquipType;*/
+      pSpellInfo = (CastSpellInfo *)pGUIWindow_CastTargetedSpell->ptr_1C;
       pSpellInfo->uFlags &= 0x7F;
       pSpellInfo->uPlayerID_2 = uActiveCharacter - 1;
       pSpellInfo->spell_target_pid = v34 - 1;
--- a/GUI/UI/UiGame.cpp	Wed May 13 02:20:05 2015 +0200
+++ b/GUI/UI/UiGame.cpp	Wed May 13 11:31:58 2015 +0200
@@ -44,8 +44,6 @@
 int uTextureID_GameUI_CharSelectionFrame; // 50C98C
 
 
-
-
 GUIWindow_GameMenu::GUIWindow_GameMenu() :
     GUIWindow(0, 0, window->GetWidth(), window->GetHeight(), 0, nullptr)
 {
--- a/Game/Game.cpp	Wed May 13 02:20:05 2015 +0200
+++ b/Game/Game.cpp	Wed May 13 11:31:58 2015 +0200
@@ -53,6 +53,7 @@
 #include "GUI/UI/Books/JournalBook.h"
 
 #include "Game/Game.h"
+#include "Game/GameMenu.h"
 
 
 void DoThatMessageThing()
@@ -111,58 +112,38 @@
 }
 
 
-void Game_StartNewGameWhilePlaying(bool force_start)
+
+void Game_CloseTargetedSpellWindow()
 {
-    if (dword_6BE138 == 124 || force_start)
+    if (pGUIWindow_CastTargetedSpell)
     {
-        pIcons_LOD->SyncLoadedFilesCount();
-        pIcons_LOD->RemoveTexturesPackFromTextureList();
-        DoThatMessageThing();
-        pGUIWindow_CurrentMenu->Release();
-        uGameState = GAME_STATE_NEWGAME_OUT_GAMEMENU;
-        current_screen_type = SCREEN_GAME;
-        viewparams->bRedrawGameUI = 1;
+        if (current_screen_type == SCREEN_CHARACTERS)
+            pMouse->SetCursorBitmap("MICON2");
+        else
+        {
+            pGUIWindow_CastTargetedSpell->Release();
+            pGUIWindow_CastTargetedSpell = nullptr;
+            pMouse->SetCursorBitmap("MICON1");
+            GameUI_Footer_TimeLeft = 0;
+            _50C9A0_IsEnchantingInProgress = 0;
+            back_to_game();
+        }
     }
-    else
-    {
-        ShowStatusBarString(pGlobalTXT_LocalizationStrings[201], 2);// "Are you sure?  Click again to start a New Game"
-        pAudioPlayer->PlaySound(SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
-        dword_6BE138 = 124;
-    }
-    stru_506E40.Release();
 }
 
-void Game_QuitGameWhilePlaying(bool force_quit)
+void Game_OnEscape()
 {
-    if (dword_6BE138 == 132 || force_quit)
-    {
-        pIcons_LOD->SyncLoadedFilesCount();
-        pIcons_LOD->RemoveTexturesPackFromTextureList();
-        DoThatMessageThing();
-        pGUIWindow_CurrentMenu->Release();
-        current_screen_type = SCREEN_GAME;
-        viewparams->bRedrawGameUI = 1;
-        pAudioPlayer->PlaySound(SOUND_WoodDoorClosing, 0, 0, -1, 0, 0, 0, 0);
-        uGameState = GAME_STATE_GAME_QUITTING_TO_MAIN_MENU;
-    }
-    else
-    {
-        ShowStatusBarString(pGlobalTXT_LocalizationStrings[82], 2);// "Are you sure?  Click again to quit"
-        pAudioPlayer->PlaySound(SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
-        dword_6BE138 = 132;
-    }
-    stru_506E40.Release();
-}
-
-void Game_OpenLoadGameDialog()
-{
-    pIcons_LOD->SyncLoadedFilesCount();
-    pIcons_LOD->RemoveTexturesPackFromTextureList();
-    DoThatMessageThing();
+    Game_CloseTargetedSpellWindow();
+    if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
+        uActiveCharacter = pParty->GetNextActiveCharacter();
     pGUIWindow_CurrentMenu->Release();
-
-    //LoadUI_Load(1);
-    pGUIWindow_CurrentMenu = new GUIWindow_Load(true);
+    if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
+        window_SpeakInHouse = 0;
+    pGUIWindow_CurrentMenu = 0;
+    pEventTimer->Resume();
+    current_screen_type = SCREEN_GAME;
+    viewparams->bRedrawGameUI = true;
+    pIcons_LOD->RemoveTexturesFromTextureList();
 }
 
 
@@ -334,9 +315,9 @@
             case UIMSG_SelectShopDialogueOption:  OnSelectShopDialogueOption(uMessageParam); continue;
             case UIMSG_SelectNPCDialogueOption:   OnSelectNPCDialogueOption((DIALOGUE_TYPE)uMessageParam); continue;
             case UIMSG_ClickHouseNPCPortrait:     _4B4224_UpdateNPCTopics(uMessageParam); continue;
-            case UIMSG_StartNewGame:              Game_StartNewGameWhilePlaying(uMessageParam); continue;
-            case UIMSG_Game_OpenLoadGameDialog:   Game_OpenLoadGameDialog(); continue;
-            case UIMSG_Quit:                      Game_QuitGameWhilePlaying(uMessageParam); continue;
+            //case UIMSG_StartNewGame:              Game_StartNewGameWhilePlaying(uMessageParam); continue;
+            //case UIMSG_Game_OpenLoadGameDialog:   Game_OpenLoadGameDialog(); continue;
+            //case UIMSG_Quit:                      Game_QuitGameWhilePlaying(uMessageParam); continue;
             case UIMSG_80:
                 __debugbreak();
                 pIcons_LOD->SyncLoadedFilesCount();
@@ -345,7 +326,7 @@
                 current_screen_type = SCREEN_OPTIONS;
                 __debugbreak();//pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_8, 0, 0);
                 continue;
-            case UIMSG_ArrowUp:
+            /*case UIMSG_ArrowUp:
                 --pSaveListPosition;
                 if (pSaveListPosition < 0)
                     pSaveListPosition = 0;
@@ -356,11 +337,11 @@
                 if (pSaveListPosition >= uMessageParam)
                     pSaveListPosition = uMessageParam - 1;
                 new OnButtonClick2(215, 323, 17, 17, (int)pBtnDownArrow, 0);
-                continue;
+                continue;*/
             case UIMSG_Cancel:
                 new OnCancel(350, 302, 106, 42, (int)pBtnCancel, 0);
                 continue;
-            case UIMSG_SaveLoadBtn:
+            /*case UIMSG_SaveLoadBtn:
                 new OnSaveLoad(241, 302, 106, 42, (int)pBtnLoadSlot, 0);
                 continue;
             case UIMSG_SelectLoadSlot:
@@ -405,6 +386,8 @@
             case UIMSG_Game_OpenSaveGameDialog:
             {
                 pGUIWindow_CurrentMenu->Release();
+
+                current_screen_type = SCREEN_SAVEGAME;
                 pGUIWindow_CurrentMenu = new GUIWindow_Save(); //SaveUI_Load(current_screen_type = SCREEN_SAVEGAME);
                 continue;
             }
@@ -664,27 +647,27 @@
                 continue;
 
             case UIMSG_SetGraphicsMode:
-                /*if ( !bUseLoResSprites )
-                {
-                byte_6BE388_graphicsmode = uMessageParam;
-                MM7Initialization();
-                continue;
-                }
-                if ( uMessageParam )
-                {
-                if ( uMessageParam == 1 )
-                {
-                byte_6BE388_graphicsmode = 0;
-                }
-                else
-                {
-                if ( uMessageParam != 2 )
-                continue;
-                byte_6BE388_graphicsmode = 1;
-                }
-                MM7Initialization();
-                continue;
-                }*/
+                //if ( !bUseLoResSprites )
+                //{
+                //    byte_6BE388_graphicsmode = uMessageParam;
+                //    MM7Initialization();
+                //    continue;
+                //}
+                //if ( uMessageParam )
+                //{
+                //    if ( uMessageParam == 1 )
+                //    {
+                //    byte_6BE388_graphicsmode = 0;
+                //    }
+                //    else
+                //    {
+                //        if ( uMessageParam != 2 )
+                //            continue;
+                //        byte_6BE388_graphicsmode = 1;
+                //    }
+                //    MM7Initialization();
+                //    continue;
+                //}
                 pModalWindow = new GUIWindow_Modal(pNPCTopics[453].pText, UIMSG_0);
                 __debugbreak(); // Nomad: graphicsmode as it was now removed
                 continue;
@@ -695,7 +678,7 @@
                 current_screen_type = SCREEN_GAME;
                 viewparams->bRedrawGameUI = 1;
                 stru_506E40.Release();
-                continue;
+                continue;*/
             case UIMSG_OpenQuestBook:
                 DoThatMessageThing();
                 if (current_screen_type != SCREEN_GAME)
@@ -753,42 +736,142 @@
                     }
                     break;
                 }
-                if (!pModalWindow)
+                if (pModalWindow)
                 {
+                    pModalWindow->Release();
+                    pModalWindow = nullptr;
+                    continue;
+                }
                     pRenderer->ClearZBuffer(0, 479);
-                    viewparams->bRedrawGameUI = 1;
+                    viewparams->bRedrawGameUI = true;
                     viewparams->field_48 = 1;
-                    if (current_screen_type != SCREEN_GAME)
+                    if (current_screen_type == SCREEN_GAME)
+                    {
+                        if (!pGUIWindow_CastTargetedSpell)//Draw Menu
+                        {
+                            dword_6BE138 = -1;
+                            new OnButtonClick2(0x25Au, 0x1C2u, 0, 0, (int)pBtn_GameSettings, (char *)1);
+
+                            DoThatMessageThing();
+                            GameMenu_Loop();
+                        }
+                        else
+                        {
+                            pGUIWindow_CastTargetedSpell->Release();
+                            pGUIWindow_CastTargetedSpell = 0;
+                            pMouse->SetCursorBitmap("MICON1");
+                            GameUI_Footer_TimeLeft = 0;
+                            _50C9A0_IsEnchantingInProgress = 0;
+                            back_to_game();
+                        }
+                        continue;
+                    }
+                    else if (current_screen_type == SCREEN_MENU)
+                    {/*
+                        pIcons_LOD->SyncLoadedFilesCount();
+                        pIcons_LOD->RemoveTexturesPackFromTextureList();
+                        pIcons_LOD->SyncLoadedFilesCount();
+                        pIcons_LOD->RemoveTexturesPackFromTextureList();
+                        stru_506E40.Release();
+                        Game_OnEscape();*/
+                        break;
+                    }
+                    else if (current_screen_type == SCREEN_SAVEGAME || current_screen_type == SCREEN_LOADGAME)
+                    {/*
+                        pIcons_LOD->RemoveTexturesPackFromTextureList();
+                        //crt_deconstruct_ptr_6A0118();
+                        stru_506E40.Release();
+                        Game_OnEscape();*/
+                        break;
+                    }
+                    else if (current_screen_type == SCREEN_OPTIONS)
+                    {/*
+                        options_menu_skin.Relaease();
+                        pIcons_LOD->SyncLoadedFilesCount();
+                        WriteWindowsRegistryInt("soundflag", (char)uSoundVolumeMultiplier);
+                        WriteWindowsRegistryInt("musicflag", (char)uMusicVolimeMultiplier);
+                        WriteWindowsRegistryInt("CharVoices", (char)uVoicesVolumeMultiplier);
+                        WriteWindowsRegistryInt("WalkSound", bWalkSound);
+                        WriteWindowsRegistryInt("ShowDamage", bShowDamage);
+                        //WriteWindowsRegistryInt("graphicsmode", (unsigned __int8)byte_6BE388_graphicsmode);
+                        WriteWindowsRegistryInt("valAlwaysRun", bAlwaysRun);
+                        WriteWindowsRegistryInt("FlipOnExit", bFlipOnExit);
+                        if (uTurnSpeed == 0)
+                            WriteWindowsRegistryInt("TurnDelta", 3);
+                        else if (uTurnSpeed == 64)
+                            WriteWindowsRegistryInt("TurnDelta", 2);
+                        else if (uTurnSpeed == 128)
+                            WriteWindowsRegistryInt("TurnDelta", 1);
+                        stru_506E40.Release();
+                        Game_OnEscape();*/
+                        break;
+                    }
+                    else if (current_screen_type == SCREEN_VIDEO_OPTIONS)
+                    {/*
+                        //if ( pRenderer->pRenderD3D )
+                        {
+                            WriteWindowsRegistryInt("Colored Lights", pRenderer->bUseColoredLights);
+                            WriteWindowsRegistryInt("Tinting", pRenderer->bTinting);
+                            WriteWindowsRegistryInt("Bloodsplats", (LOBYTE(pEngine->uFlags2) >> 5) & 1);
+                        }
+
+                        stru_506E40.Release();
+                        Game_OnEscape();*/
+                        break;
+                    }
+                    else if (current_screen_type == SCREEN_KEYBOARD_OPTIONS)
+                    {
+                        /*v197 = 1;
+                        pKeyBindingFlag = false;
+                        for (uint i = 0; i < 28; ++i)
+                        {
+                            if (GameMenuUI_InvaligKeyBindingsFlags[i])
+                                pKeyBindingFlag = true;
+                        }
+                        if (!pKeyBindingFlag)
+                        {
+                            for (uint i = 0; i < 5; i++)
+                            {
+                                if (uTextureID_Optkb[i])
+                                    pIcons_LOD->pTextures[uTextureID_Optkb[i]].Release();
+                            }
+                            memset(&uTextureID_Optkb, 0, 20);
+                            pIcons_LOD->SyncLoadedFilesCount();
+                            for (uint i = 0; i < 28; ++i)
+                            {
+                                if (pKeyActionMap->GetActionVKey((enum InputAction)i) != pPrevVirtualCidesMapping[i])
+                                {
+                                    if (v197)
+                                    {
+                                        GUI_ReplaceHotkey(pKeyActionMap->GetActionVKey((enum InputAction)i), LOBYTE(pPrevVirtualCidesMapping[i]), 1);
+                                        v197 = 0;
+                                    }
+                                    else
+                                        GUI_ReplaceHotkey(pKeyActionMap->GetActionVKey((enum InputAction)i), LOBYTE(pPrevVirtualCidesMapping[i]), 0);
+                                }
+                                if (i > 3 && i != 25 && i != 26)
+                                    pKeyToggleType = TOGGLE_OneTimePress;
+                                else
+                                    pKeyToggleType = TOGGLE_Continuously;
+                                pKeyActionMap->SetKeyMapping(i, pPrevVirtualCidesMapping[i], pKeyToggleType);
+                            }
+                            pKeyActionMap->StoreMappings();
+                            stru_506E40.Release();
+                        }
+                        else
+                            pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
+
+                        Game_OnEscape();*/
+                        break;
+                    }
+                    else
                     {
                         if (current_screen_type > SCREEN_67)
                         {
                             if (current_screen_type == SCREEN_QUICK_REFERENCE)
                             {
                                 pIcons_LOD->RemoveTexturesPackFromTextureList();
-                                if (pGUIWindow_Settings)
-                                {
-                                    if (current_screen_type == SCREEN_CHARACTERS)
-                                        pMouse->SetCursorBitmap("MICON2");
-                                    else
-                                    {
-                                        pGUIWindow_Settings->Release();
-                                        pGUIWindow_Settings = 0;
-                                        pMouse->SetCursorBitmap("MICON1");
-                                        GameUI_Footer_TimeLeft = 0;
-                                        _50C9A0_IsEnchantingInProgress = 0;
-                                        back_to_game();
-                                    }
-                                }
-                                if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
-                                    uActiveCharacter = pParty->GetNextActiveCharacter();
-                                pGUIWindow_CurrentMenu->Release();
-                                if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
-                                    window_SpeakInHouse = 0;
-                                pGUIWindow_CurrentMenu = 0;
-                                pEventTimer->Resume();
-                                current_screen_type = SCREEN_GAME;
-                                viewparams->bRedrawGameUI = 1;
-                                pIcons_LOD->RemoveTexturesFromTextureList();
+                                Game_OnEscape();
                                 continue;
                             }
                         }
@@ -817,67 +900,15 @@
                                         _50C9A8_item_enchantment_timer = 0;
                                         ptr_50C9A4_ItemToEnchant = nullptr;
                                     }
-                                    if (pGUIWindow_Settings)
-                                    {
-                                        if (current_screen_type == SCREEN_CHARACTERS)
-                                            pMouse->SetCursorBitmap("MICON2");
-                                        else
-                                        {
-                                            pGUIWindow_Settings->Release();
-                                            pGUIWindow_Settings = 0;
-                                            pMouse->SetCursorBitmap("MICON1");
-                                            GameUI_Footer_TimeLeft = 0;
-                                            _50C9A0_IsEnchantingInProgress = 0;
-                                            back_to_game();
-                                        }
-                                    }
-                                    if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
-                                        uActiveCharacter = pParty->GetNextActiveCharacter();
-                                    pGUIWindow_CurrentMenu->Release();
-                                    if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
-                                        window_SpeakInHouse = 0;
-                                    pGUIWindow_CurrentMenu = 0;
-                                    pEventTimer->Resume();
-                                    current_screen_type = SCREEN_GAME;
-                                    viewparams->bRedrawGameUI = 1;
-                                    pIcons_LOD->RemoveTexturesFromTextureList();
+                                    Game_OnEscape();
                                     continue;
                                 case SCREEN_BOOKS:
                                     pBooksButtonOverlay->Release();
                                     //crt_deconstruct_ptr_6A0118();
                                     pBooksButtonOverlay = 0;
                                     pEventTimer->Resume();
-                                    if (pGUIWindow_Settings)
-                                    {
-                                        if (current_screen_type == SCREEN_CHARACTERS)
-                                            pMouse->SetCursorBitmap("MICON2");
-                                        else
-                                        {
-                                            pGUIWindow_Settings->Release();
-                                            pGUIWindow_Settings = 0;
-                                            pMouse->SetCursorBitmap("MICON1");
-                                            GameUI_Footer_TimeLeft = 0;
-                                            _50C9A0_IsEnchantingInProgress = 0;
-                                            back_to_game();
-                                        }
-                                    }
-                                    if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
-                                        uActiveCharacter = pParty->GetNextActiveCharacter();
-                                    pGUIWindow_CurrentMenu->Release();
-                                    if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
-                                        window_SpeakInHouse = 0;
-                                    pGUIWindow_CurrentMenu = 0;
-                                    pEventTimer->Resume();
-                                    current_screen_type = SCREEN_GAME;
-                                    viewparams->bRedrawGameUI = 1;
-                                    pIcons_LOD->RemoveTexturesFromTextureList();
+                                    Game_OnEscape();
                                     continue;
-                                case SCREEN_SAVEGAME:
-                                case SCREEN_LOADGAME:
-                                    pIcons_LOD->RemoveTexturesPackFromTextureList();
-                                    //crt_deconstruct_ptr_6A0118();
-                                    stru_506E40.Release();
-                                    break;
                                 case SCREEN_CHEST_INVENTORY:
                                     current_screen_type = SCREEN_CHEST;
                                     continue;
@@ -898,96 +929,6 @@
                                     viewparams->bRedrawGameUI = 1;
                                     pEventTimer->Resume();
                                     continue;
-                                case SCREEN_OPTIONS://Close
-                                    options_menu_skin.Relaease();
-                                    pIcons_LOD->SyncLoadedFilesCount();
-                                    WriteWindowsRegistryInt("soundflag", (char)uSoundVolumeMultiplier);
-                                    WriteWindowsRegistryInt("musicflag", (char)uMusicVolimeMultiplier);
-                                    WriteWindowsRegistryInt("CharVoices", (char)uVoicesVolumeMultiplier);
-                                    WriteWindowsRegistryInt("WalkSound", bWalkSound);
-                                    WriteWindowsRegistryInt("ShowDamage", bShowDamage);
-                                    //WriteWindowsRegistryInt("graphicsmode", (unsigned __int8)byte_6BE388_graphicsmode);
-                                    WriteWindowsRegistryInt("valAlwaysRun", bAlwaysRun);
-                                    WriteWindowsRegistryInt("FlipOnExit", bFlipOnExit);
-                                    if (!uTurnSpeed)
-                                    {
-                                        WriteWindowsRegistryInt("TurnDelta", 3);
-                                        stru_506E40.Release();
-                                        break;
-                                    }
-                                    if (uTurnSpeed == 64)
-                                    {
-                                        WriteWindowsRegistryInt("TurnDelta", 2);
-                                        stru_506E40.Release();
-                                        break;
-                                    }
-                                    if (uTurnSpeed != 128)
-                                    {
-                                        stru_506E40.Release();
-                                        break;
-                                    }
-                                    WriteWindowsRegistryInt("TurnDelta", 1);
-                                    stru_506E40.Release();
-                                    break;
-                                case SCREEN_MENU:
-                                    pIcons_LOD->SyncLoadedFilesCount();
-                                    pIcons_LOD->RemoveTexturesPackFromTextureList();
-                                    pIcons_LOD->SyncLoadedFilesCount();
-                                    pIcons_LOD->RemoveTexturesPackFromTextureList();
-                                    stru_506E40.Release();
-                                    break;
-                                case SCREEN_VIDEO_OPTIONS:
-                                    //if ( pRenderer->pRenderD3D )
-                                {
-                                    WriteWindowsRegistryInt("Colored Lights", pRenderer->bUseColoredLights);
-                                    WriteWindowsRegistryInt("Tinting", pRenderer->bTinting);
-                                    WriteWindowsRegistryInt("Bloodsplats", (LOBYTE(pEngine->uFlags2) >> 5) & 1);
-                                }
-
-                                    stru_506E40.Release();
-                                    break;
-
-                                case SCREEN_KEYBOARD_OPTIONS://Return to game
-                                    v197 = 1;
-                                    pKeyBindingFlag = false;
-                                    for (uint i = 0; i < 28; ++i)
-                                    {
-                                        if (GameMenuUI_InvaligKeyBindingsFlags[i])
-                                            pKeyBindingFlag = true;
-                                    }
-                                    if (!pKeyBindingFlag)
-                                    {
-                                        for (uint i = 0; i < 5; i++)
-                                        {
-                                            if (uTextureID_Optkb[i])
-                                                pIcons_LOD->pTextures[uTextureID_Optkb[i]].Release();
-                                        }
-                                        memset(&uTextureID_Optkb, 0, 20);
-                                        pIcons_LOD->SyncLoadedFilesCount();
-                                        for (uint i = 0; i < 28; ++i)
-                                        {
-                                            if (pKeyActionMap->GetActionVKey((enum InputAction)i) != pPrevVirtualCidesMapping[i])
-                                            {
-                                                if (v197)
-                                                {
-                                                    GUI_ReplaceHotkey(pKeyActionMap->GetActionVKey((enum InputAction)i), LOBYTE(pPrevVirtualCidesMapping[i]), 1);
-                                                    v197 = 0;
-                                                }
-                                                else
-                                                    GUI_ReplaceHotkey(pKeyActionMap->GetActionVKey((enum InputAction)i), LOBYTE(pPrevVirtualCidesMapping[i]), 0);
-                                            }
-                                            if (i > 3 && i != 25 && i != 26)
-                                                pKeyToggleType = TOGGLE_OneTimePress;
-                                            else
-                                                pKeyToggleType = TOGGLE_Continuously;
-                                            pKeyActionMap->SetKeyMapping(i, pPrevVirtualCidesMapping[i], pKeyToggleType);
-                                        }
-                                        pKeyActionMap->StoreMappings();
-                                        stru_506E40.Release();
-                                        break;
-                                    }
-                                    pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
-                                    break;
                                 case SCREEN_REST://close rest screen
                                     if (_506F14_resting_stage)
                                     {
@@ -1010,30 +951,7 @@
                                     }
                                     _506F18_num_minutes_to_sleep = 0;
                                     _506F14_resting_stage = 0;
-                                    if (pGUIWindow_Settings)
-                                    {
-                                        if (current_screen_type == SCREEN_CHARACTERS)
-                                            pMouse->SetCursorBitmap("MICON2");
-                                        else
-                                        {
-                                            pGUIWindow_Settings->Release();
-                                            pGUIWindow_Settings = 0;
-                                            pMouse->SetCursorBitmap("MICON1");
-                                            GameUI_Footer_TimeLeft = 0;
-                                            _50C9A0_IsEnchantingInProgress = 0;
-                                            back_to_game();
-                                        }
-                                    }
-                                    if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
-                                        uActiveCharacter = pParty->GetNextActiveCharacter();
-                                    pGUIWindow_CurrentMenu->Release();
-                                    if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
-                                        window_SpeakInHouse = 0;
-                                    pGUIWindow_CurrentMenu = 0;
-                                    pEventTimer->Resume();
-                                    current_screen_type = SCREEN_GAME;
-                                    viewparams->bRedrawGameUI = 1;
-                                    pIcons_LOD->RemoveTexturesFromTextureList();
+                                    Game_OnEscape();
                                     continue;
                                 case SCREEN_E:
                                     __debugbreak();
@@ -1058,30 +976,7 @@
                                     pAudioPlayer->PlaySound(SOUND_WoodDoorClosing, 814, 0, -1, 0, 0, 0, 0);
                                     pMediaPlayer->Unload();
                                     pGUIWindow_CurrentMenu = window_SpeakInHouse;
-                                    if (pGUIWindow_Settings)
-                                    {
-                                        if (current_screen_type == SCREEN_CHARACTERS)
-                                            pMouse->SetCursorBitmap("MICON2");
-                                        else
-                                        {
-                                            pGUIWindow_Settings->Release();
-                                            pGUIWindow_Settings = 0;
-                                            pMouse->SetCursorBitmap("MICON1");
-                                            GameUI_Footer_TimeLeft = 0;
-                                            _50C9A0_IsEnchantingInProgress = 0;
-                                            back_to_game();
-                                        }
-                                    }
-                                    if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
-                                        uActiveCharacter = pParty->GetNextActiveCharacter();
-                                    pGUIWindow_CurrentMenu->Release();
-                                    if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
-                                        window_SpeakInHouse = 0;
-                                    pGUIWindow_CurrentMenu = 0;
-                                    pEventTimer->Resume();
-                                    current_screen_type = SCREEN_GAME;
-                                    viewparams->bRedrawGameUI = true;
-                                    pIcons_LOD->RemoveTexturesFromTextureList();
+                                    Game_OnEscape();
                                     continue;
                                 case SCREEN_INPUT_BLV://click escape
                                     if (uCurrentHouse_Animation == 153)
@@ -1140,146 +1035,26 @@
                                     CharacterUI_ReleaseButtons();
                                     ReleaseAwardsScrollBar();
                                     pIcons_LOD->RemoveTexturesPackFromTextureList();
-                                    if (pGUIWindow_Settings)
-                                    {
-                                        if (current_screen_type == SCREEN_CHARACTERS)
-                                            pMouse->SetCursorBitmap("MICON2");
-                                        else
-                                        {
-                                            pGUIWindow_Settings->Release();
-                                            pGUIWindow_Settings = 0;
-                                            pMouse->SetCursorBitmap("MICON1");
-                                            GameUI_Footer_TimeLeft = 0;
-                                            _50C9A0_IsEnchantingInProgress = 0;
-                                            back_to_game();
-                                        }
-                                    }
-                                    if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
-                                        uActiveCharacter = pParty->GetNextActiveCharacter();
-                                    pGUIWindow_CurrentMenu->Release();
-                                    if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
-                                        window_SpeakInHouse = 0;
-                                    pGUIWindow_CurrentMenu = 0;
-                                    pEventTimer->Resume();
-                                    current_screen_type = SCREEN_GAME;
-                                    viewparams->bRedrawGameUI = true;
-                                    pIcons_LOD->RemoveTexturesFromTextureList();
+                                    Game_OnEscape();
                                     continue;
                                 default:
-                                    if (pGUIWindow_Settings)
-                                    {
-                                        if (current_screen_type == SCREEN_CHARACTERS)
-                                            pMouse->SetCursorBitmap("MICON2");
-                                        else
-                                        {
-                                            pGUIWindow_Settings->Release();
-                                            pGUIWindow_Settings = 0;
-                                            pMouse->SetCursorBitmap("MICON1");
-                                            GameUI_Footer_TimeLeft = 0;
-                                            _50C9A0_IsEnchantingInProgress = 0;
-                                            back_to_game();
-                                        }
-                                    }
-                                    if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
-                                        uActiveCharacter = pParty->GetNextActiveCharacter();
-                                    pGUIWindow_CurrentMenu->Release();
-                                    if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
-                                        window_SpeakInHouse = 0;
-                                    pGUIWindow_CurrentMenu = 0;
-                                    pEventTimer->Resume();
-                                    current_screen_type = SCREEN_GAME;
-                                    viewparams->bRedrawGameUI = 1;
-                                    pIcons_LOD->RemoveTexturesFromTextureList();
+                                    __debugbreak(); // which GAME_MENU is this?
+                                    Game_OnEscape();
                                     continue;
                                 }
-                                if (pGUIWindow_Settings)
-                                {
-                                    if (current_screen_type == SCREEN_CHARACTERS)
-                                        pMouse->SetCursorBitmap("MICON2");
-                                    else
-                                    {
-                                        pGUIWindow_Settings->Release();
-                                        pGUIWindow_Settings = 0;
-                                        pMouse->SetCursorBitmap("MICON1");
-                                        GameUI_Footer_TimeLeft = 0;
-                                        _50C9A0_IsEnchantingInProgress = 0;
-                                        back_to_game();
-                                    }
-                                }
-                                if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
-                                    uActiveCharacter = pParty->GetNextActiveCharacter();
-                                pGUIWindow_CurrentMenu->Release();
-                                if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
-                                    window_SpeakInHouse = 0;
-                                pGUIWindow_CurrentMenu = 0;
-                                pEventTimer->Resume();
-                                current_screen_type = SCREEN_GAME;
-                                viewparams->bRedrawGameUI = true;
-                                pIcons_LOD->RemoveTexturesFromTextureList();
+                                __debugbreak(); // which GAME_MENU is this?
+                                Game_OnEscape();
                                 continue;
                             }
+                            __debugbreak(); // which GAME_MENU is this?
                             CharacterUI_ReleaseButtons();
                             ReleaseAwardsScrollBar();
                             pIcons_LOD->RemoveTexturesPackFromTextureList();
                         }
-                        if (pGUIWindow_Settings)
-                        {
-                            if (current_screen_type == SCREEN_CHARACTERS)
-                                pMouse->SetCursorBitmap("MICON2");
-                            else
-                            {
-                                pGUIWindow_Settings->Release();
-                                pGUIWindow_Settings = 0;
-                                pMouse->SetCursorBitmap("MICON1");
-                                GameUI_Footer_TimeLeft = 0;
-                                _50C9A0_IsEnchantingInProgress = 0;
-                                back_to_game();
-                            }
-                        }
-                        if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
-                            uActiveCharacter = pParty->GetNextActiveCharacter();
-                        pGUIWindow_CurrentMenu->Release();
-                        if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
-                            window_SpeakInHouse = 0;
-                        pGUIWindow_CurrentMenu = 0;
-                        pEventTimer->Resume();
-                        current_screen_type = SCREEN_GAME;
-                        viewparams->bRedrawGameUI = true;
-                        pIcons_LOD->RemoveTexturesFromTextureList();
+                        __debugbreak(); // which GAME_MENU is this?
+                        Game_OnEscape();
                         continue;
                     }
-                    if (!pGUIWindow_Settings)//Draw Menu
-                    {
-                        dword_6BE138 = -1;
-                        new OnButtonClick2(0x25Au, 0x1C2u, 0, 0, (int)pBtn_GameSettings, (char *)1);
-                        pEventTimer->Pause();
-                        pAudioPlayer->StopChannels(-1, -1);
-                        current_screen_type = SCREEN_MENU;
-
-                        ++pIcons_LOD->uTexturePacksCount;
-                        if (!pIcons_LOD->uNumPrevLoadedFiles)
-                            pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
-
-                        pGUIWindow_CurrentMenu = new GUIWindow_GameMenu();
-
-                        viewparams->field_48 = 1;
-
-                        stru_506E40.Release();
-                        pRenderer->SaveScreenshot("gamma.pcx", 155, 117);
-                        stru_506E40.LoadPCXFile("gamma.pcx", 0);
-
-                        continue;
-                    }
-                    pGUIWindow_Settings->Release();
-                    pGUIWindow_Settings = 0;
-                    pMouse->SetCursorBitmap("MICON1");
-                    GameUI_Footer_TimeLeft = 0;
-                    _50C9A0_IsEnchantingInProgress = 0;
-                    back_to_game();
-                    continue;
-                }
-                pModalWindow->Release();
-                pModalWindow = nullptr;
                 continue;
 
             case UIMSG_ScrollNPCPanel://Right and Left button for NPCPanel
@@ -1501,13 +1276,13 @@
                     v47 = pActors[v46].uAIState == Dead;
                     if (!v47)
                         continue;
-                    pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+                    pSpellInfo = (CastSpellInfo *)pGUIWindow_CastTargetedSpell->ptr_1C;
                     pSpellInfo->uFlags &= ~0x40u;
                     pSpellInfo->uPlayerID_2 = uMessageParam;
                     pSpellInfo->spell_target_pid = v44;
                     pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
-                    pGUIWindow_Settings->Release();
-                    pGUIWindow_Settings = 0;
+                    pGUIWindow_CastTargetedSpell->Release();
+                    pGUIWindow_CastTargetedSpell = 0;
                     pMouse->SetCursorBitmap("MICON1");
                     GameUI_Footer_TimeLeft = 0;
                     _50C9A0_IsEnchantingInProgress = 0;
@@ -1519,13 +1294,13 @@
                     v47 = (pObjectList->pObjects[pSpriteObjects[v46].uObjectDescID].uFlags & 0x10) == 0;
                     if (!v47)
                         continue;
-                    pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+                    pSpellInfo = (CastSpellInfo *)pGUIWindow_CastTargetedSpell->ptr_1C;
                     pSpellInfo->uFlags &= ~0x40u;
                     pSpellInfo->uPlayerID_2 = uMessageParam;
                     pSpellInfo->spell_target_pid = v44;
                     pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
-                    pGUIWindow_Settings->Release();
-                    pGUIWindow_Settings = 0;
+                    pGUIWindow_CastTargetedSpell->Release();
+                    pGUIWindow_CastTargetedSpell = 0;
                     pMouse->SetCursorBitmap("MICON1");
                     GameUI_Footer_TimeLeft = 0;
                     _50C9A0_IsEnchantingInProgress = 0;
@@ -1546,13 +1321,13 @@
                         if (!pODMFace->Clickable() || !pODMFace->sCogTriggeredID)
                             continue;
                         v44 = uNumSeconds;
-                        pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+                        pSpellInfo = (CastSpellInfo *)pGUIWindow_CastTargetedSpell->ptr_1C;
                         pSpellInfo->uFlags &= ~0x40u;
                         pSpellInfo->uPlayerID_2 = uMessageParam;
                         pSpellInfo->spell_target_pid = v44;
                         pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
-                        pGUIWindow_Settings->Release();
-                        pGUIWindow_Settings = 0;
+                        pGUIWindow_CastTargetedSpell->Release();
+                        pGUIWindow_CastTargetedSpell = 0;
                         pMouse->SetCursorBitmap("MICON1");
                         GameUI_Footer_TimeLeft = 0;
                         _50C9A0_IsEnchantingInProgress = 0;
@@ -1566,13 +1341,13 @@
                 }
                 if (v48)
                     continue;
-                pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+                pSpellInfo = (CastSpellInfo *)pGUIWindow_CastTargetedSpell->ptr_1C;
                 pSpellInfo->uFlags &= ~0x40u;
                 pSpellInfo->uPlayerID_2 = uMessageParam;
                 pSpellInfo->spell_target_pid = v44;
                 pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
-                pGUIWindow_Settings->Release();
-                pGUIWindow_Settings = 0;
+                pGUIWindow_CastTargetedSpell->Release();
+                pGUIWindow_CastTargetedSpell = 0;
                 pMouse->SetCursorBitmap("MICON1");
                 GameUI_Footer_TimeLeft = 0;
                 _50C9A0_IsEnchantingInProgress = 0;
@@ -1589,9 +1364,9 @@
                 }
                 else
                 {
-                    if (pGUIWindow_Settings)
+                    if (pGUIWindow_CastTargetedSpell)
                     {
-                        pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+                        pSpellInfo = (CastSpellInfo *)pGUIWindow_CastTargetedSpell->ptr_1C;
                         switch (uMessage)
                         {
                         case UIMSG_CastSpell_Character_Big_Improvement:
@@ -1606,8 +1381,8 @@
                         }
                         pSpellInfo->uPlayerID_2 = uMessageParam;
                         pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
-                        pGUIWindow_Settings->Release();
-                        pGUIWindow_Settings = 0;
+                        pGUIWindow_CastTargetedSpell->Release();
+                        pGUIWindow_CastTargetedSpell = 0;
                         pEventTimer->Resume();
                         pMouse->SetCursorBitmap("MICON1");
                         GameUI_Footer_TimeLeft = 0;
@@ -2056,7 +1831,7 @@
                 v84 = v83 >> 16;
                 if (PID_TYPE(v44) != 3 || v84 >= 5120)
                     continue;
-                pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+                pSpellInfo = (CastSpellInfo *)pGUIWindow_CastTargetedSpell->ptr_1C;
                 if (uMessage == UIMSG_CastSpell_Shoot_Monster)
                 {
                     pSpellInfo->uFlags &= ~0x08;
@@ -2071,8 +1846,8 @@
                 pSpellInfo->uPlayerID_2 = uMessageParam;
                 pSpellInfo->spell_target_pid = v44;
                 pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
-                pGUIWindow_Settings->Release();
-                pGUIWindow_Settings = 0;
+                pGUIWindow_CastTargetedSpell->Release();
+                pGUIWindow_CastTargetedSpell = 0;
                 pMouse->SetCursorBitmap("MICON1");
                 GameUI_Footer_TimeLeft = 0;
                 _50C9A0_IsEnchantingInProgress = 0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Game/GameMenu.cpp	Wed May 13 11:31:58 2015 +0200
@@ -0,0 +1,637 @@
+#include "Engine/Engine.h"
+#include "Engine/Timer.h"
+#include "Engine/LOD.h"
+#include "Engine/Party.h"
+#include "Engine/SaveLoad.h"
+#include "Engine/Registry.h"
+#include "Engine/texts.h"
+#include "Engine/Graphics/IRender.h"
+#include "Engine/Graphics/Viewport.h"
+
+#include "IO/Keyboard.h"
+#include "IO/Mouse.h"
+
+#include "GUI/UI/UIGame.h"
+#include "GUI/UI/UISaveLoad.h"
+#include "GUI/UI/UIModal.h"
+
+#include "Media/Audio/AudioPlayer.h"
+#include "Media/Audio/AIL.h"
+
+
+
+extern void DoThatMessageThing();
+
+
+void Game_StartNewGameWhilePlaying(bool force_start)
+{
+    if (dword_6BE138 == 124 || force_start)
+    {
+        pIcons_LOD->SyncLoadedFilesCount();
+        pIcons_LOD->RemoveTexturesPackFromTextureList();
+        DoThatMessageThing();
+        //pGUIWindow_CurrentMenu->Release();
+        uGameState = GAME_STATE_NEWGAME_OUT_GAMEMENU;
+        current_screen_type = SCREEN_GAME;
+        viewparams->bRedrawGameUI = 1;
+    }
+    else
+    {
+        ShowStatusBarString(pGlobalTXT_LocalizationStrings[201], 2);// "Are you sure?  Click again to start a New Game"
+        pAudioPlayer->PlaySound(SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
+        dword_6BE138 = 124;
+    }
+}
+
+void Game_QuitGameWhilePlaying(bool force_quit)
+{
+    if (dword_6BE138 == 132 || force_quit)
+    {
+        pIcons_LOD->SyncLoadedFilesCount();
+        pIcons_LOD->RemoveTexturesPackFromTextureList();
+        DoThatMessageThing();
+        //pGUIWindow_CurrentMenu->Release();
+        current_screen_type = SCREEN_GAME;
+        viewparams->bRedrawGameUI = 1;
+        pAudioPlayer->PlaySound(SOUND_WoodDoorClosing, 0, 0, -1, 0, 0, 0, 0);
+        uGameState = GAME_STATE_GAME_QUITTING_TO_MAIN_MENU;
+    }
+    else
+    {
+        ShowStatusBarString(pGlobalTXT_LocalizationStrings[82], 2);// "Are you sure?  Click again to quit"
+        pAudioPlayer->PlaySound(SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
+        dword_6BE138 = 132;
+    }
+}
+
+void Game_OpenLoadGameDialog()
+{
+    pIcons_LOD->SyncLoadedFilesCount();
+    pIcons_LOD->RemoveTexturesPackFromTextureList();
+
+    DoThatMessageThing();
+    pGUIWindow_CurrentMenu->Release();
+    pGUIWindow_CurrentMenu = nullptr;
+
+    //LoadUI_Load(1);
+    current_screen_type = SCREEN_LOADGAME;
+    pGUIWindow_CurrentMenu = new GUIWindow_Load(true);
+}
+
+
+
+
+void GameMenu_EventLoop()
+{
+    while (pMessageQueue_50CBD0->uNumMessages)
+    {
+        UIMessageType msg;
+        int param, param2;
+        pMessageQueue_50CBD0->PopMessage(&msg, &param, &param2);
+
+        switch (msg)
+        {
+            case UIMSG_StartNewGame:              Game_StartNewGameWhilePlaying(param); continue;
+            case UIMSG_Quit:                      Game_QuitGameWhilePlaying(param); continue;
+            case UIMSG_Game_OpenLoadGameDialog:   Game_OpenLoadGameDialog(); continue;
+
+            case UIMSG_ArrowUp:
+                --pSaveListPosition;
+                if (pSaveListPosition < 0)
+                    pSaveListPosition = 0;
+                new OnButtonClick2(215, 199, 17, 17, (int)pBtnArrowUp, 0);
+                continue;
+
+            case UIMSG_DownArrow:
+                ++pSaveListPosition;
+                if (pSaveListPosition >= param)
+                    pSaveListPosition = param - 1;
+                new OnButtonClick2(215, 323, 17, 17, (int)pBtnDownArrow, 0);
+                continue;
+
+            case UIMSG_Cancel:
+                new OnCancel(350, 302, 106, 42, (int)pBtnCancel, 0);
+                continue;
+
+            case UIMSG_SaveLoadBtn:
+                new OnSaveLoad(241, 302, 106, 42, (int)pBtnLoadSlot, 0);
+                continue;
+            case UIMSG_SelectLoadSlot:
+            {
+                if (pGUIWindow_CurrentMenu->receives_keyboard_input_2 == WINDOW_INPUT_IN_PROGRESS)
+                    pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_NONE);
+
+                int v10 = pSaveListPosition + param;
+                if (current_screen_type != SCREEN_SAVEGAME || uLoadGameUI_SelectedSlot != v10)
+                {
+                    if (dword_6BE138 == pSaveListPosition + param)
+                    {
+                        pMessageQueue_50CBD0->AddGUIMessage(UIMSG_SaveLoadBtn, 0, 0);
+                        pMessageQueue_50CBD0->AddGUIMessage(UIMSG_LoadGame, 0, 0);
+                    }
+                    uLoadGameUI_SelectedSlot = v10;
+                    dword_6BE138 = v10;
+                }
+                else
+                {
+                    pKeyActionMap->EnterText(0, 19, pGUIWindow_CurrentMenu);
+                    if (strcmp(pSavegameHeader[uLoadGameUI_SelectedSlot].pName, pGlobalTXT_LocalizationStrings[72]))// "Empty"
+                        strcpy(pKeyActionMap->pPressedKeysBuffer, pSavegameHeader[uLoadGameUI_SelectedSlot].pName);
+                    pKeyActionMap->uNumKeysPressed = strlen(pKeyActionMap->pPressedKeysBuffer);
+                }
+            }
+            continue;
+            case UIMSG_LoadGame:
+                if (pSavegameUsedSlots[uLoadGameUI_SelectedSlot])
+                {
+                    LoadGame(uLoadGameUI_SelectedSlot);
+                    uGameState = GAME_STATE_LOADING_GAME;
+                }
+                continue;
+            case UIMSG_SaveGame:
+                if (pGUIWindow_CurrentMenu->receives_keyboard_input_2 == WINDOW_INPUT_IN_PROGRESS)
+                {
+                    pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_NONE);
+                    strcpy((char *)&pSavegameHeader[uLoadGameUI_SelectedSlot], pKeyActionMap->pPressedKeysBuffer);
+                }
+                DoSavegame(uLoadGameUI_SelectedSlot);
+                continue;
+            case UIMSG_Game_OpenSaveGameDialog:
+            {
+                pGUIWindow_CurrentMenu->Release();
+
+                current_screen_type = SCREEN_SAVEGAME;
+                pGUIWindow_CurrentMenu = new GUIWindow_Save(); //SaveUI_Load(current_screen_type = SCREEN_SAVEGAME);
+                continue;
+            }
+            case UIMSG_Game_OpenOptionsDialog://Open
+            {
+                DoThatMessageThing();
+
+                pGUIWindow_CurrentMenu->Release();
+                pGUIWindow_CurrentMenu = new GUIWindow_GameOptions();//GameMenuUI_Options_Load();
+
+                viewparams->field_48 = 1;
+                current_screen_type = SCREEN_OPTIONS;
+
+                continue;
+            }
+
+            case UIMSG_OpenKeyMappingOptions://Open
+            {
+                DoThatMessageThing();
+
+                pGUIWindow_CurrentMenu->Release();
+                pGUIWindow_CurrentMenu = new GUIWindow_GameKeyBindings();//GameMenuUI_OptionsKeymapping_Load();
+
+                viewparams->field_48 = 1;
+                current_screen_type = SCREEN_KEYBOARD_OPTIONS;
+
+                continue;
+            }
+
+            case UIMSG_ChangeKeyButton:
+            {
+                if (uGameMenuUI_CurentlySelectedKeyIdx != -1)
+                {
+                    pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
+                }
+                else
+                {
+                    uGameMenuUI_CurentlySelectedKeyIdx = param;
+                    if (KeyboardPageNum != 1)
+                        uGameMenuUI_CurentlySelectedKeyIdx += 14;
+                    pKeyActionMap->EnterText(0, 1, pGUIWindow_CurrentMenu);
+                }
+                continue;
+            }
+
+            case UIMSG_ResetKeyMapping:
+            {
+                int v197 = 1;
+                pKeyActionMap->SetDefaultMapping();
+                for (uint i = 0; i < 28; i++)
+                {
+                    if (pKeyActionMap->GetActionVKey((enum InputAction)i) != pPrevVirtualCidesMapping[i])
+                    {
+                        if (v197)
+                        {
+                            GUI_ReplaceHotkey(LOBYTE(pPrevVirtualCidesMapping[i]), pKeyActionMap->GetActionVKey((enum InputAction)i), 1);
+                            v197 = 0;
+                        }
+                        else
+                            GUI_ReplaceHotkey(LOBYTE(pPrevVirtualCidesMapping[i]), pKeyActionMap->GetActionVKey((enum InputAction)i), 0);
+                    }
+                    pPrevVirtualCidesMapping[i] = pKeyActionMap->GetActionVKey((enum InputAction)i);
+                    GameMenuUI_InvaligKeyBindingsFlags[i] = false;
+                }
+                pAudioPlayer->PlaySound(SOUND_chimes, 0, 0, -1, 0, 0, 0, 0);
+                continue;
+            }
+
+            case UIMSG_SelectKeyPage1:
+                KeyboardPageNum = 1;
+                continue;
+            case UIMSG_SelectKeyPage2:
+                KeyboardPageNum = 2;
+                continue;
+
+            case UIMSG_OpenVideoOptions:
+            {
+                DoThatMessageThing();
+
+                pGUIWindow_CurrentMenu->Release();
+                pGUIWindow_CurrentMenu = new GUIWindow_GameVideoOptions();//GameMenuUI_OptionsVideo_Load();
+                viewparams->field_48 = 1;
+                current_screen_type = SCREEN_VIDEO_OPTIONS;
+
+                continue;
+            }
+
+            case UIMSG_1A9:
+                __debugbreak();
+                if (param == 4)
+                {
+                    //--uGammaPos;
+                    if ((uGammaPos-- - 1) < 0)
+                    {
+                        uGammaPos = 0;
+                        pAudioPlayer->PlaySound(SOUND_ClickMovingSelector, 0, 0, -1, 0, 0, 0, 0);
+                        continue;
+                    }
+                    double v19 = (double)(signed int)uGammaPos * 0.1 + 0.6;
+                    //pEngine->pGammaController->Initialize(v19);
+                    new OnButtonClick2(21, 161, 0, 0, (int)pBtn_SliderLeft, (char *)1);
+                    pAudioPlayer->PlaySound(SOUND_ClickMovingSelector, 0, 0, -1, 0, 0, 0, 0);
+                    continue;
+                }
+                if (param == 5)
+                {
+                    ++uGammaPos;
+                    if ((signed int)uGammaPos <= 9)
+                    {
+                        double v21 = (double)(signed int)uGammaPos * 0.1 + 0.6;
+                        //pEngine->pGammaController->Initialize(v21);
+                        new OnButtonClick2(213, 161, 0, 0, (int)pBtn_SliderRight, (char *)1);
+                        pAudioPlayer->PlaySound(SOUND_ClickMovingSelector, 0, 0, -1, 0, 0, 0, 0);
+                        continue;
+                    }
+                    uGammaPos = 9;
+                }
+                else
+                {
+                    POINT a2;
+                    uGammaPos = (pMouse->GetCursorPos(&a2)->x - 42) / 17;
+                    double v22 = (double)(signed int)uGammaPos * 0.1 + 0.6;
+                    //pEngine->pGammaController->Initialize(v22);
+                }
+                pAudioPlayer->PlaySound(SOUND_ClickMovingSelector, 0, 0, -1, 0, 0, 0, 0);
+                continue;
+            case UIMSG_ToggleBloodsplats:
+                pEngine->ToggleFlags2(0x20u);
+                continue;
+            case UIMSG_ToggleColoredLights:
+                pRenderer->ToggleColoredLights();
+                continue;
+            case UIMSG_ToggleTint:
+                pRenderer->ToggleTint();
+                continue;
+            case UIMSG_ChangeMusicVolume:
+                extern bool use_music_folder;
+                if (param == 4)//-
+                {
+                    --uMusicVolimeMultiplier;
+                    if ((char)uMusicVolimeMultiplier < 1)
+                        uMusicVolimeMultiplier = 0;
+                    new OnButtonClick2(243, 216, 0, 0, (int)pBtn_SliderLeft, (char *)1);
+                    if (uMusicVolimeMultiplier)
+                        pAudioPlayer->PlaySound(SOUND_hurp, -1, 0, -1, 0, 0, pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f, 0);
+
+                    if (use_music_folder)
+                        alSourcef(mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
+                    else
+                        pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
+
+                    continue;
+                }
+                if (param == 5)//+
+                {
+                    ++uMusicVolimeMultiplier;
+                    if ((char)uMusicVolimeMultiplier > 9)
+                        uMusicVolimeMultiplier = 9;
+                    new OnButtonClick2(435, 216, 0, 0, (int)pBtn_SliderRight, (char *)1);
+                    if (uMusicVolimeMultiplier)
+                        pAudioPlayer->PlaySound(SOUND_hurp, -1, 0, -1, 0, 0, pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f, 0);
+                    if (use_music_folder)
+                        alSourcef(mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
+                    else
+                        pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
+                    continue;
+                }
+
+                POINT v202;
+                uMusicVolimeMultiplier = (pMouse->GetCursorPos(&v202)->x - 263) / 17;//for mouse
+                if ((char)uMusicVolimeMultiplier > 9)
+                    uMusicVolimeMultiplier = 9;
+                if (uMusicVolimeMultiplier)
+                    pAudioPlayer->PlaySound(SOUND_hurp, -1, 0, -1, 0, 0, pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f, 0);
+                if (use_music_folder)
+                    alSourcef(mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
+                else
+                    pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
+                continue;
+            case UIMSG_ChangeSoundVolume:
+                if (param == 4)//reduce sound level button left
+                {
+                    --uSoundVolumeMultiplier;
+                    if ((char)uSoundVolumeMultiplier < 1)
+                        uSoundVolumeMultiplier = 0;
+                    new OnButtonClick2(243, 162, 0, 0, (int)pBtn_SliderLeft, (char *)1);
+                    pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f);
+                    pAudioPlayer->PlaySound(SOUND_church, -1, 0, -1, 0, 0, 0, 0);
+                    int v = AIL_redbook_volume(pAudioPlayer->hAILRedbook);
+                    //v = v+1;
+                    if (v)
+                        __debugbreak();
+                    continue;
+                }
+                if (param == 5)//Increase sound level button right
+                {
+                    ++uSoundVolumeMultiplier;
+                    if ((char)uSoundVolumeMultiplier > 8)
+                        uSoundVolumeMultiplier = 9;
+                    //v168 = 1;
+                    //v154 = (int)pBtn_SliderRight;
+                    new OnButtonClick2(435, 162, 0, 0, (int)pBtn_SliderRight, (char *)1);
+                    pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f);
+                    pAudioPlayer->PlaySound(SOUND_church, -1, 0, -1, 0, 0, 0, 0);
+                    continue;
+                }
+
+                POINT v207;
+                uSoundVolumeMultiplier = (pMouse->GetCursorPos(&v207)->x - 263) / 17;
+                if ((char)uSoundVolumeMultiplier > 8)
+                    uSoundVolumeMultiplier = 9;
+                pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f);
+                pAudioPlayer->PlaySound(SOUND_church, -1, 0, -1, 0, 0, 0, 0);
+                continue;
+            case UIMSG_ToggleFlipOnExit:
+                bFlipOnExit = bFlipOnExit == 0;
+                continue;
+            case UIMSG_ToggleAlwaysRun:
+                bAlwaysRun = bAlwaysRun == 0;
+                continue;
+            case UIMSG_ToggleWalkSound:
+                bWalkSound = bWalkSound == 0;
+                continue;
+            case UIMSG_ToggleShowDamage:
+                bShowDamage = bShowDamage == 0;
+                continue;
+            case UIMSG_ChangeVoiceVolume:
+                if (param == 4)
+                {
+                    --uVoicesVolumeMultiplier;
+                    if ((char)uVoicesVolumeMultiplier < 1)
+                        uVoicesVolumeMultiplier = 0;
+                    new OnButtonClick2(243, 270, 0, 0, (int)pBtn_SliderLeft, (char *)1);
+                    if (!uVoicesVolumeMultiplier)
+                        continue;
+                    pAudioPlayer->PlaySound(SOUND_hf445a, -1, 0, -1, 0, 0, pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0f, 0);
+                    continue;
+                }
+                if (param == 5)
+                {
+                    ++uVoicesVolumeMultiplier;
+                    if ((char)uVoicesVolumeMultiplier > 8)
+                        uVoicesVolumeMultiplier = 9;
+                    new OnButtonClick2(435, 270, 0, 0, (int)pBtn_SliderRight, (char *)1);
+                    if (!uVoicesVolumeMultiplier)
+                        continue;
+                    pAudioPlayer->PlaySound(SOUND_hf445a, -1, 0, -1, 0, 0, pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0f, 0);
+                    continue;
+                }
+
+                POINT v205;
+                uVoicesVolumeMultiplier = (pMouse->GetCursorPos(&v205)->x - 263) / 17;
+                if ((char)uVoicesVolumeMultiplier > 8)
+                    uVoicesVolumeMultiplier = 9;
+                if (!uVoicesVolumeMultiplier)
+                    continue;
+                pAudioPlayer->PlaySound(SOUND_hf445a, -1, 0, -1, 0, 0, pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0f, 0);
+                continue;
+            case UIMSG_SetTurnSpeed:
+                if (param)
+                    pParty->sRotationY = param * pParty->sRotationY / param;
+                uTurnSpeed = param;
+                continue;
+
+            case UIMSG_SetGraphicsMode:
+                //if ( !bUseLoResSprites )
+                //{
+                //    byte_6BE388_graphicsmode = uMessageParam;
+                //    MM7Initialization();
+                //    continue;
+                //}
+                //if ( uMessageParam )
+                //{
+                //    if ( uMessageParam == 1 )
+                //    {
+                //    byte_6BE388_graphicsmode = 0;
+                //    }
+                //    else
+                //    {
+                //        if ( uMessageParam != 2 )
+                //            continue;
+                //        byte_6BE388_graphicsmode = 1;
+                //    }
+                //    MM7Initialization();
+                //    continue;
+                //}
+                pModalWindow = new GUIWindow_Modal(pNPCTopics[453].pText, UIMSG_0);
+                __debugbreak(); // Nomad: graphicsmode as it was now removed
+                continue;
+
+            case UIMSG_GameMenu_ReturnToGame:
+                //pGUIWindow_CurrentMenu->Release();
+                pEventTimer->Resume();
+                current_screen_type = SCREEN_GAME;
+                viewparams->bRedrawGameUI = true;
+                continue;
+
+
+
+
+            case UIMSG_Escape:
+                if (pModalWindow)
+                {
+                    pModalWindow->Release();
+                    pModalWindow = nullptr;
+                    continue;
+                }
+                pRenderer->ClearZBuffer(0, 479);
+                viewparams->bRedrawGameUI = true;
+                viewparams->field_48 = 1;
+
+                if (current_screen_type == SCREEN_MENU)
+                {
+                    pIcons_LOD->SyncLoadedFilesCount();
+                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+                    pIcons_LOD->SyncLoadedFilesCount();
+                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+
+                    current_screen_type = SCREEN_GAME;
+                }
+                else if (current_screen_type == SCREEN_SAVEGAME || current_screen_type == SCREEN_LOADGAME)
+                {
+                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+                    //crt_deconstruct_ptr_6A0118();
+
+                    pGUIWindow_CurrentMenu->Release();
+                    current_screen_type = SCREEN_MENU;
+                    pGUIWindow_CurrentMenu = new GUIWindow_GameMenu();
+                }
+                else if (current_screen_type == SCREEN_OPTIONS)
+                {
+                    options_menu_skin.Relaease();
+                    pIcons_LOD->SyncLoadedFilesCount();
+                    WriteWindowsRegistryInt("soundflag", (char)uSoundVolumeMultiplier);
+                    WriteWindowsRegistryInt("musicflag", (char)uMusicVolimeMultiplier);
+                    WriteWindowsRegistryInt("CharVoices", (char)uVoicesVolumeMultiplier);
+                    WriteWindowsRegistryInt("WalkSound", bWalkSound);
+                    WriteWindowsRegistryInt("ShowDamage", bShowDamage);
+                    //WriteWindowsRegistryInt("graphicsmode", (unsigned __int8)byte_6BE388_graphicsmode);
+                    WriteWindowsRegistryInt("valAlwaysRun", bAlwaysRun);
+                    WriteWindowsRegistryInt("FlipOnExit", bFlipOnExit);
+                    if (!uTurnSpeed)
+                        WriteWindowsRegistryInt("TurnDelta", 3);
+                    else if (uTurnSpeed == 64)
+                        WriteWindowsRegistryInt("TurnDelta", 2);
+                    else if (uTurnSpeed == 128)
+                        WriteWindowsRegistryInt("TurnDelta", 1);
+
+                    pGUIWindow_CurrentMenu->Release();
+                    current_screen_type = SCREEN_MENU;
+                    pGUIWindow_CurrentMenu = new GUIWindow_GameMenu();
+                }
+                else if (current_screen_type == SCREEN_VIDEO_OPTIONS)
+                {
+                    //if ( pRenderer->pRenderD3D )
+                    {
+                        WriteWindowsRegistryInt("Colored Lights", pRenderer->bUseColoredLights);
+                        WriteWindowsRegistryInt("Tinting", pRenderer->bTinting);
+                        WriteWindowsRegistryInt("Bloodsplats", (LOBYTE(pEngine->uFlags2) >> 5) & 1);
+                    }
+
+                    pGUIWindow_CurrentMenu->Release();
+                    current_screen_type = SCREEN_MENU;
+                    pGUIWindow_CurrentMenu = new GUIWindow_GameMenu();
+                }
+                else if (current_screen_type == SCREEN_KEYBOARD_OPTIONS)
+                {
+                    KeyToggleType pKeyToggleType; // [sp+0h] [bp-5FCh]@287
+                    int v197 = 1;
+                    bool pKeyBindingFlag = false;
+
+                    for (uint i = 0; i < 28; ++i)
+                    {
+                        if (GameMenuUI_InvaligKeyBindingsFlags[i])
+                            pKeyBindingFlag = true;
+                    }
+                    if (!pKeyBindingFlag)
+                    {
+                        for (uint i = 0; i < 5; i++)
+                        {
+                            if (uTextureID_Optkb[i])
+                                pIcons_LOD->pTextures[uTextureID_Optkb[i]].Release();
+                        }
+                        memset(uTextureID_Optkb.data(), 0, 20);
+                        pIcons_LOD->SyncLoadedFilesCount();
+                        for (uint i = 0; i < 28; ++i)
+                        {
+                            if (pKeyActionMap->GetActionVKey((enum InputAction)i) != pPrevVirtualCidesMapping[i])
+                            {
+                                if (v197)
+                                {
+                                    GUI_ReplaceHotkey(pKeyActionMap->GetActionVKey((enum InputAction)i), LOBYTE(pPrevVirtualCidesMapping[i]), 1);
+                                    v197 = 0;
+                                }
+                                else
+                                    GUI_ReplaceHotkey(pKeyActionMap->GetActionVKey((enum InputAction)i), LOBYTE(pPrevVirtualCidesMapping[i]), 0);
+                            }
+                            if (i > 3 && i != 25 && i != 26)
+                                pKeyToggleType = TOGGLE_OneTimePress;
+                            else
+                                pKeyToggleType = TOGGLE_Continuously;
+                            pKeyActionMap->SetKeyMapping(i, pPrevVirtualCidesMapping[i], pKeyToggleType);
+                        }
+                        pKeyActionMap->StoreMappings();
+                    }
+                    else
+                        pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
+
+                    pGUIWindow_CurrentMenu->Release();
+                    current_screen_type = SCREEN_MENU;
+                    pGUIWindow_CurrentMenu = new GUIWindow_GameMenu();
+                }
+                continue;
+        }
+    }
+}
+
+void GameMenu_Loop()
+{
+    pEventTimer->Pause();
+    pAudioPlayer->StopChannels(-1, -1);
+    current_screen_type = SCREEN_MENU;
+
+    ++pIcons_LOD->uTexturePacksCount;
+    if (!pIcons_LOD->uNumPrevLoadedFiles)
+        pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
+
+    pGUIWindow_CurrentMenu = new GUIWindow_GameMenu();
+
+    viewparams->field_48 = 1;
+
+    stru_506E40.Release();
+    pRenderer->SaveScreenshot("gamma.pcx", 155, 117);
+    stru_506E40.LoadPCXFile("gamma.pcx", 0);
+
+    while (uGameState == GAME_STATE_PLAYING
+        && (
+            current_screen_type == SCREEN_MENU
+            || current_screen_type == SCREEN_SAVEGAME
+            || current_screen_type == SCREEN_LOADGAME
+            || current_screen_type == SCREEN_OPTIONS
+            || current_screen_type == SCREEN_VIDEO_OPTIONS
+            || current_screen_type == SCREEN_KEYBOARD_OPTIONS
+        )
+    )
+    {
+        MSG msg;
+        while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE))
+        {
+            if (msg.message == WM_QUIT)
+                Engine_DeinitializeAndTerminate(0);
+            TranslateMessage(&msg);
+            DispatchMessageW(&msg);
+        }
+        if (dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE)
+        {
+            WaitMessage();
+            continue;
+        }
+
+        pRenderer->BeginScene();
+        {
+            GameMenu_EventLoop();
+            GUI_UpdateWindows();
+        }
+        pRenderer->EndScene();
+        pRenderer->Present();
+    }
+
+    pGUIWindow_CurrentMenu->Release();
+    pGUIWindow_CurrentMenu = nullptr;
+
+    stru_506E40.Release();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Game/GameMenu.h	Wed May 13 11:31:58 2015 +0200
@@ -0,0 +1,3 @@
+#pragma once
+
+void GameMenu_Loop();
\ No newline at end of file