2016-05-04 19:24:41 +02:00
/*****************************************************************************
2024-12-31 20:30:04 +01:00
* Copyright (c) 2014-2025 OpenRCT2 developers
2016-05-04 19:24:41 +02:00
*
2018-06-15 14:07:34 +02:00
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
2016-05-04 19:24:41 +02:00
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
2016-05-04 19:24:41 +02:00
*****************************************************************************/
2014-10-07 19:39:52 +01:00
2017-10-16 00:13:22 +02:00
#include <limits>
2024-08-14 16:36:05 +02:00
#include <openrct2-ui/UiContext.h>
#include <openrct2-ui/input/InputManager.h>
2018-06-22 23:21:44 +02:00
#include <openrct2-ui/interface/Dropdown.h>
2018-01-03 00:13:37 +01:00
#include <openrct2-ui/interface/Viewport.h>
2024-08-14 16:36:05 +02:00
#include <openrct2-ui/interface/ViewportQuery.h>
2018-01-03 00:13:37 +01:00
#include <openrct2-ui/interface/Widget.h>
2025-01-19 15:50:54 +01:00
#include <openrct2-ui/windows/Windows.h>
2018-06-22 23:21:44 +02:00
#include <openrct2/Context.h>
#include <openrct2/Game.h>
2024-01-22 16:03:39 +01:00
#include <openrct2/GameState.h>
2018-06-22 23:21:44 +02:00
#include <openrct2/Input.h>
2025-02-13 10:51:46 -05:00
#include <openrct2/SpriteIds.h>
2023-01-27 03:20:59 -05:00
#include <openrct2/actions/PeepPickupAction.h>
2020-12-09 23:39:10 -07:00
#include <openrct2/actions/StaffFireAction.h>
2021-12-03 17:37:39 +02:00
#include <openrct2/actions/StaffHireNewAction.h>
2020-12-09 23:39:10 -07:00
#include <openrct2/actions/StaffSetColourAction.h>
2018-06-22 23:21:44 +02:00
#include <openrct2/config/Config.h>
2024-12-15 17:39:52 +01:00
#include <openrct2/core/EnumUtils.hpp>
2024-12-11 16:58:56 +01:00
#include <openrct2/core/String.hpp>
2018-06-22 23:21:44 +02:00
#include <openrct2/drawing/Drawing.h>
2025-10-23 18:44:45 +02:00
#include <openrct2/drawing/Rectangle.h>
2021-11-24 16:48:33 +02:00
#include <openrct2/entity/EntityList.h>
2021-11-24 16:58:01 +02:00
#include <openrct2/entity/EntityRegistry.h>
2022-03-08 00:14:52 +00:00
#include <openrct2/entity/PatrolArea.h>
2021-11-25 23:47:24 +02:00
#include <openrct2/entity/Staff.h>
2021-12-11 18:06:06 -05:00
#include <openrct2/localisation/Formatter.h>
2018-06-22 23:21:44 +02:00
#include <openrct2/management/Finance.h>
2024-12-05 13:37:39 +01:00
#include <openrct2/object/ObjectLimits.h>
2024-12-02 19:58:00 +01:00
#include <openrct2/object/ObjectManager.h>
#include <openrct2/object/PeepAnimationsObject.h>
2025-01-08 21:12:11 +01:00
#include <openrct2/ui/WindowManager.h>
2017-12-13 13:02:24 +01:00
#include <openrct2/util/Util.h>
2018-06-22 23:21:44 +02:00
#include <openrct2/windows/Intent.h>
2018-01-11 10:59:26 +01:00
#include <openrct2/world/Footpath.h>
2018-03-19 23:28:40 +01:00
#include <openrct2/world/Park.h>
2020-03-28 12:12:53 +00:00
#include <vector>
2014-10-07 19:39:52 +01:00
2025-10-21 12:20:00 +02:00
using namespace OpenRCT2 :: Drawing ;
2024-03-10 13:52:35 +00:00
namespace OpenRCT2 :: Ui :: Windows
2021-01-25 21:57:06 +00:00
{
2024-03-10 13:52:35 +00:00
enum
{
WINDOW_STAFF_LIST_TAB_HANDYMEN ,
WINDOW_STAFF_LIST_TAB_MECHANICS ,
WINDOW_STAFF_LIST_TAB_SECURITY ,
WINDOW_STAFF_LIST_TAB_ENTERTAINERS
};
2014-10-07 19:39:52 +01:00
2024-03-10 13:52:35 +00:00
enum WindowStaffListWidgetIdx
{
WIDX_STAFF_LIST_BACKGROUND ,
WIDX_STAFF_LIST_TITLE ,
WIDX_STAFF_LIST_CLOSE ,
WIDX_STAFF_LIST_TAB_CONTENT_PANEL ,
WIDX_STAFF_LIST_HANDYMEN_TAB ,
WIDX_STAFF_LIST_MECHANICS_TAB ,
WIDX_STAFF_LIST_SECURITY_TAB ,
WIDX_STAFF_LIST_ENTERTAINERS_TAB ,
WIDX_STAFF_LIST_LIST ,
WIDX_STAFF_LIST_UNIFORM_COLOUR_PICKER ,
WIDX_STAFF_LIST_HIRE_BUTTON ,
WIDX_STAFF_LIST_QUICK_FIRE ,
WIDX_STAFF_LIST_SHOW_PATROL_AREA_BUTTON ,
WIDX_STAFF_LIST_MAP ,
};
2014-10-07 19:39:52 +01:00
2025-06-16 23:10:47 +02:00
static constexpr StringId kWindowTitle = STR_STAFF ;
static constexpr ScreenSize kWindowSize = { 320 , 270 };
constexpr int32_t kMaximumWindowWidth = 500 ;
constexpr int32_t kMaximumWindowHeight = 450 ;
2016-01-09 11:32:28 +01:00
2024-03-10 13:52:35 +00:00
// clang-format off
2025-06-07 23:02:14 +02:00
static constexpr auto _staffListWidgets = makeWidgets (
2025-06-16 23:10:47 +02:00
makeWindowShim ( kWindowTitle , kWindowSize ),
makeWidget ({ 0 , 43 }, { kWindowSize . width , kWindowSize . height - 43 }, WidgetType :: resize , WindowColour :: secondary ), // tab content panel
makeTab ({ 3 , 17 }, STR_STAFF_HANDYMEN_TAB_TIP ), // handymen tab
makeTab ({ 34 , 17 }, STR_STAFF_MECHANICS_TAB_TIP ), // mechanics tab
makeTab ({ 65 , 17 }, STR_STAFF_SECURITY_TAB_TIP ), // security guards tab
makeTab ({ 96 , 17 }, STR_STAFF_ENTERTAINERS_TAB_TIP ), // entertainers tab
makeWidget ({ 3 , 72 }, { kWindowSize . width - 6 , 195 }, WidgetType :: scroll , WindowColour :: secondary , SCROLL_VERTICAL ), // staff list
makeWidget ({ 130 , 58 }, { 12 , 12 }, WidgetType :: colourBtn , WindowColour :: secondary , kStringIdNone , STR_UNIFORM_COLOUR_TIP ), // uniform colour picker
makeWidget ({ 165 , 17 }, { 145 , 13 }, WidgetType :: button , WindowColour :: primary , kStringIdNone , STR_HIRE_STAFF_TIP ), // hire button
makeWidget ({ 243 , 46 }, { 24 , 24 }, WidgetType :: flatBtn , WindowColour :: secondary , ImageId ( SPR_DEMOLISH ), STR_QUICK_FIRE_STAFF ), // quick fire staff
makeWidget ({ 267 , 46 }, { 24 , 24 }, WidgetType :: flatBtn , WindowColour :: secondary , ImageId ( SPR_PATROL_BTN ), STR_SHOW_PATROL_AREA_TIP ), // show staff patrol area tool
makeWidget ({ 291 , 46 }, { 24 , 24 }, WidgetType :: flatBtn , WindowColour :: secondary , ImageId ( SPR_MAP ), STR_SHOW_STAFF_ON_MAP_TIP ) // show staff on map button
2025-06-07 23:02:14 +02:00
);
2024-03-10 13:52:35 +00:00
// clang-format on
2016-07-14 14:07:49 +02:00
2024-03-10 13:52:35 +00:00
class StaffListWindow final : public Window
2020-03-28 12:12:53 +00:00
{
2024-03-10 13:52:35 +00:00
private :
struct StaffNamingConvention
2017-06-06 23:24:18 +02:00
{
2024-03-10 13:52:35 +00:00
StringId Plural ;
StringId Singular ;
StringId ActionHire ;
};
struct StaffEntry
{
EntityId Id ;
u8string Name ;
};
std :: vector < StaffEntry > _staffList ;
bool _quickFireMode {};
std :: optional < size_t > _highlightedIndex {};
int32_t _selectedTab {};
uint32_t _tabAnimationIndex {};
public :
2025-09-17 20:10:06 +02:00
void onOpen () override
2024-03-10 13:52:35 +00:00
{
2025-09-17 20:10:06 +02:00
setWidgets ( _staffListWidgets );
2024-03-10 13:52:35 +00:00
WindowInitScrollWidgets ( * this );
2025-06-16 23:10:47 +02:00
WindowSetResize ( * this , kWindowSize , { kMaximumWindowWidth , kMaximumWindowHeight });
2024-03-10 13:52:35 +00:00
2025-06-10 19:55:12 +02:00
widgets [ WIDX_STAFF_LIST_UNIFORM_COLOUR_PICKER ]. type = WidgetType :: empty ;
2024-03-10 13:52:35 +00:00
RefreshList ();
}
2025-09-17 20:10:06 +02:00
void onClose () override
2024-03-10 13:52:35 +00:00
{
CancelTools ();
}
2025-09-17 20:10:06 +02:00
void onMouseUp ( WidgetIndex widgetIndex ) override
2024-03-10 13:52:35 +00:00
{
switch ( widgetIndex )
2018-06-22 23:21:44 +02:00
{
2024-03-10 13:52:35 +00:00
case WIDX_STAFF_LIST_CLOSE :
2025-09-17 20:10:06 +02:00
close ();
2024-03-10 13:52:35 +00:00
break ;
case WIDX_STAFF_LIST_HIRE_BUTTON :
2018-06-22 23:21:44 +02:00
{
2024-03-10 13:52:35 +00:00
auto staffType = GetSelectedStaffType ();
2024-12-05 15:29:34 +01:00
HireNewMember ( staffType );
2024-03-10 13:52:35 +00:00
break ;
2017-06-06 23:24:18 +02:00
}
2024-03-10 13:52:35 +00:00
case WIDX_STAFF_LIST_SHOW_PATROL_AREA_BUTTON :
2025-03-01 15:56:36 +01:00
if ( ! ToolSet ( * this , WIDX_STAFF_LIST_SHOW_PATROL_AREA_BUTTON , Tool :: crosshair ))
2024-03-10 13:52:35 +00:00
{
ShowGridlines ();
SetPatrolAreaToRender ( GetSelectedStaffType ());
GfxInvalidateScreen ();
}
break ;
case WIDX_STAFF_LIST_MAP :
2025-09-17 23:18:52 +02:00
ContextOpenWindow ( WindowClass :: map );
2024-03-10 13:52:35 +00:00
break ;
case WIDX_STAFF_LIST_QUICK_FIRE :
_quickFireMode = ! _quickFireMode ;
2025-09-17 20:10:06 +02:00
invalidate ();
2024-03-10 13:52:35 +00:00
break ;
2021-01-25 21:57:06 +00:00
}
}
2025-09-17 20:10:06 +02:00
void onUpdate () override
2024-03-10 13:52:35 +00:00
{
2024-12-09 22:43:45 +01:00
auto animPeepType = AnimationPeepType ( static_cast < uint8_t > ( _selectedTab ) + 1 );
auto * animObj = findPeepAnimationsObjectForType ( animPeepType );
if ( animObj != nullptr )
2024-03-10 13:52:35 +00:00
{
2025-10-05 01:33:32 +02:00
auto & anim = animObj -> GetPeepAnimation ( PeepAnimationGroup :: normal );
2024-12-09 22:43:45 +01:00
_tabAnimationIndex ++ ;
2024-03-10 13:52:35 +00:00
2025-10-05 01:27:23 +02:00
if ( _tabAnimationIndex >= anim . frameOffsets . size () * 4 )
2024-12-09 22:43:45 +01:00
_tabAnimationIndex = 0 ;
2025-09-17 20:10:06 +02:00
invalidateWidget ( WIDX_STAFF_LIST_HANDYMEN_TAB + _selectedTab );
2024-12-09 22:43:45 +01:00
}
// Enable highlighting of these staff members in map window
2025-01-19 10:58:28 +01:00
auto * windowMgr = GetWindowManager ();
2025-09-17 23:18:52 +02:00
if ( windowMgr -> FindByClass ( WindowClass :: map ) != nullptr )
2024-12-09 22:43:45 +01:00
{
for ( auto peep : EntityList < Staff > ())
2021-01-25 21:57:06 +00:00
{
2025-08-31 14:29:36 +02:00
getGameState (). entities . EntitySetFlashing ( peep , false );
2024-12-09 22:43:45 +01:00
if ( peep -> AssignedStaffType == GetSelectedStaffType ())
2021-01-25 21:57:06 +00:00
{
2025-08-31 14:29:36 +02:00
getGameState (). entities . EntitySetFlashing ( peep , true );
2021-01-25 21:57:06 +00:00
}
}
2024-03-10 13:52:35 +00:00
}
// Note this may be slow if number of staff increases a large amount.
// See GuestList for fix (more intents) if required.
RefreshList ();
}
2025-09-17 20:10:06 +02:00
void onMouseDown ( WidgetIndex widgetIndex ) override
2024-03-10 13:52:35 +00:00
{
switch ( widgetIndex )
{
case WIDX_STAFF_LIST_HANDYMEN_TAB :
case WIDX_STAFF_LIST_MECHANICS_TAB :
case WIDX_STAFF_LIST_SECURITY_TAB :
case WIDX_STAFF_LIST_ENTERTAINERS_TAB :
{
auto newSelectedTab = widgetIndex - WIDX_STAFF_LIST_HANDYMEN_TAB ;
if ( _selectedTab != newSelectedTab )
{
_selectedTab = static_cast < uint8_t > ( newSelectedTab );
2024-07-21 01:35:22 +10:00
RefreshList ();
2025-09-17 20:10:06 +02:00
invalidate ();
2024-08-11 16:21:53 +02:00
scrolls [ 0 ]. contentOffsetY = 0 ;
2024-03-10 13:52:35 +00:00
CancelTools ();
}
break ;
}
case WIDX_STAFF_LIST_UNIFORM_COLOUR_PICKER :
WindowDropdownShowColour ( this , & widgets [ widgetIndex ], colours [ 1 ], StaffGetColour ( GetSelectedStaffType ()));
break ;
}
}
2025-09-17 20:10:06 +02:00
void onDropdown ( WidgetIndex widgetIndex , int32_t dropdownIndex ) override
2024-03-10 13:52:35 +00:00
{
if ( dropdownIndex == - 1 )
{
return ;
}
if ( widgetIndex == WIDX_STAFF_LIST_UNIFORM_COLOUR_PICKER )
{
2025-08-26 18:34:31 +02:00
auto action = GameActions :: StaffSetColourAction (
GetSelectedStaffType (), ColourDropDownIndexToColour ( dropdownIndex ));
2025-09-08 16:21:29 +02:00
GameActions :: Execute ( & action , getGameState ());
2024-03-10 13:52:35 +00:00
}
}
2025-09-17 20:10:06 +02:00
void onPrepareDraw () override
2024-03-10 13:52:35 +00:00
{
// Set selected tab
2025-09-17 20:10:06 +02:00
setWidgetPressed ( WIDX_STAFF_LIST_HANDYMEN_TAB , false );
setWidgetPressed ( WIDX_STAFF_LIST_MECHANICS_TAB , false );
setWidgetPressed ( WIDX_STAFF_LIST_SECURITY_TAB , false );
setWidgetPressed ( WIDX_STAFF_LIST_ENTERTAINERS_TAB , false );
setWidgetPressed ( _selectedTab + WIDX_STAFF_LIST_HANDYMEN_TAB , true );
2024-03-10 13:52:35 +00:00
widgets [ WIDX_STAFF_LIST_HIRE_BUTTON ]. text = GetStaffNamingConvention ( GetSelectedStaffType ()). ActionHire ;
2025-06-10 19:55:12 +02:00
widgets [ WIDX_STAFF_LIST_UNIFORM_COLOUR_PICKER ]. type = WidgetType :: empty ;
2024-03-10 13:52:35 +00:00
2025-10-05 14:47:16 +02:00
if ( GetSelectedStaffType () != StaffType :: entertainer )
2024-03-10 13:52:35 +00:00
{
2025-06-10 19:55:12 +02:00
widgets [ WIDX_STAFF_LIST_UNIFORM_COLOUR_PICKER ]. type = WidgetType :: colourBtn ;
2025-06-10 21:57:53 +02:00
widgets [ WIDX_STAFF_LIST_UNIFORM_COLOUR_PICKER ]. image = getColourButtonImage (
2024-03-10 13:52:35 +00:00
StaffGetColour ( GetSelectedStaffType ()));
}
2025-09-17 20:10:06 +02:00
setWidgetPressed ( WIDX_STAFF_LIST_QUICK_FIRE , _quickFireMode );
2024-03-10 13:52:35 +00:00
widgets [ WIDX_STAFF_LIST_LIST ]. right = width - 4 ;
widgets [ WIDX_STAFF_LIST_LIST ]. bottom = height - 15 ;
widgets [ WIDX_STAFF_LIST_QUICK_FIRE ]. left = width - 77 ;
widgets [ WIDX_STAFF_LIST_QUICK_FIRE ]. right = width - 54 ;
widgets [ WIDX_STAFF_LIST_SHOW_PATROL_AREA_BUTTON ]. left = width - 53 ;
widgets [ WIDX_STAFF_LIST_SHOW_PATROL_AREA_BUTTON ]. right = width - 30 ;
widgets [ WIDX_STAFF_LIST_MAP ]. left = width - 29 ;
widgets [ WIDX_STAFF_LIST_MAP ]. right = width - 6 ;
widgets [ WIDX_STAFF_LIST_HIRE_BUTTON ]. left = width - 155 ;
widgets [ WIDX_STAFF_LIST_HIRE_BUTTON ]. right = width - 11 ;
}
2025-09-17 20:10:06 +02:00
void onDraw ( RenderTarget & rt ) override
2024-03-10 13:52:35 +00:00
{
2025-09-17 20:10:06 +02:00
drawWidgets ( rt );
2025-05-05 01:06:46 +03:00
DrawTabImages ( rt );
2024-03-10 13:52:35 +00:00
2025-08-21 20:50:23 +02:00
if ( ! ( getGameState (). park . flags & PARK_FLAGS_NO_MONEY ))
2024-03-10 13:52:35 +00:00
{
auto ft = Formatter ();
ft . Add < money64 > ( GetStaffWage ( GetSelectedStaffType ()));
2025-02-24 17:59:23 +01:00
auto y = widgets [ WIDX_STAFF_LIST_TITLE ]. bottom + 17 ;
2025-05-05 01:06:46 +03:00
DrawTextBasic ( rt , windowPos + ScreenCoordsXY { width - 155 , y }, STR_COST_PER_MONTH , ft );
2024-03-10 13:52:35 +00:00
}
2025-10-05 14:47:16 +02:00
if ( GetSelectedStaffType () != StaffType :: entertainer )
2024-03-10 13:52:35 +00:00
{
DrawTextBasic (
2025-05-05 01:06:46 +03:00
rt , windowPos + ScreenCoordsXY { 6 , widgets [ WIDX_STAFF_LIST_UNIFORM_COLOUR_PICKER ]. top + 1 },
2024-03-10 13:52:35 +00:00
STR_UNIFORM_COLOUR );
}
auto namingConvention = GetStaffNamingConvention ( GetSelectedStaffType ());
auto staffTypeStringId = _staffList . size () == 1 ? namingConvention . Singular : namingConvention . Plural ;
auto ft = Formatter ();
ft . Add < uint32_t > ( _staffList . size ());
ft . Add < StringId > ( staffTypeStringId );
DrawTextBasic (
2025-05-05 01:06:46 +03:00
rt , windowPos + ScreenCoordsXY { 4 , widgets [ WIDX_STAFF_LIST_LIST ]. bottom + 2 }, STR_STAFF_LIST_COUNTER , ft );
2024-03-10 13:52:35 +00:00
}
2025-09-17 20:10:06 +02:00
ScreenSize onScrollGetSize ( int32_t scrollIndex ) override
2024-03-10 13:52:35 +00:00
{
if ( _highlightedIndex )
{
_highlightedIndex = {};
2025-09-17 20:10:06 +02:00
invalidate ();
2024-03-10 13:52:35 +00:00
}
2024-05-09 13:59:03 +02:00
auto scrollHeight = static_cast < int32_t > ( _staffList . size ()) * kScrollableRowHeight ;
2024-03-10 13:52:35 +00:00
auto i = scrollHeight - widgets [ WIDX_STAFF_LIST_LIST ]. bottom + widgets [ WIDX_STAFF_LIST_LIST ]. top + 21 ;
if ( i < 0 )
i = 0 ;
2024-08-11 16:21:53 +02:00
if ( i < scrolls [ 0 ]. contentOffsetY )
2024-03-10 13:52:35 +00:00
{
2024-08-11 16:21:53 +02:00
scrolls [ 0 ]. contentOffsetY = i ;
2025-09-17 20:10:06 +02:00
invalidate ();
2024-03-10 13:52:35 +00:00
}
2025-11-08 10:27:58 +01:00
auto scrollWidth = widgets [ WIDX_STAFF_LIST_LIST ]. width () - 16 ;
2024-03-10 13:52:35 +00:00
return { scrollWidth , scrollHeight };
}
2025-09-17 20:10:06 +02:00
void onScrollMouseOver ( int32_t scrollIndex , const ScreenCoordsXY & screenCoords ) override
2024-03-10 13:52:35 +00:00
{
2024-05-09 13:59:03 +02:00
auto i = static_cast < size_t > ( screenCoords . y / kScrollableRowHeight );
2024-03-10 13:52:35 +00:00
if ( i != _highlightedIndex )
{
_highlightedIndex = static_cast < size_t > ( i );
2025-09-17 20:10:06 +02:00
invalidate ();
2024-03-10 13:52:35 +00:00
}
}
2025-09-17 20:10:06 +02:00
void onScrollMouseDown ( int32_t scrollIndex , const ScreenCoordsXY & screenCoords ) override
2024-03-10 13:52:35 +00:00
{
2024-05-09 13:59:03 +02:00
int32_t i = screenCoords . y / kScrollableRowHeight ;
2025-09-08 16:21:29 +02:00
auto & gameState = getGameState ();
2024-03-10 13:52:35 +00:00
for ( const auto & entry : _staffList )
{
if ( i == 0 )
{
if ( _quickFireMode )
{
2025-08-26 18:34:31 +02:00
auto staffFireAction = GameActions :: StaffFireAction ( entry . Id );
2025-09-08 16:21:29 +02:00
GameActions :: Execute ( & staffFireAction , gameState );
2024-03-10 13:52:35 +00:00
}
else
{
2025-09-08 16:21:29 +02:00
auto peep = gameState . entities . GetEntity < Staff > ( entry . Id );
2024-03-10 13:52:35 +00:00
if ( peep != nullptr )
{
2025-09-17 23:18:52 +02:00
auto intent = Intent ( WindowClass :: peep );
2024-03-10 13:52:35 +00:00
intent . PutExtra ( INTENT_EXTRA_PEEP , peep );
ContextOpenIntent ( & intent );
}
}
break ;
}
i -- ;
}
}
2025-09-17 20:10:06 +02:00
void onScrollDraw ( int32_t scrollIndex , RenderTarget & rt ) override
2024-03-10 13:52:35 +00:00
{
2025-05-05 01:06:46 +03:00
auto rtCoords = ScreenCoordsXY { rt . x , rt . y };
2025-10-23 18:44:45 +02:00
Rectangle :: fill (
2025-05-05 01:06:46 +03:00
rt , { rtCoords , rtCoords + ScreenCoordsXY { rt . width - 1 , rt . height - 1 } },
2024-05-09 02:45:07 +02:00
ColourMapA [ colours [ 1 ]. colour ]. mid_light );
2024-03-10 13:52:35 +00:00
// How much space do we have for the name and action columns? (Discount scroll area and icons.)
2025-11-08 10:27:58 +01:00
const int32_t nonIconSpace = widgets [ WIDX_STAFF_LIST_LIST ]. width () - 1 - 15 - 68 ;
2024-03-10 13:52:35 +00:00
const int32_t nameColumnSize = nonIconSpace * 0.42 ;
const int32_t actionColumnSize = nonIconSpace * 0.58 ;
const int32_t actionOffset = widgets [ WIDX_STAFF_LIST_LIST ]. right - actionColumnSize - 15 ;
auto y = 0 ;
size_t i = 0 ;
for ( const auto & entry : _staffList )
{
2025-05-05 01:06:46 +03:00
if ( y > rt . y + rt . height )
2024-03-10 13:52:35 +00:00
{
break ;
}
2025-05-05 01:06:46 +03:00
if ( y + 11 >= rt . y )
2024-03-10 13:52:35 +00:00
{
2025-08-31 14:29:36 +02:00
const auto * peep = getGameState (). entities . GetEntity < Staff > ( entry . Id );
2024-03-10 13:52:35 +00:00
if ( peep == nullptr )
{
continue ;
}
2024-05-11 11:24:01 +02:00
StringId format = STR_BLACK_STRING ;
if ( _quickFireMode )
format = STR_RED_STRINGID ;
2024-03-10 13:52:35 +00:00
if ( i == _highlightedIndex )
{
2025-10-23 18:44:45 +02:00
Rectangle :: filter ( rt , { 0 , y , 800 , y + ( kScrollableRowHeight - 1 ) }, FilterPaletteID :: paletteDarken1 );
2024-05-11 11:24:01 +02:00
format = STR_WINDOW_COLOUR_2_STRINGID ;
if ( _quickFireMode )
format = STR_LIGHTPINK_STRINGID ;
2024-03-10 13:52:35 +00:00
}
auto ft = Formatter ();
peep -> FormatNameTo ( ft );
2025-05-05 01:06:46 +03:00
DrawTextEllipsised ( rt , { 0 , y }, nameColumnSize , format , ft );
2024-03-10 13:52:35 +00:00
ft = Formatter ();
peep -> FormatActionTo ( ft );
2025-05-05 01:06:46 +03:00
DrawTextEllipsised ( rt , { actionOffset , y }, actionColumnSize , format , ft );
2024-03-10 13:52:35 +00:00
// True if a patrol path is set for the worker
if ( peep -> HasPatrolArea ())
{
2025-05-05 01:06:46 +03:00
GfxDrawSprite ( rt , ImageId ( SPR_STAFF_PATROL_PATH ), { nameColumnSize + 5 , y });
2024-03-10 13:52:35 +00:00
}
auto staffOrderIcon_x = nameColumnSize + 20 ;
2025-09-15 18:00:13 -03:00
if ( ! peep -> isEntertainer ())
2024-03-10 13:52:35 +00:00
{
auto staffOrders = peep -> StaffOrders ;
auto staffOrderSprite = GetStaffOrderBaseSprite ( GetSelectedStaffType ());
while ( staffOrders != 0 )
{
if ( staffOrders & 1 )
{
2025-05-05 01:06:46 +03:00
GfxDrawSprite ( rt , ImageId ( staffOrderSprite ), { staffOrderIcon_x , y });
2024-03-10 13:52:35 +00:00
}
staffOrders = staffOrders >> 1 ;
staffOrderIcon_x += 9 ;
// TODO: Remove sprite ID addition
staffOrderSprite ++ ;
}
}
else
{
2025-05-05 01:06:46 +03:00
GfxDrawSprite ( rt , GetCostumeInlineSprite ( peep -> AnimationObjectIndex ), { staffOrderIcon_x , y });
2024-03-10 13:52:35 +00:00
}
}
2024-05-09 13:59:03 +02:00
y += kScrollableRowHeight ;
2024-03-10 13:52:35 +00:00
i ++ ;
}
}
2025-09-17 20:10:06 +02:00
void onToolDown ( WidgetIndex widgetIndex , const ScreenCoordsXY & screenCoords ) override
2024-03-10 13:52:35 +00:00
{
if ( widgetIndex == WIDX_STAFF_LIST_SHOW_PATROL_AREA_BUTTON )
{
auto closestStaffMember = GetClosestStaffMemberTo ( screenCoords );
if ( closestStaffMember != nullptr )
{
ToolCancel ();
2024-03-17 02:37:46 -04:00
auto * staffWindow = StaffOpen ( closestStaffMember );
2025-09-17 20:10:06 +02:00
staffWindow -> onDropdown ( WC_PEEP__WIDX_PATROL , 0 );
2024-03-10 13:52:35 +00:00
}
2021-01-25 21:57:06 +00:00
else
{
2024-03-10 13:52:35 +00:00
auto ft = Formatter ();
ft . Add < StringId > ( GetStaffNamingConvention ( GetSelectedStaffType ()). Plural );
2025-01-19 16:59:45 +01:00
ContextShowError ( STR_NO_THING_IN_PARK_YET , kStringIdNone , ft );
2024-03-10 13:52:35 +00:00
}
}
}
2025-09-17 20:10:06 +02:00
void onToolAbort ( WidgetIndex widgetIndex ) override
2024-03-10 13:52:35 +00:00
{
if ( widgetIndex == WIDX_STAFF_LIST_SHOW_PATROL_AREA_BUTTON )
{
HideGridlines ();
ToolCancel ();
ClearPatrolAreaToRender ();
GfxInvalidateScreen ();
}
}
void RefreshList ()
{
_staffList . clear ();
for ( auto * peep : EntityList < Staff > ())
{
2025-08-31 14:29:36 +02:00
getGameState (). entities . EntitySetFlashing ( peep , false );
2024-03-10 13:52:35 +00:00
if ( peep -> AssignedStaffType == GetSelectedStaffType ())
{
2025-08-31 14:29:36 +02:00
getGameState (). entities . EntitySetFlashing ( peep , true );
2024-03-10 13:52:35 +00:00
StaffEntry entry ;
entry . Id = peep -> Id ;
entry . Name = peep -> GetName ();
_staffList . push_back ( std :: move ( entry ));
2021-01-25 21:57:06 +00:00
}
}
2024-03-10 13:52:35 +00:00
std :: sort ( _staffList . begin (), _staffList . end (), []( const auto & a , const auto & b ) {
2024-12-11 22:28:31 +01:00
return String :: logicalCmp ( a . Name . c_str (), b . Name . c_str ()) < 0 ;
2024-03-10 13:52:35 +00:00
});
2021-01-25 21:57:06 +00:00
}
2024-03-10 13:52:35 +00:00
private :
/**
* Hires a new staff member of the given type.
*/
2024-12-05 15:29:34 +01:00
void HireNewMember ( StaffType staffType )
2021-01-25 21:57:06 +00:00
{
2025-10-07 20:14:37 +02:00
bool autoPosition = Config :: Get (). general . autoStaffPlacement ;
2025-09-30 22:35:02 +02:00
if ( GetInputManager (). isModifierKeyPressed ( ModifierKey :: shift ))
2021-01-25 21:57:06 +00:00
{
2024-03-10 13:52:35 +00:00
autoPosition = autoPosition ^ 1 ;
2021-01-25 21:57:06 +00:00
}
2024-03-10 13:52:35 +00:00
uint32_t staffOrders = 0 ;
2025-10-05 14:47:16 +02:00
if ( staffType == StaffType :: handyman )
2021-01-25 21:57:06 +00:00
{
2024-03-10 13:52:35 +00:00
staffOrders = STAFF_ORDERS_SWEEPING | STAFF_ORDERS_WATER_FLOWERS | STAFF_ORDERS_EMPTY_BINS ;
2025-10-07 20:14:37 +02:00
if ( Config :: Get (). general . handymenMowByDefault )
2024-03-10 13:52:35 +00:00
{
staffOrders |= STAFF_ORDERS_MOWING ;
}
2021-01-25 21:57:06 +00:00
}
2025-10-05 14:47:16 +02:00
else if ( staffType == StaffType :: mechanic )
2021-01-25 21:57:06 +00:00
{
2024-03-10 13:52:35 +00:00
staffOrders = STAFF_ORDERS_INSPECT_RIDES | STAFF_ORDERS_FIX_RIDES ;
2021-01-25 21:57:06 +00:00
}
2024-12-05 15:29:34 +01:00
auto animPeepType = AnimationPeepType ( static_cast < uint8_t > ( staffType ) + 1 );
ObjectEntryIndex costume ;
2025-10-05 14:47:16 +02:00
if ( staffType == StaffType :: entertainer )
2024-12-05 15:29:34 +01:00
costume = findRandomPeepAnimationsIndexForType ( animPeepType );
else
costume = findPeepAnimationsIndexForType ( animPeepType );
2025-09-08 16:21:29 +02:00
auto & gameState = getGameState ();
2025-08-26 18:34:31 +02:00
auto hireStaffAction = GameActions :: StaffHireNewAction ( autoPosition , staffType , costume , staffOrders );
2025-08-29 11:32:05 +02:00
hireStaffAction . SetCallback ([ = ]( const GameActions :: GameAction * , const GameActions :: Result * res ) -> void {
2025-12-12 11:41:49 +01:00
if ( res -> Error != GameActions :: Status :: ok )
2024-03-10 13:52:35 +00:00
return ;
2021-01-25 21:57:06 +00:00
2025-08-26 18:34:31 +02:00
auto actionResult = res -> GetData < GameActions :: StaffHireNewActionResult > ();
2025-08-31 14:29:36 +02:00
auto * staff = getGameState (). entities . GetEntity < Staff > ( actionResult . StaffEntityId );
2024-03-10 13:52:35 +00:00
if ( staff == nullptr )
return ;
2021-12-03 17:37:39 +02:00
2024-03-10 13:52:35 +00:00
// If autoposition of staff is disabled, pickup peep and then open the staff window
2025-10-05 01:28:55 +02:00
if ( staff -> State == PeepState :: picked )
2024-03-10 13:52:35 +00:00
{
CoordsXYZ nullLoc {};
nullLoc . SetNull ();
2021-12-03 17:37:39 +02:00
2025-08-26 18:34:31 +02:00
GameActions :: PeepPickupAction pickupAction { GameActions :: PeepPickupType :: Pickup , staff -> Id , nullLoc ,
2025-08-31 16:02:43 +02:00
Network :: GetCurrentPlayerId () };
2025-08-29 11:32:05 +02:00
pickupAction . SetCallback (
[ staffId = staff -> Id ]( const GameActions :: GameAction * ga , const GameActions :: Result * result ) {
2025-12-12 11:41:49 +01:00
if ( result -> Error != GameActions :: Status :: ok )
2025-08-29 11:32:05 +02:00
return ;
2021-12-03 17:37:39 +02:00
2025-08-31 14:29:36 +02:00
auto * staff2 = getGameState (). entities . GetEntity < Staff > ( staffId );
2025-09-17 23:18:52 +02:00
auto intent = Intent ( WindowClass :: peep );
2025-08-29 11:32:05 +02:00
intent . PutExtra ( INTENT_EXTRA_PEEP , staff2 );
auto * wind = ContextOpenIntent ( & intent );
if ( wind != nullptr )
{
ToolSet ( * wind , WC_STAFF__WIDX_PICKUP , Tool :: picker );
}
});
2025-09-08 16:21:29 +02:00
GameActions :: Execute ( & pickupAction , getGameState ());
2024-03-10 13:52:35 +00:00
}
else
{
// Open window for new staff.
2025-09-17 23:18:52 +02:00
auto intent = Intent ( WindowClass :: peep );
2024-03-10 13:52:35 +00:00
intent . PutExtra ( INTENT_EXTRA_PEEP , staff );
ContextOpenIntent ( & intent );
}
});
2021-12-03 17:37:39 +02:00
2025-09-08 16:21:29 +02:00
GameActions :: Execute ( & hireStaffAction , gameState );
2024-03-10 13:52:35 +00:00
}
2021-12-03 17:37:39 +02:00
2024-03-10 13:52:35 +00:00
StaffType GetSelectedStaffType () const
2021-01-25 21:57:06 +00:00
{
2024-03-10 13:52:35 +00:00
return static_cast < StaffType > ( _selectedTab );
}
2025-05-05 01:06:46 +03:00
void DrawTabImages ( RenderTarget & rt ) const
2024-03-10 13:52:35 +00:00
{
2025-03-20 19:47:53 +01:00
const auto & gameState = getGameState ();
2025-10-05 01:10:06 +02:00
DrawTabImage ( rt , WINDOW_STAFF_LIST_TAB_HANDYMEN , AnimationPeepType :: handyman , gameState . park . staffHandymanColour );
DrawTabImage ( rt , WINDOW_STAFF_LIST_TAB_MECHANICS , AnimationPeepType :: mechanic , gameState . park . staffMechanicColour );
DrawTabImage ( rt , WINDOW_STAFF_LIST_TAB_SECURITY , AnimationPeepType :: security , gameState . park . staffSecurityColour );
DrawTabImage ( rt , WINDOW_STAFF_LIST_TAB_ENTERTAINERS , AnimationPeepType :: entertainer );
2024-03-10 13:52:35 +00:00
}
2025-05-05 01:06:46 +03:00
void DrawTabImage ( RenderTarget & rt , int32_t tabIndex , AnimationPeepType type , colour_t colour ) const
2024-03-10 13:52:35 +00:00
{
2024-12-05 13:37:39 +01:00
PeepAnimationsObject * animObj = findPeepAnimationsObjectForType ( type );
if ( animObj == nullptr )
return ;
2024-03-10 13:52:35 +00:00
auto widgetIndex = WIDX_STAFF_LIST_HANDYMEN_TAB + tabIndex ;
const auto & widget = widgets [ widgetIndex ];
2024-12-05 13:37:39 +01:00
2024-12-09 22:43:45 +01:00
auto frame = _selectedTab == tabIndex ? _tabAnimationIndex / 4 : 0 ;
2025-10-05 01:33:32 +02:00
auto & anim = animObj -> GetPeepAnimation ( PeepAnimationGroup :: normal );
2025-10-05 01:27:23 +02:00
auto imageId = anim . baseImage + 1 + anim . frameOffsets [ frame ] * 4 ;
2024-12-09 22:43:45 +01:00
2024-03-10 13:52:35 +00:00
GfxDrawSprite (
2025-05-05 01:06:46 +03:00
rt , ImageId ( imageId , colour ),
2024-03-10 13:52:35 +00:00
windowPos + ScreenCoordsXY { ( widget . left + widget . right ) / 2 , widget . bottom - 6 });
2021-01-25 21:57:06 +00:00
}
2025-05-05 01:06:46 +03:00
void DrawTabImage ( RenderTarget & rt , int32_t tabIndex , AnimationPeepType type ) const
2021-01-25 21:57:06 +00:00
{
2024-12-05 13:37:39 +01:00
PeepAnimationsObject * animObj = findPeepAnimationsObjectForType ( type );
if ( animObj == nullptr )
return ;
2024-03-10 13:52:35 +00:00
auto widgetIndex = WIDX_STAFF_LIST_HANDYMEN_TAB + tabIndex ;
const auto & widget = widgets [ widgetIndex ];
2024-12-05 13:37:39 +01:00
2025-05-05 01:06:46 +03:00
RenderTarget clippedDpi ;
2024-03-10 13:52:35 +00:00
if ( ClipDrawPixelInfo (
2025-05-05 01:06:46 +03:00
clippedDpi , rt , windowPos + ScreenCoordsXY { widget . left + 1 , widget . top + 1 },
2024-03-10 13:52:35 +00:00
widget . right - widget . left - 1 , widget . bottom - widget . top - 1 ))
2021-01-25 21:57:06 +00:00
{
2024-12-09 22:43:45 +01:00
auto frame = _selectedTab == tabIndex ? _tabAnimationIndex / 4 : 0 ;
2025-10-05 01:33:32 +02:00
auto & anim = animObj -> GetPeepAnimation ( PeepAnimationGroup :: normal );
2025-10-05 01:27:23 +02:00
auto imageId = anim . baseImage + 1 + anim . frameOffsets [ frame ] * 4 ;
2024-12-09 22:43:45 +01:00
2024-03-10 13:52:35 +00:00
GfxDrawSprite ( clippedDpi , ImageId ( imageId ), { 15 , 23 });
2021-01-25 21:57:06 +00:00
}
}
2024-03-10 13:52:35 +00:00
void CancelTools ()
2021-01-25 21:57:06 +00:00
{
2024-08-05 10:47:36 +02:00
if ( isToolActive ( classification , number ))
ToolCancel ();
2024-03-10 13:52:35 +00:00
}
Peep * GetClosestStaffMemberTo ( const ScreenCoordsXY & screenCoords )
{
int32_t direction {};
TileElement * tileElement {};
auto footpathCoords = FootpathGetCoordinatesFromPos ( screenCoords , & direction , & tileElement );
if ( footpathCoords . IsNull ())
return nullptr ;
auto isPatrolAreaSet = IsPatrolAreaSetForStaffType ( GetSelectedStaffType (), footpathCoords );
Peep * closestPeep = nullptr ;
auto closestPeepDistance = std :: numeric_limits < int32_t >:: max ();
for ( auto peep : EntityList < Staff > ())
{
if ( peep -> AssignedStaffType != GetSelectedStaffType ())
continue ;
if ( isPatrolAreaSet )
{
if ( ! peep -> HasPatrolArea ())
{
continue ;
}
if ( ! peep -> IsLocationInPatrol ( footpathCoords ))
{
continue ;
}
}
2024-07-26 18:23:25 +10:00
if ( peep -> x == kLocationNull )
2018-06-22 23:21:44 +02:00
{
2017-06-06 23:24:18 +02:00
continue ;
}
2024-03-10 13:52:35 +00:00
auto distance = std :: abs ( footpathCoords . x - peep -> x ) + std :: abs ( footpathCoords . y - peep -> y );
if ( distance < closestPeepDistance )
2018-06-22 23:21:44 +02:00
{
2024-03-10 13:52:35 +00:00
closestPeepDistance = distance ;
closestPeep = peep ;
2017-06-06 23:24:18 +02:00
}
}
2024-03-10 13:52:35 +00:00
return closestPeep ;
}
2015-07-13 19:51:46 +01:00
2024-03-10 13:52:35 +00:00
static constexpr StaffNamingConvention GetStaffNamingConvention ( StaffType type )
{
switch ( type )
2018-06-22 23:21:44 +02:00
{
2024-03-10 13:52:35 +00:00
default :
2025-10-05 14:47:16 +02:00
case StaffType :: handyman :
2024-03-10 13:52:35 +00:00
return { STR_HANDYMAN_PLURAL , STR_HANDYMAN_SINGULAR , STR_HIRE_HANDYMAN };
2025-10-05 14:47:16 +02:00
case StaffType :: mechanic :
2024-03-10 13:52:35 +00:00
return { STR_MECHANIC_PLURAL , STR_MECHANIC_SINGULAR , STR_HIRE_MECHANIC };
2025-10-05 14:47:16 +02:00
case StaffType :: security :
2024-03-10 13:52:35 +00:00
return { STR_SECURITY_GUARD_PLURAL , STR_SECURITY_GUARD_SINGULAR , STR_HIRE_SECURITY_GUARD };
2025-10-05 14:47:16 +02:00
case StaffType :: entertainer :
2024-03-10 13:52:35 +00:00
return { STR_ENTERTAINER_PLURAL , STR_ENTERTAINER_SINGULAR , STR_HIRE_ENTERTAINER };
2017-06-06 23:24:18 +02:00
}
}
2015-07-13 19:51:46 +01:00
2024-03-10 13:52:35 +00:00
static uint32_t GetStaffOrderBaseSprite ( StaffType type )
2018-06-22 23:21:44 +02:00
{
2024-03-10 13:52:35 +00:00
switch ( type )
{
2025-10-05 14:47:16 +02:00
case StaffType :: handyman :
2024-03-10 13:52:35 +00:00
return SPR_STAFF_ORDERS_SWEEPING ;
2025-10-05 14:47:16 +02:00
case StaffType :: mechanic :
2024-03-10 13:52:35 +00:00
return SPR_STAFF_ORDERS_INSPECT_RIDES ;
default :
return 0 ;
}
2018-06-22 23:21:44 +02:00
}
2024-03-10 13:52:35 +00:00
2024-12-02 19:58:00 +01:00
static ImageId GetCostumeInlineSprite ( ObjectEntryIndex index )
2024-03-10 13:52:35 +00:00
{
2024-12-02 19:58:00 +01:00
auto & objManager = GetContext () -> GetObjectManager ();
auto * animObj = objManager . GetLoadedObject < PeepAnimationsObject > ( index );
return ImageId ( animObj -> GetInlineImageId ());
2024-03-10 13:52:35 +00:00
}
};
2024-03-17 02:37:46 -04:00
WindowBase * StaffListOpen ()
2024-03-10 13:52:35 +00:00
{
2025-01-19 10:58:28 +01:00
auto * windowMgr = GetWindowManager ();
2025-09-20 21:46:42 +02:00
return windowMgr -> FocusOrCreate < StaffListWindow > (
WindowClass :: staffList , kWindowSize , { WindowFlag :: higherContrastOnPress , WindowFlag :: resizable });
2021-01-25 21:57:06 +00:00
}
2024-03-10 13:52:35 +00:00
void WindowStaffListRefresh ()
2021-01-25 21:57:06 +00:00
{
2025-01-19 10:58:28 +01:00
auto * windowMgr = GetWindowManager ();
2025-09-17 23:18:52 +02:00
auto * window = windowMgr -> FindByClass ( WindowClass :: staffList );
2024-03-10 13:52:35 +00:00
if ( window != nullptr )
2018-06-22 23:21:44 +02:00
{
2024-03-10 13:52:35 +00:00
static_cast < StaffListWindow *> ( window ) -> RefreshList ();
2017-06-06 23:24:18 +02:00
}
}
2024-03-10 13:52:35 +00:00
} // namespace OpenRCT2::Ui::Windows