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

Return-To-The-Roots / s25client / 13520962205

25 Feb 2025 12:14PM UTC coverage: 50.351% (+0.02%) from 50.335%
13520962205

Pull #1745

github

web-flow
Merge 8c44f5bf8 into 26465f26c
Pull Request #1745: Don't draw content of ship window if minimized

24 of 73 new or added lines in 9 files covered. (32.88%)

16 existing lines in 8 files now uncovered.

22383 of 44454 relevant lines covered (50.35%)

37105.2 hits per line

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

0.0
/libs/s25main/ingameWindows/iwMerchandiseStatistics.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 "iwMerchandiseStatistics.h"
6
#include "GamePlayer.h"
7
#include "Loader.h"
8
#include "WindowManager.h"
9
#include "controls/ctrlMultiSelectGroup.h"
10
#include "controls/ctrlOptionGroup.h"
11
#include "controls/ctrlText.h"
12
#include "iwHelp.h"
13
#include "ogl/FontStyle.h"
14
#include "gameData/const_gui_ids.h"
15

16
// Farben für die einzelnen Balken
17
const std::array<unsigned, 14> iwMerchandiseStatistics::BarColors = {
18
  0xFF00D3F7, // türkis
19
  0xFFFB9E49, // gelb
20
  0xFFDF6161, // orange
21
  0xFF71B63C, // hellgrün
22
  0xFFAE71CB, // rosa
23
  0xFF9A75BE, // pink
24
  0xFF9EA6AE, // grau
25
  0xFF1038A6, // blau
26
  0xFF714520, // braun
27
  0xFFAE0000, // rot
28
  0xFF045514, // dunkelgrün
29
  0xFF61245D, // dunkellila
30
  0xFF5D4175, // blasslila
31
  0xFF202420  // schwarz
32
};
33

34
iwMerchandiseStatistics::iwMerchandiseStatistics(const GamePlayer& player)
×
35
    : IngameWindow(CGI_MERCHANDISE_STATISTICS, IngameWindow::posLastOrCenter, Extent(252, 310), _("Merchandise"),
×
36
                   LOADER.GetImageN("resource", 41)),
×
37
      player(player), currentTime(StatisticTime::T1Hour)
