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

Return-To-The-Roots / s25client / 24136492334

08 Apr 2026 12:56PM UTC coverage: 50.369%. First build
24136492334

Pull #1899

github

web-flow
Merge 52de5617b into e4146df45
Pull Request #1899: GUI: limit the scaling of ctrlTextButtons

82 of 91 new or added lines in 14 files covered. (90.11%)

23088 of 45838 relevant lines covered (50.37%)

42497.93 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
using Offset = DrawPoint;
39

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

115
constexpr auto rowHeight = 30;
116
constexpr auto sectionSpacing = 20;
117
constexpr auto sectionSpacingCommon = 10;
118
constexpr auto optionRowsStartPosition = DrawPoint(80, 75);
119
constexpr auto tabButtonsStartPosition = optionRowsStartPosition + Offset(0, static_cast<int>(rowHeight * 15.5));
120

121
constexpr Offset ctrlOffset(200, -5);                       // Offset of control to its description text
122
constexpr Offset ctrlOffset2 = ctrlOffset + Offset(200, 0); // Offset of 2nd control to its description text
123
constexpr Extent ctrlSize(190, 22);
124
constexpr Extent ctrlSizeLarge = ctrlSize + Extent(ctrlOffset2 - ctrlOffset);
125
} // namespace
126

127
static VideoMode getAspectRatio(const VideoMode& vm)
×
128
{
129
    // First some a bit off values where the aspect ratio is defined by convention
130
    if(vm == VideoMode(1360, 1024))
×
131
        return VideoMode(4, 3);
×
132
    else if(vm == VideoMode(1360, 768) || vm == VideoMode(1366, 768))
×
133
        return VideoMode(16, 9);
×
134

135
    // Normally Aspect ration is simply width/height as integer numbers (e.g. 4:3)
136
    int divisor = helpers::gcd(vm.width, vm.height);
×
137
    VideoMode ratio(vm.width / divisor, vm.height / divisor);
×
138
    // But there are some special cases:
139
    if(ratio == VideoMode(8, 5))
×
140
        return VideoMode(16, 10);
×
141
    else if(ratio == VideoMode(5, 3))
×
142
        return VideoMode(15, 9);
×
143
    else
144
        return ratio;
×
145
}
146

