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

Return-To-The-Roots / s25client / 20641422872

01 Jan 2026 03:57PM UTC coverage: 50.532% (-0.05%) from 50.58%
20641422872

Pull #1804

github

web-flow
Merge 04b41dbf7 into d98c92f3b
Pull Request #1804: Android build

65 of 226 new or added lines in 13 files covered. (28.76%)

15 existing lines in 5 files now uncovered.

22599 of 44722 relevant lines covered (50.53%)

35465.07 hits per line

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

35.45
/libs/s25main/desktops/dskGameInterface.cpp
1
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "dskGameInterface.h"
6
#include "CollisionDetection.h"
7
#include "EventManager.h"
8
#include "Game.h"
9
#include "GamePlayer.h"
10
#include "Loader.h"
11
#include "NWFInfo.h"
12
#include "Settings.h"
13
#include "SoundManager.h"
14
#include "WindowManager.h"
15
#include "addons/AddonMaxWaterwayLength.h"
16
#include "buildings/noBuildingSite.h"
17
#include "buildings/nobHQ.h"
18
#include "buildings/nobHarborBuilding.h"
19
#include "buildings/nobMilitary.h"
20
#include "buildings/nobStorehouse.h"
21
#include "buildings/nobTemple.h"
22
#include "buildings/nobUsual.h"
23
#include "controls/ctrlImageButton.h"
24
#include "controls/ctrlText.h"
25
#include "driver/MouseCoords.h"
26
#include "drivers/VideoDriverWrapper.h"
27
#include "helpers/format.hpp"
28
#include "helpers/strUtils.h"
29
#include "helpers/toString.h"
30
#include "ingameWindows/iwAIDebug.h"
31
#include "ingameWindows/iwAction.h"
32
#include "ingameWindows/iwBaseWarehouse.h"
33
#include "ingameWindows/iwBuildOrder.h"
34
#include "ingameWindows/iwBuilding.h"
35
#include "ingameWindows/iwBuildingProductivities.h"
36
#include "ingameWindows/iwBuildingSite.h"
37
#include "ingameWindows/iwBuildings.h"
38
#include "ingameWindows/iwDiplomacy.h"
39
#include "ingameWindows/iwDistribution.h"
40
#include "ingameWindows/iwEconomicProgress.h"
41
#include "ingameWindows/iwEndgame.h"
42
#include "ingameWindows/iwHQ.h"
43
#include "ingameWindows/iwHarborBuilding.h"
44
#include "ingameWindows/iwInventory.h"
45
#include "ingameWindows/iwMainMenu.h"
46
#include "ingameWindows/iwMapDebug.h"
47
#include "ingameWindows/iwMerchandiseStatistics.h"
48
#include "ingameWindows/iwMilitary.h"
49
#include "ingameWindows/iwMilitaryBuilding.h"
50
#include "ingameWindows/iwMinimap.h"
51
#include "ingameWindows/iwMusicPlayer.h"
52
#include "ingameWindows/iwOptionsWindow.h"
53
#include "ingameWindows/iwPostWindow.h"
54
#include "ingameWindows/iwRoadWindow.h"
55
#include "ingameWindows/iwSave.h"
56
#include "ingameWindows/iwShip.h"
57
#include "ingameWindows/iwSkipGFs.h"
58
#include "ingameWindows/iwStatistics.h"
59
#include "ingameWindows/iwTempleBuilding.h"
60
#include "ingameWindows/iwTextfile.h"
61
#include "ingameWindows/iwTools.h"
62
#include "ingameWindows/iwTrade.h"
63
#include "ingameWindows/iwTransport.h"
64
#include "ingameWindows/iwVictory.h"
65
#include "lua/GameDataLoader.h"
66
#include "network/GameClient.h"
67
#include "notifications/BuildingNote.h"
68
#include "notifications/NotificationManager.h"
69
#include "ogl/FontStyle.h"
70
#include "ogl/SoundEffectItem.h"
71
#include "ogl/glArchivItem_Bitmap_Player.h"
72
#include "ogl/glFont.h"
73
#include "pathfinding/FindPathForRoad.h"
74
#include "postSystem/PostBox.h"
75
#include "postSystem/PostMsg.h"
76
#include "random/Random.h"
77
#include "world/GameWorldBase.h"
78
#include "world/GameWorldViewer.h"
79
#include "nodeObjs/noFlag.h"
80
#include "nodeObjs/noTree.h"
81
#include "gameData/BuildingProperties.h"
82
#include "gameData/GameConsts.h"
83
#include "gameData/GuiConsts.h"
84
#include "gameData/TerrainDesc.h"
85
#include "gameData/const_gui_ids.h"
86
#include "liblobby/LobbyClient.h"
87
#include <algorithm>
88
#include <cstdio>
89
#include <utility>
90

91
namespace {
92
enum
93
{
94
    ID_btMap,
95
    ID_btOptions,
96
    ID_btConstructionAid,
97
    ID_btPost,
98
    ID_txtNumMsg
99
};
100

101
float getNextZoomLevel(const float currentZoom)
7✔
102
{
103
    // Get first level bigger than current zoom
104
    // NOLINTNEXTLINE(readability-qualified-auto)
105
    auto it = std::upper_bound(ZOOM_FACTORS.begin(), ZOOM_FACTORS.end(), currentZoom);
7✔
106
    return (it == ZOOM_FACTORS.end()) ? ZOOM_FACTORS.front() : *it;
7✔
107
}
108

109
float getPreviousZoomLevel(const float currentZoom)
4✔
110
{
111
    // Get last level bigger or equal than current zoom
112
    // NOLINTNEXTLINE(readability-qualified-auto)
113
    auto it = std::lower_bound(ZOOM_FACTORS.begin(), ZOOM_FACTORS.end(), currentZoom);
4✔
114
    return (it == ZOOM_FACTORS.begin()) ? ZOOM_FACTORS.back() : *(--it);
4✔
115
}
116
} // namespace
117

118
dskGameInterface::dskGameInterface(std::shared_ptr<Game> game, std::shared_ptr<const NWFInfo> nwfInfo,
6✔
119
                                   unsigned playerIdx, bool initOGL)
6✔
120
    : Desktop(nullptr), game_(std::move(game)), nwfInfo_(std::move(nwfInfo)),
12✔
121
      worldViewer(playerIdx, const_cast<Game&>(*game_).world_),
6✔
122
      gwv(worldViewer, Position(0, 0), VIDEODRIVER.GetRenderSize()), cbb(*LOADER.GetPaletteN("pal5")),
18✔
123
      actionwindow(nullptr), roadwindow(nullptr), minimap(worldViewer), isScrolling(false),
6✔
124
      cheats_(const_cast<Game&>(*game_).world_), cheatCommandTracker_(cheats_)
18✔
125
{
126
    road.mode = RoadBuildMode::Disabled;
6✔
127
    road.point = MapPoint(0, 0);
6✔
128
    road.start = MapPoint(0, 0);
6✔
129

130
    SetScale(false);
6✔
131

132
    DrawPoint barPos((GetSize().x - LOADER.GetImageN("resource", 29)->getWidth()) / 2 + 44,
12✔
133
                     GetSize().y - LOADER.GetImageN("resource", 29)->getHeight() + 4);
18✔
134

135
    Extent btSize = Extent(37, 32);
6✔
136
    AddImageButton(ID_btMap, barPos, btSize, TextureColor::Green1, LOADER.GetImageN("io", 50), _("Map"))
6✔
137
      ->SetBorder(false);
12✔
138
    barPos.x += btSize.x;
6✔
139
    AddImageButton(ID_btOptions, barPos, btSize, TextureColor::Green1, LOADER.GetImageN("io", 192), _("Main selection"))
6✔
140
      ->SetBorder(false);
12✔
141
    barPos.x += btSize.x;
6✔
142
    AddImageButton(ID_btConstructionAid, barPos, btSize, TextureColor::Green1, LOADER.GetImageN("io", 83),
6✔
143
                   _("Construction aid mode"))
144
      ->SetBorder(false);
12✔
145
    barPos.x += btSize.x;
6✔
146
    AddImageButton(ID_btPost, barPos, btSize, TextureColor::Green1, LOADER.GetImageN("io", 62), _("Post office"))
6✔
147
      ->SetBorder(false);
12✔
148
    barPos += DrawPoint(18, 24);
6✔
149

150
    AddText(ID_txtNumMsg, barPos, "", COLOR_YELLOW, FontStyle::CENTER | FontStyle::VCENTER, SmallFont);
6✔
151

152
    const_cast<Game&>(*game_).world_.SetGameInterface(this);
6✔
153

154
    std::fill(borders.begin(), borders.end(), (glArchivItem_Bitmap*)(nullptr));
6✔
155
    cbb.loadEdges(LOADER.GetArchive("resource"));
12✔
156
    cbb.buildBorder(VIDEODRIVER.GetRenderSize(), borders);
6✔
157

158
    InitPlayer();
6✔
159
    if(initOGL)
6✔
160
        worldViewer.InitTerrainRenderer();
×
161

162
    VIDEODRIVER.setTargetFramerate(SETTINGS.video.framerate); // Use requested setting for ingame
6✔
163
}
6✔
164

