diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 7a4a662301..2110779750 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -115,3 +115,6 @@ src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAn src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_GatehouseOpenClose.cpp src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_WorkshopWeaponSelection.cpp src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface.cpp +src/OpenSHC/UI/DisplayElements/RenderTimeUntilDefeatDisplayElement.cpp +src/OpenSHC/UI/DisplayElements/GetIfDisplayElementStateNotZero.cpp +src/OpenSHC/UI/DisplayElements/FindDisplayElementWithID.cpp diff --git a/src/OpenSHC/UI/DisplayElements/RenderSomeMultiplayerInfoUnkDisplayElement28.cpp b/src/OpenSHC/UI/DisplayElements/RenderSomeMultiplayerInfoUnkDisplayElement28.cpp new file mode 100644 index 0000000000..49ce4b0d79 --- /dev/null +++ b/src/OpenSHC/UI/DisplayElements/RenderSomeMultiplayerInfoUnkDisplayElement28.cpp @@ -0,0 +1,158 @@ +#include "../DisplayElements.func.hpp" + +#include "OpenSHC/Input/MouseState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/DisplayElementID.hpp" + +#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.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_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace UI { + namespace DisplayElements { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B2530 + void RenderSomeMultiplayerInfoUnkDisplayElement28(int posX, int posY, DWORD elementState) + { + DWORD const currentTime = timeGetTime(); + if (DAT_GameCore::instance.mapU4Int0 != 0) { + posY += 65; + } + // Nested, not early returns (early returns: quick_diff 0.9395 -> 0.6573) + if (DAT_GameSynchronyState::instance.DAT_SomeTime == 0) { + if (DAT_GameSynchronyState::instance.isHost) { + if (DAT_GameSynchronyState::instance + .currentPlayerFullIDArray[DAT_GameSynchronyState::instance.laggingPlayerIDUnk] + == -1) { + DAT_GameSynchronyState::instance.DAT_SomeTime = currentTime; + // "Timed Out" + DAT_GameSynchronyState::instance.lagNotificationCode = 65; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_UNKNOWN_99); + } else if (currentTime + - DAT_GameSynchronyState::instance + .connectionLagInfoArray[DAT_GameSynchronyState::instance.laggingPlayerIDUnk] + .time + <= 10000) { + DAT_GameSynchronyState::instance.DAT_SomeTime = currentTime; + // "Back in the Game!" + DAT_GameSynchronyState::instance.lagNotificationCode = 67; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_UNKNOWN_99); + } + } + } else if (currentTime - DAT_GameSynchronyState::instance.DAT_SomeTime > 2000) { + DAT_GameSynchronyState::instance.DAT_SomeTime = 0; + DAT_GameSynchronyState::instance.laggingPlayerIDUnk = 0; + MACRO_CALL(OpenSHC::UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + OpenSHC::UI::Enums::DEID_SOME_MULTIPLAYER_INFO_Unk_28, 0); + return; + } + DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_MAP_GAME; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBorderedBoxWithBlendedBackground, + DAT_PencilRenderCore::ptr)(posX - 204, posY, 408, 96); + DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + int const textY = posY + 20; + int const textX = posX - 190; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + DAT_GameSynchronyState::instance.finalResults + .names[DAT_GameSynchronyState::instance.laggingPlayerIDUnk], + textX, textY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE, 0); + // ": Not Responding", after the name + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_MULTIPLAYER_CONNECTION, 64), + textX, textY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, TRUE, 0); + if (DAT_GameSynchronyState::instance.DAT_SomeTime == 0) { + DAT_ButtonX::instance = posX; + DAT_ButtonY::instance = posY + 52; + DAT_ButtonW::instance = 180; + DAT_ButtonH::instance = 28; + if (DAT_GameSynchronyState::instance.isHost) { + // Seconds until the player is dropped (60 s after their last message), shown as 50 at most + int secondsLeft = 60 + - (currentTime + - DAT_GameSynchronyState::instance + .connectionLagInfoArray[DAT_GameSynchronyState::instance.laggingPlayerIDUnk] + .time) + / 1000; + if (secondsLeft > 50) { + secondsLeft = 50; + } else if (secondsLeft < 0) { + secondsLeft = 0; + } + int const buttonTextY = posY + 58; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, + DAT_TextManagerObject::ptr)(secondsLeft, posX - 102, buttonTextY, OpenSHC::Text::TTA_CENTER, + OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE, 0); + if (MACRO_CALL_MEMBER(OpenSHC::Input::MouseState_Func::isMouseInsideBox, DAT_MouseState::ptr)( + posX - DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetX, + posY - DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetY + 52, 180, + 28)) { + DAT_ButtonCurrentlyInteracting::instance = TRUE; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + // "Eject", highlighted + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, 91), + posX + 90, buttonTextY, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, + 18, FALSE, 0); + if (!DAT_MouseState::instance.leftClickStart) { + return; + } + DAT_GameSynchronyState::instance.DAT_SomeTime = timeGetTime(); + // "Ejected" + DAT_GameSynchronyState::instance.lagNotificationCode = 66; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_UNKNOWN_99); + return; + } + DAT_ButtonCurrentlyInteracting::instance = FALSE; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + // "Eject" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, 91), + posX + 90, buttonTextY, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, + FALSE, 0); + return; + } + // "Eject", greyed out: only the host can eject + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, 91), + posX + 90, posY + 58, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_7F7F7F, 18, FALSE, + 0); + return; + } + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_MULTIPLAYER_CONNECTION, + DAT_GameSynchronyState::instance.lagNotificationCode), + posX, posY + 58, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE, 0); + } + + } +} +} diff --git a/src/OpenSHC/UI/DisplayElements/RenderTimeUntilDefeatDisplayElement.cpp b/src/OpenSHC/UI/DisplayElements/RenderTimeUntilDefeatDisplayElement.cpp new file mode 100644 index 0000000000..ed263da13d --- /dev/null +++ b/src/OpenSHC/UI/DisplayElements/RenderTimeUntilDefeatDisplayElement.cpp @@ -0,0 +1,127 @@ +#include "../DisplayElements.func.hpp" + +#include "OpenSHC/Map/MapPropertiesState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Rendering/ScreenResolutionEnum.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/DisplayElementID.hpp" + +#include "OpenSHC/Globals/COL_BLACK.hpp" +#include "OpenSHC/Globals/COL_DARK_LIME.hpp" +#include "OpenSHC/Globals/DAT_00df4290.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace DisplayElements { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B2280 + void RenderTimeUntilDefeatDisplayElement(int posX, int posY, DWORD elementState) + { + if (DAT_GameCore::instance.section1095 == 2) { + MACRO_CALL(OpenSHC::UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + OpenSHC::UI::Enums::DEID_TIME_UNTIL_DEFEAT, 0); + return; + } + // "Time Until Defeat" + int const barWidth + = MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::computeTextWidth, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_OBJECTIVES, 17), + 18); + // Centred for an 800-pixel-wide layout: shifted left by (width - 800) / 2 + if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1024x768) { + posX -= 112; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1280x1024) { + posX -= 240; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1600x1200) { + posX -= 400; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1280x720) { + posX -= 240; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1440x900) { + posX -= 320; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1920x1080) { + posX -= 560; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1920x1200) { + posX -= 560; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_2560x1440) { + posX -= 880; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_2560x1600) { + posX -= 880; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1366x768) { + posX -= 283; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1680x1050) { + posX -= 440; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1600x900) { + posX -= 400; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1024x600) { + posX -= 112; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1360x768) { + posX -= 280; + } + int const halfWidth = barWidth / 2; + // posX becomes the bar's centre (a centre local: reccmp 100.0% -> 98.5%) + posX += 10 + halfWidth; + // Drawn right of the victory timer's bar when both are shown + if (MACRO_CALL(OpenSHC::UI::DisplayElements_Func::GetIfDisplayElementStateNotZero)( + OpenSHC::UI::Enums::DEID_TIME_UNTIL_VICTORY)) { + posX += DAT_00df4290::instance; + } + DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_MAP_GAME; + // The bar's left edge is written out at each use (a left local: reccmp 100.0% -> 91.1%) + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBlendedBlackBox, + DAT_PencilRenderCore::ptr)(posX - halfWidth - 7, posY - 5, halfWidth + 5 + posX, posY + 30, 16); + // "Time Until Defeat" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_OBJECTIVES, 17), + posX, posY, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 0, 18, FALSE, 0); + int const eventID + = MACRO_CALL_MEMBER(OpenSHC::Map::MapPropertiesState_Func::getEventIDForTimeUntilDefeatEventType, + DAT_MapPropertiesState::ptr)(); + int const startMonths = DAT_MapPropertiesState::instance.SEC_StartingMonth + + DAT_MapPropertiesState::instance.SEC_StartingYear * 12; + // A month is 800 ticks (4 weeks of 200) + int const deadlineTicks + = (DAT_MapPropertiesState::instance.scenarioEvents[eventID].header.month + + DAT_MapPropertiesState::instance.scenarioEvents[eventID].header.year * 12 - startMonths) + * 800; + int const elapsedMonthTicks = (DAT_GameState::instance.mapAndTime.year * 12 - startMonths + + DAT_GameState::instance.mapAndTime.month) + * 800; + // While time is halted, or the keep placement hint is up, only whole months count + int ticksLeft; + if (!DAT_GameCore::instance.isTimeHalted + && !MACRO_CALL(OpenSHC::UI::DisplayElements_Func::GetIfDisplayElementStateNotZero)( + OpenSHC::UI::Enums::DEID_KEEP_AND_GRANERY_PLACEMENT_INFO)) { + ticksLeft = deadlineTicks - DAT_GameState::instance.mapAndTime.week * 200 + - DAT_GameState::instance.gameTicksLoadBalancer - elapsedMonthTicks; + } else { + ticksLeft = deadlineTicks - elapsedMonthTicks; + } + if (ticksLeft < 0) { + ticksLeft = 0; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBorderBox, DAT_PencilRenderCore::ptr)( + posX - halfWidth - 1, posY + 18, halfWidth + 1 + posX, posY + 24, COL_BLACK::instance.shortValue); + if (ticksLeft != deadlineTicks) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(posX - halfWidth, posY + 19, + ((deadlineTicks - ticksLeft) * barWidth) / deadlineTicks - halfWidth + posX, posY + 23, + COL_DARK_LIME::instance.shortValue); + } + DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + } + + } +} +} diff --git a/src/OpenSHC/UI/DisplayElements/RenderTimeUntilVictoryDisplayElement.cpp b/src/OpenSHC/UI/DisplayElements/RenderTimeUntilVictoryDisplayElement.cpp new file mode 100644 index 0000000000..51ec553e90 --- /dev/null +++ b/src/OpenSHC/UI/DisplayElements/RenderTimeUntilVictoryDisplayElement.cpp @@ -0,0 +1,99 @@ +#include "../DisplayElements.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Rendering/ScreenResolutionEnum.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/DisplayElementID.hpp" + +#include "OpenSHC/Globals/COL_BLACK.hpp" +#include "OpenSHC/Globals/COL_DARK_LIME.hpp" +#include "OpenSHC/Globals/DAT_00df4290.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace DisplayElements { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B1EB0 + void RenderTimeUntilVictoryDisplayElement(int posX, int posY, DWORD elementState) + { + if (DAT_GameCore::instance.section1095 == 2) { + MACRO_CALL(OpenSHC::UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + OpenSHC::UI::Enums::DEID_TIME_UNTIL_VICTORY, 0); + return; + } + // "Time Until Victory" + int const barWidth + = MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::computeTextWidth, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_OBJECTIVES, 25), + 18); + DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_MAP_GAME; + // Centred for an 800-pixel-wide layout: shifted left by (width - 800) / 2 + if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1024x768) { + posX -= 112; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1280x1024) { + posX -= 240; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1600x1200) { + posX -= 400; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1280x720) { + posX -= 240; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1440x900) { + posX -= 320; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1920x1080) { + posX -= 560; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1920x1200) { + posX -= 560; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_2560x1440) { + posX -= 880; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_2560x1600) { + posX -= 880; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1366x768) { + posX -= 283; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1680x1050) { + posX -= 440; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1600x900) { + posX -= 400; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1024x600) { + posX -= 112; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1360x768) { + posX -= 280; + } + int const halfWidth = barWidth / 2; + // Read by RenderTimeUntilDefeatDisplayElement, which draws its bar to the right of this one + DAT_00df4290::instance = barWidth + 16; + // posX becomes the bar's centre (a centre local: quick_diff 0.9810 -> 0.9620) + posX += 10 + halfWidth; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBlendedBlackBox, + DAT_PencilRenderCore::ptr)(posX - halfWidth - 7, posY - 5, halfWidth + 5 + posX, posY + 30, 16); + // "Time Until Victory" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_OBJECTIVES, 25), + posX, posY, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 0, 18, FALSE, 0); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBorderBox, DAT_PencilRenderCore::ptr)( + posX - halfWidth - 1, posY + 18, halfWidth + 1 + posX, posY + 24, COL_BLACK::instance.shortValue); + if (DAT_MapPropertiesState::instance.SEC_Section1080 != DAT_MapPropertiesState::instance.SEC_Section1090) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(posX - halfWidth, posY + 19, + ((DAT_MapPropertiesState::instance.SEC_Section1090 + - DAT_MapPropertiesState::instance.SEC_Section1080) + * barWidth) + / DAT_MapPropertiesState::instance.SEC_Section1090 + - halfWidth + posX, + posY + 23, COL_DARK_LIME::instance.shortValue); + } + DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + } + + } +} +} diff --git a/src/OpenSHC/UI/MenuModals/NewEvent/MenuModalRenderFunction_NewEvent.cpp b/src/OpenSHC/UI/MenuModals/NewEvent/MenuModalRenderFunction_NewEvent.cpp new file mode 100644 index 0000000000..d00f2fc6f5 --- /dev/null +++ b/src/OpenSHC/UI/MenuModals/NewEvent/MenuModalRenderFunction_NewEvent.cpp @@ -0,0 +1,123 @@ +#include "../NewEvent.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuModals { + + // FUNCTION: STRONGHOLDCRUSADER 0x004AB790 + void NewEvent::MenuModalRenderFunction_NewEvent(int x, int y, int width, int height) + { + // "Event" + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawHeaderTextBanner, + DAT_PencilRenderCore::ptr)(OpenSHC::DE::SHCDE::TEXT_SCENARIO, 48, x, y, width, height); + // Lists the event's first seven enabled conditions, each with its parameter and value + int rowsDrawn = 0; + // Declared here, between the other two (declared in the for: quick_diff 0.9476 -> 0.9372) + int conditionIndex = 0; + int rowY = y + 165; + for (; + conditionIndex < countof(DAT_MapPropertiesState::instance.scenarioEvents[0].data.scenario.conditions); + ++conditionIndex) { + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[conditionIndex] + .enabled + == 0) { + continue; + } + // Condition names are texts 106-125, then 190 on; the four "... Acquired" ones all read "Goods + // Acquired" + int conditionText = conditionIndex + 106; + if (conditionText > 125) { + conditionText += 64; + } + if (conditionText == 111 || conditionText == 112 || conditionText == 113 || conditionText == 123) { + conditionText = 113; + } + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_SCENARIO, conditionText), + x + 150, rowY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + // Kind 1: the condition's resource + if (DAT_MissionAestheticsDefinedData::instance.EventConditionParamKind[conditionIndex] == 1) { + int const optionX = x + 158; + // "(" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_brace_close_005a2778, optionX, rowY, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_CCFAFF, 18, TRUE, 0); + // The option's text offset is read after the "(" (in the call: quick_diff 0.9476 -> 0.8429) + int const optionText = DAT_MissionAestheticsDefinedData::instance + .EventConditionOptionTextOffsets[DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[conditionIndex] + .subType]; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_SCENARIO, optionText), + optionX, rowY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, TRUE, 0); + // ")" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_brace_open_005a2774, optionX, rowY, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_CCFAFF, 18, TRUE, 0); + } + // Kind 2: the condition's lord + if (DAT_MissionAestheticsDefinedData::instance.EventConditionParamKind[conditionIndex] == 2) { + int const optionX = x + 158; + // "(" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_brace_close_005a2778, optionX, rowY, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_CCFAFF, 18, TRUE, 0); + int const optionText + = DAT_MissionAestheticsDefinedData::instance.field_0x170[DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[conditionIndex] + .subType]; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_SCENARIO, optionText), + optionX, rowY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, TRUE, 0); + // ")" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_brace_open_005a2774, optionX, rowY, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_CCFAFF, 18, TRUE, 0); + } + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[conditionIndex] + .value + * DAT_MissionAestheticsDefinedData::instance.EventConditionValueScale[conditionIndex], + x + 450, rowY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + ++rowsDrawn; + rowY += 24; + if (rowsDrawn >= 7) { + break; + } + } + // Event action names are texts 128-155, then 177 on + int eventText + = DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.ScenarioEventType + + 128; + if (eventText > 155) { + eventText += 21; + } + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_SCENARIO, eventText), + x + 158, y + 380, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + } + + } +} +} diff --git a/src/OpenSHC/UI/MenuModals/TutorialBox/MenuModalRenderFunction_TutorialBox.cpp b/src/OpenSHC/UI/MenuModals/TutorialBox/MenuModalRenderFunction_TutorialBox.cpp new file mode 100644 index 0000000000..23239f73cc --- /dev/null +++ b/src/OpenSHC/UI/MenuModals/TutorialBox/MenuModalRenderFunction_TutorialBox.cpp @@ -0,0 +1,150 @@ +#include "../TutorialBox.func.hpp" + +#include "OpenSHC/Audio/MSS/SoundSystem.func.hpp" +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Text/FontSizeClass.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/Audio/MSS/enums/SHC_SoundStream.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/IO/Graphics/GmID.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_00df5540.hpp" +#include "OpenSHC/Globals/DAT_00df5544.hpp" +#include "OpenSHC/Globals/DAT_00df5558.hpp" +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_SoundSystemState.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_TutorialCurrentStep.hpp" +#include "OpenSHC/Globals/INT_00df5564.hpp" +#include "OpenSHC/Globals/INT_00df5644.hpp" +#include "OpenSHC/Globals/INT_00df5648.hpp" +#include "OpenSHC/Globals/INT_ARRAY_00df5598.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuModals { + + // FUNCTION: STRONGHOLDCRUSADER 0x004BCBA0 + void TutorialBox::MenuModalRenderFunction_TutorialBox(int x, int y, int width, int height) + { + if (DAT_TutorialCurrentStep::instance >= 32) { + return; + } + int const textX = x + 16; + int const textWidth = width - 32; + int const tutorialTextOffset = INT_ARRAY_00df5598::instance[DAT_TutorialCurrentStep::instance]; + int blendStrength = 0; + if (DAT_00df5540::instance != 0) { + blendStrength = DAT_00df5544::instance; + } + // The frame is drawn in 24 pixel tiles, rounded up to whole tiles + int const boxWidth = ((width - 1) / 24 + 1) * 24; + int const boxHeight = ((height - 1) / 24 + 1) * 24; + for (int offsetY = 0; offsetY < boxHeight; offsetY += 24) { + // Icons 1-3 are the top row's left, inner and right tiles, 7-9 a middle row's and 13-15 the bottom's + int rowBaseIcon; + if (offsetY == 0) { + rowBaseIcon = 1; + } else if (offsetY == boxHeight - 24) { + rowBaseIcon = 13; + } else { + rowBaseIcon = 7; + } + for (int offsetX = 0; offsetX < boxWidth; offsetX += 24) { + int iconIndex = rowBaseIcon; + if (offsetX != 0) { + if (offsetX == boxWidth - 24) { + iconIndex = rowBaseIcon + 2; + } else if (rowBaseIcon == 7) { + // The plain inner tile has its own call (the original pushes 8 and 11 as constants) + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_3, 8, + offsetX + x, offsetY + y, OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_3, 11, + blendStrength); + continue; + } else { + iconIndex = rowBaseIcon + 1; + } + } + // Each tile's alpha mask is three icons on + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_3, iconIndex, + offsetX + x, offsetY + y, OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_3, iconIndex + 3, + blendStrength); + } + } + // Speaks the button hint once when it comes up, the two recordings taking turns + if (INT_00df5564::instance && !INT_00df5648::instance) { + ++INT_00df5644::instance; + if (INT_00df5644::instance > 1) { + INT_00df5644::instance = 0; + } + if (!MACRO_CALL_MEMBER(OpenSHC::Audio::MSS::SoundSystem_Func::isSampleOrStreamPlaying, + DAT_SoundSystemState::ptr)(OpenSHC::Audio::MSS::enums::SND_STR_SPEECH_1) + && !MACRO_CALL_MEMBER(OpenSHC::Audio::MSS::SoundSystem_Func::isSampleOrStreamPlaying, + DAT_SoundSystemState::ptr)(OpenSHC::Audio::MSS::enums::SND_STR_SPEECH_2)) { + char speechFileName[32]; + // "%s%s", "fx\\speech\\" + MACRO_CALL(OpenSHC::OS_Func::_sprintf)(speechFileName, s__s_s_005aa800, s_fx_speech__005a64cc, + DAT_MissionAestheticsDefinedData::instance.field_0x41e4[INT_00df5644::instance + 34][0]); + MACRO_CALL_MEMBER(OpenSHC::Audio::MSS::SoundSystem_Func::playAmbientStreamWithLoop, + DAT_SoundSystemState::ptr)(speechFileName); + } + } + INT_00df5648::instance = INT_00df5564::instance; + // >> 1 for the centre, as the original has no rounding fix (/ 2: quick_diff 0.9764 -> 0.8745) + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_TUTORIAL, tutorialTextOffset), + (width >> 1) + x, y + 15, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, + blendStrength); + int bodyY = y + 38; + if (!INT_00df5564::instance) { + // The text's offset is worked out before the call (in the call: quick_diff 0.9764 -> 0.9291) + int const bodyTextOffset = DAT_00df5558::instance + 1 + tutorialTextOffset; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderMultilineText5Unk, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_TUTORIAL, bodyTextOffset), + textX, bodyY, textWidth, OpenSHC::Rendering::Colors::COL_C2F0EB, 19, blendStrength); + bodyY += DAT_TextManagerObject::instance.field_0x4; + } + // A second test, not an else (else: quick_diff 0.9764 -> 0.9261) + if (INT_00df5564::instance) { + // Read for measuring and again in each arm (in the calls: quick_diff 0.9764 -> 0.9333) + int const measuredText = INT_00df5644::instance + 3; + // "That's not a valid option at this time." or "You can't do that at this point in the tutorial.": + // wrapped when taller than 35 pixels (more than one line), centred on one line otherwise + if (MACRO_CALL_MEMBER(OpenSHC::Text::FontSizeClass_Func::renderMultilineTextUnk, + &DAT_TextManagerObject::instance.fontSizeClassArray[18])( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_TUTORIAL_BUTTONS, measuredText), + 0, 0, textWidth, 0, 0, 1) + > 35) { + int const hintText = INT_00df5644::instance + 3; + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderMultilineText5Unk, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_TUTORIAL_BUTTONS, hintText), + textX, bodyY, textWidth, OpenSHC::Rendering::Colors::COL_0000FF, 18, blendStrength); + } else { + int const hintText = INT_00df5644::instance + 3; + // fixme: the original passes the blend as keepOffsetX here, and 0 as the blend + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_TUTORIAL_BUTTONS, hintText), + (width >> 1) + x, bodyY, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_0000FF, 18, + blendStrength, 0); + } + } + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderTutorialFloatForUIElement)(DAT_TutorialCurrentStep::instance); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6e036f9340..98e48917aa 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -25555,7 +25555,7 @@ SHC_3BB0A8C1_0x004AB570 | 0.0% | Pending SHC_3BB0A8C1_0x004AB680 | 0.0% | Pending -SHC_3BB0A8C1_0x004AB790 | 0.0% | Pending +SHC_3BB0A8C1_0x004AB790 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004ABA20 | 0.0% | Pending @@ -25999,13 +25999,13 @@ SHC_3BB0A8C1_0x004B1D90 | 0.0% | Pending SHC_3BB0A8C1_0x004B1E60 | 0.0% | Pending -SHC_3BB0A8C1_0x004B1EB0 | 0.0% | Pending +SHC_3BB0A8C1_0x004B1EB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B20B0 | 83.1% | shared arm fold direction -SHC_3BB0A8C1_0x004B2280 | 0.0% | Pending +SHC_3BB0A8C1_0x004B2280 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B2530 | 0.0% | Pending +SHC_3BB0A8C1_0x004B2530 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B2820 | 0.0% | Pending @@ -30169,7 +30169,7 @@ SHC_3BB0A8C1_0x004BCB9D | 0.0% | Pending SHC_3BB0A8C1_0x004BCB9E | 0.0% | Pending -SHC_3BB0A8C1_0x004BCBA0 | 0.0% | Pending +SHC_3BB0A8C1_0x004BCBA0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BCEC0 | 100.0% | Reimplemented