Skip to content

Commit 25dca9a

Browse files
falbrechtskirchingerFlamefire
authored andcommitted
Synchronize HUD visibility settings
Synchronize visibility of game world view HUD elements from parent to child views.
1 parent 48bc284 commit 25dca9a

4 files changed

Lines changed: 51 additions & 20 deletions

File tree

libs/s25main/ingameWindows/iwObservate.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ iwObservate::iwObservate(GameWorldView& gwv, const MapPoint selectedPt)
4848
// Fenster vergroessern/verkleinern
4949
btPos.x += btSize.x;
5050
AddImageButton(4, btPos, btSize, TextureColor::Grey, LOADER.GetImageN("io", 109), _("Resize window"));
51+
52+
// Synchronize visibility of HUD elements with parentView
53+
parentView.CopyHudSettingsTo(*view, false);
54+
gwvSettingsConnection =
55+
parentView.onHudSettingsChanged.connect([this]() { parentView.CopyHudSettingsTo(*view, false); });
5156
}
5257

5358
void iwObservate::Msg_ButtonClick(const unsigned ctrl_id)

libs/s25main/ingameWindows/iwObservate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "IngameWindow.h"
88
#include "gameTypes/MapCoordinates.h"
9+
#include <boost/signals2.hpp>
910

1011
class GameWorldView;
1112
class MouseCoords;
@@ -30,6 +31,8 @@ class iwObservate : public IngameWindow
3031
/// id of object currently followed or INVALID_ID
3132
unsigned followMovableId;
3233

34+
boost::signals2::scoped_connection gwvSettingsConnection;
35+
3336
public:
3437
iwObservate(GameWorldView& gwv, MapPoint selectedPt);
3538

libs/s25main/world/GameWorldView.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,14 +545,42 @@ void GameWorldView::DrawBoundaryStone(const MapPoint& pt, const DrawPoint pos, V
545545
}
546546
}
547547

548-
/// Schaltet Produktivitäten/Namen komplett aus oder an
548+
void GameWorldView::ToggleShowBQ()
549+
{
550+
show_bq = !show_bq;
551+
SaveIngameSettingsValues();
552+
onHudSettingsChanged();
553+
}
554+
555+
void GameWorldView::ToggleShowNames()
556+
{
557+
show_names = !show_names;
558+
SaveIngameSettingsValues();
559+
onHudSettingsChanged();
560+
}
561+
562+
void GameWorldView::ToggleShowProductivity()
563+
{
564+
show_productivity = !show_productivity;
565+
SaveIngameSettingsValues();
566+
onHudSettingsChanged();
567+
}
568+
549569
void GameWorldView::ToggleShowNamesAndProductivity()
550570
{
551571
if(show_productivity && show_names)
552572
show_productivity = show_names = false;
553573
else
554574
show_productivity = show_names = true;
555575
SaveIngameSettingsValues();
576+
onHudSettingsChanged();
577+
}
578+
579+
void GameWorldView::CopyHudSettingsTo(GameWorldView& other, bool copyBQ) const
580+
{
581+
other.show_bq = (copyBQ ? show_bq : false);
582+
other.show_names = show_names;
583+
other.show_productivity = show_productivity;
556584
}
557585

558586
void GameWorldView::MoveBy(const DrawPoint& numPixels)

libs/s25main/world/GameWorldView.h

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "DrawPoint.h"
88
#include "gameTypes/MapCoordinates.h"
99
#include "gameTypes/MapTypes.h"
10+
#include <boost/signals2.hpp>
1011
#include <vector>
1112

1213
class GameWorldBase;
@@ -80,27 +81,18 @@ class GameWorldView
8081
float GetCurrentTargetZoomFactor() const;
8182
void SetNextZoomFactor();
8283

83-
/// Bauqualitäten anzeigen oder nicht
84-
void ToggleShowBQ()
85-
{
86-
show_bq = !show_bq;
87-
SaveIngameSettingsValues();
88-
}
89-
/// Gebäudenamen zeigen oder nicht
90-
void ToggleShowNames()
91-
{
92-
show_names = !show_names;
93-
SaveIngameSettingsValues();
94-
}
95-
/// Produktivität zeigen oder nicht
96-
void ToggleShowProductivity()
97-
{
98-
show_productivity = !show_productivity;
99-
SaveIngameSettingsValues();
100-
};
101-
/// Schaltet Produktivitäten/Namen komplett aus oder an
84+
/// Show or hide construction aid
85+
void ToggleShowBQ();
86+
/// Show or hide building names
87+
void ToggleShowNames();
88+
/// Show or hide productivity
89+
void ToggleShowProductivity();
90+
/// Toggle names and productivity completely on or off
10291
void ToggleShowNamesAndProductivity();
10392

93+
/// Copy visibility of HUD elements from this view to another
94+
void CopyHudSettingsTo(GameWorldView& other, bool copyBQ) const;
95+
10496
void Draw(const RoadBuildState& rb, MapPoint selected, bool drawMouse, unsigned* water = nullptr);
10597

10698
/// Moves the map view by the given offset in pixels
@@ -128,6 +120,9 @@ class GameWorldView
128120

129121
void Resize(const Extent& newSize);
130122

123+
/// Triggered when visibility of HUD elements changes
124+
boost::signals2::signal<void()> onHudSettingsChanged;
125+
131126
private:
132127
void CalcFxLx();
133128
void DrawBoundaryStone(const MapPoint& pt, DrawPoint pos, Visibility vis);

0 commit comments

Comments
 (0)