using System;
using System.Collections.Generic;
using System.Text;
using CommonLang.Xml;
using System.Xml;
using System.IO;
using CommonLang;
namespace CommonAI.Zone.ZoneEditor.Plugin
{
// 编辑器发送到场景的消息
namespace EditorToScene
{
///
/// 地形数据通知
///
public class MsgSetScene
{
public string ProjectName;
public string FileName;
public string ResourceDir;
public string ResourceProperty;
public ZoneInfo Data;
}
///
/// 增加单位数据,如果单位已存在,则更新信息
///
public class MsgPutUnit
{
public UnitData Data;
public UnitInfo UnitData;
}
///
/// 增加物品数据,如果单位已存在,则更新信息
///
public class MsgPutItem
{
public ItemData Data;
public ItemTemplate Item;
}
///
/// 增加单位数据,如果单位已存在,则更新信息
///
public class MsgPutPoint
{
public PointData Data;
}
///
/// 增加单位数据,如果单位已存在,则更新信息
///
public class MsgPutRegion
{
public RegionData Data;
}
///
/// 增加装饰物数据,如果单位已存在,则更新信息
///
public class MsgPutDecoration
{
public DecorationData Data;
}
///
/// 增加区域数据,如果单位已存在,则更新信息
///
public class MsgPutArea
{
public AreaData Data;
}
///
/// 删除一个单位
///
public class MsgRemoveObject
{
public string Name;
}
///
/// 单位被重命名
///
public class MsgRenameObject
{
public string SrcName;
public string DstName;
}
///
/// 由编辑器UI层选中一个单位
///
public class MsgSelectObject
{
public string Name;
///
/// 摄像机是否聚焦此单位
///
public bool IsLocateCamera;
}
///
/// 设置是否显示地形阻挡
///
public class MsgShowTerrain
{
public bool Show;
}
///
/// 定位摄像机
///
public class MsgLocateCamera
{
public float X;
public float Y;
}
///
/// 设置笔刷
///
public class MsgSetTerrainBrush
{
public enum BrushType
{
Round,
Rectangle,
}
public int ARGB = (int)(0x7F00FF00L);
public int Size = 1;
public BrushType Brush = BrushType.Round;
public static float[] ToARGB_F(int ARGB)
{
float[] argb = new float[4];
argb[0] = ((ARGB >> 24) & 0xFF) / 255f;
argb[1] = ((ARGB >> 16) & 0xFF) / 255f;
argb[2] = ((ARGB >> 8 ) & 0xFF) / 255f;
argb[3] = ((ARGB ) & 0xFF) / 255f;
return argb;
}
public static int FromARGB_F(float[] argb)
{
int ARGB = 0;
ARGB |= ((int)(argb[0] * 255)) << 24;
ARGB |= ((int)(argb[1] * 255)) << 16;
ARGB |= ((int)(argb[2] * 255)) << 8;
ARGB |= ((int)(argb[3] * 255));
return ARGB;
}
public static float[] ToRGBA_F(int ARGB)
{
float[] rgba = new float[4];
rgba[3] = ((ARGB >> 24) & 0xFF) / 255f;
rgba[0] = ((ARGB >> 16) & 0xFF) / 255f;
rgba[1] = ((ARGB >> 8 ) & 0xFF) / 255f;
rgba[2] = ((ARGB) & 0xFF) / 255f;
return rgba;
}
public static int FromRGBA_F(float[] rgba)
{
int ARGB = 0;
ARGB |= ((int)(rgba[3] * 255)) << 24;
ARGB |= ((int)(rgba[0] * 255)) << 16;
ARGB |= ((int)(rgba[1] * 255)) << 8;
ARGB |= ((int)(rgba[2] * 255));
return ARGB;
}
}
///
/// 设置编辑模式
///
public class MsgSetEditorMode
{
public const int MODE_OBJECT = 0;
public const int MODE_TERRAIN = 1;
public int Mode = MODE_OBJECT;
}
}
// 场景发回编辑器的消息
namespace SceneToEditor
{
///
/// 场景初始化状态
///
public class RspEditorState
{
public const int STATE_SUCCEED = 1;
public int State = STATE_SUCCEED;
}
///
/// 设置笔刷
///
public class RspTerrainBrushChanged
{
public int Size = 1;
}
///
/// 有单位被选中
///
public class RspOnObjectSelected
{
public string Name;
public bool Selected;
}
///
/// 有单位位置改变
///
public class RspObjectPositionChanged
{
public string Name;
public float x;
public float y;
}
///
/// 有单位尺寸改变
///
public class RspObjectSizeChanged
{
public string Name;
public float x;
public float y;
}
///
/// 有单位方向改变
///
public class RspObjectDirectionChanged
{
public string Name;
public float dir;
}
///
/// 路点链接数据改变
///
public class RspPointLinkChanged
{
public string SrcPointName;
public string DstPointName;
}
///
/// 最终回馈场景地形数据
///
public class RspZoneFlagChanged
{
///
/// 场景坐标
///
public int SceneX;
///
/// 场景坐标
///
public int SceneY;
///
/// 标志
///
public int Flag;
public RspZoneFlagChanged() { }
public RspZoneFlagChanged(int x, int y, int flag)
{
this.SceneX = x;
this.SceneY = y;
this.Flag = flag;
}
public override bool Equals(object obj)
{
if (obj is RspZoneFlagChanged)
{
RspZoneFlagChanged other = obj as RspZoneFlagChanged;
return other.Flag == this.Flag && other.SceneX == this.SceneX && other.SceneY == this.SceneY;
}
return false;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
///
/// 最终回馈场景地形数据
///
public class RspZoneFlagBathChanged
{
public List Flags = new List();
}
///
/// 摄像机位置或者尺寸改变
///
public class RspCameraChanged
{
public float X;
public float Y;
public float W;
public float H;
}
}
public class EditorMessageDecoder
{
public static object DecodeMessage(string text)
{
byte[] buffer = Convert.FromBase64String(text);
string xml = Encoding.UTF8.GetString(buffer);
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
object obj = XmlUtil.XmlToObject(doc);
return obj;
}
public static string EncodeMessage(object msg)
{
XmlDocument doc = XmlUtil.ObjectToXml(msg);
string text = doc.OuterXml;
string str = Convert.ToBase64String(Encoding.UTF8.GetBytes(text));
return str;
}
}
}