Commit Graph

512 Commits

Author SHA1 Message Date
nhmall
0006ff7d01 Merge branch 'combo_msg_window_vs_getlin' of https://github.com/entrez/NetHack into NetHack-3.7 2023-12-10 10:39:58 -05:00
PatR
4140a0023c fix #4059 - TTY_PERM_INVENT not freeing memory
As part of the tty resize handling revision, code dealing with the
perm_invent window was moved out of tty_destroy_nhwindow() was moved
into a separate routine.  The new routine would have been called for
a window of NHW_PERMINVENT, but WIN_INVENT doesn't have that type,
just ordinary NHW_MENU, so the cleanup wasn't happening, resulting in
a memory leak.
2023-12-07 18:36:14 -08:00
PatR
634f492827 fix #K4058 - tty: perm_invent fixes
I think this fixes all problems with the boundary boz drawn around
perm_invent.  Also, if you enabled perm_invent in inuse_only mode
while there are already more items in use than would fix in the
available number of lines, it wasn't switching to two columns until
the next update_inventory().  And the new color handling wasn't
incorporate into tty_refresh_inventory() so after a corner window
clobbered some of perm_invent, it got redrawn but without color,
again until the next update_inventory().

With any luck this fixes more bugs than it introduces....
2023-12-07 03:22:44 -08:00
PatR
7c20bf4afa tty: term_start_color(NO_COLOR)
Make term_start_color() more versatile.  If it gets passed NO_COLOR
then it performs term_end_color().  Should be able to streamline
some of the color handling this way although this hasn't done so.
2023-12-07 02:52:41 -08:00
nhmall
11a926c4cc TTY_PERM_INVENT: menucolors colors text, not inv letter
This diff is slightly inflated because I relocated a tty function
within win/tty/wintty.c.
2023-12-06 15:41:06 -05:00
nhmall
45856e3b5b follow-up: bordercolor lacked have expected offset 2023-12-06 13:49:33 -05:00
nhmall
8018fe64cf remove an outdated TODO: comment in wintty.c
A comment made reference to something that is fulfilled by
the core now, but that probably wasn't the case when that
comment was originally added.
2023-12-06 13:42:28 -05:00
nhmall
54332f5598 TTY_PERM_INVENT: honor color passed by add_menu()
Features like menucolors and so forth, are now done in the
core, and passed to the window interfaces via add_menu().

TTY_PERM_INVENT was disregarding the passed color value.

That can be turned off by the option !menucolors.

If a way to turn off menucolors in TTY_PERM_INVENT (or
perhaps in any perm_invent implementation), while keeping
it on for other menus, then a new option will be required.
2023-12-06 13:30:33 -05:00
PatR
1b1c45d3ce TTY_PERM_INVENT perminv_mode=inuse
Revise the tty permanent inventory window's in-use mode to be able to
switch back and forth between one full width panel and two side-by-side
half width panels on the fly as needs dictate.

A lot of trial and error involved but I think it has reached a state
where it is reliable, and the smaller number of lines required at
present can probably be viable for actual usage.  At the moment it
requires at least 10 extra lines below the standard tty mesg+map+stat
display, 34 lines total for statuslines:2 or 35 for statuslines:3.
The top and bottom of the 10 or more extra lines get drawn as boundary
lines using wall characters, leaving 8 lines for full width or 16 half
lines when 8 isn't enough.  If more that 16 items are in use (maybe
lots of lit candles forced into separate inventory slots or a
menagerie on leashes), the excess get skipped.  However, it will use
more lines if they are available.  Prior to a few days ago it was
requiring 17 extra lines and able to show 15 items as full lines only,
unable to take advantage of more lines when available.
2023-12-06 02:19:41 -08:00
PatR
2d8ba944e1 add some flexibility to TTY_PERM_INVENT
Allow perm_invent to be enabled with 1 less line when statuslines==2
by not reserving a line for statuslines==3.  If the player changes
that from 2 to 3, the perm_invent window is torn down and repositioned
one line lower if that will fit.  If it won't fit, it won't reenable.

