Commit Graph

2123 Commits

Author SHA1 Message Date
PatR
4d295a38de Qt MenuOrTextWindow tweak
Funnel all potential "<action> called before we know if Menu or Text"
warnings through a common routine.  Aside from rephrasing a message
which no one should ever see, there's no change in behavior.
2023-04-23 15:55:38 -07:00
nhmall
d4fb34bbb4 system.h 2023-04-23 12:29:02 -04:00
PatR
efd6b4081b build fixes for !TEXTCOLOR
Neither X11 nor Qt would compile with TEXTCOLOR disabled.  With this
they build and seem to work, but no promises, particularly for the
ENHANCED_SYMBOLS config.
2023-04-22 16:37:48 -07:00
nhmall
826ce951e7 get rid of NetHack macro conflict with curses routine delay_output() 2023-04-21 08:25:53 -04:00
PatR
71decafefd Qt menu fix
Noticed when working on the add_menu() crash earlier, using a mouse
rather than the keyboard to pick an entry in the sub-sub menus for
'm O' -> 'disclose' -> {any disclosure category} didn't work properly.
The problem was in post-3.6.x menu code for the Qt interface.
2023-04-21 00:44:50 -07:00
PatR
889b437775 Qt add_menu() w/o start_menu()
I temporarily reverted the fix for end-of-game disclosure of overview
in order to trigger the add_menu() crash under Qt.  It came down to

if (!actual) impossible("AddMenu called before we know if Menu or Text");
actual->AddMenu(glyph,identifier,ch,gch,attr,str,itemflags);

where 'actual' happens to be Null.  impossible() gets called, goes
through pline() calling putmesg() and putstr(WIN_MESSAGE), then the
output never shows up anywhere.  I haven't figured our what's going
on with that, but changing the above to

if (!actual)
    impossible("AddMenu called before we know if Menu or Text");
else
    actual->AddMenu(glyph, identifier, ch, gch, attr, str, itemflags);

at least prevents the crash.  The main window ends up becoming
minimized/iconified but the final popups which occur after disclosure
appear and accept responses and then a clean exit takes place.

Presumably it used panic() rather than impossible() at some point,
otherwise that code makes no sense:  test for Null then deference it
regardless of the result of the test?
2023-04-20 13:15:31 -07:00
PatR
0d31bb8c88 change program_state.getting_a_command
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.
2023-04-06 01:56:08 -07:00
PatR
4927527493 get rid of warnings when building tty interface
My guess about NCURSES_CONST was right; it expands to nothing in the
/usr/include/term.h on my old OSX system.  There aren't any levers or
knobs available to avoid that so this adds casts of string literals
to avoid warnings about passing a literal to something that expects
non-const.

There's a lot of conditional code in termcap.c and the nhStr("foo")
(hidden cast) changes only got tested for my default configuraiton.
I tried to avoid typos but I attempt such all the time and we know
how that tends to go.

Are we sure that systems which need to install a curses development
package have term.h without that?  A tty-only build shouldn't require
that.
2023-04-06 01:18:39 -07:00
Pasi Kallinen
697ef9760c Curses: partial stack unselecting
In curses, selecting a partial stack, then unselecting the entry,
and then selecting it normally, the entry still kept the quantity
from the partial selection. Make it behave like all the other
windowports by resetting the quantity when the entry is unselected.
2023-04-05 19:50:43 +03:00
nhmall
2185d325c4 header file changes hack.h, decl.h/.c, system.h, wintty.h
- Move secondary preprocessor defines down further in config.h
so that they can be overridden via [platform]conf.h which is
included from global.h, specifically:
    LIVELOGFILE when LIVELOG is defined
    DUMPLOG_FILE when DUMPLOG is defined

- Minimize platform-specific, or compiler-specific code in hack.h and decl.h.

- reorganize src/decl.c to align with include/decl.h.

- a new header file cstd.h added, containing calls to C99
standard header files.

- hack.h, decl.h, and decl.c have been cleaned up and had code
moved so that things line up as follows:

     hack.h     defines values that are available to all
                NetHack source files, contains enums for use in all
                NetHack source files, and contains a number of
                struct definitions for use in all NetHack source files.
                It does not contain variable declarations or variable
                definitions.

     decl.h     contains the extern declarations for variables that
                are defined in decl.c. These variables are global and
                available to all NetHack source files. The location of
                the variables within decl.h was random, so give it some
                order for now.

     decl.c     contains the definition of the variables declared in
                decl.h, and initializes them where appropriate. The
                variable definitions are laid out in much the
                same order as their declarations in decl.h.

- wintty.h: There were some varying terminal-related prototypes in
system.h, and that was the only thing left that demanded that
system.h be included. Those have been replaced by an #include
<term.h> in include/wintty.h to get the more current (and hopefully
more correct) prototypes, rather than hardcoding them in NetHack
sources.

