• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Return-To-The-Roots / s25client / 19143370511

06 Nov 2025 04:56PM UTC coverage: 50.065%. First build
19143370511

Pull #1720

github

web-flow
Merge a3d378e6e into 7333cc249
Pull Request #1720: Add leather addon

304 of 1117 new or added lines in 66 files covered. (27.22%)

22729 of 45399 relevant lines covered (50.06%)

36159.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/s25main/ingameWindows/iwBuildings.cpp
1
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "iwBuildings.h"
6
#include "AddonHelperFunctions.h"
7
#include "GamePlayer.h"
8
#include "GlobalGameSettings.h"
9
#include "LeatherLoader.h"
10
#include "Loader.h"
11
#include "WindowManager.h"
12
#include "WineLoader.h"
13
#include "addons/const_addons.h"
14
#include "buildings/nobBaseWarehouse.h"
15
#include "buildings/nobHarborBuilding.h"
16
#include "buildings/nobMilitary.h"
17
#include "buildings/nobUsual.h"
18
#include "files.h"
19
#include "iwBaseWarehouse.h"
20
#include "iwBuilding.h"
21
#include "iwHarborBuilding.h"
22
#include "iwHelp.h"
23
#include "iwMilitaryBuilding.h"
24
#include "iwTempleBuilding.h"
25
#include "ogl/FontStyle.h"
26
#include "ogl/glFont.h"
27
#include "world/GameWorldBase.h"
28
#include "world/GameWorldView.h"
29
#include "world/GameWorldViewer.h"
30
#include "gameTypes/BuildingCount.h"
31
#include "gameData/BuildingConsts.h"
32
#include "gameData/BuildingProperties.h"
33
#include "gameData/const_gui_ids.h"
34

35
void iwBuildings::setBuildingOrder()
×
36
{
37
    // Order of the buildings in which they will be shown
38
    bts = {
×
39
      BuildingType::Barracks,       BuildingType::Guardhouse, BuildingType::Watchtower,     BuildingType::Fortress,
40
      BuildingType::GraniteMine,    BuildingType::CoalMine,   BuildingType::IronMine,       BuildingType::GoldMine,
41
      BuildingType::LookoutTower,   BuildingType::Catapult,   BuildingType::Woodcutter,     BuildingType::Fishery,
42
      BuildingType::Quarry,         BuildingType::Forester,   BuildingType::Slaughterhouse, BuildingType::Hunter,
43
      BuildingType::Brewery,        BuildingType::Armory,     BuildingType::Metalworks,     BuildingType::Ironsmelter,
44
      BuildingType::PigFarm,
45
      BuildingType::Storehouse, // entry 21
46
      BuildingType::Mill,           BuildingType::Bakery,     BuildingType::Sawmill,        BuildingType::Mint,
47
      BuildingType::Well,           BuildingType::Shipyard,   BuildingType::Farm,           BuildingType::DonkeyBreeder,
48
      BuildingType::Charburner,
49
      BuildingType::HarborBuilding,                                                       // entry 31
50
      BuildingType::Vineyard,       BuildingType::Winery,     BuildingType::Temple,       // entry 34
51
      BuildingType::Skinner,        BuildingType::Tannery,    BuildingType::LeatherWorks, // entry 37
52
    };
×
53

NEW
54
    helpers::erase_if(bts, makeIsUnusedBuilding(gwv.GetWorld().GetGGS()));
×
55
}
×
56

57
// Abstand des ersten Icons vom linken oberen Fensterrand
58
const Extent bldContentOffset(30, 40);
59
// Abstand der einzelnen Symbole untereinander
60
const Extent iconSpacing(40, 48);
61
// Abstand der Schriften unter den Icons
62
const unsigned short font_distance_y = 20;
63

64
namespace {
65
enum
66
{
67
    ID_Help,
68
    ID_BuildingsStart,
69
};
70
}
71

72
iwBuildings::iwBuildings(GameWorldView& gwv, GameCommandFactory& gcFactory)
×
73
    : IngameWindow(CGI_BUILDINGS, IngameWindow::posLastOrCenter, Extent(185, 480), _("Buildings"),
×
74
                   LOADER.GetImageN("resource", 41)),
×
75
      gwv(gwv), gcFactory(gcFactory)
