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

Return-To-The-Roots / s25client / 22041554630

15 Feb 2026 07:19PM UTC coverage: 50.777% (-0.04%) from 50.82%
22041554630

Pull #1890

github

web-flow
Merge d3241a627 into 6db06730b
Pull Request #1890: Add support for borderless Windows

13 of 120 new or added lines in 10 files covered. (10.83%)

6 existing lines in 3 files now uncovered.

22799 of 44900 relevant lines covered (50.78%)

41814.43 hits per line

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

21.71
/libs/s25main/Settings.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 "Settings.h"
6
#include "DrawPoint.h"
7
#include "RTTR_Version.h"
8
#include "RttrConfig.h"
9
#include "driver/VideoInterface.h"
10
#include "drivers/AudioDriverWrapper.h"
11
#include "drivers/VideoDriverWrapper.h"
12
#include "enum_cast.hpp"
13
#include "files.h"
14
#include "helpers/MaxEnumValue.h"
15
#include "helpers/strUtils.h"
16
#include "languages.h"
17
#include "gameData/PortraitConsts.h"
18
#include "gameData/const_gui_ids.h"
19
#include "libsiedler2/ArchivItem_Ini.h"
20
#include "libsiedler2/ArchivItem_Text.h"
21
#include "libsiedler2/libsiedler2.h"
22
#include "s25util/StringConversion.h"
23
#include "s25util/System.h"
24
#include "s25util/error.h"
25
#include <boost/filesystem/operations.hpp>
26

27
namespace {
28
#ifdef __ANDROID__
29
constexpr bool SHARED_TEXTURES_DEFAULT = false;
30
constexpr MapScrollMode MAP_SCROLL_MODE_DEFAULT = MapScrollMode::GrabAndDrag;
31
#else
32
constexpr bool SHARED_TEXTURES_DEFAULT = true;
33
constexpr MapScrollMode MAP_SCROLL_MODE_DEFAULT = MapScrollMode::ScrollOpposite;
34
#endif
35
} // namespace
36

37
const int Settings::VERSION = 13;
38
const std::array<std::string, 10> Settings::SECTION_NAMES = {
39
  {"global", "video", "language", "driver", "sound", "lobby", "server", "proxy", "interface", "addons"}};
40

41
const std::array<short, 13> Settings::SCREEN_REFRESH_RATES = {
42
  {-1, 25, 30, 50, 60, 75, 80, 100, 120, 150, 180, 200, 240}};
43

44
const std::map<GUI_ID, std::string> persistentWindows = {{CGI_CHAT, "wnd_chat"},
45
                                                         {CGI_POSTOFFICE, "wnd_postoffice"},
46
                                                         {CGI_DISTRIBUTION, "wnd_distribution"},
47
                                                         {CGI_BUILDORDER, "wnd_buildorder"},
48
                                                         {CGI_TRANSPORT, "wnd_transport"},
49
                                                         {CGI_MILITARY, "wnd_military"},
50
                                                         {CGI_TOOLS, "wnd_tools"},
51
                                                         {CGI_INVENTORY, "wnd_inventory"},
52
                                                         {CGI_MINIMAP, "wnd_minimap"},
53
                                                         {CGI_BUILDINGS, "wnd_buildings"},
54
                                                         {CGI_BUILDINGSPRODUCTIVITY, "wnd_buildingsproductivity"},
55
                                                         {CGI_MUSICPLAYER, "wnd_musicplayer"},
56
                                                         {CGI_STATISTICS, "wnd_statistics"},
57
                                                         {CGI_ECONOMICPROGRESS, "wnd_economicprogress"},
58
                                                         {CGI_DIPLOMACY, "wnd_diplomacy"},
59
                                                         {CGI_SHIP, "wnd_ship"},
60
                                                         {CGI_MERCHANDISE_STATISTICS, "wnd_merchandise_statistics"}};
61

