2021-05-13 15:49:26 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using BallanceTASEditor.Core;
|
|
|
|
|
|
using BallanceTASEditor.Core.TASStruct;
|
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
2021-05-13 22:18:51 +08:00
|
|
|
|
namespace BallanceTASEditor.UI {
|
2021-05-13 15:49:26 +08:00
|
|
|
|
public class TASViewer : IDisposable {
|
2021-05-15 16:23:16 +08:00
|
|
|
|
public TASViewer(TASFile file, Slider slider, TASFlow datagrid, TextBlock statusbar) {
|
2021-05-13 15:49:26 +08:00
|
|
|
|
mFile = file;
|
|
|
|
|
|
mSlider = slider;
|
|
|
|
|
|
mDataGrid = datagrid;
|
2021-05-15 16:23:16 +08:00
|
|
|
|
mStatusbar = statusbar;
|
2021-05-13 15:49:26 +08:00
|
|
|
|
|
|
|
|
|
|
// restore slider
|
|
|
|
|
|
mSlider.Minimum = 0;
|
|
|
|
|
|
updateSliderRange();
|
|
|
|
|
|
|
2021-05-15 16:23:16 +08:00
|
|
|
|
// init selection
|
|
|
|
|
|
mSelectionHelp = new SelectionHelp();
|
|
|
|
|
|
mSelectionHelp.SelectionChanged += funcSelectionHelp_SelectionChanged;
|
|
|
|
|
|
|
2021-05-13 15:49:26 +08:00
|
|
|
|
// init data
|
|
|
|
|
|
INVALID_FRAME_DATA = new FrameData(-1f, 0);
|
2021-05-15 16:23:16 +08:00
|
|
|
|
mDataSource = new List<FrameDataDisplay>();
|
|
|
|
|
|
mListLength = 0;
|
2021-05-13 15:49:26 +08:00
|
|
|
|
|
|
|
|
|
|
// bind event and source
|
2021-05-13 22:18:51 +08:00
|
|
|
|
mDataGrid.DataSources = mDataSource;
|
2021-05-15 16:23:16 +08:00
|
|
|
|
mDataGrid.SelectionHelp = mSelectionHelp;
|
2021-05-16 14:15:35 +08:00
|
|
|
|
|
|
|
|
|
|
mDataGrid.uiDataMenu_Set.Click += funcDataMenu_Set;
|
|
|
|
|
|
mDataGrid.uiDataMenu_Unset.Click += funcDataMenu_Unset;
|
|
|
|
|
|
mDataGrid.uiDataMenu_Copy.Click += funcDataMenu_Copy;
|
|
|
|
|
|
mDataGrid.uiDataMenu_Delete.Click += funcDataMenu_Delete;
|
|
|
|
|
|
mDataGrid.uiDataMenu_PasteAfter.Click += funcDataMenu_PasteAfter;
|
|
|
|
|
|
mDataGrid.uiDataMenu_PasteBefore.Click += funcDataMenu_PasteBefore;
|
|
|
|
|
|
mDataGrid.uiDataMenu_AddAfter.Click += funcDataMenu_AddAfter;
|
|
|
|
|
|
mDataGrid.uiDataMenu_AddBefore.Click += funcDataMenu_AddBefore;
|
|
|
|
|
|
mDataGrid.Click += funcDataMenu_Click;
|
|
|
|
|
|
|
2021-05-13 15:49:26 +08:00
|
|
|
|
mSlider.ValueChanged += sliderValueChanged;
|
2021-05-15 16:23:16 +08:00
|
|
|
|
|
|
|
|
|
|
// display data
|
|
|
|
|
|
ChangeListLength(DATA_LIST_LENGTH);
|
2021-05-13 15:49:26 +08:00
|
|
|
|
}
|
2021-05-15 16:23:16 +08:00
|
|
|
|
|
2021-05-13 15:49:26 +08:00
|
|
|
|
public void Dispose() {
|
2021-05-13 22:18:51 +08:00
|
|
|
|
mDataGrid.DataSources = null;
|
2021-05-16 14:15:35 +08:00
|
|
|
|
|
|
|
|
|
|
mDataGrid.uiDataMenu_Set.Click -= funcDataMenu_Set;
|
|
|
|
|
|
mDataGrid.uiDataMenu_Unset.Click -= funcDataMenu_Unset;
|
|
|
|
|
|
mDataGrid.uiDataMenu_Copy.Click -= funcDataMenu_Copy;
|
|
|
|
|
|
mDataGrid.uiDataMenu_Delete.Click -= funcDataMenu_Delete;
|
|
|
|
|
|
mDataGrid.uiDataMenu_PasteAfter.Click -= funcDataMenu_PasteAfter;
|
|
|
|
|
|
mDataGrid.uiDataMenu_PasteBefore.Click -= funcDataMenu_PasteBefore;
|
|
|
|
|
|
mDataGrid.uiDataMenu_AddAfter.Click -= funcDataMenu_AddAfter;
|
|
|
|
|
|
mDataGrid.uiDataMenu_AddBefore.Click -= funcDataMenu_AddBefore;
|
|
|
|
|
|
mDataGrid.Click -= funcDataMenu_Click;
|
|
|
|
|
|
|
2021-05-13 15:49:26 +08:00
|
|
|
|
mSlider.ValueChanged -= sliderValueChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-13 22:18:51 +08:00
|
|
|
|
const int DATA_LIST_LENGTH = 15;
|
2021-05-13 15:49:26 +08:00
|
|
|
|
FrameData INVALID_FRAME_DATA;
|
|
|
|
|
|
TASFile mFile;
|
|
|
|
|
|
Slider mSlider;
|
2021-05-15 16:23:16 +08:00
|
|
|
|
TextBlock mStatusbar;
|
2021-05-13 22:18:51 +08:00
|
|
|
|
TASFlow mDataGrid;
|
2021-05-15 16:23:16 +08:00
|
|
|
|
SelectionHelp mSelectionHelp;
|
|
|
|
|
|
int mListLength;
|
2021-05-13 22:18:51 +08:00
|
|
|
|
List<FrameDataDisplay> mDataSource;
|
2021-05-13 15:49:26 +08:00
|
|
|
|
|
|
|
|
|
|
private void sliderValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) {
|
2021-05-22 13:25:37 +08:00
|
|
|
|
long pos = e.NewValue.ToInt64();
|
2021-05-21 22:37:25 +08:00
|
|
|
|
mFile.Shift(pos);
|
2021-05-13 15:49:26 +08:00
|
|
|
|
|
2021-05-21 22:37:25 +08:00
|
|
|
|
RefreshDisplay();
|
2021-05-13 15:49:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void updateSliderRange() {
|
|
|
|
|
|
long newSize = mFile.mFrameCount - 1;
|
|
|
|
|
|
if (mSlider.Value > newSize)
|
|
|
|
|
|
mSlider.Value = newSize;
|
|
|
|
|
|
mSlider.Maximum = newSize;
|
|
|
|
|
|
}
|
2021-05-15 16:23:16 +08:00
|
|
|
|
|
|
|
|
|
|
private void funcSelectionHelp_SelectionChanged() {
|
|
|
|
|
|
mDataGrid.RefreshDataMenu();
|
|
|
|
|
|
mDataGrid.RefreshSelectionHighlight();
|
|
|
|
|
|
OnStatusbarSelectionChanged();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ChangeListLength(int newLen) {
|
|
|
|
|
|
if (newLen < 5 || newLen > 30) return;
|
|
|
|
|
|
int offset = newLen - mListLength;
|
|
|
|
|
|
int abs = Math.Abs(offset);
|
|
|
|
|
|
if (offset == 0) return;
|
|
|
|
|
|
|
|
|
|
|
|
// change mDataSource first
|
|
|
|
|
|
|
|
|
|
|
|
if (offset > 0) {
|
|
|
|
|
|
for (int i = 0; i < abs; i++) {
|
|
|
|
|
|
mDataSource.Add(new FrameDataDisplay(0, INVALID_FRAME_DATA));
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
mDataSource.RemoveRange(newLen, abs);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// then change viewer control
|
|
|
|
|
|
mDataGrid.SetItemCount(newLen);
|
|
|
|
|
|
|
|
|
|
|
|
// apply new value
|
|
|
|
|
|
mListLength = newLen;
|
|
|
|
|
|
|
|
|
|
|
|
// then refresh
|
2021-05-21 22:37:25 +08:00
|
|
|
|
RefreshDisplay();
|
2021-05-15 16:23:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-21 22:37:25 +08:00
|
|
|
|
public void RefreshDisplay() {
|
|
|
|
|
|
mFile.Get(mDataSource, mListLength);
|
2021-05-15 16:23:16 +08:00
|
|
|
|
mDataGrid.RefreshDataSources();
|
|
|
|
|
|
mDataGrid.RefreshSelectionHighlight();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ChangeToolMode(ToolMode mode) {
|
|
|
|
|
|
mSelectionHelp.SetMode(mode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-22 13:25:37 +08:00
|
|
|
|
public int GetItemCountInPage() {
|
|
|
|
|
|
return mListLength;
|
|
|
|
|
|
}
|
2021-05-16 14:15:35 +08:00
|
|
|
|
|
|
|
|
|
|
#region data menu
|
|
|
|
|
|
|
|
|
|
|
|
private void funcDataMenu_AddBefore(object sender, RoutedEventArgs e) {
|
2021-05-21 22:37:25 +08:00
|
|
|
|
if (!DialogUtil.AddItemDialog(out int count, out float deltaTime)) return;
|
|
|
|
|
|
|
|
|
|
|
|
var pos = mSelectionHelp.GetPoint();
|
|
|
|
|
|
mFile.Add(pos, count, deltaTime, true);
|
2021-05-22 13:25:37 +08:00
|
|
|
|
updateSliderRange();
|
2021-05-21 22:37:25 +08:00
|
|
|
|
RefreshDisplay();
|
2021-05-16 14:15:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void funcDataMenu_AddAfter(object sender, RoutedEventArgs e) {
|
2021-05-21 22:37:25 +08:00
|
|
|
|
if (!DialogUtil.AddItemDialog(out int count, out float deltaTime)) return;
|
|
|
|
|
|
|
|
|
|
|
|
var pos = mSelectionHelp.GetPoint();
|
|
|
|
|
|
mFile.Add(pos, count, deltaTime, false);
|
2021-05-22 13:25:37 +08:00
|
|
|
|
updateSliderRange();
|
2021-05-21 22:37:25 +08:00
|
|
|
|
RefreshDisplay();
|
2021-05-16 14:15:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void funcDataMenu_PasteBefore(object sender, RoutedEventArgs e) {
|
2021-05-22 13:25:37 +08:00
|
|
|
|
var data = new LinkedList<FrameData>();
|
|
|
|
|
|
if (ClipboardUtil.GetFrameData(data)) {
|
|
|
|
|
|
mFile.Insert(mSelectionHelp.GetPoint(), data, true);
|
|
|
|
|
|
updateSliderRange();
|
|
|
|
|
|
RefreshDisplay();
|
|
|
|
|
|
} else MessageBox.Show("Fail to paste due to unknow reason or blank clipboard!");
|
2021-05-16 14:15:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void funcDataMenu_PasteAfter(object sender, RoutedEventArgs e) {
|
2021-05-22 13:25:37 +08:00
|
|
|
|
var data = new LinkedList<FrameData>();
|
|
|
|
|
|
if (ClipboardUtil.GetFrameData(data)) {
|
|
|
|
|
|
mFile.Insert(mSelectionHelp.GetPoint(), data, false);
|
|
|
|
|
|
updateSliderRange();
|
|
|
|
|
|
RefreshDisplay();
|
|
|
|
|
|
} else MessageBox.Show("Fail to paste due to unknow reason or blank clipboard!");
|
2021-05-16 14:15:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void funcDataMenu_Delete(object sender, RoutedEventArgs e) {
|
2021-05-22 13:25:37 +08:00
|
|
|
|
mFile.Remove(mSelectionHelp.GetRange());
|
|
|
|
|
|
updateSliderRange();
|
|
|
|
|
|
RefreshDisplay();
|
2021-05-16 14:15:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void funcDataMenu_Copy(object sender, RoutedEventArgs e) {
|
2021-05-22 13:25:37 +08:00
|
|
|
|
var data = new LinkedList<FrameData>();
|
|
|
|
|
|
mFile.Copy(mSelectionHelp.GetRange(), data);
|
|
|
|
|
|
if (!ClipboardUtil.SetFrameData(data))
|
|
|
|
|
|
MessageBox.Show("Fail to copy due to unknow reason!");
|
2021-05-16 14:15:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void funcDataMenu_Unset(object sender, RoutedEventArgs e) {
|
2021-05-21 22:37:25 +08:00
|
|
|
|
mFile.Set(mSelectionHelp.GetFieldRange(), mSelectionHelp.GetRange(), false);
|
|
|
|
|
|
RefreshDisplay();
|
2021-05-16 14:15:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void funcDataMenu_Set(object sender, RoutedEventArgs e) {
|
2021-05-21 22:37:25 +08:00
|
|
|
|
mFile.Set(mSelectionHelp.GetFieldRange(), mSelectionHelp.GetRange(), true);
|
|
|
|
|
|
RefreshDisplay();
|
2021-05-16 14:15:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void funcDataMenu_Click() {
|
2021-05-21 22:37:25 +08:00
|
|
|
|
var data = mSelectionHelp.GetPoint();
|
2021-05-16 14:15:35 +08:00
|
|
|
|
var field = (int)mSelectionHelp.GetPointField();
|
|
|
|
|
|
mFile.Set(new SelectionRange(field, field), new SelectionRange(data, data), null);
|
2021-05-21 22:37:25 +08:00
|
|
|
|
RefreshDisplay();
|
2021-05-16 14:15:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2021-05-13 15:49:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|