Skip to content

Commit

Permalink
if announce string is too long, draw author on next line (#2195)
Browse files Browse the repository at this point in the history
* if announce string is too long, draw author on next line

* fix redeclaration
  • Loading branch information
rfomin authored Feb 11, 2025
1 parent 2bf2639 commit 4faa283
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/mn_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ void MN_BackSecondary(void);
// [FG] alternative text for missing menu graphics lumps
void MN_DrawTitle(int x, int y, const char *patch, const char *alttext);
void MN_DrawStringCR(int cx, int cy, byte *cr1, byte *cr2, const char *ch);
int MN_StringWidth(const char *string);
int MN_StringHeight(const char *string);

void MN_General(int choice);
Expand Down
1 change: 1 addition & 0 deletions src/mn_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void MN_InitMenuStrings(void);

boolean MN_StartsWithMapIdentifier(char *str);

int MN_StringWidth(const char *string);
int MN_GetPixelWidth(const char *ch);
void MN_DrawString(int cx, int cy, int color, const char *ch);

Expand Down
17 changes: 15 additions & 2 deletions src/st_widgets.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "m_config.h"
#include "m_input.h"
#include "m_misc.h"
#include "mn_menu.h"
#include "p_mobj.h"
#include "p_spec.h"
#include "r_main.h"
Expand Down Expand Up @@ -132,7 +133,7 @@ static void UpdateMessage(sbe_widget_t *widget, player_t *player)
}
}

static char announce_string[HU_MAXLINELENGTH];
static char announce_string[HU_MAXLINELENGTH], author_string[HU_MAXLINELENGTH];

static void UpdateAnnounceMessage(sbe_widget_t *widget, player_t *player)
{
Expand Down Expand Up @@ -162,6 +163,7 @@ static void UpdateAnnounceMessage(sbe_widget_t *widget, player_t *player)
}
else if (player->secretmessage)
{
author_string[0] = '\0';
state = announce_secret;
widget->duration_left = widget->duration;
M_snprintf(string, sizeof(string), GOLD_S "%s" ORIG_S,
Expand All @@ -172,6 +174,10 @@ static void UpdateAnnounceMessage(sbe_widget_t *widget, player_t *player)
if (widget->duration_left > 0)
{
ST_AddLine(widget, string);
if (author_string[0])
{
ST_AddLine(widget, author_string);
}
--widget->duration_left;
}
else
Expand Down Expand Up @@ -645,16 +651,23 @@ void ST_ResetTitle(void)
'0' + hudcolor_titl, string);

announce_string[0] = '\0';
author_string[0] = '\0';
if (hud_map_announce && leveltime == 0)
{
if (gamemapinfo && gamemapinfo->author)
{
M_snprintf(announce_string, sizeof(announce_string), "%s by %s",
string, gamemapinfo->author);
if (MN_StringWidth(announce_string) > SCREENWIDTH)
{
M_StringCopy(announce_string, string, sizeof(announce_string));
M_snprintf(author_string, sizeof(author_string), "by %s",
gamemapinfo->author);
}
}
else
{
M_snprintf(announce_string, sizeof(announce_string), "%s", string);
M_StringCopy(announce_string, string, sizeof(announce_string));
}
}
}
Expand Down

0 comments on commit 4faa283

Please sign in to comment.