165
void dskGameInterface::InitPlayer()
6✔
166
{
167
    // Jump to players HQ if it exists
168
    if(worldViewer.GetPlayer().GetHQPos().isValid())
6✔
169
        gwv.MoveToMapPt(worldViewer.GetPlayer().GetHQPos());
6✔
170

171
    evBld = worldViewer.GetWorld().GetNotifications().subscribe<BuildingNote>([this](const auto& note) {
12✔
172
        if(note.player == worldViewer.GetPlayerId())
×
173
            this->OnBuildingNote(note);
×
174
    });
6✔
175
    PostBox& postBox = GetPostBox();
6✔
176
    postBox.ObserveNewMsg([this](const auto& msg, auto msgCt) { this->NewPostMessage(msg, msgCt); });
6✔
177
    postBox.ObserveDeletedMsg([this](auto msgCt) { this->PostMessageDeleted(msgCt); });
6✔
178
    UpdatePostIcon(postBox.GetNumMsgs(), true);
6✔
179
}
6✔
180

181
PostBox& dskGameInterface::GetPostBox()
6✔
182
{
183
    PostBox* postBox = worldViewer.GetWorld().GetPostMgr().GetPostBox(worldViewer.GetPlayerId());
6✔
184
    if(!postBox)
6✔
185
        postBox = &worldViewer.GetWorldNonConst().GetPostMgr().AddPostBox(worldViewer.GetPlayerId());
6✔
186
    RTTR_Assert(postBox != nullptr);
6✔
187
    return *postBox;
6✔
188
}
189

190
dskGameInterface::~dskGameInterface()
6✔
191
{
192
    for(auto& border : borders)
30✔
193
        deletePtr(border);
24✔
194
    GAMECLIENT.RemoveInterface(this);
6✔
195
    LOBBYCLIENT.RemoveListener(this);
6✔
196
}
6✔
197

198
void dskGameInterface::SetActive(bool activate)
10✔
199
{
200
    if(activate == IsActive())
10✔
201
        return;
1✔
202
    if(!activate && isScrolling)
9✔
203
    {
204
        // Stay active if scrolling and no modal window is open
205
        const IngameWindow* wnd = WINDOWMANAGER.GetTopMostWindow();
1✔
206
        if(wnd && wnd->IsModal())
1✔
207
            StopScrolling();
×
208
        else
209
            return;
1✔
210
    }
211
    Desktop::SetActive(activate);
8✔
212
    // Do this here to allow previous screen to keep control
213
    if(activate)
8✔
214
    {
215
        GAMECLIENT.SetInterface(this);
6✔
216
        LOBBYCLIENT.AddListener(this);
6✔
217
        if(!game_->IsStarted())
6✔
218
        {
219
            GAMECLIENT.OnGameStart();
6✔
220

221
            ShowPersistentWindowsAfterSwitch();
6✔
222
        }
223
    }
224
}
225

226
void dskGameInterface::StopScrolling()
7✔
227
{
228
    isScrolling = false;
7✔
229
    WINDOWMANAGER.SetCursor(road.mode == RoadBuildMode::Disabled ? Cursor::Hand : Cursor::Remove);
7✔
230
}
7✔
231

232
void dskGameInterface::StartScrolling(const Position& mousePos)
7✔
233
{
234
    startScrollPt = mousePos;
7✔
235
    isScrolling = true;
7✔
236
    WINDOWMANAGER.SetCursor(Cursor::Scroll);
7✔
237
}
7✔
238

239
void dskGameInterface::ToggleFoW()
×
240
{
241
    DisableFoW(!GAMECLIENT.IsReplayFOWDisabled());
×
242
}
×
243

244
void dskGameInterface::DisableFoW(const bool hideFOW)
×
245
{
246
    GAMECLIENT.SetReplayFOW(hideFOW);
×
247
    // Notify viewer and minimap to recalculate the visibility
248
    worldViewer.RecalcAllColors();
×
249
    minimap.UpdateAll();
×
250
}
×
251

252
void dskGameInterface::ShowPersistentWindowsAfterSwitch()
6✔
253
{
254
    auto& windows = SETTINGS.windows.persistentSettings;
6✔
255

256
    if(windows[CGI_CHAT].isOpen)
6✔
257
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwChat>(this));
×
258
    if(windows[CGI_POSTOFFICE].isOpen)
6✔
259
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwPostWindow>(gwv, GetPostBox()));
×
260
    if(windows[CGI_DISTRIBUTION].isOpen)
6✔
261
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwDistribution>(gwv.GetViewer(), GAMECLIENT));
×
262
    if(windows[CGI_BUILDORDER].isOpen && gwv.GetWorld().GetGGS().isEnabled(AddonId::CUSTOM_BUILD_SEQUENCE))
6✔
263
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwBuildOrder>(gwv.GetViewer()));
×
264
    if(windows[CGI_TRANSPORT].isOpen)
6✔
265
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwTransport>(gwv.GetViewer(), GAMECLIENT));
×
266
    if(windows[CGI_MILITARY].isOpen)
6✔
267
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwMilitary>(gwv.GetViewer(), GAMECLIENT));
×
268
    if(windows[CGI_TOOLS].isOpen)
6✔
269
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwTools>(gwv.GetViewer(), GAMECLIENT));
×
270
    if(windows[CGI_INVENTORY].isOpen)
6✔
271
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwInventory>(gwv.GetViewer().GetPlayer()));
×
272
    if(windows[CGI_MINIMAP].isOpen)
6✔
273
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwMinimap>(minimap, gwv));
×
274
    if(windows[CGI_BUILDINGS].isOpen)
6✔
275
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwBuildings>(gwv, GAMECLIENT));
×
276
    if(windows[CGI_BUILDINGSPRODUCTIVITY].isOpen)
6✔
277
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwBuildingProductivities>(gwv.GetViewer().GetPlayer()));
×
278
    if(windows[CGI_MUSICPLAYER].isOpen)
6✔
279
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwMusicPlayer>());
×
280
    if(windows[CGI_STATISTICS].isOpen)
6✔
281
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwStatistics>(gwv.GetViewer()));
×
282
    if(windows[CGI_ECONOMICPROGRESS].isOpen && gwv.GetWorld().getEconHandler())
6✔
283
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwEconomicProgress>(gwv.GetViewer()));
×
284
    if(windows[CGI_DIPLOMACY].isOpen)
6✔
285
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwDiplomacy>(gwv.GetViewer(), GAMECLIENT));
×
286
    if(windows[CGI_SHIP].isOpen)
6✔
287
        WINDOWMANAGER.ShowAfterSwitch(
×
288
          std::make_unique<iwShip>(gwv, GAMECLIENT, gwv.GetViewer().GetPlayer().GetShipByID(0)));
×
289
    if(windows[CGI_MERCHANDISE_STATISTICS].isOpen)
6✔
290
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwMerchandiseStatistics>(gwv.GetViewer().GetPlayer()));
×
291
}
6✔
292

293
void dskGameInterface::Resize(const Extent& newSize)
×
294
{
295
    Window::Resize(newSize);
×
296

297
    // recreate borders
298
    for(auto& border : borders)
×
299
        deletePtr(border);
×
300
    cbb.buildBorder(newSize, borders);
×
301

302
    // move buttons
303
    DrawPoint barPos((newSize.x - LOADER.GetImageN("resource", 29)->getWidth()) / 2 + 44,
×
304
                     newSize.y - LOADER.GetImageN("resource", 29)->getHeight() + 4);
×
305

306
    auto* button = GetCtrl<ctrlButton>(ID_btMap);
×
307
    button->SetPos(barPos);
×
308

309
    barPos.x += button->GetSize().x;
×
310
    button = GetCtrl<ctrlButton>(ID_btOptions);
×
311
    button->SetPos(barPos);
×
312

313
    barPos.x += button->GetSize().x;
×
314
    button = GetCtrl<ctrlButton>(ID_btConstructionAid);
×
315
    button->SetPos(barPos);
×
316

317
    barPos.x += button->GetSize().x;
×
318
    button = GetCtrl<ctrlButton>(ID_btPost);
×
319
    button->SetPos(barPos);
×
320

321
    barPos += DrawPoint(18, 24);
×
322
    auto* text = GetCtrl<ctrlText>(ID_txtNumMsg);
×
323
    text->SetPos(barPos);
×
324

325
    gwv.Resize(newSize);
×
326
}
×
327

