diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/music_gui.cpp | 69 | ||||
-rw-r--r-- | src/openttd.cpp | 2 | ||||
-rw-r--r-- | src/settings.cpp | 1 | ||||
-rw-r--r-- | src/settings_type.h | 12 | ||||
-rw-r--r-- | src/sound.cpp | 7 | ||||
-rw-r--r-- | src/sound_func.h | 2 | ||||
-rw-r--r-- | src/sound_type.h | 10 | ||||
-rw-r--r-- | src/table/music_settings.ini | 75 | ||||
-rw-r--r-- | src/table/settings.h.preamble | 4 | ||||
-rw-r--r-- | src/table/settings.ini | 58 |
10 files changed, 106 insertions, 134 deletions
diff --git a/src/music_gui.cpp b/src/music_gui.cpp index 7c19c406b..a0cb8ac9b 100644 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -22,6 +22,7 @@ #include "gui.h" #include "core/geometry_func.hpp" #include "string_func.h" +#include "settings_type.h" #include "table/strings.h" #include "table/sprites.h" @@ -63,8 +64,8 @@ static byte _playlist_new_style[NUM_SONGS_CLASS + 1]; /** Indices of all ezy street songs */ static byte _playlist_ezy_street[NUM_SONGS_CLASS + 1]; -assert_compile(lengthof(_msf.custom_1) == NUM_SONGS_PLAYLIST + 1); -assert_compile(lengthof(_msf.custom_2) == NUM_SONGS_PLAYLIST + 1); +assert_compile(lengthof(_settings_client.music.custom_1) == NUM_SONGS_PLAYLIST + 1); +assert_compile(lengthof(_settings_client.music.custom_2) == NUM_SONGS_PLAYLIST + 1); /** The different playlists that can be played. */ static byte * const _playlists[] = { @@ -72,8 +73,8 @@ static byte * const _playlists[] = { _playlist_old_style, _playlist_new_style, _playlist_ezy_street, - _msf.custom_1, - _msf.custom_2, + _settings_client.music.custom_1, + _settings_client.music.custom_2, }; /** @@ -116,8 +117,8 @@ void InitializeMusic() _playlists[k + 1][j] = 0; } - ValidatePlaylist(_msf.custom_1); - ValidatePlaylist(_msf.custom_2); + ValidatePlaylist(_settings_client.music.custom_1); + ValidatePlaylist(_settings_client.music.custom_2); if (BaseMusic::GetUsedSet()->num_available < _music_wnd_cursong) { /* If there are less songs than the currently played song, @@ -191,17 +192,17 @@ static void SelectSongToPlay() memset(_cur_playlist, 0, sizeof(_cur_playlist)); do { - const char *filename = BaseMusic::GetUsedSet()->files[_playlists[_msf.playlist][i] - 1].filename; + const char *filename = BaseMusic::GetUsedSet()->files[_playlists[_settings_client.music.playlist][i] - 1].filename; /* We are now checking for the existence of that file prior * to add it to the list of available songs */ if (!StrEmpty(filename) && FioCheckFileExists(filename, GM_DIR)) { - _cur_playlist[j] = _playlists[_msf.playlist][i]; + _cur_playlist[j] = _playlists[_settings_client.music.playlist][i]; j++; } - } while (_playlists[_msf.playlist][++i] != 0 && j < lengthof(_cur_playlist) - 1); + } while (_playlists[_settings_client.music.playlist][++i] != 0 && j < lengthof(_cur_playlist) - 1); /* Do not shuffle when on the intro-start window, as the song to play has to be the original TTD Theme*/ - if (_msf.shuffle && _game_mode != GM_MENU) { + if (_settings_client.music.shuffle && _game_mode != GM_MENU) { i = 500; do { uint32 r = InteractiveRandom(); @@ -235,7 +236,7 @@ static void PlayPlaylistSong() if (_cur_playlist[0] == 0) { _song_is_active = false; _music_wnd_cursong = 0; - _msf.playing = false; + _settings_client.music.playing = false; return; } } @@ -254,9 +255,9 @@ void ResetMusic() void MusicLoop() { - if (!_msf.playing && _song_is_active) { + if (!_settings_client.music.playing && _song_is_active) { StopMusic(); - } else if (_msf.playing && !_song_is_active) { + } else if (_settings_client.music.playing && !_song_is_active) { PlayPlaylistSong(); } @@ -275,7 +276,7 @@ void MusicLoop() static void SelectPlaylist(byte list) { - _msf.playlist = list; + _settings_client.music.playlist = list; InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0); InvalidateWindowData(WC_MUSIC_WINDOW, 0); } @@ -299,15 +300,15 @@ struct MusicTrackSelectionWindow : public Window { this->InitNested(desc, number); this->LowerWidget(MTSW_LIST_LEFT); this->LowerWidget(MTSW_LIST_RIGHT); - this->SetWidgetDisabledState(MTSW_CLEAR, _msf.playlist <= 3); - this->LowerWidget(MTSW_ALL + _msf.playlist); + this->SetWidgetDisabledState(MTSW_CLEAR, _settings_client.music.playlist <= 3); + this->LowerWidget(MTSW_ALL + _settings_client.music.playlist); } virtual void SetStringParameters(int widget) const { switch (widget) { case MTSW_PLAYLIST: - SetDParam(0, STR_MUSIC_PLAYLIST_ALL + _msf.playlist); + SetDParam(0, STR_MUSIC_PLAYLIST_ALL + _settings_client.music.playlist); break; } } @@ -315,9 +316,9 @@ struct MusicTrackSelectionWindow : public Window { virtual void OnInvalidateData(int data = 0) { for (int i = 0; i < 6; i++) { - this->SetWidgetLoweredState(MTSW_ALL + i, i == _msf.playlist); + this->SetWidgetLoweredState(MTSW_ALL + i, i == _settings_client.music.playlist); } - this->SetWidgetDisabledState(MTSW_CLEAR, _msf.playlist <= 3); + this->SetWidgetDisabledState(MTSW_CLEAR, _settings_client.music.playlist <= 3); this->SetDirty(); } @@ -383,7 +384,7 @@ struct MusicTrackSelectionWindow : public Window { GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, 0); int y = r.top + WD_FRAMERECT_TOP; - for (const byte *p = _playlists[_msf.playlist]; *p != 0; p++) { + for (const byte *p = _playlists[_settings_client.music.playlist]; *p != 0; p++) { uint i = *p - 1; SetDParam(0, GetTrackNumber(i)); SetDParam(1, 2); @@ -402,10 +403,10 @@ struct MusicTrackSelectionWindow : public Window { case MTSW_LIST_LEFT: { // add to playlist int y = this->GetRowFromWidget(pt.y, widget, 0, FONT_HEIGHT_SMALL); - if (_msf.playlist < 4) return; + if (_settings_client.music.playlist < 4) return; if (!IsInsideMM(y, 0, BaseMusic::GetUsedSet()->num_available)) return; - byte *p = _playlists[_msf.playlist]; + byte *p = _playlists[_settings_client.music.playlist]; for (uint i = 0; i != NUM_SONGS_PLAYLIST - 1; i++) { if (p[i] == 0) { /* Find the actual song number */ @@ -427,10 +428,10 @@ struct MusicTrackSelectionWindow : public Window { case MTSW_LIST_RIGHT: { // remove from playlist int y = this->GetRowFromWidget(pt.y, widget, 0, FONT_HEIGHT_SMALL); - if (_msf.playlist < 4) return; + if (_settings_client.music.playlist < 4) return; if (!IsInsideMM(y, 0, NUM_SONGS_PLAYLIST)) return; - byte *p = _playlists[_msf.playlist]; + byte *p = _playlists[_settings_client.music.playlist]; for (uint i = y; i != NUM_SONGS_PLAYLIST - 1; i++) { p[i] = p[i + 1]; } @@ -441,7 +442,7 @@ struct MusicTrackSelectionWindow : public Window { } case MTSW_CLEAR: // clear - for (uint i = 0; _playlists[_msf.playlist][i] != 0; i++) _playlists[_msf.playlist][i] = 0; + for (uint i = 0; _playlists[_settings_client.music.playlist][i] != 0; i++) _playlists[_settings_client.music.playlist][i] = 0; this->SetDirty(); StopMusic(); SelectSongToPlay(); @@ -535,8 +536,8 @@ struct MusicWindow : public Window { MusicWindow(const WindowDesc *desc, WindowNumber number) : Window() { this->InitNested(desc, number); - this->LowerWidget(_msf.playlist + MW_ALL); - this->SetWidgetLoweredState(MW_SHUFFLE, _msf.shuffle); + this->LowerWidget(_settings_client.music.playlist + MW_ALL); + this->SetWidgetLoweredState(MW_SHUFFLE, _settings_client.music.shuffle); } virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) @@ -624,7 +625,7 @@ struct MusicWindow : public Window { case MW_MUSIC_VOL: case MW_EFFECT_VOL: { DrawFrameRect(r.left, r.top + 2, r.right, r.bottom - 2, COLOUR_GREY, FR_LOWERED); - byte volume = (widget == MW_MUSIC_VOL) ? _msf.music_vol : _msf.effect_vol; + byte volume = (widget == MW_MUSIC_VOL) ? _settings_client.music.music_vol : _settings_client.music.effect_vol; int x = (volume * (r.right - r.left) / 127); if (_current_text_dir == TD_RTL) { x = r.right - x; @@ -640,7 +641,7 @@ struct MusicWindow : public Window { virtual void OnInvalidateData(int data = 0) { for (int i = 0; i < 6; i++) { - this->SetWidgetLoweredState(MW_ALL + i, i == _msf.playlist); + this->SetWidgetLoweredState(MW_ALL + i, i == _settings_client.music.playlist); } this->SetDirty(); } @@ -661,17 +662,17 @@ struct MusicWindow : public Window { break; case MW_STOP: // stop playing - _msf.playing = false; + _settings_client.music.playing = false; break; case MW_PLAY: // start playing - _msf.playing = true; + _settings_client.music.playing = true; break; case MW_MUSIC_VOL: case MW_EFFECT_VOL: { // volume sliders int x = pt.x - this->GetWidget<NWidgetBase>(widget)->pos_x; - byte *vol = (widget == MW_MUSIC_VOL) ? &_msf.music_vol : &_msf.effect_vol; + byte *vol = (widget == MW_MUSIC_VOL) ? &_settings_client.music.music_vol : &_settings_client.music.effect_vol; byte new_vol = x * 127 / this->GetWidget<NWidgetBase>(widget)->current_x; if (_current_text_dir == TD_RTL) new_vol = 127 - new_vol; @@ -686,8 +687,8 @@ struct MusicWindow : public Window { } case MW_SHUFFLE: // toggle shuffle - _msf.shuffle ^= 1; - this->SetWidgetLoweredState(MW_SHUFFLE, _msf.shuffle); + _settings_client.music.shuffle ^= 1; + this->SetWidgetLoweredState(MW_SHUFFLE, _settings_client.music.shuffle); this->SetWidgetDirty(MW_SHUFFLE); StopMusic(); SelectSongToPlay(); diff --git a/src/openttd.cpp b/src/openttd.cpp index 997899513..816180ba2 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -642,7 +642,7 @@ int ttd_main(int argc, char *argv[]) _screen.zoom = ZOOM_LVL_NORMAL; /* restore saved music volume */ - _music_driver->SetVolume(_msf.music_vol); + _music_driver->SetVolume(_settings_client.music.music_vol); NetworkStartUp(); // initialize network-core diff --git a/src/settings.cpp b/src/settings.cpp index 9d4f52cab..0388d35a9 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1485,7 +1485,6 @@ static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *li static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list) { proc(ini, (const SettingDesc*)_misc_settings, "misc", NULL); - proc(ini, (const SettingDesc*)_music_settings, "music", &_msf); #if defined(WIN32) && !defined(DEDICATED) proc(ini, (const SettingDesc*)_win32_settings, "win32", NULL); #endif /* WIN32 */ diff --git a/src/settings_type.h b/src/settings_type.h index 2556aaf54..3b8b3242c 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -136,6 +136,17 @@ struct GUISettings { } }; +/** Settings related to music. */ +struct MusicSettings { + byte playlist; ///< The playlist (number) to play + byte music_vol; ///< The requested music volume + byte effect_vol; ///< The requested effects volume + byte custom_1[33]; ///< The order of the first custom playlist + byte custom_2[33]; ///< The order of the second custom playlist + bool playing; ///< Whether music is playing + bool shuffle; ///< Whether to shuffle the music +}; + /** Settings related to currency/unit systems. */ struct LocaleSettings { byte currency; ///< currency we currently use @@ -441,6 +452,7 @@ struct ClientSettings { GUISettings gui; ///< settings related to the GUI NetworkSettings network; ///< settings related to the network CompanySettings company; ///< default values for per-company settings + MusicSettings music; ///< settings related to music/sound }; /** The current settings for this game. */ diff --git a/src/sound.cpp b/src/sound.cpp index 060eb6073..4b6886d36 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -22,7 +22,6 @@ #include "base_media_func.h" static SoundEntry _original_sounds[ORIGINAL_SAMPLE_COUNT]; -MusicFileSettings _msf; static void OpenBankFile(const char *filename) { @@ -227,7 +226,7 @@ void SndCopyToPool() */ static void SndPlayScreenCoordFx(SoundID sound, int left, int right, int top, int bottom) { - if (_msf.effect_vol == 0) return; + if (_settings_client.music.effect_vol == 0) return; const Window *w; FOR_ALL_WINDOWS_FROM_BACK(w) { @@ -243,7 +242,7 @@ static void SndPlayScreenCoordFx(SoundID sound, int left, int right, int top, in StartSound( sound, panning, - (_msf.effect_vol * _vol_factor_by_zoom[vp->zoom - ZOOM_LVL_BEGIN]) / 256 + (_settings_client.music.effect_vol * _vol_factor_by_zoom[vp->zoom - ZOOM_LVL_BEGIN]) / 256 ); return; } @@ -272,7 +271,7 @@ void SndPlayVehicleFx(SoundID sound, const Vehicle *v) void SndPlayFx(SoundID sound) { - StartSound(sound, 0.5, _msf.effect_vol); + StartSound(sound, 0.5, _settings_client.music.effect_vol); } INSTANTIATE_BASE_MEDIA_METHODS(BaseMedia<SoundsSet>, SoundsSet) diff --git a/src/sound_func.h b/src/sound_func.h index ed9526bec..7117bb646 100644 --- a/src/sound_func.h +++ b/src/sound_func.h @@ -16,8 +16,6 @@ #include "vehicle_type.h" #include "tile_type.h" -extern MusicFileSettings _msf; - void SndPlayTileFx(SoundID sound, TileIndex tile); void SndPlayVehicleFx(SoundID sound, const Vehicle *v); void SndPlayFx(SoundID sound); diff --git a/src/sound_type.h b/src/sound_type.h index 1190dec1d..4eac434f3 100644 --- a/src/sound_type.h +++ b/src/sound_type.h @@ -12,16 +12,6 @@ #ifndef SOUND_TYPE_H #define SOUND_TYPE_H -struct MusicFileSettings { - byte playlist; - byte music_vol; - byte effect_vol; - byte custom_1[33]; - byte custom_2[33]; - bool playing; - bool shuffle; -}; - struct SoundEntry { uint8 file_slot; size_t file_offset; diff --git a/src/table/music_settings.ini b/src/table/music_settings.ini deleted file mode 100644 index b458b77a3..000000000 --- a/src/table/music_settings.ini +++ /dev/null @@ -1,75 +0,0 @@ -[pre-amble] -static const SettingDesc _music_settings[] = { -[post-amble] -}; -[templates] -SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $proc, $from, $to), -SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $proc, $from, $to), -SDT_LIST = SDT_LIST($base, $var, $type, $flags, $guiflags, $def, $str, $proc, $from, $to), -SDT_END = SDT_END() - -[defaults] -flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC -guiflags = 0 -interval = 0 -str = STR_NULL -proc = NULL -load = NULL -from = 0 -to = SL_MAX_VERSION - - - -[SDT_VAR] -base = MusicFileSettings -var = playlist -type = SLE_UINT8 -def = 0 -min = 0 -max = 5 -interval = 1 - -[SDT_VAR] -base = MusicFileSettings -var = music_vol -type = SLE_UINT8 -def = 127 -min = 0 -max = 127 -interval = 1 - -[SDT_VAR] -base = MusicFileSettings -var = effect_vol -type = SLE_UINT8 -def = 127 -min = 0 -max = 127 -interval = 1 - -[SDT_LIST] -base = MusicFileSettings -var = custom_1 -type = SLE_UINT8 -def = NULL - -[SDT_LIST] -base = MusicFileSettings -var = custom_2 -type = SLE_UINT8 -def = NULL - -[SDT_BOOL] -base = MusicFileSettings -var = playing -def = true - -[SDT_BOOL] -base = MusicFileSettings -var = shuffle -def = false - -[SDT_END] - - -}; diff --git a/src/table/settings.h.preamble b/src/table/settings.h.preamble index 8bb937edb..70d6826cb 100644 --- a/src/table/settings.h.preamble +++ b/src/table/settings.h.preamble @@ -153,8 +153,8 @@ static bool UpdateClientConfigValues(int32 p1); #define SDTC_BOOL(var, flags, guiflags, def, str, proc, from, to)\ SDTG_GENERAL(#var, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, _settings_client.var, 1, def, 0, 1, 0, NULL, str, proc, from, to) -#define SDTC_LIST(var, type, length, flags, guiflags, def, str, proc, from, to)\ - SDTG_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, _settings_client.var, length, def, 0, 0, 0, NULL, str, proc, from, to) +#define SDTC_LIST(var, type, flags, guiflags, def, str, proc, from, to)\ + SDTG_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, _settings_client.var, lengthof(_settings_client.var), def, 0, 0, 0, NULL, str, proc, from, to) #define SDTC_STR(var, type, flags, guiflags, def, str, proc, from, to)\ SDTG_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, _settings_client.var, lengthof(_settings_client.var), def, 0, 0, 0, NULL, str, proc, from, to) diff --git a/src/table/settings.ini b/src/table/settings.ini index 8d97878a9..b921b4b1e 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -15,14 +15,13 @@ const SettingDesc _settings[] = { SDTG_BOOL = SDTG_BOOL($name, $flags, $guiflags, $var, $def, $str, $proc, $from, $to), SDTG_VAR = SDTG_VAR($name, $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $proc, $from, $to), SDTC_BOOL = SDTC_BOOL( $var, $flags, $guiflags, $def, $str, $proc, $from, $to), -SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $proc, $from, $to), -SDTC_DBOOL = SDTC_BOOL( $var, $flags, $guiflags, $def, $str, $proc, $from, $to), -SDT_DBOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $proc, $from, $to), +SDTC_LIST = SDTC_LIST( $var, $type, $flags, $guiflags, $def, $str, $proc, $from, $to), SDTC_OMANY = SDTC_OMANY( $var, $type, $flags, $guiflags, $def, $max, $full, $str, $proc, $from, $to), -SDT_OMANY = SDT_OMANY($base, $var, $type, $flags, $guiflags, $def, $max, $full, $str, $proc, $from, $to, $load), -SDT_STR = SDT_STR($base, $var, $type, $flags, $guiflags, $def, $str, $proc, $from, $to), SDTC_STR = SDTC_STR( $var, $type, $flags, $guiflags, $def, $str, $proc, $from, $to), SDTC_VAR = SDTC_VAR( $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $proc, $from, $to), +SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $proc, $from, $to), +SDT_OMANY = SDT_OMANY($base, $var, $type, $flags, $guiflags, $def, $max, $full, $str, $proc, $from, $to, $load), +SDT_STR = SDT_STR($base, $var, $type, $flags, $guiflags, $def, $str, $proc, $from, $to), SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $proc, $from, $to), SDT_NULL = SDT_NULL($length, $from, $to), SDT_END = SDT_END() @@ -2334,6 +2333,55 @@ min = 10 max = 65500 [SDTC_VAR] +var = music.playlist +type = SLE_UINT8 +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +def = 0 +min = 0 +max = 5 +interval = 1 + +[SDTC_VAR] +var = music.music_vol +type = SLE_UINT8 +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +def = 127 +min = 0 +max = 127 +interval = 1 + +[SDTC_VAR] +var = music.effect_vol +type = SLE_UINT8 +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +def = 127 +min = 0 +max = 127 +interval = 1 + +[SDTC_LIST] +var = music.custom_1 +type = SLE_UINT8 +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +def = NULL + +[SDTC_LIST] +var = music.custom_2 +type = SLE_UINT8 +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +def = NULL + +[SDTC_BOOL] +var = music.playing +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +def = true + +[SDTC_BOOL] +var = music.shuffle +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +def = false + +[SDTC_VAR] ifdef = ENABLE_NETWORK var = gui.network_chat_box_width type = SLE_UINT16 |