OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
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;
188 size_t shuffle_index = InteractiveRandom() % (this->
active_playlist.size() - i);
221 if (_game_mode == GM_MENU && this->selected_playlist == PLCH_THEMEONLY) song.
loop =
true;
257 if ((_game_mode == GM_MENU) != (this->selected_playlist == PLCH_THEMEONLY)) {
288 return (this->selected_playlist == PLCH_CUSTOM1) || (this->selected_playlist == PLCH_CUSTOM2);
301 if (song_index >= this->
music_set.size())
return;
305 if (this->standard_playlists[this->selected_playlist].size() >=
NUM_SONGS_PLAYLIST)
return;
308 this->standard_playlists[this->selected_playlist].push_back(entry);
318 size_t newpos = InteractiveRandom() % maxpos;
321 if ((
int)newpos <= this->playlist_position) this->playlist_position++;
339 Playlist &pl = this->standard_playlists[this->selected_playlist];
340 if (song_index >= pl.size())
return;
344 pl.erase(pl.begin() + song_index);
353 if ((
int)i == this->playlist_position && this->
IsPlaying()) this->
Play();
371 this->standard_playlists[this->selected_playlist].clear();
385 this->playlist_position = 0;
387 this->playlist_position += ofs;
389 while (this->playlist_position < 0) this->playlist_position += (int)this->
active_playlist.size();
400 if (pl == PLCH_CUSTOM1) {
402 }
else if (pl == PLCH_CUSTOM2) {
411 for (Playlist::const_iterator song = this->standard_playlists[pl].begin(); song != this->standard_playlists[pl].end(); ++song) {
413 settings_pl[num++] = (byte)song->set_index + 1;
476 if (!gui_scope)
return;
477 for (
int i = 0; i < 6; i++) {
490 for (
int i = 0; i < 6; i++) {
491 SetDParam(0, STR_MUSIC_PLAYLIST_ALL + i);
494 d.width += padding.width;
495 d.height += padding.height;
503 for (MusicSystem::Playlist::const_iterator song =
_music.music_set.begin(); song !=
_music.music_set.end(); ++song) {
508 d.width = std::max(d.width, d2.width);
509 d.height += d2.height;
511 d.width += padding.width;
512 d.height += padding.height;
526 for (MusicSystem::Playlist::const_iterator song =
_music.music_set.begin(); song !=
_music.music_set.end(); ++song) {
540 for (MusicSystem::Playlist::const_iterator song =
_music.active_playlist.begin(); song !=
_music.active_playlist.end(); ++song) {
569 ShowDropDownList(
this, BuildMusicSetDropDownList(&selected), selected, widget, 0,
true,
false);
596 static const NWidgetPart _nested_music_track_selection_widgets[] = {
633 static WindowDesc _music_track_selection_desc(
637 _nested_music_track_selection_widgets,
lengthof(_nested_music_track_selection_widgets)
640 static void ShowMusicTrackSelection()
642 AllocateWindowDescFront<MusicTrackSelectionWindow>(&_music_track_selection_desc, 0);
646 static const int slider_width = 3;
654 UpdateDisabledButtons();
657 void UpdateDisabledButtons()
677 d.width += padding.width;
678 d.height += padding.height;
693 for (MusicSystem::Playlist::const_iterator song =
_music.music_set.begin(); song !=
_music.music_set.end(); ++song) {
719 StringID str = STR_MUSIC_TRACK_NONE;
723 str = STR_MUSIC_TRACK_DIGIT;
731 StringID str = STR_MUSIC_TITLE_NONE;
734 str = STR_MUSIC_TITLE_NOMUSIC;
735 }
else if (
_music.IsPlaying()) {
736 str = STR_MUSIC_TITLE_NAME;
745 const int ha = (r.bottom - r.top) / 5;
746 int wx1 = r.left, wx2 = r.right;
751 const std::vector<Point> wedge{
Point{wx1, r.bottom - ha},
Point{wx2, r.top + ha},
Point{wx2, r.bottom - ha} };
753 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[2].x, wedge[2].y, light);
755 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[1].x, wedge[1].y, shadow);
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);
774 if (!gui_scope)
return;
775 for (
int i = 0; i < 6; i++) {
779 UpdateDisabledButtons();
804 int x = pt.x - this->GetWidget<NWidgetBase>(widget)->pos_x;
808 byte new_vol =
Clamp(x * 127 / (
int)this->GetWidget<NWidgetBase>(widget)->current_x, 0, 127);
811 if (new_vol > 124) new_vol = 127;
812 if (new_vol < 3) new_vol = 0;
813 if (new_vol != *vol) {
834 ShowMusicTrackSelection();
839 _music.ChangePlaylist((MusicSystem::PlaylistChoices)(widget -
WID_M_ALL));
845 static const NWidgetPart _nested_music_window_widgets[] = {
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),
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),
913 _nested_music_window_widgets,
lengthof(_nested_music_window_widgets)
916 void ShowMusicWindow()
918 AllocateWindowDescFront<MusicWindow>(&_music_window_desc, 0);
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 Shuffle()
Enable shuffle mode and restart playback.
void ChangePlaylist(PlaylistChoices pl)
Switch to another playlist, or reload the current one.
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
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-...
void PlaylistClear()
Remove all songs from the current custom playlist.
Dimensions (a width and height) of a rectangle in 2D.
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.
virtual void PlaySong(const MusicSongInfo &song)=0
Play a particular song.
void GfxFillPolygon(const std::vector< Point > &shape, int colour, FillRectMode mode)
Fill a polygon with colour.
virtual void SetVolume(byte vol)=0
Set the volume, if possible.
bool IsShuffle() const
Is shuffle mode enabled?
bool IsCustomPlaylist() const
Is one of the custom playlists selected?
bool shuffle
Whether to shuffle the music.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
void PlaylistAdd(size_t song_index)
Append a song to a custom playlist.
bool loop
song should play in a tight loop if possible, never ending
ClientSettings _settings_client
The current settings for this game.
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.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
void Play()
Start/restart playback at current song.
int32 WindowNumber
Number to differentiate different windows of the same class.
@ WC_MUSIC_WINDOW
Music window; Window numbers:
@ SA_HOR_CENTER
Horizontally center the text.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void MusicLoop()
Check music playback status and start/stop/song-finished.
void Prev()
Skip to previous track.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Playlist displayed_playlist
current playlist as displayed in GUI, never in shuffled order
bool playing
Whether music is playing.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
void Next()
Skip to next track.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
@ WN_GAME_OPTIONS_GAME_OPTIONS
Game options.
High level window description.
@ WDP_AUTO
Find a place automatically.
ResizeInfo resize
Resize information.
static MusicDriver * GetInstance()
Get the currently active instance of the music driver.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void CheckStatus()
Check that music is playing if it should, and that appropriate playlist is active for game/main menu.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
char songname[32]
name of song displayed in UI
void ChangeMusicSet(const std::string &set_name)
Change to named music set, and reset playback.
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
void BuildPlaylists()
Rebuild all playlists for the current music set.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
bool IsPlaying() const
Is the player getting music right now?
Metadata about a music track.
void Unshuffle()
Disable shuffle and restart playback.
byte custom_2[33]
The order of the second custom playlist.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
byte playlist
The playlist (number) to play.
Coordinates of a point in 2D.
static const uint8 PC_BLACK
Black palette colour.
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.
int mouse_capture_widget
Widgetindex of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse captu...
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
@ WC_GAME_OPTIONS
Game options window; Window numbers:
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void InitializeMusic()
Prepare the music system for use.
static IDirectMusic * _music
The direct music object manages buffers and ports.
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
void SaveCustomPlaylist(PlaylistChoices pl)
Save a custom playlist to settings after modification.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
PlaylistEntry GetCurrentSong() const
Return the current song, or a dummy if none.
const char * filename
file on disk containing song (when used in MusicSet class, this pointer is owned by MD5File object fo...
#define lengthof(x)
Return the length of an fixed size array.
byte effect_vol
The requested effects volume.
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
const MusicSet * set
music set the song comes from
uint set_index
index of song in set
void Stop()
Stop playback and set flag that we don't intend to play music.
Data structure for an opened window.
void ChangePlaylistPosition(int ofs)
Change playlist position pointer by the given offset, making sure to keep it within valid range.
Playlist active_playlist
current play order of songs, including any shuffle
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Specification of a rectangle with absolute coordinates of all edges.
void LowerWidget(byte widget_index)
Marks a widget as lowered.
int GetRowFromWidget(int clickpos, int widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
MusicSettings music
settings related to music/sound
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
void ChangeMusicSet(int index)
Change the configured music set and reset playback.
byte music_vol
The requested music volume.
Playlist music_set
all songs in current music set, in set order
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
int cat_index
entry index in CAT file, for filetype==MTT_MPSMIDI
byte custom_1[33]
The order of the first custom playlist.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
@ WC_MUSIC_TRACK_SELECTION
Music track selection; Window numbers:
void PlaylistRemove(size_t song_index)
Remove a song from a custom playlist.
virtual void StopSong()=0
Stop playing the current song.