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

Return-To-The-Roots / s25client / 20607594693

30 Dec 2025 10:50PM UTC coverage: 50.479% (-0.02%) from 50.503%
20607594693

Pull #1804

github

web-flow
Merge 18406add3 into af2863637
Pull Request #1804: Android build

66 of 228 new or added lines in 13 files covered. (28.95%)

3 existing lines in 2 files now uncovered.

22599 of 44769 relevant lines covered (50.48%)

35106.04 hits per line

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

0.0
/libs/s25main/desktops/dskOptions.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 "dskOptions.h"
6
#include "GlobalGameSettings.h"
7
#include "Loader.h"
8
#include "MusicPlayer.h"
9
#include "Settings.h"
10
#include "WindowManager.h"
11
#include "controls/ctrlComboBox.h"
12
#include "controls/ctrlEdit.h"
13
#include "controls/ctrlGroup.h"
14
#include "controls/ctrlImageButton.h"
15
#include "controls/ctrlOptionGroup.h"
16
#include "controls/ctrlProgress.h"
17
#include "driver/VideoDriver.h"
18
#include "drivers/AudioDriverWrapper.h"
19
#include "drivers/VideoDriverWrapper.h"
20
#include "dskMainMenu.h"
21
#include "helpers/containerUtils.h"
22
#include "helpers/format.hpp"
23
#include "helpers/mathFuncs.h"
24
#include "helpers/toString.h"
25
#include "ingameWindows/iwAddons.h"
26
#include "ingameWindows/iwMsgbox.h"
27
#include "ingameWindows/iwMusicPlayer.h"
28
#include "ingameWindows/iwTextfile.h"
29
#include "languages.h"
30
#include "ogl/FontStyle.h"
31
#include "gameData/PortraitConsts.h"
32
#include "s25util/StringConversion.h"
33
#include "s25util/colors.h"
34
#include <mygettext/mygettext.h>
35
#include <sstream>
36

37
namespace {
38
enum
39
{
40
    ID_btBack = dskMenuBase::ID_FIRST_FREE,
41
    ID_txtOptions,
42
    ID_btAddons,
43
    ID_grpOptions,
44
    ID_btCommon,
45
    ID_btGraphics,
46
    ID_btSound,
47
    ID_grpCommon,
48
    ID_grpGraphics,
49
    ID_grpSound,
50
    ID_txtName,
51
    ID_edtName,
52
    ID_txtLanguage,
53
    ID_cbLanguage,
54
    ID_txtKeyboardLayout,
55
    ID_btKeyboardLayout,
56
    ID_txtPort,
57
    ID_edtPort,
58
    ID_txtIpv6,
59
    ID_grpIpv6,
60
    ID_txtProxy,
61
    ID_edtProxy,
62
    ID_edtProxyPort,
63
    ID_txtProxyType,
64
    ID_cbProxyType,
65
    ID_txtDebugData,
66
    ID_grpDebugData,
67
    ID_txtUPNP,
68
    ID_grpUPNP,
69
    ID_txtMapScrollMode,
70
    ID_cbMapScrollMode,
71
    ID_txtSmartCursor,
72
    ID_grpSmartCursor,
73
    ID_txtGFInfo,
74
    ID_grpGFInfo,
75
    ID_txtResolution,
76
    ID_cbResolution,
77
    ID_txtFullscreen,
78
    ID_grpFullscreen,
79
    ID_txtFramerate,
80
    ID_cbFramerate,
81
    ID_txtVBO,
82
    ID_grpVBO,
83
    ID_txtVideoDriver,
84
    ID_cbVideoDriver,
85
    ID_txtOptTextures,
86
    ID_grpOptTextures,
87
    ID_txtGuiScale,
88
    ID_cbGuiScale,
89
    ID_txtAudioDriver,
90
    ID_cbAudioDriver,
91
    ID_txtMusic,
92
    ID_grpMusic,
93
    ID_pgMusicVol,
94
    ID_txtEffects,
95
    ID_grpEffects,
96
    ID_pgEffectsVol,
97
    ID_btMusicPlayer,
98
    ID_txtCommonPortrait,
99
    ID_btCommonPortrait,
100
    ID_cbCommonPortrait,
101
    ID_txtBirdSounds,
102
    ID_grpBirdSounds,
103
};
104
// Use these as IDs in dedicated groups
105
constexpr auto ID_btOn = 1;
106
constexpr auto ID_btOff = 0;
107
// Special case: Submit debug data uses "2" for "ask user" and "0" for "unset, ask at start"
108
constexpr auto ID_btSubmitDebugOn = 1;
109
constexpr auto ID_btSubmitDebugAsk = 2;
110

111
constexpr auto rowHeight = 30;
112
constexpr auto sectionSpacing = 20;
113
constexpr auto sectionSpacingCommon = 10;
114
constexpr auto tabButtonsStartPosition = DrawPoint(80, 510);
115
constexpr auto optionRowsStartPosition = DrawPoint(80, 80);
116
} // namespace
117

118
static VideoMode getAspectRatio(const VideoMode& vm)
×
119
{
120
    // First some a bit off values where the aspect ratio is defined by convention
121
    if(vm == VideoMode(1360, 1024))
×
122
        return VideoMode(4, 3);
×
123
    else if(vm == VideoMode(1360, 768) || vm == VideoMode(1366, 768))
×
124
        return VideoMode(16, 9);
×
125

126
    // Normally Aspect ration is simply width/height as integer numbers (e.g. 4:3)
127
    int divisor = helpers::gcd(vm.width, vm.height);
×
128
    VideoMode ratio(vm.width / divisor, vm.height / divisor);
×
129
    // But there are some special cases:
130
    if(ratio == VideoMode(8, 5))
×
131
        return VideoMode(16, 10);
×
132
    else if(ratio == VideoMode(5, 3))
×
133
        return VideoMode(15, 9);
×
134
    else
135
        return ratio;
×
136
}
137

