OpenTTD Source: src/music_gui.cpp Source File

OpenTTD Source 13.1

music_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include <vector>
12 #include "openttd.h"
13 #include "base_media_base.h"
14 #include "music/music_driver.hpp"
15 #include "window_gui.h"
16 #include "strings_func.h"
17 #include "window_func.h"
18 #include "sound_func.h"
19 #include "gfx_func.h"
20 #include "zoom_func.h"
21 #include "core/random_func.hpp"
22 #include "error.h"
23 #include "core/geometry_func.hpp"
24 #include "string_func.h"
25 #include "settings_type.h"
26 #include "settings_gui.h"
27 #include "widgets/dropdown_func.h"
28 #include "widgets/dropdown_type.h"
29 #include "widgets/slider_func.h"
30 #include "mixer.h"
31
32 #include "widgets/music_widget.h"
33
34 #include "table/strings.h"
35 #include "table/sprites.h"
36
37 #include "safeguards.h"
38
39
40 struct MusicSystem {
41 struct PlaylistEntry : MusicSongInfo {
42 const MusicSet *set;
43 uint set_index;
44
45 PlaylistEntry(const MusicSet *set, uint set_index) : MusicSongInfo(set->songinfo[set_index]), set(set), set_index(set_index) { }
46 bool IsValid() const { return !StrEmpty(this->songname); }
47 };
48 typedef std::vector<PlaylistEntry> Playlist;
49
50 enum PlaylistChoices {
51 PLCH_ALLMUSIC,
52 PLCH_OLDSTYLE,
53 PLCH_NEWSTYLE,
54 PLCH_EZYSTREET,
55 PLCH_CUSTOM1,
56 PLCH_CUSTOM2,
57 PLCH_THEMEONLY,
58 PLCH_MAX,
59 };
60
61 Playlist active_playlist;
62 Playlist displayed_playlist;
63 Playlist music_set;
64
65 PlaylistChoices selected_playlist;
66
67 void BuildPlaylists();
68
69 void ChangePlaylist(PlaylistChoices pl);
70 void ChangeMusicSet(const std::string &set_name);
71 void Shuffle();
72 void Unshuffle();
73
74 void Play();
75 void Stop();
76 void Next();
77 void Prev();
78 void CheckStatus();
79
80 bool IsPlaying() const;
81 bool IsShuffle() const;
82 PlaylistEntry GetCurrentSong() const;
83
84 bool IsCustomPlaylist() const;
85 void PlaylistAdd(size_t song_index);
86 void PlaylistRemove(size_t song_index);
87 void PlaylistClear();
88
89 private:
90 void ChangePlaylistPosition(int ofs);
91 int playlist_position;
92
93 void SaveCustomPlaylist(PlaylistChoices pl);
94
95 Playlist standard_playlists[PLCH_MAX];
96 };
97
98 MusicSystem _music;
99
100
102 void MusicSystem::BuildPlaylists()
103 {
104 const MusicSet *set = BaseMusic::GetUsedSet();
105
106 /* Clear current playlists */
107 for (size_t i = 0; i < lengthof(this->standard_playlists); ++i) this->standard_playlists[i].clear();
108 this->music_set.clear();
109
110 /* Build standard playlists, and a list of available music */
111 for (uint i = 0; i < NUM_SONGS_AVAILABLE; i++) {
112 PlaylistEntry entry(set, i);
113 if (!entry.IsValid()) continue;
114
115 this->music_set.push_back(entry);
116
117 /* Add theme song to theme-only playlist */
118 if (i == 0) this->standard_playlists[PLCH_THEMEONLY].push_back(entry);
119
120 /* Don't add the theme song to standard playlists */
121 if (i > 0) {
122 this->standard_playlists[PLCH_ALLMUSIC].push_back(entry);
123 uint theme = (i - 1) / NUM_SONGS_CLASS;
124 this->standard_playlists[PLCH_OLDSTYLE + theme].push_back(entry);
125 }
126 }
127
128 /* Load custom playlists
129 * Song index offsets are 1-based, zero indicates invalid/end-of-list value */
130 for (uint i = 0; i < NUM_SONGS_PLAYLIST; i++) {
131 if (_settings_client.music.custom_1[i] > 0 && _settings_client.music.custom_1[i] <= NUM_SONGS_AVAILABLE) {
132 PlaylistEntry entry(set, _settings_client.music.custom_1[i] - 1);
133 if (entry.IsValid()) this->standard_playlists[PLCH_CUSTOM1].push_back(entry);
134 }
135 if (_settings_client.music.custom_2[i] > 0 && _settings_client.music.custom_2[i] <= NUM_SONGS_AVAILABLE) {
136 PlaylistEntry entry(set, _settings_client.music.custom_2[i] - 1);
137 if (entry.IsValid()) this->standard_playlists[PLCH_CUSTOM2].push_back(entry);
138 }
139 }
140 }
141
146 void MusicSystem::ChangePlaylist(PlaylistChoices pl)
147 {
148 assert(pl < PLCH_MAX && pl >= PLCH_ALLMUSIC);
149
150 this->displayed_playlist = this->standard_playlists[pl];
151 this->active_playlist = this->displayed_playlist;
152 this->selected_playlist = pl;
153 this->playlist_position = 0;
154
155 if (this->selected_playlist != PLCH_THEMEONLY) _settings_client.music.playlist = this->selected_playlist;
156
157 if (_settings_client.music.shuffle) {
158 this->Shuffle();
159 /* Shuffle() will also Play() if necessary, only start once */
160 } else if (_settings_client.music.playing) {
161 this->Play();
162 }
163
164 InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0);
165 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
166 }
167
172 void MusicSystem::ChangeMusicSet(const std::string &set_name)
173 {
174 BaseMusic::SetSet(set_name);
175 BaseMusic::ini_set = set_name;
176
177 this->BuildPlaylists();
178 this->ChangePlaylist(this->selected_playlist);
179
180 InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS, 0, true);
181 }
182
184 void MusicSystem::Shuffle()
185 {
186 _settings_client.music.shuffle = true;
187
188 this->active_playlist = this->displayed_playlist;
189 for (size_t i = 0; i < this->active_playlist.size(); i++) {
190 size_t shuffle_index = InteractiveRandom() % (this->active_playlist.size() - i);
191 std::swap(this->active_playlist[i], this->active_playlist[i + shuffle_index]);
192 }
193
194 if (_settings_client.music.playing) this->Play();
195
196 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
197 }
198
200 void MusicSystem::Unshuffle()
201 {
202 _settings_client.music.shuffle = false;
203 this->active_playlist = this->displayed_playlist;
204
205 if (_settings_client.music.playing) this->Play();
206
207 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
208 }
209
211 void MusicSystem::Play()
212 {
213 /* Always set the playing flag, even if there is no music */
214 _settings_client.music.playing = true;
215 MusicDriver::GetInstance()->StopSong();
216 /* Make sure playlist_position is a valid index, if playlist has changed etc. */
217 this->ChangePlaylistPosition(0);
218
219 /* If there is no music, don't try to play it */
220 if (this->active_playlist.empty()) return;
221
222 MusicSongInfo song = this->active_playlist[this->playlist_position];
223 if (_game_mode == GM_MENU && this->selected_playlist == PLCH_THEMEONLY) song.loop = true;
224 MusicDriver::GetInstance()->PlaySong(song);
225
226 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
227 }
228
230 void MusicSystem::Stop()
231 {
232 MusicDriver::GetInstance()->StopSong();
233 _settings_client.music.playing = false;
234
235 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
236 }
237
239 void MusicSystem::Next()
240 {
241 this->ChangePlaylistPosition(+1);
242 if (_settings_client.music.playing) this->Play();
243
244 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
245 }
246
248 void MusicSystem::Prev()
249 {
250 this->ChangePlaylistPosition(-1);
251 if (_settings_client.music.playing) this->Play();
252
253 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
254 }
255
257 void MusicSystem::CheckStatus()
258 {
259 if ((_game_mode == GM_MENU) != (this->selected_playlist == PLCH_THEMEONLY)) {
260 /* Make sure the theme-only playlist is active when on the title screen, and not during gameplay */
261 this->ChangePlaylist((_game_mode == GM_MENU) ? PLCH_THEMEONLY : (PlaylistChoices)_settings_client.music.playlist);
262 }
263 if (this->active_playlist.empty()) return;
264 /* If we were supposed to be playing, but music has stopped, move to next song */
265 if (this->IsPlaying() && !MusicDriver::GetInstance()->IsSongPlaying()) this->Next();
266 }
267
269 bool MusicSystem::IsPlaying() const
270 {
271 return _settings_client.music.playing && !this->active_playlist.empty();
272 }
273
275 bool MusicSystem::IsShuffle() const
276 {
277 return _settings_client.music.shuffle;
278 }
279
281 MusicSystem::PlaylistEntry MusicSystem::GetCurrentSong() const
282 {
283 if (!this->IsPlaying()) return PlaylistEntry(BaseMusic::GetUsedSet(), 0);
284 return this->active_playlist[this->playlist_position];
285 }
286
288 bool MusicSystem::IsCustomPlaylist() const
289 {
290 return (this->selected_playlist == PLCH_CUSTOM1) || (this->selected_playlist == PLCH_CUSTOM2);
291 }
292
298 void MusicSystem::PlaylistAdd(size_t song_index)
299 {
300 if (!this->IsCustomPlaylist()) return;
301
302 /* Pick out song from the music set */
303 if (song_index >= this->music_set.size()) return;
304 PlaylistEntry entry = this->music_set[song_index];
305
306 /* Check for maximum length */
307 if (this->standard_playlists[this->selected_playlist].size() >= NUM_SONGS_PLAYLIST) return;
308
309 /* Add it to the appropriate playlist, and the display */
310 this->standard_playlists[this->selected_playlist].push_back(entry);
311 this->displayed_playlist.push_back(entry);
312
313 /* Add it to the active playlist, if playback is shuffled select a random position to add at */
314 if (this->active_playlist.empty()) {
315 this->active_playlist.push_back(entry);
316 if (this->IsPlaying()) this->Play();
317 } else if (this->IsShuffle()) {
318 /* Generate a random position between 0 and n (inclusive, new length) to insert at */
319 size_t maxpos = this->displayed_playlist.size();
320 size_t newpos = InteractiveRandom() % maxpos;
321 this->active_playlist.insert(this->active_playlist.begin() + newpos, entry);
322 /* Make sure to shift up the current playback position if the song was inserted before it */
323 if ((int)newpos <= this->playlist_position) this->playlist_position++;
324 } else {
325 this->active_playlist.push_back(entry);
326 }
327
328 this->SaveCustomPlaylist(this->selected_playlist);
329
330 InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0);
331 }
332
337 void MusicSystem::PlaylistRemove(size_t song_index)
338 {
339 if (!this->IsCustomPlaylist()) return;
340
341 Playlist &pl = this->standard_playlists[this->selected_playlist];
342 if (song_index >= pl.size()) return;
343
344 /* Remove from "simple" playlists */
345 PlaylistEntry song = pl[song_index];
346 pl.erase(pl.begin() + song_index);
347 this->displayed_playlist.erase(this->displayed_playlist.begin() + song_index);
348
349 /* Find in actual active playlist (may be shuffled) and remove,
350 * if it's the current song restart playback */
351 for (size_t i = 0; i < this->active_playlist.size(); i++) {
352 Playlist::iterator s2 = this->active_playlist.begin() + i;
353 if (s2->filename == song.filename && s2->cat_index == song.cat_index) {
354 this->active_playlist.erase(s2);
355 if ((int)i == this->playlist_position && this->IsPlaying()) this->Play();
356 break;
357 }
358 }
359
360 this->SaveCustomPlaylist(this->selected_playlist);
361
362 InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0);
363 }
364
369 void MusicSystem::PlaylistClear()
370 {
371 if (!this->IsCustomPlaylist()) return;
372
373 this->standard_playlists[this->selected_playlist].clear();
374 this->ChangePlaylist(this->selected_playlist);
375
376 this->SaveCustomPlaylist(this->selected_playlist);
377 }
378
384 void MusicSystem::ChangePlaylistPosition(int ofs)
385 {
386 if (this->active_playlist.empty()) {
387 this->playlist_position = 0;
388 } else {
389 this->playlist_position += ofs;
390 while (this->playlist_position >= (int)this->active_playlist.size()) this->playlist_position -= (int)this->active_playlist.size();
391 while (this->playlist_position < 0) this->playlist_position += (int)this->active_playlist.size();
392 }
393 }
394
399 void MusicSystem::SaveCustomPlaylist(PlaylistChoices pl)
400 {
401 byte *settings_pl;
402 if (pl == PLCH_CUSTOM1) {
403 settings_pl = _settings_client.music.custom_1;
404 } else if (pl == PLCH_CUSTOM2) {
405 settings_pl = _settings_client.music.custom_2;
406 } else {
407 return;
408 }
409
410 size_t num = 0;
411 MemSetT(settings_pl, 0, NUM_SONGS_PLAYLIST);
412
413 for (Playlist::const_iterator song = this->standard_playlists[pl].begin(); song != this->standard_playlists[pl].end(); ++song) {
414 /* Music set indices in the settings playlist are 1-based, 0 means unused slot */
415 settings_pl[num++] = (byte)song->set_index + 1;
416 }
417 }
418
419
424 void MusicLoop()
425 {
426 _music.CheckStatus();
427 }
428
433 void ChangeMusicSet(int index)
434 {
435 if (BaseMusic::GetIndexOfUsedSet() == index) return;
436 _music.ChangeMusicSet(BaseMusic::GetSet(index)->name);
437 }
438
443 void InitializeMusic()
444 {
445 _music.BuildPlaylists();
446 }
447
448
449 struct MusicTrackSelectionWindow : public Window {
450 MusicTrackSelectionWindow(WindowDesc *desc, WindowNumber number) : Window(desc)
451 {
452 this->InitNested(number);
453 this->LowerWidget(WID_MTS_LIST_LEFT);
454 this->LowerWidget(WID_MTS_LIST_RIGHT);
455 this->SetWidgetDisabledState(WID_MTS_CLEAR, _settings_client.music.playlist <= 3);
456 this->LowerWidget(WID_MTS_ALL + _settings_client.music.playlist);
457 }
458
459 void SetStringParameters(int widget) const override
460 {
461 switch (widget) {
462 case WID_MTS_PLAYLIST:
463 SetDParam(0, STR_MUSIC_PLAYLIST_ALL + _settings_client.music.playlist);
464 break;
465 case WID_MTS_CAPTION:
466 SetDParamStr(0, BaseMusic::GetUsedSet()->name);
467 break;
468 }
469 }
470
476 void OnInvalidateData(int data = 0, bool gui_scope = true) override
477 {
478 if (!gui_scope) return;
479 for (int i = 0; i < 6; i++) {
480 this->SetWidgetLoweredState(WID_MTS_ALL + i, i == _settings_client.music.playlist);
481 }
482 this->SetWidgetDisabledState(WID_MTS_CLEAR, _settings_client.music.playlist <= 3);
483 this->SetDirty();
484 }
485
486 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
487 {
488 switch (widget) {
489 case WID_MTS_PLAYLIST: {
490 Dimension d = {0, 0};
491
492 for (int i = 0; i < 6; i++) {
493 SetDParam(0, STR_MUSIC_PLAYLIST_ALL + i);
494 d = maxdim(d, GetStringBoundingBox(STR_PLAYLIST_PROGRAM));
495 }
496 d.width += padding.width;
497 d.height += padding.height;
498 *size = maxdim(*size, d);
499 break;
500 }
501
502 case WID_MTS_LIST_LEFT: case WID_MTS_LIST_RIGHT: {
503 Dimension d = {0, 0};
504
505 for (MusicSystem::Playlist::const_iterator song = _music.music_set.begin(); song != _music.music_set.end(); ++song) {
506 SetDParam(0, song->tracknr);
507 SetDParam(1, 2);
508 SetDParamStr(2, song->songname);
509 Dimension d2 = GetStringBoundingBox(STR_PLAYLIST_TRACK_NAME);
510 d.width = std::max(d.width, d2.width);
511 d.height += d2.height;
512 }
513 d.width += padding.width;
514 d.height += padding.height;
515 *size = maxdim(*size, d);
516 break;
517 }
518 }
519 }
520
521 void DrawWidget(const Rect &r, int widget) const override
522 {
523 switch (widget) {
524 case WID_MTS_LIST_LEFT: {
525 GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_BLACK);
526
527 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
528 for (MusicSystem::Playlist::const_iterator song = _music.music_set.begin(); song != _music.music_set.end(); ++song) {
529 SetDParam(0, song->tracknr);
530 SetDParam(1, 2);
531 SetDParamStr(2, song->songname);
532 DrawString(tr, STR_PLAYLIST_TRACK_NAME);
533 tr.top += FONT_HEIGHT_SMALL;
534 }
535 break;
536 }
537
538 case WID_MTS_LIST_RIGHT: {
539 GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_BLACK);
540
541 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
542 for (MusicSystem::Playlist::const_iterator song = _music.active_playlist.begin(); song != _music.active_playlist.end(); ++song) {
543 SetDParam(0, song->tracknr);
544 SetDParam(1, 2);
545 SetDParamStr(2, song->songname);
546 DrawString(tr, STR_PLAYLIST_TRACK_NAME);
547 tr.top += FONT_HEIGHT_SMALL;
548 }
549 break;
550 }
551 }
552 }
553
554 void OnClick(Point pt, int widget, int click_count) override
555 {
556 switch (widget) {
557 case WID_MTS_LIST_LEFT: { // add to playlist
558 int y = this->GetRowFromWidget(pt.y, widget, 0, FONT_HEIGHT_SMALL);
559 _music.PlaylistAdd(y);
560 break;
561 }
562
563 case WID_MTS_LIST_RIGHT: { // remove from playlist
564 int y = this->GetRowFromWidget(pt.y, widget, 0, FONT_HEIGHT_SMALL);
565 _music.PlaylistRemove(y);
566 break;
567 }
568
569 case WID_MTS_MUSICSET: {
570 int selected = 0;
571 ShowDropDownList(this, BuildMusicSetDropDownList(&selected), selected, widget, 0, true, false);
572 break;
573 }
574
575 case WID_MTS_CLEAR: // clear
576 _music.PlaylistClear();
577 break;
578
579 case WID_MTS_ALL: case WID_MTS_OLD: case WID_MTS_NEW:
580 case WID_MTS_EZY: case WID_MTS_CUSTOM1: case WID_MTS_CUSTOM2: // set playlist
581 _music.ChangePlaylist((MusicSystem::PlaylistChoices)(widget - WID_MTS_ALL));
582 break;
583 }
584 }
585
586 void OnDropdownSelect(int widget, int index) override
587 {
588 switch (widget) {
589 case WID_MTS_MUSICSET:
590 ChangeMusicSet(index);
591 break;
592 default:
593 NOT_REACHED();
594 }
595 }
596 };
597
598 static const NWidgetPart _nested_music_track_selection_widgets[] = {
599 NWidget(NWID_HORIZONTAL),
600 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
601 NWidget(WWT_CAPTION, COLOUR_GREY, WID_MTS_CAPTION), SetDataTip(STR_PLAYLIST_MUSIC_SELECTION_SETNAME, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
602 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_MTS_MUSICSET), SetDataTip(STR_PLAYLIST_CHANGE_SET, STR_PLAYLIST_TOOLTIP_CHANGE_SET),
603 EndContainer(),
604 NWidget(WWT_PANEL, COLOUR_GREY),
605 NWidget(NWID_HORIZONTAL), SetPIP(2, 4, 2),
606 /* Left panel. */
607 NWidget(NWID_VERTICAL),
608 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_PLAYLIST_TRACK_INDEX, STR_NULL),
609 NWidget(WWT_PANEL, COLOUR_GREY, WID_MTS_LIST_LEFT), SetMinimalSize(180, 194), SetDataTip(0x0, STR_PLAYLIST_TOOLTIP_CLICK_TO_ADD_TRACK), EndContainer(),
610 NWidget(NWID_SPACER), SetMinimalSize(0, 2),
611 EndContainer(),
612 /* Middle buttons. */
613 NWidget(NWID_VERTICAL),
614 NWidget(NWID_SPACER), SetMinimalSize(60, 30), // Space above the first button from the title bar.
615 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_ALL), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_ALL, STR_MUSIC_TOOLTIP_SELECT_ALL_TRACKS_PROGRAM),
616 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_OLD), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_OLD_STYLE, STR_MUSIC_TOOLTIP_SELECT_OLD_STYLE_MUSIC),
617 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_NEW), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_NEW_STYLE, STR_MUSIC_TOOLTIP_SELECT_NEW_STYLE_MUSIC),
618 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_EZY), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_EZY_STREET, STR_MUSIC_TOOLTIP_SELECT_EZY_STREET_STYLE),
619 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_CUSTOM1), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_CUSTOM_1, STR_MUSIC_TOOLTIP_SELECT_CUSTOM_1_USER_DEFINED),
620 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_CUSTOM2), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_CUSTOM_2, STR_MUSIC_TOOLTIP_SELECT_CUSTOM_2_USER_DEFINED),
621 NWidget(NWID_SPACER), SetMinimalSize(0, 16), // Space above 'clear' button
622 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_MTS_CLEAR), SetFill(1, 0), SetDataTip(STR_PLAYLIST_CLEAR, STR_PLAYLIST_TOOLTIP_CLEAR_CURRENT_PROGRAM_CUSTOM1),
623 NWidget(NWID_SPACER), SetFill(0, 1),
624 EndContainer(),
625 /* Right panel. */
626 NWidget(NWID_VERTICAL),
627 NWidget(WWT_LABEL, COLOUR_GREY, WID_MTS_PLAYLIST), SetDataTip(STR_PLAYLIST_PROGRAM, STR_NULL),
628 NWidget(WWT_PANEL, COLOUR_GREY, WID_MTS_LIST_RIGHT), SetMinimalSize(180, 194), SetDataTip(0x0, STR_PLAYLIST_TOOLTIP_CLICK_TO_REMOVE_TRACK), EndContainer(),
629 NWidget(NWID_SPACER), SetMinimalSize(0, 2),
630 EndContainer(),
631 EndContainer(),
632 EndContainer(),
633 };
634
635 static WindowDesc _music_track_selection_desc(
636 WDP_AUTO, "music_track", 0, 0,
637 WC_MUSIC_TRACK_SELECTION, WC_NONE,
638 0,
639 _nested_music_track_selection_widgets, lengthof(_nested_music_track_selection_widgets)
640 );
641
642 static void ShowMusicTrackSelection()
643 {
644 AllocateWindowDescFront<MusicTrackSelectionWindow>(&_music_track_selection_desc, 0);
645 }
646
647 struct MusicWindow : public Window {
648 MusicWindow(WindowDesc *desc, WindowNumber number) : Window(desc)
649 {
650 this->InitNested(number);
651 this->LowerWidget(_settings_client.music.playlist + WID_M_ALL);
652 this->SetWidgetLoweredState(WID_M_SHUFFLE, _settings_client.music.shuffle);
653
654 UpdateDisabledButtons();
655 }
656
657 void UpdateDisabledButtons()
658 {
659 /* Disable music control widgets if there is no music
660 * -- except Programme button! So you can still select a music set. */
661 this->SetWidgetsDisabledState(
662 BaseMusic::GetUsedSet()->num_available == 0,
663 WID_M_PREV, WID_M_NEXT, WID_M_STOP, WID_M_PLAY, WID_M_SHUFFLE,
664 WID_M_ALL, WID_M_OLD, WID_M_NEW, WID_M_EZY, WID_M_CUSTOM1, WID_M_CUSTOM2,
665 WIDGET_LIST_END
666 );
667 }
668
669 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
670 {
671 switch (widget) {
672 /* Make sure that WID_M_SHUFFLE and WID_M_PROGRAMME have the same size.
673 * This can't be done by using NC_EQUALSIZE as the WID_M_INFO is
674 * between those widgets and of different size. */
675 case WID_M_SHUFFLE: case WID_M_PROGRAMME: {
676 Dimension d = maxdim(GetStringBoundingBox(STR_MUSIC_PROGRAM), GetStringBoundingBox(STR_MUSIC_SHUFFLE));
677 d.width += padding.width;
678 d.height += padding.height;
679 *size = maxdim(*size, d);
680 break;
681 }
682
683 case WID_M_TRACK_NR: {
684 Dimension d = GetStringBoundingBox(STR_MUSIC_TRACK_NONE);
685 d.width += padding.width;
686 d.height += padding.height;
687 *size = maxdim(*size, d);
688 break;
689 }
690
691 case WID_M_TRACK_NAME: {
692 Dimension d = GetStringBoundingBox(STR_MUSIC_TITLE_NONE);
693 for (MusicSystem::Playlist::const_iterator song = _music.music_set.begin(); song != _music.music_set.end(); ++song) {
694 SetDParamStr(0, song->songname);
695 d = maxdim(d, GetStringBoundingBox(STR_MUSIC_TITLE_NAME));
696 }
697 d.width += padding.width;
698 d.height += padding.height;
699 *size = maxdim(*size, d);
700 break;
701 }
702
703 /* Hack-ish: set the proper widget data; only needs to be done once
704 * per (Re)Init as that's the only time the language changes. */
705 case WID_M_PREV: this->GetWidget<NWidgetCore>(WID_M_PREV)->widget_data = _current_text_dir == TD_RTL ? SPR_IMG_SKIP_TO_NEXT : SPR_IMG_SKIP_TO_PREV; break;
706 case WID_M_NEXT: this->GetWidget<NWidgetCore>(WID_M_NEXT)->widget_data = _current_text_dir == TD_RTL ? SPR_IMG_SKIP_TO_PREV : SPR_IMG_SKIP_TO_NEXT; break;
707 case WID_M_PLAY: this->GetWidget<NWidgetCore>(WID_M_PLAY)->widget_data = _current_text_dir == TD_RTL ? SPR_IMG_PLAY_MUSIC_RTL : SPR_IMG_PLAY_MUSIC; break;
708 }
709 }
710
711 void DrawWidget(const Rect &r, int widget) const override
712 {
713 switch (widget) {
714 case WID_M_TRACK_NR: {
715 GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel.left, WidgetDimensions::scaled.bevel.top, 0, WidgetDimensions::scaled.bevel.bottom), PC_BLACK);
716 if (BaseMusic::GetUsedSet()->num_available == 0) {
717 break;
718 }
719 StringID str = STR_MUSIC_TRACK_NONE;
720 if (_music.IsPlaying()) {
721 SetDParam(0, _music.GetCurrentSong().tracknr);
722 SetDParam(1, 2);
723 str = STR_MUSIC_TRACK_DIGIT;
724 }
725 DrawString(r.Shrink(WidgetDimensions::scaled.framerect), str);
726 break;
727 }
728
729 case WID_M_TRACK_NAME: {
730 GfxFillRect(r.Shrink(0, WidgetDimensions::scaled.bevel.top, WidgetDimensions::scaled.bevel.right, WidgetDimensions::scaled.bevel.bottom), PC_BLACK);
731 StringID str = STR_MUSIC_TITLE_NONE;
732 MusicSystem::PlaylistEntry entry(_music.GetCurrentSong());
733 if (BaseMusic::GetUsedSet()->num_available == 0) {
734 str = STR_MUSIC_TITLE_NOMUSIC;
735 } else if (_music.IsPlaying()) {
736 str = STR_MUSIC_TITLE_NAME;
737 SetDParamStr(0, entry.songname);
738 }
739 DrawString(r.Shrink(WidgetDimensions::scaled.framerect), str, TC_FROMSTRING, SA_HOR_CENTER);
740 break;
741 }
742
743 case WID_M_MUSIC_VOL:
744 DrawSliderWidget(r, 0, INT8_MAX, _settings_client.music.music_vol, {});
745 break;
746
747 case WID_M_EFFECT_VOL:
748 DrawSliderWidget(r, 0, INT8_MAX, _settings_client.music.effect_vol, {});
749 break;
750 }
751 }
752
758 void OnInvalidateData(int data = 0, bool gui_scope = true) override
759 {
760 if (!gui_scope) return;
761 for (int i = 0; i < 6; i++) {
762 this->SetWidgetLoweredState(WID_M_ALL + i, i == _settings_client.music.playlist);
763 }
764
765 UpdateDisabledButtons();
766
767 this->SetDirty();
768 }
769
770 void OnClick(Point pt, int widget, int click_count) override
771 {
772 switch (widget) {
773 case WID_M_PREV: // skip to prev
774 _music.Prev();
775 break;
776
777 case WID_M_NEXT: // skip to next
778 _music.Next();
779 break;
780
781 case WID_M_STOP: // stop playing
782 _music.Stop();
783 break;
784
785 case WID_M_PLAY: // start playing
786 _music.Play();
787 break;
788
789 case WID_M_MUSIC_VOL: case WID_M_EFFECT_VOL: { // volume sliders
790 byte &vol = (widget == WID_M_MUSIC_VOL) ? _settings_client.music.music_vol : _settings_client.music.effect_vol;
791 if (ClickSliderWidget(this->GetWidget<NWidgetBase>(widget)->GetCurrentRect(), pt, 0, INT8_MAX, vol)) {
792 if (widget == WID_M_MUSIC_VOL) {
793 MusicDriver::GetInstance()->SetVolume(vol);
794 } else {
795 SetEffectVolume(vol);
796 }
797 this->SetWidgetDirty(widget);
798 SetWindowClassesDirty(WC_GAME_OPTIONS);
799 }
800
801 if (click_count > 0) this->mouse_capture_widget = widget;
802 break;
803 }
804
805 case WID_M_SHUFFLE: // toggle shuffle
806 if (_music.IsShuffle()) {
807 _music.Unshuffle();
808 } else {
809 _music.Shuffle();
810 }
811 this->SetWidgetLoweredState(WID_M_SHUFFLE, _music.IsShuffle());
812 this->SetWidgetDirty(WID_M_SHUFFLE);
813 break;
814
815 case WID_M_PROGRAMME: // show track selection
816 ShowMusicTrackSelection();
817 break;
818
819 case WID_M_ALL: case WID_M_OLD: case WID_M_NEW:
820 case WID_M_EZY: case WID_M_CUSTOM1: case WID_M_CUSTOM2: // playlist
821 _music.ChangePlaylist((MusicSystem::PlaylistChoices)(widget - WID_M_ALL));
822 break;
823 }
824 }
825 };
826
827 static const NWidgetPart _nested_music_window_widgets[] = {
828 NWidget(NWID_HORIZONTAL),
829 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
830 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_MUSIC_JAZZ_JUKEBOX_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
831 NWidget(WWT_SHADEBOX, COLOUR_GREY),
832 NWidget(WWT_STICKYBOX, COLOUR_GREY),
833 EndContainer(),
834
835 NWidget(NWID_HORIZONTAL),
836 NWidget(NWID_VERTICAL),
837 NWidget(WWT_PANEL, COLOUR_GREY, -1), SetFill(1, 1), EndContainer(),
838 NWidget(NWID_HORIZONTAL),
839 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_M_PREV), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_SKIP_TO_PREV, STR_MUSIC_TOOLTIP_SKIP_TO_PREVIOUS_TRACK),
840 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_M_NEXT), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_SKIP_TO_NEXT, STR_MUSIC_TOOLTIP_SKIP_TO_NEXT_TRACK_IN_SELECTION),
841 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_M_STOP), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_STOP_MUSIC, STR_MUSIC_TOOLTIP_STOP_PLAYING_MUSIC),
842 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_M_PLAY), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_PLAY_MUSIC, STR_MUSIC_TOOLTIP_START_PLAYING_MUSIC),
843 EndContainer(),
844 NWidget(WWT_PANEL, COLOUR_GREY, -1), SetFill(1, 1), EndContainer(),
845 EndContainer(),
846 NWidget(WWT_PANEL, COLOUR_GREY, WID_M_SLIDERS),
847 NWidget(NWID_HORIZONTAL), SetPIP(4, 0, 4),
848 NWidget(NWID_VERTICAL),
849 NWidget(WWT_LABEL, COLOUR_GREY, -1), SetFill(1, 0), SetDataTip(STR_MUSIC_MUSIC_VOLUME, STR_NULL),
850 NWidget(WWT_EMPTY, COLOUR_GREY, WID_M_MUSIC_VOL), SetMinimalSize(67, 0), SetPadding(2), SetMinimalTextLines(1, 0), SetFill(1, 0), SetDataTip(0x0, STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
851 EndContainer(),
852 NWidget(NWID_VERTICAL),
853 NWidget(WWT_LABEL, COLOUR_GREY, -1), SetFill(1, 0), SetDataTip(STR_MUSIC_EFFECTS_VOLUME, STR_NULL),
854 NWidget(WWT_EMPTY, COLOUR_GREY, WID_M_EFFECT_VOL), SetMinimalSize(67, 0), SetPadding(2), SetMinimalTextLines(1, 0), SetFill(1, 0), SetDataTip(0x0, STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
855 EndContainer(),
856 EndContainer(),
857 EndContainer(),
858 EndContainer(),
859 NWidget(WWT_PANEL, COLOUR_GREY, WID_M_BACKGROUND),
860 NWidget(NWID_HORIZONTAL), SetPIP(6, 0, 6),
861 NWidget(NWID_VERTICAL),
862 NWidget(NWID_SPACER), SetFill(0, 1),
863 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_SHUFFLE), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_SHUFFLE, STR_MUSIC_TOOLTIP_TOGGLE_PROGRAM_SHUFFLE),
864 NWidget(NWID_SPACER), SetFill(0, 1),
865 EndContainer(),
866 NWidget(NWID_VERTICAL), SetPadding(0, 0, 3, 3),
867 NWidget(WWT_LABEL, COLOUR_GREY, WID_M_TRACK), SetFill(0, 0), SetDataTip(STR_MUSIC_TRACK, STR_NULL),
868 NWidget(WWT_PANEL, COLOUR_GREY, WID_M_TRACK_NR), EndContainer(),
869 EndContainer(),
870 NWidget(NWID_VERTICAL), SetPadding(0, 3, 3, 0),
871 NWidget(WWT_LABEL, COLOUR_GREY, WID_M_TRACK_TITLE), SetFill(1, 0), SetDataTip(STR_MUSIC_XTITLE, STR_NULL),
872 NWidget(WWT_PANEL, COLOUR_GREY, WID_M_TRACK_NAME), SetFill(1, 0), EndContainer(),
873 EndContainer(),
874 NWidget(NWID_VERTICAL),
875 NWidget(NWID_SPACER), SetFill(0, 1),
876 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_M_PROGRAMME), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_PROGRAM, STR_MUSIC_TOOLTIP_SHOW_MUSIC_TRACK_SELECTION),
877 NWidget(NWID_SPACER), SetFill(0, 1),
878 EndContainer(),
879 EndContainer(),
880 EndContainer(),
881 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
882 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_ALL), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_ALL, STR_MUSIC_TOOLTIP_SELECT_ALL_TRACKS_PROGRAM),
883 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_OLD), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_OLD_STYLE, STR_MUSIC_TOOLTIP_SELECT_OLD_STYLE_MUSIC),
884 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_NEW), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_NEW_STYLE, STR_MUSIC_TOOLTIP_SELECT_NEW_STYLE_MUSIC),
885 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_EZY), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_EZY_STREET, STR_MUSIC_TOOLTIP_SELECT_EZY_STREET_STYLE),
886 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_CUSTOM1), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_CUSTOM_1, STR_MUSIC_TOOLTIP_SELECT_CUSTOM_1_USER_DEFINED),
887 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_CUSTOM2), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_CUSTOM_2, STR_MUSIC_TOOLTIP_SELECT_CUSTOM_2_USER_DEFINED),
888 EndContainer(),
889 };
890
891 static WindowDesc _music_window_desc(
892 WDP_AUTO, "music", 0, 0,
893 WC_MUSIC_WINDOW, WC_NONE,
894 0,
895 _nested_music_window_widgets, lengthof(_nested_music_window_widgets)
896 );
897
898 void ShowMusicWindow()
899 {
900 AllocateWindowDescFront<MusicWindow>(&_music_window_desc, 0);
901 }
MusicWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: music_gui.cpp:669
MusicSystem::Shuffle
void Shuffle()
Enable shuffle mode and restart playback.
Definition: music_gui.cpp:184
WID_MTS_CUSTOM2
@ WID_MTS_CUSTOM2
Custom2 button.
Definition: music_widget.h:25
MusicSystem::ChangePlaylist
void ChangePlaylist(PlaylistChoices pl)
Switch to another playlist, or reload the current one.
Definition: music_gui.cpp:146
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3252
sound_func.h
MusicSystem::PlaylistClear
void PlaylistClear()
Remove all songs from the current custom playlist.
Definition: music_gui.cpp:369
MusicSystem
Definition: music_gui.cpp:40
BaseMedia< MusicSet >::GetIndexOfUsedSet
static int GetIndexOfUsedSet()
Get the index of the currently active graphics set.
Definition: base_media_func.h:326
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1141
MusicTrackSelectionWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: music_gui.cpp:486
dropdown_func.h
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
WID_MTS_CUSTOM1
@ WID_MTS_CUSTOM1
Custom1 button.
Definition: music_widget.h:24
MusicDriver::PlaySong
virtual void PlaySong(const MusicSongInfo &song)=0
Play a particular song.
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
MusicDriver::SetVolume
virtual void SetVolume(byte vol)=0
Set the volume, if possible.
MusicSystem::IsShuffle
bool IsShuffle() const
Is shuffle mode enabled?
Definition: music_gui.cpp:275
MusicSystem::IsCustomPlaylist
bool IsCustomPlaylist() const
Is one of the custom playlists selected?
Definition: music_gui.cpp:288
MusicSettings::shuffle
bool shuffle
Whether to shuffle the music.
Definition: settings_type.h:231
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:55
NUM_SONGS_AVAILABLE
static const uint NUM_SONGS_AVAILABLE
Maximum number of songs in the full playlist; theme song + the classes.
Definition: base_media_base.h:276
WID_M_TRACK_NR
@ WID_M_TRACK_NR
Track number.
Definition: music_widget.h:40
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
WID_MTS_NEW
@ WID_MTS_NEW
New button.
Definition: music_widget.h:22
MusicSystem::PlaylistAdd
void PlaylistAdd(size_t song_index)
Append a song to a custom playlist.
Definition: music_gui.cpp:298
MusicSongInfo::loop
bool loop
song should play in a tight loop if possible, never ending
Definition: base_media_base.h:297
music_widget.h
zoom_func.h
base_media_base.h
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:644
WID_M_CUSTOM1
@ WID_M_CUSTOM1
Custom1 button.
Definition: music_widget.h:49
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
MusicTrackSelectionWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: music_gui.cpp:459
MusicSystem::Play
void Play()
Start/restart playback at current song.
Definition: music_gui.cpp:211
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:713
WC_MUSIC_WINDOW
@ WC_MUSIC_WINDOW
Music window; Window numbers:
Definition: window_type.h:589
MusicWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: music_gui.cpp:758
MusicLoop
void MusicLoop()
Check music playback status and start/stop/song-finished.
Definition: music_gui.cpp:424
MusicSystem::Prev
void Prev()
Skip to previous track.
Definition: music_gui.cpp:248
MusicTrackSelectionWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: music_gui.cpp:476
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1810
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:973
MusicSystem::displayed_playlist
Playlist displayed_playlist
current playlist as displayed in GUI, never in shuffled order
Definition: music_gui.cpp:62
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1109
MusicSettings::playing
bool playing
Whether music is playing.
Definition: settings_type.h:230
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
WID_M_TRACK_NAME
@ WID_M_TRACK_NAME
Track name.
Definition: music_widget.h:42
MusicSystem::Next
void Next()
Skip to next track.
Definition: music_gui.cpp:239
MusicWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: music_gui.cpp:770
WN_GAME_OPTIONS_GAME_OPTIONS
@ WN_GAME_OPTIONS_GAME_OPTIONS
Game options.
Definition: window_type.h:19
gfx_func.h
BaseMedia< MusicSet >::ini_set
static std::string ini_set
The set as saved in the config file.
Definition: base_media_base.h:179
WindowDesc
High level window description.
Definition: window_gui.h:102
WID_MTS_CAPTION
@ WID_MTS_CAPTION
Window caption.
Definition: music_widget.h:15
WID_M_EZY
@ WID_M_EZY
Ezy button.
Definition: music_widget.h:48
window_gui.h
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:467
MusicTrackSelectionWindow
Definition: music_gui.cpp:449
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:90
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
MusicSystem::PlaylistEntry
Definition: music_gui.cpp:41
MusicDriver::GetInstance
static MusicDriver * GetInstance()
Get the currently active instance of the music driver.
Definition: music_driver.hpp:46
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1800
MusicWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: music_gui.cpp:711
MusicSystem::CheckStatus
void CheckStatus()
Check that music is playing if it should, and that appropriate playlist is active for game/main menu.
Definition: music_gui.cpp:257
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1004
MusicSongInfo::songname
char songname[32]
name of song displayed in UI
Definition: base_media_base.h:292
WID_MTS_MUSICSET
@ WID_MTS_MUSICSET
Music set selection.
Definition: music_widget.h:19
MusicSystem::ChangeMusicSet
void ChangeMusicSet(const std::string &set_name)
Change to named music set, and reset playback.
Definition: music_gui.cpp:172
WID_M_MUSIC_VOL
@ WID_M_MUSIC_VOL
Music volume.
Definition: music_widget.h:36
WID_M_BACKGROUND
@ WID_M_BACKGROUND
Background of the window.
Definition: music_widget.h:38
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
MusicSystem::BuildPlaylists
void BuildPlaylists()
Rebuild all playlists for the current music set.
Definition: music_gui.cpp:102
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:450
MusicSystem::IsPlaying
bool IsPlaying() const
Is the player getting music right now?
Definition: music_gui.cpp:269
WID_M_STOP
@ WID_M_STOP
Stop button.
Definition: music_widget.h:33
dropdown_type.h
MusicSongInfo
Metadata about a music track.
Definition: base_media_base.h:291
MusicSystem::Unshuffle
void Unshuffle()
Disable shuffle and restart playback.
Definition: music_gui.cpp:200
MusicSettings::custom_2
byte custom_2[33]
The order of the second custom playlist.
Definition: settings_type.h:229
MusicTrackSelectionWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: music_gui.cpp:554
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
DrawSliderWidget
void DrawSliderWidget(Rect r, int min_value, int max_value, int value, const std::map< int, StringID > &labels)
Draw a slider widget with knob at given value.
Definition: slider.cpp:29
safeguards.h
music_driver.hpp
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:67
MusicSet
All data of a music set.
Definition: base_media_base.h:303
MusicSettings::playlist
byte playlist
The playlist (number) to play.
Definition: settings_type.h:225
WID_MTS_LIST_LEFT
@ WID_MTS_LIST_LEFT
Left button.
Definition: music_widget.h:16
settings_type.h
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
error.h
WID_M_PLAY
@ WID_M_PLAY
Play button.
Definition: music_widget.h:34
stdafx.h
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:242
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:116
WID_M_ALL
@ WID_M_ALL
All button.
Definition: music_widget.h:45
Window::mouse_capture_widget
int mouse_capture_widget
Widgetindex of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse captu...
Definition: window_gui.h:264
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:336
NUM_SONGS_CLASS
static const uint NUM_SONGS_CLASS
Maximum number of songs in the 'class' playlists.
Definition: base_media_base.h:272
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
FONT_HEIGHT_SMALL
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:203
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
string_func.h
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:105
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:606
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1094
strings_func.h
WID_MTS_ALL
@ WID_MTS_ALL
All button.
Definition: music_widget.h:20
WID_M_NEXT
@ WID_M_NEXT
Next button.
Definition: music_widget.h:32
InitializeMusic
void InitializeMusic()
Prepare the music system for use.
Definition: music_gui.cpp:443
WID_M_TRACK
@ WID_M_TRACK
Track playing.
Definition: music_widget.h:39
WID_M_NEW
@ WID_M_NEW
New button.
Definition: music_widget.h:47
NUM_SONGS_PLAYLIST
static const uint NUM_SONGS_PLAYLIST
Maximum number of songs in the (custom) playlist.
Definition: base_media_base.h:279
WIDGET_LIST_END
static const int WIDGET_LIST_END
indicate the end of widgets' list for vararg functions
Definition: widget_type.h:20
_music
static IDirectMusic * _music
The direct music object manages buffers and ports.
Definition: dmusic.cpp:144
MusicWindow
Definition: music_gui.cpp:647
WID_MTS_CLEAR
@ WID_MTS_CLEAR
Clear button.
Definition: music_widget.h:26
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1227
MusicSystem::SaveCustomPlaylist
void SaveCustomPlaylist(PlaylistChoices pl)
Save a custom playlist to settings after modification.
Definition: music_gui.cpp:399
geometry_func.hpp
ClickSliderWidget
bool ClickSliderWidget(Rect r, Point pt, int min_value, int max_value, int &value)
Handle click on a slider widget to change the value.
Definition: slider.cpp:79
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1012
MusicTrackSelectionWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: music_gui.cpp:586
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
Window::SetWidgetsDisabledState
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Definition: window.cpp:558
WID_M_OLD
@ WID_M_OLD
Old button.
Definition: music_widget.h:46
WID_M_SHUFFLE
@ WID_M_SHUFFLE
Shuffle button.
Definition: music_widget.h:43
WidgetDimensions::bevel
RectPadding bevel
Widths of bevel border.
Definition: window_gui.h:45
openttd.h
MusicSystem::GetCurrentSong
PlaylistEntry GetCurrentSong() const
Return the current song, or a dummy if none.
Definition: music_gui.cpp:281
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
WID_M_EFFECT_VOL
@ WID_M_EFFECT_VOL
Effect volume.
Definition: music_widget.h:37
WID_MTS_PLAYLIST
@ WID_MTS_PLAYLIST
Playlist.
Definition: music_widget.h:17
WidgetDimensions::framerect
RectPadding framerect
Offsets within frame area.
Definition: window_gui.h:47
WID_MTS_LIST_RIGHT
@ WID_MTS_LIST_RIGHT
Right button.
Definition: music_widget.h:18
WID_M_TRACK_TITLE
@ WID_M_TRACK_TITLE
Track title.
Definition: music_widget.h:41
MusicSongInfo::filename
const char * filename
file on disk containing song (when used in MusicSet class, this pointer is owned by MD5File object fo...
Definition: base_media_base.h:294
window_func.h
BaseMedia< MusicSet >::GetSet
static const MusicSet * GetSet(int index)
Get the name of the graphics set at the specified index.
Definition: base_media_func.h:342
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
MusicSettings::effect_vol
byte effect_vol
The requested effects volume.
Definition: settings_type.h:227
WID_MTS_EZY
@ WID_MTS_EZY
Ezy button.
Definition: music_widget.h:23
WID_M_PROGRAMME
@ WID_M_PROGRAMME
Program button.
Definition: music_widget.h:44
random_func.hpp
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1189
MemSetT
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
Definition: mem_func.hpp:49
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1078
WID_M_PREV
@ WID_M_PREV
Previous button.
Definition: music_widget.h:31
MusicTrackSelectionWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: music_gui.cpp:521
MusicSystem::PlaylistEntry::set
const MusicSet * set
music set the song comes from
Definition: music_gui.cpp:42
MusicSystem::PlaylistEntry::set_index
uint set_index
index of song in set
Definition: music_gui.cpp:43
MusicSystem::Stop
void Stop()
Stop playback and set flag that we don't intend to play music.
Definition: music_gui.cpp:230
Window
Data structure for an opened window.
Definition: window_gui.h:213
BaseMedia< MusicSet >::GetUsedSet
static const MusicSet * GetUsedSet()
Return the used set.
Definition: base_media_func.h:357
MusicSystem::ChangePlaylistPosition
void ChangePlaylistPosition(int ofs)
Change playlist position pointer by the given offset, making sure to keep it within valid range.
Definition: music_gui.cpp:384
MusicSystem::active_playlist
Playlist active_playlist
current play order of songs, including any shuffle
Definition: music_gui.cpp:61
settings_gui.h
WID_MTS_OLD
@ WID_MTS_OLD
Old button.
Definition: music_widget.h:21
WID_M_SLIDERS
@ WID_M_SLIDERS
Sliders.
Definition: music_widget.h:35
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:619
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
Window::LowerWidget
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:403
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3180
Window::GetRowFromWidget
int GetRowFromWidget(int clickpos, int widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
Definition: window.cpp:212
ClientSettings::music
MusicSettings music
settings related to music/sound
Definition: settings_type.h:608
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:382
ChangeMusicSet
void ChangeMusicSet(int index)
Change the configured music set and reset playback.
Definition: music_gui.cpp:433
MusicSettings::music_vol
byte music_vol
The requested music volume.
Definition: settings_type.h:226
MusicSystem::music_set
Playlist music_set
all songs in current music set, in set order
Definition: music_gui.cpp:63
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:49
MusicSongInfo::cat_index
int cat_index
entry index in CAT file, for filetype==MTT_MPSMIDI
Definition: base_media_base.h:296
MusicSettings::custom_1
byte custom_1[33]
The order of the first custom playlist.
Definition: settings_type.h:228
WID_M_CUSTOM2
@ WID_M_CUSTOM2
Custom2 button.
Definition: music_widget.h:50
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:297
WC_MUSIC_TRACK_SELECTION
@ WC_MUSIC_TRACK_SELECTION
Music track selection; Window numbers:
Definition: window_type.h:595
MusicSystem::PlaylistRemove
void PlaylistRemove(size_t song_index)
Remove a song from a custom playlist.
Definition: music_gui.cpp:337
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
mixer.h
SetMinimalTextLines
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1030
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:68
MusicDriver::StopSong
virtual void StopSong()=0
Stop playing the current song.
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
BaseMedia< MusicSet >::SetSet
static bool SetSet(const std::string &name)
Set the set to be used.
Definition: base_media_func.h:228