From 785e42a6f9d5d36b2bb98d2b941839ffc6de1fc5 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sun, 4 Apr 2021 11:22:13 +0200 Subject: [PATCH] Feature: Volume sliders in Game Options window --- src/music_gui.cpp | 1 + src/settings_gui.cpp | 40 ++++++++++++++++++++++++++++++++--- src/widgets/settings_widget.h | 2 ++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/music_gui.cpp b/src/music_gui.cpp index 469066706e..28cb6ce4e1 100644 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -790,6 +790,7 @@ struct MusicWindow : public Window { if (ClickVolumeSliderWidget(this->GetWidget(widget)->GetCurrentRect(), pt, vol)) { if (widget == WID_M_MUSIC_VOL) MusicDriver::GetInstance()->SetVolume(vol); this->SetDirty(); + SetWindowClassesDirty(WC_GAME_OPTIONS); } if (click_count > 0) this->mouse_capture_widget = widget; diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 513a3ef8f3..6788d1ae39 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -37,6 +37,7 @@ #include "fontcache.h" #include "zoom_func.h" #include "video/video_driver.hpp" +#include "music/music_driver.hpp" #include #include @@ -336,6 +337,14 @@ struct GameOptionsWindow : Window { SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode())); DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING); break; + + case WID_GO_BASE_SFX_VOLUME: + DrawVolumeSliderWidget(r, _settings_client.music.effect_vol); + break; + + case WID_GO_BASE_MUSIC_VOLUME: + DrawVolumeSliderWidget(r, _settings_client.music.music_vol); + break; } } @@ -388,6 +397,16 @@ struct GameOptionsWindow : Window { } break; + case WID_GO_BASE_SFX_VOLUME: + case WID_GO_BASE_MUSIC_VOLUME: + size->width = ScaleGUITrad(67); + size->height = ScaleGUITrad(12); + resize->width = 0; + resize->height = 0; + fill->width = 0; + fill->height = 0; + break; + default: { int selected; DropDownList list = this->BuildDropDownList(widget, &selected); @@ -442,6 +461,19 @@ struct GameOptionsWindow : Window { this->SetDirty(); break; + case WID_GO_BASE_SFX_VOLUME: + case WID_GO_BASE_MUSIC_VOLUME: { + byte &vol = (widget == WID_GO_BASE_MUSIC_VOLUME) ? _settings_client.music.music_vol : _settings_client.music.effect_vol; + if (ClickVolumeSliderWidget(this->GetWidget(widget)->GetCurrentRect(), pt, vol)) { + if (widget == WID_GO_BASE_MUSIC_VOLUME) MusicDriver::GetInstance()->SetVolume(vol); + this->SetDirty(); + SetWindowClassesDirty(WC_MUSIC_WINDOW); + } + + if (click_count > 0) this->mouse_capture_widget = widget; + break; + } + default: { int selected; DropDownList list = this->BuildDropDownList(widget, &selected); @@ -646,9 +678,10 @@ static const NWidgetPart _nested_game_options_widgets[] = { EndContainer(), NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_SFX, STR_NULL), SetPadding(0, 10, 0, 10), - NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0), + NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 7), NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_SFX_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_SFX_TOOLTIP), - NWidget(NWID_SPACER), SetFill(1, 0), + NWidget(NWID_SPACER), SetMinimalSize(150, 12), SetFill(1, 0), + NWidget(WWT_EMPTY, COLOUR_GREY, WID_GO_BASE_SFX_VOLUME), SetMinimalSize(67, 12), SetMinimalTextLines(1, 0), SetDataTip(0x0, STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC), EndContainer(), NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_SFX_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_SFX_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0), NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7), @@ -659,9 +692,10 @@ static const NWidgetPart _nested_game_options_widgets[] = { EndContainer(), NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_MUSIC, STR_NULL), SetPadding(0, 10, 0, 10), - NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0), + NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 7), NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_MUSIC_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP), NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0), + NWidget(WWT_EMPTY, COLOUR_GREY, WID_GO_BASE_MUSIC_VOLUME), SetMinimalSize(67, 12), SetMinimalTextLines(1, 0), SetDataTip(0x0, STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC), EndContainer(), NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_MUSIC_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0), NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7), diff --git a/src/widgets/settings_widget.h b/src/widgets/settings_widget.h index 6cb2d7e949..ae9c22c1a8 100644 --- a/src/widgets/settings_widget.h +++ b/src/widgets/settings_widget.h @@ -25,9 +25,11 @@ enum GameOptionsWidgets { WID_GO_BASE_GRF_TEXTFILE, ///< Open base GRF readme, changelog (+1) or license (+2). WID_GO_BASE_GRF_DESCRIPTION = WID_GO_BASE_GRF_TEXTFILE + TFT_END, ///< Description of selected base GRF. WID_GO_BASE_SFX_DROPDOWN, ///< Use to select a base SFX. + WID_GO_BASE_SFX_VOLUME, ///< Change sound effects volume. WID_GO_BASE_SFX_TEXTFILE, ///< Open base SFX readme, changelog (+1) or license (+2). WID_GO_BASE_SFX_DESCRIPTION = WID_GO_BASE_SFX_TEXTFILE + TFT_END, ///< Description of selected base SFX. WID_GO_BASE_MUSIC_DROPDOWN, ///< Use to select a base music set. + WID_GO_BASE_MUSIC_VOLUME, ///< Change music volume. WID_GO_BASE_MUSIC_STATUS, ///< Info about corrupted files etc. WID_GO_BASE_MUSIC_TEXTFILE, ///< Open base music readme, changelog (+1) or license (+2). WID_GO_BASE_MUSIC_DESCRIPTION = WID_GO_BASE_MUSIC_TEXTFILE + TFT_END, ///< Description of selected base music set.