328
bool dskGameInterface::ContextClick(const MouseCoords& mc)
2✔
329
{
330
    // Unterscheiden je nachdem Straäcnbaumodus an oder aus ist
331
    if(road.mode != RoadBuildMode::Disabled)
2✔
332
    {
333
        // in "richtige" Map-Koordinaten Konvertieren, den aktuellen selektierten Punkt
334
        const MapPoint selPt = gwv.GetSelectedPt();
1✔
335

336
        if(selPt == road.point)
1✔
337
        {
338
            // Selektierter Punkt ist der gleiche wie der Straßenpunkt --> Fenster mit Wegbau abbrechen
339
            ShowRoadWindow(mc.pos);
×
340
        } else
341
        {
342
            // altes Roadwindow schließen
343
            WINDOWMANAGER.Close((unsigned)CGI_ROADWINDOW);
1✔
344

345
            // Ist das ein gültiger neuer Wegpunkt?
346
            if(worldViewer.IsRoadAvailable(road.mode == RoadBuildMode::Boat, selPt)
1✔
347
               && worldViewer.IsPlayerTerritory(selPt))
1✔
348
            {
349
                MapPoint targetPt = selPt;
1✔
350
                if(!BuildRoadPart(targetPt))
1✔
351
                    ShowRoadWindow(mc.pos);
×
352
            } else if(worldViewer.GetBQ(selPt) != BuildingQuality::Nothing)
×
353
            {
354
                // Wurde bereits auf das gebaute Stück geklickt?
355
                unsigned idOnRoad = GetIdInCurBuildRoad(selPt);
×
356
                if(idOnRoad)
×
357
                    DemolishRoad(idOnRoad);
×
358
                else
359
                {
360
                    MapPoint targetPt = selPt;
×
361
                    if(BuildRoadPart(targetPt))
×
362
                    {
363
                        // Ist der Zielpunkt der gleiche geblieben?
364
                        if(selPt == targetPt)
×
365
                            GI_BuildRoad();
×
366
                    } else if(selPt == targetPt)
×
367
                        ShowRoadWindow(mc.pos);
×
368
                }
369
            }
370
            // Wurde auf eine Flagge geklickt und ist diese Flagge nicht der Weganfangspunkt?
371
            else if(worldViewer.GetWorld().GetNO(selPt)->GetType() == NodalObjectType::Flag && selPt != road.start)
×
372
            {
373
                MapPoint targetPt = selPt;
×
374
                if(BuildRoadPart(targetPt))
×
375
                {
376
                    if(selPt == targetPt)
×
377
                        GI_BuildRoad();
×
378
                } else if(selPt == targetPt)
×
379
                    ShowRoadWindow(mc.pos);
×
380
            } else
381
            {
382
                unsigned tbr = GetIdInCurBuildRoad(selPt);
×
383
                // Wurde bereits auf das gebaute Stück geklickt?
384
                if(tbr)
×
385
                    DemolishRoad(tbr);
×
386
                else
387
                    ShowRoadWindow(mc.pos);
×
388
            }
389
        }
390
    } else
391
    {
392
        bool enable_military_buildings = false;
1✔
393

394
        iwAction::Tabs action_tabs;
1✔
395

396
        const MapPoint cSel = gwv.GetSelectedPt();
1✔
397

398
        // Vielleicht steht hier auch ein Schiff?
399
        if(const noShip* ship = worldViewer.GetShip(cSel))
1✔
400
        {
401
            WINDOWMANAGER.Show(std::make_unique<iwShip>(gwv, GAMECLIENT, ship));
×
402
            return true;
×
403
        }
404

405
        // Evtl ists nen Haus? (unser Haus)
406
        const noBase& selObj = *worldViewer.GetWorld().GetNO(cSel);
1✔
407
        if(selObj.GetType() == NodalObjectType::Building && worldViewer.IsOwner(cSel))
1✔
408
        {
409
            if(auto* wnd = WINDOWMANAGER.FindNonModalWindow(CGI_BUILDING + MapBase::CreateGUIID(cSel)))
×
410
            {
411
                WINDOWMANAGER.SetActiveWindow(*wnd);
×
412
                return true;
×
413
            }
414
            BuildingType bt = static_cast<const noBuilding&>(selObj).GetBuildingType();
×
415
            // HQ
416
            if(bt == BuildingType::Headquarters)
×
417
                WINDOWMANAGER.Show(
×
418
                  std::make_unique<iwHQ>(gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobHQ>(cSel)));
×
419
            // Lagerhäuser
420
            else if(bt == BuildingType::Storehouse)
×
421
                WINDOWMANAGER.Show(std::make_unique<iwBaseWarehouse>(
×
422
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobStorehouse>(cSel)));
×
423
            // Hafengebäude
424
            else if(bt == BuildingType::HarborBuilding)
×
425
                WINDOWMANAGER.Show(std::make_unique<iwHarborBuilding>(
×
426
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobHarborBuilding>(cSel)));
×
427
            // Militärgebäude
428
            else if(BuildingProperties::IsMilitary(bt))
×
429
                WINDOWMANAGER.Show(std::make_unique<iwMilitaryBuilding>(
×
430
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobMilitary>(cSel)));
×
431
            else if(bt == BuildingType::Temple)
×
432
                WINDOWMANAGER.Show(std::make_unique<iwTempleBuilding>(
×
433
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobTemple>(cSel)));
×
434
            else
435
                WINDOWMANAGER.Show(std::make_unique<iwBuilding>(
×
436
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobUsual>(cSel)));
×
437
            return true;
×
438
        }
439
        // oder vielleicht eine Baustelle?
440
        else if(selObj.GetType() == NodalObjectType::Buildingsite && worldViewer.IsOwner(cSel))
1✔
441
        {
442
            if(!WINDOWMANAGER.FindNonModalWindow(CGI_BUILDING + MapBase::CreateGUIID(cSel)))
×
443
                WINDOWMANAGER.Show(
×
444
                  std::make_unique<iwBuildingSite>(gwv, worldViewer.GetWorld().GetSpecObj<noBuildingSite>(cSel)));
×
445
            return true;
×
446
        }
447

448
        action_tabs.watch = true;
1✔
449
        // Unser Land
450
        if(worldViewer.IsOwner(cSel))
1✔
451
        {
452
            const BuildingQuality bq = worldViewer.GetBQ(cSel);
1✔
453
            // Kann hier was gebaut werden?
454
            if(bq >= BuildingQuality::Mine)
1✔
455
            {
456
                action_tabs.build = true;
1✔
457

458
                // Welches Gebäude kann gebaut werden?
459
                switch(bq)
1✔
460
                {
461
                    case BuildingQuality::Mine: action_tabs.build_tabs = iwAction::BuildTab::Mine; break;
×
462
                    case BuildingQuality::Hut: action_tabs.build_tabs = iwAction::BuildTab::Hut; break;
×
463
                    case BuildingQuality::House: action_tabs.build_tabs = iwAction::BuildTab::House; break;
×
464
                    case BuildingQuality::Castle: action_tabs.build_tabs = iwAction::BuildTab::Castle; break;
1✔
465
                    case BuildingQuality::Harbor: action_tabs.build_tabs = iwAction::BuildTab::Harbor; break;
×
466
                    default: break;
×
467
                }
468

469
                if(!worldViewer.GetWorld().IsFlagAround(cSel))
1✔
470
                    action_tabs.setflag = true;
1✔
471

472
                // Prüfen, ob sich Militärgebäude in der Nähe befinden, wenn nein, können auch eigene
473
                // Militärgebäude gebaut werden
474
                enable_military_buildings =
1✔
475
                  !worldViewer.GetWorld().IsMilitaryBuildingNearNode(cSel, worldViewer.GetPlayerId());
1✔
476
            } else if(bq == BuildingQuality::Flag)
×
477
                action_tabs.setflag = true;
×
478
            else if(selObj.GetType() == NodalObjectType::Flag)
×
479
                action_tabs.flag = true;
×
480

481
            if(selObj.GetType() != NodalObjectType::Flag && selObj.GetType() != NodalObjectType::Building)
1✔
482
            {
483
                // Check if there are roads
484
                for(const Direction dir : helpers::EnumRange<Direction>{})
16✔
485
                {
486
                    const PointRoad curRoad = worldViewer.GetVisiblePointRoad(cSel, dir);
6✔
487
                    if(curRoad != PointRoad::None)
6✔
488
                    {
489
                        action_tabs.cutroad = true;
×
490
                        action_tabs.upgradeRoad |= (curRoad == PointRoad::Normal);
×
491
                    }
492
                }
493
            }
494
        }
495
        // evtl ists ein feindliches Militärgebäude, welches NICHT im Nebel liegt?
496
        else if(worldViewer.GetVisibility(cSel) == Visibility::Visible)
×
497
        {
498
            if(selObj.GetType() == NodalObjectType::Building)
×
499
            {
500
                const auto* building = worldViewer.GetWorld().GetSpecObj<noBuilding>(cSel); //-V807
×
501
                BuildingType bt = building->GetBuildingType();
×
502

503
                // Only if trade is enabled
504
                if(worldViewer.GetWorld().GetGGS().isEnabled(AddonId::TRADE))
×
505
                {
506
                    // Allied warehouse? -> Show trade window
507
                    if(BuildingProperties::IsWareHouse(bt) && worldViewer.GetPlayer().IsAlly(building->GetPlayer()))
×
508
                    {
509
                        WINDOWMANAGER.Show(std::make_unique<iwTrade>(*static_cast<const nobBaseWarehouse*>(building),
×
510
                                                                     worldViewer, GAMECLIENT));
×
511
                        return true;
×
512
                    }
513
                }
514

515
                // Ist es ein gewöhnliches Militärgebäude?
516
                if(BuildingProperties::IsMilitary(bt))
×
517
                {
518
                    // Dann darf es nicht neu gebaut sein!
519
                    if(!static_cast<const nobMilitary*>(building)->IsNewBuilt())
×
520
                        action_tabs.attack = true;
×
521
                }
522
                // oder ein HQ oder Hafen?
523
                else if(bt == BuildingType::Headquarters || bt == BuildingType::HarborBuilding)
×
524
                    action_tabs.attack = true;
×
525
                action_tabs.sea_attack =
×
526
                  action_tabs.attack && worldViewer.GetWorld().GetGGS().isEnabled(AddonId::SEA_ATTACK);
×
527
            }
528
        }
529

530
        // Bisheriges Actionfenster schließen, falls es eins gab
531
        // aktuelle Mausposition merken, da diese durch das Schließen verändert werden kann
532
        if(actionwindow)
1✔
533
            actionwindow->Close();
×
534
        VIDEODRIVER.SetMousePos(mc.pos);
1✔
535

536
        ShowActionWindow(action_tabs, cSel, mc.pos, enable_military_buildings);
1✔
537
    }
538

539
    return true;
2✔
540
}
541

