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

Return-To-The-Roots / s25client / 19864060388

02 Dec 2025 03:30PM UTC coverage: 50.494% (-0.05%) from 50.54%
19864060388

push

github

Flow86
Refactor options window layout spacing

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

312 existing lines in 4 files now uncovered.

22558 of 44675 relevant lines covered (50.49%)

35533.4 hits per line

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

0.0
/libs/s25main/ingameWindows/iwOptionsWindow.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 "iwOptionsWindow.h"
6
#include "Loader.h"
7
#include "MusicPlayer.h"
8
#include "RTTR_Version.h"
9
#include "Settings.h"
10
#include "SoundManager.h"
11
#include "WindowManager.h"
12
#include "controls/ctrlCheck.h"
13
#include "controls/ctrlImageButton.h"
14
#include "controls/ctrlProgress.h"
15
#include "drivers/AudioDriverWrapper.h"
16
#include "iwEndgame.h"
17
#include "iwMusicPlayer.h"
18
#include "iwSave.h"
19
#include "iwSettings.h"
20
#include "iwSurrender.h"
21
#include "iwTextfile.h"
22
#include "ogl/FontStyle.h"
23
#include "gameData/const_gui_ids.h"
24

25
namespace {
26
enum
27
{
28
    ID_imgSoldier,
29
    ID_txtRttr,
30
    ID_txtVersion,
31
    ID_txtCopyright,
32
    ID_btKeyboardLayout,
33
    ID_txtKeyboardLayout,
34
    ID_btReadme,
35
    ID_txtReadme,
36
    ID_btLoad,
37
    ID_txtLoad,
38
    ID_btSave,
39
    ID_txtSave,
40
    ID_btSoundEffects,
41
    ID_btMusic,
42
    ID_pgEffectVol,
43
    ID_pgMusicVol,
44
    ID_btMusicPlayer,
45
    ID_btAdvanced,
46
    ID_btSurrender,
47
    ID_btEndGame,
48
    ID_cpBirdSounds
49
};
50

51
using Offset = DrawPoint;
52
constexpr auto windowSize = Extent(300, 525);
53
constexpr auto imageButtonSize = Extent(35, 35);
54
constexpr auto optionSizeSmall = Extent(160, 22);
55
constexpr auto optionSizeBig = Extent(168, 24);
56
constexpr auto optionOffset = Offset(65, 6);
57
constexpr auto textOffset = Offset(50, 24);
58
constexpr auto centerPosition = windowSize.x / 2;
59
constexpr auto textSpacing = 17;
60
constexpr auto generalSpacing = 5;
61
constexpr auto leftMargin = 35;
62
} // namespace
63

UNCOV
64
iwOptionsWindow::iwOptionsWindow(SoundManager& soundManager)
×
65
    : IngameWindow(CGI_OPTIONSWINDOW, IngameWindow::posLastOrCenter, windowSize, _("Game menu"),
66
                   LOADER.GetImageN("resource", 41)),
×
67
      soundManager(soundManager)
