diff --git a/src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedEconomicMissionSelect_MissionSelect.cpp b/src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedEconomicMissionSelect_MissionSelect.cpp new file mode 100644 index 0000000000..dfce8c1197 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedEconomicMissionSelect_MissionSelect.cpp @@ -0,0 +1,95 @@ +#include "../Unused.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/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.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_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x00426D30 + void Unused::MenuItemRenderFunction_UnusedEconomicMissionSelect_MissionSelect(int button, ...) + { + // nothing while a dialog is open + if (DAT_MenuTextInputState::instance.currentModalDialog != OpenSHC::UI::Enums::MMT_NO_MENU + || DAT_MenuModalComposition1::instance.activeModalDialogID != OpenSHC::UI::Enums::MMT_NONE) { + return; + } + // The button holds minus the mission number: shown as mission - 32, named by entry mission - 11 of + // TEXT_MISSION_NAMES. A mission not reached yet is an empty cell. + if (!DAT_GameCore::instance.unlockAllHistoricalCampaigns + && -button > DAT_GameCore::instance.furthestMission) { + DAT_ButtonCurrentlyInteracting::instance = FALSE; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawTableCellBackground, + DAT_PencilRenderCore::ptr)(FALSE, button, 0); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + DAT_ButtonUnknownZero::instance = TRUE; + return; + } + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawTableCellBackground, + DAT_PencilRenderCore::ptr)(-button == DAT_GameCore::instance.missionNumber1to20, button, 0); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + if (-button == DAT_GameCore::instance.missionNumber1to20) { + // the selected mission: its number and name + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + -32 - button, DAT_ButtonX::instance + 8, DAT_ButtonY::instance + 5, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_CCFAFF, 19, FALSE, 0); + // y then x for the name (in the call: quick_diff 0.9302 -> 0.7608; x first: 0.8992) + int const nameY = DAT_ButtonY::instance + 5; + int const nameX = DAT_ButtonX::instance + 30; + 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_MISSION_NAMES, -11 - button), + nameX, nameY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 19, FALSE, 0); + DAT_ButtonUnknownZero::instance = FALSE; + return; + } + // The number's position and value in each branch (once, before the test: quick_diff 0.9302 -> 0.8760) + // and one call per colour (one renderText2 with a colour local: 0.6615) + if (DAT_ButtonCurrentlyInteracting::instance) { + int const numberY = DAT_ButtonY::instance + 5; + int const numberX = DAT_ButtonX::instance + 8; + int const number = -32 - button; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + number, numberX, numberY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 19, + FALSE, 0); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MISSION_NAMES, -11 - button, DAT_ButtonX::instance + 30, + DAT_ButtonY::instance + 5, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 19, + FALSE); + } else { + int const numberY = DAT_ButtonY::instance + 5; + int const numberX = DAT_ButtonX::instance + 8; + int const number = -32 - button; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + number, numberX, numberY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 19, + FALSE, 0); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MISSION_NAMES, -11 - button, DAT_ButtonX::instance + 30, + DAT_ButtonY::instance + 5, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 19, + FALSE); + } + DAT_ButtonUnknownZero::instance = FALSE; + } + + } +} +} diff --git a/src/OpenSHC/UI/MenuTextInputState/activateModalDialogAndClearText.cpp b/src/OpenSHC/UI/MenuTextInputState/activateModalDialogAndClearText.cpp new file mode 100644 index 0000000000..f1a1699148 --- /dev/null +++ b/src/OpenSHC/UI/MenuTextInputState/activateModalDialogAndClearText.cpp @@ -0,0 +1,40 @@ +#include "../MenuTextInputState.func.hpp" + +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/Text/TextArrayIndexType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" + +namespace OpenSHC { +namespace UI { + + // FUNCTION: STRONGHOLDCRUSADER 0x004916C0 + void MenuTextInputState::activateModalDialogAndClearText(MenuModalType dialogID) + { + if (this->currentModalDialog == OpenSHC::UI::Enums::MMT_NO_MENU) { + // Through the global, as the original (this->: quick_diff 1.0000 -> 0.9355) + DAT_MenuTextInputState::instance.DAT_SomeTextArrayIndex = DAT_UserTextHandlerState::instance.textArrayIndex; + DAT_UserTextHandlerState::instance.allowUserTextInput = 1; + if (DAT_UserTextHandlerState::instance.textArrayIndex != OpenSHC::Text::TAIT_ZERO) { + MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::clearTextAndCursor, DAT_UserTextHandlerState::ptr)(); + } + } + if (this->currentModalDialog != dialogID) { + // Push the current dialog onto the stack (written out per element: quick_diff 1.0000 -> 0.7742) + for (int i = countof(this->previousModalDialogs) - 1; i > 0; --i) { + this->previousModalDialogs[i] = this->previousModalDialogs[i - 1]; + } + this->previousModalDialogs[0] = this->currentModalDialog; + this->currentModalDialog = dialogID; + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(dialogID, TRUE); + } + } + +} +} diff --git a/src/OpenSHC/UI/MenuTextInputState/clearModalDialog2to6.cpp b/src/OpenSHC/UI/MenuTextInputState/clearModalDialog2to6.cpp index 6c4ae6b24c..7080d68333 100644 --- a/src/OpenSHC/UI/MenuTextInputState/clearModalDialog2to6.cpp +++ b/src/OpenSHC/UI/MenuTextInputState/clearModalDialog2to6.cpp @@ -1,4 +1,6 @@ -#include "OpenSHC/UI/MenuTextInputState.hpp" +#include "../MenuTextInputState.func.hpp" + +#include "OpenSHC/UI/Enums/MenuModalType.hpp" namespace OpenSHC { @@ -7,11 +9,9 @@ namespace UI { // FUNCTION: STRONGHOLDCRUSADER 0x00491730 void MenuTextInputState::clearModalDialog2to6() { - this->modalDialog_2 = 0; - this->modalDialog_3 = 0; - this->modalDialog_4 = 0; - this->modalDialog_5 = 0; - this->modalDialog_6 = 0; + for (int i = 0; i < countof(this->previousModalDialogs); ++i) { + this->previousModalDialogs[i] = OpenSHC::UI::Enums::MMT_NO_MENU; + } } } diff --git a/src/OpenSHC/UI/MenuTextInputState/popModalDialog.cpp b/src/OpenSHC/UI/MenuTextInputState/popModalDialog.cpp new file mode 100644 index 0000000000..c6a167304c --- /dev/null +++ b/src/OpenSHC/UI/MenuTextInputState/popModalDialog.cpp @@ -0,0 +1,43 @@ +#include "../MenuTextInputState.func.hpp" + +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/Text/TextArrayIndexType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" + +namespace OpenSHC { +namespace UI { + + // FUNCTION: STRONGHOLDCRUSADER 0x00493900 + void MenuTextInputState::popModalDialog() + { + MenuModalTypeInt const previousDialog = this->previousModalDialogs[0]; + // Pop the stack (written out per element: quick_diff 0.9394 -> 0.8788) + for (int i = 0; i < countof(this->previousModalDialogs) - 1; ++i) { + this->previousModalDialogs[i] = this->previousModalDialogs[i + 1]; + } + this->previousModalDialogs[countof(this->previousModalDialogs) - 1] = OpenSHC::UI::Enums::MMT_NO_MENU; + this->currentModalDialog = previousDialog; + // Guarded, not an early return (an early return for the empty stack: quick_diff 0.9394 -> 0.8788) + if (previousDialog != OpenSHC::UI::Enums::MMT_NO_MENU) { + if (previousDialog == OpenSHC::UI::Enums::MMT_SAVE_MAP) { + this->fileListVisibleRowCount = 16; + DAT_UserTextHandlerState::instance.allowUserTextInput = 0; + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)( + OpenSHC::Text::TAIT_TWO__FILTER_A); + MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::moveCursorToEnd, DAT_UserTextHandlerState::ptr)(); + DAT_UserTextHandlerState::instance.allowUserTextInput = 1; + } + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)((MenuModalType)previousDialog, TRUE); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, this)(); + } + } + +} +} diff --git a/src/OpenSHC/UI/MinimapViewState/convertMinimapClickToTileXY.cpp b/src/OpenSHC/UI/MinimapViewState/convertMinimapClickToTileXY.cpp new file mode 100644 index 0000000000..87caa224d4 --- /dev/null +++ b/src/OpenSHC/UI/MinimapViewState/convertMinimapClickToTileXY.cpp @@ -0,0 +1,48 @@ +#include "../MinimapViewState.func.hpp" + +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace UI { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B51A0 + void MinimapViewState::convertMinimapClickToTileXY(int* tileX, int* tileY) + { + // Guarded, not an early return (an early return when disabled: quick_diff 1.0000 -> 0.9000) + if (this->minimapClickEnabled) { + // Y and the offset up front (Y inline: quick_diff 1.0000 -> 0.7770; offset at first use: 0.6714) + int const mouseY = DAT_MouseState::instance.screenSpaceY - this->y; + int orientationOffset = 0; + // The original adds 6 here and takes it off again in the index below, so both stay. + *tileX = (((DAT_MouseState::instance.screenSpaceX - this->x) * this->oneOrTwo) / this->widthFactor + 6 + + this->tileOffsetX) + * 32; + int const screenY = ((this->oneOrTwo * mouseY) / this->heightFactor + this->tileOffsetY) * 8; + // The out parameters hold the screen point until the tile is known. + *tileY = screenY; + // Four tables, 80400 entries apart (computed from the orientation: quick_diff 1.0000 -> 0.5507) + if (DAT_TileMapState::instance.mapOrientation == 0) { + // Set again, as in renderPreviewAtMouseLocation (without this arm: quick_diff 1.0000 -> 0.8714) + orientationOffset = 0; + } else if (DAT_TileMapState::instance.mapOrientation == 6) { + orientationOffset = 80400; + } else if (DAT_TileMapState::instance.mapOrientation == 4) { + orientationOffset = 160800; + } else if (DAT_TileMapState::instance.mapOrientation == 2) { + orientationOffset = 241200; + } + int const tile = DAT_ViewportRenderState::instance + .screenPointToTileNumber[*tileX / 32 + screenY / 16 * 401 + orientationOffset - 6]; + int const row = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + *tileY = row; + *tileX = tile - DAT_ViewportRenderState::instance.translationMatrix[row].addXgetTile; + } else { + *tileX = -1; + *tileY = -1; + } + } + +} +} diff --git a/src/OpenSHC/UI/Rendering/RenderLoadAndSaveBar.cpp b/src/OpenSHC/UI/Rendering/RenderLoadAndSaveBar.cpp new file mode 100644 index 0000000000..62488b413c --- /dev/null +++ b/src/OpenSHC/UI/Rendering/RenderLoadAndSaveBar.cpp @@ -0,0 +1,70 @@ +#include "../Rendering.func.hpp" + +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/UI/Rendering/WindowAndDirectDraw.func.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/UI/Enums/BuildingsAndStatusMenuTabType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/COL_VERY_SOFT_YELLOW.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" +#include "OpenSHC/Globals/TIME_LoadSaveBar.hpp" + +namespace OpenSHC { +namespace UI { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00493690 + void Rendering::RenderLoadAndSaveBar(int progressValueUnk) + { + DWORD const currentTime = timeGetTime(); + // Redrawn every 30 ms at most + if ((int)(currentTime - TIME_LoadSaveBar::instance) <= 30) { + return; + } + TIME_LoadSaveBar::instance = currentTime; + // The progress is per mille: the bar is 300 pixels wide when full and 15 high + int const barWidth = (progressValueUnk * 300) / 1000; + if (MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::getAreWeInAInGameMenu, DAT_GameCore::ptr)()) { + DAT_TextManagerObject::instance.textSurfaceTarget = OpenSHC::Rendering::Enums::RT_MAP_GAME; + DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_MAP_GAME; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)( + DAT_MenuTextInputState::instance.progressBarX, DAT_MenuTextInputState::instance.progressBarY, + DAT_MenuTextInputState::instance.progressBarX + barWidth, + DAT_MenuTextInputState::instance.progressBarY + 15, COL_VERY_SOFT_YELLOW::instance.shortValue); + // One store of 1 for both paths (as an if/else with a store each: quick_diff 0.9459 -> 0.8742) + BOOLEnum const siegeTowerOrShieldTab + = DAT_GameCore::instance.activeMenuTab.tabType == OpenSHC::UI::Enums::BASMTT_SIEGETENT_SIEGETOWER + || DAT_GameCore::instance.activeMenuTab.tabType == OpenSHC::UI::Enums::BASMTT_SIEGETENT_SHIELD; + if (siegeTowerOrShieldTab) { + DAT_WindowAndDirectDraw::instance.pendingBltMode = 2; + } + if (!siegeTowerOrShieldTab + || DAT_GameCore::instance.currentMenuViewType == OpenSHC::UI::Enums::MVT_BUILDING_AND_STATUS_MENU) { + DAT_WindowAndDirectDraw::instance.pendingBltMode = 1; + } + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::WindowAndDirectDraw_Func::renderBltAndFlip, DAT_WindowAndDirectDraw::ptr)(1); + DAT_TextManagerObject::instance.textSurfaceTarget = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)( + DAT_MenuTextInputState::instance.progressBarX, DAT_MenuTextInputState::instance.progressBarY, + DAT_MenuTextInputState::instance.progressBarX + barWidth, + DAT_MenuTextInputState::instance.progressBarY + 15, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::WindowAndDirectDraw_Func::bltScreenMenuSurfaceToScreen, + DAT_WindowAndDirectDraw::ptr)(DAT_MenuTextInputState::instance.progressBarX, + DAT_MenuTextInputState::instance.progressBarY, DAT_MenuTextInputState::instance.progressBarX + 300, + DAT_MenuTextInputState::instance.progressBarY + 15); + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6e036f9340..a8a2f72fc0 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -6789,7 +6789,7 @@ SHC_3BB0A8C1_0x00426C50 | 0.0% | Pending SHC_3BB0A8C1_0x00426CA0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00426D30 | 0.0% | Pending +SHC_3BB0A8C1_0x00426D30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00426ED0 | 0.0% | Pending @@ -23405,7 +23405,7 @@ SHC_3BB0A8C1_0x004914D0 | 0.0% | Pending SHC_3BB0A8C1_0x00491680 | 0.0% | Pending -SHC_3BB0A8C1_0x004916C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004916C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00491730 | 100.0% | Reimplemented @@ -23625,7 +23625,7 @@ SHC_3BB0A8C1_0x004934F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00493560 | 0.0% | Pending -SHC_3BB0A8C1_0x00493690 | 0.0% | Pending +SHC_3BB0A8C1_0x00493690 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004937A4 | 0.0% | Pending @@ -23645,7 +23645,7 @@ SHC_3BB0A8C1_0x004938F8 | 0.0% | Pending SHC_3BB0A8C1_0x004938FC | 0.0% | Pending -SHC_3BB0A8C1_0x00493900 | 0.0% | Pending +SHC_3BB0A8C1_0x00493900 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00493980 | 100.0% | Reimplemented @@ -26877,7 +26877,7 @@ SHC_3BB0A8C1_0x004B5100 | 0.0% | Pending SHC_3BB0A8C1_0x004B5110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B51A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004B51A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B5280 | 100.0% | Reimplemented