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

Return-To-The-Roots / s25client / 23849259886

01 Apr 2026 12:45PM UTC coverage: 50.177% (-0.2%) from 50.337%
23849259886

Pull #1890

github

web-flow
Merge d31e037e7 into e4146df45
Pull Request #1890: Add support for borderless Windows

155 of 626 new or added lines in 44 files covered. (24.76%)

24 existing lines in 7 files now uncovered.

23064 of 45965 relevant lines covered (50.18%)

43357.7 hits per line

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

35.36
/libs/s25main/desktops/dskGameInterface.cpp
1
// Copyright (C) 2005 - 2026 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/iwSettings.h"
57
#include "ingameWindows/iwShip.h"
58
#include "ingameWindows/iwSkipGFs.h"
59
#include "ingameWindows/iwStatistics.h"
60
#include "ingameWindows/iwTempleBuilding.h"
61
#include "ingameWindows/iwTextfile.h"
62
#include "ingameWindows/iwTools.h"
63
#include "ingameWindows/iwTrade.h"
64
#include "ingameWindows/iwTransport.h"
65
#include "ingameWindows/iwVictory.h"
66
#include "lua/GameDataLoader.h"
67
#include "network/GameClient.h"
68
#include "notifications/BuildingNote.h"
69
#include "notifications/NotificationManager.h"
70
#include "ogl/FontStyle.h"
71
#include "ogl/SoundEffectItem.h"
72
#include "ogl/glArchivItem_Bitmap_Player.h"
73
#include "ogl/glFont.h"
74
#include "pathfinding/FindPathForRoad.h"
75
#include "postSystem/PostBox.h"
76
#include "postSystem/PostMsg.h"
77
#include "random/Random.h"
78
#include "world/GameWorldBase.h"
79
#include "world/GameWorldViewer.h"
80
#include "nodeObjs/noFlag.h"
81
#include "nodeObjs/noTree.h"
82
#include "gameData/BuildingProperties.h"
83
#include "gameData/GameConsts.h"
84
#include "gameData/GuiConsts.h"
85
#include "gameData/TerrainDesc.h"
86
#include "gameData/const_gui_ids.h"
87
#include "liblobby/LobbyClient.h"
88
#include <algorithm>
89
#include <cstdio>
90
#include <utility>
91

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

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

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

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

131
    SetScale(false);
6✔
132

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

303
    // move buttons
304
    // Get real renderer size as newSize may get capped but we want to keep the manually drawn borders intact
NEW
305
    const Extent realNewSize = VIDEODRIVER.GetRenderSize();
×
NEW
306
    DrawPoint barPos = DrawPoint((realNewSize.x - LOADER.GetImageN("resource", 29)->getWidth()) / 2 + 44,
×
NEW
307
                                 realNewSize.y - LOADER.GetImageN("resource", 29)->getHeight() + 4);
×
308

309
    auto* button = GetCtrl<ctrlButton>(ID_btMap);
×
310
    button->SetPos(barPos);
×
311

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

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

320
    barPos.x += button->GetSize().x;
×
321
    button = GetCtrl<ctrlButton>(ID_btPost);
×
322
    button->SetPos(barPos);
×
323

324
    barPos += DrawPoint(18, 24);
×
325
    auto* text = GetCtrl<ctrlText>(ID_txtNumMsg);
×
326
    text->SetPos(barPos);
×
327

328
    gwv.Resize(newSize);
×
329
}
×
330

331
void dskGameInterface::Msg_ButtonClick(const unsigned ctrl_id)
×
332
{
333
    switch(ctrl_id)
×
334
    {
335
        case ID_btMap: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMinimap>(minimap, gwv)); break;
×
336
        case ID_btOptions: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMainMenu>(gwv, GAMECLIENT)); break;
×
337
        case ID_btConstructionAid:
×
338
            if(WINDOWMANAGER.IsDesktopActive())
×
339
                gwv.ToggleShowBQ();
×
340
            break;
×
341
        case ID_btPost:
×
342
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwPostWindow>(gwv, GetPostBox()));
×
343
            UpdatePostIcon(GetPostBox().GetNumMsgs(), false);
×
344
            break;
×
345
    }
346
}
×
347

348
void dskGameInterface::Msg_PaintBefore()
×
349
{
350
    Desktop::Msg_PaintBefore();
×
351

352
    // Spiel ausführen
353
    Run();
×
354

355
    /// Padding of the figures
356
    const DrawPoint figPadding(12, 12);
×
357
    const DrawPoint screenSize(VIDEODRIVER.GetRenderSize());
×
358
    // Rahmen zeichnen
359
    borders[0]->DrawFull(DrawPoint(0, 0));                                      // oben (mit Ecken)
×
360
    borders[1]->DrawFull(DrawPoint(0, screenSize.y - figPadding.y));            // unten (mit Ecken)
×
361
    borders[2]->DrawFull(DrawPoint(0, figPadding.y));                           // links
×
362
    borders[3]->DrawFull(DrawPoint(screenSize.x - figPadding.x, figPadding.y)); // rechts
×
363

364
    // The figure/statues and the button bar
365
    glArchivItem_Bitmap& imgFigLeftTop = *LOADER.GetImageN("resource", 17);
×
366
    glArchivItem_Bitmap& imgFigRightTop = *LOADER.GetImageN("resource", 18);
×
367
    glArchivItem_Bitmap& imgFigLeftBot = *LOADER.GetImageN("resource", 19);
×
368
    glArchivItem_Bitmap& imgFigRightBot = *LOADER.GetImageN("resource", 20);
×
369
    imgFigLeftTop.DrawFull(figPadding);
×
370
    imgFigRightTop.DrawFull(DrawPoint(screenSize.x - figPadding.x - imgFigRightTop.getWidth(), figPadding.y));
×
371
    imgFigLeftBot.DrawFull(DrawPoint(figPadding.x, screenSize.y - figPadding.y - imgFigLeftBot.getHeight()));
×
372
    imgFigRightBot.DrawFull(screenSize - figPadding - imgFigRightBot.GetSize());
×
373

374
    glArchivItem_Bitmap& imgButtonBar = *LOADER.GetImageN("resource", 29);
×
375
    imgButtonBar.DrawFull(
×
376
      DrawPoint((screenSize.x - imgButtonBar.getWidth()) / 2, screenSize.y - imgButtonBar.getHeight()));
×
377
}
×
378

379
void dskGameInterface::Msg_PaintAfter()
×
380
{
381
    Desktop::Msg_PaintAfter();
×
382

383
    const GameWorldBase& world = worldViewer.GetWorld();
×
384

385
    if(SETTINGS.global.showGFInfo)
×
386
    {
387
        std::array<char, 256> nwf_string;
388
        if(GAMECLIENT.IsReplayModeOn())
×
389
        {
390
            snprintf(nwf_string.data(), nwf_string.size(),
×
391
                     _("(Replay-Mode) Current GF: %u (End at: %u) / GF length: %u ms / NWF length: %u gf (%u ms)"),
392
                     world.GetEvMgr().GetCurrentGF(), GAMECLIENT.GetLastReplayGF(),
×
393
                     GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1), GAMECLIENT.GetNWFLength(),
×
394
                     GAMECLIENT.GetNWFLength() * GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1));
×
395
        } else
396
            snprintf(nwf_string.data(), nwf_string.size(),
×
397
                     _("Current GF: %u / GF length: %u ms / NWF length: %u gf (%u ms) /  Ping: %u ms"),
398
                     world.GetEvMgr().GetCurrentGF(), GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1),
×
399
                     GAMECLIENT.GetNWFLength(),
×
400
                     GAMECLIENT.GetNWFLength() * GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1),
×
401
                     worldViewer.GetPlayer().ping);
×
402
        NormalFont->Draw(DrawPoint(30, 1), nwf_string.data(), FontStyle{}, COLOR_YELLOW);
