private void ShowMouseObjInfo() { string strPre = string.Empty; for (int i = 0; i < 12 - this.statusLabel4.Text.Trim().Length; i++) { strPre += " "; } if (m_mouseGrabODI != null) { LogicObj curObj = m_mouseGrabODI.lObj; //string strODI = string.Format("{0}对象: {1}[{2}]", strPre, curObj.values[0], curObj.inDex); string strODI = string.Format("{0}对象: {1}[{2}]", strPre, curObj.tyPe.ToLower().EndsWith("point") ? "Point" : (curObj.tyPe.ToLower().EndsWith("vertex") ? "Vertex" : curObj.values[0]), curObj.inDex); this.statusLabel3.Text = strODI; } else if (m_mouseUnderODI != null) { LogicObj curObj = m_mouseUnderODI.lObj; //string strODI = string.Format("{0}对象: {1}[{2}]", strPre, curObj.values[0], curObj.inDex); string strODI = string.Format("{0}对象: {1}[{2}]", strPre, curObj.tyPe.ToLower().EndsWith("point") ? "Point" : (curObj.tyPe.ToLower().EndsWith("vertex") ? "Vertex" : curObj.values[0]), curObj.inDex); this.statusLabel3.Text = strODI; } else { this.statusLabel3.Text = strPre + "对象: N/A"; } }
private void AdjustObjLogicalDir(LogicObj obj, int nDir) { if (m_parentFrm.htObjLogicDirIndices.ContainsKey(obj.tyPe) && m_parentFrm.htObjLogicRotationIndices.ContainsKey(obj.tyPe)) { int dirIndex = Convert.ToInt32(m_parentFrm.htObjLogicDirIndices[obj.tyPe]); int oldDir = Convert.ToInt32(obj.values[dirIndex]); int newDir = nDir; obj.values[dirIndex] = newDir.ToString(); obj.fields_changed[dirIndex] = true; int rotationIndex = Convert.ToInt32(m_parentFrm.htObjLogicRotationIndices[obj.tyPe]); float x = 0.0f, y = 0.0f, z = 0.0f, w = 1.0f; Program.Engine.QuaternionRotationByNDir(ref x, ref y, ref z, ref w, nDir); double xx = x, yy = y, zz = z, ww = w; xx = Math.Round(xx, 6); yy = Math.Round(yy, 6); zz = Math.Round(zz, 6); ww = Math.Round(ww, 6); string newRotation = string.Format("{0},{1},{2},{3}", xx, yy, zz, ww); obj.values[rotationIndex] = newRotation; obj.ForcePreviewChange(true, rotationIndex); obj.ForceInhandChange(true); this.m_parentFrm.ForceMapChanged(); this.m_parentFrm.Pg.Refresh(); } }
private void tree1_AfterSelNodesRemove(object sender, MWPropertyEventArgs e) { TreeNode node = e.Updated as TreeNode; // 检查是否大分类结点 if (node.Tag is string) { return; } LogicObj lobj = node.Tag as LogicObj; if (lobj == null) // 删除一组 { LogicObj onechild = node.Nodes[0].Tag as LogicObj; if (onechild != null) { foreach (TreeNode n in node.Nodes) { this.previewform.m_panel1.RemoveODI(n.Text); } } } else // 删除一个 { this.previewform.m_panel1.RemoveODI(node.Text); } }
public LogicalObjectCollectionPropertyDescriptor(LogicObj lobj, int idx) : base("#" + idx.ToString(), null) { this.oldObj = lobj.Clone() as LogicObj; this.lobj = lobj; this.index = idx; }
public LogicObj[] kids2; // 2个 #region "IClonable implementation" public object Clone() // 明显不是Deep Clone, 连Shadow Clone也算不上。只是借这个名字而已。请继续路过。 { LogicObj retobj = new LogicObj(this.tyPe); retobj.inDex = this.inDex; retobj.parentindex = this.parentindex; for (int i = 0; i < this.values.Length; i++) retobj.values[i] = this.values[i]; return retobj; }
private int LogicObjToDirection(LogicObj target) { if (htObjLogicDirIndices.ContainsKey(target.tyPe)) { string nDirection = target.values[Convert.ToInt32(htObjLogicDirIndices[target.tyPe])]; return(Convert.ToInt32(nDirection)); } else { return(-1); } }
public LogicObj[] kids2; // 2个 #region "IClonable implementation" public object Clone() // 明显不是Deep Clone, 连Shadow Clone也算不上。只是借这个名字而已。请继续路过。 { LogicObj retobj = new LogicObj(this.tyPe); retobj.inDex = this.inDex; retobj.parentindex = this.parentindex; for (int i = 0; i < this.values.Length; i++) { retobj.values[i] = this.values[i]; } return(retobj); }
private void AdjustObjLogicalPos(LogicObj obj, PointF pfClientRateAdjust) { if (m_parentFrm.htObjScenePosIndices.ContainsKey(obj.tyPe)) { double x = 0.0, y = 0.0; float height = 0.0f; // 场景pos if (m_parentFrm.htObjScenePosIndices[obj.tyPe] != null) { int posIndex = Convert.ToInt32(m_parentFrm.htObjScenePosIndices[obj.tyPe]); string vPosition = obj.values[posIndex]; string[] fields = vPosition.Split(new char[] { ',' }); x = Convert.ToDouble(fields[0]); y = Convert.ToDouble(fields[2]); x += pfClientRateAdjust.X * m_parentFrm.curMapLogicWidthTotal * m_panel1.scale; y -= pfClientRateAdjust.Y * m_parentFrm.curMapLogicHeightTotal * m_panel1.scale; x = Math.Round(x, 2); y = Math.Round(y, 2); height = 0.0f; Program.Engine.GetHeight((int)m_parentFrm.htScenePtr[m_parentFrm.m_curMapName], (float)x, (float)y, out height); vPosition = string.Format("{0},{1},{2}", x, height, y); obj.values[posIndex] = vPosition; obj.ForcePreviewChange(true, posIndex); } // 逻辑xyz if (m_parentFrm.htObjLogicNXIndices[obj.tyPe] != null) { float logic_x_start = (float)(Convert.ToDouble((m_parentFrm.maps[m_parentFrm.m_curMapName] as LO_Map).MAIN.values[11])); float logic_z_start = (float)(Convert.ToDouble((m_parentFrm.maps[m_parentFrm.m_curMapName] as LO_Map).MAIN.values[12])); int lX = 0, lY = 0, lZ = 0; Helper.SceneToLogical(ref lX, ref lY, ref lZ, (float)x, height, (float)y, 0.0f, logic_x_start, logic_z_start); int nXIndex = Convert.ToInt32(m_parentFrm.htObjLogicNXIndices[obj.tyPe]); obj.values[nXIndex] = lX.ToString(); obj.values[nXIndex + 1] = lY.ToString(); obj.values[nXIndex + 2] = lZ.ToString(); obj.ForcePreviewChange(true, nXIndex); obj.ForcePreviewChange(true, nXIndex + 1); obj.ForcePreviewChange(true, nXIndex + 2); } obj.ForceInhandChange(true); this.m_parentFrm.ForceMapChanged(); this.m_parentFrm.Pg.Refresh(); } }
/// <summary> /// 重写的绘图方法 /// </summary> /// <param name="e">绘图事件参数</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics dc = e.Graphics; if (canvasWidth == 0 || canvasHeight == 0) { return; } Bitmap bufferBMP = new Bitmap(canvasWidth, canvasHeight); // 绘图的缓冲 Graphics g = Graphics.FromImage(bufferBMP); g.Clear(this.BackColor); g.SmoothingMode = SmoothingMode.HighQuality; //高质量 g.PixelOffsetMode = PixelOffsetMode.HighQuality; //高像素偏移质量 if (image != null) // 绘制图片 { RectangleF destRect = new RectangleF(0, 0, canvasWidth, canvasHeight); RectangleF srcRect = new RectangleF((1.0f - scale) * image.Width / 2 + start_adjust_x, (1.0f - scale) * image.Height / 2 + start_adjust_y, image.Width * scale, image.Height * scale); g.DrawImage(image, destRect, srcRect, GraphicsUnit.Pixel); foreach (DictionaryEntry entry in m_ODIs) { ObjDrawInfo odi = entry.Value as ObjDrawInfo; PointF pointf = GetODIClientPos(odi); g.DrawEllipse(redPen, pointf.X - 3, pointf.Y - 3, 7, 7); int nDir = (int)(odi.nDir); if ((this.Parent as Preview).m_ShowDir && nDir != -1) { PointF adjustment = GetDirEndAdjustment(nDir); g.DrawLine(redPen, pointf.X, pointf.Y, pointf.X + adjustment.X, pointf.Y + adjustment.Y); } if ((this.Parent as Preview).m_ShowObjName) { LogicObj curObj = odi.lObj; string strODI = string.Format("{0}[{1}]", curObj.tyPe.ToLower().EndsWith("point") ? "Point" : (curObj.tyPe.ToLower().EndsWith("vertex") ? "Vertex" : curObj.values[0]), curObj.inDex); g.DrawString(strODI, timesFont, yellowBrush, pointf.X + 3, pointf.Y + 7); } } } // 从缓冲中绘制最终图像 dc.DrawImage(bufferBMP, 0, 0); // g.DrawLine(greenPen, p, p + littileSize); }
private void tree1_AfterSelect(object sender, TreeViewEventArgs e) { // 生成propertygrid需要的对象 LogicObj target = e.Node.Tag as LogicObj; if (target != null) { target.Clear(); for (int i = 0; i < target.fields.Length; i++) { target.Add(target.values[i]); } propertyGrid1.SelectedObject = target; } previewform.m_panel1.Refresh(); }
private void tree1_AfterSelNodesAdd(object sender, MWPropertyEventArgs e) { TreeNode node = e.Updated as TreeNode; // 显示图片 ShowMapContainSelectObj(node); // 检查是否大分类结点 if (node.Tag is string) { return; } LogicObj lobj = node.Tag as LogicObj; if (lobj == null) // 添加一组 { LogicObj onechild = node.Nodes[0].Tag as LogicObj; if (onechild != null) { foreach (TreeNode n in node.Nodes) { LogicObj oneObj = n.Tag as LogicObj; PointF pointf = LogicObjPosToImagePointF(oneObj); int ndir = LogicObjToDirection(oneObj); if (pointf != PointF.Empty) { ObjDrawInfo odi = new ObjDrawInfo(pointf, ndir, oneObj); this.previewform.m_panel1.AddODI(n.Text, odi); } } } } else // 添加一个 { PointF pointf = LogicObjPosToImagePointF(lobj); int ndir = LogicObjToDirection(lobj); if (pointf != PointF.Empty) { ObjDrawInfo odi = new ObjDrawInfo(pointf, ndir, lobj); this.previewform.m_panel1.AddODI(node.Text, odi); } } }
private PointF LogicObjPosToImagePointF(LogicObj target) { if (htObjScenePosIndices.ContainsKey(target.tyPe)) { string strNX = target.values[Convert.ToInt32(htObjLogicNXIndices[target.tyPe])]; int nx = Convert.ToInt32(strNX); string strNY = target.values[Convert.ToInt32(htObjLogicNXIndices[target.tyPe]) + 1]; int ny = Convert.ToInt32(strNY); float px = (float)((nx - curLogicStartX) / curMapLogicWidthTotal); float py = (float)(1.0 - (ny - curLogicStartY) / curMapLogicHeightTotal); PointF pfResult = new PointF(px, py); return(pfResult); } else { return(PointF.Empty); } }
public LogicObj lObj; // 对象ref public ObjDrawInfo(PointF pos, int dir, LogicObj obj) { this.pfPos = pos; this.nDir = dir; this.lObj = obj; }
private void DoImportOneTarget(string strFile, string mapname) { this.progressBar1.Visible = true; // 读文件 string content = Helper.FileToString(strFile, Encoding.Default); byte[] bytes = Encoding.Default.GetBytes(content); bytes = Encoding.Convert(Encoding.Default, Encoding.Unicode, bytes); char[] chars = Encoding.Unicode.GetChars(bytes); content = new String(chars); Helper.OpenIniFile(strFile, content); if (Helper.m_inis == null) { string strErr = string.Format("{0} 不是正确的ini格式,\r\n可能包含有 \"<<<<<<< .mine\" 等 SVN 合并残留字符串。\r\n请检查之。", strFile); MessageBox.Show(strErr); return; } // map 对象 LO_Map map = new LO_Map(); maps.Add(mapname, map); //maps.Add(map); map.logicalChanged = false; map.name = mapname; map.filename = strFile; LogicObj main = new LogicObj("MAIN"); main.Read(); map.MAIN = main; map.NPCs = new LogicObj[Convert.ToInt32(map.MAIN.values[0])]; map.Doodads = new LogicObj[Convert.ToInt32(map.MAIN.values[1])]; map.NPCRefreshPointSets = new LogicObj[Convert.ToInt32(map.MAIN.values[2])]; map.DoodadRefreshPointSets = new LogicObj[Convert.ToInt32(map.MAIN.values[4])]; map.AIGroups = new LogicObj[Convert.ToInt32(map.MAIN.values[6])]; map.WayPointSets = new LogicObj[Convert.ToInt32(map.MAIN.values[8])]; map.LogicalPolys = new LogicObj[Convert.ToInt32(map.MAIN.values[13])]; this.progressBar1.Step = 1; this.progressBar1.Minimum = 0; this.progressBar1.Value = 0; this.progressBar1.Maximum = Convert.ToInt32(map.MAIN.values[0]); for (int i = 0; i < Convert.ToInt32(map.MAIN.values[0]); i++) { LogicObj npc = new LogicObj("NPC"); npc.inDex = i; npc.Read(); map.NPCs[i] = npc; this.progressBar1.Value++; } this.progressBar1.Value = 0; this.progressBar1.Maximum = Convert.ToInt32(map.MAIN.values[1]); for (int i = 0; i < Convert.ToInt32(map.MAIN.values[1]); i++) { LogicObj doodad = new LogicObj("Doodad"); doodad.inDex = i; doodad.Read(); map.Doodads[i] = doodad; this.progressBar1.Value++; } this.progressBar1.Value = 0; this.progressBar1.Maximum = Convert.ToInt32(map.MAIN.values[2]); for (int i = 0; i < Convert.ToInt32(map.MAIN.values[2]); i++) { LogicObj npcrefreshset = new LogicObj("NPCRefreshPointSet"); npcrefreshset.inDex = i; npcrefreshset.Read(); npcrefreshset.kids1 = new LogicObj[Convert.ToInt32(npcrefreshset.values[2])]; npcrefreshset.kids2 = new LogicObj[Convert.ToInt32(npcrefreshset.values[3])]; for (int j = 0; j < Convert.ToInt32(npcrefreshset.values[2]); j++) { LogicObj point = new LogicObj("NPCRefreshPoint"); point.inDex = j; point.parentindex = i; point.Read(); npcrefreshset.kids1[j] = point; } for (int j = 0; j < Convert.ToInt32(npcrefreshset.values[3]); j++) { LogicObj npc = new LogicObj("NPCRefreshNPC"); npc.inDex = j; npc.parentindex = i; npc.Read(); npcrefreshset.kids2[j] = npc; } map.NPCRefreshPointSets[i] = npcrefreshset; this.progressBar1.Value++; } this.progressBar1.Value = 0; this.progressBar1.Maximum = Convert.ToInt32(map.MAIN.values[4]); for (int i = 0; i < Convert.ToInt32(map.MAIN.values[4]); i++) { LogicObj doodadrefreshset = new LogicObj("DoodadRefreshPointSet"); doodadrefreshset.inDex = i; doodadrefreshset.Read(); doodadrefreshset.kids1 = new LogicObj[Convert.ToInt32(doodadrefreshset.values[2])]; doodadrefreshset.kids2 = new LogicObj[Convert.ToInt32(doodadrefreshset.values[3])]; for (int j = 0; j < Convert.ToInt32(doodadrefreshset.values[2]); j++) { LogicObj point = new LogicObj("DoodadRefreshPoint"); point.inDex = j; point.parentindex = i; point.Read(); doodadrefreshset.kids1[j] = point; } for (int j = 0; j < Convert.ToInt32(doodadrefreshset.values[3]); j++) { LogicObj doodad = new LogicObj("DoodadRefreshDoodad"); doodad.inDex = j; doodad.parentindex = i; doodad.Read(); doodadrefreshset.kids2[j] = doodad; } map.DoodadRefreshPointSets[i] = doodadrefreshset; this.progressBar1.Value++; } this.progressBar1.Value = 0; this.progressBar1.Maximum = Convert.ToInt32(map.MAIN.values[6]); for (int i = 0; i < Convert.ToInt32(map.MAIN.values[6]); i++) { LogicObj aigroup = new LogicObj("AIGroup"); aigroup.inDex = i; aigroup.Read(); aigroup.kids1 = new LogicObj[Convert.ToInt32(aigroup.values[5])]; for (int j = 0; j < Convert.ToInt32(aigroup.values[5]); j++) { LogicObj npc = new LogicObj("AIGroupNPC"); npc.inDex = j; npc.parentindex = i; npc.Read(); aigroup.kids1[j] = npc; } map.AIGroups[i] = aigroup; this.progressBar1.Value++; } this.progressBar1.Value = 0; this.progressBar1.Maximum = Convert.ToInt32(map.MAIN.values[8]); for (int i = 0; i < Convert.ToInt32(map.MAIN.values[8]); i++) { LogicObj waypointset = new LogicObj("WayPointSet"); waypointset.inDex = i; waypointset.Read(); waypointset.kids1 = new LogicObj[Convert.ToInt32(waypointset.values[2])]; for (int j = 0; j < Convert.ToInt32(waypointset.values[2]); j++) { LogicObj waypoint = new LogicObj("WayPoint"); waypoint.inDex = j; waypoint.parentindex = i; waypoint.Read(); waypointset.kids1[j] = waypoint; } map.WayPointSets[i] = waypointset; this.progressBar1.Value++; } this.progressBar1.Value = 0; this.progressBar1.Maximum = Convert.ToInt32(map.MAIN.values[13]); for (int i = 0; i < Convert.ToInt32(map.MAIN.values[13]); i++) { LogicObj logicalpoly = new LogicObj("LogicalPoly"); logicalpoly.inDex = i; logicalpoly.Read(); logicalpoly.kids1 = new LogicObj[Convert.ToInt32(logicalpoly.values[4])]; for (int j = 0; j < Convert.ToInt32(logicalpoly.values[4]); j++) { LogicObj vertex = new LogicObj("LogicalPolyVertex"); vertex.inDex = j; vertex.parentindex = i; vertex.Read(); logicalpoly.kids1[j] = vertex; } map.LogicalPolys[i] = logicalpoly; this.progressBar1.Value++; } this.progressBar1.Visible = false; Helper.CloseIniFile(); }
private int LogicObjToDirection(LogicObj target) { if (htObjLogicDirIndices.ContainsKey(target.tyPe)) { string nDirection = target.values[Convert.ToInt32(htObjLogicDirIndices[target.tyPe])]; return Convert.ToInt32(nDirection); } else { return -1; } }
private void SaveOneLogicObj(LogicObj lobj, string strFileName, ref int affectedObjCount) { affectedObjCount++; string iniBlock = string.Empty; string iniFieldPrefix = string.Empty; int inDex = lobj.inDex; int parentindex = lobj.parentindex; switch (lobj.tyPe) { case "MAIN": iniBlock = "MAIN"; break; case "NPC": iniBlock = "NPC" + inDex.ToString(); break; case "Doodad": iniBlock = "Doodad" + inDex.ToString(); break; case "NPCRefreshPointSet": iniBlock = "NPCRefreshPointSet" + inDex.ToString(); break; case "NPCRefreshPoint": iniBlock = "NPCRefreshPointSet" + parentindex.ToString(); iniFieldPrefix = "Point" + inDex.ToString(); break; case "NPCRefreshNPC": iniBlock = "NPCRefreshPointSet" + parentindex.ToString(); iniFieldPrefix = "NPC" + inDex.ToString(); break; case "DoodadRefreshPointSet": iniBlock = "DoodadRefreshPointSet" + inDex.ToString(); break; case "DoodadRefreshPoint": iniBlock = "DoodadRefreshPointSet" + parentindex.ToString(); iniFieldPrefix = "Point" + inDex.ToString(); break; case "DoodadRefreshDoodad": iniBlock = "DoodadRefreshPointSet" + parentindex.ToString(); iniFieldPrefix = "Doodad" + inDex.ToString(); break; case "AIGroup": iniBlock = "AIGroup" + inDex.ToString(); break; case "AIGroupNPC": iniBlock = "AIGroup" + parentindex.ToString(); iniFieldPrefix = "NPC" + inDex.ToString(); break; case "WayPointSet": iniBlock = "WayPointSet" + inDex.ToString(); break; case "WayPoint": iniBlock = "WayPointSet" + parentindex.ToString(); iniFieldPrefix = "Point" + inDex.ToString(); break; case "LogicalPoly": iniBlock = "LogicalPoly" + inDex.ToString(); break; case "LogicalPolyVertex": iniBlock = "LogicalPoly" + parentindex.ToString(); iniFieldPrefix = "Vertex" + inDex.ToString(); break; } StringBuilder sb = new StringBuilder(255); for (int i = 0; i < lobj.fields.Length; i++) { Helper.WriteIniFile(iniBlock, iniFieldPrefix + lobj.fields[i], lobj.values[i], strFileName); } lobj.ForceInhandChange(false); lobj.ForcePreviewChange(false); }
private PointF LogicObjPosToImagePointF(LogicObj target) { if (htObjScenePosIndices.ContainsKey(target.tyPe)) { string strNX = target.values[Convert.ToInt32(htObjLogicNXIndices[target.tyPe])]; int nx = Convert.ToInt32(strNX); string strNY = target.values[Convert.ToInt32(htObjLogicNXIndices[target.tyPe]) + 1]; int ny = Convert.ToInt32(strNY); float px = (float)((nx - curLogicStartX) / curMapLogicWidthTotal); float py = (float)(1.0 - (ny - curLogicStartY) / curMapLogicHeightTotal); PointF pfResult = new PointF(px, py); return pfResult; } else { return PointF.Empty; } }