NEW
542
void dskGameInterface::Msg_ButtonClick(const unsigned ctrl_id)
×
543
{
NEW
544
    switch(ctrl_id)
×
545
    {
NEW
546
        case ID_btMap: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMinimap>(minimap, gwv)); break;
×
NEW
547
        case ID_btOptions: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMainMenu>(gwv, GAMECLIENT)); break;
×
NEW
548
        case ID_btConstructionAid:
×
NEW
549
            if(WINDOWMANAGER.IsDesktopActive())
×
NEW
550
                gwv.ToggleShowBQ();
×
NEW
551
            break;
×
NEW
552
        case ID_btPost:
×
NEW
553
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwPostWindow>(gwv, GetPostBox()));
×
NEW
554
            UpdatePostIcon(GetPostBox().GetNumMsgs(), false);
×
NEW
555
            break;
×
556
    }
NEW
557
}
×
558

NEW
559
void dskGameInterface::Msg_PaintBefore()
×
560
{
NEW
561
    Desktop::Msg_PaintBefore();
×
562

563
    // Spiel ausführen
NEW
564
    Run();
×
565

566
    /// Padding of the figures
NEW
567
    const DrawPoint figPadding(12, 12);
×
NEW
568
    const DrawPoint screenSize(VIDEODRIVER.GetRenderSize());
×
569
    // Rahmen zeichnen
NEW
570
    borders[0]->DrawFull(DrawPoint(0, 0));                                      // oben (mit Ecken)
×
NEW
571
    borders[1]->DrawFull(DrawPoint(0, screenSize.y - figPadding.y));            // unten (mit Ecken)
×
NEW
572
    borders[2]->DrawFull(DrawPoint(0, figPadding.y));                           // links
×
NEW
573
    borders[3]->DrawFull(DrawPoint(screenSize.x - figPadding.x, figPadding.y)); // rechts
×
574

575
    // The figure/statues and the button bar
NEW
576
    glArchivItem_Bitmap& imgFigLeftTop = *LOADER.GetImageN("resource", 17);
×
NEW
577
    glArchivItem_Bitmap& imgFigRightTop = *LOADER.GetImageN("resource", 18);
×
NEW
578
    glArchivItem_Bitmap& imgFigLeftBot = *LOADER.GetImageN("resource", 19);
×
NEW
579
    glArchivItem_Bitmap& imgFigRightBot = *LOADER.GetImageN("resource", 20);
×
NEW
580
    imgFigLeftTop.DrawFull(figPadding);
×
NEW
581
    imgFigRightTop.DrawFull(DrawPoint(screenSize.x - figPadding.x - imgFigRightTop.getWidth(), figPadding.y));
×
NEW
582
    imgFigLeftBot.DrawFull(DrawPoint(figPadding.x, screenSize.y - figPadding.y - imgFigLeftBot.getHeight()));
×
NEW
583
    imgFigRightBot.DrawFull(screenSize - figPadding - imgFigRightBot.GetSize());
×
584

NEW
585
    glArchivItem_Bitmap& imgButtonBar = *LOADER.GetImageN("resource", 29);
×
NEW
586
    imgButtonBar.DrawFull(
×
NEW
587
      DrawPoint((screenSize.x - imgButtonBar.getWidth()) / 2, screenSize.y - imgButtonBar.getHeight()));
×
NEW
588
}
×
589

NEW
590
void dskGameInterface::Msg_PaintAfter()
×
591
{
NEW
592
    Desktop::Msg_PaintAfter();
×
593

NEW
594
    const GameWorldBase& world = worldViewer.GetWorld();
×
595

NEW
596
    if(SETTINGS.global.showGFInfo)
×
597
    {
598
        std::array<char, 256> nwf_string;
NEW
599
        if(GAMECLIENT.IsReplayModeOn())
×
600
        {
NEW
601
            snprintf(nwf_string.data(), nwf_string.size(),
×
602
                     _("(Replay-Mode) Current GF: %u (End at: %u) / GF length: %u ms / NWF length: %u gf (%u ms)"),
NEW
603
                     world.GetEvMgr().GetCurrentGF(), GAMECLIENT.GetLastReplayGF(),
×
NEW
604
                     GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1), GAMECLIENT.GetNWFLength(),
×
NEW
605
                     GAMECLIENT.GetNWFLength() * GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1));
×
606
        } else
NEW
607
            snprintf(nwf_string.data(), nwf_string.size(),
×
608
                     _("Current GF: %u / GF length: %u ms / NWF length: %u gf (%u ms) /  Ping: %u ms"),
NEW
609
                     world.GetEvMgr().GetCurrentGF(), GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1),
×
NEW
610
                     GAMECLIENT.GetNWFLength(),
×
NEW
611
                     GAMECLIENT.GetNWFLength() * GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1),
×
NEW
612
                     worldViewer.GetPlayer().ping);
×
NEW
613
        NormalFont->Draw(DrawPoint(30, 1), nwf_string.data(), FontStyle{}, COLOR_YELLOW);
×
614
    }
615

616
    // tournament mode?
NEW
617
    const unsigned tournamentDuration = GAMECLIENT.GetTournamentModeDuration();
×
NEW
618
    if(tournamentDuration)
×
619
    {
NEW
620
        unsigned curGF = world.GetEvMgr().GetCurrentGF();
×
NEW
621
        std::string tournamentNotice;
×
NEW
622
        if(curGF >= tournamentDuration)
×
NEW
623
            tournamentNotice = _("Tournament finished");
×
624
        else
625
        {
626
            tournamentNotice =
NEW
627
              helpers::format("Tournament mode: %1% remaining", GAMECLIENT.FormatGFTime(tournamentDuration - curGF));
×
628
        }
NEW
629
        NormalFont->Draw(DrawPoint(VIDEODRIVER.GetRenderSize().x - 30, 1), tournamentNotice, FontStyle::AlignH::RIGHT,
×
630
                         COLOR_YELLOW);
631
    }
632

633
    // Replaydateianzeige in der linken unteren Ecke
NEW
634
    if(GAMECLIENT.IsReplayModeOn())
×
635
    {
NEW
636
        NormalFont->Draw(DrawPoint(0, VIDEODRIVER.GetRenderSize().y), GAMECLIENT.GetReplayFilename().string(),
×
637
                         FontStyle::BOTTOM, COLOR_YELLOW);
638
    } else
639
    {
640
        // Laggende Spieler anzeigen in Form von Schnecken
NEW
641
        DrawPoint snailPos(VIDEODRIVER.GetRenderSize().x - 70, 35);
×
NEW
642
        for(const NWFPlayerInfo& player : nwfInfo_->getPlayerInfos())
×
643
        {
NEW
644
            if(player.isLagging)
×
645
            {
NEW
646
                LOADER.GetPlayerImage("rttr", 0)->DrawFull(Rect(snailPos, 30, 30), COLOR_WHITE,
×
NEW
647
                                                           game_->world_.GetPlayer(player.id).color);
×
NEW
648
                snailPos.x -= 40;
×
649
            }
650
        }
651
    }
652

653
    // Show icons in the upper right corner of the game interface
