diff --git a/BallanceTASEditor/App.xaml.cs b/BallanceTASEditor/App.xaml.cs index 7742efa..44802ae 100644 --- a/BallanceTASEditor/App.xaml.cs +++ b/BallanceTASEditor/App.xaml.cs @@ -40,6 +40,12 @@ namespace BallanceTASEditor { } + protected override void OnExit(ExitEventArgs e) { + base.OnExit(e); + + GlobalVariable.configManager.Save(); + } + private void UncatchedErrorHandle(string message, string stackTrace) { try { if (!Directory.Exists("./logs")) diff --git a/BallanceTASEditor/Core/ConfigManager.cs b/BallanceTASEditor/Core/ConfigManager.cs index b4728bb..da7af6a 100644 --- a/BallanceTASEditor/Core/ConfigManager.cs +++ b/BallanceTASEditor/Core/ConfigManager.cs @@ -11,13 +11,13 @@ namespace BallanceTASEditor.Core { public ConfigManager(string fileName, Dictionary defaultValue) { _fileName = fileName; - _defaultValue = JsonConvert.SerializeObject(defaultValue); + _defaultValue = defaultValue; Configuration = Read(); } string _fileName; - string _defaultValue; + Dictionary _defaultValue; public Dictionary Configuration; public static readonly string CfgNode_Language = "Language"; @@ -35,12 +35,20 @@ namespace BallanceTASEditor.Core { fs.Close(); } + // check field to make sure each field is existed + // because version update it might be changed + foreach(var pair in _defaultValue) { + if (!data.ContainsKey(pair.Key)) { + data.Add(pair.Key, pair.Value); + } + } + return data; } void Init() { using (StreamWriter fs = new StreamWriter(Path.Combine(Environment.CurrentDirectory, _fileName), false, Encoding.UTF8)) { - fs.Write(_defaultValue); + fs.Write(JsonConvert.SerializeObject(_defaultValue)); fs.Close(); } } diff --git a/BallanceTASEditor/Language/CHS.xaml b/BallanceTASEditor/Language/CHS.xaml index 79e8b19..acf2989 100644 --- a/BallanceTASEditor/Language/CHS.xaml +++ b/BallanceTASEditor/Language/CHS.xaml @@ -16,12 +16,13 @@ 重做 项个数 覆盖式粘贴 + 横向布局 帮助 汇报漏洞 关于 - 打开一个 TAS 文件以编辑 + 打开或拖入一个 TAS 文件以编辑 选择模式 填充模式 diff --git a/BallanceTASEditor/Language/DefaultLanguage.xaml b/BallanceTASEditor/Language/DefaultLanguage.xaml index 67689fa..723b9d3 100644 --- a/BallanceTASEditor/Language/DefaultLanguage.xaml +++ b/BallanceTASEditor/Language/DefaultLanguage.xaml @@ -16,12 +16,13 @@ Redo Item Count Overwritten Paste + Horizontal Layout Help Report Bugs About - Open a TAS file for editing + Open or drop a TAS file for editing Select mode Fill mode diff --git a/BallanceTASEditor/MainWindow.xaml b/BallanceTASEditor/MainWindow.xaml index d0047a2..bc05d01 100644 --- a/BallanceTASEditor/MainWindow.xaml +++ b/BallanceTASEditor/MainWindow.xaml @@ -62,9 +62,11 @@ + - - + + + diff --git a/BallanceTASEditor/MainWindow.xaml.cs b/BallanceTASEditor/MainWindow.xaml.cs index 1984243..79b703b 100644 --- a/BallanceTASEditor/MainWindow.xaml.cs +++ b/BallanceTASEditor/MainWindow.xaml.cs @@ -22,9 +22,12 @@ namespace BallanceTASEditor { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); - RefreshUI(false); + mFlow = new TASFlow(uiTASData); mSlider = new TASSlider(uiTASSlider); + + RefreshUI(false); + ApplyConfigureManager(); } TASFile mFile; @@ -96,16 +99,24 @@ namespace BallanceTASEditor { private void funcMenu_Display_ItemCount(object sender, RoutedEventArgs e) { int newvalue = 0; if (DialogUtil.InputNumber("Input new count (>=5 && <=30)", 5, 30, ref newvalue)) { - mViewer.ChangeListLength(newvalue); + ChangeItemCount(newvalue); } } private void funcMenu_Display_OverwrittenPaste(object sender, RoutedEventArgs e) { - //uiMenu_Display_OverwrittenPaste.IsChecked = !uiMenu_Display_OverwrittenPaste.IsChecked; + uiMenu_Display_OverwrittenPaste.IsChecked = !uiMenu_Display_OverwrittenPaste.IsChecked; + + GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_IsOverwrittenPaste] = uiMenu_Display_OverwrittenPaste.IsChecked.ToString(); if (mViewer != null) mViewer.ChangeOverwrittenMode(uiMenu_Display_OverwrittenPaste.IsChecked); } + private void funcMenu_Display_HorizontalLayout(object sender, RoutedEventArgs e) { + uiMenu_Display_HorizontalLayout.IsChecked = !uiMenu_Display_HorizontalLayout.IsChecked; + GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_IsHorizonLayout] = uiMenu_Display_HorizontalLayout.IsChecked.ToString(); + ChangeLayout(uiMenu_Display_HorizontalLayout.IsChecked); + } + private void funcMenu_Display_Redo(object sender, RoutedEventArgs e) { mViewer.ProcessOperation(OperationEnum.Redo); } @@ -227,7 +238,7 @@ namespace BallanceTASEditor { } else if (KeyboardState.IsKeyPressed(KeyboardState.VirtualKeyStates.VK_CONTROL)) { // decrease item count var newvalue = mViewer.GetItemCountInPage(); - mViewer.ChangeListLength(newvalue - 1); + ChangeItemCount(newvalue - 1); } else { // normally move mSlider.MoveSliderManually(true, false, mViewer.GetItemCountInPage()); @@ -241,7 +252,7 @@ namespace BallanceTASEditor { } else if (KeyboardState.IsKeyPressed(KeyboardState.VirtualKeyStates.VK_CONTROL)) { // increase item count var newvalue = mViewer.GetItemCountInPage(); - mViewer.ChangeListLength(newvalue + 1); + ChangeItemCount(newvalue + 1); } else { // normally move mSlider.MoveSliderManually(false, false, mViewer.GetItemCountInPage()); @@ -265,9 +276,22 @@ namespace BallanceTASEditor { else e.Effects = DragDropEffects.None; } - #endregion + private void ApplyConfigureManager() { + var isOverwrittenPaste = bool.Parse(GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_IsOverwrittenPaste]); + var isHorizontalLayout = bool.Parse(GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_IsHorizonLayout]); + var itemCount = int.Parse(GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_ItemCount]); + + uiMenu_Display_OverwrittenPaste.IsChecked = isOverwrittenPaste; + uiMenu_Display_HorizontalLayout.IsChecked = isHorizontalLayout; + if (mViewer != null) { + mViewer.ChangeOverwrittenMode(isOverwrittenPaste); + mViewer.ChangeListLength(itemCount); + ChangeLayout(isHorizontalLayout); + } + } + private void OpenFile(string file) { try { mFile = new TASFile(file); @@ -284,9 +308,8 @@ namespace BallanceTASEditor { mViewer.UpdateToolMode += RefreshToolMode; RefreshUI(true); - + ApplyConfigureManager(); // apply item count and overwritten item mViewer.ChangeToolMode(ToolMode.Cursor); - mViewer.ChangeOverwrittenMode(uiMenu_Display_OverwrittenPaste.IsChecked); } private void RefreshToolMode(ToolMode mode) { @@ -333,6 +356,7 @@ namespace BallanceTASEditor { uiMenu_Display_ItemCount.IsEnabled = true; uiMenu_Display_OverwrittenPaste.IsEnabled = true; + uiMenu_Display_HorizontalLayout.IsEnabled = true; uiMenu_Display_Undo.IsEnabled = true; uiMenu_Display_Redo.IsEnabled = true; @@ -348,6 +372,7 @@ namespace BallanceTASEditor { uiMenu_Display_ItemCount.IsEnabled = false; uiMenu_Display_OverwrittenPaste.IsEnabled = false; + uiMenu_Display_HorizontalLayout.IsEnabled = false; uiMenu_Display_Undo.IsEnabled = false; uiMenu_Display_Redo.IsEnabled = false; @@ -397,5 +422,15 @@ namespace BallanceTASEditor { } } + private void ChangeItemCount(int count) { + GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_ItemCount] = count.ToString(); + mViewer.ChangeListLength(count); + } + + private void ChangeLayout(bool isHorizontal) { + mFlow.ChangeLayout(isHorizontal); + // todo: add more change + } + } } diff --git a/BallanceTASEditor/UI/TASFlow.cs b/BallanceTASEditor/UI/TASFlow.cs index 2485513..ba4231f 100644 --- a/BallanceTASEditor/UI/TASFlow.cs +++ b/BallanceTASEditor/UI/TASFlow.cs @@ -21,11 +21,13 @@ namespace BallanceTASEditor.UI { mItemList = new List(); mRectMap = new Dictionary(); mItemCount = 0; + mIsHorizontalLayout = true; SetItemCount(1); } public event Action Click; + private bool mIsHorizontalLayout; private Grid uiCoreWindow; private int mItemCount; private List mItemList; @@ -33,6 +35,13 @@ namespace BallanceTASEditor.UI { public SelectionHelp SelectionHelp { get; set; } public List DataSources { get; set; } + public void ChangeLayout(bool isHorizontal) { + // the layout changed, re-construct elements + if (isHorizontal != mIsHorizontalLayout) { + // todo: change layout + } + } + public void RefreshDataSources() { if (DataSources == null) return; @@ -135,6 +144,14 @@ namespace BallanceTASEditor.UI { } else { SelectionHelp.FirstClick(mItemList[pos.column - 1].rawFrame, pos.field); } + } else if (e.MouseDevice.RightButton == MouseButtonState.Pressed) { + // if we click right button and there are no full selection in cursor mode + // try to add a first selection + if (SelectionHelp.GetToolMode() == ToolMode.Cursor) { + if (!SelectionHelp.IsDataReady()) { + SelectionHelp.FirstClick(mItemList[pos.column - 1].rawFrame, pos.field); + } + } } // note main window to process it. diff --git a/BallanceTASEditor/UI/TASViewer.cs b/BallanceTASEditor/UI/TASViewer.cs index b790048..8d9478c 100644 --- a/BallanceTASEditor/UI/TASViewer.cs +++ b/BallanceTASEditor/UI/TASViewer.cs @@ -34,9 +34,6 @@ namespace BallanceTASEditor.UI { mDataGrid.Click += funcDataMenu_Click; mSlider.ValueChanged += funcSlider_ValueChanged; - - // display data - ChangeListLength(int.Parse(GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_ItemCount])); } public void Dispose() {