diff --git a/WHMapper.Tests/WHMapper.Tests.csproj b/WHMapper.Tests/WHMapper.Tests.csproj index e42865ba..c4dfe715 100644 --- a/WHMapper.Tests/WHMapper.Tests.csproj +++ b/WHMapper.Tests/WHMapper.Tests.csproj @@ -10,8 +10,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -19,8 +19,8 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - - + + diff --git a/WHMapper/Pages/Mapper/CustomNode/EveSystemNode.cs b/WHMapper/Pages/Mapper/CustomNode/EveSystemNode.cs index 03774ea6..a2c1e347 100644 --- a/WHMapper/Pages/Mapper/CustomNode/EveSystemNode.cs +++ b/WHMapper/Pages/Mapper/CustomNode/EveSystemNode.cs @@ -19,24 +19,12 @@ namespace WHMapper.Pages.Mapper.CustomNode { public partial class EveSystemNode : ComponentBase { - private const string MENU_LOCK_SYSTEM_VALUE = "Lock"; - private const string MENU_UNLOCK_SYSTEM_VALUE = "Unlock"; - - private EveSystemNodeModel _node = null!; private string _secColor = IWHColorHelper.DEFAULT_COLOR; private string _systemColor = IWHColorHelper.DEFAULT_COLOR; private string _whEffectColor = IWHColorHelper.DEFAULT_COLOR; - private string _menu_lock_value = MENU_LOCK_SYSTEM_VALUE; - private string _menu_lock_icon_value = Icons.Material.Sharp.Lock; - - [Inject] - IEveAPIServices EveServices { get; set; } = null!; - - [Inject] - IWHSystemRepository DbWHSystems { get; set; } = null!; [Inject] public ILogger Logger { get; set; } = null!; @@ -61,98 +49,9 @@ public EveSystemNodeModel Node _secColor = WHColorHelper.GetSecurityStatusColor(_node.SecurityStatus); _systemColor = WHColorHelper.GetSystemTypeColor(_node.SystemType); _whEffectColor = WHColorHelper.GetEffectColor(_node.Effect); - - Locked = _node.Locked; - - } - } - } - - private bool Locked - { - get - { - if (_node != null) - return _node.Locked; - else - return false; - } - set - { - if(_node!=null) - { - _node.Locked = value; - - if (_node.Locked) - { - _menu_lock_value = MENU_UNLOCK_SYSTEM_VALUE; - _menu_lock_icon_value = Icons.Material.Sharp.LockOpen; - } - else - { - _menu_lock_value = MENU_LOCK_SYSTEM_VALUE; - _menu_lock_icon_value = Icons.Material.Sharp.Lock; - } - StateHasChanged(); } } } - - - - private async Task SetSelectedSystemDestinationWaypoint() - { - try - { - if (_node.Selected) - { - var res = await EveServices.UserInterfaceServices.SetWaypoint(_node.SolarSystemId, false, true); - return true; - - } - - return false; - } - catch (Exception ex) - { - Logger.LogError(ex, "Set destination waypoint error"); - return false; - } - } - - private async Task ToggleSystemLock() - { - try - { - var whSystem = await DbWHSystems.GetById(_node.IdWH); - if (whSystem != null && whSystem.Id==_node.IdWH) - { - whSystem.Locked = !whSystem.Locked; - whSystem = await DbWHSystems.Update(whSystem.Id, whSystem); - if (whSystem == null) - { - Logger.LogError("Update lock system status error"); - return false; - } - - Locked = whSystem.Locked; - _node.Refresh(); - return true; - } - else - { - return false; - } - - - } - catch (Exception ex) - { - Logger.LogError(ex, "Toggle destination waypoint error"); - return false; - } - - } } } diff --git a/WHMapper/Pages/Mapper/CustomNode/EveSystemNode.razor b/WHMapper/Pages/Mapper/CustomNode/EveSystemNode.razor index a21f7d93..a38d163f 100644 --- a/WHMapper/Pages/Mapper/CustomNode/EveSystemNode.razor +++ b/WHMapper/Pages/Mapper/CustomNode/EveSystemNode.razor @@ -3,83 +3,74 @@ @using WHMapper.Models.DTO.EveMapper.Enums; - - - - - - - @Node.SystemType.ToDescriptionString() - - - - @Node.Name - - - @if (Locked) - { - - } - @if (Node != null && Node.Effect != WHMapper.Models.DTO.EveMapper.Enums.WHEffect.None) - { - - - - - - - @foreach (var effectInfo in Node.EffectDetails) - { - @effectInfo.Name. : @effectInfo.Value% - } - - - - } - - - - -
- @if (Node != null && Node.ConnectedUsers != null && Node.ConnectedUsers.FirstOrDefault() != null) - { - - - - - - - @foreach (var user in @Node.ConnectedUsers) - { - @user - } - - - - } - else - { - - } - @Node?.ConnectedUsers.FirstOrDefault() -
-
- @if (Node != null && Node.Statics != null && Node?.Statics.Count() > 0) - { - @foreach (var item in Node.Statics) - { - @item.EveSystemDestinationType.ToString() - } - } -
-
-
-
- - Set Destination - @_menu_lock_value - -
+ + + + + @Node.SystemType.ToDescriptionString() + + + + @Node.Name + + + @if (_node.Locked) + { + + } + @if (Node != null && Node.Effect != WHMapper.Models.DTO.EveMapper.Enums.WHEffect.None) + { + + + + + + + @foreach (var effectInfo in Node.EffectDetails) + { + @effectInfo.Name. : @effectInfo.Value% + } + + + + } + + + +
+ @if (Node != null && Node.ConnectedUsers != null && Node.ConnectedUsers.FirstOrDefault() != null) + { + + + + + + + @foreach (var user in @Node.ConnectedUsers) + { + @user + } + + + + } + else + { + + } + @Node?.ConnectedUsers.FirstOrDefault() +
+
+ @if (Node != null && Node.Statics != null && Node?.Statics.Count() > 0) + { + @foreach (var item in Node.Statics) + { + @item.EveSystemDestinationType.ToString() + } + } +
+
+
diff --git a/WHMapper/Pages/Mapper/Overview.cs b/WHMapper/Pages/Mapper/Overview.cs index 2cf91b44..8a58df61 100644 --- a/WHMapper/Pages/Mapper/Overview.cs +++ b/WHMapper/Pages/Mapper/Overview.cs @@ -26,6 +26,9 @@ using WHMapper.Services.EveMapper; using Blazor.Diagrams.Core.Behaviors; using WHMapper.Models.DTO.EveMapper.Enums; +using Blazor.Diagrams.Core; +using MudBlazor.Utilities; +using System.Xml.Linq; namespace WHMapper.Pages.Mapper { @@ -34,6 +37,12 @@ namespace WHMapper.Pages.Mapper [Authorize(Policy = "Access")] public partial class Overview : ComponentBase, IAsyncDisposable { + private const string MENU_LOCK_SYSTEM_VALUE = "Lock"; + private const string MENU_UNLOCK_SYSTEM_VALUE = "Unlock"; + + private string _menu_lock_value = MENU_LOCK_SYSTEM_VALUE; + private string _menu_lock_icon_value = Icons.Material.Sharp.Lock; + protected BlazorDiagram Diagram { get; private set; } = null!; private MudMenu ClickRightMenu { get; set; } = null!; private WHMapper.Pages.Mapper.Signatures.Overview WHSignaturesView { get; set; } = null!; @@ -46,16 +55,16 @@ public partial class Overview : ComponentBase, IAsyncDisposable private int _currentWHSystemId = 0; private EveSystemNodeModel? _selectedSystemNode = null; private EveSystemLinkModel? _selectedSystemLink = null; - + private ICollection? _selectedSystemNodes = null; private ICollection? _selectedSystemLinks = null; - private PeriodicTimer _timer=null!; - private CancellationTokenSource _cts= null!; + private PeriodicTimer _timer = null!; + private CancellationTokenSource _cts = null!; private SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(1, 1); - private HubConnection _hubConnection=null!; + private HubConnection _hubConnection = null!; [Inject] IAuthorizationService AuthorizationService { get; set; } = null!; @@ -90,7 +99,7 @@ public partial class Overview : ComponentBase, IAsyncDisposable [Inject] public ISnackbar Snackbar { get; set; } = null!; - [Inject] IWHSignatureHelper SignatureHelper { get; set; } = null!; + [Inject] IWHSignatureHelper SignatureHelper { get; set; } = null!; [Inject] public NavigationManager Navigation { get; set; } = null!; @@ -108,7 +117,7 @@ public partial class Overview : ComponentBase, IAsyncDisposable private IEnumerable WHMaps { get; set; } = new List(); private WHMap _selectedWHMap = null!; - + private int _selectedWHMapIndex = 0; private int SelectedWHMapIndex { @@ -121,7 +130,7 @@ private int SelectedWHMapIndex if (_selectedWHMapIndex != value) { _selectedWHMapIndex = value; - if(WHMaps!=null) + if (WHMaps != null) _selectedWHMap = WHMaps.ElementAtOrDefault(value); } } @@ -147,7 +156,7 @@ protected override async Task OnInitializedAsync() protected override async Task OnAfterRenderAsync(bool firstRender) { - if(firstRender) + if (firstRender) { var user = (await AuthenticationStateTask).User; @@ -199,7 +208,7 @@ private async Task InitNotificationHub() { Snackbar?.Add($"{user} are connected", Severity.Info); } - catch(Exception ex) + catch (Exception ex) { Logger.LogError(ex, "On NotifyUserConnected error"); } @@ -293,7 +302,7 @@ await Parallel.ForEachAsync(usersPosition, async (item, cancellationToken) => { try { - if (DbWHMaps!=null && _selectedWHMap!=null && wormholeId > 0 && _selectedWHMap?.Id== mapId) + if (DbWHMaps != null && _selectedWHMap != null && wormholeId > 0 && _selectedWHMap?.Id == mapId) { _selectedWHMap = await DbWHMaps.GetById(mapId); var systemNodeToDelete = Diagram?.Nodes?.FirstOrDefault(x => ((EveSystemNodeModel)x).IdWH == wormholeId); @@ -327,7 +336,7 @@ await Parallel.ForEachAsync(usersPosition, async (item, cancellationToken) => { try { - if (DbWHMaps != null && linKId > 0 && _selectedWHMap!=null && _selectedWHMap?.Id== mapId ) + if (DbWHMaps != null && linKId > 0 && _selectedWHMap != null && _selectedWHMap?.Id == mapId) { _selectedWHMap = await DbWHMaps.GetById(mapId); var link = _selectedWHMap.WHSystemLinks.Where(x => x.Id == linKId).SingleOrDefault(); @@ -350,7 +359,7 @@ await Parallel.ForEachAsync(usersPosition, async (item, cancellationToken) => try { if (DbWHMaps != null && linKId > 0 && _selectedWHMap != null && _selectedWHMap?.Id == mapId) - { + { _selectedWHMap = await DbWHMaps.GetById(mapId); var linkToDel = Diagram?.Links?.FirstOrDefault(x => ((EveSystemLinkModel)x).Id == linKId); @@ -384,7 +393,7 @@ await Parallel.ForEachAsync(usersPosition, async (item, cancellationToken) => } }); - _hubConnection.On("NotifyLinkChanged",async (user, mapId, linkId, eol, size, mass) => + _hubConnection.On("NotifyLinkChanged", async (user, mapId, linkId, eol, size, mass) => { try { @@ -407,7 +416,7 @@ await Parallel.ForEachAsync(usersPosition, async (item, cancellationToken) => } }); - _hubConnection.On("NotifyWormholeNameExtensionChanged", async (user, mapId, wormholeId,increment) => + _hubConnection.On("NotifyWormholeNameExtensionChanged", async (user, mapId, wormholeId, increment) => { try { @@ -462,7 +471,7 @@ await Parallel.ForEachAsync(usersPosition, async (item, cancellationToken) => { _selectedWHMap = await DbWHMaps.GetById(mapId); EveSystemNodeModel whChangeLock = (EveSystemNodeModel)Diagram?.Nodes?.FirstOrDefault(x => ((EveSystemNodeModel)x).IdWH == wormholeId); - if(whChangeLock!=null) + if (whChangeLock != null) { whChangeLock.Locked = locked; whChangeLock.Refresh(); @@ -482,7 +491,7 @@ await Parallel.ForEachAsync(usersPosition, async (item, cancellationToken) => } return false; } - catch(Exception ex) + catch (Exception ex) { Logger.LogError(ex, "InitNotificationHub error"); return false; @@ -498,11 +507,11 @@ private async Task NotifyUserPosition(string systemName) } } - private async Task NotifyWormoleAdded(int mapId,int wormholeId) + private async Task NotifyWormoleAdded(int mapId, int wormholeId) { if (_hubConnection is not null) { - await _hubConnection.SendAsync("SendWormholeAdded", mapId,wormholeId); + await _hubConnection.SendAsync("SendWormholeAdded", mapId, wormholeId); } } @@ -510,11 +519,11 @@ private async Task NotifyWormholeRemoved(int mapId, int wormholeId) { if (_hubConnection is not null) { - await _hubConnection.SendAsync("SendWormholeRemoved", mapId,wormholeId); + await _hubConnection.SendAsync("SendWormholeRemoved", mapId, wormholeId); } } - private async Task NotifyLinkAdded(int mapId,int linkId) + private async Task NotifyLinkAdded(int mapId, int linkId) { if (_hubConnection is not null) { @@ -530,7 +539,7 @@ private async Task NotifyLinkRemoved(int mapId, int linkId) } } - private async Task NotifyWormholeMoved(int mapId, int wormholeId,double posX,double posY) + private async Task NotifyWormholeMoved(int mapId, int wormholeId, double posX, double posY) { if (_hubConnection is not null) { @@ -538,7 +547,7 @@ private async Task NotifyWormholeMoved(int mapId, int wormholeId,double posX,dou } } - private async Task NotifyLinkChanged(int mapId,int linkId, bool eol, SystemLinkSize size, SystemLinkMassStatus mass) + private async Task NotifyLinkChanged(int mapId, int linkId, bool eol, SystemLinkSize size, SystemLinkMassStatus mass) { if (_hubConnection is not null) { @@ -546,7 +555,7 @@ private async Task NotifyLinkChanged(int mapId,int linkId, bool eol, SystemLinkS } } - private async Task NotifyWormholeNameExtensionChanged(int mapId, int wormholeId,bool increment) + private async Task NotifyWormholeNameExtensionChanged(int mapId, int wormholeId, bool increment) { if (_hubConnection is not null) { @@ -593,13 +602,14 @@ private async Task InitDiagram() Diagram.Options.Zoom.Inverse = false; Diagram.Options.Links.EnableSnapping = false; Diagram.Options.AllowMultiSelection = true; + Diagram.RegisterComponent(); Diagram.RegisterComponent(); } return true; - } - catch(Exception ex) + } + catch (Exception ex) { Logger.LogError(ex, "Init Diagram Error"); return false; @@ -624,9 +634,17 @@ private async Task OnDiagramSelectionChanged(Blazor.Diagrams.Core.Models.Base.Se _selectedSystemLink = null; if (((EveSystemNodeModel)item).Selected) + { _selectedSystemNode = (EveSystemNodeModel)item; + Diagram.SendToFront(_selectedSystemNode); + } else + { + if (_selectedSystemNode != null) + Diagram.SendToBack(_selectedSystemNode); + _selectedSystemNode = null; + } StateHasChanged(); return; @@ -642,7 +660,7 @@ private async Task OnDiagramSelectionChanged(Blazor.Diagrams.Core.Models.Base.Se else _selectedSystemLink = null; - + StateHasChanged(); return; } @@ -691,8 +709,8 @@ private async Task OnDiagramKeyDown(Blazor.Diagrams.Core.Events.KeyboardEventArg private async Task OnLinkSystemKeyPressed(Blazor.Diagrams.Core.Events.KeyboardEventArgs eventArgs) { if (eventArgs.Code == "KeyL" && _selectedWHMap != null && _selectedSystemNodes != null && _selectedSystemNodes.Count() == 2) - { - + { + if (IsLinkExist(_selectedSystemNodes.ElementAt(0), _selectedSystemNodes.ElementAt(1))) { Snackbar.Add("Nodes are already linked", Severity.Warning); @@ -709,7 +727,7 @@ private async Task OnLinkSystemKeyPressed(Blazor.Diagrams.Core.Events.Keyb else return true; } - + } return false; @@ -771,7 +789,7 @@ private async Task OnDeleteKeyPressed(Blazor.Diagrams.Core.Events.Keyboard } else { - Snackbar?.Add(string.Format("{0} wormhole is locked.You can't remove it.",node.Name), Severity.Warning); + Snackbar?.Add(string.Format("{0} wormhole is locked.You can't remove it.", node.Name), Severity.Warning); } } @@ -820,6 +838,8 @@ private async Task OnDeleteKeyPressed(Blazor.Diagrams.Core.Events.Keyboard #endregion + + private async Task OnDiagramPointerUp(Blazor.Diagrams.Core.Models.Base.Model? item, Blazor.Diagrams.Core.Events.PointerEventArgs eventArgs) { if (item == null) @@ -863,7 +883,7 @@ private async Task OnDiagramPointerUp(Blazor.Diagrams.Core.Models.Base.Model? it } } - + } private async Task Restore() @@ -891,7 +911,7 @@ private async Task Restore() } - + if (_selectedWHMap != null && _selectedWHMap.WHSystems.Count > 0) { @@ -905,9 +925,9 @@ private async Task Restore() } - if (_selectedWHMap!=null && _selectedWHMap.WHSystemLinks!=null && _selectedWHMap.WHSystemLinks.Count > 0) + if (_selectedWHMap != null && _selectedWHMap.WHSystemLinks != null && _selectedWHMap.WHSystemLinks.Count > 0) { - + foreach (WHSystemLink dbWHSysLink in _selectedWHMap.WHSystemLinks) { var whFrom = await DbWHSystems.GetById(dbWHSysLink.IdWHSystemFrom); @@ -922,7 +942,7 @@ private async Task Restore() else { Logger.LogWarning("Bad Link,Auto remove"); - if(await DbWHSystemLinks.DeleteById(dbWHSysLink.Id)) + if (await DbWHSystemLinks.DeleteById(dbWHSysLink.Id)) { _selectedWHMap.WHSystemLinks.Remove(dbWHSysLink); } @@ -932,16 +952,16 @@ private async Task Restore() Logger.LogInformation("Restore Mapper Success"); StateHasChanged(); return true; - + } - catch(Exception ex) + catch (Exception ex) { Logger.LogError(ex, "Mapper Restore"); return false; } } - private async Task HandleTimerAsync() + private async Task HandleTimerAsync() { _currentLocation = null; _currentSystemNode = null; @@ -963,13 +983,13 @@ private async Task HandleTimerAsync() _cts.Cancel();//todo redirect to logout } } - catch(OperationCanceledException oce) + catch (OperationCanceledException oce) { Logger.LogInformation(oce, "Cancel operation"); } catch (Exception ex) { - Logger.LogError(ex,"Polling error"); + Logger.LogError(ex, "Polling error"); } } @@ -983,7 +1003,7 @@ private async Task DeletedNodeOnMap(WHMap map, EveSystemNodeModel node) return false; } - if(map.WHSystems.Count>0 && map.WHSystems.FirstOrDefault(x=>x.Id==node.IdWH)==null) + if (map.WHSystems.Count > 0 && map.WHSystems.FirstOrDefault(x => x.Id == node.IdWH) == null) { Logger.LogError("DeletedNodeOnMap map doesn't contain this node"); return false; @@ -992,14 +1012,14 @@ private async Task DeletedNodeOnMap(WHMap map, EveSystemNodeModel node) if (await DbWHSystems.DeleteById(node.IdWH) != null) { var whSystemToDelete = map.WHSystems.FirstOrDefault(x => x.Id == node.IdWH); - if(whSystemToDelete!=null) + if (whSystemToDelete != null) map.WHSystems.Remove(whSystemToDelete); //db link will be automatically delete via db foreignkey cascade var whSystemLinksToDetele = map.WHSystemLinks.Where(x => x.IdWHSystemFrom == node.IdWH || x.IdWHSystemTo == node.IdWH); - foreach(var linkToDelete in whSystemLinksToDetele) + foreach (var linkToDelete in whSystemLinksToDetele) map.WHSystemLinks.Remove(linkToDelete); - + await NotifyWormholeRemoved(map.Id, node.IdWH); return true; } @@ -1023,7 +1043,7 @@ private async Task DeletedLinkOnMap(WHMap map, EveSystemLinkModel link) return false; } - if(await DbWHSystemLinks.DeleteById(link.Id)) + if (await DbWHSystemLinks.DeleteById(link.Id)) { var whSystemLinkToDelete = map.WHSystemLinks.FirstOrDefault(x => x.Id == link.Id); if (whSystemLinkToDelete != null) @@ -1043,7 +1063,7 @@ private async Task DeletedLinkOnMap(WHMap map, EveSystemLinkModel link) } - private async Task IncrementOrDecrementNodeExtensionNameOnMap(WHMap map, EveSystemNodeModel node,bool increment) + private async Task IncrementOrDecrementNodeExtensionNameOnMap(WHMap map, EveSystemNodeModel node, bool increment) { try { @@ -1085,7 +1105,7 @@ private async Task IncrementOrDecrementNodeExtensionNameOnMap(WHMap map, E return false; } } - + private async Task CreateLink(WHMap map, EveSystemNodeModel src, EveSystemNodeModel target) { try @@ -1108,7 +1128,7 @@ private async Task CreateLink(WHMap map, EveSystemNodeModel src, EveSystem } return false; } - catch(Exception ex) + catch (Exception ex) { Logger.LogError(ex, "Create link error"); return false; @@ -1156,13 +1176,13 @@ private async Task IsRouteViaWH(SolarSystem src, SolarSystem dst) return false; - if((src != null && src.Stargates==null) || dst.Stargates==null) + if ((src != null && src.Stargates == null) || dst.Stargates == null) return true; else { int[]? startgatesToCheck = null; int systemTarget = -1; - if (src!=null && src.Stargates.Length <= dst.Stargates.Length) + if (src != null && src.Stargates.Length <= dst.Stargates.Length) { startgatesToCheck = dst.Stargates; systemTarget = src.SystemId; @@ -1181,14 +1201,14 @@ private async Task IsRouteViaWH(SolarSystem src, SolarSystem dst) return false; } - return true; + return true; } } private async Task AutoMapper() { EveSystemNodeModel? previousSystem = null; - SolarSystem? previousSolarSystem = null; + SolarSystem? previousSolarSystem = null; WHSystem? newWHSystem = null; double defaultNewSystemPosX = 0; double defaultNewSystemPosY = 0; @@ -1196,8 +1216,8 @@ private async Task AutoMapper() try { EveLocation el = await EveServices.LocationServices.GetLocation(); - - if (el != null && (_currentLocation == null || _currentLocation.SolarSystemId != el.SolarSystemId) ) + + if (el != null && (_currentLocation == null || _currentLocation.SolarSystemId != el.SolarSystemId)) { previousSystem = _currentSystemNode; previousSolarSystem = _currentSolarSystem; @@ -1210,16 +1230,16 @@ private async Task AutoMapper() //determine position on map. depends of previous system if (previousSystem != null) { - defaultNewSystemPosX = (double)previousSystem.Position.X + previousSystem.Size.Width + 10; + defaultNewSystemPosX = (double)previousSystem.Position.X + previousSystem.Size.Width + 10; defaultNewSystemPosY = (double)previousSystem.Position.Y + previousSystem.Size.Height + 10; } //determine if source have same system link and get next unique ident - if(previousSystem != null && await IsRouteViaWH(previousSolarSystem, _currentSolarSystem)) + if (previousSystem != null && await IsRouteViaWH(previousSolarSystem, _currentSolarSystem)) { //test is WH - if(!MapperServices.IsWorhmole(_currentSolarSystem.Name)) + if (!MapperServices.IsWorhmole(_currentSolarSystem.Name)) { newWHSystem = await DbWHSystems.Create(new WHSystem(_selectedWHMap.Id, _currentSolarSystem.SystemId, _currentSolarSystem.Name, _currentSolarSystem.SecurityStatus, defaultNewSystemPosX, defaultNewSystemPosY)); } @@ -1228,7 +1248,7 @@ private async Task AutoMapper() //get whClass an determine if another connection to another wh with same class exist from previous system. Increment extension value in that case EveSystemType whClass = await MapperServices.GetWHClass(_currentSolarSystem); - int nbSameWHClassLink = Diagram.Links.Where(x => ((EveSystemNodeModel)x.Target.Model).SystemType==whClass && ((EveSystemNodeModel)x.Source.Model).IdWH == previousSystem.IdWH).Count(); + int nbSameWHClassLink = Diagram.Links.Where(x => ((EveSystemNodeModel)x.Target.Model).SystemType == whClass && ((EveSystemNodeModel)x.Source.Model).IdWH == previousSystem.IdWH).Count(); if (nbSameWHClassLink > 0) { @@ -1240,10 +1260,10 @@ private async Task AutoMapper() } } else - newWHSystem = await DbWHSystems.Create(new WHSystem(_selectedWHMap.Id,_currentSolarSystem.SystemId,_currentSolarSystem.Name, _currentSolarSystem.SecurityStatus, defaultNewSystemPosX, defaultNewSystemPosY)); - + newWHSystem = await DbWHSystems.Create(new WHSystem(_selectedWHMap.Id, _currentSolarSystem.SystemId, _currentSolarSystem.Name, _currentSolarSystem.SecurityStatus, defaultNewSystemPosX, defaultNewSystemPosY)); - if (newWHSystem!=null) + + if (newWHSystem != null) { var newSystemNode = await MapperServices.DefineEveSystemNodeModel(newWHSystem); newSystemNode.OnLocked += OnWHSystemNodeLocked; @@ -1256,7 +1276,7 @@ private async Task AutoMapper() if (previousSystem != null) { - if(!await CreateLink(_selectedWHMap, previousSystem, newSystemNode)) + if (!await CreateLink(_selectedWHMap, previousSystem, newSystemNode)) { Logger.LogError("Add Wormhole Link db error"); Snackbar?.Add("Add Wormhole Link db error", Severity.Error); @@ -1285,7 +1305,7 @@ private async Task AutoMapper() await previousSystem.RemoveConnectedUser(_userName); previousSystem.Refresh(); } - + _currentSystemNode = (EveSystemNodeModel)Diagram.Nodes.FirstOrDefault(x => string.Equals(x.Title, _currentSolarSystem.Name, StringComparison.OrdinalIgnoreCase)); await _currentSystemNode.AddConnectedUser(_userName); _currentSystemNode.Refresh(); @@ -1297,7 +1317,7 @@ private async Task AutoMapper() if (previousSystem != null) { - if(IsLinkExist(previousSystem, _currentSystemNode)==false) + if (IsLinkExist(previousSystem, _currentSystemNode) == false) { if (!await CreateLink(_selectedWHMap, previousSystem, _currentSystemNode)) { @@ -1305,11 +1325,11 @@ private async Task AutoMapper() Snackbar?.Add("Add Wormhole Link db error", Severity.Error); } } - } + } } } } - catch(Exception ex) + catch (Exception ex) { Logger.LogError(ex, "Auto mapper error"); } @@ -1348,6 +1368,89 @@ private void OnWHSystemNodeLocked(EveSystemNodeModel whNodeModel) #region Menu Actions + private void OnMenuOpen(MouseEventArgs args) + { + if (_selectedSystemNode != null || _selectedSystemLink!=null) + { + ClickRightMenu.PopoverStyle = $"margin-top: {args?.ClientY.ToPx()}; margin-left: {args?.ClientX.ToPx()};"; + } + } + + + private async Task SetSelectedSystemDestinationWaypoint() + { + try + { + if (_selectedSystemNode == null) + return false; + + if (_selectedSystemNode.Selected) + { + var res = await EveServices.UserInterfaceServices.SetWaypoint(_selectedSystemNode.SolarSystemId, false, true); + return true; + + } + + return false; + } + catch (Exception ex) + { + Logger.LogError(ex, "Set destination waypoint error"); + return false; + } + } + + private async Task ToggleSystemLock() + { + try + { + if (_selectedSystemNode == null) + return false; + + var whSystem = await DbWHSystems.GetById(_selectedSystemNode.IdWH); + if (whSystem != null && whSystem.Id == _selectedSystemNode.IdWH) + { + whSystem.Locked = !whSystem.Locked; + whSystem = await DbWHSystems.Update(whSystem.Id, whSystem); + if (whSystem == null) + { + Logger.LogError("Update lock system status error"); + return false; + } + + _selectedSystemNode.Locked = whSystem.Locked; + + if (_selectedSystemNode.Locked) + { + _menu_lock_value = MENU_UNLOCK_SYSTEM_VALUE; + _menu_lock_icon_value = Icons.Material.Sharp.LockOpen; + } + else + { + _menu_lock_value = MENU_LOCK_SYSTEM_VALUE; + _menu_lock_icon_value = Icons.Material.Sharp.Lock; + } + + _selectedSystemNode.Refresh(); + StateHasChanged(); + return true; + } + else + { + return false; + } + + + } + catch (Exception ex) + { + Logger.LogError(ex, "Toggle destination waypoint error"); + return false; + } + + } + + /// /// Menu intercep paste /// diff --git a/WHMapper/Pages/Mapper/Overview.razor b/WHMapper/Pages/Mapper/Overview.razor index 7b91dec8..99a0af6e 100644 --- a/WHMapper/Pages/Mapper/Overview.razor +++ b/WHMapper/Pages/Mapper/Overview.razor @@ -11,7 +11,7 @@ - + @if (!FeatureFlag.DISABLE_MULTI_MAP()) { @@ -79,6 +79,11 @@ } + @if (_selectedSystemNode != null) + { + Set Destination + @_menu_lock_value + } diff --git a/WHMapper/Pages/Mapper/Signatures/Overview.razor b/WHMapper/Pages/Mapper/Signatures/Overview.razor index 59b94499..909a1b2e 100644 --- a/WHMapper/Pages/Mapper/Signatures/Overview.razor +++ b/WHMapper/Pages/Mapper/Signatures/Overview.razor @@ -2,7 +2,7 @@ @using WHMapper.Models.DTO.EveMapper.Enums - diff --git a/WHMapper/Pages/Mapper/SystemInfos/Overview.razor b/WHMapper/Pages/Mapper/SystemInfos/Overview.razor index e8b62f89..fc14db0f 100644 --- a/WHMapper/Pages/Mapper/SystemInfos/Overview.razor +++ b/WHMapper/Pages/Mapper/SystemInfos/Overview.razor @@ -50,7 +50,7 @@ @_effect - @if (CurrentSystemNode?.Effect != WHMapper.Models.DTO.EveMapper.Enums.WHEffect.None) + @if (CurrentSystemNode != null && CurrentSystemNode?.Effect != WHMapper.Models.DTO.EveMapper.Enums.WHEffect.None) { @@ -60,7 +60,7 @@ @if (CurrentSystemNode != null && CurrentSystemNode.EffectDetails != null) { - foreach (var effectInfo in CurrentSystemNode?.EffectDetails) + foreach (var effectInfo in CurrentSystemNode.EffectDetails) { @effectInfo.Name : @effectInfo.Value% } @@ -87,4 +87,4 @@ } - \ No newline at end of file + diff --git a/WHMapper/WHMapper.csproj b/WHMapper/WHMapper.csproj index 32c1893b..bbccfdeb 100644 --- a/WHMapper/WHMapper.csproj +++ b/WHMapper/WHMapper.csproj @@ -81,8 +81,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -92,8 +92,8 @@ - - + +