29#include "slider_func.h"
34#include "table/strings.h"
46 bool IsValid()
const {
return !this->
songname.empty(); }
48 typedef std::vector<PlaylistEntry> Playlist;
50 enum PlaylistChoices : uint8_t {
64 PlaylistChoices selected_playlist{};
92 int playlist_position = 0;
96 std::array<Playlist, PLCH_MAX> standard_playlists{};
108 for (
auto &playlist : this->standard_playlists) playlist.clear();
114 if (!entry.IsValid())
continue;
119 if (i == 0) this->standard_playlists[PLCH_THEMEONLY].push_back(std::move(entry));
123 this->standard_playlists[PLCH_ALLMUSIC].push_back(entry);
125 this->standard_playlists[PLCH_OLDSTYLE + theme].push_back(std::move(entry));
134 if (entry.IsValid()) this->standard_playlists[PLCH_CUSTOM1].push_back(std::move(entry));
138 if (entry.IsValid()) this->standard_playlists[PLCH_CUSTOM2].push_back(std::move(entry));
149 assert(pl < PLCH_MAX && pl >= PLCH_ALLMUSIC);
153 if (_game_mode != GM_MENU || pl == PLCH_THEMEONLY) {
154 this->selected_playlist = pl;
155 this->
active_playlist = this->standard_playlists[this->selected_playlist];
156 this->playlist_position = 0;
199 return static_cast<size_t>(this->playlist_position) < this->
active_playlist.size()
212 this->
active_playlist = this->standard_playlists[this->selected_playlist];
214 size_t shuffle_index = InteractiveRandom() % (this->
active_playlist.size() - i);
231 this->
active_playlist = this->standard_playlists[this->selected_playlist];
251 if (_game_mode == GM_MENU && this->selected_playlist == PLCH_THEMEONLY) song.
loop =
true;
287 if ((_game_mode == GM_MENU) != (this->selected_playlist == PLCH_THEMEONLY)) {
318 return (this->selected_playlist == PLCH_CUSTOM1) || (this->selected_playlist == PLCH_CUSTOM2);
331 if (song_index >= this->
music_set.size())
return;
335 if (this->standard_playlists[this->selected_playlist].size() >=
NUM_SONGS_PLAYLIST)
return;
338 this->standard_playlists[this->selected_playlist].push_back(entry);
347 size_t newpos = InteractiveRandom() % maxpos;
350 if ((
int)newpos <= this->playlist_position) this->playlist_position++;
368 Playlist &pl = this->standard_playlists[this->selected_playlist];
369 if (song_index >= pl.size())
return;
373 pl.erase(pl.begin() + song_index);
381 if ((
int)i == this->playlist_position && this->
IsPlaying()) this->
Play();
399 this->standard_playlists[this->selected_playlist].clear();
413 this->playlist_position = 0;
415 this->playlist_position += ofs;
417 while (this->playlist_position < 0) this->playlist_position += (int)this->
active_playlist.size();
427 uint8_t *settings_pl;
428 if (pl == PLCH_CUSTOM1) {
430 }
else if (pl == PLCH_CUSTOM2) {
439 for (
const auto &song : this->standard_playlists[pl]) {
441 settings_pl[num++] = (uint8_t)song.set_index + 1;
504 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
506 if (!gui_scope)
return;
507 for (
int i = 0; i < 6; i++) {
525 for (
int i = 0; i < 6; i++) {
528 d.width += padding.width;
529 d.height += padding.height;
537 for (
const auto &song : _music.
music_set) {
542 d.width += padding.width;
543 d.height += padding.height;
557 for (
const auto &song : _music.
music_set) {
594 ShowDropDownList(
this, BuildSetDropDownList<BaseMusic>(&selected), selected, widget);
621static constexpr NWidgetPart _nested_music_track_selection_widgets[] = {
662 _nested_music_track_selection_widgets
665static void ShowMusicTrackSelection()
667 AllocateWindowDescFront<MusicTrackSelectionWindow>(_music_track_selection_desc, 0);
677 UpdateDisabledButtons();
680 void UpdateDisabledButtons()
702 d.width += padding.width;
703 d.height += padding.height;
711 d.width += padding.width;
719 for (
const auto &song : _music.
music_set) {
722 d.width += padding.width;
784 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
786 if (!gui_scope)
return;
787 for (
int i = 0; i < 6; i++) {
791 UpdateDisabledButtons();
821 if (
ClickSliderWidget(this->GetWidget<NWidgetBase>(widget)->GetCurrentRect(), pt, 0, INT8_MAX, 0, vol)) {
825 SetEffectVolume(vol);
846 ShowMusicTrackSelection();
857static constexpr NWidgetPart _nested_music_window_widgets[] = {
880 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_M_MUSIC_VOL),
SetMinimalSize(67, 0),
SetMinimalTextLines(1, 0),
SetFill(1, 0),
SetToolTip(STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
884 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_M_EFFECT_VOL),
SetMinimalSize(67, 0),
SetMinimalTextLines(1, 0),
SetFill(1, 0),
SetToolTip(STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
921 _nested_music_window_widgets
924void ShowMusicWindow()
926 AllocateWindowDescFront<MusicWindow>(_music_window_desc, 0);
static std::string ini_set
The set as saved in the config file.
virtual void StopSong()=0
Stop playing the current song.
static MusicDriver * GetInstance()
Get the currently active instance of the music driver.
virtual void PlaySong(const MusicSongInfo &song)=0
Play a particular song.
virtual void SetVolume(uint8_t vol)=0
Set the volume, if possible.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Functions related to the drop down widget.
Types related to the drop down widget.
Functions related to errors.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Functions related to the gfx engine.
@ FS_SMALL
Index of the small font in the font tables.
@ SA_HOR_CENTER
Horizontally center the text.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Functions to mix sound samples.
Base for all music playback.
void MusicLoop()
Check music playback status and start/stop/song-finished.
void ChangeMusicSet(int index)
Change the configured music set and reset playback.
void InitializeMusic()
Prepare the music system for use.
static constexpr PixelColour PC_BLACK
Black palette colour.
Pseudo random number generator.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Functions for setting GUIs.
Types related to global configuration settings.
void DrawSliderWidget(Rect r, Colours wedge_colour, Colours handle_colour, TextColour text_colour, int min_value, int max_value, int nmarks, int value, SliderMarkFunc *mark_func)
Draw a slider widget with knob at given value.
bool ClickSliderWidget(Rect r, Point pt, int min_value, int max_value, int nmarks, int &value)
Handle click on a slider widget to change the value.
Functions related to sound.
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
Functions related to low-level strings.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
uint64_t GetParamMaxDigits(uint count, FontSize size)
Get some number that is suitable for string size computations.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
MusicSettings music
settings related to music/sound
Dimensions (a width and height) of a rectangle in 2D.
uint8_t effect_vol
The requested effects volume.
bool playing
Whether music is playing.
uint8_t music_vol
The requested music volume.
uint8_t custom_1[33]
The order of the first custom playlist.
uint8_t custom_2[33]
The order of the second custom playlist.
uint8_t playlist
The playlist (number) to play.
bool shuffle
Whether to shuffle the music.
Metadata about a music track.
std::string songname
name of song displayed in UI
uint8_t tracknr
track number of song displayed in UI
std::string filename
file on disk containing song (when used in MusicSet class)
bool loop
song should play in a tight loop if possible, never ending
int cat_index
entry index in CAT file, for filetype==MTT_MPSMIDI
const MusicSet * set
music set the song comes from
uint set_index
index of song in set
void SaveCustomPlaylist(PlaylistChoices pl)
Save a custom playlist to settings after modification.
void CheckStatus()
Check that music is playing if it should, and that appropriate playlist is active for game/main menu.
void ChangeMusicSet(const std::string &set_name)
Change to named music set, and reset playback.
void ChangePlaylist(PlaylistChoices pl)
Switch to another playlist, or reload the current one.
void Shuffle()
Enable shuffle mode.
void Stop()
Stop playback and set flag that we don't intend to play music.
void BuildPlaylists()
Rebuild all playlists for the current music set.
void Next()
Skip to next track.
void Play()
Start/restart playback at current song.
bool IsPlaying() const
Is the player getting music right now?
void Unshuffle()
Disable shuffle mode.
void PlaylistRemove(size_t song_index)
Remove a song from a custom playlist.
PlaylistEntry GetCurrentSong() const
Return the current song, or a dummy if none.
void PlaylistAdd(size_t song_index)
Append a song to a custom playlist.
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 Prev()
Skip to previous track.
void PlaylistClear()
Remove all songs from the current custom playlist.
void SetPositionBySetIndex(uint set_index)
Set playlist position by set index.
bool IsCustomPlaylist() const
Is one of the custom playlists selected?
bool IsShuffle() const
Is shuffle mode enabled?
Playlist music_set
all songs in current music set, in set order
uint GetSetIndex()
Get set index from current playlist position.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void UpdateWidgetSize(WidgetID 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, WidgetID widget) const override
Draw the contents of a nested widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
High level window description.
Number to differentiate different windows of the same class.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
WidgetID mouse_capture_widget
ID of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse capture.
ResizeInfo resize
Resize information.
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
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-...
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ WDP_AUTO
Find a place automatically.
@ WN_GAME_OPTIONS_GAME_OPTIONS
Game options.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_MUSIC_TRACK_SELECTION
Music track selection; Window numbers:
@ WC_MUSIC_WINDOW
Music window; Window numbers:
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Functions related to zooming.