changeset 2552:ac16f4a3a91e

Load from MainMenu logic separated from MainMenu window
author a.parshin
date Wed, 13 May 2015 01:33:20 +0200
parents 4008b2f34be0
children 48708da03b7f
files Build/Visual Studio 2013/World of Might and Magic.vcxproj Build/Visual Studio 2013/World of Might and Magic.vcxproj.filters Engine/Engine.cpp Engine/SaveLoad.cpp GUI/GUIWindow.cpp GUI/GUIWindow.h GUI/UI/UIMainMenu.cpp Game/MainMenu.cpp Game/MainMenuLoad.cpp Game/MainMenuLoad.h
diffstat 10 files changed, 211 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/Build/Visual Studio 2013/World of Might and Magic.vcxproj	Tue May 12 12:03:30 2015 +0200
+++ b/Build/Visual Studio 2013/World of Might and Magic.vcxproj	Wed May 13 01:33:20 2015 +0200
@@ -154,6 +154,7 @@
     <ClCompile Include="..\..\Game\Game.cpp" />
     <ClCompile Include="..\..\Game\GameOver.cpp" />
     <ClCompile Include="..\..\Game\MainMenu.cpp" />
+    <ClCompile Include="..\..\Game\MainMenuLoad.cpp" />
     <ClCompile Include="..\..\GUI\GUIButton.cpp" />
     <ClCompile Include="..\..\GUI\GUIFont.cpp" />
     <ClCompile Include="..\..\GUI\GUIProgressBar.cpp" />
@@ -333,6 +334,7 @@
     <ClInclude Include="..\..\Game\Game.h" />
     <ClInclude Include="..\..\Game\GameOver.h" />
     <ClInclude Include="..\..\Game\MainMenu.h" />
+    <ClInclude Include="..\..\Game\MainMenuLoad.h" />
     <ClInclude Include="..\..\GUI\GUIButton.h" />
     <ClInclude Include="..\..\GUI\GUIFont.h" />
     <ClInclude Include="..\..\GUI\GUIProgressBar.h" />
--- a/Build/Visual Studio 2013/World of Might and Magic.vcxproj.filters	Tue May 12 12:03:30 2015 +0200
+++ b/Build/Visual Studio 2013/World of Might and Magic.vcxproj.filters	Wed May 13 01:33:20 2015 +0200
@@ -601,6 +601,9 @@
     <ClCompile Include="..\..\GUI\UI\Chest.cpp">
       <Filter>GUI\UI</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\Game\MainMenuLoad.cpp">
+      <Filter>Game</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\lib\libavcodec\avcodec.h">
@@ -1369,6 +1372,9 @@
     <ClInclude Include="..\..\GUI\UI\Chest.h">
       <Filter>GUI\UI</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\Game\MainMenuLoad.h">
+      <Filter>Game</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\lib\OpenAL\lib\x86\avcodec-55.def">
--- a/Engine/Engine.cpp	Tue May 12 12:03:30 2015 +0200
+++ b/Engine/Engine.cpp	Wed May 13 01:33:20 2015 +0200
@@ -1811,8 +1811,8 @@
     Log::Warning(L"MM: entering main loop");
     while (1)
     {
-        MainMenuWindow *main_menu_window = MainMenuWindow::Create();
-        window->AddControl(main_menu_window);
+        //MainMenuWindow *main_menu_window = MainMenuWindow::Create();
+        //window->AddControl(main_menu_window);
         MainMenu_Loop();
         uGameState = GAME_STATE_PLAYING;
         while (1)
--- a/Engine/SaveLoad.cpp	Tue May 12 12:03:30 2015 +0200
+++ b/Engine/SaveLoad.cpp	Wed May 13 01:33:20 2015 +0200
@@ -179,7 +179,11 @@
     }
   }
 
-  pGUIWindow_CurrentMenu->Release();
+  if (pGUIWindow_CurrentMenu)
+  {
+      pGUIWindow_CurrentMenu->Release();
+      pGUIWindow_CurrentMenu = nullptr;
+  }
   current_screen_type = SCREEN_GAME;
 
   viewparams->bRedrawGameUI = true;