×
68
{
69
    DrawPoint curPos = DrawPoint(centerPosition, 10);
×
70

71
    // The soldier on top
UNCOV
72
    constexpr Offset soldierOffset(0, 26);
×
UNCOV
73
    AddImage(ID_imgSoldier, curPos + soldierOffset, LOADER.GetImageN("io", 30));
×
UNCOV
74
    curPos.y += textSpacing + soldierOffset.y;
×
75

UNCOV
76
    AddText(ID_txtRttr, curPos, "Return To The Roots", COLOR_YELLOW, FontStyle::CENTER, NormalFont);
×
UNCOV
77
    curPos.y += textSpacing;
×
78

79
    AddText(ID_txtVersion, curPos, rttr::version::GetReadableVersion(), COLOR_YELLOW, FontStyle::CENTER, NormalFont);
×
80
    curPos.y += textSpacing;
×
81

UNCOV
82
    AddFormattedText(ID_txtCopyright, curPos,
×
83
                     "\xC2\xA9"
84
                     "2005 - %s Settlers Freaks",
UNCOV
85
                     COLOR_YELLOW, FontStyle::CENTER, NormalFont)
×
UNCOV
86
      % rttr::version::GetYear();
×
87
    curPos.y += textSpacing * 2;
×
88
    curPos.x = leftMargin;
×
89

UNCOV
90
    AddImageButton(ID_btKeyboardLayout, curPos, imageButtonSize, TextureColor::Green2, LOADER.GetImageN("io", 79));
×
91
    AddText(ID_txtKeyboardLayout, curPos + textOffset, _("Keyboard layout"), COLOR_YELLOW, FontStyle::BOTTOM,
×
92
            NormalFont);
×
UNCOV
93
    curPos.y += imageButtonSize.y + generalSpacing;
×
94

95
    AddImageButton(ID_btReadme, curPos, imageButtonSize, TextureColor::Green2, LOADER.GetImageN("io", 79));
×
96
    AddText(ID_txtReadme, curPos + textOffset, _("Load 'ReadMe' file"), COLOR_YELLOW, FontStyle::BOTTOM, NormalFont);
×
UNCOV
97
    curPos.y += imageButtonSize.y + generalSpacing;
×
98

99
    // TODO: Implement
100
    // AddImageButton(ID_btLoad, curPos, imageButtonSize, TextureColor::Green2, LOADER.GetImageN("io", 48));
101
    // AddText(ID_txtLoad, curPos + textOffset, _("Load game!"), COLOR_YELLOW, FontStyle::BOTTOM, NormalFont);
102
    // curPos.y += imageButtonSize.y + generalSpacing;
103

UNCOV
104
    curPos.y += 3 + imageButtonSize.y / 2; // TODO: Delete this row, if the Load button is implemented
×
105
    AddImageButton(ID_btSave, curPos, imageButtonSize, TextureColor::Green2, LOADER.GetImageN("io", 47));
×
UNCOV
106
    AddText(ID_txtSave, curPos + textOffset, _("Save game!"), COLOR_YELLOW, FontStyle::BOTTOM, NormalFont);
×
107
    curPos.y += 3 + imageButtonSize.y / 2; // TODO: Delete this row, if the Load button is implemented
×
UNCOV
108
    curPos.y += imageButtonSize.y + generalSpacing;
×
109

110
    // Sound on/off + volume
111
    AddImageButton(ID_btSoundEffects, curPos, imageButtonSize, TextureColor::Green2,
×
112
                   LOADER.GetImageN("io", 114 + !SETTINGS.sound.effectsEnabled)); //-V807
×
113
    AddProgress(ID_pgEffectVol, curPos + optionOffset, optionSizeSmall, TextureColor::Green2, 139, 138, 100)
×
114
      ->SetPosition((SETTINGS.sound.effectsVolume * 100) / 255);
×
NEW
115
    curPos.y += imageButtonSize.y;
×
NEW
116
    curPos.x += optionOffset.x;
×
117

NEW
118
    AddCheckBox(ID_cpBirdSounds, curPos, optionSizeSmall, TextureColor::Green2, _("Bird sounds"), NormalFont, false)
×
UNCOV
119
      ->setChecked(SETTINGS.sound.birdsEnabled);
×
NEW
120
    curPos.y += optionSizeSmall.y + generalSpacing * 3;
×
NEW
121
    curPos.x = leftMargin;
×
122

123
    // Music on/off + volume
UNCOV
124
    AddImageButton(ID_btMusic, curPos, imageButtonSize, TextureColor::Green2,
×
125
                   LOADER.GetImageN("io", 116 + !SETTINGS.sound.musicEnabled));
×
126
    AddProgress(ID_pgMusicVol, curPos + optionOffset, optionSizeSmall, TextureColor::Green2, 139, 138, 100)
×
127
      ->SetPosition((SETTINGS.sound.musicVolume * 100) / 255);
×
NEW
128
    curPos.y += imageButtonSize.y;
×
NEW
129
    curPos.x += optionOffset.x;
×
130

NEW
131
    AddTextButton(ID_btMusicPlayer, curPos, optionSizeSmall, TextureColor::Green2, _("Music player"), NormalFont);
×
NEW
132
    curPos.y += optionSizeSmall.y + generalSpacing * 3;
×
NEW
133
    curPos.x = leftMargin;
×
134

135
    // Buttons at the bottom
UNCOV
136
    curPos.x = centerPosition - optionSizeBig.x / 2;
×
137
    AddTextButton(ID_btAdvanced, curPos, optionSizeBig, TextureColor::Green2, _("Advanced"), NormalFont);
×
138
    curPos.y += optionSizeBig.y + generalSpacing;
×
139
    AddTextButton(ID_btSurrender, curPos, optionSizeBig, TextureColor::Red1, _("Surrender"), NormalFont);
×
140
    curPos.y += optionSizeBig.y + generalSpacing;
×
141
    AddTextButton(ID_btEndGame, curPos, optionSizeBig, TextureColor::Red1, _("End game"), NormalFont);
×
142
}
×
143

