Example #1
0
        private void GenerateTileBounds()
        {
            tileDestBounds   = new List <Rectangle>();
            tileSourceBounds = new List <Rectangle>();

            Rectangle sourceRect = new Rectangle();
            Rectangle destRect   = new Rectangle();

            for (int i = 0; i < map.SegmentDefinitions.Count; i++)
            {
                SegmentDefinition segmentDefinition = map.SegmentDefinitions[i];

                destRect.X = paletteOffsetX;
                destRect.Y = 50 + i * 60;

                sourceRect = segmentDefinition.SourceRect;

                // Maintain scale never exceeding 45 pixels on either dimension
                if (sourceRect.Width > sourceRect.Height)
                {
                    destRect.Width  = 45;
                    destRect.Height = (int)(((float)sourceRect.Height / (float)sourceRect.Width) * 45.0);
                }
                else
                {
                    destRect.Height = 45;
                    destRect.Width  = (int)(((float)sourceRect.Width / (float)sourceRect.Height) * 45.0f);
                }

                tileSourceBounds.Add(sourceRect);
                tileDestBounds.Add(destRect);
            }
        }
Example #2
0
        /// <summary>
        /// Minimu requirments to create waypoin
        /// </summary>
        /// <param name="route">Route where create waypoint</param>
        /// <param name="index">waypoint index</param>
        /// <param name="lat">Latitude in radians</param>
        /// <param name="lng">Longitude in radians</param>
        /// <returns></returns>
        public Route AddWaypoint(Route route, int index, double lat, double lng)
        {
            TraverseAlgorithm wpAlgorithm = _mappingRequestService.GetAlgoritmByClassName("com.ugcs.ucs.service.routing.impl.WaypointAlgorithm");
            SegmentDefinition newSegment  = new SegmentDefinition
            {
                Uuid = Guid.NewGuid().ToString(),
                AlgorithmClassName = wpAlgorithm.ImplementationClass
            };

            newSegment.Figure = new Figure {
                Type = wpAlgorithm.FigureType
            };

            newSegment.ParameterValues.Add(new ParameterValue()
            {
                Name           = "speed",
                Value          = "5.0",
                ValueSpecified = true
            });
            newSegment.ParameterValues.Add(new ParameterValue()
            {
                Name           = "wpTurnType",
                Value          = "SPLINE",
                ValueSpecified = true
            });
            newSegment.ParameterValues.Add(new ParameterValue()
            {
                Name           = "avoidObstacles",
                Value          = "True",
                ValueSpecified = true
            });
            newSegment.ParameterValues.Add(new ParameterValue()
            {
                Name           = "avoidTerrain",
                Value          = "True",
                ValueSpecified = true
            });


            newSegment.Figure.Points.Add(new FigurePoint()
            {
                AglAltitude           = 20,
                AglAltitudeSpecified  = true,
                AltitudeType          = AltitudeType.AT_AGL,
                AltitudeTypeSpecified = true,
                Latitude           = lat, //0.99443566874164979,
                LatitudeSpecified  = true,
                Longitude          = lng, //0.42015588448045021,
                LongitudeSpecified = true,
                Order                  = 0,
                Wgs84Altitude          = 0.0,
                Wgs84AltitudeSpecified = true
            });

            route.Segments.Insert(index, newSegment);
            return(SaveUpdatedRoute(route));
        }
Example #3
0
        private static LogicalSegment ConvertSegmentDefinition(
            SegmentDefinition def, Dictionary <object, object> objectMap,
            ObjectModule module)
        {
            // Convert the record.
            LogicalSegment segment = new LogicalSegment(def, objectMap, module);

            return(segment);
        }
        internal LogicalSegment(
            SegmentDefinition def,
            Dictionary <object, object> objectMap,
            ObjectModule module)
        {
            if (def.IsUse32)
            {
                throw new NotSupportedException("Use32 is not supported.");
            }
            if (def.Length > 0x10000)
            {
                throw new NotSupportedException("Segments larger than 64KB are not supported.");
            }

            this.definition = def;
            this.fullName   = module.Name + "." + def.SegmentName;
            this.data       = def.Data;
        }
Example #5
0
        public SEGDEFRecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            SegmentDefinition def = new SegmentDefinition();

            // Read the record.
            byte acbp = reader.ReadByte();
            def.Alignment = GetAlignment(acbp);
            def.Combination = GetCombination(acbp);
            def.IsUse32 = GetUse32(acbp);

            if (def.Alignment == SegmentAlignment.Absolute)
            {
                def.Frame = reader.ReadUInt16();
                def.Offset = reader.ReadByte();
            }

            UInt32 storedLength=reader.ReadUInt16Or32();
            def.Length = GetLength(acbp, storedLength, reader.RecordNumber);

            UInt16 segmentNameIndex = reader.ReadIndex();
            if (segmentNameIndex > context.Names.Count)
                throw new InvalidDataException("SegmentNameIndex is out of range.");
            if (segmentNameIndex > 0)
                def.SegmentName = context.Names[segmentNameIndex - 1];

            UInt16 classNameIndex = reader.ReadIndex();
            if (classNameIndex > context.Names.Count)
                throw new InvalidDataException("ClassNameIndex is out of range.");
            if (classNameIndex > 0)
                def.ClassName = context.Names[classNameIndex - 1];

            UInt16 overlayNameIndex = reader.ReadIndex();
            if (overlayNameIndex > context.Names.Count)
                throw new InvalidDataException("OverlayNameIndex is out of range.");
            if (overlayNameIndex > 0)
                def.OverlayName = context.Names[overlayNameIndex - 1];

            def.Data = new byte[def.Length];
            //def.Fixups = new List<FixupDefinition>();

            this.Definition = def;
            context.Segments.Add(def);
        }
Example #6
0
        private void DrawMapSegments()
        {
            DrawTransparentLayer(new Rectangle(paletteOffsetX, 20, 280, 550), new Color(0, 0, 0, 100));

            for (int i = 0; i < tileDestBounds.Count; i++)
            {
                SegmentDefinition segmentDefinition = map.SegmentDefinitions[i];

                if (segmentDefinition == null)
                {
                    continue;
                }

                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

                spriteBatch.Draw(mapsTexture[segmentDefinition.SourceIndex], tileDestBounds[i], tileSourceBounds[i], Color.White);

                spriteBatch.End();

                Text.Color = Color.White;
                Text.DrawText(tileDestBounds[i].X + 50, tileDestBounds[i].Y, segmentDefinition.Name);
            }
        }
 public Segment(SegmentDefinition definition, Dimension dimension)
 {
     Definition = definition;
     Dimension = dimension;
 }
Example #8
0
        public SEGDEFRecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            SegmentDefinition def = new SegmentDefinition();

            // Read the record.
            byte acbp = reader.ReadByte();

            def.Alignment   = GetAlignment(acbp);
            def.Combination = GetCombination(acbp);
            def.IsUse32     = GetUse32(acbp);

            if (def.Alignment == SegmentAlignment.Absolute)
            {
                def.Frame  = reader.ReadUInt16();
                def.Offset = reader.ReadByte();
            }

            UInt32 storedLength = reader.ReadUInt16Or32();

            def.Length = GetLength(acbp, storedLength, reader.RecordNumber);

            UInt16 segmentNameIndex = reader.ReadIndex();

            if (segmentNameIndex > context.Names.Count)
            {
                throw new InvalidDataException("SegmentNameIndex is out of range.");
            }
            if (segmentNameIndex > 0)
            {
                def.SegmentName = context.Names[segmentNameIndex - 1];
            }

            UInt16 classNameIndex = reader.ReadIndex();

            if (classNameIndex > context.Names.Count)
            {
                throw new InvalidDataException("ClassNameIndex is out of range.");
            }
            if (classNameIndex > 0)
            {
                def.ClassName = context.Names[classNameIndex - 1];
            }

            UInt16 overlayNameIndex = reader.ReadIndex();

            if (overlayNameIndex > context.Names.Count)
            {
                throw new InvalidDataException("OverlayNameIndex is out of range.");
            }
            if (overlayNameIndex > 0)
            {
                def.OverlayName = context.Names[overlayNameIndex - 1];
            }

            def.Data = new byte[def.Length];
            //def.Fixups = new List<FixupDefinition>();

            this.Definition = def;
            context.Segments.Add(def);
        }
Example #9
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            Rectangle sRect = new Rectangle();
            Rectangle dRect = new Rectangle();

            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

            map.Draw(sprite, mapsTex, scroll);

            //if (drawType == DRAW_COL)
            DrawGrid();
            DrawLedges();

            sprite.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
            Color oColor = new Color(new Vector4(1.0f, 1.0f, 1.0f, 0.3f));

            sprite.Draw(nullTex, new Rectangle(100, 50, 400, 1), oColor);
            sprite.Draw(nullTex, new Rectangle(100, 50, 1, 500), oColor);
            sprite.Draw(nullTex, new Rectangle(500, 50, 1, 500), oColor);
            sprite.Draw(nullTex, new Rectangle(100, 550, 400, 1), oColor);


            sprite.Draw(nullTex, new Rectangle(100, 300, 400, 1), oColor);

            sprite.End();


            String layerName = "map";

            switch (curLayer)
            {
            case 0:
                layerName = "back";
                break;

            case 1:
                layerName = "mid";
                break;

            case 2:
                layerName = "fore";
                break;
            }
            if (text.DrawClickText(5, 5, "layer: " + layerName, mosX, mosY, mouseClick))
            {
                curLayer = (curLayer + 1) % 3;
            }

            switch (drawType)
            {
            case DRAW_SELECT:
                layerName = "select";
                break;

            case DRAW_COL:
                layerName = "col";
                break;

            case DRAW_LEDGE:
                layerName = "ledge";
                break;

            case DRAW_SCRIPT:
                layerName = "script";
                break;
            }
            if (text.DrawClickText(5, 25, "draw: " + layerName, mosX, mosY, mouseClick))
            {
                drawType = (drawType + 1) % 4;
            }

            if (drawType == DRAW_SCRIPT)
            {
                sprite.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
                sprite.Draw(nullTex, new Rectangle(400, 20, 400, 565), new Color(
                                new Vector4(0f, 0f, 0f, .62f)));
                sprite.End();

                for (int i = scriptScroll; i < scriptScroll + 28; i++)
                {
                    if (selScript == i)
                    {
                        text.SetColor(Color.White);
                        text.DrawText(405, 25 + (i - scriptScroll) * 20,
                                      i.ToString() + ": " + map.script[i] + "*");
                    }
                    else
                    {
                        if (text.DrawClickText(405, 25 + (i - scriptScroll) * 20,
                                               i.ToString() + ": " + map.script[i],
                                               mosX, mosY, mouseClick))
                        {
                            selScript   = i;
                            editingText = EDITING_SCRIPT;
                        }
                    }
                    if (map.script[i].Length > 0)
                    {
                        String[] split = map.script[i].Split(' ');
                        int      c     = GetCommandColor(split[0]);
                        if (c > COLOR_NONE)
                        {
                            switch (c)
                            {
                            case COLOR_GREEN:
                                text.SetColor(Color.Lime);
                                break;

                            case COLOR_YELLOW:
                                text.SetColor(Color.Yellow);
                                break;
                            }
                            text.DrawText(405, 25 + (i - scriptScroll) * 20,
                                          i.ToString() + ": " + split[0]);
                        }
                    }
                    text.SetColor(Color.White);
                    text.DrawText(405, 25 + (i - scriptScroll) * 20,
                                  i.ToString() + ": ");
                }

                if (drawButton(770, 20, 1, mosX, mosY, mouseDown) &&
                    scriptScroll > 0)
                {
                    scriptScroll--;
                }

                if (drawButton(770, 550, 2, mosX, mosY, mouseDown) &&
                    scriptScroll < map.script.Length - 28)
                {
                    scriptScroll++;
                }
            }

            if (drawType == DRAW_LEDGE)
            {
                for (int i = 0; i < 16; i++)
                {
                    int y = 50 + i * 20;
                    if (curLedge == i)
                    {
                        text.SetColor(Color.Lime);
                        text.DrawText(520, 50 + i * 20, "ledge " + i.ToString());
                    }
                    else
                    {
                        if (text.DrawClickText(520, 50 + i * 20, "ledge " + i.ToString(),
                                               mosX, mosY, mouseClick))
                        {
                            curLedge = i;
                        }
                    }
                    text.SetColor(Color.White);
                    text.DrawText(620, 50 + i * 20, "n" + map.GetLedgeTotalNodes(i).ToString());

                    if (text.DrawClickText(680, 50 + i * 20, "f" +
                                           map.GetLedgeFlags(i).ToString(), mosX, mosY, mouseClick))
                    {
                        map.SetLedgeFlags(i, (map.GetLedgeFlags(i) + 1) % 2);
                    }
                }
            }

            text.SetColor(Color.White);
            if (editingText == EDITING_PATH)
            {
                text.DrawText(5, 45, map.path + "*");
            }
            else
            {
                if (text.DrawClickText(5, 45, map.path, mosX, mosY, mouseClick))
                {
                    editingText = EDITING_PATH;
                }
            }

            if (drawButton(5, 65, 3, mosX, mosY, mouseClick))
            {
                map.Write();
                map.Write(true);
            }

            if (drawButton(40, 65, 4, mosX, mosY, mouseClick))
            {
                map.Read();
            }

            for (int i = selScroll; i < selScroll + 20; i++)
            {
                if (map.GetSegIdx(curLayer, i) > -1)
                {
                    SegmentDefinition segDef =
                        map.GetSegDef(map.GetSegIdx(curLayer, i));
                    if (selIdx == i)
                    {
                        text.SetColor(Color.Lime);
                        text.DrawText(5, 100 + (i - selScroll) * 16, segDef.GetName());
                    }
                    else
                    {
                        if (text.DrawClickText(
                                5, 100 + (i - selScroll) * 16, segDef.GetName(),
                                mosX, mosY, mouseClick))
                        {
                            selIdx = i;
                        }
                    }
                }
            }
            if (drawButton(100, 100, 1, mosX, mosY, mouseDown))
            {
                if (selScroll > 0)
                {
                    selScroll--;
                }
            }
            if (drawButton(100, 500, 2, mosX, mosY, mouseDown))
            {
                if (selScroll < 43)
                {
                    selScroll++;
                }
            }
            if (drawButton(5, 500, 1, mosX, mosY, mouseDown))
            {
                if (selIdx > 0)
                {
                    map.SwapSegs(curLayer, selIdx, selIdx - 1);
                    selIdx--;
                }
            }
            if (drawButton(25, 500, 2, mosX, mosY, mouseDown))
            {
                if (selIdx < 63)
                {
                    map.SwapSegs(curLayer, selIdx, selIdx + 1);
                    selIdx++;
                }
            }

            if (drawType == DRAW_SELECT)
            {
                sprite.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);

                sprite.Draw(nullTex, new Rectangle(500, 20, 280, 550), new Color(
                                new Vector4(0.0f, 0.0f, 0.0f, 0.4f)));
                sprite.End();

                for (int i = segScroll; i < segScroll + 9; i++)
                {
                    SegmentDefinition segDef = map.GetSegDef(i);
                    if (segDef != null)
                    {
                        sprite.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);

                        dRect.X = 500;
                        dRect.Y = 50 + (i - segScroll) * 60;

                        sRect = segDef.GetSrcRect();

                        if (sRect.Width > sRect.Height)
                        {
                            dRect.Width  = 45;
                            dRect.Height = (int)(((float)sRect.Height / (float)sRect.Width) * 45.0f);
                        }
                        else
                        {
                            dRect.Height = 45;
                            dRect.Width  = (int)(((float)sRect.Width / (float)sRect.Height) * 45.0f);
                        }

                        sprite.Draw(mapsTex[map.GetSegDef(i).GetSrcIdx()], dRect, sRect, Color.White);

                        sprite.End();

                        text.SetSize(0.5f);
                        text.SetColor(Color.White);
                        text.DrawText(dRect.X + 50, dRect.Y, segDef.GetName());

                        if (mouseDown)
                        {
                            if (mosX > dRect.X && mosX < 700 && mosY > dRect.Y && mosY < dRect.Y + 45)
                            {
                                if (mouseDragSeg == -1)
                                {
                                    int f = map.AddSeg(curLayer, i);
                                    if (f > -1)
                                    {
                                        float layerScalar = 0.5f;
                                        if (curLayer == 0)
                                        {
                                            layerScalar = 0.375f;
                                        }
                                        if (curLayer == 2)
                                        {
                                            layerScalar = 0.675f;
                                        }

                                        map.SetSegLoc(curLayer, f,
                                                      new Vector2((float)(mosX - sRect.Width / 4 + scroll.X * layerScalar),
                                                                  (float)(mosY - sRect.Height / 4 + scroll.Y * layerScalar)));
                                        mouseDragSeg = f;
                                        pMosX        = mosX;
                                        pMosY        = mosY;
                                    }
                                }
                            }
                        }
                    }
                }

                if (drawButton(740, 20, 1, mosX, mosY, mouseDown))
                {
                    if (segScroll > 0)
                    {
                        segScroll--;
                    }
                }
                if (drawButton(740, 550, 2, mosX, mosY, mouseDown))
                {
                    if (segScroll < 80)
                    {
                        segScroll++;
                    }
                }
            }

            Vector2 v = new Vector2((float)mosX, (float)mosY) + scroll / 2.0f;

            v *= 2f;
            text.SetSize(.5f);
            text.SetColor(Color.White);
            text.DrawText(5, 580, ((int)v.X).ToString() + ", " +
                          ((int)v.Y).ToString());

            DrawCursor();

            mouseClick = false;

            base.Draw(gameTime);
        }