OpenTTD Source: src/music_gui.cpp Source File

OpenTTD Source 1.11.0-RC1

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
30 #include "widgets/music_widget.h"
31
32 #include "table/strings.h"
33 #include "table/sprites.h"
34
35 #include "safeguards.h"
36
37
38 struct MusicSystem {
39 struct PlaylistEntry : MusicSongInfo {
40 const MusicSet *set;
41 uint set_index;
42
43 PlaylistEntry(const MusicSet *set, uint set_index) : MusicSongInfo(set->songinfo[set_index]), set(set), set_index(set_index) { }
44 bool IsValid() const { return !StrEmpty(this->songname); }
45 };
46 typedef std::vector<PlaylistEntry> Playlist;
47
48 enum PlaylistChoices {
49 PLCH_ALLMUSIC,
50 PLCH_OLDSTYLE,
51 PLCH_NEWSTYLE,
52 PLCH_EZYSTREET,
53 PLCH_CUSTOM1,
54 PLCH_CUSTOM2,
55 PLCH_THEMEONLY,
56 PLCH_MAX,
57 };
58
59 Playlist active_playlist;
60 Playlist displayed_playlist;
61 Playlist music_set;
62
63 PlaylistChoices selected_playlist;
64
65 void BuildPlaylists();
66
67 void ChangePlaylist(PlaylistChoices pl);
68 void ChangeMusicSet(const std::string &set_name);
69 void Shuffle();
70 void Unshuffle();
71
72 void Play();
73 void Stop();
74 void Next();
75 void Prev();
76 void CheckStatus();
77
78 bool IsPlaying() const;
79 bool IsShuffle() const;
80 PlaylistEntry GetCurrentSong() const;
81
82 bool IsCustomPlaylist() const;
83 void PlaylistAdd(size_t song_index);
84 void PlaylistRemove(size_t song_index);
85 void PlaylistClear();
86
87 private:
88 void ChangePlaylistPosition(int ofs);
89 int playlist_position;
90
91 void SaveCustomPlaylist(PlaylistChoices pl);
92
93 Playlist standard_playlists[PLCH_MAX];
94 };
95
96 MusicSystem _music;
97
98
100 void MusicSystem::BuildPlaylists()
101 {
102 const MusicSet *set = BaseMusic::GetUsedSet();
103
104 /* Clear current playlists */
105 for (size_t i = 0; i < lengthof(this->standard_playlists); ++i) this->standard_playlists[i].clear();
106 this->music_set.clear();
107
108 /* Build standard playlists, and a list of available music */
109 for (uint i = 0; i < NUM_SONGS_AVAILABLE; i++) {
110 PlaylistEntry entry(set, i);
111 if (!entry.IsValid()) continue;
112
113 this->music_set.push_back(entry);
114
115 /* Add theme song to theme-only playlist */
116 if (i == 0) this->standard_playlists[PLCH_THEMEONLY].push_back(entry);
117
118 /* Don't add the theme song to standard playlists */
119 if (i > 0) {
120 this->standard_playlists[PLCH_ALLMUSIC].push_back(entry);
121 uint theme = (i - 1) / NUM_SONGS_CLASS;
122 this->standard_playlists[PLCH_OLDSTYLE + theme].push_back(entry);
123 }
124 }
125
126 /* Load custom playlists
127 * Song index offsets are 1-based, zero indicates invalid/end-of-list value */
128 for (uint i = 0; i < NUM_SONGS_PLAYLIST; i++) {
129 if (_settings_client.music.custom_1[i] > 0) {
130 PlaylistEntry entry(set, _settings_client.music.custom_1[i] - 1);
131 if (entry.IsValid()) this->standard_playlists[PLCH_CUSTOM1].push_back(entry);
132 }
133 if (_settings_client.music.custom_2[i] > 0) {
134 PlaylistEntry entry(set, _settings_client.music.custom_2[i] - 1);
135 if (entry.IsValid()) this->standard_playlists[PLCH_CUSTOM2].push_back(entry);
136 }
137 }
138 }
139
144 void MusicSystem::ChangePlaylist(PlaylistChoices pl)
145 {
146 assert(pl < PLCH_MAX && pl >= PLCH_ALLMUSIC);
147
148 this->displayed_playlist = this->standard_playlists[pl];
149 this->active_playlist = this->displayed_playlist;
150 this->selected_playlist = pl;
151 this->playlist_position = 0;
152
153 if (this->selected_playlist != PLCH_THEMEONLY) _settings_client.music.playlist = this->selected_playlist;
154
155 if (_settings_client.music.shuffle) {
156 this->Shuffle();
157 /* Shuffle() will also Play() if necessary, only start once */
158 } else if (_settings_client.music.playing) {
159 this->Play();
160 }
161
162 InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0);
163 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
164 }
165
170 void MusicSystem::ChangeMusicSet(const std::string &set_name)
171 {
172 BaseMusic::SetSet(set_name);
173 BaseMusic::ini_set = set_name;
174
175 this->BuildPlaylists();
176 this->ChangePlaylist(this->selected_playlist);
177
178 InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS, 0, true);
179 }
180
182 void MusicSystem::Shuffle()
183 {
184 _settings_client.music.shuffle = true;
185
186 this->active_playlist = this->displayed_playlist;
187 for (size_t i = 0; i < this->active_playlist.size(); i++) {
188 size_t shuffle_index = InteractiveRandom() % (this->active_playlist.size() - i);
189 std::swap(this->active_playlist[i], this->active_playlist[i + shuffle_index]);
190 }
191
192 if (_settings_client.music.playing) this->Play();
193
194 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
195 }
196
198 void MusicSystem::Unshuffle()
199 {
200 _settings_client.music.shuffle = false;
201 this->active_playlist = this->displayed_playlist;
202
203 if (_settings_client.music.playing) this->Play();
204
205 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
206 }
207
209 void MusicSystem::Play()
210 {
211 /* Always set the playing flag, even if there is no music */
212 _settings_client.music.playing = true;
213 MusicDriver::GetInstance()->StopSong();
214 /* Make sure playlist_position is a valid index, if playlist has changed etc. */
215 this->ChangePlaylistPosition(0);
216
217 /* If there is no music, don't try to play it */
218 if (this->active_playlist.empty()) return;
219
220 MusicSongInfo song = this->active_playlist[this->playlist_position];
221 if (_game_mode == GM_MENU && this->selected_playlist == PLCH_THEMEONLY) song.loop = true;
222 MusicDriver::GetInstance()->PlaySong(song);
223
224 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
225 }
226
228 void MusicSystem::Stop()
229 {
230 MusicDriver::GetInstance()->StopSong();
231 _settings_client.music.playing = false;
232
233 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
234 }
235
237 void MusicSystem::Next()
238 {
239 this->ChangePlaylistPosition(+1);
240 if (_settings_client.music.playing) this->Play();
241
242 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
243 }
244
246 void MusicSystem::Prev()
247 {
248 this->ChangePlaylistPosition(-1);
249 if (_settings_client.music.playing) this->Play();
250
251 InvalidateWindowData(WC_MUSIC_WINDOW, 0);
252 }
253
255 void MusicSystem::CheckStatus()
256 {
257 if ((_game_mode == GM_MENU) != (this->selected_playlist == PLCH_THEMEONLY)) {
258 /* Make sure the theme-only playlist is active when on the title screen, and not during gameplay */
259 this->ChangePlaylist((_game_mode == GM_MENU) ? PLCH_THEMEONLY : (PlaylistChoices)_settings_client.music.playlist);
260 }
261 if (this->active_playlist.empty()) return;
262 /* If we were supposed to be playing, but music has stopped, move to next song */
263 if (this->IsPlaying() && !MusicDriver::GetInstance()->IsSongPlaying()) this->Next();
264 }
265
267 bool MusicSystem::IsPlaying() const
268 {
269 return _settings_client.music.playing && !this->active_playlist.empty();
270 }
271
273 bool MusicSystem::IsShuffle() const
274 {
275 return _settings_client.music.shuffle;
276 }
277
279 MusicSystem::PlaylistEntry MusicSystem::GetCurrentSong() const
280 {
281 if (!this->IsPlaying()) return PlaylistEntry(BaseMusic::GetUsedSet(), 0);
282 return this->active_playlist[this->playlist_position];
283 }
284
286 bool MusicSystem::IsCustomPlaylist() const
287 {
288 return (this->selected_playlist == PLCH_CUSTOM1) || (this->selected_playlist == PLCH_CUSTOM2);
289 }
290
296 void MusicSystem::PlaylistAdd(size_t song_index)
297 {
298 if (!this->IsCustomPlaylist()) return;
299
300 /* Pick out song from the music set */
301 if (song_index >= this->music_set.size()) return;
302 PlaylistEntry entry = this->music_set[song_index];
303
304 /* Check for maximum length */
305 if (this->standard_playlists[this->selected_playlist].size() >= NUM_SONGS_PLAYLIST) return;
306
307 /* Add it to the appropriate playlist, and the display */
308 this->standard_playlists[this->selected_playlist].push_back(entry);
309 this->displayed_playlist.push_back(entry);
310
311 /* Add it to the active playlist, if playback is shuffled select a random position to add at */
312 if (this->active_playlist.empty()) {
313 this->active_playlist.push_back(entry);
314 if (this->IsPlaying()) this->Play();
315 } else if (this->IsShuffle()) {
316 /* Generate a random position between 0 and n (inclusive, new length) to insert at */
317 size_t maxpos = this->displayed_playlist.size();
318 size_t newpos = InteractiveRandom() % maxpos;
319 this->active_playlist.insert(this->active_playlist.begin() + newpos, entry);
320 /* Make sure to shift up the current playback position if the song was inserted before it */
321 if ((int)newpos <= this->playlist_position) this->playlist_position++;
322 } else {
323 this->active_playlist.push_back(entry);
324 }
325
326 this->SaveCustomPlaylist(this->selected_playlist);
327
328 InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0);
329 }
330
335 void MusicSystem::PlaylistRemove(size_t song_index)
336 {
337 if (!this->IsCustomPlaylist()) return;
338
339 Playlist &pl = this->standard_playlists[this->selected_playlist];
340 if (song_index >= pl.size()) return;
341
342 /* Remove from "simple" playlists */
343 PlaylistEntry song = pl[song_index];
344 pl.erase(pl.begin() + song_index);
345 this->displayed_playlist.erase(this->displayed_playlist.begin() + song_index);
346
347 /* Find in actual active playlist (may be shuffled) and remove,
348 * if it's the current song restart playback */
349 for (size_t i = 0; i < this->active_playlist.size(); i++) {
350 Playlist::iterator s2 = this->active_playlist.begin() + i;
351 if (s2->filename == song.filename && s2->cat_index == song.cat_index) {
352 this->active_playlist.erase(s2);
353 if ((int)i == this->playlist_position && this->IsPlaying()) this->Play();
354 break;
355 }
356 }
357
358 this->SaveCustomPlaylist(this->selected_playlist);
359
360 InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0);
361 }
362
367 void MusicSystem::PlaylistClear()
368 {
369 if (!this->IsCustomPlaylist()) return;
370
371 this->standard_playlists[this->selected_playlist].clear();
372 this->ChangePlaylist(this->selected_playlist);
373
374 this->SaveCustomPlaylist(this->selected_playlist);
375 }
376
382 void MusicSystem::ChangePlaylistPosition(int ofs)
383 {
384 if (this->active_playlist.empty()) {
385 this->playlist_position = 0;
386 } else {
387 this->playlist_position += ofs;
388 while (this->playlist_position >= (int)this->active_playlist.size()) this->playlist_position -= (int)this->active_playlist.size();
389 while (this->playlist_position < 0) this->playlist_position += (int)this->active_playlist.size();
390 }
391 }
392
397 void MusicSystem::SaveCustomPlaylist(PlaylistChoices pl)
398 {
399 byte *settings_pl;
400 if (pl == PLCH_CUSTOM1) {
401 settings_pl = _settings_client.music.custom_1;
402 } else if (pl == PLCH_CUSTOM2) {
403 settings_pl = _settings_client.music.custom_2;
404 } else {
405 return;
406 }
407
408 size_t num = 0;
409 MemSetT(settings_pl, 0, NUM_SONGS_PLAYLIST);
410
411 for (Playlist::const_iterator song = this->standard_playlists[pl].begin(); song != this->standard_playlists[pl].end(); ++song) {
412 /* Music set indices in the settings playlist are 1-based, 0 means unused slot */
413 settings_pl[num++] = (byte)song->set_index + 1;
414 }
415 }
416
417
422 void MusicLoop()
423 {
424 _music.CheckStatus();
425 }
426
431 void ChangeMusicSet(int index)
432 {
433 if (BaseMusic::GetIndexOfUsedSet() == index) return;
434 _music.ChangeMusicSet(BaseMusic::GetSet(index)->name);
435 }
436
441 void InitializeMusic()
442 {
443 _music.BuildPlaylists();
444 }
445
446
447 struct MusicTrackSelectionWindow : public Window {
448 MusicTrackSelectionWindow(WindowDesc *desc, WindowNumber number) : Window(desc)
449 {
450 this->InitNested(number);
451 this->LowerWidget(WID_MTS_LIST_LEFT);
452 this->LowerWidget(WID_MTS_LIST_RIGHT);
453 this->SetWidgetDisabledState(WID_MTS_CLEAR, _settings_client.music.playlist <= 3);
454 this->LowerWidget(WID_MTS_ALL + _settings_client.music.playlist);
455 }
456
457 void SetStringParameters(int widget) const override
458 {
459 switch (widget) {
460 case WID_MTS_PLAYLIST:
461 SetDParam(0, STR_MUSIC_PLAYLIST_ALL + _settings_client.music.playlist);
462 break;
463 case WID_MTS_CAPTION:
464 SetDParamStr(0, BaseMusic::GetUsedSet()->name.c_str());
465 break;
466 }
467 }
468
474 void OnInvalidateData(int data = 0, bool gui_scope = true) override
475 {
476 if (!gui_scope) return;
477 for (int i = 0; i < 6; i++) {
478 this->SetWidgetLoweredState(WID_MTS_ALL + i, i == _settings_client.music.playlist);
479 }
480 this->SetWidgetDisabledState(WID_MTS_CLEAR, _settings_client.music.playlist <= 3);
481 this->SetDirty();
482 }
483
484 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
485 {
486 switch (widget) {
487 case WID_MTS_PLAYLIST: {
488 Dimension d = {0, 0};
489
490 for (int i = 0; i < 6; i++) {
491 SetDParam(0, STR_MUSIC_PLAYLIST_ALL + i);
492 d = maxdim(d, GetStringBoundingBox(STR_PLAYLIST_PROGRAM));
493 }
494 d.width += padding.width;
495 d.height += padding.height;
496 *size = maxdim(*size, d);
497 break;
498 }
499
500 case WID_MTS_LIST_LEFT: case WID_MTS_LIST_RIGHT: {
501 Dimension d = {0, 0};
502
503 for (MusicSystem::Playlist::const_iterator song = _music.music_set.begin(); song != _music.music_set.end(); ++song) {
504 SetDParam(0, song->tracknr);
505 SetDParam(1, 2);
506 SetDParamStr(2, song->songname);
507 Dimension d2 = GetStringBoundingBox(STR_PLAYLIST_TRACK_NAME);
508 d.width = std::max(d.width, d2.width);
509 d.height += d2.height;
510 }
511 d.width += padding.width;
512 d.height += padding.height;
513 *size = maxdim(*size, d);
514 break;
515 }
516 }
517 }
518
519 void DrawWidget(const Rect &r, int widget) const override
520 {
521 switch (widget) {
522 case WID_MTS_LIST_LEFT: {
523 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK);
524
525 int y = r.top + WD_FRAMERECT_TOP;
526 for (MusicSystem::Playlist::const_iterator song = _music.music_set.begin(); song != _music.music_set.end(); ++song) {
527 SetDParam(0, song->tracknr);
528 SetDParam(1, 2);
529 SetDParamStr(2, song->songname);
530 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_PLAYLIST_TRACK_NAME);
531 y += FONT_HEIGHT_SMALL;
532 }
533 break;
534 }
535
536 case WID_MTS_LIST_RIGHT: {
537 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK);
538
539 int y = r.top + WD_FRAMERECT_TOP;
540 for (MusicSystem::Playlist::const_iterator song = _music.active_playlist.begin(); song != _music.active_playlist.end(); ++song) {
541 SetDParam(0, song->tracknr);
542 SetDParam(1, 2);
543 SetDParamStr(2, song->songname);
544 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_PLAYLIST_TRACK_NAME);
545 y += FONT_HEIGHT_SMALL;
546 }
547 break;
548 }
549 }
550 }
551
552 void OnClick(Point pt, int widget, int click_count) override
553 {
554 switch (widget) {
555 case WID_MTS_LIST_LEFT: { // add to playlist
556 int y = this->GetRowFromWidget(pt.y, widget, 0, FONT_HEIGHT_SMALL);
557 _music.PlaylistAdd(y);
558 break;
559 }
560
561 case WID_MTS_LIST_RIGHT: { // remove from playlist
562 int y = this->GetRowFromWidget(pt.y, widget, 0, FONT_HEIGHT_SMALL);
563 _music.PlaylistRemove(y);
564 break;
565 }
566
567 case WID_MTS_MUSICSET: {
568 int selected = 0;
569 ShowDropDownList(this, BuildMusicSetDropDownList(&selected), selected, widget, 0, true, false);
570 break;
571 }
572
573 case WID_MTS_CLEAR: // clear
574 _music.PlaylistClear();
575 break;
576
577 case WID_MTS_ALL: case WID_MTS_OLD: case WID_MTS_NEW:
578 case WID_MTS_EZY: case WID_MTS_CUSTOM1: case WID_MTS_CUSTOM2: // set playlist
579 _music.ChangePlaylist((MusicSystem::PlaylistChoices)(widget - WID_MTS_ALL));
580 break;
581 }
582 }
583
584 void OnDropdownSelect(int widget, int index) override
585 {
586 switch (widget) {
587 case WID_MTS_MUSICSET:
588 ChangeMusicSet(index);
589 break;
590 default:
591 NOT_REACHED();
592 }
593 }
594 };
595
596 static const NWidgetPart _nested_music_track_selection_widgets[] = {
597 NWidget(NWID_HORIZONTAL),
598 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
599 NWidget(WWT_CAPTION, COLOUR_GREY, WID_MTS_CAPTION), SetDataTip(STR_PLAYLIST_MUSIC_SELECTION_SETNAME, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
600 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_MTS_MUSICSET), SetDataTip(STR_PLAYLIST_CHANGE_SET, STR_PLAYLIST_TOOLTIP_CHANGE_SET),
601 EndContainer(),
602 NWidget(WWT_PANEL, COLOUR_GREY),
603 NWidget(NWID_HORIZONTAL), SetPIP(2, 4, 2),
604 /* Left panel. */
605 NWidget(NWID_VERTICAL),
606 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_PLAYLIST_TRACK_INDEX, STR_NULL),
607 NWidget(WWT_PANEL, COLOUR_GREY, WID_MTS_LIST_LEFT), SetMinimalSize(180, 194), SetDataTip(0x0, STR_PLAYLIST_TOOLTIP_CLICK_TO_ADD_TRACK), EndContainer(),
608 NWidget(NWID_SPACER), SetMinimalSize(0, 2),
609 EndContainer(),
610 /* Middle buttons. */
611 NWidget(NWID_VERTICAL),
612 NWidget(NWID_SPACER), SetMinimalSize(60, 30), // Space above the first button from the title bar.
613 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_ALL), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_ALL, STR_MUSIC_TOOLTIP_SELECT_ALL_TRACKS_PROGRAM),
614 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_OLD), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_OLD_STYLE, STR_MUSIC_TOOLTIP_SELECT_OLD_STYLE_MUSIC),
615 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_NEW), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_NEW_STYLE, STR_MUSIC_TOOLTIP_SELECT_NEW_STYLE_MUSIC),
616 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_EZY), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_EZY_STREET, STR_MUSIC_TOOLTIP_SELECT_EZY_STREET_STYLE),
617 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),
618 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),
619 NWidget(NWID_SPACER), SetMinimalSize(0, 16), // Space above 'clear' button
620 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_MTS_CLEAR), SetFill(1, 0), SetDataTip(STR_PLAYLIST_CLEAR, STR_PLAYLIST_TOOLTIP_CLEAR_CURRENT_PROGRAM_CUSTOM1),
621 NWidget(NWID_SPACER), SetFill(0, 1),
622 EndContainer(),
623 /* Right panel. */
624 NWidget(NWID_VERTICAL),
625 NWidget(WWT_LABEL, COLOUR_GREY, WID_MTS_PLAYLIST), SetDataTip(STR_PLAYLIST_PROGRAM, STR_NULL),
626 NWidget(WWT_PANEL, COLOUR_GREY, WID_MTS_LIST_RIGHT), SetMinimalSize(180, 194), SetDataTip(0x0, STR_PLAYLIST_TOOLTIP_CLICK_TO_REMOVE_TRACK), EndContainer(),
627 NWidget(NWID_SPACER), SetMinimalSize(0, 2),
628 EndContainer(),
629 EndContainer(),
630 EndContainer(),
631 };
632
633 static WindowDesc _music_track_selection_desc(
634 WDP_AUTO, "music_track", 0, 0,
635 WC_MUSIC_TRACK_SELECTION, WC_NONE,
636 0,
637 _nested_music_track_selection_widgets, lengthof(_nested_music_track_selection_widgets)
638 );
639
640 static void ShowMusicTrackSelection()
641 {
642 AllocateWindowDescFront<MusicTrackSelectionWindow>(&_music_track_selection_desc, 0);
643 }
644
645 struct MusicWindow : public Window {
646 static const int slider_width = 3;
647
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 += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
686 d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
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 += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
698 d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
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.left + 1, r.top + 1, r.right, r.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.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, str);
726 break;
727 }
728
729 case WID_M_TRACK_NAME: {
730 GfxFillRect(r.left, r.top + 1, r.right - 1, r.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.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, str, TC_FROMSTRING, SA_HOR_CENTER);
740 break;
741 }
742
743 case WID_M_MUSIC_VOL: case WID_M_EFFECT_VOL: {
744 /* Draw a wedge indicating low to high volume level. */
745 const int ha = (r.bottom - r.top) / 5;
746 int wx1 = r.left, wx2 = r.right;
747 if (_current_text_dir == TD_RTL) std::swap(wx1, wx2);
748 const uint shadow = _colour_gradient[COLOUR_GREY][3];
749 const uint fill = _colour_gradient[COLOUR_GREY][6];
750 const uint light = _colour_gradient[COLOUR_GREY][7];
751 const std::vector<Point> wedge{ Point{wx1, r.bottom - ha}, Point{wx2, r.top + ha}, Point{wx2, r.bottom - ha} };
752 GfxFillPolygon(wedge, fill);
753 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[2].x, wedge[2].y, light);
754 GfxDrawLine(wedge[1].x, wedge[1].y, wedge[2].x, wedge[2].y, _current_text_dir == TD_RTL ? shadow : light);
755 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[1].x, wedge[1].y, shadow);
756 /* Draw a slider handle indicating current volume level. */
757 const int sw = ScaleGUITrad(slider_width);
758 byte volume = (widget == WID_M_MUSIC_VOL) ? _settings_client.music.music_vol : _settings_client.music.effect_vol;
759 if (_current_text_dir == TD_RTL) volume = 127 - volume;
760 const int x = r.left + (volume * (r.right - r.left - sw) / 127);
761 DrawFrameRect(x, r.top, x + sw, r.bottom, COLOUR_GREY, FR_NONE);
762 break;
763 }
764 }
765 }
766
772 void OnInvalidateData(int data = 0, bool gui_scope = true) override
773 {
774 if (!gui_scope) return;
775 for (int i = 0; i < 6; i++) {
776 this->SetWidgetLoweredState(WID_M_ALL + i, i == _settings_client.music.playlist);
777 }
778
779 UpdateDisabledButtons();
780
781 this->SetDirty();
782 }
783
784 void OnClick(Point pt, int widget, int click_count) override
785 {
786 switch (widget) {
787 case WID_M_PREV: // skip to prev
788 _music.Prev();
789 break;
790
791 case WID_M_NEXT: // skip to next
792 _music.Next();
793 break;
794
795 case WID_M_STOP: // stop playing
796 _music.Stop();
797 break;
798
799 case WID_M_PLAY: // start playing
800 _music.Play();
801 break;
802
803 case WID_M_MUSIC_VOL: case WID_M_EFFECT_VOL: { // volume sliders
804 int x = pt.x - this->GetWidget<NWidgetBase>(widget)->pos_x;
805
806 byte *vol = (widget == WID_M_MUSIC_VOL) ? &_settings_client.music.music_vol : &_settings_client.music.effect_vol;
807
808 byte new_vol = Clamp(x * 127 / (int)this->GetWidget<NWidgetBase>(widget)->current_x, 0, 127);
809 if (_current_text_dir == TD_RTL) new_vol = 127 - new_vol;
810 /* Clamp to make sure min and max are properly settable */
811 if (new_vol > 124) new_vol = 127;
812 if (new_vol < 3) new_vol = 0;
813 if (new_vol != *vol) {
814 *vol = new_vol;
815 if (widget == WID_M_MUSIC_VOL) MusicDriver::GetInstance()->SetVolume(new_vol);
816 this->SetDirty();
817 }
818
819 if (click_count > 0) this->mouse_capture_widget = widget;
820 break;
821 }
822
823 case WID_M_SHUFFLE: // toggle shuffle
824 if (_music.IsShuffle()) {
825 _music.Unshuffle();
826 } else {
827 _music.Shuffle();
828 }
829 this->SetWidgetLoweredState(WID_M_SHUFFLE, _music.IsShuffle());
830 this->SetWidgetDirty(WID_M_SHUFFLE);
831 break;
832
833 case WID_M_PROGRAMME: // show track selection
834 ShowMusicTrackSelection();
835 break;
836
837 case WID_M_ALL: case WID_M_OLD: case WID_M_NEW:
838 case WID_M_EZY: case WID_M_CUSTOM1: case WID_M_CUSTOM2: // playlist
839 _music.ChangePlaylist((MusicSystem::PlaylistChoices)(widget - WID_M_ALL));
840 break;
841 }
842 }
843 };
844
845 static const NWidgetPart _nested_music_window_widgets[] = {
846 NWidget(NWID_HORIZONTAL),
847 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
848 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_MUSIC_JAZZ_JUKEBOX_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
849 NWidget(WWT_SHADEBOX, COLOUR_GREY),
850 NWidget(WWT_STICKYBOX, COLOUR_GREY),
851 EndContainer(),
852
853 NWidget(NWID_HORIZONTAL),
854 NWidget(NWID_VERTICAL),
855 NWidget(WWT_PANEL, COLOUR_GREY, -1), SetFill(1, 1), EndContainer(),
856 NWidget(NWID_HORIZONTAL),
857 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_M_PREV), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_SKIP_TO_PREV, STR_MUSIC_TOOLTIP_SKIP_TO_PREVIOUS_TRACK),
858 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),
859 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_M_STOP), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_STOP_MUSIC, STR_MUSIC_TOOLTIP_STOP_PLAYING_MUSIC),
860 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_M_PLAY), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_PLAY_MUSIC, STR_MUSIC_TOOLTIP_START_PLAYING_MUSIC),
861 EndContainer(),
862 NWidget(WWT_PANEL, COLOUR_GREY, -1), SetFill(1, 1), EndContainer(),
863 EndContainer(),
864 NWidget(WWT_PANEL, COLOUR_GREY, WID_M_SLIDERS),
865 NWidget(NWID_HORIZONTAL), SetPIP(4, 0, 4),
866 NWidget(NWID_VERTICAL),
867 NWidget(WWT_LABEL, COLOUR_GREY, -1), SetFill(1, 0), SetDataTip(STR_MUSIC_MUSIC_VOLUME, STR_NULL),
868 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),
869 EndContainer(),
870 NWidget(NWID_VERTICAL),
871 NWidget(WWT_LABEL, COLOUR_GREY, -1), SetFill(1, 0), SetDataTip(STR_MUSIC_EFFECTS_VOLUME, STR_NULL),
872 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),
873 EndContainer(),
874 EndContainer(),
875 EndContainer(),
876 EndContainer(),
877 NWidget(WWT_PANEL, COLOUR_GREY, WID_M_BACKGROUND),
878 NWidget(NWID_HORIZONTAL), SetPIP(6, 0, 6),
879 NWidget(NWID_VERTICAL),
880 NWidget(NWID_SPACER), SetFill(0, 1),
881 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_SHUFFLE), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_SHUFFLE, STR_MUSIC_TOOLTIP_TOGGLE_PROGRAM_SHUFFLE),
882 NWidget(NWID_SPACER), SetFill(0, 1),
883 EndContainer(),
884 NWidget(NWID_VERTICAL), SetPadding(0, 0, 3, 3),
885 NWidget(WWT_LABEL, COLOUR_GREY, WID_M_TRACK), SetFill(0, 0), SetDataTip(STR_MUSIC_TRACK, STR_NULL),
886 NWidget(WWT_PANEL, COLOUR_GREY, WID_M_TRACK_NR), EndContainer(),
887 EndContainer(),
888 NWidget(NWID_VERTICAL), SetPadding(0, 3, 3, 0),
889 NWidget(WWT_LABEL, COLOUR_GREY, WID_M_TRACK_TITLE), SetFill(1, 0), SetDataTip(STR_MUSIC_XTITLE, STR_NULL),
890 NWidget(WWT_PANEL, COLOUR_GREY, WID_M_TRACK_NAME), SetFill(1, 0), EndContainer(),
891 EndContainer(),
892 NWidget(NWID_VERTICAL),
893 NWidget(NWID_SPACER), SetFill(0, 1),
894 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_M_PROGRAMME), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_PROGRAM, STR_MUSIC_TOOLTIP_SHOW_MUSIC_TRACK_SELECTION),
895 NWidget(NWID_SPACER), SetFill(0, 1),
896 EndContainer(),
897 EndContainer(),
898 EndContainer(),
899 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
900 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_ALL), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_ALL, STR_MUSIC_TOOLTIP_SELECT_ALL_TRACKS_PROGRAM),
901 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_OLD), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_OLD_STYLE, STR_MUSIC_TOOLTIP_SELECT_OLD_STYLE_MUSIC),
902 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_NEW), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_NEW_STYLE, STR_MUSIC_TOOLTIP_SELECT_NEW_STYLE_MUSIC),
903 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_EZY), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_EZY_STREET, STR_MUSIC_TOOLTIP_SELECT_EZY_STREET_STYLE),
904 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),
905 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),
906 EndContainer(),
907 };
908
909 static WindowDesc _music_window_desc(
910 WDP_AUTO, "music", 0, 0,
911 WC_MUSIC_WINDOW, WC_NONE,
912 0,
913 _nested_music_window_widgets, lengthof(_nested_music_window_widgets)
914 );
915
916 void ShowMusicWindow()
917 {
918 AllocateWindowDescFront<MusicWindow>(&_music_window_desc, 0);
919 }
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:182
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:144
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
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:3321
sound_func.h
MusicSystem::PlaylistClear
void PlaylistClear()
Remove all songs from the current custom playlist.
Definition: music_gui.cpp:367
MusicSystem
Definition: music_gui.cpp:38
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:1045
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:484
dropdown_func.h
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.
GfxFillPolygon
void GfxFillPolygon(const std::vector< Point > &shape, int colour, FillRectMode mode)
Fill a polygon with colour.
Definition: gfx.cpp:210
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:273
MusicSystem::IsCustomPlaylist
bool IsCustomPlaylist() const
Is one of the custom playlists selected?
Definition: music_gui.cpp:286
MusicSettings::shuffle
bool shuffle
Whether to shuffle the music.
Definition: settings_type.h:212
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:296
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:79
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:640
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:457
MusicSystem::Play
void Play()
Start/restart playback at current song.
Definition: music_gui.cpp:209
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
WC_MUSIC_WINDOW
@ WC_MUSIC_WINDOW
Music window; Window numbers:
Definition: window_type.h:590
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_func.h:97
MusicWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: music_gui.cpp:772
MusicLoop
void MusicLoop()
Check music playback status and start/stop/song-finished.
Definition: music_gui.cpp:422
MusicSystem::Prev
void Prev()
Skip to previous track.
Definition: music_gui.cpp:246
MusicTrackSelectionWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: music_gui.cpp:474
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:52
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1871
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:199
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:909
MusicSystem::displayed_playlist
Playlist displayed_playlist
current playlist as displayed in GUI, never in shuffled order
Definition: music_gui.cpp:60
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1013
MusicSettings::playing
bool playing
Whether music is playing.
Definition: settings_type.h:211
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:842
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:237
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:784
WN_GAME_OPTIONS_GAME_OPTIONS
@ WN_GAME_OPTIONS_GAME_OPTIONS
Game options.
Definition: window_type.h:18
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:166
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:428
MusicTrackSelectionWindow
Definition: music_gui.cpp:447
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:154
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:322
MusicSystem::PlaylistEntry
Definition: music_gui.cpp:39
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:1861
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:255
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
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:170
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
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
MusicSystem::BuildPlaylists
void BuildPlaylists()
Rebuild all playlists for the current music set.
Definition: music_gui.cpp:100
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:453
MusicSystem::IsPlaying
bool IsPlaying() const
Is the player getting music right now?
Definition: music_gui.cpp:267
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:198
MusicSettings::custom_2
byte custom_2[33]
The order of the second custom playlist.
Definition: settings_type.h:210
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:552
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:392
safeguards.h
music_driver.hpp
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:60
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:206
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:206
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:114
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:335
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
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:176
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:103
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:998
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
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:441
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:645
WID_MTS_CLEAR
@ WID_MTS_CLEAR
Clear button.
Definition: music_widget.h:26
ScaleGUITrad
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:76
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1113
MusicSystem::SaveCustomPlaylist
void SaveCustomPlaylist(PlaylistChoices pl)
Save a custom playlist to settings after modification.
Definition: music_gui.cpp:397
geometry_func.hpp
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:946
MusicTrackSelectionWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: music_gui.cpp:584
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:536
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
openttd.h
MusicSystem::GetCurrentSong
PlaylistEntry GetCurrentSong() const
Return the current song, or a dummy if none.
Definition: music_gui.cpp:279
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
WID_MTS_LIST_RIGHT
@ WID_MTS_LIST_RIGHT
Right button.
Definition: music_widget.h:18
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:175
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:367
MusicSettings::effect_vol
byte effect_vol
The requested effects volume.
Definition: settings_type.h:208
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:1075
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:982
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:519
MusicSystem::PlaylistEntry::set
const MusicSet * set
music set the song comes from
Definition: music_gui.cpp:40
MusicSystem::PlaylistEntry::set_index
uint set_index
index of song in set
Definition: music_gui.cpp:41
MusicSystem::Stop
void Stop()
Stop playback and set flag that we don't intend to play music.
Definition: music_gui.cpp:228
Window
Data structure for an opened window.
Definition: window_gui.h:276
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:382
MusicSystem::active_playlist
Playlist active_playlist
current play order of songs, including any shuffle
Definition: music_gui.cpp:59
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
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:597
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
Window::LowerWidget
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:474
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:201
ClientSettings::music
MusicSettings music
settings related to music/sound
Definition: settings_type.h:581
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:453
ChangeMusicSet
void ChangeMusicSet(int index)
Change the configured music set and reset playback.
Definition: music_gui.cpp:431
MusicSettings::music_vol
byte music_vol
The requested music volume.
Definition: settings_type.h:207
MusicSystem::music_set
Playlist music_set
all songs in current music set, in set order
Definition: music_gui.cpp:61
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:48
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:209
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:286
WC_MUSIC_TRACK_SELECTION
@ WC_MUSIC_TRACK_SELECTION
Music track selection; Window numbers:
Definition: window_type.h:596
MusicSystem::PlaylistRemove
void PlaylistRemove(size_t song_index)
Remove a song from a custom playlist.
Definition: music_gui.cpp:335
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
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:964
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