2021-05-16 14:15:35 +08:00
|
|
|
|
using BallanceTASEditor.Core;
|
|
|
|
|
|
using BallanceTASEditor.Core.TASStruct;
|
2021-05-13 22:18:51 +08:00
|
|
|
|
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 {
|
2021-09-20 13:58:10 +08:00
|
|
|
|
public partial class TASFlow {
|
|
|
|
|
|
public TASFlow(Grid coreWindow) {
|
|
|
|
|
|
uiCoreWindow = coreWindow;
|
2021-05-13 22:18:51 +08:00
|
|
|
|
mItemList = new List<TASFlowUIItem>();
|
2021-05-15 16:23:16 +08:00
|
|
|
|
mRectMap = new Dictionary<Rectangle, CellPosition>();
|
2021-05-13 22:18:51 +08:00
|
|
|
|
mItemCount = 0;
|
|
|
|
|
|
SetItemCount(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-16 14:15:35 +08:00
|
|
|
|
public event Action Click;
|
|
|
|
|
|
|
2021-09-20 13:58:10 +08:00
|
|
|
|
private Grid uiCoreWindow;
|
2021-05-13 22:18:51 +08:00
|
|
|
|
private int mItemCount;
|
|
|
|
|
|
private List<TASFlowUIItem> mItemList;
|
2021-05-15 16:23:16 +08:00
|
|
|
|
private Dictionary<Rectangle, CellPosition> mRectMap;
|
|
|
|
|
|
public SelectionHelp SelectionHelp { get; set; }
|
2021-05-13 22:18:51 +08:00
|
|
|
|
public List<FrameDataDisplay> DataSources { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public void RefreshDataSources() {
|
|
|
|
|
|
if (DataSources == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < mItemCount; i++) {
|
|
|
|
|
|
mItemList[i].Reload(DataSources[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetItemCount(int newCount) {
|
|
|
|
|
|
var offset = newCount - mItemCount;
|
|
|
|
|
|
var abs = Math.Abs(offset);
|
|
|
|
|
|
if (offset == 0) return;
|
|
|
|
|
|
|
|
|
|
|
|
// change column defination first
|
|
|
|
|
|
if (offset > 0) {
|
2021-09-20 13:58:10 +08:00
|
|
|
|
for (int i = 0; i < abs; i++) {
|
2021-05-13 22:18:51 +08:00
|
|
|
|
var item = new ColumnDefinition();
|
2021-09-20 13:58:10 +08:00
|
|
|
|
item.Width = new GridLength(1, GridUnitType.Star);
|
2021-05-13 22:18:51 +08:00
|
|
|
|
uiCoreWindow.ColumnDefinitions.Add(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
uiCoreWindow.ColumnDefinitions.RemoveRange(newCount + 1, abs); // the first col is sheet header, so add 1 additionally
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// add / remove item
|
|
|
|
|
|
if (offset > 0) {
|
|
|
|
|
|
for (int i = 0; i < abs; i++) {
|
|
|
|
|
|
var newItem = new TASFlowUIItem(mItemCount + 1 + i); // the first col is sheet header, so add 1 additionally
|
2021-05-15 16:23:16 +08:00
|
|
|
|
newItem.Add(uiCoreWindow, mRectMap, Rectangle_MouseDown);
|
2021-05-13 22:18:51 +08:00
|
|
|
|
mItemList.Add(newItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2021-09-20 13:58:10 +08:00
|
|
|
|
for (int i = 0; i < abs; i++) {
|
2021-05-15 16:23:16 +08:00
|
|
|
|
mItemList[newCount + i].Remove(uiCoreWindow, mRectMap, Rectangle_MouseDown);
|
2021-05-13 22:18:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
mItemList.RemoveRange(newCount, abs);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// apply new count
|
|
|
|
|
|
mItemCount = newCount;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-15 16:23:16 +08:00
|
|
|
|
public void RefreshSelectionHighlight() {
|
|
|
|
|
|
ToolMode mode = SelectionHelp.GetToolMode();
|
|
|
|
|
|
|
|
|
|
|
|
if (mode == ToolMode.Cursor) {
|
|
|
|
|
|
if (SelectionHelp.IsDataReady()) {
|
|
|
|
|
|
var data = SelectionHelp.GetRange();
|
|
|
|
|
|
foreach (var item in mItemList) {
|
|
|
|
|
|
if (data.Within(item.rawFrame)) {
|
|
|
|
|
|
item.SelectFull();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
item.Unselect();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
} else if (SelectionHelp.IsDataPartialReady()) {
|
|
|
|
|
|
var data = SelectionHelp.GetPoint();
|
|
|
|
|
|
foreach (var item in mItemList) {
|
|
|
|
|
|
if (data == item.rawFrame) {
|
|
|
|
|
|
item.SelectFull();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
item.Unselect();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (mode == ToolMode.Fill) {
|
|
|
|
|
|
if (SelectionHelp.IsDataReady()) {
|
|
|
|
|
|
var data = SelectionHelp.GetRange();
|
|
|
|
|
|
var field = SelectionHelp.GetFieldRange();
|
|
|
|
|
|
foreach (var item in mItemList) {
|
|
|
|
|
|
if (data.Within(item.rawFrame)) {
|
|
|
|
|
|
item.SelectField(field);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
item.Unselect();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// fail if prog run into this position, clear
|
|
|
|
|
|
foreach (var item in mItemList) {
|
|
|
|
|
|
item.Unselect();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Rectangle_MouseDown(object sender, MouseButtonEventArgs e) {
|
|
|
|
|
|
if (SelectionHelp == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
// because the first column is header
|
|
|
|
|
|
// so all pos.column should -1
|
|
|
|
|
|
var rect = sender as Rectangle;
|
|
|
|
|
|
var pos = mRectMap[rect];
|
|
|
|
|
|
if (!mItemList[pos.column - 1].rawIsEnable) return;
|
|
|
|
|
|
if (e.MouseDevice.LeftButton == MouseButtonState.Pressed) {
|
2021-05-16 14:15:35 +08:00
|
|
|
|
if (KeyboardState.IsKeyPressed(KeyboardState.VirtualKeyStates.VK_SHIFT)) {
|
|
|
|
|
|
SelectionHelp.LastClick(mItemList[pos.column - 1].rawFrame, pos.field);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
SelectionHelp.FirstClick(mItemList[pos.column - 1].rawFrame, pos.field);
|
|
|
|
|
|
}
|
2021-05-15 16:23:16 +08:00
|
|
|
|
}
|
2021-05-16 14:15:35 +08:00
|
|
|
|
|
|
|
|
|
|
// note main window to process it.
|
|
|
|
|
|
OnClick();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// only raised in overwrite mode
|
|
|
|
|
|
private void OnClick() {
|
|
|
|
|
|
if (SelectionHelp.GetToolMode() == ToolMode.Overwrite)
|
|
|
|
|
|
Click?.Invoke();
|
2021-05-15 16:23:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-13 22:18:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class TASFlowUIItem {
|
|
|
|
|
|
private static readonly Thickness DEFAULT_MARGIN = new Thickness(2);
|
|
|
|
|
|
private static readonly Thickness RECT_MARGIN = new Thickness(1);
|
2021-05-15 16:23:16 +08:00
|
|
|
|
private static readonly SolidColorBrush SEL_RECT_NORMAL_BRUSH = new SolidColorBrush(Colors.White);
|
2021-05-16 14:15:35 +08:00
|
|
|
|
private static readonly SolidColorBrush SEL_RECT_SELECTED_BRUSH = new SolidColorBrush(Colors.OrangeRed);
|
|
|
|
|
|
private static readonly SolidColorBrush SEL_RECT_STROKE = new SolidColorBrush(Colors.LightGray);
|
2021-05-13 22:18:51 +08:00
|
|
|
|
private static readonly Color COLOR_SET = Color.FromRgb(30, 144, 255);
|
|
|
|
|
|
private static readonly Color COLOR_UNSET = Color.FromArgb(0, 255, 255, 255);
|
2021-05-16 14:15:35 +08:00
|
|
|
|
private static readonly Color COLOR_SELECTED = Colors.OrangeRed;
|
|
|
|
|
|
private static readonly Color COLOR_UNSELECTED = Colors.LightGray;
|
2021-05-13 22:18:51 +08:00
|
|
|
|
private const int KEY_COUNT = 9;
|
2021-05-15 16:23:16 +08:00
|
|
|
|
private const double SELECTION_HEADER_HEIGHT = 10.0f;
|
2021-05-13 22:18:51 +08:00
|
|
|
|
|
|
|
|
|
|
public TASFlowUIItem(int column) {
|
|
|
|
|
|
// basic item
|
2021-05-15 16:23:16 +08:00
|
|
|
|
sel_rect = new Rectangle();
|
2021-05-13 22:18:51 +08:00
|
|
|
|
frame = new TextBlock();
|
|
|
|
|
|
deltaTime = new TextBlock();
|
|
|
|
|
|
|
2021-05-15 16:23:16 +08:00
|
|
|
|
Grid.SetRow(sel_rect, 0);
|
|
|
|
|
|
Grid.SetRow(frame, 1);
|
|
|
|
|
|
Grid.SetRow(deltaTime, 2);
|
|
|
|
|
|
Grid.SetColumn(sel_rect, column);
|
2021-05-13 22:18:51 +08:00
|
|
|
|
Grid.SetColumn(frame, column);
|
|
|
|
|
|
Grid.SetColumn(deltaTime, column);
|
|
|
|
|
|
|
2021-05-15 16:23:16 +08:00
|
|
|
|
sel_rect.Margin = RECT_MARGIN;
|
2021-05-13 22:18:51 +08:00
|
|
|
|
frame.Margin = DEFAULT_MARGIN;
|
|
|
|
|
|
deltaTime.Margin = DEFAULT_MARGIN;
|
|
|
|
|
|
|
2021-05-16 14:15:35 +08:00
|
|
|
|
sel_rect.StrokeThickness = 2;
|
2021-05-15 16:23:16 +08:00
|
|
|
|
sel_rect.Stroke = SEL_RECT_STROKE;
|
|
|
|
|
|
sel_rect.Height = SELECTION_HEADER_HEIGHT;
|
|
|
|
|
|
|
2021-05-13 22:18:51 +08:00
|
|
|
|
// keystates item
|
|
|
|
|
|
keystates = new Rectangle[KEY_COUNT];
|
|
|
|
|
|
keystatesFill = new SolidColorBrush[KEY_COUNT];
|
2021-05-15 16:23:16 +08:00
|
|
|
|
keystatesStroke = new SolidColorBrush[KEY_COUNT];
|
2021-05-13 22:18:51 +08:00
|
|
|
|
for (int i = 0; i < KEY_COUNT; i++) {
|
|
|
|
|
|
keystates[i] = new Rectangle();
|
|
|
|
|
|
keystatesFill[i] = new SolidColorBrush(COLOR_UNSET);
|
2021-05-15 16:23:16 +08:00
|
|
|
|
keystatesStroke[i] = new SolidColorBrush(COLOR_UNSELECTED);
|
|
|
|
|
|
Grid.SetRow(keystates[i], 3 + i);
|
2021-05-13 22:18:51 +08:00
|
|
|
|
Grid.SetColumn(keystates[i], column);
|
|
|
|
|
|
keystates[i].Margin = RECT_MARGIN;
|
2021-05-15 16:23:16 +08:00
|
|
|
|
keystates[i].StrokeThickness = 3;
|
|
|
|
|
|
keystates[i].Stroke = keystatesStroke[i];
|
2021-05-13 22:18:51 +08:00
|
|
|
|
keystates[i].Fill = keystatesFill[i];
|
|
|
|
|
|
}
|
2021-05-15 16:23:16 +08:00
|
|
|
|
|
|
|
|
|
|
this.column = column;
|
|
|
|
|
|
rawFrame = 0;
|
|
|
|
|
|
rawIsEnable = false;
|
2021-05-13 22:18:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-15 16:23:16 +08:00
|
|
|
|
public void Add(Grid target, Dictionary<Rectangle, CellPosition> map, MouseButtonEventHandler func) {
|
|
|
|
|
|
target.Children.Add(sel_rect);
|
2021-05-13 22:18:51 +08:00
|
|
|
|
target.Children.Add(frame);
|
|
|
|
|
|
target.Children.Add(deltaTime);
|
|
|
|
|
|
for (int i = 0; i < KEY_COUNT; i++) {
|
|
|
|
|
|
target.Children.Add(keystates[i]);
|
2021-05-15 16:23:16 +08:00
|
|
|
|
keystates[i].MouseDown += func;
|
|
|
|
|
|
map.Add(keystates[i], new CellPosition(column, (FrameDataField)i));
|
2021-05-13 22:18:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-15 16:23:16 +08:00
|
|
|
|
public void Remove(Grid target, Dictionary<Rectangle, CellPosition> map, MouseButtonEventHandler func) {
|
|
|
|
|
|
target.Children.Remove(sel_rect);
|
2021-05-13 22:18:51 +08:00
|
|
|
|
target.Children.Remove(frame);
|
|
|
|
|
|
target.Children.Remove(deltaTime);
|
|
|
|
|
|
for (int i = 0; i < KEY_COUNT; i++) {
|
|
|
|
|
|
target.Children.Remove(keystates[i]);
|
2021-05-15 16:23:16 +08:00
|
|
|
|
keystates[i].MouseDown -= func;
|
|
|
|
|
|
map.Remove(keystates[i]);
|
2021-05-13 22:18:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Reload(FrameDataDisplay fdd) {
|
|
|
|
|
|
var isEnable = fdd.isEnable;
|
|
|
|
|
|
frame.Text = isEnable ? fdd.index.ToString() : "";
|
|
|
|
|
|
deltaTime.Text = isEnable ? fdd.deltaTime.ToString() : "";
|
|
|
|
|
|
keystatesFill[0].Color = isEnable && fdd.key_up ? COLOR_SET : COLOR_UNSET;
|
|
|
|
|
|
keystatesFill[1].Color = isEnable && fdd.key_down ? COLOR_SET : COLOR_UNSET;
|
|
|
|
|
|
keystatesFill[2].Color = isEnable && fdd.key_left ? COLOR_SET : COLOR_UNSET;
|
|
|
|
|
|
keystatesFill[3].Color = isEnable && fdd.key_right ? COLOR_SET : COLOR_UNSET;
|
|
|
|
|
|
keystatesFill[4].Color = isEnable && fdd.key_shift ? COLOR_SET : COLOR_UNSET;
|
|
|
|
|
|
keystatesFill[5].Color = isEnable && fdd.key_space ? COLOR_SET : COLOR_UNSET;
|
|
|
|
|
|
keystatesFill[6].Color = isEnable && fdd.key_q ? COLOR_SET : COLOR_UNSET;
|
|
|
|
|
|
keystatesFill[7].Color = isEnable && fdd.key_esc ? COLOR_SET : COLOR_UNSET;
|
|
|
|
|
|
keystatesFill[8].Color = isEnable && fdd.key_enter ? COLOR_SET : COLOR_UNSET;
|
|
|
|
|
|
|
2021-05-16 14:15:35 +08:00
|
|
|
|
sel_rect.Visibility = isEnable ? Visibility.Visible : Visibility.Collapsed;
|
2021-05-13 22:18:51 +08:00
|
|
|
|
frame.Visibility = isEnable ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
|
|
deltaTime.Visibility = isEnable ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
|
|
for (int i = 0; i < KEY_COUNT; i++) {
|
|
|
|
|
|
keystates[i].Visibility = isEnable ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
|
|
}
|
2021-05-15 16:23:16 +08:00
|
|
|
|
|
|
|
|
|
|
rawIsEnable = isEnable;
|
|
|
|
|
|
rawFrame = fdd.index;
|
2021-05-13 22:18:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-15 16:23:16 +08:00
|
|
|
|
public void SelectFull() {
|
|
|
|
|
|
sel_rect.Fill = SEL_RECT_SELECTED_BRUSH;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SelectField(SelectionRange range) {
|
|
|
|
|
|
for (int i = 0; i < KEY_COUNT; i++) {
|
|
|
|
|
|
keystatesStroke[i].Color = range.Within(i) ? COLOR_SELECTED : COLOR_UNSELECTED;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Unselect() {
|
|
|
|
|
|
sel_rect.Fill = SEL_RECT_NORMAL_BRUSH;
|
|
|
|
|
|
for (int i = 0; i < KEY_COUNT; i++) {
|
|
|
|
|
|
keystatesStroke[i].Color = COLOR_UNSELECTED;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long rawFrame;
|
|
|
|
|
|
public bool rawIsEnable;
|
|
|
|
|
|
|
|
|
|
|
|
public Rectangle sel_rect;
|
2021-05-13 22:18:51 +08:00
|
|
|
|
public TextBlock frame;
|
|
|
|
|
|
public TextBlock deltaTime;
|
|
|
|
|
|
public Rectangle[] keystates;
|
|
|
|
|
|
private SolidColorBrush[] keystatesFill;
|
2021-05-15 16:23:16 +08:00
|
|
|
|
private SolidColorBrush[] keystatesStroke;
|
|
|
|
|
|
private int column;
|
2021-05-13 22:18:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|