From 9cb181e05e485435ef48586dd4f2811ba1e672b3 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 31 Jan 2007 23:50:58 +0100 Subject: [PATCH] rnd-20070131-1-src * fixed displaying and typing of player name when it is centered * added special characters to be allowed for player name (not only A-Z) * fixed blit in ScrollLevel() to same bitmap to not overlap anymore (newer versions of the SDL library seem to not like this anymore) --- ChangeLog | 8 +++ src/Makefile | 1 + src/conf_gfx.c | 2 + src/conftime.h | 2 +- src/game.c | 18 +------ src/libgame/misc.c | 20 ++++--- src/libgame/misc.h | 1 + src/libgame/sdl.h | 5 +- src/libgame/x11.h | 3 +- src/main.c | 2 + src/main.h | 34 ++++++------ src/netserv.c | 3 +- src/screens.c | 128 ++++++++++++++++++++++++++++++++++----------- src/tools.c | 16 ++++-- 14 files changed, 164 insertions(+), 79 deletions(-) diff --git a/ChangeLog b/ChangeLog index 92ceec49..ae937d76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-01-31 + * fixed displaying and typing of player name when it is centered + * added special characters to be allowed for player name (not only A-Z) + +2007-01-25 + * fixed blit in ScrollLevel() to same bitmap to not overlap anymore + (newer versions of the SDL library seem to not like this anymore) + 2007-01-23 * added code for configuration directives for control of game panel diff --git a/src/Makefile b/src/Makefile index ee0da818..86fcd3b0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -55,6 +55,7 @@ PLATFORM = unix endif ifeq ($(PLATFORM),macosx) +EXTRA_LDFLAGS = -lstdc++ PLATFORM = unix TARGET = sdl endif diff --git a/src/conf_gfx.c b/src/conf_gfx.c index 333a8426..b30403fd 100644 --- a/src/conf_gfx.c +++ b/src/conf_gfx.c @@ -5077,9 +5077,11 @@ struct ConfigInfo image_config[] = { "main.text.level_info_1.x", "272" }, { "main.text.level_info_1.y", "352" }, { "main.text.level_info_1.align", "center" }, + { "main.text.level_info_1.chars", "-1" }, { "main.text.level_info_2.x", "272" }, { "main.text.level_info_2.y", "523" }, { "main.text.level_info_2.align", "center" }, + { "main.text.level_info_2.chars", "-1" }, { "main.text.title_1.x", "272" }, { "main.text.title_1.y", "8" }, { "main.text.title_1.align", "center" }, diff --git a/src/conftime.h b/src/conftime.h index caae2a71..8fd2ce3f 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2007-01-26 02:51" +#define COMPILE_DATE_STRING "2007-01-31 23:47" diff --git a/src/game.c b/src/game.c index 0b52048d..af0b7413 100644 --- a/src/game.c +++ b/src/game.c @@ -10588,26 +10588,11 @@ void ScrollLevel(int dx, int dy) FX + TILEX * (dx != 0 ? i : 0), FY + TILEY * (dy != 0 ? i : 0)); } + #else int softscroll_offset = (setup.soft_scrolling ? TILEX : 0); -#if 1 - BlitBitmap(drawto_field, bitmap_db_field2, - FX + TILEX * (dx == -1) - softscroll_offset, - FY + TILEY * (dy == -1) - softscroll_offset, - SXSIZE - TILEX * (dx != 0) + 2 * softscroll_offset, - SYSIZE - TILEY * (dy != 0) + 2 * softscroll_offset, - FX + TILEX * (dx == 1) - softscroll_offset, - FY + TILEY * (dy == 1) - softscroll_offset); - BlitBitmap(bitmap_db_field2, drawto_field, - FX + TILEX * (dx == 1) - softscroll_offset, - FY + TILEY * (dy == 1) - softscroll_offset, - SXSIZE - TILEX * (dx != 0) + 2 * softscroll_offset, - SYSIZE - TILEY * (dy != 0) + 2 * softscroll_offset, - FX + TILEX * (dx == 1) - softscroll_offset, - FY + TILEY * (dy == 1) - softscroll_offset); -#else BlitBitmap(drawto_field, drawto_field, FX + TILEX * (dx == -1) - softscroll_offset, FY + TILEY * (dy == -1) - softscroll_offset, @@ -10615,7 +10600,6 @@ void ScrollLevel(int dx, int dy) SYSIZE - TILEY * (dy != 0) + 2 * softscroll_offset, FX + TILEX * (dx == 1) - softscroll_offset, FY + TILEY * (dy == 1) - softscroll_offset); -#endif #endif if (dx != 0) diff --git a/src/libgame/misc.c b/src/libgame/misc.c index f01ce132..88d2e299 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1219,6 +1219,7 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) { KSYM_asciitilde, "XK_asciitilde", "~" }, /* special (non-ASCII) keys */ + { KSYM_degree, "XK_degree", "°" }, { KSYM_Adiaeresis, "XK_Adiaeresis", "Ä" }, { KSYM_Odiaeresis, "XK_Odiaeresis", "Ö" }, { KSYM_Udiaeresis, "XK_Udiaeresis", "Ü" }, @@ -1447,16 +1448,23 @@ Key getKeyFromX11KeyName(char *x11name) char getCharFromKey(Key key) { char *keyname = getKeyNameFromKey(key); - char letter = 0; + char c = 0; if (strlen(keyname) == 1) - letter = keyname[0]; + c = keyname[0]; else if (strEqual(keyname, "space")) - letter = ' '; - else if (strEqual(keyname, "circumflex")) - letter = '^'; + c = ' '; - return letter; + return c; +} + +char getValidConfigValueChar(char c) +{ + if (c == '#' || /* used to mark comments */ + c == '\\') /* used to mark continued lines */ + c = 0; + + return c; } diff --git a/src/libgame/misc.h b/src/libgame/misc.h index a42a7584..9a5e9186 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -158,6 +158,7 @@ char *getX11KeyNameFromKey(Key); Key getKeyFromKeyName(char *); Key getKeyFromX11KeyName(char *); char getCharFromKey(Key); +char getValidConfigValueChar(char); int get_integer_from_string(char *); boolean get_boolean_from_string(char *); diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 5ab0461d..19ead5e5 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -78,8 +78,8 @@ struct MouseCursorInfo int width, height; int hot_x, hot_y; - char data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8]; - char mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8]; + byte data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8]; + byte mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8]; }; @@ -187,6 +187,7 @@ struct MouseCursorInfo #define KSYM_braceright KSYM_UNDEFINED /* undefined */ #define KSYM_asciitilde KSYM_UNDEFINED /* undefined */ +#define KSYM_degree SDLK_WORLD_16 #define KSYM_Adiaeresis SDLK_WORLD_36 #define KSYM_Odiaeresis SDLK_WORLD_54 #define KSYM_Udiaeresis SDLK_WORLD_60 diff --git a/src/libgame/x11.h b/src/libgame/x11.h index 28e8f5e8..2ebaf86c 100644 --- a/src/libgame/x11.h +++ b/src/libgame/x11.h @@ -75,7 +75,7 @@ struct X11DrawableInfo { char *source_filename; - int width, height; + unsigned int width, height; Drawable drawable; Drawable clip_mask; GC gc; /* GC for normal drawing (inheritated from 'window') */ @@ -198,6 +198,7 @@ struct MouseCursorInfo #define KSYM_braceright XK_braceright #define KSYM_asciitilde XK_asciitilde +#define KSYM_degree XK_degree #define KSYM_Adiaeresis XK_Adiaeresis #define KSYM_Odiaeresis XK_Odiaeresis #define KSYM_Udiaeresis XK_Udiaeresis diff --git a/src/main.c b/src/main.c index 83eefa6d..dee69a89 100644 --- a/src/main.c +++ b/src/main.c @@ -5521,9 +5521,11 @@ struct TokenIntPtrInfo image_config_vars[] = { "main.text.level_info_1.x", &menu.main.text.level_info_1.x }, { "main.text.level_info_1.y", &menu.main.text.level_info_1.y }, { "main.text.level_info_1.align", &menu.main.text.level_info_1.align }, + { "main.text.level_info_1.chars", &menu.main.text.level_info_1.chars }, { "main.text.level_info_2.x", &menu.main.text.level_info_2.x }, { "main.text.level_info_2.y", &menu.main.text.level_info_2.y }, { "main.text.level_info_2.align", &menu.main.text.level_info_2.align }, + { "main.text.level_info_2.chars", &menu.main.text.level_info_2.chars }, { "main.text.title_1.x", &menu.main.text.title_1.x }, { "main.text.title_1.y", &menu.main.text.title_1.y }, { "main.text.title_1.align", &menu.main.text.title_1.align }, diff --git a/src/main.h b/src/main.h index fd1fe6ee..2331cc3b 100644 --- a/src/main.h +++ b/src/main.h @@ -1992,23 +1992,23 @@ struct MenuMainButtonInfo struct MenuMainTextInfo { - struct MenuPosInfo name; - struct MenuPosInfo levels; - struct MenuPosInfo scores; - struct MenuPosInfo editor; - struct MenuPosInfo info; - struct MenuPosInfo game; - struct MenuPosInfo setup; - struct MenuPosInfo quit; - - struct MenuPosInfo current_level; - struct MenuPosInfo first_level; - struct MenuPosInfo last_level; - struct MenuPosInfo level_info_1; - struct MenuPosInfo level_info_2; - struct MenuPosInfo title_1; - struct MenuPosInfo title_2; - struct MenuPosInfo title_3; + struct TextPosInfo name; + struct TextPosInfo levels; + struct TextPosInfo scores; + struct TextPosInfo editor; + struct TextPosInfo info; + struct TextPosInfo game; + struct TextPosInfo setup; + struct TextPosInfo quit; + + struct TextPosInfo current_level; + struct TextPosInfo first_level; + struct TextPosInfo last_level; + struct TextPosInfo level_info_1; + struct TextPosInfo level_info_2; + struct TextPosInfo title_1; + struct TextPosInfo title_2; + struct TextPosInfo title_3; }; struct MenuMainInputInfo diff --git a/src/netserv.c b/src/netserv.c index a62cae02..ac1b71c4 100644 --- a/src/netserv.c +++ b/src/netserv.c @@ -662,7 +662,8 @@ void NetworkServer(int port, int serveronly) if (FD_ISSET(lfd, &fds)) { - int newfd, slen; + int newfd; + socklen_t slen; slen = sizeof(saddr); newfd = accept(lfd, (struct sockaddr *)&saddr, &slen); diff --git a/src/screens.c b/src/screens.c index bd5eb569..460468d9 100644 --- a/src/screens.c +++ b/src/screens.c @@ -238,7 +238,7 @@ struct MainControlInfo struct MenuPosInfo *pos_button; int button_graphic; - struct MenuPosInfo *pos_text; + struct TextPosInfo *pos_text; char *text; int font_text; @@ -388,7 +388,7 @@ static void InitializeMainControls() struct MainControlInfo *mci = &main_controls[i]; int nr = mci->nr; struct MenuPosInfo *pos_button = mci->pos_button; - struct MenuPosInfo *pos_text = mci->pos_text; + struct TextPosInfo *pos_text = mci->pos_text; struct MenuPosInfo *pos_input = mci->pos_input; char *text = mci->text; char *input = mci->input; @@ -421,8 +421,13 @@ static void InitializeMainControls() menu.main.input.name.y = menu.main.text.name.y; #endif +#if 1 + menu.main.input.name.width = input_width; + menu.main.input.name.height = input_height; +#else menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN; menu.main.input.name.height = font_input_height; +#endif } if (pos_button != NULL) @@ -476,7 +481,7 @@ static void DrawCursorAndText_Main_Ext(int nr, boolean active_text, if (mci->nr == nr || nr == -1) { struct MenuPosInfo *pos_button = mci->pos_button; - struct MenuPosInfo *pos_text = mci->pos_text; + struct TextPosInfo *pos_text = mci->pos_text; struct MenuPosInfo *pos_input = mci->pos_input; char *text = mci->text; char *input = mci->input; @@ -507,7 +512,7 @@ static void DrawCursorAndText_Main_Ext(int nr, boolean active_text, if (pos_text != NULL && text != NULL) { - struct MenuPosInfo *pos = pos_text; + struct TextPosInfo *pos = pos_text; int x = mSX + ALIGNED_MENU_XPOS(pos); int y = mSY + ALIGNED_MENU_YPOS(pos); @@ -563,6 +568,18 @@ static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y) y >= rect_y && y < rect_y + rect->height); } +static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y) +{ + if (rect == NULL) + return FALSE; + + 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); +} + static void drawCursorExt(int xpos, int ypos, boolean active, int graphic) { static int cursor_array[SCR_FIELDY]; @@ -1235,7 +1252,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) for (i = 0; main_controls[i].nr != -1; i++) { if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) || - insideMenuPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) || + insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) || insideMenuPosRect(main_controls[i].pos_input, mx - mSX, my - mSY)) { pos = main_controls[i].nr; @@ -2467,12 +2484,12 @@ void DrawInfoScreen_Version() int font_text = FONT_TEXT_2; int xstep = getFontWidth(font_text); int ystep = getFontHeight(font_text); - int xstart1 = SX + 2 * xstep; - int xstart2 = SX + 18 * xstep; - int xstart3 = SX + 28 * xstep; int ystart = 150; int ybottom = SYSIZE - 20; + int xstart1 = SX + 2 * xstep; + int xstart2 = SX + 18 * xstep; #if defined(TARGET_SDL) + int xstart3 = SX + 28 * xstep; SDL_version sdl_version_compiled; const SDL_version *sdl_version_linked; #endif @@ -2526,10 +2543,7 @@ void DrawInfoScreen_Version() sdl_version_linked->patch); SDL_IMAGE_VERSION(&sdl_version_compiled); -#if 0 sdl_version_linked = IMG_Linked_Version(); -#else -#endif ystart += ystep; DrawTextF(xstart1, ystart, font_text, "SDL_image"); @@ -2537,14 +2551,10 @@ void DrawInfoScreen_Version() sdl_version_compiled.major, sdl_version_compiled.minor, sdl_version_compiled.patch); -#if 0 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d", sdl_version_linked->major, sdl_version_linked->minor, sdl_version_linked->patch); -#else - DrawTextF(xstart3, ystart, font_text, "?.?.?"); -#endif SDL_MIXER_VERSION(&sdl_version_compiled); sdl_version_linked = Mix_Linked_Version(); @@ -2560,10 +2570,19 @@ void DrawInfoScreen_Version() sdl_version_linked->minor, sdl_version_linked->patch); + SDL_NET_VERSION(&sdl_version_compiled); + sdl_version_linked = SDLNet_Linked_Version(); + ystart += ystep; DrawTextF(xstart1, ystart, font_text, "SDL_net"); - DrawTextF(xstart2, ystart, font_text, "?.?.?"); - DrawTextF(xstart3, ystart, font_text, "?.?.?"); + DrawTextF(xstart2, ystart, font_text, "%d.%d.%d", + sdl_version_compiled.major, + sdl_version_compiled.minor, + sdl_version_compiled.patch); + DrawTextF(xstart3, ystart, font_text, "%d.%d.%d", + sdl_version_linked->major, + sdl_version_linked->minor, + sdl_version_linked->patch); #endif DrawTextSCentered(ybottom, FONT_TEXT_4, @@ -2736,6 +2755,7 @@ void HandleInfoScreen(int mx, int my, int dx, int dy, int button) void HandleTypeName(int newxpos, Key key) { + static char last_player_name[MAX_PLAYER_NAME_LEN + 1]; struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME); #if 1 struct MenuPosInfo *pos = mci->pos_input; @@ -2760,35 +2780,42 @@ void HandleTypeName(int newxpos, Key key) int startx = mSX + 32 + name_width; int starty = mSY + ypos * 32; #endif + char key_char = getValidConfigValueChar(getCharFromKey(key)); + boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0)); + boolean is_active = TRUE; + + DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr); if (newxpos) { + strcpy(last_player_name, setup.player_name); + xpos = newxpos; +#if 0 + /* add one character width for added cursor character */ + pos->width += font_width; + startx = mSX + ALIGNED_MENU_XPOS(pos); + DrawText(startx, starty, setup.player_name, font_active_nr); DrawText(startx + xpos * font_width, starty, "_", font_active_nr); - - return; +#endif } - - if (((key >= KSYM_A && key <= KSYM_Z) || - (key >= KSYM_a && key <= KSYM_z)) && - xpos < MAX_PLAYER_NAME_LEN) + else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN) { - char ascii; - - if (key >= KSYM_A && key <= KSYM_Z) - ascii = 'A' + (char)(key - KSYM_A); - else - ascii = 'a' + (char)(key - KSYM_a); - - setup.player_name[xpos] = ascii; + setup.player_name[xpos] = key_char; setup.player_name[xpos + 1] = 0; xpos++; +#if 0 + /* add one character width for added name text character */ + pos->width += font_width; + startx = mSX + ALIGNED_MENU_XPOS(pos); + DrawText(startx, starty, setup.player_name, font_active_nr); DrawText(startx + xpos * font_width, starty, "_", font_active_nr); +#endif } else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0) { @@ -2796,17 +2823,56 @@ void HandleTypeName(int newxpos, Key key) setup.player_name[xpos] = 0; +#if 0 + /* remove one character width for removed name text character */ + pos->width -= font_width; + startx = mSX + ALIGNED_MENU_XPOS(pos); + + DrawText(startx, starty, setup.player_name, font_active_nr); DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr); +#endif } else if (key == KSYM_Return && xpos > 0) { +#if 0 + /* remove one character width for removed cursor text character */ + pos->width -= font_width; + startx = mSX + ALIGNED_MENU_XPOS(pos); + DrawText(startx, starty, setup.player_name, font_nr); DrawText(startx + xpos * font_width, starty, " ", font_active_nr); +#endif SaveSetup(); + is_active = FALSE; + game_status = GAME_MODE_MAIN; } + else if (key == KSYM_Escape) + { + strcpy(setup.player_name, last_player_name); + + is_active = FALSE; + + game_status = GAME_MODE_MAIN; + } + + if (is_active) + { + pos->width = (strlen(setup.player_name) + 1) * font_width; + startx = mSX + ALIGNED_MENU_XPOS(pos); + + DrawText(startx, starty, setup.player_name, font_active_nr); + DrawText(startx + xpos * font_width, starty, "_", font_active_nr); + } + else + { + pos->width = strlen(setup.player_name) * font_width; + startx = mSX + ALIGNED_MENU_XPOS(pos); + + DrawText(startx, starty, setup.player_name, font_nr); + } } diff --git a/src/tools.c b/src/tools.c index d6881982..ca1970ca 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1778,7 +1778,7 @@ static void DrawPreviewLevelExt(int from_x, int from_y) #define MICROLABEL_IMPORTED_BY_HEAD 6 #define MICROLABEL_IMPORTED_BY 7 -static int getMaxTextLength(struct MenuPosInfo *pos, int font_nr) +static int getMaxTextLength(struct TextPosInfo *pos, int font_nr) { int max_text_width = SXSIZE; int font_width = getFontWidth(font_nr); @@ -1795,7 +1795,7 @@ static int getMaxTextLength(struct MenuPosInfo *pos, int font_nr) static void DrawPreviewLevelLabelExt(int mode) { - struct MenuPosInfo *pos = &menu.main.text.level_info_2; + struct TextPosInfo *pos = &menu.main.text.level_info_2; char label_text[MAX_OUTPUT_LINESIZE + 1]; int max_len_label_text; int font_nr = FONT_TEXT_2; @@ -1812,6 +1812,11 @@ static void DrawPreviewLevelLabelExt(int mode) max_len_label_text = SXSIZE / getFontWidth(font_nr); #endif +#if 1 + if (pos->chars != -1) + max_len_label_text = pos->chars; +#endif + for (i = 0; i < max_len_label_text; i++) label_text[i] = ' '; label_text[max_len_label_text] = '\0'; @@ -1898,7 +1903,7 @@ void DrawPreviewLevel(boolean restart) if (leveldir_current->name) { - struct MenuPosInfo *pos = &menu.main.text.level_info_1; + struct TextPosInfo *pos = &menu.main.text.level_info_1; char label_text[MAX_OUTPUT_LINESIZE + 1]; int font_nr = FONT_TEXT_1; #if 1 @@ -1911,6 +1916,11 @@ void DrawPreviewLevel(boolean restart) int lxpos, lypos; #endif +#if 1 + if (pos->chars != -1) + max_len_label_text = pos->chars; +#endif + strncpy(label_text, leveldir_current->name, max_len_label_text); label_text[max_len_label_text] = '\0'; -- 2.34.1