-
Notifications
You must be signed in to change notification settings - Fork 99
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 all commits
fa453a0
3175b05
d489b4c
5728636
d6c53b8
11df35a
0572598
cfebdce
795a110
bdfd9b1
7957d83
1f70192
4f4fa6e
7ec4ce5
ab91acd
16840a8
0ed0c34
e4df373
675e474
0f408f0
caef896
ae81945
93246c4
83752d2
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 | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||||
| // Copyright (C) 2005 - 2026 Settlers Freaks (sf-team at siedler25.org) | ||||||||
| // | ||||||||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||||||||
|
|
||||||||
| #pragma once | ||||||||
|
|
||||||||
| #include "AddonBool.h" | ||||||||
| #include "mygettext/mygettext.h" | ||||||||
|
|
||||||||
| /** | ||||||||
| * Show building radius information in tooltips and as map overlay | ||||||||
| */ | ||||||||
| class AddonBuildingRadius : public AddonBool | ||||||||
| { | ||||||||
| public: | ||||||||
| AddonBuildingRadius() | ||||||||
| : AddonBool(AddonId::BUILDING_RADIUS, AddonGroup::GamePlay, _("Show building radius"), | ||||||||
| _("Shows the working radius of buildings in the build menu tooltip and as an overlay on the map " | ||||||||
| "when hovering over a building icon or selecting a building."), | ||||||||
| 1) // Enabled by default | ||||||||
|
Comment on lines
+19
to
+20
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.
Suggested change
The convention is that the default is S2-like behavior, so you can "disable" all addons and get vanilla S2
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. Yeah can revert this. Making it default enabled allowed me to continue using my save game for testing tho so it's been nice. Also playing campaign with it enabled is lovely. I'm addicted I can't play without it. Let's revert to default disable last thing before merge ok? |
||||||||
| {} | ||||||||
| }; | ||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -750,6 +750,9 @@ bool dskGameInterface::Msg_LeftUp(const MouseCoords& mc) | |||||
|
|
||||||
| bool dskGameInterface::Msg_MouseMove(const MouseCoords& mc) | ||||||
| { | ||||||
| // Update radius preview for buildings under the cursor (event-driven, not in draw loop) | ||||||
|
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. Make sure to clean such "intermediate" comments from AI
Suggested change
|
||||||
| gwv.UpdateRadiusPreviewForMousePos(mc.pos); | ||||||
|
|
||||||
| if(!isScrolling) | ||||||
| { | ||||||
| if(mc.num_tfingers == 1) | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |||||||||
| #include "nodeObjs/noFlag.h" | ||||||||||
| #include "gameData/BuildingConsts.h" | ||||||||||
| #include "gameData/const_gui_ids.h" | ||||||||||
| #include <boost/format.hpp> | ||||||||||
| #include <sstream> | ||||||||||
|
|
||||||||||
| // Tab - Flags | ||||||||||
|
|
@@ -46,7 +47,7 @@ enum TabID | |||||||||
| iwAction::iwAction(GameInterface& gi, GameWorldView& gwv, const Tabs& tabs, MapPoint selectedPt, | ||||||||||
| const DrawPoint& mousePos, Params params, bool military_buildings) | ||||||||||
| : IngameWindow(CGI_ACTION, mousePos, Extent(200, 254), _("Activity window"), LOADER.GetImageN("io", 1)), gi(gi), | ||||||||||
| gwv(gwv), selectedPt(selectedPt), mousePosAtOpen_(mousePos) | ||||||||||
| gwv(gwv), selectedPt(selectedPt), mousePosAtOpen_(mousePos), activeHoveredIcon_(nullptr) | ||||||||||
| { | ||||||||||
| /* | ||||||||||
| TAB_FLAG 1 = Land road | ||||||||||
|
|
@@ -159,6 +160,7 @@ iwAction::iwAction(GameInterface& gi, GameWorldView& gwv, const Tabs& tabs, MapP | |||||||||
| building_available[BuildingType::LeatherWorks] = false; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const bool showBuildingRadius = gwv.GetWorld().GetGGS().isEnabled(AddonId::BUILDING_RADIUS); | ||||||||||
| constexpr helpers::EnumArray<unsigned, BuildTab> NUM_TABS = {1, 2, 3, 1, 3}; | ||||||||||
|
|
||||||||||
| for(unsigned char i = 0; i < NUM_TABS[tabs.build_tabs]; ++i) | ||||||||||
|
|
@@ -175,6 +177,13 @@ iwAction::iwAction(GameInterface& gi, GameWorldView& gwv, const Tabs& tabs, MapP | |||||||||
| std::stringstream tooltip; | ||||||||||
| tooltip << _(BUILDING_NAMES[bld]); | ||||||||||
|
|
||||||||||
| // Radius anzeigen falls vorhanden | ||||||||||
|
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. English comments only (at least for new/changed ones) |
||||||||||
| unsigned radius = 0; | ||||||||||
| if(showBuildingRadius) | ||||||||||
| radius = GetBuildingRadius(bld); | ||||||||||
|
Comment on lines
+181
to
+183
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. Prefer const variables:
Suggested change
|
||||||||||
| if(radius > 0) | ||||||||||
| tooltip << boost::format(_("\nRange: %1% tiles")) % radius; | ||||||||||
|
|
||||||||||
| tooltip << _("\nCosts: "); | ||||||||||
| if(BUILDING_COSTS[bld].boards > 0) | ||||||||||
| tooltip << (int)BUILDING_COSTS[bld].boards << _(" boards"); | ||||||||||
|
|
@@ -186,8 +195,26 @@ iwAction::iwAction(GameInterface& gi, GameWorldView& gwv, const Tabs& tabs, MapP | |||||||||
| } | ||||||||||
|
|
||||||||||
| DrawPoint iconPos((k % 5) * 36, (k / 5) * 36 + 45); | ||||||||||
| build_tab->GetGroup(static_cast<int>(bt)) | ||||||||||
| ->AddBuildingIcon(k, iconPos, bld, player.nation, 36, tooltip.str()); | ||||||||||
| ctrlBuildingIcon* icon = build_tab->GetGroup(static_cast<int>(bt)) | ||||||||||
| ->AddBuildingIcon(k, iconPos, bld, player.nation, 36, tooltip.str()); | ||||||||||
|
|
||||||||||
| // Store hover callback; activeHoveredIcon_ guards against stale leaves from | ||||||||||
| // reversed child iteration order in Msg_MouseMove dispatch | ||||||||||
|
Comment on lines
+201
to
+202
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. Similar AI comment unless I'm missing something this is completely redundant
Suggested change
|
||||||||||
| if(radius > 0) | ||||||||||
| { | ||||||||||
| icon->SetOnHoverChanged([this, icon, radius](bool hovered) noexcept { | ||||||||||
| if(hovered) | ||||||||||
| { | ||||||||||
| this->activeHoveredIcon_ = icon; | ||||||||||
| this->gwv.SetRadiusPreview(std::make_pair(this->selectedPt, radius)); | ||||||||||
| } else if(this->activeHoveredIcon_ == icon) | ||||||||||
| { | ||||||||||
| this->activeHoveredIcon_ = nullptr; | ||||||||||
| this->gwv.SetRadiusPreview(std::nullopt); | ||||||||||
| } | ||||||||||
| // else: stale leave from a previously-hovered icon, ignore | ||||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| ++k; | ||||||||||
| } | ||||||||||
|
|
@@ -407,6 +434,8 @@ void iwAction::Close() | |||||||||
| { | ||||||||||
| if(ShouldBeClosed()) | ||||||||||
| return; | ||||||||||
| activeHoveredIcon_ = nullptr; | ||||||||||
| gwv.SetRadiusPreview(std::nullopt); | ||||||||||
| IngameWindow::Close(); | ||||||||||
| if(mousePosAtOpen_.isValid()) | ||||||||||
| VIDEODRIVER.SetMousePos(mousePosAtOpen_); | ||||||||||
|
|
@@ -526,6 +555,7 @@ void iwAction::Msg_Group_TabChange(const unsigned /*group_id*/, const unsigned c | |||||||||
| void iwAction::Msg_PaintAfter() | ||||||||||
| { | ||||||||||
| IngameWindow::Msg_PaintAfter(); | ||||||||||
|
|
||||||||||
| auto* tab = GetCtrl<ctrlTab>(0); | ||||||||||
| if(tab) | ||||||||||
| { | ||||||||||
|
|
||||||||||
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.
This doesn't seem correct. Please revert
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.
This is to allow default enabled addons.
Ok I find it very useful to have it default enabled for testing. Can we revert this last thing before merge.