From: PatR Date: Mon, 17 Aug 2020 22:41:33 +0000 (-0700) Subject: Qt: paper doll display of BUC status X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=26060634f60f126405b1e4789606dd4b85be35bc;p=nethack Qt: paper doll display of BUC status When items in the paper doll inventory subset (primary worn and wielded items) have known BUC state, indicate what that is. It now draws a one pixel wide white border around each doll tile, and if BUC is known, that border gets its color changed (red for known cursed, yellow for known uncursed, cyan for known blessed). That isn't very visual so the first pixel inside the tile is overwritten with the same color, and alternating pixels are also overwritten for the second rectangle within. The 2..3 pixel wide border is visible without cluttering the tile for 'normal' sized paper doll. The tiles are allowed to be scrunched down to as small as 6x6 so there won't be much left after 1 or 2 around the edge are replaced. Initially I was going to try to highlight welded items but the more general BUC highlighting is simpler and usually more useful to the player. The qt_map.* bits are just reformatting. I was looking at pet and pile annotations as a way to do BUC annotations but decided not to attempt that. --- diff --git a/doc/fixes37.0 b/doc/fixes37.0 index 76f29dfe1..e465340d5 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -1,4 +1,4 @@ -NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.286 $ $NHDT-Date: 1597700875 2020/08/17 21:47:55 $ +NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.287 $ $NHDT-Date: 1597704087 2020/08/17 22:41:27 $ General Fixes and Modified Features ----------------------------------- @@ -510,6 +510,8 @@ user_sounds: provide an experimental mechanism for terminal-side sounds similar act on it) Qt: the "paper doll" inventory subset can be controlled via the "Qt Settings" dialog box ("Preferences..." on OSX) +Qt: draw a border around each tile in the paper door inventory; when BUC is + known for a doll item, change the border's color and thicken it NetHack Community Patches (or Variation) Included diff --git a/win/Qt/qt_glyph.cpp b/win/Qt/qt_glyph.cpp index 7ca292c87..5554a7b3f 100644 --- a/win/Qt/qt_glyph.cpp +++ b/win/Qt/qt_glyph.cpp @@ -18,6 +18,8 @@ extern "C" { #include "qt_glyph.h" #include "qt_bind.h" #include "qt_set.h" +#include "qt_inv.h" +#include "qt_map.h" #include "qt_str.h" extern short glyph2tile[]; // from tile.c @@ -91,6 +93,64 @@ void NetHackQtGlyphs::drawCell(QPainter& painter, int glyph, drawGlyph(painter, glyph, cellx * width(), celly * height()); } +void NetHackQtGlyphs::drawBorderedCell(QPainter& painter, int glyph, + int cellx, int celly, int border) +{ + int wd = width(), + ht = height(), + lox = cellx * (wd + 2), + loy = celly * (ht + 2); + + drawGlyph(painter, glyph, lox + 1, loy + 1); + +#ifdef TEXTCOLOR + if (border != NO_BORDER) { + // gray would be a better mid-point between red and cyan but it + // doesn't show up well enough against the wall tile background + painter.setPen((border == BORDER_CURSED) ? Qt::red + : (border == BORDER_UNCURSED) ? Qt::yellow + : (border == BORDER_BLESSED) ? Qt::cyan + : Qt::white); // BORDER_DEFAULT + // assuming 32x32, draw 34x34 rectangle from 0..33x0..33, outside glyph +#if 0 /* Qt 5.11 drawRect(x,y,width,height) seems to have an off by 1 bug; + * drawRect(0,0,34,34) is drawing at 0..34x0..34 which is 35x35; + * should subtract 1 when adding width and/or height to base coord; + * the relevant code in QtCore/QRect.h is correct so this observable + * misbehavior is a mystery... */ + painter.drawRect(lox, loy, wd + 2, ht + 2); +#else + painter.drawLine(lox, loy, lox + wd + 1, loy); // 0,0->33,0 + painter.drawLine(lox, loy + ht + 1, lox + wd + 1, loy + ht + 1); + painter.drawLine(lox, loy, lox, loy + ht + 1); // 0,0->0,33 + painter.drawLine(lox + wd + 1, loy, lox + wd + 1, loy + ht + 1); +#endif + if (border != BORDER_DEFAULT) { + // assuming 32x32, draw rectangle from 1..32x1..32, inside glyph +#if 0 /* (see above) */ + painter.drawRect(lox + 1, loy + 1, wd, ht); +#else + painter.drawLine(lox + 1, loy + 1, lox + wd, loy + 1); // 1,1->32,1 + painter.drawLine(lox + 1, loy + ht, lox + wd, loy + ht); + painter.drawLine(lox + 1, loy + 1, lox + 1, loy + ht); // 1,1->1,32 + painter.drawLine(lox + wd, loy + 1, lox + wd, loy + ht); +#endif + for (int i = lox + 2; i < lox + wd - 1; i += 2) { + // assuming 32x32, draw points along <2..31,2> and <2..31,31> + painter.drawPoint(i, loy + 2); + painter.drawPoint(i + 1, loy + ht - 1); + } + for (int j = loy + 2; j < loy + ht - 1; j += 2) { + // assuming 32x32, draw points along <2,2..31> and <31,2..31> + painter.drawPoint(lox + 2, j); + painter.drawPoint(lox + wd - 1, j + 1); + } + } + } +#else + nhUse(border); +#endif +} + QPixmap NetHackQtGlyphs::glyph(int glyph) { int tile = glyph2tile[glyph]; diff --git a/win/Qt/qt_glyph.h b/win/Qt/qt_glyph.h index b85c4f4d3..719e5cf17 100644 --- a/win/Qt/qt_glyph.h +++ b/win/Qt/qt_glyph.h @@ -9,6 +9,11 @@ namespace nethack_qt_ { +enum border_code { + NO_BORDER, BORDER_DEFAULT, + BORDER_CURSED, BORDER_UNCURSED, BORDER_BLESSED +}; + class NetHackQtGlyphs { public: NetHackQtGlyphs(); @@ -20,6 +25,8 @@ public: void drawGlyph(QPainter&, int glyph, int pixelx, int pixely); void drawCell(QPainter&, int glyph, int cellx, int celly); + void drawBorderedCell(QPainter&, int glyph, + int cellx, int celly, int bordercode); QPixmap glyph(int glyph); private: diff --git a/win/Qt/qt_inv.cpp b/win/Qt/qt_inv.cpp index f34d0e48a..1cab0ab11 100644 --- a/win/Qt/qt_inv.cpp +++ b/win/Qt/qt_inv.cpp @@ -48,13 +48,22 @@ void NetHackQtInvUsageWindow::drawWorn(QPainter& painter, obj* nhobj, int x, int y, bool canbe) { short int glyph; + int border; + if (nhobj) { - /* Hallucination doesn't affect inventory */ + border = BORDER_DEFAULT; + if (Role_if('P') && !Blind) + nhobj->bknown = 1; + if (nhobj->bknown) + border = nhobj->cursed ? BORDER_CURSED + : !nhobj->blessed ? BORDER_UNCURSED + : BORDER_BLESSED; glyph = obj_to_glyph(nhobj, rn2_on_display_rng); } else { + border = NO_BORDER; glyph = canbe ? cmap_to_glyph(S_room) : GLYPH_UNEXPLORED; } - qt_settings->glyphs().drawCell(painter, glyph, x, y); + qt_settings->glyphs().drawBorderedCell(painter, glyph, x, y, border); } void NetHackQtInvUsageWindow::paintEvent(QPaintEvent*) @@ -132,14 +141,16 @@ QSize NetHackQtInvUsageWindow::sizeHint(void) const { if (qt_settings) { int w = 0, h = 0; + // 1+X+1: one pixel border surrounding each tile in the paper doll, + // so +1 left and +1 right, also +1 above and +1 below #ifdef ENHANCED_PAPERDOLL if (qt_settings->doll_is_shown) { - w = qt_settings->dollWidth * 3; - h = qt_settings->dollHeight * 6; + w = (1 + qt_settings->dollWidth + 1) * 3; + h = (1 + qt_settings->dollHeight + 1) * 6; } #else - w = qt_settings->glyphs().width() * 3; - h = qt_settings->glyphs().height() * 6; + w = (1 + qt_settings->glyphs().width() + 1) * 3; + h = (1 + qt_settings->glyphs().height() + 1) * 6; #endif return QSize(w, h); } else { diff --git a/win/Qt/qt_map.cpp b/win/Qt/qt_map.cpp index 51fafda2d..eb497da86 100644 --- a/win/Qt/qt_map.cpp +++ b/win/Qt/qt_map.cpp @@ -63,7 +63,8 @@ NetHackQtMapViewport::NetHackQtMapViewport(NetHackQtClickBuffer& click_sink) : clicksink(click_sink), change(10) { - pet_annotation = QPixmap(qt_compact_mode ? pet_mark_small_xpm : pet_mark_xpm); + pet_annotation = QPixmap(qt_compact_mode ? pet_mark_small_xpm + : pet_mark_xpm); pile_annotation = QPixmap(pile_mark_xpm); Clear(); @@ -153,9 +154,13 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event) } #ifdef TEXTCOLOR if (((special & MG_PET) != 0) && ::iflags.hilite_pet) { - painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), j*qt_settings->glyphs().height()), pet_annotation); + painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), + j*qt_settings->glyphs().height()), + pet_annotation); } else if (((special & MG_OBJPILE) != 0) && ::iflags.hilite_pile) { - painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), j*qt_settings->glyphs().height()), pile_annotation); + painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), + j*qt_settings->glyphs().height()), + pile_annotation); } #endif } @@ -173,9 +178,13 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event) qt_settings->glyphs().drawCell(painter, g, i, j); #ifdef TEXTCOLOR if (((special & MG_PET) != 0) && ::iflags.hilite_pet) { - painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), j*qt_settings->glyphs().height()), pet_annotation); + painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), + j*qt_settings->glyphs().height()), + pet_annotation); } else if (((special & MG_OBJPILE) != 0) && ::iflags.hilite_pile) { - painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), j*qt_settings->glyphs().height()), pile_annotation); + painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), + j*qt_settings->glyphs().height()), + pile_annotation); } #endif } @@ -646,7 +655,8 @@ NetHackQtMapWindow::NetHackQtMapWindow(NetHackQtClickBuffer& click_sink) : palette.setColor(viewport.backgroundRole(), Qt::black); viewport.setPalette(palette); - pet_annotation = QPixmap(qt_compact_mode ? pet_mark_small_xpm : pet_mark_xpm); + pet_annotation = QPixmap(qt_compact_mode ? pet_mark_small_xpm + : pet_mark_xpm); pile_annotation = QPixmap(pile_mark_xpm); cursor.setX(0); @@ -836,9 +846,13 @@ void NetHackQtMapWindow::paintEvent(QPaintEvent* event) ); #ifdef TEXTCOLOR if (((special & MG_PET) != 0) && ::iflags.hilite_pet) { - painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), j*qt_settings->glyphs().height()), pet_annotation); + painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), + j*qt_settings->glyphs().height()), + pet_annotation); } else if (((special & MG_OBJPILE) != 0) && ::iflags.hilite_pile) { - painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), j*qt_settings->glyphs().height()), pile_annotation); + painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), + j*qt_settings->glyphs().height()), + pile_annotation); } #endif } @@ -856,9 +870,13 @@ void NetHackQtMapWindow::paintEvent(QPaintEvent* event) qt_settings->glyphs().drawCell(painter, g, i, j); #ifdef TEXTCOLOR if (((special & MG_PET) != 0) && ::iflags.hilite_pet) { - painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), j*qt_settings->glyphs().height()), pet_annotation); + painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), + j*qt_settings->glyphs().height()), + pet_annotation); } else if (((special & MG_OBJPILE) != 0) && ::iflags.hilite_pile) { - painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), j*qt_settings->glyphs().height()), pile_annotation); + painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), + j*qt_settings->glyphs().height()), + pile_annotation); } #endif } diff --git a/win/Qt/qt_map.h b/win/Qt/qt_map.h index 8849a18da..bf8afceb4 100644 --- a/win/Qt/qt_map.h +++ b/win/Qt/qt_map.h @@ -22,7 +22,8 @@ public: protected: virtual void paintEvent(QPaintEvent* event); - bool DrawWalls(QPainter& painter, int x, int y, int w, int h, unsigned ch); + bool DrawWalls(QPainter& painter, int x, int y, + int w, int h, unsigned ch); virtual QSize sizeHint() const; virtual QSize minimumSizeHint() const; virtual void mousePressEvent(QMouseEvent* event);