Skip to content

Commit

Permalink
Merge pull request #4 from BlackTasty/multi_select_across_decks
Browse files Browse the repository at this point in the history
Added new issue trackers, multi-select across decks is now possible
  • Loading branch information
BlackTasty authored Jun 3, 2024
2 parents cbcf6d2 + 18ff145 commit 11013b5
Show file tree
Hide file tree
Showing 31 changed files with 758 additions and 299 deletions.
13 changes: 13 additions & 0 deletions SLC_LayoutEditor/Controls/CabinDeckControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ public CabinDeckControl()
renderer?.SelectAllSlots();
}
}, ViewModelMessage.Keybind_SelectAllSlotsOnDeck);

Mediator.Instance.Register(o =>
{
if (o is CabinDeck cabinDeck && cabinDeck != CabinDeck)
{
renderer.DeselectAllSlots(false);
}
}, ViewModelMessage.DeselectOther_Deck);
}

public void RefreshCabinDeckLayout()
Expand Down Expand Up @@ -146,6 +154,11 @@ public void RefreshCabinDeckLayout()
Logger.Default.WriteLog("Cabin deck rendered in {0} seconds", Math.Round((double)sw.ElapsedMilliseconds / 1000, 3));
}

public void SelectAllSlots(bool fireEvent)
{
renderer.SelectAllSlots(fireEvent);
}

private void Renderer_CloseTooltip(object sender, EventArgs e)
{
if (tooltip != null)
Expand Down
66 changes: 33 additions & 33 deletions SLC_LayoutEditor/Controls/CabinLayoutControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,39 @@
</Grid.RowDefinitions>
<Border Grid.RowSpan="2" Background="{DynamicResource TemplatingModeBackBrush}"
Visibility="{Binding RelativeSource={RelativeSource AncestorType=local:CabinLayoutControl, Mode=FindAncestor}, Path=CabinLayout.IsTemplate, FallbackValue=Collapsed, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<ScrollViewer x:Name="deck_scroll" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Grid.RowSpan="2"
PreviewMouseWheel="deck_scroll_PreviewMouseWheel" ScrollChanged="deck_scroll_ScrollChanged">
<ScrollViewer.Style>
<Style TargetType="ScrollViewer" BasedOn="{StaticResource {x:Type ScrollViewer}}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:CabinLayoutControl, Mode=FindAncestor}, Path=IsHorizontalScrollBarVisible, UpdateSourceTrigger=PropertyChanged}" Value="True"/>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:CabinLayoutControl, Mode=FindAncestor}, Path=IsVerticalScrollBarVisible, UpdateSourceTrigger=PropertyChanged}" Value="False"/>
</MultiDataTrigger.Conditions>
<Setter Property="Margin" Value="0,0,0,-14"/>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:CabinLayoutControl, Mode=FindAncestor}, Path=IsHorizontalScrollBarVisible, UpdateSourceTrigger=PropertyChanged}" Value="False"/>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:CabinLayoutControl, Mode=FindAncestor}, Path=IsVerticalScrollBarVisible, UpdateSourceTrigger=PropertyChanged}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter Property="Margin" Value="0,0,-14,0"/>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:CabinLayoutControl, Mode=FindAncestor}, Path=IsHorizontalScrollBarVisible, UpdateSourceTrigger=PropertyChanged}" Value="True"/>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:CabinLayoutControl, Mode=FindAncestor}, Path=IsVerticalScrollBarVisible, UpdateSourceTrigger=PropertyChanged}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter Property="Margin" Value="0,0,-14,-14"/>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</ScrollViewer.Style>
<StackPanel x:Name="container_decks" Grid.IsSharedSizeScope="True" Margin="0,91,0,96"
Loaded="container_decks_Loaded"
SizeChanged="deck_scroll_SizeChanged">