62
namespace validate {
63
boost::optional<uint16_t> checkPort(const std::string& port)
9✔
64
{
65
    int32_t iPort;
66
    if((helpers::tryFromString(port, iPort) || s25util::tryFromStringClassic(port, iPort)) && checkPort(iPort))
9✔
67
        return static_cast<uint16_t>(iPort);
3✔
68
    else
69
        return boost::none;
6✔
70
}
71
bool checkPort(int port)
7✔
72
{
73
    // Disallow port 0 as it may cause problems
74
    return port > 0 && port <= 65535;
7✔
75
}
76
} // namespace validate
77

78
Settings::Settings() //-V730
5✔
79
{
80
    LoadDefaults();
5✔
81
}
5✔
82

83
void Settings::LoadDefaults()
5✔
84
{
85
    // global
86
    // {
87
    // 0 = ask user at start, 1 = enabled, 2 = always ask
88
    global.submit_debug_data = 0;
5✔
89
    global.use_upnp = false;
5✔
90
    global.smartCursor = true;
5✔
91
    global.debugMode = false;
5✔
92
    global.showGFInfo = false;
5✔
93
    // }
94

95
    // video
96
    // {
97
    if(VIDEODRIVER.IsLoaded())
5✔
98
    {
99
        video.fullscreenSize = VIDEODRIVER.GetWindowSize();
3✔
100
        video.windowedSize =
3✔
101
          (VIDEODRIVER.GetDisplayMode() == DisplayMode::Fullscreen) ? video.fullscreenSize : VideoMode(800, 600);
3✔
102
        video.displayMode = VIDEODRIVER.GetDisplayMode();
3✔
103
    } else
104
    {
105
        video.windowedSize = video.fullscreenSize = VideoMode(800, 600);
2✔
106
        video.displayMode = DisplayMode::Windowed;
2✔
107
    }
108
    video.framerate = 0; // Special value for HW vsync
5✔
109
    video.vbo = true;
5✔
110
    video.shared_textures = SHARED_TEXTURES_DEFAULT;
5✔
111
    video.guiScale = 0; // special value indicating automatic selection
5✔
112
    // }
113

114
    // language
115
    // {
116
    language.language.clear();
5✔
117
    // }
118

119
    LANGUAGES.setLanguage(language.language);
5✔
120

121
    // driver
122
    // {
123
    driver.audio = AUDIODRIVER.GetName();
5✔
124
    driver.video = VIDEODRIVER.GetName();
5✔
125
    // }
126

127
    // sound
128
    // {
129
    sound.musicEnabled = false;
5✔
130
    sound.musicVolume = 30;
5✔
131
    sound.effectsEnabled = true;
5✔
132
    sound.effectsVolume = 75;
5✔
133
    sound.birdsEnabled = true;
5✔
134
    sound.playlist = s25::files::defaultPlaylist;
5✔
135
    // }
136

137
    // lobby
138
    // {
139

140
    lobby.name = System::getUserName();
5✔
141
    lobby.portraitIndex = 0;
5✔
142
    lobby.password.clear();
5✔
143
    lobby.save_password = false;
5✔
144
    // }
145

146
    // server
147
    // {
148
    server.last_ip.clear();
5✔
149
    server.localPort = 3665;
5✔
150
    server.ipv6 = false;
5✔
151
    // }
152

153
    proxy = ProxySettings();
5✔
154
    proxy.port = 1080;
5✔
155

156
    // interface
157
    // {
158
    interface.autosave_interval = 0;
5✔
159
    interface.mapScrollMode = MAP_SCROLL_MODE_DEFAULT;
5✔
160
    interface.enableWindowPinning = false;
5✔
161
    interface.windowSnapDistance = 8;
5✔
162
    // }
163

164
    // addons
165
    // {
166
    addons.configuration.clear();
5✔
167
    // }
168

169
    LoadIngameDefaults();
5✔
170
}
5✔
171

