From: Holger Schemel Date: Sat, 17 Oct 2020 15:57:44 +0000 (+0200) Subject: improved code to type player name in main menu X-Git-Tag: 4.2.1.0~54 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=02a095de0eb40735cb15b3f043c1639dbd883ce1;p=rocksndiamonds.git improved code to type player name in main menu --- diff --git a/src/events.c b/src/events.c index 2594f131..f2f64593 100644 --- a/src/events.c +++ b/src/events.c @@ -1749,7 +1749,7 @@ void HandleButton(int mx, int my, int button, int button_nr) break; case GAME_MODE_PSEUDO_TYPENAME: - HandleTypeName(0, KSYM_Return); + HandleTypeName(KSYM_Return); break; case GAME_MODE_LEVELS: @@ -2297,7 +2297,7 @@ void HandleKey(Key key, int key_status) switch (game_status) { case GAME_MODE_PSEUDO_TYPENAME: - HandleTypeName(0, key); + HandleTypeName(key); break; case GAME_MODE_TITLE: diff --git a/src/screens.c b/src/screens.c index 4d5c8b18..16a3fc1b 100644 --- a/src/screens.c +++ b/src/screens.c @@ -252,6 +252,7 @@ static void DrawChooseLevelSet(void); static void DrawChooseLevelNr(void); static void DrawInfoScreen(void); static void DrawSetupScreen(void); +static void DrawTypeName(void); static void DrawInfoScreen_NotAvailable(char *, char *); static void DrawInfoScreen_HelpAnim(int, int, boolean); @@ -2080,7 +2081,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) { SetGameStatus(GAME_MODE_PSEUDO_TYPENAME); - HandleTypeName(strlen(setup.player_name), 0); + DrawTypeName(); } } else if (pos == MAIN_CONTROL_LEVELS) @@ -3960,7 +3961,7 @@ void HandleInfoScreen(int mx, int my, int dx, int dy, int button) // type name functions // ============================================================================ -void HandleTypeName(int newxpos, Key key) +static void HandleTypeNameExt(boolean initialize, Key key) { static char last_player_name[MAX_PLAYER_NAME_LEN + 1]; struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME); @@ -3977,11 +3978,11 @@ void HandleTypeName(int newxpos, Key key) DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr); - if (newxpos) + if (initialize) { strcpy(last_player_name, setup.player_name); - xpos = newxpos; + xpos = strlen(setup.player_name); StartTextInput(startx, starty, pos->width, pos->height); } @@ -4034,6 +4035,16 @@ void HandleTypeName(int newxpos, Key key) } } +static void DrawTypeName(void) +{ + HandleTypeNameExt(TRUE, 0); +} + +void HandleTypeName(Key key) +{ + HandleTypeNameExt(FALSE, key); +} + // ============================================================================ // tree menu functions diff --git a/src/screens.h b/src/screens.h index f49fd244..3cb08c1e 100644 --- a/src/screens.h +++ b/src/screens.h @@ -35,7 +35,7 @@ void HandleChooseLevelNr(int, int, int, int, int); void HandleHallOfFame(int, int, int, int, int); void HandleInfoScreen(int, int, int, int, int); void HandleSetupScreen(int, int, int, int, int); -void HandleTypeName(int, Key); +void HandleTypeName(Key); void HandleGameActions(void); void CreateScreenGadgets(void);