Example #1
0
        /// <summary>
        /// Make a new point (only if it is not already there)
        /// </summary>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        private void makePoint(int X, int Y)
        {
            SFX.YATT.Tools.Vector <float> coor = findAreaCoor(X, Y, areaViewer.Area);

            if (coor != null)
            {
                Pair <double, double> p = new Pair <double, double>(coor[0], coor[1]);
                Point id = new Point((int)Math.Floor(coor[0]), (int)Math.Floor(coor[1]));
                if (!pointsAlready.ContainsKey(id))
                {
                    pointsAlready[id] = "1";

                    // Get the current area
                    NWN2Toolset.NWN2.Views.NWN2AreaViewer viewer   = getAreaViewer();
                    NWN2Toolset.NWN2ToolsetMainForm       mainForm = NWN2Toolset.NWN2ToolsetMainForm.App;
                    NWN2GameArea area = viewer.Area;

                    // Make waypoint
                    NWN2Toolset.NWN2.Data.Instances.NWN2WaypointInstance wayPoint = new NWN2Toolset.NWN2.Data.Instances.NWN2WaypointInstance();
                    wayPoint.Tag      = WAYPOINT_TAG;
                    wayPoint.Position = new Vector3(coor[0], coor[1], coor[2]);
                    area.AddInstance(wayPoint);

                    debugOut("Point: " + p + " added");
                }
            }
        }
Example #2
0
        /// <summary>
        /// The code to show the at the given coordiantes.
        /// The colour of the circle is different based on the type we are working with
        /// </summary>
        /// <param name="coor">The coordinates the circle is to be shown at</param>
        private void showBrush(SFX.YATT.Tools.Vector <float> coor)
        {
            Color col;

            if (data.mode == paintmode.paint)
            {
                col = Color.Black;
            }
            else if (data.mode == paintmode.eyedrop)
            {
                col = Color.Blue;
            }
            else
            {
                col = Color.Red;
            }

            Vector3 vec = new Vector3(coor[0], coor[1], coor[2]);

            NWN2NetDisplayManager.Instance.TerrainBrush(this.electronPanel.NDWindow.Scene,
                                                        1,
                                                        1,
                                                        vec,
                                                        (float)newInner,
                                                        (float)newOuter,
                                                        NWN2ToolsetMainForm.App.TerrainEditor.TerrainValue,
                                                        NWN2ToolsetMainForm.App.TerrainEditor.TerrainValue2,
                                                        NWN2ToolsetMainForm.App.TerrainEditor.TerrainBrushColor,
                                                        col.ToArgb(),
                                                        NWN2ToolsetMainForm.App.TerrainEditor.TerrainBrushTexture,
                                                        NWN2ToolsetMainForm.App.TerrainEditor.TerrainMode);
            byte[] buffer2 = null;
            bool   bCancel = false;

            if ((NWN2ToolsetMainForm.App.TerrainEditor.TerrainMode != TerrainModificationType.Water) && (NWN2ToolsetMainForm.App.TerrainEditor.TerrainMode != TerrainModificationType.NoWater))
            {
                NWN2NetDisplayManager.Instance.BeginSynchronizedOperation();
                int num6 = NWN2NetDisplayManager.Instance.TerrainSelection(this.electronPanel.NDWindow.Scene, vec);
                NWN2NetDisplayManager.Instance.WaitForMessageSynchronous(NetDisplayMessageType.TerrainSelectResults, out buffer2, num6);
                NWN2NetDisplayManager.Instance.EndSynchronizedOperation();
                if (buffer2 != null)
                {
                    NWN2ToolsetMainForm.App.TerrainEditor.HandleSelectTerrain(buffer2, ref bCancel);
                }
            }
        }
Example #3
0
        /// <summary>
        /// This method finds the coordinates that have been clicked on the area (not the coordinates that have been clicked on in the toolset).
        /// </summary>
        /// <param name="X">The X coordinates from the toolset panel</param>
        /// <param name="Y">The Y coordinates from the toolset panel</param>
        /// <param name="area">The area we are working on</param>
        /// <returns></returns>
        private SFX.YATT.Tools.Vector <float> findAreaCoor(int X, int Y, NWN2GameArea area)
        {
            try {
                NWN2NetDisplayManager manager = NWN2NetDisplayManager.Instance;
                byte[] cMessage = null;
                bool   flag     = false;

                Random ran = new Random();

                manager.BeginSynchronizedOperation();

                int iMessageID = manager.PlanePick(areaViewer.AreaNetDisplayWindow,
                                                   X,
                                                   Y,
                                                   NWN2ToolsetMainForm.App.TerrainEditor.TerrainValue);
                manager.WaitForMessageSynchronous(NetDisplayMessageType.TerrainPickResults, out cMessage, iMessageID);
                manager.EndSynchronizedOperation();

                if (!flag)
                {
                    BinaryReader reader = new BinaryReader(new MemoryStream(cMessage));
                    if (reader.ReadInt32() != areaViewer.AreaNetDisplayWindow.Scene.ID)
                    {
                        throw new Exception("Reader Error");
                    }

                    int num = reader.ReadInt32();
                    // The coordinates from the mouse
                    float valueX = reader.ReadSingle();
                    float valueY = reader.ReadSingle();
                    float valueZ = reader.ReadSingle();

                    SFX.YATT.Tools.Vector <float> vec = new SFX.YATT.Tools.Vector <float>(valueX, valueY, valueZ);

                    return(vec);
                }
                else
                {
                    return(null);
                }
            } catch (Exception e) {
                debugOut("Problem with finding the coordinates: " + e.Message);
                throw new Exception("Problem with finding the coordinates: " + e.Message);
            }
        }
Example #4
0
        /// <summary>
        /// This is called when the mousecurser moves around on the area so that we can either
        /// show the circle normally seen, or stop viewing it
        /// </summary>
        /// <param name="panel">The information from the </param>
        public void Move(MousePanel panel)
        {
            areaViewer = getAreaViewer();

            if (!panel.ButtonHeld || areaViewer == null || areaViewer.Area == null)
            {
                SFX.YATT.Tools.Vector <float> coor = findAreaCoor(panel.MouseX, panel.MouseY, areaViewer.Area);

                if (coor != null)
                {
                    showBrush(coor);
                }
                else
                {
                    stopShowingCircle();
                }
            }
            else
            {
                stopShowingCircle();
            }
        }
Example #5
0
        /// <summary>
        /// This method finds the coordinates that have been clicked on the area (not the coordinates that have been clicked on in the toolset).
        /// </summary>
        /// <param name="X">The X coordinates from the toolset panel</param>
        /// <param name="Y">The Y coordinates from the toolset panel</param>
        /// <param name="area">The area we are working on</param>
        /// <returns></returns>
        private SFX.YATT.Tools.Vector<float> findAreaCoor(int X, int Y, NWN2GameArea area)
        {
            try {
                NWN2NetDisplayManager manager = NWN2NetDisplayManager.Instance;
                byte[] cMessage = null;
                bool flag = false;

                Random ran = new Random();

                manager.BeginSynchronizedOperation();

                int iMessageID = manager.PlanePick(areaViewer.AreaNetDisplayWindow,
                                                   X,
                                                   Y,
                                                   NWN2ToolsetMainForm.App.TerrainEditor.TerrainValue);
                manager.WaitForMessageSynchronous(NetDisplayMessageType.TerrainPickResults, out cMessage, iMessageID);
                manager.EndSynchronizedOperation();

                if (!flag)
                {
                    BinaryReader reader = new BinaryReader(new MemoryStream(cMessage));
                    if (reader.ReadInt32() != areaViewer.AreaNetDisplayWindow.Scene.ID)
                    {
                        throw new Exception("Reader Error");
                    }

                    int num = reader.ReadInt32();
                    // The coordinates from the mouse
                    float valueX = reader.ReadSingle();
                    float valueY = reader.ReadSingle();
                    float valueZ = reader.ReadSingle();

                    SFX.YATT.Tools.Vector<float> vec = new SFX.YATT.Tools.Vector<float>(valueX, valueY, valueZ);

                    return vec;
                } else {
                    return null;
                }
            } catch (Exception e) {
                debugOut("Problem with finding the coordinates: " + e.Message);
                throw new Exception("Problem with finding the coordinates: " + e.Message);
            }
        }
Example #6
0
        /// <summary>
        /// The code for painting on-line3
        /// </summary>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        private void TerrianCode(int X, int Y)
        {
            try {
                areaViewer = getAreaViewer();
                SFX.YATT.Tools.Vector <float> coor = findAreaCoor(X, Y, areaViewer.Area);

                Random ran = new Random();

                if (coor != null)
                {
                    NWN2ToolsetMainForm.App.TerrainEditor.SetBrushType(NWN2TerrainEditorForm.BrushType.StandardTerrain);


                    // Textures:
                    opTexture.Checked = true;
                    if (data.randomize)
                    {
                        ran = new Random(System.DateTime.Now.Millisecond);

                        ArrayList texData = new ArrayList(data.textures.Count);
                        texData.AddRange(data.textures);

                        while (texData.Count > 0)
                        {
                            int         num     = ran.Next(0, texData.Count - 1);
                            textureData texture = (textureData)texData[num];
                            texturePreperation(coor, TerrainModificationType.Texture, texture);
                            texData.RemoveAt(num);
                        }
                    }
                    else
                    {
                        LinkedListNode <textureData> node = data.textures.Last;
                        while (node != null)
                        {
                            DateTime dateTime = DateTime.Now;

                            double start = ((double)dateTime.Ticks) / 1000000.0;
                            texturePreperation(coor, TerrainModificationType.Texture, node.Value);
                            dateTime = DateTime.Now;
                            node     = node.Previous;
                        }
                    }

                    if (data.grassOption == grassOption.Paint)
                    {
                        opGrass.Checked = true;

                        barPressure.Value        = data.grassDensity * 100;
                        grassSize.Value          = (data.grassSize / 30);
                        grassSizeVariation.Value = (data.grassSizeVariation / 10);

                        object[] objList = new object[grassListBox.Items.Count];
                        grassListBox.Items.CopyTo(objList, 0);

                        int index = 0;

                        grassListBox.SelectedIndices.Clear();

                        foreach (TextureListItem textureItem in objList)
                        {
                            string textStr = textureItem.Text;
                            if (textStr == data.grassTexture[0] ||
                                textStr == data.grassTexture[1] ||
                                textStr == data.grassTexture[2])
                            {
                                grassListBox.SelectedItem = textureItem;
                                index++;

                                if (index == 3)
                                {
                                    break;
                                }
                            }
                        }

                        NWN2ToolsetMainForm.App.TerrainEditor.SetBrushType(NWN2TerrainEditorForm.BrushType.FloraGrass);
                        texturePreperation(coor, TerrainModificationType.Grass, data.textures.First.Value);
                    }


                    if (data.colourOption == colourOption.Colour)
                    {
                        opTerrain.Checked      = true;
                        opColour.Checked       = true;
                        colourButton.BackColor = data.col;
                        barPressure.Value      = data.colourPresure * 100;
                        texturePreperation(coor, TerrainModificationType.Color, data.textures.First.Value);
                    }
                }
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }
Example #7
0
        /// <summary>
        /// The method that prepares to call the Method that does the actual paiting
        /// This include finding the coordinates that are to be painted, in what order, and the size of the outer and inner brush
        /// </summary>
        /// <param name="coor">The coordiantes we are going to start from</param>
        /// <param name="modType">The type of painting we are to do</param>
        /// <param name="localTexture">The texture we are going to paint</param>
        private void texturePreperation(SFX.YATT.Tools.Vector <float> coor, TerrainModificationType modType, textureData localTexture)
        {
            float valueX = coor[0];
            float valueY = coor[1];
            float valueZ = coor[2];

            int radius = (data.outerCircle + data.innerCircle) / 2;

            double roundModifier = 2 - (rounds / 11);

            float localOuter = (float)((newOuter / rounds) * roundModifier);
            float localInner = (float)((newInner / rounds) * roundModifier);

            opTexture.Checked = true;
            outerRadius.Value = Math.Min((int)localOuter, outerRadius.Maximum);
            innerRadius.Value = Math.Min((int)localInner, innerRadius.Maximum);

            float baseCoordinatesX = Math.Max(0, valueX - (radius / 2));
            float baseCoordinatesY = Math.Max(0, valueY - (radius / 2));

            float step = (radius / rounds);

            float coorX;
            float coorY;

            int ran = 0;

            // Make sure we have a new random number
            random = new Random(System.DateTime.Now.Millisecond);
            System.Collections.Generic.List <Pair <float, float> > coordinates = new System.Collections.Generic.List <Pair <float, float> >();

            for (int index1 = 1; index1 <= rounds; index1++)
            {
                coorX = baseCoordinatesX + (step * index1);

                for (int index2 = 1; index2 <= rounds; index2++)
                {
                    coorY = baseCoordinatesY + (step * index2);

                    coordinates.Add(new Pair <float, float>(coorX, coorY));
                }
            }

            int    coverage   = 0;
            string textureStr = localTexture.texture;
            int    col        = Color.White.ToArgb();

            if (modType == TerrainModificationType.Texture)
            {
                // CoverageChange must be bigger than 0 and less than 100
                coverage = localTexture.Coverage;

                // Set the presure of the current texture
                barPressure.Value = localTexture.Presure * 100;
            }
            else if (modType == TerrainModificationType.Grass)
            {
                coverage = data.grassCoverage;
            }
            else if (modType == TerrainModificationType.Color)
            {
                coverage = data.colourCoverage;
                col      = data.col.ToArgb();
            }
            else
            {
                throw new Exception("Wrong Terrain Modification Type");
            }

            foreach (Pair <float, float> point in coordinates)
            {
                coorX = point.X;
                coorY = point.Y;

                ran = random.Next(1, 100);

                NWN2NetDisplayManager.Instance.BeginSynchronizedOperation();
                if (ran <= coverage)
                {
                    paintTexture(textureStr, modType, col, localInner, localOuter, coorX, coorY, valueZ);
                }
                NWN2NetDisplayManager.Instance.EndSynchronizedOperation();
            }
        }