Skip to content

Commit

Permalink
Merge pull request #142 from OliBomby/dev
Browse files Browse the repository at this point in the history
fixes and features
  • Loading branch information
OliBomby authored Apr 3, 2021
2 parents be83147 + 72ea2d0 commit eb4d026
Show file tree
Hide file tree
Showing 21 changed files with 265 additions and 151 deletions.
3 changes: 2 additions & 1 deletion Mapping Tools/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml"
ShutdownMode="OnMainWindowClose">
ShutdownMode="OnMainWindowClose"
DispatcherUnhandledException="App_DispatcherUnhandledException">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down
12 changes: 7 additions & 5 deletions Mapping Tools/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
using System.IO;
using System.Windows;
using System.Windows.Threading;
using static Mapping_Tools.MainWindow;

namespace Mapping_Tools {
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) {
// Process unhandled exception
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) {
// Log the exception, display it, etc
var exception = e.Exception;
var lines = new List<string> { exception.Message, exception.StackTrace, exception.Source };

Expand All @@ -22,12 +23,13 @@ void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptio
lines.Add(exception.Source);
}

var path = Path.Combine("crash-log.txt");
const string filename = "crash-log.txt";
var path = AppDataPath != null ? Path.Combine(AppDataPath, filename) : filename;
File.WriteAllLines(path, lines);
MessageBox.Show($"The program encountered an unhandled exception. Look in crash-log.txt for more info:\n{path}", "Error");
MessageBox.Show($"The program encountered an unhandled exception. Look in {filename} for more info:\n{path}", "Error");

// Prevent default unhandled exception processing
e.Handled = true;
e.Handled = AppDataPath != null;
}
}
}
58 changes: 37 additions & 21 deletions Mapping Tools/Classes/HitsoundStuff/HitsoundZone.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
using Mapping_Tools.Classes.MathUtil;
using Mapping_Tools.Classes.BeatmapHelper.Enums;
using Mapping_Tools.Classes.MathUtil;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Mapping_Tools.Classes.BeatmapHelper;
using Mapping_Tools.Classes.BeatmapHelper.Enums;

