32 #include "table/strings.h" 46 typedef std::vector<PlaylistEntry> Playlist;
48 enum PlaylistChoices {
63 PlaylistChoices selected_playlist;
89 int playlist_position;
93 Playlist standard_playlists[PLCH_MAX];
105 for (
size_t i = 0; i <
lengthof(this->standard_playlists); ++i) this->standard_playlists[i].clear();
111 if (!entry.IsValid())
continue;
116 if (i == 0) this->standard_playlists[PLCH_THEMEONLY].push_back(entry);
120 this->standard_playlists[PLCH_ALLMUSIC].push_back(entry);
122 this->standard_playlists[PLCH_OLDSTYLE + theme].push_back(entry);
131 if (entry.IsValid()) this->standard_playlists[PLCH_CUSTOM1].push_back(entry);
135 if (entry.IsValid()) this->standard_playlists[PLCH_CUSTOM2].push_back(entry);
146 assert(pl < PLCH_MAX && pl >= PLCH_ALLMUSIC);
150 this->selected_playlist = pl;
151 this->playlist_position = 0;
190 size_t shuffle_index = InteractiveRandom() % (this->
active_playlist.size() - i);
223 if (_game_mode == GM_MENU && this->selected_playlist == PLCH_THEMEONLY) song.
loop =
true;
259 if ((_game_mode == GM_MENU) != (this->selected_playlist == PLCH_THEMEONLY)) {
290 return (this->selected_playlist == PLCH_CUSTOM1) || (this->selected_playlist == PLCH_CUSTOM2);
303 if (song_index >= this->
music_set.size())
return;
307 if (this->standard_playlists[this->selected_playlist].size() >=
NUM_SONGS_PLAYLIST)
return;
310 this->standard_playlists[this->selected_playlist].push_back(entry);
320 size_t newpos = InteractiveRandom() % maxpos;
323 if ((
int)newpos <= this->playlist_position) this->playlist_position++;
341 Playlist &pl = this->standard_playlists[this->selected_playlist];
342 if (song_index >= pl.size())
return;
346 pl.erase(pl.begin() + song_index);
355 if ((
int)i == this->playlist_position && this->
IsPlaying()) this->
Play();
373 this->standard_playlists[this->selected_playlist].clear();
387 this->playlist_position = 0;
389 this->playlist_position += ofs;
391 while (this->playlist_position < 0) this->playlist_position += (int)this->
active_playlist.size();
402 if (pl == PLCH_CUSTOM1) {
404 }
else if (pl == PLCH_CUSTOM2) {
413 for (Playlist::const_iterator song = this->standard_playlists[pl].begin(); song != this->standard_playlists[pl].end(); ++song) {
415 settings_pl[num++] = (byte)song->set_index + 1;
453 this->InitNested(number);
479 if (!gui_scope)
return;
480 for (
int i = 0; i < 6; i++) {
493 for (
int i = 0; i < 6; i++) {
494 SetDParam(0, STR_MUSIC_PLAYLIST_ALL + i);
497 d.width += padding.width;
498 d.height += padding.height;
506 for (MusicSystem::Playlist::const_iterator song = _music.
music_set.begin(); song != _music.
music_set.end(); ++song) {
511 d.width =
max(d.width, d2.width);
512 d.height += d2.height;
514 d.width += padding.width;
515 d.height += padding.height;
529 for (MusicSystem::Playlist::const_iterator song = _music.
music_set.begin(); song != _music.
music_set.end(); ++song) {
572 ShowDropDownList(
this, BuildMusicSetDropDownList(&selected), selected, widget, 0,
true,
false);
599 static const NWidgetPart _nested_music_track_selection_widgets[] = {
636 static WindowDesc _music_track_selection_desc(
640 _nested_music_track_selection_widgets,
lengthof(_nested_music_track_selection_widgets)
643 static void ShowMusicTrackSelection()
645 AllocateWindowDescFront<MusicTrackSelectionWindow>(&_music_track_selection_desc, 0);
649 static const int slider_width = 3;
653 this->InitNested(number);
657 UpdateDisabledButtons();
660 void UpdateDisabledButtons()
664 this->SetWidgetsDisabledState(
680 d.width += padding.width;
681 d.height += padding.height;
696 for (MusicSystem::Playlist::const_iterator song = _music.
music_set.begin(); song != _music.
music_set.end(); ++song) {
722 StringID str = STR_MUSIC_TRACK_NONE;
726 str = STR_MUSIC_TRACK_DIGIT;
734 StringID str = STR_MUSIC_TITLE_NONE;
736 str = STR_MUSIC_TITLE_NOMUSIC;
738 str = STR_MUSIC_TITLE_NAME;
751 int x = r.left + (volume * (r.right - r.left - sw) / 127);
752 DrawFrameRect(x, r.top, x + sw, r.bottom, COLOUR_GREY, FR_NONE);
765 if (!gui_scope)
return;
766 for (
int i = 0; i < 6; i++) {
770 UpdateDisabledButtons();
795 int x = pt.x - this->GetWidget<NWidgetBase>(widget)->pos_x;
799 byte new_vol =
Clamp(x * 127 / (
int)this->GetWidget<NWidgetBase>(widget)->current_x, 0, 127);
802 if (new_vol > 124) new_vol = 127;
803 if (new_vol < 3) new_vol = 0;
804 if (new_vol != *vol) {
810 if (click_count > 0) this->mouse_capture_widget = widget;
825 ShowMusicTrackSelection();
836 static const NWidgetPart _nested_music_window_widgets[] = {
859 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),
872 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),
922 _nested_music_window_widgets,
lengthof(_nested_music_window_widgets)
925 void ShowMusicWindow()
927 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.