For edge-case platform compatiblity, there is no #include <term.h>
if the build defines NO_TERMCAP_HEADERS. In that case one set of
hardcoded prototypes is still used in include/wintty.h.

The added #include "term.h" is also bypassed for NO_TERMS builds (builds
that don't link to terminfo/termcap at all, but still present a tty
interface using platform or window-port specific functions to fulfill
the same role as that of terminfo/termcap).

- some scattered, unnecessary #include "integer.h" were removed from
various files, since that's always included in current NetHack-3.7
sources, either directly from config.h or indirectly from #include
"hack.h".

- system.h references removed.

- new cstd.h added; the #include "system.h" references in Makefiles
and project files (Xcode, visual studio), were replaced
with #include "cstd.h" references. A "make depends" is probably
warranted.

Also:

 - Use of <term.h>, which defines clear_screen() as a macro, conflicts
with an actual function with that name in win/tty/termcap.c. The most
straight-forward course of action was to rename the NetHack function,
and change the references to it, from clear_screen() to
term_clear_screen(), so that was done.
2023-04-05 11:49:09 -04:00
nhmall
ddca5650ea qt comment bit 2023-04-04 14:25:24 -04:00
PatR
aa821006de curses: message window border again
This is a better workaround for the missing message window border when
when restoring with align_status:left.  Unlike the previous hack, this
may even be the correct way to handle it in the first place.

I haven't tracked down when the problem started.
2023-03-25 00:57:28 -07:00
PatR
e0e9d1d8b2 curses: message window border w/ align_status:left
This fixes the missing message window border when restoring with
align_status:left (which narrows and forces that window to the right).
It can't possibly be the correct way to fix things but does work.

This was not a problem with 3.6.4 (the most recent pre-3.7 playground
I have on hand) but I don't have the energy to use 'git bisect' to
track done when it started to whether the cause is discernable.  The
message history is put into place without going through putstr() so
differs from normal message handling.
2023-03-24 17:51:21 -07:00
PatR
8a0484321e add flags.silent handling to X11_nhbell() 2023-03-24 14:23:30 -07:00
nhmall
07ba3904fd window-ports should respect flags.silent setting
Like tty_nhbell() in termcap.c, window-ports really should
respect the flags.silent setting.
2023-03-24 12:23:19 -04:00
nhmall
a136dbac06 comment update in win/curses/cursmisc.c 2023-03-24 11:54:47 -04:00
PatR
3fcd56e6e3 curses: resize vs beep
Dynamically resizing the terminal window during play by dragging its
edges was beeping (a lot if you dragged slowly).  Recogize the key
code sent for that instead of complaining about unrecognized input.
2023-03-23 12:47:56 -07:00
PatR
f5d400be75 fix github issue #1002 - curses screen flash
Reported by jeremyhetzler:  with recently revised curses interface,
when dismissing a menu or prompt with ESC the screen flashed.

This was caused by calling beep() when the terminal is set for
'visible bell' (of flagged as incapable of 'audible bell'); the
curses library flashed the screen deliberately.  We don't want that.

Change the function key handling to not call beep() when an ESC
is typed by itself rather than being the leading part of a
multi-character escape sequence.  beep() will still be called if
you type an arrow key (or other function key) when nethack is
expecting text input.  That's what the recent change intended.

This also removes an early return from parse_escape_sequence()
when a number pad key generates an escape sequence.  I don't have
a number pad to verify that this bit works as intended.

