Mouse control package 4: fire buttons with confirmation, OPZ chips, sonar clicks, dip contact rows

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tk5v1FfvkLKPYqPVE98DaY
This commit is contained in:
Claude committed 2026-10-06 20:24:58 +00:00
1 parent 9653acc04b
commit b2be5e4a64
20 files changed
+308 -27

No files matched your search

+10
View File
@@ -2968,6 +2968,11 @@
"helo.waypoint_rule": "WEGPUNKT rechtweisend {bearing}° | Entfernung {range} sm",
"helo.rtb_margin": "RTB-MARGE {margin} min | Q/E Kartenzoom",
"helo.launch_rule": "H: Start / Rückkehr | ←/→ Wegpunkt-Peilung | ↑/↓ Abstand",
"fire.confirm": "nochmal klicken: Feuer",
"fire.essm": "ESSM starten",
"fire.mpa_torpedo": "Torpedo abwerfen",
"fire.consort_asroc": "Zerstörer feuert ASROC",
"fire.helo_torpedo": "Lufttorpedo abwerfen",
"helo.weapon_controls": "B: Sonarboje | Strg+Eingabe: Lufttorpedo",
"sonar.status.array": "ARRAY {array} | TAS {state} {payout}% {ready}{pause}",
"sonar.status.array.short": "{array} | TAS {state} {payout}% {ready}{pause}",
@@ -5862,6 +5867,7 @@
"opz.mpa.pattern": "Muster {pattern}: noch {count}",
"opz.mpa.keys_orders": "H anfordern / zurück (wie Helikopter)",
"opz.mpa.keys_buoys": "X Muster · B Boje · Umschalt+B Modus",
"opz.mpa.keys_pattern_stop": "Umschalt+X Bojenmuster abbrechen",
"opz.mpa.keys_weapons": "Strg+R Radar · Umschalt+M MAD · D Torpedo (Strg+Eingabe)",
"help.control.mpa_request": "OPZ Seite 3: Seefernaufklärer anfordern / heimschicken (Tasten wie beim Helikopter)",
"help.control.mpa_waypoint": "Seite 3: Suchgebiet auf die gewählte Spur (sonst eigenes Schiff); Klick in die Karte für einen Punkt",
@@ -8068,6 +8074,10 @@
"sonar.keys.target": "Ziel",
"sonar.keys.tas": "Schleppsonar",
"sonar.keys.vds": "VDS",
"opz.keys.track_number": "Tracknummer",
"opz.keys.dissolve": "Fusion lösen",
"opz.keys.suppress": "Track unterdrücken",
"opz.keys.show_suppressed": "Unterdrückte zeigen",
"opz.keys.designate": "Ziel zuweisen",
"opz.keys.chaff": "Chaff",
"opz.keys.asm_track": "ASM-Track",
+10
View File
@@ -2968,6 +2968,11 @@
"helo.waypoint_rule": "WAYPOINT TRUE/NORTH {bearing}° | Range {range} NM",
"helo.rtb_margin": "RTB MARGIN {margin} min | Q/E chart zoom",
"helo.launch_rule": "H: launch / return | ←/→ waypoint bearing | ↑/↓ range",
"fire.confirm": "click again to fire",
"fire.essm": "launch ESSM",
"fire.mpa_torpedo": "drop torpedo",
"fire.consort_asroc": "consort fires ASROC",
"fire.helo_torpedo": "drop air torpedo",
"helo.weapon_controls": "B: sonobuoy | Ctrl+Enter: air torpedo",
"sonar.status.array": "ARRAY {array} | TAS {state} {payout}% {ready}{pause}",
"sonar.status.array.short": "{array} | TAS {state} {payout}% {ready}{pause}",
@@ -5862,6 +5867,7 @@
"opz.mpa.pattern": "Pattern {pattern}: {count} to go",
"opz.mpa.keys_orders": "H request / return (as the helicopter)",
"opz.mpa.keys_buoys": "X pattern · B buoy · Shift+B mode",
"opz.mpa.keys_pattern_stop": "Shift+X stop the buoy pattern",
"opz.mpa.keys_weapons": "Ctrl+R radar · Shift+M MAD · D torpedo (Ctrl+Enter)",
"help.control.mpa_request": "OPZ page 3: request the patrol aircraft / send it home (keys as the helicopter)",
"help.control.mpa_waypoint": "Page 3: search area on the selected track (else own ship); click the chart for a point",
@@ -8068,6 +8074,10 @@
"sonar.keys.target": "Target",
"sonar.keys.tas": "Towed array",
"sonar.keys.vds": "VDS",
"opz.keys.track_number": "Track number",
"opz.keys.dissolve": "Dissolve fusion",
"opz.keys.suppress": "Suppress track",
"opz.keys.show_suppressed": "Show suppressed",
"opz.keys.designate": "Assign target",
"opz.keys.chaff": "Chaff",
"opz.keys.asm_track": "ASM track",
+2
View File
@@ -135,6 +135,8 @@ Jede Taste in der Tastenleiste am Fuß der Station lässt sich anklicken; gedrü
- Die Tastenchips unter den Karten wirken auf den gewählten Kontakt: `C` klassifizieren, `T` TMA, `G` Freigabe an die OPZ, `M` Ziel, `Y`/`Umschalt+Y` Schleppsonar und VDS ausbringen oder einholen.
- Ein Klick auf den BROADBAND-Wasserfall richtet die Hörpeilung dorthin oder auf einen Kontakt, der höchstens eine halbe Keulenbreite vom Klick entfernt liegt.
- Ein Klick auf einen Seitenreiter öffnet diese Seite.
- Ein Klick in die LOFAR- oder DEMON-Anzeige setzt den weißen Cursor auf diese Frequenz, wie `Z`/`X`.
- Die linke Hälfte des Chips GAIN senkt die Verstärkung wie `I`, die rechte hebt sie wie `O`.
## Standardablauf {#sonar-sop}
+2
View File
@@ -134,6 +134,8 @@ Every key in the key bar at the foot of the station can be clicked; holding the
- The key chips under the cards act on the selected contact: `C` classify, `T` TMA, `G` release to the CIC, `M` target, `Y`/`Shift+Y` stream or recover the towed array and the VDS.
- A click on the BROADBAND waterfall steers the listening bearing there, or onto a contact within half a beam width of the click.
- A click on a page tab opens that page.
- A click in the LOFAR or DEMON display puts the white cursor on that frequency, like `Z`/`X`.
- The left half of the GAIN chip lowers the gain like `I`, the right half raises it like `O`.
## Standard procedure {#sonar-sop}
+2 -1
View File
@@ -88,7 +88,8 @@ Zwei Schalter oben links in der Karte schalten auf jeder Seite Seeradar und Luft
Jede Taste in der Tastenleiste am Fuß der Station lässt sich anklicken; gedrückt halten hält die Taste. Lampen, Seitenreiter und Tastenhinweise im Text sind ebenfalls anklickbar (Kapitel Werkzeuge, Maus). Außerdem:
- Ein Klick auf eine Trackkarte wählt den Track.
- Die Tastenchips auf der Zielseite weisen das Ziel zu (`M`), werfen Düppel (`G`) und schalten den ASM-Track weiter (`←`/`→`); ESSM feuert nur mit `Strg+Eingabe`.
- Die Tastenchips auf der Zielseite weisen das Ziel zu (`M`), werfen Düppel (`G`) und schalten den ASM-Track weiter (`←`/`→`); die Chips `J`, `H`, `Umschalt+L`, `Entf` und `K` (Folgen) wirken ebenfalls per Klick.
- **Feuerknöpfe:** Der ESSM-Knopf auf der Zielseite, der Torpedoknopf des Seefernaufklärers auf Seite 3 (sichtbar, sobald `D` den Torpedo gewählt hat) und der ASROC-Knopf des Begleiters auf Seite 4 feuern erst beim zweiten Klick: Der erste Klick macht den Knopf scharf (er zeigt "nochmal klicken: Feuer"), ein zweiter Klick innerhalb von 3 s feuert wie `Strg+Eingabe`; sonst entschärft er sich wieder.
- Seite 3: Ein Klick auf die Karte setzt das Suchgebiet des Seefernaufklärers; Seite 4: Ein Klick setzt den Punkt des Begleiters, und seine Befehlstasten im Feld sind anklickbar.
- Seite 5: Ein Klick auf eine Zeile schaltet sie weiter; die Ebenen-Chips unter der Karte und die beiden Radarschalter oben links wirken auf jeder Seite.
- Auf der Karte zoomt das Mausrad, Ziehen verschiebt (und beendet das Folgen mit `K`) und ein Klick heftet eine Kurzinfo an.
+2 -1
View File
@@ -88,7 +88,8 @@ Two switches in the chart's top left turn the surface and air radar on and off o
Every key in the key bar at the foot of the station can be clicked; holding the button holds the key. Lamps, page tabs and key hints in the text are clickable too (chapter Tools, Mouse). In addition:
- A click on a track card selects the track.
- The key chips on the target page assign the target (`M`), launch chaff (`G`) and step the missile track (`←`/`→`); ESSM fires only with `Ctrl+Enter`.
- The key chips on the target page assign the target (`M`), launch chaff (`G`) and step the missile track (`←`/`→`); the chips `J`, `H`, `Shift+L`, `Del` and `K` (follow) work by click too.
- **Fire buttons:** the ESSM button on the target page, the patrol aircraft's torpedo button on page 3 (shown once `D` has chosen the torpedo) and the consort's ASROC button on page 4 fire only on a second click: the first click arms the button (it reads "click again to fire"), a second click within 3 s fires like `Ctrl+Enter`; otherwise it disarms itself.
- Page 3: a click on the chart sets the patrol aircraft's search area; page 4: a click sets the consort's point and its order keys in the panel are clickable.
- Page 5: a click on a row moves it on; the layer chips under the chart and the two radar switches in its top left work on every page.
- On the chart the wheel zooms, dragging pans (it ends `K` follow) and a click pins a tooltip.
+2
View File
@@ -66,6 +66,8 @@ Jede Taste in der Tastenleiste am Fuß der Station lässt sich anklicken; gedrü
- Auf Seite 2 sind die in den Regeln genannten Tasten (`H`, `Y`, `U`/`V`, `Umschalt+A`, `B`, `D`, `Umschalt+B`, `Umschalt+M`, `Strg+R`) Schalter: Ein Klick drückt sie.
- Auf Seite 1 ist die Windenlampe im Feld Rettungswinde ein Schalter für `Z`.
- Auf der Akustikseite schaltet ein Klick auf die Quellenangabe die Hörquelle um.
- Auf Seite 2 feuert der Torpedoknopf den Lufttorpedo erst beim zweiten Klick innerhalb von 3 s (der erste macht ihn scharf), wie `Strg+Eingabe`.
- Auf Seite 3 wählt ein Klick auf eine Kontaktzeile des Tauchsonars diesen Kontakt, wie `Umschalt+↑`/`Umschalt+↓`.
- Auf der Karte zoomt das Mausrad, Ziehen verschiebt (und beendet das Folgen mit `K`) und ein Klick heftet eine Kurzinfo an.
## Standardablauf {#helicopter-sop}
+2
View File
@@ -66,6 +66,8 @@ Every key in the key bar at the foot of the station can be clicked; holding the
- On page 2 the keys named in the rules (`H`, `Y`, `U`/`V`, `Shift+A`, `B`, `D`, `Shift+B`, `Shift+M`, `Ctrl+R`) are switches: a click presses them.
- On page 1 the winch lamp of the rescue hoist panel is a switch for `Z`.
- On the acoustic page a click on the source label switches the listening source.
- On page 2 the torpedo button fires the air torpedo only on a second click within 3 s (the first arms it), like `Ctrl+Enter`.
- On page 3 a click on a contact line of the dipping sonar selects that contact, like `Shift+↑`/`Shift+↓`.
- On the chart the wheel zooms, dragging pans (it ends `K` follow) and a click pins a tooltip.
## Standard procedure {#helicopter-sop}
+6 -1
View File
@@ -707,6 +707,8 @@ Jede Taste in der Tastenleiste am Fuß der Station lässt sich anklicken; gedrü
- Die Tastenchips unter den Karten wirken auf den gewählten Kontakt: `C` klassifizieren, `T` TMA, `G` Freigabe an die OPZ, `M` Ziel, `Y`/`Umschalt+Y` Schleppsonar und VDS ausbringen oder einholen.
- Ein Klick auf den BROADBAND-Wasserfall richtet die Hörpeilung dorthin oder auf einen Kontakt, der höchstens eine halbe Keulenbreite vom Klick entfernt liegt.
- Ein Klick auf einen Seitenreiter öffnet diese Seite.
- Ein Klick in die LOFAR- oder DEMON-Anzeige setzt den weißen Cursor auf diese Frequenz, wie `Z`/`X`.
- Die linke Hälfte des Chips GAIN senkt die Verstärkung wie `I`, die rechte hebt sie wie `O`.
### Standardablauf
@@ -1127,7 +1129,8 @@ Zwei Schalter oben links in der Karte schalten auf jeder Seite Seeradar und Luft
Jede Taste in der Tastenleiste am Fuß der Station lässt sich anklicken; gedrückt halten hält die Taste. Lampen, Seitenreiter und Tastenhinweise im Text sind ebenfalls anklickbar (Kapitel Werkzeuge, Maus). Außerdem:
- Ein Klick auf eine Trackkarte wählt den Track.
- Die Tastenchips auf der Zielseite weisen das Ziel zu (`M`), werfen Düppel (`G`) und schalten den ASM-Track weiter (`←`/`→`); ESSM feuert nur mit `Strg+Eingabe`.
- Die Tastenchips auf der Zielseite weisen das Ziel zu (`M`), werfen Düppel (`G`) und schalten den ASM-Track weiter (`←`/`→`); die Chips `J`, `H`, `Umschalt+L`, `Entf` und `K` (Folgen) wirken ebenfalls per Klick.
- **Feuerknöpfe:** Der ESSM-Knopf auf der Zielseite, der Torpedoknopf des Seefernaufklärers auf Seite 3 (sichtbar, sobald `D` den Torpedo gewählt hat) und der ASROC-Knopf des Begleiters auf Seite 4 feuern erst beim zweiten Klick: Der erste Klick macht den Knopf scharf (er zeigt "nochmal klicken: Feuer"), ein zweiter Klick innerhalb von 3 s feuert wie `Strg+Eingabe`; sonst entschärft er sich wieder.
- Seite 3: Ein Klick auf die Karte setzt das Suchgebiet des Seefernaufklärers; Seite 4: Ein Klick setzt den Punkt des Begleiters, und seine Befehlstasten im Feld sind anklickbar.
- Seite 5: Ein Klick auf eine Zeile schaltet sie weiter; die Ebenen-Chips unter der Karte und die beiden Radarschalter oben links wirken auf jeder Seite.
- Auf der Karte zoomt das Mausrad, Ziehen verschiebt (und beendet das Folgen mit `K`) und ein Klick heftet eine Kurzinfo an.
@@ -1488,6 +1491,8 @@ Jede Taste in der Tastenleiste am Fuß der Station lässt sich anklicken; gedrü
- Auf Seite 2 sind die in den Regeln genannten Tasten (`H`, `Y`, `U`/`V`, `Umschalt+A`, `B`, `D`, `Umschalt+B`, `Umschalt+M`, `Strg+R`) Schalter: Ein Klick drückt sie.
- Auf Seite 1 ist die Windenlampe im Feld Rettungswinde ein Schalter für `Z`.
- Auf der Akustikseite schaltet ein Klick auf die Quellenangabe die Hörquelle um.
- Auf Seite 2 feuert der Torpedoknopf den Lufttorpedo erst beim zweiten Klick innerhalb von 3 s (der erste macht ihn scharf), wie `Strg+Eingabe`.
- Auf Seite 3 wählt ein Klick auf eine Kontaktzeile des Tauchsonars diesen Kontakt, wie `Umschalt+↑`/`Umschalt+↓`.
- Auf der Karte zoomt das Mausrad, Ziehen verschiebt (und beendet das Folgen mit `K`) und ein Klick heftet eine Kurzinfo an.
### Standardablauf
+6 -1
View File
@@ -706,6 +706,8 @@ Every key in the key bar at the foot of the station can be clicked; holding the
- The key chips under the cards act on the selected contact: `C` classify, `T` TMA, `G` release to the CIC, `M` target, `Y`/`Shift+Y` stream or recover the towed array and the VDS.
- A click on the BROADBAND waterfall steers the listening bearing there, or onto a contact within half a beam width of the click.
- A click on a page tab opens that page.
- A click in the LOFAR or DEMON display puts the white cursor on that frequency, like `Z`/`X`.
- The left half of the GAIN chip lowers the gain like `I`, the right half raises it like `O`.
### Standard procedure
@@ -1126,7 +1128,8 @@ Two switches in the chart's top left turn the surface and air radar on and off o
Every key in the key bar at the foot of the station can be clicked; holding the button holds the key. Lamps, page tabs and key hints in the text are clickable too (chapter Tools, Mouse). In addition:
- A click on a track card selects the track.
- The key chips on the target page assign the target (`M`), launch chaff (`G`) and step the missile track (`←`/`→`); ESSM fires only with `Ctrl+Enter`.
- The key chips on the target page assign the target (`M`), launch chaff (`G`) and step the missile track (`←`/`→`); the chips `J`, `H`, `Shift+L`, `Del` and `K` (follow) work by click too.
- **Fire buttons:** the ESSM button on the target page, the patrol aircraft's torpedo button on page 3 (shown once `D` has chosen the torpedo) and the consort's ASROC button on page 4 fire only on a second click: the first click arms the button (it reads "click again to fire"), a second click within 3 s fires like `Ctrl+Enter`; otherwise it disarms itself.
- Page 3: a click on the chart sets the patrol aircraft's search area; page 4: a click sets the consort's point and its order keys in the panel are clickable.
- Page 5: a click on a row moves it on; the layer chips under the chart and the two radar switches in its top left work on every page.
- On the chart the wheel zooms, dragging pans (it ends `K` follow) and a click pins a tooltip.
@@ -1487,6 +1490,8 @@ Every key in the key bar at the foot of the station can be clicked; holding the
- On page 2 the keys named in the rules (`H`, `Y`, `U`/`V`, `Shift+A`, `B`, `D`, `Shift+B`, `Shift+M`, `Ctrl+R`) are switches: a click presses them.
- On page 1 the winch lamp of the rescue hoist panel is a switch for `Z`.
- On the acoustic page a click on the source label switches the listening source.
- On page 2 the torpedo button fires the air torpedo only on a second click within 3 s (the first arms it), like `Ctrl+Enter`.
- On page 3 a click on a contact line of the dipping sonar selects that contact, like `Shift+↑`/`Shift+↓`.
- On the chart the wheel zooms, dragging pans (it ends `K` follow) and a click pins a tooltip.
### Standard procedure
+6
View File
@@ -689,6 +689,12 @@ class OperatorMixin(WeaponOrdersMixin):
self._cycle_sonar_mode()
elif action == "gain":
self._adjust_sonar_gain(3.0)
elif action == "cursor_hz":
value = target.get("value")
if not (isinstance(value, tuple) and len(value) == 2):
return False
if self.set_sonar_cursor(*value) is not True:
return False
elif action == "band_filter":
self._cycle_sonar_band()
elif action == "notch":
+1 -1
View File
@@ -521,7 +521,7 @@ def display_message(kind: str, value: object):
# Strg, Eingabe, Rücktaste, Leertaste, Entf, Bild↑/↓, Pos1 and Ende.
_GERMAN_KEY_NAMES = (("Shift", "Umschalt"), ("Umsch", "Umschalt"), ("Ctrl", "Strg"),
("Enter", "Eingabe"), ("Backspace", "Rücktaste"), ("Bksp", "Rück"),
("Space", "Leertaste"), ("SPACE", "Leertaste"), ("Delete", "Entf"),
("Space", "Leertaste"), ("SPACE", "Leertaste"), ("Delete", "Entf"), ("Del", "Entf"),
("PgUp", "Bild↑"), ("PgDn", "Bild↓"), ("Home", "Pos1"), ("End", "Ende"))
_KEY_NAME_PATTERN = re.compile(r"(?<![\w])(" + "|".join(
english for english, _german in _GERMAN_KEY_NAMES) + r")(?![\w])")
+16 -2
View File
@@ -226,6 +226,11 @@ def _contact_key_rows(game, contacts):
return panel, rows
def _demon_plot(main) -> pygame.Rect:
"""The DEMON spectrum's plot area inside the main panel."""
return pygame.Rect(main.x + 57, main.y + 62, main.w - 83, main.h - 109)
def sonar_click_target(game, pos):
"""Resolve only explicitly safe sonar actions; return no simulation object."""
if pos is None:
@@ -252,6 +257,16 @@ def sonar_click_target(game, pos):
if separation <= threshold:
return {"action": "contact_listen", "value": nearest.id, "safe": True}
return {"action": "listen_bearing", "value": bearing % 360.0, "safe": True}
# LOFAR and DEMON: a click puts the frequency cursor where it lands.
if page == 1 and plot.collidepoint(pos):
axis = (pos[0] - plot.x) / max(1, plot.w - 1)
return {"action": "cursor_hz", "value": ("lofar", axis * config.LOFAR_FMAX_HZ),
"safe": True}
demon = _demon_plot(geometry["main"])
if page == 2 and demon.collidepoint(pos):
axis = (pos[0] - demon.x) / max(1, demon.w - 1)
return {"action": "cursor_hz", "value": ("demon", axis * DEMON_DISPLAY_MAX_HZ),
"safe": True}
if geometry["contacts"].collidepoint(pos):
for item, rect in _list_rows(game, geometry["contacts"], page)[0]:
if rect.collidepoint(pos):
@@ -397,8 +412,7 @@ def sonar_hit_target(game, pos):
if beam is not None else None,
target_id=f"sonar:lofar:{frequency:.1f}")
if page == 2:
plot = pygame.Rect(main.x + 57, main.y + 62, main.w - 83,
main.h - 109)
plot = _demon_plot(main)
if not plot.collidepoint(pos):
return None
frequency = (pos[0] - plot.x) / max(1, plot.w - 1) * DEMON_DISPLAY_MAX_HZ
+3 -3
View File
@@ -1286,9 +1286,9 @@ def draw_sonar_view(game, tr=None) -> None:
rect = segment["rect"]
layout.record_geometry("sonar-action", rect,
f"sonar:action:{segment['action']}")
if segment["action"] == "cursor":
# Cursor and TMA hypothesis: the chip presses its keys (left
# half the first, right half the second), as the keyboard does.
if segment["action"] in ("cursor", "gain"):
# Cursor, TMA hypothesis and gain: the chip presses its keys
# (left half the first, right half the second), as the keyboard does.
pointer.add_legend(rect, _CURSOR_KEYS.get(segment["text"][0],
segment["text"][0]))
elif not (segment["action"] == "array" # the boat's array: a readout
+31
View File
@@ -139,6 +139,37 @@ def _shortcut_footer(screen, rect, specs) -> None:
pointer.add_action(segment, page)
# Fire by click outside the weapons station needs a second click: the first
# arms the button for FIRE_CONFIRM_S wall seconds, the second presses
# Ctrl+Enter, which passes the same checks as the key.
FIRE_CONFIRM_S = 3.0
def fire_armed(game, fire_id: str) -> bool:
armed = getattr(game, "_fire_armed", None)
return (armed is not None and armed[0] == fire_id
and 0.0 <= game._t - armed[1] < FIRE_CONFIRM_S)
def fire_click(game, fire_id: str) -> None:
if not fire_armed(game, fire_id):
game._fire_armed = (fire_id, game._t)
return
game._fire_armed = None
for kind in (pygame.KEYDOWN, pygame.KEYUP):
game.handle_event(pygame.event.Event(kind, key=pygame.K_RETURN,
mod=pygame.KMOD_CTRL, unicode="\r",
scancode=0))
def fire_button(game, screen, rect, label, fire_id: str) -> None:
"""A Ctrl+Enter button that fires on a confirming second click."""
armed = fire_armed(game, fire_id)
layout.key_button(screen, rect, "Ctrl+Enter", "fire.confirm" if armed else label,
size=14, min_size=11, active=armed)
pointer.add_action(rect, lambda _pos: fire_click(game, fire_id))
def list_window(screen, rect, first: int, shown: int, total: int,
up="↑", down="↓") -> None:
"""One row under a scrolling list: which part of it is on show, and that
+25 -7
View File
@@ -16,7 +16,7 @@ from src.air import helicopter as helicopter_physics
from src.ui.stations.common import (_panel, _shortcut_footer, _station_content_top,
draw_station_page_tabs, message)
draw_station_page_tabs, fire_button, message)
from src.ui.stations.opz import (_helo_dip_contact_line, helo_dip_contacts)
@@ -180,6 +180,11 @@ _HELO_ACOUSTIC_TABS = ("helo.acoustic.tab_broadband", "helo.acoustic.tab_lofar",
"helo.acoustic.tab_demon")
def _select_dip_contact(game, contact):
if contact.target_id in game.sonar.contacts:
game.selected_contact = contact
def _helicopter_acoustic_observations(game):
source = game.helo_listen_source
observations = []
@@ -898,7 +903,7 @@ def draw_helicopter_view(game, tr=None) -> None:
tokens = ((), (("Q/E", "Q/E"),),
(("H:", "H"), ("←/→", "←/→"), ("↑/↓", "↑/↓")),
(("Y", "Y"), ("U/V", "U/V"), ("Shift+A", "Shift+A")),
(("B:", "B"), ("Ctrl+Enter:", None)),
(("B:", "B"),),
(("Shift+↑/↓", None), ("G", "G")),
(("Buoys:", "Shift+B"), ("Bojen:", "Shift+B"), ("MAD", "Shift+M")),
(("Radar", "Ctrl+R"),), ())
@@ -914,6 +919,10 @@ def draw_helicopter_view(game, tr=None) -> None:
pointer.add_token_keys((mx, line_y, mw, block_h), text, 18, keys, min_size=16,
screen=s)
line_y += block_h + 4
if line_y + 28 <= regions["rules"].bottom - 6:
# The air torpedo fires by this button on a confirming second click.
fire_button(game, s, (mx, line_y + 2, min(mw, 420), 26),
"fire.helo_torpedo", "helo_torpedo")
elif page == 2:
plot = layout.box(s, regions["rules"], "helo.dip_sonar")
px, py, pw, ph = plot
@@ -951,6 +960,7 @@ def draw_helicopter_view(game, tr=None) -> None:
gauge_text_w, 26),
config.COLOR_TEXT, size=15)
lines = []
owners = [] # the contact of each line, for a click
source_label = localize("helo.source.buoy" if getattr(game, "helo_sensor_source", "DIP") == "BUOY"
else "helo.source.dip")
layout.blit_line(s, source_label, (px + 8, py + 4, int(pw * .55), 22),
@@ -983,6 +993,7 @@ def draw_helicopter_view(game, tr=None) -> None:
int(center_y - math.cos(theta) * radius))
pygame.draw.line(s, config.COLOR_OK,
(int(center_x), int(center_y)), end, 2)
owners.append(contact)
lines.append(message("helo.dip_passive_line", contact=label,
bearing=f"{contact.dip_bearing:05.1f}",
error=f"{contact.dip_bearing_uncertainty_deg:.1f}",
@@ -998,6 +1009,7 @@ def draw_helicopter_view(game, tr=None) -> None:
max(3, min(radius, int(radius * fix["uncertainty_nm"] / 20.0))), 1)
pygame.draw.circle(s, config.COLOR_WARN,
marker, 5)
owners.append(contact)
lines.append(message("helo.dip_active_line", contact=label,
range=f"{distance:.1f}",
range_error=f"{fix['uncertainty_nm']:.1f}",
@@ -1008,6 +1020,7 @@ def draw_helicopter_view(game, tr=None) -> None:
for seq, row in sorted(contact.buoy_reports.items()):
if not 0 <= game.sim_t - row["measured_at"] < config.SONAR_CONTACT_LOST_S:
continue
owners.append(contact)
lines.append(message("helo.buoy_report_line", buoy=f"SB{seq:02d}",
contact=label, bearing=f"{row['bearing']:05.1f}",
range=(f"{row['range_nm']:.1f} {nm_unit()}"
@@ -1032,9 +1045,15 @@ def draw_helicopter_view(game, tr=None) -> None:
line_h = max(22, layout.font(15).get_linesize() + 2)
list_y = gauge_y + gauge_h + 18
for index, line in enumerate(lines[:max(1, int((py + ph - list_y) / line_h))]):
layout.blit_line(s, line, (int(px + pw * .62), list_y + index * line_h,
int(pw * .38), line_h),
config.COLOR_TEXT, size=15)
row = pygame.Rect(int(px + pw * .62), list_y + index * line_h,
int(pw * .38), line_h)
owner = owners[index] if index < len(owners) else None
if owner is not None:
# A click selects the line's contact, like Shift+Up/Down.
if owner is game.selected_contact:
pygame.draw.rect(s, config.COLOR_TAB_ACTIVE, row)
pointer.add_action(row, lambda _pos, c=owner: _select_dip_contact(game, c))
layout.blit_line(s, line, row, config.COLOR_TEXT, size=15)
else:
_draw_helicopter_acoustic_view(game, regions["rules"])
if page < len(HELICOPTER_FOOTER):
@@ -1043,8 +1062,7 @@ def draw_helicopter_view(game, tr=None) -> None:
HELICOPTER_FOOTER[page])
# Per page; Ctrl+Enter (the air torpedo) stays a key: fire by click only at
# the weapons station.
# Per page; the air torpedo fires by its button on the rules page.
HELICOPTER_FOOTER = (
(("H", "helo.footer.launch"), ("Z", "helo.footer.hoist"),
("Ctrl+R", "helo.footer.radar"), ("Q/E", "footer.zoom"), ("K", "footer.follow")),
+24 -7
View File
@@ -24,6 +24,7 @@ from src.ui.stations import opz_display_view
from src.ui.stations.common import (
fire_button,
list_window,
_observation_bearing,
_observation_position,
@@ -486,6 +487,7 @@ def _draw_mpa_sidebar(game, s, x, py, w, bottom) -> int:
("opz.mpa.keys_orders", (("H", "H"),)),
("opz.mpa.keys_area", (("W", "W"),)),
("opz.mpa.keys_buoys", (("X", "X"), ("B", "B"), ("Shift+B", "Shift+B"))),
("opz.mpa.keys_pattern_stop", (("Shift+X", "Shift+X"),)),
("opz.mpa.keys_weapons", (("Ctrl+R", "Ctrl+R"), ("Strg+R", "Ctrl+R"),
("Shift+M", "Shift+M"), ("D", "D"),
("(Ctrl+Enter)", None)))):
@@ -505,15 +507,20 @@ def _draw_mpa_sidebar(game, s, x, py, w, bottom) -> int:
size=14, min_size=11, active=chosen == "mpa_torpedo")
pointer.add_key(chip, pygame.K_d)
py += 28
if chosen == "mpa_torpedo" and py + 26 <= bottom:
fire_button(game, s, (x, py + 2, w, 24), "fire.mpa_torpedo", "mpa_torpedo")
py += 30
return py
OPZ_TARGET_KEYS = ((("M", "opz.keys.designate"), ("G", "opz.keys.chaff")),
(("←/→", "opz.keys.asm_track"), ("I", "opz.keys.ciws")),
(("R", "opz.keys.surface_radar"), ("Shift+R", "opz.keys.air_radar")))
(("R", "opz.keys.surface_radar"), ("Shift+R", "opz.keys.air_radar")),
(("J", "opz.keys.track_number"),), (("H", "opz.keys.show_suppressed"),),
(("Shift+L", "opz.keys.dissolve"),), (("Del", "opz.keys.suppress"),))
# The consort's order hints: each key in them is a switch. Ctrl+Enter (its
# ASROC) is not: fire by click only at the weapons station.
# The consort's order hints: each key in them is a switch. Its ASROC fires
# by the button below them, on a confirming second click.
CONSORT_KEY_TOKENS = {
"opz.group.keys_orders": (("Y", "Y"), ("F", "F"), ("H", "H")),
"opz.group.keys_point": (("X", "X"), ("W", "W")),
@@ -614,6 +621,9 @@ def _draw_consort_sidebar(game, s, x, py, w, bottom) -> int:
pointer.add_token_keys((x, py, w, 22), key, 14, CONSORT_KEY_TOKENS[key],
screen=s)
py += 24
if py + 28 <= bottom:
fire_button(game, s, (x, py + 2, w, 24), "fire.consort_asroc", "consort_asroc")
py += 30
return py
@@ -1308,11 +1318,13 @@ def draw_opz_view(game, tr=None) -> None:
size=16)
py += 26
content_bottom = regions["classify"].top - 7
# The target page's orders as key chips (full mouse control); the
# ESSM fire key stays a key: fire by click only at the weapons station.
# The target page's orders as key chips (full mouse control); ESSM
# fires by its button on a confirming second click.
keys_top = content_bottom - len(OPZ_TARGET_KEYS) * 24
for index, specs in enumerate(OPZ_TARGET_KEYS):
_shortcut_footer(s, (x, keys_top + index * 24 + 2, w, 22), specs)
keys_top -= 28
fire_button(game, s, (x, keys_top + 2, w, 24), "fire.essm", "essm")
content_bottom = keys_top - 4
if asm_tracks:
n = len(asm_tracks)
@@ -1358,7 +1370,12 @@ def draw_opz_view(game, tr=None) -> None:
layout.command_segment(s, range_rect, "Q/E", "opz.footer.range", "",
f"{max_nm:g} NM {scales}", size=11)
pointer.add_legend(range_rect, "Q/E")
# K: the chart follows own ship (or stays where it was panned).
follow_w = layout.text_width(layout.font(11), "K " + localize("footer.follow")) + 24
follow_rect = pygame.Rect(range_rect.right + 6, footer_rect.y, follow_w, footer_rect.h)
layout.command_segment(s, follow_rect, "K", "footer.follow", size=11)
pointer.add_legend(follow_rect, "K")
# Layer chips: what the chart draws now; a click moves one on.
opz_display_view.draw_chips(game, s, pygame.Rect(
range_rect.right + 8, footer_rect.y + 1,
footer_rect.right - range_rect.right - 8, footer_rect.h - 2))
follow_rect.right + 8, footer_rect.y + 1,
footer_rect.right - follow_rect.right - 8, footer_rect.h - 2))
+70
View File
@@ -0,0 +1,70 @@
"""Fire by click outside the weapons station needs a confirming second click."""
import pygame
import pytest
from src.core.game import Game
from src.core.station import Station
from src.ui import layout, pointer
from src.ui.stations import common
@pytest.fixture
def game(monkeypatch):
monkeypatch.setattr(pygame.display, "get_window_size", lambda: (1280, 720))
instance = Game(seed=31, start_menu=False, audio_enabled=False, language="de")
yield instance
instance.commander.stop()
instance.audio.shutdown()
layout.configure_for(large_text=False)
def fire_target(game):
game.draw()
return next(t for t in pointer.targets("station") if t.action is not None
and getattr(t.action, "__qualname__", "").startswith("fire_button"))
def click(game, target):
for kind in (pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP):
game.handle_event(pygame.event.Event(kind, button=1, pos=target.rect.center))
@pytest.mark.parametrize("station, page, launcher", (
(Station.OPZ, 1, "launch_essm"),
(Station.HELICOPTER, 1, "launch_helo_torpedo"),
))
def test_first_click_arms_second_fires(game, monkeypatch, station, page, launcher):
fired = []
monkeypatch.setattr(game, launcher, lambda *a, **k: fired.append(launcher))
game.station, game.station_page = station, page
target = fire_target(game)
click(game, target)
assert fired == [] and common.fire_armed(game, game._fire_armed[0])
click(game, fire_target(game))
assert fired == [launcher]
assert not getattr(game, "_fire_armed", None)
def test_the_arming_runs_out(game, monkeypatch):
fired = []
monkeypatch.setattr(game, "launch_essm", lambda *a, **k: fired.append(1))
game.station, game.station_page = Station.OPZ, 1
click(game, fire_target(game))
game._t += common.FIRE_CONFIRM_S + 0.1
click(game, fire_target(game)) # too late: arms again, fires nothing
assert fired == []
def test_mpa_torpedo_button_only_once_chosen(game, monkeypatch):
fired = []
monkeypatch.setattr(game, "mpa_attack", lambda *a, **k: fired.append(1) or "ok")
monkeypatch.setattr(game, "_mpa_order_feedback", lambda result: None)
game.station, game.station_page = Station.OPZ, 2
game.draw()
assert not any(getattr(t.action, "__qualname__", "").startswith("fire_button")
for t in pointer.targets("station") if t.action is not None)
game.opz_weapon = "mpa_torpedo"
click(game, fire_target(game))
click(game, fire_target(game))
assert fired == [1]
+3 -3
View File
@@ -18,9 +18,9 @@ from src.ui import layout, pointer, sonar_hit
from src.ui.stations import common
from src.ui.uboot_view import station_pages
# Fire keys outside the weapons station stay keys (fire by click only at
# station 3): drawn as a cap in the rules text, never a switch.
FIRE_CAPS = {"Ctrl+Enter", "Strg+Eingabe"}
# Every fire key is clickable now: outside the weapons station through a
# button that fires on a confirming second click.
FIRE_CAPS = set()
@pytest.fixture
+85
View File
@@ -0,0 +1,85 @@
"""Package 4 of the mouse plan: the rest of the stations by click."""
import pygame
import pytest
from src.core import config
from src.core.game import Game
from src.core.station import Station
from src.ui import layout, pointer
from src.ui.sonar_hit import _demon_plot, _waterfall_plot, sonar_geometry
@pytest.fixture
def game(monkeypatch):
monkeypatch.setattr(pygame.display, "get_window_size", lambda: (1280, 720))
instance = Game(seed=31, start_menu=False, audio_enabled=False, language="de")
instance.station = Station.SONAR
yield instance
instance.commander.stop()
instance.audio.shutdown()
layout.configure_for(large_text=False)
def geometry(game):
"""The sonar's geometry as the click sees it (full station rect)."""
game.draw()
previous = config.STATION_RECT
config.STATION_RECT = config.FULL_STATION_RECT
try:
return sonar_geometry(game)
finally:
config.STATION_RECT = previous
def click(game, pos):
game.draw()
for kind in (pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP):
game.handle_event(pygame.event.Event(kind, button=1, pos=pos))
def test_a_click_in_lofar_and_demon_sets_the_cursor(game):
game.sonar_page = 1
plot = _waterfall_plot(geometry(game)["main"], 1)
click(game, (plot.x + plot.w // 2, plot.centery))
assert abs(game.sonar_tools.lofar_cursor_hz - config.LOFAR_FMAX_HZ / 2) < 5
game.sonar_page = 2
plot = _demon_plot(geometry(game)["main"])
click(game, (plot.x + plot.w // 4, plot.centery))
assert game.sonar_tools.demon_cursor_hz != 10.0
def test_gain_chip_halves_lower_and_raise(game):
game.sonar_page = 0
game.draw()
lower = next(t.rect for t in pointer.targets("station") if t.key == pygame.K_i)
raise_ = next(t.rect for t in pointer.targets("station") if t.key == pygame.K_o)
assert lower.right <= raise_.x # left half lowers, right half raises
click(game, raise_.center)
assert game.sonar.gain_db == 3.0
click(game, lower.center)
click(game, lower.center)
assert game.sonar.gain_db == -3.0
def test_a_click_on_a_dip_line_selects_its_contact(game):
from src.sonar.contact import Contact
contacts = []
for number, bearing in ((7, 40.0), (8, 200.0)):
current = Contact(number, 7654300 + number, "passiv", "sub")
current.update_passive(bearing, .8, .8, "label", game.sim_t)
current.update_dip_passive(bearing, game.sim_t, 20.0, 30.0, 1.5)
game.sonar.contacts[current.target_id] = current
contacts.append(current)
game.station = Station.HELICOPTER
game.station_page = 2
game.selected_contact = contacts[0]
game.draw()
rows = [t.rect for t in pointer.targets("station")
if t.action is not None and t.key is None and t.rect.x > 700
and t.rect.y > 250 and t.rect.h <= 30]
assert len(rows) >= 2
click(game, rows[1].center)
assert game.selected_contact is contacts[1]
click(game, rows[0].center)
assert game.selected_contact is contacts[0]