예제 #1
0
        /// <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);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>Loads the currently selected file in lsbLoadSaveFile into the editor.</summary>
        private void loadSelectedFile()
        {
            StringBuilder path = new StringBuilder();
            foreach (ButtonText b in btnSaveLoadPath)
            {
                path.Append(b.Text);
                path.Append('\\');
            }
            path.Append(lsbSaveLoadFiles.SelectedItem);

            hoveredNode = null;
            selectedNode = null;
            hoveredSeg = null;
            selectedSeg = null;
            hoveredSegEnd = null;
            hoveredSegEndOwner = null;
            selectedSegEnd = null;
            hoveredGeo = null;
            selectedGeo = null;
            world = WorldLoader.loadWorld(path.ToString(), Graphics);

            refreshSideBar();
        }
예제 #3
0
        /// <summary>Removes the selected geo vertex or line from the world.</summary>
        private void removeSelGeo()
        {
            VectorF[] vertices;

            if (selectedGeoIsLine)
            {
                if (selectedGeo.Vertices.Length == 2)
                {
                    world.removeGeo(selectedGeo);
                    selectedGeo = null;
                    loadObjectEditor();
                    return;
                }

                vertices = new VectorF[selectedGeo.Vertices.Length - 2];
                for (int i = 0; i < selectedGeoVertex; i++)
                {
                    vertices[i] = selectedGeo.Vertices[i];
                }
                for (int i = selectedGeoVertex + 2; i < selectedGeo.Vertices.Length; i++)
                {
                    vertices[i - 2] = selectedGeo.Vertices[i];
                }
            }
            else if (selectedGeoVertex == -1)
            {
                world.removeGeo(selectedGeo);
                selectedGeo = null;
                loadObjectEditor();
                return;
            }
            else
            {
                if (selectedGeo.Vertices.Length == 1)
                {
                    world.removeGeo(selectedGeo);
                    selectedGeo = null;
                    loadObjectEditor();
                    return;
                }

                if (selectedGeo.Vertices.Length == 2)
                {
                    vertices = new VectorF[1];
                    vertices[0] = selectedGeo.Vertices[1 - selectedGeoVertex];
                }
                else if (selectedGeoVertex == 0)
                {
                    vertices = new VectorF[selectedGeo.Vertices.Length - 2];
                    for (int i = 2; i < selectedGeo.Vertices.Length; i++)
                    {
                        vertices[i - 2] = selectedGeo.Vertices[i];
                    }
                }
                else if (selectedGeoVertex == selectedGeo.Vertices.Length - 1)
                {
                    vertices = new VectorF[selectedGeo.Vertices.Length - 2];
                    for (int i = 0, max = selectedGeo.Vertices.Length - 2; i < max; i++)
                    {
                        vertices[i] = selectedGeo.Vertices[i];
                    }
                }
                else
                {
                    vertices = new VectorF[selectedGeo.Vertices.Length - 2];
                    for (int i = 0, max = selectedGeoVertex - 1; i < max; i++)
                    {
                        vertices[i] = selectedGeo.Vertices[i];
                    }
                    for (int i = selectedGeoVertex + 1; i < selectedGeo.Vertices.Length; i++)
                    {
                        vertices[i - 2] = selectedGeo.Vertices[i];
                    }
                }
            }

            world.Grid.Rect(selectedGeo.UpperLeft, selectedGeo.LowerRight, selectedGeo, world.gridRemoveGeo);
            selectedGeo.Vertices = vertices;
            if (selectedGeo.Vertices.Length < 3)
            {
                selectedGeo.CloseLoop = false;
                selectedGeo.Display = false;
            }
            selectedGeo.refreshMath(new Vector2((float)tGeo.Width, (float)tGeo.Height));
            world.Grid.Rect(selectedGeo.UpperLeft, selectedGeo.LowerRight, selectedGeo, world.gridAddGeo);
            selectedGeo = null;
            loadObjectEditor();
        }
예제 #4
0
 /// <summary>Creates a new instance of LevelEditorMode.</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 LevelEditorMode(GraphicsDeviceManager graphics, ContentManager content, SpriteBatch batch, BasicEffect bEffect)
     : base(graphics, content, batch, bEffect)
 {
     world = new World(true);
     world.Grid = new GridManager(1, 1, world);
     hoveredNode = null;
     selectedNode = null;
     hoveredSeg = null;
     selectedSeg = null;
     hoveredSegEnd = null;
     hoveredSegEndOwner = null;
     selectedSegEnd = null;
     hoveredGeo = null;
     hoveredGeoVertex = -1;
     hoveredGeoIsLine = false;
     selectedGeo = null;
     selectedGeoVertex = -1;
     selectedGeoIsLine = false;
     desktop = new Desktop();
     lastClickedPoint = new VectorF();
     dragOffset = new VectorF();
     isDragging = false;
 }
예제 #5
0
파일: World.cs 프로젝트: wwarnick/Sever
 /// <summary>Removes the specified geometric obstacle from the world.</summary>
 /// <param name="geo">The geometric obstacle to remove.</param>
 public void removeGeo(Geo geo)
 {
     removeGeo(Geos.IndexOf(geo));
 }
예제 #6
0
파일: World.cs 프로젝트: wwarnick/Sever
 /// <summary>Adds the provided geometric obstacle to the world.</summary>
 /// <param name="geo">The geometri obstacle to add to the world.</param>
 public void addGeo(Geo geo)
 {
     if (geo.ID == null)
         geo.ID = getNextGeoID();
     Geos.Add(geo);
     GeoByID.Add(geo.ID, geo);
     Grid.Rect(geo.UpperLeft, geo.LowerRight, geo, gridAddGeo);
 }
예제 #7
0
파일: FogOfWar.cs 프로젝트: wwarnick/Sever
        /// <summary>Sets the visibility for each line in the geo.</summary>
        /// <param name="geo">The geo to test.</param>
        public void setLineVisibility(Geo geo)
        {
            if (geo.Vertices.Length > 1)
            {
                for (int i = 0; i < geo.Vertices.Length; i += 2)
                {
                    geo.LineVisible[i / 2] = isVisible(geo.Vertices[i], geo.Vertices[i + 1]);
                }

                if (geo.CloseLoop && geo.Vertices.Length > 2)
                    geo.LineVisible[geo.LineVisible.Length - 1] = isVisible(geo.Vertices[geo.Vertices.Length - 1], geo.Vertices[0]);
            }
        }
예제 #8
0
        private static void readGeoVars(List<string[]> commands, World map, Dictionary<string, Geo> geos, List<Geo> geoNoID)
        {
            double tempDbl0 = 0f;
            double tempDbl1 = 0f;
            string id = null;
            bool display = true;
            bool closeLoop = true;
            List<VectorF> vertices = new List<VectorF>();

            for (int j = 1; j < commands.Count; j++)
            {
                string value = translateValue(commands[j][2], "[Grid]", map);
                bool valueValid = true;
                switch (commands[j][0])
                {
                    case "Vertex":
                        string[] tempStr = value.Split(',');

                        for (int i = 0; i < tempStr.Length; i += 2)
                        {
                            valueValid = double.TryParse(tempStr[i], out tempDbl0);
                            valueValid = double.TryParse(tempStr[i + 1], out tempDbl1);

                            // add previous vertex again to start new line
                            if (vertices.Count > 1)
                                vertices.Add(vertices[vertices.Count - 1]);

                            vertices.Add(new VectorF((FInt)tempDbl0, (FInt)tempDbl1));
                        }
                        break;
                    case "ID":
                        id = value;
                        break;
                    case "Display":
                        valueValid = value == "true" || value == "false";
                        display = value == "true";
                        break;
                    case "CloseLoop":
                        valueValid = value == "true" || value == "false";
                        closeLoop = value == "true";
                        break;
                    default:
                        throw new Exception("Geo variable not recognized: " + commands[j][0]);
                }

                if (!valueValid)
                    throw new Exception("Value '" + commands[j][2] + "' not valid.");
            }

            Geo geo = new Geo(map);
            if (id != null)
            {
                geo.ID = id;
                geos.Add(id, geo);
            }
            geo.Display = display;
            geo.CloseLoop = closeLoop;
            VectorF[] vArray = new VectorF[vertices.Count];
            vertices.CopyTo(vArray);
            geo.Vertices = vArray;
            geo.refreshMath(new Vector2(50f)); // TODO: find out texture size

            if (id != null)
                map.addGeo(geo);
            else
                geoNoID.Add(geo);
        }