×
403
    }
404

405
    // tournament mode?
406
    const unsigned tournamentDuration = GAMECLIENT.GetTournamentModeDuration();
×
407
    if(tournamentDuration)
×
408
    {
409
        unsigned curGF = world.GetEvMgr().GetCurrentGF();
×
410
        std::string tournamentNotice;
×
411
        if(curGF >= tournamentDuration)
×
412
            tournamentNotice = _("Tournament finished");
×
413
        else
414
        {
415
            tournamentNotice =
416
              helpers::format("Tournament mode: %1% remaining", GAMECLIENT.FormatGFTime(tournamentDuration - curGF));
×
417
        }
418
        NormalFont->Draw(DrawPoint(VIDEODRIVER.GetRenderSize().x - 30, 1), tournamentNotice, FontStyle::AlignH::RIGHT,
×
419
                         COLOR_YELLOW);
420
    }
421

422
    // Replaydateianzeige in der linken unteren Ecke
423
    if(GAMECLIENT.IsReplayModeOn())
×
424
    {
425
        NormalFont->Draw(DrawPoint(0, VIDEODRIVER.GetRenderSize().y), GAMECLIENT.GetReplayFilename().string(),
×
426
                         FontStyle::BOTTOM, COLOR_YELLOW);
427
    } else
428
    {
429
        // Laggende Spieler anzeigen in Form von Schnecken
430
        DrawPoint snailPos(VIDEODRIVER.GetRenderSize().x - 70, 35);
×
431
        for(const NWFPlayerInfo& player : nwfInfo_->getPlayerInfos())
×
432
        {
433
            if(player.isLagging)
×
434
            {
435
                LOADER.GetPlayerImage("rttr", 0)->DrawFull(Rect(snailPos, 30, 30), COLOR_WHITE,
×
436
                                                           game_->world_.GetPlayer(player.id).color);
×
437
                snailPos.x -= 40;
×
438
            }
439
        }
440
    }
441

442
    // Show icons in the upper right corner of the game interface
443
    DrawPoint iconPos(VIDEODRIVER.GetRenderSize().x - 56, 32);
×
444

445
    // Draw cheating indicator icon (WINTER)
446
    if(cheats_.isCheatModeOn())
×
447
    {
448
        glArchivItem_Bitmap* cheatingImg = LOADER.GetImageN("io", 75);
×
449
        cheatingImg->DrawFull(iconPos);
×
450
        iconPos -= DrawPoint(cheatingImg->getWidth() + 6, 0);
×
451
    }
452

453
    // Draw speed indicator icon
454
    const int speedStep = static_cast<int>(REFERENCE_SPEED / 10ms) - static_cast<int>(GAMECLIENT.GetGFLength() / 10ms);
×
455

456
    if(speedStep != 0)
×
457
    {
458
        glArchivItem_Bitmap* runnerImg = LOADER.GetImageN("io", 164);
×
459

460
        runnerImg->DrawFull(iconPos);
×
461

462
        if(speedStep != 1)
×
463
        {
464
            std::string multiplier = helpers::toString(std::abs(speedStep));
×
465
            NormalFont->Draw(iconPos - runnerImg->GetOrigin() + DrawPoint(19, 6), multiplier, FontStyle::LEFT,
×
466
                             speedStep > 0 ? COLOR_YELLOW : COLOR_RED);
467
        }
468
        iconPos -= DrawPoint(runnerImg->getWidth() + 4, 0);
×
469
    }
470

471
    // Draw zoom level indicator icon
472
    if(gwv.GetCurrentTargetZoomFactor() != 1.f) //-V550
×
473
    {
474
        glArchivItem_Bitmap* magnifierImg = LOADER.GetImageN("io", 36);
×
475

476
        magnifierImg->DrawFull(iconPos);
×
477

478
        std::string zoom_percent = helpers::toString((int)(gwv.GetCurrentTargetZoomFactor() * 100)) + "%";
×
479
        NormalFont->Draw(iconPos - magnifierImg->GetOrigin() + DrawPoint(9, 7), zoom_percent, FontStyle::CENTER,
×
480
                         COLOR_YELLOW);
481
        iconPos -= DrawPoint(magnifierImg->getWidth() + 4, 0);
×
482
    }