Temporarily(?) allow perminv_mode==InUse to be enabled with room for
only 8 lines instead of requiring 15.  It will use more than 8 if are
more rows.

8 happens to be the amount (via 1+21+3+(1+8+1)) that will fit within
35 lines which is the biggest I can make fit on may laptop without
switching to a smaller font.  Switching is a nuisance, worse than that
for the font tiny enough to fit the full perm_invent.

ToDo:  if in-use won't fit in the number of lines allotted, switch to
two columns before resorting to ignoring the excess.

Maybe:  allow fewer lines for full perm_invent too and use the '|'
command to scroll them.  Might be too clumsy to be worthwhile.
2023-12-04 13:20:25 -08:00
nhmall
706232faf0 invlet_basic follow-up 2023-11-30 11:23:29 -05:00
nhmall
d7fef5f194 avoid another magic number
Some of the hardcoded +1 scattered about are likely
invlet_gold or invlet_overflow, but I didn't hunt those down.
2023-11-30 11:15:32 -05:00
Michael Meyer
79cdcff7e4 Fix: msg_window:combination and TTY getlin() ^P
The ability to use ^P from within a TTY getlin prompt didn't work with
msg_window:combination: it's a combination (unsurprisingly) of 'full'
and 'single', but hooked_tty_getlin() was treating it like 'full': i.e.
expecting everything to be displayed at once, with doprev_message()
returning only once the user was finished reading.  I didn't even know
^P was supposed to be accessible from a getlin prompt until Pat's recent
commit 5120764, because I have always used msg_window:combination -- I
had come up with a system where I'd name a potion thrown at me "xx",
check the previous messages with ^P, and then rename it from the
discoveries list.  This will be a lot easier!
2023-11-30 01:06:28 -05:00
PatR
5120764560 ^P in getlin()
Replace magic number 020 with ^P.
2023-11-29 11:24:46 -08:00
nhmall
04082a2033 Remove TEXTCOLOR build option 2023-11-22 16:01:58 -05:00
PatR
f23176155c tty: fix 'statuslines' off by 1 error
With CLIPPING disabled you should need a terminal or window with at
least 25 lines to change the 'statuslines' option from 2 to 3, but
it was being allowed on tty when there were only 24 lines available.

I think the other interfaces always have clipping capability enabled
so aren't affected.

Not many level maps extend to the bottom row (line 22 for a 1-based
count) so it wasn't likely to be noticed during play.  That points
that maps which don't use all rows and/or all columns could get by
without clipping by adjusting their position.  However, implementing
adaptive clipping is not something that I'm going to try to tackle.
2023-11-19 01:11:43 -08:00
PatR
3021423a5f github issue #1145 - ^C-induced panic on tty
Issue reported by entrez:  on tty, ^C while a menu was open followed
by 'yes' to "Really quit?" would lead to a bad window panic.

Brought on by screen erasure changes included with recent SIGWINCH
(window resize signal) changes.

Closes #1145
2023-11-18 17:45:43 -08:00
nhmall
4803022e90 Revert "follow-up for alternative fix for menu search (':')"
This reverts commit 569955ccac.
2023-11-17 13:54:41 -05:00
nhmall
569955ccac follow-up for alternative fix for menu search (':') 2023-11-17 13:40:38 -05:00
nhmall
a46c71f4c5 replace useful descriptive comment in tty getline 2023-11-17 09:04:27 -05:00
nhmall
8d1001842d alternative fix for menu search (':')
This avoids clearing core context variables within a window port.
2023-11-17 08:37:54 -05:00
PatR
73fed3d5d8 tty: menu search (':') fix
'm O' is a prime candidate for using ':' to select a menu item since
you can use that to avoid scrolling through many pages, but typing ':'
would immediately overwrite two or three lines of the menu with a
status refresh.  curses doesn't suffer from this problem.  X11 and Qt
show menus in separate windows do don't either.  Not sure about WinGUI.

