Skip to content
Closed
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
45 changes: 38 additions & 7 deletions Source/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#include <SDL3/SDL_rect.h>
#include <SDL3/SDL_surface.h>
#else
#include <SDL.h>

Check warning on line 18 in Source/cursor.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/cursor.cpp:18:1 [misc-include-cleaner]

included header SDL.h is not used directly
#endif

#include <fmt/format.h>

Check warning on line 21 in Source/cursor.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/cursor.cpp:21:1 [misc-include-cleaner]

included header format.h is not used directly

#include "DiabloUI/diabloui.h"
#include "control.h"
Expand All @@ -30,7 +30,7 @@
#include "engine/point.hpp"
#include "engine/points_in_rectangle_range.hpp"
#include "engine/render/clx_render.hpp"
#include "engine/render/primitive_render.hpp"

Check warning on line 33 in Source/cursor.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/cursor.cpp:33:1 [misc-include-cleaner]

included header primitive_render.hpp is not used directly
#include "engine/trn.hpp"
#include "headless_mode.hpp"
#include "hwcursor.hpp"
Expand All @@ -42,43 +42,43 @@
#include "qol/stash.h"
#include "towners.h"
#include "track.h"
#include "utils/attributes.h"

Check warning on line 45 in Source/cursor.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/cursor.cpp:45:1 [misc-include-cleaner]

included header attributes.h is not used directly
#include "utils/is_of.hpp"
#include "utils/language.h"
#include "utils/palette_blending.hpp"
#include "utils/sdl_bilinear_scale.hpp"
#include "utils/surface_to_clx.hpp"
#include "utils/utf8.hpp"

Check warning on line 51 in Source/cursor.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/cursor.cpp:51:1 [misc-include-cleaner]

included header utf8.hpp is not used directly

#ifdef UNPACKED_MPQS
#include "engine/load_clx.hpp"
#else
#include "engine/load_cel.hpp"
#include "engine/load_file.hpp"

Check warning on line 57 in Source/cursor.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/cursor.cpp:57:1 [misc-include-cleaner]

included header load_file.hpp is not used directly
#include "utils/parse_int.hpp"
#endif

namespace devilution {
namespace {
/** Cursor images CEL */
OptionalOwnedClxSpriteList pCursCels;

Check warning on line 64 in Source/cursor.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/cursor.cpp:64:1 [misc-include-cleaner]

no header providing "devilution::OptionalOwnedClxSpriteList" is directly included
OptionalOwnedClxSpriteList pCursCels2;

OptionalOwnedClxSpriteList *HalfSizeItemSprites;
OptionalOwnedClxSpriteList *HalfSizeItemSpritesRed;

bool IsValidMonsterForSelection(const Monster &monster)

Check warning on line 70 in Source/cursor.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/cursor.cpp:70:39 [misc-include-cleaner]

no header providing "devilution::Monster" is directly included
{
if (monster.hasNoLife())
return false;
if ((monster.flags & MFLAG_HIDDEN) != 0)

Check warning on line 74 in Source/cursor.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/cursor.cpp:74:23 [misc-include-cleaner]

no header providing "devilution::MFLAG_HIDDEN" is directly included
return false;
if (monster.isPlayerMinion())
return false;
return true;
}

bool TrySelectMonster(bool flipflag, Point tile, tl::function_ref<bool(const Monster &)> isValidMonster)

Check warning on line 81 in Source/cursor.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/cursor.cpp:81:54 [misc-include-cleaner]

no header providing "tl::function_ref" is directly included
{
auto checkPosition = [&](SelectionRegion selectionRegion, Displacement displacement) {
const Point posToCheck = tile + displacement;
Expand Down Expand Up @@ -412,6 +412,14 @@
return result;
}
#endif
/**
* @brief Checks if the tile under the cursor is within the specified radius of the target position
*/
bool IsWithinTileRadius(Point cursor, Point target, int radius)
{
return std::abs(cursor.x - target.x) <= radius
&& std::abs(cursor.y - target.y) <= radius;
}

} // namespace

Expand Down Expand Up @@ -779,16 +787,39 @@
*/
bool CheckMouseHold(const Point currentTile)
{
if ((sgbMouseDown != CLICK_NONE || ControllerActionHeld != GameActionType_NONE) && IsNoneOf(LastPlayerAction, PlayerActionType::None, PlayerActionType::Attack, PlayerActionType::Spell)) {
InvalidateTargets();
const bool holdActive = (sgbMouseDown != CLICK_NONE || ControllerActionHeld != GameActionType_NONE)
&& IsNoneOf(LastPlayerAction, PlayerActionType::None, PlayerActionType::Attack, PlayerActionType::Spell);

if (!holdActive) {
return false;
}

if (pcursmonst == -1 && ObjectUnderCursor == nullptr && pcursitem == -1 && pcursinvitem == -1 && pcursstashitem == StashStruct::EmptyCell && PlayerUnderCursor == nullptr) {
cursPosition = currentTile;
DisplayTriggerInfo();
if (sgbMouseDown != CLICK_NONE) {
if (pcursmonst != -1) {
const Monster &monster = Monsters[pcursmonst];
if (!IsWithinTileRadius(currentTile, monster.position.tile, 1)) {
pcursmonst = -1;
}
}

if (PlayerUnderCursor != nullptr) {
const Player &player = *PlayerUnderCursor;
if (!IsWithinTileRadius(currentTile, player.position.tile, 1)) {
PlayerUnderCursor = nullptr;
}
}
return true;
}
return false;

InvalidateTargets();

if (pcursmonst == -1 && ObjectUnderCursor == nullptr && pcursitem == -1
&& pcursinvitem == -1 && pcursstashitem == StashStruct::EmptyCell
&& PlayerUnderCursor == nullptr) {
cursPosition = currentTile;
DisplayTriggerInfo();
}

return true;
}

void ResetCursorInfo()
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Features

#### Gameplay

- Improved balance for mouse and keyboard by requiring repeating actions to have the mouse near the target

## DevilutionX 1.5.2

### Bug Fixes
Expand Down
Loading