diff options
author | belugas <belugas@openttd.org> | 2006-07-07 02:44:51 +0000 |
---|---|---|
committer | belugas <belugas@openttd.org> | 2006-07-07 02:44:51 +0000 |
commit | 351c878365ed1737afb3f80ad75fc9fc3a266d89 (patch) | |
tree | d03d3af94e7ce1ddb0e15dba460d980f00d5d203 | |
parent | 7aa821b7fcbf7a34b37239baf3ad6da9ba1ad50c (diff) | |
download | openttd-351c878365ed1737afb3f80ad75fc9fc3a266d89.tar.xz |
(svn r5464) [Behaviour Fix] : When starting the game, the system will now verify the presence of music files in gm forlder.
A song can now be removed from the programmed list (in custom list 1 and 2) by clicking on it.
Added music.c[ch] files, to make it all a bit cleaner.
Now, the name of the gm file is associated with the title of the song.
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | lang/english.txt | 1 | ||||
-rw-r--r-- | music.c | 28 | ||||
-rw-r--r-- | music.h | 16 | ||||
-rw-r--r-- | music_gui.c | 93 | ||||
-rw-r--r-- | openttd.vcproj | 6 | ||||
-rw-r--r-- | openttd_vs80.vcproj | 8 | ||||
-rw-r--r-- | strings.c | 28 |
8 files changed, 113 insertions, 68 deletions
@@ -671,6 +671,7 @@ SRCS += misc.c SRCS += misc_cmd.c SRCS += misc_gui.c SRCS += mixer.c +SRCS += music.c SRCS += music_gui.c SRCS += namegen.c SRCS += network.c diff --git a/lang/english.txt b/lang/english.txt index 55ee294aa..ef823281a 100644 --- a/lang/english.txt +++ b/lang/english.txt @@ -551,6 +551,7 @@ STR_01F7_SELECT_CUSTOM_2_USER_DEFINED :{BLACK}Select ' STR_01F8_CLEAR_CURRENT_PROGRAM_CUSTOM1 :{BLACK}Clear current programme (Custom1 or Custom2 only) STR_01F9_SAVE_MUSIC_SETTINGS :{BLACK}Save music settings STR_01FA_CLICK_ON_MUSIC_TRACK_TO :{BLACK}Click on music track to add to current programme (Custom1 or Custom2 only) +STR_CLICK_ON_TRACK_TO_REMOVE :{BLACK}Click on music track to remove it from current programme (Custom1 or Custom2 only) STR_01FB_TOGGLE_PROGRAM_SHUFFLE :{BLACK}Toggle programme shuffle on/off STR_01FC_SHOW_MUSIC_TRACK_SELECTION :{BLACK}Show music track selection window STR_01FD_CLICK_ON_SERVICE_TO_CENTER :{BLACK}Click on service to centre view on industry/town diff --git a/music.c b/music.c new file mode 100644 index 000000000..80c6dfe51 --- /dev/null +++ b/music.c @@ -0,0 +1,28 @@ +/* $Id */ + +#include "music.h" + +const SongSpecs origin_songs_specs[NUM_SONGS_AVAILABLE] = { + {"gm_tt00.gm", "Tycoon DELUXE Theme"}, + {"gm_tt02.gm", "Easy Driver"}, + {"gm_tt03.gm", "Little Red Diesel"}, + {"gm_tt17.gm", "Cruise Control"}, + {"gm_tt07.gm", "Don't Walk!"}, + {"gm_tt09.gm", "Fell Apart On Me"}, + {"gm_tt04.gm", "City Groove"}, + {"gm_tt19.gm", "Funk Central"}, + {"gm_tt06.gm", "Stoke It"}, + {"gm_tt12.gm", "Road Hog"}, + {"gm_tt05.gm", "Aliens Ate My Railway"}, + {"gm_tt01.gm", "Snarl Up"}, + {"gm_tt18.gm", "Stroll On"}, + {"gm_tt10.gm", "Can't Get There From Here"}, + {"gm_tt08.gm", "Sawyer's Tune"}, + {"gm_tt13.gm", "Hold That Train!"}, + {"gm_tt21.gm", "Movin' On"}, + {"gm_tt15.gm", "Goss Groove"}, + {"gm_tt16.gm", "Small Town"}, + {"gm_tt14.gm", "Broomer's Oil Rag"}, + {"gm_tt20.gm", "Jammit"}, + {"gm_tt11.gm", "Hard Drivin'"}, +}; diff --git a/music.h b/music.h new file mode 100644 index 000000000..5d968404a --- /dev/null +++ b/music.h @@ -0,0 +1,16 @@ +/* $Id */ + +#ifndef MUSIC_H +#define MUSIC_H + +#define NUM_SONGS_PLAYLIST 33 +#define NUM_SONGS_AVAILABLE 22 + +typedef struct SongSpecs { + char filename[256]; + char song_name[64]; +} SongSpecs; + +extern const SongSpecs origin_songs_specs[NUM_SONGS_AVAILABLE]; + +#endif //MUSIC_H diff --git a/music_gui.c b/music_gui.c index 3a9eb2e69..dee4a6896 100644 --- a/music_gui.c +++ b/music_gui.c @@ -10,12 +10,12 @@ #include "hal.h" #include "macros.h" #include "variables.h" +#include "music.h" static byte _music_wnd_cursong; static bool _song_is_active; -static byte _cur_playlist[33]; +static byte _cur_playlist[NUM_SONGS_PLAYLIST]; -#define NUM_SONGS_AVAILABLE 22 static byte _playlist_all[] = { @@ -43,33 +43,6 @@ static byte * const _playlists[] = { msf.custom_2, }; -// Map the order of the song names to the numbers of the midi filenames -static const byte midi_idx[] = { - 0, // Tycoon DELUXE Theme - 2, // Easy Driver - 3, // Little Red Diesel - 17, // Cruise Control - 7, // Don't Walk! - 9, // Fell Apart On Me - 4, // City Groove - 19, // Funk Central - 6, // Stoke It - 12, // Road Hog - 5, // Aliens Ate My Railway - 1, // Snarl Up - 18, // Stroll On - 10, // Can't Get There From Here - 8, // Sawyer's Tune - 13, // Hold That Train! - 21, // Movin' On - 15, // Goss Groove - 16, // Small Town - 14, // Broomer's Oil Rag - 20, // Jammit - 11 // Hard Drivin' -}; - - static void SkipToPrevSong(void) { byte *b = _cur_playlist; @@ -118,8 +91,8 @@ static void MusicVolumeChanged(byte new_vol) static void DoPlaySong(void) { char filename[256]; - snprintf(filename, sizeof(filename), "%sgm_tt%.2d.gm", - _path.gm_dir, midi_idx[_music_wnd_cursong - 1]); + snprintf(filename, sizeof(filename), "%s%s", + _path.gm_dir, origin_songs_specs[_music_wnd_cursong - 1].filename); _music_driver->play_song(filename); } @@ -131,10 +104,19 @@ static void DoStopMusic(void) static void SelectSongToPlay(void) { uint i = 0; + uint j = 0; + char filename[256]; memset(_cur_playlist, 0, sizeof(_cur_playlist)); do { - _cur_playlist[i] = _playlists[msf.playlist][i]; + snprintf(filename, sizeof(filename), "%s%s", + _path.gm_dir, origin_songs_specs[_playlists[msf.playlist][i]].filename); + //we are now checking for the existence of that file prior + //to add it to the list of available songs + if (FileExists(filename)) { + _cur_playlist[j] = _playlists[msf.playlist][i]; + j++; + } } while (_playlists[msf.playlist][i++] != 0 && i < lengthof(_cur_playlist) - 1); if (msf.shuffle) { @@ -165,7 +147,15 @@ static void PlayPlaylistSong(void) { if (_cur_playlist[0] == 0) { SelectSongToPlay(); - if (_cur_playlist[0] == 0) return; + //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 + if (_cur_playlist[0] == 0) { + _song_is_active = false; + _music_wnd_cursong = 0; + msf.playing = false; + return; + } } _music_wnd_cursong = _cur_playlist[0]; DoPlaySong(); @@ -188,7 +178,7 @@ void MusicLoop(void) PlayPlaylistSong(); } - if (_song_is_active == false) return; + if (!_song_is_active) return; if (!_music_driver->is_song_playing()) { if (_game_mode != GM_MENU) { @@ -233,7 +223,7 @@ static void MusicTrackSelectionWndProc(Window *w, WindowEvent *e) } DrawStringCentered(216, 45+8*6+16, STR_01F0_CLEAR, 0); - DrawStringCentered(216, 45+8*6+16*2, STR_01F1_SAVE, 0); + //DrawStringCentered(216, 45+8*6+16*2, STR_01F1_SAVE, 0); y = 23; for (p = _playlists[msf.playlist], i = 0; (i = *p) != 0; p++) { @@ -257,7 +247,7 @@ static void MusicTrackSelectionWndProc(Window *w, WindowEvent *e) if (!IS_INT_INSIDE(y, 0, NUM_SONGS_AVAILABLE)) return; p = _playlists[msf.playlist]; - for (i = 0; i != 32; i++) { + for (i = 0; i != NUM_SONGS_PLAYLIST - 1; i++) { if (p[i] == 0) { p[i] = y + 1; p[i + 1] = 0; @@ -266,17 +256,36 @@ static void MusicTrackSelectionWndProc(Window *w, WindowEvent *e) break; } } + } break; + + case 4: { /* remove from playlist */ + int y = (e->click.pt.y - 23) / 6; + uint i; + byte *p; + if (msf.playlist < 4) return; + if (!IS_INT_INSIDE(y, 0, NUM_SONGS_AVAILABLE)) return; + + p = _playlists[msf.playlist]; + for (i = y; i != NUM_SONGS_PLAYLIST - 1; i++) { + p[i] = p[i + 1]; + } + + SetWindowDirty(w); + SelectSongToPlay(); } break; + case 11: /* clear */ _playlists[msf.playlist][0] = 0; SetWindowDirty(w); StopMusic(); SelectSongToPlay(); break; - case 12: /* save */ - ShowInfo("MusicTrackSelectionWndProc:save not implemented\n"); - break; + + //case 12: /* save */ + // ShowInfo("MusicTrackSelectionWndProc:save not implemented\n"); + // break; + case 5: case 6: case 7: case 8: case 9: case 10: /* set playlist */ msf.playlist = e->click.widget - 5; SetWindowDirty(w); @@ -294,7 +303,7 @@ static const Widget _music_track_selection_widgets[] = { { WWT_CAPTION, RESIZE_NONE, 14, 11, 431, 0, 13, STR_01EB_MUSIC_PROGRAM_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, { WWT_IMGBTN, RESIZE_NONE, 14, 0, 431, 14, 217, 0x0, STR_NULL}, { WWT_IMGBTN, RESIZE_NONE, 14, 2, 181, 22, 215, 0x0, STR_01FA_CLICK_ON_MUSIC_TRACK_TO}, -{ WWT_IMGBTN, RESIZE_NONE, 14, 250, 429, 22, 215, 0x0, STR_01F2_CURRENT_PROGRAM_OF_MUSIC}, +{ WWT_IMGBTN, RESIZE_NONE, 14, 250, 429, 22, 215, 0x0, STR_CLICK_ON_TRACK_TO_REMOVE}, { WWT_PUSHIMGBTN, RESIZE_NONE, 14, 186, 245, 44, 51, 0x0, STR_01F3_SELECT_ALL_TRACKS_PROGRAM}, { WWT_PUSHIMGBTN, RESIZE_NONE, 14, 186, 245, 52, 59, 0x0, STR_01F4_SELECT_OLD_STYLE_MUSIC}, { WWT_PUSHIMGBTN, RESIZE_NONE, 14, 186, 245, 60, 67, 0x0, STR_01F5_SELECT_NEW_STYLE_MUSIC}, @@ -302,7 +311,7 @@ static const Widget _music_track_selection_widgets[] = { { WWT_PUSHIMGBTN, RESIZE_NONE, 14, 186, 245, 76, 83, 0x0, STR_01F6_SELECT_CUSTOM_1_USER_DEFINED}, { WWT_PUSHIMGBTN, RESIZE_NONE, 14, 186, 245, 84, 91, 0x0, STR_01F7_SELECT_CUSTOM_2_USER_DEFINED}, { WWT_PUSHIMGBTN, RESIZE_NONE, 14, 186, 245, 108, 115, 0x0, STR_01F8_CLEAR_CURRENT_PROGRAM_CUSTOM1}, -{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 186, 245, 124, 131, 0x0, STR_01F9_SAVE_MUSIC_SETTINGS}, +//{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 186, 245, 124, 131, 0x0, STR_01F9_SAVE_MUSIC_SETTINGS}, { WIDGETS_END}, }; @@ -339,7 +348,7 @@ static void MusicWindowWndProc(Window *w, WindowEvent *e) color = 0xB8; } } - GfxFillRect(187, 33 - i * 2, 200, 33 - i * 2, color); + GfxFillRect(187, NUM_SONGS_PLAYLIST - i * 2, 200, NUM_SONGS_PLAYLIST - i * 2, color); } GfxFillRect(60, 46, 239, 52, 0); diff --git a/openttd.vcproj b/openttd.vcproj index 37afbc289..fae8e0b59 100644 --- a/openttd.vcproj +++ b/openttd.vcproj @@ -253,6 +253,9 @@ RelativePath=".\mixer.c"> </File> <File + RelativePath=".\music.c"> + </File> + <File RelativePath=".\namegen.c"> </File> <File @@ -479,6 +482,9 @@ RelativePath=".\mixer.h"> </File> <File + RelativePath=".\music.h"> + </File> + <File RelativePath=".\network.h"> </File> <File diff --git a/openttd_vs80.vcproj b/openttd_vs80.vcproj index 5384f1052..091fe29b0 100644 --- a/openttd_vs80.vcproj +++ b/openttd_vs80.vcproj @@ -346,6 +346,10 @@ >
</File>
<File
+ RelativePath=".\music.c"
+ >
+ </File>
+ <File
RelativePath=".\namegen.c"
>
</File>
@@ -655,6 +659,10 @@ >
</File>
<File
+ RelativePath=".\music.h"
+ >
+ </File>
+ <File
RelativePath=".\network.h"
>
</File>
@@ -18,6 +18,7 @@ #include "variables.h" #include "newgrf_text.h" #include "table/landscape_const.h" +#include "music.h" char _userstring[128]; @@ -1015,31 +1016,6 @@ static char *GenPresidentName(char *buff, uint32 x) return buff; } -static const char * const _song_names[] = { - "Tycoon DELUXE Theme", - "Easy Driver", - "Little Red Diesel", - "Cruise Control", - "Don't Walk!", - "Fell Apart On Me", - "City Groove", - "Funk Central", - "Stoke It", - "Road Hog", - "Aliens Ate My Railway", - "Snarl Up", - "Stroll On", - "Can't Get There From Here", - "Sawyer's Tune", - "Hold That Train!", - "Movin' On", - "Goss Groove", - "Small Town", - "Broomer's Oil Rag", - "Jammit", - "Hard Drivin'" -}; - static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv) { switch (ind) { @@ -1053,7 +1029,7 @@ static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv) return GenPresidentName(buff, GetInt32(&argv)); case 4: // song names - return strecpy(buff, _song_names[GetInt32(&argv) - 1], NULL); + return strecpy(buff, origin_songs_specs[GetInt32(&argv) - 1].song_name, NULL); } // town name? |