--- a/GUI/GUIWindow.cpp	Tue May 12 12:03:30 2015 +0200
+++ b/GUI/GUIWindow.cpp	Wed May 13 01:33:20 2015 +0200
@@ -64,7 +64,7 @@
 enum WindowType current_character_screen_window;
 struct GUIWindow *pWindow_MMT_MainMenu;
 struct GUIWindow *pWindow_MainMenu;
-std::array<struct GUIWindow *, 20> pWindowList;
+std::array<struct GUIWindow *, 50> pWindowList;
 
 struct GUIMessageQueue *pMessageQueue_50CBD0 = new GUIMessageQueue;
 struct GUIMessageQueue *pMessageQueue_50C9E8 = new GUIMessageQueue;
--- a/GUI/GUIWindow.h	Tue May 12 12:03:30 2015 +0200
+++ b/GUI/GUIWindow.h	Wed May 13 01:33:20 2015 +0200
@@ -37,7 +37,7 @@
   UIMSG_MainMenu_ShowLoadWindow = 55,
   UIMSG_ShowCredits = 56,
   UIMSG_ExitToWindows = 57,
-  UIMSG_3A = 58,
+  UIMSG_DebugBlv = 58,
 
   UIMSG_PlayerCreationChangeName = 60,
 
@@ -134,7 +134,7 @@
   UIMSG_PlayerCreation_FacePrev = 171,
   UIMSG_PlayerCreation_FaceNext = 172,
   UIMSG_AD = 173,
-  UIMSG_AE = 174,
+  UIMSG_DebugBlv2 = 174,
   UIMSG_ClickNPCTopic = 175,
   UIMSG_CycleCharacters = 176,
   UIMSG_OnCastLloydsBeacon = 177,
@@ -606,7 +606,7 @@
 extern enum WindowType current_character_screen_window;
 extern struct GUIWindow *pWindow_MMT_MainMenu;
 extern struct GUIWindow *pWindow_MainMenu;
-extern std::array<struct GUIWindow *, 20> pWindowList;
+extern std::array<struct GUIWindow *, 50> pWindowList;
 
 
 
--- a/GUI/UI/UIMainMenu.cpp	Tue May 12 12:03:30 2015 +0200
+++ b/GUI/UI/UIMainMenu.cpp	Wed May 13 01:33:20 2015 +0200
@@ -56,8 +56,8 @@
     POINT pt;
     pMouse->GetCursorPos(&pt);
     GUIWindow *pWindow = this;//pWindow_MainMenu;
-    if (GetCurrentMenuID() == MENU_SAVELOAD)
-        pWindow = pGUIWindow_CurrentMenu;
+    //if (GetCurrentMenuID() == MENU_SAVELOAD)
+    //    pWindow = pGUIWindow_CurrentMenu;
 
 
     if (GetCurrentMenuID() == MENU_MAIN)
--- a/Game/MainMenu.cpp	Tue May 12 12:03:30 2015 +0200
+++ b/Game/MainMenu.cpp	Wed May 13 01:33:20 2015 +0200
@@ -17,6 +17,7 @@
 #include "Media/Audio/AudioPlayer.h"
 
 #include "Game/MainMenu.h"
+#include "Game/MainMenuLoad.h"
 
 
 RGBTexture main_menu_background;
@@ -61,7 +62,8 @@
                 break;
             case UIMSG_MainMenu_ShowLoadWindow:
                 new OnButtonClick2(495, 227, 0, 0, (int)pMainMenu_BtnLoad, 0);
-                SetCurrentMenuID(MENU_SAVELOAD);
+                //SetCurrentMenuID(MENU_SAVELOAD);
+                MainMenuLoad_Loop();
                 break;
             case UIMSG_ShowCredits:
                 new OnButtonClick2(495, 282, 0, 0, (int)pMainMenu_BtnCredits, 0);
