Sidenote: The main window size calculations are getting stupid.
It would be better to find out the widget sizes and shift
the splitter up, instead of letting it just take up half of the main window.
Idea and part of the code by Richard Henschel
The g? structs had a mix of variables that were written to
the savefile, and those that were not.
For better clarity and to distinguish those that end up in
the savefile, relocate some g? variables that get written
directly to the savefile into different structs.
This updates EDITLEVEL, although technically it probably
didn't need to, since savefile contents are not changing.
Details:
gb.bases -> svb.bases
gb.bbubbles -> svb.bbubbles
gb.branches -> svb.branches
gc.context -> svc.context
gd.disco -> svd.disco
gd.dndest -> svd.dndest
gd.doors -> svd.doors
gd.doors_alloc -> svd.doors_alloc
gd.dungeon_topology -> svd.dungeon_topology
gd.dungeons -> svd.dungeons
ge.exclusion_zones -> sve.exclusion_zones
gh.hackpid -> svh.hackpid
gi.inv_pos -> svi.inv_pos
gk.killer -> svk.killer
gl.lastseentyp -> svl.lastseentyp
gl.level -> svl.level
gl.level_info -> svl.level_info
gm.mapseenchn -> svm.mapseenchn
gm.moves -> svm.moves
gm.mvitals -> svm.mvitals
gn.n_dgns -> svn.n_dgns
gn.n_regions -> svn.n_regions
gn.nroom -> svn.nroom
go.oracle_cnt -> svo.oracle_cnt
gp.pl_character -> svp.pl_character
gp.pl_fruit -> svp.pl_fruit
gp.plname -> svp.plname
gp.program_state -> svp.program_state
gq.quest_status -> svq.quest_status
gr.rooms -> svr.rooms
gs.sp_levchn -> svs.sp_levchn
gs.spl_book -> svs.spl_book
gt.timer_id -> svt.timer_id
gt.tune -> svt.tune
gu.updest -> svu.updest
gx.xmax -> svx.xmax
gx.xmin -> svx.xmin
gy.ymax -> svy.ymax
gy.ymin -> svy.ymin
Related note:
There are some pointer variables that are heads of chains that were not
moved from 'g?' to 'sv?', because they are not actually written to the
savefile directly, but the objects/monst/trap/lightsource/timer in the
chains they point to are. That can be changed, if desired.
Examples: gi.invent, gm.migrating_objs, gb.billobjs, gm.migrating_mons,
gf.ftrap, gl.light_base, gt.timer_base
There was an error:
../win/Qt/qt_main.cpp:767:37: error: attempt to use a deleted function
action->setData(actchar);
^
/usr/include/x86_64-linux-gnu/qt6/QtCore/qvariant.h:199:5: note: 'QVariant<char *, false>' has been explicitly marked deleted here
QVariant(T) = delete;
^
1 error generated.
I'm hoping the fix applied is the correct one for the error.
A printf call was introduced in 20fb008012 that caused the terminal
window to be filled with repeated debugging messages as the window
containing the Qt windowport was resized. I removed it because I
assumed it was meant to be temporary and was left in the commit by
mistake, considering it isn't mentioned in the commit message; if it was
meant to be permanent it'd probably be good to block it out with #ifdef
DEBUG or something at least, because it produces a real deluge of
terminal output if the player spends any time resizing the window by
hand.
* qt_tilewidth and qt_tileheight are allocated with alloc() and need
to be freed with free().
* Don't use them after they're freed. Instead, retrieve the size from
the glyphs object.
to program_state.input_state
Rename program_state.getting_a_command and give it an int value
instead of treating it as boolean. Start using to it for Qt to
suppress commands initiated from the drop down menus in the title bar
if nethack isn't expecting to get a command from the user. Those menu
choices inject extended command text into the input stream and should
be avoided when entering text or waiting for a menu to be dismissed.
These menus would be better if they grayed out unavailable choices
when pulled down instead of accepting any choice and then treating
that no good. I'm not going to try to figure out to do that with Qt.
And this workaround for the menus doesn't have any affect on the
toolbar buttons below the title bar. Those execute core commands
directly and when I tried to use jacket routines instead, the tool bar
stopped showing up so I've given up.
This won't fix the reported problem of getting stuck in a loop.
The consolidation of global variables from scattered source
files into decl.c and declared in decl.h was begun in 3.7.0.
Their placement in common files was done for centralized
initialization and potential re-initialization during a
"play again" scenario.
It wasn't really necessary for all of them to be housed in a
single huge structure to meet the "play again" requirement,
and the single huge structure has been a little unwieldy when
it comes to maintenance.
Following this commit, instead of one single extremely large structure
named 'g' to house all of the relocated global variables, they
are distributed into several ga through gz.
To make things easy for the developer, each variable is placed
into the struct corresponding to the starting letter of the variable.
That way, no lookup is required in order to know which struct houses
a particular variable, it is a simple match to the starting letter
for all the centralized global variables.
A global variable named 'amulets', would be found in ga.
ga.amulets
^ ^
A global varable named 'move', would be found in gm.
gm.moves
^ ^
A global variable named 'val_for_n_or_more' would be found in gv.
gv.val_for_n_or_more
^ ^
A global variable named 'youmonst' would be found in gy.
gy.youmonst
^ ^
The test system is Slackware 14.2, which uses Qt 4.8.7.
* WANT_WIN_QT4 is defined, and has the expected meaning. Qt 5 is still
the default.
* The QT_NO_SOUND macro now excludes all headers and declarations
relating to sound; the multimedia package is not needed to build
(on any Qt 4, 5 or 6).
* A new function, nh_qsprintf, replaces QString::asprintf, for Qt
older than 5.5. These versions do not have QString::asprintf.
* DYNAMIC_STATUSLINES is disabled for Qt older than 5.9. These versions
do not have QSplitter::replaceWidget.
Add "Lua" and its version number of the 'About' popup. No copyright
information is included since neither nethack's nor Qt's is shown.
Lua copyright text is included in the output of '#version'.
Our C() macro conflicts with Qt6 usage, so #undef C has added. Move
that from nearly every qt_*.cpp into qt_pre.h where other similar
fixups are handled.
Mostly the warnings were about QString::sprintf and QFontMetrics::width.
sprintf replacement is asprintf, which annoyingly behaves differently
from sprintf - it seems to append to the string.
Not thoroughly tested, but seems to work.
../win/Qt/qt_main.cpp: In member function ‘virtual void nethack_qt_::NetHackQtMainWindow::closeEvent(QCloseEvent*)’:
../win/Qt/qt_main.cpp:1377:9: warning: variable ‘ok’ set but not used [-Wunused-but-set-variable]
1377 | int ok = 0;
| ^~
I can't take credit for this and still have no idea why it is
needed, but it fixes use of ^V as a command and as input to
to the regular version of yn_function(). In particular, '&'
command reports it as ^V. Unfortunately when 'popup_dialog' is
set, no control characters seem to be accepted by the part of
NetHackQtYnDialog(Exec+KeyPressEvent) responsible for arbitrary
input.
It also causes getlin() to terminate but I can't think of any
situation where ^V would be considered to be valid input for
getlin() so won't worry about that.
I put it in as '#if MACOSX' because I don't know whether any
other Qt platforms need it.
Binding 'repeat' (DOAGAIN, or redo) to a different key than ^A
didn't work as intended because the code that used it was
checking for DOAGAIN (a key value from config.h) instead of
g.Cmd.spkeys[NHKF_DOAGAIN] (the key currently bound to repeat).
Contrary to the github issue, re-bound prefix keys worked ok for
me if followed by a direction. However, they behaved strangely
if followed by anything else. If the keystroke was stolen from
some other command and that command hadn't been bound to another
key, following the prefix with a non-direction could end up
executing the command that used to own the key. For example,
BIND=d:nopickup
to use 'd' to move without auto-pickup would work if you used
d<direction> but if you used d<something-else> if would execute
the drop command.
The NHKF_REQMENU prefix could be bound to some key other than
'm' but it only worked as intended if the new key was a movement
prefix.
This also makes DOAGAIN be unconditional. If it is deleted or
commented out in config.h, the default binding will be '\000' so
unusable (freeing up ^A for something), but still be available
to be bound to some key (perhaps even ^A).
This also includes an unrelated change to mdlib.c. The comments
added to config.h will force a full rebuild. Changing mdlib.c
now rather than separately will avoid forcing that twice.
Fixes#426
Turns out it was nearly as simple as I originally thought.
I just missed one significant detail the first time around.
This leaves DYNAMIC_STATUSLINES as conditionl but now enables
it by default. Using 'O' to change 'statuslines' from 2 to 3
or vice versa now works for Qt as well as for curses and tty.
Change "_Quit-without-saving" in the Game dropdown menu to be
"\177Quit-without-saving". That makes the prefix used on OSX to
prevent matching "^[&]?[Qq][Uu][Ii][Tt].*" be invisible.
Also change the order of the choices for the command+Q and
application dropdown menu entry "quit nethack" so that "cancel
and return to game" is the default for arbitrary response to the
confirmation prompt. <return> and <space> select "quit without
saving". Note that the nethack dropdown menu is OSX-specific
(a Qt feature to emulate other OSX applications) and its
nethack->Quit action is separate-from/in-addition-to Game->Quit
menu action mentioned above (which runs nethack's #quit command).
Prevent Qt from inserting an extra entry in the Help dropdown
menu displayed in the menu bar across the top of the screen
when nethack has focus. "Search [______]" lets the user enter
a string to search for but doesn't give nethack any control
over that so we can't have it.
I haven't found a sane way to get rid of it. The insane way
of not naming any menu "Help" works. This uses "\177Help" so
that it still looks like "Help" but won't match that string.
Qt on OSX is inserting "Search [_____]" as the first entry in
the Help dropdown menu (the one in the toolbar at the top of the
desttop). While trying--and failing--to figure out how to get
rid of that, I cleaned up a little bit of the old menu hackery
(that tries to workaround the fact that Qt on OSX insists that
some menu actions--based solely on their names--should go into
the appication menu rather than whichever menu the program is
trying to insert them into). The only observeable difference
is that 'About NetHack-Qt' will be at the top (actually second
because of that Search one) of the Help dropdown, where it is on
non-OSX builds, rather than last.
This tries to make the program name consistent too, changing
several instances of "Qt NetHack" to be "NetHack-Qt". The latter
is the name being set up as ApplicationName in qt_bind.cpp that
gets used when Qt stashes the Qt-specific settings wherever it
stashes them.
It also makes another tweak in formatting of 'About NetHack-Qt',
inserting one explicit line break to avoid some poor looking line
wrapping. I still haven't figured out how to control that popup's
size.
Condense the Qt status slightly, moving Alignment field from the
Conditons line to the Characteristics line and the Time and Score
fields from their own possibly blank line to the HP,&c,Gold line.
That's for statuslines:2, which is the default. statuslines:3
restores the previous layout. I tried to make that become the
default for Qt but it got messy fast and I gave up.
I also tried to make changing 'statuslines' back and forth on the
fly work but failed. I left the code in as #if DYNAMIC_STATUSLINES
but that isn't defined anywhere. For the time being at least,
'statuslines' is config file or NETHACKOPTIONS only for Qt, not
changeable via 'O' like for curses and tty.
Change the option description for 'statuslines'. That depended
upon whether curses was compiled in when it should depend on which
interface is active. This moves the alternate info to Guidebook.
Simplify a recent change to the screen layout. Qt can calculate
the details and the recent code resulted in a slight amount of
blank space between the paperdoll and its resize hotspot.
Fix an off-by-one bug in the paperdoll resize routine. (The one
pixel margin at the top was being overlooked.)
Try to set the initial window sizes to be big enough to show the
full welcome line in the message window when the Qt settings
(Preferences on OSX) specify Large font (Huge/Medium/Small/Tiny
seemed ok but I wasn't systematic about checking them).
While at it, I added a long comment about the status window format
and noticed a bug with experience formatting there. Again only
seemed to matter for Large font but the change to fix ignores font
size.
Plus add a couple of Qt "issues", one old and one just discovered.
The toolbar contains do-Again, Pick up, Drop, Kick, Throw, Fire,
Eat, and Rest. Insert Search in front of Rest since it's useful
in its own right and some players prefer it even when resting.
Includes a new 12x13 icon; a tiny magnifying glass shown straight
on is something I can manage.
Both the toolbar button for pick up and the action menu entry for
pick up were labeled "Get". That's confusing for an experienced
player who is looking for "Pick up". Rename both of them.
Also, consolidate repetitive code used to set up toolbar buttons.
Clicking on the paper doll inventory subset window will cause
the '*' command (#seeall) to execute. They convey the same
information (unless multiple leashes or multiple light sources
are in use; seeall lists all of them instead of just the first
of each) but the doll shows the info with a small grid of map
tiles and seeall shows it with an inventory display of worn and
wielded items plus tools in active use.
Ideally it should show information about a specific item as a
"tool tip" when the mouse hovers over one of the doll slots.
I don't know whether I'll ever attempt to tackle that or even
if that's feasible with Qt. Perhaps use right click instead.
For Qt with 'popup_dialog' On, fix number entry when user types
a digit (or '#') directly onto the dialog instead of clicking
inside the Count box and then typing. Before, that first typed
digit was starting out as selected, so typing the next digit
replaced the selection instead of getting appended to the string
of digits being constructed. Fixed by moving the relevant code
to the KeyPress handler instead of re-executing the dialog.
Also, if a keypress is just a modifier, ignore it. The next
event should be the actual character. Prevents treating <shift>
(and <caps lock>!) as useless dialog responses. Before this,
attempting to type '#' to initiate a count wouldn't work because
the <shift> part of shift+3 ended the dialog. Now '#' works
(and is still optional; starting with a digit suffices).
Support MSGTYPE=stop by having qt_display_nhwindow(WIN_MESSAGE,TRUE)
issue a tty-style --More-- prompt. For popup_dialog Off, the prompt
gets appended to the most recent message; for popup_dialog On, it is
issued via a popup and not displayed in the message window.
It accepts <space>, ^J, ^M, and ^[ (ESC) to dismiss. There's no way
to dismiss it with the mouse (for !popup_dialog) which might need
some fix....
Several adventures along the way. The '^C-in-parent-terminal triggers
infinite loop repeatedly complaining about "event loop already running"'
is now a one-shot complaint. It isn't fixed but the severity of
having it happen is greatly reduced.
The Qt interface highlights the last message issued (using a
mechanism for selection, as if for copy+paste or similar operation)
but it was staying highlighted until another message was eventually
given. Having an old message seem to stick around is annoying and
is particularly bad when the message is a prompt. If the player's
answer doesn't cause a message to be shown then it seems as if the
prompt is still pending.
This removes the highlighting (by bulk unselecting) once the player
gives another input keystroke or mouse click.
It would be much better if the selecting/highlighting was for all
messages issued since last time highlighting was cleared. Figuring
out how to do that correctly is more effort than I want to expend.
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.)
Move the nine #undef's common to all qt_*.cpp sources into qt_pre.h.
Make "hack.h" usage consistent; always enclose withing 'extern "C {'
and '}' even though only some of the sources care.
The core is mapping #annotate to ^N, which has no effect when
number_pad is Off. The Qt menu setup saw it as the way to run
that command, which will only work when number_pad is On. This
fixes the menu and didn't break the large subset of other menu
commands I've tried, but I haven't gotten through half of them yet.
The Qt menu entries which were executing nethack's help command
(the '?' menu) were doing so because their command keystroke was
a meta-character and such characters are being converted to '?'
to indicate an error in conversion to Latin1 character set. The
old Qt3 code didn't perform any such conversion.
This fix feels fragile because there are two different places
deciding how to disambiguate partial extended commands (the code
for Qt's '#' handling and a new routine in the core). Qt menus
now send '#' and enough letters to satisfy '#' handling for any
command which uses M-c or has no regular keystroke nor M-c one.
(If it were to send the full extended command name, the letters
after the unambiguous prefix would be left in the input queue to
be processed as subsequent commands.)
There is a fundamental problem that this doesn't address: if
the player uses BIND directives in the run-time config file, the
Qt menu bindings will break unless the BINDs are all done before
selecting windowtype. Qt's menu bindings translate a click on
a menu entry into the keystroke used to invoke the corresponding
command, so using BIND to change that after the menus are set up
will result in the wrong commands being executed.
Changes affecting everybody (using Qt): rename game->Save to
game->Save-and-exit and game->Quit to game->Quit-without-saving.
OSX-specific changes: add separate nethack->Quit and change
game->Quit-without-saving to game->_Quit-without-saving to prevent
that from being hijacked for the nethack menu. nethack->Quit menu
entry works. Command+Q is a keyboard shortcut for it. They bring
up a menu with choices of "Quit without saving" and "Cancel and
return to game". It's not the same as the handler for the window
Close button, which used to offer "Save" or "Cancel" (with the
latter triggering an infinite loop) but now offers "Save and exit"
or "Quit without saving". They don't share any code. The
game->_Quit-without-saving entry doesn't work; it runs nethack's '?'
command like a bunch of other broken menu entries. If it did work,
it would give nethack's "Really quit?" prompt and proceed from there.
The "Quit without saving" response for nethack->Quit confirmation
bypasses that and just quits.
Also OSX, add a second 'about' entry. The first one is hijacked and
added to the nethack menu, the second is help->_About_Qt_NetHack_
and avoids hijacking. Both nethack->About and help->_About_ bring
up the same dialog box showing version and assorted other info.
A lot of flailing about with for relatively small amount of progress.
Menu hackery: change a couple of menu entry names on OSX to
control where they end up.
Move nethack's 'O' command from its hijacked position (due to name
"Options") of "nethack->Preferences..." to "Game->Run-time options".
Move persistent Qt settings on OSX from "Game->Qt settings" to
"nethack->Preferences...".
The Qt settings dialog (now accessed as Preferences...) desperately
needs a title and/or other explanatory text but I haven't figured
out how do to that. The values set with it are persistent, with
apparently quite a few choices for where to save them for future
runs. I used it to increase the size of text in the status window,
and found my settings stored in binary file
~/Library/Preferences/org.nethack.NetHack.plist
The subdirectories ~/Library and ~/Library/Preferences are
standard OSX per-user things. The file name is derived from values
set up in main routine: qt_main.cpp is setting OrganizationDomain
to "nethack.org" and ApplicationName to "NetHack". I've added a
value for ApplicationVersion but don't know whether anything cares
about it.
Add ^X (as "Attributes (extended status)") to the "Info" drop down
menu, also Overview, and Annotate.
Attributes and Overview work, Annotate results in running southeast.
Existing entries Conduct, Adjust, and Skills execute nethack's '?'
command so I didn't bother holding back on adding Annotate. Other
existing entries (Inventory, Discoveries, Spells, and Name) work.
If there's any sort of pattern involved, I'm not seeing it.
The Game menu has "Save", which shows up and works, but that's
supposed to be followed by "Quit" which doesn't show up when the
menu is used. This doesn't attempt to deal with that.
Command+q keystroke, which should close the application, behaves
the same as previously mentioned "quit nethack" in nethack menu:
runs nethack's '?' command and then resumes play.
Prevent an infinite loop that occurred if player clicked on the
close window button and then tried to cancel out of that in the
dialog it brings up.
I don't know whether Qt interface on platforms other than OSX
need this but they're getting it. The choices are changed from
"Save" or "Cancel" to "Save and exit" or "Quit without saving".
Since save allows subsequent restore, not being able to cancel
out of the application shutdown should only be an inconvenience.
Unresolved issues:
I don't know whether there's any other way to bring up that dialog,
where Cancel might be a viable choice. If so, handling that might
be tricky. Quit should definitely be available as an alterative
to Save, but that type of dialog doesn't seem to allow more than
two choices.
Picking "nethack" from application menu and then "quit nethack"
from the resulting pull down menu results in executing nethack's
help command (the '?' menu) and then just resumes play.
Add Michael's fix for control+x.
The enum name of the argument suggests that option+x should have
been sending control characters but that wasn't the case for me.
Before this fix, both control+x and option+x behaved like dead
keys, not transmitting anything for nethack to use. After this
fix, control+x sends ^X as desired but option+x is still dead.