From 35145a5fd3af70ed9e8497e89fc8610f4b496add Mon Sep 17 00:00:00 2001
From: yhh <359807859@qq.com>
Date: Wed, 17 Jul 2019 18:02:14 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E9=93=BE=E6=8E=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CLEditor/CLEngine.Editor.csproj | 2 +-
CLEditor/core/CommandBindings.cs | 10 --
CLEditor/core/converts/EditorImageConvert.cs | 32 +++++
CLEditor/viewmodel/DataBaseViewModel.cs | 124 +++++++++++++++++-
CLEditor/windows/DataBaseWindow.xaml | 20 ++-
CLEditor/windows/DataBaseWindow.xaml.cs | 33 ++---
Engine/CLEngine.Core/CLEngine.Core.csproj | 3 +
.../framework/FrameworkManager.cs | 73 ++++++++++-
.../framework/FrameworkSettings.cs | 20 +--
Engine/CLEngine.Core/framework/ItemManager.cs | 31 +----
Engine/CLEngine.Core/framework/ItemObject.cs | 5 +-
.../CLEngine.Core/framework/SkillManager.cs | 30 +----
12 files changed, 276 insertions(+), 107 deletions(-)
delete mode 100644 CLEditor/core/CommandBindings.cs
create mode 100644 CLEditor/core/converts/EditorImageConvert.cs
diff --git a/CLEditor/CLEngine.Editor.csproj b/CLEditor/CLEngine.Editor.csproj
index 39785dd..850384b 100644
--- a/CLEditor/CLEngine.Editor.csproj
+++ b/CLEditor/CLEngine.Editor.csproj
@@ -253,7 +253,7 @@
VisualScriptingNode.xaml
-
+
diff --git a/CLEditor/core/CommandBindings.cs b/CLEditor/core/CommandBindings.cs
deleted file mode 100644
index 76f8700..0000000
--- a/CLEditor/core/CommandBindings.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using System.Windows.Input;
-
-namespace CLEngine.Editor.core
-{
- public static class CommandBindings
- {
- public static readonly RoutedUICommand FullDebug = new RoutedUICommand("完整调试", "FullDebug", typeof(MainWindow));
- public static readonly RoutedUICommand ToCollisionBlock = new RoutedUICommand("碰撞阻挡", "ToCollisionBlock", typeof(MainWindow));
- }
-}
\ No newline at end of file
diff --git a/CLEditor/core/converts/EditorImageConvert.cs b/CLEditor/core/converts/EditorImageConvert.cs
new file mode 100644
index 0000000..655bfe8
--- /dev/null
+++ b/CLEditor/core/converts/EditorImageConvert.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Globalization;
+using System.IO;
+using System.Windows.Data;
+using System.Windows.Media.Imaging;
+using CLEngine.Core;
+
+namespace CLEngine.Editor.core.converts
+{
+ ///
+ /// 编辑器内路径转图片
+ ///
+ public class EditorImageConvert : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is string path)
+ {
+ // 先转绝对路径
+ var relativePath = Path.Combine(SceneManager.GameProject.ProjectPath, path);
+ return new BitmapImage(new Uri(relativePath, UriKind.RelativeOrAbsolute));
+ }
+
+ return null;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
\ No newline at end of file
diff --git a/CLEditor/viewmodel/DataBaseViewModel.cs b/CLEditor/viewmodel/DataBaseViewModel.cs
index e5b6b87..f5591e1 100644
--- a/CLEditor/viewmodel/DataBaseViewModel.cs
+++ b/CLEditor/viewmodel/DataBaseViewModel.cs
@@ -1,8 +1,14 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Linq;
+using System.Windows.Forms;
+using CLEngine.Core;
using CLEngine.Core.framework;
+using CLEngine.Editor.windows;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
+using MessageBox = System.Windows.Forms.MessageBox;
namespace CLEngine.Editor.viewmodel
{
@@ -25,6 +31,19 @@ namespace CLEngine.Editor.viewmodel
public List GenderTypes {
get { return FrameworkSettings.GenderTypes; }
}
+ ///
+ /// 物品分类
+ ///
+ public List ItemTypes
+ {
+ get { return FrameworkSettings.ItemTypes.Keys.ToList(); }
+ }
+
+ ///
+ /// 物品子类
+ ///
+ public ObservableCollection ItemChildTypes { get; set; }
+
///
/// 职业列表
///
@@ -32,10 +51,113 @@ namespace CLEngine.Editor.viewmodel
get { return FrameworkSettings.OccupationTypes; }
}
+ ///
+ /// 背包图标浏览
+ ///
+ public RelayCommand BagBrowserCommand { get; set; }
+ ///
+ /// 掉落图标浏览
+ ///
+ public RelayCommand DropBrowserCommand { get; set; }
+ ///
+ /// 保存数据按钮
+ ///
+ public RelayCommand SaveCommand { get; set; }
+
public DataBaseViewModel()
{
ItemObjects = new ObservableCollection();
AddItemCommand = new RelayCommand(AddItemAction);
+ ItemChildTypes = new ObservableCollection();
+ // 我们需要数据通知子类发生变化
+ ItemChildTypes.CollectionChanged += (sender, args) => { RaisePropertyChanged(() => ItemChildTypes); };
+
+ BagBrowserCommand = new RelayCommand(BagBrowserAction);
+ DropBrowserCommand = new RelayCommand(DropBrowserAction);
+ SaveCommand = new RelayCommand(SaveAction);
+ }
+
+ private void SaveAction()
+ {
+ FrameworkManager.SaveData("item");
+ }
+
+ private void DropBrowserAction()
+ {
+ Logger.Error("还未支持");
+ //var fileSelectDialog = new OpenFileDialog();
+ //var itemObject = (ItemObject)DataBaseWindow.ItemListInstance.SelectedItem;
+ }
+
+ private void BagBrowserAction()
+ {
+ var fileSelectDialog = new OpenFileDialog();
+ var itemObject = (ItemObject)DataBaseWindow.ItemListInstance.SelectedItem;
+ if (itemObject != null)
+ {
+ itemObject.IconPath = ProcessDialog(fileSelectDialog, "Icon\\");
+ RaisePropertyChanged(() => itemObject.IconPath);
+ }
+ }
+
+ private string ProcessDialog(OpenFileDialog ofd, string specificFolder = "")
+ {
+ var result = ofd.ShowDialog();
+ if (result == DialogResult.OK || result == DialogResult.Yes)
+ {
+ string destFolder = (SceneManager.GameProject.ProjectPath + "\\Content\\" + specificFolder).Trim();
+ string filename = System.IO.Path.GetFileName(ofd.FileName);
+
+ bool fileOnDirectory = ofd.FileName.StartsWith(SceneManager.GameProject.ProjectPath);
+
+ if (!System.IO.Directory.Exists(destFolder) && !fileOnDirectory)
+ System.IO.Directory.CreateDirectory(destFolder);
+
+ if (!System.IO.File.Exists(destFolder + filename) || fileOnDirectory)
+ return this.SetNewPath(ofd.FileName, destFolder, specificFolder, filename);
+
+ var overwriteResult = MessageBox.Show("带有名称的文件 " + filename + " 已经存在。 你想覆盖它吗?", "警告", MessageBoxButtons.YesNoCancel);
+ if (overwriteResult == DialogResult.Yes)
+ return this.SetNewPath(ofd.FileName, destFolder, specificFolder, filename, true);
+ }
+
+ return null;
+ }
+
+ private string SetNewPath(string srcPath, string destFolder, string specificFolder, string filename, bool overwrite = false)
+ {
+ try
+ {
+ bool fileOnDirectory = srcPath.StartsWith(SceneManager.GameProject.ProjectPath);
+
+ if (!fileOnDirectory)
+ System.IO.File.Copy(srcPath, destFolder + filename, overwrite);
+
+ string relativePath = (@"\Content\" + specificFolder + filename).Trim();
+ if (fileOnDirectory)
+ relativePath = srcPath.Replace(SceneManager.GameProject.ProjectPath, string.Empty);
+
+ if (relativePath.StartsWith("\\"))
+ relativePath = relativePath.Substring(1, relativePath.Length - 1);
+
+ return relativePath;
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message);
+ return null;
+ }
+ }
+
+ ///
+ /// 清除子类数据并重新赋值
+ ///
+ ///
+ public void ClearItemChildTypes(object value)
+ {
+ ItemChildTypes.Clear();
+ foreach (var itemType in FrameworkSettings.ItemTypes[value.ToString()])
+ ItemChildTypes.Add(itemType);
}
private void AddItemAction()
diff --git a/CLEditor/windows/DataBaseWindow.xaml b/CLEditor/windows/DataBaseWindow.xaml
index 8e91539..fd3e467 100644
--- a/CLEditor/windows/DataBaseWindow.xaml
+++ b/CLEditor/windows/DataBaseWindow.xaml
@@ -8,9 +8,15 @@
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}">
+
+
+
+
+
@@ -22,13 +28,13 @@
-
+
-
+
-
+
@@ -39,9 +45,9 @@
-
-
-
+
+
+
@@ -91,7 +97,7 @@
-
+
diff --git a/CLEditor/windows/DataBaseWindow.xaml.cs b/CLEditor/windows/DataBaseWindow.xaml.cs
index 7206cae..e4670c2 100644
--- a/CLEditor/windows/DataBaseWindow.xaml.cs
+++ b/CLEditor/windows/DataBaseWindow.xaml.cs
@@ -1,17 +1,6 @@
-using CLEngine.Core;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
+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.Shapes;
+using CLEngine.Editor.viewmodel;
namespace CLEngine.Editor.windows
{
@@ -20,10 +9,24 @@ namespace CLEngine.Editor.windows
///
public partial class DataBaseWindow : Window
{
- public DataBaseWindow()
+ public static ListBox ItemListInstance;
+
+ public DataBaseWindow()
{
InitializeComponent();
- }
+ ItemListInstance = ItemList;
+ ClassificationComboBox.SelectionChanged += ClassificationComboBoxOnSelectionChanged;
+ }
+
+ ///
+ /// 分类下拉框值发生改变
+ ///
+ ///
+ ///
+ private void ClassificationComboBoxOnSelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ (DataContext as DataBaseViewModel)?.ClearItemChildTypes(ClassificationComboBox.SelectedValue);
+ }
private void CloseBtn_Click(object sender, RoutedEventArgs e)
{
diff --git a/Engine/CLEngine.Core/CLEngine.Core.csproj b/Engine/CLEngine.Core/CLEngine.Core.csproj
index c4bb1bf..da368f3 100644
--- a/Engine/CLEngine.Core/CLEngine.Core.csproj
+++ b/Engine/CLEngine.Core/CLEngine.Core.csproj
@@ -293,10 +293,13 @@
+
+
+
diff --git a/Engine/CLEngine.Core/framework/FrameworkManager.cs b/Engine/CLEngine.Core/framework/FrameworkManager.cs
index d220041..5836db3 100644
--- a/Engine/CLEngine.Core/framework/FrameworkManager.cs
+++ b/Engine/CLEngine.Core/framework/FrameworkManager.cs
@@ -1,4 +1,8 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.IO;
+using System.Linq;
namespace CLEngine.Core.framework
{
@@ -7,7 +11,7 @@ namespace CLEngine.Core.framework
///
public static class FrameworkManager
{
- private static Dictionary _dataFrameworks;
+ private static readonly Dictionary _dataFrameworks;
static FrameworkManager()
{
@@ -19,7 +23,8 @@ namespace CLEngine.Core.framework
///
/// 注册事件框架
///
- ///
+ /// 事件名
+ /// 事件数据
public static void RegisterDataFramework(string name, IDataFramework framework)
{
_dataFrameworks.Add(name, framework);
@@ -49,10 +54,13 @@ namespace CLEngine.Core.framework
///
/// 加载所有数据
///
+ [SuppressMessage("ReSharper", "ForCanBeConvertedToForeach")]
public static void LoadAllData()
{
- foreach (var dataFramework in _dataFrameworks)
- dataFramework.Value.LoadData();
+ var dataFrameworkList = _dataFrameworks.ToList();
+ // 不要使用foreach 列表发生更改时会报错
+ for (int i = 0; i < dataFrameworkList.Count; i++)
+ dataFrameworkList[i].Value.LoadData();
}
///
@@ -64,6 +72,15 @@ namespace CLEngine.Core.framework
dataFramework.Value.SaveData();
}
+ ///
+ /// 保存指定数据
+ ///
+ ///
+ public static void SaveData(string name)
+ {
+ _dataFrameworks[name].SaveData();
+ }
+
///
/// 改变指定数据
///
@@ -73,5 +90,51 @@ namespace CLEngine.Core.framework
{
_dataFrameworks[name] = data;
}
+
+ ///
+ /// 加载数据
+ ///
+ /// 数据类型 存储于FrameworkManager中的名称
+ /// 文件名
+ public static void LoadFrameworkData(string type, string name)
+ {
+ if (string.IsNullOrEmpty(SceneManager.GameProject.ProjectPath))
+ throw new Exception("未加载工程前无法加载游戏数据");
+
+ var dataPath = Path.Combine(SceneManager.GameProject.ProjectPath, "Content", "Data");
+ try
+ {
+ var dataManager = (ItemManager)CHelper.DeserializeObject(Path.Combine(dataPath, name + ".data"));
+ if (dataManager != null)
+ ChangeData(type, dataManager);
+ }
+ catch (Exception e)
+ {
+ throw new Exception(e.Message, e);
+ }
+ }
+
+ ///
+ /// 保存数据
+ ///
+ /// 文件名
+ /// 数据
+ public static void SaveFrameworkData(string name, object type)
+ {
+ if (string.IsNullOrEmpty(SceneManager.GameProject.ProjectPath))
+ throw new Exception("未加载工程前无法保存游戏数据");
+
+ var dataPath = Path.Combine(SceneManager.GameProject.ProjectPath, "Content", "Data");
+ Directory.CreateDirectory(dataPath);
+ try
+ {
+ Directory.CreateDirectory(dataPath);
+ CHelper.SerializeObject(Path.Combine(dataPath, name + ".data"), type);
+ }
+ catch (Exception e)
+ {
+ throw new Exception(e.Message, e);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Engine/CLEngine.Core/framework/FrameworkSettings.cs b/Engine/CLEngine.Core/framework/FrameworkSettings.cs
index 6bd686a..3a6db8c 100644
--- a/Engine/CLEngine.Core/framework/FrameworkSettings.cs
+++ b/Engine/CLEngine.Core/framework/FrameworkSettings.cs
@@ -34,8 +34,8 @@ namespace CLEngine.Core.framework
/// 物品列表
///
public static Dictionary> ItemTypes = new Dictionary>{
- {"物品",new List{"消耗品","任务用品","材料","礼包" } },
- {"装备",new List{"武器","鞋子","帽子","衣服","裤子","首饰","戒指" } },
+ {"物品",new List{"消耗品","任务用品","材料","礼包" } },
+ {"装备",new List{"武器","鞋子","帽子","衣服","裤子","首饰","戒指" } },
};
///
@@ -43,17 +43,17 @@ namespace CLEngine.Core.framework
///
public static List GenderTypes = new List()
{
- "无",
+ "无",
"男",
"女"
};
- ///
- /// 职业列表
- ///
- public static List OccupationTypes = new List()
- {
+ ///
+ /// 职业列表
+ ///
+ public static List OccupationTypes = new List()
+ {
- };
- }
+ };
+ }
}
\ No newline at end of file
diff --git a/Engine/CLEngine.Core/framework/ItemManager.cs b/Engine/CLEngine.Core/framework/ItemManager.cs
index a562e0a..f5a8af8 100644
--- a/Engine/CLEngine.Core/framework/ItemManager.cs
+++ b/Engine/CLEngine.Core/framework/ItemManager.cs
@@ -85,20 +85,7 @@ namespace CLEngine.Core.framework
///
public void SaveData()
{
- if (string.IsNullOrEmpty(SceneManager.GameProject.ProjectPath))
- throw new Exception("未加载工程前无法保存物品信息");
-
- var itemPath = Path.Combine(SceneManager.GameProject.ProjectPath, "Content", "Items");
- Directory.CreateDirectory(itemPath);
- try
- {
- CHelper.SerializeObject(Path.Combine(itemPath, "worldItem.db"), this);
- Logger.Info("物品保存成功");
- }
- catch (Exception e)
- {
- throw new Exception(e.Message, e);
- }
+ FrameworkManager.SaveFrameworkData("items", this);
}
///
@@ -106,21 +93,9 @@ namespace CLEngine.Core.framework
///
public void LoadData()
{
- if (string.IsNullOrEmpty(SceneManager.GameProject.ProjectPath))
- throw new Exception("未加载工程前无法加载物品信息");
-
- var itemPath = Path.Combine(SceneManager.GameProject.ProjectPath, "Content", "Items");
- try
- {
- var itemManager = (ItemManager) CHelper.DeserializeObject(Path.Combine(itemPath, "worldItem.db"));
- FrameworkManager.ChangeData("item", itemManager);
- Logger.Info("物品加载成功");
- }
- catch (Exception e)
- {
- throw new Exception(e.Message, e);
- }
+ FrameworkManager.LoadFrameworkData("item", "items");
}
+
///
/// 世界物品中通过名称找物品
///
diff --git a/Engine/CLEngine.Core/framework/ItemObject.cs b/Engine/CLEngine.Core/framework/ItemObject.cs
index 41c1a7c..dc63065 100644
--- a/Engine/CLEngine.Core/framework/ItemObject.cs
+++ b/Engine/CLEngine.Core/framework/ItemObject.cs
@@ -257,17 +257,18 @@ namespace CLEngine.Core.framework
set
{
_iconPath = value;
+ var path = Path.Combine(SceneManager.GameProject.ProjectPath, _iconPath);
if (string.IsNullOrEmpty(_iconPath))
{
IconTex = null;
}
- else if (File.Exists(_iconPath))
+ else if (File.Exists(path))
{
IconTex = TextureLoader.FromContent(_iconPath);
}
else
{
- throw new Exception("文件" + _iconPath + "不存在");
+ throw new Exception("文件" + path + "不存在");
}
}
}
diff --git a/Engine/CLEngine.Core/framework/SkillManager.cs b/Engine/CLEngine.Core/framework/SkillManager.cs
index b66d867..81a706f 100644
--- a/Engine/CLEngine.Core/framework/SkillManager.cs
+++ b/Engine/CLEngine.Core/framework/SkillManager.cs
@@ -63,20 +63,7 @@ namespace CLEngine.Core.framework
///
public void LoadData()
{
- if (string.IsNullOrEmpty(SceneManager.GameProject.ProjectPath))
- throw new Exception("未加载工程前无法加载物品信息");
-
- var skillPath = Path.Combine(SceneManager.GameProject.ProjectPath, "Content", "Skills");
- try
- {
- var skillManager = (ItemManager)CHelper.DeserializeObject(Path.Combine(skillPath, "worldSkill.db"));
- FrameworkManager.ChangeData("skill", skillManager);
- Logger.Info("技能加载成功");
- }
- catch (Exception e)
- {
- throw new Exception(e.Message, e);
- }
+ FrameworkManager.LoadFrameworkData("skill", "skills");
}
///
@@ -84,20 +71,7 @@ namespace CLEngine.Core.framework
///
public void SaveData()
{
- if (string.IsNullOrEmpty(SceneManager.GameProject.ProjectPath))
- throw new Exception("未加载工程前无法保存物品信息");
-
- var itemPath = Path.Combine(SceneManager.GameProject.ProjectPath, "Content", "Skills");
- Directory.CreateDirectory(itemPath);
- try
- {
- CHelper.SerializeObject(Path.Combine(itemPath, "worldSkill.db"), this);
- Logger.Info("技能保存成功");
- }
- catch (Exception e)
- {
- throw new Exception(e.Message, e);
- }
+ FrameworkManager.SaveFrameworkData("skills", this);
}
}
}
\ No newline at end of file
--
Gitee
From 107524f2267c9b77fd7756a034e0259e63451027 Mon Sep 17 00:00:00 2001
From: yhh <359807859@qq.com>
Date: Wed, 17 Jul 2019 18:47:36 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BA=8F=E5=88=97?=
=?UTF-8?q?=E5=8C=96=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../framework/FrameworkManager.cs | 20 ++++--
Engine/CLEngine.Core/framework/ItemManager.cs | 18 +++--
Engine/CLEngine.Core/framework/ItemObject.cs | 8 ++-
.../CLEngine.Core/framework/SkillManager.cs | 66 +++++++++----------
4 files changed, 63 insertions(+), 49 deletions(-)
diff --git a/Engine/CLEngine.Core/framework/FrameworkManager.cs b/Engine/CLEngine.Core/framework/FrameworkManager.cs
index 5836db3..8f14120 100644
--- a/Engine/CLEngine.Core/framework/FrameworkManager.cs
+++ b/Engine/CLEngine.Core/framework/FrameworkManager.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
+using System.Windows.Forms;
namespace CLEngine.Core.framework
{
@@ -78,7 +79,14 @@ namespace CLEngine.Core.framework
///
public static void SaveData(string name)
{
- _dataFrameworks[name].SaveData();
+ try
+ {
+ _dataFrameworks[name].SaveData();
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.StackTrace);
+ }
}
///
@@ -94,9 +102,8 @@ namespace CLEngine.Core.framework
///
/// 加载数据
///
- /// 数据类型 存储于FrameworkManager中的名称
/// 文件名
- public static void LoadFrameworkData(string type, string name)
+ public static object LoadFrameworkData(string name)
{
if (string.IsNullOrEmpty(SceneManager.GameProject.ProjectPath))
throw new Exception("未加载工程前无法加载游戏数据");
@@ -104,9 +111,9 @@ namespace CLEngine.Core.framework
var dataPath = Path.Combine(SceneManager.GameProject.ProjectPath, "Content", "Data");
try
{
- var dataManager = (ItemManager)CHelper.DeserializeObject(Path.Combine(dataPath, name + ".data"));
- if (dataManager != null)
- ChangeData(type, dataManager);
+ var path = Path.Combine(dataPath, name + ".data");
+
+ return File.Exists(path) ? CHelper.DeserializeObject(path) : null;
}
catch (Exception e)
{
@@ -125,7 +132,6 @@ namespace CLEngine.Core.framework
throw new Exception("未加载工程前无法保存游戏数据");
var dataPath = Path.Combine(SceneManager.GameProject.ProjectPath, "Content", "Data");
- Directory.CreateDirectory(dataPath);
try
{
Directory.CreateDirectory(dataPath);
diff --git a/Engine/CLEngine.Core/framework/ItemManager.cs b/Engine/CLEngine.Core/framework/ItemManager.cs
index f5a8af8..a9c4899 100644
--- a/Engine/CLEngine.Core/framework/ItemManager.cs
+++ b/Engine/CLEngine.Core/framework/ItemManager.cs
@@ -31,8 +31,8 @@ namespace CLEngine.Core.framework
static ItemManager()
{
_worldItem = new Dictionary();
- _playerItem = new List();
- WorldId = 1;
+ _playerItem = new List();
+ WorldId = 1;
}
///
@@ -43,7 +43,7 @@ namespace CLEngine.Core.framework
var item = new ItemObject(name) { Id = WorldId };
_worldItem.Add(name, item);
- WorldId++;
+ WorldId++;
return item;
}
@@ -85,7 +85,9 @@ namespace CLEngine.Core.framework
///
public void SaveData()
{
- FrameworkManager.SaveFrameworkData("items", this);
+ FrameworkManager.SaveFrameworkData("worldItem", _worldItem);
+ FrameworkManager.SaveFrameworkData("playerItem", _playerItem);
+ FrameworkManager.SaveFrameworkData("worldId", WorldId);
}
///
@@ -93,7 +95,11 @@ namespace CLEngine.Core.framework
///
public void LoadData()
{
- FrameworkManager.LoadFrameworkData("item", "items");
+ _worldItem = (Dictionary)FrameworkManager.LoadFrameworkData("worldItem") ?? new Dictionary();
+ _playerItem = (List)FrameworkManager.LoadFrameworkData("playerItem") ?? new List();
+ var worldId = FrameworkManager.LoadFrameworkData("worldId");
+ if (worldId != null)
+ WorldId = (int) worldId;
}
///
@@ -225,7 +231,7 @@ namespace CLEngine.Core.framework
}
}
}
- if (!is_finish||(!have&&item.OnlyGetOne))
+ if (!is_finish || (!have && item.OnlyGetOne))
{
onget.Number = number;
_playerItem.Add(onget);
diff --git a/Engine/CLEngine.Core/framework/ItemObject.cs b/Engine/CLEngine.Core/framework/ItemObject.cs
index dc63065..fff3078 100644
--- a/Engine/CLEngine.Core/framework/ItemObject.cs
+++ b/Engine/CLEngine.Core/framework/ItemObject.cs
@@ -76,7 +76,6 @@ namespace CLEngine.Core.framework
[DataMember] private int _addAtkSpeed;
[DataMember] private int _addAtkRange;
[DataMember] private Dictionary _customProp;
- [DataMember] private Image _guiIcon;
[DataMember] private bool _isGuiShow;
[DataMember] private int _lv;
[DataMember] private string _child;
@@ -101,6 +100,7 @@ namespace CLEngine.Core.framework
[DataMember] private float _magicUseSpeed;
[DataMember] private string _classification;
[DataMember] private bool _onlyStoreOne;
+ [NonSerialized] private Image _guiIcon;
[NonSerialized] private Texture2D _texture;
private int _positionInBag;
@@ -257,12 +257,14 @@ namespace CLEngine.Core.framework
set
{
_iconPath = value;
- var path = Path.Combine(SceneManager.GameProject.ProjectPath, _iconPath);
if (string.IsNullOrEmpty(_iconPath))
{
IconTex = null;
+ return;
}
- else if (File.Exists(path))
+
+ var path = Path.Combine(SceneManager.GameProject.ProjectPath, _iconPath);
+ if (File.Exists(path))
{
IconTex = TextureLoader.FromContent(_iconPath);
}
diff --git a/Engine/CLEngine.Core/framework/SkillManager.cs b/Engine/CLEngine.Core/framework/SkillManager.cs
index 81a706f..c913b22 100644
--- a/Engine/CLEngine.Core/framework/SkillManager.cs
+++ b/Engine/CLEngine.Core/framework/SkillManager.cs
@@ -1,56 +1,56 @@
using System;
using System.Collections.Generic;
-using System.IO;
using System.Runtime.Serialization;
namespace CLEngine.Core.framework
{
- ///
- /// 技能管理器
- ///
+ ///
+ /// 技能管理器
+ ///
#if WIN
[Serializable]
#endif
[DataContract]
- public class SkillManager : IDataFramework
- {
- ///
- /// 全局技能
- ///
- [DataMember] private static Dictionary _worldSkill;
+ public class SkillManager : IDataFramework
+ {
+ ///
+ /// 全局技能
+ ///
+ [DataMember] private static Dictionary _worldSkill;
- static SkillManager()
- {
- _worldSkill = new Dictionary();
- }
+ static SkillManager()
+ {
+ _worldSkill = new Dictionary();
+ }
- ///
- /// 添加技能
- ///
- /// 技能名
- /// 技能
- public static SkillObject AddSkill(string name)
- {
- var skill = new SkillObject();
- _worldSkill.Add(name, skill);
+ ///
+ /// 添加技能
+ ///
+ /// 技能名
+ /// 技能
+ public static SkillObject AddSkill(string name)
+ {
+ var skill = new SkillObject();
+ _worldSkill.Add(name, skill);
- return skill;
- }
+ return skill;
+ }
///
/// 删除技能
///
/// 技能名
- public static void RemoveSkill(string name)
- {
- _worldSkill.Remove(name);
- }
+ public static void RemoveSkill(string name)
+ {
+ _worldSkill.Remove(name);
+ }
///
/// 获取技能列表
///
/// 技能列表
- public static List GetSkillList(){
+ public static List GetSkillList()
+ {
var skillList = new List();
foreach (var skill in _worldSkill)
skillList.Add(skill.Value);
@@ -63,7 +63,7 @@ namespace CLEngine.Core.framework
///
public void LoadData()
{
- FrameworkManager.LoadFrameworkData("skill", "skills");
+ _worldSkill = (Dictionary)FrameworkManager.LoadFrameworkData("skills") ?? new Dictionary();
}
///
@@ -71,7 +71,7 @@ namespace CLEngine.Core.framework
///
public void SaveData()
{
- FrameworkManager.SaveFrameworkData("skills", this);
+ FrameworkManager.SaveFrameworkData("skills", _worldSkill);
}
- }
+ }
}
\ No newline at end of file
--
Gitee