1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-22 22:34:33 +01:00

Staff window: make tab animation lengths dynamic

This commit is contained in:
Aaron van Geffen
2024-12-09 22:43:45 +01:00
parent 44a9f530f7
commit f3a0593591
2 changed files with 50 additions and 34 deletions

View File

@@ -635,16 +635,12 @@ namespace OpenRCT2::Ui::Windows
auto& objManager = GetContext()->GetObjectManager();
auto* animObj = objManager.GetLoadedObject<PeepAnimationsObject>(staff->AnimationObjectIndex);
int32_t imageIndex = animObj->GetPeepAnimation(staff->AnimationGroup).base_image + 1;
int32_t offset = 0;
const auto& anim = animObj->GetPeepAnimation(staff->AnimationGroup);
int32_t animFrame = 0;
if (page == WINDOW_STAFF_OVERVIEW)
{
offset = _tabAnimationOffset;
offset = floor2(offset, 4);
}
imageIndex += offset;
animFrame = _tabAnimationOffset / 4;
auto imageIndex = anim.base_image + 1 + anim.frame_offsets[animFrame] * 4;
GfxDrawSprite(clip_dpi, ImageId(imageIndex, staff->TshirtColour, staff->TrousersColour), screenCoords);
}
@@ -694,12 +690,25 @@ namespace OpenRCT2::Ui::Windows
void OverviewUpdate()
{
_tabAnimationOffset++;
_tabAnimationOffset %= 24;
auto* staff = GetStaff();
auto& objManager = GetContext()->GetObjectManager();
auto* animObj = objManager.GetLoadedObject<PeepAnimationsObject>(staff->AnimationObjectIndex);
// Update pickup animation, can only happen in this tab.
// Get walking animation length
const auto& walkingAnim = animObj->GetPeepAnimation(staff->AnimationGroup, PeepAnimationType::Walking);
const auto walkingAnimLength = walkingAnim.frame_offsets.size();
// Overview tab animation offset
_tabAnimationOffset++;
_tabAnimationOffset %= walkingAnimLength * 4;
// Get pickup animation length
const auto& pickAnim = animObj->GetPeepAnimation(staff->AnimationGroup, PeepAnimationType::Hanging);
const auto pickAnimLength = pickAnim.frame_offsets.size();
// Update pickup animation frame
picked_peep_frame++;
picked_peep_frame %= 48;
picked_peep_frame %= pickAnimLength * 4;
InvalidateWidget(WIDX_TAB_1);
}
@@ -741,8 +750,8 @@ namespace OpenRCT2::Ui::Windows
auto& objManager = GetContext()->GetObjectManager();
auto* animObj = objManager.GetLoadedObject<PeepAnimationsObject>(staff->AnimationObjectIndex);
auto baseImageId = animObj->GetPeepAnimation(staff->AnimationGroup, PeepAnimationType::Hanging).base_image;
baseImageId += picked_peep_frame >> 2;
auto& pickupAnim = animObj->GetPeepAnimation(staff->AnimationGroup, PeepAnimationType::Hanging);
auto baseImageId = pickupAnim.base_image + pickupAnim.frame_offsets[picked_peep_frame >> 2];
gPickupPeepImage = ImageId(baseImageId, staff->TshirtColour, staff->TrousersColour);
}

View File

@@ -189,26 +189,29 @@ namespace OpenRCT2::Ui::Windows
void OnUpdate() override
{
_tabAnimationIndex++;
if (_tabAnimationIndex >= 24)
auto animPeepType = AnimationPeepType(static_cast<uint8_t>(_selectedTab) + 1);
auto* animObj = findPeepAnimationsObjectForType(animPeepType);
if (animObj != nullptr)
{
_tabAnimationIndex = 0;
}
else
{
InvalidateWidget(WIDX_STAFF_LIST_HANDYMEN_TAB + _selectedTab);
auto& anim = animObj->GetPeepAnimation(PeepAnimationGroup::Normal);
_tabAnimationIndex++;
// Enable highlighting of these staff members in map window
auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager();
if (windowMgr->FindByClass(WindowClass::Map) != nullptr)
if (_tabAnimationIndex >= anim.frame_offsets.size() * 4)
_tabAnimationIndex = 0;
InvalidateWidget(WIDX_STAFF_LIST_HANDYMEN_TAB + _selectedTab);
}
// Enable highlighting of these staff members in map window
auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager();
if (windowMgr->FindByClass(WindowClass::Map) != nullptr)
{
for (auto peep : EntityList<Staff>())
{
for (auto peep : EntityList<Staff>())
EntitySetFlashing(peep, false);
if (peep->AssignedStaffType == GetSelectedStaffType())
{
EntitySetFlashing(peep, false);
if (peep->AssignedStaffType == GetSelectedStaffType())
{
EntitySetFlashing(peep, true);
}
EntitySetFlashing(peep, true);
}
}
}
@@ -624,8 +627,10 @@ namespace OpenRCT2::Ui::Windows
auto widgetIndex = WIDX_STAFF_LIST_HANDYMEN_TAB + tabIndex;
const auto& widget = widgets[widgetIndex];
auto imageId = (_selectedTab == tabIndex ? (_tabAnimationIndex & ~3) : 0);
imageId += animObj->GetPeepAnimation(PeepAnimationGroup::Normal).base_image + 1;
auto frame = _selectedTab == tabIndex ? _tabAnimationIndex / 4 : 0;
auto& anim = animObj->GetPeepAnimation(PeepAnimationGroup::Normal);
auto imageId = anim.base_image + 1 + anim.frame_offsets[frame] * 4;
GfxDrawSprite(
dpi, ImageId(imageId, colour),
windowPos + ScreenCoordsXY{ (widget.left + widget.right) / 2, widget.bottom - 6 });
@@ -645,8 +650,10 @@ namespace OpenRCT2::Ui::Windows
clippedDpi, dpi, windowPos + ScreenCoordsXY{ widget.left + 1, widget.top + 1 },
widget.right - widget.left - 1, widget.bottom - widget.top - 1))
{
auto imageId = (_selectedTab == 3 ? (_tabAnimationIndex & ~3) : 0);
imageId += animObj->GetPeepAnimation(PeepAnimationGroup::Normal).base_image + 1;
auto frame = _selectedTab == tabIndex ? _tabAnimationIndex / 4 : 0;
auto& anim = animObj->GetPeepAnimation(PeepAnimationGroup::Normal);
auto imageId = anim.base_image + 1 + anim.frame_offsets[frame] * 4;
GfxDrawSprite(clippedDpi, ImageId(imageId), { 15, 23 });
}
}