Closes #1002
2023-03-23 11:12:34 -07:00
nhmall
8f142020a1 some Windows fixes
remove a couple of extraneous files from visual studio project
remove several trailing whitespace at end of line
remove an address sanitizer bounds error during player dialog init
rework fix for darkened lit tiles (fix issue #997)
2023-03-22 11:29:10 -04:00
Pasi Kallinen
201874a85a Curses: delete curses window
When NetHack deletes a window, also free the curses window data.
2023-03-14 11:16:13 +02:00
Pasi Kallinen
2db6f20700 Curses: free all perm_invent data 2023-03-14 09:18:32 +02:00
Pasi Kallinen
35273b8a8c Curses: prevent spurious cursor updates
While watching a ttyrec, I noticed strange behaviour in
the cursor updates; it was moved to approximately middle
of the map window every so often, usually when doing ranged
attacks. This wasn't really noticeable in normal gameplay,
as it was moving the cursor there, and then almost immediately
to where it was supposed to be.

I managed to trace it down to the refresh() in curses_delay_output().
That call updates the terminal to match the ncurses stdscr window,
but the stdscr window cursor position wasn't updated by NetHack.
2023-03-12 19:21:51 +02:00
nhmall
8e05a06d24 fix off-by-one (premature-truncation, not overflow) 2023-03-10 13:54:44 -05:00
nhmall
b61f55f0e4 Use-after-free when saving Qt message history #996
Possibly resolve #996
2023-03-10 11:27:11 -05:00
PatR
30de551f02 more curses key handling
Some bits made when attempting and failing to figure out the curses
problem (which turned out to be an early return skipping reset of
input timeout and fixed by paxed).
2023-03-08 14:38:53 -08:00
Pasi Kallinen
96587d2acf Fix curses quitting when trying to move
parse_escape_sequence changed getch timeout, but when receiving
a certain escape sequence, it returned without changing the
timeout back. This caused all subsequent getch calls be
non-blocking, and getch returns ERR when there's no input
waiting in that mode.

NetHack interprets ERR as the terminal going away, so performs
an automatic save.
2023-03-08 12:19:57 +02:00
nhmall
32ca917d2c sym-changes - add engravings to the map
1. Add "engraved room floor" pchar sym (S_engroom). The symbol that
displays at the engraved part of a room (not a corridor though).
The default symbol is '`' which is currently never shown if people
have defined the boulder symbol to '0' and statues are displayed as
monster symbols. It is bright blue.

Add some stylized variations of the S_engroom symset to some of
the symsets.

2. Add "engraved corridor" pchar sym (S_engrcorr). The symbol that
displays at the engraved part of a corridor. The default symbol is
'#', and it matches the symbol for corridor from for whatever the
current symset uses. It is bright blue to match the color of the
S_engroom symbol. Using the normal corridor symbol for display
preserves the lines of the corridor so is not as visually-disruptive
as a smaller symbol would be. Explicit entries that match the S_corr
symbol have been added to the symset file.

Magic mapping and clairvoyance impacts yet to be determined.

The Guidebook updates will come later.
2023-03-05 17:35:49 -05:00
Michael Meyer
2bb73b8fd8 Prevent curses 'More' (>>) from overwriting msg
In some scenarios where a message prompted a 'more' (in curses shown as
'>>'), the '>>' could overwrite the last one or two characters of the
message.

This could happen if a single message on its own was the length of the
message space minus 2 (e.g. for an 80 character terminal, "h - a concave
amulet named this is an amulet name, it is very long, and so on."), or
if an addition to an existing line brought it to the length of the
message space minus 1 or 2 (e.g. "You materialize on a different level!
You remember this level as testlevlname.").  The two scenarios had
slightly different causes.

I think this fixes both of those scenarios.  I believe this is the
cause of the problem described in GitHub issue #990 but there isn't
enough detail to know that for a fact.
2023-03-03 11:13:54 -08:00
nhmall
6836eb07d8 follow-up bit for cursmisc.c 2023-03-01 20:05:43 -05:00
nhmall
5a4d983104 fix uppercase alt key combinations with PDCurses 2023-03-01 17:06:15 -05:00
nhmall
d14a6b03fa Merge branch 'missing_framecolor' of https://github.com/entrez/NetHack into NetHack-3.7 2023-03-01 16:04:33 -05:00
Michael Meyer
68d1db2203 Initialize scrollbar 'framecolor' before use
Caused an asan crash because the value is used to index an array.
2023-03-01 15:23:46 -05:00
nhmall
76e82d1312 fix remaining contrived issues re HANGUPHANDLING 2023-03-01 12:01:43 -05:00
PatR
6ba11256ba partial fix for #K3869 - curses: meta characters
Meta-key fix for curses interface running on top of ncurses library.
Previously only digits and lower case letters would produce a meta
character when combined with Alt (or Option on Apple keyboards), now
it should work for any basic character (not arrows or other function
keys).  It only works on terminals that send two characters ESC k
for Alt+k but that is not a change in behavior.

curses interface running on top of PDcurses library uses different
code which isn't fixed by this.  The alt key fixup it does have was
already present in curses_read_char() and recently got duplicated in
curses_convert_keys().  At least one other routine calls the latter
so it was necessary, but curses_read_char() calls that routine so
doesn't need to keep its own copy of the fixup.
2023-02-28 10:14:25 -08:00
nhmall
7c0d65718c paste error 2023-02-28 00:09:37 -05:00
nhmall
42e337c306 return correct ALT-key sequences with PDCurses
They weren't working at all because the values of ALT_A through ALT_Z
were out of the normal char range with PDCurses, and caught by the default
case in the switch, where reject got set.

/* use key as-is unless it's out of normal char range */
        reject = ((uchar) ret < 1 || ret > 255);
2023-02-28 00:05:04 -05:00
PatR
d75beae272 address github issue #987 - curses: arrow keys
Issue reported by jeremyhetzler:  left and right arrows produced
unexpected characters when trying to use them to edit text that is
being entered.

The curses interface converts arrow keys and function keys related
to the keypad into movement keys (hjkl or 4286 depending on the
number_pad setting).  But it was doing that all the time, not just
when nethack wanted movement keys.  This extends the existing
program_state.getting_a_command flag to getdir() so that it can be
used for controlling that in addition to 'altmeta' support.

Typing an arrow when interacting with the map (actual command or
getpos, now getdir too) will still work.  Typing one when making a
wish or naming a pet will issue a beep and be treated as if '\0' had
been typed, and that normally gets treated as if ESC had been typed.
[Possible room for improvement there.  Losing the whole text when
trying to back up a character feels a bit harsh.]

Treating left arrow as escape rather than as h or 4 will probably be
enough to train players not to try to edit text with it after they
get burned by that a time or two.

Bonus fix:  curses' keystroke conversion only supported traditional
number_pad behavior, not the inverted phone number pad layout.

Closes #987
2023-02-23 14:02:28 -08:00
PatR
ecf247a2a6 tty_display_file()
For the !defined(DEF_PAGER) config, if the file to be displayed
can't be opened, refresh the screen after complaining about that
rather than when no complaint is issued.
2023-02-21 14:00:31 -08:00
nhmall
d1fda1773a fix a warning on Linux for X11 if -std=c99 2023-02-17 16:56:27 -05:00
PatR
a07098b206 X11_hangup()
I was looking at backporting an X11 build fix to 3.6 and decided
that the hangup handling wasn't correct if SAFERHANGUP is defined
(which it is by default).  It didn't attempt to perform a hangup
save.  Also, the handler might return when the X code calling it
expected it to not do so.

I don't know how to force a hangup within X11 so haven't tested
this properly.  It works fine when there's no hangup.  :-/
2023-02-10 15:19:13 -08:00
nhmall
24461058e6 more work on bundle and starting from Finder 2023-02-10 01:55:49 -05:00
PatR
a807b208ba wintty.c and cursstat.c formatting bits
Apply another old stashed commit.
2023-02-09 10:48:04 -08:00
PatR
042d40faac generic objects refinement
Give generic objects a name as well as a description to avoid some
potential object formatting problems.  Also remove the 'unique' flag
from them to avoid confusion.  Not exhaustively tested.
2023-02-07 16:47:42 -08:00
nhmall
fbd9a7bae8 another update to the soundlib interface
sound_verbal(char *text, int32_t gender, int32_t tone, int32_t vol,
             int32_t moreinfo);
    -- NetHack will call this function when it wants to pass text of
       spoken language by a character or creature within the game.
    -- text is a transcript of what has been spoken.
    -- gender indicates MALE or FEMALE sounding voice.
    -- tone indicates the tone of the voice.
    -- vol is the volume (1% - 100%) for the sound.
    -- moreinfo is used to provide additional information to the soundlib.
    -- there may be some accessibility uses for this function.

It may be useful for accessibility purposes too.

A preliminary implementation has been attempted for macsound to test
the interface on macOS. No tinkering of the voices has been done.

Use of the test implementation requires the following at build time with make.
    WANT_SPEECH=1
That needs to be included on the make command line to enable the test code,
otherwise just the interface update is compiled in.

I don't know for certain when AVSpeechSynthesizer went into macOS, but older versions
likely don't support it, and would just leave off the WANT_SPEECH=1.

If built with WANT_SPEECH=1, the 'voices' NetHack option needs to be enabled.

It was a bit strange, when I first started up the test, to hear Asidonhopo,
the shopkeeper, talking to me as I entered his shop and interacted with him.
2023-02-07 00:44:36 -05:00
Pasi Kallinen
7401b44fa1 Walls of lava
Add "walls of lava", basically lava which blocks vision and
require a bit more than just levitation or flight to move through.

No levels use this yet, as testing isn't thorough enough.
2023-02-06 19:23:42 +02:00
nhmall
36ca64acdb start to add some SOUND_TRIGGER_ACHIEVEMENTS code
Start to add supporting code to windsound and macsound. The latter
remains commented out because I haven't had a chance to try
it on macOS yet.

In order to test it out, I added two more stock sounds:
sa2_xplevelup and sa2_xpleveldown.
2023-02-04 14:28:59 -05:00
nhmall
2acd8e7b29 update soundlib interface
Add SOUND_TRIGGER_AMBIENCE
2023-02-03 13:32:44 -05:00
nhmall
3214335bb5 undefine X11_BUILD after hack.h or config.h
So as not to complicate any onefile efforts by leaving it defined.
2023-02-01 14:04:20 -05:00
nhmall
d4a111083a avoid some issues with c++ and X11 2023-02-01 10:41:04 -05:00
nhmall
e6012ab658 Only embed wav resources if soundlib defined 2023-01-31 02:22:25 -05:00