NEW
654
    DrawPoint iconPos(VIDEODRIVER.GetRenderSize().x - 56, 32);
×
655

656
    // Draw cheating indicator icon (WINTER)
NEW
657
    if(cheats_.isCheatModeOn())
×
658
    {
NEW
659
        glArchivItem_Bitmap* cheatingImg = LOADER.GetImageN("io", 75);
×
NEW
660
        cheatingImg->DrawFull(iconPos);
×
NEW
661
        iconPos -= DrawPoint(cheatingImg->getWidth() + 6, 0);
×
662
    }
663

664
    // Draw speed indicator icon
NEW
665
    const int speedStep = static_cast<int>(REFERENCE_SPEED / 10ms) - static_cast<int>(GAMECLIENT.GetGFLength() / 10ms);
×
666

NEW
667
    if(speedStep != 0)
×
668
    {
NEW
669
        glArchivItem_Bitmap* runnerImg = LOADER.GetImageN("io", 164);
×
670

NEW
671
        runnerImg->DrawFull(iconPos);
×
672

NEW
673
        if(speedStep != 1)
×
674
        {
NEW
675
            std::string multiplier = helpers::toString(std::abs(speedStep));
×
NEW
676
            NormalFont->Draw(iconPos - runnerImg->GetOrigin() + DrawPoint(19, 6), multiplier, FontStyle::LEFT,
×
677
                             speedStep > 0 ? COLOR_YELLOW : COLOR_RED);
678
        }
NEW
679
        iconPos -= DrawPoint(runnerImg->getWidth() + 4, 0);
×
680
    }
681

682
    // Draw zoom level indicator icon
NEW
683
    if(gwv.GetCurrentTargetZoomFactor() != 1.f) //-V550
×
684
    {
NEW
685
        glArchivItem_Bitmap* magnifierImg = LOADER.GetImageN("io", 36);
×
686

NEW
687
        magnifierImg->DrawFull(iconPos);
×
688

NEW
689
        std::string zoom_percent = helpers::toString((int)(gwv.GetCurrentTargetZoomFactor() * 100)) + "%";
×
NEW
690
        NormalFont->Draw(iconPos - magnifierImg->GetOrigin() + DrawPoint(9, 7), zoom_percent, FontStyle::CENTER,
×
691
                         COLOR_YELLOW);
NEW
692
        iconPos -= DrawPoint(magnifierImg->getWidth() + 4, 0);
×
693
    }
NEW
694
}
×
695

696
bool dskGameInterface::Msg_LeftDown(const MouseCoords& mc)
3✔
697
{
698
    DrawPoint btOrig(VIDEODRIVER.GetRenderSize().x / 2 - LOADER.GetImageN("resource", 29)->getWidth() / 2 + 44,
6✔
699
                     VIDEODRIVER.GetRenderSize().y - LOADER.GetImageN("resource", 29)->getHeight() + 4);
9✔
700
    Extent btSize = Extent(37, 32) * 4u;
3✔
701
    if(IsPointInRect(mc.pos, Rect(btOrig, btSize)))
3✔
NEW
702
        return false;
×
703

704
    if(!VIDEODRIVER.IsTouch())
3✔
705
    {
706
        // Start scrolling also on Ctrl + left click
707
        if(VIDEODRIVER.GetModKeyState().ctrl)
3✔
708
        {
709
            Msg_RightDown(mc);
1✔
710
            return true;
1✔
711
        } else if(isScrolling)
2✔
712
            StopScrolling();
2✔
713

714
        return ContextClick(mc);
2✔
715

NEW
716
    } else if(mc.num_tfingers < 2)
×
NEW
717
        touchDuration = VIDEODRIVER.GetTickCount();
×
NEW
718
    else if(isScrolling) // 2 fingers down -> zoom mode. Do not click or scroll map
×
NEW
719
        StopScrolling();
×
720

NEW
721
    return true;
×
722
}
723

724
bool dskGameInterface::Msg_LeftUp(const MouseCoords& mc)
2✔
725
{
726
    if(isScrolling)
2✔
727
    {
728
        StopScrolling();
1✔
729
        return true;
1✔
730
    }
731

732
    // num_tfingers is reduced after this function to check if it's still a touch event
733
    // Was touch duration short enough to trigger conext click?
734
    if(mc.num_tfingers == 1 && (VIDEODRIVER.GetTickCount() - touchDuration) < TOUCH_MAX_CLICK_INTERVAL)
1✔
NEW
735
        return ContextClick(mc);
×
736

737
    return false;
1✔
738
}
739

740
bool dskGameInterface::Msg_MouseMove(const MouseCoords& mc)
22✔
741
{
742
    if(!isScrolling)
22✔
743
    {
744
        if(mc.num_tfingers == 1)
13✔
NEW
745
            Msg_RightDown(mc);
×
746
        else
747
            return false;
13✔
748
    }
749

750
    if(SETTINGS.interface.mapScrollMode == MapScrollMode::GrabAndDrag)
9✔
751
    {
752
        const Position mapPos = gwv.ViewPosToMap(mc.pos);
1✔
753
        gwv.MoveBy(-(mapPos - startScrollPt));
1✔
754
        startScrollPt = mapPos;
1✔
755
    } else
756
    {
757
        int acceleration = SETTINGS.global.smartCursor ? 2 : 3;
8✔
758

759
        if(SETTINGS.interface.mapScrollMode == MapScrollMode::ScrollSame)
8✔
760
            acceleration = -acceleration;
1✔
761

762
        gwv.MoveBy((mc.pos - startScrollPt) * acceleration);
8✔
763
        VIDEODRIVER.SetMousePos(startScrollPt);
8✔
764

765
        if(!SETTINGS.global.smartCursor)
8✔
NEW
766
            startScrollPt = mc.pos;
×
767
    }
768

769
    return true;
9✔
770
}
771

772
bool dskGameInterface::Msg_RightDown(const MouseCoords& mc)
7✔
773
{
774
    if(SETTINGS.interface.mapScrollMode == MapScrollMode::GrabAndDrag)
7✔
775
        StartScrolling(gwv.ViewPosToMap(mc.pos));
1✔
776
    else
777
        StartScrolling(mc.pos);
6✔
778
    return true;
7✔
779
}
780

781
bool dskGameInterface::Msg_RightUp(const MouseCoords& /*mc*/) //-V524
4✔
782
{
783
    if(isScrolling)
4✔
784
        StopScrolling();
4✔
785
    return false;
4✔
786
}
787

788
bool dskGameInterface::Msg_KeyDown(const KeyEvent& ke)
15✔
789
{
790
    cheatCommandTracker_.onKeyEvent(ke);
15✔
791

792
    switch(ke.kt)
15✔
793
    {
794
        default: break;
15✔
795
        case KeyType::Return: // Open chat
×
796
            WINDOWMANAGER.Show(std::make_unique<iwChat>(this));
×
797
            return true;
×
798

799
        case KeyType::Space: // Show / hide construction aid
×
800
            gwv.ToggleShowBQ();
×
801
            return true;
×
802

803
        case KeyType::Left: // Scroll left
×
804
            gwv.MoveBy({-30, 0});
×
805
            return true;
×
806
        case KeyType::Right: // Scroll right
×
807
            gwv.MoveBy({30, 0});
×
808
            return true;
×
809
        case KeyType::Up: // Scroll up
×
810
            gwv.MoveBy({0, -30});
×
811
            return true;
×
812
        case KeyType::Down: // Scroll down
×
813
            gwv.MoveBy({0, 30});
×
814
            return true;
×
815

816
        case KeyType::F2: // Open save game window
×
817
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwSave>());
×
818
            return true;
×
819
        case KeyType::F3: // Map debug window
×
820
        {
821
            const bool replayMode = GAMECLIENT.IsReplayModeOn();
×
822
            if(replayMode)
×
823
                DisableFoW(true);
×
824
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMapDebug>(gwv, game_->world_.IsSinglePlayer() || replayMode));
×
825
            return true;
×
826
        }
827
        case KeyType::F8:
×
828
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("keyboardlayout.txt", _("Keyboard layout")));
×
829
            return true;
×
830
        case KeyType::F9:
×
831
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("readme.txt", _("Readme!")));
×
832
            return true;
×
833
        case KeyType::F11: // Music player (midi files)
×
834
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMusicPlayer>());
×
835
            return true;
×
836
        case KeyType::F12: // Ingame options
×
837
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwOptionsWindow>(gwv.GetSoundMgr()));
×
838
            return true;
×
839
    }
840

841
    switch(ke.c)