483
}
×
484

485
bool dskGameInterface::ContextClick(const MouseCoords& mc)
2✔
486
{
487
    // Handle road building mode if active
488
    if(road.mode != RoadBuildMode::Disabled)
2✔
489
    {
490
        // in "richtige" Map-Koordinaten Konvertieren, den aktuellen selektierten Punkt
491
        const MapPoint selPt = gwv.GetSelectedPt();
1✔
492

493
        if(selPt == road.point)
1✔
494
        {
495
            // Selektierter Punkt ist der gleiche wie der Straßenpunkt --> Fenster mit Wegbau abbrechen
496
            ShowRoadWindow(mc.pos);
×
497
        } else
498
        {
499
            // altes Roadwindow schließen
500
            WINDOWMANAGER.Close((unsigned)CGI_ROADWINDOW);
1✔
501

502
            // Ist das ein gültiger neuer Wegpunkt?
503
            if(worldViewer.IsRoadAvailable(road.mode == RoadBuildMode::Boat, selPt)
1✔
504
               && worldViewer.IsPlayerTerritory(selPt))
1✔
505
            {
506
                MapPoint targetPt = selPt;
1✔
507
                if(!BuildRoadPart(targetPt))
1✔
508
                    ShowRoadWindow(mc.pos);
×
509
            } else if(worldViewer.GetBQ(selPt) != BuildingQuality::Nothing)
×
510
            {
511
                // Wurde bereits auf das gebaute Stück geklickt?
512
                unsigned idOnRoad = GetIdInCurBuildRoad(selPt);
×
513
                if(idOnRoad)
×
514
                    DemolishRoad(idOnRoad);
×
515
                else
516
                {
517
                    MapPoint targetPt = selPt;
×
518
                    if(BuildRoadPart(targetPt))
×
519
                    {
520
                        // Ist der Zielpunkt der gleiche geblieben?
521
                        if(selPt == targetPt)
×
522
                            GI_BuildRoad();
×
523
                    } else if(selPt == targetPt)
×
524
                        ShowRoadWindow(mc.pos);
×
525
                }
526
            }
527
            // Wurde auf eine Flagge geklickt und ist diese Flagge nicht der Weganfangspunkt?
528
            else if(worldViewer.GetWorld().GetNO(selPt)->GetType() == NodalObjectType::Flag && selPt != road.start)
×
529
            {
530
                MapPoint targetPt = selPt;
×
531
                if(BuildRoadPart(targetPt))
×
532
                {
533
                    if(selPt == targetPt)
×
534
                        GI_BuildRoad();
×
535
                } else if(selPt == targetPt)
×
536
                    ShowRoadWindow(mc.pos);
×
537
            } else
538
            {
539
                unsigned tbr = GetIdInCurBuildRoad(selPt);
×
540
                // Wurde bereits auf das gebaute Stück geklickt?
541
                if(tbr)
×
542
                    DemolishRoad(tbr);
×
543
                else
544
                    ShowRoadWindow(mc.pos);
×
545
            }
546
        }
547
    } else // Not in road building mode
548
    {
549
        bool enable_military_buildings = false;
1✔
550

551
        iwAction::Tabs action_tabs;
1✔
552

553
        const MapPoint cSel = gwv.GetSelectedPt();
1✔
554

555
        // Vielleicht steht hier auch ein Schiff?
556
        if(const noShip* ship = worldViewer.GetShip(cSel))
1✔
557
        {
558
            WINDOWMANAGER.Show(std::make_unique<iwShip>(gwv, GAMECLIENT, ship));
×
559
            return true;
×
560
        }
561

562
        // Evtl ists nen Haus? (unser Haus)
563
        const noBase& selObj = *worldViewer.GetWorld().GetNO(cSel);
1✔
564
        if(selObj.GetType() == NodalObjectType::Building && worldViewer.IsOwner(cSel))
1✔
565
        {
566
            if(auto* wnd = WINDOWMANAGER.FindNonModalWindow(CGI_BUILDING + MapBase::CreateGUIID(cSel)))
×
567
            {
568
                WINDOWMANAGER.SetActiveWindow(*wnd);
×
569
                return true;
×
570
            }
571
            BuildingType bt = static_cast<const noBuilding&>(selObj).GetBuildingType();
×
572
            // HQ
573
            if(bt == BuildingType::Headquarters)
×
574
                WINDOWMANAGER.Show(
×
575
                  std::make_unique<iwHQ>(gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobHQ>(cSel)));
×
576
            // Lagerhäuser
577
            else if(bt == BuildingType::Storehouse)
×
578
                WINDOWMANAGER.Show(std::make_unique<iwBaseWarehouse>(
×
579
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobStorehouse>(cSel)));
×
580
            // Hafengebäude
581
            else if(bt == BuildingType::HarborBuilding)
×
582
                WINDOWMANAGER.Show(std::make_unique<iwHarborBuilding>(
×
583
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobHarborBuilding>(cSel)));
×
584
            // Militärgebäude
585
            else if(BuildingProperties::IsMilitary(bt))
×
586
                WINDOWMANAGER.Show(std::make_unique<iwMilitaryBuilding>(
×
587
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobMilitary>(cSel)));
×
588
            else if(bt == BuildingType::Temple)
×
589
                WINDOWMANAGER.Show(std::make_unique<iwTempleBuilding>(
×
590
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobTemple>(cSel)));
×
591
            else
592
                WINDOWMANAGER.Show(std::make_unique<iwBuilding>(
×
593
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobUsual>(cSel)));
×
594
            return true;
×
595
        }
596
        // oder vielleicht eine Baustelle?
597
        else if(selObj.GetType() == NodalObjectType::Buildingsite && worldViewer.IsOwner(cSel))
1✔
598
        {
599
            if(!WINDOWMANAGER.FindNonModalWindow(CGI_BUILDING + MapBase::CreateGUIID(cSel)))
×
600
                WINDOWMANAGER.Show(
×
601
                  std::make_unique<iwBuildingSite>(gwv, worldViewer.GetWorld().GetSpecObj<noBuildingSite>(cSel)));
×
602
            return true;
×
603
        }
604

605
        action_tabs.watch = true;
1✔
606
        // Unser Land
607
        if(worldViewer.IsOwner(cSel))
1✔
608
        {
609
            const BuildingQuality bq = worldViewer.GetBQ(cSel);
1✔
610
            // Kann hier was gebaut werden?
611
            if(bq >= BuildingQuality::Mine)
1✔
612
            {
613
                action_tabs.build = true;
1✔
614

615
                // Welches Gebäude kann gebaut werden?
616
                switch(bq)
1✔
617
                {
618
                    case BuildingQuality::Mine: action_tabs.build_tabs = iwAction::BuildTab::Mine; break;
×
619
                    case BuildingQuality::Hut: action_tabs.build_tabs = iwAction::BuildTab::Hut; break;
×
620
                    case BuildingQuality::House: action_tabs.build_tabs = iwAction::BuildTab::House; break;
×
621
                    case BuildingQuality::Castle: action_tabs.build_tabs = iwAction::BuildTab::Castle; break;
1✔
622
                    case BuildingQuality::Harbor: action_tabs.build_tabs = iwAction::BuildTab::Harbor; break;
×
623
                    default: break;
×
624
                }
625

626
                if(!worldViewer.GetWorld().IsFlagAround(cSel))
1✔
627
                    action_tabs.setflag = true;
1✔
628

629
                // Prüfen, ob sich Militärgebäude in der Nähe befinden, wenn nein, können auch eigene
630
                // Militärgebäude gebaut werden
631
                enable_military_buildings =
1✔
632
                  !worldViewer.GetWorld().IsMilitaryBuildingNearNode(cSel, worldViewer.GetPlayerId());
1✔
633
            } else if(bq == BuildingQuality::Flag)
×
634
                action_tabs.setflag = true;
×
635
            else if(selObj.GetType() == NodalObjectType::Flag)
×
636
                action_tabs.flag = true;
×
637

638
            if(selObj.GetType() != NodalObjectType::Flag && selObj.GetType() != NodalObjectType::Building)
1✔
639
            {
640
                // Check if there are roads
641
                for(const Direction dir : helpers::EnumRange<Direction>{})
16✔
642
                {
643
                    const PointRoad curRoad = worldViewer.GetVisiblePointRoad(cSel, dir);
6✔
644
                    if(curRoad != PointRoad::None)
6✔
645
                    {
646
                        action_tabs.cutroad = true;
×
647
                        action_tabs.upgradeRoad |= (curRoad == PointRoad::Normal);
×
648
                    }
649
                }
650
            }
651
        }
652
        // evtl ists ein feindliches Militärgebäude, welches NICHT im Nebel liegt?
653
        else if(worldViewer.GetVisibility(cSel) == Visibility::Visible)
×
654
        {
655
            if(selObj.GetType() == NodalObjectType::Building)
×
656
            {
657
                const auto* building = worldViewer.GetWorld().GetSpecObj<noBuilding>(cSel); //-V807
×
658
                BuildingType bt = building->GetBuildingType();
×
659

660
                // Only if trade is enabled
661
                if(worldViewer.GetWorld().GetGGS().isEnabled(AddonId::TRADE))
×
662
                {
663
                    // Allied warehouse? -> Show trade window
664
                    if(BuildingProperties::IsWareHouse(bt) && worldViewer.GetPlayer().IsAlly(building->GetPlayer()))
×
665
                    {
666
                        WINDOWMANAGER.Show(std::make_unique<iwTrade>(*static_cast<const nobBaseWarehouse*>(building),
×
667
                                                                     worldViewer, GAMECLIENT));
×
668
                        return true;
×
669
                    }
670
                }
671

672
                // Ist es ein gewöhnliches Militärgebäude?
673
                if(BuildingProperties::IsMilitary(bt))
×
674
                {
675
                    // Dann darf es nicht neu gebaut sein!
676
                    if(!static_cast<const nobMilitary*>(building)->IsNewBuilt())
×
677
                        action_tabs.attack = true;
×
678
                }
679
                // oder ein HQ oder Hafen?
680
                else if(bt == BuildingType::Headquarters || bt == BuildingType::HarborBuilding)
×
681
                    action_tabs.attack = true;
×
682
                action_tabs.sea_attack =
×
683
                  action_tabs.attack && worldViewer.GetWorld().GetGGS().isEnabled(AddonId::SEA_ATTACK);
×
684
            }
685
        }
686

687
        // Bisheriges Actionfenster schließen, falls es eins gab
688
        // aktuelle Mausposition merken, da diese durch das Schließen verändert werden kann
689
        if(actionwindow)
1✔
690
            actionwindow->Close();
×
691
        VIDEODRIVER.SetMousePos(mc.pos);
1✔
692

693
        ShowActionWindow(action_tabs, cSel, mc.pos, enable_military_buildings);
1✔
694
    }
695

696
    return true;
2✔
697
}
698

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

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