I think that this may have been reported in the past, but if so I don't
recall by whom, or why it wasn't addressed.
2023-11-16 23:11:54 -08:00
nhmall
a82a897da3 avoid ctrl_nhwindow-related impossible
Remove the impossible(), so that new functionality can be added
incrementally without requiring every window-port to be visited up front.
2023-11-16 21:00:59 -05:00
nhmall
86067dcffd use ctrl_nhwindow() for menu prompt style
This implements the mechanics to use the ctrl_nhwindow() interface
capability to pass down a setting change from the core to the active
window port, without resorting to accessing a core global variable
from within the window port, and without altering the interface..

The passed setting is honored in the tty and curses window ports.

X11 and mswin receive and store the values, but no implementation
to change the menu prompt style is there yet.

Qt does not store the values or have an implementation.

The setting change is done in allmain.c immediately after
creating the WIN_INVEN window.
2023-11-16 00:10:06 -05:00
nhmall
4b79baa55b add_menu follow-up, part 2 of interface adjustment
Remove menu_color support from the window port side of the interface.
The window port just has to honor the color parameter that was added
to the add_menu() interface definition in June 2022 commit
2770223d10, and let the core-side of
the interface handle things.

To that end, this does the following:

Removes the #define of add_menu() from include/winprocs.h and add a
real core-side add_menu() function to windows.c which acts as a
trampoline to the window port win_add_menu() function, while providing
a single location to adjust the parameters passed to the window port
function. get_menu_coloring() is now called in there.

Moves get_menu_coloring() from options.c into windows.c and makes it
static.

Removes all the calls to get_menu_coloring() from the tty, Qt, X11,
curses, and win32 interfaces and adjusts their code to simply honor
the color parameter in add_menu, similar to what the menu_headings
change from earlier today did.
2023-11-13 12:56:38 -05:00
nhmall
682ae10f51 missing prototype warning ifndef TEXTCOLOR
../win/tty/wintty.c: In function ‘set_item_state’:
../win/tty/wintty.c:1174:9: warning: implicit declaration of function
‘term_start_color’; did you mean ‘term_start_attr’?
[-Wimplicit-function-declaration]
 1174 |         term_start_color(item->color);
      |         ^~~~~~~~~~~~~~~~
      |         term_start_attr
 ../win/tty/wintty.c:1178:9: warning: implicit declaration
 of function ‘term_end_color’; did you mean ‘term_end_attr’?
 [-Wimplicit-function-declaration]
 1178 |         term_end_color();
      |         ^~~~~~~~~~~~~~
      |         term_end_attr
2023-11-13 07:26:04 -05:00
Pasi Kallinen
dd5ca5b058 Change menu_headings to accept color and attribute
Instead of just accepting an attribute, it's now possible to
use a color, or both color and attribute, for example:

OPTIONS=menu_headings:inverse
OPTIONS=menu_headings:red
OPTIONS=menu_headings:red&underline

Default is still just inverse.
This lets the player change the menu heading color without
needing to use menu colors for them.

Also makes it so the core uses NO_COLOR instead of 0, for all
the menu lines which don't have any prefedefined color.

Tested for tty, curses, x11, qt, and win32
2023-11-13 07:33:56 +02:00
PatR
2ee7509945 replace getenv("TTYINV") with perminv_mode option
Add a new option 'perminv_mode' to augment perm_invent.  It handles
the same choices as the temporary TTYINV method:  show all items other
than gold, show full inventory including gold, or only show in-use
items (similar to the '*' command).

For tty, both the all-except-gold and full-inventory modes can add
the poorly named 'sparse' variation which populates unused slots in
its fixed grid with the inventory letter that would go in each.

For others, the default has been changed from full-inventory to
all-except-gold.  Note that gold is treated as part of 'all' or of
'in-use' if it is quivered because having the amount be shown on the
status line doesn't make that redundant.

Changing the default may mess up WinGUI if it assumes that perm_invent
is full inventory with gold.

Initially I was going to change perm_invent into a compound but this
leaves it as an on/off toggle and adds perminv_mode as a separate
option for how to show the inventory when the toggle is on.  It may
make sense to combine them since dual controls is a little confusing,
but right now setting perm_invent On when perminv_mode is 'none'
changes that to 'all' and changing perminv_mode away from 'none' when
perm_invent is Off toggles it to On.

