finish basic i18n and cfg loader
This commit is contained in:
@ -40,6 +40,12 @@ namespace BallanceTASEditor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnExit(ExitEventArgs e) {
|
||||||
|
base.OnExit(e);
|
||||||
|
|
||||||
|
GlobalVariable.configManager.Save();
|
||||||
|
}
|
||||||
|
|
||||||
private void UncatchedErrorHandle(string message, string stackTrace) {
|
private void UncatchedErrorHandle(string message, string stackTrace) {
|
||||||
try {
|
try {
|
||||||
if (!Directory.Exists("./logs"))
|
if (!Directory.Exists("./logs"))
|
||||||
|
|||||||
@ -11,13 +11,13 @@ namespace BallanceTASEditor.Core {
|
|||||||
|
|
||||||
public ConfigManager(string fileName, Dictionary<string, string> defaultValue) {
|
public ConfigManager(string fileName, Dictionary<string, string> defaultValue) {
|
||||||
_fileName = fileName;
|
_fileName = fileName;
|
||||||
_defaultValue = JsonConvert.SerializeObject(defaultValue);
|
_defaultValue = defaultValue;
|
||||||
|
|
||||||
Configuration = Read();
|
Configuration = Read();
|
||||||
}
|
}
|
||||||
|
|
||||||
string _fileName;
|
string _fileName;
|
||||||
string _defaultValue;
|
Dictionary<string, string> _defaultValue;
|
||||||
public Dictionary<string, string> Configuration;
|
public Dictionary<string, string> Configuration;
|
||||||
|
|
||||||
public static readonly string CfgNode_Language = "Language";
|
public static readonly string CfgNode_Language = "Language";
|
||||||
@ -35,12 +35,20 @@ namespace BallanceTASEditor.Core {
|
|||||||
fs.Close();
|
fs.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check field to make sure each field is existed
|
||||||
|
// because version update it might be changed
|
||||||
|
foreach(var pair in _defaultValue) {
|
||||||
|
if (!data.ContainsKey(pair.Key)) {
|
||||||
|
data.Add(pair.Key, pair.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init() {
|
void Init() {
|
||||||
using (StreamWriter fs = new StreamWriter(Path.Combine(Environment.CurrentDirectory, _fileName), false, Encoding.UTF8)) {
|
using (StreamWriter fs = new StreamWriter(Path.Combine(Environment.CurrentDirectory, _fileName), false, Encoding.UTF8)) {
|
||||||
fs.Write(_defaultValue);
|
fs.Write(JsonConvert.SerializeObject(_defaultValue));
|
||||||
fs.Close();
|
fs.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,12 +16,13 @@
|
|||||||
<sys:String x:Key="ui_MainWindow_Menu_Display_Redo">重做</sys:String>
|
<sys:String x:Key="ui_MainWindow_Menu_Display_Redo">重做</sys:String>
|
||||||
<sys:String x:Key="ui_MainWindow_Menu_Display_ItemCount">项个数</sys:String>
|
<sys:String x:Key="ui_MainWindow_Menu_Display_ItemCount">项个数</sys:String>
|
||||||
<sys:String x:Key="ui_MainWindow_Menu_Display_OverwrittenPaste">覆盖式粘贴</sys:String>
|
<sys:String x:Key="ui_MainWindow_Menu_Display_OverwrittenPaste">覆盖式粘贴</sys:String>
|
||||||
|
<sys:String x:Key="ui_MainWindow_Menu_Display_HorizontalLayout">横向布局</sys:String>
|
||||||
|
|
||||||
<sys:String x:Key="ui_MainWindow_Menu_Help">帮助</sys:String>
|
<sys:String x:Key="ui_MainWindow_Menu_Help">帮助</sys:String>
|
||||||
<sys:String x:Key="ui_MainWindow_Menu_Help_ReportBugs">汇报漏洞</sys:String>
|
<sys:String x:Key="ui_MainWindow_Menu_Help_ReportBugs">汇报漏洞</sys:String>
|
||||||
<sys:String x:Key="ui_MainWindow_Menu_Help_About">关于</sys:String>
|
<sys:String x:Key="ui_MainWindow_Menu_Help_About">关于</sys:String>
|
||||||
|
|
||||||
<sys:String x:Key="ui_MainWindow_EditorNote">打开一个 TAS 文件以编辑</sys:String>
|
<sys:String x:Key="ui_MainWindow_EditorNote">打开或拖入一个 TAS 文件以编辑</sys:String>
|
||||||
|
|
||||||
<sys:String x:Key="ui_MainWindow_Tools_Cursor">选择模式</sys:String>
|
<sys:String x:Key="ui_MainWindow_Tools_Cursor">选择模式</sys:String>
|
||||||
<sys:String x:Key="ui_MainWindow_Tools_Fill">填充模式</sys:String>
|
<sys:String x:Key="ui_MainWindow_Tools_Fill">填充模式</sys:String>
|
||||||
|
|||||||
@ -16,12 +16,13 @@
|
|||||||
<sys:String x:Key="ui_MainWindow_Menu_Display_Redo">Redo</sys:String>
|
<sys:String x:Key="ui_MainWindow_Menu_Display_Redo">Redo</sys:String>
|
||||||
<sys:String x:Key="ui_MainWindow_Menu_Display_ItemCount">Item Count</sys:String>
|
<sys:String x:Key="ui_MainWindow_Menu_Display_ItemCount">Item Count</sys:String>
|
||||||
<sys:String x:Key="ui_MainWindow_Menu_Display_OverwrittenPaste">Overwritten Paste</sys:String>
|
<sys:String x:Key="ui_MainWindow_Menu_Display_OverwrittenPaste">Overwritten Paste</sys:String>
|
||||||
|
<sys:String x:Key="ui_MainWindow_Menu_Display_HorizontalLayout">Horizontal Layout</sys:String>
|
||||||
|
|
||||||
<sys:String x:Key="ui_MainWindow_Menu_Help">Help</sys:String>
|
<sys:String x:Key="ui_MainWindow_Menu_Help">Help</sys:String>
|
||||||
<sys:String x:Key="ui_MainWindow_Menu_Help_ReportBugs">Report Bugs</sys:String>
|
<sys:String x:Key="ui_MainWindow_Menu_Help_ReportBugs">Report Bugs</sys:String>
|
||||||
<sys:String x:Key="ui_MainWindow_Menu_Help_About">About</sys:String>
|
<sys:String x:Key="ui_MainWindow_Menu_Help_About">About</sys:String>
|
||||||
|
|
||||||
<sys:String x:Key="ui_MainWindow_EditorNote">Open a TAS file for editing</sys:String>
|
<sys:String x:Key="ui_MainWindow_EditorNote">Open or drop a TAS file for editing</sys:String>
|
||||||
|
|
||||||
<sys:String x:Key="ui_MainWindow_Tools_Cursor">Select mode</sys:String>
|
<sys:String x:Key="ui_MainWindow_Tools_Cursor">Select mode</sys:String>
|
||||||
<sys:String x:Key="ui_MainWindow_Tools_Fill">Fill mode</sys:String>
|
<sys:String x:Key="ui_MainWindow_Tools_Fill">Fill mode</sys:String>
|
||||||
|
|||||||
@ -62,9 +62,11 @@
|
|||||||
<MenuItem Header="{DynamicResource ui_MainWindow_Menu_Display}">
|
<MenuItem Header="{DynamicResource ui_MainWindow_Menu_Display}">
|
||||||
<MenuItem x:Name="uiMenu_Display_Undo" Header="{DynamicResource ui_MainWindow_Menu_Display_Undo}" Click="funcMenu_Display_Undo" InputGestureText="Ctrl + Z"/>
|
<MenuItem x:Name="uiMenu_Display_Undo" Header="{DynamicResource ui_MainWindow_Menu_Display_Undo}" Click="funcMenu_Display_Undo" InputGestureText="Ctrl + Z"/>
|
||||||
<MenuItem x:Name="uiMenu_Display_Redo" Header="{DynamicResource ui_MainWindow_Menu_Display_Redo}" Click="funcMenu_Display_Redo" InputGestureText="Ctrl + Y"/>
|
<MenuItem x:Name="uiMenu_Display_Redo" Header="{DynamicResource ui_MainWindow_Menu_Display_Redo}" Click="funcMenu_Display_Redo" InputGestureText="Ctrl + Y"/>
|
||||||
|
<Separator/>
|
||||||
<MenuItem x:Name="uiMenu_Display_ItemCount" Header="{DynamicResource ui_MainWindow_Menu_Display_ItemCount}" Click="funcMenu_Display_ItemCount"/>
|
<MenuItem x:Name="uiMenu_Display_ItemCount" Header="{DynamicResource ui_MainWindow_Menu_Display_ItemCount}" Click="funcMenu_Display_ItemCount"/>
|
||||||
<MenuItem x:Name="uiMenu_Display_OverwrittenPaste" Header="{DynamicResource ui_MainWindow_Menu_Display_OverwrittenPaste}" IsCheckable="True" Checked="funcMenu_Display_OverwrittenPaste" Unchecked="funcMenu_Display_OverwrittenPaste"/>
|
<Separator/>
|
||||||
<MenuItem x:Name="uiMenu_Display_HorizontalLayout" Header="???" IsCheckable="True"/>
|
<MenuItem x:Name="uiMenu_Display_OverwrittenPaste" Header="{DynamicResource ui_MainWindow_Menu_Display_OverwrittenPaste}" Click="funcMenu_Display_OverwrittenPaste"/>
|
||||||
|
<MenuItem x:Name="uiMenu_Display_HorizontalLayout" Header="{DynamicResource ui_MainWindow_Menu_Display_HorizontalLayout}" Click="funcMenu_Display_HorizontalLayout"/>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="{DynamicResource ui_MainWindow_Menu_Help}">
|
<MenuItem Header="{DynamicResource ui_MainWindow_Menu_Help}">
|
||||||
<MenuItem x:Name="uiMenu_Help_ReportBugs" Header="{DynamicResource ui_MainWindow_Menu_Help_ReportBugs}" Click="funcMenu_Help_ReportBugs"/>
|
<MenuItem x:Name="uiMenu_Help_ReportBugs" Header="{DynamicResource ui_MainWindow_Menu_Help_ReportBugs}" Click="funcMenu_Help_ReportBugs"/>
|
||||||
|
|||||||
@ -22,9 +22,12 @@ namespace BallanceTASEditor {
|
|||||||
public partial class MainWindow : Window {
|
public partial class MainWindow : Window {
|
||||||
public MainWindow() {
|
public MainWindow() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
RefreshUI(false);
|
|
||||||
mFlow = new TASFlow(uiTASData);
|
mFlow = new TASFlow(uiTASData);
|
||||||
mSlider = new TASSlider(uiTASSlider);
|
mSlider = new TASSlider(uiTASSlider);
|
||||||
|
|
||||||
|
RefreshUI(false);
|
||||||
|
ApplyConfigureManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
TASFile mFile;
|
TASFile mFile;
|
||||||
@ -96,16 +99,24 @@ namespace BallanceTASEditor {
|
|||||||
private void funcMenu_Display_ItemCount(object sender, RoutedEventArgs e) {
|
private void funcMenu_Display_ItemCount(object sender, RoutedEventArgs e) {
|
||||||
int newvalue = 0;
|
int newvalue = 0;
|
||||||
if (DialogUtil.InputNumber("Input new count (>=5 && <=30)", 5, 30, ref newvalue)) {
|
if (DialogUtil.InputNumber("Input new count (>=5 && <=30)", 5, 30, ref newvalue)) {
|
||||||
mViewer.ChangeListLength(newvalue);
|
ChangeItemCount(newvalue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void funcMenu_Display_OverwrittenPaste(object sender, RoutedEventArgs e) {
|
private void funcMenu_Display_OverwrittenPaste(object sender, RoutedEventArgs e) {
|
||||||
//uiMenu_Display_OverwrittenPaste.IsChecked = !uiMenu_Display_OverwrittenPaste.IsChecked;
|
uiMenu_Display_OverwrittenPaste.IsChecked = !uiMenu_Display_OverwrittenPaste.IsChecked;
|
||||||
|
|
||||||
|
GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_IsOverwrittenPaste] = uiMenu_Display_OverwrittenPaste.IsChecked.ToString();
|
||||||
if (mViewer != null)
|
if (mViewer != null)
|
||||||
mViewer.ChangeOverwrittenMode(uiMenu_Display_OverwrittenPaste.IsChecked);
|
mViewer.ChangeOverwrittenMode(uiMenu_Display_OverwrittenPaste.IsChecked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void funcMenu_Display_HorizontalLayout(object sender, RoutedEventArgs e) {
|
||||||
|
uiMenu_Display_HorizontalLayout.IsChecked = !uiMenu_Display_HorizontalLayout.IsChecked;
|
||||||
|
GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_IsHorizonLayout] = uiMenu_Display_HorizontalLayout.IsChecked.ToString();
|
||||||
|
ChangeLayout(uiMenu_Display_HorizontalLayout.IsChecked);
|
||||||
|
}
|
||||||
|
|
||||||
private void funcMenu_Display_Redo(object sender, RoutedEventArgs e) {
|
private void funcMenu_Display_Redo(object sender, RoutedEventArgs e) {
|
||||||
mViewer.ProcessOperation(OperationEnum.Redo);
|
mViewer.ProcessOperation(OperationEnum.Redo);
|
||||||
}
|
}
|
||||||
@ -227,7 +238,7 @@ namespace BallanceTASEditor {
|
|||||||
} else if (KeyboardState.IsKeyPressed(KeyboardState.VirtualKeyStates.VK_CONTROL)) {
|
} else if (KeyboardState.IsKeyPressed(KeyboardState.VirtualKeyStates.VK_CONTROL)) {
|
||||||
// decrease item count
|
// decrease item count
|
||||||
var newvalue = mViewer.GetItemCountInPage();
|
var newvalue = mViewer.GetItemCountInPage();
|
||||||
mViewer.ChangeListLength(newvalue - 1);
|
ChangeItemCount(newvalue - 1);
|
||||||
} else {
|
} else {
|
||||||
// normally move
|
// normally move
|
||||||
mSlider.MoveSliderManually(true, false, mViewer.GetItemCountInPage());
|
mSlider.MoveSliderManually(true, false, mViewer.GetItemCountInPage());
|
||||||
@ -241,7 +252,7 @@ namespace BallanceTASEditor {
|
|||||||
} else if (KeyboardState.IsKeyPressed(KeyboardState.VirtualKeyStates.VK_CONTROL)) {
|
} else if (KeyboardState.IsKeyPressed(KeyboardState.VirtualKeyStates.VK_CONTROL)) {
|
||||||
// increase item count
|
// increase item count
|
||||||
var newvalue = mViewer.GetItemCountInPage();
|
var newvalue = mViewer.GetItemCountInPage();
|
||||||
mViewer.ChangeListLength(newvalue + 1);
|
ChangeItemCount(newvalue + 1);
|
||||||
} else {
|
} else {
|
||||||
// normally move
|
// normally move
|
||||||
mSlider.MoveSliderManually(false, false, mViewer.GetItemCountInPage());
|
mSlider.MoveSliderManually(false, false, mViewer.GetItemCountInPage());
|
||||||
@ -265,9 +276,22 @@ namespace BallanceTASEditor {
|
|||||||
else e.Effects = DragDropEffects.None;
|
else e.Effects = DragDropEffects.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private void ApplyConfigureManager() {
|
||||||
|
var isOverwrittenPaste = bool.Parse(GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_IsOverwrittenPaste]);
|
||||||
|
var isHorizontalLayout = bool.Parse(GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_IsHorizonLayout]);
|
||||||
|
var itemCount = int.Parse(GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_ItemCount]);
|
||||||
|
|
||||||
|
uiMenu_Display_OverwrittenPaste.IsChecked = isOverwrittenPaste;
|
||||||
|
uiMenu_Display_HorizontalLayout.IsChecked = isHorizontalLayout;
|
||||||
|
if (mViewer != null) {
|
||||||
|
mViewer.ChangeOverwrittenMode(isOverwrittenPaste);
|
||||||
|
mViewer.ChangeListLength(itemCount);
|
||||||
|
ChangeLayout(isHorizontalLayout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OpenFile(string file) {
|
private void OpenFile(string file) {
|
||||||
try {
|
try {
|
||||||
mFile = new TASFile(file);
|
mFile = new TASFile(file);
|
||||||
@ -284,9 +308,8 @@ namespace BallanceTASEditor {
|
|||||||
mViewer.UpdateToolMode += RefreshToolMode;
|
mViewer.UpdateToolMode += RefreshToolMode;
|
||||||
|
|
||||||
RefreshUI(true);
|
RefreshUI(true);
|
||||||
|
ApplyConfigureManager(); // apply item count and overwritten item
|
||||||
mViewer.ChangeToolMode(ToolMode.Cursor);
|
mViewer.ChangeToolMode(ToolMode.Cursor);
|
||||||
mViewer.ChangeOverwrittenMode(uiMenu_Display_OverwrittenPaste.IsChecked);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshToolMode(ToolMode mode) {
|
private void RefreshToolMode(ToolMode mode) {
|
||||||
@ -333,6 +356,7 @@ namespace BallanceTASEditor {
|
|||||||
|
|
||||||
uiMenu_Display_ItemCount.IsEnabled = true;
|
uiMenu_Display_ItemCount.IsEnabled = true;
|
||||||
uiMenu_Display_OverwrittenPaste.IsEnabled = true;
|
uiMenu_Display_OverwrittenPaste.IsEnabled = true;
|
||||||
|
uiMenu_Display_HorizontalLayout.IsEnabled = true;
|
||||||
uiMenu_Display_Undo.IsEnabled = true;
|
uiMenu_Display_Undo.IsEnabled = true;
|
||||||
uiMenu_Display_Redo.IsEnabled = true;
|
uiMenu_Display_Redo.IsEnabled = true;
|
||||||
|
|
||||||
@ -348,6 +372,7 @@ namespace BallanceTASEditor {
|
|||||||
|
|
||||||
uiMenu_Display_ItemCount.IsEnabled = false;
|
uiMenu_Display_ItemCount.IsEnabled = false;
|
||||||
uiMenu_Display_OverwrittenPaste.IsEnabled = false;
|
uiMenu_Display_OverwrittenPaste.IsEnabled = false;
|
||||||
|
uiMenu_Display_HorizontalLayout.IsEnabled = false;
|
||||||
uiMenu_Display_Undo.IsEnabled = false;
|
uiMenu_Display_Undo.IsEnabled = false;
|
||||||
uiMenu_Display_Redo.IsEnabled = false;
|
uiMenu_Display_Redo.IsEnabled = false;
|
||||||
|
|
||||||
@ -397,5 +422,15 @@ namespace BallanceTASEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ChangeItemCount(int count) {
|
||||||
|
GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_ItemCount] = count.ToString();
|
||||||
|
mViewer.ChangeListLength(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ChangeLayout(bool isHorizontal) {
|
||||||
|
mFlow.ChangeLayout(isHorizontal);
|
||||||
|
// todo: add more change
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,11 +21,13 @@ namespace BallanceTASEditor.UI {
|
|||||||
mItemList = new List<TASFlowUIItem>();
|
mItemList = new List<TASFlowUIItem>();
|
||||||
mRectMap = new Dictionary<Rectangle, CellPosition>();
|
mRectMap = new Dictionary<Rectangle, CellPosition>();
|
||||||
mItemCount = 0;
|
mItemCount = 0;
|
||||||
|
mIsHorizontalLayout = true;
|
||||||
SetItemCount(1);
|
SetItemCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event Action Click;
|
public event Action Click;
|
||||||
|
|
||||||
|
private bool mIsHorizontalLayout;
|
||||||
private Grid uiCoreWindow;
|
private Grid uiCoreWindow;
|
||||||
private int mItemCount;
|
private int mItemCount;
|
||||||
private List<TASFlowUIItem> mItemList;
|
private List<TASFlowUIItem> mItemList;
|
||||||
@ -33,6 +35,13 @@ namespace BallanceTASEditor.UI {
|
|||||||
public SelectionHelp SelectionHelp { get; set; }
|
public SelectionHelp SelectionHelp { get; set; }
|
||||||
public List<FrameDataDisplay> DataSources { get; set; }
|
public List<FrameDataDisplay> DataSources { get; set; }
|
||||||
|
|
||||||
|
public void ChangeLayout(bool isHorizontal) {
|
||||||
|
// the layout changed, re-construct elements
|
||||||
|
if (isHorizontal != mIsHorizontalLayout) {
|
||||||
|
// todo: change layout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void RefreshDataSources() {
|
public void RefreshDataSources() {
|
||||||
if (DataSources == null) return;
|
if (DataSources == null) return;
|
||||||
|
|
||||||
@ -135,6 +144,14 @@ namespace BallanceTASEditor.UI {
|
|||||||
} else {
|
} else {
|
||||||
SelectionHelp.FirstClick(mItemList[pos.column - 1].rawFrame, pos.field);
|
SelectionHelp.FirstClick(mItemList[pos.column - 1].rawFrame, pos.field);
|
||||||
}
|
}
|
||||||
|
} else if (e.MouseDevice.RightButton == MouseButtonState.Pressed) {
|
||||||
|
// if we click right button and there are no full selection in cursor mode
|
||||||
|
// try to add a first selection
|
||||||
|
if (SelectionHelp.GetToolMode() == ToolMode.Cursor) {
|
||||||
|
if (!SelectionHelp.IsDataReady()) {
|
||||||
|
SelectionHelp.FirstClick(mItemList[pos.column - 1].rawFrame, pos.field);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// note main window to process it.
|
// note main window to process it.
|
||||||
|
|||||||
@ -34,9 +34,6 @@ namespace BallanceTASEditor.UI {
|
|||||||
|
|
||||||
mDataGrid.Click += funcDataMenu_Click;
|
mDataGrid.Click += funcDataMenu_Click;
|
||||||
mSlider.ValueChanged += funcSlider_ValueChanged;
|
mSlider.ValueChanged += funcSlider_ValueChanged;
|
||||||
|
|
||||||
// display data
|
|
||||||
ChangeListLength(int.Parse(GlobalVariable.configManager.Configuration[ConfigManager.CfgNode_ItemCount]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
|
|||||||
Reference in New Issue
Block a user