<ScrollViewer x:Name="deck_scroll" VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto" Grid.RowSpan="2"
PreviewMouseWheel="deck_scroll_PreviewMouseWheel" ScrollChanged="deck_scroll_ScrollChanged">
<ScrollViewer.Style>
<Style TargetType="ScrollViewer" BasedOn="{StaticResource {x:Type ScrollViewer}}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:CabinLayoutControl, Mode=FindAncestor}, Path=IsHorizontalScrollBarVisible, UpdateSourceTrigger=PropertyChanged}" Value="True"/>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:CabinLayoutControl, Mode=FindAncestor}, Path=IsVerticalScrollBarVisible, UpdateSourceTrigger=PropertyChanged}" Value="False"/>
</MultiDataTrigger.Conditions>
<Setter Property="Margin" Value="0,0,0,-14"/>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:CabinLayoutControl, Mode=FindAncestor}, Path=IsHorizontalScrollBarVisible, UpdateSourceTrigger=PropertyChanged}" Value="False"/>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:CabinLayoutControl, Mode=FindAncestor}, Path=IsVerticalScrollBarVisible, UpdateSourceTrigger=PropertyChanged}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter Property="Margin" Value="0,0,-14,0"/>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:CabinLayoutControl, Mode=FindAncestor}, Path=IsHorizontalScrollBarVisible, UpdateSourceTrigger=PropertyChanged}" Value="True"/>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:CabinLayoutControl, Mode=FindAncestor}, Path=IsVerticalScrollBarVisible, UpdateSourceTrigger=PropertyChanged}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter Property="Margin" Value="0,0,-14,-14"/>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</ScrollViewer.Style>
<StackPanel x:Name="container_decks" Grid.IsSharedSizeScope="True" Margin="0,91,0,96"
Loaded="container_decks_Loaded"
SizeChanged="deck_scroll_SizeChanged">
</StackPanel>
</ScrollViewer>
<Border Grid.RowSpan="2">
Expand Down
68 changes: 22 additions & 46 deletions SLC_LayoutEditor/Controls/CabinLayoutControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,11 @@ protected void InvokePropertyChanged(params string[] propertyNames)
public event EventHandler<ChangedEventArgs> Changed;
public event EventHandler<EventArgs> TemplatingModeToggled;
public event EventHandler<TemplateCreatedEventArgs> TemplateCreated;
public event EventHandler<SelectedDeckChangedEventArgs> SelectedDeckChanged;

public event EventHandler<CabinDeckChangedEventArgs> CabinDeckChanged;

private CabinDeck currentRemoveTarget;

private CabinDeckControl selectedDeck;

#region CabinLayout property
public CabinLayout CabinLayout
{
Expand Down Expand Up @@ -106,18 +103,6 @@ private static string GetCabinLayoutValueForLog(CabinLayout cabinLayout)
}
#endregion

#region SelectedCabinSlots property
public List<CabinSlot> SelectedCabinSlots
{
get { return (List<CabinSlot>)GetValue(SelectedCabinSlotsProperty); }
set { SetValue(SelectedCabinSlotsProperty, value); }
}

// Using a DependencyProperty as the backing store for SelectedCabinSlots. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SelectedCabinSlotsProperty =
DependencyProperty.Register("SelectedCabinSlots", typeof(List<CabinSlot>), typeof(CabinLayoutControl), new PropertyMetadata(new List<CabinSlot>()));
#endregion

public ContextMenu GuideMenu
{
get { return (ContextMenu)GetValue(GuideMenuProperty); }
Expand All @@ -138,18 +123,6 @@ public ContextMenu GuideMenu

public bool IsVerticalScrollBarVisible => deck_scroll.ComputedVerticalScrollBarVisibility == Visibility.Visible;

#region SelectedCabinSlotFloor property
public int SelectedCabinSlotFloor
{
get { return (int)GetValue(SelectedCabinSlotFloorProperty); }
set { SetValue(SelectedCabinSlotFloorProperty, value); }
}

// Using a DependencyProperty as the backing store for SelectedCabinSlotFloor. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SelectedCabinSlotFloorProperty =
DependencyProperty.Register("SelectedCabinSlotFloor", typeof(int), typeof(CabinLayoutControl), new PropertyMetadata(0));
#endregion

#region SelectedMultiSlotTypeIndex properties
public int SelectedMultiSlotTypeIndex
{
Expand Down Expand Up @@ -216,6 +189,24 @@ public CabinLayoutControl()
{
StartReloadLayout();
}, ViewModelMessage.Keybind_ReloadLayout);

Mediator.Instance.Register(o =>
{
foreach (CabinDeckControl deckLayoutControl in container_decks.Children.OfType<CabinDeckControl>())
{
deckLayoutControl.SelectAllSlots(true);
}
}, ViewModelMessage.SelectAll_Layout);

Mediator.Instance.Register(o =>
{
if (o is int floor)
{
container_decks.Children.OfType<CabinDeckControl>()
.FirstOrDefault(x => x.CabinDeck.Floor == floor)
?.SelectAllSlots(true);
}
}, ViewModelMessage.SelectAll_Deck);
}

public void GenerateThumbnailForLayout(bool overwrite = false)
Expand Down Expand Up @@ -324,23 +315,15 @@ private void AddCabinDeckToUI(CabinDeck cabinDeck)

public void DeselectSlots()
{
selectedDeck?.DeselectSlots();
foreach (CabinDeckControl cabinDeckControl in container_decks.Children.OfType<CabinDeckControl>())
{
cabinDeckControl.DeselectSlots();
}
}

private void CabinDeckControl_SelectedSlotsChanged(object sender, SelectedSlotsChangedEventArgs e)
{
if (selectedDeck != null &&
selectedDeck.CabinDeck.Floor != e.DeckControl.CabinDeck.Floor)
{
DeselectSlots();
}

SelectedCabinSlots = e.NewSelection.ToList();
SelectedCabinSlotFloor = e.Floor;
selectedDeck = e.DeckControl;

OnSelectedSlotsChanged(e);
OnSelectedDeckChanged(new SelectedDeckChangedEventArgs(selectedDeck));
}