Guidebook.mn has been updated but as usual Guidebook.tex is lagging.
2023-11-05 02:31:26 -08:00
PatR
814a69f061 update a couple of tty perm_invent comments
Gold can be quivered but not wielded, so remove the reference to the
latter.  Inuse-only mode gets passed lamps and leashes when they're
actively used, so remove the reference to that being different from
Qt's paperdoll.  (It is actually different, but not because they
won't be shown as in-use.  The paperdoll only shows one of each but
inventory of in-use items might have more than one of either or both.)
Add a what-if comment to tools_in_use().
2023-10-22 16:44:49 -07:00
PatR
85a5c3125e TTY_PERM_INVENT fix header for empty perm_invent
and reimplement 'sparse' mode (TTYINV=2 or TTYINV=3).

When hero had no inventory except for gold and perminv display mode is
ignoring gold, the header said "empty" when "only gold" was intended.

Sparse mode populates perminv with inventory letters in the unused
slots instead of leaving them blank.  (The core doesn't need to be
aware of that since it doesn't affect what display_inventory() sends
to the inventory menu.)
2023-10-22 08:54:41 -07:00
PatR
b0ab22a4e6 tty build fix
My repository got out of synch and I had a hell of a time restoring
sanity.

The most recent commit included a line in wintty.c that shouldn't have
been there.
2023-10-22 08:50:33 -07:00
PatR
77ae10f566 more TTY_PERM_INVENT, part 3 of 2
Some changes I made while chasing the slots 'A' and 'B' bug.  These
weren't necessary to fix that and I don't think they produce any
change in behavior, aside from making the "Bad window id N" panic
be more specific if it occurs.
2023-10-22 01:38:13 -07:00
PatR
a2f80a611a TTY_PERM_INVENT fix, part 2 of 2
The problem with tty perminv slots 'A' and 'B' boiled down to
  slot_limit = SIZE(slot_tracker); /*54*/
  ...
  /* blank out unused slots */
  for (slot = 0; slot < slot_limit; ++slot) {
    ...
    row = (slot % rows_per_side) + 1; /* +1: top border */
    side = slot < rows_per_side ? 0 : 1;
    ttyinv_populate_slot(row,side,...);
  }

Unused slots [52] and [53] (available for show_gold mode to display
"$a..zA..Z#", not filled with inventory for normal tty perm_invent
"a..zA..Z") yielded rows 1 and 2, side 1, so clobbered slots 'A' and
'B' with blanks.

This is a subset of the changes I was working with and didn't get as
much testing as the full set.
2023-10-20 22:52:38 -07:00
PatR
2476329b2c fix ^ as choice in / menu for tty and X11
It turned out that using '^' as a group accelerator (new behavior for
the 'whatis' command to view traps) already worked for curses and Qt.
Fix that for tty and X11.  I don't know the situation for WinGUI.

Offering any of the menu paging keystrokes as group accelerators
should be avoided if there's any chance that the menu will need more
that one page.  The menu for '/' is short though so losing "^ to go
back to first page" for it isn't an issue.
2023-10-14 17:24:39 -07:00
PatR
284452796c redo tty resizing
Rest of 'not PR #1102'.  Resizing the terminal while getpos was in
operation recalculated the map from scratch instead of redrawing what
the core considers to already be shown.  And it was always operating
while an asynchronous signal was excuting which could potentially
clobber whatever was running at the time the signal arrived.

This uses same redrawing as the prior '^R during getpos()' fix.  It
also only performs the resize while tty_nhgetch() is waiting for
input.  If that is the situation at the time that the signal arrives
then it will resize immediately (while in the asynchronous signal
handler); if not, it will set a flag and tty_nhgetch() will do the
resize the next time it gets called.

This builds with TTY_PERM_INVENT enabled and doesn't seem to be any
worse than before, but there are bugs with that.  The only way I could
get perminv to appear was to save and restore, then perm_invent was
honored for both RC file and mO command.  And once I managed to get it
to display, moving an item from a lower case slot to slot 'A', made
that item vanish; nothing appeared in the invent's right hand panel.

