diff --git a/src/OpenSHC/UI/Helpers/InitTutorialState.cpp b/src/OpenSHC/UI/Helpers/InitTutorialState.cpp new file mode 100644 index 0000000000..1adfaf3426 --- /dev/null +++ b/src/OpenSHC/UI/Helpers/InitTutorialState.cpp @@ -0,0 +1,41 @@ +#include "../Helpers.func.hpp" + +#include "OpenSHC/Globals/DAT_00df5558.hpp" +#include "OpenSHC/Globals/DAT_00df555c.hpp" +#include "OpenSHC/Globals/DAT_00df5560.hpp" +#include "OpenSHC/Globals/DAT_00df556c.hpp" +#include "OpenSHC/Globals/DAT_DisableTutorialRestrictions.hpp" +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TutorialCurrentStep.hpp" +#include "OpenSHC/Globals/INT_00df5554.hpp" +#include "OpenSHC/Globals/INT_00df5564.hpp" +#include "OpenSHC/Globals/INT_ARRAY_00df5598.hpp" + +namespace OpenSHC { +namespace UI { + + // FUNCTION: STRONGHOLDCRUSADER 0x004BC6F0 + void Helpers::InitTutorialState() + { + // The main menu's tutorial button calls this once the tutorial map is loaded + MACRO_CALL(OpenSHC::UI::Helpers_Func::InitTutorialStepTransition)(1); + DAT_00df555c::instance = DAT_MissionAestheticsDefinedData::instance.TutorialStepActionCount[0]; + DAT_DisableTutorialRestrictions::instance = FALSE; + DAT_TutorialCurrentStep::instance = 0; + INT_00df5554::instance = 32; + DAT_00df5558::instance = 0; + DAT_00df5560::instance = 0; + INT_00df5564::instance = 0; + DAT_00df556c::instance = 36; + // Where each step starts: two past the previous start, plus the previous step's action count + int start = 1; + for (int step = 0; step < countof(INT_ARRAY_00df5598::instance); ++step) { + ++start; + INT_ARRAY_00df5598::instance[step] = start; + start += DAT_MissionAestheticsDefinedData::instance.TutorialStepActionCount[step] + 1; + } + MACRO_CALL(OpenSHC::UI::Helpers_Func::ResetTutorialActionTrackers)(); + } + +} +} diff --git a/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_ChatBox.cpp b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_ChatBox.cpp new file mode 100644 index 0000000000..a27aa59c92 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_ChatBox.cpp @@ -0,0 +1,103 @@ +#include "../LobbyMenu.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/COL_DARK_LIME.hpp" +#include "OpenSHC/Globals/DAT_00b960dc.hpp" +#include "OpenSHC/Globals/DAT_ButtonBackgroundBlendStrength.hpp" +#include "OpenSHC/Globals/DAT_ButtonH.hpp" +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x0042AC90 + void LobbyMenu::MenuItemRenderFunction_LobbyMenu_ChatBox(int buttonID, ...) + { + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER) { + return; + } + if (DAT_MenuModalComposition1::instance.activeModalDialogID != OpenSHC::UI::Enums::MMT_NONE + && DAT_MenuModalComposition1::instance.activeModalDialogID != OpenSHC::UI::Enums::MMT_SEND_MAP_TO + && DAT_MenuModalComposition1::instance.activeModalDialogID != OpenSHC::UI::Enums::MMT_RECEIVE_MAP_FROM + && MACRO_CALL(OpenSHC::UI::Helpers_Func::AModalDialogIsActiveButIsNotQuitting)()) { + return; + } + int const blend = DAT_ButtonBackgroundBlendStrength::instance - 32; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + // Nested, not early returns (early returns: quick_diff 0.9671 -> 0.6184) + if (buttonID != -3) { + if (buttonID != -2) { + // the waiting room's texts, and for -1 the player's own name + if (buttonID != -1) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderInGameText2, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, buttonID, + DAT_ButtonX::instance, DAT_ButtonY::instance + 6, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_00A2FF, OpenSHC::Rendering::Colors::COL_003E66, 17, FALSE, + blend * 32 / 32 + 32); + return; + } + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, DAT_TextManagerObject::ptr)( + DAT_GameSynchronyState::instance + .DAT_PlayerNames[DAT_GameSynchronyState::instance.currentPlayerSlotID], + DAT_ButtonX::instance, DAT_ButtonY::instance + 6, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_00A2FF, OpenSHC::Rendering::Colors::COL_003E66, 17, FALSE, + blend * 32 / 32 + 32); + return; + } + // -2: the line being typed, with the cursor behind it + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBlendedBlackBox, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance + 2, + DAT_ButtonW::instance + DAT_ButtonX::instance, DAT_ButtonH::instance + DAT_ButtonY::instance - 2, + blend * 16 / 32 + 32); + int const cursorX + = MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::getTextWidthUntilCurrentCursor, + DAT_UserTextHandlerState::ptr)(); + if (DAT_00b960dc::instance == 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance + 6 + cursorX, DAT_ButtonY::instance + 2, + DAT_ButtonX::instance + 7 + cursorX, DAT_ButtonH::instance + DAT_ButtonY::instance - 2, + COL_DARK_LIME::instance.shortValue); + } + // the blend strength read again after the calls (the blend local: quick_diff 0.9671 -> 0.8803) + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, + DAT_TextManagerObject::ptr)(MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::getCurrentText, + DAT_UserTextHandlerState::ptr)(), + DAT_ButtonX::instance + 8, DAT_ButtonY::instance + 5, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_FFFFFF, OpenSHC::Rendering::Colors::COL_000000, 19, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + return; + } + // -3: the chat messages + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBlendedBlackBox, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance + 3, + DAT_ButtonW::instance + DAT_ButtonX::instance, DAT_ButtonH::instance + DAT_ButtonY::instance, + blend * 16 / 32 + 32); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::renderChatMessageList, + DAT_GameSynchronyState::ptr)(DAT_ButtonX::instance + 8, + DAT_ButtonH::instance + DAT_ButtonY::instance - 31, DAT_GameSynchronyState::instance.chatScrollOffset); + } + + } +} +} diff --git a/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_MapSelectTable.cpp b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_MapSelectTable.cpp new file mode 100644 index 0000000000..f3200233fd --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_MapSelectTable.cpp @@ -0,0 +1,149 @@ +#include "../LobbyMenu.func.hpp" + +#include "OpenSHC/Global.func.hpp" +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/IO/Graphics/GmID.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_ButtonBackgroundBlendStrength.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x0042B4C0 + void LobbyMenu::MenuItemRenderFunction_LobbyMenu_MapSelectTable(int row, ...) + { + if (MACRO_CALL(OpenSHC::UI::Helpers_Func::AModalDialogIsActiveButIsNotQuitting)()) { + return; + } + // TRUE for the host while an AI setup dialog is open (no flag: quick_diff 0.9781 -> 0.9607) + BOOLEnum const aiSetupOpen + = DAT_MenuModalComposition1::instance.activeModalDialogID == OpenSHC::UI::Enums::MMT_ROUNDTABLE + || DAT_MenuModalComposition1::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_BASIC_AI_LORD_SELECT + || DAT_MenuModalComposition1::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_EXTENDED_AI_LORD_SELECT; + if (aiSetupOpen) { + DAT_ButtonUnknownZero::instance = TRUE; + } + if (!aiSetupOpen || !DAT_GameSynchronyState::instance.isHost) { + DAT_ButtonUnknownZero::instance = FALSE; + } + // for a guest, -1 marks another map than the host's and 1 the host's map + int hostMap = 0; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + if (!DAT_GameSynchronyState::instance.isHost) { + hostMap = -1; + DAT_ButtonCurrentlyInteracting::instance = FALSE; + if (DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + row + < DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber + && MACRO_CALL(OpenSHC::OS_Func::__stricmp)( + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, + DAT_ResourceManager::ptr)(DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + + row]), + DAT_GameSynchronyState::instance.mapName) + == 0) { + hostMap = 1; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawTableCellBackground, + DAT_PencilRenderCore::ptr)(TRUE, row, DAT_ButtonBackgroundBlendStrength::instance); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawTableCellBackground, + DAT_PencilRenderCore::ptr)(FALSE, row, DAT_ButtonBackgroundBlendStrength::instance); + } + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawTableCellBackground, + DAT_PencilRenderCore::ptr)(row == DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected, + row, DAT_ButtonBackgroundBlendStrength::instance); + } + if (DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + row + >= DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber) { + return; + } + int iconsWidth = 0; + uint color; + if (DAT_GameSynchronyState::instance.unknownMapRelatedReceivedDataArray[DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + row]] + <= 0) { + color = OpenSHC::Rendering::Colors::COL_7F7F7F; + } else if ((row == DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected + || DAT_ButtonCurrentlyInteracting::instance || hostMap == 1) + && hostMap >= 0) { + color = OpenSHC::Rendering::Colors::COL_CCFAFF; + } else { + color = OpenSHC::Rendering::Colors::COL_C2F0EB; + } + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_GameSynchronyState::instance.mapPlayerCountArray[DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + row]], + DAT_ButtonX::instance + 8, DAT_ButtonY::instance + 3, OpenSHC::Text::TTA_LEFT, color, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + if (DAT_GameSynchronyState::instance.mapBalanceArray[DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + row]] + != 0) { + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_3, 210, + DAT_ButtonX::instance + 24, DAT_ButtonY::instance + 5, DAT_ButtonBackgroundBlendStrength::instance); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + iconsWidth = 20; + } + // declared once for both calls (at each call: quick_diff 0.9781 -> 0.9649) + int descriptionGroup; + if (DAT_GameSynchronyState::instance.mapU4Int0_2Array[DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + row]] + != 0) { + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 394, + DAT_ButtonX::instance + 24 + iconsWidth, DAT_ButtonY::instance + 5, + DAT_ButtonBackgroundBlendStrength::instance); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + // The file name in a local (as an argument: quick_diff 0.9781 -> 0.9518) + char* const loadedName = MACRO_CALL_MEMBER( + OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, DAT_ResourceManager::ptr)( + DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + row]); + char* const mapName + = MACRO_CALL(OpenSHC::Global_Func::GetStringBasedOnHardcodedMaps)(loadedName, &descriptionGroup); + DAT_TextManagerObject::instance.field_0x30 = 1; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderMultilineText5Unk, DAT_TextManagerObject::ptr)( + mapName, DAT_ButtonX::instance + 44 + iconsWidth, DAT_ButtonY::instance + 3, 150 - iconsWidth, + color, 18, (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + return; + } + char* const loadedName + = MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, + DAT_ResourceManager::ptr)(DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + row]); + char* const mapName + = MACRO_CALL(OpenSHC::Global_Func::GetStringBasedOnHardcodedMaps)(loadedName, &descriptionGroup); + DAT_TextManagerObject::instance.field_0x30 = 1; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderMultilineText5Unk, DAT_TextManagerObject::ptr)( + mapName, DAT_ButtonX::instance + 24 + iconsWidth, DAT_ButtonY::instance + 3, 170 - iconsWidth, color, + 18, (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } + + } +} +} diff --git a/src/OpenSHC/UI/MenuItems/MainMenu/MenuItemActionHandler_MainMenu_Main.cpp b/src/OpenSHC/UI/MenuItems/MainMenu/MenuItemActionHandler_MainMenu_Main.cpp new file mode 100644 index 0000000000..534109bdba --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/MainMenu/MenuItemActionHandler_MainMenu_Main.cpp @@ -0,0 +1,169 @@ +#include "../MainMenu.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map/MapPropertiesState.func.hpp" +#include "OpenSHC/Rendering/Bink/BinkControlClass.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/UI/MenuTextInputState.func.hpp" +#include "OpenSHC/Audio/SFX/SoundEffectID.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Rendering/Enums/DirectDrawStatus.hpp" +#include "OpenSHC/UI/Enums/BuildMenuTabType.hpp" +#include "OpenSHC/UI/Enums/BuildingsAndStatusMenuTabType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_BinkControlState.hpp" +#include "OpenSHC/Globals/DAT_BlendingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MapMissionType.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" +#include "OpenSHC/Globals/INT_00b95954.hpp" +#include "OpenSHC/Globals/INT_00b95b64.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004251A0 + void MainMenu::MenuItemActionHandler_MainMenu_Main(int button, ...) + { + switch (button) { + case 1: + // historical campaigns + DAT_GameCore::instance.gameSuspended = 0; + DAT_GameState::instance.mapAndTime.difficulty = DAT_GameCore::instance.missionDifficulty; + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_HISTORIC_CAMPAIGN_SELECT, 0); + for (int i = 0; i < countof(DAT_BlendingDefinedData::instance.PlayerSlotUnitColor); ++i) { + DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[i] + = DAT_BlendingDefinedData::instance.DefaultPlayerSlotUnitColor[i]; + } + return; + case 2: + // crusader + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_SELECT_CRUSADE, 0); + return; + case 3: + // castle builder; the tail in each case (one copy after the switch: quick_diff 0.9500 -> 0.7756) + DAT_GameCore::instance.missionNumber1to20 = 0; + DAT_GameCore::instance.gameMode_2 = OpenSHC::Game::GM_BUILDERUnk; + DAT_GameCore::instance.xbowProducible_logic = 1; + DAT_GameCore::instance.pikeProducible_logic = 1; + DAT_GameCore::instance.swordProducible_logic = 1; + DAT_GameCore::instance.bowProducible_logic = 1; + DAT_GameCore::instance.spearProducible_logic = 1; + DAT_GameCore::instance.maceProducible_logic = 1; + MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::resetTeams, DAT_GameState::ptr)(); + DAT_MapMissionType::instance = 0; + INT_00b95b64::instance = 1; + DAT_GameCore::instance.standaloneFilename[0] = '\0'; + DAT_GameState::instance.mapAndTime.difficulty = DAT_GameCore::instance.missionDifficulty_0; + DAT_GameCore::instance.menuTabToSwitchTo.tabType = OpenSHC::UI::Enums::BASMTT_NONE; + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_SINGLEPLAYER_MAP_CHOICE, 0); + for (int i = 0; i < countof(DAT_BlendingDefinedData::instance.PlayerSlotUnitColor); ++i) { + DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[i] + = DAT_BlendingDefinedData::instance.DefaultPlayerSlotUnitColor[i]; + } + return; + case 4: + // multiplayer + if (DAT_GameCore::instance.directDrawStatus < OpenSHC::Rendering::Enums::DD7_LOADED) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::clearEntry, DAT_UserTextHandlerState::ptr)(5); + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::clearEntry, DAT_UserTextHandlerState::ptr)(6); + DAT_GameSynchronyState::instance.nextModalDialog + = OpenSHC::UI::Enums::MMT_CHOOSE_NETWORK_SERVICE_PROVIDER; + DAT_GameSynchronyState::instance.kickedAtTime = 0; + DAT_GameSynchronyState::instance.ipArrayIndex = 0; + DAT_GameCore::instance.gameMode_2 = OpenSHC::Game::GM_SKIRMISH_AND_MULTIPLAYER; + DAT_GameCore::instance.xbowProducible_logic = 1; + DAT_GameCore::instance.pikeProducible_logic = 1; + DAT_GameCore::instance.swordProducible_logic = 1; + DAT_GameCore::instance.bowProducible_logic = 1; + DAT_GameCore::instance.spearProducible_logic = 1; + DAT_GameCore::instance.maceProducible_logic = 1; + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_MP_CONNECTION, 0); + for (int i = 0; i < countof(DAT_BlendingDefinedData::instance.PlayerSlotUnitColor); ++i) { + DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[i] + = DAT_BlendingDefinedData::instance.DefaultPlayerSlotUnitColor[i]; + } + return; + case 9: + // custom scenarios + DAT_GameCore::instance.gameMode_2 = OpenSHC::Game::GM_EDITOR; + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_CUSTOM_SCENARIOS, 0); + return; + case 6: + // tutorial + DAT_GameCore::instance.missionNumber1to20 = 30; + DAT_GameCore::instance.gameMode_2 = OpenSHC::Game::GM_CRUSADER_TUTORIAL; + DAT_GameCore::instance.xbowProducible_logic = 0; + DAT_GameCore::instance.pikeProducible_logic = 0; + DAT_GameCore::instance.swordProducible_logic = 0; + DAT_GameCore::instance.bowProducible_logic = 0; + DAT_GameCore::instance.spearProducible_logic = 0; + DAT_GameCore::instance.maceProducible_logic = 0; + MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::resetTeams, DAT_GameState::ptr)(); + DAT_GameSynchronyState::instance.currentPlayerSlotID = 1; + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[1] = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::MapPropertiesState_Func::loadMap, DAT_MapPropertiesState::ptr)( + // "Crusader_tutorial.map" + (char*)s_Crusader_tutorial_map_005a1ff8); + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.buildMenuTab = OpenSHC::UI::Enums::BMTT_CASTLE; + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_BUILD_MENU, 0); + MACRO_CALL_MEMBER( + OpenSHC::UI::MenuTextInputState_Func::clearModalDialog2to6, DAT_MenuTextInputState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_TUTORIAL_BOX, FALSE); + MACRO_CALL(OpenSHC::UI::Helpers_Func::InitTutorialState)(); + return; + case 8: + // options + DAT_GameSynchronyState::instance.currentPlayerSlotID = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_ASK_FOR_SLOT_ASSIGNMENT); + MACRO_CALL_MEMBER(OpenSHC::UI::MenuTextInputState_Func::activateModalDialogAndClearText, + DAT_MenuTextInputState::ptr)(OpenSHC::UI::Enums::MMT_MAIN_MENU_OPTIONS); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::setUpSFXToPlayUnk, DAT_SFXState::ptr)( + OpenSHC::Audio::SFX::SEID_UNKNOWN_0x101); + return; + case 5: + // quit + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 9; + MACRO_CALL_MEMBER(OpenSHC::UI::MenuTextInputState_Func::activateModalDialogAndClearText, + DAT_MenuTextInputState::ptr)(OpenSHC::UI::Enums::MMT_YES_NO_DIALOG); + MACRO_CALL_MEMBER( + OpenSHC::Rendering::Bink::BinkControlClass_Func::stopBinkPlayback, DAT_BinkControlState::ptr)(0); + return; + case 7: + // credits + INT_00b95954::instance = 0; + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_CREDITS, 0); + return; + } + } + + } +} +} diff --git a/src/OpenSHC/UI/MenuItems/SinglePlayerMapChoice/MenuItemActionHandler_SingleplayerMapChoice_MapTableHeader.cpp b/src/OpenSHC/UI/MenuItems/SinglePlayerMapChoice/MenuItemActionHandler_SingleplayerMapChoice_MapTableHeader.cpp new file mode 100644 index 0000000000..c98811fc7c --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/SinglePlayerMapChoice/MenuItemActionHandler_SingleplayerMapChoice_MapTableHeader.cpp @@ -0,0 +1,121 @@ +#include "../SinglePlayerMapChoice.func.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x00449290 + void SinglePlayerMapChoice::MenuItemActionHandler_SingleplayerMapChoice_MapTableHeader(int column, ...) + { + // A click on a column header sorts the map list by that column, and a second click reverses the order + switch (column) { + case 0: { + // Name: the order kept in DAT_ArrayOfMapIndices2, backwards after the first click + if (DAT_MenuTextInputState::instance.fileListSortOrder == 0) { + for (int i = 0; i < DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber; ++i) { + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] + = DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices2[DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber + - 2 - i]; + } + DAT_MenuTextInputState::instance.fileListSortOrder = 1; + break; + } + int i = 0; + if (i < DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber) { + // A guarded do-while (a for or a while loop: quick_diff 0.9738 -> 0.9283) + do { + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] + = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices2[i - 1]; + ++i; + } while (i < DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber); + } + DAT_MenuTextInputState::instance.fileListSortOrder = 0; + break; + } + case 1: { + // Date: a bubble sort on the file times, newest first after the first click + int const last = DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber - 1; + if (DAT_MenuTextInputState::instance.fileListSortOrder == 2) { + for (int swaps = 1; swaps != 0;) { + swaps = 0; + for (int i = 0; i < last; ++i) { + int const nextMapIndex = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1]; + int const mapIndex = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i]; + if (DAT_ResourceManager::instance.mapFileTimes[mapIndex] + > DAT_ResourceManager::instance.mapFileTimes[nextMapIndex]) { + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] = nextMapIndex; + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1] = mapIndex; + ++swaps; + } + } + } + DAT_MenuTextInputState::instance.fileListSortOrder = 3; + break; + } + for (int swaps = 1; swaps != 0;) { + swaps = 0; + for (int i = 0; i < last; ++i) { + int const nextMapIndex = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1]; + int const mapIndex = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i]; + if (DAT_ResourceManager::instance.mapFileTimes[mapIndex] + < DAT_ResourceManager::instance.mapFileTimes[nextMapIndex]) { + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] = nextMapIndex; + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1] = mapIndex; + ++swaps; + } + } + } + DAT_MenuTextInputState::instance.fileListSortOrder = 2; + break; + } + case 2: { + // The third column: a bubble sort on arrayOfMapEndInt2, with its own order flag + int const last = DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber - 1; + if (DAT_GameSynchronyState::instance.lobbyMapSortOrder == 5) { + for (int swaps = 1; swaps != 0;) { + swaps = 0; + for (int i = 0; i < last; ++i) { + int const nextMapIndex = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1]; + int const mapIndex = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i]; + if (DAT_MenuTextInputState::instance.arrayOfMapEndInt2[mapIndex] + < DAT_MenuTextInputState::instance.arrayOfMapEndInt2[nextMapIndex]) { + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] = nextMapIndex; + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1] = mapIndex; + ++swaps; + } + } + } + DAT_GameSynchronyState::instance.lobbyMapSortOrder = 6; + break; + } + for (int swaps = 1; swaps != 0;) { + swaps = 0; + for (int i = 0; i < last; ++i) { + int const nextMapIndex = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1]; + int const mapIndex = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i]; + if (DAT_MenuTextInputState::instance.arrayOfMapEndInt2[mapIndex] + > DAT_MenuTextInputState::instance.arrayOfMapEndInt2[nextMapIndex]) { + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] = nextMapIndex; + DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1] = mapIndex; + ++swaps; + } + } + } + DAT_GameSynchronyState::instance.lobbyMapSortOrder = 5; + break; + } + } + MACRO_CALL(OpenSHC::UI::MenuItems::SinglePlayerMapChoice_Func:: + MenuItemActionHandler_SingleplayerMapChoice_MapTable)( + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected); + DAT_MenuTextInputState::instance.lastClickedListIndex = -1; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index a1c219ccf9..a2a259068c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -6687,7 +6687,7 @@ SHC_3BB0A8C1_0x00424DA0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00424F50 | 0.0% | Pending -SHC_3BB0A8C1_0x004251A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004251A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004254D0 | 0.0% | Pending @@ -6979,7 +6979,7 @@ SHC_3BB0A8C1_0x0042AC60 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0042AC70 | 0.0% | Pending -SHC_3BB0A8C1_0x0042AC90 | 0.0% | Pending +SHC_3BB0A8C1_0x0042AC90 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0042AE90 | 0.0% | Pending @@ -7419,7 +7419,7 @@ SHC_3BB0A8C1_0x0042B460 | 0.0% | Pending SHC_3BB0A8C1_0x0042B470 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0042B4C0 | 0.0% | Pending +SHC_3BB0A8C1_0x0042B4C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0042B7B0 | 100.0% | Reimplemented @@ -16391,7 +16391,7 @@ SHC_3BB0A8C1_0x0044927C | 0.0% | Pending SHC_3BB0A8C1_0x00449280 | 0.0% | Pending -SHC_3BB0A8C1_0x00449290 | 0.0% | Pending +SHC_3BB0A8C1_0x00449290 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004492E0 | 0.0% | Pending @@ -30093,7 +30093,7 @@ SHC_3BB0A8C1_0x004BC690 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BC6C0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004BC6F0 | 0.0% | Pending +SHC_3BB0A8C1_0x004BC6F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BC770 | 100.0% | Reimplemented