-
Notifications
You must be signed in to change notification settings - Fork 95
Radius overlay #1946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Radius overlay #1946
Changes from 7 commits
fa453a0
3175b05
d489b4c
5728636
d6c53b8
11df35a
0572598
cfebdce
795a110
bdfd9b1
7957d83
1f70192
4f4fa6e
7ec4ce5
ab91acd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,12 @@ | |
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| #include "world/GameWorldView.h" | ||
| #include <optional> | ||
| #include "CatapultStone.h" | ||
| #include "Cheats.h" | ||
| #include "FOWObjects.h" | ||
| #include "ReturnMapPointWithRadius.h" | ||
| #include "Window.h" | ||
| #include "GameInterface.h" | ||
| #include "GamePlayer.h" | ||
| #include "GlobalGameSettings.h" | ||
|
|
@@ -220,6 +223,36 @@ void GameWorldView::Draw(const RoadBuildState& rb, const MapPoint selected, bool | |
| if(show_names || show_productivity) | ||
| DrawNameProductivityOverlay(terrainRenderer); | ||
|
|
||
| // Draw radius preview outline (if set via action window hover) | ||
| if(radiusPreview_) | ||
| DrawRadiusOutline(radiusPreview_->first, radiusPreview_->second); | ||
|
|
||
| // Draw radius outline for the building under the mouse cursor | ||
| if(!radiusPreview_ && mousePos.x >= 0 && mousePos.x < static_cast<int>(size_.x) && mousePos.y >= 0 | ||
|
Flamefire marked this conversation as resolved.
Outdated
|
||
| && mousePos.y < static_cast<int>(size_.y)) | ||
| { | ||
| std::optional<BuildingType> bldType; | ||
| const Visibility vis = gwv.GetVisibility(selPt); | ||
| if(vis == Visibility::Visible) | ||
| { | ||
| const auto* bld = GetWorld().GetSpecObj<noBaseBuilding>(selPt); | ||
| if(bld) | ||
| bldType = bld->GetBuildingType(); | ||
| } else if(vis == Visibility::FogOfWar) | ||
| { | ||
| const FOWObject* fow = gwv.GetYoungestFOWObject(selPt); | ||
| if(fow && fow->GetType() == FoW_Type::Building) | ||
| bldType = static_cast<const fowBuilding&>(*fow).GetBuildingType(); | ||
| } | ||
|
|
||
| if(bldType) | ||
| { | ||
| const unsigned bldRadius = GetBuildingRadius(*bldType); | ||
| if(bldRadius > 0) | ||
| DrawRadiusOutline(selPt, bldRadius); | ||
| } | ||
| } | ||
|
|
||
| DrawGUI(rb, terrainRenderer, selected, drawMouse); | ||
|
|
||
| // Draw catapult stones | ||
|
|
@@ -713,6 +746,41 @@ void GameWorldView::RemoveDrawNodeCallback(IDrawNodeCallback* callbackToRemove) | |
| drawNodeCallbacks.erase(itPos); | ||
| } | ||
|
|
||
| void GameWorldView::DrawRadiusOutline(const MapPoint& center, unsigned radius) | ||
| { | ||
| const auto& world = GetWorld(); | ||
| // Get all border points at the exact radius | ||
| auto pts = world.GetPointsInRadius(center, radius, ReturnMapPointWithRadius{}); | ||
|
|
||
| const MapExtent mapSize = world.GetSize(); | ||
| constexpr unsigned BORDER_COLOR = 0xFFFF0000; // Red with full alpha | ||
|
|
||
| const int w = mapSize.x; | ||
| const int h = mapSize.y; | ||
|
|
||
| for(const auto& ptWithRadius : pts) | ||
| { | ||
| if(ptWithRadius.second != radius) | ||
| continue; | ||
|
|
||
| const MapPoint& basePt = ptWithRadius.first; | ||
|
|
||
| // Draw at all 9 toroidal copies (canonical ± 1 map dimension). | ||
| // Using all copies guarantees the ring is continuous across the seam | ||
| // regardless of viewport position — the renderer clips off-screen pixels. | ||
| for(int dw : {-w, 0, w}) | ||
| { | ||
| for(int dh : {-h, 0, h}) | ||
| { | ||
| const MapPoint copyPt = MakeMapPoint(Position(basePt.x + dw, basePt.y + dh), mapSize); | ||
| const auto alt = world.GetNode(copyPt).altitude; | ||
| const DrawPoint scr = GetNodePos(copyPt) - DrawPoint(0, HEIGHT_FACTOR * alt) - offset; | ||
| Window::DrawRectangle(Rect(scr - DrawPoint(2, 2), Extent(5, 5)), BORDER_COLOR); | ||
| } | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is indeed hard. You can use the I don't think it gets better than that: You have to draw possibly all copies when the zoom factor is large which it seems is also not yet taken into account. Possibly even that is not enough.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found that s25edit draws a brush under the cursor which is resizeable by numpad +/- and based the radius outline drawing on that! |
||
| } | ||
| } | ||
|
|
||
| void GameWorldView::CalcFxLx() | ||
| { | ||
| // Calc first and last point in map units (with 1 extra for incomplete triangles) | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm hunters look for animals in a SQUARE?
Should fix to be circle? Kinda out of scope but can include or do separate PR. Cause right now the range outline doesn't match what game uses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created PR #1948 to make Hunters use circle instead of square.