15✔
842
    {
843
        case '+':
×
844
            if(GAMECLIENT.IsReplayModeOn() || game_->world_.IsSinglePlayer())
×
845
                GAMECLIENT.IncreaseSpeed();
×
846
            return true;
×
847
        case '-':
×
848
            if(GAMECLIENT.IsReplayModeOn() || game_->world_.IsSinglePlayer())
×
849
                GAMECLIENT.DecreaseSpeed();
×
850
            return true;
×
851

852
        // Switch to specific player
853
        case '1':
×
854
        case '2':
855
        case '3':
856
        case '4':
857
        case '5':
858
        case '6':
859
        case '7':
860
        case '8':
861
        {
862
            unsigned playerIdx = ke.c - '1';
×
863
            if(GAMECLIENT.IsReplayModeOn())
×
864
            {
865
                unsigned oldPlayerId = worldViewer.GetPlayerId();
×
866
                GAMECLIENT.ChangePlayerIngame(worldViewer.GetPlayerId(), playerIdx);
×
867
                RTTR_Assert(worldViewer.GetPlayerId() == oldPlayerId || worldViewer.GetPlayerId() == playerIdx);
×
868
            } else if(playerIdx < worldViewer.GetWorld().GetNumPlayers())
×
869
            {
870
                // On multiplayer this currently asyncs, but as this is a debug feature anyway just disable it.
871
                // If this should be enabled again, look into the handling/clearing of accumulated GCs
872
                if(game_->world_.IsSinglePlayer())
×
873
                {
874
                    const GamePlayer& player = worldViewer.GetWorld().GetPlayer(playerIdx);
×
875
                    if(player.ps == PlayerState::AI && player.aiInfo.type == AI::Type::Dummy)
×
876
                        GAMECLIENT.RequestSwapToPlayer(playerIdx);
×
877
                }
878
            }
879
            return true;
×
880
        }
881

882
        case 'b': gwv.MoveToLastPosition(); return true;
×
883
        case 'v':
×
884
            if(game_->world_.IsSinglePlayer())
×
885
                GAMECLIENT.IncreaseSpeed(true);
×
886
            return true;
×
887
        case 'c': // Show/hide building names
×
888
            gwv.ToggleShowNames();
×
889
            return true;
×
890
        case 'd': // Enable/Disable fog of war (in replay mode)
×
891
            ToggleFoW();
×
892
            return true;
×
893
        case 'h': // Go to HQ
×
894
        {
895
            const GamePlayer& player = worldViewer.GetPlayer();
×
896
            // HQ might not exist anymore
897
            if(player.GetHQPos().isValid())
×
898
                gwv.MoveToMapPt(player.GetHQPos());
×
899
        }
900
            return true;
×
901
        case 'i': // Show inventory
×
902
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwInventory>(worldViewer.GetPlayer()));
×
903
            return true;
×
904
        case 'j': // Skip GFs (fast forward)
×
905
            if(game_->world_.IsSinglePlayer() || GAMECLIENT.IsReplayModeOn())
×
906
                WINDOWMANAGER.ToggleWindow(std::make_unique<iwSkipGFs>(gwv));
×
907
            return true;
×
908
        case 'l': // Show minimap
×
909
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMinimap>(minimap, gwv));
×
910
            return true;
×
911
        case 'm': // Show main menu
2✔
912
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMainMenu>(gwv, GAMECLIENT));
2✔
913
            return true;
2✔
914
        case 'n': // Show message window
×
915
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwPostWindow>(gwv, GetPostBox()));
×
916
            UpdatePostIcon(GetPostBox().GetNumMsgs(), false);
×
917
            return true;
×
918
        case 'p': // Pause
×
919
            GAMECLIENT.TogglePause();
×
920
            return true;
×
921
        case 'q': // Quit game (dialog)
×
922
            if(ke.alt)
×
923
                WINDOWMANAGER.ToggleWindow(std::make_unique<iwEndgame>());
×
924
            return true;
×
925
        case 's': // Show/hide productivity overlay
×
926
            gwv.ToggleShowProductivity();
×
927
            return true;
×
928
        case 26: // ctrl+z
×
929
            gwv.SetZoomFactor(ZOOM_FACTORS[ZOOM_DEFAULT_INDEX]);
×
930
            return true;
×
931
        case 'z':
9✔
932
            if(ke.ctrl) // Reset zoom
9✔
933
                gwv.SetZoomFactor(ZOOM_FACTORS[ZOOM_DEFAULT_INDEX]);
2✔
934
            else // zoom in
935
                gwv.SetZoomFactor(getNextZoomLevel(gwv.GetCurrentTargetZoomFactor()));
7✔
936
            return true;
9✔
937
        case 'Z': // shift-z, zoom out
4✔
938
            gwv.SetZoomFactor(getPreviousZoomLevel(gwv.GetCurrentTargetZoomFactor()));
4✔
939
            return true;
4✔
940
    }
941

942
    return false;
×
943
}
944

945
bool dskGameInterface::Msg_WheelUp(const MouseCoords&)
8✔
946
{
947
    WheelZoom(ZOOM_WHEEL_INCREMENT);
8✔
948
    return true;
8✔
949
}
950
bool dskGameInterface::Msg_WheelDown(const MouseCoords&)
9✔
951
{
952
    WheelZoom(-ZOOM_WHEEL_INCREMENT);
9✔
953
    return true;
9✔
954
}
955

956
void dskGameInterface::WheelZoom(const float step)
17✔
957
{
958
    auto targetZoomFactor = gwv.GetCurrentTargetZoomFactor() * (1 + step);
17✔
959
    targetZoomFactor = std::clamp(targetZoomFactor, ZOOM_FACTORS.front(), ZOOM_FACTORS.back());
17✔
960
    if(targetZoomFactor > 1 - ZOOM_WHEEL_INCREMENT && targetZoomFactor < 1 + ZOOM_WHEEL_INCREMENT)
17✔
961
        targetZoomFactor = 1.f; // Snap to 100%
2✔
962

963
    gwv.SetZoomFactor(targetZoomFactor);
17✔
964
}
17✔
965

966
void dskGameInterface::OnBuildingNote(const BuildingNote& note)
×
967
{
968
    switch(note.type)
×
969
    {
970
        case BuildingNote::Constructed:
×
971
        case BuildingNote::Destroyed:
972
        case BuildingNote::Lost:
973
            // Close the related window as the building does not exist anymore
974
            // In "Constructed" this means the buildingsite
975
            WINDOWMANAGER.Close(CGI_BUILDING + MapBase::CreateGUIID(note.pos));
×
976
            break;
×
977
        default: break;
×
978
    }
979
}
×
980

981
void dskGameInterface::Run()
×
982
{
983
    // Reset draw counter of the trees before drawing
984
    noTree::ResetDrawCounter();
×
985

986
    unsigned water_percent;
987
    // Draw mouse only if not on window
988
    bool drawMouse = WINDOWMANAGER.FindWindowAtPos(VIDEODRIVER.GetMousePos()) == nullptr;
×
989
    gwv.Draw(road, actionwindow != nullptr ? actionwindow->GetSelectedPt() : MapPoint::Invalid(), drawMouse,
×
990
             &water_percent);
991

992
    // Indicate that the game is paused by darkening the screen (dark semi-transparent overlay)
993
    if(GAMECLIENT.IsPaused())
×
994
        DrawRectangle(Rect(DrawPoint(0, 0), VIDEODRIVER.GetRenderSize()), COLOR_SHADOW);
×
995
    else
996
    {
997
        // Play ambient sounds if game is not paused
998
        worldViewer.GetSoundMgr().playOceanBrawling(water_percent);
×
999
        worldViewer.GetSoundMgr().playBirdSounds(noTree::QueryDrawCounter());
×
1000
    }
1001

1002
    messenger.Draw();
×
1003
}
×
1004

1005
void dskGameInterface::GI_StartRoadBuilding(const MapPoint startPt, bool waterRoad)
3✔
1006
{
1007
    // Im Replay keine Straßen bauen
1008
    if(GAMECLIENT.IsReplayModeOn())
3✔
1009
        return;
×
1010

1011
    road.mode = waterRoad ? RoadBuildMode::Boat : RoadBuildMode::Normal;
3✔
1012
    road.route.clear();
3✔
1013
    road.start = road.point = startPt;
3✔
1014
    WINDOWMANAGER.SetCursor(Cursor::Remove);
3✔
1015
}
1016

1017
void dskGameInterface::GI_CancelRoadBuilding()
2✔
1018
{
1019
    if(road.mode == RoadBuildMode::Disabled)
2✔
1020
        return;
×
1021
    road.mode = RoadBuildMode::Disabled;
2✔
1022
    worldViewer.RemoveVisualRoad(road.start, road.route);
2✔
1023
    WINDOWMANAGER.SetCursor(isScrolling ? Cursor::Scroll : Cursor::Hand);
2✔
1024
}
1025