namespace Mapping_Tools.Classes.HitsoundStuff
{
namespace Mapping_Tools.Classes.HitsoundStuff {
/// <summary>
///
/// </summary>
Expand All @@ -21,29 +15,33 @@ public class HitsoundZone : INotifyPropertyChanged
private string _filename;
private double _xPos;
private double _yPos;
private SampleSet _sampleSet;
private Hitsound _hitsound;
private SampleSet _sampleSet;
private SampleSet _additionsSet;
private int _customIndex;

/// <inheritdoc />
public HitsoundZone() {
_isSelected = false;
_name = "";
_filename = "";
_xPos = -1;
_yPos = -1;
_sampleSet = SampleSet.Auto;
_hitsound = Hitsound.Normal;
_sampleSet = SampleSet.Auto;
_additionsSet = SampleSet.Auto;
_customIndex = 0;
}

/// <inheritdoc />
public HitsoundZone(bool isSelected, string name, string filename, double xPos, double yPos, SampleSet sampleSet, Hitsound hitsound) {
public HitsoundZone(bool isSelected, string name, string filename, double xPos, double yPos, Hitsound hitsound, SampleSet sampleSet, SampleSet additionsSet, int customIndex) {
_isSelected = isSelected;
_name = name;
_filename = filename;
_xPos = xPos;
_yPos = yPos;
_sampleSet = sampleSet;
_hitsound = hitsound;
_sampleSet = sampleSet;
_additionsSet = additionsSet;
_customIndex = customIndex;
}

/// <summary>
Expand All @@ -62,11 +60,11 @@ public double Distance(Vector2 pos) {
/// </summary>
/// <returns></returns>
public HitsoundZone Copy() {
return new HitsoundZone(IsSelected, Name, Filename, XPos, YPos, SampleSet, Hitsound);
return new HitsoundZone(IsSelected, Name, Filename, XPos, YPos, Hitsound, SampleSet, AdditionsSet, CustomIndex);
}

public bool IsSelected {
get { return _isSelected; }
get => _isSelected;
set {
if (_isSelected == value) return;
_isSelected = value;
Expand Down Expand Up @@ -110,6 +108,15 @@ public double YPos {
}
}

public Hitsound Hitsound {
get => _hitsound;
set {
if (_hitsound == value) return;
_hitsound = value;
OnPropertyChanged();
}
}

public SampleSet SampleSet {
get => _sampleSet;
set {
Expand All @@ -119,11 +126,20 @@ public SampleSet SampleSet {
}
}

public Hitsound Hitsound {
get => _hitsound;
public SampleSet AdditionsSet {
get => _additionsSet;
set {
if (_hitsound == value) return;
_hitsound = value;
if (_additionsSet == value) return;
_additionsSet = value;
OnPropertyChanged();
}
}

public int CustomIndex {
get => _customIndex;
set {
if (_customIndex == value) return;
_customIndex = value;
OnPropertyChanged();
}
}
Expand Down
31 changes: 26 additions & 5 deletions Mapping Tools/Classes/HitsoundStuff/SamplePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,48 @@ public void SetAllOutsideVolume(double outsideVolume) {
public SampleSet GetSampleSet() {
SampleSet sampleSet = SampleSet.Auto;
int bestPriority = int.MaxValue;
foreach (var sample in Samples)
{
if (sample.Hitsound == 0 && sample.Priority <= bestPriority)
{
foreach (var sample in Samples) {
if (sample.Hitsound == 0 && sample.Priority <= bestPriority) {
sampleSet = sample.SampleSet;
bestPriority = sample.Priority;
}
}

// If only auto was found, try to get a sampleset from the additions
if (sampleSet == SampleSet.Auto) {
bestPriority = int.MaxValue;
foreach (var sample in Samples) {
if (sample.Hitsound != 0 && sample.Priority <= bestPriority) {
sampleSet = sample.SampleSet;
bestPriority = sample.Priority;
}
}
}

return sampleSet;
}

public SampleSet GetAdditions() {
SampleSet additions = SampleSet.Auto;
int bestPriority = int.MaxValue;
foreach (Sample sample in Samples) {
foreach (var sample in Samples) {
if (sample.Hitsound != 0 && sample.Priority <= bestPriority) {
additions = sample.SampleSet;
bestPriority = sample.Priority;
}
}

// If only auto was found, try to get a sampleset from the normals
if (additions == SampleSet.Auto) {
bestPriority = int.MaxValue;
foreach (var sample in Samples) {
if (sample.Hitsound == 0 && sample.Priority <= bestPriority) {
additions = sample.SampleSet;
bestPriority = sample.Priority;
}
}
}

return additions;
}

Expand Down
4 changes: 1 addition & 3 deletions Mapping Tools/Classes/SystemTools/IOHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ public static string GetCurrentBeatmap() {
Console.WriteLine(ex.StackTrace);
try {
var reader = EditorReaderStuff.GetEditorReader();
reader.FetchEditor();
reader.SetHOM();
reader.ReadHOM();
reader.FetchHOM();
reader.FetchBeatmap();
path = EditorReaderStuff.GetCurrentBeatmap(reader);
}
Expand Down
10 changes: 7 additions & 3 deletions Mapping Tools/Classes/SystemTools/ListenerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,13 @@ private static void QuickUndo() {
System.Windows.Application.Current.Dispatcher.Invoke(BackupManager.QuickUndo);
}

private static void QuickBetterSave()
{
EditorReaderStuff.BetterSave();
private static void QuickBetterSave() {
try {
EditorReaderStuff.BetterSave();
}
catch (Exception e) {
e.Show();
}
}

private static void SmartQuickRun()
Expand Down
50 changes: 50 additions & 0 deletions Mapping Tools/Components/Domain/DoubleArrayToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Mapping_Tools.Classes.BeatmapHelper;
using Mapping_Tools.Classes.SystemTools;
using System;
using System.Globalization;
using System.Text;
using System.Windows.Controls;
using System.Windows.Data;

namespace Mapping_Tools.Components.Domain {
internal class DoubleArrayToStringConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
if (!(value is double[] beatDivisors)) return string.Empty;

var builder = new StringBuilder();
bool first = true;
foreach (var d in beatDivisors) {
if (!first) {
builder.Append(", ");
}

builder.Append(d.ToInvariant());

first = false;
}

return builder.ToString();
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
if (!(value is string str)) return new double[0];
if (string.IsNullOrWhiteSpace(str)) return new double[0];

var vals = str.Split(',');
var beatDivisors = new double[vals.Length];

for (int i = 0; i < vals.Length; i++) {
var val = vals[i];

var valid = TypeConverters.TryParseDouble(val, out double doubleValue);
if (valid) {
beatDivisors[i] = doubleValue;
} else {
return new ValidationResult(false, "Double format error.");
}
}

return beatDivisors;
}
}
}
10 changes: 9 additions & 1 deletion Mapping Tools/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ShowInTaskbar="True"
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
Background="{DynamicResource MaterialDesignPaper}"
Closing="Window_Closing"
>
<WindowChrome.WindowChrome>
<WindowChrome
Expand Down Expand Up @@ -55,7 +56,14 @@
<StackPanel WindowChrome.IsHitTestVisibleInChrome="true" HorizontalAlignment="Right" Orientation="Horizontal">
<Button Style="{DynamicResource MaterialDesignFlatButton}" Content="{materialDesign:PackIcon WindowMinimize}" Click="MinimizeWin" Panel.ZIndex="1" Foreground="{DynamicResource MaterialDesignBody}"/>
<Button x:Name="toggle_button" Style="{DynamicResource MaterialDesignFlatButton}" Content="{materialDesign:PackIcon WindowMaximize}" Click="ToggleWin" Foreground="{DynamicResource MaterialDesignBody}"/>
<Button Style="{DynamicResource MaterialDesignFlatButton}" Content="{materialDesign:PackIcon WindowCLose}" Click="CloseWin" Foreground="{DynamicResource MaterialDesignBody}"/>
<Button Style="{DynamicResource MaterialDesignFlatButton}" Content="{materialDesign:PackIcon WindowCLose}" Click="CloseWin" Foreground="{DynamicResource MaterialDesignBody}">
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="_Exit without saving" Click="CloseWinNoSave"
ToolTip="Exits the program without saving any preferences or tool settings."/>
</ContextMenu>
</Button.ContextMenu>
</Button>
</StackPanel>
</Grid>

Expand Down
Loading

0 comments on commit eb4d026

Please sign in to comment.