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

Return-To-The-Roots / s25client / 15712104444

17 Jun 2025 03:52PM UTC coverage: 50.437% (-0.01%) from 50.448%
15712104444

push

github

web-flow
Merge pull request #1780 from tehKaiN/clean-up-settings-desktop

Replace magic numbers with constants, unify spacing

0 of 124 new or added lines in 1 file covered. (0.0%)

15 existing lines in 3 files now uncovered.

22502 of 44614 relevant lines covered (50.44%)

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

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

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

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

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

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

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

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

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

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

162
    // Common
163
    // {
164

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

NEW
272
    groupCommon->AddText(ID_txtInvertScroll, curPos, _("Invert Mouse Pan:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
NEW
273
    ctrlOptionGroup* invertScroll = groupCommon->AddOptionGroup(ID_grpInvertScroll, GroupSelectType::Check);
×
UNCOV
274
    invertScroll->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"), NormalFont,
×
275
                                _("Map moves in the opposite direction the mouse is moved when scrolling/panning."));
276
    invertScroll->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont,
×
277
                                _("Map moves in the same direction the mouse is moved when scrolling/panning."));
278
    invertScroll->SetSelection(SETTINGS.interface.invertMouse);
×
NEW
279
    curPos.y += rowHeight;
×
280

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

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

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

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

NEW
307
    mainGroup->SetSelection(SETTINGS.global.showGFInfo);
×
308

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

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

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

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

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

335
    const auto video_drivers = drivers::DriverWrapper::LoadDriverList(drivers::DriverType::Video);
×
336

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

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

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

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

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

