mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-11-19 01:52:29 +01:00
Apply live beacon settings and improve station map (#164)
Apply beacon checkbox changes at runtime and keep the aggregate status chip synchronized. Improve explicit station-map navigation, spatial filter overlays, overlay legend, selected-path contrast, and the documented map screenshot.
This commit is contained in:
1 parent
4d96822c0c
commit
d925c83412
61 files changed
+2686
-299
No files matched your search
@@ -319,6 +319,9 @@ map.showPathAnalysis=Streckenanalyse zeigen
|
||||
map.hidePathAnalysis=Streckenanalyse ausblenden
|
||||
map.pathAnalysisHidden=Die Streckenanalyse ist ausgeblendet.
|
||||
map.tilesUnavailable=Kartenkacheln nicht verfügbar — die Netzverbindung prüfen.
|
||||
map.overlayAntenna=Antenne
|
||||
map.overlayFilters=Aktive Filter
|
||||
map.overlayLegendTooltip=Rot: tatsächliche Antennenrichtung, Öffnungswinkel und maximaler QRB. Blau: aktive QTF- und QRB-Filter.
|
||||
path.title=Strecken- und Geländeanalyse
|
||||
path.selectStation=Eine Station wählen, um Strecken- und Geländeanalyse vorzubereiten.
|
||||
path.fromLocator=Vom Locator:
|
||||
|
||||
@@ -328,6 +328,9 @@ map.showPathAnalysis=Show path analysis
|
||||
map.hidePathAnalysis=Hide path analysis
|
||||
map.pathAnalysisHidden=Path analysis is hidden.
|
||||
map.tilesUnavailable=Map tiles unavailable — check the network connection.
|
||||
map.overlayAntenna=Antenna
|
||||
map.overlayFilters=Active filters
|
||||
map.overlayLegendTooltip=Red: actual antenna heading, beamwidth and maximum QRB. Blue: active QTF and QRB filters.
|
||||
path.title=Path / terrain analysis
|
||||
path.selectStation=Select a station to prepare path and terrain analysis.
|
||||
path.fromLocator=From locator:
|
||||
|
||||
@@ -3278,6 +3278,16 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
||||
}),
|
||||
newJoined,
|
||||
reachability);
|
||||
composeMainWindowState.getThreadButtons().registerAction(
|
||||
ChatController.BEACON_STATUS_SOURCE,
|
||||
() -> {
|
||||
chatcontroller.toggleUsableBeacons();
|
||||
return kotlin.Unit.INSTANCE;
|
||||
});
|
||||
composeMainWindowState.getThreadButtons().registerStatusProvider(
|
||||
ChatController.BEACON_STATUS_SOURCE,
|
||||
chatcontroller::currentBeaconStatus);
|
||||
chatcontroller.refreshBeaconStatus();
|
||||
|
||||
/*
|
||||
* The feed, not the window construction, owns the timeline's data from here.
|
||||
@@ -4136,6 +4146,17 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshMapDisplaySettings() {
|
||||
uiDispatcher.runOnUi(() -> {
|
||||
if (composeMainWindowState == null) {
|
||||
return;
|
||||
}
|
||||
composeMainWindowState.refreshMapDisplaySettings();
|
||||
forceChatMemberFilterRefresh();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* No-op since the JavaFX own-QRG text field was removed with the never-shown window.
|
||||
*
|
||||
|
||||
@@ -10,6 +10,8 @@ import androidx.compose.runtime.setValue
|
||||
import kst4contest.controller.On4KstConnectionState
|
||||
import kst4contest.model.ChatPreferences
|
||||
import kst4contest.observe.SimpleRoster
|
||||
import kst4contest.view.compose.map.MapDisplaySettingsState
|
||||
import kst4contest.view.compose.map.MapNavigationState
|
||||
|
||||
/**
|
||||
* Everything the main window draws, in one object.
|
||||
@@ -67,6 +69,19 @@ class MainWindowState(
|
||||
val reachability: ReachabilityState = ReachabilityState(activeBands),
|
||||
) {
|
||||
|
||||
internal val mapNavigation = MapNavigationState()
|
||||
|
||||
internal val mapDisplaySettings = MapDisplaySettingsState(prefs)
|
||||
|
||||
init {
|
||||
stationSelection.explicitSelectionListener = { member, source ->
|
||||
when {
|
||||
source == StationSelectionSource.RESET_VIEW -> mapNavigation.resetToHome()
|
||||
member != null -> StationIdentity.of(member)?.let(mapNavigation::fitSelectedPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Explicit map analysis requested from either station context menu. */
|
||||
val mapReachability = MapReachabilityState(prefs.stn_loginLocatorMainCat.orEmpty())
|
||||
|
||||
@@ -111,9 +126,15 @@ class MainWindowState(
|
||||
|
||||
/** Applies only a deliberate QTF filter entry, never a restored or reset filter value. */
|
||||
fun applyExplicitQtfFilterDirection(qtf: Double) {
|
||||
mapNavigation.centerOnQtf(qtf)
|
||||
applyExplicitQtfHeading(prefs, qtf)
|
||||
}
|
||||
|
||||
/** Refreshes map geometry after the Station settings draft has been applied. */
|
||||
fun refreshMapDisplaySettings() {
|
||||
mapDisplaySettings.refreshFromPreferences()
|
||||
}
|
||||
|
||||
fun requestLayoutSave() {
|
||||
layoutSaveRequested?.invoke()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package kst4contest.view.compose
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import kst4contest.observe.ObservableValue
|
||||
import java.util.function.Consumer
|
||||
@@ -35,3 +39,19 @@ class ObservedValue<T>(private val source: ObservableValue<T>) {
|
||||
source.removeListener(follower)
|
||||
}
|
||||
}
|
||||
|
||||
/** Observes a domain value only for the lifetime of the current composition. */
|
||||
@Composable
|
||||
internal fun <T> ObservableValue<T>.observeAsState(): State<T?> {
|
||||
val state = remember(this) { mutableStateOf(get()) }
|
||||
|
||||
DisposableEffect(this) {
|
||||
val follower = Consumer<T> { updated -> state.value = updated }
|
||||
addListener(follower)
|
||||
// Close the gap between the initial read and listener registration.
|
||||
state.value = get()
|
||||
onDispose { removeListener(follower) }
|
||||
}
|
||||
|
||||
return state
|
||||
}
|
||||
@@ -62,6 +62,9 @@ interface SettingsHost {
|
||||
*/
|
||||
fun refreshSo2rState()
|
||||
|
||||
/** Pushes applied antenna-beam geometry into the open Compose map. */
|
||||
fun refreshMapDisplaySettings()
|
||||
|
||||
/** Rebuilds the Ctrl+1..Ctrl+0 context menus from the snippet list. */
|
||||
fun refreshTextSnippetContextMenusFromSettings()
|
||||
|
||||
@@ -148,6 +151,8 @@ fun buildSettingsTabs(
|
||||
applySecondCategory = { category -> controller.setChatCategorySecondChat(category) },
|
||||
connectionState = connectionState,
|
||||
applySecondRotator = { controller.reconfigureSecondRotator(); host.refreshSo2rState() },
|
||||
refreshBeaconStatus = controller::refreshBeaconStatus,
|
||||
applyMapDisplaySettings = host::refreshMapDisplaySettings,
|
||||
)
|
||||
|
||||
val notificationState = NotificationTabState(
|
||||
@@ -185,6 +190,8 @@ fun buildSettingsTabs(
|
||||
draft,
|
||||
validateBeaconTemplate = { template -> controller.validateBeaconTemplate(template) },
|
||||
restartBeaconTimer = { controller.restartBeaconTimer() },
|
||||
setMainBeaconEnabled = controller::setMainBeaconEnabled,
|
||||
setSecondBeaconEnabled = controller::setSecondBeaconEnabled,
|
||||
mainCategoryName = categoryName(controller.chatCategoryMain, kst4contest.view.i18n.CurrentStrings.get().settingsCategoryMainFallback),
|
||||
secondCategoryName = categoryName(controller.chatCategorySecondChat, kst4contest.view.i18n.CurrentStrings.get().settingsCategorySecondFallback),
|
||||
)
|
||||
|
||||
@@ -90,6 +90,13 @@ class StationSelectionState : TableSelectionModel<ChatMember> {
|
||||
var lastSource: StationSelectionSource by mutableStateOf(StationSelectionSource.PROGRAMMATIC)
|
||||
private set
|
||||
|
||||
/** Changes only for deliberate station choices, including repeated choices. */
|
||||
var explicitSelectionRevision: Long by mutableStateOf(0L)
|
||||
private set
|
||||
|
||||
/** Receives deliberate station choices without observing roster reconciliation. */
|
||||
internal var explicitSelectionListener: ((ChatMember?, StationSelectionSource) -> Unit)? = null
|
||||
|
||||
val identity: StationIdentity?
|
||||
get() = StationIdentity.of(current)
|
||||
|
||||
@@ -101,6 +108,10 @@ class StationSelectionState : TableSelectionModel<ChatMember> {
|
||||
current = row
|
||||
lastSource = source
|
||||
selectionRevision++
|
||||
if (source.isExplicitSelection()) {
|
||||
explicitSelectionRevision++
|
||||
explicitSelectionListener?.invoke(row, source)
|
||||
}
|
||||
if (row != null && source.requestsStationTableScroll()) {
|
||||
scrollRequestRevision++
|
||||
}
|
||||
@@ -118,6 +129,11 @@ class StationSelectionState : TableSelectionModel<ChatMember> {
|
||||
}
|
||||
}
|
||||
|
||||
private fun StationSelectionSource.isExplicitSelection(): Boolean = when (this) {
|
||||
StationSelectionSource.PROGRAMMATIC -> false
|
||||
else -> true
|
||||
}
|
||||
|
||||
private fun StationSelectionSource.requestsStationTableScroll(): Boolean = when (this) {
|
||||
StationSelectionSource.STATION_TABLE,
|
||||
StationSelectionSource.STATION_CONTEXT_MENU,
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.TooltipArea
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||
@@ -25,6 +26,7 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
@@ -39,11 +41,9 @@ import kst4contest.controller.On4KstConnectionState
|
||||
* only the indicators are left here — which is also what finally makes the bar wrap
|
||||
* properly on a narrow window instead of pushing the badges out of sight.
|
||||
*
|
||||
* Nothing in this bar is clickable. The three indicators were mouse-transparent and
|
||||
* non-focusable in JavaFX and stay that way: the operator is typing into the chat, and a
|
||||
* status badge must never take the keyboard. The background-thread buttons were ordinary
|
||||
* focusable Buttons there, with no action attached — they are drawn as plain labels here,
|
||||
* which is what they always behaved like.
|
||||
* The connection and notice indicators remain non-clickable. A background-thread status is
|
||||
* actionable only when the application explicitly registers an action for that source; the
|
||||
* beacon uses this for its quick switch, while every other worker remains a plain label.
|
||||
*/
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
@@ -206,10 +206,16 @@ private fun ThreadStatusButtonView(button: ThreadStatusButton) {
|
||||
val foreground = if (button.highlighted) scheme.onPrimary else scheme.onSurfaceVariant
|
||||
|
||||
TooltipArea(tooltip = { TooltipCard(button.tooltip) }) {
|
||||
val actionModifier = if (button.hasAction) {
|
||||
Modifier.clickable(role = Role.Button) { button.activate() }
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.defaultMinSize(minHeight = 22.dp)
|
||||
.background(background, NOTICE_SHAPE)
|
||||
.then(actionModifier)
|
||||
.padding(NOTICE_PADDING),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
|
||||
@@ -176,20 +176,34 @@ object StatusIndicators {
|
||||
class ThreadStatusButtons {
|
||||
|
||||
private val bySource = LinkedHashMap<String, ThreadStatusButton>()
|
||||
private val actions = LinkedHashMap<String, () -> Unit>()
|
||||
private val statusProviders = LinkedHashMap<String, () -> ThreadStateMessage>()
|
||||
private val ordered = mutableStateListOf<ThreadStatusButton>()
|
||||
|
||||
val buttons: List<ThreadStatusButton> get() = ordered
|
||||
|
||||
fun update(sourceName: String, message: ThreadStateMessage) {
|
||||
val effectiveMessage = statusProviders[sourceName]?.invoke() ?: message
|
||||
val button = bySource.getOrPut(sourceName) {
|
||||
ThreadStatusButton(sourceName).also { ordered.add(it) }
|
||||
ThreadStatusButton(sourceName, actions[sourceName]).also { ordered.add(it) }
|
||||
}
|
||||
button.report(
|
||||
label = "$sourceName: ${message.runningInformationTextDescription}",
|
||||
tooltip = message.runningInformation.orEmpty(),
|
||||
label = "$sourceName: ${effectiveMessage.runningInformationTextDescription}",
|
||||
tooltip = effectiveMessage.runningInformation.orEmpty(),
|
||||
)
|
||||
}
|
||||
|
||||
/** Gives one status source an explicit action without changing any other source. */
|
||||
fun registerAction(sourceName: String, action: () -> Unit) {
|
||||
actions[sourceName] = action
|
||||
bySource[sourceName]?.setAction(action)
|
||||
}
|
||||
|
||||
/** Resolves a status only when its queued UI update is actually applied. */
|
||||
fun registerStatusProvider(sourceName: String, provider: () -> ThreadStateMessage) {
|
||||
statusProviders[sourceName] = provider
|
||||
}
|
||||
|
||||
companion object {
|
||||
/** How long the flash stays on; JavaFX used a 0.2 s PauseTransition. */
|
||||
const val HIGHLIGHT_MILLIS = 200L
|
||||
@@ -197,7 +211,10 @@ class ThreadStatusButtons {
|
||||
}
|
||||
|
||||
/** One background thread's button. */
|
||||
class ThreadStatusButton(val sourceName: String) {
|
||||
class ThreadStatusButton(
|
||||
val sourceName: String,
|
||||
initialAction: (() -> Unit)? = null,
|
||||
) {
|
||||
|
||||
var label: String by mutableStateOf(sourceName)
|
||||
private set
|
||||
@@ -212,6 +229,12 @@ class ThreadStatusButton(val sourceName: String) {
|
||||
var revision: Int by mutableStateOf(0)
|
||||
private set
|
||||
|
||||
var action: (() -> Unit)? by mutableStateOf(initialAction)
|
||||
private set
|
||||
|
||||
val hasAction: Boolean
|
||||
get() = action != null
|
||||
|
||||
internal fun report(label: String, tooltip: String) {
|
||||
this.label = label
|
||||
this.tooltip = tooltip
|
||||
@@ -222,4 +245,15 @@ class ThreadStatusButton(val sourceName: String) {
|
||||
fun clearHighlight() {
|
||||
highlighted = false
|
||||
}
|
||||
|
||||
internal fun setAction(action: () -> Unit) {
|
||||
this.action = action
|
||||
}
|
||||
|
||||
/** Runs the registered action and reports whether this status is actionable. */
|
||||
fun activate(): Boolean {
|
||||
val current = action ?: return false
|
||||
current()
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -112,10 +112,15 @@ fun ComposeStationMap(
|
||||
antennaAzimuthDeg: Double,
|
||||
antennaBeamWidthDeg: Double,
|
||||
maxQrbKm: Double,
|
||||
selectedTarget: MapCallsignRawSnapshot? = markers.firstOrNull {
|
||||
it.callSignRaw() == selectedMarkerCallsign
|
||||
},
|
||||
spatialFilterOverlay: SpatialFilterOverlayState? = null,
|
||||
onMarkerClicked: ((MapCallsignRawSnapshot) -> Unit)?,
|
||||
onMarkerContextRequested: ((List<MapCallsignRawSnapshot>, IntOffset) -> Unit)? = null,
|
||||
workedGrossFields: Set<String> = emptySet(),
|
||||
darkMode: Boolean = true,
|
||||
onCanvasSizeChanged: (Size) -> Unit = { },
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val imageCache = remember { TileBitmapCache() }
|
||||
@@ -147,6 +152,13 @@ fun ComposeStationMap(
|
||||
* one linear pass over a few hundred markers.
|
||||
*/
|
||||
val home = remember(ownLocator6) { homePosition(ownLocator6) }
|
||||
val selectedTargetOutsideMarkers by remember(markers, selectedTarget) {
|
||||
derivedStateOf {
|
||||
selectedTarget?.takeIf { target ->
|
||||
target.hasUsablePosition() && markers.none { it.callSignRaw() == target.callSignRaw() }
|
||||
}
|
||||
}
|
||||
}
|
||||
val clusterResult by remember(markers, groupingEnabled, canvasSize) {
|
||||
derivedStateOf {
|
||||
StationMapClusterer.cluster(
|
||||
@@ -205,17 +217,28 @@ fun ComposeStationMap(
|
||||
Canvas(
|
||||
modifier = modifier
|
||||
.clipToBounds()
|
||||
.onSizeChanged { canvasSize = Size(it.width.toFloat(), it.height.toFloat()) }
|
||||
.onSizeChanged {
|
||||
canvasSize = Size(it.width.toFloat(), it.height.toFloat())
|
||||
onCanvasSizeChanged(canvasSize)
|
||||
}
|
||||
.onGloballyPositioned { canvasCoordinates = it }
|
||||
.onPointerEvent(PointerEventType.Press) { event ->
|
||||
if (event.buttons.isSecondaryPressed) {
|
||||
val local = event.changes.firstOrNull()?.position ?: return@onPointerEvent
|
||||
val viewport = mapState.viewportFor(canvasSize.width, canvasSize.height)
|
||||
val result = StationMapClusterer.cluster(markers, viewport, groupingEnabled)
|
||||
val selectedOutside = selectedTargetOutsideMarkers?.takeIf { marker ->
|
||||
within(
|
||||
local,
|
||||
viewport.screenXWrapped(marker.longitudeDeg()).toFloat(),
|
||||
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
||||
MARKER_HIT_RADIUS_PX,
|
||||
)
|
||||
}
|
||||
val cluster = result.clusters().firstOrNull { candidate ->
|
||||
within(
|
||||
local,
|
||||
viewport.screenX(candidate.centerLon).toFloat(),
|
||||
viewport.screenXWrapped(candidate.centerLon).toFloat(),
|
||||
viewport.screenY(candidate.centerLat).toFloat(),
|
||||
clusterRadiusPx(candidate.size()),
|
||||
)
|
||||
@@ -223,12 +246,14 @@ fun ComposeStationMap(
|
||||
val individual = result.individual().firstOrNull { marker ->
|
||||
within(
|
||||
local,
|
||||
viewport.screenX(marker.longitudeDeg()).toFloat(),
|
||||
viewport.screenXWrapped(marker.longitudeDeg()).toFloat(),
|
||||
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
||||
MARKER_HIT_RADIUS_PX,
|
||||
)
|
||||
}
|
||||
val targets = cluster?.getMarkers() ?: individual?.let(::listOf)
|
||||
val targets = selectedOutside?.let(::listOf)
|
||||
?: cluster?.getMarkers()
|
||||
?: individual?.let(::listOf)
|
||||
val window = canvasCoordinates?.localToWindow(local)
|
||||
if (!targets.isNullOrEmpty() && window != null) {
|
||||
onMarkerContextRequested?.invoke(
|
||||
@@ -281,15 +306,28 @@ fun ComposeStationMap(
|
||||
}
|
||||
}
|
||||
}
|
||||
.pointerInput(markers, groupingEnabled, onMarkerClicked) {
|
||||
.pointerInput(markers, selectedTargetOutsideMarkers, groupingEnabled, onMarkerClicked) {
|
||||
detectTapGestures { offset ->
|
||||
val viewport = mapState.viewportFor(size.width.toFloat(), size.height.toFloat())
|
||||
val result = StationMapClusterer.cluster(markers, viewport, groupingEnabled)
|
||||
|
||||
val selectedOutside = selectedTargetOutsideMarkers?.takeIf { marker ->
|
||||
within(
|
||||
offset,
|
||||
viewport.screenXWrapped(marker.longitudeDeg()).toFloat(),
|
||||
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
||||
MARKER_HIT_RADIUS_PX,
|
||||
)
|
||||
}
|
||||
if (selectedOutside != null) {
|
||||
onMarkerClicked?.invoke(selectedOutside)
|
||||
return@detectTapGestures
|
||||
}
|
||||
|
||||
val hitCluster = result.clusters().firstOrNull { cluster ->
|
||||
within(
|
||||
offset,
|
||||
viewport.screenX(cluster.centerLon).toFloat(),
|
||||
viewport.screenXWrapped(cluster.centerLon).toFloat(),
|
||||
viewport.screenY(cluster.centerLat).toFloat(),
|
||||
clusterRadiusPx(cluster.size()),
|
||||
)
|
||||
@@ -312,14 +350,12 @@ fun ComposeStationMap(
|
||||
val hit = result.individual().firstOrNull { marker ->
|
||||
within(
|
||||
offset,
|
||||
viewport.screenX(marker.longitudeDeg()).toFloat(),
|
||||
viewport.screenXWrapped(marker.longitudeDeg()).toFloat(),
|
||||
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
||||
MARKER_HIT_RADIUS_PX,
|
||||
)
|
||||
}
|
||||
if (hit != null) {
|
||||
onMarkerClicked?.invoke(hit)
|
||||
}
|
||||
if (hit != null) onMarkerClicked?.invoke(hit)
|
||||
}
|
||||
}
|
||||
) {
|
||||
@@ -335,11 +371,34 @@ fun ComposeStationMap(
|
||||
drawRect(color = if (darkMode) MAP_BACKGROUND_DARK else MAP_BACKGROUND_LIGHT)
|
||||
|
||||
drawTiles(viewport, imageCache, darkMode)
|
||||
if (home != null && spatialFilterOverlay != null) {
|
||||
drawSpatialFilterOverlay(
|
||||
viewport = viewport,
|
||||
homeLatitudeDeg = home.first,
|
||||
homeLongitudeDeg = home.second,
|
||||
state = spatialFilterOverlay,
|
||||
darkMode = darkMode,
|
||||
)
|
||||
}
|
||||
drawMaidenheadGrid(viewport, textMeasurer, darkMode)
|
||||
drawWorkedGrossFields(viewport, workedGrossFields)
|
||||
drawBeamAndPath(viewport, home, antennaAzimuthDeg, antennaBeamWidthDeg, maxQrbKm, markers, selectedMarkerCallsign, darkMode)
|
||||
drawBeamAndPath(
|
||||
viewport,
|
||||
home,
|
||||
antennaAzimuthDeg,
|
||||
antennaBeamWidthDeg,
|
||||
maxQrbKm,
|
||||
selectedTarget,
|
||||
darkMode,
|
||||
)
|
||||
drawStations(viewport, clusterResult, selectedMarkerCallsign, textMeasurer, darkMode)
|
||||
drawHover(viewport, hoverPosition, clusterResult, textMeasurer)
|
||||
selectedTargetOutsideMarkers?.let { target ->
|
||||
val x = viewport.screenXWrapped(target.longitudeDeg()).toFloat()
|
||||
val y = viewport.screenY(target.latitudeDeg()).toFloat()
|
||||
drawStationDot(x, y, selected = true, worked = target.worked(), warning = target.warningToMyDirection())
|
||||
drawStationLabel(x, y, target.markerLabel(), target.warningToMyDirection(), textMeasurer, darkMode)
|
||||
}
|
||||
drawHover(viewport, hoverPosition, clusterResult, selectedTargetOutsideMarkers, textMeasurer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -474,8 +533,8 @@ private fun DrawScope.drawMaidenheadGrid(
|
||||
val verticals = sortedSetOf<Float>()
|
||||
val horizontals = sortedSetOf<Float>()
|
||||
for (cell in cells) {
|
||||
verticals.add(viewport.screenX(cell.westLon()).toFloat())
|
||||
verticals.add(viewport.screenX(cell.eastLon()).toFloat())
|
||||
verticals.add(viewport.screenXWrapped(cell.westLon()).toFloat())
|
||||
verticals.add(viewport.screenXWrapped(cell.eastLon()).toFloat())
|
||||
horizontals.add(viewport.screenY(cell.northLat()).toFloat())
|
||||
horizontals.add(viewport.screenY(cell.southLat()).toFloat())
|
||||
}
|
||||
@@ -516,7 +575,7 @@ private fun DrawScope.drawMaidenheadGrid(
|
||||
}
|
||||
|
||||
/* Centred in the cell, the way the stylesheet's translate(-50%, -50%) was. */
|
||||
val centerX = viewport.screenX((cell.westLon() + cell.eastLon()) / 2.0).toFloat()
|
||||
val centerX = viewport.screenXWrapped((cell.westLon() + cell.eastLon()) / 2.0).toFloat()
|
||||
val centerY = viewport.screenY((cell.southLat() + cell.northLat()) / 2.0).toFloat()
|
||||
|
||||
val layout = textMeasurer.measure(cell.locatorLabel(), style = labelStyle)
|
||||
@@ -540,8 +599,7 @@ private fun DrawScope.drawBeamAndPath(
|
||||
antennaAzimuthDeg: Double,
|
||||
antennaBeamWidthDeg: Double,
|
||||
maxQrbKm: Double,
|
||||
markers: List<MapCallsignRawSnapshot>,
|
||||
selectedMarkerCallsign: String?,
|
||||
selectedTarget: MapCallsignRawSnapshot?,
|
||||
darkMode: Boolean,
|
||||
) {
|
||||
if (home == null) {
|
||||
@@ -549,32 +607,40 @@ private fun DrawScope.drawBeamAndPath(
|
||||
}
|
||||
val (homeLat, homeLon) = home
|
||||
|
||||
if (antennaBeamWidthDeg > 0.0 && maxQrbKm > 0.0) {
|
||||
if (isAntennaSectorDrawable(home, antennaAzimuthDeg, antennaBeamWidthDeg, maxQrbKm)) {
|
||||
val polygon = Path()
|
||||
buildBeamPolygon(homeLat, homeLon, antennaAzimuthDeg, antennaBeamWidthDeg, maxQrbKm)
|
||||
.forEachIndexed { index, point ->
|
||||
val x = viewport.screenX(point.second).toFloat()
|
||||
val x = viewport.screenXWrapped(point.second).toFloat()
|
||||
val y = viewport.screenY(point.first).toFloat()
|
||||
if (index == 0) polygon.moveTo(x, y) else polygon.lineTo(x, y)
|
||||
}
|
||||
polygon.close()
|
||||
|
||||
drawPath(path = polygon, color = BEAM_COLOR, alpha = BEAM_FILL_ALPHA, style = Fill)
|
||||
drawPath(path = polygon, color = BEAM_COLOR, style = Stroke(width = BEAM_STROKE_WIDTH_PX))
|
||||
drawPath(path = polygon, color = ANTENNA_OVERLAY_COLOR, alpha = BEAM_FILL_ALPHA, style = Fill)
|
||||
drawPath(path = polygon, color = ANTENNA_OVERLAY_COLOR, style = Stroke(width = BEAM_STROKE_WIDTH_PX))
|
||||
}
|
||||
|
||||
val selected = markers.firstOrNull {
|
||||
it.callSignRaw() == selectedMarkerCallsign && it.hasUsablePosition()
|
||||
}
|
||||
val selected = selectedTarget?.takeIf(MapCallsignRawSnapshot::hasUsablePosition)
|
||||
if (selected != null) {
|
||||
val start = Offset(viewport.screenXWrapped(homeLon).toFloat(), viewport.screenY(homeLat).toFloat())
|
||||
val end = Offset(
|
||||
viewport.screenXWrapped(selected.longitudeDeg()).toFloat(),
|
||||
viewport.screenY(selected.latitudeDeg()).toFloat(),
|
||||
)
|
||||
drawLine(
|
||||
color = if (darkMode) CONNECTION_HALO_DARK else CONNECTION_HALO_LIGHT,
|
||||
alpha = CONNECTION_HALO_ALPHA,
|
||||
start = start,
|
||||
end = end,
|
||||
strokeWidth = CONNECTION_HALO_WIDTH_PX,
|
||||
pathEffect = PathEffect.dashPathEffect(CONNECTION_DASH_PX),
|
||||
)
|
||||
drawLine(
|
||||
color = if (darkMode) CONNECTION_COLOR_DARK else CONNECTION_COLOR_LIGHT,
|
||||
alpha = CONNECTION_ALPHA,
|
||||
start = Offset(viewport.screenX(homeLon).toFloat(), viewport.screenY(homeLat).toFloat()),
|
||||
end = Offset(
|
||||
viewport.screenX(selected.longitudeDeg()).toFloat(),
|
||||
viewport.screenY(selected.latitudeDeg()).toFloat(),
|
||||
),
|
||||
start = start,
|
||||
end = end,
|
||||
strokeWidth = CONNECTION_STROKE_WIDTH_PX,
|
||||
pathEffect = PathEffect.dashPathEffect(CONNECTION_DASH_PX),
|
||||
)
|
||||
@@ -585,9 +651,9 @@ private fun DrawScope.drawBeamAndPath(
|
||||
* home is, and with the beam switched off there was none. A small dot is kept here
|
||||
* deliberately.
|
||||
*/
|
||||
val homeX = viewport.screenX(homeLon).toFloat()
|
||||
val homeX = viewport.screenXWrapped(homeLon).toFloat()
|
||||
val homeY = viewport.screenY(homeLat).toFloat()
|
||||
drawCircle(color = BEAM_COLOR, radius = HOME_RADIUS_PX, center = Offset(homeX, homeY))
|
||||
drawCircle(color = ANTENNA_OVERLAY_COLOR, radius = HOME_RADIUS_PX, center = Offset(homeX, homeY))
|
||||
drawCircle(color = Color.White, radius = HOME_INNER_RADIUS_PX, center = Offset(homeX, homeY))
|
||||
}
|
||||
|
||||
@@ -602,7 +668,7 @@ private fun DrawScope.drawStations(
|
||||
) {
|
||||
for (cluster in clusterResult.clusters()) {
|
||||
drawClusterBubble(
|
||||
x = viewport.screenX(cluster.centerLon).toFloat(),
|
||||
x = viewport.screenXWrapped(cluster.centerLon).toFloat(),
|
||||
y = viewport.screenY(cluster.centerLat).toFloat(),
|
||||
count = cluster.size(),
|
||||
containsWorked = cluster.getMarkers().any { it.worked() },
|
||||
@@ -611,7 +677,7 @@ private fun DrawScope.drawStations(
|
||||
}
|
||||
|
||||
for (marker in clusterResult.individual()) {
|
||||
val x = viewport.screenX(marker.longitudeDeg()).toFloat()
|
||||
val x = viewport.screenXWrapped(marker.longitudeDeg()).toFloat()
|
||||
val y = viewport.screenY(marker.latitudeDeg()).toFloat()
|
||||
val selected = marker.callSignRaw() == selectedMarkerCallsign
|
||||
|
||||
@@ -729,14 +795,23 @@ private fun DrawScope.drawHover(
|
||||
viewport: MapViewport,
|
||||
hoverPosition: Offset?,
|
||||
clusterResult: StationMapClusterer.Result,
|
||||
selectedTargetOutsideMarkers: MapCallsignRawSnapshot?,
|
||||
textMeasurer: TextMeasurer,
|
||||
) {
|
||||
val position = hoverPosition ?: return
|
||||
|
||||
val selectedTargetUnderPointer = selectedTargetOutsideMarkers?.takeIf { marker ->
|
||||
within(
|
||||
position,
|
||||
viewport.screenXWrapped(marker.longitudeDeg()).toFloat(),
|
||||
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
||||
MARKER_HIT_RADIUS_PX,
|
||||
)
|
||||
}
|
||||
val clusterUnderPointer = clusterResult.clusters().firstOrNull { cluster ->
|
||||
within(
|
||||
position,
|
||||
viewport.screenX(cluster.centerLon).toFloat(),
|
||||
viewport.screenXWrapped(cluster.centerLon).toFloat(),
|
||||
viewport.screenY(cluster.centerLat).toFloat(),
|
||||
clusterRadiusPx(cluster.size()),
|
||||
)
|
||||
@@ -744,13 +819,14 @@ private fun DrawScope.drawHover(
|
||||
val markerUnderPointer = clusterResult.individual().firstOrNull { marker ->
|
||||
within(
|
||||
position,
|
||||
viewport.screenX(marker.longitudeDeg()).toFloat(),
|
||||
viewport.screenXWrapped(marker.longitudeDeg()).toFloat(),
|
||||
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
||||
MARKER_HIT_RADIUS_PX,
|
||||
)
|
||||
}
|
||||
|
||||
val text = when {
|
||||
selectedTargetUnderPointer != null -> selectedTargetUnderPointer.tooltipText()
|
||||
|
||||
clusterUnderPointer != null -> MapMarkerClusterTooltip.build(clusterUnderPointer)
|
||||
|
||||
markerUnderPointer != null -> markerUnderPointer.tooltipText()
|
||||
@@ -804,8 +880,8 @@ private fun DrawScope.drawWorkedGrossFields(
|
||||
workedGrossFields: Set<String>,
|
||||
) {
|
||||
visibleWorkedGrossFieldCells(viewport, workedGrossFields).forEach { cell ->
|
||||
val left = viewport.screenX(cell.westLon()).toFloat()
|
||||
val right = viewport.screenX(cell.eastLon()).toFloat()
|
||||
val left = viewport.screenXWrapped(cell.westLon()).toFloat()
|
||||
val right = viewport.screenXWrapped(cell.eastLon()).toFloat()
|
||||
val top = viewport.screenY(cell.northLat()).toFloat()
|
||||
val bottom = viewport.screenY(cell.southLat()).toFloat()
|
||||
val topLeft = Offset(minOf(left, right), minOf(top, bottom))
|
||||
@@ -863,7 +939,7 @@ private fun clusterFontSizePx(count: Int): Float = when {
|
||||
}
|
||||
|
||||
/** Null rather than a guess when the operator has no usable locator configured. */
|
||||
private fun homePosition(ownLocator6: String): Pair<Double, Double>? {
|
||||
internal fun homePosition(ownLocator6: String): Pair<Double, Double>? {
|
||||
if (ownLocator6.length < 4) {
|
||||
return null
|
||||
}
|
||||
@@ -875,6 +951,15 @@ private fun homePosition(ownLocator6: String): Pair<Double, Double>? {
|
||||
}
|
||||
}
|
||||
|
||||
internal fun isAntennaSectorDrawable(
|
||||
home: Pair<Double, Double>?,
|
||||
antennaAzimuthDeg: Double,
|
||||
antennaBeamWidthDeg: Double,
|
||||
maxQrbKm: Double,
|
||||
): Boolean = home != null && antennaAzimuthDeg.isFinite() &&
|
||||
antennaBeamWidthDeg.isFinite() && antennaBeamWidthDeg > 0.0 &&
|
||||
maxQrbKm.isFinite() && maxQrbKm > 0.0
|
||||
|
||||
fun calculateDestinationPoint(
|
||||
startLatDeg: Double,
|
||||
startLonDeg: Double,
|
||||
@@ -982,16 +1067,20 @@ private const val CLUSTER_RADIUS_SMALL_PX = 16f
|
||||
private const val CLUSTER_RADIUS_MEDIUM_PX = 18f
|
||||
private const val CLUSTER_RADIUS_LARGE_PX = 21f
|
||||
|
||||
private val BEAM_COLOR = Color(0xFFFF4D4D)
|
||||
internal val ANTENNA_OVERLAY_COLOR = Color(0xFFFF4D4D)
|
||||
private const val BEAM_FILL_ALPHA = 0.12f
|
||||
private const val BEAM_STROKE_WIDTH_PX = 2f
|
||||
private const val HOME_RADIUS_PX = 6f
|
||||
private const val HOME_INNER_RADIUS_PX = 2f
|
||||
|
||||
private val CONNECTION_COLOR_DARK = Color(0xFF2FD7FF)
|
||||
private val CONNECTION_COLOR_LIGHT = Color(0xFF00A4CF)
|
||||
private const val CONNECTION_ALPHA = 0.85f
|
||||
private const val CONNECTION_STROKE_WIDTH_PX = 2f
|
||||
private val CONNECTION_COLOR_DARK = Color(0xFF52E7FF)
|
||||
private val CONNECTION_COLOR_LIGHT = Color(0xFF007A9E)
|
||||
private val CONNECTION_HALO_DARK = Color.White
|
||||
private val CONNECTION_HALO_LIGHT = Color.Black
|
||||
private const val CONNECTION_ALPHA = 0.98f
|
||||
private const val CONNECTION_HALO_ALPHA = 0.82f
|
||||
private const val CONNECTION_STROKE_WIDTH_PX = 3f
|
||||
private const val CONNECTION_HALO_WIDTH_PX = 5f
|
||||
private val CONNECTION_DASH_PX = floatArrayOf(6f, 6f)
|
||||
|
||||
private val TOOLTIP_BACKGROUND = Color.White.copy(alpha = 0.92f)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package kst4contest.view.compose.map
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import kst4contest.model.ChatPreferences
|
||||
|
||||
/** Compose-observable map geometry read from the active profile. */
|
||||
internal class MapDisplaySettingsState(private val prefs: ChatPreferences) {
|
||||
|
||||
var antennaBeamWidthDeg: Double by mutableStateOf(prefs.stn_antennaBeamWidthDeg)
|
||||
private set
|
||||
|
||||
var maxQrbKm: Double by mutableStateOf(prefs.stn_maxQRBDefault)
|
||||
private set
|
||||
|
||||
fun refreshFromPreferences() {
|
||||
antennaBeamWidthDeg = prefs.stn_antennaBeamWidthDeg
|
||||
maxQrbKm = prefs.stn_maxQRBDefault
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package kst4contest.view.compose.map
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import kst4contest.view.compose.StationIdentity
|
||||
|
||||
/** A deliberate operator action that may move the station-map camera. */
|
||||
internal sealed interface MapNavigationRequest {
|
||||
data class FitSelectedPath(val identity: StationIdentity) : MapNavigationRequest
|
||||
|
||||
data class CenterOnQtf(val qtfDegrees: Double) : MapNavigationRequest
|
||||
|
||||
data object ResetToHome : MapNavigationRequest
|
||||
}
|
||||
/**
|
||||
* The latest deliberate map-navigation request.
|
||||
*
|
||||
* Ordinary model refreshes never write this state. Keeping one monotonically increasing
|
||||
* revision makes repeated selections observable and gives the most recent station or QTF
|
||||
* action deterministic precedence when several actions happen before the map draws.
|
||||
*/
|
||||
internal class MapNavigationState {
|
||||
|
||||
var request: MapNavigationRequest? by mutableStateOf(null)
|
||||
private set
|
||||
|
||||
var requestRevision: Long by mutableStateOf(0L)
|
||||
private set
|
||||
|
||||
fun fitSelectedPath(identity: StationIdentity) {
|
||||
publish(MapNavigationRequest.FitSelectedPath(identity))
|
||||
}
|
||||
|
||||
fun centerOnQtf(qtfDegrees: Double) {
|
||||
if (!qtfDegrees.isFinite() || qtfDegrees !in 0.0..360.0) return
|
||||
publish(MapNavigationRequest.CenterOnQtf(qtfDegrees))
|
||||
}
|
||||
|
||||
fun resetToHome() {
|
||||
publish(MapNavigationRequest.ResetToHome)
|
||||
}
|
||||
|
||||
private fun publish(next: MapNavigationRequest) {
|
||||
request = next
|
||||
requestRevision++
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package kst4contest.view.compose.map
|
||||
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.TooltipArea
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||
import androidx.compose.foundation.layout.FlowRow
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kst4contest.view.compose.TooltipCard
|
||||
import kst4contest.view.i18n.LocalStrings
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class, ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
internal fun MapOverlayLegend(
|
||||
showAntenna: Boolean,
|
||||
showSpatialFilters: Boolean,
|
||||
darkMode: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
if (!showAntenna && !showSpatialFilters) return
|
||||
|
||||
val strings = LocalStrings.current
|
||||
TooltipArea(
|
||||
tooltip = { TooltipCard(strings.mapOverlayLegendTooltip) },
|
||||
modifier = modifier,
|
||||
) {
|
||||
FlowRow(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
itemVerticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
if (showAntenna) {
|
||||
LegendItem(
|
||||
color = ANTENNA_OVERLAY_COLOR,
|
||||
label = strings.mapOverlayAntenna,
|
||||
tag = MAP_ANTENNA_LEGEND_TAG,
|
||||
)
|
||||
}
|
||||
if (showSpatialFilters) {
|
||||
LegendItem(
|
||||
color = spatialFilterOverlayLineColor(darkMode),
|
||||
label = strings.mapOverlayFilters,
|
||||
tag = MAP_FILTER_LEGEND_TAG,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LegendItem(color: Color, label: String, tag: String) {
|
||||
Row(
|
||||
modifier = Modifier.testTag(tag),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
androidx.compose.foundation.layout.Box(
|
||||
Modifier
|
||||
.size(9.dp)
|
||||
.clip(androidx.compose.foundation.shape.CircleShape)
|
||||
.background(color),
|
||||
)
|
||||
Text(text = label, style = MaterialTheme.typography.bodySmall)
|
||||
}
|
||||
}
|
||||
|
||||
internal const val MAP_ANTENNA_LEGEND_TAG = "station-map-antenna-legend"
|
||||
internal const val MAP_FILTER_LEGEND_TAG = "station-map-filter-legend"
|
||||
@@ -0,0 +1,273 @@
|
||||
package kst4contest.view.compose.map
|
||||
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Rect
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Path
|
||||
import androidx.compose.ui.graphics.PathEffect
|
||||
import androidx.compose.ui.graphics.PathFillType
|
||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||
import androidx.compose.ui.graphics.drawscope.Fill
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import kst4contest.locatorUtils.DirectionUtils
|
||||
import kst4contest.view.map.MapViewport
|
||||
import kst4contest.view.map.PathGeometryUtils
|
||||
import kotlin.math.ceil
|
||||
|
||||
/** Immutable effective QTF/QRB filter values drawn by the station map. */
|
||||
data class SpatialFilterOverlayState(
|
||||
val qtfEnabled: Boolean,
|
||||
val qtfDegrees: Double,
|
||||
val beamWidthDeg: Double,
|
||||
val minQrbEnabled: Boolean,
|
||||
val minQrbKm: Double,
|
||||
val maxQrbEnabled: Boolean,
|
||||
val maxQrbKm: Double,
|
||||
) {
|
||||
val isActive: Boolean
|
||||
get() = qtfEnabled || minQrbEnabled || maxQrbEnabled
|
||||
|
||||
val hasEmptyDistanceRange: Boolean
|
||||
get() = minQrbEnabled && maxQrbEnabled && minQrbKm >= maxQrbKm
|
||||
|
||||
val hasRenderableValues: Boolean
|
||||
get() = (!qtfEnabled || qtfDegrees.isFinite() && beamWidthDeg.isFinite()) &&
|
||||
(!minQrbEnabled || minQrbKm.isFinite()) &&
|
||||
(!maxQrbEnabled || maxQrbKm.isFinite())
|
||||
|
||||
/** True when the current values produce at least one visible fill or boundary. */
|
||||
val hasDrawableGeometry: Boolean
|
||||
get() {
|
||||
if (!isActive || !hasRenderableValues) return false
|
||||
if (minQrbEnabled && !maxQrbEnabled) return true
|
||||
if (minQrbEnabled && minQrbKm > 0.0) return true
|
||||
if (maxQrbEnabled && maxQrbKm > 0.0) return true
|
||||
return qtfEnabled && !maxQrbEnabled
|
||||
}
|
||||
|
||||
/** Mirrors the filter predicate: minimum exclusive, maximum inclusive. */
|
||||
fun accepts(distanceKm: Double, bearingDeg: Double): Boolean {
|
||||
if (!distanceKm.isFinite() || !bearingDeg.isFinite()) return false
|
||||
if (minQrbEnabled && distanceKm <= minQrbKm) return false
|
||||
if (maxQrbEnabled && distanceKm > maxQrbKm) return false
|
||||
if (qtfEnabled && !DirectionUtils.isAngleInRange(bearingDeg, qtfDegrees, beamWidthDeg)) return false
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
internal fun DrawScope.drawSpatialFilterOverlay(
|
||||
viewport: MapViewport,
|
||||
homeLatitudeDeg: Double,
|
||||
homeLongitudeDeg: Double,
|
||||
state: SpatialFilterOverlayState,
|
||||
darkMode: Boolean,
|
||||
) {
|
||||
if (!state.hasDrawableGeometry ||
|
||||
!homeLatitudeDeg.isFinite() || !homeLongitudeDeg.isFinite()
|
||||
) return
|
||||
|
||||
val fillColor = if (darkMode) FILTER_FILL_DARK else FILTER_FILL_LIGHT
|
||||
val lineColor = spatialFilterOverlayLineColor(darkMode)
|
||||
val angular = state.qtfEnabled && state.beamWidthDeg.isFinite()
|
||||
val validAngularArea = !angular || state.beamWidthDeg > 0.0 && state.beamWidthDeg < 360.0
|
||||
val visibleRadius = visibleRadiusKm(viewport, homeLatitudeDeg, homeLongitudeDeg)
|
||||
val outerRadius = if (state.maxQrbEnabled) state.maxQrbKm else visibleRadius
|
||||
val innerRadius = if (state.minQrbEnabled) state.minQrbKm else 0.0
|
||||
|
||||
if (!state.hasEmptyDistanceRange && validAngularArea && outerRadius > innerRadius && outerRadius > 0.0) {
|
||||
val fillPath = when {
|
||||
angular -> annularSectorPath(
|
||||
viewport,
|
||||
homeLatitudeDeg,
|
||||
homeLongitudeDeg,
|
||||
state.qtfDegrees,
|
||||
state.beamWidthDeg,
|
||||
innerRadius.coerceAtLeast(0.0),
|
||||
outerRadius,
|
||||
)
|
||||
|
||||
state.minQrbEnabled && !state.maxQrbEnabled -> outsideCirclePath(
|
||||
viewport,
|
||||
homeLatitudeDeg,
|
||||
homeLongitudeDeg,
|
||||
innerRadius.coerceAtLeast(0.0),
|
||||
)
|
||||
|
||||
else -> ringPath(
|
||||
viewport,
|
||||
homeLatitudeDeg,
|
||||
homeLongitudeDeg,
|
||||
innerRadius.coerceAtLeast(0.0),
|
||||
outerRadius,
|
||||
)
|
||||
}
|
||||
drawPath(fillPath, fillColor, style = Fill)
|
||||
}
|
||||
|
||||
val stroke = Stroke(
|
||||
width = FILTER_LINE_WIDTH_PX,
|
||||
pathEffect = PathEffect.dashPathEffect(FILTER_DASH_PX),
|
||||
)
|
||||
if (state.minQrbEnabled && state.minQrbKm > 0.0) {
|
||||
drawPath(circlePath(viewport, homeLatitudeDeg, homeLongitudeDeg, state.minQrbKm), lineColor, style = stroke)
|
||||
}
|
||||
if (state.maxQrbEnabled && state.maxQrbKm > 0.0) {
|
||||
drawPath(circlePath(viewport, homeLatitudeDeg, homeLongitudeDeg, state.maxQrbKm), lineColor, style = stroke)
|
||||
}
|
||||
if (angular) {
|
||||
val boundaryRadius = if (state.maxQrbEnabled) state.maxQrbKm else visibleRadius
|
||||
val halfWidth = state.beamWidthDeg.coerceAtLeast(0.0) / 2.0
|
||||
listOf(state.qtfDegrees - halfWidth, state.qtfDegrees + halfWidth).forEach { bearing ->
|
||||
val endpoint = calculateDestinationPoint(
|
||||
homeLatitudeDeg,
|
||||
homeLongitudeDeg,
|
||||
bearing,
|
||||
boundaryRadius,
|
||||
)
|
||||
drawLine(
|
||||
color = lineColor,
|
||||
start = Offset(
|
||||
viewport.screenXWrapped(homeLongitudeDeg).toFloat(),
|
||||
viewport.screenY(homeLatitudeDeg).toFloat(),
|
||||
),
|
||||
end = Offset(
|
||||
viewport.screenXWrapped(endpoint.second).toFloat(),
|
||||
viewport.screenY(endpoint.first).toFloat(),
|
||||
),
|
||||
strokeWidth = FILTER_LINE_WIDTH_PX,
|
||||
pathEffect = PathEffect.dashPathEffect(FILTER_DASH_PX),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun outsideCirclePath(
|
||||
viewport: MapViewport,
|
||||
homeLatitudeDeg: Double,
|
||||
homeLongitudeDeg: Double,
|
||||
radiusKm: Double,
|
||||
): Path = Path().apply {
|
||||
fillType = PathFillType.EvenOdd
|
||||
addRect(Rect(0f, 0f, viewport.widthPx().toFloat(), viewport.heightPx().toFloat()))
|
||||
addPath(circlePath(viewport, homeLatitudeDeg, homeLongitudeDeg, radiusKm))
|
||||
}
|
||||
|
||||
private fun ringPath(
|
||||
viewport: MapViewport,
|
||||
homeLatitudeDeg: Double,
|
||||
homeLongitudeDeg: Double,
|
||||
innerRadiusKm: Double,
|
||||
outerRadiusKm: Double,
|
||||
): Path = Path().apply {
|
||||
fillType = PathFillType.EvenOdd
|
||||
addPath(circlePath(viewport, homeLatitudeDeg, homeLongitudeDeg, outerRadiusKm))
|
||||
if (innerRadiusKm > 0.0) {
|
||||
addPath(circlePath(viewport, homeLatitudeDeg, homeLongitudeDeg, innerRadiusKm))
|
||||
}
|
||||
}
|
||||
|
||||
private fun annularSectorPath(
|
||||
viewport: MapViewport,
|
||||
homeLatitudeDeg: Double,
|
||||
homeLongitudeDeg: Double,
|
||||
centerBearingDeg: Double,
|
||||
beamWidthDeg: Double,
|
||||
innerRadiusKm: Double,
|
||||
outerRadiusKm: Double,
|
||||
): Path {
|
||||
val halfWidth = beamWidthDeg / 2.0
|
||||
val outer = arcPoints(
|
||||
homeLatitudeDeg,
|
||||
homeLongitudeDeg,
|
||||
centerBearingDeg - halfWidth,
|
||||
beamWidthDeg,
|
||||
outerRadiusKm,
|
||||
)
|
||||
val inner = if (innerRadiusKm > 0.0) {
|
||||
arcPoints(
|
||||
homeLatitudeDeg,
|
||||
homeLongitudeDeg,
|
||||
centerBearingDeg - halfWidth,
|
||||
beamWidthDeg,
|
||||
innerRadiusKm,
|
||||
).asReversed()
|
||||
} else {
|
||||
listOf(homeLatitudeDeg to homeLongitudeDeg)
|
||||
}
|
||||
|
||||
return pathThrough(viewport, outer + inner, close = true)
|
||||
}
|
||||
|
||||
private fun circlePath(
|
||||
viewport: MapViewport,
|
||||
homeLatitudeDeg: Double,
|
||||
homeLongitudeDeg: Double,
|
||||
radiusKm: Double,
|
||||
): Path = pathThrough(
|
||||
viewport,
|
||||
arcPoints(homeLatitudeDeg, homeLongitudeDeg, 0.0, 360.0, radiusKm),
|
||||
close = true,
|
||||
)
|
||||
|
||||
private fun arcPoints(
|
||||
homeLatitudeDeg: Double,
|
||||
homeLongitudeDeg: Double,
|
||||
startBearingDeg: Double,
|
||||
sweepDeg: Double,
|
||||
radiusKm: Double,
|
||||
): List<Pair<Double, Double>> {
|
||||
val segmentCount = maxOf(24, ceil(kotlin.math.abs(sweepDeg) / 3.0).toInt())
|
||||
return (0..segmentCount).map { segment ->
|
||||
calculateDestinationPoint(
|
||||
homeLatitudeDeg,
|
||||
homeLongitudeDeg,
|
||||
startBearingDeg + sweepDeg * segment / segmentCount,
|
||||
radiusKm,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun pathThrough(
|
||||
viewport: MapViewport,
|
||||
points: List<Pair<Double, Double>>,
|
||||
close: Boolean,
|
||||
): Path = Path().apply {
|
||||
points.forEachIndexed { index, point ->
|
||||
val x = viewport.screenXWrapped(point.second).toFloat()
|
||||
val y = viewport.screenY(point.first).toFloat()
|
||||
if (index == 0) moveTo(x, y) else lineTo(x, y)
|
||||
}
|
||||
if (close && points.isNotEmpty()) close()
|
||||
}
|
||||
|
||||
private fun visibleRadiusKm(
|
||||
viewport: MapViewport,
|
||||
homeLatitudeDeg: Double,
|
||||
homeLongitudeDeg: Double,
|
||||
): Double {
|
||||
val corners = listOf(
|
||||
viewport.northLat() to viewport.westLon(),
|
||||
viewport.northLat() to viewport.eastLon(),
|
||||
viewport.southLat() to viewport.westLon(),
|
||||
viewport.southLat() to viewport.eastLon(),
|
||||
)
|
||||
val farthestCorner = corners.maxOfOrNull { (latitude, longitude) ->
|
||||
PathGeometryUtils.calculateGreatCircleDistanceKm(
|
||||
homeLatitudeDeg,
|
||||
homeLongitudeDeg,
|
||||
latitude,
|
||||
longitude,
|
||||
)
|
||||
} ?: 0.0
|
||||
return farthestCorner * VIEWPORT_RADIUS_MARGIN
|
||||
}
|
||||
|
||||
private val FILTER_FILL_LIGHT = Color(0xFF5B4BC4).copy(alpha = 0.16f)
|
||||
private val FILTER_FILL_DARK = Color(0xFF78A9FF).copy(alpha = 0.18f)
|
||||
private val FILTER_LINE_LIGHT = Color(0xFF4937B8).copy(alpha = 0.88f)
|
||||
private val FILTER_LINE_DARK = Color(0xFF8CB8FF).copy(alpha = 0.92f)
|
||||
internal fun spatialFilterOverlayLineColor(darkMode: Boolean): Color =
|
||||
if (darkMode) FILTER_LINE_DARK else FILTER_LINE_LIGHT
|
||||
private const val FILTER_LINE_WIDTH_PX = 2f
|
||||
private val FILTER_DASH_PX = floatArrayOf(7f, 5f)
|
||||
private const val VIEWPORT_RADIUS_MARGIN = 1.12
|
||||
@@ -11,6 +11,8 @@ import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.text.font.FontStyle
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
@@ -26,6 +28,7 @@ import kst4contest.view.compose.StationContextOverlays
|
||||
import kst4contest.view.compose.StationSelectionSource
|
||||
import kst4contest.view.map.MapCallsignRawSnapshotBuilder
|
||||
import kst4contest.view.map.PathAnalysisResult
|
||||
import kst4contest.view.map.MapViewportNavigation
|
||||
import kst4contest.view.map.StationMapStatusText
|
||||
import kst4contest.view.map.TileFetcher
|
||||
import java.util.EnumSet
|
||||
@@ -108,9 +111,8 @@ object StationMapWindow {
|
||||
* @param chatMembers the roster a marker click looks its station up in; a marker stands
|
||||
* for a raw callsign, and this is where its category variants come from
|
||||
* @param mapState where the map is looking
|
||||
* @param pathAnalysis asked each time the selection changes; null means there is no
|
||||
* running application, and then the map neither pans nor analyses, exactly as
|
||||
* when no chat controller existed before the split
|
||||
* @param pathAnalysis asked for an explicit selection; null disables only the terrain
|
||||
* analysis while viewport navigation remains available
|
||||
*/
|
||||
@Composable
|
||||
internal fun Content(
|
||||
@@ -151,8 +153,8 @@ object StationMapWindow {
|
||||
|
||||
val ownLocator6 by remember { androidx.compose.runtime.mutableStateOf(mainWindowState.prefs.stn_loginLocatorMainCat) }
|
||||
val antennaAzimuthDeg = mainWindowState.antennaQtf.value
|
||||
val antennaBeamWidthDeg = mainWindowState.prefs.stn_antennaBeamWidthDeg
|
||||
val maxQrbKm = mainWindowState.prefs.stn_maxQRBDefault
|
||||
val antennaBeamWidthDeg = mainWindowState.mapDisplaySettings.antennaBeamWidthDeg
|
||||
val maxQrbKm = mainWindowState.mapDisplaySettings.maxQrbKm
|
||||
|
||||
/*
|
||||
* The markers are the stations the list shows, not all of them (#21): the
|
||||
@@ -184,20 +186,37 @@ object StationMapWindow {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Selection is independent of the filtered marker set. A selected station
|
||||
* remains a target even when an active filter removes its normal marker; it is
|
||||
* drawn in a separate selection layer and never enters marker counts or clusters.
|
||||
*/
|
||||
val selectedTarget by remember(
|
||||
selectedMember,
|
||||
mainWindowState.stations.contentRevision,
|
||||
mainWindowState.activeBands,
|
||||
) {
|
||||
derivedStateOf {
|
||||
selectedMember?.let { selected ->
|
||||
val variants = chatMembers().filter { it.callSignRaw == selected.callSignRaw }
|
||||
.ifEmpty { listOf(selected) }
|
||||
val bands = EnumSet.noneOf(Band::class.java).apply {
|
||||
addAll(mainWindowState.activeBands)
|
||||
}
|
||||
MapCallsignRawSnapshotBuilder()
|
||||
.buildSnapshots(variants, selected, bands)
|
||||
.firstOrNull()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var pathAnalysisResult by remember { mutableStateOf<PathAnalysisResult?>(null) }
|
||||
var automaticAnalysisRevision by remember { mutableStateOf(0L) }
|
||||
|
||||
// Read through updated state so a caller passing a new lambda is never served a stale one.
|
||||
val currentPathAnalysis by rememberUpdatedState(pathAnalysis)
|
||||
|
||||
/*
|
||||
* Whether the selected station has a marker. A filter can hide it (#21), and a
|
||||
* station without a locator never has one; then there is nothing to analyse.
|
||||
*/
|
||||
val selectedHasMarker = selectedMember != null &&
|
||||
markers.any { it.callSignRaw() == selectedMember.callSignRaw }
|
||||
|
||||
LaunchedEffect(selectedMember, selectedHasMarker) {
|
||||
LaunchedEffect(mainWindowState.stationSelection.explicitSelectionRevision) {
|
||||
val automaticRequest = ++automaticAnalysisRevision
|
||||
val explicitRevisionAtStart = mainWindowState.mapReachability.requestRevision
|
||||
if (selectedMember == null) {
|
||||
@@ -205,34 +224,15 @@ object StationMapWindow {
|
||||
return@LaunchedEffect
|
||||
}
|
||||
|
||||
val selectedSnapshot = markers.find { it.callSignRaw() == selectedMember.callSignRaw }
|
||||
val selectedSnapshot = selectedTarget
|
||||
if (selectedSnapshot == null) {
|
||||
// No marker: no request, and no "Loading" for a station the map does not show.
|
||||
// No valid locator: no request and no misleading loading state.
|
||||
pathAnalysisResult = null
|
||||
return@LaunchedEffect
|
||||
}
|
||||
|
||||
val analysis = currentPathAnalysis()
|
||||
if (analysis != null) {
|
||||
if (selectedSnapshot.hasUsablePosition()) {
|
||||
/*
|
||||
* Pan to the station and leave the zoom alone. The Leaflet map
|
||||
* did exactly this (focusCallsignRaw) and touched the zoom only
|
||||
* when the station was hidden inside a bubble, and then only far
|
||||
* enough to break the bubble open. An earlier Compose version
|
||||
* recomputed a zoom from a bounding box on every selection and
|
||||
* clamped it into 4..12, which threw an operator working at zoom
|
||||
* 15 out to about 7 every time they picked the next station.
|
||||
* AGENTS.md names zoom first among the things not to change as
|
||||
* an incidental side effect.
|
||||
*/
|
||||
mapState.centerLon = selectedSnapshot.longitudeDeg()
|
||||
mapState.centerLat = selectedSnapshot.latitudeDeg()
|
||||
mapState.zoom = kst4contest.view.map.StationMapClusterer
|
||||
.zoomToRevealStations(mapState.zoom.toDouble(), groupingEnabled)
|
||||
.toFloat()
|
||||
}
|
||||
|
||||
pathAnalysisResult = PathAnalysisResult.loading(
|
||||
prefs.stn_loginLocatorMainCat,
|
||||
selectedSnapshot.locator6(),
|
||||
@@ -249,6 +249,72 @@ object StationMapWindow {
|
||||
}
|
||||
}
|
||||
|
||||
var mapCanvasSize by remember { mutableStateOf(Size.Zero) }
|
||||
var consumedNavigationRevision by remember(mapState) { mutableStateOf(Long.MIN_VALUE) }
|
||||
val navigationRevision = mainWindowState.mapNavigation.requestRevision
|
||||
val navigationRequest = mainWindowState.mapNavigation.request
|
||||
val navigationPaddingPx = with(LocalDensity.current) { 40.dp.toPx().toDouble() }
|
||||
|
||||
LaunchedEffect(
|
||||
navigationRevision,
|
||||
navigationRequest,
|
||||
mapCanvasSize,
|
||||
selectedTarget,
|
||||
ownLocator6,
|
||||
) {
|
||||
if (navigationRevision == consumedNavigationRevision ||
|
||||
mapCanvasSize.width <= 0f || mapCanvasSize.height <= 0f
|
||||
) {
|
||||
return@LaunchedEffect
|
||||
}
|
||||
|
||||
val home = runCatching { kst4contest.locatorUtils.Location(ownLocator6) }.getOrNull()
|
||||
val current = mapState.viewportFor(mapCanvasSize.width, mapCanvasSize.height)
|
||||
val next = when (val request = navigationRequest) {
|
||||
is MapNavigationRequest.FitSelectedPath -> {
|
||||
val target = selectedTarget
|
||||
if (home == null || target == null || !target.hasUsablePosition() ||
|
||||
request.identity != StationIdentity.of(selectedMember)
|
||||
) {
|
||||
null
|
||||
} else {
|
||||
MapViewportNavigation.fitPath(
|
||||
current,
|
||||
home.latitude.toDegrees(),
|
||||
home.longitude.toDegrees(),
|
||||
target.latitudeDeg(),
|
||||
target.longitudeDeg(),
|
||||
navigationPaddingPx,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is MapNavigationRequest.CenterOnQtf -> {
|
||||
if (home == null) null else MapViewportNavigation.centreOnBearing(
|
||||
current,
|
||||
home.latitude.toDegrees(),
|
||||
home.longitude.toDegrees(),
|
||||
request.qtfDegrees,
|
||||
QTF_FORWARD_CENTRE_FRACTION,
|
||||
)
|
||||
}
|
||||
|
||||
MapNavigationRequest.ResetToHome -> {
|
||||
if (home == null) null else MapViewportNavigation.centreOnHome(
|
||||
current,
|
||||
home.latitude.toDegrees(),
|
||||
home.longitude.toDegrees(),
|
||||
)
|
||||
}
|
||||
|
||||
null -> null
|
||||
}
|
||||
consumedNavigationRevision = navigationRevision
|
||||
if (next != null) {
|
||||
mapState.applyFrom(next)
|
||||
}
|
||||
}
|
||||
|
||||
val explicitReachabilityResult = mainWindowState.mapReachability.result
|
||||
LaunchedEffect(mainWindowState.mapReachability.requestRevision, explicitReachabilityResult) {
|
||||
if (explicitReachabilityResult != null) {
|
||||
@@ -264,6 +330,24 @@ object StationMapWindow {
|
||||
} else {
|
||||
emptySet()
|
||||
}
|
||||
val spatialFilterOverlay = SpatialFilterOverlayState(
|
||||
qtfEnabled = mainWindowState.stationFilter.qtfEnabled,
|
||||
qtfDegrees = mainWindowState.stationFilter.qtfDegrees,
|
||||
beamWidthDeg = antennaBeamWidthDeg,
|
||||
minQrbEnabled = mainWindowState.stationFilter.minQrbEnabled,
|
||||
minQrbKm = mainWindowState.stationFilter.minQrbKm,
|
||||
maxQrbEnabled = mainWindowState.stationFilter.maxQrbEnabled,
|
||||
maxQrbKm = mainWindowState.stationFilter.maxQrbKm,
|
||||
)
|
||||
val mapHome = remember(ownLocator6) { homePosition(ownLocator6) }
|
||||
val showAntennaOverlay = isAntennaSectorDrawable(
|
||||
mapHome,
|
||||
antennaAzimuthDeg ?: 0.0,
|
||||
antennaBeamWidthDeg,
|
||||
maxQrbKm,
|
||||
)
|
||||
val showSpatialFilterOverlay = mapHome != null && spatialFilterOverlay.hasDrawableGeometry
|
||||
val isDarkTheme = isDarkThemeState.value
|
||||
|
||||
androidx.compose.material3.Surface(
|
||||
color = androidx.compose.material3.MaterialTheme.colorScheme.background,
|
||||
@@ -288,7 +372,7 @@ object StationMapWindow {
|
||||
markers.size,
|
||||
mainWindowState.stationFilter.activeFilters.isNotEmpty() ||
|
||||
mainWindowState.stationFilter.searchText.isNotBlank(),
|
||||
markers.firstOrNull { it.callSignRaw() == selectedMember?.callSignRaw },
|
||||
selectedTarget,
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -308,6 +392,12 @@ object StationMapWindow {
|
||||
)
|
||||
}
|
||||
|
||||
MapOverlayLegend(
|
||||
showAntenna = showAntennaOverlay,
|
||||
showSpatialFilters = showSpatialFilterOverlay,
|
||||
darkMode = isDarkTheme,
|
||||
)
|
||||
|
||||
if (selectedMember != null) {
|
||||
kst4contest.view.compose.Form.button(strings.mapTriggerClusterSpot) {
|
||||
ApplicationRuntimeLauncher.getCurrent()?.chatController
|
||||
@@ -317,12 +407,6 @@ object StationMapWindow {
|
||||
|
||||
kst4contest.view.compose.Form.button(strings.mapResetView) {
|
||||
mainWindowState.selectStation(null, StationSelectionSource.RESET_VIEW)
|
||||
val home = runCatching {
|
||||
kst4contest.locatorUtils.Location(ownLocator6)
|
||||
}.getOrNull()
|
||||
mapState.centerLon = home?.longitude?.toDegrees() ?: 10.0
|
||||
mapState.centerLat = home?.latitude?.toDegrees() ?: 51.0
|
||||
/* The zoom is deliberately left alone; see AGENTS.md, UI behaviour. */
|
||||
}
|
||||
|
||||
kst4contest.view.compose.Form.button(strings.filterReset) {
|
||||
@@ -388,7 +472,6 @@ object StationMapWindow {
|
||||
|
||||
val leftPane: @Composable () -> Unit = {
|
||||
Column(Modifier.fillMaxHeight()) {
|
||||
val isDarkTheme = isDarkThemeState.value
|
||||
androidx.compose.foundation.layout.Box(Modifier.weight(1f).fillMaxWidth()) {
|
||||
ComposeStationMap(
|
||||
markers = markers,
|
||||
@@ -400,8 +483,11 @@ object StationMapWindow {
|
||||
antennaAzimuthDeg = antennaAzimuthDeg ?: 0.0,
|
||||
antennaBeamWidthDeg = antennaBeamWidthDeg,
|
||||
maxQrbKm = maxQrbKm,
|
||||
selectedTarget = selectedTarget,
|
||||
spatialFilterOverlay = spatialFilterOverlay,
|
||||
darkMode = isDarkTheme,
|
||||
workedGrossFields = workedGrossFields,
|
||||
onCanvasSizeChanged = { mapCanvasSize = it },
|
||||
onMarkerClicked = { snapshot ->
|
||||
val variants = chatMembers()
|
||||
.filter { it.callSignRaw == snapshot.callSignRaw() }
|
||||
@@ -501,6 +587,7 @@ object StationMapWindow {
|
||||
internal const val MAP_CANVAS_TAG = "station-map-canvas"
|
||||
internal const val GROUPING_TAG = "station-map-grouping"
|
||||
internal const val ALWAYS_ON_TOP_TAG = "station-map-always-on-top"
|
||||
private const val QTF_FORWARD_CENTRE_FRACTION = 0.25
|
||||
|
||||
@JvmStatic
|
||||
fun applyDarkMode(darkMode: Boolean) {
|
||||
|
||||
@@ -4,9 +4,11 @@ import kst4contest.view.i18n.LocalStrings
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kst4contest.view.compose.Form
|
||||
import kst4contest.view.compose.observeAsState
|
||||
|
||||
/**
|
||||
* The beacon tab: one CQ template per chat category and the interval they share.
|
||||
@@ -18,12 +20,14 @@ import kst4contest.view.compose.Form
|
||||
@Composable
|
||||
fun BeaconTab(state: BeaconTabState, onRefused: (String) -> Unit) {
|
||||
val strings = LocalStrings.current
|
||||
val mainEnabled by state.mainBeaconEnabled.observeAsState()
|
||||
val secondEnabled by state.secondBeaconEnabled.observeAsState()
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
Form.section(strings.beaconSectionFor(state.mainCategoryName)) {
|
||||
Form.check(strings.beaconEnabled, state.bcn_beaconsEnabledMainCat) {
|
||||
Form.check(strings.beaconEnabled, mainEnabled == true) {
|
||||
state.bcn_beaconsEnabledMainCat = it
|
||||
}
|
||||
Form.committed(
|
||||
@@ -36,7 +40,7 @@ fun BeaconTab(state: BeaconTabState, onRefused: (String) -> Unit) {
|
||||
}
|
||||
|
||||
Form.section(strings.beaconSectionFor(state.secondCategoryName)) {
|
||||
Form.check(strings.beaconEnabled, state.bcn_beaconsEnabledSecondCat) {
|
||||
Form.check(strings.beaconEnabled, secondEnabled == true) {
|
||||
state.bcn_beaconsEnabledSecondCat = it
|
||||
}
|
||||
Form.committed(
|
||||
|
||||
@@ -12,8 +12,9 @@ import kst4contest.view.compose.setting
|
||||
* The two commit methods are the ports of `applyBeaconTextSetting` and
|
||||
* `applySharedBeaconInterval`. Both returned nothing and opened an alert; here they
|
||||
* return the refusal text instead, so the tab decides how to show it and a test can
|
||||
* read it. An accepted value is staged in the window's [SettingsDraft] and takes effect
|
||||
* when the operator applies it; a refused one never gets there.
|
||||
* read it. Accepted templates and intervals are staged in the window's [SettingsDraft]
|
||||
* and take effect when the operator applies them. The two enable switches deliberately
|
||||
* bypass the draft so the running timer sees their values immediately.
|
||||
*
|
||||
* @param validateBeaconTemplate throws IllegalArgumentException with the reason,
|
||||
* the contract of `ChatController.validateBeaconTemplate`.
|
||||
@@ -27,15 +28,20 @@ class BeaconTabState(
|
||||
private val restartBeaconTimer: () -> Unit,
|
||||
val mainCategoryName: String,
|
||||
val secondCategoryName: String,
|
||||
private val setMainBeaconEnabled: (Boolean) -> Unit = prefs::setBcn_beaconsEnabledMainCat,
|
||||
private val setSecondBeaconEnabled: (Boolean) -> Unit = prefs::setBcn_beaconsEnabledSecondCat,
|
||||
) {
|
||||
|
||||
var bcn_beaconsEnabledMainCat: Boolean by draft.setting(
|
||||
{ prefs.isBcn_beaconsEnabledMainCat() },
|
||||
) { prefs.setBcn_beaconsEnabledMainCat(it) }
|
||||
val mainBeaconEnabled = prefs.bcnBeaconsEnabledMainCatProperty()
|
||||
val secondBeaconEnabled = prefs.bcnBeaconsEnabledSecondCatProperty()
|
||||
|
||||
var bcn_beaconsEnabledSecondCat: Boolean by draft.setting(
|
||||
{ prefs.isBcn_beaconsEnabledSecondCat() },
|
||||
) { prefs.setBcn_beaconsEnabledSecondCat(it) }
|
||||
var bcn_beaconsEnabledMainCat: Boolean
|
||||
get() = prefs.isBcn_beaconsEnabledMainCat()
|
||||
set(value) = setMainBeaconEnabled(value)
|
||||
|
||||
var bcn_beaconsEnabledSecondCat: Boolean
|
||||
get() = prefs.isBcn_beaconsEnabledSecondCat()
|
||||
set(value) = setSecondBeaconEnabled(value)
|
||||
|
||||
private var textMainCat: String by draft.setting(
|
||||
{ prefs.getBcn_beaconTextMainCat() },
|
||||
@@ -69,7 +75,7 @@ class BeaconTabState(
|
||||
*
|
||||
* The clamp is not cosmetic: a stored zero would otherwise be displayed as a
|
||||
* valid setting while `ChatController` sends at the minimum anyway
|
||||
* (ChatController:3425). The JavaFX field applied the same `Math.max` when it
|
||||
* when scheduling the timer. The JavaFX field applied the same `Math.max` when it
|
||||
* restored the value after a rejected entry.
|
||||
*/
|
||||
val beaconIntervalMinutes: Int
|
||||
|
||||
@@ -44,6 +44,10 @@ class StationTabState(
|
||||
* TRX synch tab through [SECOND_ROTATOR], so it runs once per apply.
|
||||
*/
|
||||
private val applySecondRotator: () -> Unit = {},
|
||||
/** Recomputes status whose available-count depends on the second-chat switch. */
|
||||
private val refreshBeaconStatus: () -> Unit = {},
|
||||
/** Repaints applied beam geometry and dependent QTF results in the running UI. */
|
||||
private val applyMapDisplaySettings: () -> Unit = {},
|
||||
) {
|
||||
|
||||
var loginChatCategoryMain: ChatCategory?
|
||||
@@ -55,7 +59,11 @@ class StationTabState(
|
||||
get() = prefs.getLoginChatCategorySecond()
|
||||
set(value) { prefs.setLoginChatCategorySecond(value) }
|
||||
|
||||
var stn_antennaBeamWidthDeg: Double by draft.setting({ prefs.getStn_antennaBeamWidthDeg() }) { prefs.setStn_antennaBeamWidthDeg(it) }
|
||||
var stn_antennaBeamWidthDeg: Double by draft.setting(
|
||||
{ prefs.getStn_antennaBeamWidthDeg() },
|
||||
effectKey = MAP_DISPLAY_SETTINGS,
|
||||
effect = applyMapDisplaySettings,
|
||||
) { prefs.setStn_antennaBeamWidthDeg(it) }
|
||||
|
||||
var stn_bandActive10G: Boolean by draft.setting({ prefs.isStn_bandActive10G() }) { prefs.setStn_bandActive10G(it) }
|
||||
|
||||
@@ -95,7 +103,11 @@ class StationTabState(
|
||||
get() = prefs.getStn_loginPassword()
|
||||
set(value) { prefs.setStn_loginPassword(value) }
|
||||
|
||||
var stn_maxQRBDefault: Double by draft.setting({ prefs.getStn_maxQRBDefault() }) { prefs.setStn_maxQRBDefault(it) }
|
||||
var stn_maxQRBDefault: Double by draft.setting(
|
||||
{ prefs.getStn_maxQRBDefault() },
|
||||
effectKey = MAP_DISPLAY_SETTINGS,
|
||||
effect = applyMapDisplaySettings,
|
||||
) { prefs.setStn_maxQRBDefault(it) }
|
||||
|
||||
var stn_on4kstServersDns: String by draft.setting({ prefs.getStn_on4kstServersDns() }) { prefs.setStn_on4kstServersDns(it) }
|
||||
|
||||
@@ -234,7 +246,10 @@ class StationTabState(
|
||||
* pickers it governs. It decides what the Connect button does, so it belongs with
|
||||
* the login settings and not with the display options.
|
||||
*/
|
||||
var loginToSecondChatEnabled: Boolean by draft.setting({ prefs.isLoginToSecondChatEnabled() }) { prefs.setLoginToSecondChatEnabled(it) }
|
||||
var loginToSecondChatEnabled: Boolean by draft.setting(
|
||||
{ prefs.isLoginToSecondChatEnabled() },
|
||||
effect = { refreshBeaconStatus() },
|
||||
) { prefs.setLoginToSecondChatEnabled(it) }
|
||||
|
||||
/**
|
||||
* Whether the login fields may be edited. The JavaFX window disabled callsign,
|
||||
@@ -289,6 +304,9 @@ class StationTabState(
|
||||
/** The effect key of everything that restarts rotator 2; shared with the TRX synch tab. */
|
||||
const val SECOND_ROTATOR: String = "secondRotator"
|
||||
|
||||
/** Shared effect for the two settings that define the map's antenna sector. */
|
||||
const val MAP_DISPLAY_SETTINGS: String = "mapDisplaySettings"
|
||||
|
||||
/**
|
||||
* Whether two PSTRotator ports collide: the same port, or one apart because
|
||||
* PSTRotator answers on port + 1, which would be the other client's local port.
|
||||
|
||||
Reference in new issue
Block a user