]> granicus.if.org Git - nethack/commitdiff
TTY_PERM_INVENT tweaks
authornhmall <nhmall@nethack.org>
Sun, 26 Jun 2022 02:26:18 +0000 (22:26 -0400)
committernhmall <nhmall@nethack.org>
Sun, 26 Jun 2022 02:26:18 +0000 (22:26 -0400)
src/invent.c
sys/windows/stubs.c
win/tty/wintty.c

index c9890369d3cf742a5598ab08c0d184092654c35d..65487b618b7ceb7201364a17d555d6db298ed8e3 100644 (file)
@@ -5349,6 +5349,7 @@ static char Empty[1] = { '\0' };
 static int done_environment_var = 0;
 #ifdef TTY_PERM_INVENT
 extern void tty_perm_invent_toggled(boolean negated);
+extern boolean in_tty_perm_invent_toggled;
 #endif
 
 void
@@ -5376,7 +5377,8 @@ core_update_invent_slot()
         || (pi_info.tocore.tocore_flags & prohibited))
             return;
 
-    if (!iflags.perm_invent && g.core_invent_state) {
+    if ((!iflags.perm_invent && g.core_invent_state)
+        && !in_tty_perm_invent_toggled) {
         /* Odd - but this could be end-of-game disclosure
          * which just sets boolean iflag.perm_invent to
          * FALSE without actually doing anything else.
@@ -5388,7 +5390,8 @@ core_update_invent_slot()
         (void) doredraw();
         return;
     }
-
+    if (!iflags.perm_invent && !in_tty_perm_invent_toggled)
+        return;
     /*
      * The core looks after what content goes into the
      * inventory slots, and deals with things like obj
@@ -5419,7 +5422,7 @@ core_update_invent_slot()
         wport_id = "perm_invent";
 
     pi_info.fromcore.core_request = 0;
-    if (!g.core_invent_state) {
+    if ((iflags.perm_invent && !g.core_invent_state) || in_tty_perm_invent_toggled) {
         /* Send the wport a request to get the related settings. */
         pi_info.fromcore.core_request = request_settings;
         if ((pi = update_invent_slot(g.perm_invent_win, (slot = 0), &pi_info))) {
@@ -5427,7 +5430,7 @@ core_update_invent_slot()
                 /* sizes aren't good enough */
                 set_option_mod_status("perm_invent", set_gameview);
                 iflags.perm_invent = FALSE;
-                pline("%s could not be enabled.", wport_id); 
+                pline("%s could not be enabled.", wport_id);
                 pline("%s needs a terminal that is at least %dx%d, yours is %dx%d.",
                       wport_id,
                       pi->tocore.needrows, pi->tocore.needcols,
@@ -5442,8 +5445,10 @@ core_update_invent_slot()
         display_nhwindow(g.perm_invent_win, FALSE);
         g.core_invent_state++;
     }
-    text = Empty; /* lint suppression */
+    if (!pi || pi->tocore.maxslot == 0)
+        return;
 
+    text = Empty; /* lint suppression */
     pi_info.fromcore.core_request = update_slot;
     obj = g.invent;
     for (slot = 0; slot < pi->tocore.maxslot; ++slot) {
index bebd22fdf9cb17d32eea60330b33ac813a2ba79a..2cdc4ff22cf872411abe52f8ab6ba88137cd2f73 100644 (file)
@@ -162,12 +162,14 @@ synch_cursor(void)
     return;
 }
 #ifdef TTY_PERM_INVENT
+boolean in_tty_perm_invent_toggled = FALSE;
+
 void
 tty_perm_invent_toggled(boolean negated)
 {
 }
-#endif
-#endif
+#endif /* TTY_PERM_INVENT */
+#endif /* TTY_GRAPHICS */
 
 void
 more(void)
index 09c505877a6b8d70240929a1d655c6eb733cea94..0b5225c693017a19287202d339a4c42a76bf3786 100644 (file)
@@ -267,6 +267,8 @@ static boolean done_tty_perm_invent_init = FALSE;
 #ifndef NOINVSYM /* invent.c */
 #define NOINVSYM '#'
 #endif
+/* not static, core_update_invent_slot() needs to see it from invent.c */
+boolean in_tty_perm_invent_toggled = FALSE;
 static int ttyinv_create_window(int, struct WinDesc *);
 
 static void tty_invent_box_glyph_init(struct WinDesc *cw);
@@ -3926,15 +3928,20 @@ tty_invent_box_glyph_init(struct WinDesc *cw)
 void
 tty_perm_invent_toggled(boolean negated)
 {
+    in_tty_perm_invent_toggled = TRUE;
     if (negated) {
         if (g.perm_invent_win != WIN_ERR)
             destroy_nhwindow(g.perm_invent_win), g.perm_invent_win = WIN_ERR;
         done_tty_perm_invent_init = FALSE;
+        g.core_invent_state = 0;
     } else {
-        g.perm_invent_win = create_nhwindow(NHW_PERMINVENT);
-        if (g.perm_invent_win != WIN_ERR)
-            display_nhwindow(g.perm_invent_win, FALSE);
+        core_update_invent_slot();
+        /* Doing this here was a problem */
+ //       g.perm_invent_win = create_nhwindow(NHW_PERMINVENT);
+ //       if (g.perm_invent_win != WIN_ERR)
+ //           display_nhwindow(g.perm_invent_win, FALSE);
     }
+    in_tty_perm_invent_toggled = FALSE;
 }
 #endif  /* TTY_PERM_INVENT */