/// <summary> /// 使用HtmlAgilityPack生成DOM树 /// </summary> /// <param name="source"></param> private void GenerateDOMTree(string source) { Task.Run(() => { HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(source); var root = doc.DocumentNode; //获取html结果 var htmlNode = root.SelectSingleNode("html"); this.Dispatcher.Invoke(() => { this.tree_DOM.Items.Clear(); NodeStruct nodeStruct = new NodeStruct(); nodeStruct.InnerHtml = "<html></html>"; nodeStruct.InnerText = ""; nodeStruct.DisplayName = "html"; NodeRecursion(ref nodeStruct, htmlNode); this.tree_DOM.Items.Add(nodeStruct); if (this.tree_DOM.ActualWidth < this.grid_Content.ActualWidth / 2) { this.tree_DOM.Width = 0; } }); }); }
public NodeStruct ArrowLength(TreeNode node, ref int longPath) { if (node is null) { return(new NodeStruct()); } NodeStruct leftStruct = ArrowLength(node.left, ref longPath); NodeStruct rightStruct = ArrowLength(node.right, ref longPath); var currStruct = new NodeStruct(); if (node.left != null && node.left.val == node.val) { currStruct.LeftMax = Math.Max(leftStruct.LeftMax, leftStruct.RightMax) + 1; } if (node.right != null && node.right.val == node.val) { currStruct.RightMax = Math.Max(rightStruct.LeftMax, rightStruct.RightMax) + 1; } longPath = Math.Max(longPath, currStruct.LeftMax + currStruct.RightMax); return(currStruct); }
private void NodeRecursion(ref NodeStruct nodeStruct, HtmlAgilityPack.HtmlNode htmlNode) { HtmlAgilityPack.HtmlNodeCollection childCollection = htmlNode.ChildNodes; List <NodeStruct> list = new List <NodeStruct>(); for (int i = 0; i < childCollection.Count; i++) { if (string.IsNullOrEmpty(childCollection[i].InnerHtml.Trim())) { continue; } NodeStruct htmlStruct = new NodeStruct(); htmlStruct.DisplayName = childCollection[i].Name; htmlStruct.OuterHtml = childCollection[i].OuterHtml; htmlStruct.InnerHtml = childCollection[i].InnerHtml; htmlStruct.InnerText = childCollection[i].InnerText; list.Add(htmlStruct); nodeStruct.Children = list; if (childCollection[i].HasChildNodes) { NodeRecursion(ref htmlStruct, childCollection[i]); } } }
private static bool ParseTowns(NodeStruct node, FileLoader fileLoader) { byte type; NodeStruct nodeTown = fileLoader.GetChildNode(node, out type); while (nodeTown != null) { if (type != (byte)OtbmNodeTypes.Town) { return(false); } MemoryStream props; if (!fileLoader.GetProps(nodeTown, out props)) { return(false); } uint townId = props.ReadUInt32(); if (!Towns.ContainsKey(townId)) { Towns.Add(townId, new Town { TownId = townId }); } Town town = Towns[townId]; town.TownName = props.GetString(); town.TemplePosition = new Position(props.ReadUInt16(), props.ReadUInt16(), (byte)props.ReadByte()); nodeTown = fileLoader.GetNextNode(nodeTown, out type); } return(true); }
private void btn_suo_add_Click(object sender, EventArgs e) { String suo = txt_suo.Text.Trim(); if (suo == "") { MessageBox.Show("请输入内容"); } else { if (NodeStructPro.isExist(suo, "suo", NodeStructPro.getQuId()) == 1) { MessageBox.Show("该信息已存在"); } else { NodeStruct node = new NodeStruct(); node.Id = Utils.GetId(); node.Name = suo; node.Type = "suo"; node.Parent_id = NodeStructPro.getQuId(); node.Admin_user = ""; NodeStructPro.Add(node); MessageBox.Show("添加成功"); } } }
private static bool ParseWaypoints(NodeStruct node, FileLoader fileLoader) { byte type; NodeStruct nodeWaypoint = fileLoader.GetChildNode(node, out type); while (nodeWaypoint != null) { if (type != (byte)OtbmNodeTypes.Waypoint) { return(false); } MemoryStream props; if (!fileLoader.GetProps(nodeWaypoint, out props)) { return(false); } //(name, new Position(x, y, z) Waypoints.Add(props.GetString(), new Position(props.ReadUInt16(), props.ReadUInt16(), (byte)props.ReadByte())); nodeWaypoint = fileLoader.GetNextNode(nodeWaypoint, out type); } return(true); }
private void btn_zhan_add_Click(object sender, EventArgs e) { String suo = cob_suo.Text.Trim(); String zhan = txt_zhan_name.Text.Trim(); if (suo == "" || zhan == "") { MessageBox.Show("请输入内容"); } NodeStruct node_suo = NodeStructPro.getNodeStruct(suo, "suo", NodeStructPro.getQuId()); if (NodeStructPro.isExist(zhan, "zhan", node_suo.Id) == 1) { MessageBox.Show("信息已存在"); } else { NodeStruct node = new NodeStruct(); node.Id = Utils.GetId(); node.Name = zhan; node.Type = "zhan"; node.Parent_id = node_suo.Id; node.Admin_user = ""; NodeStructPro.Add(node); MessageBox.Show("添加成功"); } }
public FrameObjectJoint() : base() { dataSize = 0; nodeData = new NodeStruct[dataSize]; for (int i = 0; i != dataSize; i++) { nodeData[i] = new NodeStruct(); } }
public override void ReadFromFile(BinaryReader reader) { base.ReadFromFile(reader); dataSize = reader.ReadByte(); nodeData = new NodeStruct[dataSize]; for (int i = 0; i != dataSize; i++) { nodeData[i] = new NodeStruct(reader); } }
public void AddChild(string meshFileName) { IntPtr nodePtr = ICreateByNodeFullName(meshFileName); AddChildInternal(this.NativeHandle, nodePtr); NodeStruct newStruct = new NodeStruct(); newStruct._nodeFileName = meshFileName; newStruct._nodePtr = nodePtr; _childNodeList.Add(newStruct); }
public override void ReadFromFile(MemoryStream reader, bool isBigEndian) { base.ReadFromFile(reader, isBigEndian); dataSize = reader.ReadByte8(); nodeData = new NodeStruct[dataSize]; for (int i = 0; i != dataSize; i++) { nodeData[i] = new NodeStruct(reader, isBigEndian); } }
protected Point[] BacktrackNodes(NodeStruct start) { var res = new List <Point>(); var n = start; res.Add(new Point(n.X, n.Y)); while (n.ParentX != -1) { n = _grid[n.ParentX + n.ParentY * _width]; res.Add(new Point(n.X, n.Y)); } return(res.ToArray()); }
void CreatePrenode(int parentId, int prenodeId, int precond) //Create Prenode { NodeStruct parent = nodeSet[parentId]; Rect parentRect = parent.rectangle; PrenodeStruct newPrenode = new PrenodeStruct(); newPrenode.nodeId = prenodeId; newPrenode.parentId = parent.nodeId; newPrenode.futureId = parent.nodeId; newPrenode.condId = precond; float nX = parentRect.x + width + width / 4; float nY = parentRect.y; newPrenode.rectangle = new Rect(nX, nY, preWidth, preHeight); prenodeSet.Add(newPrenode.nodeId, newPrenode); }
void CreateFirst() //Create first Step/Node { NodeStruct newNode = new NodeStruct(); newNode.heightWindow = 110f; newNode.nodeId = temporalId; newNode.parentId = -1; newNode.nodeName = "Name Step"; newNode.nodeDescription = "Description Step"; newNode.conditionId = 0; newNode.consequenceId = 0; newNode.rectangle = new Rect(10f, 20f, width, height); //Initialize first windows on pos (10f, 20f) newNode.conditions = new List <ConditionStructUI>(); newNode.consequences = new List <ConsequenceStructUI>(); nodeSet.Add(newNode.nodeId, newNode); }
private void btn_add_Click(object sender, EventArgs e) { string suo = cob_suo.SelectedText.Trim(); string zhan = cob_zhan.SelectedText.Trim(); string xianlu = cob_xianlu.SelectedText.Trim(); string taiqu = txt_taiqu.Text.Trim(); NodeStruct node = new NodeStruct(); if (suo == "" && zhan == "" && xianlu == "" && taiqu == "") { MessageBox.Show("请输入信息"); } else if (!(suo != "" && zhan != "" && xianlu != "") && taiqu != "") { MessageBox.Show("请选择台区所在外置"); } }
void CreateNode(int parentId, int prenodeId) { NodeStruct parent = nodeSet[parentId]; Rect parentRect = parent.rectangle; NodeStruct newNode = new NodeStruct(); newNode.heightWindow = 110f; newNode.nodeId = prenodeId; newNode.parentId = parent.nodeId; newNode.nodeName = "New Node"; newNode.nodeDescription = "New Description"; newNode.conditionId = 0; newNode.consequenceId = 0; float nX = prenodeSet[prenodeId].rectangle.x; float nY = prenodeSet[prenodeId].rectangle.y; newNode.rectangle = new Rect(nX, nY, width, height); newNode.conditions = new List <ConditionStructUI>(); newNode.consequences = new List <ConsequenceStructUI>(); nodeSet.Add(newNode.nodeId, newNode); prenodeSet.Remove(prenodeId); }
void WindowFunctionPreNode(int windowID) { bool keep = true; PrenodeStruct tmpPreode = prenodeSet[windowID]; GUI.DragWindow(new Rect(0, 0, preWidth, heightElements)); EditorGUILayout.BeginHorizontal(); tmpPreode.futureId = EditorGUILayout.IntField(tmpPreode.futureId); if (GUILayout.Button("Reference")) { if (nodeSet.ContainsKey(tmpPreode.futureId)) { NodeStruct tmpNd = nodeSet[tmpPreode.parentId]; ConditionStructUI tmpNc = tmpNd.conditions[tmpPreode.condId]; tmpNc.nextId = tmpPreode.futureId; tmpNd.conditions[tmpPreode.condId] = tmpNc; nodeSet[tmpPreode.parentId] = tmpNd; prenodeSet.Remove(tmpPreode.nodeId); keep = false; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("New")) { CreateNode(tmpPreode.parentId, tmpPreode.nodeId); keep = false; } EditorGUILayout.EndHorizontal(); if (keep) { prenodeSet[windowID] = tmpPreode; } }
public void Start() { GameSignals.PauseGame.AddListener(Pause); runner = FindObjectOfType <DialogueRunner>(); List <Node> nodes = new List <Node>(runner.yarnProject.GetProgram().Nodes.Values); //runner.onNodeComplete.AddListener(NodeComplete); for (int i = 0; i < nodes.Count; ++i) { NodeStruct node = new NodeStruct(nodes[i]); switch (node.type) { case NodeType.Joke: jokeNodes.Add(nodes[i]); break; case NodeType.Work: workNodes.Add(nodes[i]); break; case NodeType.Lifestyle: lifestyleNodes.Add(nodes[i]); break; case NodeType.Relationship: relationshipNodes.Add(nodes[i]); break; } nodeDict[node.node.Name] = node; } runner.AddCommandHandler <string>("WaitForType", WaitForSignal); StartCoroutine(WaitForSeconds(0.1f, () => runner.StartDialogue("Node"))); }
private static bool LoadFromOtb() { FileLoader fileLoader = new FileLoader(); if (!fileLoader.OpenFile("Data/Items/items.otb", "OTBI")) { Logger.LogOperationFailed("OTB file could not be loaded!"); return(false); } byte type; NodeStruct node = fileLoader.GetChildNode(null, out type); MemoryStream props; if (fileLoader.GetProps(node, out props)) { //4 byte flags //attributes //0x01 = version data props.ReadUInt32(); props.ReadByte(); byte attr = (byte)props.ReadByte(); if (attr == 0x01)//ROOT_ATTR_VERSION { ushort datalen = props.ReadUInt16(); if (datalen != 140) // 3 integers + 128 bytes { Logger.LogOperationFailed("OTB file is in invalid format!"); return(false); } DwMajorVersion = props.ReadUInt32(); DwMinorVersion = props.ReadUInt32(); DwBuildNumber = props.ReadUInt32(); } } if (DwMajorVersion == 0xFFFFFFFF) { Logger.Log(LogLevels.Warning, "items.otb using generic client version!"); } else if (DwMajorVersion != 3) { Logger.LogOperationFailed("Old version detected, a newer version of items.otb is required."); return(false); } else if (DwMinorVersion < (uint)OtbClientVersion.V1076) { Logger.LogOperationFailed("A newer version of items.otb is required."); return(false); } node = fileLoader.GetChildNode(node, out type); while (node != null) { if (!fileLoader.GetProps(node, out props)) { Logger.LogOperationFailed("OTB file is in invalid format!"); return(false); } ItemFlags flags = (ItemFlags)props.ReadUInt32(); ushort serverId = 0; ushort clientId = 0; ushort speed = 0; ushort wareId = 0; byte lightLevel = 0; byte lightColor = 0; byte alwaysOnTopOrder = 0; int attrib; while ((attrib = props.ReadByte()) != -1) { ushort datalen = props.ReadUInt16(); switch ((ItemAttributes)attrib) { case ItemAttributes.ServerId: serverId = props.ReadUInt16(); if (serverId > 30000 && serverId < 30100) { serverId -= 30000; } break; case ItemAttributes.ClientId: clientId = props.ReadUInt16(); break; case ItemAttributes.Speed: speed = props.ReadUInt16(); break; case ItemAttributes.Light2: lightLevel = (byte)props.ReadUInt16(); lightColor = (byte)props.ReadUInt16(); break; case ItemAttributes.TopOrder: alwaysOnTopOrder = (byte)props.ReadByte(); break; case ItemAttributes.WareId: wareId = props.ReadUInt16(); break; default: props.ReadBytes(datalen); break; } } if (!ReverseItemDict.ContainsKey(clientId)) { ReverseItemDict[clientId] = serverId; } if (!Templates.ContainsKey(serverId)) { Templates[serverId] = new ItemTemplate(); } ItemTemplate item = Templates[serverId]; item.DoesBlockSolid = flags.HasFlag(ItemFlags.BlocksSolid); item.DoesBlockProjectile = flags.HasFlag(ItemFlags.BlocksProjectile); item.DoesBlockPathFinding = flags.HasFlag(ItemFlags.BlocksPathFinding); item.HasHeight = flags.HasFlag(ItemFlags.HasHeight); item.IsUseable = flags.HasFlag(ItemFlags.Useable); item.IsPickupable = flags.HasFlag(ItemFlags.Pickupable); item.IsMoveable = flags.HasFlag(ItemFlags.Moveable); item.IsStackable = flags.HasFlag(ItemFlags.Stackable); item.IsAlwaysOnTop = flags.HasFlag(ItemFlags.AlwaysOnTop); item.IsVertical = flags.HasFlag(ItemFlags.Vertical); item.IsHorizontal = flags.HasFlag(ItemFlags.Horizontal); item.IsHangable = flags.HasFlag(ItemFlags.Hangable); item.AllowDistanceRead = flags.HasFlag(ItemFlags.AllowDistanceRead); item.IsRotatable = flags.HasFlag(ItemFlags.Rotatable); item.CanReadText = flags.HasFlag(ItemFlags.Readable); item.CanLookThrough = flags.HasFlag(ItemFlags.LookThrough); item.IsAnimation = flags.HasFlag(ItemFlags.Animation); // item.WalkStack = flags.HasFlag(ItemFlags.FullTile); item.ForceUse = flags.HasFlag(ItemFlags.ForceUse); item.Group = (ItemGroups)type; switch ((ItemGroups)type) { case ItemGroups.Container: item.Type = ItemTypes.Container; break; case ItemGroups.Door: item.Type = ItemTypes.Door; break; case ItemGroups.MagicField: item.Type = ItemTypes.MagicField; break; case ItemGroups.Teleport: item.Type = ItemTypes.Teleport; break; } item.Id = serverId; item.ClientId = clientId; item.Speed = speed; item.LightLevel = lightLevel; item.LightColor = lightColor; item.WareId = wareId; item.AlwaysOnTopOrder = alwaysOnTopOrder; node = fileLoader.GetNextNode(node, out type); } fileLoader.Close(); return(true); }
void WindowFunction(int windowID) { if (nodeSet.ContainsKey(windowID)) { NodeStruct tmpNode = nodeSet[windowID]; GUI.DragWindow(new Rect(0, 0, width, heightElements)); EditorGUILayout.BeginHorizontal(); tmpNode.nodeName = EditorGUILayout.TextField(nodeSet[windowID].nodeName); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); tmpNode.nodeDescription = EditorGUILayout.TextField(nodeSet[windowID].nodeDescription); EditorGUILayout.EndHorizontal(); for (int i = 0; i < tmpNode.consequences.Count; i++) { ConsequenceStructUI cons = tmpNode.consequences[i]; int oldPos = cons.popupPos; EditorGUILayout.BeginHorizontal(); cons.popupPos = EditorGUILayout.Popup(cons.popupPos, optionsConsequences); if (oldPos != cons.popupPos) { if (oldPos == 6 || oldPos == 7) { tmpNode.heightWindow -= 20f; } if (cons.popupPos == 6 || cons.popupPos == 7) { tmpNode.heightWindow += 20f; cons.primString = "ComponentName"; } if (cons.popupPos == 3 || cons.popupPos == 2) { tmpNode.heightWindow += 20f; cons.primString = "Reason"; } } if (cons.popupPos < 2) { cons.integer = EditorGUILayout.IntField(cons.integer); //Timer if (cons.integer < 0) { cons.integer = 0; } } else if (cons.popupPos < 4) { cons.primString = EditorGUILayout.TextField(cons.primString); //Finish } else if (cons.popupPos < 6) { cons.objectAtr = EditorGUILayout.ObjectField(cons.objectAtr, typeof(Object), true); //Interact } else if (cons.popupPos < 8) { //Touch cons.objectAtr = EditorGUILayout.ObjectField(cons.objectAtr, typeof(Object), true); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); cons.primString = EditorGUILayout.TextField(cons.primString); } EditorGUILayout.EndHorizontal(); tmpNode.consequences[i] = cons; } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Add Consequence")) { ConsequenceStructUI tmpCs = new ConsequenceStructUI(); tmpCs.popupPos = 0; tmpCs.integer = 1; tmpCs.objectAtr = null; tmpCs.primString = "null2"; tmpNode.consequences.Add(tmpCs); tmpNode.consequenceId = tmpNode.consequenceId + 1; tmpNode.heightWindow += 20f; } EditorGUILayout.EndHorizontal(); for (int i = 0; i < tmpNode.conditions.Count; i++) { ConditionStructUI cond = tmpNode.conditions[i]; GUIStyle gsTest = new GUIStyle(); gsTest.normal.textColor = colors[i % colors.Length]; EditorGUILayout.BeginHorizontal(); cond.popupPos = EditorGUILayout.Popup(cond.popupPos, optionsConditions, gsTest); if (cond.popupPos == 0) { cond.time = EditorGUILayout.IntField(cond.time); if (cond.time < 0) { cond.time = 0; } } else if (cond.popupPos == 1) { cond.target = EditorGUILayout.ObjectField(cond.target, typeof(Object), true); } else if (cond.popupPos == 2) { cond.target = EditorGUILayout.ObjectField(cond.target, typeof(Object), true); } EditorGUILayout.EndHorizontal(); tmpNode.conditions[i] = cond; } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Add Condition")) { ConditionStructUI tmpC = new ConditionStructUI(); tmpC.popupPos = 0; tmpC.nextId = temporalId + 1; ++temporalId; tmpC.time = 1; tmpC.target = null; tmpNode.consequenceId = tmpNode.conditionId + 1; tmpC.color = colors[tmpNode.conditionId % colors.Length]; tmpNode.conditions.Add(tmpC); tmpNode.heightWindow += 20f; CreatePrenode(windowID, tmpC.nextId, tmpNode.conditionId); tmpNode.conditionId++; } EditorGUILayout.EndHorizontal(); nodeSet[windowID] = tmpNode; } }
void OnGUI() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(text); if (GUILayout.Button("Restart")) { temporalId = 0; nodeSet = new Dictionary <int, NodeStruct>(); prenodeSet = new Dictionary <int, PrenodeStruct>(); //listNode = new List<NodeStruct>(); CreateFirst(); } if (GUILayout.Button("Recover")) { if (listNode.Count > 0) { ListToDictionary(); } else { StorytellController smg = GameObject.Find("Controller").GetComponent <StorytellController>() as StorytellController; List <StorytellController.StepStruct> stepList = smg.listSteps; if (stepList.Count > 0) { foreach (StorytellController.StepStruct scTmp in stepList) { NodeStruct nsTmp = new NodeStruct(); nsTmp.nodeId = scTmp.id; nsTmp.nodeName = scTmp.nameStep; nsTmp.nodeDescription = scTmp.descriptionStep; nsTmp.rectangle = scTmp.rectangle; nsTmp.heightWindow = scTmp.heightWindow; nsTmp.parentId = scTmp.parentId; List <ConditionStructUI> conditions = new List <ConditionStructUI>(); nsTmp.conditionId = 0; foreach (StorytellController.ConditionStruct cdTmp in scTmp.conditions) { ConditionStructUI tmpC = new ConditionStructUI(); tmpC.nextId = cdTmp.nextId; tmpC.popupPos = cdTmp.popupPos; tmpC.time = cdTmp.time; tmpC.target = cdTmp.objTarget; tmpC.color = cdTmp.color; nsTmp.conditionId++; conditions.Add(tmpC); } nsTmp.conditions = conditions; List <ConsequenceStructUI> consequences = new List <ConsequenceStructUI>(); nsTmp.consequenceId = 0; foreach (StorytellController.ConsequenceStruct csTmp in scTmp.consequences) { ConsequenceStructUI tmpC = new ConsequenceStructUI(); tmpC.popupPos = csTmp.popupPos; tmpC.integer = csTmp.integer; tmpC.objectAtr = csTmp.objectAtr; tmpC.primString = csTmp.secondaryAtribute; nsTmp.consequenceId++; consequences.Add(tmpC); } nsTmp.consequences = consequences; listNode.Add(nsTmp); } ListToDictionary(); } else { text = "Create your Storytell: No storytell saved"; } } } if (nodeSet.Count == 0) { temporalId = 0; } List <int> keysN = new List <int>(nodeSet.Keys); //We are going to iterate over dictionary keys if (GUILayout.Button("Save")) { if (prenodeSet.Count == 0) //All prenodes assigned { savedId = temporalId; List <StorytellController.StepStruct> stepList = new List <StorytellController.StepStruct>(); listNode = new List <NodeStruct>(); //Set listNode values, because it's Serilizable foreach (int key in keysN) { NodeStruct node = nodeSet[key]; listNode.Add(node); StorytellController.StepStruct tmpStep = new StorytellController.StepStruct(); tmpStep.id = node.nodeId; tmpStep.nameStep = node.nodeName; tmpStep.descriptionStep = node.nodeDescription; tmpStep.rectangle = node.rectangle; tmpStep.heightWindow = node.heightWindow; tmpStep.parentId = node.parentId; List <StorytellController.ConsequenceStruct> consList = new List <StorytellController.ConsequenceStruct>(); foreach (ConsequenceStructUI cons in node.consequences) { StorytellController.ConsequenceStruct tcons = new StorytellController.ConsequenceStruct(); tcons.type = optionsConsequences[cons.popupPos]; tcons.integer = cons.integer; string TobjArt; if (cons.objectAtr == null) { TobjArt = "null"; } else { TobjArt = cons.objectAtr.name; } tcons.primaryAtribute = TobjArt; tcons.secondaryAtribute = cons.primString; //New tcons.popupPos = cons.popupPos; tcons.objectAtr = cons.objectAtr; consList.Add(tcons); } tmpStep.consequences = consList; List <StorytellController.ConditionStruct> condList = new List <StorytellController.ConditionStruct>(); foreach (ConditionStructUI cond in node.conditions) { StorytellController.ConditionStruct tcond = new StorytellController.ConditionStruct(); tcond.nextId = cond.nextId; tcond.type = optionsConditions[cond.popupPos]; tcond.time = cond.time; string target; if (cond.target == null) { target = "null"; } else { target = cond.target.name; } tcond.target = target; //New tcond.popupPos = cond.popupPos; tcond.objTarget = cond.target; tcond.color = cond.color; condList.Add(tcond); } tmpStep.conditions = condList; stepList.Add(tmpStep); } StorytellController smg = GameObject.Find("Controller").GetComponent <StorytellController>() as StorytellController; smg.listSteps = stepList; text = "Create your Storytell:"; } else //Still some prenodes without assign { text = "Create your Storytell: Assign all steps"; } } EditorGUILayout.EndHorizontal(); BeginWindows(); foreach (int key in keysN) { NodeStruct node = nodeSet[key]; foreach (ConditionStructUI cond in node.conditions) { int chId = cond.nextId; if (nodeSet.ContainsKey(chId) || prenodeSet.ContainsKey(chId)) { DrawLine(chId, node.nodeId, cond.color); } } node.rectangle = SetRectangle(node.rectangle); node.rectangle = GUI.Window(node.nodeId, node.rectangle, WindowFunction, "" + node.nodeId); node.rectangle.height = node.heightWindow; nodeSet[key] = node; } List <int> keysP = new List <int>(prenodeSet.Keys); foreach (int key in keysP) { PrenodeStruct prenode = prenodeSet[key]; prenode.rectangle = SetRectangle(prenode.rectangle); prenode.rectangle = GUI.Window(prenode.nodeId, prenode.rectangle, WindowFunctionPreNode, "Create Node"); prenodeSet[key] = prenode; } EndWindows(); }
private static bool ParseTileArea(NodeStruct node, FileLoader fileLoader) { byte type; MemoryStream props; if (!fileLoader.GetProps(node, out props)) { return(false); } int baseX = props.ReadUInt16(); int baseY = props.ReadUInt16(); int baseZ = props.ReadByte(); NodeStruct nodeTile = fileLoader.GetChildNode(node, out type); while (nodeTile != null) { if (type != (byte)OtbmNodeTypes.Tile && type != (byte)OtbmNodeTypes.HouseTile) { Logger.Log(LogLevels.Error, "NOT TILE OR HOUSETILE"); return(false); } if (!fileLoader.GetProps(nodeTile, out props)) { return(false); } int pX = baseX + props.ReadByte(); int pY = baseY + props.ReadByte(); int pZ = baseZ; TileFlags tileFlags = TileFlags.None; bool isHouseTile = false; Item groundItem = null; House house = null; Tile tile = null; if (type == (byte)OtbmNodeTypes.HouseTile) { //TODO: HOUSES uint houseId = props.ReadUInt32(); if (!Houses.ContainsKey(houseId)) { Houses.Add(houseId, new House { HouseId = houseId }); } house = Houses[houseId]; tile = new HouseTile(pX, pY, pZ, house); house.AddTile((HouseTile)tile); isHouseTile = true; } int attribute; while ((attribute = props.ReadByte()) != -1) { switch ((OtbmAttributes)attribute) { case OtbmAttributes.TileFlags: TileFlags flags = (TileFlags)props.ReadUInt32(); if (flags.HasFlag(TileFlags.ProtectionZone)) { tileFlags |= TileFlags.ProtectionZone; } else if (flags.HasFlag(TileFlags.NoPvpZone)) { tileFlags |= TileFlags.NoPvpZone; } else if (flags.HasFlag(TileFlags.PvpZone)) { tileFlags |= TileFlags.PvpZone; } if (flags.HasFlag(TileFlags.NoLogout)) { tileFlags |= TileFlags.NoLogout; } break; case OtbmAttributes.Item: Item item = Item.CreateItem(props); if (item == null) { return(false); } if (isHouseTile && item.IsMovable) { Logger.Log(LogLevels.Warning, "Moveable item found in house: " + house.HouseId); item.DecrementReferenceCounter(); } else { if (item.Count <= 0) { item.Count = 1; } if (tile != null) { tile.InternalAddThing(item); item.StartDecaying(); item.IsLoadedFromMap = true; } else if (item.IsGroundTile) { groundItem = item; } else { tile = CreateTile(groundItem, item, pX, pY, pZ); tile.InternalAddThing(item); item.StartDecaying(); item.IsLoadedFromMap = true; } } break; default: Logger.Log(LogLevels.Warning, "Unknown tile attribute on; X:" + pX + ", Y:" + pY + ", Z:" + pZ + "!"); return(false); } } NodeStruct nodeItem = fileLoader.GetChildNode(nodeTile, out type); while (nodeItem != null) { if (type != (byte)OtbmNodeTypes.Item) { return(false); } MemoryStream stream; if (!fileLoader.GetProps(nodeItem, out stream)) { return(false); } Item item = Item.CreateItem(stream); if (item == null) { return(false); } //TODO: UNSERIALIZE if (isHouseTile && item.IsMovable) { Logger.Log(LogLevels.Warning, "Moveable item found in house: " + house.HouseId); item.DecrementReferenceCounter(); } else { if (item.Count <= 0) { item.Count = 1; } if (tile != null) { tile.InternalAddThing(item); item.StartDecaying(); item.IsLoadedFromMap = true; } else if (item.IsGroundTile) { groundItem = item; } else { tile = CreateTile(groundItem, item, pX, pY, pZ); tile.InternalAddThing(item); item.StartDecaying(); item.IsLoadedFromMap = true; } } nodeItem = nodeItem.Next; } if (tile == null) { tile = CreateTile(groundItem, null, pX, pY, pZ); } tile.SetFlag(tileFlags); SetTile(tile); nodeTile = fileLoader.GetNextNode(nodeTile, out type); } return(true); }
private static bool LoadOtbm() { FileLoader fileLoader = new FileLoader(); if (!fileLoader.OpenFile("Data/World/" + ConfigManager.Instance[ConfigStr.MapName] + ".otbm", "OTBM")) { Logger.LogOperationFailed("Could not open map file: " + ConfigManager.Instance[ConfigStr.MapName]); return(false); } byte type; NodeStruct root = fileLoader.GetChildNode(null, out type); MemoryStream props; if (!fileLoader.GetProps(root, out props)) { Logger.LogOperationFailed("Could not read root property!"); return(false); } props.ReadByte(); uint version = props.ReadUInt32(); Width = props.ReadUInt16(); Height = props.ReadUInt16(); uint majorVersionItems = props.ReadUInt32(); uint minorVersionItems = props.ReadUInt32(); if (version <= 0) { //In otbm version 1 the count variable after splashes/fluidcontainers and stackables //are saved as attributes instead, this solves alot of problems with items //that is changed (stackable/charges/fluidcontainer/splash) during an update. Logger.LogOperationFailed("This map need to be upgraded by using the latest map editor version to be able to load correctly."); return(false); } if (version > 2) { Logger.LogOperationFailed("Unknown OTBM version detected."); return(false); } if (majorVersionItems < 3) { Logger.LogOperationFailed("This map need to be upgraded by using the latest map editor version to be able to load correctly."); return(false); } if (majorVersionItems > ItemManager.DwMajorVersion) { Logger.LogOperationFailed("The map was saved with a different items.otb version, an upgraded items.otb is required."); return(false); } if (minorVersionItems < (uint)OtbClientVersion.V810) { Logger.LogOperationFailed("This map needs to be updated."); return(false); } if (minorVersionItems > ItemManager.DwMinorVersion) { Logger.Log(LogLevels.Warning, "This map needs an updated items.otb."); } NodeStruct nodeMap = fileLoader.GetChildNode(root, out type); if (type != (byte)OtbmNodeTypes.MapData) { Logger.LogOperationFailed("Could not read data node."); return(false); } if (!fileLoader.GetProps(nodeMap, out props)) { Logger.LogOperationFailed("Could not read map data attributes."); return(false); } int attribute; while ((attribute = props.ReadByte()) != -1) { switch ((OtbmAttributes)attribute) { case OtbmAttributes.Description: Description = props.GetString(); break; case OtbmAttributes.ExtSpawnFile: SpawnFile = string.Format("Data/World/{0}", props.GetString()); break; case OtbmAttributes.ExtHouseFile: HouseFile = string.Format("Data/World/{0}", props.GetString()); break; default: Logger.LogOperationFailed("Map file unknown header node!"); return(false); } } NodeStruct nodeMapData = fileLoader.GetChildNode(nodeMap, out type); while (nodeMapData != null) { if (type == (byte)OtbmNodeTypes.TileArea) { if (!ParseTileArea(nodeMapData, fileLoader)) { Logger.LogOperationFailed("Could not parse tile area!"); return(false); } } else if (type == (byte)OtbmNodeTypes.Towns) { if (!ParseTowns(nodeMapData, fileLoader)) { Logger.LogOperationFailed("Could not parse towns!"); return(false); } } else if (type == (byte)OtbmNodeTypes.Waypoints && version > 1) { if (!ParseWaypoints(nodeMapData, fileLoader)) { Logger.LogOperationFailed("Could not parse waypoints!"); return(false); } } else { Logger.LogOperationFailed("Unknown map node!"); return(false); } nodeMapData = fileLoader.GetNextNode(nodeMapData, out type); } fileLoader.Close(); return(true); }
protected short Manhattan(NodeStruct point1, Point point2) { return((short)(Math.Abs(point1.X - point2.X) + Math.Abs(point1.Y - point2.Y))); }