private void CabinDeckControl_DeckRendered(object sender, EventArgs e)
Expand Down Expand Up @@ -504,8 +487,6 @@ private void ReloadDeck_DialogClosing(object sender, DialogClosingEventArgs e)

private void ReloadLayout()
{
SelectedCabinSlots.Clear();
selectedDeck?.SelectSlots(SelectedCabinSlots);
CabinLayout.LoadCabinLayoutFromFile(true);
RefreshCabinLayout(false);
OnLayoutReloaded(EventArgs.Empty);
Expand Down Expand Up @@ -633,11 +614,6 @@ private void EditCabinLayoutName_Click(object sender, RoutedEventArgs e)
Mediator.Instance.NotifyColleagues(ViewModelMessage.EditLayoutNameRequested, CabinLayout);
}

protected virtual void OnSelectedDeckChanged(SelectedDeckChangedEventArgs e)
{
SelectedDeckChanged?.Invoke(this, e);
}

protected virtual void OnSelectedSlotsChanged(SelectedSlotsChangedEventArgs e)
{
SelectedSlotsChanged?.Invoke(this, e);
Expand Down
29 changes: 29 additions & 0 deletions SLC_LayoutEditor/Controls/IssueTracker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,35 @@
ShowAutoFix="True"
AutoFixApplying="DuplicateDoors_AutoFixApplying"
Description="Make sure that each door has a unique number across all decks"/>
<local:LayoutProblemText ValidText="Less than 100 doors/bays"
IsValid="{Binding ActiveLayout.HasNoDoorSurplus}"
ShowEye="False"
Description="Any cabin layout can only have a maximum of 99 total catering doors, loading bays and doors">
<local:LayoutProblemText.Style>
<Style TargetType="local:LayoutProblemText">
<Setter Property="InvalidText" Value="{Binding ActiveLayout.DoorSurplus, StringFormat={}{0} doors more than allowed!}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ActiveLayout.DoorSurplus}" Value="1">
<Setter Property="InvalidText" Value="1 door more than allowed!"/>
</DataTrigger>
</Style.Triggers>
</Style>
</local:LayoutProblemText.Style>
</local:LayoutProblemText>
<local:LayoutProblemText ValidText="Less than 10 catering doors"
IsValid="{Binding ActiveLayout.HasNoCateringDoorSurplus}"
ShowEye="False"
Description="Any cabin layout can only have a maximum of 9 catering doors">
<local:LayoutProblemText.Style>
<Style TargetType="local:LayoutProblemText">
<Setter Property="InvalidText" Value="{Binding ActiveLayout.CateringDoorSurplus, StringFormat={}{0} catering doors more than allowed!}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ActiveLayout.CateringDoorSurplus}" Value="1">
<Setter Property="InvalidText" Value="1 catering door more than allowed!"/>
</DataTrigger>
</Style.Triggers>
</Style>
</local:LayoutProblemText.Style></local:LayoutProblemText>

<local:LayoutProblemText ValidText="Stairway positions valid"
InvalidText="{Binding StairwayErrorMessage}"
Expand Down
18 changes: 16 additions & 2 deletions SLC_LayoutEditor/Controls/IssueTracker.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,23 @@ private void StairwayPositions_AutoFixApplying(object sender, AutoFixApplyingEve
{
if (e.Target is CabinLayout target)
{
target.FixStairwayPositions();
AutoFixResult result = target.FixStairwayPositions();

string message = result.FailCount > 0 ?
string.Format("{0} non-aisle slots have been overridden while fixing {1} stairway positions.", result.FailCount, result.SuccessCount) :
string.Format("Fixed {0} stairway positions.", result.SuccessCount);

result.SendNotification(message);
}
}

private void Slots_AutoFixApplying(object sender, AutoFixApplyingEventArgs e)
{
if (e.Target is CabinDeck target)
{
target.FixSlotCount();
AutoFixResult result = target.FixSlotCount();

result.SendNotification(string.Format("{0} missing slots have been added to your layout", result.SuccessCount));
}
}

Expand All @@ -133,6 +141,12 @@ private void DuplicateDoors_AutoFixApplying(object sender, AutoFixApplyingEventA
{
AutoFixResult result = target.FixDuplicateDoors();

string message = result.FailCount > 0 ?
string.Format("{0}/{1} door numbers have been\nadjusted successfully.\n{2} doors could not be adjusted.", result.SuccessCount, result.TotalCount, result.FailCount) :
string.Format("{0} door numbers have been adjusted.", result.SuccessCount);

result.SendNotification(message);

if (App.GuidedTour.IsAwaitingAutoFix)
{
App.GuidedTour.ForceCompleteEntry(0, result.AllSucceeded);
Expand Down
Loading

0 comments on commit 11013b5

Please sign in to comment.