From f96d1b4342f3e49fb819ac9190aa98ecdbab6a9f Mon Sep 17 00:00:00 2001 From: PatR Date: Fri, 31 Dec 2021 15:29:10 -0800 Subject: [PATCH] Qt tiles file loading Redo how Qt retries if it can't load the primary tiles file. --- doc/fixes37.0 | 3 +++ win/Qt/qt_glyph.cpp | 57 +++++++++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/doc/fixes37.0 b/doc/fixes37.0 index beb2dc6d9..0d0b2005b 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -1103,6 +1103,9 @@ Qt: while a text window was shown (such as the "things that are here" popup when stepping on items), typing commands had the input passed on to the map and then executed; sometimes that caused the not-yet-dismissed text window to hang +Qt: if player's run-time options specified a tiles file and it couldn't be + loaded, Qt was falling back to x11tiles just like when the default + can't be loaded; fallback to player's file plus explicit path instead Qt: {maybe just Qt+OSX:} when viewing a text window ('V' to look at 'history' for instance), clicking on [Search], entering a search target in the resulting popup and clicking on [Okay] or typing , the text diff --git a/win/Qt/qt_glyph.cpp b/win/Qt/qt_glyph.cpp index 6c1df7c0c..06647638d 100644 --- a/win/Qt/qt_glyph.cpp +++ b/win/Qt/qt_glyph.cpp @@ -40,29 +40,46 @@ static int tilefile_tile_H=16; NetHackQtGlyphs::NetHackQtGlyphs() { - const char* tile_file = PIXMAPDIR "/nhtiles.bmp"; + boolean tilesok = TRUE, user_tiles = (::iflags.wc_tile_file != NULL); + char cbuf[BUFSZ]; + const char *tile_file = NULL, *tile_list[2]; - if (iflags.wc_tile_file) - tile_file = iflags.wc_tile_file; + tiles_per_row = TILES_PER_ROW; - if (!img.load(tile_file)) { - tiles_per_row = TILES_PER_ROW; - - tile_file = PIXMAPDIR "/x11tiles"; - if (!img.load(tile_file)) { - QString msg = QString::asprintf("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); - } - } + if (user_tiles) { + tile_list[0] = ::iflags.wc_tile_file; + Snprintf(cbuf, sizeof cbuf, "%s/%s", PIXMAPDIR, tile_list[0]); + tile_list[1] = cbuf; } else { - tiles_per_row = 40; + tile_list[0] = PIXMAPDIR "/nhtiles.bmp"; + tile_list[1] = PIXMAPDIR "/x11tiles"; + } + + if (img.load(tile_list[0])) + tile_file = tile_list[0]; + else if (img.load(tile_list[1])) + tile_file = tile_list[1]; + + if (!tile_file) { + tilesok = FALSE; + QString msg = QString::asprintf("Cannot load '%s'.", + user_tiles ? tile_list[0] + // mismatched quotes match format + : "nhtiles.bmp' or 'x11tiles"); + QMessageBox::warning(0, "IO Error", msg); + } else { + if (img.width() % tiles_per_row) { + tilesok = FALSE; + impossible( + "Tile file \"%s\" has %d columns, not multiple of row count (%d)", + tile_file, img.width(), tiles_per_row); + } + } + + if (!tilesok) { + ::iflags.wc_ascii_map = 1; + ::iflags.wc_tiled_map = 0; + tiles_per_row = 40; // arbitrary } if (iflags.wc_tile_width)