Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libs/s25main/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void Settings::LoadDefaults()
sound.musicVolume = 30;
sound.effectsEnabled = true;
sound.effectsVolume = 75;
sound.birdsEnabled = true;
sound.playlist = s25::files::defaultPlaylist;
// }

Expand Down Expand Up @@ -258,6 +259,7 @@ void Settings::Load()
sound.musicVolume = iniSound->getIntValue("musik_volume");
sound.effectsEnabled = iniSound->getBoolValue("effekte");
sound.effectsVolume = iniSound->getIntValue("effekte_volume");
sound.birdsEnabled = iniSound->getBoolValue("bird_sounds");
sound.playlist = iniSound->getValue("playlist");
// }

Expand Down Expand Up @@ -444,6 +446,7 @@ void Settings::Save()
iniSound->setValue("musik_volume", sound.musicVolume);
iniSound->setValue("effekte", sound.effectsEnabled);
iniSound->setValue("effekte_volume", sound.effectsVolume);
iniSound->setValue("bird_sounds", sound.birdsEnabled);
iniSound->setValue("playlist", sound.playlist);
// }

Expand Down
1 change: 1 addition & 0 deletions libs/s25main/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Settings : public Singleton<Settings, SingletonPolicies::WithLongevity>
uint8_t musicVolume;
bool effectsEnabled;
uint8_t effectsVolume;
bool birdsEnabled;
std::string playlist; /// musicplayer playlist name
} sound;

Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/SoundManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void SoundManager::playAnimalSound(unsigned soundLstId)

void SoundManager::playBirdSounds(const unsigned treeCount)
{
if(!SETTINGS.sound.effectsEnabled)
if(!SETTINGS.sound.effectsEnabled || !SETTINGS.sound.birdsEnabled)
return;

using namespace std::chrono;
Expand Down
34 changes: 22 additions & 12 deletions libs/s25main/desktops/dskOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ enum
ID_txtCommonPortrait,
ID_btCommonPortrait,
ID_cbCommonPortrait,
ID_txtBirdSounds,
ID_grpBirdSounds,
};
// Use these as IDs in dedicated groups
constexpr auto ID_btOn = 1;
Expand Down Expand Up @@ -359,16 +361,6 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
constexpr Offset volOffset(400, -5);
constexpr Extent ctrlSizeSmall(90, ctrlSize.y);

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

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

groupSound->AddText(ID_txtEffects, curPos, _("Effects"), COLOR_YELLOW, FontStyle{}, NormalFont);
mainGroup = groupSound->AddOptionGroup(ID_grpEffects, GroupSelectType::Check);
mainGroup->AddTextButton(ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _("On"), NormalFont);
Expand All @@ -379,6 +371,22 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
FXvolume->SetPosition((SETTINGS.sound.effectsVolume * 100) / 255);
curPos.y += rowHeight + sectionSpacing;

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

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

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

groupSound->AddTextButton(ID_btMusicPlayer, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("Music player"),
NormalFont);
curPos.y += rowHeight + sectionSpacing;
Expand Down Expand Up @@ -452,8 +460,9 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
// Sound
// {

groupSound->GetCtrl<ctrlOptionGroup>(ID_grpMusic)->SetSelection(SETTINGS.sound.musicEnabled);
groupSound->GetCtrl<ctrlOptionGroup>(ID_grpEffects)->SetSelection(SETTINGS.sound.effectsEnabled);
groupSound->GetCtrl<ctrlOptionGroup>(ID_grpBirdSounds)->SetSelection(SETTINGS.sound.birdsEnabled);
groupSound->GetCtrl<ctrlOptionGroup>(ID_grpMusic)->SetSelection(SETTINGS.sound.musicEnabled);

// }

Expand Down Expand Up @@ -560,14 +569,15 @@ void dskOptions::Msg_Group_OptionGroupChange(const unsigned /*group_id*/, const
case ID_grpFullscreen: SETTINGS.video.fullscreen = enabled; break;
case ID_grpVBO: SETTINGS.video.vbo = enabled; break;
case ID_grpOptTextures: SETTINGS.video.shared_textures = enabled; break;
case ID_grpEffects: SETTINGS.sound.effectsEnabled = enabled; break;
case ID_grpBirdSounds: SETTINGS.sound.birdsEnabled = enabled; break;
case ID_grpMusic:
SETTINGS.sound.musicEnabled = enabled;
if(enabled)
MUSICPLAYER.Play();
else
MUSICPLAYER.Stop();
break;
case ID_grpEffects: SETTINGS.sound.effectsEnabled = enabled; break;
case ID_grpDebugData:
// Special case: Uses e.g. ID_btSubmitDebugOn directly
SETTINGS.global.submit_debug_data = selection;
Expand Down
32 changes: 24 additions & 8 deletions libs/s25main/ingameWindows/iwOptionsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ enum
ID_btMusicPlayer,
ID_btAdvanced,
ID_btSurrender,
ID_btEndGame
ID_btEndGame,
ID_cpBirdSounds
};
}

