Qt "Paper Doll" inventory

Enhance the "Qt Settings" dialog box to provide control over the
paper doll subset of inventory displayed between the message and
status windows (above the map).  A ton of flailing about for a
fairly small but useful change in functionality.

Old dialog (no title):
| [ ] Zoomed            -- check box
| "Width:"  [      ]    -- number entry spinner
| "Height:" [      ]    -- ditto
| "Font:"   [      ]    -- Huge:18pt, Large:14, Medium:12, Small:10, Tiny:8
| [      Dismiss      ] -- button

New dialog:
|     "Qt NetHack Settings"
|
| "Map:"    [ ] "Zoomed"        -- check box
|           "Tile Width"   [  ] -- number entry spinner
|           "Tile Height"  [  ] -- ditto
| "Invent:" [ ] "Shown"         -- check box
|           "Doll Width"   [  ] -- number entry spinner
|           "Doll Height"  [  ] -- ditto
| "Font:"   [      ]    -- Huge:18pt, Large:14, Medium:12, Small:10, Tiny:8
| [          Dismiss          ] -- button

The inventory subset can now be suppressed.  When shown (the default),
its size can be set independently of the map tiles' size.  I've set
the default to be 32x32 tiles instead of 16x16 used for the map.

The settings are saved and restored automatically by Qt, and persist
not just across save/restore cycles but into new games.  (That's not
a change, just a reminder.)
This commit is contained in:
PatR
2020-08-15 19:48:33 -07:00
parent 89fbe2162e
commit 9a866d3601
8 changed files with 299 additions and 57 deletions

View File

@@ -1,4 +1,4 @@
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.284 $ $NHDT-Date: 1597357458 2020/08/13 22:24:18 $
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.285 $ $NHDT-Date: 1597546107 2020/08/16 02:48:27 $
General Fixes and Modified Features
-----------------------------------
@@ -507,6 +507,8 @@ user_sounds: provide an experimental mechanism for terminal-side sounds similar
requires compile-time definition of TTY_SOUND_ESCCODES (also requires
terminal-side code external to NetHack to recognize the sequence and
act on it)
Qt: the "paper doll" inventory subset can be controlled via the "Qt Settings"
dialog box ("Preferences..." on OSX)
NetHack Community Patches (or Variation) Included

View File

@@ -110,9 +110,27 @@ NetHackQtBind::NetHackQtBind(int& argc, char** argv) :
} else {
splash = 0;
}
// these used to be in MainWindow but we want them before QtSettings
// which we want before MainWindow...
QCoreApplication::setOrganizationName("The NetHack DevTeam");
QCoreApplication::setOrganizationDomain("nethack.org");
QCoreApplication::setApplicationName("NetHack-Qt"); // Qt NetHack
{
char cvers[BUFSZ];
QString qvers = version_string(cvers);
QCoreApplication::setApplicationVersion(qvers);
}
#ifdef MACOSX
/* without this, neither control+x nor option+x do anything;
with it, control+x is ^X and option+x still does nothing */
QCoreApplication::setAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
#endif
qt_settings = new NetHackQtSettings(); /*(main->width(),main->height());*/
main = new NetHackQtMainWindow(keybuffer);
connect(qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit()));
qt_settings=new NetHackQtSettings(main->width(),main->height());
msgs_strings = new QStringList();
msgs_initd = false;
msgs_saved = false;

View File

@@ -63,14 +63,16 @@ public:
static void qt_cliparound(int x, int y);
static void qt_cliparound_window(winid wid, int x, int y);
static void qt_print_glyph(winid wid,XCHAR_P x,XCHAR_P y,int glyph,int bkglyph);
static void qt_print_glyph(winid wid, XCHAR_P x, XCHAR_P y,
int glyph, int bkglyph);
static void qt_raw_print(const char *str);
static void qt_raw_print_bold(const char *str);
static int qt_nhgetch();
static int qt_nh_poskey(int *x, int *y, int *mod);
static void qt_nhbell();
static int qt_doprev_message();
static char qt_yn_function(const char *question, const char *choices, CHAR_P def);
static char qt_yn_function(const char *question,
const char *choices, CHAR_P def);
static void qt_getlin(const char *prompt, char *line);
static int qt_get_ext_cmd();
static void qt_number_pad(int);