×
38
{
39
    // Statistikfeld
40
    AddImage(0, DrawPoint(10 + 115, 23 + 81), LOADER.GetImageN("io", 228));
×
41

42
    // Waren-Buttons
43
    // obere Reihe
44
    ctrlMultiSelectGroup* types = AddMultiSelectGroup(22, GroupSelectType::Illuminate);
×
45
    types->AddImageButton(1, DrawPoint(17, 192), Extent(30, 30), TextureColor::Grey, LOADER.GetWareTex(GoodType::Wood),
×
46
                          _("Wood"));
47
    types->AddImageButton(2, DrawPoint(48, 192), Extent(30, 30), TextureColor::Grey,
×
48
                          LOADER.GetWareTex(GoodType::Boards), _("Boards"));
×
49
    types->AddImageButton(3, DrawPoint(79, 192), Extent(30, 30), TextureColor::Grey,
×
50
                          LOADER.GetWareTex(GoodType::Stones), _("Stones"));
×
51
    types->AddImageButton(4, DrawPoint(110, 192), Extent(30, 30), TextureColor::Grey, LOADER.GetImageN("io", 80),
×
52
                          _("Food"));
53
    types->AddImageButton(5, DrawPoint(141, 192), Extent(30, 30), TextureColor::Grey,
×
54
                          LOADER.GetWareTex(GoodType::Water), _("Water"));
×
55
    types->AddImageButton(6, DrawPoint(172, 192), Extent(30, 30), TextureColor::Grey, LOADER.GetWareTex(GoodType::Beer),
×
56
                          _("Beer"));
57
    types->AddImageButton(7, DrawPoint(203, 192), Extent(30, 30), TextureColor::Grey, LOADER.GetWareTex(GoodType::Coal),
×
58
                          _("Coal"));
59

60
    // untere Reihe
61
    types->AddImageButton(8, DrawPoint(17, 227), Extent(30, 30), TextureColor::Grey,
×
62
                          LOADER.GetWareTex(GoodType::IronOre), _("Ironore"));
×
63
    types->AddImageButton(9, DrawPoint(48, 227), Extent(30, 30), TextureColor::Grey, LOADER.GetWareTex(GoodType::Gold),
×
64
                          _("Gold"));
65
    types->AddImageButton(10, DrawPoint(79, 227), Extent(30, 30), TextureColor::Grey, LOADER.GetWareTex(GoodType::Iron),
×
66
                          _("Iron"));
67
    types->AddImageButton(11, DrawPoint(110, 227), Extent(30, 30), TextureColor::Grey,
×
68
                          LOADER.GetWareTex(GoodType::Coins), _("Coins"));
×
69
    types->AddImageButton(12, DrawPoint(141, 227), Extent(30, 30), TextureColor::Grey,
×
70
                          LOADER.GetWareTex(GoodType::Hammer), _("Tools"));
×
71
    types->AddImageButton(13, DrawPoint(172, 227), Extent(30, 30), TextureColor::Grey, LOADER.GetImageN("io", 111),
×
72
                          _("Weapons"));
73
    types->AddImageButton(14, DrawPoint(203, 227), Extent(30, 30), TextureColor::Grey,
×
74
                          LOADER.GetWareTex(GoodType::Boat), _("Boats"));
×
75

76
    // Hilfe
77
    AddImageButton(16, DrawPoint(17, 261), Extent(30, 32), TextureColor::Grey, LOADER.GetImageN("io", 225), _("Help"));
×
78

79
    // Mülleimer
80
    AddImageButton(17, DrawPoint(49, 263), Extent(30, 28), TextureColor::Grey, LOADER.GetImageN("io", 106),
×
81
                   _("Delete all"));
82

83
    // Zeiten
84
    ctrlOptionGroup* times = AddOptionGroup(23, GroupSelectType::Illuminate);
×
85
    times->AddTextButton(18, DrawPoint(81, 263), Extent(36, 28), TextureColor::Grey, _("15 m"), NormalFont);
×
86
    times->AddTextButton(19, DrawPoint(119, 263), Extent(36, 28), TextureColor::Grey, _("1 h"), NormalFont);
×
87
    times->AddTextButton(20, DrawPoint(155, 263), Extent(36, 28), TextureColor::Grey, _("4 h"), NormalFont);
×
88
    times->AddTextButton(21, DrawPoint(191, 263), Extent(36, 28), TextureColor::Grey, _("16 h"), NormalFont);
×
89
    times->SetSelection(19);
×
90

91
    // Zeit-Werte an der x-Achse
92
    timeAnnotations = std::vector<ctrlText*>(7);
×
93
    for(unsigned i = 0; i < 7; ++i)
×
94
    {
95
        timeAnnotations[i] = AddText(32 + i, DrawPoint(211 + i, 125 + i), "", MakeColor(255, 136, 96, 52),
×
96
                                     FontStyle::CENTER | FontStyle::TOP | FontStyle::NO_OUTLINE, NormalFont);
×
97
    }
98

99
    // Aktueller Maximalwert an der y-Achse
100
    maxValue = AddText(31, DrawPoint(211, 55), "1", MakeColor(255, 136, 96, 52),
×
101
                       FontStyle::RIGHT | FontStyle::VCENTER | FontStyle::NO_OUTLINE, NormalFont);
×
102
}
×
103

104
iwMerchandiseStatistics::~iwMerchandiseStatistics() = default;
×
105