iwOptionsWindow::iwOptionsWindow(SoundManager& soundManager)
: IngameWindow(CGI_OPTIONSWINDOW, IngameWindow::posLastOrCenter, Extent(300, 515), _("Game menu"),
: IngameWindow(CGI_OPTIONSWINDOW, IngameWindow::posLastOrCenter, Extent(300, 545), _("Game menu"),
LOADER.GetImageN("resource", 41)),
soundManager(soundManager)
{
Expand Down Expand Up @@ -84,22 +85,25 @@ iwOptionsWindow::iwOptionsWindow(SoundManager& soundManager)
LOADER.GetImageN("io", 114 + !SETTINGS.sound.effectsEnabled)); //-V807

// Musik an/aus
AddImageButton(ID_btMusic, DrawPoint(35, 340), Extent(35, 35), TextureColor::Green2,
AddImageButton(ID_btMusic, DrawPoint(35, 371), Extent(35, 35), TextureColor::Green2,
LOADER.GetImageN("io", 116 + !SETTINGS.sound.musicEnabled));

// Geräuschlautstärke
AddProgress(ID_pgEffectVol, DrawPoint(100, 306), Extent(160, 22), TextureColor::Green2, 139, 138, 100)
->SetPosition((SETTINGS.sound.effectsVolume * 100) / 255);

// Vogelgeräusche an/aus
AddCheckBox(ID_cpBirdSounds, DrawPoint(100, 342), Extent(160, 22), TextureColor::Green2, _("Bird sounds"), NormalFont, false);

// Musiklautstärke
AddProgress(ID_pgMusicVol, DrawPoint(100, 346), Extent(160, 22), TextureColor::Green2, 139, 138, 100)
AddProgress(ID_pgMusicVol, DrawPoint(100, 377), Extent(160, 22), TextureColor::Green2, 139, 138, 100)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the spacing of the progress bars, checkbox and button is even. Can you use a similar pattern to the desktop: constexpr Extent ctrlSize(160, 22);, DrawPoint pos = ..., and pos.y += ctrlSize.y + spacingY and the use pos for the position?

The 2 buttons for enable/disable of music&effects would then need to be relative

While the current approach works with more controls added it becomes harder to reason if they are all placed "correctly".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With "the desktops" you mean the mechanism at for example my already touched libs/s25main/desktops/dskOptions.cpp? This would be really better indeed, due it was way easier for me to add my changes there then in the in-game menu.

I could try this, but I would need some time to implement the same principle to this menu. I'm not very familiar with C++ actually. 😁 I will let you know. 💪

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly. And you were familiar enough to do this change, so don't worry! :-)

You don't need to do this for this PR, just let me know if you are up to it and I'll wait before merging to avoid introducing this change just to change it again for a "better" solution.

If you need any help feel free to ask here, show intermediate results if that helps you question.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thx, I will try, yes pls wait, I let you know 💪

->SetPosition((SETTINGS.sound.musicVolume * 100) / 255);

AddTextButton(ID_btMusicPlayer, DrawPoint(100, 380), Extent(160, 22), TextureColor::Green2, _("Music player"),
AddTextButton(ID_btMusicPlayer, DrawPoint(100, 413), Extent(160, 22), TextureColor::Green2, _("Music player"),
NormalFont);
AddTextButton(ID_btAdvanced, DrawPoint(67, 412), Extent(168, 24), TextureColor::Green2, _("Advanced"), NormalFont);
AddTextButton(ID_btSurrender, DrawPoint(67, 443), Extent(168, 24), TextureColor::Red1, _("Surrender"), NormalFont);
AddTextButton(ID_btEndGame, DrawPoint(67, 474), Extent(168, 24), TextureColor::Red1, _("End game"), NormalFont);
AddTextButton(ID_btAdvanced, DrawPoint(67, 442), Extent(168, 24), TextureColor::Green2, _("Advanced"), NormalFont);
AddTextButton(ID_btSurrender, DrawPoint(67, 473), Extent(168, 24), TextureColor::Red1, _("Surrender"), NormalFont);
AddTextButton(ID_btEndGame, DrawPoint(67, 504), Extent(168, 24), TextureColor::Red1, _("End game"), NormalFont);
}

void iwOptionsWindow::Msg_ButtonClick(const unsigned ctrl_id)
Expand Down Expand Up @@ -160,3 +164,15 @@ void iwOptionsWindow::Msg_ProgressChange(const unsigned ctrl_id, const unsigned
break;
}
}

void iwOptionsWindow::Msg_CheckboxChange(const unsigned ctrl_id, const bool checked)
{
switch(ctrl_id)
{
case ID_cpBirdSounds:
{
SETTINGS.sound.birdsEnabled = checked;
break;
}
}
}
1 change: 1 addition & 0 deletions libs/s25main/ingameWindows/iwOptionsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ class iwOptionsWindow : public IngameWindow
private:
void Msg_ButtonClick(unsigned ctrl_id) override;
void Msg_ProgressChange(unsigned ctrl_id, unsigned short position) override;
void Msg_CheckboxChange(unsigned ctrl_id, bool checked) override;
};
1 change: 1 addition & 0 deletions libs/s25main/notifications/NotificationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "notifications/Subscription.h"
#include <deque>
#include <functional>
#include <cstdint>
#include <unordered_map>

class NotificationManager
Expand Down
Loading