362
    groupSound->AddText(ID_txtMusic, curPos, _("Music"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
NEW
363
    mainGroup = groupSound->AddOptionGroup(ID_grpMusic, GroupSelectType::Check);
×
NEW
364
    mainGroup->AddTextButton(ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _("On"), NormalFont);
×
NEW
365
    mainGroup->AddTextButton(ID_btOff, curPos + bt2Offset, ctrlSizeSmall, TextureColor::Grey, _("Off"), NormalFont);
×
366

367
    ctrlProgress* Mvolume =
368
      groupSound->AddProgress(ID_pgMusicVol, curPos + volOffset, ctrlSize, TextureColor::Grey, 139, 138, 100);
×
369
    Mvolume->SetPosition((SETTINGS.sound.musicVolume * 100) / 255); //-V807
×
NEW
370
    curPos.y += rowHeight + sectionSpacing;
×
371

UNCOV
372
    groupSound->AddText(ID_txtEffects, curPos, _("Effects"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
NEW
373
    mainGroup = groupSound->AddOptionGroup(ID_grpEffects, GroupSelectType::Check);
×
NEW
374
    mainGroup->AddTextButton(ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _("On"), NormalFont);
×
NEW
375
    mainGroup->AddTextButton(ID_btOff, curPos + bt2Offset, ctrlSizeSmall, TextureColor::Grey, _("Off"), NormalFont);
×
376

377
    ctrlProgress* FXvolume =
378
      groupSound->AddProgress(ID_pgEffectsVol, curPos + volOffset, ctrlSize, TextureColor::Grey, 139, 138, 100);
×
379
    FXvolume->SetPosition((SETTINGS.sound.effectsVolume * 100) / 255);
×
NEW
380
    curPos.y += rowHeight + sectionSpacing;
×
381

382
    groupSound->AddTextButton(ID_btMusicPlayer, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("Music player"),
×
383
                              NormalFont);
×
NEW
384
    curPos.y += rowHeight + sectionSpacing;
×
385

386
    groupSound->AddText(ID_txtAudioDriver, curPos, _("Sounddriver"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
387
    combo = groupSound->AddComboBox(ID_cbAudioDriver, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey,
×
388
                                    NormalFont, 100);
×
389

390
    const auto audio_drivers = drivers::DriverWrapper::LoadDriverList(drivers::DriverType::Audio);
×
391

392
    for(const auto& audio_driver : audio_drivers)
×
393
    {
394
        combo->AddString(audio_driver.GetName());
×
395
        if(audio_driver.GetName() == SETTINGS.driver.audio)
×
396
            combo->SetSelection(combo->GetNumItems() - 1);
×
397
    }
398

399
    // "Allgemein" auswählen
NEW
400
    mainGroup = GetCtrl<ctrlOptionGroup>(ID_grpOptions);
×
NEW
401
    mainGroup->SetSelection(ID_btCommon, true);
×
402

403
    // Graphics
404
    // {
405

406
    loadVideoModes();
×
407

408
    // Und zu der Combobox hinzufügen
NEW
409
    ctrlComboBox& cbVideoModes = *groupGraphics->GetCtrl<ctrlComboBox>(ID_cbResolution);
×
410
    for(const auto& videoMode : video_modes)
×
411
    {
412
        VideoMode ratio = getAspectRatio(videoMode);
×
413
        s25util::ClassicImbuedStream<std::ostringstream> str;
×
414
        str << videoMode.width << "x" << videoMode.height;
×
415
        // Make the length always the same as 'iiiixiiii' to align the ratio
416
        int len = str.str().length();
×
417
        for(int i = len; i < 4 + 1 + 4; i++)
×
418
            str << " ";
×
419
        str << " (" << ratio.width << ":" << ratio.height << ")";
×
420

421
        cbVideoModes.AddString(str.str());
×
422

423
        // Ist das die aktuelle Auflösung? Dann selektieren
424
        if(videoMode == SETTINGS.video.fullscreenSize) //-V807
×
425
            cbVideoModes.SetSelection(cbVideoModes.GetNumItems() - 1);
×
426
    }
427

428
    // "Vollbild" setzen
NEW
429
    groupGraphics->GetCtrl<ctrlOptionGroup>(ID_grpFullscreen)->SetSelection(SETTINGS.video.fullscreen); //-V807
×
430

431
    // "Limit Framerate" füllen
NEW
432
    auto* cbFrameRate = groupGraphics->GetCtrl<ctrlComboBox>(ID_cbFramerate);
×
433
    if(VIDEODRIVER.HasVSync())
×
434
        cbFrameRate->AddString(_("Dynamic (Limits to display refresh rate, works with most drivers)"));
×
435
    for(int framerate : Settings::SCREEN_REFRESH_RATES)
×
436
    {
437
        if(framerate == -1)
×
438
            cbFrameRate->AddString(_("Disabled"));
×
439
        else
440
            cbFrameRate->AddString(helpers::toString(framerate) + " FPS");
×
441
        if(SETTINGS.video.framerate == framerate)
×
442
            cbFrameRate->SetSelection(cbFrameRate->GetNumItems() - 1);
×
443
    }
444
    if(!cbFrameRate->GetSelection())
×
445
        cbFrameRate->SetSelection(0);
×
446

NEW
447
    groupGraphics->GetCtrl<ctrlOptionGroup>(ID_grpVBO)->SetSelection(SETTINGS.video.vbo);
×
448

NEW
449
    groupGraphics->GetCtrl<ctrlOptionGroup>(ID_grpOptTextures)->SetSelection(SETTINGS.video.shared_textures);
×
450
    // }
451

452
    // Sound
453
    // {
454

455
    groupSound->GetCtrl<ctrlOptionGroup>(ID_grpMusic)->SetSelection(SETTINGS.sound.musicEnabled);
×
456
    groupSound->GetCtrl<ctrlOptionGroup>(ID_grpEffects)->SetSelection(SETTINGS.sound.effectsEnabled);
×
457

458
    // }
459

460
    // Load game settings
461
    ggs.LoadSettings();
×
462
}
×
463

464
dskOptions::~dskOptions()
×
465
{
466
    // Save game settings
467
    ggs.SaveSettings();
×
468
}
×
469

470
void dskOptions::Msg_Group_ProgressChange(const unsigned /*group_id*/, const unsigned ctrl_id,
×
471
                                          const unsigned short position)
472
{
473
    switch(ctrl_id)
×
474
    {
475
        case ID_pgEffectsVol:
×
476
            SETTINGS.sound.effectsVolume = static_cast<uint8_t>((position * 255) / 100);
×
477
            AUDIODRIVER.SetMasterEffectVolume(SETTINGS.sound.effectsVolume);
×
478
            break;
×
479
        case ID_pgMusicVol:
×
480
            SETTINGS.sound.musicVolume = static_cast<uint8_t>((position * 255) / 100);
×
481
            AUDIODRIVER.SetMusicVolume(SETTINGS.sound.musicVolume);
×
482
            break;
×
483
    }
484
}
×
485

486
void dskOptions::Msg_Group_ComboSelectItem(const unsigned group_id, const unsigned ctrl_id, const unsigned selection)
×
487
{
488
    auto* group = GetCtrl<ctrlGroup>(group_id);
×
489
    auto* combo = group->GetCtrl<ctrlComboBox>(ctrl_id);
×
490

491
    switch(ctrl_id)
×
492
    {
493
        case ID_cbCommonPortrait:
×
494
            SETTINGS.lobby.portraitIndex = selection;
×
495
            updatePortraitControls();
×
496
            break;
×
497
        case ID_cbLanguage:
×
498
        {
499
            // Language changed?
500
            std::string old_lang = SETTINGS.language.language; //-V807
×
501
            SETTINGS.language.language = LANGUAGES.setLanguage(selection);
×
502
            if(SETTINGS.language.language != old_lang)
×
503
                WINDOWMANAGER.Switch(std::make_unique<dskOptions>());
×
504
        }
505
        break;
×
506
        case ID_cbProxyType:
×
507
            switch(selection)
508
            {
509
                case 0: SETTINGS.proxy.type = ProxyType::None; break;
×
510
                case 1: SETTINGS.proxy.type = ProxyType::Socks4; break;
×
511
                case 2: SETTINGS.proxy.type = ProxyType::Socks5; break;
×
512
            }
513

514
            // ipv6 gleich sichtbar deaktivieren
515
            if(SETTINGS.proxy.type == ProxyType::Socks4 && SETTINGS.server.ipv6)
×
516
            {
NEW
517
                GetCtrl<ctrlGroup>(ID_grpCommon)->GetCtrl<ctrlOptionGroup>(ID_grpIpv6)->SetSelection(0);
×
NEW
518
                GetCtrl<ctrlGroup>(ID_grpCommon)
×
UNCOV
519
                  ->GetCtrl<ctrlOptionGroup>(ID_grpIpv6)
×
520
                  ->GetCtrl<ctrlButton>(1)
521
                  ->SetEnabled(false);
×
522
                SETTINGS.server.ipv6 = false;
×
523
            }
524

525
            if(SETTINGS.proxy.type != ProxyType::Socks4)
×
NEW
526
                GetCtrl<ctrlGroup>(ID_grpCommon)
×
527
                  ->GetCtrl<ctrlOptionGroup>(ID_grpIpv6)
×
528
                  ->GetCtrl<ctrlButton>(1)
529
                  ->SetEnabled(true);
×
530
            break;
×
531
        case ID_cbResolution: SETTINGS.video.fullscreenSize = video_modes[selection]; break;
×
532
        case ID_cbFramerate:
×
533
            if(VIDEODRIVER.HasVSync())
×
534
            {
535
                if(selection == 0)
×
536
                    SETTINGS.video.framerate = 0;
×
537
                else
538
                    SETTINGS.video.framerate = Settings::SCREEN_REFRESH_RATES[selection - 1];
×
539
            } else
540
                SETTINGS.video.framerate = Settings::SCREEN_REFRESH_RATES[selection];
×
541

542
            VIDEODRIVER.setTargetFramerate(SETTINGS.video.framerate);
×
543
            break;
×
544
        case ID_cbVideoDriver: SETTINGS.driver.video = combo->GetText(selection); break;
×
545
        case ID_cbGuiScale:
×
546
            SETTINGS.video.guiScale = guiScales_[selection];
×
547
            VIDEODRIVER.setGuiScalePercent(SETTINGS.video.guiScale);
×
548
            break;
×
549
        case ID_cbAudioDriver: SETTINGS.driver.audio = combo->GetText(selection); break;
×
550
    }
551
}
×
552

553
void dskOptions::Msg_Group_OptionGroupChange(const unsigned /*group_id*/, const unsigned ctrl_id,
×
554
                                             const unsigned selection)
555
{
556
    const bool enabled = selection == ID_btOn;
×
557
    switch(ctrl_id)
×
558
    {
559
        case ID_grpIpv6: SETTINGS.server.ipv6 = enabled; break;
×
560
        case ID_grpFullscreen: SETTINGS.video.fullscreen = enabled; break;
×
561
        case ID_grpVBO: SETTINGS.video.vbo = enabled; break;
×
562
        case ID_grpOptTextures: SETTINGS.video.shared_textures = enabled; break;
×
563
        case ID_grpMusic:
×
564
            SETTINGS.sound.musicEnabled = enabled;
×
565
            if(enabled)
×
566
                MUSICPLAYER.Play();
×
567
            else
568
                MUSICPLAYER.Stop();
×
569
            break;
×
570
        case ID_grpEffects: SETTINGS.sound.effectsEnabled = enabled; break;
×
571
        case ID_grpDebugData:
×
572
            // Special case: Uses e.g. ID_btSubmitDebugOn directly
573
            SETTINGS.global.submit_debug_data = selection;
×
574
            break;
×
575
        case ID_grpUPNP: SETTINGS.global.use_upnp = enabled; break;
×
576
        case ID_grpInvertScroll: SETTINGS.interface.invertMouse = enabled; break;
×
577
        case ID_grpSmartCursor:
×
578
            SETTINGS.global.smartCursor = enabled;
×
579
            VIDEODRIVER.SetMouseWarping(enabled);
×
580
            break;
×
581
        case ID_grpGFInfo: SETTINGS.global.showGFInfo = enabled; break;
×
582
    }
583
}
×
584

585
void dskOptions::Msg_OptionGroupChange(const unsigned ctrl_id, const unsigned selection)
×
586
{
587
    if(ctrl_id == ID_grpOptions)
×
588
    {
NEW
589
        const auto visGrp = selection + ID_grpCommon - ID_btCommon;
×
NEW
590
        for(const unsigned id : {ID_grpCommon, ID_grpGraphics, ID_grpSound})
×
UNCOV
591
            GetCtrl<ctrlGroup>(id)->SetVisible(id == visGrp);
×
592
    }
593
}
×
594

595
/// Check that the port is valid and sets outPort to it. Shows an error otherwise
596
static bool validatePort(const std::string& sPort, uint16_t& outPort)
×
597
{
598
    boost::optional<uint16_t> port = validate::checkPort(sPort);
×
599
    if(port)
×
600
        outPort = *port;
×
601
    else
602
    {
603
        WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(_("Error"),
×
604
                                                      _("Invalid port. The valid port-range is 1 to 65535!"), nullptr,
×
605
                                                      MsgboxButton::Ok, MsgboxIcon::ExclamationRed, 1));
×
606
    }
607
    return static_cast<bool>(port);
×
608
}
609

610
void dskOptions::Msg_ButtonClick(const unsigned ctrl_id)
×
611
{
612
    switch(ctrl_id)
×
613
    {
614
        case ID_btBack:
×
615
        {
NEW
616
            auto* groupCommon = GetCtrl<ctrlGroup>(ID_grpCommon);
×
617

618
            // Name abspeichern
NEW
619
            SETTINGS.lobby.name = groupCommon->GetCtrl<ctrlEdit>(ID_edtName)->GetText();
×
NEW
620
            if(!validatePort(groupCommon->GetCtrl<ctrlEdit>(ID_edtPort)->GetText(), SETTINGS.server.localPort))
×
UNCOV
621
                return;
×
622

NEW
623
            SETTINGS.proxy.hostname = groupCommon->GetCtrl<ctrlEdit>(ID_edtProxy)->GetText();
×
NEW
624
            if(!validatePort(groupCommon->GetCtrl<ctrlEdit>(ID_edtProxyPort)->GetText(), SETTINGS.proxy.port))
×
UNCOV
625
                return;
×
626

627
            SETTINGS.Save();
×
628

629
            // Is the selected backend required to support GUI scaling to fullfill the user's choice?
630
            // If so, warn the user if the backend is unable to support GUI scaling.
631
            if(VIDEODRIVER.getGuiScale().percent() == 100
×
632
               && (SETTINGS.video.guiScale != 100
×
633
                   || (SETTINGS.video.guiScale == 0 && VIDEODRIVER.getGuiScaleRange().recommendedPercent != 100)))
×
634
            {
635
                WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(
×
636
                  _("Sorry!"), _("The selected video driver does not support GUI scaling! Setting won't be used."),
×
637
                  this, MsgboxButton::Ok, MsgboxIcon::ExclamationGreen, 1));
×
638
            }
639

640
            if((SETTINGS.video.fullscreen && SETTINGS.video.fullscreenSize != VIDEODRIVER.GetWindowSize()) //-V807
×
641
               || SETTINGS.video.fullscreen != VIDEODRIVER.IsFullscreen())
×
642
            {
643
                const auto screenSize =
644
                  SETTINGS.video.fullscreen ? SETTINGS.video.fullscreenSize : SETTINGS.video.windowedSize;
×
645
                if(!VIDEODRIVER.ResizeScreen(screenSize, SETTINGS.video.fullscreen))
×
646
                {
647
                    WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(
×
648
                      _("Sorry!"), _("You need to restart your game to change the screen resolution!"), this,
×
649
                      MsgboxButton::Ok, MsgboxIcon::ExclamationGreen, 1));
×
650
                    return;
×
651
                }
652
            }
653
            if(SETTINGS.driver.video != VIDEODRIVER.GetName() || SETTINGS.driver.audio != AUDIODRIVER.GetName())
×
654
            {
655
                WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(
×
656
                  _("Sorry!"), _("You need to restart your game to change the video or audio driver!"), this,
×
657
                  MsgboxButton::Ok, MsgboxIcon::ExclamationGreen, 1));
×
658
                return;
×
659
            }
660

661
            WINDOWMANAGER.Switch(std::make_unique<dskMainMenu>());
×
662
        }
663
        break;
×
664
        case ID_btAddons: WINDOWMANAGER.ToggleWindow(std::make_unique<iwAddons>(ggs)); break;
×
665
    }
666
}
667

668
void dskOptions::Msg_Group_ButtonClick(const unsigned /*group_id*/, const unsigned ctrl_id)
×
669
{
670
    switch(ctrl_id)
×
671
    {
672
        default: break;
×
673
        case ID_btCommonPortrait:
×
674
            SETTINGS.lobby.portraitIndex = (SETTINGS.lobby.portraitIndex + 1) % Portraits.size();
×
675
            updatePortraitControls();
×
676
            break;
×
677
        case ID_btMusicPlayer: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMusicPlayer>()); break;
×
678
        case ID_btKeyboardLayout:
×
679
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("keyboardlayout.txt", _("Keyboard layout")));
×
680
            break;
×
681
    }
