Example #1
0
        public override void OnRender(Canvas canvas)
        {
            if (!PauseRendering)
            {
                Rectangle PlayfieldRect = canvas.TargetControl.ClientRectangle;
                _playfield.ClientArea = PlayfieldRect;

                int bottom_left = (PlayfieldRect.Y + PlayfieldRect.Height);

                Rectangle SpriteRect = Rectangle.Empty;

                if (Map != null)
                {
                    SpriteRect = Map.ToRectangle();

                    // Prevent black from appearing on sides of map.
                    if (!SpriteRect.Contains(PlayfieldRect))
                    {
                        int right = (int)(Map.Position.X + (Map.TextureWidth * _playfield.Scale));
                        int bottom = (int)(Map.Position.Y + (Map.TextureHeight * _playfield.Scale));
                        if (right < PlayfieldRect.Width)
                        {
                            Pan(PlayfieldRect.Width - right, 0);
                        }
                        if (bottom < PlayfieldRect.Height)
                        {
                            Pan(0, PlayfieldRect.Height - bottom);
                        }
                        if (Map.Position.Y > PlayfieldRect.Y)
                        {
                            Pan(0, -(Map.Position.Y));
                        }
                        if (Map.Position.X > PlayfieldRect.X)
                        {
                            Pan(-(Map.Position.X), 0);
                        }
                    }
                }

                switch (MapScrollState)
                {
                    case MapPlayfieldScrollState.UP:
                        Pan(0, -10);
                        break;
                    case MapPlayfieldScrollState.DOWN:
                        Pan(0, 10);
                        break;
                    case MapPlayfieldScrollState.LEFT:
                        Pan(-10, 0);
                        break;
                    case MapPlayfieldScrollState.RIGHT:
                        Pan(10, 0);
                        break;
                }

                _playfield.OnRender(canvas);

                if (WBRoom != null)
                {
                    // Draw Whiteboard information from other selected rooms
                    List<string> otherWBNames = WBRoom.GetOtherWBRoomNames();
                    if (otherWBNames != null)
                    {
                        foreach (string otherWBName in otherWBNames)
                        {
                            DrawWhiteboardRoomObjects(WBRoom.GetOtherWBRoom(otherWBName), canvas);
                        }
                    }

                    // Draw Whiteboard information from current room
                    DrawWhiteboardRoomObjects(WBRoom, canvas);

                    // Draw any commands in progress
                    if ((WBRoom.DrawMode == DrawModes.Line) &&
                        (DrawDistanceLine == true) && (WhiteboardDrawing == true))
                    {
                        if ((WBRoom.DrawText != null) && (WBRoom.DrawText.Length > 0))
                        {
                            int lineTextSize = LineTextSize;

                            DrawShortenedLine(canvas, WBRoom.DrawColor, WBRoom.DrawPointSize, LineStartLocation.X, LineStartLocation.Y,
                                LineEndLocation.X, LineEndLocation.Y, 1f);

                            if (lineTextSize > MaxFontSize)
                            {
                                lineTextSize = MaxFontSize;
                            }
                            if (lineTextSize < 1)
                            {
                                lineTextSize = 1;
                            }
                            if (wbFonts[lineTextSize] == null)
                            {
                                wbFonts[lineTextSize] = canvas.CreateFont(new System.Drawing.Font("Arial", lineTextSize, FontStyle.Bold, GraphicsUnit.Pixel));
                            }
                            DrawCenteredText(wbFonts[lineTextSize], WBRoom.DrawText, LineEndLocation.X, LineEndLocation.Y, WBRoom.DrawColor);
                        }
                        else
                        {
                            canvas.DrawLine(WBRoom.DrawColor, WBRoom.DrawPointSize, LineStartLocation.X, LineStartLocation.Y,
                                LineEndLocation.X, LineEndLocation.Y);
                        }
                    }
                    else if ((WBRoom.DrawMode == DrawModes.Circle) &&
                        (DrawDistanceLine == true) && (WhiteboardDrawing == true))
                    {
                        canvas.DrawCircle(WBRoom.DrawColor, WBRoom.DrawPointSize, LineStartLocation.X, LineStartLocation.Y,
                            LineEndLocation.X, LineEndLocation.Y);
                    }
                    else if ((WBRoom.DrawMode == DrawModes.Arrow) &&
                        (DrawDistanceLine == true) && (WhiteboardDrawing == true))
                    {
                        canvas.DrawArrow(WBRoom.DrawColor, WBRoom.DrawPointSize, LineStartLocation.X, LineStartLocation.Y,
                            LineEndLocation.X, LineEndLocation.Y);
                    }
                    else if ((WBRoom.DrawMode == DrawModes.Text) &&
                        (DrawDistanceLine == true) && (WhiteboardDrawing == true))
                    {
                        if ((WBRoom.DrawText != null) && (WBRoom.DrawText.Length > 0))
                        {
                            int drawPointSize = WBRoom.DrawPointSize + 7;

                            if (drawPointSize > MaxFontSize)
                            {
                                drawPointSize = MaxFontSize;
                            }
                            if (wbFonts[drawPointSize] == null)
                            {
                                wbFonts[drawPointSize] = canvas.CreateFont(new System.Drawing.Font("Arial", drawPointSize, FontStyle.Bold, GraphicsUnit.Pixel));
                            }
                            DrawCenteredText(wbFonts[drawPointSize], WBRoom.DrawText, LineEndLocation.X, LineEndLocation.Y, WBRoom.DrawColor);
                        }
                    }
                    else if ((WBRoom.DrawMode == DrawModes.Selection) &&
                        (DrawDistanceLine == true) && (WhiteboardDrawing == true))
                    {
                        RectangleF selectionRect;

                        int selectionX = Math.Min(LineStartLocation.X, LineEndLocation.X);
                        int selectionY = Math.Min(LineStartLocation.Y, LineEndLocation.Y);

                        selectionRect = new RectangleF((float)selectionX, (float)selectionY,
                            (float)Math.Abs(LineStartLocation.X - LineEndLocation.X),
                            (float)Math.Abs(LineStartLocation.Y - LineEndLocation.Y));
                        canvas.DrawRect(selectionRect, Color.Orange);
                    }
                }

                // Draw Mini map
                _bottom_status_bar.Height = 35;
                _bottom_status_bar.Width = PlayfieldRect.Width;
                _bottom_status_bar.X = PlayfieldRect.X;
                _bottom_status_bar.Y = bottom_left - _bottom_status_bar.Height;
                canvas.DrawFillRect(_bottom_status_bar, _mini_map_background);
                
                if (true) //check DDD_Global or playfield
                {
                    if (_rangeFinderFont == null && this.Fonts.ContainsKey("RangeRing"))
                    {
                        _rangeFinderFont = this.Fonts["RangeRing"];
                    }
                    string rangeText = DDD_Global.Instance.GetRangeFinderDisplayString();

                    if (_rangeFinderFont != null && rangeText.Trim() != string.Empty)
                    {
                        _mouseoverRangeFinderDisplay = _rangeFinderFont.MeasureString(null, rangeText, DrawTextFormat.Center, Color.White);
                        _mouseoverRangeFinderDisplay.X = Convert.ToInt32(DDD_Global.Instance.RangeFinderXDisplay);// 500;
                        _mouseoverRangeFinderDisplay.Y = Convert.ToInt32(DDD_Global.Instance.RangeFinderYDisplay);// 400;
                        _mouseoverRangeFinderDisplay.Width += 10;
                        canvas.DrawFillRect(_mouseoverRangeFinderDisplay, _mini_map_background);//_rangeFinderMaterial);
                        _rangeFinderFont.DrawText(null, rangeText, _mouseoverRangeFinderDisplay, DrawTextFormat.Center, Color.White);

                        //DRAW LINE FROM OBJECT TO CURSOR

                        float objX = 0f;
                        float objY = 0f;
                        DDDObjects obj = _playfield.GetSelectedObject();
                        if (obj != null)
                        {
                            objX = obj.ScreenCoordinates.X;
                            objY = obj.ScreenCoordinates.Y;

                            canvas.DrawLine(Color.Black, 3, _mouseoverRangeFinderDisplay.X - 10, _mouseoverRangeFinderDisplay.Y - 15, objX, objY);
                        }
                    }
                }

                if (!MiniMapOverride)
                {
                    if ((!Map_IsContained_Horizontal(PlayfieldRect)) && (!Map_IsContained_Vertical(PlayfieldRect)))
                    {
                        ShowMiniMap = false;
                    }
                    else
                    {
                        ShowMiniMap = true;
                    }

                    if (WBRoom != null)
                    {
                        ShowMiniMap = true;
                    }
     
                    if (ShowMiniMap)
                    {
                        _mini_map.X = (PlayfieldRect.X + PlayfieldRect.Width) - _mini_map.Width;
                        _mini_map.Y = 0;
                        _mini_map.Height = (int)((Map.TextureHeight / Map.TextureWidth) * (float)_mini_map.Width);

                        _mini_map_thumb.X = (int)(-(Map.Position.X / (Map.TextureWidth * _playfield.Scale)) * (float)_mini_map.Width) + _mini_map.X;
                        _mini_map_thumb.Y = (int)(-(Map.Position.Y / (Map.TextureHeight * _playfield.Scale)) * (float)_mini_map.Height) + _mini_map.Y;
                        _mini_map_thumb.Width = (int)(_mini_map.Width * ((float)PlayfieldRect.Width / (Map.TextureWidth * _playfield.Scale)));
                        _mini_map_thumb.Height = (int)(_mini_map.Height * ((float)PlayfieldRect.Height / (Map.TextureHeight * _playfield.Scale)));

                        canvas.DrawFillRect(_mini_map, _mini_map_background);

                        // Draw rect for other users in a whiteboard room
                        if (wbRoom != null)
                        {
                            int originX = 0;
                            int originY = 0;
                            int screenSizeWidth = 0;
                            int screenSizeHeight = 0;
                            double screenZoom = 0.0;

                            foreach (string wbUser in wbRoom.MembershipList)
                            {
                                if (string.Compare(wbUser, DDD_Global.Instance.PlayerID) == 0)
                                {
                                    continue;
                                }

                                if (wbRoom.GetScreenViewInfo(wbUser, ref originX, ref originY, ref screenSizeWidth, ref screenSizeHeight,
                                        ref screenZoom))
                                {
                                    Rectangle userMiniMapRect = Rectangle.Empty;
                                    Vector2 _metersPerPixelValues = new Vector2();
                                    Vector2 userPosition = new Vector2();
                                    _metersPerPixelValues.X = UTM_Mapping.HorizonalMetersPerPixel;
                                    _metersPerPixelValues.Y = UTM_Mapping.VerticalMetersPerPixel;

                                    userPosition.X = (float) originX / _metersPerPixelValues.X;
                                    userPosition.Y = (float)originY  / _metersPerPixelValues.Y;
                                    userMiniMapRect.X = (int)((userPosition.X / (Map.TextureWidth)) * (float)_mini_map.Width) + _mini_map.X;
                                    userMiniMapRect.Y = (int)((userPosition.Y / (Map.TextureHeight)) * (float)_mini_map.Height) + _mini_map.Y;
                                    userMiniMapRect.Width = (int)((float)screenSizeWidth / _metersPerPixelValues.X /
                                        Map.TextureWidth * (float)_mini_map.Width);
                                    userMiniMapRect.Height = (int)((float)screenSizeHeight / _metersPerPixelValues.Y /
                                        Map.TextureHeight * (float)_mini_map.Height);

                                    // Draw rect for this a whiteboard user
                                    if (DMColorMap.ContainsKey(wbUser))
                                    {
                                        canvas.DrawRect(userMiniMapRect, Color.FromArgb(DMColorMap[wbUser]));
                                    }
                                    else
                                    {
                                        canvas.DrawRect(userMiniMapRect, Color.DarkBlue);
                                    }
                                }

                            }
                        }

                        // Draw rect for this user
                        if ((wbRoom != null) && DMColorMap.ContainsKey(DDD_Global.Instance.PlayerID))
                        {
                            canvas.DrawRect(_mini_map_thumb, Color.FromArgb(DMColorMap[DDD_Global.Instance.PlayerID]));
                        }
                        else
                        {
                            canvas.DrawRect(_mini_map_thumb, Color.Red);
                        }

                        lock (this)
                        {
                            DDDObjects selected = GetSelectedObject();
                            foreach (string obj_name in _playfield.PlayfieldObjects)
                            {
                                DDDObjects obj = (DDDObjects)_playfield.GetMappableObject(obj_name);
                                if (obj != null)
                                {
                                    _mini_map_track.X = (int)(((_mini_map.Width / Map.TextureWidth) * obj.Position.X) + _mini_map.X) - (int)(.5 * _mini_map_track.Width);
                                    _mini_map_track.Y = (int)(((_mini_map.Height / Map.TextureHeight) * obj.Position.Y) + _mini_map.Y) - (int)(.5 * _mini_map_track.Height);
                                    if (selected != null)
                                    {
                                        if ((selected.ID == obj.ID) && !ShowUnitColorOnMiniMap)
                                        {
                                            canvas.DrawTri(_mini_map_track, Color.Yellow, DIRECTION.UP);
                                            continue;
                                        }
                                    }

                                    if (!ShowUnitColorOnMiniMap)
                                    {
                                        canvas.DrawTri(_mini_map_track, Color.DodgerBlue, DIRECTION.UP);
                                    }
                                    else
                                    {
                                        canvas.DrawTri(_mini_map_track, obj.TextBoxColor, DIRECTION.UP);
                                    }

                                }
                            }


                            foreach (string obj_name in _playfield.PlayfieldObjects)
                            {
                                DDDObjects obj = (DDDObjects)_playfield.GetMappableObject(obj_name);
                                if (obj != null)
                                {
                                    _mini_map_track.X = (int)(((_mini_map.Width / Map.TextureWidth) * obj.Position.X) + _mini_map.X) - (int)(.5 * _mini_map_track.Width);
                                    _mini_map_track.Y = (int)(((_mini_map.Height / Map.TextureHeight) * obj.Position.Y) + _mini_map.Y) - (int)(.5 * _mini_map_track.Height);

                                    if (obj.IsBeingAttacked)
                                    {
                                        if (GameFramework.ElapsedSeconds(AnimationTimer, AnimationCycle))
                                        {
                                            AnimationTimer = GameFramework.QueryPerformanceTimer();
                                        }
                                        if (GameFramework.ElapsedSeconds(AnimationTimer, BlinkCycle))
                                        {
                                            canvas.DrawTri(_mini_map_track, Color.White, DIRECTION.UP);
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }



                if (ShowPosition)
                {

                    DDDObjects obj = _playfield.GetSelectedObject();
                    if (obj != null)
                    {
                        if (obj.IsPathCalculatorRunning())
                        {
                            canvas.DrawFillRect(_bottom_status_bar, _mini_map_background);
                            SizeF size = obj.DrawIcon(canvas, PlayfieldRect.X, _bottom_status_bar.Y, 30, 30);

                            int font_height = (Fonts["Arial8B"].MeasureString(null, obj.FullVelocityStr, DrawTextFormat.None, Color.White)).Height;

                            Fonts["Arial8B"].DrawText(null, obj.FullVelocityStr, PlayfieldRect.X + (int)size.Width + 2, _bottom_status_bar.Y, Color.White);
                            Fonts["Arial8B"].DrawText(null, obj.FullTTDStr, PlayfieldRect.X + (int)size.Width + 2, (_bottom_status_bar.Y + font_height), Color.White);
                            Fonts["Arial8B"].DrawText(null, obj.FullDestinationStr, PlayfieldRect.X + (int)size.Width + 2, (_bottom_status_bar.Y + (2 * font_height)), Color.White);
                        }
                        else
                        {
                            SizeF size = obj.DrawIcon(canvas, PlayfieldRect.X, _bottom_status_bar.Y, 30, 30);

                            int font_height = (Fonts["Arial10B"].MeasureString(null, obj.ObjectID, DrawTextFormat.None, Color.White)).Height;
                            Fonts["Arial10B"].DrawText(null, obj.ObjectID, PlayfieldRect.X + (int)size.Width, (_bottom_status_bar.Bottom - font_height), Color.White);
                        }
                    }
                }


                int width;
                String str = String.Empty;
                if (!IsPaused)
                {
                    if (DDD_Global.Instance.IsForkReplay)
                    {
                        str = String.Format("Fork Replay {0}", Time);
                    }
                    else
                    {
                        str = Time;
                    }
                }
                else
                {
                    str = "Paused";
                }
                width = (Fonts["Arial10B"].MeasureString(null, str, DrawTextFormat.None, Color.Yellow)).Width + 5;
                Fonts["Arial10B"].DrawText(null, str, _bottom_status_bar.X + (_bottom_status_bar.Width - width), _bottom_status_bar.Y + 5, Color.Yellow);
                //if (!IsPaused)
                //{
                //    if (DDD_Global.Instance.IsForkReplay)
                //    {
                //        width = (Fonts["Arial10B"].MeasureString(null, Time, DrawTextFormat.None, Color.Yellow)).Width + 5;
                //        Fonts["Arial10B"].DrawText(null, String.Format("Fork Replay {0}",Time), _bottom_status_bar.X + (_bottom_status_bar.Width - width), _bottom_status_bar.Y + 5, Color.Yellow);
                //    }
                //    else
                //    {
                //        width = (Fonts["Arial10B"].MeasureString(null, Time, DrawTextFormat.None, Color.Yellow)).Width + 5;
                //        Fonts["Arial10B"].DrawText(null, Time, _bottom_status_bar.X + (_bottom_status_bar.Width - width), _bottom_status_bar.Y + 5, Color.Yellow);
                //    }
                //}
                //else
                //{
                //    width = (Fonts["Arial10B"].MeasureString(null, Time, DrawTextFormat.None, Color.Yellow)).Width + 5;
                //    Fonts["Arial10B"].DrawText(null, "Paused", _bottom_status_bar.X + (_bottom_status_bar.Width - width), _bottom_status_bar.Y + 5, Color.Yellow);
                //}

            }

        }
Example #2
0
        public void DrawWhiteboardRoomObjects(WhiteboardRoom wbRoom, Canvas canvas)
        {
            if (wbRoom == null)
            {
                return;
            }

            // Draw all whiteboard commands
            Array drawingCommands = wbRoom.GetCurrentDrawingCommands();

            foreach (object obj in drawingCommands)
            {
                if (obj is LineObject)
                {
                    LineObject line = (LineObject)obj;
                    LocationValue start = new LocationValue();
                    LocationValue end = new LocationValue();
                    int drawPointSize = (int)(line.Width * _playfield.Scale);

                    if ((drawPointSize == 0) && (line.Width > 0))
                    {
                        drawPointSize = 1;
                    }

                    if ((line.Mode == DrawModes.Line) || (line.Mode == DrawModes.Circle) ||
                        (line.Mode == DrawModes.Arrow))
                    {
                        start.X = line.Start.X * _playfield.Scale + Map.Position.X;
                        start.Y = line.Start.Y * _playfield.Scale + Map.Position.Y;

                        end.X = line.End.X * _playfield.Scale + Map.Position.X;
                        end.Y = line.End.Y * _playfield.Scale + Map.Position.Y;

                        if (line.Mode == DrawModes.Line)
                        {
                            if ((line.Text != null) && (line.Text.Length > 0))
                            {
                                int lineTextSize = (int) ((LineTextSize / line.OriginalScale) * _playfield.Scale);

                                DrawShortenedLine(canvas, line.Color, drawPointSize, (float)start.X, (float)start.Y,
                                    (float)end.X, (float)end.Y, (float) (_playfield.Scale / line.OriginalScale));

                                if (lineTextSize > MaxFontSize)
                                {
                                    lineTextSize = MaxFontSize;
                                }
                                if (lineTextSize < 1)
                                {
                                    lineTextSize = 1;
                                }
                                if (wbFonts[lineTextSize] == null)
                                {
                                    wbFonts[lineTextSize] = canvas.CreateFont(new System.Drawing.Font("Arial", lineTextSize, FontStyle.Bold, GraphicsUnit.Pixel));
                                }
                                DrawCenteredText(wbFonts[lineTextSize], line.Text, (int)end.X, (int)end.Y, line.Color);
                            }
                            else
                            {
                                canvas.DrawLine(line.Color, drawPointSize, (float)start.X, (float)start.Y,
                                    (float)end.X, (float)end.Y);
                            }
                        }
                        else if (line.Mode == DrawModes.Circle)
                        {
                            canvas.DrawCircle(line.Color, drawPointSize, (float)start.X, (float)start.Y,
                                (float)end.X, (float)end.Y);
                        }
                        else if (line.Mode == DrawModes.Arrow)
                        {
                            canvas.DrawArrow(line.Color, drawPointSize, (float)start.X, (float)start.Y,
                                (float)end.X, (float)end.Y);
                        }
                    }
                    else if ((line.Mode == DrawModes.Text) && (line.Text != null) &&
                        (line.Text.Length > 0))
                    {
                        start.X = line.Start.X * _playfield.Scale + Map.Position.X;
                        start.Y = line.Start.Y * _playfield.Scale + Map.Position.Y;

                        if (drawPointSize > MaxFontSize)
                        {
                            drawPointSize = MaxFontSize;
                        }
                        if (wbFonts[drawPointSize] == null)
                        {
                            wbFonts[drawPointSize] = canvas.CreateFont(new System.Drawing.Font("Arial", drawPointSize, FontStyle.Bold, GraphicsUnit.Pixel));
                        }
                        DrawCenteredText(wbFonts[drawPointSize], line.Text, (int)start.X, (int)start.Y, line.Color);

                        // Update the bounding box if needed
                        if ((line.BoundingPolygon == null) || (wbRoom == WBRoom))
                        {
                            RectangleF textRect;
                            Polygon textPoly;
                            float width;
                            float height;
                            PointF boundStart = new PointF();

                            textRect = wbFonts[drawPointSize].MeasureString(null, line.Text, DrawTextFormat.None, line.Color);

                            width = textRect.Right / _playfield.Scale;
                            if ((width * line.OriginalScale) < 5)
                            {
                                width = 5 / (float) line.OriginalScale;
                            }
                            height = textRect.Bottom / _playfield.Scale;
                            if ((height * line.OriginalScale) < 5)
                            {
                                height = 5 / (float) line.OriginalScale;
                            }
                            boundStart.X = (float)line.Start.X - (width / 2);
                            boundStart.Y = (float)line.Start.Y - (height / 2);

                            textPoly = new Polygon();
                            textPoly.Points.Add(new Vector(boundStart.X, boundStart.Y));
                            textPoly.Points.Add(new Vector(boundStart.X + width, boundStart.Y));
                            textPoly.Points.Add(new Vector(boundStart.X + width, boundStart.Y + height));
                            textPoly.Points.Add(new Vector(boundStart.X, boundStart.Y + height));
                            textPoly.Offset(0, 0);
                            textPoly.BuildEdges();

                            line.BoundingPolygon = textPoly;
                        }
                    }

                    // Draw Bounding rectable if object is selected
                    if ((line.ObjectSelected) && (line.BoundingPolygon != null) && (line.BoundingPolygon.Points.Count >= 2))
                    {
                        LocationValue boundStart = new LocationValue();
                        LocationValue boundEnd = new LocationValue();
                        Vector prevPoint = line.BoundingPolygon.Points[line.BoundingPolygon.Points.Count - 1]; 
                        foreach (Vector curPoint in line.BoundingPolygon.Points)
                        {
                            boundStart.X = prevPoint.X * _playfield.Scale + Map.Position.X;
                            boundStart.Y = prevPoint.Y * _playfield.Scale + Map.Position.Y;

                            boundEnd.X = curPoint.X * _playfield.Scale + Map.Position.X;
                            boundEnd.Y = curPoint.Y * _playfield.Scale + Map.Position.Y;

                            canvas.DrawLine(Color.Black.ToArgb(), 1, (float)boundStart.X, (float)boundStart.Y,
                                (float)boundEnd.X, (float)boundEnd.Y);

                            prevPoint = curPoint;
                        }
                    }
                }
            }
        }