Files
BallanceTasEditor/UI/TASViewer.cs

68 lines
2.1 KiB
C#
Raw Normal View History

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-13 22:18:51 +08:00
public TASViewer(TASFile file, Slider slider, TASFlow datagrid) {
2021-05-13 15:49:26 +08:00
mFile = file;
mSlider = slider;
mDataGrid = datagrid;
// restore slider
mSlider.Minimum = 0;
updateSliderRange();
// init data
mPosition = 0;
2021-05-13 22:18:51 +08:00
mDataSource = new List<FrameDataDisplay>();
2021-05-13 15:49:26 +08:00
INVALID_FRAME_DATA = new FrameData(-1f, 0);
for (int i = 0; i < DATA_LIST_LENGTH; i++) {
mDataSource.Add(new FrameDataDisplay(0, INVALID_FRAME_DATA));
}
mFile.Get(mDataSource, 0, DATA_LIST_LENGTH);
// bind event and source
2021-05-13 22:18:51 +08:00
mDataGrid.SetItemCount(DATA_LIST_LENGTH);
mDataGrid.DataSources = mDataSource;
mDataGrid.RefreshDataSources();
2021-05-13 15:49:26 +08:00
mSlider.ValueChanged += sliderValueChanged;
}
public void Dispose() {
2021-05-13 22:18:51 +08:00
mDataGrid.DataSources = null;
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-13 22:18:51 +08:00
TASFlow mDataGrid;
2021-05-13 15:49:26 +08:00
long mPosition;
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) {
long pos = Convert.ToInt64(Math.Floor(e.NewValue));
long offset = pos - mPosition;
mFile.Shift(offset);
2021-05-13 22:18:51 +08:00
mFile.Get(mDataSource, pos, DATA_LIST_LENGTH);
2021-05-13 15:49:26 +08:00
mPosition = pos;
2021-05-13 22:18:51 +08:00
mDataGrid.RefreshDataSources();
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;
}
}
}