682
}
×
683

684
void dskOptions::Msg_MsgBoxResult(const unsigned msgbox_id, const MsgboxResult /*mbr*/)
×
685
{
686
    switch(msgbox_id)
×
687
    {
688
        default: break;
×
689
        // "You need to restart your game ..."
690
        // "The selected video driver does not support GUI scaling!"
691
        case 1: WINDOWMANAGER.Switch(std::make_unique<dskMainMenu>()); break;
×
692
    }
693
}
×
694

695
static bool cmpVideoModes(const VideoMode& left, const VideoMode& right)
×
696
{
697
    if(left.width == right.width)
×
698
        return left.height > right.height;
×
699
    else
700
        return left.width > right.width;
×
701
}
702

703
void dskOptions::loadVideoModes()
×
704
{
705
    // Get available modes
706
    VIDEODRIVER.ListVideoModes(video_modes);
×
707
    // Remove everything below 800x600
708
    helpers::erase_if(video_modes, [](const auto& it) { return it.width < 800 && it.height < 600; });
×
709
    // Sort by aspect ratio
710
    std::sort(video_modes.begin(), video_modes.end(), cmpVideoModes);
×
711
}
×
712

713
void dskOptions::Msg_ScreenResize(const ScreenResizeEvent& sr)
×
714
{
715
    Desktop::Msg_ScreenResize(sr);
×
716
    updateGuiScale();
×
717
}
×
718