172
void Settings::LoadIngameDefaults()
5✔
173
{
174
    // ingame
175
    // {
176
    ingame.scale_statistics = false;
5✔
177
    ingame.showBQ = false;
5✔
178
    ingame.showNames = false;
5✔
179
    ingame.showProductivity = false;
5✔
180
    ingame.minimapExtended = false;
5✔
181
    // }
182

183
    // windows
184
    // {
185
    for(const auto& window : persistentWindows)
90✔
186
        windows.persistentSettings[window.first] = PersistentWindowSettings();
85✔
187
    // }
188
}
5✔
189

190
///////////////////////////////////////////////////////////////////////////////
191
// Routine for loading the configuration
192
void Settings::Load()
×
193
{
194
    libsiedler2::Archiv settings;
×
195
    const auto settingsPath = RTTRCONFIG.ExpandPath(s25::resources::config);
×
196
    try
197
    {
198
        if(libsiedler2::Load(settingsPath, settings) != 0 || settings.size() < SECTION_NAMES.size())
×
199
            throw std::runtime_error("File missing or invalid");
×
200

201
        const libsiedler2::ArchivItem_Ini* iniGlobal =
202
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("global"));
×
203
        const libsiedler2::ArchivItem_Ini* iniVideo = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("video"));
×
204
        const libsiedler2::ArchivItem_Ini* iniLanguage =
205
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("language"));
×
206
        const libsiedler2::ArchivItem_Ini* iniDriver =
207
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("driver"));
×
208
        const libsiedler2::ArchivItem_Ini* iniSound = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("sound"));
×
209
        const libsiedler2::ArchivItem_Ini* iniLobby = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("lobby"));
×
210
        const libsiedler2::ArchivItem_Ini* iniServer =
211
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("server"));
×
212
        const libsiedler2::ArchivItem_Ini* iniProxy = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("proxy"));
×
213
        const libsiedler2::ArchivItem_Ini* iniInterface =
214
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("interface"));
×
215
        const libsiedler2::ArchivItem_Ini* iniAddons =
216
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("addons"));
×
217

218
        // Is one of the categories missing?
219
        if(!iniGlobal || !iniVideo || !iniLanguage || !iniDriver || !iniSound || !iniLobby || !iniServer || !iniProxy
×
220
           || !iniInterface || !iniAddons)
×
221
        {
222
            throw std::runtime_error("Missing section");
×
223
        }
224
        // Is the settings version correct?
225
        if(iniGlobal->getValue("version", 0) != VERSION)
×
226
            throw std::runtime_error("Wrong version");
×
227

228
        // global
229
        // {
230
        if(iniGlobal->getValue("gameversion") != rttr::version::GetRevision())
×
231
            s25util::warning("Your application version has changed - please recheck your settings!");
×
232

233
        global.submit_debug_data = iniGlobal->getIntValue("submit_debug_data");
×
234
        global.use_upnp = iniGlobal->getBoolValue("use_upnp");
×
235
        global.smartCursor = iniGlobal->getValue("smartCursor", true);
×
236
        global.debugMode = iniGlobal->getValue("debugMode", false);
×
237
        global.showGFInfo = iniGlobal->getValue("showGFInfo", false);
×
238
        // };
239

240
        // video
241
        // {
242
        video.windowedSize.width = iniVideo->getIntValue("windowed_width");
×
243
        video.windowedSize.height = iniVideo->getIntValue("windowed_height");
×
244
        video.fullscreenSize.width = iniVideo->getIntValue("fullscreen_width");
×
245
        video.fullscreenSize.height = iniVideo->getIntValue("fullscreen_height");
×
NEW
246
        const auto displayMode = iniVideo->getValue("displayMode", -1);
×
NEW
247
        if(displayMode >= 0 && static_cast<unsigned>(displayMode) <= helpers::MaxEnumValue_v<DisplayMode>)
×
NEW
248
            video.displayMode = DisplayMode(displayMode);
×
249
        else
250
        {
NEW
251
            video.displayMode =
×
NEW
252
              iniVideo->getValue("fullscreen", false) ? DisplayMode::Fullscreen : DisplayMode::Windowed;
×
253
        }