View File

@@ -49,13 +49,13 @@ void NetHackQtInvUsageWindow::drawWorn(QPainter& painter, obj* nhobj,
{
short int glyph;
if (nhobj)
glyph=obj_to_glyph(nhobj, rn2_on_display_rng);
glyph = obj_to_glyph(nhobj, rn2_on_display_rng);
else if (canbe)
glyph=cmap_to_glyph(S_room);
glyph = cmap_to_glyph(S_room);
else
glyph=cmap_to_glyph(S_stone);
glyph = GLYPH_UNEXPLORED; // was cmap_to_glyph(S_stone)
qt_settings->glyphs().drawCell(painter,glyph,x,y);
qt_settings->glyphs().drawCell(painter, glyph, x, y);
}
void NetHackQtInvUsageWindow::paintEvent(QPaintEvent*)
@@ -76,6 +76,13 @@ void NetHackQtInvUsageWindow::paintEvent(QPaintEvent*)
// show lit lamp/lantern/candle/candelabrum on lower right side;
// show leash-in-use on lower left side
#ifdef ENHANCED_PAPERDOLL
if (!qt_settings->doll_is_shown)
return;
qt_settings->glyphs().setSize(qt_settings->dollWidth,
qt_settings->dollHeight);
#endif
QPainter painter;
painter.begin(this);
@@ -115,13 +122,27 @@ void NetHackQtInvUsageWindow::paintEvent(QPaintEvent*)
drawWorn(painter, find_tool(OIL_LAMP), 2, 4);
painter.end();
#ifdef ENHANCED_PAPERDOLL
qt_settings->glyphs().setSize(qt_settings->tileWidth,
qt_settings->tileHeight);
#endif
}
QSize NetHackQtInvUsageWindow::sizeHint(void) const
{
if (qt_settings) {
return QSize(qt_settings->glyphs().width()*3,
qt_settings->glyphs().height()*6);
int w = 0, h = 0;
#ifdef ENHANCED_PAPERDOLL
if (qt_settings->doll_is_shown) {
w = qt_settings->dollWidth * 3;
h = qt_settings->dollHeight * 6;
}
#else
w = qt_settings->glyphs().width() * 3;
h = qt_settings->glyphs().height() * 6;
#endif
return QSize(w, h);
} else {
return QWidget::sizeHint();
}

View File

@@ -508,20 +508,6 @@ NetHackQtMainWindow::NetHackQtMainWindow(NetHackQtKeyBuffer& ks) :
addToolBar(toolbar);
menubar = menuBar();
QCoreApplication::setOrganizationName("The NetHack DevTeam");
QCoreApplication::setOrganizationDomain("nethack.org");
QCoreApplication::setApplicationName("NetHack");
{
char cvers[BUFSZ];
QString qvers = version_string(cvers);
QCoreApplication::setApplicationVersion(qvers);
}
#ifdef MACOSX
/* without this, neither control+x nor option+x do anything;
with it, control+x is ^X and option+x still does nothing */
QCoreApplication::setAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
#endif
setWindowTitle("Qt NetHack");
setWindowIcon(QIcon(QPixmap(qt_compact_mode ? nh_icon_small : nh_icon)));
@@ -1051,8 +1037,9 @@ void NetHackQtMainWindow::RemoveWindow(NetHackQtWindow* window)
void NetHackQtMainWindow::updateInventory()
{
if ( invusage )
if (invusage) {
invusage->repaint();
}
}
void NetHackQtMainWindow::fadeHighlighting()
@@ -1084,6 +1071,76 @@ void NetHackQtMainWindow::layout()
toph,c->width(),maph);
}
#endif
if (qt_settings && !qt_compact_mode
&& map && message && status && invusage) {
// For the initial PaperDoll sizing, message window
// and/or status window might still be empty;
// widen them before changing PaperDoll to use saved settings.
QList<int> splittersizes = hsplitter->sizes();
#define MIN_WIN_WIDTH 400
if (splittersizes[0] < MIN_WIN_WIDTH
|| splittersizes[2] < MIN_WIN_WIDTH) {
if (splittersizes[0] < MIN_WIN_WIDTH)
splittersizes[0] = MIN_WIN_WIDTH;
#ifndef ENHANCED_PAPERDOLL
if (splittersizes[1] < 6) // TILEWMIN
splittersizes[1] = 16; // 16x16
#endif
if (splittersizes[2] < MIN_WIN_WIDTH)
splittersizes[2] = MIN_WIN_WIDTH;
hsplitter->setSizes(splittersizes);
}
#ifdef ENHANCED_PAPERDOLL
// call resizePaperDoll() indirectly...
qt_settings->resizeDoll();
#endif
}
}
void NetHackQtMainWindow::resizePaperDoll(bool showdoll)
{
#ifdef ENHANCED_PAPERDOLL
// this is absurd...
NetHackQtInvUsageWindow *w = static_cast <NetHackQtMainWindow *>
(NetHackQtBind::mainWidget())->invusage;
QList<int> hsplittersizes = hsplitter->sizes(),
vsplittersizes = vsplitter->sizes();
w->resize(w->sizeHint());
int oldwidth = hsplittersizes[1],
newwidth = w->width();
if (newwidth != oldwidth) {
if (oldwidth > newwidth)
hsplittersizes[0] += (oldwidth - newwidth);
else
hsplittersizes[2] += (newwidth - oldwidth);
hsplittersizes[1] = newwidth;
hsplitter->setSizes(hsplittersizes);
}
// Height limit is 48 pixels per doll cell;
// values greater than 44 need taller window which pushes the map down.
// FIXME: this doesn't shrink the window back if size is reduced from 45+
int oldheight = vsplittersizes[0],
newheight = w->height();
if (newheight > oldheight && oldheight > 0 && vsplittersizes[1] > 0) {
vsplittersizes[0] = newheight;
vsplitter->setSizes(vsplittersizes);
}
if (showdoll) {
if (w->isHidden())
w->show();
else
w->repaint();
} else {
if (w->isVisible())
w->hide();
}
#else
nhUse(showdoll);
#endif /* ENHANCED_PAPERDOLL */
}
void NetHackQtMainWindow::resizeEvent(QResizeEvent*)