106
void iwMerchandiseStatistics::Msg_ButtonClick(const unsigned ctrl_id)
×
107
{
108
    switch(ctrl_id)
×
109
    {
110
        case 16: // Hilfe
×
111
        {
112
            WINDOWMANAGER.ReplaceWindow(std::make_unique<iwHelp>(
×
113
              _("The merchandise statistics window allows you to check the quantities "
×
114
                "of your merchandise. By clicking the left mouse button you can switch "
115
                "the display of individual goods on and off. These can displayed over "
116
                "four different time periods. To delete all displays, click on the wastebasket button.")));
×
117
        }
118
        break;
×
119
        case 17: // Alle abwählen
×
120
        {
121
            const std::set<unsigned> active = GetCtrl<ctrlMultiSelectGroup>(22)->GetSelection();
×
122
            for(unsigned sel : active)
×
123
                GetCtrl<ctrlMultiSelectGroup>(22)->RemoveSelection(sel);
×
124
        }
125
        break;
×
126
    }
127
}
×
128

129
void iwMerchandiseStatistics::Msg_OptionGroupChange(const unsigned ctrl_id, const unsigned selection)
×
130
{
131
    switch(ctrl_id)
×
132
    {
133
        case 23: // Zeitbereich wählen
×
134
            switch(selection)
135
            {
136
                case 18: currentTime = StatisticTime::T15Minutes; break;
×
137
                case 19: currentTime = StatisticTime::T1Hour; break;
×
138
                case 20: currentTime = StatisticTime::T4Hours; break;
×
139
                case 21: currentTime = StatisticTime::T16Hours; break;
×
140
            }
141
            break;
×
142
    }
143
}
×
144

NEW
145
void iwMerchandiseStatistics::DrawContent()
×
146
{
147
    DrawRectangles();
×
UNCOV
148
    DrawAxis();
×
149
    DrawStatistic();
×
UNCOV
150
}
×
151

152
// TODO
153
void iwMerchandiseStatistics::DrawStatistic()
×
154
{
155
    // Ein paar benötigte Werte...
156
    const int sizeX = 180;
×
157
    const int sizeY = 80;
×
158
    const DrawPoint topLeft = GetPos() + DrawPoint(34, 64);
×
159
    const int stepX = sizeX / NUM_STAT_STEPS; // 6
×
160

161
    // Aktive Buttons holen (Achtung ID == BarColor + 1)
162
    const std::set<unsigned>& active = GetCtrl<ctrlMultiSelectGroup>(22)->GetSelection();
×
163

164
    // Statistik holen
165
    const GamePlayer::Statistic stat = player.GetStatistic(currentTime);
×
166

167
    // Maximalwert suchen
168
    unsigned short max = 1;
×
169
    for(unsigned it : active)
×
170
    {
171
        for(unsigned i = 0; i < NUM_STAT_STEPS; ++i)
×
172
        {
173
            if(max < stat.merchandiseData[it - 1][i])
×
174
            {
175
                max = stat.merchandiseData[it - 1][i];
×
176
            }
177
        }
178
    }
179

180
    // Maximalen Wert an die Achse schreiben
181
    maxValue->SetText(std::to_string(max));
×
182

183
    DrawPoint previous(0, 0);
×
184
    unsigned short currentIndex = stat.currentIndex;
×
185

186
    for(unsigned short it : active)
×
187
    {
188
        // Testing only:
189
        // DrawLine(topLeft.x, topLeft.y + 3 * (*it), topLeft + DrawPoint(sizeX, 3 * (*it)), 2, BarColors[(*it) - 1]);
190

191
        for(unsigned i = 0; i < NUM_STAT_STEPS; ++i)
×
192
        {
193
            DrawPoint drawPos = topLeft;
×
194
            drawPos.x += (NUM_STAT_STEPS - i) * stepX;
×
195
            drawPos.y += sizeY
×
196
                         - ((stat.merchandiseData[it - 1][(currentIndex >= i) ? (currentIndex - i) :
×
197
                                                                                (NUM_STAT_STEPS - i + currentIndex)])
×
198
                            * sizeY)
×
199
                             / max;
×
200
            if(i != 0)
×
201
            {
202
                DrawLine(drawPos, previous, 2, BarColors[it - 1]);
×
203
            }
204
            previous = drawPos;
×
205
        }
206
    }
207
}
×
208