@@ -190,10 +192,11 @@
             case UIMSG_ChangeCursor:
                 pMouse->SetCursorBitmap("MICON2");
                 break;
-            case UIMSG_3A:
+            case UIMSG_DebugBlv:
+                __debugbreak();//some debugging tool
                 SetCurrentMenuID(MENU_DebugBLVLevel);
                 break;
-            case UIMSG_LoadGame:
+            /*case UIMSG_LoadGame:
                 if (!pSavegameUsedSlots[uLoadGameUI_SelectedSlot])
                     break;
                 SetCurrentMenuID(MENU_LoadingProcInMainMenu);
@@ -233,22 +236,24 @@
                     pSaveListPosition = 0;
                 pWindow = pGUIWindow_CurrentMenu;
                 new OnButtonClick2(pWindow->uFrameX + 215, pGUIWindow_CurrentMenu->uFrameY + 323, 0, 0, (int)pBtnDownArrow, 0);
-                break;
+                break;*/
             case UIMSG_Cancel:
                 new OnCancel3(pGUIWindow_CurrentMenu->uFrameX + 350, pGUIWindow_CurrentMenu->uFrameY + 302, 61, 28, (int)pBtnCancel, 0);
                 break;
-            case UIMSG_ArrowUp:
+            /*case UIMSG_ArrowUp:
                 --pSaveListPosition;
                 if (pSaveListPosition < 0)
                     pSaveListPosition = 0;
                 pWindow = pGUIWindow_CurrentMenu;
                 new OnButtonClick2(pWindow->uFrameX + 215, pGUIWindow_CurrentMenu->uFrameY + 197, 0, 0, (int)pBtnArrowUp, 0);
-                break;
+                break;*/
             case UIMSG_AD:
+                __debugbreak();//some debugging tool
                 new OnButtonClick2(pMainMenu_BtnNew->uX, pMainMenu_BtnNew->uY, 0, 0, (int)pMainMenu_BtnNew, 0);
                 SetCurrentMenuID(MENU_LoadingProcInMainMenu);
                 break;
-            case UIMSG_AE:
+            case UIMSG_DebugBlv2:
+                __debugbreak();//some debugging tool
                 new OnButtonClick2(pMainMenu_BtnExit->uX, pMainMenu_BtnExit->uY, 0, 0, (int)pMainMenu_BtnExit, 0);
                 SetCurrentMenuID(MENU_DebugBLVLevel);
                 break;
@@ -283,7 +288,7 @@
                     pMessageQueue_50CBD0->AddGUIMessage(UIMSG_ChangeGameState, 0, 0);
                     break;
                 }
-                if (GetCurrentMenuID() == MENU_CREDITSPROC && !current_screen_type)
+                if (GetCurrentMenuID() == MENU_CREDITSPROC && current_screen_type == SCREEN_GAME)
                 {
                     //if ( current_screen_type == SCREEN_VIDEO )
                     //pVideoPlayer->FastForwardToFrame(pVideoPlayer->pResetflag);
@@ -300,7 +305,7 @@
                     pMessageQueue_50CBD0->AddGUIMessage(UIMSG_ChangeGameState, 0, 0);
                     break;
                 }