719
bool dskOptions::Msg_WheelUp(const MouseCoords& mc)
×
720
{
721
    if(VIDEODRIVER.GetModKeyState().ctrl)
×
722
    {
723
        scrollGuiScale(true);
×
724
        return true;
×
725
    } else
726
        return Desktop::Msg_WheelUp(mc);
×
727
}
728

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

739
void dskOptions::updateGuiScale()
×
740
{
741
    // generate GUI scale percentages in 10% increments
742
    constexpr auto stepSize = 10u;
×
743
    const auto roundGuiScale = [=](unsigned percent) {
×
744
        return helpers::iround<unsigned>(static_cast<float>(percent) / stepSize) * stepSize;
×
745
    };
746

747
    const auto range = VIDEODRIVER.getGuiScaleRange();
×
748
    const auto recommendedPercentRounded = roundGuiScale(range.recommendedPercent);
×
749
    auto* combo = GetCtrl<ctrlGroup>(ID_grpGraphics)->GetCtrl<ctrlComboBox>(ID_cbGuiScale);
×
750

751
    guiScales_.clear();
×
752
    combo->DeleteAllItems();
×
753

754
    guiScales_.push_back(0);
×
755
    combo->AddString(helpers::format(_("Auto (%u%%)"), range.recommendedPercent));
×
756
    if(SETTINGS.video.guiScale == 0)
×
757
        combo->SetSelection(0);
×
758

759
    for(unsigned percent = roundGuiScale(range.minPercent); percent <= range.maxPercent; percent += stepSize)
×
760
    {
761
        if(percent == recommendedPercentRounded)
×
762
            recommendedGuiScaleIndex_ = guiScales_.size();
×
763
        guiScales_.push_back(percent);
×
764

765
        combo->AddString(helpers::toString(percent) + "%");
×
766
        if(percent == SETTINGS.video.guiScale)
×
767
            combo->SetSelection(combo->GetNumItems() - 1);
×
768
    }
769

770
    // if GUI scale exceeds maximum, lower it to keep UI elements on screen
771
    if(SETTINGS.video.guiScale > guiScales_.back())
×
772
    {
773
        combo->SetSelection(combo->GetNumItems() - 1);
×
774
        SETTINGS.video.guiScale = guiScales_.back();
×
775
        VIDEODRIVER.setGuiScalePercent(SETTINGS.video.guiScale);
×
776
    }
777
}
×
778