144
void iwOptionsWindow::Msg_ButtonClick(const unsigned ctrl_id)
×
145
{
146
    switch(ctrl_id)
×
147
    {
UNCOV
148
        case ID_btEndGame:
×
149
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwEndgame>());
×
UNCOV
150
            Close();
×
151
            break;
×
UNCOV
152
        case ID_btKeyboardLayout:
×
153
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("keyboardlayout.txt", _("Keyboard layout")));
×
UNCOV
154
            break;
×
155
        case ID_btReadme: WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("readme.txt", _("Readme!"))); break;
×
156
        case ID_btSave: WINDOWMANAGER.ToggleWindow(std::make_unique<iwSave>()); break;
×
157

158
        case ID_btSoundEffects:
×
159
            SETTINGS.sound.effectsEnabled = !SETTINGS.sound.effectsEnabled; //-V807
×
160
            GetCtrl<ctrlImageButton>(ID_btSoundEffects)
×
161
              ->SetImage(LOADER.GetTextureN("io", 114 + !SETTINGS.sound.effectsEnabled));
×
162

UNCOV
163
            if(!SETTINGS.sound.effectsEnabled)
×
164
                soundManager.stopAll();
×
UNCOV
165
            break;
×
166

UNCOV
167
        case ID_btMusic:
×
UNCOV
168
            SETTINGS.sound.musicEnabled = !SETTINGS.sound.musicEnabled;
×
UNCOV
169
            GetCtrl<ctrlImageButton>(ID_btMusic)
×
UNCOV
170
              ->SetImage(LOADER.GetTextureN("io", 116 + !SETTINGS.sound.musicEnabled));
×
UNCOV
171
            if(SETTINGS.sound.musicEnabled)
×
UNCOV
172
                MUSICPLAYER.Play();
×
173
            else
UNCOV
174
                MUSICPLAYER.Stop();
×
UNCOV
175
            break;
×
UNCOV
176
        case ID_btMusicPlayer: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMusicPlayer>()); break;
×
UNCOV
177
        case ID_btSurrender:
×
UNCOV
178
            WINDOWMANAGER.ReplaceWindow(std::make_unique<iwSurrender>());
×
UNCOV
179
            Close();
×
UNCOV
180
            break;
×
UNCOV
181
        case ID_btAdvanced:
×
UNCOV
182
            WINDOWMANAGER.ReplaceWindow(std::make_unique<iwSettings>());
×
UNCOV
183
            Close();
×
UNCOV
184
            break;
×
185
    }
UNCOV
186
}
×
187

UNCOV
188
void iwOptionsWindow::Msg_ProgressChange(const unsigned ctrl_id, const unsigned short position)
×
189
{
UNCOV
190
    switch(ctrl_id)
×
191
    {
UNCOV
192
        case ID_pgEffectVol:
×
UNCOV
193
            SETTINGS.sound.effectsVolume = static_cast<uint8_t>((position * 255) / 100);
×
UNCOV
194
            AUDIODRIVER.SetMasterEffectVolume(SETTINGS.sound.effectsVolume);
×
UNCOV
195
            break;
×
UNCOV
196
        case ID_pgMusicVol:
×
UNCOV
197
            SETTINGS.sound.musicVolume = static_cast<uint8_t>((position * 255) / 100);
×
UNCOV
198
            AUDIODRIVER.SetMusicVolume(SETTINGS.sound.musicVolume);
×
UNCOV
199
            break;
×
200
    }
UNCOV
201
}
×
202

UNCOV
203
void iwOptionsWindow::Msg_CheckboxChange(const unsigned ctrl_id, const bool checked)
×
204
{
UNCOV
205
    RTTR_Assert(ctrl_id == ID_cpBirdSounds);
×
UNCOV
206
    SETTINGS.sound.birdsEnabled = checked;
×
UNCOV
207
}
×
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