717
        return ContextClick(mc);
2✔
718

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

724
    return true;
×
725
}
726

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

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

740
    return false;
1✔
741
}
742

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

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

762
        if(SETTINGS.interface.mapScrollMode == MapScrollMode::ScrollSame)
8✔
763
            acceleration = -acceleration;
1✔
764

765
        gwv.MoveBy((mc.pos - startScrollPt) * acceleration);
8✔
766
        VIDEODRIVER.SetMousePos(startScrollPt);
8✔
767

768
        if(!SETTINGS.global.smartCursor)
8✔
769
            startScrollPt = mc.pos;
×
770
    }
771

772
    return true;
9✔
773
}
774

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

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

791
bool dskGameInterface::Msg_KeyDown(const KeyEvent& ke)
15✔
792
{
793
    cheatCommandTracker_.onKeyEvent(ke);
15✔
794

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

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

815
        case KeyType::F2: // Open save game window
×
816
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwSave>());
×
817
            return true;
×
818
        case KeyType::F3: // Map debug window
×
819
        {
820
            const bool replayMode = GAMECLIENT.IsReplayModeOn();
×
821
            if(replayMode)
×
822
                DisableFoW(true);
×
823
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMapDebug>(gwv, game_->world_.IsSinglePlayer() || replayMode));
×
824
            return true;
