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
3 changes: 3 additions & 0 deletions cmake/compiler-flags-gl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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);
}

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

}
}
}
Loading
Loading