예제 #1
0
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            if (SimulationGame.IsWorldBuilderOpen)
            {
                spriteBatch.Draw(backgroundOverlay, Bounds.ToXnaRectangle(), backgroundColor);
                base.Draw(spriteBatch, gameTime);

                if (placementType != PlacementType.NoType && placementType != PlacementType.Inspect && placementType != PlacementType.WorldPartDetails)
                {
                    switch (placementMode)
                    {
                    case PlacementMode.Manage:
                        manageObjectList.Draw(spriteBatch, gameTime);

                        if (manageObjectList.SelectedElement != null)
                        {
                            editBtn.Draw(spriteBatch, gameTime);
                            createNewFromBtn.Draw(spriteBatch, gameTime);
                            removeBtn.Draw(spriteBatch, gameTime);
                        }
                        break;

                    case PlacementMode.ChooseTileset:
                        tilesetSelectionList.Draw(spriteBatch, gameTime);
                        break;

                    case PlacementMode.CreateFromTileset:
                        tileSetSelectionView.Draw(spriteBatch, gameTime);

                        if (tileSetSelectionView.SelectedSpritePosition != null)
                        {
                            createBtn.Draw(spriteBatch, gameTime);
                            createIfNotExistBtn.Draw(spriteBatch, gameTime);
                        }

                        break;
                    }

                    manageBtn.Draw(spriteBatch, gameTime);
                    createFromJsonBtn.Draw(spriteBatch, gameTime);

                    if (placementType != PlacementType.LivingEntityPlacement)
                    {
                        createFromTilesetBtn.Draw(spriteBatch, gameTime);
                    }
                }
                else if (placementType == PlacementType.WorldPartDetails)
                {
                    changePersistencyBtn.Draw(spriteBatch, gameTime);
                    createWorldLinkBtn.Draw(spriteBatch, gameTime);
                    createInteriorBtn.Draw(spriteBatch, gameTime);

                    if (SimulationGame.Player.InteriorID != Interior.Outside)
                    {
                        changeInteriorDimensionsBtn.Draw(spriteBatch, gameTime);
                        removeInteriorBtn.Draw(spriteBatch, gameTime);
                    }

                    worldPartDetailsTextView.Draw(spriteBatch, gameTime);
                }
                else if (placementType == PlacementType.Inspect)
                {
                    if (inspectView.SelectedGameObjects.Count > 0)
                    {
                        editInstanceBtn.Draw(spriteBatch, gameTime);
                        removeInstanceBtn.Draw(spriteBatch, gameTime);
                        showInstanceTypeBtn.Draw(spriteBatch, gameTime);
                        selectedObjectDetailTextView.Draw(spriteBatch, gameTime);
                    }
                    else if (inspectView.SelectedWorldLink != null)
                    {
                        editInstanceBtn.Draw(spriteBatch, gameTime);
                        removeInstanceBtn.Draw(spriteBatch, gameTime);

                        selectedObjectDetailTextView.Draw(spriteBatch, gameTime);
                    }
                }

                if ((placementMode == PlacementMode.Manage && manageObjectList.SelectedElement != null) ||
                    (placementMode == PlacementMode.CreateFromTileset && tileSetSelectionView.SelectedObject != null))
                {
                    placeView.Draw(spriteBatch, gameTime);

                    if (placeView.Bounds.Contains(SimulationGame.MouseState.Position))
                    {
                        if (SimulationGame.KeyboardState.IsKeyDown(Keys.LeftControl) || SimulationGame.KeyboardState.IsKeyDown(Keys.RightControl))
                        {
                            WorldBuilderUtils.DrawPreview(spriteBatch, SimulationGame.MouseState.Position.ToVector2(), (placementMode == PlacementMode.Manage) ? ((ObjectListItem)manageObjectList.SelectedElement).GetObject() : tileSetSelectionView.SelectedObject);
                        }
                        else
                        {
                            var isBlockSelected = false;

                            if (placementMode == PlacementMode.Manage)
                            {
                                if (((ObjectListItem)manageObjectList.SelectedElement) is BlockListItem)
                                {
                                    isBlockSelected = true;
                                }
                            }
                            else if (placementMode == PlacementMode.CreateFromTileset)
                            {
                                if (tileSetSelectionView.SelectedObject is BlockType)
                                {
                                    isBlockSelected = true;
                                }
                            }

                            if (isBlockSelected)
                            {
                                var worldBlockPosition = GeometryUtils.GetBlockFromReal((int)SimulationGame.RealWorldMousePosition.X, (int)SimulationGame.RealWorldMousePosition.Y);

                                WorldBuilderUtils.DrawPreview(spriteBatch, SimulationGame.ConvertWorldPositionToUIPosition(worldBlockPosition.X * WorldGrid.BlockSize.X, worldBlockPosition.Y * WorldGrid.BlockSize.Y), (placementMode == PlacementMode.Manage) ? ((ObjectListItem)manageObjectList.SelectedElement).GetObject() : tileSetSelectionView.SelectedObject);
                            }
                            else
                            {
                                var worldBlockPosition = GeometryUtils.GetChunkPosition((int)SimulationGame.RealWorldMousePosition.X, (int)SimulationGame.RealWorldMousePosition.Y, 16, 16);

                                WorldBuilderUtils.DrawPreview(spriteBatch, SimulationGame.ConvertWorldPositionToUIPosition(worldBlockPosition.X * 16, worldBlockPosition.Y * 16), (placementMode == PlacementMode.Manage) ? ((ObjectListItem)manageObjectList.SelectedElement).GetObject() : tileSetSelectionView.SelectedObject);
                            }
                        }
                    }
                }
                else
                {
                    inspectView.Draw(spriteBatch, gameTime);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Raises the <see cref="Control.Paint"></see> event.
        /// </summary>
        /// <param name="e">A <see cref="PaintEventArgs"></see> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            int       currentXPos      = 0;
            int       currentYPos      = 0;
            bool      adjustScrollBars = false;
            Graphics  g             = e.Graphics;
            Rectangle clipRectangle = e.ClipRectangle;

            if (clipRectangle.Width <= 0 || clipRectangle.Height <= 0)
            {
                return;
            }

            bool isFullRepaint = clipRectangle.X == 0 && clipRectangle.Y == 0 &&
                                 clipRectangle.Width == Width && clipRectangle.Height == Height;

            g.TextRenderingHint = TextEditorProperties.TextRenderingHint;

            foreach (AbstractMargin margin in _leftMargins)
            {
                if (margin.IsVisible)
                {
                    Rectangle marginRectangle = new Rectangle(currentXPos, currentYPos, margin.Size.Width, Height - currentYPos);
                    if (marginRectangle != margin.DrawingPosition)
                    {
                        // margin changed size
                        if (!isFullRepaint && !clipRectangle.Contains(marginRectangle))
                        {
                            Invalidate(); // do a full repaint
                        }
                        adjustScrollBars       = true;
                        margin.DrawingPosition = marginRectangle;
                    }
                    currentXPos += margin.DrawingPosition.Width;
                    if (clipRectangle.IntersectsWith(marginRectangle))
                    {
                        marginRectangle.Intersect(clipRectangle);
                        if (!marginRectangle.IsEmpty)
                        {
                            margin.Draw(g, marginRectangle);
                        }
                    }
                }
            }

            Rectangle textViewArea = new Rectangle(currentXPos, currentYPos, Width - currentXPos, Height - currentYPos);

            if (textViewArea != _textView.DrawingPosition)
            {
                adjustScrollBars          = true;
                _textView.DrawingPosition = textViewArea;
                // update caret position (but outside of WM_PAINT!)
                BeginInvoke((MethodInvoker)_caret.UpdateCaretPosition);
            }
            if (clipRectangle.IntersectsWith(textViewArea))
            {
                textViewArea.Intersect(clipRectangle);
                if (!textViewArea.IsEmpty)
                {
                    _textView.Draw(g, textViewArea);
                }
            }

            if (adjustScrollBars)
            {
                _motherTextAreaControl.AdjustScrollBars();
            }

            base.OnPaint(e);
        }