Skip to content

Commit

Permalink
Actions tab can be cancelled, updated styling for cancel button (#37)
Browse files Browse the repository at this point in the history
* Cancel button for Actions tab
* Clean tab selection changed code
* Update Cancel button styling & changed Cancel text to X icon
* Reset visibility to collapsed
* Fix issue with action tab
  • Loading branch information
Dyvinia authored Apr 4, 2022
1 parent 6903275 commit 395d1f6
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 84 deletions.
127 changes: 65 additions & 62 deletions FrostyModManager/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ public partial class MainWindow : FrostyWindow
private List<FrostyPack> packs = new List<FrostyPack>();
private FrostyPack selectedPack;
private FileSystem fs;
private TabItem currentTab;

private static int manifestVersion = 1;

Expand Down Expand Up @@ -1315,78 +1314,84 @@ private void UpdateConflicts()
StringBuilder sb = new StringBuilder();
List<ModResourceInfo> totalResourceList = new List<ModResourceInfo>();

FrostyTaskWindow.Show("Updating Actions", "", (task) =>
{
// Iterate through mod resources
for (int i = 0; i < selectedPack.AppliedMods.Count; i++)
{
FrostyAppliedMod appliedMod = selectedPack.AppliedMods[i];
if (!appliedMod.IsEnabled)
continue;

FrostyMod mod = appliedMod.Mod;
if (mod.NewFormat)
{
foreach (BaseModResource resource in mod.Resources)
{
if (resource.Type == ModResourceType.Embedded)
continue;
CancellationTokenSource cancelToken = new CancellationTokenSource();

string resType = resource.Type.ToString().ToLower();
string resourceName = resource.Name;
bool cancelled = false;
FrostyTaskWindow.Show("Updating Actions", "", (task) => {
try {
// Iterate through mod resources
for (int i = 0; i < selectedPack.AppliedMods.Count; i++) {
FrostyAppliedMod appliedMod = selectedPack.AppliedMods[i];
if (!appliedMod.IsEnabled)
continue;

FrostyMod mod = appliedMod.Mod;
if (mod.NewFormat) {
foreach (BaseModResource resource in mod.Resources) {
if (resource.Type == ModResourceType.Embedded)
continue;

if (resource.UserData != "")
{
string[] arr = resource.UserData.Split(';');
resType = arr[0].ToLower();
resourceName = arr[1];
}
string resType = resource.Type.ToString().ToLower();
string resourceName = resource.Name;

int index = totalResourceList.FindIndex((ModResourceInfo a) => a.Equals(resType + "/" + resourceName));
if (resource.UserData != "") {
string[] arr = resource.UserData.Split(';');
resType = arr[0].ToLower();
resourceName = arr[1];
}

if (index == -1)
{
ModResourceInfo resInfo = new ModResourceInfo(resourceName, resType);
totalResourceList.Add(resInfo);
index = totalResourceList.Count - 1;
}
int index = totalResourceList.FindIndex((ModResourceInfo a) => a.Equals(resType + "/" + resourceName));

ModPrimaryActionType primaryAction = ModPrimaryActionType.None;
if (resource.HasHandler)
{
if ((uint)resource.Handler == 0xBD9BFB65)
primaryAction = ModPrimaryActionType.Merge;
else
{
ICustomActionHandler handler = null;
if (resource.Type == ModResourceType.Ebx)
handler = App.PluginManager.GetCustomHandler((uint)resource.Handler);
else if (resource.Type == ModResourceType.Res)
handler = App.PluginManager.GetCustomHandler((ResourceType)(resource as ResResource).ResType);
if (index == -1) {
ModResourceInfo resInfo = new ModResourceInfo(resourceName, resType);
totalResourceList.Add(resInfo);
index = totalResourceList.Count - 1;
}

cancelToken.Token.ThrowIfCancellationRequested();

if (handler.Usage == HandlerUsage.Merge)
{
foreach (string actionString in handler.GetResourceActions(resource.Name, mod.GetResourceData(resource)))
{
string[] arr = actionString.Split(';');
AddResourceAction(totalResourceList, mod.Filename, arr[0], arr[1], (ModPrimaryActionType)Enum.Parse(typeof(ModPrimaryActionType), arr[2]));
}
ModPrimaryActionType primaryAction = ModPrimaryActionType.None;
if (resource.HasHandler) {
if ((uint)resource.Handler == 0xBD9BFB65)
primaryAction = ModPrimaryActionType.Merge;
else {
ICustomActionHandler handler = null;
if (resource.Type == ModResourceType.Ebx)
handler = App.PluginManager.GetCustomHandler((uint)resource.Handler);
else if (resource.Type == ModResourceType.Res)
handler = App.PluginManager.GetCustomHandler((ResourceType)(resource as ResResource).ResType);

if (handler.Usage == HandlerUsage.Merge) {
foreach (string actionString in handler.GetResourceActions(resource.Name, mod.GetResourceData(resource))) {
string[] arr = actionString.Split(';');
AddResourceAction(totalResourceList, mod.Filename, arr[0], arr[1], (ModPrimaryActionType)Enum.Parse(typeof(ModPrimaryActionType), arr[2]));
}
primaryAction = ModPrimaryActionType.Merge;
}
else primaryAction = ModPrimaryActionType.Modify;
}
else primaryAction = ModPrimaryActionType.Modify;
}
}
else if (resource.IsAdded) primaryAction = ModPrimaryActionType.Add;
else if (resource.IsModified) primaryAction = ModPrimaryActionType.Modify;
else if (resource.IsAdded) primaryAction = ModPrimaryActionType.Add;
else if (resource.IsModified) primaryAction = ModPrimaryActionType.Modify;

totalResourceList[index].AddMod(mod.Filename, primaryAction, resource.AddedBundles);
totalResourceList[index].AddMod(mod.Filename, primaryAction, resource.AddedBundles);
}
}
}

}
catch (OperationCanceledException) {
cancelled = true;
}

if (onlyShowReplacements)
totalResourceList.RemoveAll(item => item.ModCount <= 1);
});
}, showCancelButton: true, cancelCallback: (task) => cancelToken.Cancel());

if (cancelled) {
Dispatcher.BeginInvoke((Action)(() => tabControl.SelectedItem = appliedModsTabItem));
return;
}

List<GridViewColumn> columns = new List<GridViewColumn>
{
Expand Down Expand Up @@ -1454,6 +1459,7 @@ private void UpdateConflicts()
return result == 0 ? a.Name.CompareTo(b.Name) : result;
});

Dispatcher.BeginInvoke((Action)(() => tabControl.SelectedItem = conflictsTabItem));
conflictsListView.ItemsSource = totalResourceList;
conflictsListView.SelectedIndex = 0;
}
Expand All @@ -1473,11 +1479,8 @@ private void AddResourceAction(List<ModResourceInfo> totalResourceList, string m

private void tabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (tabControl.SelectedItem != currentTab)
{
currentTab = tabControl.SelectedItem as TabItem;
if (currentTab == conflictsTabItem)
UpdateConflicts();
if (conflictsTabItem.IsSelected) {
UpdateConflicts();
}
}

Expand Down
50 changes: 28 additions & 22 deletions FrostyPlugin/Windows/FrostyTaskWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,6 @@
mc:Ignorable="d"
Title="" Height="150" Width="400" AllowsTransparency="True" WindowStyle="None" Background="Transparent" UseLayoutRounding="True" SnapsToDevicePixels="True"
WindowStartupLocation="CenterOwner" ShowInTaskbar="False">
<Window.Resources>
<Style x:Key="CancelButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="{StaticResource FontColor}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="buttonBorder" Background="Transparent" BorderThickness="0" CornerRadius="4">
<ContentPresenter x:Name="content" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="{TemplateBinding Padding}">
<ContentPresenter.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextDecorations" Value="Underline" />
</Style>
</ContentPresenter.Resources>
</ContentPresenter>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid x:Name="taskWindow" Visibility="Visible" SnapsToDevicePixels="True">
<Border Background="Transparent"/>
<Border Background="{StaticResource ControlBackground}" VerticalAlignment="Center" HorizontalAlignment="Center" Width="350" Height="125" BorderBrush="{StaticResource ListBackground}" BorderThickness="1">
Expand Down Expand Up @@ -57,8 +37,34 @@

<TextBlock x:Name="statusTextBox" Grid.Column="1" Background="Transparent" Text="Status Text" Padding="4,5,4,0" Foreground="{StaticResource FontColor}" FontFamily="Global User Interface" TextTrimming="CharacterEllipsis"/>

<Button x:Name="cancelButton" Grid.Column="2" Content="Cancel" Margin="0" Padding="8 0 8 0" Style="{StaticResource CancelButtonStyle}" Visibility="Collapsed" Cursor="Hand"/>

<Button x:Name="cancelButton" Grid.Column="2" Margin="0" Visibility="Collapsed" Cursor="Hand">
<Image Source="/FrostyControls;component/Images/CloseWindow.png"/>
<!--<TextBlock Padding="8 0 8 0" TextDecorations="Underline">
Cancel
</TextBlock>-->
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource FontColor}"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="0.6"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Opacity" Value="0.4"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}" >
<Border Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" Margin="{TemplateBinding Padding}"/>
</Border>
</ControlTemplate>
</Button.Template>
</Button>

</Grid>
</Grid>
</Border>
Expand Down

0 comments on commit 395d1f6

Please sign in to comment.