summaryrefslogtreecommitdiff
path: root/src/music_gui.cpp
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2018-03-20 17:06:39 +0100
committerfrosch <github@elsenhans.name>2018-04-29 19:26:05 +0200
commit19f5a6cbb07a3d9edcfee083f6b211b6023f1292 (patch)
tree42acf471b3b5c77562e1f6bccd60cea6e874d284 /src/music_gui.cpp
parent430e20f7e443de7d6b5ffa4e0835ddcbb390ed6d (diff)
downloadopenttd-19f5a6cbb07a3d9edcfee083f6b211b6023f1292.tar.xz
Feature #6090: Change music set during gameplay
Diffstat (limited to 'src/music_gui.cpp')
-rw-r--r--src/music_gui.cpp58
1 files changed, 57 insertions, 1 deletions
diff --git a/src/music_gui.cpp b/src/music_gui.cpp
index fb01cf505..25bb41314 100644
--- a/src/music_gui.cpp
+++ b/src/music_gui.cpp
@@ -24,6 +24,9 @@
#include "core/geometry_func.hpp"
#include "string_func.h"
#include "settings_type.h"
+#include "settings_gui.h"
+#include "widgets/dropdown_func.h"
+#include "widgets/dropdown_type.h"
#include "widgets/music_widget.h"
@@ -303,6 +306,36 @@ static void SelectPlaylist(byte list)
InvalidateWindowData(WC_MUSIC_WINDOW, 0);
}
+/**
+ * Change the configured music set and reset playback
+ * @param index Index of music set to switch to
+ */
+void ChangeMusicSet(int index)
+{
+ if (BaseMusic::GetIndexOfUsedSet() == index) return;
+
+ /* Resume playback after switching?
+ * Always if music is already playing, and also if the user is switching
+ * away from an empty music set.
+ * If the user switches away from an empty set, assume it's because they
+ * want to hear music now. */
+ bool shouldplay = _song_is_active || (BaseMusic::GetUsedSet()->num_available == 0);
+ StopMusic();
+
+ const char *name = BaseMusic::GetSet(index)->name;
+ BaseMusic::SetSet(name);
+ free(BaseMusic::ini_set);
+ BaseMusic::ini_set = stredup(name);
+
+ InitializeMusic();
+ ResetPlaylist();
+ _settings_client.music.playing = shouldplay;
+
+ InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0);
+ InvalidateWindowData(WC_MUSIC_WINDOW, 0);
+ InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS, 0, true);
+}
+
struct MusicTrackSelectionWindow : public Window {
MusicTrackSelectionWindow(WindowDesc *desc, WindowNumber number) : Window(desc)
{
@@ -319,6 +352,9 @@ struct MusicTrackSelectionWindow : public Window {
case WID_MTS_PLAYLIST:
SetDParam(0, STR_MUSIC_PLAYLIST_ALL + _settings_client.music.playlist);
break;
+ case WID_MTS_CAPTION:
+ SetDParamStr(0, BaseMusic::GetUsedSet()->name);
+ break;
}
}
@@ -456,6 +492,13 @@ struct MusicTrackSelectionWindow : public Window {
break;
}
+ case WID_MTS_MUSICSET: {
+ int selected = 0;
+ DropDownList *dropdown = BuildMusicSetDropDownList(&selected);
+ ShowDropDownList(this, dropdown, selected, widget, 0, true, false);
+ break;
+ }
+
case WID_MTS_CLEAR: // clear
for (uint i = 0; _playlists[_settings_client.music.playlist][i] != 0; i++) _playlists[_settings_client.music.playlist][i] = 0;
this->SetDirty();
@@ -471,12 +514,25 @@ struct MusicTrackSelectionWindow : public Window {
break;
}
}
+
+ virtual void OnDropdownSelect(int widget, int index)
+ {
+ switch (widget) {
+ case WID_MTS_MUSICSET:
+ ChangeMusicSet(index);
+ break;
+ default:
+ NOT_REACHED();
+ break;
+ }
+ }
};
static const NWidgetPart _nested_music_track_selection_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
- NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_PLAYLIST_MUSIC_PROGRAM_SELECTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
+ NWidget(WWT_CAPTION, COLOUR_GREY, WID_MTS_CAPTION), SetDataTip(STR_PLAYLIST_MUSIC_SELECTION_SETNAME, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
+ NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_MTS_MUSICSET), SetDataTip(STR_PLAYLIST_CHANGE_SET, STR_PLAYLIST_TOOLTIP_CHANGE_SET),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(NWID_HORIZONTAL), SetPIP(2, 4, 2),