254
        video.framerate = iniVideo->getValue("framerate", 0);
×
255
        video.vbo = iniVideo->getBoolValue("vbo");
×
256
        video.shared_textures = iniVideo->getBoolValue("shared_textures");
×
257
        video.guiScale = iniVideo->getValue("gui_scale", 0);
×
258
        // };
259

260
        if(video.fullscreenSize.width == 0 || video.fullscreenSize.height == 0 || video.windowedSize.width == 0
×
261
           || video.windowedSize.height == 0)
×
262
            throw std::runtime_error("Invalid video settings");
×
263

264
        // language
265
        // {
266
        language.language = iniLanguage->getValue("language");
×
267
        // }
268

269
        LANGUAGES.setLanguage(language.language);
×
270

271
        // driver
272
        // {
273
        driver.video = iniDriver->getValue("video");
×
274
        driver.audio = iniDriver->getValue("audio");
×
275
        // }
276

277
        // sound
278
        // {
279
        sound.musicEnabled = iniSound->getBoolValue("musik");
×
280
        sound.musicVolume = iniSound->getIntValue("musik_volume");
×
281
        sound.effectsEnabled = iniSound->getBoolValue("effekte");
×
282
        sound.effectsVolume = iniSound->getIntValue("effekte_volume");
×
283
        sound.birdsEnabled = iniSound->getValue("bird_sounds", true);
×
284
        sound.playlist = iniSound->getValue("playlist");
×
285
        // }
286

287
        // lobby
288
        // {
289
        lobby.name = iniLobby->getValue("name");
×
290
        lobby.portraitIndex = iniLobby->getIntValue("portrait_index");
×
291
        lobby.password = iniLobby->getValue("password");
×
292
        lobby.save_password = iniLobby->getBoolValue("save_password");
×
293
        // }
294

295
        if(lobby.name.empty())
×
296
            lobby.name = System::getUserName();
×
297

298
        if(lobby.portraitIndex >= Portraits.size())
×
299
        {
300
            lobby.portraitIndex = 0;
×
301
        }
302

303
        // server
304
        // {
305
        server.last_ip = iniServer->getValue("last_ip");
×
306
        boost::optional<uint16_t> port = validate::checkPort(iniServer->getValue("local_port"));
×
307
        server.localPort = port.value_or(3665);
×
308
        server.ipv6 = iniServer->getBoolValue("ipv6");
×
309
        // }
310

311
        // proxy
312
        // {
313
        proxy.hostname = iniProxy->getValue("proxy");
×
314
        port = validate::checkPort(iniProxy->getValue("port"));
×
315
        proxy.port = port.value_or(1080);
×
316
        proxy.type = ProxyType(iniProxy->getIntValue("typ"));
×
317
        // }
318

319
        // Empty proxy address completely disables proxy.
320
        // Disabled proxy removes proxy address.
321
        if(proxy.hostname.empty() || (proxy.type != ProxyType::Socks4 && proxy.type != ProxyType::Socks5))
×
322
        {
323
            proxy.type = ProxyType::None;
×
324
            proxy.hostname.clear();
×
325
        }
326
        // Enabled Socks v4 disables IPv6
327
        else if(proxy.type == ProxyType::Socks4 && server.ipv6)
×
328
            server.ipv6 = false;
×
329

330
        // interface
331
        // {
332
        interface.autosave_interval = iniInterface->getIntValue("autosave_interval");
×
333
        try
334
        {
335
            interface.mapScrollMode = static_cast<MapScrollMode>(iniInterface->getIntValue("map_scroll_mode"));
×
336
        } catch(const std::runtime_error&)
×
337
        {
338
            interface.mapScrollMode =
×
339
              iniInterface->getBoolValue("invert_mouse") ? MapScrollMode::ScrollSame : MapScrollMode::ScrollOpposite;
×
340
            s25util::warning(
×
341
              "Value 'map_scroll_mode' not found! Using 'invert_mouse' instead - please recheck your settings!");
342
        }
