Skip to content

Commit

Permalink
Improvement OpenRCT2#2940: Staff patrol areas can now be mouse-painte…
Browse files Browse the repository at this point in the history
…d in singleplayer mode
  • Loading branch information
ViktorFriberg committed Sep 8, 2018
1 parent a5cbcb4 commit bdfe8cb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
1 change: 1 addition & 0 deletions distribution/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
------------------------------------------------------------------------
- Feature: [#7956, #7964] Add sprite font glyphs for Hungarian and some Czech letters.
- Fix: [#7975] Inspection flag not cleared for rides which are set to never be inspected (Original bug).
- Improved: [#2940] Allow mouse-dragging to set patrol area (Singleplayer only).
- Improved: [#7930] Automatically create folders for custom content.
- Removed: [#7929] Support for scenario text objects.

Expand Down
67 changes: 65 additions & 2 deletions src/openrct2-ui/windows/Staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <openrct2/config/Config.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/management/Finance.h>
#include <openrct2/network/network.h>
#include <openrct2/peep/Staff.h>
#include <openrct2/sprites.h>
#include <openrct2/windows/Intent.h>
Expand Down Expand Up @@ -137,6 +138,8 @@ static void window_staff_overview_paint(rct_window *w, rct_drawpixelinfo *dpi);
static void window_staff_overview_tab_paint(rct_window* w, rct_drawpixelinfo* dpi);
static void window_staff_overview_tool_update(rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t y);
static void window_staff_overview_tool_down(rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t y);
static void window_staff_overview_tool_drag(rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t y);
static void window_staff_overview_tool_up(rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t y);
static void window_staff_overview_tool_abort(rct_window *w, rct_widgetindex widgetIndex);
static void window_staff_overview_text_input(rct_window *w, rct_widgetindex widgetIndex, char *text);
static void window_staff_overview_viewport_rotate(rct_window *w);
Expand Down Expand Up @@ -171,8 +174,8 @@ static rct_window_event_list window_staff_overview_events = {
nullptr,
window_staff_overview_tool_update,
window_staff_overview_tool_down,
nullptr,
nullptr,
window_staff_overview_tool_drag,
window_staff_overview_tool_up,
window_staff_overview_tool_abort,
nullptr,
nullptr,
Expand Down Expand Up @@ -290,6 +293,8 @@ static constexpr const uint32_t window_staff_page_enabled_widgets[] = {

static uint8_t _availableCostumes[ENTERTAINER_COSTUME_COUNT];

static int32_t _staffPatrolAreaPaintValue = -1;

/**
*
* rct2: 0x006BEE98
Expand Down Expand Up @@ -1196,10 +1201,68 @@ void window_staff_overview_tool_down(rct_window* w, rct_widgetindex widgetIndex,
if (dest_x == LOCATION_NULL)
return;

rct_sprite* sprite = try_get_sprite(w->number);
if (sprite == nullptr || sprite->IsPeep() == false)
return;

rct_peep& peep = sprite->peep;
if (peep.type != PEEP_TYPE_STAFF)
return;

if (staff_is_patrol_area_set(peep.staff_id, dest_x, dest_y) == true)
{
_staffPatrolAreaPaintValue = 0;
}
else
{
_staffPatrolAreaPaintValue = 1;
}
game_do_command(dest_x, 1, dest_y, w->number, GAME_COMMAND_SET_STAFF_PATROL, 0, 0);
}
}

void window_staff_overview_tool_drag(rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t y)
{
if (widgetIndex != WIDX_PATROL)
return;

if (network_get_mode() != NETWORK_MODE_NONE)
return;

// This works only for singleplayer if the game_do_command can not be prevented
// to send packets more often than patrol area is updated.

int32_t dest_x, dest_y;
footpath_get_coordinates_from_pos(x, y, &dest_x, &dest_y, nullptr, nullptr);

if (dest_x == LOCATION_NULL)
return;

rct_sprite* sprite = try_get_sprite(w->number);
if (sprite == nullptr || sprite->IsPeep() == false)
return;

rct_peep& peep = sprite->peep;
if (peep.type != PEEP_TYPE_STAFF)
return;

bool patrolAreaValue = staff_is_patrol_area_set(peep.staff_id, dest_x, dest_y);
if (_staffPatrolAreaPaintValue == 1 && patrolAreaValue == true)
return; // Since area is already the value we want, skip...
if (_staffPatrolAreaPaintValue == 0 && patrolAreaValue == false)
return; // Since area is already the value we want, skip...

game_do_command(dest_x, 1, dest_y, w->number, GAME_COMMAND_SET_STAFF_PATROL, 0, 0);
}

void window_staff_overview_tool_up(rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t y)
{
if (widgetIndex != WIDX_PATROL)
return;

_staffPatrolAreaPaintValue = -1;
}

/**
*
* rct2: 0x6BDFAE
Expand Down

0 comments on commit bdfe8cb

Please sign in to comment.