209
// Lustige bunte Kästchen über den Buttons malen
210
void iwMerchandiseStatistics::DrawRectangles()
×
211
{
212
    const Extent size(30, 4);
×
213
    const DrawPoint step(31, 35);
×
214

215
    const DrawPoint pos = GetDrawPos();
×
216
    DrawPoint curOffset(17, 187);
×
217

218
    for(unsigned i = 0; i < 14; ++i)
×
219
    {
220
        DrawRectangle(Rect(pos + curOffset, size), BarColors[i]);
×
221
        if(i == 6)
×
222
        {
223
            curOffset.x = 17;
×
224
            curOffset.y += step.y;
×
225
        } else
226
            curOffset.x += step.x;
×
227
    }
228
}
×
229

230
void iwMerchandiseStatistics::DrawAxis()
×
231
{
232
    // Ein paar benötigte Werte...
233
    const int sizeX = 180;
×
234
    const int sizeY = 80;
×
235
    const DrawPoint topLeft = GetPos() + DrawPoint(34, 64);
×
236
    const DrawPoint topLeftRel(37, 64);
×
237

238
    // X-Achse, horizontal, war irgendwie zu lang links :S
239
    DrawLine(topLeft + DrawPoint(6, sizeY + 2), // bisschen tiefer, damit man nulllinien noch sieht
×
240
             topLeft + DrawPoint(sizeX, sizeY + 1), 1, MakeColor(255, 88, 44, 16));
×
241

242
    // Y-Achse, vertikal
243
    DrawLine(topLeft + DrawPoint(sizeX, 0), topLeft + DrawPoint(sizeX, sizeY + 5), 1, MakeColor(255, 88, 44, 16));
×
244

245
    // Striche an der Y-Achse
246
    DrawLine(topLeft + DrawPoint(sizeX - 3, 0), topLeft + DrawPoint(sizeX + 4, 0), 1, MakeColor(255, 88, 44, 16));
×
247
    DrawLine(topLeft + DrawPoint(sizeX - 3, sizeY / 2), topLeft + DrawPoint(sizeX + 4, sizeY / 2), 1,
×
248
             MakeColor(255, 88, 44, 16));
249

250
    // Striche an der X-Achse + Beschriftung
251
    // Zunächst die 0, die haben alle
252
    timeAnnotations[6]->SetPos(topLeftRel + DrawPoint(180, sizeY + 6));
×
253
    timeAnnotations[6]->SetText("0");
×
254
    timeAnnotations[6]->SetVisible(true);
×
255

256
    switch(currentTime)
×
257
    {
258
        case StatisticTime::T15Minutes:
×
259
            // -15
260
            DrawLine(topLeft + DrawPoint(6, sizeY + 2), topLeft + DrawPoint(6, sizeY + 4), 1,
×
261
                     MakeColor(255, 88, 44, 16));
262
            timeAnnotations[0]->SetPos(topLeftRel + DrawPoint(6, sizeY + 6));
×
263
            timeAnnotations[0]->SetText("-15");
×
264
            timeAnnotations[0]->SetVisible(true);
×
265

266
            // -12
267
            DrawLine(topLeft + DrawPoint(40, sizeY + 2), topLeft + DrawPoint(40, sizeY + 4), 1,
×
268
                     MakeColor(255, 88, 44, 16));
269
            timeAnnotations[1]->SetPos(topLeftRel + DrawPoint(40, sizeY + 6));
×
270
            timeAnnotations[1]->SetText("-12");
×
271
            timeAnnotations[1]->SetVisible(true);
×
272

273
            // -9
274
            DrawLine(topLeft + DrawPoint(75, sizeY + 2), topLeft + DrawPoint(75, sizeY + 4), 1,
×
275
                     MakeColor(255, 88, 44, 16));
276
            timeAnnotations[2]->SetPos(topLeftRel + DrawPoint(75, sizeY + 6));
×
277
            timeAnnotations[2]->SetText("-9");
×
278
            timeAnnotations[2]->SetVisible(true);
×
279

280
            // -6
281
            DrawLine(topLeft + DrawPoint(110, sizeY + 2), topLeft + DrawPoint(110, sizeY + 4), 1,
×
282
                     MakeColor(255, 88, 44, 16));
283
            timeAnnotations[3]->SetPos(topLeftRel + DrawPoint(110, sizeY + 6));
×
284
            timeAnnotations[3]->SetText("-6");
×
285
            timeAnnotations[3]->SetVisible(true);
×
286

287
            // -3
288
            DrawLine(topLeft + DrawPoint(145, sizeY + 2), topLeft + DrawPoint(145, sizeY + 4), 1,
×
289
                     MakeColor(255, 88, 44, 16));
290
            timeAnnotations[4]->SetPos(topLeftRel + DrawPoint(145, sizeY + 6));
×
291
            timeAnnotations[4]->SetText("-3");
×
292
            timeAnnotations[4]->SetVisible(true);
×
293

294
            timeAnnotations[5]->SetVisible(false);
×
295
            break;
×
296
        case StatisticTime::T1Hour:
×
297
            // -60
298
            DrawLine(topLeft + DrawPoint(6, sizeY + 2), topLeft + DrawPoint(6, sizeY + 4), 1,
×
299
                     MakeColor(255, 88, 44, 16));
300
            timeAnnotations[0]->SetPos(topLeftRel + DrawPoint(6, sizeY + 6));
×
301
            timeAnnotations[0]->SetText("-60");
×
302
            timeAnnotations[0]->SetVisible(true);
×
303

304
            // -50
305
            DrawLine(topLeft + DrawPoint(35, sizeY + 2), topLeft + DrawPoint(35, sizeY + 4), 1,
×
306
                     MakeColor(255, 88, 44, 16));
307
            timeAnnotations[1]->SetPos(topLeftRel + DrawPoint(35, sizeY + 6));
×
308
            timeAnnotations[1]->SetText("-50");
×
309
            timeAnnotations[1]->SetVisible(true);
×
310

311
            // -40
312
            DrawLine(topLeft + DrawPoint(64, sizeY + 2), topLeft + DrawPoint(64, sizeY + 4), 1,
×
313
                     MakeColor(255, 88, 44, 16));
314
            timeAnnotations[2]->SetPos(topLeftRel + DrawPoint(64, sizeY + 6));
×
315
            timeAnnotations[2]->SetText("-40");
×
316
            timeAnnotations[2]->SetVisible(true);
×
317

318
            // -30
319
            DrawLine(topLeft + DrawPoint(93, sizeY + 2), topLeft + DrawPoint(93, sizeY + 4), 1,
×
320
                     MakeColor(255, 88, 44, 16));
321
            timeAnnotations[3]->SetPos(topLeftRel + DrawPoint(93, sizeY + 6));
×
322
            timeAnnotations[3]->SetText("-30");
×
323
            timeAnnotations[3]->SetVisible(true);
×
324

325
            // -20
326
            DrawLine(topLeft + DrawPoint(122, sizeY + 2), topLeft + DrawPoint(122, sizeY + 4), 1,
×
327
                     MakeColor(255, 88, 44, 16));
328
            timeAnnotations[4]->SetPos(topLeftRel + DrawPoint(122, sizeY + 6));
×
329
            timeAnnotations[4]->SetText("-20");
×
330
            timeAnnotations[4]->SetVisible(true);
×
331

332
            // -10
333
            DrawLine(topLeft + DrawPoint(151, sizeY + 2), topLeft + DrawPoint(151, sizeY + 4), 1,
×
334
                     MakeColor(255, 88, 44, 16));
335
            timeAnnotations[5]->SetPos(topLeftRel + DrawPoint(151, sizeY + 6));
×
336
            timeAnnotations[5]->SetText("-10");
×
337
            timeAnnotations[5]->SetVisible(true);
×
338
            break;
×
339
        case StatisticTime::T4Hours:
×
340
            // -240
341
            DrawLine(topLeft + DrawPoint(6, sizeY + 2), topLeft + DrawPoint(6, sizeY + 4), 1,
×
342
                     MakeColor(255, 88, 44, 16));
343
            timeAnnotations[0]->SetPos(topLeftRel + DrawPoint(6, sizeY + 6));
×
344
            timeAnnotations[0]->SetText("-240");
×
345
            timeAnnotations[0]->SetVisible(true);
×
346

347
            // -180
348
            DrawLine(topLeft + DrawPoint(49, sizeY + 2), topLeft + DrawPoint(49, sizeY + 4), 1,
×
349
                     MakeColor(255, 88, 44, 16));
350
            timeAnnotations[1]->SetPos(topLeftRel + DrawPoint(49, sizeY + 6));
×
351
            timeAnnotations[1]->SetText("-180");
×
352
            timeAnnotations[1]->SetVisible(true);
×
353

354
            // -120
355
            DrawLine(topLeft + DrawPoint(93, sizeY + 2), topLeft + DrawPoint(93, sizeY + 4), 1,
×
356
                     MakeColor(255, 88, 44, 16));
357
            timeAnnotations[2]->SetPos(topLeftRel + DrawPoint(93, sizeY + 6));
×
358
            timeAnnotations[2]->SetText("-120");
×
359
            timeAnnotations[2]->SetVisible(true);
×
360

361
            // -60
362
            DrawLine(topLeft + DrawPoint(136, sizeY + 2), topLeft + DrawPoint(136, sizeY + 4), 1,
×
363
                     MakeColor(255, 88, 44, 16));
364
            timeAnnotations[3]->SetPos(topLeftRel + DrawPoint(136, sizeY + 6));
×
365
            timeAnnotations[3]->SetText("-60");
×
366
            timeAnnotations[3]->SetVisible(true);
×
367

368
            timeAnnotations[4]->SetVisible(false);
×
369
            timeAnnotations[5]->SetVisible(false);
×
370
            break;
×
371
        case StatisticTime::T16Hours:
×
372
            // -960
373
            DrawLine(topLeft + DrawPoint(6, sizeY + 2), topLeft + DrawPoint(6, sizeY + 4), 1,
×
374
                     MakeColor(255, 88, 44, 16));
375
            timeAnnotations[0]->SetPos(topLeftRel + DrawPoint(6, sizeY + 6));
×
376
            timeAnnotations[0]->SetText("-960");
×
377
            timeAnnotations[0]->SetVisible(true);
×
378

379
            // -720
380
            DrawLine(topLeft + DrawPoint(49, sizeY + 2), topLeft + DrawPoint(49, sizeY + 4), 1,
×
381
                     MakeColor(255, 88, 44, 16));
382
            timeAnnotations[1]->SetPos(topLeftRel + DrawPoint(49, sizeY + 6));
×
383
            timeAnnotations[1]->SetText("-720");
×
384
            timeAnnotations[1]->SetVisible(true);
×
385

386
            // -480
387
            DrawLine(topLeft + DrawPoint(93, sizeY + 2), topLeft + DrawPoint(93, sizeY + 4), 1,
×
388
                     MakeColor(255, 88, 44, 16));
389
            timeAnnotations[2]->SetPos(topLeftRel + DrawPoint(93, sizeY + 6));
×
390
            timeAnnotations[2]->SetText("-480");
×
391
            timeAnnotations[2]->SetVisible(true);
×
392

393
            // -240
394
            DrawLine(topLeft + DrawPoint(136, sizeY + 2), topLeft + DrawPoint(136, sizeY + 4), 1,
×
395
                     MakeColor(255, 88, 44, 16));
396
            timeAnnotations[3]->SetPos(topLeftRel + DrawPoint(136, sizeY + 6));
×
397
            timeAnnotations[3]->SetText("-240");
×
398
            timeAnnotations[3]->SetVisible(true);
×
399

400
            timeAnnotations[4]->SetVisible(false);
×
401
            timeAnnotations[5]->SetVisible(false);
×
402
            break;
×
403
    }
404
}
×
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