343
        interface.enableWindowPinning = iniInterface->getValue("enable_window_pinning", false);
×
344
        interface.windowSnapDistance = iniInterface->getValue("window_snap_distance", 8);
×
345
        // }
346

347
        // addons
348
        // {
349
        for(unsigned addon = 0; addon < iniAddons->size(); ++addon)
×
350
        {
351
            const auto* item = dynamic_cast<const libsiedler2::ArchivItem_Text*>(iniAddons->get(addon));
×
352

353
            if(item)
×
354
                addons.configuration.insert(std::make_pair(s25util::fromStringClassic<unsigned>(item->getName()),
×
355
                                                           s25util::fromStringClassic<unsigned>(item->getText())));
×
356
        }
357

358
        LoadIngame();
×
359
        // }
360
    } catch(const std::runtime_error& e)
×
361
    {
362
        s25util::warning(std::string("Could not use settings from \"") + settingsPath.string()
×
363
                         + "\", using default values. Reason: " + e.what());
×
364
        LoadDefaults();
×
365
        Save();
×
366
    }
367
}
×
368

369
void Settings::LoadIngame()
×
370
{
371
    libsiedler2::Archiv settingsIngame;
×
372
    const auto settingsPathIngame = RTTRCONFIG.ExpandPath(s25::resources::ingameOptions);
×
373
    try
374
    {
375
        if(libsiedler2::Load(settingsPathIngame, settingsIngame) != 0)
×
376
            throw std::runtime_error("File missing");
×
377

378
        const libsiedler2::ArchivItem_Ini* iniIngame =
379
          static_cast<libsiedler2::ArchivItem_Ini*>(settingsIngame.find("ingame"));
×
380
        if(!iniIngame)
×
381
            throw std::runtime_error("Missing section");
×
382
        // ingame
383
        // {
384
        ingame.scale_statistics = iniIngame->getBoolValue("scale_statistics");
×
385
        ingame.showBQ = iniIngame->getBoolValue("show_building_quality");
×
386
        ingame.showNames = iniIngame->getBoolValue("show_names");
×
387
        ingame.showProductivity = iniIngame->getBoolValue("show_productivity");
×
388
        ingame.minimapExtended = iniIngame->getBoolValue("minimap_extended");
×
389
        // }
390
        // ingame windows
391
        for(const auto& window : persistentWindows)
×
392
        {
393
            const auto* iniWindow = static_cast<const libsiedler2::ArchivItem_Ini*>(settingsIngame.find(window.second));
×
394
            if(!iniWindow)
×
395
                continue;
×
396
            auto& settings = windows.persistentSettings[window.first];
×
397
            const auto lastPos = settings.lastPos =
×
398
              DrawPoint(iniWindow->getIntValue("pos_x"), iniWindow->getIntValue("pos_y"));
×
399
            settings.restorePos = DrawPoint(iniWindow->getValue("restore_pos_x", lastPos.x),
×
400
                                            iniWindow->getValue("restore_pos_y", lastPos.y));
×
401
            settings.isOpen = iniWindow->getIntValue("is_open");
×
402
            settings.isPinned = iniWindow->getValue("is_pinned", false);
×
403
            settings.isMinimized = iniWindow->getValue("is_minimized", false);
×
404
        }
405
    } catch(const std::runtime_error& e)
×
406
    {
407
        s25util::warning(std::string("Could not use ingame settings from \"") + settingsPathIngame.string()
×
408
                         + "\", using default values. Reason: " + e.what());
×
409
        LoadIngameDefaults();
×
410
        SaveIngame();
×
411
    }
412
}
×
413

414
///////////////////////////////////////////////////////////////////////////////
415
// Routine for saving the configuration
416
void Settings::Save()
×
417
{
418
    libsiedler2::Archiv settings;
×
419
    settings.alloc(SECTION_NAMES.size());
×
420
    for(unsigned i = 0; i < SECTION_NAMES.size(); ++i)
×
421
        settings.set(i, std::make_unique<libsiedler2::ArchivItem_Ini>(SECTION_NAMES[i]));
×
422

423
    libsiedler2::ArchivItem_Ini* iniGlobal = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("global"));
