34 #include "table/strings.h" 48 typedef std::vector<PlaylistEntry> Playlist;
50 enum PlaylistChoices {
65 PlaylistChoices selected_playlist;
91 int playlist_position;
95 Playlist standard_playlists[PLCH_MAX];
107 for (
size_t i = 0; i <
lengthof(this->standard_playlists); ++i) this->standard_playlists[i].clear();
113 if (!entry.IsValid())
continue;
118 if (i == 0) this->standard_playlists[PLCH_THEMEONLY].push_back(entry);
122 this->standard_playlists[PLCH_ALLMUSIC].push_back(entry);
124 this->standard_playlists[PLCH_OLDSTYLE + theme].push_back(entry);
133 if (entry.IsValid()) this->standard_playlists[PLCH_CUSTOM1].push_back(entry);
137 if (entry.IsValid()) this->standard_playlists[PLCH_CUSTOM2].push_back(entry);
148 assert(pl < PLCH_MAX && pl >= PLCH_ALLMUSIC);
152 this->selected_playlist = pl;
153 this->playlist_position = 0;
192 size_t shuffle_index = InteractiveRandom() % (this->
active_playlist.size() - i);
225 if (_game_mode == GM_MENU && this->selected_playlist == PLCH_THEMEONLY) song.
loop =
true;
261 if ((_game_mode == GM_MENU) != (this->selected_playlist == PLCH_THEMEONLY)) {
292 return (this->selected_playlist == PLCH_CUSTOM1) || (this->selected_playlist == PLCH_CUSTOM2);
305 if (song_index >= this->
music_set.size())
return;
309 if (this->standard_playlists[this->selected_playlist].size() >=
NUM_SONGS_PLAYLIST)
return;
312 this->standard_playlists[this->selected_playlist].push_back(entry);
322 size_t newpos = InteractiveRandom() % maxpos;
325 if ((
int)newpos <= this->playlist_position) this->playlist_position++;
343 Playlist &pl = this->standard_playlists[this->selected_playlist];
344 if (song_index >= pl.size())
return;
348 pl.erase(pl.begin() + song_index);
357 if ((
int)i == this->playlist_position && this->
IsPlaying()) this->
Play();
375 this->standard_playlists[this->selected_playlist].clear();
389 this->playlist_position = 0;
391 this->playlist_position += ofs;
393 while (this->playlist_position < 0) this->playlist_position += (int)this->
active_playlist.size();
404 if (pl == PLCH_CUSTOM1) {
406 }
else if (pl == PLCH_CUSTOM2) {
415 for (Playlist::const_iterator song = this->standard_playlists[pl].begin(); song != this->standard_playlists[pl].end(); ++song) {
417 settings_pl[num++] = (byte)song->set_index + 1;
455 this->InitNested(number);
481 if (!gui_scope)
return;
482 for (
int i = 0; i < 6; i++) {
495 for (
int i = 0; i < 6; i++) {
496 SetDParam(0, STR_MUSIC_PLAYLIST_ALL + i);
499 d.width += padding.width;
500 d.height += padding.height;
508 for (MusicSystem::Playlist::const_iterator song = _music.
music_set.begin(); song != _music.
music_set.end(); ++song) {
513 d.width =
max(d.width, d2.width);
514 d.height += d2.height;
516 d.width += padding.width;
517 d.height += padding.height;
531 for (MusicSystem::Playlist::const_iterator song = _music.
music_set.begin(); song != _music.
music_set.end(); ++song) {
574 ShowDropDownList(
this, BuildMusicSetDropDownList(&selected), selected, widget, 0,
true,
false);
601 static const NWidgetPart _nested_music_track_selection_widgets[] = {
638 static WindowDesc _music_track_selection_desc(
642 _nested_music_track_selection_widgets,
lengthof(_nested_music_track_selection_widgets)
645 static void ShowMusicTrackSelection()
647 AllocateWindowDescFront<MusicTrackSelectionWindow>(&_music_track_selection_desc, 0);
651 static const int slider_width = 3;
655 this->InitNested(number);
659 UpdateDisabledButtons();
662 void UpdateDisabledButtons()
666 this->SetWidgetsDisabledState(
682 d.width += padding.width;
683 d.height += padding.height;
698 for (MusicSystem::Playlist::const_iterator song = _music.
music_set.begin(); song != _music.
music_set.end(); ++song) {
724 StringID str = STR_MUSIC_TRACK_NONE;
728 str = STR_MUSIC_TRACK_DIGIT;
736 StringID str = STR_MUSIC_TITLE_NONE;
738 str = STR_MUSIC_TITLE_NOMUSIC;
740 str = STR_MUSIC_TITLE_NAME;
753 int x = r.left + (volume * (r.right - r.left - sw) / 127);
754 DrawFrameRect(x, r.top, x + sw, r.bottom, COLOUR_GREY, FR_NONE);
767 if (!gui_scope)
return;
768 for (
int i = 0; i < 6; i++) {
772 UpdateDisabledButtons();
797 int x = pt.x - this->GetWidget<NWidgetBase>(widget)->pos_x;
801 byte new_vol =
Clamp(x * 127 / (
int)this->GetWidget<NWidgetBase>(widget)->current_x, 0, 127);
804 if (new_vol > 124) new_vol = 127;
805 if (new_vol < 3) new_vol = 0;
806 if (new_vol != *vol) {
812 if (click_count > 0) this->mouse_capture_widget = widget;
827 ShowMusicTrackSelection();
838 static const NWidgetPart _nested_music_window_widgets[] = {
861 NWidget(
WWT_EMPTY, COLOUR_GREY,
WID_M_MUSIC_VOL),
SetMinimalSize(67, 0),
SetMinimalTextLines(1, 0),
SetFill(1, 0),
SetDataTip(0x0, STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
874 NWidget(
WWT_EMPTY, COLOUR_GREY,
WID_M_EFFECT_VOL),
SetMinimalSize(67, 0),
SetMinimalTextLines(1, 0),
SetFill(1, 0),
SetDataTip(0x0, STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
924 _nested_music_window_widgets,
lengthof(_nested_music_window_widgets)
927 void ShowMusicWindow()
929 AllocateWindowDescFront<MusicWindow>(&_music_window_desc, 0);
Functions related to OTTD's strings.
Metadata about a music track.
Playlist music_set
all songs in current music set, in set order
void Shuffle()
Enable shuffle mode and restart playback.
Music window; Window numbers:
Horizontally center the text.
void ChangePlaylistPosition(int ofs)
Change playlist position pointer by the given offset, making sure to keep it within valid range...
bool IsPlaying() const
Is the player getting music right now?
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...
High level window description.
Playlist active_playlist
current play order of songs, including any shuffle
bool IsShuffle() const
Is shuffle mode enabled?
Offset at top to draw the frame rectangular area.
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
void Play()
Start/restart playback at current song.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Music track selection; Window numbers:
bool IsCustomPlaylist() const
Is one of the custom playlists selected?
MusicSettings music
settings related to music/sound
void BuildPlaylists()
Rebuild all playlists for the current music set.
byte playlist
The playlist (number) to play.
char songname[32]
name of song displayed in UI
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
bool playing
Whether music is playing.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
static T max(const T a, const T b)
Returns the maximum of two values.
virtual void PlaySong(const MusicSongInfo &song)=0
Play a particular song.
void Next()
Skip to next track.
Functions, definitions and such used only by the GUI.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Pseudo random number generator.
Data structure for an opened window.
Playlist displayed_playlist
current playlist as displayed in GUI, never in shuffled order
void PlaylistAdd(size_t song_index)
Append a song to a custom playlist.
void CheckStatus()
Check that music is playing if it should, and that appropriate playlist is active for game/main menu...
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Functions related to low-level strings.
Functions related to errors.
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
virtual void SetVolume(byte vol)=0
Set the volume, if possible.
bool shuffle
Whether to shuffle the music.
void InitializeMusic()
Prepare the music system for use.
void MusicLoop()
Check music playback status and start/stop/song-finished.
const char * name
The name of the base set.
Functions related to the gfx engine.
void PlaylistClear()
Remove all songs from the current custom playlist.
ClientSettings _settings_client
The current settings for this game.
Types related to global configuration settings.
void Stop()
Stop playback and set flag that we don't intend to play music.
Base for all music playback.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
void Prev()
Skip to previous track.
byte custom_1[33]
The order of the first custom playlist.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
const char * filename
file on disk containing song (when used in MusicSet class, this pointer is owned by MD5File object fo...
Offset at bottom to draw the frame rectangular area.
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.
static MusicDriver * GetInstance()
Get the currently active instance of the music driver.
#define lengthof(x)
Return the length of an fixed size array.
Types related to the drop down widget.
Functions related to sound.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
virtual bool IsSongPlaying()=0
Are we currently playing a song?
static const uint8 PC_BLACK
Black palette colour.
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.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void Unshuffle()
Disable shuffle and restart playback.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
PlaylistEntry GetCurrentSong() const
Return the current song, or a dummy if none.
byte music_vol
The requested music volume.
byte tracknr
track number of song displayed in UI
If set the frame is lowered and the background colour brighter (ie. buttons when pressed) ...
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
TextDirection _current_text_dir
Text direction of the currently selected language.
uint set_index
index of song in set
void ChangeMusicSet(const char *set_name)
Change to named music set, and reset playback.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Functions for setting GUIs.
bool loop
song should play in a tight loop if possible, never ending
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.
Functions related to zooming.
Functions related to the drop down widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
const MusicSet * set
music set the song comes from
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Coordinates of a point in 2D.
int cat_index
entry index in CAT file, for filetype==MTT_MPSMIDI
byte custom_2[33]
The order of the second custom playlist.
void PlaylistRemove(size_t song_index)
Remove a song from a custom playlist.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
virtual void StopSong()=0
Stop playing the current song.
void ChangePlaylist(PlaylistChoices pl)
Switch to another playlist, or reload the current one.
Offset at right to draw the frame rectangular area.
int32 WindowNumber
Number to differentiate different windows of the same class.
Specification of a rectangle with absolute coordinates of all edges.
Text is written right-to-left by default.
Window functions not directly related to making/drawing windows.
Find a place automatically.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
void SaveCustomPlaylist(PlaylistChoices pl)
Save a custom playlist to settings after modification.
Dimensions (a width and height) of a rectangle in 2D.
Offset at left to draw the frame rectangular area.
This file contains all sprite-related enums and defines.
byte effect_vol
The requested effects volume.
Game options window; Window numbers:
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-...
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.