-                if (current_screen_type == SCREEN_LOADGAME)
+                /*if (current_screen_type == SCREEN_LOADGAME)
                 {
                     pIcons_LOD->RemoveTexturesPackFromTextureList();
                     //crt_deconstruct_ptr_6A0118();
@@ -315,7 +320,7 @@
                     current_screen_type = SCREEN_GAME;
                     viewparams->bRedrawGameUI = v15;
                     break;
-                }
+                }*/
                 if (current_screen_type == SCREEN_VIDEO)
                 {
                     //pVideoPlayer->Unload();
@@ -323,10 +328,17 @@
                 else
                 {
                     if (current_screen_type != SCREEN_1B)
-                    {
-                        pGUIWindow_CurrentMenu->Release();
-                        pGUIWindow2->Release();
-                        pGUIWindow2 = 0;
+                    { // MENU_CREDITSCLOSE  for example
+                        if (pGUIWindow_CurrentMenu)
+                        {
+                            pGUIWindow_CurrentMenu->Release();
+                            pGUIWindow_CurrentMenu = nullptr;
+                        }
+                        if (pGUIWindow2)
+                        {
+                            pGUIWindow2->Release();
+                            pGUIWindow2 = 0;
+                        }
                         pEventTimer->Resume();
                         current_screen_type = SCREEN_GAME;
                         viewparams->bRedrawGameUI = v15;
@@ -368,12 +380,14 @@
     SetCurrentMenuID(MENU_MAIN);
     SetForegroundWindow(window->GetApiHandle());
     SendMessageW(window->GetApiHandle(), WM_ACTIVATEAPP, 1, 0);
-    while (GetCurrentMenuID() == MENU_MAIN || GetCurrentMenuID() == MENU_SAVELOAD)
+
+    //while (GetCurrentMenuID() == MENU_MAIN || GetCurrentMenuID() == MENU_SAVELOAD)
+    while (GetCurrentMenuID() == MENU_MAIN)
     {
         POINT pt;
         pMouse->GetCursorPos(&pt);
         pWindow = pWindow_MainMenu;
-        if (GetCurrentMenuID() == MENU_SAVELOAD)
+        /*if (GetCurrentMenuID() == MENU_SAVELOAD)
         {
             if (current_screen_type != SCREEN_LOADGAME)
             {
@@ -385,7 +399,7 @@
                 pGUIWindow_CurrentMenu = new GUIWindow_Load(false);
             }
             pWindow = pGUIWindow_CurrentMenu;
-        }
+        }*/
 
         while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE))
         {
@@ -417,11 +431,11 @@
     pRenderer->EndScene();
     pRenderer->Present();
     main_menu_background.Release();
-    if (pGUIWindow2)
+    /*if (pGUIWindow2)
     {
         pGUIWindow2->Release();
         pGUIWindow2 = 0;
-    }
+    }*/
     pWindow_MainMenu->Release();
     pIcons_LOD->RemoveTexturesPackFromTextureList();
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Game/MainMenuLoad.cpp	Wed May 13 01:33:20 2015 +0200
@@ -0,0 +1,152 @@
+#include "Engine/Engine.h"
+#include "Engine/SaveLoad.h"
+#include "Engine/LOD.h"
+#include "Engine/Timer.h"
+#include "Engine/Graphics/IRender.h"
+#include "Engine/Graphics/Viewport.h"
+
+#include "IO/Keyboard.h"
+
+#include "GUI/UI/UISaveLoad.h"
+
+#include "Game/MainMenu.h"
+#include "Game/MainMenuLoad.h"
+
+void MainMenuLoad_EventLoop()
+{
+    while (pMessageQueue_50CBD0->uNumMessages)
+    {
+        UIMessageType msg;
+        int param, param2;
+        pMessageQueue_50CBD0->PopMessage(&msg, &param, &param2);
+
+        switch (msg)
+        {
+            case UIMSG_LoadGame:
+            {
+                if (!pSavegameUsedSlots[uLoadGameUI_SelectedSlot])
+                    break;
+                SetCurrentMenuID(MENU_LoadingProcInMainMenu);
+            }
+            break;
+
+            case UIMSG_SelectLoadSlot:
+            {
+                //main menu save/load wnd   clicking on savegame lines
+                if (pGUIWindow_CurrentMenu->receives_keyboard_input_2 == WINDOW_INPUT_IN_PROGRESS)
+                    pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_NONE);
+                if (current_screen_type != SCREEN_SAVEGAME || uLoadGameUI_SelectedSlot != param + pSaveListPosition)
+                {
+                    //load clicked line
+                    int v26 = param + pSaveListPosition;
+                    if (dword_6BE138 == v26)
+                    {
+                        pMessageQueue_50CBD0->AddGUIMessage(UIMSG_SaveLoadBtn, 0, 0);
+                        pMessageQueue_50CBD0->AddGUIMessage(UIMSG_LoadGame, 0, 0);
+                    }
+                    uLoadGameUI_SelectedSlot = v26;
+                    dword_6BE138 = v26;
+                }
+                else
+                {
+                    //typing in the line
+                    pKeyActionMap->EnterText(0, 19, pGUIWindow_CurrentMenu);
+                    strcpy(pKeyActionMap->pPressedKeysBuffer, pSavegameHeader[uLoadGameUI_SelectedSlot].pName);
+                    pKeyActionMap->uNumKeysPressed = strlen(pKeyActionMap->pPressedKeysBuffer);
+                }
+            }
+            break;
+
+            case UIMSG_SaveLoadBtn:
+                new OnSaveLoad(pGUIWindow_CurrentMenu->uFrameX + 241, pGUIWindow_CurrentMenu->uFrameY + 302, 61, 28, (int)pBtnLoadSlot, 0);
+            break;
+
+
+            case UIMSG_DownArrow:
+            {
+                ++pSaveListPosition;
+                if (pSaveListPosition >= param)
+                    pSaveListPosition = param - 1;
+                if (pSaveListPosition < 1)
+                    pSaveListPosition = 0;
+                new OnButtonClick2(pGUIWindow_CurrentMenu->uFrameX + 215, pGUIWindow_CurrentMenu->uFrameY + 323, 0, 0, (int)pBtnDownArrow, 0);
+            }
+            break;
+
+
+            case UIMSG_ArrowUp:
+            {
+                --pSaveListPosition;
+                if (pSaveListPosition < 0)
+                    pSaveListPosition = 0;
+                new OnButtonClick2(pGUIWindow_CurrentMenu->uFrameX + 215, pGUIWindow_CurrentMenu->uFrameY + 197, 0, 0, (int)pBtnArrowUp, 0);
+            }
+            break;
+
+            case UIMSG_Cancel:
+                new OnCancel3(pGUIWindow_CurrentMenu->uFrameX + 350, pGUIWindow_CurrentMenu->uFrameY + 302, 61, 28, (int)pBtnCancel, 0);
+            break;
+
+
+            case UIMSG_Escape:
+            {
+                viewparams->field_48 = 1;
+                //if (current_screen_type == SCREEN_LOADGAME)
+                {
+                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+                    //crt_deconstruct_ptr_6A0118();
+                    main_menu_background.Release();
+                    main_menu_background.Load("title.pcx", 0);
+                    SetCurrentMenuID(MENU_MAIN);
+                    current_screen_type = SCREEN_GAME;
+                    pEventTimer->Resume();
+                    viewparams->bRedrawGameUI = true;
+                    break;
+                }
+            }
+            break;
+        }
+    }
+}
+
+void MainMenuLoad_Loop()
+{
+    SetCurrentMenuID(MENU_SAVELOAD);
+    current_screen_type = SCREEN_LOADGAME;
+
+    main_menu_background.Release();
+    main_menu_background.Load("lsave640.pcx", 0);
+
+        //LoadUI_Load(0);
+    pGUIWindow_CurrentMenu = new GUIWindow_Load(false);
+
+
+    while (GetCurrentMenuID() == MENU_SAVELOAD && current_screen_type == SCREEN_LOADGAME)
+    {
+        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();
+        pRenderer->DrawTextureNew(0, 0, &main_menu_background);
+
+        MainMenuLoad_EventLoop();
+        GUI_UpdateWindows();
+
+        pRenderer->EndScene();
+        pRenderer->Present();
+    }
+
+    pGUIWindow_CurrentMenu->Release();
+    pGUIWindow_CurrentMenu = nullptr;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Game/MainMenuLoad.h	Wed May 13 01:33:20 2015 +0200
@@ -0,0 +1,5 @@
+#pragma once
+
+
+void MainMenuLoad_Loop();
+void MainMenuLoad_EventLoop();
\ No newline at end of file