Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
}
93 changes: 93 additions & 0 deletions src/OpenSHC/UI/Menu/Constructor_Menu.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

}
}
107 changes: 107 additions & 0 deletions src/OpenSHC/UI/Menu/handleMenuItems.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}

}
}
Loading
Loading