Skip to content
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

Synchronize game world view HUD visibility settings #1613

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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