×
825
        }
826
        case KeyType::F8:
×
827
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("keyboardlayout.txt", _("Keyboard layout")));
×
828
            return true;
×
829
        case KeyType::F9:
×
830
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("readme.txt", _("Readme!")));
×
831
            return true;
×
NEW
832
        case KeyType::F10: WINDOWMANAGER.ToggleWindow(std::make_unique<iwSettings>()); 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 ' ': // Show/hide construction aid
×
929
            // workaround for Wayland which does not capture SDLK_SPACE when SDL_StartTextInput() was called
930
            gwv.ToggleShowBQ();
×
931
            return true;
×
932
        case 26: // ctrl+z
×
933
            gwv.SetZoomFactor(ZOOM_FACTORS[ZOOM_DEFAULT_INDEX]);
×
934
            return true;
×
935
        case 'z':
9✔
936
            if(ke.ctrl) // Reset zoom
9✔
937
                gwv.SetZoomFactor(ZOOM_FACTORS[ZOOM_DEFAULT_INDEX]);
2✔
938
            else // zoom in
939
                gwv.SetZoomFactor(getNextZoomLevel(gwv.GetCurrentTargetZoomFactor()));
7✔
940
            return true;
9✔
941
        case 'Z': // shift-z, zoom out
4✔
942
            gwv.SetZoomFactor(getPreviousZoomLevel(gwv.GetCurrentTargetZoomFactor()));