View File

@@ -49,6 +49,9 @@ public:
void fadeHighlighting();
// this is unconditional in case qt_main.h comes before qt_set.h
void resizePaperDoll(bool); // ENHANCED_PAPERDOLL
public slots:
void doMenuItem(QAction *);
void doQtSettings(bool);

View File

@@ -2,7 +2,8 @@
// Qt4 conversion copyright (c) Ray Chason, 2012-2014.
// NetHack may be freely redistributed. See license for details.
// qt_set.cpp -- the Qt settings
// qt_set.cpp -- Qt-specific settings, saved and restored by Qt so
// persist not just across save/restore but into new games.
extern "C" {
#include "hack.h"
@@ -17,8 +18,36 @@ extern "C" {
#include "qt_set.h"
#include "qt_set.moc"
#include "qt_glyph.h"
#include "qt_main.h"
#include "qt_bind.h"
#include "qt_str.h"
// Dialog box accessed via "Qt Settings..." in the games menu (non-OSX)
// or via "Preferences..." in the application menu (OSX):
//--
// "Qt NetHack Settings"
// "Map:" [ ] Zoomed -- check box
// tilewidth -- number entry spinner
// tileheight -- ditto
// "Invent:" [ ] Shown -- check box
// dollwidth -- number entry spinner
// dollheight -- ditto
// "Font:" fontsize -- Huge:18pt, Large:14, Medium:12, Small:10, Tiny:8
// [dismiss] -- button
//--
// Map remembers 2 size pairs, one for Zoomed unchecked, another for checked.
// (Player controls whether the box is checked, using the dialog to manually
// switch back and forth if desired; nothing forces the Zoomed setting to
// specify larger tile size than not-Zoomed.)
// Paper doll inventory subset is shown or suppressed depending on check box.
// (It only remembers one tile size pair and that only matters when shown.
// The size could be different from both map settings but it is highly
// recommended that it match one of those unless Zoomed is never toggled.)
// Font size is used for message window and for text in the status window.
// (TODO: support separate font sizes for the two windows.)
// There's no way to undo or avoid saving any changes which player makes but
// all of the fields can be manually reversed.
/* Used by tile/font-size patch below and in ../../src/files.c */
char *qt_tilewidth=NULL;
char *qt_tileheight=NULL;
@@ -34,13 +63,20 @@ namespace nethack_qt_ {
#define TILEWMIN 6
#define TILEHMIN 6
NetHackQtSettings::NetHackQtSettings(int w UNUSED, int h UNUSED) :
NetHackQtSettings::NetHackQtSettings() :
settings(),
whichsize("&Zoomed", this),
tilewidth(this),
tileheight(this),
widthlbl("&Width:",this),
heightlbl("&Height:",this),
whichsize("&Zoomed",this),
widthlbl("Tile &width:", this),
heightlbl("Tile &height:", this),
#ifdef ENHANCED_PAPERDOLL
dollshown("&Shown", this),
dollwidth(this),
dollheight(this),
dollwidthlbl("&Doll width:", this), // should "Doll tile width"...
dollheightlbl("Doll height:", this), // ...but that's too verbose
#endif
fontsize(this),
normal("times"),
#ifdef WS_WIN
@@ -50,7 +86,6 @@ NetHackQtSettings::NetHackQtSettings(int w UNUSED, int h UNUSED) :
#endif
large("times"),
theglyphs(0)
{
int default_fontsize;
@@ -58,9 +93,19 @@ NetHackQtSettings::NetHackQtSettings(int w UNUSED, int h UNUSED) :
tilewidth.setRange(TILEWMIN, 128);
heightlbl.setBuddy(&tileheight);
tileheight.setRange(TILEHMIN, 128);
tilewidth.setValue(settings.value("tilewidth", 16).toInt());
tileheight.setValue(settings.value("tileheight", 16).toInt());
#ifdef ENHANCED_PAPERDOLL
dollwidthlbl.setBuddy(&dollwidth);
dollwidth.setRange(TILEWMIN, 48);
dollheightlbl.setBuddy(&dollheight);
dollheight.setRange(TILEHMIN, 48);
dollwidth.setValue(settings.value("dollwidth", 32).toInt());
dollheight.setValue(settings.value("dollheight", 32).toInt());
doll_is_shown = settings.value("dollShown", true).toBool();
// needed the very first time
settings.setValue("dollShown", QVariant(doll_is_shown));
#endif
default_fontsize = settings.value("fontsize", 2).toInt();
// Tile/font sizes read from .nethackrc
@@ -86,9 +131,15 @@ NetHackQtSettings::NetHackQtSettings(int w UNUSED, int h UNUSED) :
theglyphs=new NetHackQtGlyphs();
resizeTiles();
connect(&tilewidth,SIGNAL(valueChanged(int)),this,SLOT(resizeTiles()));
connect(&tileheight,SIGNAL(valueChanged(int)),this,SLOT(resizeTiles()));
connect(&whichsize,SIGNAL(toggled(bool)),this,SLOT(setGlyphSize(bool)));
connect(&whichsize, SIGNAL(toggled(bool)), this, SLOT(setGlyphSize(bool)));
connect(&tilewidth, SIGNAL(valueChanged(int)), this, SLOT(resizeTiles()));
connect(&tileheight, SIGNAL(valueChanged(int)), this, SLOT(resizeTiles()));
#ifdef ENHANCED_PAPERDOLL
connect(&dollshown, SIGNAL(toggled(bool)), this, SLOT(setDollShown(bool)));
connect(&dollwidth, SIGNAL(valueChanged(int)), this, SLOT(resizeDoll()));
connect(&dollheight, SIGNAL(valueChanged(int)), this, SLOT(resizeDoll()));
#endif
fontsize.addItem("Huge");
fontsize.addItem("Large");
@@ -96,25 +147,51 @@ NetHackQtSettings::NetHackQtSettings(int w UNUSED, int h UNUSED) :
fontsize.addItem("Small");
fontsize.addItem("Tiny");
fontsize.setCurrentIndex(default_fontsize);
connect(&fontsize,SIGNAL(activated(int)),this,SLOT(changedFont()));
connect(&fontsize, SIGNAL(activated(int)), this, SLOT(changedFont()));
QGridLayout* grid = new QGridLayout(this);
grid->addWidget(&whichsize, 0, 0, 1, 2);
grid->addWidget(&tilewidth, 1, 1); grid->addWidget(&widthlbl, 1, 0);
grid->addWidget(&tileheight, 2, 1); grid->addWidget(&heightlbl, 2, 0);
QLabel* flabel=new QLabel("&Font:",this);
int row = 0; // used like X11-style XtSetArg(), ++argc
QGridLayout *grid = new QGridLayout(this);
// dialog box label, spans first two rows and all three columns
QLabel *settings_label = new QLabel("Qt NetHack Settings\n", this);
grid->addWidget(settings_label, row, 0, 2, 3), row += 2; // uses extra row
settings_label->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
QLabel *map_label = new QLabel("&Map:", this);
map_label->setBuddy(&whichsize);
grid->addWidget(map_label, row, 0), // "Map: [ ]Zoomed"
grid->addWidget(&whichsize, row, 1), ++row;
grid->addWidget(&widthlbl, row, 1),
grid->addWidget(&tilewidth, row, 2), ++row;
grid->addWidget(&heightlbl, row, 1),
grid->addWidget(&tileheight, row, 2), ++row;
#ifdef ENHANCED_PAPERDOLL
dollshown.QAbstractButton::setChecked(doll_is_shown);
QLabel *doll_label = new QLabel("&Invent:", this);
doll_label->setBuddy(&dollshown);
grid->addWidget(doll_label, row, 0), // "Invent: [ ]Shown"
grid->addWidget(&dollshown, row, 1), ++row;
grid->addWidget(&dollwidthlbl, row, 1),
grid->addWidget(&dollwidth, row, 2), ++row;
grid->addWidget(&dollheightlbl, row, 1),
grid->addWidget(&dollheight, row, 2), ++row;
#endif
QLabel *flabel = new QLabel("&Font:", this);
flabel->setBuddy(&fontsize);
grid->addWidget(flabel, 3, 0); grid->addWidget(&fontsize, 3, 1);
QPushButton* dismiss=new QPushButton("Dismiss",this);
grid->addWidget(flabel, row, 0),
grid->addWidget(&fontsize, row, 1), ++row;
QPushButton *dismiss = new QPushButton("Dismiss", this);
dismiss->setDefault(true);
grid->addWidget(dismiss, 4, 0, 1, 2);
grid->setRowStretch(4,0);
grid->setColumnStretch(1,1);
grid->setColumnStretch(2,2);
grid->addWidget(dismiss, row, 0, 1, 3), ++row;
grid->setRowStretch(row - 1, 0);
grid->setColumnStretch(1, 1);
grid->setColumnStretch(2, 2);
grid->activate();
connect(dismiss,SIGNAL(clicked()),this,SLOT(accept()));
resize(150,140);
connect(dismiss, SIGNAL(clicked()), this, SLOT(accept()));
resize(150, 140);
}
NetHackQtGlyphs& NetHackQtSettings::glyphs()
@@ -130,12 +207,13 @@ void NetHackQtSettings::changedFont()
void NetHackQtSettings::resizeTiles()
{
int w = tilewidth.value();
int h = tileheight.value();
tileWidth = tilewidth.value();
tileHeight = tileheight.value();
settings.setValue("tilewidth", tilewidth.value());
settings.setValue("tileheight", tileheight.value());
theglyphs->setSize(w,h);
settings.setValue("tilewidth", tileWidth);
settings.setValue("tileheight", tileHeight);
theglyphs->setSize(tileWidth, tileHeight);
emit tilesChanged();
}
@@ -159,6 +237,37 @@ void NetHackQtSettings::setGlyphSize(bool which UNUSED)
othersize = n;
}
#ifdef ENHANCED_PAPERDOLL
void NetHackQtSettings::resizeDoll()
{
dollWidth = dollwidth.value();
dollHeight = dollheight.value();
settings.setValue("dollwidth", dollWidth);
settings.setValue("dollheight", dollHeight);
settings.setValue("dollShown", doll_is_shown);
//NetHackQtMainWindow::resizePaperDoll(doll_is_shown);
NetHackQtMainWindow *w = static_cast <NetHackQtMainWindow *>
(NetHackQtBind::mainWidget());
w->resizePaperDoll(doll_is_shown);
}
void NetHackQtSettings::toggleDollShown()
{
dollshown.toggle();
}
void NetHackQtSettings::setDollShown(bool on_off)
{
if (on_off != doll_is_shown) {
dollshown.QAbstractButton::setChecked(on_off);
doll_is_shown = on_off;
resizeDoll();
}
}
#endif
const QFont& NetHackQtSettings::normalFont()
{
static int size[]={ 18, 14, 12, 10, 8 };

View File

@@ -7,15 +7,25 @@
#ifndef QT4SET_H
#define QT4SET_H
#define ENHANCED_PAPERDOLL /* separate size from map tiles, can be hidden */
#include "qt_bind.h" // needed for mainWidget() for updateInventory()
namespace nethack_qt_ {
class NetHackQtGlyphs;
class NetHackQtMainWindow;
class NetHackQtSettings : public QDialog {
Q_OBJECT
public:
// Size of window - used to decide default sizes
NetHackQtSettings(int width, int height);
int tileWidth = 16, tileHeight = 16;
#ifdef ENHANCED_PAPERDOLL
int dollWidth = 32, dollHeight = 32;
bool doll_is_shown = true;
#endif
// dialog box for Qt-specific settings
NetHackQtSettings();
NetHackQtGlyphs& glyphs();
const QFont& normalFont();
@@ -31,21 +41,41 @@ signals:
public slots:
void toggleGlyphSize();
void setGlyphSize(bool);
#ifdef ENHANCED_PAPERDOLL
void toggleDollShown();
void setDollShown(bool);
void resizeDoll();
#endif
private:
QSettings settings;
QCheckBox whichsize;
QSpinBox tilewidth;
QSpinBox tileheight;
QLabel widthlbl;
QLabel heightlbl;
QCheckBox whichsize;
QSize othersize;
#ifdef ENHANCED_PAPERDOLL
QCheckBox dollshown;
QSpinBox dollwidth;
QSpinBox dollheight;
QLabel dollwidthlbl;
QLabel dollheightlbl;
#endif
QComboBox fontsize;
QFont normal, normalfixed, large;
NetHackQtGlyphs* theglyphs;
#if 0
void updateInventory()
{
static_cast <NetHackQtMainWindow *> (NetHackQtBind::mainWidget())
->updateInventory();
}
#endif
private slots:
void resizeTiles();