1026
bool dskGameInterface::BuildRoadPart(MapPoint& cSel)
3✔
1027
{
1028
    std::vector<Direction> new_route =
1029
      FindPathForRoad(worldViewer, road.point, cSel, road.mode == RoadBuildMode::Boat, 100);
6✔
1030
    // Weg gefunden?
1031
    if(new_route.empty())
3✔
1032
        return false;
×
1033

1034
    // Test on water way length
1035
    if(road.mode == RoadBuildMode::Boat)
3✔
1036
    {
1037
        unsigned char index = worldViewer.GetWorld().GetGGS().getSelection(AddonId::MAX_WATERWAY_LENGTH);
×
1038

1039
        RTTR_Assert(index < waterwayLengths.size());
×
1040
        const unsigned max_length = waterwayLengths[index];
×
1041

1042
        unsigned length = road.route.size() + new_route.size();
×
1043

1044
        // max_length == 0 heißt beliebig lang, ansonsten
1045
        // Weg zurechtstutzen.
1046
        if(max_length > 0)
×
1047
        {
1048
            while(length > max_length)
×
1049
            {
1050
                new_route.pop_back();
×
1051
                --length;
×
1052
            }
1053
        }
1054
    }
1055

1056
    // Weg (visuell) bauen
1057
    for(const auto dir : new_route)
22✔
1058
    {
1059
        worldViewer.SetVisiblePointRoad(road.point, dir,
19✔
1060
                                        (road.mode == RoadBuildMode::Boat) ? PointRoad::Boat : PointRoad::Normal);
19✔
1061
        worldViewer.RecalcBQForRoad(road.point);
19✔
1062
        road.point = worldViewer.GetWorld().GetNeighbour(road.point, dir);
19✔
1063
    }
1064
    worldViewer.RecalcBQForRoad(road.point);
3✔
1065

1066
    // Zielpunkt updaten (für Wasserweg)
1067
    cSel = road.point;
3✔
1068

1069
    road.route.insert(road.route.end(), new_route.begin(), new_route.end());
3✔
1070

1071
    return true;
3✔
1072
}
1073

1074
unsigned dskGameInterface::GetIdInCurBuildRoad(const MapPoint pt)
1✔
1075
{
1076
    MapPoint curPt = road.start;
1✔
1077
    for(unsigned i = 0; i < road.route.size(); ++i)
2✔
1078
    {
1079
        if(curPt == pt)
2✔
1080
            return i + 1;
1✔
1081

1082
        curPt = worldViewer.GetNeighbour(curPt, road.route[i]);
1✔
1083
    }
1084
    return 0;
×
1085
}
1086

1087
void dskGameInterface::ShowRoadWindow(const Position& mousePos)
×
1088
{
1089
    roadwindow = &WINDOWMANAGER.Show(
×
1090
      std::make_unique<iwRoadWindow>(*this, worldViewer.GetBQ(road.point) != BuildingQuality::Nothing, mousePos), true);
×
1091
}
×
1092

1093
void dskGameInterface::ShowActionWindow(const iwAction::Tabs& action_tabs, MapPoint cSel, const DrawPoint& mousePos,
2✔
1094
                                        const bool enable_military_buildings)
1095
{
1096
    const GameWorldBase& world = worldViewer.GetWorld();
2✔
1097

1098
    iwAction::Params params;
2✔
1099

1100
    // Sind wir am Wasser?
1101
    if(action_tabs.setflag)
2✔
1102
    {
1103
        auto isWater = [](const auto& desc) { return desc.kind == TerrainKind::Water; };
6✔
1104
        if(world.HasTerrain(cSel, isWater))
1✔
1105
            params = iwAction::FlagType::WaterFlag;
×
1106
    }
1107

1108
    // Wenn es einen Flaggen-Tab gibt, dann den Flaggentyp herausfinden und die Art des Fensters entsprechende setzen
1109
    if(action_tabs.flag)
2✔
1110
    {
1111
        if(world.GetNO(world.GetNeighbour(cSel, Direction::NorthWest))->GetGOT() == GO_Type::NobHq)
×
1112
            params = iwAction::FlagType::HQ;
×
1113
        else if(world.GetNO(cSel)->GetType() == NodalObjectType::Flag)
×
1114
        {
1115
            if(world.GetSpecObj<noFlag>(cSel)->GetFlagType() == FlagType::Water)
×
1116
                params = iwAction::FlagType::WaterFlag;
×
1117
        }
1118
    }
1119

1120
    // Angriffstab muss wissen, wieviel Soldaten maximal entsendet werden können
1121
    if(action_tabs.attack)
2✔
1122
    {
1123
        params = worldViewer.GetNumSoldiersForAttack(cSel);
×
1124
    }
1125

1126
    actionwindow = &WINDOWMANAGER.Show(
2✔
1127
      std::make_unique<iwAction>(*this, gwv, action_tabs, cSel, mousePos, params, enable_military_buildings), true);
2✔
1128
}
2✔
1129

1130
void dskGameInterface::OnChatCommand(const std::string& cmd)
×
1131
{
1132
    cheatCommandTracker_.onChatCommand(cmd);
×
1133

1134
    if(cmd == "surrender")
×
1135
        GAMECLIENT.Surrender();
×
1136
    else if(cmd == "async")
×
1137
        (void)RANDOM.Rand(RANDOM_CONTEXT2(0), 255);
×
1138
    else if(cmd == "segfault")
×
1139
    {
1140
        char* x = nullptr;
×
1141
        *x = 1; //-V522 // NOLINT
×
1142
    } else if(cmd == "reload")
×
1143
    {
1144
        WorldDescription newDesc;
×
1145
        GameDataLoader gdLoader(newDesc);
×
1146
        if(gdLoader.Load())
×
1147
        {
1148
            const_cast<GameWorld&>(game_->world_).GetDescriptionWriteable() = newDesc;
×
1149
            worldViewer.InitTerrainRenderer();
×
1150
        }
1151
    }
1152
}
×
1153

1154
void dskGameInterface::GI_BuildRoad()
×
1155
{
1156
    if(GAMECLIENT.BuildRoad(road.start, road.mode == RoadBuildMode::Boat, road.route))
×
1157
    {
1158
        road.mode = RoadBuildMode::Disabled;
×
1159
        WINDOWMANAGER.SetCursor(Cursor::Hand);
×
1160
    }
1161
}
×
1162

1163
void dskGameInterface::Msg_WindowClosed(IngameWindow& wnd)
2✔
1164
{
1165
    if(actionwindow == &wnd)
2✔
1166
        actionwindow = nullptr;
1✔
1167
    else if(roadwindow == &wnd)
1✔
1168
        roadwindow = nullptr;
×
1169
}
2✔
1170

1171
void dskGameInterface::GI_FlagDestroyed(const MapPoint pt)
×
1172
{
1173
    // Im Wegbaumodus und haben wir von hier eine Flagge gebaut?
1174
    if(road.mode != RoadBuildMode::Disabled && road.start == pt)
×
1175
    {
1176
        GI_CancelRoadBuilding();
×
1177
    }
1178

1179
    // Evtl Actionfenster schließen, da sich das ja auch auf diese Flagge bezieht
1180
    if(actionwindow)
×
1181
    {
1182
        if(actionwindow->GetSelectedPt() == pt)
×
1183
            actionwindow->Close();
×
1184
    }
1185
}
×
1186

1187
void dskGameInterface::CI_PlayerLeft(const unsigned playerId)
×
1188
{
1189
    // Info-Meldung ausgeben
1190
    std::string text =
1191
      helpers::format(_("Player '%s' left the game!"), worldViewer.GetWorld().GetPlayer(playerId).name);
×
1192
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_RED);
×
1193
    // Im Spiel anzeigen, dass die KI das Spiel betreten hat
1194
    text = helpers::format(_("Player '%s' joined the game!"), "KI");
×
1195
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_GREEN);
×
1196
}
×
1197

1198
void dskGameInterface::CI_GGSChanged(const GlobalGameSettings& /*ggs*/)
×
1199
{
1200
    // TODO: print what has changed
1201
    const std::string text = helpers::format(_("Note: Game settings changed by the server%s"), "");
×
1202
    messenger.AddMessage("", 0, ChatDestination::System, text);
×
1203
}
×
1204

1205
void dskGameInterface::CI_Chat(const unsigned playerId, const ChatDestination cd, const std::string& msg)
×
1206
{
1207
    messenger.AddMessage(worldViewer.GetWorld().GetPlayer(playerId).name,
×
1208
                         worldViewer.GetWorld().GetPlayer(playerId).color, cd, msg);
×
1209
}
×
1210

1211
void dskGameInterface::CI_Async(const std::string& checksums_list)
×
1212
{
1213
    messenger.AddMessage("", 0, ChatDestination::System,
×
1214
                         _("The Game is not in sync. Checksums of some players don't match."), COLOR_RED);
1215
    messenger.AddMessage("", 0, ChatDestination::System, checksums_list, COLOR_YELLOW);
×
1216
    messenger.AddMessage("", 0, ChatDestination::System, _("A auto-savegame is created..."), COLOR_RED);
×
1217
}
×
1218

1219
void dskGameInterface::CI_ReplayAsync(const std::string& msg)
×
1220
{
1221
    messenger.AddMessage("", 0, ChatDestination::System, msg, COLOR_RED);
×
1222
}
×
1223

