Qt paperdoll bit

For the tool tips shown if you let the mouse pointer hover over
any of the cells in the paperdoll (inventory subset showing
worn and wielded items), remove the trailing period and add a
leading space and a trailing space.  Improves readability.
This commit is contained in:
PatR
2020-11-22 02:36:10 -08:00
parent 6d4fd933b2
commit 3339d0247f

View File

@@ -46,6 +46,7 @@ NetHackQtInvUsageWindow::NetHackQtInvUsageWindow(QWidget* parent) :
// needed to enable tool tips
setMouseTracking(true);
// paperdoll is 6x3 but the indices are column oriented: 0..2x0..5
for (int x = 0; x <= 2; ++x)
for (int y = 0; y <= 5; ++y)
tips[x][y] = NULL;
@@ -65,7 +66,9 @@ void NetHackQtInvUsageWindow::drawWorn(QPainter &painter, obj *nhobj,
{
short int glyph;
int border;
bool rev = false;
char tipstr[1 + BUFSZ + 1]; // extra room for leading and trailing space
bool rev = (flags == dollReverse),
canbe = (flags != dollUnused);
if (nhobj) {
border = BORDER_DEFAULT;
@@ -79,35 +82,41 @@ void NetHackQtInvUsageWindow::drawWorn(QPainter &painter, obj *nhobj,
: BORDER_BLESSED;
// set up a tool tip describing the item that will be displayed here
char *itmnam = xprname(nhobj, (char *) 0, nhobj->invlet, TRUE, 0L, 0L);
if (tips[x][y] && strlen(itmnam) > strlen(tips[x][y]))
Sprintf(tipstr, " %s ", // extra spaces for enhanced readability
// xprname: invlet, space, dash, space, object description
xprname(nhobj, (char *) NULL, nhobj->invlet, FALSE, 0L, 0L));
// tips are managed with nethack's alloc(); we don't track allocation
// amount; allocated buffers get reused when big enough (usual case
// since paperdoll updates occur more often than equipment changes)
if (tips[x][y] && strlen(tipstr) > strlen(tips[x][y]))
free((void *) tips[x][y]), tips[x][y] = NULL;
if (tips[x][y])
Strcpy(tips[x][y], itmnam);
Strcpy(tips[x][y], tipstr); // guaranteed to fit
else
tips[x][y] = dupstr(itmnam);
rev = (flags == dollReverse);
tips[x][y] = dupstr(tipstr);
#endif
glyph = obj_to_glyph(nhobj, rn2_on_display_rng);
} else {
border = NO_BORDER;
#ifdef ENHANCED_PAPERDOLL
// caller passes an alternative tool tip for empty cells
if (tips[x][y] && (!alttip || strlen(alttip) > strlen(tips[x][y])))
// caller usually passes an alternate tool tip for empty cells
size_t altlen = alttip ? 1U + strlen(alttip) + 1U : 0U;
if (tips[x][y] && (!alttip || altlen > strlen(tips[x][y])))
free((void *) tips[x][y]), tips[x][y] = NULL;
if (tips[x][y]) // above guarantees that test fails if alttip is Null
Strcpy(tips[x][y], alttip);
else if (alttip)
tips[x][y] = dupstr(alttip);
if (alttip) {
Sprintf(tipstr, " %s ", alttip);
if (tips[x][y])
Strcpy(tips[x][y], tipstr); // guaranteed to fit
else
tips[x][y] = dupstr(tipstr);
}
#else
nhUse(alttip);
#endif
// an empty slot is shown as floor tile unless it's always empty
glyph = (flags != dollUnused) ? cmap_to_glyph(S_room)
: GLYPH_UNEXPLORED;
glyph = canbe ? cmap_to_glyph(S_room) : GLYPH_UNEXPLORED;
}
qt_settings->glyphs().drawBorderedCell(painter, glyph, x, y, border, rev);
}