コード例 #1
0
ファイル: Room.cs プロジェクト: gusmanb/Mir
        public void Render(
            IGameContext gameContext, 
            IRenderContext renderContext, 
            RoomObject focused, 
            bool renderFocusedTransparently, 
            Matrix? matrix = null)
        {
            if (this.m_RefreshBuffers)
            {
                this.RefreshBuffers(renderContext);
                this.m_RefreshBuffers = false;
            }

            var oldWorld = renderContext.World;

            renderContext.World = matrix ?? Matrix.Identity;

            renderContext.EnableTextures();
            renderContext.SetActiveTexture(this.m_TextureAsset.Texture);

            foreach (var pass in renderContext.Effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                this.RenderRoom(renderContext);

                foreach (var obj in this.m_RoomObjects)
                {
                    if (renderFocusedTransparently && obj == focused)
                    {
                        continue;
                    }

                    obj.Render(gameContext, renderContext);
                }
            }

            if (renderFocusedTransparently && focused != null && this.m_RoomObjects.Contains(focused))
            {
                renderContext.GraphicsDevice.BlendState = BlendState.AlphaBlend;
                renderContext.Effect.Parameters["Alpha"].SetValue(0.5f);

                foreach (var pass in renderContext.Effect.CurrentTechnique.Passes)
                {
                    pass.Apply();

                    focused.Render(gameContext, renderContext);
                }

                renderContext.Effect.Parameters["Alpha"].SetValue(1f);
            }

            renderContext.GraphicsDevice.BlendState = BlendState.Opaque;

            renderContext.World = oldWorld;
        }
コード例 #2
0
ファイル: RoomEditorEntity.cs プロジェクト: gusmanb/Mir
 public void ReleaseCurrentSelection()
 {
     this.m_RoomEditorMode = RoomEditorMode.Hovering;
     this.m_SelectedRoomObject = null;
     this.m_SelectedRoomObjectFace = -1;
     this.m_SelectedRoomObjectVerticalEdge = -1;
     this.m_SelectedMouseStartPosition = Vector3.Zero;
     this.m_SelectedRoomObjectDistanceToPlayer = -1;
     this.m_SelectedMouseStartPositionRelative = Vector3.Zero;
 }
コード例 #3
0
ファイル: RoomEditorEntity.cs プロジェクト: gusmanb/Mir
        public void Update(IGameContext gameContext, IUpdateContext updateContext)
        {
            this.m_RenderSelectionTransparently = false;

            var world = (RoomEditorWorld)gameContext.World;

            switch (this.m_RoomEditorMode)
            {
                case RoomEditorMode.Hovering:
                {
                    this.m_HoveredRoomObject = null;
                    this.m_HoveredRoomObjectFace = -1;

                    Vector3 position;
                    IMesh mesh;
                    if (this.m_MeshCollider.Collides(
                        gameContext.MouseRay,
                        this.m_Room.Objects.Concat(new IMesh[] { this.m_Room }),
                        out position,
                        out mesh))
                    {
                        var roomObject = mesh as RoomObject;
                        if (roomObject != null && (!roomObject.SizeLocked || !(world.ActiveRoomTool is SizeRoomTool)))
                        {
                            this.m_HoveredRoomObject = roomObject;
                            this.m_HoveredRoomObjectFace = this.m_HoveredRoomObject.GetFaceForTouchPosition(position);
                            this.m_HoveredRoomObjectVerticalEdge = this.m_HoveredRoomObject.GetVerticalEdge(position);
                            this.m_HoveredMouseStartPosition = position;

                            if (this.UseAlternative)
                            {
                                this.m_RenderSelectionTransparently = true;

                                this.m_MeshCollider.Collides(
                                    gameContext.MouseRay,
                                    new[] { mesh },
                                    out position,
                                    out mesh,
                                    true);

                                this.m_HoveredRoomObjectFace = this.m_HoveredRoomObject.GetFaceForTouchPosition(
                                    position);
                                this.m_HoveredRoomObjectVerticalEdge = this.m_HoveredRoomObject.GetVerticalEdge(
                                    position);
                            }
                        }
                        else if (roomObject == null && mesh == this.m_Room && world.ActiveRoomTool is NewRoomTool)
                        {
                            this.m_HoveredRoomObject = null;
                            this.m_HoveredRoomObjectFace = -1;
                            this.m_HoveredRoomObjectVerticalEdge = -1;
                            this.m_HoveredMouseStartPosition = position;
                        }
                    }

                    break;
                }

                case RoomEditorMode.Selected:
                {
                    if (this.m_IsAlternateMode)
                    {
                        this.m_RenderSelectionTransparently = true;
                    }

                    if (Math.Abs(this.m_SelectedRoomObjectDistanceToPlayer - (-1f)) < 0.0001f)
                    {
                        var player = world.Entities.OfType<PlayerEntity>().First();
                        this.m_SelectedRoomObjectDistanceToPlayer =
                            (this.m_SelectedMouseStartPosition - new Vector3(player.X, player.Y, player.Z)).Length();
                    }

                    if (world.ActiveRoomTool is SizeRoomTool)
                    {
                        this.HandleResize(gameContext);
                    }
                    else if (world.ActiveRoomTool is MoveRoomTool)
                    {
                        this.HandleMove(gameContext);
                    }
                    else if (world.ActiveRoomTool is AngleRoomTool)
                    {
                        this.HandleAngle();
                        this.ReleaseCurrentSelection();
                    }
                    else if (world.ActiveRoomTool is TextureRoomTool)
                    {
                        this.HandleTexture();
                        this.ReleaseCurrentSelection();
                    }
                    else if (world.ActiveRoomTool is NewRoomTool)
                    {
                        this.HandleNew(gameContext);
                        this.ReleaseCurrentSelection();
                    }
                    else if (world.ActiveRoomTool is DeleteRoomTool)
                    {
                        this.HandleDelete();
                        this.ReleaseCurrentSelection();
                    }

                    break;
                }
            }
        }