4✔
943
            return true;
4✔
944
    }
945

946
    return false;
×
947
}
948

949
bool dskGameInterface::Msg_WheelUp(const MouseCoords&)
9✔
950
{
951
    WheelZoom(ZOOM_WHEEL_INCREMENT);
9✔
952
    return true;
9✔
953
}
954
bool dskGameInterface::Msg_WheelDown(const MouseCoords&)
10✔
955
{
956
    WheelZoom(-ZOOM_WHEEL_INCREMENT);
10✔
957
    return true;
10✔
958
}
959

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

967
    gwv.SetZoomFactor(targetZoomFactor);
19✔
968
}
19✔
969

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

985
void dskGameInterface::Run()
×
986
{
987
    // Reset draw counter of the trees before drawing
988
    noTree::ResetDrawCounter();
×
989

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

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

1006
    messenger.Draw();
×
1007
}
×
1008

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

1015
    road.mode = waterRoad ? RoadBuildMode::Boat : RoadBuildMode::Normal;
3✔
1016
    road.route.clear();
3✔
1017
    road.start = road.point = startPt;
3✔
1018
    WINDOWMANAGER.SetCursor(Cursor::Remove);
3✔
1019
}
1020

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

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

1038
    // Test on water way length
1039
    if(road.mode == RoadBuildMode::Boat)
3✔
1040
    {
1041
        unsigned char index = worldViewer.GetWorld().GetGGS().getSelection(AddonId::MAX_WATERWAY_LENGTH);
×
1042

1043
        RTTR_Assert(index < waterwayLengths.size());
×
1044
        const unsigned max_length = waterwayLengths[index];
×
1045

1046
        unsigned length = road.route.size() + new_route.size();
×
1047

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

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

1070
    // Zielpunkt updaten (für Wasserweg)
1071
    cSel = road.point;
3✔
1072

1073
    road.route.insert(road.route.end(), new_route.begin(), new_route.end());
3✔
1074

1075
    return true;
3✔
1076
}
1077

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

