#define SETUP_TOKEN_TIME_LIMIT 13
#define SETUP_TOKEN_FULLSCREEN 14
#define SETUP_TOKEN_ASK_ON_ESCAPE 15
-#define SETUP_TOKEN_GRAPHICS_DIR 16
-#define SETUP_TOKEN_SOUNDS_DIR 17
-#define SETUP_TOKEN_MUSIC_DIR 18
+#define SETUP_TOKEN_GRAPHICS_SET 16
+#define SETUP_TOKEN_SOUNDS_SET 17
+#define SETUP_TOKEN_MUSIC_SET 18
#define NUM_GLOBAL_SETUP_TOKENS 19
{ TYPE_SWITCH, &si.time_limit, "time_limit" },
{ TYPE_SWITCH, &si.fullscreen, "fullscreen" },
{ TYPE_SWITCH, &si.ask_on_escape, "ask_on_escape" },
- { TYPE_STRING, &si.graphics_dir, "graphics_dir" },
- { TYPE_STRING, &si.sounds_dir, "sounds_dir" },
- { TYPE_STRING, &si.music_dir, "music_dir" },
+ { TYPE_STRING, &si.graphics_set, "graphics_set" },
+ { TYPE_STRING, &si.sounds_set, "sounds_set" },
+ { TYPE_STRING, &si.music_set, "music_set" },
};
static struct TokenInfo shortcut_setup_tokens[] =
si->fullscreen = FALSE;
si->ask_on_escape = TRUE;
- si->graphics_dir = getStringCopy(GRAPHICS_DIRECTORY);
- si->sounds_dir = getStringCopy(SOUNDS_DIRECTORY);
- si->music_dir = getStringCopy(MUSIC_DIRECTORY);
+ si->graphics_set = getStringCopy(GRAPHICS_SUBDIR);
+ si->sounds_set = getStringCopy(SOUNDS_SUBDIR);
+ si->music_set = getStringCopy(MUSIC_SUBDIR);
si->shortcut.save_game = DEFAULT_KEY_SAVE_GAME;
si->shortcut.load_game = DEFAULT_KEY_LOAD_GAME;
fprintf(file, "%s\n", getSetupLine(global_setup_tokens, "", i));
/* just to make things nicer :) */
- if (i == SETUP_TOKEN_PLAYER_NAME || i == SETUP_TOKEN_GRAPHICS_DIR - 1)
+ if (i == SETUP_TOKEN_PLAYER_NAME || i == SETUP_TOKEN_GRAPHICS_SET - 1)
fprintf(file, "\n");
}
redraw_mask = REDRAW_ALL;
}
+void ReloadCustomArtwork()
+{
+ if (artwork.graphics_set_current != artwork.gfx_current->name)
+ {
+ int i;
+
+ for(i=0; i<NUM_PICTURES; i++)
+ ReloadCustomImage(&pix[i], image_filename[i]);
+
+ InitGfxBackground();
+ SetDoorState(DOOR_OPEN_1 | DOOR_CLOSE_2);
+
+ artwork.graphics_set_current = artwork.gfx_current->name;
+ }
+
+ if (artwork.sounds_set_current != artwork.snd_current->name)
+ {
+ printf("reload sounds ...\n");
+
+ artwork.sounds_set_current = artwork.snd_current->name;
+ }
+
+ if (artwork.music_set_current != artwork.mus_current->name)
+ {
+ printf("reload music ...\n");
+
+ artwork.music_set_current = artwork.mus_current->name;
+ }
+}
+
void InitGadgets()
{
CreateLevelEditorGadgets();
#include "main.h"
void OpenAll(void);
+void ReloadCustomArtwork();
void CloseAllAndExit(int);
#endif
#include "sound.h"
#include "joystick.h"
#include "misc.h"
+#include "setup.h"
#include "pcx.h"
#define AllegroDefaultScreen() (display->screens[display->default_screen])
Screen *screen;
Display *display;
BITMAP *mouse_bitmap = NULL;
+ char *mouse_filename =getCustomImageFilename(program.msdos_pointer_filename);
- mouse_bitmap = Read_PCX_to_AllegroBitmap(program.msdos_pointer_filename);
- if (mouse_bitmap == NULL)
+ if ((mouse_bitmap = Read_PCX_to_AllegroBitmap(mouse_filename)) == NULL)
return NULL;
screen = malloc(sizeof(Screen));
/* free temporary surface */
SDL_FreeSurface(sdl_image_tmp);
+ new_bitmap->width = new_bitmap->surface->w;
+ new_bitmap->height = new_bitmap->surface->h;
+
return new_bitmap;
}
struct SDLSurfaceInfo
{
char *source_filename;
+ int width, height;
SDL_Surface *surface;
SDL_Surface *surface_masked;
GC gc;
return filename;
/* 4th try: look for default artwork in new default artwork directory */
- filename = getPath2(getDefaultGraphicsDir("gfx_classic"), basename);
+ filename = getPath2(getDefaultGraphicsDir(GRAPHICS_SUBDIR), basename);
if (fileExists(filename))
return filename;
return (node != NULL && !node->node_group && !node->parent_link);
}
-TreeInfo *getFirstValidLevelSeries(TreeInfo *node)
+TreeInfo *getFirstValidTreeInfoEntry(TreeInfo *node)
{
if (node == NULL)
{
- if (leveldir_first) /* start with first level directory entry */
- return getFirstValidLevelSeries(leveldir_first);
+ if (node->node_top) /* start with first tree entry */
+ return getFirstValidTreeInfoEntry(*node->node_top);
else
return NULL;
}
else if (node->node_group) /* enter level group (step down into tree) */
- return getFirstValidLevelSeries(node->node_group);
+ return getFirstValidTreeInfoEntry(node->node_group);
else if (node->parent_link) /* skip start entry of level group */
{
if (node->next) /* get first real level series entry */
- return getFirstValidLevelSeries(node->next);
+ return getFirstValidTreeInfoEntry(node->next);
else /* leave empty level group and go on */
- return getFirstValidLevelSeries(node->node_parent->next);
+ return getFirstValidTreeInfoEntry(node->node_parent->next);
}
else /* this seems to be a regular level series */
return node;
LoadLevelInfoFromLevelDir(&leveldir_first, NULL, options.level_directory);
LoadLevelInfoFromLevelDir(&leveldir_first, NULL, getUserLevelDir(NULL));
- leveldir_current = getFirstValidLevelSeries(leveldir_first);
+ /* before sorting, the first entries will be from the user directory */
+ leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
if (leveldir_first == NULL)
Error(ERR_EXIT, "cannot find any valid level series in any directory");
char *check_dir = NULL;
int i;
- if (access(getUserLevelDir(filename), F_OK) == 0) /* file exists */
+ if (access(filename, F_OK) == 0) /* file exists */
loadSetupFileList(filename);
if (setup_file_list == NULL) /* no config file -- look for artwork files */
struct dirent *dir_entry;
boolean valid_file_found = FALSE;
- if ((dir = opendir(base_directory)) != NULL)
+ if ((dir = opendir(directory_path)) != NULL)
{
while ((dir_entry = readdir(dir)) != NULL)
{
if (!valid_file_found)
{
- Error(ERR_WARN, "ignoring artwork directory '%s'", base_directory);
+ if (options.debug)
+ Error(ERR_WARN, "ignoring artwork directory '%s'", base_directory);
free(directory_path);
free(filename);
TREE_TYPE_MUSIC_DIR);
/* before sorting, the first entries will be from the user directory */
- artwork.gfx_current = artwork.gfx_first;
- artwork.snd_current = artwork.snd_first;
- artwork.mus_current = artwork.mus_first;
+ artwork.gfx_current =
+ getTreeInfoFromFilename(artwork.gfx_first, setup.graphics_set);
+ if (artwork.gfx_current == NULL)
+ artwork.gfx_current = getFirstValidTreeInfoEntry(artwork.gfx_first);
+
+ artwork.snd_current =
+ getTreeInfoFromFilename(artwork.snd_first, setup.sounds_set);
+ if (artwork.snd_current == NULL)
+ artwork.snd_current = getFirstValidTreeInfoEntry(artwork.snd_first);
+
+ artwork.mus_current =
+ getTreeInfoFromFilename(artwork.mus_first, setup.music_set);
+ if (artwork.mus_current == NULL)
+ artwork.mus_current = getFirstValidTreeInfoEntry(artwork.mus_first);
+
+ artwork.graphics_set_current = artwork.gfx_current->name;
+ artwork.sounds_set_current = artwork.snd_current->name;
+ artwork.music_set_current = artwork.mus_current->name;
sortTreeInfo(&artwork.gfx_first, compareTreeInfoEntries);
sortTreeInfo(&artwork.snd_first, compareTreeInfoEntries);
struct SetupFileList *level_setup_list = NULL;
/* always start with reliable default values */
- leveldir_current = getFirstValidLevelSeries(leveldir_first);
+ leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
/* ----------------------------------------------------------------------- */
/* ~/.<program>/levelsetup.conf */
leveldir_current = getTreeInfoFromFilename(leveldir_first,
last_level_series);
if (leveldir_current == NULL)
- leveldir_current = leveldir_first;
+ leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
checkSetupFileListIdentifier(level_setup_list, getCookie("LEVELSETUP"));
void pushTreeInfo(TreeInfo **, TreeInfo *);
int numTreeInfo(TreeInfo *);
boolean validLevelSeries(TreeInfo *);
-TreeInfo *getFirstValidLevelSeries(TreeInfo *);
+TreeInfo *getFirstValidTreeInfoEntry(TreeInfo *);
TreeInfo *getTreeInfoFirstGroupEntry(TreeInfo *);
int numTreeInfoInGroup(TreeInfo *);
int posTreeInfo(TreeInfo *);
void InitProgramInfo(char *unix_userdata_directory, char *program_title,
char *window_title, char *icon_title,
- char *x11_icon_basename, char *x11_iconmask_basename,
- char *msdos_pointer_basename,
+ char *x11_icon_filename, char *x11_iconmask_filename,
+ char *msdos_pointer_filename,
char *cookie_prefix, char *filename_prefix,
int program_version)
{
- char *x11_icon_filename =
- getPath2(options.graphics_directory, x11_icon_basename);
- char *x11_iconmask_filename =
- getPath2(options.graphics_directory, x11_iconmask_basename);
- char *msdos_pointer_filename =
- getPath2(options.graphics_directory, msdos_pointer_basename);
-
#if defined(PLATFORM_UNIX)
program.userdata_directory = unix_userdata_directory;
#else
new_bitmap = X11LoadImage(filename);
#endif
+ new_bitmap->source_filename = getStringCopy(filename);
+
return new_bitmap;
}
if ((new_bitmap = LoadImage(filename)) == NULL)
Error(ERR_EXIT, "LoadImage() failed: %s", GetError());
- new_bitmap->source_filename = getStringCopy(filename);
-
return new_bitmap;
}
+void ReloadCustomImage(Bitmap **bitmap, char *basename)
+{
+ char *filename = getCustomImageFilename(basename);
+ Bitmap *old_bitmap = *bitmap;
+ Bitmap *new_bitmap;
+
+ if (filename == NULL) /* (should never happen) */
+ {
+ Error(ERR_WARN, "ReloadCustomImage(): cannot find file '%s'", basename);
+ return;
+ }
+
+ if (strcmp(filename, old_bitmap->source_filename) == 0)
+ {
+ /* The old and new image are the same (have the same filename and path).
+ This usually means that this image does not exist in this graphic set
+ and a fallback to the existing image is done. */
+
+ return;
+ }
+
+ if ((new_bitmap = LoadImage(filename)) == NULL)
+ {
+ Error(ERR_WARN, "LoadImage() failed: %s", GetError());
+ return;
+ }
+
+ if (old_bitmap->width != new_bitmap->width ||
+ old_bitmap->height != new_bitmap->height)
+ {
+ Error(ERR_WARN, "ReloadCustomImage: new image has wrong dimensions");
+ FreeBitmap(new_bitmap);
+ return;
+ }
+
+ /* copy filename for new image */
+ free(old_bitmap->source_filename);
+ old_bitmap->source_filename = getStringCopy(filename);
+
+ /* copy bitmap data for new image */
+ BlitBitmap(new_bitmap, old_bitmap, 0,0,
+ old_bitmap->width, old_bitmap->height, 0,0);
+
+ FreeBitmap(new_bitmap);
+}
+
/* ========================================================================= */
/* audio functions */
#define RW_BASE_PATH RW_GAME_DIR
#define GRAPHICS_DIRECTORY "graphics"
-#define MUSIC_DIRECTORY "music"
#define SOUNDS_DIRECTORY "sounds"
+#define MUSIC_DIRECTORY "music"
#define LEVELS_DIRECTORY "levels"
#define TAPES_DIRECTORY "tapes"
#define SCORES_DIRECTORY "scores"
+#if !defined(PLATFORM_MSDOS)
+#define GRAPHICS_SUBDIR "gfx_classic"
+#define SOUNDS_SUBDIR "snd_classic"
+#define MUSIC_SUBDIR "mus_classic"
+#else
+#define GRAPHICS_SUBDIR "gfx_orig"
+#define SOUNDS_SUBDIR "snd_orig"
+#define MUSIC_SUBDIR "mus_orig"
+#endif
+
/* areas in bitmap PIX_DOOR */
/* meaning in PIX_DB_DOOR: (3 PAGEs)
PAGEX1: 1. buffer for DOOR_1
boolean fullscreen;
boolean ask_on_escape;
- char *graphics_dir;
- char *sounds_dir;
- char *music_dir;
+ char *graphics_set;
+ char *sounds_set;
+ char *music_set;
struct SetupShortcutInfo shortcut;
struct SetupInputInfo input[MAX_PLAYERS];
SoundsDirTree *snd_current;
MusicDirTree *mus_first;
MusicDirTree *mus_current;
+
+ char *graphics_set_current;
+ char *sounds_set_current;
+ char *music_set_current;
};
Bitmap *LoadImage(char *);
Bitmap *LoadCustomImage(char *);
+void ReloadCustomImage(Bitmap **, char *);
inline void OpenAudio(void);
inline void CloseAudio(void);
#include "system.h"
#include "pcx.h"
#include "misc.h"
+#include "setup.h"
#if defined(TARGET_X11)
icon_pic.picture_filename);
#endif
if (XReadBitmapFile(display, new_window->drawable,
- program.x11_icon_filename,
+ getCustomImageFilename(program.x11_icon_filename),
&icon_width, &icon_height, &icon_pixmap,
&icon_hot_x, &icon_hot_y) != BitmapSuccess)
Error(ERR_EXIT, "cannot read icon bitmap file '%s'",
icon_pic.picturemask_filename);
#endif
if (XReadBitmapFile(display, new_window->drawable,
- program.x11_iconmask_filename,
+ getCustomImageFilename(program.x11_iconmask_filename),
&icon_width, &icon_height, &iconmask_pixmap,
&icon_hot_x, &icon_hot_y) != BitmapSuccess)
Error(ERR_EXIT, "cannot read icon bitmap file '%s'",
return new_window;
}
+static void SetImageDimensions(Bitmap *bitmap)
+{
+ Window root;
+ int x, y;
+ unsigned int border_width, depth;
+
+ XGetGeometry(display, bitmap->drawable, &root, &x, &y,
+ &bitmap->width, &bitmap->height, &border_width, &depth);
+}
+
Bitmap *X11LoadImage(char *filename)
{
Bitmap *new_bitmap = CreateBitmapStruct();
/* set GraphicContext inheritated from Window */
new_bitmap->gc = window->gc;
+ /* set image width and height */
+ SetImageDimensions(new_bitmap);
+
return new_bitmap;
}
struct X11DrawableInfo
{
char *source_filename;
+ int width, height;
Drawable drawable;
Drawable clip_mask;
GC gc; /* GC for normal drawing (inheritated from 'window') */
/* needed if last screen was the setup screen and fullscreen state changed */
ToggleFullscreenIfNeeded();
+ /* needed if last screen (setup/level) changed graphics, sounds or music */
+ ReloadCustomArtwork();
+
#ifdef TARGET_SDL
SetDrawtoField(DRAW_BACKBUFFER);
#endif
/* leveldir_current may be invalid (level group, parent link) */
if (!validLevelSeries(leveldir_current))
- leveldir_current = getFirstValidLevelSeries(leveldir_last_valid);
+ leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
/* store valid level series information */
leveldir_last_valid = leveldir_current;
static struct TokenInfo *setup_info;
static int num_setup_info;
-static char *custom_graphics, *custom_sounds, *custom_music;
static void execSetupMain()
{
static void execSetupGraphics()
{
- custom_graphics = artwork.gfx_current->name;
+ setup.graphics_set = artwork.gfx_current->name;
setup_mode = SETUP_MODE_GRAPHICS;
DrawSetupScreen();
static void execSetupSound()
{
- custom_sounds = artwork.snd_current->name;
- custom_music = artwork.mus_current->name;
+ setup.sounds_set = artwork.snd_current->name;
+ setup.music_set = artwork.mus_current->name;
setup_mode = SETUP_MODE_SOUND;
DrawSetupScreen();
static struct TokenInfo setup_info_graphics[] =
{
{ TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
- { TYPE_STRING, &custom_graphics, "" },
+ { TYPE_STRING, &setup.graphics_set, "" },
{ TYPE_EMPTY, NULL, "" },
{ TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
{ TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
{ TYPE_SWITCH, &setup.sound_music, "Game Music:" },
{ TYPE_EMPTY, NULL, "" },
{ TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
- { TYPE_STRING, &custom_sounds, "" },
+ { TYPE_STRING, &setup.sounds_set, "" },
{ TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
- { TYPE_STRING, &custom_music, "" },
+ { TYPE_STRING, &setup.music_set, "" },
{ TYPE_EMPTY, NULL, "" },
{ TYPE_LEAVE_MENU, execSetupMain, "Exit" },
{ 0, NULL, NULL }
{
int xpos = MENU_SCREEN_VALUE_XPOS;
int ypos = MENU_SCREEN_START_YPOS + pos;
- int value_color = FC_YELLOW;
+ int font_size = FS_BIG;
+ int font_color = FC_YELLOW;
char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
setup_info[pos].value);
if (setup_info[pos].type & TYPE_QUERY)
{
value_string = "<press key>";
- value_color = FC_RED;
+ font_color = FC_RED;
}
}
else if (setup_info[pos].type & TYPE_STRING)
{
- xpos = 3;
+ int max_value_len = (SCR_FIELDX - 2) * 2;
+
+ xpos = 1;
+ font_size = FS_MEDIUM;
- if (strlen(value_string) > 14)
- value_string[14] = '\0';
+ if (strlen(value_string) > max_value_len)
+ value_string[max_value_len] = '\0';
}
else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
!*(boolean *)(setup_info[pos].value))
- value_color = FC_BLUE;
+ font_color = FC_BLUE;
DrawText(SX + xpos * 32, SY + ypos * 32,
(xpos == 3 ? " " : " "), FS_BIG, FC_YELLOW);
- DrawText(SX + xpos * 32, SY + ypos * 32, value_string, FS_BIG, value_color);
+ DrawText(SX + xpos * 32, SY + ypos * 32, value_string, font_size,font_color);
}
static void changeSetupValue(int pos)
-#define COMPILE_DATE_STRING "[2002-04-06 14:21]"
+#define COMPILE_DATE_STRING "[2002-04-07 13:13]"
unsigned int GetDoorState()
{
- return(MoveDoor(DOOR_GET_STATE));
+ return MoveDoor(DOOR_GET_STATE);
+}
+
+unsigned int SetDoorState(unsigned int door_state)
+{
+ return MoveDoor(door_state | DOOR_SET_STATE);
}
unsigned int MoveDoor(unsigned int door_state)
if (door_state == DOOR_GET_STATE)
return(door1 | door2);
+ if (door_state & DOOR_SET_STATE)
+ {
+ if (door_state & DOOR_ACTION_1)
+ door1 = door_state & DOOR_ACTION_1;
+ if (door_state & DOOR_ACTION_2)
+ door2 = door_state & DOOR_ACTION_2;
+
+ return(door1 | door2);
+ }
+
if (door1 == DOOR_OPEN_1 && door_state & DOOR_OPEN_1)
door_state &= ~DOOR_OPEN_1;
else if (door1 == DOOR_CLOSE_1 && door_state & DOOR_CLOSE_1)
#define DOOR_COPY_BACK (1 << 4)
#define DOOR_NO_DELAY (1 << 5)
#define DOOR_GET_STATE (1 << 6)
+#define DOOR_SET_STATE (1 << 7)
/* for Request */
#define REQ_ASK (1 << 0)
unsigned int OpenDoor(unsigned int);
unsigned int CloseDoor(unsigned int);
unsigned int GetDoorState(void);
+unsigned int SetDoorState(unsigned int);
unsigned int MoveDoor(unsigned int);
void DrawSpecialEditorDoor();
void UndrawSpecialEditorDoor();