From fc3e3906bc92d72480ba8b8ee981c21e2aa950cd Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sat, 22 May 2021 13:25:37 +0800 Subject: [PATCH] write shit successfully --- Core/ClipboardUtil.cs | 8 ++++++++ Core/TASFile.cs | 2 +- Core/Util.cs | 19 ++++++++++++++++--- MainWindow.xaml | 10 +++++----- MainWindow.xaml.cs | 42 ++++++++++++++++++++++++++++++++++++++++++ UI/AddItem.xaml | 2 +- UI/TASFlow.xaml | 2 +- UI/TASViewer.cs | 31 +++++++++++++++++++++++++------ 8 files changed, 99 insertions(+), 17 deletions(-) diff --git a/Core/ClipboardUtil.cs b/Core/ClipboardUtil.cs index 7169aa0..02a559f 100644 --- a/Core/ClipboardUtil.cs +++ b/Core/ClipboardUtil.cs @@ -29,7 +29,11 @@ namespace BallanceTASEditor.Core { Clipboard.SetDataObject(data, true); } return true; +#if DEBUG + } catch (Exception e) { +#else } catch { +#endif return false; } } @@ -55,7 +59,11 @@ namespace BallanceTASEditor.Core { } return true; +#if DEBUG + } catch (Exception e) { +#else } catch { +#endif return false; } } diff --git a/Core/TASFile.cs b/Core/TASFile.cs index a30b560..deec381 100644 --- a/Core/TASFile.cs +++ b/Core/TASFile.cs @@ -92,7 +92,7 @@ namespace BallanceTASEditor.Core { // if state is true, it mean the deleted content is placed before pointer previously. // so we need shift the pointer to the head of selection range. // and we should consider 2 situations, the full delete of LinkedList and delete from head - if (mPointerIndex <= absoluteRange.end) { + if (mPointerIndex >= absoluteRange.start) { var newIndex = absoluteRange.start - 1; if (newIndex < 0) { // this contains 2 situation diff --git a/Core/Util.cs b/Core/Util.cs index 737d327..4b3863b 100644 --- a/Core/Util.cs +++ b/Core/Util.cs @@ -8,6 +8,19 @@ using System.Text; namespace BallanceTASEditor.Core { public static class Util { + public static Int32 ToInt32(this double value) { + return (Int32)Math.Floor(value); + } + public static Int64 ToInt64(this double value) { + return (Int64)Math.Floor(value); + } + + public static int Clamp(int value, int min, int max) { + if (value < min) return min; + if (value > max) return max; + return value; + } + public static bool ToBool(this UInt32 num) { return (num != 0); } @@ -29,11 +42,11 @@ namespace BallanceTASEditor.Core { } public static LinkedListNode FastGetNode(this LinkedList ls, LinkedListNode refNode, long refIndex, long targetIndex) { - long count = ls.Count; - if (targetIndex >= count || refIndex >= count) throw new Exception("Index is invalid!"); + long count = ls.Count - 1; + if (targetIndex > count || refIndex > count) throw new Exception("Index is invalid!"); var span = new StupidSortStruct[3] { new StupidSortStruct() { type = 1, data = targetIndex }, - new StupidSortStruct() { type = 2, data = count - targetIndex }, + new StupidSortStruct() { type = 2, data = targetIndex - count }, new StupidSortStruct() { type = 3, data = targetIndex - refIndex } }; diff --git a/MainWindow.xaml b/MainWindow.xaml index e0ad970..981889f 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:BallanceTASEditor" xmlns:controls="clr-namespace:BallanceTASEditor.UI" mc:Ignorable="d" - Title="Ballance TAS Editor" Height="500" Width="800"> + Title="Ballance TAS Editor" Height="500" Width="800" KeyUp="funcWindow_KeyUp"> @@ -85,14 +85,14 @@ - - - -