1086
        curPt = worldViewer.GetNeighbour(curPt, road.route[i]);
1✔
1087
    }
1088
    return 0;
×
1089
}
1090

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

1097
void dskGameInterface::ShowActionWindow(const iwAction::Tabs& action_tabs, MapPoint cSel, const DrawPoint& mousePos,
2✔
1098
                                        const bool enable_military_buildings)
1099
{
1100
    const GameWorldBase& world = worldViewer.GetWorld();
2✔
1101

1102
    iwAction::Params params;
2✔
1103

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

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

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

1130
    actionwindow = &WINDOWMANAGER.Show(
2✔
1131
      std::make_unique<iwAction>(*this, gwv, action_tabs, cSel, mousePos, params, enable_military_buildings), true);
2✔
1132
}
2✔
1133

1134
void dskGameInterface::OnChatCommand(const std::string& cmd)
×
1135
{
1136
    cheatCommandTracker_.onChatCommand(cmd);
×
1137

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

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

1167
void dskGameInterface::Msg_WindowClosed(IngameWindow& wnd)
2✔
1168
{
1169
    if(actionwindow == &wnd)
2✔
1170
        actionwindow = nullptr;
1✔
1171
    else if(roadwindow == &wnd)
1✔
1172
        roadwindow = nullptr;
×
1173
}
2✔
1174

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

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

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

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

1209
void dskGameInterface::CI_Chat(const unsigned playerId, const ChatDestination cd, const std::string& msg)
×
1210
{
1211
    messenger.AddMessage(worldViewer.GetWorld().GetPlayer(playerId).name,
×
1212
                         worldViewer.GetWorld().GetPlayer(playerId).color, cd, msg);
×
1213
}
×
1214

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

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

1228
void dskGameInterface::CI_ReplayEndReached(const std::string& msg)
×
1229
{
1230
    messenger.AddMessage("", 0, ChatDestination::System, msg, COLOR_BLUE);
×
1231
}
×
1232

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

1238
void dskGameInterface::CI_GameResumed()
×
1239
{
1240
    messenger.AddMessage(_("SYSTEM"), COLOR_GREY, ChatDestination::System, _("Game was resumed."));
×
1241
}
×
1242

1243
void dskGameInterface::CI_Error(const ClientError ce)
×
1244
{
1245
    messenger.AddMessage("", 0, ChatDestination::System, ClientErrorToStr(ce), COLOR_RED);
×
1246
    GAMECLIENT.SetPause(true);
×
1247
}
×
1248

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

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

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

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

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

1293
    /// Lokaler Spieler?
1294
    if(playerId == worldViewer.GetPlayerId())
×
1295
    {
1296
        /// Sichtbarkeiten neu berechnen
1297
        worldViewer.RecalcAllColors();
×
1298
        // Minimap updaten
1299
        minimap.UpdateAll();
×
1300
    }
1301
}
×
1302

1303
void dskGameInterface::GI_UpdateMinimap(const MapPoint pt)
×
1304
{
1305
    // Minimap Bescheid sagen
1306
    minimap.UpdateNode(pt);
×
1307
}
×
1308

1309
void dskGameInterface::GI_UpdateMapVisibility()
×
1310
{
1311
    // recalculate visibility
1312
    worldViewer.RecalcAllColors();
×
1313
    // update minimap
1314
    minimap.UpdateAll();
×
1315
}
×
1316

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

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

1346
    road.route.resize(start_id - 1);
1✔
1347
}
1✔
1348

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

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

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

1382
/**
1383
 *  Es wurde eine Postnachricht vom Spieler gelöscht
1384
 */
1385
void dskGameInterface::PostMessageDeleted(const unsigned msgCt)
×
1386
{
1387
    UpdatePostIcon(msgCt, false);
×
1388
}
×
1389

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

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