2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file music_gui.cpp GUI for the music playback. */
|
2007-03-03 04:04:22 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2009-12-22 21:40:29 +00:00
|
|
|
#include "base_media_base.h"
|
2007-07-05 12:23:54 +00:00
|
|
|
#include "music/music_driver.hpp"
|
2007-12-19 19:44:29 +00:00
|
|
|
#include "window_gui.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "window_func.h"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_func.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "gfx_func.h"
|
2008-01-29 00:26:31 +00:00
|
|
|
#include "core/random_func.hpp"
|
2011-12-10 13:54:10 +00:00
|
|
|
#include "error.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "core/geometry_func.hpp"
|
|
|
|
#include "string_func.h"
|
2011-03-05 18:00:48 +00:00
|
|
|
#include "settings_type.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-12-15 22:22:55 +00:00
|
|
|
#include "widgets/music_widget.h"
|
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/sprites.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2009-12-22 18:34:07 +00:00
|
|
|
/**
|
|
|
|
* Get the name of the song.
|
|
|
|
* @param index of the song.
|
|
|
|
* @return the name of the song.
|
|
|
|
*/
|
|
|
|
static const char *GetSongName(int index)
|
|
|
|
{
|
2009-12-22 21:40:29 +00:00
|
|
|
return BaseMusic::GetUsedSet()->song_name[index];
|
2009-12-22 18:34:07 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 21:40:29 +00:00
|
|
|
/**
|
|
|
|
* Get the track number of the song.
|
|
|
|
* @param index of the song.
|
|
|
|
* @return the track number of the song.
|
|
|
|
*/
|
|
|
|
static int GetTrackNumber(int index)
|
|
|
|
{
|
|
|
|
return BaseMusic::GetUsedSet()->track_nr[index];
|
|
|
|
}
|
2009-12-22 18:34:07 +00:00
|
|
|
|
2009-12-22 21:40:29 +00:00
|
|
|
/** The currently played song */
|
|
|
|
static byte _music_wnd_cursong = 1;
|
|
|
|
/** Whether a song is currently played */
|
|
|
|
static bool _song_is_active = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-12-22 21:40:29 +00:00
|
|
|
/** Indices of the songs in the current playlist */
|
|
|
|
static byte _cur_playlist[NUM_SONGS_PLAYLIST + 1];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-12-22 21:40:29 +00:00
|
|
|
/** Indices of all songs */
|
|
|
|
static byte _playlist_all[NUM_SONGS_AVAILABLE + 1];
|
|
|
|
/** Indices of all old style songs */
|
|
|
|
static byte _playlist_old_style[NUM_SONGS_CLASS + 1];
|
|
|
|
/** Indices of all new style songs */
|
|
|
|
static byte _playlist_new_style[NUM_SONGS_CLASS + 1];
|
|
|
|
/** Indices of all ezy street songs */
|
|
|
|
static byte _playlist_ezy_street[NUM_SONGS_CLASS + 1];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-03-05 18:00:48 +00:00
|
|
|
assert_compile(lengthof(_settings_client.music.custom_1) == NUM_SONGS_PLAYLIST + 1);
|
|
|
|
assert_compile(lengthof(_settings_client.music.custom_2) == NUM_SONGS_PLAYLIST + 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-12-22 21:40:29 +00:00
|
|
|
/** The different playlists that can be played. */
|
2004-08-09 17:04:08 +00:00
|
|
|
static byte * const _playlists[] = {
|
|
|
|
_playlist_all,
|
|
|
|
_playlist_old_style,
|
|
|
|
_playlist_new_style,
|
|
|
|
_playlist_ezy_street,
|
2011-03-05 18:00:48 +00:00
|
|
|
_settings_client.music.custom_1,
|
|
|
|
_settings_client.music.custom_2,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2009-12-22 21:40:29 +00:00
|
|
|
/**
|
|
|
|
* Validate a playlist.
|
2011-10-16 19:56:47 +00:00
|
|
|
* @param playlist The playlist to validate.
|
|
|
|
* @param last The last location in the list.
|
2009-12-22 21:40:29 +00:00
|
|
|
*/
|
2011-10-16 19:59:07 +00:00
|
|
|
void ValidatePlaylist(byte *playlist, byte *last)
|
2009-12-22 21:40:29 +00:00
|
|
|
{
|
2011-10-16 19:56:47 +00:00
|
|
|
while (*playlist != 0 && playlist <= last) {
|
2011-10-16 19:53:02 +00:00
|
|
|
/* Song indices are saved off-by-one so 0 is "nothing". */
|
|
|
|
if (*playlist <= NUM_SONGS_AVAILABLE && !StrEmpty(GetSongName(*playlist - 1))) {
|
2009-12-22 21:40:29 +00:00
|
|
|
playlist++;
|
|
|
|
continue;
|
|
|
|
}
|
2011-10-16 19:56:47 +00:00
|
|
|
for (byte *p = playlist; *p != 0 && p <= last; p++) {
|
2009-12-22 21:40:29 +00:00
|
|
|
p[0] = p[1];
|
|
|
|
}
|
|
|
|
}
|
2011-10-16 19:56:47 +00:00
|
|
|
|
|
|
|
/* Make sure the list is null terminated. */
|
|
|
|
*last = 0;
|
2009-12-22 21:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Initialize the playlists */
|
|
|
|
void InitializeMusic()
|
|
|
|
{
|
|
|
|
uint j = 0;
|
|
|
|
for (uint i = 0; i < NUM_SONGS_AVAILABLE; i++) {
|
|
|
|
if (StrEmpty(GetSongName(i))) continue;
|
|
|
|
_playlist_all[j++] = i + 1;
|
|
|
|
}
|
|
|
|
/* Terminate the list */
|
|
|
|
_playlist_all[j] = 0;
|
|
|
|
|
|
|
|
/* Now make the 'styled' playlists */
|
|
|
|
for (uint k = 0; k < NUM_SONG_CLASSES; k++) {
|
|
|
|
j = 0;
|
|
|
|
for (uint i = 0; i < NUM_SONGS_CLASS; i++) {
|
|
|
|
int id = k * NUM_SONGS_CLASS + i + 1;
|
|
|
|
if (StrEmpty(GetSongName(id))) continue;
|
|
|
|
_playlists[k + 1][j++] = id + 1;
|
|
|
|
}
|
|
|
|
/* Terminate the list */
|
|
|
|
_playlists[k + 1][j] = 0;
|
|
|
|
}
|
|
|
|
|
2011-10-16 19:56:47 +00:00
|
|
|
ValidatePlaylist(_settings_client.music.custom_1, lastof(_settings_client.music.custom_1));
|
|
|
|
ValidatePlaylist(_settings_client.music.custom_2, lastof(_settings_client.music.custom_2));
|
2009-12-22 21:40:29 +00:00
|
|
|
|
|
|
|
if (BaseMusic::GetUsedSet()->num_available < _music_wnd_cursong) {
|
|
|
|
/* If there are less songs than the currently played song,
|
|
|
|
* just pause and reset to no song. */
|
|
|
|
_music_wnd_cursong = 0;
|
|
|
|
_song_is_active = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void SkipToPrevSong()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
byte *b = _cur_playlist;
|
|
|
|
byte *p = b;
|
|
|
|
byte t;
|
|
|
|
|
2006-10-17 03:39:30 +00:00
|
|
|
if (b[0] == 0) return; // empty playlist
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-10-17 03:39:30 +00:00
|
|
|
do p++; while (p[0] != 0); // find the end
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-17 03:39:30 +00:00
|
|
|
t = *--p; // and copy the bytes
|
2004-08-09 17:04:08 +00:00
|
|
|
while (p != b) {
|
|
|
|
p--;
|
|
|
|
p[1] = p[0];
|
|
|
|
}
|
|
|
|
*b = t;
|
|
|
|
|
|
|
|
_song_is_active = false;
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void SkipToNextSong()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-01-10 00:31:47 +00:00
|
|
|
byte *b = _cur_playlist;
|
2005-11-14 19:48:04 +00:00
|
|
|
byte t;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
t = b[0];
|
|
|
|
if (t != 0) {
|
|
|
|
while (b[1] != 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
b[0] = b[1];
|
|
|
|
b++;
|
|
|
|
}
|
|
|
|
b[0] = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
_song_is_active = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void MusicVolumeChanged(byte new_vol)
|
|
|
|
{
|
2007-07-05 12:23:54 +00:00
|
|
|
_music_driver->SetVolume(new_vol);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void DoPlaySong()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-17 15:48:57 +00:00
|
|
|
char filename[MAX_PATH];
|
2011-12-04 14:17:51 +00:00
|
|
|
if (FioFindFullPath(filename, lengthof(filename), BASESET_DIR, BaseMusic::GetUsedSet()->files[_music_wnd_cursong - 1].filename) == NULL) {
|
|
|
|
FioFindFullPath(filename, lengthof(filename), OLD_GM_DIR, BaseMusic::GetUsedSet()->files[_music_wnd_cursong - 1].filename);
|
|
|
|
}
|
2007-07-05 12:23:54 +00:00
|
|
|
_music_driver->PlaySong(filename);
|
2009-12-22 21:40:29 +00:00
|
|
|
SetWindowDirty(WC_MUSIC_WINDOW, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void DoStopMusic()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-07-05 12:23:54 +00:00
|
|
|
_music_driver->StopSong();
|
2009-12-22 21:40:29 +00:00
|
|
|
SetWindowDirty(WC_MUSIC_WINDOW, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void SelectSongToPlay()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-31 17:18:43 +00:00
|
|
|
uint i = 0;
|
2006-07-07 02:44:51 +00:00
|
|
|
uint j = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-31 17:18:43 +00:00
|
|
|
memset(_cur_playlist, 0, sizeof(_cur_playlist));
|
2005-06-01 11:52:44 +00:00
|
|
|
do {
|
2011-03-05 18:00:48 +00:00
|
|
|
const char *filename = BaseMusic::GetUsedSet()->files[_playlists[_settings_client.music.playlist][i] - 1].filename;
|
2007-06-17 15:48:57 +00:00
|
|
|
/* We are now checking for the existence of that file prior
|
|
|
|
* to add it to the list of available songs */
|
2011-11-14 21:34:27 +00:00
|
|
|
if (!StrEmpty(filename) && FioCheckFileExists(filename, BASESET_DIR)) {
|
2011-03-05 18:00:48 +00:00
|
|
|
_cur_playlist[j] = _playlists[_settings_client.music.playlist][i];
|
2007-06-17 15:48:57 +00:00
|
|
|
j++;
|
2006-07-07 02:44:51 +00:00
|
|
|
}
|
2011-03-05 18:00:48 +00:00
|
|
|
} while (_playlists[_settings_client.music.playlist][++i] != 0 && j < lengthof(_cur_playlist) - 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-10-17 01:33:21 +00:00
|
|
|
/* Do not shuffle when on the intro-start window, as the song to play has to be the original TTD Theme*/
|
2011-03-05 18:00:48 +00:00
|
|
|
if (_settings_client.music.shuffle && _game_mode != GM_MENU) {
|
2004-08-09 17:04:08 +00:00
|
|
|
i = 500;
|
|
|
|
do {
|
|
|
|
uint32 r = InteractiveRandom();
|
2005-07-20 15:29:28 +00:00
|
|
|
byte *a = &_cur_playlist[GB(r, 0, 5)];
|
|
|
|
byte *b = &_cur_playlist[GB(r, 8, 5)];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (*a != 0 && *b != 0) {
|
|
|
|
byte t = *a;
|
|
|
|
*a = *b;
|
|
|
|
*b = t;
|
|
|
|
}
|
|
|
|
} while (--i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void StopMusic()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_music_wnd_cursong = 0;
|
|
|
|
DoStopMusic();
|
|
|
|
_song_is_active = false;
|
2009-09-13 19:15:59 +00:00
|
|
|
SetWindowWidgetDirty(WC_MUSIC_WINDOW, 0, 9);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void PlayPlaylistSong()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if (_cur_playlist[0] == 0) {
|
|
|
|
SelectSongToPlay();
|
2006-10-17 03:39:30 +00:00
|
|
|
/* if there is not songs in the playlist, it may indicate
|
|
|
|
* no file on the gm folder, or even no gm folder.
|
|
|
|
* Stop the playback, then */
|
2006-07-07 02:44:51 +00:00
|
|
|
if (_cur_playlist[0] == 0) {
|
|
|
|
_song_is_active = false;
|
|
|
|
_music_wnd_cursong = 0;
|
2011-03-05 18:00:48 +00:00
|
|
|
_settings_client.music.playing = false;
|
2006-07-07 02:44:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
_music_wnd_cursong = _cur_playlist[0];
|
|
|
|
DoPlaySong();
|
|
|
|
_song_is_active = true;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2009-09-13 19:15:59 +00:00
|
|
|
SetWindowWidgetDirty(WC_MUSIC_WINDOW, 0, 9);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ResetMusic()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_music_wnd_cursong = 1;
|
|
|
|
DoPlaySong();
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void MusicLoop()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2011-03-05 18:00:48 +00:00
|
|
|
if (!_settings_client.music.playing && _song_is_active) {
|
2004-08-09 17:04:08 +00:00
|
|
|
StopMusic();
|
2011-03-05 18:00:48 +00:00
|
|
|
} else if (_settings_client.music.playing && !_song_is_active) {
|
2007-10-17 01:33:21 +00:00
|
|
|
PlayPlaylistSong();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-07-07 02:44:51 +00:00
|
|
|
if (!_song_is_active) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-05 12:23:54 +00:00
|
|
|
if (!_music_driver->IsSongPlaying()) {
|
2005-04-24 19:04:56 +00:00
|
|
|
if (_game_mode != GM_MENU) {
|
|
|
|
StopMusic();
|
|
|
|
SkipToNextSong();
|
|
|
|
PlayPlaylistSong();
|
2005-11-14 19:48:04 +00:00
|
|
|
} else {
|
2005-04-24 19:04:56 +00:00
|
|
|
ResetMusic();
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 14:09:51 +00:00
|
|
|
static void SelectPlaylist(byte list)
|
|
|
|
{
|
2011-03-05 18:00:48 +00:00
|
|
|
_settings_client.music.playlist = list;
|
2009-09-02 14:09:51 +00:00
|
|
|
InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0);
|
|
|
|
InvalidateWindowData(WC_MUSIC_WINDOW, 0);
|
|
|
|
}
|
|
|
|
|
2008-05-17 22:52:51 +00:00
|
|
|
struct MusicTrackSelectionWindow : public Window {
|
2013-05-26 19:23:42 +00:00
|
|
|
MusicTrackSelectionWindow(WindowDesc *desc, WindowNumber number) : Window(desc)
|
2008-05-17 22:52:51 +00:00
|
|
|
{
|
2013-05-26 19:23:42 +00:00
|
|
|
this->InitNested(number);
|
2011-12-16 18:02:27 +00:00
|
|
|
this->LowerWidget(WID_MTS_LIST_LEFT);
|
|
|
|
this->LowerWidget(WID_MTS_LIST_RIGHT);
|
|
|
|
this->SetWidgetDisabledState(WID_MTS_CLEAR, _settings_client.music.playlist <= 3);
|
|
|
|
this->LowerWidget(WID_MTS_ALL + _settings_client.music.playlist);
|
2008-05-17 22:52:51 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 14:09:51 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
2008-05-17 22:52:51 +00:00
|
|
|
{
|
2009-09-02 14:09:51 +00:00
|
|
|
switch (widget) {
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_MTS_PLAYLIST:
|
2011-03-05 18:00:48 +00:00
|
|
|
SetDParam(0, STR_MUSIC_PLAYLIST_ALL + _settings_client.music.playlist);
|
2009-09-02 14:09:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-03-13 21:31:29 +00:00
|
|
|
/**
|
|
|
|
* Some data on this window has become invalid.
|
|
|
|
* @param data Information about the changed data.
|
|
|
|
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
|
|
|
|
*/
|
|
|
|
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
2009-09-02 14:09:51 +00:00
|
|
|
{
|
2011-03-13 21:31:29 +00:00
|
|
|
if (!gui_scope) return;
|
2009-09-02 14:09:51 +00:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2011-12-16 18:02:27 +00:00
|
|
|
this->SetWidgetLoweredState(WID_MTS_ALL + i, i == _settings_client.music.playlist);
|
2009-09-02 14:09:51 +00:00
|
|
|
}
|
2011-12-16 18:02:27 +00:00
|
|
|
this->SetWidgetDisabledState(WID_MTS_CLEAR, _settings_client.music.playlist <= 3);
|
2009-09-02 14:09:51 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-09-02 14:09:51 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_MTS_PLAYLIST: {
|
2009-09-02 14:09:51 +00:00
|
|
|
Dimension d = {0, 0};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-09-02 14:09:51 +00:00
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
SetDParam(0, STR_MUSIC_PLAYLIST_ALL + i);
|
|
|
|
d = maxdim(d, GetStringBoundingBox(STR_PLAYLIST_PROGRAM));
|
|
|
|
}
|
|
|
|
d.width += padding.width;
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = maxdim(*size, d);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_MTS_LIST_LEFT: case WID_MTS_LIST_RIGHT: {
|
2009-09-02 14:09:51 +00:00
|
|
|
Dimension d = {0, 0};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-12-22 21:40:29 +00:00
|
|
|
for (uint i = 0; i < NUM_SONGS_AVAILABLE; i++) {
|
|
|
|
const char *song_name = GetSongName(i);
|
|
|
|
if (StrEmpty(song_name)) continue;
|
|
|
|
|
|
|
|
SetDParam(0, GetTrackNumber(i));
|
2009-11-19 13:56:10 +00:00
|
|
|
SetDParam(1, 2);
|
2009-12-22 21:40:29 +00:00
|
|
|
SetDParamStr(2, GetSongName(i));
|
2009-11-19 13:56:10 +00:00
|
|
|
Dimension d2 = GetStringBoundingBox(STR_PLAYLIST_TRACK_NAME);
|
2009-09-02 14:09:51 +00:00
|
|
|
d.width = max(d.width, d2.width);
|
|
|
|
d.height += d2.height;
|
|
|
|
}
|
|
|
|
d.width += padding.width;
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = maxdim(*size, d);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2009-09-02 14:09:51 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-09-02 14:09:51 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_MTS_LIST_LEFT: {
|
2011-05-06 21:13:29 +00:00
|
|
|
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK);
|
2009-09-02 14:09:51 +00:00
|
|
|
|
|
|
|
int y = r.top + WD_FRAMERECT_TOP;
|
2009-12-22 21:40:29 +00:00
|
|
|
for (uint i = 0; i < NUM_SONGS_AVAILABLE; i++) {
|
|
|
|
const char *song_name = GetSongName(i);
|
|
|
|
if (StrEmpty(song_name)) continue;
|
|
|
|
|
|
|
|
SetDParam(0, GetTrackNumber(i));
|
2009-11-19 13:56:10 +00:00
|
|
|
SetDParam(1, 2);
|
2009-12-22 21:40:29 +00:00
|
|
|
SetDParamStr(2, song_name);
|
2009-11-19 13:56:10 +00:00
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_PLAYLIST_TRACK_NAME);
|
2009-09-02 14:09:51 +00:00
|
|
|
y += FONT_HEIGHT_SMALL;
|
|
|
|
}
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_MTS_LIST_RIGHT: {
|
2011-05-06 21:13:29 +00:00
|
|
|
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK);
|
2009-09-02 14:09:51 +00:00
|
|
|
|
|
|
|
int y = r.top + WD_FRAMERECT_TOP;
|
2011-03-05 18:00:48 +00:00
|
|
|
for (const byte *p = _playlists[_settings_client.music.playlist]; *p != 0; p++) {
|
2009-12-22 21:40:29 +00:00
|
|
|
uint i = *p - 1;
|
|
|
|
SetDParam(0, GetTrackNumber(i));
|
2009-11-19 13:56:10 +00:00
|
|
|
SetDParam(1, 2);
|
2009-12-22 21:40:29 +00:00
|
|
|
SetDParamStr(2, GetSongName(i));
|
2009-11-19 13:56:10 +00:00
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_PLAYLIST_TRACK_NAME);
|
2009-09-02 14:09:51 +00:00
|
|
|
y += FONT_HEIGHT_SMALL;
|
|
|
|
}
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-17 22:52:51 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_MTS_LIST_LEFT: { // add to playlist
|
2010-07-26 13:02:28 +00:00
|
|
|
int y = this->GetRowFromWidget(pt.y, widget, 0, FONT_HEIGHT_SMALL);
|
2008-05-17 22:52:51 +00:00
|
|
|
|
2011-03-05 18:00:48 +00:00
|
|
|
if (_settings_client.music.playlist < 4) return;
|
2009-12-22 21:40:29 +00:00
|
|
|
if (!IsInsideMM(y, 0, BaseMusic::GetUsedSet()->num_available)) return;
|
2008-05-17 22:52:51 +00:00
|
|
|
|
2011-03-05 18:00:48 +00:00
|
|
|
byte *p = _playlists[_settings_client.music.playlist];
|
2009-04-10 10:29:28 +00:00
|
|
|
for (uint i = 0; i != NUM_SONGS_PLAYLIST - 1; i++) {
|
2008-05-17 22:52:51 +00:00
|
|
|
if (p[i] == 0) {
|
2009-12-22 21:40:29 +00:00
|
|
|
/* Find the actual song number */
|
|
|
|
for (uint j = 0; j < NUM_SONGS_AVAILABLE; j++) {
|
|
|
|
if (GetTrackNumber(j) == y + 1) {
|
|
|
|
p[i] = j + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-05-17 22:52:51 +00:00
|
|
|
p[i + 1] = 0;
|
|
|
|
this->SetDirty();
|
|
|
|
SelectSongToPlay();
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-07-07 02:44:51 +00:00
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_MTS_LIST_RIGHT: { // remove from playlist
|
2010-07-26 13:02:28 +00:00
|
|
|
int y = this->GetRowFromWidget(pt.y, widget, 0, FONT_HEIGHT_SMALL);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-03-05 18:00:48 +00:00
|
|
|
if (_settings_client.music.playlist < 4) return;
|
2009-12-22 21:40:29 +00:00
|
|
|
if (!IsInsideMM(y, 0, NUM_SONGS_PLAYLIST)) return;
|
2006-07-07 02:44:51 +00:00
|
|
|
|
2011-03-05 18:00:48 +00:00
|
|
|
byte *p = _playlists[_settings_client.music.playlist];
|
2009-04-10 10:29:28 +00:00
|
|
|
for (uint i = y; i != NUM_SONGS_PLAYLIST - 1; i++) {
|
2008-05-17 22:52:51 +00:00
|
|
|
p[i] = p[i + 1];
|
2006-07-07 02:44:51 +00:00
|
|
|
}
|
|
|
|
|
2008-05-17 22:52:51 +00:00
|
|
|
this->SetDirty();
|
|
|
|
SelectSongToPlay();
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-07-07 02:44:51 +00:00
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_MTS_CLEAR: // clear
|
2011-03-05 18:00:48 +00:00
|
|
|
for (uint i = 0; _playlists[_settings_client.music.playlist][i] != 0; i++) _playlists[_settings_client.music.playlist][i] = 0;
|
2008-05-17 22:52:51 +00:00
|
|
|
this->SetDirty();
|
|
|
|
StopMusic();
|
|
|
|
SelectSongToPlay();
|
|
|
|
break;
|
2006-07-07 02:44:51 +00:00
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_MTS_ALL: case WID_MTS_OLD: case WID_MTS_NEW:
|
|
|
|
case WID_MTS_EZY: case WID_MTS_CUSTOM1: case WID_MTS_CUSTOM2: // set playlist
|
|
|
|
SelectPlaylist(widget - WID_MTS_ALL);
|
2008-05-17 22:52:51 +00:00
|
|
|
StopMusic();
|
|
|
|
SelectSongToPlay();
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-17 22:52:51 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-04-10 11:06:12 +00:00
|
|
|
static const NWidgetPart _nested_music_track_selection_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_PLAYLIST_MUSIC_PROGRAM_SELECTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-04-10 11:06:12 +00:00
|
|
|
EndContainer(),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY),
|
2009-04-10 11:06:12 +00:00
|
|
|
NWidget(NWID_HORIZONTAL), SetPIP(2, 4, 2),
|
|
|
|
/* Left panel. */
|
|
|
|
NWidget(NWID_VERTICAL),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_PLAYLIST_TRACK_INDEX, STR_NULL),
|
2011-12-16 18:02:27 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_MTS_LIST_LEFT), SetMinimalSize(180, 194), SetDataTip(0x0, STR_PLAYLIST_TOOLTIP_CLICK_TO_ADD_TRACK), EndContainer(),
|
2009-04-10 11:06:12 +00:00
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
|
|
|
|
EndContainer(),
|
|
|
|
/* Middle buttons. */
|
|
|
|
NWidget(NWID_VERTICAL),
|
2009-09-02 14:09:51 +00:00
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(60, 30), // Space above the first button from the title bar.
|
2011-12-16 18:02:27 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_ALL), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_ALL, STR_MUSIC_TOOLTIP_SELECT_ALL_TRACKS_PROGRAM),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_OLD), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_OLD_STYLE, STR_MUSIC_TOOLTIP_SELECT_OLD_STYLE_MUSIC),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_NEW), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_NEW_STYLE, STR_MUSIC_TOOLTIP_SELECT_NEW_STYLE_MUSIC),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_EZY), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_EZY_STREET, STR_MUSIC_TOOLTIP_SELECT_EZY_STREET_STYLE),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_CUSTOM1), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_CUSTOM_1, STR_MUSIC_TOOLTIP_SELECT_CUSTOM_1_USER_DEFINED),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_MTS_CUSTOM2), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_CUSTOM_2, STR_MUSIC_TOOLTIP_SELECT_CUSTOM_2_USER_DEFINED),
|
2009-04-10 11:06:12 +00:00
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 16), // Space above 'clear' button
|
2011-12-16 18:02:27 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_MTS_CLEAR), SetFill(1, 0), SetDataTip(STR_PLAYLIST_CLEAR, STR_PLAYLIST_TOOLTIP_CLEAR_CURRENT_PROGRAM_CUSTOM1),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(0, 1),
|
2009-04-10 11:06:12 +00:00
|
|
|
EndContainer(),
|
|
|
|
/* Right panel. */
|
|
|
|
NWidget(NWID_VERTICAL),
|
2011-12-16 18:02:27 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, WID_MTS_PLAYLIST), SetDataTip(STR_PLAYLIST_PROGRAM, STR_NULL),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_MTS_LIST_RIGHT), SetMinimalSize(180, 194), SetDataTip(0x0, STR_PLAYLIST_TOOLTIP_CLICK_TO_REMOVE_TRACK), EndContainer(),
|
2009-04-10 11:06:12 +00:00
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _music_track_selection_desc(
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_AUTO, "music_track", 0, 0,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_MUSIC_TRACK_SELECTION, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_music_track_selection_widgets, lengthof(_nested_music_track_selection_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void ShowMusicTrackSelection()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-17 22:52:51 +00:00
|
|
|
AllocateWindowDescFront<MusicTrackSelectionWindow>(&_music_track_selection_desc, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-17 22:52:51 +00:00
|
|
|
struct MusicWindow : public Window {
|
2009-08-30 21:31:54 +00:00
|
|
|
static const int slider_width = 3;
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
MusicWindow(WindowDesc *desc, WindowNumber number) : Window(desc)
|
2008-05-17 22:52:51 +00:00
|
|
|
{
|
2013-05-26 19:23:42 +00:00
|
|
|
this->InitNested(number);
|
2011-12-16 18:02:27 +00:00
|
|
|
this->LowerWidget(_settings_client.music.playlist + WID_M_ALL);
|
|
|
|
this->SetWidgetLoweredState(WID_M_SHUFFLE, _settings_client.music.shuffle);
|
2008-05-17 22:52:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-09-01 19:18:42 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 18:02:27 +00:00
|
|
|
/* Make sure that WID_M_SHUFFLE and WID_M_PROGRAMME have the same size.
|
|
|
|
* This can't be done by using NC_EQUALSIZE as the WID_M_INFO is
|
2009-09-01 19:18:42 +00:00
|
|
|
* between those widgets and of different size. */
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_SHUFFLE: case WID_M_PROGRAMME: {
|
2009-09-01 19:18:42 +00:00
|
|
|
Dimension d = maxdim(GetStringBoundingBox(STR_MUSIC_PROGRAM), GetStringBoundingBox(STR_MUSIC_SHUFFLE));
|
|
|
|
d.width += padding.width;
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = maxdim(*size, d);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-09-01 21:30:14 +00:00
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_TRACK_NR: {
|
2009-09-01 21:30:14 +00:00
|
|
|
Dimension d = GetStringBoundingBox(STR_MUSIC_TRACK_NONE);
|
|
|
|
d.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
|
|
|
|
d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
|
|
|
*size = maxdim(*size, d);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-09-01 21:30:14 +00:00
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_TRACK_NAME: {
|
2009-09-01 21:30:14 +00:00
|
|
|
Dimension d = GetStringBoundingBox(STR_MUSIC_TITLE_NONE);
|
2009-12-22 21:40:29 +00:00
|
|
|
for (uint i = 0; i < NUM_SONGS_AVAILABLE; i++) {
|
2009-12-22 18:34:07 +00:00
|
|
|
SetDParamStr(0, GetSongName(i));
|
2009-09-01 21:30:14 +00:00
|
|
|
d = maxdim(d, GetStringBoundingBox(STR_MUSIC_TITLE_NAME));
|
|
|
|
}
|
|
|
|
d.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
|
|
|
|
d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
|
|
|
*size = maxdim(*size, d);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-11-19 20:34:45 +00:00
|
|
|
|
|
|
|
/* Hack-ish: set the proper widget data; only needs to be done once
|
|
|
|
* per (Re)Init as that's the only time the language changes. */
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_PREV: this->GetWidget<NWidgetCore>(WID_M_PREV)->widget_data = _current_text_dir == TD_RTL ? SPR_IMG_SKIP_TO_NEXT : SPR_IMG_SKIP_TO_PREV; break;
|
|
|
|
case WID_M_NEXT: this->GetWidget<NWidgetCore>(WID_M_NEXT)->widget_data = _current_text_dir == TD_RTL ? SPR_IMG_SKIP_TO_PREV : SPR_IMG_SKIP_TO_NEXT; break;
|
|
|
|
case WID_M_PLAY: this->GetWidget<NWidgetCore>(WID_M_PLAY)->widget_data = _current_text_dir == TD_RTL ? SPR_IMG_PLAY_MUSIC_RTL : SPR_IMG_PLAY_MUSIC; break;
|
2009-09-01 19:18:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-30 19:23:36 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
2008-05-17 22:52:51 +00:00
|
|
|
{
|
2009-08-30 19:23:36 +00:00
|
|
|
switch (widget) {
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_TRACK_NR: {
|
2011-05-06 21:13:29 +00:00
|
|
|
GfxFillRect(r.left + 1, r.top + 1, r.right, r.bottom, PC_BLACK);
|
2009-08-30 19:23:36 +00:00
|
|
|
StringID str = STR_MUSIC_TRACK_NONE;
|
|
|
|
if (_song_is_active != 0 && _music_wnd_cursong != 0) {
|
2009-12-22 21:40:29 +00:00
|
|
|
SetDParam(0, GetTrackNumber(_music_wnd_cursong - 1));
|
2009-11-24 13:14:48 +00:00
|
|
|
SetDParam(1, 2);
|
2009-11-19 13:56:10 +00:00
|
|
|
str = STR_MUSIC_TRACK_DIGIT;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2009-09-01 21:30:14 +00:00
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, str);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-09-01 21:30:14 +00:00
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_TRACK_NAME: {
|
2011-05-06 21:13:29 +00:00
|
|
|
GfxFillRect(r.left, r.top + 1, r.right - 1, r.bottom, PC_BLACK);
|
2009-09-01 21:30:14 +00:00
|
|
|
StringID str = STR_MUSIC_TITLE_NONE;
|
2009-08-30 19:23:36 +00:00
|
|
|
if (_song_is_active != 0 && _music_wnd_cursong != 0) {
|
|
|
|
str = STR_MUSIC_TITLE_NAME;
|
2009-12-22 18:34:07 +00:00
|
|
|
SetDParamStr(0, GetSongName(_music_wnd_cursong - 1));
|
2009-08-30 19:23:36 +00:00
|
|
|
}
|
2010-07-02 13:53:05 +00:00
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, str, TC_FROMSTRING, SA_HOR_CENTER);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-08-30 21:31:54 +00:00
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_MUSIC_VOL: case WID_M_EFFECT_VOL: {
|
2009-11-24 13:14:48 +00:00
|
|
|
DrawFrameRect(r.left, r.top + 2, r.right, r.bottom - 2, COLOUR_GREY, FR_LOWERED);
|
2011-12-16 18:02:27 +00:00
|
|
|
byte volume = (widget == WID_M_MUSIC_VOL) ? _settings_client.music.music_vol : _settings_client.music.effect_vol;
|
2009-11-19 20:34:45 +00:00
|
|
|
int x = (volume * (r.right - r.left) / 127);
|
2010-11-13 09:56:25 +00:00
|
|
|
if (_current_text_dir == TD_RTL) {
|
2009-11-19 20:34:45 +00:00
|
|
|
x = r.right - x;
|
|
|
|
} else {
|
|
|
|
x += r.left;
|
|
|
|
}
|
2009-11-24 13:14:48 +00:00
|
|
|
DrawFrameRect(x, r.top, x + slider_width, r.bottom, COLOUR_GREY, FR_NONE);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2009-08-30 19:23:36 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2011-03-13 21:31:29 +00:00
|
|
|
/**
|
|
|
|
* Some data on this window has become invalid.
|
|
|
|
* @param data Information about the changed data.
|
|
|
|
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
|
|
|
|
*/
|
|
|
|
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
2009-09-02 14:09:51 +00:00
|
|
|
{
|
2011-03-13 21:31:29 +00:00
|
|
|
if (!gui_scope) return;
|
2009-09-02 14:09:51 +00:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2011-12-16 18:02:27 +00:00
|
|
|
this->SetWidgetLoweredState(WID_M_ALL + i, i == _settings_client.music.playlist);
|
2009-09-02 14:09:51 +00:00
|
|
|
}
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-17 22:52:51 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_PREV: // skip to prev
|
2008-05-17 22:52:51 +00:00
|
|
|
if (!_song_is_active) return;
|
|
|
|
SkipToPrevSong();
|
2009-09-01 21:30:14 +00:00
|
|
|
this->SetDirty();
|
2008-05-17 22:52:51 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_NEXT: // skip to next
|
2008-05-17 22:52:51 +00:00
|
|
|
if (!_song_is_active) return;
|
|
|
|
SkipToNextSong();
|
2009-09-01 21:30:14 +00:00
|
|
|
this->SetDirty();
|
2008-05-17 22:52:51 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_STOP: // stop playing
|
2011-03-05 18:00:48 +00:00
|
|
|
_settings_client.music.playing = false;
|
2008-05-17 22:52:51 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_PLAY: // start playing
|
2011-03-05 18:00:48 +00:00
|
|
|
_settings_client.music.playing = true;
|
2008-05-17 22:52:51 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_MUSIC_VOL: case WID_M_EFFECT_VOL: { // volume sliders
|
2009-09-19 11:31:12 +00:00
|
|
|
int x = pt.x - this->GetWidget<NWidgetBase>(widget)->pos_x;
|
2008-05-17 22:52:51 +00:00
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
byte *vol = (widget == WID_M_MUSIC_VOL) ? &_settings_client.music.music_vol : &_settings_client.music.effect_vol;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-09-19 11:31:12 +00:00
|
|
|
byte new_vol = x * 127 / this->GetWidget<NWidgetBase>(widget)->current_x;
|
2010-11-13 09:56:25 +00:00
|
|
|
if (_current_text_dir == TD_RTL) new_vol = 127 - new_vol;
|
2008-05-17 22:52:51 +00:00
|
|
|
if (new_vol != *vol) {
|
|
|
|
*vol = new_vol;
|
2011-12-16 18:02:27 +00:00
|
|
|
if (widget == WID_M_MUSIC_VOL) MusicVolumeChanged(new_vol);
|
2008-05-17 22:52:51 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-17 22:52:51 +00:00
|
|
|
_left_button_clicked = false;
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-05-17 22:52:51 +00:00
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_SHUFFLE: // toggle shuffle
|
2011-03-05 18:00:48 +00:00
|
|
|
_settings_client.music.shuffle ^= 1;
|
2011-12-16 18:02:27 +00:00
|
|
|
this->SetWidgetLoweredState(WID_M_SHUFFLE, _settings_client.music.shuffle);
|
|
|
|
this->SetWidgetDirty(WID_M_SHUFFLE);
|
2008-05-17 22:52:51 +00:00
|
|
|
StopMusic();
|
|
|
|
SelectSongToPlay();
|
2009-09-01 21:30:14 +00:00
|
|
|
this->SetDirty();
|
2008-05-17 22:52:51 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_PROGRAMME: // show track selection
|
2008-05-17 22:52:51 +00:00
|
|
|
ShowMusicTrackSelection();
|
|
|
|
break;
|
|
|
|
|
2011-12-16 18:02:27 +00:00
|
|
|
case WID_M_ALL: case WID_M_OLD: case WID_M_NEW:
|
|
|
|
case WID_M_EZY: case WID_M_CUSTOM1: case WID_M_CUSTOM2: // playlist
|
|
|
|
SelectPlaylist(widget - WID_M_ALL);
|
2008-05-17 22:52:51 +00:00
|
|
|
StopMusic();
|
|
|
|
SelectSongToPlay();
|
2009-09-01 21:30:14 +00:00
|
|
|
this->SetDirty();
|
2008-05-17 22:52:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-17 22:52:51 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-04-10 11:06:12 +00:00
|
|
|
static const NWidgetPart _nested_music_window_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_MUSIC_JAZZ_JUKEBOX_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2013-09-15 15:56:46 +00:00
|
|
|
NWidget(WWT_SHADEBOX, COLOUR_GREY),
|
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_GREY),
|
2009-04-10 11:06:12 +00:00
|
|
|
EndContainer(),
|
|
|
|
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 13:14:48 +00:00
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, -1), SetFill(1, 1), EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2011-12-16 18:02:27 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_M_PREV), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_SKIP_TO_PREV, STR_MUSIC_TOOLTIP_SKIP_TO_PREVIOUS_TRACK),
|
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_M_NEXT), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_SKIP_TO_NEXT, STR_MUSIC_TOOLTIP_SKIP_TO_NEXT_TRACK_IN_SELECTION),
|
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_M_STOP), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_STOP_MUSIC, STR_MUSIC_TOOLTIP_STOP_PLAYING_MUSIC),
|
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_M_PLAY), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_PLAY_MUSIC, STR_MUSIC_TOOLTIP_START_PLAYING_MUSIC),
|
2009-11-24 13:14:48 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, -1), SetFill(1, 1), EndContainer(),
|
|
|
|
EndContainer(),
|
2011-12-16 18:02:27 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_M_SLIDERS),
|
2011-07-30 07:38:38 +00:00
|
|
|
NWidget(NWID_HORIZONTAL), SetPIP(20, 20, 20),
|
2009-11-24 13:14:48 +00:00
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetFill(1, 0), SetDataTip(STR_MUSIC_MUSIC_VOLUME, STR_NULL),
|
2011-12-16 18:02:27 +00:00
|
|
|
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),
|
2009-11-24 13:14:48 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MIN, STR_NULL),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MARKER, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MARKER, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MARKER, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MARKER, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MARKER, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MAX, STR_NULL),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetFill(1, 0), SetDataTip(STR_MUSIC_EFFECTS_VOLUME, STR_NULL),
|
2011-12-16 18:02:27 +00:00
|
|
|
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),
|
2009-11-24 13:14:48 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MIN, STR_NULL),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MARKER, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MARKER, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MARKER, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MARKER, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MARKER, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, -1), SetDataTip(STR_MUSIC_RULER_MAX, STR_NULL),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
2009-08-30 20:38:57 +00:00
|
|
|
EndContainer(),
|
2009-04-10 11:06:12 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
2011-12-16 18:02:27 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_M_BACKGROUND),
|
2009-09-01 19:18:42 +00:00
|
|
|
NWidget(NWID_HORIZONTAL), SetPIP(6, 0, 6),
|
2009-11-24 13:14:48 +00:00
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(NWID_SPACER), SetFill(0, 1),
|
2011-12-16 18:02:27 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_SHUFFLE), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_SHUFFLE, STR_MUSIC_TOOLTIP_TOGGLE_PROGRAM_SHUFFLE),
|
2009-11-24 13:14:48 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(0, 1),
|
|
|
|
EndContainer(),
|
2009-09-01 21:30:14 +00:00
|
|
|
NWidget(NWID_VERTICAL), SetPadding(0, 0, 3, 3),
|
2011-12-16 18:02:27 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, WID_M_TRACK), SetFill(0, 0), SetDataTip(STR_MUSIC_TRACK, STR_NULL),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_M_TRACK_NR), EndContainer(),
|
2009-09-01 21:30:14 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_VERTICAL), SetPadding(0, 3, 3, 0),
|
2011-12-16 18:02:27 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, WID_M_TRACK_TITLE), SetFill(1, 0), SetDataTip(STR_MUSIC_XTITLE, STR_NULL),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_M_TRACK_NAME), SetFill(1, 0), EndContainer(),
|
2009-11-24 13:14:48 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(NWID_SPACER), SetFill(0, 1),
|
2011-12-16 18:02:27 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_M_PROGRAMME), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_PROGRAM, STR_MUSIC_TOOLTIP_SHOW_MUSIC_TRACK_SELECTION),
|
2009-11-24 13:14:48 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(0, 1),
|
2009-04-10 11:06:12 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
2009-08-30 20:38:57 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2011-12-16 18:02:27 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_ALL), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_ALL, STR_MUSIC_TOOLTIP_SELECT_ALL_TRACKS_PROGRAM),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_OLD), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_OLD_STYLE, STR_MUSIC_TOOLTIP_SELECT_OLD_STYLE_MUSIC),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_NEW), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_NEW_STYLE, STR_MUSIC_TOOLTIP_SELECT_NEW_STYLE_MUSIC),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_EZY), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_EZY_STREET, STR_MUSIC_TOOLTIP_SELECT_EZY_STREET_STYLE),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_CUSTOM1), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_CUSTOM_1, STR_MUSIC_TOOLTIP_SELECT_CUSTOM_1_USER_DEFINED),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_M_CUSTOM2), SetFill(1, 0), SetDataTip(STR_MUSIC_PLAYLIST_CUSTOM_2, STR_MUSIC_TOOLTIP_SELECT_CUSTOM_2_USER_DEFINED),
|
2009-04-10 11:06:12 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _music_window_desc(
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_AUTO, "music", 0, 0,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_MUSIC_WINDOW, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_music_window_widgets, lengthof(_nested_music_window_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowMusicWindow()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-02-24 14:46:15 +00:00
|
|
|
if (BaseMusic::GetUsedSet()->num_available == 0) ShowErrorMessage(STR_ERROR_NO_SONGS, INVALID_STRING_ID, WL_WARNING);
|
2008-05-17 22:52:51 +00:00
|
|
|
AllocateWindowDescFront<MusicWindow>(&_music_window_desc, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|