1224
void dskGameInterface::CI_ReplayEndReached(const std::string& msg)
×
1225
{
1226
    messenger.AddMessage("", 0, ChatDestination::System, msg, COLOR_BLUE);
×
1227
}
×
1228

1229
void dskGameInterface::CI_GamePaused()
×
1230
{
1231
    messenger.AddMessage(_("SYSTEM"), COLOR_GREY, ChatDestination::System, _("Game was paused."));
×
1232
}
×
1233

1234
void dskGameInterface::CI_GameResumed()
×
1235
{
1236
    messenger.AddMessage(_("SYSTEM"), COLOR_GREY, ChatDestination::System, _("Game was resumed."));
×
1237
}
×
1238

1239
void dskGameInterface::CI_Error(const ClientError ce)
×
1240
{
1241
    messenger.AddMessage("", 0, ChatDestination::System, ClientErrorToStr(ce), COLOR_RED);
×
1242
    GAMECLIENT.SetPause(true);
×
1243
}
×
1244

1245
/**
1246
 *  Status: Verbindung verloren.
1247
 */
1248
void dskGameInterface::LC_Status_ConnectionLost()
×
1249
{
1250
    messenger.AddMessage("", 0, ChatDestination::System, _("Lost connection to lobby!"), COLOR_RED);
×
1251
}
×
1252

1253
/**
1254
 *  (Lobby-)Status: Benutzerdefinierter Fehler
1255
 */
1256
void dskGameInterface::LC_Status_Error(const std::string& error)
×
1257
{
1258
    messenger.AddMessage("", 0, ChatDestination::System, error, COLOR_RED);
×
1259
}
×
1260

1261
void dskGameInterface::CI_PlayersSwapped(const unsigned player1, const unsigned player2)
×
1262
{
1263
    // Meldung anzeigen
1264
    std::string text = "Player '" + worldViewer.GetWorld().GetPlayer(player1).name + "' switched to player '"
×
1265
                       + worldViewer.GetWorld().GetPlayer(player2).name + "'";
×
1266
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_YELLOW);
×
1267

1268
    // Sichtbarkeiten und Minimap neu berechnen, wenn wir ein von den beiden Spielern sind
1269
    const unsigned localPlayerId = worldViewer.GetPlayerId();
×
1270
    if(player1 == localPlayerId || player2 == localPlayerId)
×
1271
    {
1272
        worldViewer.ChangePlayer(player1 == localPlayerId ? player2 : player1);
×
1273
        // Set visual settings back to the actual ones
1274
        GAMECLIENT.ResetVisualSettings();
×
1275
        minimap.UpdateAll();
×
1276
        InitPlayer();
×
1277
    }
1278
}
×
1279

1280
/**
1281
 *  Wenn ein Spieler verloren hat
1282
 */
1283
void dskGameInterface::GI_PlayerDefeated(const unsigned playerId)
×
1284
{
1285
    const std::string text =
1286
      helpers::format(_("Player '%s' was defeated!"), worldViewer.GetWorld().GetPlayer(playerId).name);
×
1287
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_ORANGE);
×
1288

1289
    /// Lokaler Spieler?
1290
    if(playerId == worldViewer.GetPlayerId())
×
1291
    {
1292
        /// Sichtbarkeiten neu berechnen
1293
        worldViewer.RecalcAllColors();
×
1294
        // Minimap updaten
1295
        minimap.UpdateAll();
×
1296
    }
1297
}
×
1298

1299
void dskGameInterface::GI_UpdateMinimap(const MapPoint pt)
×
1300
{
1301
    // Minimap Bescheid sagen
1302
    minimap.UpdateNode(pt);
×
1303
}
×
1304

1305
void dskGameInterface::GI_UpdateMapVisibility()
×
1306
{
1307
    // recalculate visibility
1308
    worldViewer.RecalcAllColors();
×
1309
    // update minimap
1310
    minimap.UpdateAll();
×
1311
}
×
1312

1313
/**
1314
 *  Bündnisvertrag wurde abgeschlossen oder abgebrochen --> Minimap updaten
1315
 */
1316
void dskGameInterface::GI_TreatyOfAllianceChanged(unsigned playerId)
×
1317
{
1318
    // Nur wenn Team-Sicht aktiviert ist, können sihc die Sichtbarkeiten auch ändern
1319
    if(playerId == worldViewer.GetPlayerId() && worldViewer.GetWorld().GetGGS().teamView)
×
1320
    {
1321
        /// Sichtbarkeiten neu berechnen
1322
        worldViewer.RecalcAllColors();
×
1323
        // Minimap updaten
1324
        minimap.UpdateAll();
×
1325
    }
1326
}
×
1327

1328
/**
1329
 *  Baut Weg zurück von Ende bis zu start_id
1330
 */
1331
void dskGameInterface::DemolishRoad(const unsigned start_id)
1✔
1332
{
1333
    RTTR_Assert(start_id > 0);
1✔
1334
    for(unsigned i = road.route.size(); i >= start_id; --i)
6✔
1335
    {
1336
        MapPoint t = road.point;
5✔
1337
        road.point = worldViewer.GetWorld().GetNeighbour(road.point, road.route[i - 1] + 3u);
5✔
1338
        worldViewer.SetVisiblePointRoad(road.point, road.route[i - 1], PointRoad::None);
5✔
1339
        worldViewer.RecalcBQForRoad(t);
5✔
1340
    }
1341

1342
    road.route.resize(start_id - 1);
1✔
1343
}
1✔
1344

1345
/**
1346
 *  Updatet das Post-Icon mit der Nachrichtenanzahl und der Taube
1347
 */
1348
void dskGameInterface::UpdatePostIcon(const unsigned postmessages_count, bool showPigeon)
6✔
1349
{
1350
    // Taube setzen oder nicht (Post)
1351
    if(postmessages_count == 0 || !showPigeon)
6✔
1352
        GetCtrl<ctrlImageButton>(3)->SetImage(LOADER.GetImageN("io", 62));
12✔
1353
    else
1354
        GetCtrl<ctrlImageButton>(3)->SetImage(LOADER.GetImageN("io", 59));
×
1355

1356
    // und Anzahl der Postnachrichten aktualisieren
1357
    if(postmessages_count > 0)
6✔
1358
    {
1359
        GetCtrl<ctrlText>(ID_txtNumMsg)->SetText(std::to_string(postmessages_count));
×
1360
    } else
1361
        GetCtrl<ctrlText>(ID_txtNumMsg)->SetText("");
6✔
1362
}
6✔
1363

1364
/**
1365
 *  Neue Post-Nachricht eingetroffen
1366
 */
1367
void dskGameInterface::NewPostMessage(const PostMsg& msg, const unsigned msgCt)
×
1368
{
1369
    UpdatePostIcon(msgCt, true);
×
1370
    SoundEffect soundEffect = msg.GetSoundEffect();
×
1371
    switch(soundEffect)
×
1372
    {
1373
        case SoundEffect::Pidgeon: LOADER.GetSoundN("sound", 114)->Play(100, false); break;
×
1374
        case SoundEffect::Fanfare: LOADER.GetSoundN("sound", 110)->Play(100, false);
×
1375
    }
1376
}
×
1377

1378
/**
1379
 *  Es wurde eine Postnachricht vom Spieler gelöscht
1380
 */
1381
void dskGameInterface::PostMessageDeleted(const unsigned msgCt)
×
1382
{
1383
    UpdatePostIcon(msgCt, false);
×
1384
}
×
1385

1386
/**
1387
 *  Ein Spieler hat das Spiel gewonnen.
1388
 */
1389
void dskGameInterface::GI_Winner(const unsigned playerId)
×
1390
{
1391
    const std::string name = worldViewer.GetWorld().GetPlayer(playerId).name;
×
1392
    const std::string text = (boost::format(_("Player '%s' is the winner!")) % name).str();
×
1393
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_ORANGE);
×
1394
    WINDOWMANAGER.Show(std::make_unique<iwVictory>(std::vector<std::string>(1, name)));
×
1395
}
×
1396

1397
/**
1398
 *  Ein Team hat das Spiel gewonnen.
1399
 */
1400
void dskGameInterface::GI_TeamWinner(const unsigned playerMask)
×
1401
{
1402
    std::vector<std::string> winners;
×
1403
    const GameWorldBase& world = worldViewer.GetWorld();
×
1404
    for(unsigned i = 0; i < world.GetNumPlayers(); i++)
×
1405
    {
1406
        if(playerMask & (1 << i))
×
1407
            winners.push_back(world.GetPlayer(i).name);
×
1408
    }
1409
    const std::string text =
1410
      (boost::format(_("%1% are the winners!")) % helpers::join(winners, ", ", _(" and "))).str();
×
1411
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_ORANGE);
×
1412
    WINDOWMANAGER.Show(std::make_unique<iwVictory>(winners));
×
1413
}
×
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