Files
nethack/win/Qt/qt_glyph.cpp
nhmall 0c3b9642e4 pmnames mons gender naming plus a window port interface change
add MALE, FEMALE, and gender-neutral names for individual monster species
to the mons array. The gender-neutral name (NEUTRAL) is mandatory, the
MALE and FEMALE versions are not.

replace code uses of the mname field of permonst with one of the three
potentially-available gender-specific names.

consolidate some separate mons entries that differed only by species into a
single mons entry (caveman, cavewoman and priest,priestess etc.)

consolidate several "* lord" and "* queen/* king" monst entries into
their single species, and allow both genders on some where it makes some
sense (there is probably more work and cleanup to come out of this at some
point, and the chosen gender-neutral name variations are not cast in stone
if someone has better suggestions).

related function or macro additions:
    pmname(pm, gender) to get the gender variation of the permonst name. It
    guards against monsters that haven't got anything except NEUTRAL naming
    and falls back to the NEUTRAL version if FEMALE and MALE versions are
    missing.

    Ugender to obtain the current hero gender.
    Mgender(mtmp) to obtain the gender of a monster

While the code can safely refer directly to pmnames[NEUTRAL] safely in the
code because it always exists, the other two (pmnames[MALE] and
pmnames[FEMALE] may not exist so use:
    pmname(ptr, gidx)
      where -ptr is a permonst *
            -gidx is an index into the pmnames array field of the
             permonst struct
pmname() checks for a valid index and checks for null-pointers for
pmnames[MALE] and pmnames[FEMALE], and will fall back to pmnames[NEUTRAL] if
the pointer requested if the requested variation is unavailable, or if the
gidx is out-of-range.

Allow code to specify makemon flags to request female or male (via MM_MALE
and MM_FEMALE flags respectively)to makedefs, since the species alone doesn't
distinguish male/female anymore. Specifying MM_MALE or MM_FEMALE won't
override the pm M2_MALE and M2_FEMALE flags on a mons[] entry.

male and female tiles have been added to win/share/monsters.txt.
The majority are duplicated placeholders except for those that were
separate mons entries before. Perhaps someone will contribute artwork in the
future to make the male and female variations visually distinguishable.

tilemapping via has the MALE tile indexes in the glyph2tile[]
array produced at build time. If a window port has information that the
FEMALE tile is required, it just has to increment the index returned
from the glyph2tile[] array by 1.

statues already preserved gender of the monster through STATUE_FEMALE
and STATUE_MALE, so ensure that pmnames takes that into consideration.

I expect some refinement will be required after broad play-testing puts it to
the test.

    consolidate caveman,cavewoman and priest,priestess monst.c entries etc

This commit will require a bump of editlevel in patchlevel.h because it alters
the index numbers of the monsters due to the consolidation of some. Those
index numbers are saved in some other structures, even though the mons[] array
itself is not part of the savefile.

Window Port Interface Change

Also add a parameter to print_glyph to convey additional information beyond
the glyph to the window ports. Every single window port was calling back to
mapglyph for the information anyway, so just included it in the interface and
produce the information right in the display core.

The mapglyph() function uses will be eliminated, although there are still some
in the code yet to be dealt with.

win32, tty, x11, Qt, msdos window ports have all had adjustments done to
utilize the new parameter instead of calling mapglyph, but some of those
window ports have not been thoroughly tested since the changes.

Interface change additional info:

    print_glyph(window, x, y, glyph, bkglyph, *glyphmod)
            -- Print the glyph at (x,y) on the given window.  Glyphs are
               integers at the interface, mapped to whatever the window-
               port wants (symbol, font, color, attributes, ...there's
               a 1-1 map between glyphs and distinct things on the map).
            -- bkglyph is a background glyph for potential use by some
               graphical or tiled environments to allow the depiction
               to fall against a background consistent with the grid
               around x,y. If bkglyph is NO_GLYPH, then the parameter
               should be ignored (do nothing with it).
                -- glyphmod provides extended information about the glyph
               that window ports can use to enhance the display in
               various ways.
                    unsigned int glyphmod[NUM_GLYPHMOD]
               where:
                    glyphmod[GM_TTYCHAR]  is the text characters associated
                                          with the original NetHack display.

                    glyphmod[GM_FLAGS]    are the special flags that denote
                                          additional information that window
                                          ports can use.

                    glyphmod[GM_COLOR] is the text character
                                       color associated with the original
                                       NetHack display.

Support for including the glyphmod info in the display glyph buffer
alongside the glyph itself was added and is the default operation.
That can be turned off by defining UNBUFFERED_GLYPHMOD at compile time.
With UNBUFFERED_GLYPHMOD operation, a call will be placed to map_glyphmod()
immediately prior to every print_glyph() call.
2020-12-26 11:23:23 -05:00

237 lines
7.4 KiB
C++

// Copyright (c) Warwick Allison, 1999.
// Qt4 conversion copyright (c) Ray Chason, 2012-2014.
// NetHack may be freely redistributed. See license for details.
// qt_glyph.cpp -- class to manage the glyphs in a tile set
extern "C" {
#include "hack.h"
#include "tile2x11.h" /* x11tiles is potential fallback for nhtiles.bmp */
}
#include "qt_pre.h"
#include <QtGui/QtGui>
#if QT_VERSION >= 0x050000
#include <QtWidgets/QtWidgets>
#endif
#include "qt_post.h"
#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
namespace nethack_qt_ {
static int tilefile_tile_W=16;
static int tilefile_tile_H=16;
// Debian uses a separate PIXMAPDIR
#ifndef PIXMAPDIR
# ifdef HACKDIR
# define PIXMAPDIR HACKDIR
# else
# define PIXMAPDIR "."
# endif
#endif
NetHackQtGlyphs::NetHackQtGlyphs()
{
const char* tile_file = PIXMAPDIR "/nhtiles.bmp";
if (iflags.wc_tile_file)
tile_file = iflags.wc_tile_file;
if (!img.load(tile_file)) {
tiles_per_row = TILES_PER_ROW;
tile_file = PIXMAPDIR "/x11tiles";
if (!img.load(tile_file)) {
QString msg;
msg.sprintf("Cannot load 'nhtiles.bmp' or 'x11tiles'.");
QMessageBox::warning(0, "IO Error", msg);
iflags.wc_ascii_map = 1;
iflags.wc_tiled_map = 0;
} else {
if (img.width() % tiles_per_row) {
impossible(
"Tile file \"%s\" has %d columns, not multiple of row count (%d)",
tile_file, img.width(), tiles_per_row);
}
}
} else {
tiles_per_row = 40;
}
if (iflags.wc_tile_width)
tilefile_tile_W = iflags.wc_tile_width;
else if (iflags.wc_ascii_map)
tilefile_tile_W = 16;
else
tilefile_tile_W = img.width() / tiles_per_row;
if (iflags.wc_tile_height)
tilefile_tile_H = iflags.wc_tile_height;
else
tilefile_tile_H = tilefile_tile_W;
setSize(tilefile_tile_W, tilefile_tile_H);
}
void NetHackQtGlyphs::drawGlyph(QPainter& painter, int glyph, int x, int y,
bool fem, bool reversed)
{
if (!reversed) {
int tile = glyph2tile[glyph];
if (fem)
++tile;
int px = (tile % tiles_per_row) * width();
int py = tile / tiles_per_row * height();
painter.drawPixmap(x, y, pm, px, py, width(), height());
} else {
// for paper doll; mirrored image for left side of two-handed weapon
painter.drawPixmap(x, y, reversed_pixmap(glyph, fem),
0, 0, width(), height());
}
}
void NetHackQtGlyphs::drawCell(QPainter& painter, int glyph,
int cellx, int celly, bool fem)
{
drawGlyph(painter, glyph, cellx * width(), celly * height(), fem, false);
}
void NetHackQtGlyphs::drawBorderedCell(QPainter& painter, int glyph,
int cellx, int celly, int border,
bool reversed, bool fem)
{
int wd = width(),
ht = height(),
yoffset = 1, // tiny extra margin at top
lox = cellx * (wd + 2),
loy = celly * (ht + 2) + yoffset;
drawGlyph(painter, glyph, lox + 1, loy + 1, fem, reversed);
#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
}
// mis-named routine to get the pixmap for a particular glyph
QPixmap NetHackQtGlyphs::glyph(int glyphindx, bool fem)
{
int tile = glyph2tile[glyphindx];
if (fem)
++tile;
int px = (tile % tiles_per_row) * tilefile_tile_W;
int py = tile / tiles_per_row * tilefile_tile_H;
return QPixmap::fromImage(img.copy(px, py,
tilefile_tile_W, tilefile_tile_H));
}
// transpose a glyph's tile horizontally, scaled for use in paper doll
QPixmap NetHackQtGlyphs::reversed_pixmap(int glyphindx, bool fem)
{
QPixmap pxmp = glyph(glyphindx, fem);
#ifdef ENHANCED_PAPERDOLL
qreal wid = (qreal) pxmp.width(),
//hgt = (qreal) pxmp.height(),
xscale = (qreal) qt_settings->dollWidth / (qreal) tilefile_tile_W,
yscale = (qreal) qt_settings->dollHeight / (qreal) tilefile_tile_H;
QTransform *mirrormatrix = new QTransform(
// negate x coordinates to flip the image across the y-axis
-1.0 * xscale, 0.0, 0.0, yscale,
// slide flipped image to the right to make things positive again
wid * xscale, 0.0
);
return pxmp.transformed(*mirrormatrix);
#else
return pxmp;
#endif
}
void NetHackQtGlyphs::setSize(int w, int h)
{
if (size == QSize(w, h))
return;
size = QSize(w, h);
if (!w || !h)
return; // Still not decided
if (size == pm1.size()) { // not zoomed
pm = pm1;
return;
}
if (size == pm2.size()) { // zoomed
pm = pm2;
return;
}
bool was1 = (size == pm1.size());
if (w == tilefile_tile_W && h == tilefile_tile_H) {
pm.convertFromImage(img);
} else {
QApplication::setOverrideCursor(Qt::WaitCursor);
QImage scaled = img.scaled(
w * img.width() / tilefile_tile_W,
h * img.height() / tilefile_tile_H,
Qt::IgnoreAspectRatio,
Qt::FastTransformation
);
pm.convertFromImage(scaled, Qt::ThresholdDither | Qt::PreferDither);
QApplication::restoreOverrideCursor();
}
(was1 ? pm2 : pm1) = pm;
}
} // namespace nethack_qt_