remove TASFlow and re-define it as a assist class

This commit is contained in:
2021-09-20 13:58:10 +08:00
parent 1def4c47f6
commit 1c57481f84
9 changed files with 357 additions and 249 deletions

View File

@ -29,13 +29,13 @@ namespace BallanceTASEditor {
// init configure manager
GlobalVariable.configManager = new Core.ConfigManager("ballance-tas-editor.cfg", new Dictionary<string, string>() {
{"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]);
}

View File

@ -76,9 +76,8 @@
<Compile Include="UI\OperationEnum.cs" />
<Compile Include="UI\SelectionHelp.cs" />
<Compile Include="UI\StyleConverter.cs" />
<Compile Include="UI\TASFlow.xaml.cs">
<DependentUpon>TASFlow.xaml</DependentUpon>
</Compile>
<Compile Include="UI\TASFlow.cs" />
<Compile Include="UI\TASSlider.cs" />
<Compile Include="UI\TASViewer.cs" />
<Compile Include="UI\Util.cs" />
<Page Include="Language\CHS.xaml">
@ -110,10 +109,6 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UI\TASFlow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">

View File

@ -20,6 +20,10 @@ namespace BallanceTASEditor.Core {
string _defaultValue;
public Dictionary<string, string> Configuration;
public static readonly string CfgNode_Language = "Language";
public static readonly string CfgNode_ItemCount = "ItemCount";
public static readonly string CfgNode_IsHorizonLayout = "IsHorizonLayout";
Dictionary<string, string> Read() {
if (!File.Exists(Path.Combine(Environment.CurrentDirectory, _fileName)))
Init();

View File

@ -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">
<!-- shortcut defination-->
<Window.Resources>
<RoutedUICommand x:Key="commandMenu_File_Open"/>
<RoutedUICommand x:Key="commandMenu_File_Save"/>
<RoutedUICommand x:Key="commandMenu_Display_Undo"/>
<RoutedUICommand x:Key="commandMenu_Display_Redo"/>
</Window.Resources>
<Window.InputBindings>
<KeyBinding Gesture="Ctrl+O" Command="{StaticResource commandMenu_File_Open}"/>
<KeyBinding Gesture="Ctrl+S" Command="{StaticResource commandMenu_File_Save}"/>
<KeyBinding Gesture="Ctrl+Z" Command="{StaticResource commandMenu_Display_Undo}"/>
<KeyBinding Gesture="Ctrl+Y" Command="{StaticResource commandMenu_Display_Redo}"/>
</Window.InputBindings>
<Window.CommandBindings>
<CommandBinding Command="{StaticResource commandMenu_File_Open}" Executed="funcCommand_Menu_File_Open" CanExecute="funcCanExeCmd_Menu_File_Open"/>
<CommandBinding Command="{StaticResource commandMenu_File_Save}" Executed="funcCommand_Menu_File_Save" CanExecute="funcCanExeCmd_Menu_File_Save"/>
<CommandBinding Command="{StaticResource commandMenu_Display_Undo}" Executed="funcCommand_Menu_Display_Undo" CanExecute="funcCanExeCmd_Menu_Display_Undo"/>
<CommandBinding Command="{StaticResource commandMenu_Display_Redo}" Executed="funcCommand_Menu_Display_Redo" CanExecute="funcCanExeCmd_Menu_Display_Redo"/>
</Window.CommandBindings>
<!-- real ui elements-->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
@ -78,8 +101,59 @@
</Button>
</StackPanel>
<controls:TASFlow x:Name="uiTASData" Grid.Row="1" Margin="5" BorderThickness="1" BorderBrush="Gray">
</controls:TASFlow>
<Border BorderThickness="1" BorderBrush="Gray" Grid.Row="1" Margin="5" Background="#ffffff">
<Grid x:Name="uiTASData">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem x:Name="uiDataMenu_Set" Header="{DynamicResource ui_TASFlow_Menu_Set}" Click="uiDataMenu_Set_Click"/>
<MenuItem x:Name="uiDataMenu_Unset" Header="{DynamicResource ui_TASFlow_Menu_Unset}" Click="uiDataMenu_Unset_Click"/>
<Separator/>
<MenuItem x:Name="uiDataMenu_Cut" Header="{DynamicResource ui_TASFlow_Menu_Cut}" Click="uiDataMenu_Cut_Click" InputGestureText="Ctrl + X"/>
<MenuItem x:Name="uiDataMenu_Copy" Header="{DynamicResource ui_TASFlow_Menu_Copy}" Click="uiDataMenu_Copy_Click" InputGestureText="Ctrl + C"/>
<MenuItem x:Name="uiDataMenu_PasteAfter" Header="{DynamicResource ui_TASFlow_Menu_PasteAfter}" Click="uiDataMenu_PasteAfter_Click"/>
<MenuItem x:Name="uiDataMenu_PasteBefore" Header="{DynamicResource ui_TASFlow_Menu_PasterBefore}" Click="uiDataMenu_PasteBefore_Click"/>
<Separator/>
<MenuItem x:Name="uiDataMenu_Delete" Header="{DynamicResource ui_TASFlow_Menu_Delete}" Click="uiDataMenu_Delete_Click"/>
<MenuItem x:Name="uiDataMenu_DeleteAfter" Header="{DynamicResource ui_TASFlow_Menu_DeleteAfter}" Click="uiDataMenu_DeleteAfter_Click" InputGestureText="Del"/>
<MenuItem x:Name="uiDataMenu_DeleteBefore" Header="{DynamicResource ui_TASFlow_Menu_PasterBefore}" Click="uiDataMenu_DeleteBefore_Click" InputGestureText="Backspace"/>
<Separator/>
<MenuItem x:Name="uiDataMenu_AddAfter" Header="{DynamicResource ui_TASFlow_Menu_AddAfter}" Click="uiDataMenu_AddAfter_Click"/>
<MenuItem x:Name="uiDataMenu_AddBefore" Header="{DynamicResource ui_TASFlow_Menu_AddBefore}" Click="uiDataMenu_AddBefore_Click"/>
</ContextMenu>
</Grid.ContextMenu>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="1" Text="{DynamicResource ui_TASFlow_Sheet_Frame}"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="2" Text="{DynamicResource ui_TASFlow_Sheet_DeltaTime}"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="3" Text="^"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="4" Text="v"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="5" Text="&lt;"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="6" Text="&gt;"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="7" Text="shift"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="8" Text="space"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="9" Text="q"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="10" Text="esc"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="11" Text="enter"/>
</Grid>
</Border>
<Grid Grid.Row="2" Margin="5">
<Grid.ColumnDefinitions>
@ -128,8 +202,6 @@
</Slider>
</Grid>
</Grid>
<StatusBar x:Name="uiStatusbar" Grid.Row="2">

View File

@ -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;
}
}
}

View File

@ -15,12 +15,9 @@ using System.Windows.Navigation;
using System.Windows.Shapes;
namespace BallanceTASEditor.UI {
/// <summary>
/// TASFlow.xaml 的交互逻辑
/// </summary>
public partial class TASFlow : UserControl {
public TASFlow() {
InitializeComponent();
public partial class TASFlow {
public TASFlow(Grid coreWindow) {
uiCoreWindow = coreWindow;
mItemList = new List<TASFlowUIItem>();
mRectMap = new Dictionary<Rectangle, CellPosition>();
mItemCount = 0;
@ -28,8 +25,8 @@ namespace BallanceTASEditor.UI {
}
public event Action Click;
public event Action<OperationEnum> NewOperation;
private Grid uiCoreWindow;
private int mItemCount;
private List<TASFlowUIItem> mItemList;
private Dictionary<Rectangle, CellPosition> 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 {

View File

@ -1,60 +0,0 @@
<UserControl x:Class="BallanceTASEditor.UI.TASFlow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BallanceTASEditor.UI"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="800">
<Grid x:Name="uiCoreWindow" Background="#ffffff">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem x:Name="uiDataMenu_Set" Header="{DynamicResource ui_TASFlow_Menu_Set}" Click="uiDataMenu_Set_Click"/>
<MenuItem x:Name="uiDataMenu_Unset" Header="{DynamicResource ui_TASFlow_Menu_Unset}" Click="uiDataMenu_Unset_Click"/>
<Separator/>
<MenuItem x:Name="uiDataMenu_Cut" Header="{DynamicResource ui_TASFlow_Menu_Cut}" Click="uiDataMenu_Cut_Click" InputGestureText="Ctrl + X"/>
<MenuItem x:Name="uiDataMenu_Copy" Header="{DynamicResource ui_TASFlow_Menu_Copy}" Click="uiDataMenu_Copy_Click" InputGestureText="Ctrl + C"/>
<MenuItem x:Name="uiDataMenu_PasteAfter" Header="{DynamicResource ui_TASFlow_Menu_PasteAfter}" Click="uiDataMenu_PasteAfter_Click"/>
<MenuItem x:Name="uiDataMenu_PasteBefore" Header="{DynamicResource ui_TASFlow_Menu_PasterBefore}" Click="uiDataMenu_PasteBefore_Click"/>
<Separator/>
<MenuItem x:Name="uiDataMenu_Delete" Header="{DynamicResource ui_TASFlow_Menu_Delete}" Click="uiDataMenu_Delete_Click"/>
<MenuItem x:Name="uiDataMenu_DeleteAfter" Header="{DynamicResource ui_TASFlow_Menu_DeleteAfter}" Click="uiDataMenu_DeleteAfter_Click" InputGestureText="Del"/>
<MenuItem x:Name="uiDataMenu_DeleteBefore" Header="{DynamicResource ui_TASFlow_Menu_PasterBefore}" Click="uiDataMenu_DeleteBefore_Click" InputGestureText="Backspace"/>
<Separator/>
<MenuItem x:Name="uiDataMenu_AddAfter" Header="{DynamicResource ui_TASFlow_Menu_AddAfter}" Click="uiDataMenu_AddAfter_Click"/>
<MenuItem x:Name="uiDataMenu_AddBefore" Header="{DynamicResource ui_TASFlow_Menu_AddBefore}" Click="uiDataMenu_AddBefore_Click"/>
</ContextMenu>
</Grid.ContextMenu>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="1" Text="{DynamicResource ui_TASFlow_Sheet_Frame}"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="2" Text="{DynamicResource ui_TASFlow_Sheet_DeltaTime}"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="3" Text="^"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="4" Text="v"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="5" Text="&lt;"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="6" Text="&gt;"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="7" Text="shift"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="8" Text="space"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="9" Text="q"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="10" Text="esc"/>
<TextBlock Padding="2" Background="#afafaf" Grid.Column="0" Grid.Row="11" Text="enter"/>
</Grid>
</UserControl>

View File

@ -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<long> 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<double> e) {
ValueChanged?.Invoke(e.NewValue.ToInt64());
}
}
}

View File

@ -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<FrameDataDisplay> mDataSource;
bool mOverwrittenPaste;
private void sliderValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) {
long pos = e.NewValue.ToInt64();
mFile.Shift(pos);
#region self event
public event Action<bool, bool, bool> UpdateDataUI;
public event Action<ToolMode> UpdateToolMode;
public event Action<SelectionHelp> 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();
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();
}
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;
}
}
#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;
@ -226,7 +220,7 @@ 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
}
}