From 8932f698c0831ab0e4ae2e03d64a48be1aeee82a Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Fri, 22 Mar 2002 19:17:28 +0100 Subject: [PATCH] rnd-20020322-1-src --- CHANGES | 1 + src/editor.c | 24 ++++++++++++++++++++++-- src/events.c | 6 +++--- src/libgame/gadgets.c | 25 ++++++++++++++++--------- src/libgame/gadgets.h | 2 ++ src/libgame/misc.c | 32 +++++++++++++++++++++++++++----- src/libgame/sound.c | 33 ++++++++++++++++++++------------- src/libgame/system.h | 2 ++ src/tools.c | 12 ------------ 9 files changed, 93 insertions(+), 44 deletions(-) diff --git a/CHANGES b/CHANGES index df78da4d..e59d98d4 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,7 @@ Release Version 2.0.2 [XX XXX XXXX] - changed default slipping behaviour of gems back to 2.0.0 style; this is now an element property for gems in the level editor, although existing converted levels use the new EM gems behaviour + - behaviour of "Escape" key in level editor now more intuitive Release Version 2.0.1 [19 MAR 2002] ----------------------------------- diff --git a/src/editor.c b/src/editor.c index 388083ee..196f9fb4 100644 --- a/src/editor.c +++ b/src/editor.c @@ -4018,10 +4018,12 @@ void HandleLevelEditorKeyInput(Key key) DrawLevelText(0, 0, 0, TEXT_BACKSPACE); else if (key == KSYM_Return) DrawLevelText(0, 0, 0, TEXT_NEWLINE); + else if (key == KSYM_Escape) + DrawLevelText(0, 0, 0, TEXT_END); } else if (button_status == MB_RELEASED) { - int i, id; + int i, id = GADGET_ID_NONE; switch (key) { @@ -4046,8 +4048,20 @@ void HandleLevelEditorKeyInput(Key key) button = MB_RIGHTBUTTON; break; + case KSYM_Escape: + if (edit_mode == ED_MODE_DRAWING) + { + game_status = MAINMENU; + DrawMainMenu(); + } + else + { + DrawDrawingWindow(); + edit_mode = ED_MODE_DRAWING; + } + break; + default: - id = GADGET_ID_NONE; break; } @@ -4083,6 +4097,9 @@ void HandleEditorGadgetInfoText(void *ptr) ClearEditorGadgetInfoText(); + if (gi->event.type == GD_EVENT_INFO_LEAVING) + return; + /* misuse this function to delete brush cursor, if needed */ if (edit_mode == ED_MODE_DRAWING && draw_with_brush) DeleteBrushFromCursor(); @@ -4130,6 +4147,9 @@ static void HandleDrawingAreaInfo(struct GadgetInfo *gi) ClearEditorGadgetInfoText(); + if (gi->event.type == GD_EVENT_INFO_LEAVING) + return; + /* make sure to stay inside drawing area boundaries */ sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx); sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy); diff --git a/src/events.c b/src/events.c index 79ffdd4a..fd8c3513 100644 --- a/src/events.c +++ b/src/events.c @@ -511,9 +511,9 @@ void HandleKey(Key key, int key_status) } /* allow quick escape to the main menu with the Escape key */ - if (key == KSYM_Escape && game_status != MAINMENU) + if (key == KSYM_Escape && + game_status != MAINMENU && game_status != LEVELED) { - CloseDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY); game_status = MAINMENU; DrawMainMenu(); return; @@ -605,7 +605,7 @@ void HandleKey(Key key, int key_status) break; case LEVELED: - if (!anyTextGadgetActiveOrJustFinished) + if (!anyTextGadgetActiveOrJustFinished || key == KSYM_Escape) HandleLevelEditorKeyInput(key); break; diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 02d22f9f..7f5125d2 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -82,11 +82,6 @@ static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my) static void default_callback_info(void *ptr) { -#if 0 - if (game_status == LEVELED) - HandleEditorGadgetInfoText(ptr); -#endif - return; } @@ -851,15 +846,27 @@ void HandleGadgets(int mx, int my, int button) if (last_info_gi != new_gi || (new_gi && new_gi->type == GD_TYPE_DRAWING_AREA && changed_position)) { - last_info_gi = new_gi; - if (new_gi != NULL && (button == 0 || new_gi == last_gi)) { - new_gi->event.type = 0; + new_gi->event.type = GD_EVENT_INFO_ENTERING; new_gi->callback_info(new_gi); } - else + else if (last_info_gi != NULL) + { + last_info_gi->event.type = GD_EVENT_INFO_LEAVING; + last_info_gi->callback_info(last_info_gi); + +#if 0 default_callback_info(NULL); + + printf("It seems that we are leaving gadget [%s]!\n", + (last_info_gi != NULL && + last_info_gi->info_text != NULL ? + last_info_gi->info_text : "")); +#endif + } + + last_info_gi = new_gi; } if (gadget_pressed) diff --git a/src/libgame/gadgets.h b/src/libgame/gadgets.h index 82100008..11a8578b 100644 --- a/src/libgame/gadgets.h +++ b/src/libgame/gadgets.h @@ -45,6 +45,8 @@ #define GD_EVENT_OFF_BORDERS (1 << 4) #define GD_EVENT_TEXT_RETURN (1 << 5) #define GD_EVENT_TEXT_LEAVING (1 << 6) +#define GD_EVENT_INFO_ENTERING (1 << 7) +#define GD_EVENT_INFO_LEAVING (1 << 8) /* gadget button states */ #define GD_BUTTON_UNPRESSED 0 diff --git a/src/libgame/misc.c b/src/libgame/misc.c index e8e34e0b..a78429b7 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -426,6 +426,8 @@ void GetOptions(char *argv[]) options.rw_base_directory = RW_BASE_PATH; options.level_directory = RO_BASE_PATH "/" LEVELS_DIRECTORY; options.graphics_directory = RO_BASE_PATH "/" GRAPHICS_DIRECTORY; + options.sounds_directory = RO_BASE_PATH "/" SOUNDS_DIRECTORY; + options.music_directory = RO_BASE_PATH "/" MUSIC_DIRECTORY; options.serveronly = FALSE; options.network = FALSE; options.verbose = FALSE; @@ -469,12 +471,14 @@ void GetOptions(char *argv[]) { printf("Usage: %s [options] [server.name [port]]\n" "Options:\n" - " -d, --display machine:0 X server display\n" - " -b, --basepath directory alternative base directory\n" - " -l, --level directory alternative level directory\n" - " -g, --graphics directory alternative graphics directory\n" + " -d, --display [:] X server display\n" + " -b, --basepath alternative base directory\n" + " -l, --level alternative level directory\n" + " -g, --graphics alternative graphics directory\n" + " -s, --sounds alternative graphics directory\n" + " -m, --music alternative graphics directory\n" " -n, --network network multiplayer game\n" - " -s, --serveronly only start network server\n" + " --serveronly only start network server\n" " -v, --verbose verbose mode\n" " --debug display debugging information\n", program.command_basename); @@ -522,6 +526,24 @@ void GetOptions(char *argv[]) if (option_arg == next_option) options_left++; } + else if (strncmp(option, "-sounds", option_len) == 0) + { + if (option_arg == NULL) + Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); + + options.sounds_directory = option_arg; + if (option_arg == next_option) + options_left++; + } + else if (strncmp(option, "-music", option_len) == 0) + { + if (option_arg == NULL) + Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); + + options.music_directory = option_arg; + if (option_arg == next_option) + options_left++; + } else if (strncmp(option, "-network", option_len) == 0) { options.network = TRUE; diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 088df127..faa9a49d 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -917,7 +917,7 @@ static int ulaw_to_linear(unsigned char ulawbyte) static boolean LoadSoundExt(char *sound_name, boolean is_music) { struct SampleInfo *snd_info; - char filename[256]; + char *filename; #if !defined(TARGET_SDL) && !defined(PLATFORM_MSDOS) byte sound_header_buffer[WAV_HEADER_SIZE]; char chunk[CHUNK_ID_LEN + 1]; @@ -935,14 +935,15 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) snd_info = &Sound[num_sounds - 1]; snd_info->name = sound_name; - sprintf(filename, "%s/%s/%s", options.ro_base_directory, - (is_music ? MUSIC_DIRECTORY : SOUNDS_DIRECTORY), snd_info->name); + filename = getPath2((is_music ? options.music_directory : + options.sounds_directory), snd_info->name); #if defined(TARGET_SDL) if ((snd_info->mix_chunk = Mix_LoadWAV(filename)) == NULL) { Error(ERR_WARN, "cannot read sound file '%s' -- no sounds", filename); + free(filename); return FALSE; } @@ -951,6 +952,7 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) if ((file = fopen(filename, MODE_READ)) == NULL) { Error(ERR_WARN, "cannot open sound file '%s' -- no sounds", filename); + free(filename); return FALSE; } @@ -960,6 +962,7 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) { Error(ERR_WARN, "missing 'RIFF' chunk of sound file '%s'", filename); fclose(file); + free(filename); return FALSE; } @@ -969,6 +972,7 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) { Error(ERR_WARN, "missing 'WAVE' chunk of sound file '%s'", filename); fclose(file); + free(filename); return FALSE; } @@ -982,6 +986,7 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) { Error(ERR_WARN, "missing 'data' chunk of sound file '%s'", filename); fclose(file); + free(filename); return FALSE; } @@ -994,6 +999,7 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) { Error(ERR_WARN, "cannot read sound file '%s' -- no sounds", filename); fclose(file); + free(filename); return FALSE; } @@ -1013,6 +1019,8 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) #endif + free(filename); + return TRUE; } @@ -1025,7 +1033,7 @@ boolean LoadMod(char *mod_name) { #if defined(TARGET_SDL) struct SampleInfo *mod_info; - char filename[256]; + char *filename; num_mods++; Mod = checked_realloc(Mod, num_mods * sizeof(struct SampleInfo)); @@ -1033,15 +1041,17 @@ boolean LoadMod(char *mod_name) mod_info = &Mod[num_mods - 1]; mod_info->name = mod_name; - sprintf(filename, "%s/%s/%s", options.ro_base_directory, - MUSIC_DIRECTORY, mod_info->name); + filename = getPath2(options.music_directory, mod_info->name); if ((mod_info->mix_music = Mix_LoadMUS(filename)) == NULL) { Error(ERR_WARN, "cannot read music file '%s' -- no music", filename); + free(filename); return FALSE; } + free(filename); + return TRUE; #else return FALSE; @@ -1052,18 +1062,17 @@ int LoadMusic(void) { DIR *dir; struct dirent *dir_entry; - char *music_directory = getPath2(options.ro_base_directory, MUSIC_DIRECTORY); int num_wav_music = 0; int num_mod_music = 0; if (!audio.sound_available) return 0; - if ((dir = opendir(music_directory)) == NULL) + if ((dir = opendir(options.music_directory)) == NULL) { - Error(ERR_WARN, "cannot read music directory '%s'", music_directory); + Error(ERR_WARN, "cannot read music directory '%s'", + options.music_directory); audio.music_available = FALSE; - free(music_directory); return 0; } @@ -1092,9 +1101,7 @@ int LoadMusic(void) if (num_wav_music == 0 && num_mod_music == 0) Error(ERR_WARN, "cannot find any valid music files in directory '%s'", - music_directory); - - free(music_directory); + options.music_directory); num_music = (num_mod_music > 0 ? num_mod_music : num_wav_music); diff --git a/src/libgame/system.h b/src/libgame/system.h index 75a986be..bf0f58b1 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -157,6 +157,8 @@ struct OptionInfo char *rw_base_directory; char *level_directory; char *graphics_directory; + char *sounds_directory; + char *music_directory; boolean serveronly; boolean network; boolean verbose; diff --git a/src/tools.c b/src/tools.c index d467fcda..ca2bbd5d 100644 --- a/src/tools.c +++ b/src/tools.c @@ -2282,13 +2282,6 @@ static struct } }; -#if 0 -static void DoNotDisplayInfoText(void *ptr) -{ - return; -} -#endif - void CreateToolButtons() { int i; @@ -2335,11 +2328,6 @@ void CreateToolButtons() GDI_DECORATION_SIZE, MINI_TILEX, MINI_TILEY, GDI_DECORATION_SHIFTING, 1, 1, GDI_EVENT_MASK, event_mask, - -#if 0 - GDI_CALLBACK_INFO, DoNotDisplayInfoText, -#endif - GDI_CALLBACK_ACTION, HandleToolButtons, GDI_END); -- 2.34.1