Win32ScenePlugin.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using GameEditorPlugin.Win32.Editor;
  2. using GameEditorPlugin.Win32.Runtime;
  3. using System;
  4. using System.IO;
  5. using System.Runtime.InteropServices;
  6. using System.Windows.Forms;
  7. using CommonAI.Zone.ZoneEditor;
  8. namespace CommonAIEditor.Plugins.Win32
  9. {
  10. public partial class Win32ScenePlugin : ISceneEditorPlugin
  11. {
  12. private Win32EditorPanel panel;
  13. public Win32ScenePlugin()
  14. {
  15. panel = new Win32EditorPanel(this);
  16. }
  17. //------------------------------------------------------------------------------
  18. public bool EnableRight { get { return true; } }
  19. public event PluginMessageHandler OnGetPluginMessage;
  20. public event CallAddSceneObject CallAddObject;
  21. public event CallResetSceneObject CallResetObject;
  22. public Control AsControl()
  23. {
  24. return panel;
  25. }
  26. public void SendMessage(object dt)
  27. {
  28. //string xml = EditorMessageDecoder.EncodeMessage(dt);
  29. //object data = EditorMessageDecoder.DecodeMessage(xml);
  30. panel.OnMsgReceived(dt);
  31. }
  32. class Win32EditorPanel : EditorDisplayPanel
  33. {
  34. private readonly Win32ScenePlugin plugin;
  35. public Win32EditorPanel(Win32ScenePlugin plugin)
  36. {
  37. this.plugin = plugin;
  38. }
  39. public override void SendToEditor(object data)
  40. {
  41. if (plugin.OnGetPluginMessage != null)
  42. {
  43. plugin.OnGetPluginMessage.Invoke(data);
  44. }
  45. }
  46. protected override T CallAddObjectData<T>(Action<T> callback)
  47. {
  48. if (plugin.CallAddObject != null)
  49. {
  50. return plugin.CallAddObject.Invoke(typeof(T), (t) => { callback.Invoke(t as T); }) as T;
  51. }
  52. return null;
  53. }
  54. protected override T CallResetObjectData<T>(string name, Action<T> callback)
  55. {
  56. if (plugin.CallResetObject != null)
  57. {
  58. return plugin.CallResetObject.Invoke(name, (t) => { if (t is T) { callback.Invoke(t as T); } }) as T;
  59. }
  60. return null;
  61. }
  62. }
  63. }
  64. public class Win32EditorGamePlugin : IGameEditorPlugin
  65. {
  66. [DllImport("user32.dll", SetLastError = true)]
  67. static extern void SwitchToThisWindow(IntPtr hWnd, bool turnOn);
  68. public string Name { get { return "Win32"; } }
  69. public string PluginDLL { get { return EditorPlugin.PluginDLL; } set { } }
  70. public string DataRoot { get { return Editor.EditorRootDir; } set { } }
  71. public ISceneEditorPlugin CreateScenePlugin(IGameEditorPlugin default_plugin)
  72. {
  73. return new Win32ScenePlugin();
  74. }
  75. public bool AcceptResource(IGameEditorPlugin d, string filename)
  76. {
  77. return true;
  78. }
  79. public void RunModelView(IGameEditorPlugin d, string[] filepath)
  80. {
  81. }
  82. public void RunTest(IGameEditorPlugin d, string data_dir, int sceneID, int actorTemplateID)
  83. {
  84. FormRuntimeGameLocal test = new FormRuntimeGameLocal(new DirectoryInfo(data_dir), sceneID);
  85. test.Show();
  86. }
  87. public void RunLocalPlay(IGameEditorPlugin d, DirectoryInfo data_dir, int sceneID, bool recorder)
  88. {
  89. new FormRuntimeGameLocal(data_dir, sceneID, recorder).Show();
  90. }
  91. public void RunServerPlay(IGameEditorPlugin d, DirectoryInfo data_dir, int sceneID)
  92. {
  93. new GameEditorPluginServer.Server.FormServer(data_dir, sceneID).Show();
  94. }
  95. }
  96. }