feat(app): add waypoint functionality to map and context menu
This commit is contained in:
@@ -8,6 +8,7 @@ import { loadWormholeSystems, saveWormholeSystem, deleteWormholeSystem } from '@
|
||||
import { System, Position, Connection as ConnectionType } from '@/lib/types';
|
||||
import { getSecurityColor } from '@/utils/securityColors';
|
||||
import { Header } from './Header';
|
||||
import { ListCharacters, StartESILogin, SetDestinationForAll, AddWaypointForAllByName } from 'wailsjs/go/main/App';
|
||||
|
||||
interface RegionMapProps {
|
||||
regionName: string;
|
||||
@@ -67,6 +68,16 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho
|
||||
const [positions, setPositions] = useState<Record<string, Position>>({});
|
||||
const svgRef = useRef<SVGSVGElement>(null);
|
||||
|
||||
const [viaMode, setViaMode] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') setViaMode(false);
|
||||
};
|
||||
window.addEventListener('keydown', onKeyDown);
|
||||
return () => window.removeEventListener('keydown', onKeyDown);
|
||||
}, []);
|
||||
|
||||
const { data: rsystems, isLoading, error } = useRegionData(regionName);
|
||||
useEffect(() => {
|
||||
if (!isLoading && error == null && rsystems && rsystems.size > 0)
|
||||
@@ -363,6 +374,34 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho
|
||||
}
|
||||
};
|
||||
|
||||
const ensureAnyLoggedIn = async () => {
|
||||
try {
|
||||
const list = await ListCharacters();
|
||||
if (Array.isArray(list) && list.length > 0) return true;
|
||||
await StartESILogin();
|
||||
return false;
|
||||
} catch {
|
||||
await StartESILogin();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const onSetDestination = async (systemName: string, wantVia: boolean) => {
|
||||
try {
|
||||
if (!(await ensureAnyLoggedIn())) return;
|
||||
if (!viaMode) {
|
||||
// First selection: set destination and optionally enter via mode
|
||||
await SetDestinationForAll(systemName, true, false);
|
||||
if (wantVia) setViaMode(true);
|
||||
} else {
|
||||
// Append waypoint
|
||||
await AddWaypointForAllByName(systemName, false);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Set destination failed:', e);
|
||||
}
|
||||
};
|
||||
|
||||
// Close context menu when clicking outside
|
||||
useEffect(() => {
|
||||
const handleClickOutside = () => setContextMenu(null);
|
||||
@@ -403,7 +442,7 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho
|
||||
width="100%"
|
||||
height="100%"
|
||||
viewBox={`${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}`}
|
||||
className="cursor-grab active:cursor-grabbing"
|
||||
className={`cursor-grab active:cursor-grabbing ${viaMode ? 'ring-2 ring-emerald-500' : ''}`}
|
||||
onMouseDown={handleMouseDown}
|
||||
onMouseMove={(e) => {
|
||||
if (isPanning) {
|
||||
@@ -506,6 +545,7 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho
|
||||
onRename={(newName) => handleRenameSystem(contextMenu.system.solarSystemName, newName)}
|
||||
onDelete={handleDeleteSystem}
|
||||
onClearConnections={handleClearConnections}
|
||||
onSetDestination={onSetDestination}
|
||||
onClose={() => setContextMenu(null)}
|
||||
/>
|
||||
)}
|
||||
|
Reference in New Issue
Block a user