From: Holger Schemel Date: Wed, 24 Jan 2007 21:21:45 +0000 (+0100) Subject: rnd-20070124-2-src X-Git-Tag: 3.2.4^2~103 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=dd84b7b1787629d37dd3cabeb8c5c6218190730f rnd-20070124-2-src * added code for configuration directives for control of game panel --- diff --git a/ChangeLog b/ChangeLog index f9fee811..92ceec49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2007-01-23 + * added code for configuration directives for control of game panel + 2007-01-21 * fixed small cosmetical bug with underlining property tabs in editor diff --git a/src/conf_gfx.c b/src/conf_gfx.c index dd669e0e..d21f22ec 100644 --- a/src/conf_gfx.c +++ b/src/conf_gfx.c @@ -5128,8 +5128,9 @@ struct ConfigInfo image_config[] = { "game.panel.inventory.y", "89" }, { "game.panel.inventory.align", "center" }, { "game.panel.inventory.digits", "3" }, - { "game.panel.keys.x", "18" }, + { "game.panel.keys.x", "50" }, { "game.panel.keys.y", "123" }, + { "game.panel.keys.align", "center" }, { "game.panel.score.x", "50" }, { "game.panel.score.y", "159" }, { "game.panel.score.align", "center" }, @@ -5213,10 +5214,10 @@ struct ConfigInfo image_config[] = { "game.panel.key_8.y", "-1" }, { "game.panel.key_white.x", "-1" }, { "game.panel.key_white.y", "-1" }, - { "game.panel.num_white_keys.x", "-1" }, - { "game.panel.num_white_keys.y", "-1" }, - { "game.panel.num_white_keys.align", "left" }, - { "game.panel.num_white_keys.digits", "-1" }, + { "game.panel.white_keys.x", "-1" }, + { "game.panel.white_keys.y", "-1" }, + { "game.panel.white_keys.align", "left" }, + { "game.panel.white_keys.digits", "-1" }, { "game.panel.shield_normal.x", "-1" }, { "game.panel.shield_normal.y", "-1" }, diff --git a/src/conftime.h b/src/conftime.h index 3eeebb95..190f6d06 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2007-01-24 03:14]" +#define COMPILE_DATE_STRING "[2007-01-24 22:14]" diff --git a/src/game.c b/src/game.c index 62ed8bbb..3652cc99 100644 --- a/src/game.c +++ b/src/game.c @@ -85,9 +85,15 @@ #define EX_TYPE_DYNA (1 << 4) #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER) +#if 1 +#define PANEL_DEACTIVATED(p) ((p)->x < 0 || (p)->y < 0) +#define PANEL_XPOS(p) (DX + ALIGNED_MENU_XPOS(p)) +#define PANEL_YPOS(p) (DY + ALIGNED_MENU_YPOS(p)) +#else #define PANEL_DEACTIVATED(p) ((p).x < 0 || (p).y < 0) #define PANEL_XPOS(p) (ALIGNED_XPOS((p).x, (p).width, (p).align)) #define PANEL_YPOS(p) ((p).y) +#endif /* special positions in the game control window (relative to control window) */ #define XX_LEVEL1 (PANEL_XPOS(game.panel.level)) @@ -1325,148 +1331,151 @@ static inline void InitField_WithBug2(int x, int y, boolean init_game) #if 1 -inline void DrawGameValue_Emeralds(int value) +void DrawGameValue_Emeralds(int value) { + struct TextPosInfo *pos = &game.panel.gems; int font_nr = FONT_TEXT_2; int font_width = getFontWidth(font_nr); - int xpos = (3 * 14 - 3 * font_width) / 2; + int digits = pos->chars; - if (PANEL_DEACTIVATED(game.panel.gems)) + if (PANEL_DEACTIVATED(pos)) return; - game.panel.gems.width = game.panel.gems.chars * font_width; - xpos = 0; + pos->width = digits * font_width; - DrawText(DX_EMERALDS + xpos, DY_EMERALDS, int2str(value, 3), font_nr); + DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr); } -inline void DrawGameValue_Dynamite(int value) +void DrawGameValue_Dynamite(int value) { + struct TextPosInfo *pos = &game.panel.inventory; int font_nr = FONT_TEXT_2; int font_width = getFontWidth(font_nr); - int xpos = (3 * 14 - 3 * font_width) / 2; - - if (PANEL_DEACTIVATED(game.panel.inventory)) - return; - - game.panel.inventory.width = game.panel.inventory.chars * font_width; - xpos = 0; - - DrawText(DX_DYNAMITE + xpos, DY_DYNAMITE, int2str(value, 3), font_nr); -} - -inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS]) -{ - int base_key_graphic = EL_KEY_1; - int i; + int digits = pos->chars; - if (PANEL_DEACTIVATED(game.panel.keys)) + if (PANEL_DEACTIVATED(pos)) return; - if (level.game_engine_type == GAME_ENGINE_TYPE_EM) - base_key_graphic = EL_EM_KEY_1; + pos->width = digits * font_width; - /* currently only 4 of 8 possible keys are displayed */ - for (i = 0; i < STD_NUM_KEYS; i++) - { - int x = XX_KEYS + i * MINI_TILEX; - int y = YY_KEYS; - - if (key[i]) - DrawMiniGraphicExt(drawto, DX + x,DY + y, el2edimg(base_key_graphic + i)); - else - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, - DOOR_GFX_PAGEX5 + x, y, MINI_TILEX, MINI_TILEY, DX + x,DY + y); - } + DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr); } -inline void DrawGameValue_Score(int value) +void DrawGameValue_Score(int value) { + struct TextPosInfo *pos = &game.panel.score; int font_nr = FONT_TEXT_2; int font_width = getFontWidth(font_nr); - int xpos = (5 * 14 - 5 * font_width) / 2; + int digits = pos->chars; - if (PANEL_DEACTIVATED(game.panel.score)) + if (PANEL_DEACTIVATED(pos)) return; - game.panel.score.width = game.panel.score.chars * font_width; - xpos = 0; + pos->width = digits * font_width; - DrawText(DX_SCORE + xpos, DY_SCORE, int2str(value, 5), font_nr); + DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr); } -inline void DrawGameValue_Time(int value) +void DrawGameValue_Time(int value) { + struct TextPosInfo *pos = &game.panel.time; static int last_value = -1; - int num_digits1 = 3; - int num_digits2 = 4; - int num_digits = game.panel.time.chars; + int digits1 = 3; + int digits2 = 4; + int digits = pos->chars; int font1_nr = FONT_TEXT_2; int font2_nr = FONT_TEXT_1; int font_nr = font1_nr; - int font1_width = getFontWidth(font1_nr); - int font2_width = getFontWidth(font2_nr); - int xpos3 = (3 * 14 - 3 * font1_width) / 2; - int xpos4 = (4 * 10 - 4 * font2_width) / 2; + boolean use_dynamic_digits = (digits == -1 ? TRUE : FALSE); - if (PANEL_DEACTIVATED(game.panel.time)) + if (PANEL_DEACTIVATED(pos)) return; - if (num_digits == -1) /* use dynamic number of digits */ + if (use_dynamic_digits) /* use dynamic number of digits */ { - num_digits = (value < 1000 ? num_digits1 : num_digits2); - font_nr = (value < 1000 ? font1_nr : font2_nr); + digits = (value < 1000 ? digits1 : digits2); + font_nr = (value < 1000 ? font1_nr : font2_nr); } - xpos3 = 0; - xpos4 = 0; - /* clear background if value just changed its size (dynamic digits only) */ - if (game.panel.time.chars == -1 && (last_value < 1000) != (value < 1000)) + if (use_dynamic_digits && (last_value < 1000) != (value < 1000)) { - int width1 = num_digits1 * getFontWidth(font1_nr); - int width2 = num_digits2 * getFontWidth(font2_nr); + int width1 = digits1 * getFontWidth(font1_nr); + int width2 = digits2 * getFontWidth(font2_nr); int max_width = MAX(width1, width2); int max_height = MAX(getFontHeight(font1_nr), getFontHeight(font2_nr)); - game.panel.time.width = max_width; + pos->width = max_width; - ClearRectangleOnBackground(drawto, DX_TIME, DY_TIME, max_width, max_height); + ClearRectangleOnBackground(drawto, PANEL_XPOS(pos), PANEL_YPOS(pos), + max_width, max_height); } - game.panel.time.width = num_digits * getFontWidth(font_nr); + pos->width = digits * getFontWidth(font_nr); - DrawText(DX_TIME, DY_TIME, int2str(value, num_digits), font_nr); + DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr); last_value = value; } -inline void DrawGameValue_Level(int value) +void DrawGameValue_Level(int value) { - int num_digits1 = 2; - int num_digits2 = 3; - int num_digits = game.panel.level.chars; + struct TextPosInfo *pos = &game.panel.level; + int digits1 = 2; + int digits2 = 3; + int digits = pos->chars; int font1_nr = FONT_TEXT_2; int font2_nr = FONT_TEXT_1; int font_nr = font1_nr; + boolean use_dynamic_digits = (digits == -1 ? TRUE : FALSE); - if (PANEL_DEACTIVATED(game.panel.level)) + if (PANEL_DEACTIVATED(pos)) return; - if (num_digits == -1) /* use dynamic number of digits */ + if (use_dynamic_digits) /* use dynamic number of digits */ { - num_digits = (level_nr < 100 ? num_digits1 : num_digits2); - font_nr = (level_nr < 100 ? font1_nr : font2_nr); + digits = (level_nr < 100 ? digits1 : digits2); + font_nr = (level_nr < 100 ? font1_nr : font2_nr); } - game.panel.level.width = num_digits * getFontWidth(font_nr); + pos->width = digits * getFontWidth(font_nr); - DrawText(DX_LEVEL, DY_LEVEL, int2str(value, num_digits), font_nr); + DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr); +} + +void DrawGameValue_Keys(int key[MAX_NUM_KEYS]) +{ + struct TextPosInfo *pos = &game.panel.keys; + int base_key_graphic = EL_KEY_1; + int i; + + if (PANEL_DEACTIVATED(pos)) + return; + + if (level.game_engine_type == GAME_ENGINE_TYPE_EM) + base_key_graphic = EL_EM_KEY_1; + + pos->width = 4 * MINI_TILEX; + + /* currently only 4 of 8 possible keys are displayed */ + for (i = 0; i < STD_NUM_KEYS; i++) + { + int src_x = DOOR_GFX_PAGEX5 + 18; + int src_y = DOOR_GFX_PAGEY1 + 123; + int dst_x = PANEL_XPOS(pos) + i * MINI_TILEX; + int dst_y = PANEL_YPOS(pos); + + if (key[i]) + DrawMiniGraphicExt(drawto, dst_x, dst_y, el2edimg(base_key_graphic + i)); + else + BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, src_x, src_y, + MINI_TILEX, MINI_TILEY, dst_x, dst_y); + } } #else -inline void DrawGameValue_Emeralds(int value) +void DrawGameValue_Emeralds(int value) { int font_nr = FONT_TEXT_2; int xpos = (3 * 14 - 3 * getFontWidth(font_nr)) / 2; @@ -1477,7 +1486,7 @@ inline void DrawGameValue_Emeralds(int value) DrawText(DX_EMERALDS + xpos, DY_EMERALDS, int2str(value, 3), font_nr); } -inline void DrawGameValue_Dynamite(int value) +void DrawGameValue_Dynamite(int value) { int font_nr = FONT_TEXT_2; int xpos = (3 * 14 - 3 * getFontWidth(font_nr)) / 2; @@ -1488,32 +1497,7 @@ inline void DrawGameValue_Dynamite(int value) DrawText(DX_DYNAMITE + xpos, DY_DYNAMITE, int2str(value, 3), font_nr); } -inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS]) -{ - int base_key_graphic = EL_KEY_1; - int i; - - if (PANEL_DEACTIVATED(game.panel.keys)) - return; - - if (level.game_engine_type == GAME_ENGINE_TYPE_EM) - base_key_graphic = EL_EM_KEY_1; - - /* currently only 4 of 8 possible keys are displayed */ - for (i = 0; i < STD_NUM_KEYS; i++) - { - int x = XX_KEYS + i * MINI_TILEX; - int y = YY_KEYS; - - if (key[i]) - DrawMiniGraphicExt(drawto, DX + x,DY + y, el2edimg(base_key_graphic + i)); - else - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, - DOOR_GFX_PAGEX5 + x, y, MINI_TILEX, MINI_TILEY, DX + x,DY + y); - } -} - -inline void DrawGameValue_Score(int value) +void DrawGameValue_Score(int value) { int font_nr = FONT_TEXT_2; int xpos = (5 * 14 - 5 * getFontWidth(font_nr)) / 2; @@ -1524,7 +1508,7 @@ inline void DrawGameValue_Score(int value) DrawText(DX_SCORE + xpos, DY_SCORE, int2str(value, 5), font_nr); } -inline void DrawGameValue_Time(int value) +void DrawGameValue_Time(int value) { int font1_nr = FONT_TEXT_2; #if 1 @@ -1548,7 +1532,7 @@ inline void DrawGameValue_Time(int value) DrawText(DX_TIME2 + xpos4, DY_TIME, int2str(value, 4), font2_nr); } -inline void DrawGameValue_Level(int value) +void DrawGameValue_Level(int value) { int font1_nr = FONT_TEXT_2; #if 1 @@ -1566,6 +1550,31 @@ inline void DrawGameValue_Level(int value) DrawText(DX_LEVEL2, DY_LEVEL, int2str(value, 3), font2_nr); } +void DrawGameValue_Keys(int key[MAX_NUM_KEYS]) +{ + int base_key_graphic = EL_KEY_1; + int i; + + if (PANEL_DEACTIVATED(game.panel.keys)) + return; + + if (level.game_engine_type == GAME_ENGINE_TYPE_EM) + base_key_graphic = EL_EM_KEY_1; + + /* currently only 4 of 8 possible keys are displayed */ + for (i = 0; i < STD_NUM_KEYS; i++) + { + int x = XX_KEYS + i * MINI_TILEX; + int y = YY_KEYS; + + if (key[i]) + DrawMiniGraphicExt(drawto, DX + x,DY + y, el2edimg(base_key_graphic + i)); + else + BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, + DOOR_GFX_PAGEX5 + x, y, MINI_TILEX, MINI_TILEY, DX + x,DY + y); + } +} + #endif void DrawAllGameValues(int emeralds, int dynamite, int score, int time, diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 114087ac..355eefed 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -1619,17 +1619,21 @@ static void printSetupFileHash(SetupFileHash *hash) } #endif +#define ALLOW_TOKEN_VALUE_SEPARATOR_BEING_WHITESPACE 1 +#define CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING 0 + static void *loadSetupFileData(char *filename, boolean use_hash) { - char line[MAX_LINE_LEN], previous_line[MAX_LINE_LEN]; + char line[MAX_LINE_LEN], line_raw[MAX_LINE_LEN], previous_line[MAX_LINE_LEN]; char *token, *value, *line_ptr; void *setup_file_data, *insert_ptr = NULL; boolean read_continued_line = FALSE; boolean token_value_separator_found; -#if 1 +#if CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING boolean token_value_separator_warning = FALSE; #endif FILE *file; + int line_nr = 0; if (!(file = fopen(filename, MODE_READ))) { @@ -1649,11 +1653,18 @@ static void *loadSetupFileData(char *filename, boolean use_hash) if (!fgets(line, MAX_LINE_LEN, file)) break; - /* cut trailing newline or carriage return */ + /* check if line was completely read and is terminated by line break */ + if (strlen(line) > 0 && line[strlen(line) - 1] == '\n') + line_nr++; + + /* cut trailing line break (this can be newline and/or carriage return) */ for (line_ptr = &line[strlen(line)]; line_ptr >= line; line_ptr--) if ((*line_ptr == '\n' || *line_ptr == '\r') && *(line_ptr + 1) == '\0') *line_ptr = '\0'; + /* copy raw input line for later use (mainly debugging output) */ + strcpy(line_raw, line); + if (read_continued_line) { /* cut leading whitespaces from input line */ @@ -1714,6 +1725,7 @@ static void *loadSetupFileData(char *filename, boolean use_hash) for (line_ptr = token; *line_ptr; line_ptr++) { #if 1 + /* first look for an explicit token/value separator, like ':' or '=' */ if (*line_ptr == ':' || *line_ptr == '=') #else if (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == ':') @@ -1728,7 +1740,7 @@ static void *loadSetupFileData(char *filename, boolean use_hash) } } -#if 1 +#if ALLOW_TOKEN_VALUE_SEPARATOR_BEING_WHITESPACE /* fallback: if no token/value separator found, also allow whitespaces */ if (!token_value_separator_found) { @@ -1745,19 +1757,19 @@ static void *loadSetupFileData(char *filename, boolean use_hash) } } -#if 1 +#if CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING if (token_value_separator_found) { if (!token_value_separator_warning) { Error(ERR_RETURN_LINE, "-"); - Error(ERR_WARN, "no valid token/value separator in config file:"); + Error(ERR_WARN, "missing token/value separator(s) in config file:"); Error(ERR_RETURN, "- config file: '%s'", filename); token_value_separator_warning = TRUE; } - Error(ERR_RETURN, "- no separator in line: '%s'", line); + Error(ERR_RETURN, "- line %d: '%s'", line_nr, line_raw); } #endif } @@ -1789,7 +1801,7 @@ static void *loadSetupFileData(char *filename, boolean use_hash) fclose(file); -#if 1 +#if CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING if (token_value_separator_warning) Error(ERR_RETURN_LINE, "-"); #endif @@ -2400,6 +2412,7 @@ static TreeInfo *getArtworkInfoCacheEntry(LevelDirTree *level_node, int type) cached = FALSE; } } + *artwork_info = ldi; } diff --git a/src/libgame/system.h b/src/libgame/system.h index 9d3e578a..b25dc128 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -210,6 +210,8 @@ #define ALIGNED_XPOS(x,w,a) ((a) == ALIGN_CENTER ? (x) - (w) / 2 : \ (a) == ALIGN_RIGHT ? (x) - (w) : (x)) +#define ALIGNED_MENU_XPOS(p) ALIGNED_XPOS((p)->x, (p)->width, (p)->align) +#define ALIGNED_MENU_YPOS(p) ((p)->y) /* values for redraw_mask */ #define REDRAW_NONE (0) diff --git a/src/main.c b/src/main.c index 8e83997f..2e4fb740 100644 --- a/src/main.c +++ b/src/main.c @@ -5571,6 +5571,7 @@ struct TokenIntPtrInfo image_config_vars[] = { "game.panel.inventory.digits", &game.panel.inventory.chars }, { "game.panel.keys.x", &game.panel.keys.x }, { "game.panel.keys.y", &game.panel.keys.y }, + { "game.panel.keys.align", &game.panel.keys.align }, { "game.panel.score.x", &game.panel.score.x }, { "game.panel.score.y", &game.panel.score.y }, { "game.panel.score.align", &game.panel.score.align }, diff --git a/src/screens.c b/src/screens.c index 6ba029e7..fa44e771 100644 --- a/src/screens.c +++ b/src/screens.c @@ -505,8 +505,8 @@ static void DrawCursorAndText_Main_Ext(int nr, boolean active_text, if (pos_text != NULL && text != NULL) { struct MenuPosInfo *pos = pos_text; - int x = mSX + ALIGNED_XPOS(pos->x, pos->width, pos->align); - int y = mSY + pos->y; + int x = mSX + ALIGNED_MENU_XPOS(pos); + int y = mSY + ALIGNED_MENU_YPOS(pos); DrawBackgroundForFont(x, y, pos->width, pos->height, font_text); DrawText(x, y, text, font_text); @@ -515,8 +515,8 @@ static void DrawCursorAndText_Main_Ext(int nr, boolean active_text, if (pos_input != NULL && input != NULL) { struct MenuPosInfo *pos = pos_input; - int x = mSX + ALIGNED_XPOS(pos->x, pos->width, pos->align); - int y = mSY + pos->y; + int x = mSX + ALIGNED_MENU_XPOS(pos); + int y = mSY + ALIGNED_MENU_YPOS(pos); DrawBackgroundForFont(x, y, pos->width, pos->height, font_input); DrawText(x, y, input, font_input); @@ -553,8 +553,8 @@ static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y) if (rect == NULL) return FALSE; - int rect_x = ALIGNED_XPOS(rect->x, rect->width, rect->align); - int rect_y = rect->y; + int rect_x = ALIGNED_MENU_XPOS(rect); + int rect_y = ALIGNED_MENU_YPOS(rect); return (x >= rect_x && x < rect_x + rect->width && y >= rect_y && y < rect_y + rect->height); @@ -2587,8 +2587,8 @@ void HandleTypeName(int newxpos, Key key) struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME); #if 1 struct MenuPosInfo *pos = mci->pos_input; - int startx = mSX + ALIGNED_XPOS(pos->x, pos->width, pos->align); - int starty = mSY + pos->y; + int startx = mSX + ALIGNED_MENU_XPOS(pos); + int starty = mSY + ALIGNED_MENU_YPOS(pos); #endif #if 1 static int xpos = 0;