29 #include "table/strings.h" 91 while (*playlist != 0 && playlist <= last) {
97 for (byte *p = playlist; *p != 0 && p <= last; p++) {
121 int id = k * NUM_SONGS_CLASS + i + 1;
123 _playlists[k + 1][j++] =
id + 1;
126 _playlists[k + 1][j] = 0;
140 static void SkipToPrevSong()
146 if (b[0] == 0)
return;
148 do p++;
while (p[0] != 0);
160 static void SkipToNextSong()
177 static void MusicVolumeChanged(byte new_vol)
182 static void DoPlaySong()
184 char filename[MAX_PATH];
192 static void DoStopMusic()
198 static void SelectSongToPlay()
223 uint32 r = InteractiveRandom();
227 if (*a != 0 && *b != 0) {
236 static void StopMusic()
244 static void PlayPlaylistSong()
282 if (_game_mode != GM_MENU) {
292 static void SelectPlaylist(byte list)
325 if (!gui_scope)
return;
326 for (
int i = 0; i < 6; i++) {
339 for (
int i = 0; i < 6; i++) {
340 SetDParam(0, STR_MUSIC_PLAYLIST_ALL + i);
343 d.width += padding.width;
344 d.height += padding.height;
360 d.width =
max(d.width, d2.width);
361 d.height += d2.height;
363 d.width += padding.width;
364 d.height += padding.height;
469 static const NWidgetPart _nested_music_track_selection_widgets[] = {
505 static WindowDesc _music_track_selection_desc(
509 _nested_music_track_selection_widgets,
lengthof(_nested_music_track_selection_widgets)
512 static void ShowMusicTrackSelection()
514 AllocateWindowDescFront<MusicTrackSelectionWindow>(&_music_track_selection_desc, 0);
518 static const int slider_width = 3;
535 d.width += padding.width;
536 d.height += padding.height;
574 StringID str = STR_MUSIC_TRACK_NONE;
578 str = STR_MUSIC_TRACK_DIGIT;
586 StringID str = STR_MUSIC_TITLE_NONE;
588 str = STR_MUSIC_TITLE_NAME;
598 int x = (volume * (r.right - r.left) / 127);
604 DrawFrameRect(x, r.top, x + slider_width, r.bottom, COLOUR_GREY, FR_NONE);
617 if (!gui_scope)
return;
618 for (
int i = 0; i < 6; i++) {
648 int x = pt.x - this->GetWidget<NWidgetBase>(widget)->pos_x;
654 if (new_vol != *vol) {
674 ShowMusicTrackSelection();
688 static const NWidgetPart _nested_music_window_widgets[] = {
711 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),
724 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),
774 _nested_music_window_widgets,
lengthof(_nested_music_window_widgets)
777 void ShowMusicWindow()
780 AllocateWindowDescFront<MusicWindow>(&_music_window_desc, 0);
Functions related to OTTD's strings.
static byte _playlist_old_style[NUM_SONGS_CLASS+1]
Indices of all old style songs.
Old subdirectory for the music.
Music window; Window numbers:
Horizontally center the text.
ResizeInfo resize
Resize information.
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
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...
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
static byte _music_wnd_cursong
The currently played song.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
High level window description.
static int GetTrackNumber(int index)
Get the track number of the song.
static bool IsInsideMM(const T x, const uint min, const uint max)
Checks if a value is in an interval.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Offset at top to draw the frame rectangular area.
static byte _playlist_ezy_street[NUM_SONGS_CLASS+1]
Indices of all ezy street songs.
static byte _playlist_new_style[NUM_SONGS_CLASS+1]
Indices of all new style songs.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Music track selection; Window numbers:
MusicSettings music
settings related to music/sound
#define lastof(x)
Get the last element of an fixed size array.
byte playlist
The playlist (number) to play.
bool playing
Whether music is playing.
MD5File files[NUM_FILES]
All files part of this set.
Subdirectory for all base data (base sets, intro game)
static T max(const T a, const T b)
Returns the maximum of two values.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Functions, definitions and such used only by the GUI.
static byte *const _playlists[]
The different playlists that can be played.
bool _left_button_clicked
Is left mouse button clicked?
Pseudo random number generator.
Data structure for an opened window.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=NULL, uint textref_stack_size=0, const uint32 *textref_stack=NULL)
Display an error message in a window.
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.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
const char * filename
filename
bool shuffle
Whether to shuffle the music.
void InitializeMusic()
Initialize the playlists.
char * FioFindFullPath(char *buf, const char *last, Subdirectory subdir, const char *filename)
Find a path to the filename in one of the search directories.
Functions related to the gfx engine.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
ClientSettings _settings_client
The current settings for this game.
Types related to global configuration settings.
Base for all music playback.
Definition of base types and functions in a cross-platform compatible way.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
A number of safeguards to prevent using unsafe methods.
byte custom_1[33]
The order of the first custom playlist.
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.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
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.
void ValidatePlaylist(byte *playlist, byte *last)
Validate a playlist.
bool FioCheckFileExists(const char *filename, Subdirectory subdir)
Check whether the given file exists.
Functions related to sound.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static const uint8 PC_BLACK
Black palette colour.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
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.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
byte music_vol
The requested music volume.
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
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.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
TextDirection _current_text_dir
Text direction of the currently selected language.
static byte _playlist_all[NUM_SONGS_AVAILABLE+1]
Indices of all songs.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
char song_name[NUM_SONGS_AVAILABLE][32]
The name of the different songs.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Coordinates of a point in 2D.
byte custom_2[33]
The order of the second custom playlist.
static bool _song_is_active
Whether a song is currently played.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
virtual void StopSong()=0
Stop playing the current song.
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.
virtual void PlaySong(const char *filename)=0
Play a particular song.
Find a place automatically.
static const char * GetSongName(int index)
Get the name of the song.
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.
static byte _cur_playlist[NUM_SONGS_PLAYLIST+1]
Indices of the songs in the current playlist.
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 SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.