From 3947234fc8757b139816afe688b00b5ea08c3f8c Mon Sep 17 00:00:00 2001
From: yhh <359807859@qq.com>
Date: Thu, 25 Jul 2019 16:07:35 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE=E5=BA=93?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CLEditor/CLEngine.Editor.csproj | 7 +
CLEditor/viewmodel/DataBaseViewModel.cs | 196 +++++++++++++++++-
CLEditor/windows/CustomPropWindow.xaml | 3 +-
CLEditor/windows/DataBaseWindow.xaml | 82 +++++---
CLEditor/windows/SelectScriptWindow.xaml | 18 ++
CLEditor/windows/SelectScriptWindow.xaml.cs | 26 +++
.../framework/FrameworkSettings.cs | 9 +
Engine/CLEngine.Core/framework/ItemObject.cs | 1 +
8 files changed, 304 insertions(+), 38 deletions(-)
create mode 100644 CLEditor/windows/SelectScriptWindow.xaml
create mode 100644 CLEditor/windows/SelectScriptWindow.xaml.cs
diff --git a/CLEditor/CLEngine.Editor.csproj b/CLEditor/CLEngine.Editor.csproj
index e8ce653..e26fbdd 100644
--- a/CLEditor/CLEngine.Editor.csproj
+++ b/CLEditor/CLEngine.Editor.csproj
@@ -483,6 +483,9 @@
ScriptingEditorWindow.xaml
+
+ SelectScriptWindow.xaml
+
SettingsWindow.xaml
@@ -612,6 +615,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
diff --git a/CLEditor/viewmodel/DataBaseViewModel.cs b/CLEditor/viewmodel/DataBaseViewModel.cs
index 15399e2..be84a77 100644
--- a/CLEditor/viewmodel/DataBaseViewModel.cs
+++ b/CLEditor/viewmodel/DataBaseViewModel.cs
@@ -10,6 +10,7 @@ using CLEngine.Core.framework;
using CLEngine.Editor.windows;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
+using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using MessageBox = System.Windows.Forms.MessageBox;
namespace CLEngine.Editor.viewmodel
@@ -45,6 +46,14 @@ namespace CLEngine.Editor.viewmodel
get { return FrameworkSettings.ItemTypes.Keys.ToList(); }
}
+ ///
+ /// 脚本分类
+ ///
+ public List ScriptTypes
+ {
+ get { return FrameworkSettings.ScriptTypes.ToList(); }
+ }
+
///
/// 物品子类
///
@@ -73,9 +82,25 @@ namespace CLEngine.Editor.viewmodel
/// 创建脚本按钮
///
public RelayCommand CreateScriptCommand { get; set; }
+ ///
+ /// 脚本选择按钮
+ ///
+ public RelayCommand ScriptSelectCommand { get; set; }
+ ///
+ /// 确认脚本选择
+ ///
+ public RelayCommand ConfirmScriptSelectCommand { get; set; }
+ ///
+ /// 移除脚本
+ ///
+ public RelayCommand RemoveScriptCommand { get; set; }
+ public RelayCommand UpScriptCommand { get; set; }
+ public RelayCommand DownScriptCommand { get; set; }
private string _iconPath;
-
+ ///
+ /// 背包图标路径
+ ///
public string IconPath
{
get { return _iconPath; }
@@ -87,7 +112,9 @@ namespace CLEngine.Editor.viewmodel
}
private string _dropIconPath;
-
+ ///
+ /// 掉落图标路径
+ ///
public string DropIconPath
{
get { return _dropIconPath; }
@@ -98,19 +125,182 @@ namespace CLEngine.Editor.viewmodel
}
}
+ private string _scriptType;
+ ///
+ /// 脚本类型
+ ///
+ public string ScriptType
+ {
+ get { return _scriptType; }
+ set
+ {
+ _scriptType = value;
+ RaisePropertyChanged(() => ScriptType);
+ }
+ }
+
+ public ObservableCollection CanSelectScriptCollection { get; set; }
+
+ private string _selectScript;
+ public string SelectScript
+ {
+ get { return _selectScript;}
+ set
+ {
+ _selectScript = value;
+ RaisePropertyChanged(() => SelectScript);
+ }
+ }
+
public DataBaseViewModel()
{
ItemObjects = GetItemObjects();
AddItemCommand = new RelayCommand(AddItemAction);
ItemChildTypes = new ObservableCollection();
+ CanSelectScriptCollection = new ObservableCollection();
// 我们需要数据通知子类发生变化
- ItemChildTypes.CollectionChanged += (sender, args) => { RaisePropertyChanged(() => ItemChildTypes); };
+ ItemChildTypes.CollectionChanged += (sender, args) => { RaisePropertyChanged(() => ItemChildTypes); };
BagBrowserCommand = new RelayCommand(BagBrowserAction);
DropBrowserCommand = new RelayCommand(DropBrowserAction);
SaveCommand = new RelayCommand(SaveAction);
RemoveItemCommand = new RelayCommand(RemoveItemAction);
CreateScriptCommand = new RelayCommand(CreateScriptAction);
+ ScriptSelectCommand = new RelayCommand(ScriptSelectAction);
+ ConfirmScriptSelectCommand = new RelayCommand(ConfirmScriptSelectAction);
+ RemoveScriptCommand = new RelayCommand(RemoveScriptAction);
+ UpScriptCommand = new RelayCommand(UpScriptAction);
+ DownScriptCommand = new RelayCommand(DownScriptAction);
+
+ ScriptType = "CSharp";
+ }
+
+ private void DownScriptAction()
+ {
+ if (DataBaseWindow.Instance.ScriptListBox.SelectedValue == null)
+ {
+ Logger.Error("请先选择一个脚本!");
+ return;
+ }
+
+ if (DataBaseWindow.Instance.ItemList.SelectedValue is ItemObject item)
+ {
+ var selectItem = DataBaseWindow.Instance.ScriptListBox.SelectedValue.ToString();
+ var index = item.ScriptList.IndexOf(selectItem);
+ item.ScriptList.Remove(selectItem);
+ item.ScriptList.Insert(index + 1 > item.ScriptList.Count ? item.ScriptList.Count : index + 1, selectItem);
+
+ // 刷新列表
+ DataBaseWindow.Instance.ScriptListBox.ItemsSource = null;
+ DataBaseWindow.Instance.ScriptListBox.ItemsSource = item.ScriptList;
+ }
+ }
+
+ private void UpScriptAction()
+ {
+ if (DataBaseWindow.Instance.ScriptListBox.SelectedValue == null)
+ {
+ Logger.Error("请先选择一个脚本!");
+ return;
+ }
+
+ if (DataBaseWindow.Instance.ItemList.SelectedValue is ItemObject item)
+ {
+ var selectItem = DataBaseWindow.Instance.ScriptListBox.SelectedValue.ToString();
+ var index = item.ScriptList.IndexOf(selectItem);
+ item.ScriptList.Remove(selectItem);
+ item.ScriptList.Insert(index - 1 < 0 ? 0 : index - 1, selectItem);
+
+ // 刷新列表
+ DataBaseWindow.Instance.ScriptListBox.ItemsSource = null;
+ DataBaseWindow.Instance.ScriptListBox.ItemsSource = item.ScriptList;
+ }
+ }
+
+ private void RemoveScriptAction()
+ {
+ if (DataBaseWindow.Instance.ScriptListBox.SelectedValue == null)
+ {
+ Logger.Error("请先选择一个脚本!");
+ return;
+ }
+
+ if (DataBaseWindow.Instance.ItemList.SelectedValue is ItemObject item)
+ {
+ var selectItem = DataBaseWindow.Instance.ScriptListBox.SelectedValue.ToString();
+ item.ScriptList.Remove(selectItem);
+
+ // 刷新列表
+ DataBaseWindow.Instance.ScriptListBox.ItemsSource = null;
+ DataBaseWindow.Instance.ScriptListBox.ItemsSource = item.ScriptList;
+ }
+ }
+
+ private void ConfirmScriptSelectAction()
+ {
+ if (string.IsNullOrEmpty(SelectScript))
+ {
+ Logger.Error("必须先选择一个脚本后才能确定!");
+ return;
+ }
+
+ if (DataBaseWindow.Instance.ItemList.SelectedValue == null)
+ {
+ Logger.Error("清先选择一个物品后再选择脚本!");
+ return;
+ }
+
+ if (DataBaseWindow.Instance.ItemList.SelectedValue is ItemObject item)
+ {
+ // 兼容4.0.3.8之前版本
+ if (item.ScriptList == null)
+ item.ScriptList = new List();
+
+ if (!item.ScriptList.Contains(SelectScript))
+ item.ScriptList.Add(SelectScript);
+ else
+ Logger.Warn("您已添加该脚本,已自动忽略该脚本");
+
+ // 刷新列表
+ DataBaseWindow.Instance.ScriptListBox.ItemsSource = null;
+ DataBaseWindow.Instance.ScriptListBox.ItemsSource = item.ScriptList;
+ }
+
+ SelectScriptWindow.Instance.Close();
+ }
+
+ private void ScriptSelectAction()
+ {
+ // 先设置内容再打开
+ SetScriptContent();
+
+ var scriptSelect = new SelectScriptWindow();
+ scriptSelect.ShowDialog();
+ }
+
+ ///
+ /// 设置脚本内容
+ ///
+ public void SetScriptContent()
+ {
+ string[] files = {};
+ if (ScriptType == "CSharp")
+ {
+ files = Directory.GetFiles(SceneManager.GameProject.ProjectPath, "*.cs", SearchOption.AllDirectories);
+ }
+ else if (ScriptType == "Lua")
+ {
+ files = Directory.GetFiles(SceneManager.GameProject.ProjectPath, "*.lua", SearchOption.AllDirectories);
+ }
+
+ CanSelectScriptCollection.Clear();
+
+ foreach (var file in files)
+ {
+ CanSelectScriptCollection.Add(file);
+ }
+
+ RaisePropertyChanged(() => CanSelectScriptCollection);
}
private void RemoveItemAction()
diff --git a/CLEditor/windows/CustomPropWindow.xaml b/CLEditor/windows/CustomPropWindow.xaml
index e2eaf75..49e1f98 100644
--- a/CLEditor/windows/CustomPropWindow.xaml
+++ b/CLEditor/windows/CustomPropWindow.xaml
@@ -3,8 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:CLEngine.Editor.windows"
- xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:controls="clr-namespace:CLEngine.Editor.controls" x:Class="CLEngine.Editor.windows.CustomPropWindow"
+ xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" x:Class="CLEngine.Editor.windows.CustomPropWindow"
mc:Ignorable="d" Background="{DynamicResource PanelBackground}"
Title="自定义" Height="600" Width="400">
diff --git a/CLEditor/windows/DataBaseWindow.xaml b/CLEditor/windows/DataBaseWindow.xaml
index a88d79e..24e8aba 100644
--- a/CLEditor/windows/DataBaseWindow.xaml
+++ b/CLEditor/windows/DataBaseWindow.xaml
@@ -3,15 +3,13 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:CLEngine.Editor.windows"
- xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:Options="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
+ xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:controls="clr-namespace:CLEngine.Editor.controls"
xmlns:framework="clr-namespace:CLEngine.Core.framework;assembly=CLEngine.Core"
- xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
xmlns:converts="clr-namespace:CLEngine.Editor.core.converts"
x:Class="CLEngine.Editor.windows.DataBaseWindow"
mc:Ignorable="d" DataContext="{Binding DataBase, Source={StaticResource Locator}}"
- Title="游戏数据库" Height="800" Width="1366" Background="{DynamicResource PanelBackground}">
+ Title="游戏数据库" Height="800" Width="1366" Background="{DynamicResource PanelBackground}" ResizeMode="NoResize" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen">
@@ -49,22 +47,31 @@
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -80,22 +87,28 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -103,11 +116,14 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/CLEditor/windows/SelectScriptWindow.xaml b/CLEditor/windows/SelectScriptWindow.xaml
new file mode 100644
index 0000000..d1122b9
--- /dev/null
+++ b/CLEditor/windows/SelectScriptWindow.xaml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
diff --git a/CLEditor/windows/SelectScriptWindow.xaml.cs b/CLEditor/windows/SelectScriptWindow.xaml.cs
new file mode 100644
index 0000000..78af43a
--- /dev/null
+++ b/CLEditor/windows/SelectScriptWindow.xaml.cs
@@ -0,0 +1,26 @@
+using System.Windows;
+using System.Windows.Controls;
+using CLEngine.Editor.viewmodel;
+
+namespace CLEngine.Editor.windows
+{
+ ///
+ /// SelectScriptWindow.xaml 的交互逻辑
+ ///
+ public partial class SelectScriptWindow : Window
+ {
+ public static SelectScriptWindow Instance;
+
+ public SelectScriptWindow()
+ {
+ InitializeComponent();
+ Instance = this;
+ ScriptTypeBox.SelectionChanged += ScriptTypeBoxOnSelectionChanged;
+ }
+
+ private void ScriptTypeBoxOnSelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ (DataContext as DataBaseViewModel)?.SetScriptContent();
+ }
+ }
+}
diff --git a/Engine/CLEngine.Core/framework/FrameworkSettings.cs b/Engine/CLEngine.Core/framework/FrameworkSettings.cs
index 3a6db8c..31f8494 100644
--- a/Engine/CLEngine.Core/framework/FrameworkSettings.cs
+++ b/Engine/CLEngine.Core/framework/FrameworkSettings.cs
@@ -48,6 +48,15 @@ namespace CLEngine.Core.framework
"女"
};
+ ///
+ /// 脚本列表
+ ///
+ public static List ScriptTypes = new List()
+ {
+ "CSharp",
+ "Lua",
+ };
+
///
/// 职业列表
///
diff --git a/Engine/CLEngine.Core/framework/ItemObject.cs b/Engine/CLEngine.Core/framework/ItemObject.cs
index f7ec76a..c3905f7 100644
--- a/Engine/CLEngine.Core/framework/ItemObject.cs
+++ b/Engine/CLEngine.Core/framework/ItemObject.cs
@@ -388,6 +388,7 @@ namespace CLEngine.Core.framework
/// 物品名称
public ItemObject(string name = "")
{
+ ScriptList = new List();
BagPosition = Vector2.Zero;
Name = name;
}
--
Gitee