Skip to content

Radius overlay - #1946

Open
morganchristiansson wants to merge 23 commits into
Return-To-The-Roots:masterfrom
morganchristiansson:radius-overlay
Open

morganchristiansson wants to merge 23 commits into
Return-To-The-Roots:masterfrom
morganchristiansson:radius-overlay

Conversation

@morganchristiansson

@morganchristiansson morganchristiansson commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Add tooltip and overlay for building ranges

image image image image

@Flamefire Flamefire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, makes it a bit S4-like.

@Spikeone Should this be an addon too?

Comment thread libs/s25main/gameData/BuildingConsts.h Outdated
Comment thread libs/s25main/gameData/BuildingConsts.h Outdated
Comment thread libs/s25main/ingameWindows/iwAction.h Outdated
Comment thread libs/s25main/world/GameWorldView.cpp Outdated
Comment thread libs/s25main/world/GameWorldView.cpp Outdated
Comment thread libs/s25main/world/GameWorldView.cpp Outdated
Comment thread libs/s25main/figures/nofHunter.cpp
@Flamefire

Flamefire commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

Given #129 was a request for an addon, can you add one and guard the code changing the tooltip and setting the draw-circle by the addon setting? We usually keep the default behavior to be the same as in S2

BTW: Unless you just applied a suggested code snippet directly please don't resolve conversations as then we miss your reply

@Spikeone

Copy link
Copy Markdown
Member

@Spikeone Should this be an addon too?

Yes, I think so

@morganchristiansson

morganchristiansson commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor Author

I think it should be player toggleable during game, and per player in multiplayer.
It's just a fancy measuring tool so I think this should be fine.
Also I think the list of addons is getting large.

But most ppl said it should be addon so maybe best to proceed with that.

But should tooltip also be guarded by addon?

BTW: Unless you just applied a suggested code snippet directly please don't resolve conversations as then we miss your reply

Ok I will leave resolving to original commenter from now on. I just did it to track what I resolved.

@stefson

stefson commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

nice idea, but please make it an optional addon.

also, the red isn't very much in the style of S2,

@morganchristiansson

morganchristiansson commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor Author

nice idea, but please make it an optional addon.

it is now an addon

also, the red isn't very much in the style of S2,

not sure what graphics to use, please provide/suggest.

@morganchristiansson
morganchristiansson marked this pull request as ready for review June 18, 2026 20:30
@morganchristiansson

Copy link
Copy Markdown
Contributor Author

Ok all issues solved.
There's been calls for better graphics. I'm not a good artist and noone has stepped up. I think for measuring tool/hud the red rectangles are fine.

And made the addon enabled by default - mainly so I could use my existing save for testing.

@morganchristiansson

Copy link
Copy Markdown
Contributor Author

Found an edge case: it hovers game world buildings thru windows and will draw outline

@morganchristiansson

Copy link
Copy Markdown
Contributor Author

I have played many games with this enabled and it works perfectly. Hard to play without it.

Only remaining issue is to use custom graphics instead of red rectangles.

Comment thread libs/s25main/gameData/BuildingConsts.cpp Outdated
Comment thread libs/s25main/addons/AddonBuildingRadius.h Outdated
Comment thread libs/s25main/ingameWindows/iwAction.cpp Outdated
Comment thread libs/s25main/ingameWindows/iwAction.cpp Outdated
Comment thread libs/s25main/world/GameWorldView.cpp Outdated
Comment thread libs/s25main/world/GameWorldView.cpp Outdated
Comment thread libs/s25main/world/GameWorldView.cpp Outdated
Comment thread libs/s25main/world/GameWorldView.cpp Outdated
Comment thread libs/s25main/GlobalGameSettings.cpp
Comment thread libs/s25main/world/GameWorldView.cpp Outdated

// Auto-detect radius for the building under the cursor.
// Do not trigger hover when the mouse is over an ingame window.
if(!radiusPreview_ && GetWorld().GetGGS().isEnabled(AddonId::BUILDING_RADIUS)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be rather on the outside, e.g. in dskGameInterface where it could be more efficiently in a MouseMove handler. This way it is opt-in and e.g. doesn't enable for observation windows (suspicion only, haven't checked)
And whereever this is done I'd say it makes sense to cache GetWorld().GetGGS().isEnabled(AddonId::BUILDING_RADIUS) (effectively const) instead of getting this on every draw call.

@morganchristiansson

Copy link
Copy Markdown
Contributor Author

Addressed all feedback.
Ran clang-format.
24 commits so far getting a bit messy maybe could squash it.
Or I would've liked to split it but it's only usable and testable as a whole.

Comment thread libs/s25main/desktops/dskGameInterface.cpp Outdated
Comment thread libs/s25main/ingameWindows/iwAction.cpp Outdated
Comment thread libs/s25main/ingameWindows/iwAction.cpp Outdated
Comment thread libs/s25main/ingameWindows/iwAction.cpp Outdated
Comment thread libs/s25main/world/GameWorldView.cpp Outdated
Comment thread libs/s25main/world/GameWorldView.cpp Outdated

void GameWorldView::UpdateRadiusPreviewForMousePos(const Position& mousePos)
{
if(!isBuildingRadiusEnabled_ || WINDOWMANAGER.FindWindowAtPos(mousePos))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this looks like this check should rather be handled by the caller: You update by selPt not mousePos and that is only set/updated in the Draw call so likely to be stale by 1 frame anyway.
Passing a value into this class just to check it using a different layer (world vs windows) feels wrong

Maybe we can turn it around: Add a method that gets the building type at the selection which we can reuse in dskGameInterface::ContextClick too, see existing code.
Do we really want to handle non-owned buildings? Feels like a cheat... If we do the code will be different so then I'd say a method getSelectedBuildingType here and handling the mouse pos/window-manager and buildings-enabled in the caller is cleaner.

Comment thread libs/s25main/world/GameWorldView.cpp Outdated
Flamefire
Flamefire previously approved these changes Oct 4, 2026
@Flamefire
Flamefire enabled auto-merge October 4, 2026 12:35
@Flamefire
Flamefire force-pushed the radius-overlay branch 2 times, most recently from 779c717 to 1469a6d Compare October 4, 2026 19:37
@Flamefire

Copy link
Copy Markdown
Member

I resolved the conflicts & comments and tested it a bit.
Only glitch remaining is when a window is very close to the hovered/selected building on the map. When you move the mouse to the window the radius continues to be shown until you leave the window.

I haven't found a way to avoid this as the MouseMove on the desktop doesn't trigger when a modal window is open so the mouse moves on the map but doesn't show any radii.
I've also seen weird artifacts when the selected point gets stale:
If there is a selection and then the desktop doesn't update the position anymore (UpdateRadiusPreviewForMousePos) it causes weird artifacts as in the viewer the selected point will change while the center point won't so it basically moves the circle to somewhere else in the torsoid. Not sure exactly what happened there but it seems that we need to update the selection when updating the selected point (which is done inside the view-class) as that is the assumption in the Snap-method

I'd say this glitch is fine.

morganchristiansson and others added 17 commits October 4, 2026 23:33
Co-authored-by: Alexander Grund <Flamefire@users.noreply.github.com>
It uses `world` which only exists during a game.
Make that explicit by taking the settings as a parameter
It is not constant as it may depend on game settings.
Calculating the points in a large radius in every draw call is costly.
Do the constant part only once when the radius gets enabled.
When the desktop does not has the focus it won't update the radius preview.

It then shows the last highlighted buildings radius when the selected
point is close enough.
Move the selected-building check back to GameWorldView and use the
`showMouse` parameter as the sign whether to handle the mouse.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants