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

Return-To-The-Roots / s25client / 20956918287

13 Jan 2026 12:35PM UTC coverage: 50.573% (+0.01%) from 50.562%
20956918287

Pull #1858

github

web-flow
Merge 16052f239 into 771c60533
Pull Request #1858: Add tooltips for temple and shipyard production toggle buttons and fix translations

0 of 2 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

22576 of 44640 relevant lines covered (50.57%)

36307.6 hits per line

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

0.0
/libs/s25main/ingameWindows/iwBuilding.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 "iwBuilding.h"
6
#include "GamePlayer.h"
7
#include "Loader.h"
8
#include "WindowManager.h"
9
#include "buildings/nobShipYard.h"
10
#include "controls/ctrlImageButton.h"
11
#include "controls/ctrlPercent.h"
12
#include "controls/ctrlText.h"
13
#include "factories/GameCommandFactory.h"
14
#include "helpers/containerUtils.h"
15
#include "iwDemolishBuilding.h"
16
#include "iwHelp.h"
17
#include "iwTempleBuilding.h"
18
#include "ogl/FontStyle.h"
19
#include "ogl/glArchivItem_Bitmap.h"
20
#include "ogl/glFont.h"
21
#include "world/GameWorldBase.h"
22
#include "world/GameWorldView.h"
23
#include "gameData/BuildingConsts.h"
24
#include "gameData/BuildingProperties.h"
25
#include "gameData/const_gui_ids.h"
26
#include <sstream>
27

28
/// IDs in der IO_DAT von Boot und Schiffs-Bild für den Umschaltebutton beim Schiffsbauer
29
const unsigned IODAT_BOAT_ID = 219;
30
const unsigned IODAT_SHIP_ID = 218;
31

32
iwBuilding::iwBuilding(GameWorldView& gwv, GameCommandFactory& gcFactory, nobUsual* const building, Extent extent)
×
33
    : IngameWindow(CGI_BUILDING + MapBase::CreateGUIID(building->GetPos()), IngameWindow::posAtMouse, extent,
×
34
                   _(BUILDING_NAMES[building->GetBuildingType()]), LOADER.GetImageN("resource", 41)),
×
35
      gwv(gwv), gcFactory(gcFactory), building(building)
×
36
{
37
    // Arbeitersymbol
38
    AddImage(0, DrawPoint(28, 39), LOADER.GetMapTexture(2298));
×
39

40
    if(const auto job = BLD_WORK_DESC[building->GetBuildingType()].job)
×
41
        AddImage(13, DrawPoint(28, 39), LOADER.GetJobTex(*job));
×
42

43
    // Gebäudesymbol
44
    AddImage(1, DrawPoint(117, 114), &building->GetBuildingImage());
×
45

46
    // Symbol der produzierten Ware (falls hier was produziert wird)
47
    const auto& producedWare = BLD_WORK_DESC[building->GetBuildingType()].producedWare;
×
48
    ITexture* tex = visit(
×
49
      composeVisitor([](GoodType gt) -> ITexture* { return gt != GoodType::Nothing ? LOADER.GetWareTex(gt) : nullptr; },
×
50
                     [](Job job) -> ITexture* { return LOADER.GetJobTex(job); },
×
51
                     [](boost::none_t) -> ITexture* { return nullptr; }),
×
52
      producedWare);
53
    if(tex)
×
54
    {
55
        AddImage(2, DrawPoint(196, 39), LOADER.GetMapTexture(2298));
×
56
        AddImage(3, DrawPoint(196, 39), tex);
×
57
    }
58

59
    // Info
60
    AddImageButton(4, DrawPoint(16, extent.y - 47), Extent(30, 32), TextureColor::Grey, LOADER.GetImageN("io", 225),
×
61
                   _("Help"));
62
    // Abreißen
63
    AddImageButton(5, DrawPoint(50, extent.y - 47), Extent(34, 32), TextureColor::Grey, LOADER.GetImageN("io", 23),
×
64
                   _("Demolish house"));
65
    // Produktivität einstellen (196,197) (bei Spähturm ausblenden)
66
    Window* enable_productivity = AddImageButton(
×
67
      6, DrawPoint(90, extent.y - 47), Extent(34, 32), TextureColor::Grey,
×
68
      LOADER.GetImageN("io", ((building->IsProductionDisabledVirtual()) ? 197 : 196)), _("Production on/off"));
×
69
    if(building->GetBuildingType() == BuildingType::LookoutTower)
×
70
        enable_productivity->SetVisible(false);
×
71
    // Bei Bootsbauer Button zum Umwählen von Booten und Schiffen
72
    if(building->GetBuildingType() == BuildingType::Shipyard)
×
73
    {
74
        // Jenachdem Boot oder Schiff anzeigen
75
        unsigned io_dat_id =
76
          (static_cast<nobShipYard*>(building)->GetMode() == nobShipYard::Mode::Boats) ? IODAT_BOAT_ID : IODAT_SHIP_ID;
×
77
        AddImageButton(11, DrawPoint(130, extent.y - 47), Extent(43, 32), TextureColor::Grey,
×
NEW
78
                       LOADER.GetImageN("io", io_dat_id), _("Ships/Boats"));
×
79
    }
80

81
    // "Gehe Zum Ort"
82
    AddImageButton(7, DrawPoint(179, extent.y - 47), Extent(30, 32), TextureColor::Grey, LOADER.GetImageN("io", 107),
×
83
                   _("Go to place"));
84

85
    // Produktivitätsanzeige (bei Katapulten und Spähtürmen ausblenden)
86
    Window* productivity = AddPercent(9, DrawPoint(59, 31), Extent(106, 16), TextureColor::Grey, 0xFFFFFF00, SmallFont,
×
87
                                      building->GetProductivityPointer());
×
88
    if(building->GetBuildingType() == BuildingType::Catapult
×
89
       || building->GetBuildingType() == BuildingType::LookoutTower)
×
90
        productivity->SetVisible(false);
×
91

92
    AddText(10, DrawPoint(113, 50), _("(House unoccupied)"), COLOR_RED, FontStyle::CENTER, NormalFont);
×
93

94
    // "Go to next" (building of same type)
95
    AddImageButton(12, DrawPoint(179, extent.y - 79), Extent(30, 32), TextureColor::Grey,
×
96
                   LOADER.GetImageN("io_new", 11), _("Go to next building of same type"));
×
97
}
×
98

