diff --git a/src/OpenSHC/UI/BottomLeftTextDisplayState/setBottomLeftTextDisplayText.cpp b/src/OpenSHC/UI/BottomLeftTextDisplayState/setBottomLeftTextDisplayText.cpp new file mode 100644 index 0000000000..da9dc92ec4 --- /dev/null +++ b/src/OpenSHC/UI/BottomLeftTextDisplayState/setBottomLeftTextDisplayText.cpp @@ -0,0 +1,78 @@ +#include "../BottomLeftTextDisplayState.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Map/Buildings/BuildingFailReasonEnum.hpp" +#include "OpenSHC/UI/Enums/TextMessageBLLookupStructTypeEnum.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_RenderingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" + +namespace OpenSHC { +namespace UI { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F4E00 + void BottomLeftTextDisplayState::setBottomLeftTextDisplayText(int messageTypeUnk, int textGroupIndex, + int textNumInGroup, int associatedTypeUnk, int importanceUnk, int displayDurationUnk) + { + if (messageTypeUnk == 0) { + this->currentlyDisplayedTextIsDisplayedUnk = 0; + return; + } + if (this->currentlyDisplayedTextIsDisplayedUnk != 0) { + // a less important text doesn't replace the one shown + if (importanceUnk < this->currentlyDisplayedTextImportanceUnk) { + return; + } + if (textGroupIndex != this->currentlyDisplayedUnkTextGroupIndex_0x4 + || textNumInGroup != this->currentlyDisplayedUnkTextNumInGroup_0x8 + || associatedTypeUnk != this->currentlyDisplayedUnktextExtraObject.buildingType) { + this->countdown = 0; + } + } else { + this->countdown = 0; + } + this->currentlyDisplayedTextIsDisplayedUnk = messageTypeUnk; + if (textGroupIndex == -1) { + // the text is looked up by the type of message and the object it is about + // the index is declared before messageType: in the for it loses the match + int i = 0; + TextMessageBLLookupStructTypeEnumInt messageType = OpenSHC::UI::Enums::TMBLLSTE_UNKNOWN_0; + if (messageTypeUnk == 2) { + messageType = OpenSHC::UI::Enums::TMBLLSTE_BUILDING_TEXT; + } + for (; DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].messageType != -1; ++i) { + if (messageType == DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].messageType + && associatedTypeUnk + == DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].associatedType.buildingType) { + this->currentlyDisplayedUnkTextGroupIndex_0x4 + = DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].textGroupIndex; + this->currentlyDisplayedUnkTextNumInGroup_0x8 + = DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].textIndexInGroup; + break; + } + } + } else { + this->currentlyDisplayedUnkTextGroupIndex_0x4 = textGroupIndex; + this->currentlyDisplayedUnkTextNumInGroup_0x8 = textNumInGroup; + // "Not enough workers available to run this building." + if (messageTypeUnk == 1 && textGroupIndex == OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK + && textNumInGroup == OpenSHC::Map::Buildings::BFRE_NOT_ENOUGH_WORKERS) { + // "placement_warning1.wav" + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_placement_warning1_wav_005ab8f4); + } + } + this->currentlyDisplayedUnktextExtraObject.buildingType = (MappersEnum)associatedTypeUnk; + this->currentlyDisplayedTextImportanceUnk = importanceUnk; + if (displayDurationUnk != -1) { + this->textMessageDurationUnk = displayDurationUnk; + this->textMessageTime = timeGetTime(); + } else { + this->textMessageDurationUnk = 0; + } + } + +} +} diff --git a/src/OpenSHC/UI/Menu/Constructor_Menu.cpp b/src/OpenSHC/UI/Menu/Constructor_Menu.cpp new file mode 100644 index 0000000000..ea0a1b248f --- /dev/null +++ b/src/OpenSHC/UI/Menu/Constructor_Menu.cpp @@ -0,0 +1,93 @@ +#include "../Menu.func.hpp" + +#include "OpenSHC/UI/Enums/MenuItemType.hpp" +#include "OpenSHC/UI/Enums/MenuItemUCMarker.hpp" + +namespace OpenSHC { +namespace UI { + + using namespace OpenSHC::UI::Enums; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F4100 + Menu* Menu::Constructor_Menu(MenuItem* menuItemArrayAddress) + { + // item types and flags without a name yet, as in handleMenuItems + int const optionGroupFlag = 1 << 29; + int const optionType = MIT_START_OF_INTERACTION_GROUPUnk | 1 << 28; + int const alternativeFlag = 1 << 26; + int const alternativesFlag = 1 << 27; + this->menuItemArray = menuItemArrayAddress; + this->xPosition = 0; + this->yPosition = 0; + this->thousand = 1000; + this->zero = 0; + this->someTimestampUnk = 0; + this->mouseXScreenSpace = -1000; + for (MenuItem* item = menuItemArrayAddress; item->menuItemType != MIT_LAST_ENTRY; ++item) { + item->menuPointer = this; + if (item->position.ucInfo.ucMarker_0x0 == USE_UC_COORDS) { + item->ucID = item->position.ucInfo.ucIndex_0x4; + } else { + item->ucID = -1; + } + item->unknownZero = 0; + if (item->menuItemType == MIT_TAB_CONSIDER_ITEM_SKIP_BECAUSE_OTHER_MENU_TAB) { + // a tab's items reach up to the next tab, the end, or past a stop item + int count = 0; + MenuItem* next; + for (next = item + 1; next->menuItemType != MIT_LAST_ENTRY + && next->menuItemType != MIT_TAB_CONSIDER_ITEM_SKIP_BECAUSE_OTHER_MENU_TAB + && next->menuItemType != MIT_STOP_HANDLING; + ++next) { + ++count; + } + if (next->menuItemType == MIT_STOP_HANDLING) { + ++count; + } + item->firstItemTypeData.itemsToSkip = count; + } else if (item->menuItemType == MIT_START_OF_INTERACTION_GROUPUnk) { + // the group's members take the group's callbacks where they have none + MenuItemActionHandlerUnion actionHandler = item->menuItemActionHandler; + MenuItemRenderFunctionUnion renderFunction = item->menuItemRenderFunction; + MenuItem* member = item + 1; + int count = 0; + for (; member->menuItemType & MIT_PART_OF_INTERACTION_GROUPUnk; ++member) { + if (member->menuItemActionHandler.simple == NULL) { + member->menuItemActionHandler = actionHandler; + } + if (member->menuItemRenderFunction.simple == NULL) { + member->menuItemRenderFunction = renderFunction; + } + ++count; + } + item->firstItemTypeData.itemsToSkip = count; + // options follow, each with members of its own (a for: quick_diff 0.8787 -> 0.6025) + while (member->menuItemType == optionType) { + item->menuItemType |= optionGroupFlag; + actionHandler = member->menuItemActionHandler; + renderFunction = member->menuItemRenderFunction; + MenuItem* const option = member; + count = 0; + for (++member; member->menuItemType & MIT_PART_OF_INTERACTION_GROUPUnk; ++member) { + if (member->menuItemActionHandler.simple == NULL) { + member->menuItemActionHandler = actionHandler; + } + if (member->menuItemRenderFunction.simple == NULL) { + member->menuItemRenderFunction = renderFunction; + } + ++count; + } + option->firstItemTypeData.itemsToSkip = count; + } + } else if (item->menuItemType & alternativeFlag) { + // the item before a run of alternatives is marked as its head + MenuItem* head; + for (head = item; head->menuItemType & alternativeFlag && head != menuItemArrayAddress; --head) {} + head->menuItemType |= alternativesFlag; + } + } + return this; + } + +} +} diff --git a/src/OpenSHC/UI/Menu/handleMenuItems.cpp b/src/OpenSHC/UI/Menu/handleMenuItems.cpp new file mode 100644 index 0000000000..31c44f858c --- /dev/null +++ b/src/OpenSHC/UI/Menu/handleMenuItems.cpp @@ -0,0 +1,107 @@ +#include "../Menu.func.hpp" + +#include "OpenSHC/UI/MenuItem.func.hpp" +#include "OpenSHC/UI/Enums/MenuItemType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MenuHandlerState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" + +namespace OpenSHC { +namespace UI { + + using namespace OpenSHC::UI::Enums; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F6280 + void Menu::handleMenuItems(MenuItemHandleState funcIndex) + { + // item types without a name yet: two kinds of option group, and flags in the high bits + int const optionGroupType = MIT_START_OF_INTERACTION_GROUPUnk | 1 << 29; + int const optionType = MIT_START_OF_INTERACTION_GROUPUnk | 1 << 28; + int const clickHandlerType = 7; + int const alternativeFlag = 1 << 26; + int const alternativesFlag = 1 << 27; + int const renderSeparatelyFlag = 1 << 23; + int const hiddenFlag = 1 << 31; + this->currentBuildMenuButtonShiftUnk_0x14 = 0; + for (MenuItem* item = this->menuItemArray; item->menuItemType != MIT_LAST_ENTRY; ++item) { + MenuItemTypeInt const type = item->menuItemType; + if (type == MIT_TAB_CONSIDER_ITEM_SKIP_BECAUSE_OTHER_MENU_TAB) { + if (item->callbackParameter.activeMenuTab.tabType != DAT_GameCore::instance.activeMenuTab.tabType + && funcIndex != MIHS_RESET_MENU_ITEM_STATEUnk) { + item += item->firstItemTypeData.itemsToSkip; + } + } else if (type == MIT_TAB_CONSIDER_STOP_BECAUSE_IS_CURRENT_MENU_TAB) { + if (item->callbackParameter.activeMenuTab.tabType == DAT_GameCore::instance.activeMenuTab.tabType + && funcIndex != MIHS_RESET_MENU_ITEM_STATEUnk) { + return; + } + } else if (type == MIT_STOP_HANDLING) { + return; + } else if (type == MIT_ENABLE_OR_WRAP_BUILD_MENU_TRANSITION_OFFSET) { + if (DAT_MenuHandlerState::instance.isBuildMenuTransitioning_0x18 + && funcIndex == MIHS_HANDLE_INPUT_CALLBACKSUnk) { + return; + } + if (this->currentBuildMenuButtonShiftUnk_0x14 != 0) { + this->currentBuildMenuButtonShiftUnk_0x14 = 0; + } else { + this->currentBuildMenuButtonShiftUnk_0x14 + = DAT_MenuHandlerState::instance.buildMenuItemsLeftShift_0x28; + } + } else if (type == MIT_MENU_MODALUnk) { + if (DAT_MenuModalComposition1::instance.activeModalDialogID != MMT_NONE) { + return; + } + } else if (type == optionGroupType) { + for (MenuItem* option = item + item->firstItemTypeData.itemsToSkip + 1; + option->menuItemType == optionType; option += option->firstItemTypeData.itemsToSkip + 1) { + if (option->testNotEqualZero == DAT_GameCore::instance.unknownAlwaysZero01) { + item = option; + break; + } + } + } else if (type == optionType) { + item += item->firstItemTypeData.itemsToSkip; + } else if (type == clickHandlerType) { + DAT_GameCore::instance.menuType7_MenuItemClickHandlerUnk = item->menuItemActionHandler.simple; + } else if (type != MIT_START_OF_INTERACTION_GROUPUnk && (type & alternativeFlag) == 0) { + if (type & alternativesFlag) { + for (MenuItem* alternative = item + 1; alternative->menuItemType & alternativeFlag; ++alternative) { + if (alternative->testNotEqualZero == DAT_GameCore::instance.unknownAlwaysZero01) { + item = alternative; + break; + } + } + } + // the sign bit is tested with &, not as >= 0, as the original does + if (item->menuItemType & hiddenFlag) { + continue; + } + if (!(((item->menuItemType & renderSeparatelyFlag) != 0 + && funcIndex == MIHS_PREPARE_AND_RENDER_FOR_FLAG_0X800000) + || ((item->menuItemType & renderSeparatelyFlag) == 0 && funcIndex == MIHS_PREPARE_AND_RENDER) + || funcIndex == MIHS_HANDLE_INPUT_CALLBACKSUnk || funcIndex == MIHS_RESET_MENU_ITEM_STATEUnk)) { + continue; + } + switch (funcIndex) { + case MIHS_HANDLE_INPUT_CALLBACKSUnk: + if (MACRO_CALL_MEMBER(OpenSHC::UI::MenuItem_Func::handleMenuElementsCallbacks, item)()) { + return; + } + break; + case MIHS_PREPARE_AND_RENDER: + case MIHS_PREPARE_AND_RENDER_FOR_FLAG_0X800000: + MACRO_CALL_MEMBER(OpenSHC::UI::MenuItem_Func::prepareAndRenderMenuItems, item)(); + break; + case MIHS_RESET_MENU_ITEM_STATEUnk: + MACRO_CALL_MEMBER(OpenSHC::UI::MenuItem_Func::resetMenuItemStateUnk, item)(); + break; + } + } + } + } + +} +} diff --git a/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp b/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp new file mode 100644 index 0000000000..8189dab411 --- /dev/null +++ b/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp @@ -0,0 +1,270 @@ +#include "../Menu.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/BuildingsAndStatusMenuTabType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" + +#include "OpenSHC/Globals/COL_GREYISH_YELLOW.hpp" +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_RenderingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + + using namespace OpenSHC::UI::Enums; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F64A0 + void Menu::renderConstructionMenu() + { + DWORD const now = timeGetTime(); + MenuItem* const item = this->hoveredItem; + // the text's index is the low word of textMessageLookupIndex, read as a dword and masked, as the original does + int const indexMask = 0xffff; + if (item != NULL && (*(int*)&item->textMessageLookupIndex & indexMask) != 0) { + // in the building menus, only these tabs show texts + if (DAT_GameCore::instance.currentMenuViewType != MVT_BUILDING_AND_STATUS_MENU + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_BARRACKS_OR_MPMENU_MODEM + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_MERCENARYPOST + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_TOWER + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_GATEHOUSE + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_ENGINEERSGUILD + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_TUNNELERSGUILD + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_CATHEDRAL) { + int const index = *(int*)&item->textMessageLookupIndex & indexMask; + // each case stores and returns on its own: a shared store after a break loses the match + switch (DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].messageType) { + case TMBLLSTE_UNKNOWN_0: + return; + case TMBLLSTE_BUTTON_TEXT: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].associatedType.buttonText, + 50, -1); + } + this->zero = 0; + return; + case TMBLLSTE_UNKNOWN_13: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(13, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case TMBLLSTE_UNKNOWN_7: + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(7, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].associatedType.buildingType, + 50, -1); + this->zero = 0; + return; + case TMBLLSTE_BUILDING_TEXT: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(2, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case TMBLLSTE_WALL_TEXT: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(4, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case TMBLLSTE_UNKNOWN_9: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(9, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case TMBLLSTE_POPULARITY_HELP_TEXT: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(3, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case TMBLLSTE_UNITS_AND_WEAPONS_TEXT: + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(6, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.unitsAndWeaponsType, + 50, -1); + this->zero = 0; + return; + case TMBLLSTE_UNKNOWN_12: + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(12, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].associatedType.buildingType, + 50, -1); + this->zero = 0; + return; + case TMBLLSTE_UNKNOWN_8: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(8, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case TMBLLSTE_UNKNOWN_10: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(10, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case TMBLLSTE_UNKNOWN_11: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(11, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + default: + // the tooltip, once the mouse has rested on the item for 200 ms + if (DAT_MouseState::instance.leftClickState || DAT_MouseState::instance.rightClickState + || DAT_MouseState::instance.midClickState || !DAT_GameCore::instance.settingBubbleHelp) { + break; + } + if (this->zero == 0) { + this->zero = 1; + this->someTimestampUnk = now; + this->mouseXScreenSpace = DAT_MouseState::instance.screenSpaceX; + this->mouseYScreenSpace = DAT_MouseState::instance.screenSpaceY; + return; + } + if (this->zero == 1 && DAT_MouseState::instance.screenSpaceX == this->mouseXScreenSpace + && DAT_MouseState::instance.screenSpaceY == this->mouseYScreenSpace) { + if ((int)(now - this->someTimestampUnk) <= 200) { + return; + } + this->zero = 2; + // masked again here, as the original does (reusing index: quick_diff 0.9559 -> 0.8883) + this->textIndexInGroup + = DAT_RenderingDefinedData::instance + .TextMessageLookupTable[(*(int*)&item->textMessageLookupIndex & indexMask)] + .textIndexInGroup; + this->textGroupIndex + = DAT_RenderingDefinedData::instance + .TextMessageLookupTable[(*(int*)&item->textMessageLookupIndex & indexMask)] + .textGroupIndex; + // "Resume Game" while the game is paused + if (this->textIndexInGroup == 302 + && this->textGroupIndex == OpenSHC::DE::SHCDE::TEXT_BUBBLE_HELP_TEXT + && DAT_GameCore::instance.gameSuspended == 1) { + this->textGroupIndex = OpenSHC::DE::SHCDE::TEXT_GAME_OPTIONS; + this->textIndexInGroup = 10; + } + this->someMenuItemPtr_0x3c = item; + return; + } + if (this->zero == 2 && this->someMenuItemPtr_0x3c == item) { + char* const text = MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)( + (OpenSHC::DE::SHCDE::eTextSections)this->textGroupIndex, this->textIndexInGroup); + int const width = MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::computeTextWidth, DAT_TextManagerObject::ptr)(text, 17); + // hoverTextX in both branches (one store before the test: quick_diff 0.9559 -> 0.9046) + if (DAT_GameCore::instance.currentMenuViewType != MVT_MISSION_FINISHED_TRANSITION + && DAT_GameCore::instance.currentMenuViewType != MVT_GAME_LOSTUnk) { + this->hoverTextX = DAT_MouseState::instance.screenSpaceX - width / 2 + 8; + this->hoverTextY = DAT_MouseState::instance.screenSpaceY - 68; + } else { + this->hoverTextX = DAT_MouseState::instance.screenSpaceX - width / 2 + 8; + this->hoverTextY = DAT_MouseState::instance.screenSpaceY + 16; + } + if (this->hoverTextY + 23 > DAT_WindowAndDirectDraw::instance.resolutionY) { + this->hoverTextY = DAT_MouseState::instance.screenSpaceY - 23; + } + if (this->hoverTextX + width + 20 > DAT_WindowAndDirectDraw::instance.resolutionX) { + this->hoverTextX = DAT_WindowAndDirectDraw::instance.resolutionX - width - 20; + } + if (this->hoverTextX < 0) { + this->hoverTextX = 0; + } + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::dimBox, DAT_PencilRenderCore::ptr)( + this->hoverTextX, this->hoverTextY, this->hoverTextX + width + 18, this->hoverTextY + 26); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBorderBox, + DAT_PencilRenderCore::ptr)(this->hoverTextX - 1, this->hoverTextY - 1, + this->hoverTextX + width + 19, this->hoverTextY + 27, + COL_GREYISH_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, + DAT_TextManagerObject::ptr)(text, this->hoverTextX + 11, this->hoverTextY + 3, + OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 17, FALSE, 0); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + break; + } + } + } + this->zero = 0; + } + +} +} diff --git a/src/OpenSHC/UI/MenuItem/prepareAndRenderMenuItems.cpp b/src/OpenSHC/UI/MenuItem/prepareAndRenderMenuItems.cpp new file mode 100644 index 0000000000..860b016332 --- /dev/null +++ b/src/OpenSHC/UI/MenuItem/prepareAndRenderMenuItems.cpp @@ -0,0 +1,137 @@ +#include "../MenuItem.func.hpp" + +#include "OpenSHC/UI/Enums/MenuItemRenderFunctionType.hpp" +#include "OpenSHC/UI/Enums/MenuItemType.hpp" + +#include "OpenSHC/Globals/DAT_ButtonBlendStrength.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonH.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_CurrentButtonGmDataIndex.hpp" +#include "OpenSHC/Globals/DAT_CurrentButtonPictureInGm.hpp" +#include "OpenSHC/Globals/DAT_GMImageHeaders.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MenuHandlerState.hpp" +#include "OpenSHC/Globals/DAT_UIButtonDefinedData.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace UI { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F49D0 + void MenuItem::prepareAndRenderMenuItems() + { + if (this->iconDeactivatedUnk_0x36 != 0) { + return; + } + if (this->menuItemRenderFunctionType == OpenSHC::UI::Enums::MIRFT_GM_DATA_IMAGE) { + int const image = GMFirstPictureIndex::instance[DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[this->firstItemTypeData.gmDataIndex] + .gmId_0x0] + + DAT_UIButtonDefinedData::instance.ButtonGmDataArray[this->firstItemTypeData.gmDataIndex] + .pictureInGm_0x4 + - 1; + this->itemWidth = DAT_GMImageHeaders::instance.imh[image].width; + this->itemHeight = DAT_GMImageHeaders::instance.imh[image].height; + } + DAT_ButtonX::instance = this->menuPointer->xPosition - this->menuPointer->currentBuildMenuButtonShiftUnk_0x14 + + this->position.position.x; + DAT_ButtonY::instance = this->menuPointer->yPosition + this->position.position.y; + DAT_ButtonW::instance = this->itemWidth; + DAT_ButtonH::instance = this->itemHeight; + // the low 23 bits are the index (the same mask as MIT_MENU_ITEM_TYPE_ID_PARTUnk) + int const gmDataIndexMask = 0x7fffff; + DAT_CurrentButtonGmDataIndex::instance = this->firstItemTypeData.gmDataIndex & gmDataIndexMask; + DAT_ButtonCurrentlyInteracting::instance = this->clicked | this->hovering; + DAT_ButtonBlendStrength::instance = 0; + DAT_ButtonUnknownZero::instance = this->unknownZero; + if (DAT_GameCore::instance.hasMenuRenderedUnk) { + DAT_ButtonCurrentlyInteracting::instance = FALSE; + } + int const shift = this->menuPointer->currentBuildMenuButtonShiftUnk_0x14; + if (shift != 0) { + // while the build menu slides, items outside its area aren't drawn, and none are around the halfway point + if (this->position.position.x - shift < (int)DAT_MenuHandlerState::instance.const017) { + return; + } + if (this->position.position.x - shift + this->itemWidth > (int)DAT_MenuHandlerState::instance.const516) { + return; + } + int const progress = DAT_MenuHandlerState::instance.buildMenuTransitionProgress_0x38; + if (progress > 45 && progress < 55) { + return; + } + if (progress < 50) { + DAT_ButtonBlendStrength::instance = progress * 32 / 45; + } else { + DAT_ButtonBlendStrength::instance = (100 - progress) * 32 / 45; + } + } + if (this->menuItemRenderFunctionType == OpenSHC::UI::Enums::MIRFT_SLIDER_OR_SCROLLBAR) { + if (this->menuPointer->one) { + // 1: set-up: range and position + (*this->menuItemActionHandler.slider)(this->callbackParameter.parameter, 1, + &this->secondItemTypeData.scrollbarOrSliderState.minValue, + &this->secondItemTypeData.scrollbarOrSliderState.maxValue, + &this->secondItemTypeData.scrollbarOrSliderState.currentValue); + this->secondItemTypeData.scrollbarOrSliderState.dragTiming = -1000; + if (this->secondItemTypeData.scrollbarOrSliderState.currentValue + < this->secondItemTypeData.scrollbarOrSliderState.minValue) { + this->secondItemTypeData.scrollbarOrSliderState.currentValue + = this->secondItemTypeData.scrollbarOrSliderState.minValue; + } + if (this->secondItemTypeData.scrollbarOrSliderState.currentValue + > this->secondItemTypeData.scrollbarOrSliderState.maxValue) { + this->secondItemTypeData.scrollbarOrSliderState.currentValue + = this->secondItemTypeData.scrollbarOrSliderState.maxValue; + } + } + // declared here, before thumbPos and thumbLength: at its first use it loses the match + BOOLEnum isDragged = FALSE; + int thumbPos = 0; + int length = this->itemWidth; + if ((this->menuItemType & OpenSHC::UI::Enums::MIT_MENU_ITEM_TYPE_ID_PARTUnk) + == OpenSHC::UI::Enums::MIT_SCROLLBARUnk) { + length = this->itemHeight; + } + int thumbLength = length; + // the range is written out at each use: a local loses the match + if ((this->secondItemTypeData.scrollbarOrSliderState.maxValue + - this->secondItemTypeData.scrollbarOrSliderState.minValue) + > 0) { + thumbLength = length + / ((this->secondItemTypeData.scrollbarOrSliderState.maxValue + - this->secondItemTypeData.scrollbarOrSliderState.minValue) + + 1); + if (thumbLength <= this->firstItemTypeData.itemsToSkip) { + thumbLength = this->firstItemTypeData.itemsToSkip; + } + thumbPos = (this->secondItemTypeData.scrollbarOrSliderState.currentValue + - this->secondItemTypeData.scrollbarOrSliderState.minValue) + * (length - thumbLength) + / (this->secondItemTypeData.scrollbarOrSliderState.maxValue + - this->secondItemTypeData.scrollbarOrSliderState.minValue); + } + if (this->secondItemTypeData.scrollbarOrSliderState.dragTiming > -1000) { + isDragged = TRUE; + } + (*this->menuItemRenderFunction.slider)(this->callbackParameter.parameter, thumbPos, + this->secondItemTypeData.scrollbarOrSliderState.currentValue, thumbLength, isDragged); + } else if (this->menuItemRenderFunctionType == OpenSHC::UI::Enums::MIRFT_SIMPLE_RENDERUnk) { + (*this->menuItemRenderFunction.simple)(this->callbackParameter.parameter); + } else if (this->menuItemRenderFunctionType == OpenSHC::UI::Enums::MIRFT_GM_DATA_IMAGE) { + (*this->menuItemRenderFunction.gmDataImage)(this->callbackParameter.parameter); + this->secondItemTypeData.buttonState.currentButtonPictureInGm_0xc = DAT_CurrentButtonPictureInGm::instance; + } + if (this->menuPointer->hoveredItem == this + && DAT_ButtonCurrentlyInteracting::instance != (this->clicked | this->hovering)) { + this->menuPointer->zero = 0; + } + this->unknownZero = DAT_ButtonUnknownZero::instance; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index ed989c9a21..08fd667a1d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38621,7 +38621,7 @@ SHC_3BB0A8C1_0x004F4050 | 0.0% | Pending SHC_3BB0A8C1_0x004F4070 | 0.0% | Pending -SHC_3BB0A8C1_0x004F4100 | 0.0% | Pending +SHC_3BB0A8C1_0x004F4100 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F4140 | 0.0% | Pending @@ -38631,7 +38631,7 @@ SHC_3BB0A8C1_0x004F4270 | 0.0% | Pending SHC_3BB0A8C1_0x004F4290 | 0.0% | Pending -SHC_3BB0A8C1_0x004F49D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F49D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F4C30 | 100.0% | Reimplemented @@ -38643,7 +38643,7 @@ SHC_3BB0A8C1_0x004F4CD0 | 0.0% | Pending SHC_3BB0A8C1_0x004F4D70 | 0.0% | Pending -SHC_3BB0A8C1_0x004F4E00 | 0.0% | Pending +SHC_3BB0A8C1_0x004F4E00 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F4EF0 | 0.0% | Pending @@ -38685,7 +38685,7 @@ SHC_3BB0A8C1_0x004F6200 | 0.0% | Pending SHC_3BB0A8C1_0x004F6210 | 0.0% | Pending -SHC_3BB0A8C1_0x004F6280 | 0.0% | Pending +SHC_3BB0A8C1_0x004F6280 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F641D | 0.0% | Pending @@ -38699,7 +38699,7 @@ SHC_3BB0A8C1_0x004F6464 | 0.0% | Pending SHC_3BB0A8C1_0x004F6470 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F64A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F64A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F6998 | 0.0% | Pending