147
dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
×
148
{
NEW
149
    SetLimit(false);
×
150
    AddText(ID_txtOptions, DrawPoint(400, 10), _("Options"), COLOR_YELLOW, FontStyle::CENTER, LargeFont);
×
151

152
    ctrlOptionGroup* mainGroup = AddOptionGroup(ID_grpOptions, GroupSelectType::Check);
×
153

154
    DrawPoint curPos = tabButtonsStartPosition;
×
155
    mainGroup->AddTextButton(ID_btCommon, DrawPoint(curPos.x, curPos.y), Extent(200, 22), TextureColor::Green2,
×
156
                             _("Common"), NormalFont);
×
157
    mainGroup->AddTextButton(ID_btGraphics, DrawPoint(curPos.x + 220, curPos.y), Extent(200, 22), TextureColor::Green2,
×
158
                             _("Graphics"), NormalFont);
×
159
    mainGroup->AddTextButton(ID_btSound, DrawPoint(curPos.x + 440, curPos.y), Extent(200, 22), TextureColor::Green2,
×
160
                             _("Sound/Music"), NormalFont);
×
161
    curPos.y += rowHeight;
×
162

163
    AddTextButton(ID_btBack, DrawPoint(curPos.x + 220, curPos.y), Extent(200, 22), TextureColor::Red1, _("Back"),
×
164
                  NormalFont);
×
165
    AddTextButton(ID_btAddons, DrawPoint(curPos.x + 440, curPos.y), Extent(200, 22), TextureColor::Green2, _("Addons"),
×
166
                  NormalFont);
×
167

168
    ctrlGroup* groupCommon = AddGroup(ID_grpCommon);
×
169
    ctrlGroup* groupGraphics = AddGroup(ID_grpGraphics);
×
170
    ctrlGroup* groupSound = AddGroup(ID_grpSound);
×
171
    ctrlComboBox* combo;
172

173
    // Common
174
    // {
175

176
    curPos = optionRowsStartPosition;
×
177

178
    groupCommon->AddText(ID_txtName, curPos, _("Name in Game:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
179
    ctrlEdit* name =
180
      groupCommon->AddEdit(ID_edtName, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 15);
×
181
    name->SetText(SETTINGS.lobby.name);
×
182

183
    const auto& currentPortrait = Portraits[SETTINGS.lobby.portraitIndex];
×
184
    groupCommon->AddImageButton(ID_btCommonPortrait, DrawPoint(500, curPos.y + ctrlOffset.y), Extent(40, rowHeight * 2),
×
185
                                TextureColor::Grey,
186
                                LOADER.GetImageN(currentPortrait.resourceId, currentPortrait.resourceIndex));
×
187
    curPos.y += rowHeight;
×
188

189
    groupCommon->AddText(ID_txtCommonPortrait, curPos, _("Portrait:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
190
    combo =
191
      groupCommon->AddComboBox(ID_cbCommonPortrait, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 100);
×
192

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

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

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

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

220
    groupCommon->AddTextButton(ID_btKeyboardLayout, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey,
×
221
                               _("Keyboard layout"), NormalFont);
×
222
    curPos.y += rowHeight;
×
223

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

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

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

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

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

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

270
    switch(SETTINGS.proxy.type)
×
271
    {
272
        default: combo->SetSelection(0); break;
×
273
        case ProxyType::Socks4: combo->SetSelection(1); break;
×
274
        case ProxyType::Socks5: combo->SetSelection(2); break;
×
275
    }
276
    curPos.y += rowHeight;
×
277

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

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

299
    groupCommon->AddText(ID_txtWindowPinning, curPos, _("Window pinning"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
300
    ctrlOptionGroup* windowPinning = groupCommon->AddOptionGroup(ID_grpWindowPinning, GroupSelectType::Check);
×
301
    windowPinning->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"), NormalFont,
×
302
                                 _("Replace minimize button on windows by pin button avoiding closing the window with "
303
                                   "ESC.\nMinimize by double-clicking the title bar."));
304
    windowPinning->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont);
×
305
    windowPinning->SetSelection(SETTINGS.interface.enableWindowPinning);
×
306
    curPos.y += rowHeight;
×
307

308
    curPos.y += sectionSpacingCommon;
×
309
    groupCommon->AddText(ID_txtDebugData, curPos, _("Submit debug data:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
310
    mainGroup = groupCommon->AddOptionGroup(ID_grpDebugData, GroupSelectType::Check);
×
311
    mainGroup->AddTextButton(ID_btSubmitDebugOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"),
×
312
                             NormalFont);
×
313
    mainGroup->AddTextButton(ID_btSubmitDebugAsk, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Ask always"),
×
314
                             NormalFont);
×
315

316
    mainGroup->SetSelection((SETTINGS.global.submit_debug_data == 1) ? ID_btSubmitDebugOn :
×
317
                                                                       ID_btSubmitDebugAsk); //-V807
318
    curPos.y += rowHeight;
×
319

320
    groupCommon->AddText(ID_txtGFInfo, curPos, _("Show GameFrame Info:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
321
    mainGroup = groupCommon->AddOptionGroup(ID_grpGFInfo, GroupSelectType::Check);
×
322
    mainGroup->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"), NormalFont);
×
323
    mainGroup->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont);
×
324

325
    mainGroup->SetSelection(SETTINGS.global.showGFInfo);
×
326

327
    curPos = optionRowsStartPosition;
×
328
    groupGraphics->AddText(ID_txtResolution, curPos, _("Fullscreen resolution:"), COLOR_YELLOW, FontStyle{},
×
329
                           NormalFont);
×
330
    groupGraphics->AddComboBox(ID_cbResolution, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 150);
×
331
    curPos.y += rowHeight;
×
332

333
    curPos.y += sectionSpacing;
×
334
    groupGraphics->AddText(ID_txtFullscreen, curPos, _("Mode:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
335
    mainGroup = groupGraphics->AddOptionGroup(ID_grpFullscreen, GroupSelectType::Check);
×
336
    mainGroup->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("Fullscreen"), NormalFont);
×
337
    mainGroup->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Windowed"), NormalFont);
×
338
    curPos.y += rowHeight;
×
339

340
    curPos.y += sectionSpacing;
×
341
    groupGraphics->AddText(ID_txtFramerate, curPos, _("Limit Framerate:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
342
    groupGraphics->AddComboBox(ID_cbFramerate, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey, NormalFont, 150);
×
343
    curPos.y += rowHeight;
×
344

345
    curPos.y += sectionSpacing;
×
346
    groupGraphics->AddText(ID_txtVBO, curPos, _("Vertex Buffer Objects:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
347
    mainGroup = groupGraphics->AddOptionGroup(ID_grpVBO, GroupSelectType::Check);
×
348
    mainGroup->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"), NormalFont);
×
349
    mainGroup->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont);
×
350
    curPos.y += rowHeight;
×
351

352
    curPos.y += sectionSpacing;
×
353
    groupGraphics->AddText(ID_txtVideoDriver, curPos, _("Graphics Driver"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
354
    combo = groupGraphics->AddComboBox(ID_cbVideoDriver, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey,
×
355
                                       NormalFont, 100);
×
356

357
    const auto video_drivers = drivers::DriverWrapper::LoadDriverList(drivers::DriverType::Video);
×
358

359
    for(const auto& video_driver : video_drivers)
×
360
    {
361
        combo->AddString(video_driver.GetName());
×
362
        if(video_driver.GetName() == SETTINGS.driver.video)
×
363
            combo->SetSelection(combo->GetNumItems() - 1);
×
364
    }
365
    curPos.y += rowHeight;
×
366

367
    curPos.y += sectionSpacing;
×
368
    groupGraphics->AddText(ID_txtOptTextures, curPos, _("Optimized Textures:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
369
    mainGroup = groupGraphics->AddOptionGroup(ID_grpOptTextures, GroupSelectType::Check);
×
370

371
    mainGroup->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"), NormalFont);
×
372
    mainGroup->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont);
×
373
    curPos.y += rowHeight;
×
374

375
    curPos.y += sectionSpacing;
×
376
    groupGraphics->AddText(ID_txtGuiScale, curPos, _("GUI Scale:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
377
    groupGraphics->AddComboBox(ID_cbGuiScale, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 100);
×
378
    updateGuiScale();
×
379

380
    curPos = optionRowsStartPosition;
×
381
    constexpr Offset bt1Offset(200, -5);
×
382
    constexpr Offset bt2Offset(300, -5);
×
383
    constexpr Offset volOffset(400, -5);
×
384
    constexpr Extent ctrlSizeSmall(90, ctrlSize.y);
×
385

386
    groupSound->AddText(ID_txtEffects, curPos, _("Effects"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
387
    mainGroup = groupSound->AddOptionGroup(ID_grpEffects, GroupSelectType::Check);
×
388
    mainGroup->AddTextButton(ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _("On"), NormalFont);
×
389
    mainGroup->AddTextButton(ID_btOff, curPos + bt2Offset, ctrlSizeSmall, TextureColor::Grey, _("Off"), NormalFont);
×
390

391
    ctrlProgress* FXvolume =
392
      groupSound->AddProgress(ID_pgEffectsVol, curPos + volOffset, ctrlSize, TextureColor::Grey, 139, 138, 100);
×
393
    FXvolume->SetPosition((SETTINGS.sound.effectsVolume * 100) / 255);
×
394
    curPos.y += rowHeight;
×
395

396
    curPos.y += sectionSpacing;
×
397
    groupSound->AddText(ID_txtBirdSounds, curPos, _("Bird sounds"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
398
    mainGroup = groupSound->AddOptionGroup(ID_grpBirdSounds, GroupSelectType::Check);
×
399
    mainGroup->AddTextButton(ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _("On"), NormalFont);
×
400
    mainGroup->AddTextButton(ID_btOff, curPos + bt2Offset, ctrlSizeSmall, TextureColor::Grey, _("Off"), NormalFont);
×
401
    curPos.y += rowHeight;
×
402

403
    curPos.y += sectionSpacing;
×
404
    groupSound->AddText(ID_txtMusic, curPos, _("Music"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
405
    mainGroup = groupSound->AddOptionGroup(ID_grpMusic, GroupSelectType::Check);
×
406
    mainGroup->AddTextButton(ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _("On"), NormalFont);
×
407
    mainGroup->AddTextButton(ID_btOff, curPos + bt2Offset, ctrlSizeSmall, TextureColor::Grey, _("Off"), NormalFont);
×
408

409
    ctrlProgress* Mvolume =
410
      groupSound->AddProgress(ID_pgMusicVol, curPos + volOffset, ctrlSize, TextureColor::Grey, 139, 138, 100);
×
411
    Mvolume->SetPosition((SETTINGS.sound.musicVolume * 100) / 255); //-V807
×
412
    curPos.y += rowHeight;
×
413

414
    curPos.y += sectionSpacing;
×
415
    groupSound->AddTextButton(ID_btMusicPlayer, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("Music player"),
×
416
                              NormalFont);
×
417
    curPos.y += rowHeight;
×
418

419
    curPos.y += sectionSpacing;
×
420
    groupSound->AddText(ID_txtAudioDriver, curPos, _("Sounddriver"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
421
    combo = groupSound->AddComboBox(ID_cbAudioDriver, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey,
×
422
                                    NormalFont, 100);
×
423

424
    const auto audio_drivers = drivers::DriverWrapper::LoadDriverList(drivers::DriverType::Audio);
×
425

426
    for(const auto& audio_driver : audio_drivers)
×
427
    {
428
        combo->AddString(audio_driver.GetName());
×
429
        if(audio_driver.GetName() == SETTINGS.driver.audio)
×
430
            combo->SetSelection(combo->GetNumItems() - 1);
×
431
    }
432

433
    // Select "General"
434
    mainGroup = GetCtrl<ctrlOptionGroup>(ID_grpOptions);
×
435
    mainGroup->SetSelection(ID_btCommon, true);
×
436

437
    // Graphics
438
    // {
439

440
    loadVideoModes();
×
441

442
    // and add to the combo box
443
    ctrlComboBox& cbVideoModes = *groupGraphics->GetCtrl<ctrlComboBox>(ID_cbResolution);
×
444
    for(const auto& videoMode : video_modes)
×
445
    {
446
        VideoMode ratio = getAspectRatio(videoMode);
×
447
        s25util::ClassicImbuedStream<std::ostringstream> str;
×
448
        str << videoMode.width << "x" << videoMode.height;
×
449
        // Make the length always the same as 'iiiixiiii' to align the ratio
450
        int len = str.str().length();
×
451
        for(int i = len; i < 4 + 1 + 4; i++)
×
452
            str << " ";
×
453
        str << " (" << ratio.width << ":" << ratio.height << ")";
×
454

455
        cbVideoModes.AddString(str.str());
×
456

457
        // Select, if this is the current resolution
458
        if(videoMode == SETTINGS.video.fullscreenSize) //-V807
×
459
            cbVideoModes.SetSelection(cbVideoModes.GetNumItems() - 1);
×
460
    }
461

462
    // Set "Fullscreen"
463
    groupGraphics->GetCtrl<ctrlOptionGroup>(ID_grpFullscreen)->SetSelection(SETTINGS.video.fullscreen); //-V807
×
464

465
    // Fill "Limit Framerate"
466
    auto* cbFrameRate = groupGraphics->GetCtrl<ctrlComboBox>(ID_cbFramerate);
×
467
    if(VIDEODRIVER.HasVSync())
×
468
        cbFrameRate->AddString(_("Dynamic (Limits to display refresh rate, works with most drivers)"));
×
469
    for(int framerate : Settings::SCREEN_REFRESH_RATES)
×
470
    {
471
        if(framerate == -1)
×
472
            cbFrameRate->AddString(_("Disabled"));
×
473
        else
474
            cbFrameRate->AddString(helpers::toString(framerate) + " FPS");
×
475
        if(SETTINGS.video.framerate == framerate)
×
476
            cbFrameRate->SetSelection(cbFrameRate->GetNumItems() - 1);
×
477
    }
478
    if(!cbFrameRate->GetSelection())
×
479
        cbFrameRate->SetSelection(0);
×
480

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

483
    groupGraphics->GetCtrl<ctrlOptionGroup>(ID_grpOptTextures)->SetSelection(SETTINGS.video.shared_textures);
×
484
    // }
485

486
    // Sound
487
    // {
488

489
    groupSound->GetCtrl<ctrlOptionGroup>(ID_grpEffects)->SetSelection(SETTINGS.sound.effectsEnabled);
×
490
    groupSound->GetCtrl<ctrlOptionGroup>(ID_grpBirdSounds)->SetSelection(SETTINGS.sound.birdsEnabled);
×
491
    groupSound->GetCtrl<ctrlOptionGroup>(ID_grpMusic)->SetSelection(SETTINGS.sound.musicEnabled);
×
492

493
    // }
494

495
    // Load game settings
496
    ggs.LoadSettings();
×
497
}
×
498

499
dskOptions::~dskOptions()
×
500
{
501
    // Save game settings
502
    ggs.SaveSettings();
×
503
}
×
504

505
void dskOptions::Msg_Group_ProgressChange(const unsigned /*group_id*/, const unsigned ctrl_id,
×
506
                                          const unsigned short position)
507
{
508
    switch(ctrl_id)
×
509
    {
510
        case ID_pgEffectsVol:
×
511
            SETTINGS.sound.effectsVolume = static_cast<uint8_t>((position * 255) / 100);
×
512
            AUDIODRIVER.SetMasterEffectVolume(SETTINGS.sound.effectsVolume);
×
513
            break;
×
514
        case ID_pgMusicVol:
×
515
            SETTINGS.sound.musicVolume = static_cast<uint8_t>((position * 255) / 100);
×
516
            AUDIODRIVER.SetMusicVolume(SETTINGS.sound.musicVolume);
×
517
            break;
×
518
    }
519
}
×
520

521
void dskOptions::Msg_Group_ComboSelectItem(const unsigned group_id, const unsigned ctrl_id, const unsigned selection)
×
522
{
523
    auto* group = GetCtrl<ctrlGroup>(group_id);
×
524
    auto* combo = group->GetCtrl<ctrlComboBox>(ctrl_id);
×
525

526
    switch(ctrl_id)
×
527
    {
528
        case ID_cbCommonPortrait:
×
529
            SETTINGS.lobby.portraitIndex = selection;
×
530
            updatePortraitControls();
×
531
            break;
×
532
        case ID_cbLanguage:
×
533
        {
534
            // Language changed?
535
            std::string old_lang = SETTINGS.language.language; //-V807
×
536
            SETTINGS.language.language = LANGUAGES.setLanguage(selection);
×
537
            if(SETTINGS.language.language != old_lang)
×
538
                WINDOWMANAGER.Switch(std::make_unique<dskOptions>());
×
539
        }
540
        break;
×
541
        case ID_cbProxyType:
×
542
            switch(selection)
543
            {
544
                case 0: SETTINGS.proxy.type = ProxyType::None; break;
×
545
                case 1: SETTINGS.proxy.type = ProxyType::Socks4; break;
×
546
                case 2: SETTINGS.proxy.type = ProxyType::Socks5; break;
×
547
            }
548

549
            // Disable IPv6 visually
550
            if(SETTINGS.proxy.type == ProxyType::Socks4 && SETTINGS.server.ipv6)
×
551
            {
552
                GetCtrl<ctrlGroup>(ID_grpCommon)->GetCtrl<ctrlOptionGroup>(ID_grpIpv6)->SetSelection(0);
×
553
                GetCtrl<ctrlGroup>(ID_grpCommon)
×
554
                  ->GetCtrl<ctrlOptionGroup>(ID_grpIpv6)
×
555
                  ->GetCtrl<ctrlButton>(1)
556
                  ->SetEnabled(false);
×
557
                SETTINGS.server.ipv6 = false;
×
558
            }
559

560
            if(SETTINGS.proxy.type != ProxyType::Socks4)
×
561
                GetCtrl<ctrlGroup>(ID_grpCommon)
×
562
                  ->GetCtrl<ctrlOptionGroup>(ID_grpIpv6)
×
563
                  ->GetCtrl<ctrlButton>(1)
564
                  ->SetEnabled(true);
×
565
            break;
×
566
        case ID_cbMapScrollMode: SETTINGS.interface.mapScrollMode = static_cast<MapScrollMode>(selection); break;
×
567
        case ID_cbResolution: SETTINGS.video.fullscreenSize = video_modes[selection]; break;
×
568
        case ID_cbFramerate:
×
569
            if(VIDEODRIVER.HasVSync())
×
570
            {
571
                if(selection == 0)
×
572
                    SETTINGS.video.framerate = 0;
×
573
                else
574
                    SETTINGS.video.framerate = Settings::SCREEN_REFRESH_RATES[selection - 1];
×
575
            } else
576
                SETTINGS.video.framerate = Settings::SCREEN_REFRESH_RATES[selection];
×
577

578
            VIDEODRIVER.setTargetFramerate(SETTINGS.video.framerate);
×
579
            break;
×
580
        case ID_cbVideoDriver: SETTINGS.driver.video = combo->GetText(selection); break;
×
581
        case ID_cbGuiScale:
×
582
            SETTINGS.video.guiScale = guiScales_[selection];
×
583
            VIDEODRIVER.setGuiScalePercent(SETTINGS.video.guiScale);
×
584
            break;
×
585
        case ID_cbAudioDriver: SETTINGS.driver.audio = combo->GetText(selection); break;
×
586
    }
587
}
×
588

589
void dskOptions::Msg_Group_OptionGroupChange(const unsigned /*group_id*/, const unsigned ctrl_id,
×
590
                                             const unsigned selection)
591
{
592
    const bool enabled = selection == ID_btOn;
×
593
    switch(ctrl_id)
×
594
    {
595
        case ID_grpIpv6: SETTINGS.server.ipv6 = enabled; break;
×
596
        case ID_grpFullscreen: SETTINGS.video.fullscreen = enabled; break;
×
597
        case ID_grpVBO: SETTINGS.video.vbo = enabled; break;
×
598
        case ID_grpOptTextures: SETTINGS.video.shared_textures = enabled; break;
×
599
        case ID_grpEffects: SETTINGS.sound.effectsEnabled = enabled; break;
×
600
        case ID_grpBirdSounds: SETTINGS.sound.birdsEnabled = enabled; break;
×
601
        case ID_grpMusic:
×
602
            SETTINGS.sound.musicEnabled = enabled;
×
603
            if(enabled)
×
604
                MUSICPLAYER.Play();
×
605
            else
606
                MUSICPLAYER.Stop();
×
607
            break;
×
608
        case ID_grpDebugData:
×
609
            // Special case: Uses e.g. ID_btSubmitDebugOn directly
610
            SETTINGS.global.submit_debug_data = selection;
×
611
            break;
×
612
        case ID_grpUPNP: SETTINGS.global.use_upnp = enabled; break;
×
613
        case ID_grpSmartCursor:
×
614
            SETTINGS.global.smartCursor = enabled;
×
615
            VIDEODRIVER.SetMouseWarping(enabled);
×
616
            break;
×
617
        case ID_grpWindowPinning: SETTINGS.interface.enableWindowPinning = enabled; break;
×
618
        case ID_grpGFInfo: SETTINGS.global.showGFInfo = enabled; break;
×
619
    }
620
}
×
621

622
void dskOptions::Msg_OptionGroupChange(const unsigned ctrl_id, const unsigned selection)
×
623
{
624
    if(ctrl_id == ID_grpOptions)
×
625
    {
626
        const auto visGrp = selection + ID_grpCommon - ID_btCommon;
×
627
        for(const unsigned id : {ID_grpCommon, ID_grpGraphics, ID_grpSound})
×
628
            GetCtrl<ctrlGroup>(id)->SetVisible(id == visGrp);
×
629
    }
630
}
×
631

632
/// Check that the port is valid and sets outPort to it. Shows an error otherwise
633
static bool validatePort(const std::string& sPort, uint16_t& outPort)
×
634
{
635
    boost::optional<uint16_t> port = validate::checkPort(sPort);
×
636
    if(port)
×
637
        outPort = *port;
×
638
    else
639
    {
640
        WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(_("Error"),
×
641
                                                      _("Invalid port. The valid port-range is 1 to 65535!"), nullptr,
×
642
                                                      MsgboxButton::Ok, MsgboxIcon::ExclamationRed, 1));
×
643
    }
644
    return static_cast<bool>(port);
×
645
}
646

647
void dskOptions::Msg_ButtonClick(const unsigned ctrl_id)
×
648
{
649
    switch(ctrl_id)
×
650
    {
651
        case ID_btBack:
×
652
        {
653
            auto* groupCommon = GetCtrl<ctrlGroup>(ID_grpCommon);
×
654

655
            // Save the name
656
            SETTINGS.lobby.name = groupCommon->GetCtrl<ctrlEdit>(ID_edtName)->GetText();
×
657
            if(!validatePort(groupCommon->GetCtrl<ctrlEdit>(ID_edtPort)->GetText(), SETTINGS.server.localPort))
×
658
                return;
×
659

660
            SETTINGS.proxy.hostname = groupCommon->GetCtrl<ctrlEdit>(ID_edtProxy)->GetText();
×
661
            if(!validatePort(groupCommon->GetCtrl<ctrlEdit>(ID_edtProxyPort)->GetText(), SETTINGS.proxy.port))
×
662
                return;
×
663

664
            SETTINGS.Save();
×
665

666
            // Is the selected backend required to support GUI scaling to fullfill the user's choice?
667
            // If so, warn the user if the backend is unable to support GUI scaling.
668
            if(VIDEODRIVER.getGuiScale().percent() == 100
×
669
               && (SETTINGS.video.guiScale != 100
×
670
                   || (SETTINGS.video.guiScale == 0 && VIDEODRIVER.getGuiScaleRange().recommendedPercent != 100)))
×
671
            {
672
                WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(
×
673
                  _("Sorry!"), _("The selected video driver does not support GUI scaling! Setting won't be used."),
×
674
                  this, MsgboxButton::Ok, MsgboxIcon::ExclamationGreen, 1));
×
675
            }
676

677
            if((SETTINGS.video.fullscreen && SETTINGS.video.fullscreenSize != VIDEODRIVER.GetWindowSize()) //-V807
×
678
               || SETTINGS.video.fullscreen != VIDEODRIVER.IsFullscreen())
×
679
            {
680
                const auto screenSize =
681
                  SETTINGS.video.fullscreen ? SETTINGS.video.fullscreenSize : SETTINGS.video.windowedSize;
×
682
                if(!VIDEODRIVER.ResizeScreen(screenSize, SETTINGS.video.fullscreen))
×
683
                {
684
                    WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(
×
685
                      _("Sorry!"), _("You need to restart your game to change the screen resolution!"), this,
×
686
                      MsgboxButton::Ok, MsgboxIcon::ExclamationGreen, 1));
×
687
                    return;
×
688
                }
689
            }
690
            if(SETTINGS.driver.video != VIDEODRIVER.GetName() || SETTINGS.driver.audio != AUDIODRIVER.GetName())
×
691
            {
692
                WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(
×
693
                  _("Sorry!"), _("You need to restart your game to change the video or audio driver!"), this,
×
694
                  MsgboxButton::Ok, MsgboxIcon::ExclamationGreen, 1));
×
695
                return;
×
696
            }
697

698
            WINDOWMANAGER.Switch(std::make_unique<dskMainMenu>());
×
699
        }
700
        break;
×
701
        case ID_btAddons: WINDOWMANAGER.ToggleWindow(std::make_unique<iwAddons>(ggs)); break;
×
702
    }
703
}
704

705
void dskOptions::Msg_Group_ButtonClick(const unsigned /*group_id*/, const unsigned ctrl_id)
×
706
{
707
    switch(ctrl_id)
×
708
    {
709
        default: break;
×
710
        case ID_btCommonPortrait:
×
711
            SETTINGS.lobby.portraitIndex = (SETTINGS.lobby.portraitIndex + 1) % Portraits.size();
×
712
            updatePortraitControls();
×
713
            break;
×
714
        case ID_btMusicPlayer: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMusicPlayer>()); break;
×
715
        case ID_btKeyboardLayout:
×
716
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("keyboardlayout.txt", _("Keyboard layout")));
×
717
            break;
×
718
    }
719
}
×
720

721
void dskOptions::Msg_MsgBoxResult(const unsigned msgbox_id, const MsgboxResult /*mbr*/)
×
722
{
723
    switch(msgbox_id)
×
724
    {
725
        default: break;
×
726
        // "You need to restart your game ..."
727
        // "The selected video driver does not support GUI scaling!"
728
        case 1: WINDOWMANAGER.Switch(std::make_unique<dskMainMenu>()); break;
×
729
    }
730
}
×
731

732
static bool cmpVideoModes(const VideoMode& left, const VideoMode& right)
×
733
{
734
    if(left.width == right.width)
×
735
        return left.height > right.height;
×
736
    else
737
        return left.width > right.width;
×
738
}
739

740
void dskOptions::loadVideoModes()
×
741
{
742
    // Get available modes
743
    VIDEODRIVER.ListVideoModes(video_modes);
×
744
    // Remove everything below 800x600
745
    helpers::erase_if(video_modes, [](const auto& it) { return it.width < 800 && it.height < 600; });
×
746
    // Sort by aspect ratio
747
    std::sort(video_modes.begin(), video_modes.end(), cmpVideoModes);
×
748
}
×
749

750
void dskOptions::Msg_ScreenResize(const ScreenResizeEvent& sr)
×
751
{
752
    Desktop::Msg_ScreenResize(sr);
×
753
    updateGuiScale();
×
754
}
×
755

756
bool dskOptions::Msg_WheelUp(const MouseCoords& mc)
×
757
{
758
    if(VIDEODRIVER.GetModKeyState().ctrl)
×
759
    {
760
        scrollGuiScale(true);
×
761
        return true;
×
762
    } else
763
        return Desktop::Msg_WheelUp(mc);
×
764
}
765

766
bool dskOptions::Msg_WheelDown(const MouseCoords& mc)
×
767
{
768
    if(VIDEODRIVER.GetModKeyState().ctrl)
×
769
    {
770
        scrollGuiScale(false);
×
771
        return true;
×
772
    } else
773
        return Desktop::Msg_WheelDown(mc);
×
774
}
775

776
void dskOptions::updateGuiScale()
×
777
{
778
    // generate GUI scale percentages in 10% increments
779
    constexpr auto stepSize = 10u;
×
780
    const auto roundGuiScale = [=](unsigned percent) {
×
781
        return helpers::iround<unsigned>(static_cast<float>(percent) / stepSize) * stepSize;
×
782
    };
783

784
    const auto range = VIDEODRIVER.getGuiScaleRange();
×
785
    const auto recommendedPercentRounded = roundGuiScale(range.recommendedPercent);
×
786
    auto* combo = GetCtrl<ctrlGroup>(ID_grpGraphics)->GetCtrl<ctrlComboBox>(ID_cbGuiScale);
×
787

788
    guiScales_.clear();
×
789
    combo->DeleteAllItems();
×
790

791
    guiScales_.push_back(0);
×
792
    combo->AddString(helpers::format(_("Auto (%u%%)"), range.recommendedPercent));
×
793
    if(SETTINGS.video.guiScale == 0)
×
794
        combo->SetSelection(0);
×
795

796
    for(unsigned percent = roundGuiScale(range.minPercent); percent <= range.maxPercent; percent += stepSize)
×
797
    {
798
        if(percent == recommendedPercentRounded)
×
799
            recommendedGuiScaleIndex_ = guiScales_.size();
×
800
        guiScales_.push_back(percent);
×
801

802
        combo->AddString(helpers::toString(percent) + "%");
×
803
        if(percent == SETTINGS.video.guiScale)
×
804
            combo->SetSelection(combo->GetNumItems() - 1);
×
805
    }
806

807
    // if GUI scale exceeds maximum, lower it to keep UI elements on screen
808
    if(SETTINGS.video.guiScale > guiScales_.back())
×
809
    {
810
        combo->SetSelection(combo->GetNumItems() - 1);
×
811
        SETTINGS.video.guiScale = guiScales_.back();
×
812
        VIDEODRIVER.setGuiScalePercent(SETTINGS.video.guiScale);
×
813
    }
814
}
×
815

816
void dskOptions::scrollGuiScale(bool up)
×
817
{
818
    auto* combo = GetCtrl<ctrlGroup>(ID_grpGraphics)->GetCtrl<ctrlComboBox>(ID_cbGuiScale);
×
819
    const auto& selection = combo->GetSelection();
×
820
    unsigned newSelection = 0;
×
821
    if(!selection || *selection == 0) // No selection or "Auto" item selected
×
822
        newSelection = recommendedGuiScaleIndex_;
×
823
    else
824
        newSelection = std::clamp<unsigned>(*selection + (up ? 1 : -1), 1, combo->GetNumItems() - 1);
×
825

826
    if(newSelection != selection)
×
827
    {
828
        combo->SetSelection(newSelection);
×
829
        SETTINGS.video.guiScale = guiScales_[newSelection];
×
830
        VIDEODRIVER.setGuiScalePercent(SETTINGS.video.guiScale);
×
831
    }
832
}
×
833

834
void dskOptions::updatePortraitControls()
×
835
{
836
    const auto& newPortrait = Portraits[SETTINGS.lobby.portraitIndex];
×
837
    auto* groupCommon = GetCtrl<ctrlGroup>(ID_grpCommon);
×
838

839
    auto* portraitButton = groupCommon->GetCtrl<ctrlImageButton>(ID_btCommonPortrait);
×
840
    auto* newPortraitTexture = LOADER.GetTextureN(newPortrait.resourceId, newPortrait.resourceIndex);
×
841
    portraitButton->SetImage(newPortraitTexture);
×
842

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