From 1c57481f8455524e87c651c624a8b2ca22e2d1af Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Mon, 20 Sep 2021 13:58:10 +0800 Subject: [PATCH] remove TASFlow and re-define it as a assist class --- BallanceTASEditor/App.xaml.cs | 8 +- BallanceTASEditor/BallanceTASEditor.csproj | 9 +- BallanceTASEditor/Core/ConfigManager.cs | 4 + BallanceTASEditor/MainWindow.xaml | 84 +++++++- BallanceTASEditor/MainWindow.xaml.cs | 185 ++++++++++++++++-- .../UI/{TASFlow.xaml.cs => TASFlow.cs} | 86 +------- BallanceTASEditor/UI/TASFlow.xaml | 60 ------ BallanceTASEditor/UI/TASSlider.cs | 44 +++++ BallanceTASEditor/UI/TASViewer.cs | 126 +++++------- 9 files changed, 357 insertions(+), 249 deletions(-) rename BallanceTASEditor/UI/{TASFlow.xaml.cs => TASFlow.cs} (77%) delete mode 100644 BallanceTASEditor/UI/TASFlow.xaml create mode 100644 BallanceTASEditor/UI/TASSlider.cs diff --git a/BallanceTASEditor/App.xaml.cs b/BallanceTASEditor/App.xaml.cs index 4d2bd46..63a8110 100644 --- a/BallanceTASEditor/App.xaml.cs +++ b/BallanceTASEditor/App.xaml.cs @@ -29,13 +29,13 @@ namespace BallanceTASEditor { // init configure manager GlobalVariable.configManager = new Core.ConfigManager("ballance-tas-editor.cfg", new Dictionary() { - {"Language", CultureInfo.CurrentCulture.ThreeLetterWindowsLanguageName}, - {"ItemCount", "15"}, - {"IsHorizonLayout", "True"} + {Core.ConfigManager.CfgNode_Language, CultureInfo.CurrentCulture.ThreeLetterWindowsLanguageName}, + {Core.ConfigManager.CfgNode_ItemCount, "15"}, + {Core.ConfigManager.CfgNode_IsHorizonLayout, "True"} }); // init i18n - Core.I18NProcessor.ChangeLanguage(GlobalVariable.configManager.Configuration["Language"]); + Core.I18NProcessor.ChangeLanguage(GlobalVariable.configManager.Configuration[Core.ConfigManager.CfgNode_Language]); } diff --git a/BallanceTASEditor/BallanceTASEditor.csproj b/BallanceTASEditor/BallanceTASEditor.csproj index b6c04f6..eda5c69 100644 --- a/BallanceTASEditor/BallanceTASEditor.csproj +++ b/BallanceTASEditor/BallanceTASEditor.csproj @@ -76,9 +76,8 @@ - - TASFlow.xaml - + + @@ -110,10 +109,6 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - diff --git a/BallanceTASEditor/Core/ConfigManager.cs b/BallanceTASEditor/Core/ConfigManager.cs index 1d26303..2b7d382 100644 --- a/BallanceTASEditor/Core/ConfigManager.cs +++ b/BallanceTASEditor/Core/ConfigManager.cs @@ -20,6 +20,10 @@ namespace BallanceTASEditor.Core { string _defaultValue; public Dictionary Configuration; + public static readonly string CfgNode_Language = "Language"; + public static readonly string CfgNode_ItemCount = "ItemCount"; + public static readonly string CfgNode_IsHorizonLayout = "IsHorizonLayout"; + Dictionary Read() { if (!File.Exists(Path.Combine(Environment.CurrentDirectory, _fileName))) Init(); diff --git a/BallanceTASEditor/MainWindow.xaml b/BallanceTASEditor/MainWindow.xaml index 9caa619..fa3fcd8 100644 --- a/BallanceTASEditor/MainWindow.xaml +++ b/BallanceTASEditor/MainWindow.xaml @@ -8,8 +8,31 @@ xmlns:input="clr-namespace:System.Windows.Input;assembly=PresentationCore" mc:Ignorable="d" Title="{DynamicResource ui_MainWindow_Title}" Height="500" Width="800" KeyUp="funcWindow_KeyUp" - input:InputMethod.IsInputMethodEnabled="False"> + input:InputMethod.IsInputMethodEnabled="False" MouseWheel="funcWindow_MouseWheel"> + + + + + + + + + + + + + + + + + + + + + + + @@ -78,8 +101,59 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -123,13 +197,11 @@ - + - - diff --git a/BallanceTASEditor/MainWindow.xaml.cs b/BallanceTASEditor/MainWindow.xaml.cs index 416b975..06c725f 100644 --- a/BallanceTASEditor/MainWindow.xaml.cs +++ b/BallanceTASEditor/MainWindow.xaml.cs @@ -23,14 +23,31 @@ namespace BallanceTASEditor { public MainWindow() { InitializeComponent(); RefreshUI(false); + mFlow = new TASFlow(uiTASData); + mSlider = new TASSlider(uiTASSlider); } TASFile mFile; TASViewer mViewer; + TASFlow mFlow; + TASSlider mSlider; #region ui func + // shortcut + + private void funcCommand_Menu_File_Open(object sender, ExecutedRoutedEventArgs e) => funcMenu_File_Open(sender, e); + private void funcCommand_Menu_File_Save(object sender, ExecutedRoutedEventArgs e) => funcMenu_File_Save(sender, e); + private void funcCommand_Menu_Display_Undo(object sender, ExecutedRoutedEventArgs e) => funcMenu_Display_Undo(sender, e); + private void funcCommand_Menu_Display_Redo(object sender, ExecutedRoutedEventArgs e) => funcMenu_Display_Redo(sender, e); + private void funcCanExeCmd_Menu_File_Open(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = uiMenu_File_Open.IsEnabled; + private void funcCanExeCmd_Menu_File_Save(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = uiMenu_File_Save.IsEnabled; + private void funcCanExeCmd_Menu_Display_Undo(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = uiMenu_Display_Undo.IsEnabled; + private void funcCanExeCmd_Menu_Display_Redo(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = uiMenu_Display_Redo.IsEnabled; + // =========================== menu + #region window menu + private void funcMenu_Help_ReportBugs(object sender, RoutedEventArgs e) { System.Diagnostics.Process.Start("https://github.com/yyc12345/BallanceTASEditor/issues"); } @@ -43,9 +60,15 @@ namespace BallanceTASEditor { var file = DialogUtil.OpenFileDialog(); if (file == "") return; mFile = new TASFile(file); - mViewer = new TASViewer(mFile, uiTASSlider, uiTASData, uiStatusbar_Selected); + mViewer = new TASViewer(mFile, mSlider, mFlow); + + mViewer.UpdateDataUI += RefreshDataUI; + mViewer.UpdateSelection += RefreshSelection; + mViewer.UpdateToolMode += RefreshToolMode; + RefreshUI(true); - ChangeToolMode(ToolMode.Cursor); + + mViewer.ChangeToolMode(ToolMode.Cursor); mViewer.ChangeOverwrittenMode(uiMenu_Display_OverwrittenPaste.IsChecked); } @@ -61,6 +84,11 @@ namespace BallanceTASEditor { private void funcMenu_File_Close(object sender, RoutedEventArgs e) { if (!DialogUtil.ConfirmDialog("Do you want to close this TAS file?")) return; + + mViewer.UpdateDataUI -= RefreshDataUI; + mViewer.UpdateSelection -= RefreshSelection; + mViewer.UpdateToolMode -= RefreshToolMode; + mViewer.Dispose(); mFile = null; mViewer = null; @@ -88,35 +116,85 @@ namespace BallanceTASEditor { mViewer.ProcessOperation(OperationEnum.Undo); } + #endregion + + #region menu operation + + private void uiDataMenu_Set_Click(object sender, RoutedEventArgs e) { + mViewer.ProcessOperation(OperationEnum.Set); + } + + private void uiDataMenu_Unset_Click(object sender, RoutedEventArgs e) { + mViewer.ProcessOperation(OperationEnum.Unset); + } + + private void uiDataMenu_Cut_Click(object sender, RoutedEventArgs e) { + mViewer.ProcessOperation(OperationEnum.Cut); + } + + private void uiDataMenu_Copy_Click(object sender, RoutedEventArgs e) { + mViewer.ProcessOperation(OperationEnum.Copy); + } + + private void uiDataMenu_PasteAfter_Click(object sender, RoutedEventArgs e) { + mViewer.ProcessOperation(OperationEnum.PasteAfter); + } + + private void uiDataMenu_PasteBefore_Click(object sender, RoutedEventArgs e) { + mViewer.ProcessOperation(OperationEnum.PasteBefore); + } + + private void uiDataMenu_Delete_Click(object sender, RoutedEventArgs e) { + mViewer.ProcessOperation(OperationEnum.Delete); + } + + private void uiDataMenu_DeleteAfter_Click(object sender, RoutedEventArgs e) { + mViewer.ProcessOperation(OperationEnum.DeleteAfter); + } + + private void uiDataMenu_DeleteBefore_Click(object sender, RoutedEventArgs e) { + mViewer.ProcessOperation(OperationEnum.DeleteBefore); + } + + private void uiDataMenu_AddAfter_Click(object sender, RoutedEventArgs e) { + mViewer.ProcessOperation(OperationEnum.AddAfter); + } + + private void uiDataMenu_AddBefore_Click(object sender, RoutedEventArgs e) { + mViewer.ProcessOperation(OperationEnum.AddBefore); + } + + #endregion + // =========================== btn private void funcBtn_Cursor(object sender, RoutedEventArgs e) { - ChangeToolMode(ToolMode.Cursor); + mViewer.ChangeToolMode(ToolMode.Cursor); } private void funcBtn_Fill(object sender, RoutedEventArgs e) { - ChangeToolMode(ToolMode.Fill); + mViewer.ChangeToolMode(ToolMode.Fill); } private void funcBtn_Overwrite(object sender, RoutedEventArgs e) { - ChangeToolMode(ToolMode.Overwrite); + mViewer.ChangeToolMode(ToolMode.Overwrite); } // move btn private void funcBtn_FastMovePrev(object sender, RoutedEventArgs e) { - MoveSliderManually(true, true); + mSlider.MoveSliderManually(true, true, mViewer.GetItemCountInPage()); } private void funcBtn_MovePrev(object sender, RoutedEventArgs e) { - MoveSliderManually(true, false); + mSlider.MoveSliderManually(true, false, mViewer.GetItemCountInPage()); } private void funcBtn_MoveNext(object sender, RoutedEventArgs e) { - MoveSliderManually(false, false); + mSlider.MoveSliderManually(false, false, mViewer.GetItemCountInPage()); } private void funcBtn_FastMoveNext(object sender, RoutedEventArgs e) { - MoveSliderManually(false, true); + mSlider.MoveSliderManually(false, true, mViewer.GetItemCountInPage()); } // move keyboard @@ -126,24 +204,56 @@ namespace BallanceTASEditor { switch(e.Key) { case Key.A: - MoveSliderManually(true, true); + mSlider.MoveSliderManually(true, true, mViewer.GetItemCountInPage()); break; case Key.S: - MoveSliderManually(true, false); + mSlider.MoveSliderManually(true, false, mViewer.GetItemCountInPage()); break; case Key.D: - MoveSliderManually(false, false); + mSlider.MoveSliderManually(false, false, mViewer.GetItemCountInPage()); break; case Key.F: - MoveSliderManually(false, true); + mSlider.MoveSliderManually(false, true, mViewer.GetItemCountInPage()); break; } } + // move mouse + + private void funcWindow_MouseWheel(object sender, MouseWheelEventArgs e) { + if (e.Delta > 0) { + // wheel up + if (KeyboardState.IsKeyPressed(KeyboardState.VirtualKeyStates.VK_SHIFT)) { + // move quickly + mSlider.MoveSliderManually(true, true, mViewer.GetItemCountInPage()); + } else if (KeyboardState.IsKeyPressed(KeyboardState.VirtualKeyStates.VK_CONTROL)) { + // decrease item count + var newvalue = mViewer.GetItemCountInPage(); + mViewer.ChangeListLength(newvalue - 1); + } else { + // normally move + mSlider.MoveSliderManually(true, false, mViewer.GetItemCountInPage()); + } + + } else if (e.Delta < 0) { + // wheel down + if (KeyboardState.IsKeyPressed(KeyboardState.VirtualKeyStates.VK_SHIFT)) { + // move quickly + mSlider.MoveSliderManually(false, true, mViewer.GetItemCountInPage()); + } else if (KeyboardState.IsKeyPressed(KeyboardState.VirtualKeyStates.VK_CONTROL)) { + // increase item count + var newvalue = mViewer.GetItemCountInPage(); + mViewer.ChangeListLength(newvalue + 1); + } else { + // normally move + mSlider.MoveSliderManually(false, false, mViewer.GetItemCountInPage()); + } + } + } + #endregion - - private void ChangeToolMode(ToolMode mode) { + private void RefreshToolMode(ToolMode mode) { switch (mode) { case ToolMode.Cursor: uiBtn_Cursor.IsEnabled = false; @@ -173,8 +283,6 @@ namespace BallanceTASEditor { uiStatusbar_Mode_Overwrite.Visibility = Visibility.Visible; break; } - - mViewer.ChangeToolMode(mode); } private void RefreshUI(bool isFileOpened) { @@ -211,9 +319,46 @@ namespace BallanceTASEditor { } } - private void MoveSliderManually(bool isPrev, bool isFast) { - var step = isFast ? mViewer.GetItemCountInPage() : 1; - uiTASSlider.Value = Util.Clamp(uiTASSlider.Value.ToInt32() + (isPrev ? -1 : 1) * step, uiTASSlider.Minimum.ToInt32(), uiTASSlider.Maximum.ToInt32()); + private void RefreshDataUI(bool showCursorPasteAddDeleteOne, bool showFill, bool showCursorCopyDelete) { + uiDataMenu_Set.IsEnabled = showFill; + uiDataMenu_Unset.IsEnabled = showFill; + uiDataMenu_Cut.IsEnabled = showCursorCopyDelete; + uiDataMenu_Copy.IsEnabled = showCursorCopyDelete; + uiDataMenu_Delete.IsEnabled = showCursorCopyDelete; + uiDataMenu_DeleteAfter.IsEnabled = showCursorPasteAddDeleteOne; + uiDataMenu_DeleteBefore.IsEnabled = showCursorPasteAddDeleteOne; + uiDataMenu_PasteAfter.IsEnabled = showCursorPasteAddDeleteOne; + uiDataMenu_PasteBefore.IsEnabled = showCursorPasteAddDeleteOne; + uiDataMenu_AddAfter.IsEnabled = showCursorPasteAddDeleteOne; + uiDataMenu_AddBefore.IsEnabled = showCursorPasteAddDeleteOne; + } + + private void RefreshSelection(SelectionHelp mSelectionHelp) { + var mode = mSelectionHelp.GetToolMode(); + + switch (mode) { + case ToolMode.Cursor: + if (mSelectionHelp.IsDataReady()) { + var data = mSelectionHelp.GetRange(); + uiStatusbar_Selected.Text = $"{data.start} - {data.end}"; + } else if (mSelectionHelp.IsDataPartialReady()) { + var data2 = mSelectionHelp.GetPoint(); + uiStatusbar_Selected.Text = data2.ToString(); + } else uiStatusbar_Selected.Text = "-"; + break; + case ToolMode.Fill: + if (mSelectionHelp.IsDataReady()) { + var data3 = mSelectionHelp.GetRange(); + uiStatusbar_Selected.Text = $"{data3.start} - {data3.end}"; + } else uiStatusbar_Selected.Text = "-"; + break; + case ToolMode.Overwrite: + if (mSelectionHelp.IsDataReady()) { + var data4 = mSelectionHelp.GetPoint(); + uiStatusbar_Selected.Text = data4.ToString(); + } else uiStatusbar_Selected.Text = "-"; + break; + } } } diff --git a/BallanceTASEditor/UI/TASFlow.xaml.cs b/BallanceTASEditor/UI/TASFlow.cs similarity index 77% rename from BallanceTASEditor/UI/TASFlow.xaml.cs rename to BallanceTASEditor/UI/TASFlow.cs index 9ce173b..2485513 100644 --- a/BallanceTASEditor/UI/TASFlow.xaml.cs +++ b/BallanceTASEditor/UI/TASFlow.cs @@ -15,12 +15,9 @@ using System.Windows.Navigation; using System.Windows.Shapes; namespace BallanceTASEditor.UI { - /// - /// TASFlow.xaml 的交互逻辑 - /// - public partial class TASFlow : UserControl { - public TASFlow() { - InitializeComponent(); + public partial class TASFlow { + public TASFlow(Grid coreWindow) { + uiCoreWindow = coreWindow; mItemList = new List(); mRectMap = new Dictionary(); mItemCount = 0; @@ -28,8 +25,8 @@ namespace BallanceTASEditor.UI { } public event Action Click; - public event Action NewOperation; + private Grid uiCoreWindow; private int mItemCount; private List mItemList; private Dictionary mRectMap; @@ -51,9 +48,9 @@ namespace BallanceTASEditor.UI { // change column defination first if (offset > 0) { - for(int i = 0; i < abs; i++) { + for (int i = 0; i < abs; i++) { var item = new ColumnDefinition(); - item.Width = GridLength.Auto; + item.Width = new GridLength(1, GridUnitType.Star); uiCoreWindow.ColumnDefinitions.Add(item); } } else { @@ -68,7 +65,7 @@ namespace BallanceTASEditor.UI { mItemList.Add(newItem); } } else { - for(int i = 0; i < abs; i++) { + for (int i = 0; i < abs; i++) { mItemList[newCount + i].Remove(uiCoreWindow, mRectMap, Rectangle_MouseDown); } mItemList.RemoveRange(newCount, abs); @@ -78,27 +75,6 @@ namespace BallanceTASEditor.UI { mItemCount = newCount; } - public void RefreshDataMenu() { - if (SelectionHelp == null) return; - - ToolMode mode = SelectionHelp.GetToolMode(); - bool showCursorPasteAddDeleteOne = mode == ToolMode.Cursor && SelectionHelp.IsDataPartialReady(); - bool showFill = mode == ToolMode.Fill && SelectionHelp.IsDataReady(); - bool showCursorCopyDelete = mode == ToolMode.Cursor && SelectionHelp.IsDataReady(); - - uiDataMenu_Set.IsEnabled = showFill; - uiDataMenu_Unset.IsEnabled = showFill; - uiDataMenu_Cut.IsEnabled = showCursorCopyDelete; - uiDataMenu_Copy.IsEnabled = showCursorCopyDelete; - uiDataMenu_Delete.IsEnabled = showCursorCopyDelete; - uiDataMenu_DeleteAfter.IsEnabled = showCursorPasteAddDeleteOne; - uiDataMenu_DeleteBefore.IsEnabled = showCursorPasteAddDeleteOne; - uiDataMenu_PasteAfter.IsEnabled = showCursorPasteAddDeleteOne; - uiDataMenu_PasteBefore.IsEnabled = showCursorPasteAddDeleteOne; - uiDataMenu_AddAfter.IsEnabled = showCursorPasteAddDeleteOne; - uiDataMenu_AddBefore.IsEnabled = showCursorPasteAddDeleteOne; - } - public void RefreshSelectionHighlight() { ToolMode mode = SelectionHelp.GetToolMode(); @@ -171,54 +147,6 @@ namespace BallanceTASEditor.UI { Click?.Invoke(); } - #region menu operation - - private void uiDataMenu_Set_Click(object sender, RoutedEventArgs e) { - NewOperation?.Invoke(OperationEnum.Set); - } - - private void uiDataMenu_Unset_Click(object sender, RoutedEventArgs e) { - NewOperation?.Invoke(OperationEnum.Unset); - } - - private void uiDataMenu_Cut_Click(object sender, RoutedEventArgs e) { - NewOperation?.Invoke(OperationEnum.Cut); - } - - private void uiDataMenu_Copy_Click(object sender, RoutedEventArgs e) { - NewOperation?.Invoke(OperationEnum.Copy); - } - - private void uiDataMenu_PasteAfter_Click(object sender, RoutedEventArgs e) { - NewOperation?.Invoke(OperationEnum.PasteAfter); - } - - private void uiDataMenu_PasteBefore_Click(object sender, RoutedEventArgs e) { - NewOperation?.Invoke(OperationEnum.PasteBefore); - } - - private void uiDataMenu_Delete_Click(object sender, RoutedEventArgs e) { - NewOperation?.Invoke(OperationEnum.Delete); - } - - private void uiDataMenu_DeleteAfter_Click(object sender, RoutedEventArgs e) { - NewOperation?.Invoke(OperationEnum.DeleteAfter); - } - - private void uiDataMenu_DeleteBefore_Click(object sender, RoutedEventArgs e) { - NewOperation?.Invoke(OperationEnum.DeleteBefore); - } - - private void uiDataMenu_AddAfter_Click(object sender, RoutedEventArgs e) { - NewOperation?.Invoke(OperationEnum.AddAfter); - } - - private void uiDataMenu_AddBefore_Click(object sender, RoutedEventArgs e) { - NewOperation?.Invoke(OperationEnum.AddBefore); - } - - #endregion - } public class TASFlowUIItem { diff --git a/BallanceTASEditor/UI/TASFlow.xaml b/BallanceTASEditor/UI/TASFlow.xaml deleted file mode 100644 index 9868791..0000000 --- a/BallanceTASEditor/UI/TASFlow.xaml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/BallanceTASEditor/UI/TASSlider.cs b/BallanceTASEditor/UI/TASSlider.cs new file mode 100644 index 0000000..209fc76 --- /dev/null +++ b/BallanceTASEditor/UI/TASSlider.cs @@ -0,0 +1,44 @@ +using BallanceTASEditor.Core; +using BallanceTASEditor.Core.TASStruct; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BallanceTASEditor.UI { + public class TASSlider { + public TASSlider(Slider slider) { + mSlider = slider; + mSlider.Minimum = 0; + + mSlider.ValueChanged += func_SliderValueChanged; + } + + public event Action ValueChanged; + Slider mSlider; + + public void MoveSliderManually(bool isPrev, bool isFast, int fastCount) { + var step = isFast ? fastCount : 1; + mSlider.Value = Util.Clamp(mSlider.Value.ToInt32() + (isPrev ? -1 : 1) * step, mSlider.Minimum.ToInt32(), mSlider.Maximum.ToInt32()); + } + + public void UpdateRange(TASFile mFile) { + mSlider.Maximum = mFile.mFrameCount - 1; + mSlider.Value = mFile.GetPointerIndex(); + } + + private void func_SliderValueChanged(object sender, RoutedPropertyChangedEventArgs e) { + ValueChanged?.Invoke(e.NewValue.ToInt64()); + } + + } +} diff --git a/BallanceTASEditor/UI/TASViewer.cs b/BallanceTASEditor/UI/TASViewer.cs index 46cd6e4..b790048 100644 --- a/BallanceTASEditor/UI/TASViewer.cs +++ b/BallanceTASEditor/UI/TASViewer.cs @@ -10,15 +10,13 @@ using System.Windows; namespace BallanceTASEditor.UI { public class TASViewer : IDisposable { - public TASViewer(TASFile file, Slider slider, TASFlow datagrid, TextBlock statusbar) { + public TASViewer(TASFile file, TASSlider slider, TASFlow datagrid) { mFile = file; mSlider = slider; mDataGrid = datagrid; - mStatusbar = statusbar; // restore slider - mSlider.Minimum = 0; - updateSliderRange(); + mSlider.UpdateRange(mFile); // init selection mSelectionHelp = new SelectionHelp(); @@ -35,86 +33,81 @@ namespace BallanceTASEditor.UI { mDataGrid.SelectionHelp = mSelectionHelp; mDataGrid.Click += funcDataMenu_Click; - mDataGrid.NewOperation += funcDataMenu_NewOperation; - - mSlider.ValueChanged += sliderValueChanged; + mSlider.ValueChanged += funcSlider_ValueChanged; // display data - ChangeListLength(DATA_LIST_LENGTH); + ChangeListLength(int.Parse(GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_ItemCount])); } public void Dispose() { mDataGrid.DataSources = null; mDataGrid.Click -= funcDataMenu_Click; - mDataGrid.NewOperation -= funcDataMenu_NewOperation; - - mSlider.ValueChanged -= sliderValueChanged; + mSlider.ValueChanged -= funcSlider_ValueChanged; } - const int DATA_LIST_LENGTH = 15; + //const int DATA_LIST_LENGTH = 15; FrameData INVALID_FRAME_DATA; TASFile mFile; - Slider mSlider; - TextBlock mStatusbar; + TASSlider mSlider; TASFlow mDataGrid; SelectionHelp mSelectionHelp; int mListLength; List mDataSource; bool mOverwrittenPaste; - private void sliderValueChanged(object sender, RoutedPropertyChangedEventArgs e) { - long pos = e.NewValue.ToInt64(); - mFile.Shift(pos); + #region self event + public event Action UpdateDataUI; + public event Action UpdateToolMode; + public event Action UpdateSelection; + private void OnUpdateDataUI() { + ToolMode mode = mSelectionHelp.GetToolMode(); + bool showCursorPasteAddDeleteOne = mode == ToolMode.Cursor && mSelectionHelp.IsDataPartialReady(); + bool showFill = mode == ToolMode.Fill && mSelectionHelp.IsDataReady(); + bool showCursorCopyDelete = mode == ToolMode.Cursor && mSelectionHelp.IsDataReady(); + + UpdateDataUI?.Invoke(showCursorPasteAddDeleteOne, showFill, showCursorCopyDelete); + } + + private void OnUpdateToolMode() { + UpdateToolMode?.Invoke(mSelectionHelp.GetToolMode()); + } + + private void OnUpdateSelection() { + UpdateSelection?.Invoke(mSelectionHelp); + } + + #endregion + + #region process event + + private void funcSlider_ValueChanged(long pos) { + mFile.Shift(pos); RefreshDisplay(); } - private void updateSliderRange() { - mSlider.Maximum = mFile.mFrameCount - 1; - mSlider.Value = mFile.GetPointerIndex(); - } - private void funcSelectionHelp_SelectionChanged() { - mDataGrid.RefreshDataMenu(); mDataGrid.RefreshSelectionHighlight(); - OnStatusbarSelectionChanged(); + OnUpdateDataUI(); + OnUpdateSelection(); } - private void OnStatusbarSelectionChanged() { - var mode = mSelectionHelp.GetToolMode(); - - switch (mode) { - case ToolMode.Cursor: - if (mSelectionHelp.IsDataReady()) { - var data = mSelectionHelp.GetRange(); - mStatusbar.Text = $"{data.start} - {data.end}"; - } else if (mSelectionHelp.IsDataPartialReady()) { - var data2 = mSelectionHelp.GetPoint(); - mStatusbar.Text = data2.ToString(); - } else mStatusbar.Text = "-"; - break; - case ToolMode.Fill: - if (mSelectionHelp.IsDataReady()) { - var data3 = mSelectionHelp.GetRange(); - mStatusbar.Text = $"{data3.start} - {data3.end}"; - } else mStatusbar.Text = "-"; - break; - case ToolMode.Overwrite: - if (mSelectionHelp.IsDataReady()) { - var data4 = mSelectionHelp.GetPoint(); - mStatusbar.Text = data4.ToString(); - } else mStatusbar.Text = "-"; - break; - } + private void funcDataMenu_Click() { + var data = mSelectionHelp.GetPoint(); + var field = (int)mSelectionHelp.GetPointField(); + mFile.Set(new SelectionRange(field, field), new SelectionRange(data, data), null); + RefreshDisplay(); } + #endregion + public void ChangeOverwrittenMode(bool isOverwritten) { mOverwrittenPaste = isOverwritten; } public void ChangeListLength(int newLen) { - if (newLen < 5 || newLen > 30) return; + if (newLen < 5 || newLen > 200) return; int offset = newLen - mListLength; int abs = Math.Abs(offset); if (offset == 0) return; @@ -147,6 +140,7 @@ namespace BallanceTASEditor.UI { public void ChangeToolMode(ToolMode mode) { mSelectionHelp.SetMode(mode); + OnUpdateToolMode(); } public int GetItemCountInPage() { @@ -176,7 +170,7 @@ namespace BallanceTASEditor.UI { // do delete mFile.Remove(mSelectionHelp.GetRange()); mSelectionHelp.Reset(); - updateSliderRange(); + mSlider.UpdateRange(mFile); RefreshDisplay(); } break; @@ -193,7 +187,7 @@ namespace BallanceTASEditor.UI { if (ClipboardUtil.GetFrameData(data)) { mFile.Insert(mSelectionHelp.GetPoint(), data, oper == OperationEnum.PasteBefore, mOverwrittenPaste); mSelectionHelp.Reset(); - updateSliderRange(); + mSlider.UpdateRange(mFile); RefreshDisplay(); } else MessageBox.Show("Fail to paste due to unknow reason or blank clipboard!"); } @@ -201,7 +195,7 @@ namespace BallanceTASEditor.UI { case OperationEnum.Delete: { mFile.Remove(mSelectionHelp.GetRange()); mSelectionHelp.Reset(); - updateSliderRange(); + mSlider.UpdateRange(mFile); RefreshDisplay(); } break; @@ -225,8 +219,8 @@ namespace BallanceTASEditor.UI { // do real operation mFile.Remove(new SelectionRange(pos, pos)); - - updateSliderRange(); + + mSlider.UpdateRange(mFile); RefreshDisplay(); } break; @@ -237,40 +231,26 @@ namespace BallanceTASEditor.UI { var pos = mSelectionHelp.GetPoint(); mFile.Add(pos, count, deltaTime, oper == OperationEnum.AddBefore); mSelectionHelp.Reset(); - updateSliderRange(); + mSlider.UpdateRange(mFile); RefreshDisplay(); } break; case OperationEnum.Undo: { mFile.Undo(); mSelectionHelp.Reset(); - updateSliderRange(); + mSlider.UpdateRange(mFile); RefreshDisplay(); } break; case OperationEnum.Redo: { mFile.Redo(); mSelectionHelp.Reset(); - updateSliderRange(); + mSlider.UpdateRange(mFile); RefreshDisplay(); } break; } } - #region data menu - - private void funcDataMenu_Click() { - var data = mSelectionHelp.GetPoint(); - var field = (int)mSelectionHelp.GetPointField(); - mFile.Set(new SelectionRange(field, field), new SelectionRange(data, data), null); - RefreshDisplay(); - } - - private void funcDataMenu_NewOperation(OperationEnum obj) { - ProcessOperation(obj); - } - - #endregion } }