| @@ -52,6 +52,8 @@ class OpeningMixin: |
| 52 | 52 | self.course_stats = {"errors": 0, "hints": 0} |
| 53 | 53 | self.opening_busy = False # wartet auf Gegnerzug, Bewertung oder Zurücknahme |
| 54 | 54 | self._name_cache = {} |
| 55 | + self.coach_log = [] # Rückmeldungen: {"ply": Halbzug der zugehörigen Stellung, "markup": Text} |
| 56 | + self.coach_index = None # angezeigte Rückmeldung; None = die neueste |
| 55 | 57 | |
| 56 | 58 | # --- Oberfläche -------------------------------------------------------- |
| 57 | 59 | |
| @@ -65,18 +67,70 @@ class OpeningMixin: |
| 65 | 67 | label="Gegen Maia weiterspielen", valign=Gtk.Align.CENTER, visible=False, margin_end=10, |
| 66 | 68 | ) |
| 67 | 69 | self.coach_button.set_action_name("win.opening-continue") |
| 70 | + # Blättern durch die letzten Rückmeldungen; das Brett zeigt die Stellung dazu |
| 71 | + self.coach_nav = Gtk.Box(spacing=2, valign=Gtk.Align.CENTER, margin_end=6) |
| 72 | + self.coach_prev = Gtk.Button(icon_name="go-previous-symbolic", tooltip_text="Vorherige Rückmeldung", |
| 73 | + css_classes=["flat"]) |
| 74 | + self.coach_next = Gtk.Button(icon_name="go-next-symbolic", tooltip_text="Nächste Rückmeldung", |
| 75 | + css_classes=["flat"]) |
| 76 | + self.coach_last = Gtk.Button(icon_name="go-last-symbolic", tooltip_text="Zum aktuellen Zug", |
| 77 | + css_classes=["flat"]) |
| 78 | + self.coach_prev.connect("clicked", lambda *_: self._coach_step(-1)) |
| 79 | + self.coach_next.connect("clicked", lambda *_: self._coach_step(1)) |
| 80 | + self.coach_last.connect("clicked", lambda *_: self._coach_latest()) |
| 81 | + for button in (self.coach_prev, self.coach_next, self.coach_last): |
| 82 | + self.coach_nav.append(button) |
| 68 | 83 | card = Gtk.Box(spacing=6, css_classes=["card"], margin_start=12, margin_end=12, margin_bottom=12) |
| 69 | 84 | card.append(Gtk.Image(icon_name="dialog-information-symbolic", margin_start=14, valign=Gtk.Align.CENTER)) |
| 70 | 85 | card.append(self.coach_label) |
| 86 | + card.append(self.coach_nav) |
| 71 | 87 | card.append(self.coach_button) |
| 72 | 88 | self.coach = Gtk.Revealer(child=card, transition_type=Gtk.RevealerTransitionType.SLIDE_UP) |
| 73 | 89 | return self.coach |
| 74 | 90 | |
| 75 | | - def _coach(self, markup, final=False): |
| 76 | | - self.coach_label.set_markup(markup) |
| 77 | | - self.coach_button.set_visible(final) |
| 91 | + def _coach(self, markup, ply=None, replace=False): |
| 92 | + """Neue Rückmeldung zur Stellung nach Halbzug ``ply`` (Standard: aktuelle Stellung).""" |
| 93 | + entry = {"ply": len(self.board.move_stack) - 1 if ply is None else ply, "markup": markup} |
| 94 | + if replace and self.coach_log: |
| 95 | + self.coach_log[-1] = entry |
| 96 | + else: |
| 97 | + self.coach_log.append(entry) |
| 98 | + self.coach_index = None |
| 99 | + self.browse_ply = None # neue Rückmeldung: Anzeige springt zum aktuellen Zug |
| 100 | + self._coach_show() |
| 101 | + |
| 102 | + def _coach_show(self): |
| 103 | + if not self.coach_log: |
| 104 | + self.coach.set_reveal_child(False) |
| 105 | + return |
| 106 | + last = len(self.coach_log) - 1 |
| 107 | + index = last if self.coach_index is None else self.coach_index |
| 108 | + self.coach_label.set_markup(self.coach_log[index]["markup"]) |
| 109 | + self.coach_nav.set_visible(last > 0) |
| 110 | + self.coach_prev.set_sensitive(index > 0) |
| 111 | + self.coach_next.set_sensitive(index < last) |
| 112 | + self.coach_last.set_sensitive(index < last) |
| 113 | + self.coach_button.set_visible(self.final_text is not None and index == last) |
| 78 | 114 | self.coach.set_reveal_child(True) |
| 79 | 115 | |
| 116 | + def _coach_step(self, delta): |
| 117 | + last = len(self.coach_log) - 1 |
| 118 | + index = (last if self.coach_index is None else self.coach_index) + delta |
| 119 | + index = max(0, min(last, index)) |
| 120 | + self.coach_index = None if index == last else index |
| 121 | + ply = self.coach_log[index]["ply"] |
| 122 | + current = len(self.board.move_stack) - 1 |
| 123 | + # zurückgeblättert: Brett zeigt die Stellung zur Rückmeldung, ziehen erst wieder am aktuellen Zug |
| 124 | + self.browse_ply = None if self.coach_index is None or ply >= current else ply |
| 125 | + self._refresh() |
| 126 | + self._coach_show() |
| 127 | + |
| 128 | + def _coach_latest(self): |
| 129 | + self.coach_index = None |
| 130 | + self.browse_ply = None |
| 131 | + self._refresh() |
| 132 | + self._coach_show() |
| 133 | + |
| 80 | 134 | def _opening_title(self): |
| 81 | 135 | return self.course.title if self.course else "Eröffnung" |
| 82 | 136 | |
| @@ -152,6 +206,7 @@ class OpeningMixin: |
| 152 | 206 | self.save_path = "" |
| 153 | 207 | self.view.flipped = self.human == chess.BLACK |
| 154 | 208 | self.list_btn.set_active(False) |
| 209 | + self.coach_log = [] |
| 155 | 210 | self._coach(_escape(notation.text(course.welcome or course.intro, self._notation()))) |
| 156 | 211 | self._changed() |
| 157 | 212 | self._refresh() |
| @@ -160,6 +215,8 @@ class OpeningMixin: |
| 160 | 215 | def _opening_leave(self): |
| 161 | 216 | self.course = None |
| 162 | 217 | self.opening_busy = False |
| 218 | + self.coach_log = [] |
| 219 | + self.coach_index = None |
| 163 | 220 | self.coach.set_reveal_child(False) |
| 164 | 221 | self.coach_button.set_visible(False) |
| 165 | 222 | |
| @@ -234,7 +291,8 @@ class OpeningMixin: |
| 234 | 291 | name = f" – das ist {_escape(verdict.name)}" if verdict.name else "" |
| 235 | 292 | self._opening_off(ply, f"<b>{label}</b> ist spielbar{name}. Wir üben hier aber einen anderen Plan.") |
| 236 | 293 | return |
| 237 | | - self._coach(f"<b>{label}</b> … Moment, ich schaue mir den Zug an.") |
| 294 | + # gehört zur Stellung vor dem Fehlzug – der wird ja gleich zurückgenommen |
| 295 | + self._coach(f"<b>{label}</b> … Moment, ich schaue mir den Zug an.", ply=ply - 1) |
| 238 | 296 | gen = self.gen |
| 239 | 297 | |
| 240 | 298 | def on_result(result, error): |
| @@ -251,12 +309,15 @@ class OpeningMixin: |
| 251 | 309 | text = f"<b>{label}</b> ?! – ungenau. Das ist kein Buchzug, und es gibt Besseres." |
| 252 | 310 | else: |
| 253 | 311 | text = f"<b>{label}</b> ist kein Buchzug, aber in Ordnung. Wir üben hier aber einen anderen Plan." |
| 254 | | - self._opening_off(ply, text) |
| 312 | + self._opening_off(ply, text, replace=True) |
| 255 | 313 | |
| 256 | 314 | self.stockfish.submit(annotate.fallback_job(before, move), on_result) |
| 257 | 315 | |
| 258 | | - def _opening_off(self, ply, markup): |
| 259 | | - self._coach(f"{markup} Versuch es nochmal! <span alpha='70%'>Tipp: Der Hinweis (H) zeigt dir den Kurszug.</span>") |
| 316 | + def _opening_off(self, ply, markup, replace=False): |
| 317 | + self._coach( |
| 318 | + f"{markup} Versuch es nochmal! <span alpha='70%'>Tipp: Der Hinweis (H) zeigt dir den Kurszug.</span>", |
| 319 | + ply=ply - 1, replace=replace, |
| 320 | + ) |
| 260 | 321 | self._refresh() |
| 261 | 322 | GLib.timeout_add(TAKE_BACK_MS, self._opening_take_back, self.gen, ply) |
| 262 | 323 | |
| @@ -267,6 +328,7 @@ class OpeningMixin: |
| 267 | 328 | self.symbols.pop(ply, None) |
| 268 | 329 | self.badge_ply = None |
| 269 | 330 | self.opening_busy = False |
| 331 | + self.browse_ply = None |
| 270 | 332 | self._changed() |
| 271 | 333 | self._refresh() |
| 272 | 334 | return False |
| @@ -290,8 +352,8 @@ class OpeningMixin: |
| 290 | 352 | parts.append(f"{hints} Hinweis" + ("e" if hints > 1 else "")) |
| 291 | 353 | summary = f"Ziel erreicht – mit {' und '.join(parts)}." |
| 292 | 354 | self.final_text = summary |
| 293 | | - self.coach_button.set_visible(True) |
| 294 | 355 | self._refresh() |
| 356 | + self._coach_show() |
| 295 | 357 | |
| 296 | 358 | def _opening_again(self, *_): |
| 297 | 359 | if self.course is not None: |
| @@ -315,5 +377,6 @@ class OpeningMixin: |
| 315 | 377 | self.final_text = None |
| 316 | 378 | self.end_shown = False |
| 317 | 379 | self.opening_busy = False |
| 318 | | - self.coach_button.set_visible(False) |
| 380 | + plies = len(self.board.move_stack) |
| 381 | + self.coach_log = [e for e in self.coach_log if e["ply"] < plies] |
| 319 | 382 | self._coach("Zurückgenommen – du bist wieder am Zug.") |