Both of those misbehaviors already happen prior to this commit.  I
also saw an abort+panictrace if I resized while at the "Dump core?"
prompt when running the pre-commit code and didn't see that with the
post-commit code (although the prompt wasn't shown so I couldn't tell
that it was waiting for an answer).  The abort probably sounds scarier
than it warrants; I suspect that the pre-commit code just treated the
resize as answering 'y' for some reason, possibly a stale value in the
variable it uses.
2023-10-12 18:45:14 -07:00
PatR
f70f84aee7 not PR #1102 - map refresh during #terrain
This fixes the part of pull request #1102 by entrez dealing with the
map refresh side of things.  It was pulled out of a much larger patch
that also deals with terminal window resize for tty.

Using ^R when getpos() is in operation, whether actually picking a
position for something or browsing the map during #terrain or post
detection magic, it was reconstructing the known map and positioning
the cursor on the hero instead redrawing the selected terrain subset
or detected objects/monsters/whatever.  There's already a routine to
redraw the current view of the map without recalculating it, but it
wasn't being used for ^R during getpos operation.
2023-10-12 01:18:55 -07:00
Michael Meyer
f64c2070df Fix: clipping on horizontal window resize
Clipping mode was not activated when a comfortably-sized game window was
resized horizontally to become too narrow to display the entire map,
causing various display errors and bugs if the window was resized like
that.  I think the horizontal resize check was removed by mistake in
d1dade164e.
2023-09-27 10:49:08 +03:00
PatR
2b47ef9670 some wintty.c cleanup
Mostly undefining macros when they're no longer needed.
2023-09-22 21:00:07 -07:00
PatR
9eb938fe06 tty status_sanity_check()
While experimenting with a potential status change I managed to get
a corrupted message in paniclog:
|status_sanity_check failed on tty_status[NOW][Jan].
where "Jan" was intended to be a "BL_" name.

Make tty's status_sanity_check() be a bit more robust.  This fix
shouldn't have any effect on the stable code.
2023-09-22 17:58:41 -07:00
PatR
6636db94e7 corridor engravings in black and white
The default engraving-in-corridor character is the same as the default
corridor symbol (and also default lit corridor one), distinguished by
color.  Show it differently (in inverse vidoe, like lava vs water and
sink vs fountain) if color is Off.

It might be better to change the engraving-in-room symbol to be the
same as the room one so that they'll be more consistent with corridors;
color is probably sufficient without resorting to back-tick.  But this
update hasn't done that.
2023-09-12 01:34:47 -07:00
nhmall
f3ad23fce2 first character of message window special outside putmixed
Issue #1042 states the following:
> Steps to reproduce:
> *name pet so that first (or only) character is non-ascii: example Ä or emoji.
> Most of the time the name is correctly shown.
> If new row starts with pet's name then character is not printed correctly.

The kludge for handling mixed glyphs and text shouldn't have been engaging
the special handling of the first character for anything outside of putmixed().
This should resolve that.
2023-05-31 00:10:22 -04:00
nhmall
68b8e84aa3 changes to build with VSI C compiler
The changes from past OpenVMS compilers are #ifdef'd VMS9
2023-05-22 14:43:10 -04:00
nhmall
13a5d978f9 remove a non-UNIX problematic define in termcap.c 2023-05-22 14:13:22 -04:00
nhmall
ec9d3cb88e keep external identifiers under 31 characters length 2023-05-13 13:49:57 -04:00
nhmall
826ce951e7 get rid of NetHack macro conflict with curses routine delay_output() 2023-04-21 08:25:53 -04: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
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
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
PatR
a807b208ba wintty.c and cursstat.c formatting bits
Apply another old stashed commit.
2023-02-09 10:48:04 -08:00
nhmall
446044e1d5 1st of a few sequencing changes
rename display_gamewindows() to init_sound_and_display_gamewindows()
(I know that's getting pretty long-named).

move activate_chosen_soundlib() into init_sound_and_display_gamewindows()
from moveloop_preamble().

Also included was a missing break in a switch related to sounds.
2023-01-26 17:15:59 -05:00