2021-05-15 16:23:16 +08:00
|
|
|
|
using BallanceTASEditor.Core.TASStruct;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
2021-05-21 22:37:25 +08:00
|
|
|
|
using BallanceTASEditor.Core;
|
2021-05-15 16:23:16 +08:00
|
|
|
|
|
|
|
|
|
|
namespace BallanceTASEditor.UI {
|
|
|
|
|
|
public class SelectionHelp {
|
|
|
|
|
|
public SelectionHelp() {
|
|
|
|
|
|
SetMode(ToolMode.Cursor);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public event Action SelectionChanged;
|
|
|
|
|
|
|
|
|
|
|
|
ToolMode mMode;
|
|
|
|
|
|
FrameDataField mStartField;
|
|
|
|
|
|
FrameDataField mEndField;
|
|
|
|
|
|
long mStart;
|
|
|
|
|
|
bool mIsStartConfirmed;
|
|
|
|
|
|
long mEnd;
|
|
|
|
|
|
bool mIsEndConfirmed;
|
|
|
|
|
|
|
|
|
|
|
|
public void SetMode(ToolMode mode) {
|
|
|
|
|
|
switch (mode) {
|
|
|
|
|
|
case ToolMode.Cursor:
|
|
|
|
|
|
mStart = 0;
|
|
|
|
|
|
mEnd = 0;
|
|
|
|
|
|
mIsStartConfirmed = false;
|
|
|
|
|
|
mIsEndConfirmed = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ToolMode.Fill:
|
|
|
|
|
|
mStartField = FrameDataField.Key_Up;
|
|
|
|
|
|
mEndField = FrameDataField.Key_Up;
|
|
|
|
|
|
mStart = 0;
|
|
|
|
|
|
mEnd = 0;
|
|
|
|
|
|
mIsStartConfirmed = false;
|
|
|
|
|
|
mIsEndConfirmed = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ToolMode.Overwrite:
|
|
|
|
|
|
mStartField = FrameDataField.Key_Up;
|
|
|
|
|
|
mStart = 0;
|
|
|
|
|
|
mIsStartConfirmed = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mMode = mode;
|
|
|
|
|
|
OnSelectionChanged();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void FirstClick(long index, FrameDataField field) {
|
|
|
|
|
|
mStartField = field;
|
|
|
|
|
|
mStart = index;
|
|
|
|
|
|
mIsStartConfirmed = true;
|
|
|
|
|
|
mIsEndConfirmed = false;
|
|
|
|
|
|
|
|
|
|
|
|
OnSelectionChanged();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void LastClick(long index, FrameDataField field) {
|
|
|
|
|
|
if (mMode == ToolMode.Overwrite) return;
|
|
|
|
|
|
if (!mIsStartConfirmed) return;
|
|
|
|
|
|
|
|
|
|
|
|
mEndField = field;
|
|
|
|
|
|
mEnd = index;
|
|
|
|
|
|
mIsEndConfirmed = true;
|
|
|
|
|
|
OnSelectionChanged();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Reset() {
|
|
|
|
|
|
// reuse set mode to reset
|
|
|
|
|
|
SetMode(mMode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public SelectionRange GetRange() {
|
|
|
|
|
|
if (mMode == ToolMode.Overwrite) throw new Exception("Read with wrong mode.");
|
|
|
|
|
|
if (!(mIsStartConfirmed && mIsEndConfirmed)) throw new Exception("Data is not ready to read");
|
|
|
|
|
|
return new SelectionRange(mStart, mEnd);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public SelectionRange GetFieldRange() {
|
|
|
|
|
|
if (mMode != ToolMode.Fill) throw new Exception("Read with wrong mode.");
|
|
|
|
|
|
if (!(mIsStartConfirmed && mIsEndConfirmed)) throw new Exception("Data is not ready to read");
|
|
|
|
|
|
return new SelectionRange((int)mStartField, (int)mEndField);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long GetPoint() {
|
|
|
|
|
|
if (mMode == ToolMode.Fill) throw new Exception("Read with wrong mode.");
|
|
|
|
|
|
if (!mIsStartConfirmed) throw new Exception("Data is not ready to read");
|
|
|
|
|
|
|
2021-05-16 14:15:35 +08:00
|
|
|
|
if (mMode == ToolMode.Overwrite) return mStart;
|
2021-05-15 16:23:16 +08:00
|
|
|
|
else {
|
|
|
|
|
|
// cursor mode
|
|
|
|
|
|
if (mIsStartConfirmed) return mStart;
|
|
|
|
|
|
else throw new Exception("Data is not ready to read");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-16 14:15:35 +08:00
|
|
|
|
public FrameDataField GetPointField() {
|
|
|
|
|
|
if (mMode != ToolMode.Overwrite) throw new Exception("Read with wrong mode.");
|
|
|
|
|
|
if (!mIsStartConfirmed) throw new Exception("Data is not ready to read");
|
|
|
|
|
|
|
|
|
|
|
|
return mStartField;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-15 16:23:16 +08:00
|
|
|
|
public bool IsDataReady() {
|
|
|
|
|
|
switch (mMode) {
|
|
|
|
|
|
case ToolMode.Cursor:
|
|
|
|
|
|
case ToolMode.Fill:
|
|
|
|
|
|
return (mIsStartConfirmed && mIsEndConfirmed);
|
|
|
|
|
|
case ToolMode.Overwrite:
|
|
|
|
|
|
return mIsStartConfirmed;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsDataPartialReady() {
|
|
|
|
|
|
return (mMode == ToolMode.Cursor && mIsStartConfirmed && !mIsEndConfirmed);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ToolMode GetToolMode() {
|
|
|
|
|
|
return mMode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnSelectionChanged() {
|
|
|
|
|
|
SelectionChanged?.Invoke();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|