99
void iwBuilding::Msg_PaintBefore()
×
100
{
101
    IngameWindow::Msg_PaintBefore();
×
102

103
    // Haus unbesetzt ggf ausblenden
104
    GetCtrl<ctrlText>(10)->SetVisible(!building->HasWorker());
×
105
}
×
106

107
void iwBuilding::Msg_PaintAfter()
×
108
{
109
    IngameWindow::Msg_PaintAfter();
×
110
    const auto& bldWorkDesk = BLD_WORK_DESC[building->GetBuildingType()];
×
111
    if(BuildingProperties::IsMine(building->GetBuildingType()))
×
112
    {
113
        // Bei Bergwerken sieht die Nahrungsanzeige ein wenig anders aus (3x 2)
114

115
        // "Schwarzer Rahmen"
116
        DrawRectangle(Rect(GetDrawPos() + DrawPoint(40, 60), Extent(144, 24)), 0x80000000);
×
117
        DrawPoint curPos = GetDrawPos() + DrawPoint(52, 72);
×
118
        for(unsigned char i = 0; i < bldWorkDesk.waresNeeded.size(); ++i)
×
119
        {
120
            for(unsigned char z = 0; z < bldWorkDesk.numSpacesPerWare; ++z)
×
121
            {
122
                LOADER.GetWareTex(bldWorkDesk.waresNeeded[i])
×
123
                  ->DrawFull(curPos, (z < building->GetNumWares(i) ? 0xFFFFFFFF : 0xFF404040));
×
124
                curPos.x += 24;
×
125
            }
126
        }
127
    } else
128
    {
129
        DrawPoint curPos = GetDrawPos() + DrawPoint(GetSize().x / 2, 60);
×
130
        for(unsigned char i = 0; i < bldWorkDesk.waresNeeded.size(); ++i)
×
131
        {
132
            const unsigned wares_count = bldWorkDesk.numSpacesPerWare;
×
133

134
            // "Schwarzer Rahmen"
135
            DrawPoint waresPos = curPos - DrawPoint(24 * wares_count / 2, 0);
×
136
            DrawRectangle(Rect(waresPos, Extent(24 * wares_count, 24)), 0x80000000);
×
137
            waresPos += DrawPoint(12, 12);
×
138

139
            for(unsigned char z = 0; z < wares_count; ++z)
×
140
            {
141
                LOADER.GetWareTex(bldWorkDesk.waresNeeded[i])
×
142
                  ->DrawFull(waresPos, (z < building->GetNumWares(i) ? COLOR_WHITE : 0xFF404040));
×
143
                waresPos.x += 24;
×
144
            }
145

146
            std::stringstream text;
×
147
            text << (unsigned)building->GetNumWares(i) << "/" << wares_count;
×
148
            NormalFont->Draw(curPos + DrawPoint(0, 12), text.str(), FontStyle::CENTER | FontStyle::VCENTER);
×
149
            curPos.y += 29;
×
150
        }
151
    }
152
}
×
153

154
void iwBuilding::Msg_ButtonClick(const unsigned ctrl_id)
×
155
{
156
    switch(ctrl_id)
×
157
    {
158
        case 4: // Hilfe
×
159
        {
160
            WINDOWMANAGER.ReplaceWindow(
×
161
              std::make_unique<iwHelp>(_(BUILDING_HELP_STRINGS[building->GetBuildingType()])));
×
162
        }
163
        break;
×
164
        case 5: // Gebäude abbrennen
×
165
        {
166
            // Abreißen?
167
            Close();
×
168
            WINDOWMANAGER.Show(std::make_unique<iwDemolishBuilding>(gwv, building));
×
169
        }
170
        break;
×
171
        case 6:
×
172
        {
173
            // Produktion einstellen/fortführen
174
            // NC senden
175
            if(gcFactory.SetProductionEnabled(building->GetPos(), building->IsProductionDisabledVirtual()))
×
176
            {
177
                // visuell anzeigen, falls erfolgreich
178
                building->ToggleProductionVirtual();
×
179

180
                // anderes Bild auf dem Button
181
                if(building->IsProductionDisabledVirtual())
×
182
                    GetCtrl<ctrlImageButton>(6)->SetImage(LOADER.GetImageN("io", 197));
×
183
                else
184
                    GetCtrl<ctrlImageButton>(6)->SetImage(LOADER.GetImageN("io", 196));
×
185

186
                auto* text = GetCtrl<ctrlText>(10);
×
187
                if(building->IsProductionDisabledVirtual() && building->HasWorker())
×
188
                    text->SetText(_("(House unoccupied)"));
×
189
                else if(building->HasWorker())
×
190
                    text->SetVisible(false);
×
191
            }
192
        }
193
        break;
×
194
        case 7: // "Gehe Zum Ort"
×
195
        {
196
            gwv.MoveToMapPt(building->GetPos());
×
197
        }
198
        break;
×
199
        case 11: // Schiff/Boot umstellen bei Schiffsbauer
×
200
        {
201
            if(gcFactory.SetShipYardMode(building->GetPos(), static_cast<const nobShipYard*>(building)->GetMode()
×
202
                                                               == nobShipYard::Mode::Boats))
203
            {
204
                // Auch optisch den Button umstellen
205
                auto* button = GetCtrl<ctrlImageButton>(11);
×
206
                if(button->GetImage() == LOADER.GetImageN("io", IODAT_BOAT_ID))
×
207
                    button->SetImage(LOADER.GetImageN("io", IODAT_SHIP_ID));
×
208
                else
209
                    button->SetImage(LOADER.GetImageN("io", IODAT_BOAT_ID));
×
210
            }
211
        }
212
        break;
×
213
        case 12: // go to next of same type
×
214
        {
215
            const std::list<nobUsual*>& buildings = gwv.GetWorld()
×
216
                                                      .GetPlayer(building->GetPlayer())
×
217
                                                      .GetBuildingRegister()
×
218
                                                      .GetBuildings(building->GetBuildingType());
×
219
            // go through list once we get to current building -> open window for the next one and go to next location
220
            auto it = helpers::find_if(
221
              buildings, [bldPos = building->GetPos()](const auto* it) { return it->GetPos() == bldPos; });
×
222
            if(it != buildings.end()) // got to current building in the list?
×
223
            {
224
                // close old window, open new window (todo: only open if it isnt already open), move to location of next
225
                // building
226
                Close();
×
227
                ++it;
×
228
                if(it == buildings.end()) // was last entry in list -> goto first
×
229
                    it = buildings.begin();
×
230
                gwv.MoveToMapPt((*it)->GetPos());
×
231
                if(building->GetBuildingType() == BuildingType::Temple)
×
232
                    WINDOWMANAGER.ReplaceWindow(std::make_unique<iwTempleBuilding>(gwv, gcFactory, *it))
×
233
                      .SetPos(GetPos());
×
234
                else
235
                    WINDOWMANAGER.ReplaceWindow(std::make_unique<iwBuilding>(gwv, gcFactory, *it)).SetPos(GetPos());
×
236
                break;
×
237
            }
238
        }
239
        break;
×
240
    }
241
}
×
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