| @@ -136,6 +136,7 @@ class Window(OnlineMixin, PuzzleMixin, O |
| 136 | 136 | self.symbols = {} # Halbzug-Index -> "!", "??", … |
| 137 | 137 | self.waiting_toast = None # „Moment …“, solange ein Hinweis oder Baum gerechnet wird |
| 138 | 138 | self.why_not_entries = {} # (FEN davor, Zug) -> „Warum nicht?“ aus der Zugliste |
| 139 | + self.why_not_toast = None # Toast „Ein Fehler – Warum?“ zum letzten eigenen Zug |
| 139 | 140 | self.badge_ply = None |
| 140 | 141 | self.hint_move = None |
| 141 | 142 | self.hint_final = False |
| @@ -1694,7 +1695,11 @@ class Window(OnlineMixin, PuzzleMixin, O |
| 1694 | 1695 | WHY_NOT_WORDS = {"?!": "Ungenau", "?": "Ein Fehler", "??": "Ein grober Fehler"} |
| 1695 | 1696 | |
| 1696 | 1697 | def _why_not_offer(self, ply, move, symbol): |
| 1697 | | - """Bei ?!, ? und ?? zum eigenen Zug: Hinweis in der Coach-Leiste mit Knopf „Warum nicht?“.""" |
| 1698 | + """Bei ?!, ? und ?? zum eigenen Zug: kurzer Toast mit Knopf „Warum?“. |
| 1699 | + |
| 1700 | + Ein Toast statt der Coach-Leiste: das Brett bleibt gleich groß, und der |
| 1701 | + Hinweis verschwindet von selbst, ohne den Spielfluss zu unterbrechen. |
| 1702 | + """ |
| 1698 | 1703 | if self.mode != "maia" or symbol not in self.WHY_NOT_WORDS or self.demo is not None: |
| 1699 | 1704 | return |
| 1700 | 1705 | if not self.settings.get("live_glyphs", True): |
| @@ -1703,12 +1708,20 @@ class Window(OnlineMixin, PuzzleMixin, O |
| 1703 | 1708 | if before.turn != self.human: |
| 1704 | 1709 | return |
| 1705 | 1710 | label = notation.label(before, move, self._notation()) + symbol |
| 1706 | | - why = {"label": "Warum nicht?", "why_not": (before, move), "keep": True} |
| 1707 | | - # außerhalb der Kurse: nur der Hinweis zum letzten eigenen Zug; Blättern in der Zugliste bleibt |
| 1708 | | - self.coach_log = [{"ply": ply, "markup": f"<b>{GLib.markup_escape_text(label)}</b> – " |
| 1709 | | - f"{self.WHY_NOT_WORDS[symbol]}.", "shapes": (), "demos": [why]}] |
| 1710 | | - self.coach_index = None |
| 1711 | | - self._coach_show() |
| 1711 | + self._why_not_clear() |
| 1712 | + toast = Adw.Toast(title=f"{GLib.markup_escape_text(label)} – {self.WHY_NOT_WORDS[symbol]}", |
| 1713 | + button_label="Warum?", timeout=5) |
| 1714 | + |
| 1715 | + def explain(*_): |
| 1716 | + stack = self.board.move_stack |
| 1717 | + if len(stack) > ply and stack[ply] == move: # der Zug steht noch in der Partie |
| 1718 | + self._why_not_from_list(ply) |
| 1719 | + |
| 1720 | + toast.connect("button-clicked", explain) |
| 1721 | + toast.connect("dismissed", lambda t: setattr(self, "why_not_toast", None) |
| 1722 | + if self.why_not_toast is t else None) |
| 1723 | + self.why_not_toast = toast |
| 1724 | + self.toasts.add_toast(toast) |
| 1712 | 1725 | |
| 1713 | 1726 | def _why_not_from_list(self, ply): |
| 1714 | 1727 | """Knopf „Warum nicht?“ in der Zugliste (auch wenn die Zeichen nicht aufs Brett sollen).""" |
| @@ -1725,6 +1738,9 @@ class Window(OnlineMixin, PuzzleMixin, O |
| 1725 | 1738 | self._why_not(entry) |
| 1726 | 1739 | |
| 1727 | 1740 | def _why_not_clear(self): |
| 1741 | + toast, self.why_not_toast = getattr(self, "why_not_toast", None), None |
| 1742 | + if toast is not None: |
| 1743 | + toast.dismiss() # der Hinweis gehörte zum vorigen eigenen Zug |
| 1728 | 1744 | if self.mode != "opening" and self.coach_log: |
| 1729 | 1745 | self.coach_log = [] |
| 1730 | 1746 | self._coach_show() |