779
void dskOptions::scrollGuiScale(bool up)
×
780
{
781
    auto* combo = GetCtrl<ctrlGroup>(ID_grpGraphics)->GetCtrl<ctrlComboBox>(ID_cbGuiScale);
×
782
    const auto& selection = combo->GetSelection();
×
783
    unsigned newSelection = 0;
×
784
    if(!selection || *selection == 0) // No selection or "Auto" item selected
×
785
        newSelection = recommendedGuiScaleIndex_;
×
786
    else
787
        newSelection = std::clamp<unsigned>(*selection + (up ? 1 : -1), 1, combo->GetNumItems() - 1);
×
788

789
    if(newSelection != selection)
×
790
    {
791
        combo->SetSelection(newSelection);
×
792
        SETTINGS.video.guiScale = guiScales_[newSelection];
×
793
        VIDEODRIVER.setGuiScalePercent(SETTINGS.video.guiScale);
×
794
    }
795
}
×
796

797
void dskOptions::updatePortraitControls()
×
798
{
799
    const auto& newPortrait = Portraits[SETTINGS.lobby.portraitIndex];
×
NEW
800
    auto* groupCommon = GetCtrl<ctrlGroup>(ID_grpCommon);
×
801

802
    auto* portraitButton = groupCommon->GetCtrl<ctrlImageButton>(ID_btCommonPortrait);
×
803
    auto* newPortraitTexture = LOADER.GetTextureN(newPortrait.resourceId, newPortrait.resourceIndex);
×
804
    portraitButton->SetImage(newPortraitTexture);
×
805

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