×
424
    libsiedler2::ArchivItem_Ini* iniVideo = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("video"));
×
425
    libsiedler2::ArchivItem_Ini* iniLanguage = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("language"));
×
426
    libsiedler2::ArchivItem_Ini* iniDriver = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("driver"));
×
427
    libsiedler2::ArchivItem_Ini* iniSound = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("sound"));
×
428
    libsiedler2::ArchivItem_Ini* iniLobby = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("lobby"));
×
429
    libsiedler2::ArchivItem_Ini* iniServer = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("server"));
×
430
    libsiedler2::ArchivItem_Ini* iniProxy = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("proxy"));
×
431
    libsiedler2::ArchivItem_Ini* iniInterface = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("interface"));
×
432
    libsiedler2::ArchivItem_Ini* iniAddons = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("addons"));
×
433

434
    // Is one of the categories missing?
435
    RTTR_Assert(iniGlobal && iniVideo && iniLanguage && iniDriver && iniSound && iniLobby && iniServer && iniProxy
×
436
                && iniInterface && iniAddons);
437

438
    // global
439
    // {
440
    iniGlobal->setValue("version", VERSION);
×
441
    iniGlobal->setValue("gameversion", rttr::version::GetRevision());
×
442
    iniGlobal->setValue("submit_debug_data", global.submit_debug_data);
×
443
    iniGlobal->setValue("use_upnp", global.use_upnp);
×
444
    iniGlobal->setValue("smartCursor", global.smartCursor);
×
445
    iniGlobal->setValue("debugMode", global.debugMode);
×
446
    iniGlobal->setValue("showGFInfo", global.showGFInfo);
×
447
    // };
448

449
    // video
450
    // {
451
    iniVideo->setValue("fullscreen_width", video.fullscreenSize.width);
×
452
    iniVideo->setValue("fullscreen_height", video.fullscreenSize.height);
×
453
    iniVideo->setValue("windowed_width", video.windowedSize.width);
×
454
    iniVideo->setValue("windowed_height", video.windowedSize.height);
×
NEW
455
    iniVideo->setValue("displayMode", rttr::enum_cast(video.displayMode));
×
456
    iniVideo->setValue("framerate", video.framerate);
×
457
    iniVideo->setValue("vbo", video.vbo);
×
458
    iniVideo->setValue("shared_textures", video.shared_textures);
×
459
    iniVideo->setValue("gui_scale", video.guiScale);
×
460
    // };
461

462
    // language
463
    // {
464
    iniLanguage->setValue("language", language.language);
×
465
    // }
466

467
    // driver
468
    // {
469
    iniDriver->setValue("video", driver.video);
×
470
    iniDriver->setValue("audio", driver.audio);
×
471
    // }
472

473
    // sound
474
    // {
475
    iniSound->setValue("musik", sound.musicEnabled);
×
476
    iniSound->setValue("musik_volume", sound.musicVolume);
×
477
    iniSound->setValue("effekte", sound.effectsEnabled);
×
478
    iniSound->setValue("effekte_volume", sound.effectsVolume);
×
479
    iniSound->setValue("bird_sounds", sound.birdsEnabled);
×
480
    iniSound->setValue("playlist", sound.playlist);
×
481
    // }
482

483
    // lobby
484
    // {
485
    iniLobby->setValue("name", lobby.name);
×
486
    iniLobby->setValue("portrait_index", lobby.portraitIndex);
×
487
    iniLobby->setValue("password", lobby.password);
×
488
    iniLobby->setValue("save_password", lobby.save_password);
×
489
    // }
490

491
    // server
492
    // {
493
    iniServer->setValue("last_ip", server.last_ip);
×
494
    iniServer->setValue("local_port", server.localPort);
×
495
    iniServer->setValue("ipv6", server.ipv6);
