Skip to content

Commit

Permalink
Added tooltips, fixed inverted delete logic, added dialog when quest …
Browse files Browse the repository at this point in the history
…connection fails, using resource brushes for everything
  • Loading branch information
tommaier123 committed Feb 28, 2022
1 parent a19da33 commit 9146045
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 72 deletions.
105 changes: 72 additions & 33 deletions NoodleManagerX/MainWindow.axaml

Large diffs are not rendered by default.

64 changes: 35 additions & 29 deletions NoodleManagerX/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@ namespace NoodleManagerX
public class MainWindow : Window
{
public static MainWindow s_instance;
public static BrushConverter brushConverter = new BrushConverter();
public static BrushConverter BrushConverter = new BrushConverter();

private const string tabActiveColor = "#f91c85";
private const string tabInactiveColor = "#aa49e0";
private const string difficultyActiveColor = "#ffffff";
private const string difficultyInactiveColor = "#888888";
public static Brush tabActiveBrush;
public static Brush tabInactiveBrush;
public static Brush difficultyActiveBrush;
public static Brush difficultyInactiveBrush;
public static Brush TabActiveBrush;
public static Brush TabInactiveBrush;
public static Brush DifficultyActiveBrush;
public static Brush DifficultyInactiveBrush;

private Grid blackBar;
private bool lastleftclick = false;
Expand All @@ -36,11 +32,6 @@ public MainWindow()
{
s_instance = this;

tabActiveBrush = (Brush)brushConverter.ConvertFromString(tabActiveColor);
tabInactiveBrush = (Brush)brushConverter.ConvertFromString(tabInactiveColor);
difficultyActiveBrush = (Brush)brushConverter.ConvertFromString(difficultyActiveColor);
difficultyInactiveBrush = (Brush)brushConverter.ConvertFromString(difficultyInactiveColor);

this.DataContext = new MainViewModel();

InitializeComponent();
Expand Down Expand Up @@ -100,6 +91,23 @@ private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}

public static Brush GetBrush(Brush brush, string colorResource)
{
if (brush == null)
{
try
{
brush = MainWindow.s_instance.Resources[colorResource] as Brush;
}
catch
{
brush = (Brush)BrushConverter.ConvertFromString("#ff00ff");
}
}

return brush;
}
}

public class EqualsConverter : IValueConverter
Expand Down Expand Up @@ -131,7 +139,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
throw new ArgumentNullException(nameof(value));
}

return (value.ToString() == parameter.ToString()) ? MainWindow.tabActiveBrush : MainWindow.tabInactiveBrush;
return (value.ToString() == parameter.ToString()) ? MainWindow.GetBrush(MainWindow.TabActiveBrush, "TabActiveColor") : MainWindow.GetBrush(MainWindow.TabInactiveBrush, "TabInactiveColor");
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down Expand Up @@ -174,7 +182,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
present = difficulties.Contains("Custom");
break;
}
return (present) ? MainWindow.difficultyActiveBrush : MainWindow.difficultyInactiveBrush;
return (present) ? MainWindow.GetBrush(MainWindow.DifficultyActiveBrush, "DifficultyActiveColor") : MainWindow.GetBrush(MainWindow.DifficultyInactiveBrush, "DifficultyInactiveColor");
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand All @@ -189,7 +197,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
{
if (value == null || parameter == null)
{
throw new ArgumentNullException(nameof(value));
throw new ArgumentNullException();
}
string[] paths = ((string)parameter).Split("|");
if (paths.Length > 1)
Expand All @@ -212,16 +220,11 @@ public class TwoParameterPathConverter : IMultiValueConverter
{
public object Convert(IList<object> values, Type targetType, object parameter, CultureInfo culture)
{
if (parameter == null)
if (parameter == null || values == null || values.Count != 2)
{
throw new ArgumentNullException();
}

if (values == null || values.Count != 2)
{
throw new ArgumentOutOfRangeException(nameof(values));
}

string[] paths = ((string)parameter).Split("|");

if (paths.Count() > 4)
Expand Down Expand Up @@ -279,16 +282,19 @@ public class BoolColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
string par = parameter.ToString();
if (value == null || String.IsNullOrEmpty(par))
{
throw new ArgumentNullException(nameof(value));
throw new ArgumentNullException();
}
string[] par = parameter.ToString().Split("|");
if (par.Length != 2)

string[] colors = ((string)parameter).Split("|");
if (colors.Length != 2)
{
throw new ArgumentNullException(nameof(value));
throw new ArgumentOutOfRangeException(nameof(colors));
}
return ((bool)value) ? (Brush)MainWindow.brushConverter.ConvertFromString(par[0]) : (Brush)MainWindow.brushConverter.ConvertFromString(par[1]);

return ((bool)value) ? MainWindow.GetBrush(null, colors[0]) : MainWindow.GetBrush(null, colors[1]);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
4 changes: 3 additions & 1 deletion NoodleManagerX/Models/DownloadScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ public static void Remove(GenericItem item)
_ = Dispatcher.UIThread.InvokeAsync(() =>
{
MainViewModel.s_instance.progress = 0;
MainViewModel.s_instance.progressText = null;
});
}
else
{
_ = Dispatcher.UIThread.InvokeAsync(() =>
{
MainViewModel.s_instance.progress = 100 - (int)((queue.Count + downloading.Count) / (toDownload * 0.01f));
MainViewModel.s_instance.progress = Math.Min(100 - (int)((queue.Count + downloading.Count) / (toDownload * 0.01f)), 1);
MainViewModel.s_instance.progressText = "Downloading: " + MainViewModel.s_instance.progress + "% (" + (toDownload - queue.Count - downloading.Count) + "/" + toDownload + ")";
});
}
}
Expand Down
6 changes: 5 additions & 1 deletion NoodleManagerX/Models/GenericHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public async Task LoadLocalItems()
_ = Dispatcher.UIThread.InvokeAsync(() =>
{
MainViewModel.s_instance.progress = (int)(i / (localFilenames.Length * 0.01f));
MainViewModel.s_instance.progressText = "Loading Database: " + MainViewModel.s_instance.progress + "% (" + i + "/" + localFilenames.Length + ")";
});

if (extensions.Contains(Path.GetExtension(filename)))
Expand Down Expand Up @@ -88,6 +89,7 @@ public async Task LoadLocalItems()
_ = Dispatcher.UIThread.InvokeAsync(() =>
{
MainViewModel.s_instance.progress = 0;
MainViewModel.s_instance.progressText = null;
});
}
catch (Exception e) { MainViewModel.Log(MethodBase.GetCurrentMethod(), e); }
Expand Down Expand Up @@ -290,17 +292,19 @@ public async Task GetAll()
}
pageCountAll = page.pagecount;

if (DownloadScheduler.queue.Count == 0)
if (DownloadScheduler.queue.Count == 0 && DownloadScheduler.downloading.Count == 0)
{
_ = Dispatcher.UIThread.InvokeAsync(() =>
{
if (i < pageCountAll)
{
MainViewModel.s_instance.progress = (int)(i / (pageCountAll * 0.01f));
MainViewModel.s_instance.progressText = "Getting All (checking for new maps): " + MainViewModel.s_instance.progress + "% (" + i + "/" + pageCountAll + ")";
}
else
{
MainViewModel.s_instance.progress = 0;
MainViewModel.s_instance.progressText = null;
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion NoodleManagerX/Models/GenericItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public bool Delete(string filename)
try
{
StorageAbstraction.DeleteFile(Path.Combine(target, filename));
MainViewModel.s_instance.localItems = MainViewModel.s_instance.localItems.Where(x => x != null && x.itemType == itemType && x.filename == filename).ToList();
MainViewModel.s_instance.localItems = MainViewModel.s_instance.localItems.Where(x => x != null && !(x.itemType == itemType && x.filename == filename)).ToList();
return true;
}
catch (Exception e) { MainViewModel.Log(MethodBase.GetCurrentMethod(), e); }
Expand Down
11 changes: 7 additions & 4 deletions NoodleManagerX/Models/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ class MainViewModel : ReactiveObject
//possibly remove unnecessary flags from function parameters, use state machine/individual parameters
//get description when rightclicking an item and display in context menu
//multiple files
//update reminder
//don't leave thread safety up to luck
//get a updated at timestamp for updating, published at is fine for filesystem timestamp



[Reactive] private string version { get; set; } = "V0.7.0";
[Reactive] private string version { get; set; } = "V0.7.2";

public static MainViewModel s_instance;

Expand All @@ -69,6 +67,7 @@ class MainViewModel : ReactiveObject
[Reactive] private string synthDirectory { get; set; }
[Reactive] public bool directoryValid { get; set; }
[Reactive] public int progress { get; set; } = 0;
[Reactive] public string progressText { get; set; } = null;
[Reactive] public bool questConnected { get; set; } = false;
[Reactive] public bool updatingLocalItems { get; set; } = false;

Expand Down Expand Up @@ -202,6 +201,7 @@ public MainViewModel()
_ = Dispatcher.UIThread.InvokeAsync(() =>
{
progress = 1;
progressText = "Getting Page";

});
foreach (GenericItem item in toDownload)
Expand Down Expand Up @@ -279,6 +279,7 @@ public MainViewModel()
_ = Dispatcher.UIThread.InvokeAsync(() =>
{
progress = e.ProgressPercentage;
progressText = "Updating: " + progress + "%";
});
};
string temp = Path.GetTempPath();
Expand Down Expand Up @@ -428,6 +429,7 @@ public Task GetAll()
if (StorageAbstraction.CanDownload() && !updatingLocalItems)
{
progress = 1;
progressText = "Getting All";
DownloadScheduler.toDownload = DownloadScheduler.queue.Count;

return Task.Run(async () =>
Expand Down Expand Up @@ -534,6 +536,7 @@ public Task LoadLocalItems()
await Dispatcher.UIThread.InvokeAsync(() =>
{
progress = 1;
progressText = "Loading Database";
updatingLocalItems = true;
});

Expand Down Expand Up @@ -593,7 +596,7 @@ await Dispatcher.UIThread.InvokeAsync(async () =>
{
updatingLocalItems = false;
progress = 0;

progressText = null;
});
});
}
Expand Down
17 changes: 14 additions & 3 deletions NoodleManagerX/Models/MtpDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static class MtpDevice
public static string path = "";
public static bool connected = false;

public static void Connect(bool reload = false)
public static void Connect(bool isCommand = false)
{
if (!connected)
{
Expand All @@ -30,20 +30,31 @@ public static void Connect(bool reload = false)
string dir = Path.Combine(directory, "SynthRidersUC");
if (d.DirectoryExists(dir))
{
MainViewModel.Log("Synth Riders device found " + d.Description);
MainViewModel.Log("Synth Riders device found " + d.FriendlyName);
device = d;
path = dir;
connected = true;
MainViewModel.s_instance.questConnected = true;
d.DeviceRemoved += DeviceRemoved;
if (reload) MainViewModel.s_instance.ReloadLocalSources();
if (isCommand) MainViewModel.s_instance.ReloadLocalSources();
return;
}
}
d.Disconnect();
}
catch { }
}
if (isCommand)
{
if (devices.Count() > 0)
{
MainViewModel.s_instance.OpenErrorDialog("Found " + devices.Count() + " MTP devices but none of them had the SynthRidersUC folder" + Environment.NewLine + String.Join(Environment.NewLine, devices.Select(x => x.FriendlyName)));
}
else
{
MainViewModel.s_instance.OpenErrorDialog("No MTP devices found" + Environment.NewLine + "Make sure to allow storage access on the headset");
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions NoodleManagerX/NoodleManagerX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<TrimMode>link</TrimMode>
<DebugType>embedded</DebugType>
<Platforms>AnyCPU;x64</Platforms>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.Invariant" Value="true" />
Expand Down

0 comments on commit 9146045

Please sign in to comment.