Feature #6090: Change music set during gameplay
This commit is contained in:

committed by
frosch

parent
430e20f7e4
commit
19f5a6cbb0
@@ -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),
|
||||
|
Reference in New Issue
Block a user