×
496
    // }
497

498
    // proxy
499
    // {
500
    iniProxy->setValue("proxy", proxy.hostname);
×
501
    iniProxy->setValue("port", proxy.port);
×
502
    iniProxy->setValue("typ", static_cast<int>(proxy.type));
×
503
    // }
504

505
    // interface
506
    // {
507
    iniInterface->setValue("autosave_interval", interface.autosave_interval);
×
508
    iniInterface->setValue("map_scroll_mode", static_cast<int>(interface.mapScrollMode));
×
509
    iniInterface->setValue("enable_window_pinning", interface.enableWindowPinning);
×
510
    iniInterface->setValue("window_snap_distance", interface.windowSnapDistance);
×
511
    // }
512

513
    // addons
514
    // {
515
    iniAddons->clear();
×
516
    for(const auto& it : addons.configuration)
×
517
        iniAddons->setValue(s25util::toStringClassic(it.first), s25util::toStringClassic(it.second));
×
518
    // }
519

520
    bfs::path settingsPath = RTTRCONFIG.ExpandPath(s25::resources::config);
×
521
    if(libsiedler2::Write(settingsPath, settings) == 0)
×
522
        bfs::permissions(settingsPath, bfs::owner_read | bfs::owner_write);
×
523

524
    SaveIngame();
×
525
}
×
526

527
void Settings::SaveIngame()
×
528
{
529
    libsiedler2::Archiv settingsIngame;
×
530
    settingsIngame.alloc(1 + persistentWindows.size());
×
531
    settingsIngame.set(0, std::make_unique<libsiedler2::ArchivItem_Ini>("ingame"));
×
532
    unsigned i = 1;
×
533
    for(const auto& window : persistentWindows)
×
534
    {
535
        settingsIngame.set(i, std::make_unique<libsiedler2::ArchivItem_Ini>(window.second));
×
536
        i++;
×
537
    }
538

539
    auto* iniIngame = static_cast<libsiedler2::ArchivItem_Ini*>(settingsIngame.find("ingame"));
×
540

541
    RTTR_Assert(iniIngame);
×
542

543
    // ingame
544
    // {
545
    iniIngame->setValue("scale_statistics", ingame.scale_statistics);
×
546
    iniIngame->setValue("show_building_quality", ingame.showBQ);
×
547
    iniIngame->setValue("show_names", ingame.showNames);
×
548
    iniIngame->setValue("show_productivity", ingame.showProductivity);
×
549
    iniIngame->setValue("minimap_extended", ingame.minimapExtended);
×
550
    // }
551

552
    // ingame windows
553
    for(const auto& window : persistentWindows)
×
554
    {
555
        auto* iniWindow = static_cast<libsiedler2::ArchivItem_Ini*>(settingsIngame.find(window.second));
×
556
        if(!iniWindow)
×
557
            continue;
×
558
        const auto& settings = windows.persistentSettings[window.first];
×
559
        iniWindow->setValue("pos_x", settings.lastPos.x);
×
560
        iniWindow->setValue("pos_y", settings.lastPos.y);
×
561
        if(settings.restorePos != settings.lastPos)
×
562
        {
563
            // only save if different; defaults to lastPos on load
564
            iniWindow->setValue("restore_pos_x", settings.restorePos.x);
×
565
            iniWindow->setValue("restore_pos_y", settings.restorePos.y);
×
566
        }
567
        iniWindow->setValue("is_open", settings.isOpen);
×
568
        iniWindow->setValue("is_pinned", settings.isPinned);
×
569
        iniWindow->setValue("is_minimized", settings.isMinimized);
×
570
    }
571

572
    bfs::path settingsPathIngame = RTTRCONFIG.ExpandPath(s25::resources::ingameOptions);
×
573
    if(libsiedler2::Write(settingsPathIngame, settingsIngame) == 0)
×
574
        bfs::permissions(settingsPathIngame, bfs::owner_read | bfs::owner_write);
×
575
}
×
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