Skip to content

Commit

Permalink
Synchronize HUD visibility settings
Browse files Browse the repository at this point in the history
Synchronize visibility of game world view HUD elements from parent to
child views.
  • Loading branch information
falbrechtskirchinger authored and Flamefire committed Jul 26, 2023
1 parent 48bc284 commit 25dca9a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
5 changes: 5 additions & 0 deletions libs/s25main/ingameWindows/iwObservate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ iwObservate::iwObservate(GameWorldView& gwv, const MapPoint selectedPt)
// Fenster vergroessern/verkleinern
btPos.x += btSize.x;
AddImageButton(4, btPos, btSize, TextureColor::Grey, LOADER.GetImageN("io", 109), _("Resize window"));

// Synchronize visibility of HUD elements with parentView
parentView.CopyHudSettingsTo(*view, false);
gwvSettingsConnection =
parentView.onHudSettingsChanged.connect([this]() { parentView.CopyHudSettingsTo(*view, false); });
}

void iwObservate::Msg_ButtonClick(const unsigned ctrl_id)
Expand Down
3 changes: 3 additions & 0 deletions libs/s25main/ingameWindows/iwObservate.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "IngameWindow.h"
#include "gameTypes/MapCoordinates.h"
#include <boost/signals2.hpp>

class GameWorldView;
class MouseCoords;
Expand All @@ -30,6 +31,8 @@ class iwObservate : public IngameWindow
/// id of object currently followed or INVALID_ID
unsigned followMovableId;

boost::signals2::scoped_connection gwvSettingsConnection;

public:
iwObservate(GameWorldView& gwv, MapPoint selectedPt);

Expand Down
30 changes: 29 additions & 1 deletion libs/s25main/world/GameWorldView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,14 +545,42 @@ void GameWorldView::DrawBoundaryStone(const MapPoint& pt, const DrawPoint pos, V
}
}

/// Schaltet Produktivitäten/Namen komplett aus oder an
void GameWorldView::ToggleShowBQ()
{
show_bq = !show_bq;
SaveIngameSettingsValues();
onHudSettingsChanged();
}

void GameWorldView::ToggleShowNames()
{
show_names = !show_names;
SaveIngameSettingsValues();
onHudSettingsChanged();
}

void GameWorldView::ToggleShowProductivity()
{
show_productivity = !show_productivity;
SaveIngameSettingsValues();
onHudSettingsChanged();
}

void GameWorldView::ToggleShowNamesAndProductivity()
{
if(show_productivity && show_names)
show_productivity = show_names = false;
else
show_productivity = show_names = true;
SaveIngameSettingsValues();
onHudSettingsChanged();
}

void GameWorldView::CopyHudSettingsTo(GameWorldView& other, bool copyBQ) const
{
other.show_bq = (copyBQ ? show_bq : false);
other.show_names = show_names;
other.show_productivity = show_productivity;
}

void GameWorldView::MoveBy(const DrawPoint& numPixels)
Expand Down
33 changes: 14 additions & 19 deletions libs/s25main/world/GameWorldView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "DrawPoint.h"
#include "gameTypes/MapCoordinates.h"
#include "gameTypes/MapTypes.h"
#include <boost/signals2.hpp>
#include <vector>

class GameWorldBase;
Expand Down Expand Up @@ -80,27 +81,18 @@ class GameWorldView
float GetCurrentTargetZoomFactor() const;
void SetNextZoomFactor();

/// Bauqualitäten anzeigen oder nicht
void ToggleShowBQ()
{
show_bq = !show_bq;
SaveIngameSettingsValues();
}
/// Gebäudenamen zeigen oder nicht
void ToggleShowNames()
{
show_names = !show_names;
SaveIngameSettingsValues();
}
/// Produktivität zeigen oder nicht
void ToggleShowProductivity()
{
show_productivity = !show_productivity;
SaveIngameSettingsValues();
};
/// Schaltet Produktivitäten/Namen komplett aus oder an
/// Show or hide construction aid
void ToggleShowBQ();
/// Show or hide building names
void ToggleShowNames();
/// Show or hide productivity
void ToggleShowProductivity();
/// Toggle names and productivity completely on or off
void ToggleShowNamesAndProductivity();

/// Copy visibility of HUD elements from this view to another
void CopyHudSettingsTo(GameWorldView& other, bool copyBQ) const;

void Draw(const RoadBuildState& rb, MapPoint selected, bool drawMouse, unsigned* water = nullptr);

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

void Resize(const Extent& newSize);

/// Triggered when visibility of HUD elements changes
boost::signals2::signal<void()> onHudSettingsChanged;

private:
void CalcFxLx();
void DrawBoundaryStone(const MapPoint& pt, DrawPoint pos, Visibility vis);
Expand Down

0 comments on commit 25dca9a

Please sign in to comment.