/// <summary>Removes the selected node from the world.</summary> private void removeSelHotspot() { foreach (Node node in world.Nodes) { if (node.OwnsHotspot == selectedHotspot) node.OwnsHotspot = null; } world.removeHotspot(selectedHotspot); selectedHotspot = null; loadObjectEditor(); }
/// <summary>Updates all variables in this mode.</summary> /// <param name="gameTime">The current game time.</param> public override void Update(GameTime gameTime) { base.Update(gameTime); FInt elapsed = (FInt)gameTime.ElapsedGameTime.TotalSeconds; // update gui if (Inp.OldMse.Position != Inp.Mse.Position) desktop.mouseMove(Inp.Mse.Position); GUI.Desktop.Event evnt = Desktop.Event.MouseRightUp; bool guiOwnedInput = false; if (Inp.OldMse.LeftButton == ButtonState.Pressed && Inp.Mse.LeftButton == ButtonState.Released) guiOwnedInput |= desktop.PerformMouseEvent(Desktop.Event.MouseLeftUp, Inp.Mse.Position, Inp); if (Inp.OldMse.LeftButton == ButtonState.Released && Inp.Mse.LeftButton == ButtonState.Pressed) guiOwnedInput |= desktop.PerformMouseEvent(Desktop.Event.MouseLeftDown, Inp.Mse.Position, Inp); if (Inp.OldMse.RightButton == ButtonState.Pressed && Inp.Mse.RightButton == ButtonState.Released) guiOwnedInput |= desktop.PerformMouseEvent(Desktop.Event.MouseRightUp, Inp.Mse.Position, Inp); if (Inp.OldMse.RightButton == ButtonState.Released && Inp.Mse.RightButton == ButtonState.Pressed) guiOwnedInput |= desktop.PerformMouseEvent(Desktop.Event.MouseRightUp, Inp.Mse.Position, Inp); Keys[] newKeys = Inp.Key.GetPressedKeys(); if (newKeys.Length != 0) guiOwnedInput |= desktop.PerformKeyEvent(newKeys, Inp); if (guiOwnedInput) { hoveredNode = null; hoveredSeg = null; hoveredSegEnd = null; hoveredSegEndOwner = null; hoveredGeo = null; hoveredHotspot = null; isDragging = false; } else { // prepare grid manager world.Grid.startNewUpdate(gameTime); // move camera if (Inp.Key.IsKeyDown(Keys.OemPlus)) world.Cam.Zoom += world.Cam.Zoom * elapsed; if (Inp.Key.IsKeyDown(Keys.OemMinus)) world.Cam.Zoom -= world.Cam.Zoom * elapsed; if (Inp.Key.IsKeyDown(Keys.A)) world.Cam.CenterX -= (700 / world.Cam.Zoom) * elapsed; if (Inp.Key.IsKeyDown(Keys.D)) world.Cam.CenterX += (700 / world.Cam.Zoom) * elapsed; if (Inp.Key.IsKeyDown(Keys.W)) world.Cam.CenterY -= (700 / world.Cam.Zoom) * elapsed; if (Inp.Key.IsKeyDown(Keys.S)) world.Cam.CenterY += (700 / world.Cam.Zoom) * elapsed; world.Cam.Zoom += (FInt)(Inp.Mse.ScrollWheelValue - Inp.OldMse.ScrollWheelValue) / (FInt)120 * (FInt).1d * world.Cam.Zoom; world.Cam.refreshCorners(); // get cursor world coordinates VectorF cursorPos = world.Cam.screenToWorld(new Vector2((float)Inp.Mse.X, (float)Inp.Mse.Y)); // check for hovered node, segment, segment end, and hotspot hoveredNode = world.NodeAtPoint(cursorPos, false); hoveredSeg = (hoveredNode == null) ? world.segmentAtPoint(cursorPos, null) : null; hoveredSegEnd = world.SegmentEndAtPoint(cursorPos); if (hoveredSegEnd != null) { foreach (Segment seg in world.Segments) { if (seg.Nodes[0] == hoveredSegEnd || seg.Nodes[1] == hoveredSegEnd) { hoveredSegEndOwner = seg.Owner; break; } } } else { hoveredSegEndOwner = null; } hoveredHotspot = world.HotspotAtPoint(cursorPos); // test geo vertices hoveredGeo = world.geoAtPoint(cursorPos, out hoveredGeoVertex, true); // test geo lines if (hoveredGeo == null) { hoveredGeo = world.geoAtPoint(cursorPos, out hoveredGeoVertex, false); hoveredGeoIsLine = true; } else { hoveredGeoIsLine = false; } // if the user just released the left mouse button if (Inp.OldMse.LeftButton == ButtonState.Pressed && Inp.Mse.LeftButton == ButtonState.Released) { if (selectedSegEnd != null) { // do nothing } // add node else if (btnAddNode.Pressed && cmbNodeTypes.SelectedIndex != -1 && selectedGeo == null && (selectedNode == null || isDragging) && selectedSeg == null && selectedHotspot == null) { bool useHoveredEnd = (hoveredSegEnd != null && (selectedNode == null || selectedNode.Owner == hoveredSegEndOwner)); // add node Node node = new Node(world, world.NodeTypes[cmbEditorAddNodeType.SelectedIndex]); node.Pos = useHoveredEnd ? hoveredSegEnd.Pos : cursorPos; node.Active = true; if (selectedNode != null && isDragging) { node.Owner = selectedNode.Owner; if (selectedNode.NumSegments < selectedNode.Segments.Length) // add segment too { Segment seg = new Segment(world); seg.Owner = selectedNode.Owner; seg.Nodes[0] = selectedNode; seg.Nodes[1] = node; selectedNode.addSegment(seg, false); node.addSegment(seg, false); seg.refreshMath(); seg.EndLength[0] = seg.Length; seg.EndLength[1] = seg.Length; seg.refreshEndLocs(); world.addSegment(seg); } } else if (selectedNode == null && hoveredSegEnd != null) { node.Owner = hoveredSegEndOwner; } else if (cmbEditorAddNodeOwner.SelectedIndex != 0) { node.Owner = world.Players[cmbEditorAddNodeOwner.SelectedIndex - 1]; } if (useHoveredEnd) { // link segments to it foreach (Segment seg in (hoveredSegEndOwner == null ? world.Segments : hoveredSegEndOwner.Segments)) { for (int i = 0; i < 2; i++) { if (seg.Nodes[i] == hoveredSegEnd) { seg.Nodes[i] = node; break; } } } } world.addNode(node); selectedNode = node; selectedSeg = null; loadObjectEditor(); } // add segment else if (btnAddSeg.Pressed && isDragging && selectedSeg == null && selectedGeo == null && (selectedNode == null || selectedNode.NumSegments < selectedNode.Segments.Length) && selectedHotspot == null) { Segment seg = new Segment(world); seg.Owner = (selectedNode != null) ? selectedNode.Owner : (hoveredNode != null) ? hoveredNode.Owner : (cmbEditorAddSegOwner.SelectedIndex > 0) ? world.Players[cmbEditorAddSegOwner.SelectedIndex - 1] : null; if (selectedNode != null) { seg.Nodes[0] = selectedNode; seg.Owner = selectedNode.Owner; selectedNode.addSegment(seg, false); } else { seg.State[1] = SegmentSkel.SegState.Retracting; seg.Nodes[0] = new Node(world); seg.Nodes[0].Pos = lastClickedPoint; seg.Nodes[0].Active = false; seg.Nodes[0].Destroyed = true; seg.Nodes[0].initSegArrays(0); } if (hoveredNode != null && hoveredNode.NumSegments != hoveredNode.Segments.Length && (selectedNode == null || (hoveredNode != selectedNode && hoveredNode.Owner == selectedNode.Owner && hoveredNode.relatedSeg(selectedNode) == -1))) { seg.Nodes[1] = hoveredNode; hoveredNode.addSegment(seg, false); } else { seg.State[0] = SegmentSkel.SegState.Building; seg.Nodes[1] = new Node(world); seg.Nodes[1].Pos = cursorPos; seg.Nodes[1].Active = false; seg.Nodes[1].Destroyed = true; seg.Nodes[1].initSegArrays(0); } seg.refreshMath(); seg.EndLength[0] = seg.Length; seg.EndLength[1] = seg.Length; seg.refreshEndLocs(); world.addSegment(seg); selectedNode = null; selectedSeg = seg; loadObjectEditor(); } // add geo vertex else if (btnAddGeo.Pressed && selectedNode == null && selectedSeg == null && selectedSegEnd == null && selectedHotspot == null) { // add vertex to existing geo if (selectedGeo != null && !selectedGeoIsLine && isDragging && (selectedGeoVertex == 0 || selectedGeoVertex == selectedGeo.Vertices.Length - 1)) { VectorF[] vertices; if (selectedGeo.Vertices.Length == 1) { vertices = new VectorF[selectedGeo.Vertices.Length + 1]; vertices[0] = cursorPos; vertices[1] = selectedGeo.Vertices[0]; } else if (selectedGeoVertex == 0) { vertices = new VectorF[selectedGeo.Vertices.Length + 2]; selectedGeo.Vertices.CopyTo(vertices, 2); vertices[0] = cursorPos; vertices[1] = selectedGeo.Vertices[0]; } else { vertices = new VectorF[selectedGeo.Vertices.Length + 2]; selectedGeo.Vertices.CopyTo(vertices, 0); vertices[selectedGeo.Vertices.Length] = selectedGeo.Vertices[selectedGeo.Vertices.Length - 1]; vertices[selectedGeo.Vertices.Length + 1] = cursorPos; selectedGeoVertex = vertices.Length - 1; } world.Grid.Rect(selectedGeo.UpperLeft, selectedGeo.LowerRight, selectedGeo, world.gridRemoveGeo); selectedGeo.Vertices = vertices; selectedGeo.refreshMath(new Vector2((float)tGeo.Width, (float)tGeo.Height)); world.Grid.Rect(selectedGeo.UpperLeft, selectedGeo.LowerRight, selectedGeo, world.gridAddGeo); selectedGeoIsLine = false; loadObjectEditor(); } // add vertex in the middle of a line else if (hoveredGeo != null && hoveredGeoIsLine) { VectorF[] vertices = new VectorF[hoveredGeo.Vertices.Length + 2]; int v2 = (hoveredGeoVertex == hoveredGeo.Vertices.Length - 1) ? 0 : hoveredGeoVertex + 1; float dist = (float)Calc.getAdj(VectorF.Distance(cursorPos, hoveredGeo.Vertices[hoveredGeoVertex]), Calc.LinePointDistance(cursorPos, hoveredGeo.Vertices[hoveredGeoVertex], hoveredGeo.Vertices[v2])); Vector2 dir = Vector2.Normalize((Vector2)(hoveredGeo.Vertices[v2] - hoveredGeo.Vertices[hoveredGeoVertex])); VectorF pos = (VectorF)((Vector2)hoveredGeo.Vertices[hoveredGeoVertex] + (dir * dist)); for (int i = 0; i <= hoveredGeoVertex; i++) { vertices[i] = hoveredGeo.Vertices[i]; } if (hoveredGeoVertex == selectedGeo.Vertices.Length - 1) { vertices[hoveredGeoVertex + 1] = selectedGeo.Vertices[selectedGeo.Vertices.Length - 1]; vertices[hoveredGeoVertex + 2] = pos; } else { vertices[hoveredGeoVertex + 1] = pos; vertices[hoveredGeoVertex + 2] = pos; for (int i = hoveredGeoVertex + 1; i < hoveredGeo.Vertices.Length; i++) { vertices[i + 2] = hoveredGeo.Vertices[i]; } } world.Grid.Rect(hoveredGeo.UpperLeft, hoveredGeo.LowerRight, hoveredGeo, world.gridRemoveGeo); hoveredGeo.Vertices = vertices; hoveredGeo.refreshMath(new Vector2((float)tGeo.Width, (float)tGeo.Height)); world.Grid.Rect(hoveredGeo.UpperLeft, hoveredGeo.LowerRight, hoveredGeo, world.gridAddGeo); hoveredGeoIsLine = false; hoveredGeoVertex += 2; selectedGeo = hoveredGeo; selectedGeoIsLine = false; selectedGeoVertex = hoveredGeoVertex; loadObjectEditor(); } // add new geo else if (hoveredGeo == null) { Geo geo = new Geo(world); geo.Vertices = new VectorF[] { cursorPos }; geo.CloseLoop = false; geo.Display = false; geo.refreshMath(new Vector2((float)tGeo.Width, (float)tGeo.Height)); world.addGeo(geo); selectedGeo = geo; selectedGeoIsLine = false; selectedGeoVertex = 0; loadObjectEditor(); } } else if (btnAddHotspot.Pressed && selectedNode == null && selectedSeg == null && selectedSegEnd == null && selectedGeo == null) { // add hotspot Hotspot hotspot = new Hotspot(world); hotspot.Pos = cursorPos; world.addHotspot(hotspot); selectedHotspot = hotspot; loadObjectEditor(); } selectedSegEnd = null; isDragging = false; } // if the player just released the right mouse button else if (Inp.OldMse.RightButton == ButtonState.Pressed && Inp.Mse.RightButton == ButtonState.Released) { } // user just pressed the left mouse button else if (Inp.OldMse.LeftButton == ButtonState.Released && Inp.Mse.LeftButton == ButtonState.Pressed) { lastClickedPoint = world.Cam.screenToWorld(new Vector2((float)Inp.Mse.X, (float)Inp.Mse.Y)); isDragging = false; // check for selected node selectedNode = hoveredNode; // check for selected segment end selectedSegEnd = (selectedNode == null) ? hoveredSegEnd : null; // check for selected segment selectedSeg = (selectedNode == null && selectedSegEnd == null) ? hoveredSeg : null; // check for selected hotspot selectedHotspot = (selectedNode == null && selectedSegEnd == null && selectedSeg == null) ? hoveredHotspot : null; // check for selected geo if (selectedNode == null && selectedSeg == null && selectedSegEnd == null && selectedHotspot == null) { selectedGeo = hoveredGeo; selectedGeoIsLine = hoveredGeoIsLine; selectedGeoVertex = hoveredGeoVertex; } else { selectedGeo = null; } loadObjectEditor(); } // user just pressed the right mouse button else if (Inp.OldMse.RightButton == ButtonState.Released && Inp.Mse.RightButton == ButtonState.Pressed) { } // if the left mouse button is still pressed else if (desktop.Focused == null && Inp.OldMse.LeftButton == ButtonState.Pressed && Inp.Mse.LeftButton == ButtonState.Pressed) { if (!isDragging && Vector2.Distance(world.Cam.worldToScreen(lastClickedPoint), new Vector2((float)Inp.Mse.X, (float)Inp.Mse.Y)) >= distToDrag) { isDragging = true; if (selectedNode != null) dragOffset = selectedNode.Pos - lastClickedPoint; else if (selectedSegEnd != null) dragOffset = selectedSegEnd.Pos - lastClickedPoint; else if (selectedSeg != null) dragOffset = selectedSeg.Nodes[0].Pos - lastClickedPoint; else if (selectedHotspot != null) dragOffset = selectedHotspot.Pos - lastClickedPoint; else if (selectedGeo != null) { if (selectedGeoVertex == -1) dragOffset = selectedGeo.Center - lastClickedPoint; else dragOffset = selectedGeo.Vertices[selectedGeoVertex] - lastClickedPoint; } } } // if [Del] key is pressed else if (!Inp.OldKey.IsKeyDown(Keys.Delete) && Inp.Key.IsKeyDown(Keys.Delete)) { if (selectedNode != null) removeSelNode(); else if (selectedSeg != null) removeSelSeg(); else if (selectedHotspot != null) removeSelHotspot(); else if (selectedGeo != null) removeSelGeo(); } // drag if (isDragging) { // move node if (selectedNode != null && !btnAddSeg.Pressed && (!btnAddNode.Pressed || cmbEditorAddNodeType.SelectedIndex < 0)) { moveNode(selectedNode, cursorPos + dragOffset); } // move segment end else if (selectedSegEnd != null) { moveNode(selectedSegEnd, cursorPos + dragOffset); } // move segment else if (selectedSeg != null) { VectorF moveVect = cursorPos + dragOffset - selectedSeg.Nodes[0].Pos; moveNode(selectedSeg.Nodes[0], selectedSeg.Nodes[0].Pos + moveVect); moveNode(selectedSeg.Nodes[1], selectedSeg.Nodes[1].Pos + moveVect); } // move hotspot else if (selectedHotspot != null) { moveHotspot(selectedHotspot, cursorPos + dragOffset); } // move geo/vertex else if (selectedGeo != null && !btnAddGeo.Pressed) { world.Grid.Rect(selectedGeo.UpperLeft, selectedGeo.LowerRight, selectedGeo, world.gridRemoveGeo); if (selectedGeoIsLine) { if (selectedGeoVertex == selectedGeo.Vertices.Length - 1) { selectedGeo.Vertices[0] += cursorPos + dragOffset - selectedGeo.Vertices[selectedGeoVertex]; } else { if (selectedGeoVertex != 0) selectedGeo.Vertices[selectedGeoVertex - 1] = cursorPos + dragOffset; selectedGeo.Vertices[selectedGeoVertex + 1] += cursorPos + dragOffset - selectedGeo.Vertices[selectedGeoVertex]; if (selectedGeoVertex != selectedGeo.Vertices.Length - 2) selectedGeo.Vertices[selectedGeoVertex + 2] += cursorPos + dragOffset - selectedGeo.Vertices[selectedGeoVertex]; } selectedGeo.Vertices[selectedGeoVertex] = cursorPos + dragOffset; } else if (selectedGeoVertex == -1) { VectorF toMove = cursorPos + dragOffset - selectedGeo.Center; for (int i = 0; i < selectedGeo.Vertices.Length; i++) { selectedGeo.Vertices[i] += toMove; } } else { if (selectedGeoVertex != 0 && selectedGeoVertex != selectedGeo.Vertices.Length - 1) selectedGeo.Vertices[selectedGeoVertex - 1] = cursorPos + dragOffset; selectedGeo.Vertices[selectedGeoVertex] = cursorPos + dragOffset; } selectedGeo.refreshMath(new Vector2((float)tGeo.Width, (float)tGeo.Height)); world.Grid.Rect(selectedGeo.UpperLeft, selectedGeo.LowerRight, selectedGeo, world.gridAddGeo); } } } }
/// <summary>Removes the specified hotspot from the world.</summary> /// <param name="hotspot">The hotspot to remove.</param> public void removeHotspot(Hotspot hotspot) { removeHotspot(Hotspots.IndexOf(hotspot)); }
private void moveHotspot(Hotspot hotspot, VectorF to) { // remove from grid world.Grid.Point(hotspot.Pos, hotspot, world.gridRemoveHotspot); hotspot.Pos = to; // add back into grid if (world.Hotspots.Contains(hotspot)) world.Grid.Point(hotspot.Pos, hotspot, world.gridAddHotspot); }
/// <summary>Adds the specified hotspot to the world.</summary> /// <param name="hotspot">The hotspot to add.</param> public void addHotspot(Hotspot hotspot) { if (hotspot.ID == null) hotspot.ID = getNextHotspotID(); HotspotByID.Add(hotspot.ID, hotspot); Hotspots.Add(hotspot); Grid.Point(hotspot.Pos, hotspot, gridAddHotspot); }
/// <summary>Creates a shallow copy of this Hotspot.</summary> /// <returns>A shallow copyof this Hotspot.</returns> public Hotspot Clone() { Hotspot hotspot = new Hotspot(this.InWorld); hotspot.ID = this.ID; hotspot.Pos = this.Pos; hotspot.Script = this.Script; hotspot.LastCheck = this.LastCheck; hotspot.LastCheckNum = this.LastCheckNum; return hotspot; }
/// <summary>Updates all game variables in this mode.</summary> /// <param name="gameTime">The current game time.</param> public override void Update(GameTime gameTime) { base.Update(gameTime); FInt elapsed = (FInt)gameTime.ElapsedGameTime.TotalSeconds; hoveredNode = null; hoveredSeg = null; hoveredHotspot = null; Player hPlayer = null; Player cPlayer = null; foreach (Player p in map.Players) { if (p.Type == Player.PlayerType.Human) { hPlayer = p; break; } } foreach (Player p in map.Players) { if (p.Type == Player.PlayerType.Computer) { cPlayer = p; break; } } // prepare grid manager map.Grid.startNewUpdate(gameTime); // move camera if (Inp.Key.IsKeyDown(Keys.OemPlus)) map.Cam.Zoom += map.Cam.Zoom * elapsed; if (Inp.Key.IsKeyDown(Keys.OemMinus)) map.Cam.Zoom -= map.Cam.Zoom * elapsed; if (Inp.Key.IsKeyDown(Keys.A)) map.Cam.CenterX -= (700 / map.Cam.Zoom) * elapsed; if (Inp.Key.IsKeyDown(Keys.D)) map.Cam.CenterX += (700 / map.Cam.Zoom) * elapsed; if (Inp.Key.IsKeyDown(Keys.W)) map.Cam.CenterY -= (700 / map.Cam.Zoom) * elapsed; if (Inp.Key.IsKeyDown(Keys.S)) map.Cam.CenterY += (700 / map.Cam.Zoom) * elapsed; map.Cam.Zoom += (FInt)(Inp.Mse.ScrollWheelValue - Inp.OldMse.ScrollWheelValue) / (FInt)120 * (FInt).1d * map.Cam.Zoom; map.Cam.refreshCorners(); // get cursor world coordinates VectorF cursorPos = map.Cam.screenToWorld(new Vector2((float)Inp.Mse.X, (float)Inp.Mse.Y)); /*/ find path if (!tempBool) { Node fromNode = cPlayer.Nodes[cPlayer.Nodes.Count - 1]; VectorF fromPos = fromNode.Pos; // find path VectorF nde = fromPos / cPlayer.Path.NodeSpacing; nde.X = (FInt)Math.Round((double)nde.X); nde.Y = (FInt)Math.Round((double)nde.Y); int srcNode = (int)nde.Y * cPlayer.Path.NumCols + (int)nde.X; nde = (hPlayer.Nodes[0].Pos + hPlayer.Nodes[1].Pos) / FInt.F2 / cPlayer.Path.NodeSpacing; nde.X = (FInt)Math.Round((double)nde.X); nde.Y = (FInt)Math.Round((double)nde.Y); int destNode = (int)nde.Y * cPlayer.Path.NumCols + (int)nde.X; shortest = cPlayer.Path.search(cPlayer.Path.Nodes[srcNode], cPlayer.Path.Nodes[destNode]); tempBool = true; }*/ if (Inp.OldMse.Position != Inp.Mse.Position) desktop.mouseMove(Inp.Mse.Position); GUI.Desktop.Event evnt = Desktop.Event.MouseRightUp; bool evntHappened = true; if (Inp.OldMse.LeftButton == ButtonState.Pressed && Inp.Mse.LeftButton == ButtonState.Released) evnt = Desktop.Event.MouseLeftUp; else if (Inp.OldMse.LeftButton == ButtonState.Released && Inp.Mse.LeftButton == ButtonState.Pressed) evnt = Desktop.Event.MouseLeftDown; else if (Inp.OldMse.RightButton == ButtonState.Pressed && Inp.Mse.RightButton == ButtonState.Released) evnt = Desktop.Event.MouseRightUp; else if (Inp.OldMse.RightButton == ButtonState.Released && Inp.Mse.RightButton == ButtonState.Pressed) evnt = Desktop.Event.MouseRightUp; else evntHappened = false; if (selectedNode != null) hoveredHotspot = map.HotspotAtPoint(cursorPos); if (selectedNode == null && evntHappened && desktop.PerformMouseEvent(evnt, Inp.Mse.Position, Inp)) { hoveredNode = null; } else { // check for hovered node and segment hoveredNode = map.NodeAtPoint(cursorPos, true); hoveredSeg = (hoveredNode == null) ? map.segmentAtPoint(cursorPos, hPlayer) : null; // if node is selected, determine which node type may be built at the selected distance selNodeType = (selectedNode == null) ? null : map.getNodeType(selectedNode.Pos, cursorPos); // if the user just released the left mouse button if (Inp.OldMse.LeftButton == ButtonState.Pressed && Inp.Mse.LeftButton == ButtonState.Released) { if (selectedNode != null) { if (hoveredNode == null) { if (hoveredHotspot != null) map.PlayerActions.Add(new PlayerAction(hPlayer, PlayerAction.ActionType.BuildSeg, selectedNode.ID, true, hoveredHotspot.ID)); else if (selNodeType != null) map.PlayerActions.Add(new PlayerAction(hPlayer, PlayerAction.ActionType.BuildSeg, selectedNode.ID, false, cursorPos)); } else if (hoveredNode != selectedNode) { map.PlayerActions.Add(new PlayerAction(hPlayer, PlayerAction.ActionType.ClaimNode, selectedNode.ID, hoveredNode.ID)); } selectedNode = null; } } // user just pressed the left mouse button else if ((Inp.OldMse.LeftButton == ButtonState.Released && Inp.Mse.LeftButton == ButtonState.Pressed) || (Inp.OldMse.RightButton == ButtonState.Released && Inp.Mse.RightButton == ButtonState.Pressed)) { if (hoveredNode != null && hoveredNode.Owner == hPlayer && (Inp.Mse.RightButton == ButtonState.Pressed || hoveredNode.NumSegments < hoveredNode.Segments.Length)) selectedNode = hoveredNode; } // if the left mouse button is still pressed else if (Inp.OldMse.LeftButton == ButtonState.Pressed && Inp.Mse.LeftButton == ButtonState.Pressed) { if (selectedNode != null && cursorPos.Y >= FInt.F0 && cursorPos.X >= FInt.F0 && cursorPos.X < map.Width && cursorPos.Y < map.Height) { List<SegmentSkel> ignoreSeg = new List<SegmentSkel>(selectedNode.Segments.Length); foreach (Segment seg in selectedNode.Segments) { if (seg != null) ignoreSeg.Add(seg); } List<NodeSkel> ignoreNode = new List<NodeSkel>(1) { selectedNode }; SegmentSkel segColl; NodeSkel nodeColl; GeoSkel geoColl; map.Collision.segCollisionIntPoint(selectedNode.Pos, cursorPos, ignoreSeg, ignoreNode, out segColl, out nodeColl, out geoColl, out intersectPoint); } } // if the player just released the right mouse button else if (Inp.OldMse.RightButton == ButtonState.Pressed && Inp.Mse.RightButton == ButtonState.Released) { if (selectedNode != null && hoveredNode == selectedNode) { map.PlayerActions.Add(new PlayerAction(hPlayer, PlayerAction.ActionType.DestroyNode, selectedNode.ID)); } else if (hoveredSeg != null) { map.PlayerActions.Add(new PlayerAction(hPlayer, PlayerAction.ActionType.SplitSeg, hoveredSeg.ID, cursorPos)); hoveredSeg = null; } selectedNode = null; } // if the player just pressed the spacebar else if (!Inp.OldKey.IsKeyDown(Keys.Space) && Inp.Key.IsKeyDown(Keys.Space)) { paused = !paused; } } // update world if (!paused && !cntMsgBox.Visible) map.update(gameTime); // execute action queue if (map.FrontEndActions.Count > 0 && !cntMsgBox.Visible) { FrontEndAction action = map.FrontEndActions.Dequeue(); switch (action.Action) { case FrontEndAction.ActionType.LoadMap: loadWorld((string)action.Params[0]); break; case FrontEndAction.ActionType.Message: showMsg((string)action.Params[0]); break; } } }
/// <summary>Creates a new instance of PlayMode.</summary> /// <param name="graphics">The graphics device manager to use.</param> /// <param name="content">The content manager to use.</param> /// <param name="batch">The sprite batch to use.</param> /// <param name="bEffect">The basic effect to use.</param> public PlayMode(GraphicsDeviceManager graphics, ContentManager content, SpriteBatch batch, BasicEffect bEffect) : base(graphics, content, batch, bEffect) { hoveredNode = null; hoveredSeg = null; hoveredHotspot = null; selectedNode = null; desktop = new Desktop(); lblCursorPos = new Label(); lblCursorPos.Left = 0; lblCursorPos.Top = 0; lblCursorPos.Width = 0; lblCursorPos.Height = 0; lblCursorPos.ForeColor = Color.White; desktop.Controls.Add(lblCursorPos); /* TEMPORARY */ loadWorld(@"..\..\..\testscripting.txt");//testLevel.txt"); //map = WorldLoader.loadWorld(@"..\..\..\testLevel.txt", Graphics); /* TEMPORARY */ }
private static void readHotspotVars(List<string[]> commands, World map, Dictionary<string, Hotspot> hotspots, List<Hotspot> hotspotNoID) { double tempDouble = 0d; Hotspot hotspot = new Hotspot(map); for (int j = 1; j < commands.Count; j++) { string value = translateValue(commands[j][2], "[Hotspot]", map); bool valueValid = true; switch (commands[j][0]) { case "ID": hotspot.ID = value; hotspots.Add(value, hotspot); break; case "X": valueValid = double.TryParse(value, out tempDouble); hotspot.X = (FInt)tempDouble; break; case "Y": valueValid = double.TryParse(value, out tempDouble); hotspot.Y = (FInt)tempDouble; break; case "Script": hotspot.Script = value.Replace("[newline]", "\n"); break; default: throw new Exception("Hotspot variable not recognized: " + commands[j][0]); } if (!valueValid) throw new Exception("Value '" + commands[j][2] + "' not valid for variable '" + commands[j][0] + "'."); } if (hotspot.ID != null) map.addHotspot(hotspot); }