OpenTTD Source: src/music_gui.cpp Source File

OpenTTD Source 14.0-beta1

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