Skip to content

Commit

Permalink
Fix button placement in minimized in-game windows
Browse files Browse the repository at this point in the history
Some windows position their buttons based on GetSize().y, which results
in incorrect placement if the window is persisted and minimized.
Replace uses of GetSize().y with the full window height.

Affected windows:
* iwBuildings
* iwDistribution
* iwWares
  • Loading branch information
falbrechtskirchinger committed Jul 25, 2023
1 parent 5907058 commit bb146d7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
18 changes: 11 additions & 7 deletions libs/s25main/ingameWindows/iwBuildings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#include "gameData/BuildingProperties.h"
#include "gameData/const_gui_ids.h"

namespace {
/// Reihenfolge der Gebäude
const std::array<BuildingType, 32> bts = {
constexpr std::array<BuildingType, 32> bts = {
BuildingType::Barracks, BuildingType::Guardhouse, BuildingType::Watchtower, BuildingType::Fortress,
BuildingType::GraniteMine, BuildingType::CoalMine, BuildingType::IronMine, BuildingType::GoldMine,
BuildingType::LookoutTower, BuildingType::Catapult, BuildingType::Woodcutter, BuildingType::Fishery,
Expand All @@ -41,14 +42,17 @@ const std::array<BuildingType, 32> bts = {
};

// Abstand des ersten Icons vom linken oberen Fensterrand
const DrawPoint iconPadding(30, 40);
constexpr DrawPoint iconPadding(30, 40);
// Abstand der einzelnen Symbole untereinander
const DrawPoint iconSpacing(40, 48);
constexpr DrawPoint iconSpacing(40, 48);
// Abstand der Schriften unter den Icons
const unsigned short font_distance_y = 20;
constexpr unsigned short font_distance_y = 20;

constexpr auto BuildingsWindowSize = Extent(185, 480);
} // namespace

iwBuildings::iwBuildings(GameWorldView& gwv, GameCommandFactory& gcFactory)
: IngameWindow(CGI_BUILDINGS, IngameWindow::posLastOrCenter, Extent(185, 480), _("Buildings"),
: IngameWindow(CGI_BUILDINGS, IngameWindow::posLastOrCenter, BuildingsWindowSize, _("Buildings"),
LOADER.GetImageN("resource", 41)),
gwv(gwv), gcFactory(gcFactory)
{
Expand All @@ -69,8 +73,8 @@ iwBuildings::iwBuildings(GameWorldView& gwv, GameCommandFactory& gcFactory)

// Hilfe-Button
Extent btSize = Extent(30, 32);
AddImageButton(32, GetSize() - DrawPoint(14, 20) - btSize, btSize, TextureColor::Grey, LOADER.GetImageN("io", 225),
_("Help"));
AddImageButton(32, BuildingsWindowSize - DrawPoint(14, 20) - btSize, btSize, TextureColor::Grey,
LOADER.GetImageN("io", 225), _("Help"));

Check warning on line 77 in libs/s25main/ingameWindows/iwBuildings.cpp

View check run for this annotation

Codecov / codecov/patch

libs/s25main/ingameWindows/iwBuildings.cpp#L76-L77

Added lines #L76 - L77 were not covered by tests
}

/// Anzahlen der Gebäude zeichnen
Expand Down
14 changes: 9 additions & 5 deletions libs/s25main/ingameWindows/iwDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ struct iwDistribution::DistributionGroup
};
std::vector<iwDistribution::DistributionGroup> iwDistribution::groups;

namespace {
/// Dertermines width of the progress bars: distance to the window borders
const unsigned PROGRESS_BORDER_DISTANCE = 20;
constexpr unsigned PROGRESS_BORDER_DISTANCE = 20;

constexpr auto DistributionWindowSize = Extent(290, 312);
} // namespace

iwDistribution::iwDistribution(const GameWorldViewer& gwv, GameCommandFactory& gcFactory)
: TransmitSettingsIgwAdapter(CGI_DISTRIBUTION, IngameWindow::posLastOrCenter, Extent(290, 312),
: TransmitSettingsIgwAdapter(CGI_DISTRIBUTION, IngameWindow::posLastOrCenter, DistributionWindowSize,
_("Distribution of goods"), LOADER.GetImageN("resource", 41)),
gwv(gwv), gcFactory(gcFactory)
{
Expand Down Expand Up @@ -63,11 +67,11 @@ iwDistribution::iwDistribution(const GameWorldViewer& gwv, GameCommandFactory& g

const Extent btSize(32, 32);
// Hilfe
AddImageButton(2, DrawPoint(15, GetSize().y - 15 - btSize.y), btSize, TextureColor::Grey,
AddImageButton(2, DrawPoint(15, DistributionWindowSize.y - 15 - btSize.y), btSize, TextureColor::Grey,

Check warning on line 70 in libs/s25main/ingameWindows/iwDistribution.cpp

View check run for this annotation

Codecov / codecov/patch

libs/s25main/ingameWindows/iwDistribution.cpp#L70

Added line #L70 was not covered by tests
LOADER.GetImageN("io", 225), _("Help"));
// Standardbelegung
AddImageButton(10, GetSize() - DrawPoint::all(15) - btSize, btSize, TextureColor::Grey, LOADER.GetImageN("io", 191),
_("Default"));
AddImageButton(10, DistributionWindowSize - DrawPoint::all(15) - btSize, btSize, TextureColor::Grey,
LOADER.GetImageN("io", 191), _("Default"));

Check warning on line 74 in libs/s25main/ingameWindows/iwDistribution.cpp

View check run for this annotation

Codecov / codecov/patch

libs/s25main/ingameWindows/iwDistribution.cpp#L73-L74

Added lines #L73 - L74 were not covered by tests

iwDistribution::UpdateSettings();
}
Expand Down
4 changes: 2 additions & 2 deletions libs/s25main/ingameWindows/iwWares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ iwWares::iwWares(unsigned id, const DrawPoint& pos, const Extent& size, const st
}

// "Blättern"
AddImageButton(0, DrawPoint(52, GetSize().y - 47), Extent(66, 32), TextureColor::Grey, LOADER.GetImageN("io", 84),
AddImageButton(0, DrawPoint(52, size.y - 47), Extent(66, 32), TextureColor::Grey, LOADER.GetImageN("io", 84),

Check warning on line 134 in libs/s25main/ingameWindows/iwWares.cpp

View check run for this annotation

Codecov / codecov/patch

libs/s25main/ingameWindows/iwWares.cpp#L134

Added line #L134 was not covered by tests
_("Next page"));
// Hilfe
AddImageButton(12, DrawPoint(16, GetSize().y - 47), Extent(32, 32), TextureColor::Grey, LOADER.GetImageN("io", 225),
AddImageButton(12, DrawPoint(16, size.y - 47), Extent(32, 32), TextureColor::Grey, LOADER.GetImageN("io", 225),

Check warning on line 137 in libs/s25main/ingameWindows/iwWares.cpp

View check run for this annotation

Codecov / codecov/patch

libs/s25main/ingameWindows/iwWares.cpp#L137

Added line #L137 was not covered by tests
_("Help"));

waresPage.SetVisible(true);
Expand Down

0 comments on commit bb146d7

Please sign in to comment.