コード例 #4
0
ファイル: RoomEditorEntity.cs プロジェクト: gusmanb/Mir
        private void HandleNewWire(RoomObject sourceObject, RoomObject destinationObject)
        {
            var sourceConnectable = (IConnectable)sourceObject;
            var destinationConnectable = (IConnectable)destinationObject;

            if (!sourceConnectable.Connections.Contains(destinationConnectable))
            {
                sourceConnectable.Connections.Add(destinationConnectable);
                sourceConnectable.ConnectionsUpdated();
            }

            if (!destinationConnectable.Connections.Contains(sourceConnectable))
            {
                destinationConnectable.Connections.Add(sourceConnectable);
                destinationConnectable.ConnectionsUpdated();
            }
        }
コード例 #5
0
ファイル: RoomEditorEntity.cs プロジェクト: gusmanb/Mir
        public void SelectCurrentHover(IGameContext gameContext, bool secondaryAlt)
        {
            var world = (RoomEditorWorld)gameContext.World;

            if (world.ActiveRoomTool is ExitRoomTool)
            {
                gameContext.SwitchWorld(world.PreviousWorld);
                return;
            }

            if (this.m_HoveredRoomObject == null && !(world.ActiveRoomTool is NewRoomTool))
            {
                return;
            }

            if (this.m_HoveredRoomObject != null && this.m_HoveredRoomObject.SizeLocked && world.ActiveRoomTool is SizeRoomTool)
            {
                // Can't select this object.
                return;
            }

            if (world.ActiveRoomTool is WireNewRoomTool)
            {
                if (this.m_WireSourceRoomObject == null)
                {
                    if (this.m_HoveredRoomObject is IConnectable)
                    {
                        this.m_WireSourceRoomObject = this.m_HoveredRoomObject;
                    }

                    return;
                }

                if (this.m_HoveredRoomObject != this.m_WireSourceRoomObject)
                {
                    if (this.m_HoveredRoomObject is IConnectable)
                    {
                        this.HandleNewWire(this.m_WireSourceRoomObject, this.m_HoveredRoomObject);
                        this.m_WireSourceRoomObject = null;
                    }

                    return;
                }
            }

            this.m_IsAlternateMode = this.UseAlternative;
            this.m_IsSecondaryAlternateMode = secondaryAlt;
            this.m_RoomEditorMode = RoomEditorMode.Selected;
            this.m_SelectedRoomObject = this.m_HoveredRoomObject;
            this.m_SelectedRoomObjectFace = this.m_HoveredRoomObjectFace;
            this.m_SelectedRoomObjectVerticalEdge = this.m_HoveredRoomObjectVerticalEdge;
            this.m_SelectedMouseStartPosition = this.m_HoveredMouseStartPosition;
            this.m_SelectedRoomObjectDistanceToPlayer = -1;

            if (this.m_HoveredRoomObject != null && this.m_SelectedRoomObject != null)
            {
                this.m_SelectedMouseStartPositionRelative = this.m_HoveredMouseStartPosition
                                                            - new Vector3(
                                                                  this.m_HoveredRoomObject.X,
                                                                  this.m_HoveredRoomObject.Y,
                                                                  this.m_HoveredRoomObject.Z);

                switch (this.m_SelectedRoomObjectFace)
                {
                    case 0:
                        this.m_SelectedRoomObjectStartValue1 = this.m_SelectedRoomObject.X;
                        this.m_SelectedRoomObjectStartValue2 = this.m_SelectedRoomObject.Width;
                        break;
                    case 1:
                        this.m_SelectedRoomObjectStartValue1 = this.m_SelectedRoomObject.Width;
                        break;
                    case 2:
                        this.m_SelectedRoomObjectStartValue1 = this.m_SelectedRoomObject.Z;
                        this.m_SelectedRoomObjectStartValue2 = this.m_SelectedRoomObject.Depth;
                        break;
                    case 3:
                        this.m_SelectedRoomObjectStartValue1 = this.m_SelectedRoomObject.Depth;
                        break;
                    case 4:
                        this.m_SelectedRoomObjectStartValue1 = this.m_SelectedRoomObject.Y;
                        this.m_SelectedRoomObjectStartValue2 = this.m_SelectedRoomObject.Height;
                        break;
                    case 5:
                        this.m_SelectedRoomObjectStartValue1 = this.m_SelectedRoomObject.Height;
                        break;
                }
            }
        }