138
dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
×
139
{
140
    AddText(ID_txtOptions, DrawPoint(400, 10), _("Options"), COLOR_YELLOW, FontStyle::CENTER, LargeFont);
×
141

142
    ctrlOptionGroup* mainGroup = AddOptionGroup(ID_grpOptions, GroupSelectType::Check);
×
143

144
    DrawPoint curPos = tabButtonsStartPosition;
×
145
    mainGroup->AddTextButton(ID_btCommon, DrawPoint(curPos.x, curPos.y), Extent(200, 22), TextureColor::Green2,
×
146
                             _("Common"), NormalFont);
×
147
    mainGroup->AddTextButton(ID_btGraphics, DrawPoint(curPos.x + 220, curPos.y), Extent(200, 22), TextureColor::Green2,
×
148
                             _("Graphics"), NormalFont);
×
149
    mainGroup->AddTextButton(ID_btSound, DrawPoint(curPos.x + 440, curPos.y), Extent(200, 22), TextureColor::Green2,
×
150
                             _("Sound/Music"), NormalFont);
×
151
    curPos.y += rowHeight + sectionSpacingCommon;
×
152

153
    AddTextButton(ID_btBack, DrawPoint(curPos.x + 220, curPos.y), Extent(200, 22), TextureColor::Red1, _("Back"),
×
154
                  NormalFont);
×
155
    AddTextButton(ID_btAddons, DrawPoint(curPos.x + 440, curPos.y), Extent(200, 22), TextureColor::Green2, _("Addons"),
×
156
                  NormalFont);
×
157

158
    ctrlGroup* groupCommon = AddGroup(ID_grpCommon);
×
159
    ctrlGroup* groupGraphics = AddGroup(ID_grpGraphics);
×
160
    ctrlGroup* groupSound = AddGroup(ID_grpSound);
×
161
    ctrlComboBox* combo;
162

163
    // Common
164
    // {
165

166
    curPos = optionRowsStartPosition;
×
167
    using Offset = DrawPoint;
168
    constexpr Offset ctrlOffset(200, -5);                       // Offset of control to its description text
×
169
    constexpr Offset ctrlOffset2 = ctrlOffset + Offset(200, 0); // Offset of 2nd control to its description text
×
170
    constexpr Extent ctrlSize(190, 22);
×
171
    constexpr Extent ctrlSizeLarge = ctrlSize + Extent(ctrlOffset2 - ctrlOffset);
×
172

173
    groupCommon->AddText(ID_txtName, curPos, _("Name in Game:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
174
    ctrlEdit* name =
175
      groupCommon->AddEdit(ID_edtName, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 15);
×
176
    name->SetText(SETTINGS.lobby.name);
×
177

178
    const auto& currentPortrait = Portraits[SETTINGS.lobby.portraitIndex];
×
179
    groupCommon->AddImageButton(ID_btCommonPortrait, DrawPoint(500, curPos.y - 5), Extent(40, 54), TextureColor::Grey,
×
180
                                LOADER.GetImageN(currentPortrait.resourceId, currentPortrait.resourceIndex));
×
181
    curPos.y += rowHeight;
×
182

183
    groupCommon->AddText(ID_txtCommonPortrait, DrawPoint(80, curPos.y), _("Portrait:"), COLOR_YELLOW, FontStyle{},
×
184
                         NormalFont);
×
185
    combo = groupCommon->AddComboBox(ID_cbCommonPortrait, DrawPoint(280, curPos.y - 5), Extent(190, 20),
×
186
                                     TextureColor::Grey, NormalFont, 100);
×
187

188
    for(unsigned i = 0; i < Portraits.size(); ++i)
×
189
    {
190
        combo->AddString(_(Portraits[i].name));
×
191
        if(SETTINGS.lobby.portraitIndex == i)
×
192
        {
193
            combo->SetSelection(i);
×
194
        }
195
    }
196
    curPos.y += rowHeight;
×
197

198
    groupCommon->AddText(ID_txtLanguage, curPos, _("Language:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
199
    combo = groupCommon->AddComboBox(ID_cbLanguage, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 100);
×
200

201
    bool selected = false;
×
202
    for(unsigned i = 0; i < LANGUAGES.size(); ++i)
×
203
    {
204
        const Language& l = LANGUAGES.getLanguage(i);
×
205

206
        combo->AddString(_(l.name));
×
207
        if(SETTINGS.language.language == l.code)
×
208
        {
209
            combo->SetSelection(static_cast<unsigned short>(i));
×
210
            selected = true;
×
211
        }
212
    }
213
    if(!selected)
×
214
        combo->SetSelection(0);
×
215
    curPos.y += rowHeight;
×
216

217
    groupCommon->AddTextButton(ID_btKeyboardLayout, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey,
×
218
                               _("Keyboard layout"), NormalFont);
×
219
    curPos.y += rowHeight + sectionSpacingCommon;
×
220

221
    groupCommon->AddText(ID_txtPort, curPos, _("Local Port:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
222
    ctrlEdit* edtPort =
223
      groupCommon->AddEdit(ID_edtPort, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 15);
×
224
    edtPort->SetNumberOnly(true);
×
225
    edtPort->SetText(SETTINGS.server.localPort);
×
226
    curPos.y += rowHeight;
×
227

228
    // IPv4/6
229
    groupCommon->AddText(ID_txtIpv6, curPos, _("Use IPv6:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
230

231
    ctrlOptionGroup* ipv6 = groupCommon->AddOptionGroup(ID_grpIpv6, GroupSelectType::Check);
×
232
    ipv6->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("IPv6"), NormalFont);
×
233
    ipv6->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("IPv4"), NormalFont);
×
234
    ipv6->SetSelection(SETTINGS.server.ipv6);
×
235
    // Enable/disable the IPv6 field if necessary
236
    ipv6->GetCtrl<ctrlButton>(1)->SetEnabled(SETTINGS.proxy.type != ProxyType::Socks5); //-V807
×
237
    curPos.y += rowHeight + sectionSpacingCommon;
×
238

239
    // Proxy server
240
    groupCommon->AddText(ID_txtProxy, curPos, _("Proxyserver:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
241
    ctrlEdit* proxy = groupCommon->AddEdit(ID_edtProxy, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont);
×
242
    proxy->SetText(SETTINGS.proxy.hostname);
×
243
    proxy =
244
      groupCommon->AddEdit(ID_edtProxyPort, curPos + ctrlOffset2, Extent(50, 22), TextureColor::Grey, NormalFont, 5);
×
245
    proxy->SetNumberOnly(true);
×
246
    proxy->SetText(SETTINGS.proxy.port);
×
247
    curPos.y += rowHeight;
×
248

249
    groupCommon->AddText(ID_txtUPNP, curPos, _("Use UPnP"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
250
    ctrlOptionGroup* upnp = groupCommon->AddOptionGroup(ID_grpUPNP, GroupSelectType::Check);
×
251
    upnp->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"), NormalFont);
×
252
    upnp->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont);
×
253
    upnp->SetSelection(SETTINGS.global.use_upnp);
×
254
    curPos.y += rowHeight;
×
255

256
    // Proxy type
257
    groupCommon->AddText(ID_txtProxyType, curPos, _("Proxytyp:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
258
    combo =
259
      groupCommon->AddComboBox(ID_cbProxyType, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey, NormalFont, 100);
×
260
    combo->AddString(_("No Proxy"));
×
261
    combo->AddString(_("Socks v4"));
×
262
    // TODO: not implemented
263
    // combo->AddString(_("Socks v5"));
264

265
    switch(SETTINGS.proxy.type)
×
266
    {
267
        default: combo->SetSelection(0); break;
×
268
        case ProxyType::Socks4: combo->SetSelection(1); break;
×
269
        case ProxyType::Socks5: combo->SetSelection(2); break;
×
270
    }
271
    curPos.y += rowHeight + sectionSpacingCommon;
×
272

NEW
273
    groupCommon->AddText(ID_txtMapScrollMode, curPos, _("Map scroll mode:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
NEW
274
    combo = groupCommon->AddComboBox(ID_cbMapScrollMode, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey,
×
NEW
275
                                     NormalFont, 100);
×
NEW
276
    combo->AddString(_("Scroll same (Map moves in the same direction the mouse is moved when scrolling/panning.)"));
×
NEW
277
    combo->AddString(
×
278
      _("Scroll opposite (Map moves in the opposite direction the mouse is moved when scrolling/panning.)"));
NEW
279
    combo->AddString(_("Grab and drag (Map moves with your cursor when scrolling/panning.)"));
×
NEW
280
    combo->SetSelection(static_cast<int>(SETTINGS.interface.mapScrollMode));
×
NEW
281
    curPos.y += rowHeight + sectionSpacingCommon;
×
282

283
    groupCommon->AddText(ID_txtSmartCursor, curPos, _("Smart Cursor"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
284
    ctrlOptionGroup* smartCursor = groupCommon->AddOptionGroup(ID_grpSmartCursor, GroupSelectType::Check);
×
285
    smartCursor->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"), NormalFont,
×
286
                               _("Place cursor on default button for new dialogs / action windows (default)"));
287
    smartCursor->AddTextButton(
×
288
      ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont,
×
289
      _("Don't move cursor automatically\nUseful e.g. for split-screen / dual-mice multiplayer (see wiki)"));
290
    smartCursor->SetSelection(SETTINGS.global.smartCursor);
×
291
    curPos.y += rowHeight + sectionSpacingCommon;
×
292

293
    groupCommon->AddText(ID_txtDebugData, curPos, _("Submit debug data:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
294
    mainGroup = groupCommon->AddOptionGroup(ID_grpDebugData, GroupSelectType::Check);
×
295
    mainGroup->AddTextButton(ID_btSubmitDebugOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"),
×
296
                             NormalFont);
×
297
    mainGroup->AddTextButton(ID_btSubmitDebugAsk, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Ask always"),
×
298
                             NormalFont);
×
299

300
    mainGroup->SetSelection((SETTINGS.global.submit_debug_data == 1) ? ID_btSubmitDebugOn :
×
301
                                                                       ID_btSubmitDebugAsk); //-V807
302
    curPos.y += rowHeight;
×
303

304
    groupCommon->AddText(ID_txtGFInfo, curPos, _("Show GameFrame Info:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
305
    mainGroup = groupCommon->AddOptionGroup(ID_grpGFInfo, GroupSelectType::Check);
×
306
    mainGroup->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"), NormalFont);
×
307
    mainGroup->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont);
×
308

309
    mainGroup->SetSelection(SETTINGS.global.showGFInfo);
×
310

311
    curPos = optionRowsStartPosition;
×
312
    groupGraphics->AddText(ID_txtResolution, curPos, _("Fullscreen resolution:"), COLOR_YELLOW, FontStyle{},
×
313
                           NormalFont);
×
314
    groupGraphics->AddComboBox(ID_cbResolution, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 150);
×
315
    curPos.y += rowHeight + sectionSpacing;
×
316

317
    groupGraphics->AddText(ID_txtFullscreen, curPos, _("Mode:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
318
    mainGroup = groupGraphics->AddOptionGroup(ID_grpFullscreen, GroupSelectType::Check);
×
319
    mainGroup->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("Fullscreen"), NormalFont);
×
320
    mainGroup->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Windowed"), NormalFont);
×
321
    curPos.y += rowHeight + sectionSpacing;
×
322

323
    groupGraphics->AddText(ID_txtFramerate, curPos, _("Limit Framerate:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
324
    groupGraphics->AddComboBox(ID_cbFramerate, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey, NormalFont, 150);
×
325
    curPos.y += rowHeight + sectionSpacing;
×
326

327
    groupGraphics->AddText(ID_txtVBO, curPos, _("Vertex Buffer Objects:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
328
    mainGroup = groupGraphics->AddOptionGroup(ID_grpVBO, GroupSelectType::Check);
×
329
    mainGroup->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"), NormalFont);
×
330
    mainGroup->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont);
×
331
    curPos.y += rowHeight + sectionSpacing;
×
332

333
    groupGraphics->AddText(ID_txtVideoDriver, curPos, _("Graphics Driver"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
334
    combo = groupGraphics->AddComboBox(ID_cbVideoDriver, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey,
×
335
                                       NormalFont, 100);
×
336

337
    const auto video_drivers = drivers::DriverWrapper::LoadDriverList(drivers::DriverType::Video);
×
338

339
    for(const auto& video_driver : video_drivers)
×
340
    {
341
        combo->AddString(video_driver.GetName());
×
342
        if(video_driver.GetName() == SETTINGS.driver.video)
×
343
            combo->SetSelection(combo->GetNumItems() - 1);
×
344
    }
345
    curPos.y += rowHeight + sectionSpacing;
×
346

347
    groupGraphics->AddText(ID_txtOptTextures, curPos, _("Optimized Textures:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
348
    mainGroup = groupGraphics->AddOptionGroup(ID_grpOptTextures, GroupSelectType::Check);
×
349

350
    mainGroup->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"), NormalFont);
×
351
    mainGroup->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont);
×
352
    curPos.y += rowHeight + sectionSpacing;
×
353

354
    groupGraphics->AddText(ID_txtGuiScale, curPos, _("GUI Scale:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
355
    groupGraphics->AddComboBox(ID_cbGuiScale, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 100);
×
356
    updateGuiScale();
×
357

358
    curPos = optionRowsStartPosition;
×
359
    constexpr Offset bt1Offset(200, -5);
×
360
    constexpr Offset bt2Offset(300, -5);
×
361
    constexpr Offset volOffset(400, -5);
×
362
    constexpr Extent ctrlSizeSmall(90, ctrlSize.y);
×
363

364
    groupSound->AddText(ID_txtEffects, curPos, _("Effects"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
365
    mainGroup = groupSound->AddOptionGroup(ID_grpEffects, GroupSelectType::Check);
×
366
    mainGroup->AddTextButton(ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _("On"), NormalFont);
×
367
    mainGroup->AddTextButton(ID_btOff, curPos + bt2Offset, ctrlSizeSmall, TextureColor::Grey, _("Off"), NormalFont);
×
368

369
    ctrlProgress* FXvolume =
370
      groupSound->AddProgress(ID_pgEffectsVol, curPos + volOffset, ctrlSize, TextureColor::Grey, 139, 138, 100);
×
371
    FXvolume->SetPosition((SETTINGS.sound.effectsVolume * 100) / 255);
×
372
    curPos.y += rowHeight + sectionSpacing;
×
373

374
    groupSound->AddText(ID_txtBirdSounds, curPos, _("Bird sounds"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
375
    mainGroup = groupSound->AddOptionGroup(ID_grpBirdSounds, GroupSelectType::Check);
×
376
    mainGroup->AddTextButton(ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _("On"), NormalFont);
×
377
    mainGroup->AddTextButton(ID_btOff, curPos + bt2Offset, ctrlSizeSmall, TextureColor::Grey, _("Off"), NormalFont);
×
378
    curPos.y += rowHeight + sectionSpacing;
×
379

380
    groupSound->AddText(ID_txtMusic, curPos, _("Music"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
381
    mainGroup = groupSound->AddOptionGroup(ID_grpMusic, GroupSelectType::Check);
×
382
    mainGroup->AddTextButton(ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _("On"), NormalFont);
×
383
    mainGroup->AddTextButton(ID_btOff, curPos + bt2Offset, ctrlSizeSmall, TextureColor::Grey, _("Off"), NormalFont);
×
384

385
    ctrlProgress* Mvolume =
386
      groupSound->AddProgress(ID_pgMusicVol, curPos + volOffset, ctrlSize, TextureColor::Grey, 139, 138, 100);
×
387
    Mvolume->SetPosition((SETTINGS.sound.musicVolume * 100) / 255); //-V807
×
388
    curPos.y += rowHeight + sectionSpacing;
×
389

390
    groupSound->AddTextButton(ID_btMusicPlayer, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("Music player"),
×
391
                              NormalFont);
×
392
    curPos.y += rowHeight + sectionSpacing;
×
393

394
    groupSound->AddText(ID_txtAudioDriver, curPos, _("Sounddriver"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
395
    combo = groupSound->AddComboBox(ID_cbAudioDriver, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey,
×
396
                                    NormalFont, 100);
×
397

398
    const auto audio_drivers = drivers::DriverWrapper::LoadDriverList(drivers::DriverType::Audio);
×
399

400
    for(const auto& audio_driver : audio_drivers)
×
401
    {
402
        combo->AddString(audio_driver.GetName());
×
403
        if(audio_driver.GetName() == SETTINGS.driver.audio)
×
404
            combo->SetSelection(combo->GetNumItems() - 1);
×
405
    }
406

407
    // Select "General"
408
    mainGroup = GetCtrl<ctrlOptionGroup>(ID_grpOptions);
×
409
    mainGroup->SetSelection(ID_btCommon, true);
×
410

411
    // Graphics
412
    // {
413

414
    loadVideoModes();
×
415

416
    // and add to the combo box
417
    ctrlComboBox& cbVideoModes = *groupGraphics->GetCtrl<ctrlComboBox>(ID_cbResolution);
×
418
    for(const auto& videoMode : video_modes)
×
419
    {
420
        VideoMode ratio = getAspectRatio(videoMode);
×
421
        s25util::ClassicImbuedStream<std::ostringstream> str;
×
422
        str << videoMode.width << "x" << videoMode.height;
×
423
        // Make the length always the same as 'iiiixiiii' to align the ratio
424
        int len = str.str().length();
×
425
        for(int i = len; i < 4 + 1 + 4; i++)
×
426
            str << " ";
×
427
        str << " (" << ratio.width << ":" << ratio.height << ")";
×
428

429
        cbVideoModes.AddString(str.str());
×
430

431
        // Select, if this is the current resolution
432
        if(videoMode == SETTINGS.video.fullscreenSize) //-V807
×
433
            cbVideoModes.SetSelection(cbVideoModes.GetNumItems() - 1);
×
434
    }
435

436
    // Set "Fullscreen"
437
    groupGraphics->GetCtrl<ctrlOptionGroup>(ID_grpFullscreen)->SetSelection(SETTINGS.video.fullscreen); //-V807
×
438

439
    // Fill "Limit Framerate"
440
    auto* cbFrameRate = groupGraphics->GetCtrl<ctrlComboBox>(ID_cbFramerate);
×
441
    if(VIDEODRIVER.HasVSync())
×
442
        cbFrameRate->AddString(_("Dynamic (Limits to display refresh rate, works with most drivers)"));
×
443
    for(int framerate : Settings::SCREEN_REFRESH_RATES)
×
444
    {
445
        if(framerate == -1)
×
446
            cbFrameRate->AddString(_("Disabled"));
×
447
        else
448
            cbFrameRate->AddString(helpers::toString(framerate) + " FPS");
×
449
        if(SETTINGS.video.framerate == framerate)
×
450
            cbFrameRate->SetSelection(cbFrameRate->GetNumItems() - 1);
×
451
    }
452
    if(!cbFrameRate->GetSelection())
×
453
        cbFrameRate->SetSelection(0);
×
454

455
    groupGraphics->GetCtrl<ctrlOptionGroup>(ID_grpVBO)->SetSelection(SETTINGS.video.vbo);
×
456

457
    groupGraphics->GetCtrl<ctrlOptionGroup>(ID_grpOptTextures)->SetSelection(SETTINGS.video.shared_textures);
×
458
    // }
459

460
    // Sound
461
    // {
462

463
    groupSound->GetCtrl<ctrlOptionGroup>(ID_grpEffects)->SetSelection(SETTINGS.sound.effectsEnabled);
×
464
    groupSound->GetCtrl<ctrlOptionGroup>(ID_grpBirdSounds)->SetSelection(SETTINGS.sound.birdsEnabled);
×
465
    groupSound->GetCtrl<ctrlOptionGroup>(ID_grpMusic)->SetSelection(SETTINGS.sound.musicEnabled);
×
466

467
    // }
468

469
    // Load game settings
470
    ggs.LoadSettings();
×
471
}
×
472

473
dskOptions::~dskOptions()
×
474
{
475
    // Save game settings
476
    ggs.SaveSettings();
×
477
}
×
478

479
void dskOptions::Msg_Group_ProgressChange(const unsigned /*group_id*/, const unsigned ctrl_id,
×
480
                                          const unsigned short position)
481
{
482
    switch(ctrl_id)
×
483
    {
484
        case ID_pgEffectsVol:
×
485
            SETTINGS.sound.effectsVolume = static_cast<uint8_t>((position * 255) / 100);
×
486
            AUDIODRIVER.SetMasterEffectVolume(SETTINGS.sound.effectsVolume);
×
487
            break;
×
488
        case ID_pgMusicVol:
×
489
            SETTINGS.sound.musicVolume = static_cast<uint8_t>((position * 255) / 100);
×
490
            AUDIODRIVER.SetMusicVolume(SETTINGS.sound.musicVolume);
×
491
            break;
×
492
    }
493
}
×
494

495
void dskOptions::Msg_Group_ComboSelectItem(const unsigned group_id, const unsigned ctrl_id, const unsigned selection)
×
496
{
497
    auto* group = GetCtrl<ctrlGroup>(group_id);
×
498
    auto* combo = group->GetCtrl<ctrlComboBox>(ctrl_id);
×
499

500
    switch(ctrl_id)
×
501
    {
502
        case ID_cbCommonPortrait:
×
503
            SETTINGS.lobby.portraitIndex = selection;
×
504
            updatePortraitControls();
×
505
            break;
×
506
        case ID_cbLanguage:
×
507
        {
508
            // Language changed?
509
            std::string old_lang = SETTINGS.language.language; //-V807
×
510
            SETTINGS.language.language = LANGUAGES.setLanguage(selection);
×
511
            if(SETTINGS.language.language != old_lang)
×
512
                WINDOWMANAGER.Switch(std::make_unique<dskOptions>());
×
513
        }
514
        break;
×
515
        case ID_cbProxyType:
×
516
            switch(selection)
517
            {
518
                case 0: SETTINGS.proxy.type = ProxyType::None; break;
×
519
                case 1: SETTINGS.proxy.type = ProxyType::Socks4; break;
×
520
                case 2: SETTINGS.proxy.type = ProxyType::Socks5; break;
×
521
            }
522

523
            // Disable IPv6 visually
524
            if(SETTINGS.proxy.type == ProxyType::Socks4 && SETTINGS.server.ipv6)
×
525
            {
526
                GetCtrl<ctrlGroup>(ID_grpCommon)->GetCtrl<ctrlOptionGroup>(ID_grpIpv6)->SetSelection(0);
×
527
                GetCtrl<ctrlGroup>(ID_grpCommon)
×
528
                  ->GetCtrl<ctrlOptionGroup>(ID_grpIpv6)
×
529
                  ->GetCtrl<ctrlButton>(1)
530
                  ->SetEnabled(false);
×
531
                SETTINGS.server.ipv6 = false;
×
532
            }
533

534
            if(SETTINGS.proxy.type != ProxyType::Socks4)
×
535
                GetCtrl<ctrlGroup>(ID_grpCommon)
×
536
                  ->GetCtrl<ctrlOptionGroup>(ID_grpIpv6)
×
537
                  ->GetCtrl<ctrlButton>(1)
538
                  ->SetEnabled(true);
×
539
            break;
×
NEW
540
        case ID_cbMapScrollMode: SETTINGS.interface.mapScrollMode = static_cast<MapScrollMode>(selection); break;
×
541
        case ID_cbResolution: SETTINGS.video.fullscreenSize = video_modes[selection]; break;
×
542
        case ID_cbFramerate:
×
543
            if(VIDEODRIVER.HasVSync())
×
544
            {
545
                if(selection == 0)
×
546
                    SETTINGS.video.framerate = 0;
×
547
                else
548
                    SETTINGS.video.framerate = Settings::SCREEN_REFRESH_RATES[selection - 1];
×
549
            } else
550
                SETTINGS.video.framerate = Settings::SCREEN_REFRESH_RATES[selection];
×
551

552
            VIDEODRIVER.setTargetFramerate(SETTINGS.video.framerate);
×
553
            break;
×
554
        case ID_cbVideoDriver: SETTINGS.driver.video = combo->GetText(selection); break;
×
555
        case ID_cbGuiScale:
×
556
            SETTINGS.video.guiScale = guiScales_[selection];
×
557
            VIDEODRIVER.setGuiScalePercent(SETTINGS.video.guiScale);
×
558
            break;
×
559
        case ID_cbAudioDriver: SETTINGS.driver.audio = combo->GetText(selection); break;
×
560
    }
561
}
×
562

563
void dskOptions::Msg_Group_OptionGroupChange(const unsigned /*group_id*/, const unsigned ctrl_id,
×
564
                                             const unsigned selection)
565
{
566
    const bool enabled = selection == ID_btOn;
×
567
    switch(ctrl_id)
×
568
    {
569
        case ID_grpIpv6: SETTINGS.server.ipv6 = enabled; break;
×
570
        case ID_grpFullscreen: SETTINGS.video.fullscreen = enabled; break;
×
571
        case ID_grpVBO: SETTINGS.video.vbo = enabled; break;
×
572
        case ID_grpOptTextures: SETTINGS.video.shared_textures = enabled; break;
×
573
        case ID_grpEffects: SETTINGS.sound.effectsEnabled = enabled; break;
×
574
        case ID_grpBirdSounds: SETTINGS.sound.birdsEnabled = enabled; break;
×
575
        case ID_grpMusic:
×
576
            SETTINGS.sound.musicEnabled = enabled;
×
577
            if(enabled)
×
578
                MUSICPLAYER.Play();
×
579
            else
580
                MUSICPLAYER.Stop();
×
581
            break;
×
582
        case ID_grpDebugData:
×
583
            // Special case: Uses e.g. ID_btSubmitDebugOn directly
584
            SETTINGS.global.submit_debug_data = selection;
×
585
            break;
×
586
        case ID_grpUPNP: SETTINGS.global.use_upnp = enabled; break;
×
587
        case ID_grpSmartCursor:
×
588
            SETTINGS.global.smartCursor = enabled;
×
589
            VIDEODRIVER.SetMouseWarping(enabled);
×
590
            break;
×
591
        case ID_grpGFInfo: SETTINGS.global.showGFInfo = enabled; break;
×
592
    }
593
}
×
594

595
void dskOptions::Msg_OptionGroupChange(const unsigned ctrl_id, const unsigned selection)
×
596
{
597
    if(ctrl_id == ID_grpOptions)
×
598
    {
599
        const auto visGrp = selection + ID_grpCommon - ID_btCommon;
×
600
        for(const unsigned id : {ID_grpCommon, ID_grpGraphics, ID_grpSound})
×
601
            GetCtrl<ctrlGroup>(id)->SetVisible(id == visGrp);
×
602
    }
603
}
×
604

605
/// Check that the port is valid and sets outPort to it. Shows an error otherwise
606
static bool validatePort(const std::string& sPort, uint16_t& outPort)
×
607
{
608
    boost::optional<uint16_t> port = validate::checkPort(sPort);
×
609
    if(port)
×
610
        outPort = *port;
×
611
    else
612
    {
613
        WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(_("Error"),
×
614
                                                      _("Invalid port. The valid port-range is 1 to 65535!"), nullptr,
×
615
                                                      MsgboxButton::Ok, MsgboxIcon::ExclamationRed, 1));
×
616
    }
617
    return static_cast<bool>(port);
×
618
}
619

620
void dskOptions::Msg_ButtonClick(const unsigned ctrl_id)
×
621
{
622
    switch(ctrl_id)
×
623
    {
624
        case ID_btBack:
×
625
        {
626
            auto* groupCommon = GetCtrl<ctrlGroup>(ID_grpCommon);
×
627

628
            // Save the name
629
            SETTINGS.lobby.name = groupCommon->GetCtrl<ctrlEdit>(ID_edtName)->GetText();
×
630
            if(!validatePort(groupCommon->GetCtrl<ctrlEdit>(ID_edtPort)->GetText(), SETTINGS.server.localPort))
×
631
                return;
×
632

633
            SETTINGS.proxy.hostname = groupCommon->GetCtrl<ctrlEdit>(ID_edtProxy)->GetText();
×
634
            if(!validatePort(groupCommon->GetCtrl<ctrlEdit>(ID_edtProxyPort)->GetText(), SETTINGS.proxy.port))
×
635
                return;
×
636

637
            SETTINGS.Save();
×
638

639
            // Is the selected backend required to support GUI scaling to fullfill the user's choice?
640
            // If so, warn the user if the backend is unable to support GUI scaling.
641
            if(VIDEODRIVER.getGuiScale().percent() == 100
×
642
               && (SETTINGS.video.guiScale != 100
×
643
                   || (SETTINGS.video.guiScale == 0 && VIDEODRIVER.getGuiScaleRange().recommendedPercent != 100)))
×
644
            {
645
                WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(
×
646
                  _("Sorry!"), _("The selected video driver does not support GUI scaling! Setting won't be used."),
×
647
                  this, MsgboxButton::Ok, MsgboxIcon::ExclamationGreen, 1));
×
648
            }
649

650
            if((SETTINGS.video.fullscreen && SETTINGS.video.fullscreenSize != VIDEODRIVER.GetWindowSize()) //-V807
×
651
               || SETTINGS.video.fullscreen != VIDEODRIVER.IsFullscreen())
×
652
            {
653
                const auto screenSize =
654
                  SETTINGS.video.fullscreen ? SETTINGS.video.fullscreenSize : SETTINGS.video.windowedSize;
×
655
                if(!VIDEODRIVER.ResizeScreen(screenSize, SETTINGS.video.fullscreen))
×
656
                {
657
                    WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(
×
658
                      _("Sorry!"), _("You need to restart your game to change the screen resolution!"), this,
×
659
                      MsgboxButton::Ok, MsgboxIcon::ExclamationGreen, 1));
×
660
                    return;
×
661
                }
662
            }
663
            if(SETTINGS.driver.video != VIDEODRIVER.GetName() || SETTINGS.driver.audio != AUDIODRIVER.GetName())
×
664
            {
665
                WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(
×
666
                  _("Sorry!"), _("You need to restart your game to change the video or audio driver!"), this,
×
667
                  MsgboxButton::Ok, MsgboxIcon::ExclamationGreen, 1));
×
668
                return;
×
669
            }
670

671
            WINDOWMANAGER.Switch(std::make_unique<dskMainMenu>());
×
672
        }
673
        break;
×
674
        case ID_btAddons: WINDOWMANAGER.ToggleWindow(std::make_unique<iwAddons>(ggs)); break;
×
675
    }
676
}
677

678
void dskOptions::Msg_Group_ButtonClick(const unsigned /*group_id*/, const unsigned ctrl_id)
×
679
{
680
    switch(ctrl_id)
×
681
    {
682
        default: break;
×
683
        case ID_btCommonPortrait:
×
684
            SETTINGS.lobby.portraitIndex = (SETTINGS.lobby.portraitIndex + 1) % Portraits.size();
×
685
            updatePortraitControls();
×
686
            break;
×
687
        case ID_btMusicPlayer: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMusicPlayer>()); break;
×
688
        case ID_btKeyboardLayout:
×
689
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("keyboardlayout.txt", _("Keyboard layout")));
×
690
            break;
×
691
    }
692
}
×
693

694
void dskOptions::Msg_MsgBoxResult(const unsigned msgbox_id, const MsgboxResult /*mbr*/)
×
695
{
696
    switch(msgbox_id)
×
697
    {
698
        default: break;
×
699
        // "You need to restart your game ..."
700
        // "The selected video driver does not support GUI scaling!"
701
        case 1: WINDOWMANAGER.Switch(std::make_unique<dskMainMenu>()); break;
×
702
    }
703
}
×
704

705
static bool cmpVideoModes(const VideoMode& left, const VideoMode& right)
×
706
{
707
    if(left.width == right.width)
×
708
        return left.height > right.height;
×
709
    else
710
        return left.width > right.width;
×
711
}
712

713
void dskOptions::loadVideoModes()
×
714
{
715
    // Get available modes
716
    VIDEODRIVER.ListVideoModes(video_modes);
×
717
    // Remove everything below 800x600
718
    helpers::erase_if(video_modes, [](const auto& it) { return it.width < 800 && it.height < 600; });
×
719
    // Sort by aspect ratio
720
    std::sort(video_modes.begin(), video_modes.end(), cmpVideoModes);
×
721
}
×
722

723
void dskOptions::Msg_ScreenResize(const ScreenResizeEvent& sr)
×
724
{
725
    Desktop::Msg_ScreenResize(sr);
×
726
    updateGuiScale();
×
727
}
×
728

729
bool dskOptions::Msg_WheelUp(const MouseCoords& mc)
×
730
{
731
    if(VIDEODRIVER.GetModKeyState().ctrl)
×
732
    {
733
        scrollGuiScale(true);
×
734
        return true;
×
735
    } else
736
        return Desktop::Msg_WheelUp(mc);
×
737
}
738

739
bool dskOptions::Msg_WheelDown(const MouseCoords& mc)
×
740
{
741
    if(VIDEODRIVER.GetModKeyState().ctrl)
×
742
    {
743
        scrollGuiScale(false);
×
744
        return true;
×
745
    } else
746
        return Desktop::Msg_WheelDown(mc);
×
747
}
748

749
void dskOptions::updateGuiScale()
×
750
{
751
    // generate GUI scale percentages in 10% increments
752
    constexpr auto stepSize = 10u;
×
753
    const auto roundGuiScale = [=](unsigned percent) {
×
754
        return helpers::iround<unsigned>(static_cast<float>(percent) / stepSize) * stepSize;
×
755
    };
756

757
    const auto range = VIDEODRIVER.getGuiScaleRange();
×
758
    const auto recommendedPercentRounded = roundGuiScale(range.recommendedPercent);
×
759
    auto* combo = GetCtrl<ctrlGroup>(ID_grpGraphics)->GetCtrl<ctrlComboBox>(ID_cbGuiScale);
×
760

761
    guiScales_.clear();
×
762
    combo->DeleteAllItems();
×
763

764
    guiScales_.push_back(0);
×
765
    combo->AddString(helpers::format(_("Auto (%u%%)"), range.recommendedPercent));
×
766
    if(SETTINGS.video.guiScale == 0)
×
767
        combo->SetSelection(0);
×
768

769
    for(unsigned percent = roundGuiScale(range.minPercent); percent <= range.maxPercent; percent += stepSize)
×
770
    {
771
        if(percent == recommendedPercentRounded)
×
772
            recommendedGuiScaleIndex_ = guiScales_.size();
×
773
        guiScales_.push_back(percent);
×
774

775
        combo->AddString(helpers::toString(percent) + "%");
×
776
        if(percent == SETTINGS.video.guiScale)
×
777
            combo->SetSelection(combo->GetNumItems() - 1);
×
778
    }
779

780
    // if GUI scale exceeds maximum, lower it to keep UI elements on screen
781
    if(SETTINGS.video.guiScale > guiScales_.back())
×
782
    {
783
        combo->SetSelection(combo->GetNumItems() - 1);
×
784
        SETTINGS.video.guiScale = guiScales_.back();
×
785
        VIDEODRIVER.setGuiScalePercent(SETTINGS.video.guiScale);
×
786
    }
787
}
×
788

789
void dskOptions::scrollGuiScale(bool up)
×
790
{
791
    auto* combo = GetCtrl<ctrlGroup>(ID_grpGraphics)->GetCtrl<ctrlComboBox>(ID_cbGuiScale);
×
792
    const auto& selection = combo->GetSelection();
×
793
    unsigned newSelection = 0;
×
794
    if(!selection || *selection == 0) // No selection or "Auto" item selected
×
795
        newSelection = recommendedGuiScaleIndex_;
×
796
    else
797
        newSelection = std::clamp<unsigned>(*selection + (up ? 1 : -1), 1, combo->GetNumItems() - 1);
×
798

799
    if(newSelection != selection)
×
800
    {
801
        combo->SetSelection(newSelection);
×
802
        SETTINGS.video.guiScale = guiScales_[newSelection];
×
803
        VIDEODRIVER.setGuiScalePercent(SETTINGS.video.guiScale);
×
804
    }
805
}
×
806

807
void dskOptions::updatePortraitControls()
×
808
{
809
    const auto& newPortrait = Portraits[SETTINGS.lobby.portraitIndex];
×
810
    auto* groupCommon = GetCtrl<ctrlGroup>(ID_grpCommon);
×
811

812
    auto* portraitButton = groupCommon->GetCtrl<ctrlImageButton>(ID_btCommonPortrait);
×
813
    auto* newPortraitTexture = LOADER.GetTextureN(newPortrait.resourceId, newPortrait.resourceIndex);
×
814
    portraitButton->SetImage(newPortraitTexture);
×
815

816
    auto* portraitCombo = groupCommon->GetCtrl<ctrlComboBox>(ID_cbCommonPortrait);
×
817
    portraitCombo->SetSelection(SETTINGS.lobby.portraitIndex);
×
818
}
×
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