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 // needed to enable tool tips
setMouseTracking(true); setMouseTracking(true);
// paperdoll is 6x3 but the indices are column oriented: 0..2x0..5
for (int x = 0; x <= 2; ++x) for (int x = 0; x <= 2; ++x)
for (int y = 0; y <= 5; ++y) for (int y = 0; y <= 5; ++y)
tips[x][y] = NULL; tips[x][y] = NULL;
@@ -65,7 +66,9 @@ void NetHackQtInvUsageWindow::drawWorn(QPainter &painter, obj *nhobj,
{ {
short int glyph; short int glyph;
int border; 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) { if (nhobj) {
border = BORDER_DEFAULT; border = BORDER_DEFAULT;
@@ -79,35 +82,41 @@ void NetHackQtInvUsageWindow::drawWorn(QPainter &painter, obj *nhobj,
: BORDER_BLESSED; : BORDER_BLESSED;
// set up a tool tip describing the item that will be displayed here // set up a tool tip describing the item that will be displayed here
char *itmnam = xprname(nhobj, (char *) 0, nhobj->invlet, TRUE, 0L, 0L); Sprintf(tipstr, " %s ", // extra spaces for enhanced readability
if (tips[x][y] && strlen(itmnam) > strlen(tips[x][y])) // 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; free((void *) tips[x][y]), tips[x][y] = NULL;
if (tips[x][y]) if (tips[x][y])
Strcpy(tips[x][y], itmnam); Strcpy(tips[x][y], tipstr); // guaranteed to fit
else else
tips[x][y] = dupstr(itmnam); tips[x][y] = dupstr(tipstr);
rev = (flags == dollReverse);
#endif #endif
glyph = obj_to_glyph(nhobj, rn2_on_display_rng); glyph = obj_to_glyph(nhobj, rn2_on_display_rng);
} else { } else {
border = NO_BORDER; border = NO_BORDER;
#ifdef ENHANCED_PAPERDOLL #ifdef ENHANCED_PAPERDOLL
// caller passes an alternative tool tip for empty cells // caller usually passes an alternate tool tip for empty cells
if (tips[x][y] && (!alttip || strlen(alttip) > strlen(tips[x][y]))) 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; free((void *) tips[x][y]), tips[x][y] = NULL;
if (tips[x][y]) // above guarantees that test fails if alttip is Null if (alttip) {
Strcpy(tips[x][y], alttip); Sprintf(tipstr, " %s ", alttip);
else if (alttip) if (tips[x][y])
tips[x][y] = dupstr(alttip); Strcpy(tips[x][y], tipstr); // guaranteed to fit
else
tips[x][y] = dupstr(tipstr);
}
#else #else
nhUse(alttip); nhUse(alttip);
#endif #endif
// an empty slot is shown as floor tile unless it's always empty // an empty slot is shown as floor tile unless it's always empty
glyph = (flags != dollUnused) ? cmap_to_glyph(S_room) glyph = canbe ? cmap_to_glyph(S_room) : GLYPH_UNEXPLORED;
: GLYPH_UNEXPLORED;
} }
qt_settings->glyphs().drawBorderedCell(painter, glyph, x, y, border, rev); qt_settings->glyphs().drawBorderedCell(painter, glyph, x, y, border, rev);
} }