mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-11-10 03:14:40 +00:00
* feat(signatures): Add custom info to system signatures * feat(connections): Add custom info to system connections * feat(Map): Add system signature type * feat(Map): Update wormhole types info * feat(Map): Add undo action for removed systems * feat(Map): Delete systems on Backspace hotkey * feat(Map): Update k-space systems background & styles * feat(Map): Update systems status background styles * feat(Map): add support for new wh type data. add signatures settings modal menu; reworked signatures widget - was added info of wormhole; --------- Co-authored-by: achichenkov <aleksei.chichenkov@telleqt.ai>
171 lines
4.0 KiB
TypeScript
171 lines
4.0 KiB
TypeScript
import { useCallback, useRef, useState } from 'react';
|
|
import { ContextMenu } from 'primereact/contextmenu';
|
|
import { OutCommand, OutCommandHandler } from '@/hooks/Mapper/types/mapHandlers.ts';
|
|
import { SolarSystemRawType } from '@/hooks/Mapper/types';
|
|
import { WaypointSetContextHandler } from '@/hooks/Mapper/components/contexts/types.ts';
|
|
import { ctxManager } from '@/hooks/Mapper/utils/contextManager.ts';
|
|
import { useDeleteSystems } from '@/hooks/Mapper/components/contexts/hooks';
|
|
|
|
interface UseContextMenuSystemHandlersProps {
|
|
hubs: string[];
|
|
systems: SolarSystemRawType[];
|
|
outCommand: OutCommandHandler;
|
|
}
|
|
|
|
export const useContextMenuSystemHandlers = ({ systems, hubs, outCommand }: UseContextMenuSystemHandlersProps) => {
|
|
const contextMenuRef = useRef<ContextMenu | null>(null);
|
|
|
|
const [system, setSystem] = useState<string>();
|
|
|
|
const { deleteSystems } = useDeleteSystems();
|
|
|
|
const ref = useRef({ hubs, system, systems, outCommand, deleteSystems });
|
|
ref.current = { hubs, system, systems, outCommand, deleteSystems };
|
|
|
|
const open = useCallback((ev: any, systemId: string) => {
|
|
setSystem(systemId);
|
|
ev.preventDefault();
|
|
ctxManager.next('ctxSys', contextMenuRef.current);
|
|
contextMenuRef.current?.show(ev);
|
|
}, []);
|
|
|
|
const onDeleteSystem = useCallback(() => {
|
|
const { system, deleteSystems } = ref.current;
|
|
if (!system) {
|
|
return;
|
|
}
|
|
|
|
deleteSystems([system]);
|
|
setSystem(undefined);
|
|
}, []);
|
|
|
|
const onLockToggle = useCallback(() => {
|
|
const { system, systems, outCommand } = ref.current;
|
|
if (!system) {
|
|
return;
|
|
}
|
|
|
|
const sysInfo = systems.find(x => x.id === system)!;
|
|
|
|
outCommand({
|
|
type: OutCommand.updateSystemLocked,
|
|
data: {
|
|
system_id: system,
|
|
value: !sysInfo.locked,
|
|
},
|
|
});
|
|
setSystem(undefined);
|
|
}, []);
|
|
|
|
const onHubToggle = useCallback(() => {
|
|
const { hubs, system, outCommand } = ref.current;
|
|
if (!system) {
|
|
return;
|
|
}
|
|
|
|
outCommand({
|
|
type: !hubs.includes(system) ? OutCommand.addHub : OutCommand.deleteHub,
|
|
data: {
|
|
system_id: system,
|
|
},
|
|
});
|
|
setSystem(undefined);
|
|
}, []);
|
|
|
|
const onSystemTag = useCallback((tag?: string) => {
|
|
const { system, outCommand } = ref.current;
|
|
if (!system) {
|
|
return;
|
|
}
|
|
|
|
outCommand({
|
|
type: OutCommand.updateSystemTag,
|
|
data: {
|
|
system_id: system,
|
|
value: tag ?? '',
|
|
},
|
|
});
|
|
setSystem(undefined);
|
|
}, []);
|
|
|
|
const onSystemStatus = useCallback((status: number) => {
|
|
const { system, outCommand } = ref.current;
|
|
if (!system) {
|
|
return;
|
|
}
|
|
|
|
outCommand({
|
|
type: OutCommand.updateSystemStatus,
|
|
data: {
|
|
system_id: system,
|
|
value: status,
|
|
},
|
|
});
|
|
setSystem(undefined);
|
|
}, []);
|
|
|
|
const onSystemLabels = useCallback((labels: string) => {
|
|
const { system, outCommand } = ref.current;
|
|
if (!system) {
|
|
return;
|
|
}
|
|
|
|
outCommand({
|
|
type: OutCommand.updateSystemLabels,
|
|
data: {
|
|
system_id: system,
|
|
value: labels,
|
|
},
|
|
});
|
|
setSystem(undefined);
|
|
}, []);
|
|
|
|
const onOpenSettings = useCallback(() => {
|
|
const { system, outCommand } = ref.current;
|
|
if (!system) {
|
|
return;
|
|
}
|
|
|
|
outCommand({
|
|
type: OutCommand.openSettings,
|
|
data: {
|
|
system_id: system,
|
|
},
|
|
});
|
|
setSystem(undefined);
|
|
}, []);
|
|
|
|
const onWaypointSet: WaypointSetContextHandler = useCallback(({ charIds, clearWay, fromBeginning, destination }) => {
|
|
const { system, outCommand } = ref.current;
|
|
if (!system) {
|
|
return;
|
|
}
|
|
|
|
outCommand({
|
|
type: OutCommand.setAutopilotWaypoint,
|
|
data: {
|
|
character_eve_ids: charIds,
|
|
add_to_beginning: fromBeginning,
|
|
clear_other_waypoints: clearWay,
|
|
destination_id: destination,
|
|
},
|
|
});
|
|
setSystem(undefined);
|
|
}, []);
|
|
|
|
return {
|
|
open,
|
|
|
|
contextMenuRef,
|
|
onDeleteSystem,
|
|
onLockToggle,
|
|
onHubToggle,
|
|
onSystemTag,
|
|
onSystemStatus,
|
|
onSystemLabels,
|
|
onOpenSettings,
|
|
onWaypointSet,
|
|
systemId: system,
|
|
};
|
|
};
|