×
76
{
77
    setBuildingOrder();
×
78
    Resize(iconSpacing * Extent(4, helpers::divCeil(bts.size(), 4) + 1) + bldContentOffset);
×
79

80
    const Nation playerNation = gwv.GetViewer().GetPlayer().nation;
×
81
    // Symbole für die einzelnen Gebäude erstellen
82
    for(unsigned y = 0; y < bts.size() / 4 + (bts.size() % 4 > 0 ? 1 : 0); ++y)
×
83
    {
84
        for(unsigned x = 0; x < 4; ++x)
×
85
        {
86
            if(y * 4 + x >= bts.size()) //-V547
×
87
                break;
×
88

89
            Extent btSize = Extent(32, 32);
×
90
            DrawPoint btPos = bldContentOffset - btSize / 2 + iconSpacing * DrawPoint(x, y);
×
NEW
91
            AddImageButton(ID_BuildingsStart + y * 4 + x, btPos, btSize, TextureColor::Grey,
×
92
                           LOADER.GetNationIcon(playerNation, bts[y * 4 + x]), _(BUILDING_NAMES[bts[y * 4 + x]]));
×
93
        }
94
    }
95

96
    // "Help" button
97
    Extent btSize = Extent(30, 32);
×
NEW
98
    AddImageButton(ID_Help, GetFullSize() - DrawPoint(14, 20) - btSize, btSize, TextureColor::Grey,
×
99
                   LOADER.GetImageN("io", 225), _("Help"));
×
100
}
×
101

102
/// Anzahlen der Gebäude zeichnen
103
void iwBuildings::Msg_PaintAfter()
×
104
{
105
    static boost::format fmt("%1%/%2%");
×
106
    IngameWindow::Msg_PaintAfter();
×
107
    // Anzahlen herausfinden
108
    BuildingCount bc = gwv.GetViewer().GetPlayer().GetBuildingRegister().GetBuildingNums();
×
109

110
    // Anzahlen unter die Gebäude schreiben
111
    DrawPoint rowPos = GetDrawPos() + bldContentOffset + DrawPoint(0, font_distance_y);
×
112
    for(unsigned y = 0; y < helpers::divCeil(bts.size(), 4); ++y)
×
113
    {
114
        DrawPoint curPos = rowPos;
×
115
        for(unsigned x = 0; x < 4; x++)
×
116
        {
117
            if(y * 4 + x >= bts.size()) //-V547
×
118
                break;
×
119

120
            fmt % bc.buildings[bts[y * 4 + x]] % bc.buildingSites[bts[y * 4 + x]];
×
121
            NormalFont->Draw(curPos, fmt.str(), FontStyle::CENTER, COLOR_YELLOW);
×
122
            curPos.x += iconSpacing.x;
×
123
        }
124
        rowPos.y += iconSpacing.y;
×
125
    }
126
}
×
127

128
void iwBuildings::Msg_ButtonClick(const unsigned ctrl_id)
×
129
{
NEW
130
    if(ctrl_id == ID_Help) // Help button
×
131
    {
132
        WINDOWMANAGER.ReplaceWindow(
×
133
          std::make_unique<iwHelp>(_("The building statistics window gives you an insight into "
×
134
                                     "the number of buildings you have, by type. The number on "
135
                                     "the left is the total number of this type of building "
136
                                     "completed, the number on the right shows how many are "
137
                                     "currently under construction.")));
×
138
        return;
×
139
    }
140

141
    // no buildings of type complete? -> do nothing
142
    const GamePlayer& localPlayer = gwv.GetViewer().GetPlayer();
×
143
    const BuildingRegister& buildingRegister = localPlayer.GetBuildingRegister();
×
144

NEW
145
    BuildingType bldType = bts[ctrl_id - ID_BuildingsStart];
×
146
    if(BuildingProperties::IsMilitary(bldType))
×
147
        GoToFirstMatching<iwMilitaryBuilding>(bldType, buildingRegister.GetMilitaryBuildings());
×
148
    else if(bldType == BuildingType::HarborBuilding)
×
149
        GoToFirstMatching<iwHarborBuilding>(bldType, buildingRegister.GetHarbors());
×
150
    else if(BuildingProperties::IsWareHouse(bldType))
×
151
        GoToFirstMatching<iwBaseWarehouse>(bldType, buildingRegister.GetStorehouses());
×
152
    else if(bldType == BuildingType::Temple)
×
153
        GoToFirstMatching<iwTempleBuilding>(bldType, buildingRegister.GetBuildings(bldType));
×
154
    else
155
        GoToFirstMatching<iwBuilding>(bldType, buildingRegister.GetBuildings(bldType));
×
156
}
157

158
template<class T_Window, class T_Building>
159
void iwBuildings::GoToFirstMatching(BuildingType bldType, const std::list<T_Building*>& blds)
×
160
{
161
    for(T_Building* bld : blds)
×
162
    {
163
        if(bld->GetBuildingType() == bldType)
×
164
        {
165
            gwv.MoveToMapPt(bld->GetPos());
×
166
            auto nextscrn = std::make_unique<T_Window>(gwv, gcFactory, static_cast<T_Building*>(bld));
×
167
            nextscrn->SetPos(GetPos());
×
168
            WINDOWMANAGER.ReplaceWindow(std::move(nextscrn));
×
169
            return;
×
170
        }
171
    }
172
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc