Пример #1
0
        protected internal override void Update(GameTime gameTime)
        {
            DrawList.Clear();

            if ((!IsInitialized) || (this.Map == null) || (this.Viewport == Rectangle.Empty))
            {
                return;
            }

            float revScale = 2.0f - Scale;

            int scaledViewportWidth  = (int)(Viewport.Width * revScale);
            int scaledViewportHeight = (int)(Viewport.Height * revScale);

            Rectangle viewRectangle = new Rectangle((int)Camera.X - (int)(scaledViewportWidth / 2), (int)Camera.Y - (int)(scaledViewportHeight / 2), scaledViewportWidth + (int)(scaledViewportWidth / 2), scaledViewportHeight + (int)(scaledViewportHeight / 2));

            for (int LayerIndex = 0; LayerIndex <= Map.LayerDrawing.GetUpperBound(0); LayerIndex++)
            {
                for (int ItemIndex = 0; ItemIndex <= Map.LayerDrawing[LayerIndex].GetUpperBound(0); ItemIndex++)
                {
                    IMapDrawable item            = Map.LayerDrawing[LayerIndex][ItemIndex];
                    Rectangle    sourceRectangle = item.Sprite.Source;
                    Rectangle    decorRectangle  = new Rectangle((int)item.Position.X, (int)item.Position.Y, (int)(sourceRectangle.Width * item.Scale * Scale), (int)(sourceRectangle.Height * item.Scale * Scale));

                    if (decorRectangle.Intersects(viewRectangle))
                    {
                        DrawList.Add(item);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        ///     Adds a new draw object to the map and redraws the map
        /// </summary>
        /// <param name="drawObject">The IMapDrawable object that should be added</param>
        public void AddDrawObject(IMapDrawable drawObject)
        {
            m_DrawObjects.Add(drawObject);

            // Redraw the map
            Refresh();
        }
Пример #3
0
 /// <summary>
 ///     Removes a draw object from the list of displayed objects
 /// </summary>
 /// <param name="drawObject">The draw object to be removed</param>
 public void RemoveDrawObject(IMapDrawable drawObject)
 {
     if (m_DrawObjects.Contains(drawObject))
     {
         m_DrawObjects.Remove(drawObject);
     }
 }
Пример #4
0
 public userMapOverlay(IMapDrawable drawable, Geocode geocode, Library.User user)
 {
     _drawable = (userMapDrawable)drawable;
     _geocode = geocode;
     _user = user;
     _offset = new Point((ClientSettings.SmallArtSize + (ClientSettings.Margin * 2) / 2), (ClientSettings.SmallArtSize + (ClientSettings.Margin * 2)));
 }
Пример #5
0
        /// <summary>
        ///     Adds a new draw object to the map
        /// </summary>
        /// <param name="drawObject">The IMapDrawable object that is being added to the map</param>
        /// <param name="refresh">Specifies whether the map should be redrawn after the object is added</param>
        public void AddDrawObject(IMapDrawable drawObject, bool refresh)
        {
            m_DrawObjects.Add(drawObject);

            if (refresh)
            {
                Refresh();
            }
        }
Пример #6
0
 public void Play(IMapDrawable drawer, ILivingCondition condition)
 {
     var map = new Map(Template.GetPentadecathlon());
     while (true)
     {
         map.Generation++;
         drawer.Draw(map);
         condition.ConfirmationAlive(map);
         var read = Console.ReadLine();
         if (read == "end") break;
     }
 }
Пример #7
0
        private void ItemDrawing()
        {
            Vector2 destinationVector = Vector2.Zero;

            for (int i = 0; i < DrawList.Count; i++)
            {
                IMapDrawable item = DrawList[i];

                destinationVector.X = item.Position.X - Camera.X + Viewport.Center.X;
                destinationVector.Y = item.Position.Y - Camera.Y + Viewport.Center.Y;

                SpriteBatch.Draw(item.Sprite.Texture, destinationVector, item.Sprite.Source, Color.White, (MathHelper.Pi * 2) * item.Rotation, new Vector2(0, 0), item.Scale * Scale, SpriteEffects.None, item.Layer);
            }
        }
Пример #8
0
        /// <summary>
        /// When the mouse hovers display the balooon tool tip
        /// </summary>
        private void Map_MouseHover(object sender, EventArgs e)
        {
            if (m_Balloon == null)
            {
                System.Drawing.Point location = Pandora.Map.PointToClient(System.Windows.Forms.Control.MousePosition);

                IMapDrawable obj = Pandora.Map.FindDrawObject(location, 5);

                if (obj != null && obj is SpawnDrawObject)
                {
                    SpawnDrawObject spawn = obj as SpawnDrawObject;

                    m_Balloon = MessageBalloon.Show(spawn.Spawn.ToolTipDetailed, Pandora.TextProvider["Travel.SpawnDetails"],
                                                    null,
                                                    MessageBalloonOptions.All,
                                                    MessageBalloon.MousePosition);
                    m_Balloon.VisibleChanged += new EventHandler(m_Balloon_VisibleChanged);
                }
            }
        }
Пример #9
0
        void ReadCallback(IAsyncResult result)
        {
            GetTileData data = (GetTileData)result.AsyncState;

            try
            {
                int read = data.ResponseStream.EndRead(result);
                if (read > 0)
                {
                    data.MemoryStream.Write(data.Buffer, 0, read);
                    data.ResponseStream.BeginRead(data.Buffer, 0, data.Buffer.Length, new AsyncCallback(ReadCallback), data);
                }
                else
                {
                    using (data)
                    {
                        string tilePath = GetTilePathForKey(data.Key);
                        using (FileStream file = new FileStream(tilePath, FileMode.Create, FileAccess.Write))
                        {
                            file.Write(data.MemoryStream.GetBuffer(), 0, (int)data.MemoryStream.Length);
                        }

                        data.MemoryStream.Seek(0, SeekOrigin.Begin);
                        IMapDrawable pbitmap = data.Renderer.GetBitmapFromStream(this, data.MemoryStream);
                        if (pbitmap == null)
                        {
                            throw new Exception();
                        }
                        TileCache[data.Key] = new TileData(pbitmap);
                        data.Callback(data.State);
                    }
                }
            }
            catch (Exception e)
            {
                CleanupTileData(data);
            }
        }
Пример #10
0
 public MapOverlay(IMapDrawable drawable, Geocode geocode, Point offset)
 {
     myDrawable = drawable;
     myOffset   = offset;
     myGeocode  = geocode;
 }
Пример #11
0
 public void Draw(IMapDrawable drawable, Rectangle destRect, Rectangle sourceRect)
 {
     IGraphicsDrawable graphicsDrawable = drawable as IGraphicsDrawable;
     graphicsDrawable.Draw(Graphics, destRect, sourceRect);
 }
Пример #12
0
 /// <summary>
 /// Creates a new EventArgs for use with draw objects
 /// </summary>
 /// <param name="drawobject">The IMapDrawable object used as data for this args</param>
 /// <param name="point">The point that originated the event</param>
 public DrawObjectEventArgs( IMapDrawable drawobject, Point point )
 {
     m_DrawObject = drawobject;
     m_Point = point;
 }
Пример #13
0
 public TileData(IMapDrawable bitmap)
 {
     Bitmap = bitmap;
 }
Пример #14
0
 void DrawAtGeocode(Geocode tlGeo, Geocode brGeo, IMapRenderer renderer, Geocode geocode, int pixelLevelZoom, int adjustX, int adjustY, IMapDrawable drawable)
 {
     if (!GeocodeBoxContains(tlGeo, brGeo, geocode) || drawable == null)
         return;
     Point p = GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY);
     renderer.Draw(drawable, new Rectangle(p.X - drawable.Width / 2, p.Y - drawable.Height / 2, drawable.Width, drawable.Height), new Rectangle(0, 0, drawable.Width, drawable.Height));
 }
Пример #15
0
        public int DrawMap(IMapRenderer renderer, int x, int y, int width, int height, WaitCallback callback, object state)
        {
            int unavailable = 0;

            // approximate the the top left tile (it may be off by 1), but the loop
            // below will kept it from being drawn
            int       midX        = x + width / 2 - myCenterOffset.X;
            int       midY        = y + height / 2 - myCenterOffset.Y;
            int       xTiles      = (midX - x) / 256 + 1;
            int       yTiles      = (midY - y) / 256 + 1;
            Key       currentXKey = new Key(myCenterTile.X - xTiles, myCenterTile.Y - yTiles, myZoom);
            int       xStart      = midX - xTiles * 256;
            int       yStart      = midY - yTiles * 256;
            Rectangle rect        = new Rectangle(x, y, width, height);

            int tickCount = Environment.TickCount;

            for (int currentX = xStart; currentX < x + width; currentX += 256, currentXKey.X++)
            {
                Key key = currentXKey;
                for (int currentY = yStart; currentY < y + height; currentY += 256, key.Y++)
                {
                    IMapDrawable tile = null;

                    // find the intersect region of the tile that we are drawing
                    Rectangle tileRect = new Rectangle(currentX, currentY, 256, 256);
                    tileRect.Intersect(rect);
                    Rectangle sourceRect = new Rectangle(tileRect.X - currentX, tileRect.Y - currentY, tileRect.Width, tileRect.Height);

                    // dont draw off the map tiles
                    if (!key.IsValid)
                    {
                        // dont draw gray rect if we're drawing transparent
                        if (!HasAlpha)
                        {
                            renderer.FillRectangle(BackColor, tileRect);
                        }
                        continue;
                    }

                    // first try to get the tile from the tileData
                    TileData tileData = GetTile(key, renderer, callback, state);

                    if (tileData != null)
                    {
                        tile = tileData.Bitmap;
                        tileData.LastUsed = tickCount;
                    }

                    if (tile == null)
                    {
                        // tile not available, so try to generate a tile from child tiles
                        unavailable++;

                        Key      childKey = new Key(key.X * 2, key.Y * 2, key.Zoom + 1);
                        Key      tl       = childKey;
                        Key      tr       = new Key(childKey.X + 1, childKey.Y, childKey.Zoom);
                        Key      br       = new Key(childKey.X + 1, childKey.Y + 1, childKey.Zoom);
                        Key      bl       = new Key(childKey.X, childKey.Y + 1, childKey.Zoom);
                        TileData tld;
                        TileData trd;
                        TileData bld;
                        TileData brd;

                        // see if the children are available
                        // we also need to null check, because they could be loading
                        if (TileCache.TryGetValue(tl, out tld) && TileCache.TryGetValue(tr, out trd) && TileCache.TryGetValue(br, out brd) && TileCache.TryGetValue(bl, out bld) &&
                            tld != null && trd != null && bld != null & brd != null &&
                            tld.Bitmap != null && trd.Bitmap != null && bld.Bitmap != null && brd.Bitmap != null)
                        {
                            // children are available, so mark them as recently used
                            tld.LastUsed = trd.LastUsed = bld.LastUsed = brd.LastUsed = tickCount;

                            // calculate the destination rects of each child tile
                            Rectangle tlr = new Rectangle(currentX, currentY, 128, 128);
                            Rectangle trr = new Rectangle(currentX + 128, currentY, 128, 128);
                            Rectangle blr = new Rectangle(currentX, currentY + 128, 128, 128);
                            Rectangle brr = new Rectangle(currentX + 128, currentY + 128, 128, 128);

                            tlr.Intersect(rect);
                            trr.Intersect(rect);
                            blr.Intersect(rect);
                            brr.Intersect(rect);

                            // calculate the source rect of each child tile
                            Rectangle tlsr = new Rectangle(tlr.X - currentX, tlr.Y - currentY, tlr.Width * 2, tlr.Height * 2);
                            Rectangle trsr = new Rectangle(trr.X - currentX - 128, trr.Y - currentY, trr.Width * 2, trr.Height * 2);
                            Rectangle blsr = new Rectangle(blr.X - currentX, blr.Y - currentY - 128, blr.Width * 2, blr.Height * 2);
                            Rectangle brsr = new Rectangle(brr.X - currentX - 128, brr.Y - currentY - 128, brr.Width * 2, brr.Height * 2);

                            // don't attempt to draw tiles that we don't need to
                            if (tlsr.Width > 0 && tlsr.Height > 0)
                            {
                                renderer.Draw(tld.Bitmap, tlr, tlsr);
                            }
                            if (trsr.Width > 0 && trsr.Height > 0)
                            {
                                renderer.Draw(trd.Bitmap, trr, trsr);
                            }
                            if (blsr.Width > 0 && blsr.Height > 0)
                            {
                                renderer.Draw(bld.Bitmap, blr, blsr);
                            }
                            if (brsr.Width > 0 && brsr.Height > 0)
                            {
                                renderer.Draw(brd.Bitmap, brr, brsr);
                            }
                            continue;
                        }
                        else
                        {
                            // can't generate from children, so try generating one of the parents
                            Key       parent     = key;
                            Rectangle parentRect = sourceRect;
                            TileData  parentData = null;
                            while (parent.Zoom >= 0 && parentData == null)
                            {
                                parentRect.Width  /= 2;
                                parentRect.Height /= 2;
                                parentRect.X      /= 2;
                                parentRect.Y      /= 2;
                                if (parent.X % 2 == 1)
                                {
                                    parentRect.X += 128;
                                }
                                if (parent.Y % 2 == 1)
                                {
                                    parentRect.Y += 128;
                                }
                                parent.X /= 2;
                                parent.Y /= 2;
                                parent.Zoom--;
                                TileCache.TryGetValue(parent, out parentData);
                            }

                            if (parentData != null && parentData.Bitmap != null)
                            {
                                // mark this tile as used recently
                                parentData.LastUsed = tickCount;
                                if (tileRect.Width > 0 && tileRect.Height > 0)
                                {
                                    renderer.Draw(parentData.Bitmap, tileRect, parentRect);
                                }
                                continue;
                            }
                            else
                            {
                                // tile is being downloaded, and we have no parent or child images we can use to draw a temp
                                // image. let's try to use a refresh bitmap.

                                // tile is not available, and this is a transparent draw,
                                // so dont draw at all
                                if (HasAlpha)
                                {
                                    continue;
                                }
                                if ((tile = RefreshBitmap) == null)
                                {
                                    renderer.FillRectangle(BackColor, tileRect);
                                    continue;
                                }
                            }
                        }
                    }

                    if (tile != null && tileRect.Width > 0 && tileRect.Height > 0)
                    {
                        renderer.Draw(tile, tileRect, sourceRect);
                    }
                }
            }

            int     pixelLevelZoom   = myZoom + 8;
            int     centerXReference = myCenterTile.X << 8;
            int     centerYReference = myCenterTile.Y << 8;
            Geocode tlGeo            = PointToGeocode(new Point(Math.Max(centerXReference + myCenterOffset.X - width / 2, 0), Math.Max(centerYReference + myCenterOffset.Y - height / 2, 0)), pixelLevelZoom);
            Geocode brGeo            = PointToGeocode(new Point(Math.Min(centerXReference + myCenterOffset.X + width / 2, 1 << pixelLevelZoom), Math.Min(centerYReference + myCenterOffset.Y + height / 2, 1 << pixelLevelZoom)), pixelLevelZoom);
            int     adjustX          = midX - centerXReference;
            int     adjustY          = midY - centerYReference;

            foreach (Route route in myRoutes)
            {
                List <Point> points             = new List <Point>();
                Geocode      lastOffscreenPoint = Geocode.Null;
                for (int i = 0; i < route.PolyLine.Length; i++)
                {
                    Geocode geocode = route.PolyLine[i];
                    if (myLevelToZoom[route.Levels[i]] > myZoom)
                    {
                        continue;
                    }

                    // check if we're drawing off the screen
                    if (!GeocodeBoxContains(tlGeo, brGeo, geocode))
                    {
                        // if we're drawing from on screen to off screen, draw it, but note that
                        // we are now off screen
                        if (lastOffscreenPoint == Geocode.Null)
                        {
                            points.Add(GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY));
                        }

                        lastOffscreenPoint = geocode;
                        continue;
                    }

                    // draw in from off the screen if necessary
                    if (lastOffscreenPoint != Geocode.Null)
                    {
                        points.Add(GeocodeToScreen(lastOffscreenPoint, pixelLevelZoom, adjustX, adjustY));
                    }
                    // note that we are now in screen space
                    lastOffscreenPoint = Geocode.Null;

                    points.Add(GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY));
                }
                if (points.Count > 1)
                {
                    renderer.DrawLines(route.LineWidth, Color.Cyan, points.ToArray());
                }
            }

            foreach (IMapOverlay overlay in Overlays)
            {
                DrawAtGeocode(tlGeo, brGeo, renderer, overlay.Geocode, pixelLevelZoom, adjustX + overlay.Offset.X, adjustY + overlay.Offset.Y, overlay.Drawable);
            }

            return(unavailable);
        }
Пример #16
0
        void DrawAtGeocode(Geocode tlGeo, Geocode brGeo, IMapRenderer renderer, Geocode geocode, int pixelLevelZoom, int adjustX, int adjustY, IMapDrawable drawable)
        {
            if (!GeocodeBoxContains(tlGeo, brGeo, geocode) || drawable == null)
            {
                return;
            }
            Point p = GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY);

            renderer.Draw(drawable, new Rectangle(p.X - drawable.Width / 2, p.Y - drawable.Height / 2, drawable.Width, drawable.Height), new Rectangle(0, 0, drawable.Width, drawable.Height));
        }
Пример #17
0
 public TileData(IMapDrawable bitmap)
 {
     Bitmap = bitmap;
 }
Пример #18
0
        /// <summary>
        /// Adds a new draw object to the map
        /// </summary>
        /// <param name="drawObject">The IMapDrawable object that is being added to the map</param>
        /// <param name="refresh">Specifies whether the map should be redrawn after the object is added</param>
        public void AddDrawObject( IMapDrawable drawObject, bool refresh )
        {
            m_DrawObjects.Add( drawObject );

            if ( refresh )
                Refresh();
        }
Пример #19
0
        /// <summary>
        /// Adds a new draw object to the map and redraws the map
        /// </summary>
        /// <param name="drawObject">The IMapDrawable object that should be added</param>
        public void AddDrawObject( IMapDrawable drawObject )
        {
            m_DrawObjects.Add( drawObject );

            // Redraw the map
            Refresh();
        }
Пример #20
0
        void GetTile(object o)
        {
            using (GetTileData data = (GetTileData)o)
            {
                try
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(data.Uri);
                    request.Timeout   = 15000;
                    request.Method    = "GET";
                    request.UserAgent = "Windows-RSS-Platform/1.0 (MSIE 7.0; Windows NT 5.1)";

                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        if (response.StatusCode != HttpStatusCode.OK)
                        {
                            throw new Exception("Error while downloading tile.");
                        }

                        if (TileCache != null)
                        {
                            using (Stream s = response.GetResponseStream())
                            {
                                using (MemoryStream mem = new MemoryStream())
                                {
                                    int    read   = 0;
                                    byte[] buffer = new byte[10000];
                                    do
                                    {
                                        read = s.Read(buffer, 0, buffer.Length);
                                        mem.Write(buffer, 0, read);
                                    }while (read != 0);
                                    mem.Seek(0, SeekOrigin.Begin);

                                    string tilePath = GetTilePathForKey(data.Key);
                                    using (FileStream file = new FileStream(tilePath, FileMode.Create, FileAccess.Write))
                                    {
                                        file.Write(mem.GetBuffer(), 0, (int)mem.Length);
                                    }

                                    IMapDrawable pbitmap = data.Renderer.GetBitmapFromStream(this, mem);
                                    if (pbitmap == null)
                                    {
                                        throw new Exception();
                                    }
                                    TileCache[data.Key] = new TileData(pbitmap);
                                }
                            }
                            if (data.Callback != null)
                            {
                                data.Callback(data.State);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    if (TileCache != null)
                    {
                        //TileCache.Remove(data.Key);
                        TileCache[data.Key] = InvalidTile;
                    }
                }
            }
        }
Пример #21
0
 /// <summary>
 /// Creates a new EventArgs for use with draw objects
 /// </summary>
 /// <param name="drawobject">The IMapDrawable object used as data for this args</param>
 /// <param name="point">The point that originated the event</param>
 public DrawObjectEventArgs(IMapDrawable drawobject, Point point)
 {
     m_DrawObject = drawobject;
     m_Point      = point;
 }
Пример #22
0
        public void Draw(IMapDrawable drawable, Rectangle destRect, Rectangle sourceRect)
        {
            IGraphicsDrawable graphicsDrawable = drawable as IGraphicsDrawable;

            graphicsDrawable.Draw(Graphics, destRect, sourceRect);
        }
Пример #23
0
        public override TileData GetTile(TiledMapSession.Key key, IMapRenderer renderer, System.Threading.WaitCallback callback, object state)
        {
            TileData tileData = null;

            // try to get the tile
            if (TileCache.TryGetValue(key, out tileData))
            {
                if (tileData != InvalidTile)
                {
                    return(tileData);
                }
                TileCache.Remove(key);
            }

            // check if it is in the file cache
            string tilePath = GetTilePathForKey(key);

            if (File.Exists(tilePath))
            {
                FileInfo finfo = new FileInfo(tilePath);
                if (DateTime.Now - finfo.CreationTime > new TimeSpan(2, 0, 0, 0))
                {
                    // tile is old, expire it
                    File.Delete(tilePath);
                }
                else
                {
                    TileCache[key] = null;
                    ThreadPool.QueueUserWorkItem((o) =>
                    {
                        try
                        {
                            using (FileStream fstream = new FileStream(tilePath, FileMode.Open))
                            {
                                IMapDrawable bitmap = renderer.GetBitmapFromStream(this, fstream);
                                TileCache[key]      = new TileData(bitmap);
                                if (callback != null)
                                {
                                    callback(state);
                                }
                            }
                        }
                        catch (Exception)
                        {
                            File.Delete(tilePath);
                        }
                    });
                    return(null);
                }
            }

            // check if its a bad key
            Uri uri = GetUriForKey(key);

            if (uri != null)
            {
                // mark tile as being downloaded
                TileCache[key] = null;
                GetTileData data = new GetTileData();
                data.Renderer = renderer;
                data.Key      = key;
                data.Callback = callback;
                data.State    = state;
                data.Uri      = uri;
                ThreadPool.QueueUserWorkItem(new WaitCallback(GetTile), data);
                //GetTile(data);
            }
            return(tileData);
        }
Пример #24
0
 public MapOverlay(IMapDrawable drawable, Geocode geocode, Point offset)
 {
     myDrawable = drawable;
     myOffset = offset;
     myGeocode = geocode;
 }
Пример #25
0
 /// <summary>
 /// Removes a draw object from the list of displayed objects
 /// </summary>
 /// <param name="drawObject">The draw object to be removed</param>
 public void RemoveDrawObject( IMapDrawable drawObject )
 {
     if ( m_DrawObjects.Contains( drawObject ) )
         m_DrawObjects.Remove( drawObject );
 }