Пример #1
0
        public override void UpdateEditing(Camera cam)
        {
            if (editingHUD == null || editingHUD.UserData as Hull != this)
            {
                editingHUD = CreateEditingHUD(Screen.Selected != GameMain.SubEditorScreen);
            }

            if (!PlayerInput.KeyDown(Keys.Space))
            {
                return;
            }
            bool lClick = PlayerInput.PrimaryMouseButtonClicked();
            bool rClick = PlayerInput.SecondaryMouseButtonClicked();

            if (!lClick && !rClick)
            {
                return;
            }

            Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);

            if (lClick)
            {
                foreach (MapEntity entity in mapEntityList)
                {
                    if (entity == this || !entity.IsHighlighted)
                    {
                        continue;
                    }
                    if (!entity.IsMouseOn(position))
                    {
                        continue;
                    }
                    if (entity.Linkable && entity.linkedTo != null)
                    {
                        entity.linkedTo.Add(this);
                        linkedTo.Add(entity);
                    }
                }
            }
            else
            {
                foreach (MapEntity entity in mapEntityList)
                {
                    if (entity == this || !entity.IsHighlighted)
                    {
                        continue;
                    }
                    if (!entity.IsMouseOn(position))
                    {
                        continue;
                    }
                    if (entity.linkedTo != null && entity.linkedTo.Contains(this))
                    {
                        entity.linkedTo.Remove(this);
                        linkedTo.Remove(entity);
                    }
                }
            }
        }
        public void DrawPinnedEvent(SpriteBatch spriteBatch)
        {
            if (PinnedEvent != null)
            {
                Rectangle rect = DrawEvent(spriteBatch, PinnedEvent, null);

                if (rect != Rectangle.Empty)
                {
                    if (rect.Contains(PlayerInput.MousePosition) && !isDragging)
                    {
                        GUI.MouseCursor = CursorState.Move;
                        if (PlayerInput.PrimaryMouseButtonDown() || PlayerInput.PrimaryMouseButtonHeld())
                        {
                            isDragging = true;
                        }

                        if (PlayerInput.SecondaryMouseButtonClicked() || PlayerInput.SecondaryMouseButtonHeld())
                        {
                            PinnedEvent = null;
                            isDragging  = false;
                        }
                    }
                }

                if (isDragging)
                {
                    GUI.MouseCursor = CursorState.Dragging;
                    pinnedPosition  = PlayerInput.MousePosition - (new Vector2(rect.Width / 2.0f, -24));
                    if (!PlayerInput.PrimaryMouseButtonHeld())
                    {
                        isDragging = false;
                    }
                }
            }
        }
        public override void UpdateWhilePaused(float deltaTime)
        {
            if (CoroutineManager.IsCoroutineRunning("LevelTransition") || CoroutineManager.IsCoroutineRunning("SubmarineTransition") || gameOver)
            {
                return;
            }

            if (PlayerInput.SecondaryMouseButtonClicked() ||
                PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                ShowCampaignUI = false;
                if (GUIMessageBox.VisibleBox?.UserData is RoundSummary roundSummary &&
                    roundSummary.ContinueButton != null &&
                    roundSummary.ContinueButton.Visible)
                {
                    GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox);
                }
            }

            if (CrewManager.ChatBox != null)
            {
                CrewManager.ChatBox.Update(deltaTime);
            }

            CrewManager.UpdateReports();
        }
Пример #4
0
        protected virtual void Update(float deltaTime)
        {
            if (!Visible)
            {
                return;
            }

            if (CanBeFocused && OnSecondaryClicked != null)
            {
                if (GUI.IsMouseOn(this) && PlayerInput.SecondaryMouseButtonClicked())
                {
                    OnSecondaryClicked?.Invoke(this, userData);
                }
            }

            if (flashTimer > 0.0f)
            {
                flashTimer -= deltaTime;
            }
            if (spriteFadeTimer > 0)
            {
                spriteFadeTimer -= deltaTime;
            }
            if (colorFadeTimer > 0)
            {
                colorFadeTimer -= deltaTime;
            }
        }
Пример #5
0
        protected virtual void Update(float deltaTime)
        {
            if (!Visible)
            {
                return;
            }

            if (CanBeFocused && OnSecondaryClicked != null)
            {
                if (GUI.IsMouseOn(this) && PlayerInput.SecondaryMouseButtonClicked())
                {
                    OnSecondaryClicked?.Invoke(this, userData);
                }
            }

            if (Bounce)
            {
                if (bounceTimer > 3.0f || bounceDown)
                {
                    RectTransform.ScreenSpaceOffset = new Point(RectTransform.ScreenSpaceOffset.X, (int)-(bounceJump * 10f));
                    if (!bounceDown)
                    {
                        bounceJump += deltaTime * 4;
                        if (bounceJump > 0.5f)
                        {
                            bounceDown = true;
                        }
                    }
                    else
                    {
                        bounceJump -= deltaTime * 4;
                        if (bounceJump <= 0.0f)
                        {
                            bounceJump  = 0.0f;
                            bounceTimer = 0.0f;
                            bounceDown  = false;
                        }
                    }
                }
                else
                {
                    bounceTimer += deltaTime;
                }
            }

            if (flashTimer > 0.0f)
            {
                flashTimer -= deltaTime;
            }
            if (spriteFadeTimer > 0)
            {
                spriteFadeTimer -= deltaTime;
            }
            if (colorFadeTimer > 0)
            {
                colorFadeTimer -= deltaTime;
            }
        }
Пример #6
0
        public override void UpdatePlacing(Camera cam)
        {
            if (PlayerInput.SecondaryMouseButtonClicked())
            {
                selected = null;
                return;
            }

            Vector2   position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
            Vector2   size     = ScaledSize;
            Rectangle newRect  = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);

            if (placePosition == Vector2.Zero)
            {
                if (PlayerInput.PrimaryMouseButtonHeld())
                {
                    placePosition = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
                }

                newRect.X = (int)position.X;
                newRect.Y = (int)position.Y;
            }
            else
            {
                Vector2 placeSize = size;
                if (ResizeHorizontal)
                {
                    placeSize.X = position.X - placePosition.X;
                }
                if (ResizeVertical)
                {
                    placeSize.Y = placePosition.Y - position.Y;
                }

                //don't allow resizing width/height to less than the grid size
                if (ResizeHorizontal && Math.Abs(placeSize.X) < Submarine.GridSize.X)
                {
                    placeSize.X = Submarine.GridSize.X;
                }
                if (ResizeVertical && Math.Abs(placeSize.Y) < Submarine.GridSize.Y)
                {
                    placeSize.Y = Submarine.GridSize.Y;
                }

                newRect = Submarine.AbsRect(placePosition, placeSize);
                if (PlayerInput.PrimaryMouseButtonReleased())
                {
                    newRect.Location -= MathUtils.ToPoint(Submarine.MainSub.Position);
                    new Structure(newRect, this, Submarine.MainSub)
                    {
                        Submarine = Submarine.MainSub
                    };

                    selected = null;
                    return;
                }
            }
        }
        public virtual void UpdatePlacing(Camera cam)
        {
            if (PlayerInput.SecondaryMouseButtonClicked())
            {
                selected = null;
                return;
            }

            Vector2 placeSize = Submarine.GridSize;

            if (placePosition == Vector2.Zero)
            {
                Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);

                if (PlayerInput.PrimaryMouseButtonHeld())
                {
                    placePosition = position;
                }
            }
            else
            {
                Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);

                if (ResizeHorizontal)
                {
                    placeSize.X = position.X - placePosition.X;
                }
                if (ResizeVertical)
                {
                    placeSize.Y = placePosition.Y - position.Y;
                }

                Rectangle newRect = Submarine.AbsRect(placePosition, placeSize);
                newRect.Width  = (int)Math.Max(newRect.Width, Submarine.GridSize.X);
                newRect.Height = (int)Math.Max(newRect.Height, Submarine.GridSize.Y);

                if (Submarine.MainSub != null)
                {
                    newRect.Location -= MathUtils.ToPoint(Submarine.MainSub.Position);
                }

                if (PlayerInput.PrimaryMouseButtonReleased())
                {
                    CreateInstance(newRect);
                    placePosition = Vector2.Zero;
                    if (!PlayerInput.IsShiftDown())
                    {
                        selected = null;
                    }
                }

                newRect.Y = -newRect.Y;
            }
        }
Пример #8
0
        protected virtual void Update(float deltaTime)
        {
            if (!Visible)
            {
                return;
            }

            if (CanBeFocused && OnSecondaryClicked != null)
            {
                if (GUI.IsMouseOn(this) && PlayerInput.SecondaryMouseButtonClicked())
                {
                    OnSecondaryClicked?.Invoke(this, userData);
                }
            }
Пример #9
0
        public override void DrawPlacing(SpriteBatch spriteBatch, Camera cam)
        {
            Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);

            if (PlayerInput.SecondaryMouseButtonClicked())
            {
                selected = null;
                return;
            }

            if (!ResizeHorizontal && !ResizeVertical)
            {
                sprite.Draw(spriteBatch, new Vector2(position.X, -position.Y) + sprite.size / 2.0f * Scale, SpriteColor, scale: Scale);
            }
            else
            {
Пример #10
0
        public override void Update(double deltaTime)
        {
            cam.MoveCamera((float)deltaTime, allowMove: true, allowZoom: GUI.MouseOn == null);

            if (GUI.MouseOn is null && PlayerInput.PrimaryMouseButtonHeld())
            {
                sizeRefPosition = cam.ScreenToWorld(PlayerInput.MousePosition);
            }

            if (PlayerInput.SecondaryMouseButtonClicked())
            {
                CreateContextMenu();
            }

            if (selectedPrefab != null && emitter != null)
            {
                emitter.Emit((float)deltaTime, Vector2.Zero);
            }

            GameMain.ParticleManager.Update((float)deltaTime);
        }
Пример #11
0
        public bool IsHit()
        {
            switch (MouseButton)
            {
            case MouseButton.None:
                return(PlayerInput.KeyHit(Key));

            case MouseButton.PrimaryMouse:
                return(PlayerInput.PrimaryMouseButtonClicked());

            case MouseButton.SecondaryMouse:
                return(PlayerInput.SecondaryMouseButtonClicked());

            case MouseButton.LeftMouse:
                return(PlayerInput.LeftButtonClicked());

            case MouseButton.RightMouse:
                return(PlayerInput.RightButtonClicked());

            case MouseButton.MiddleMouse:
                return(PlayerInput.MidButtonClicked());

            case MouseButton.MouseButton4:
                return(PlayerInput.Mouse4ButtonClicked());

            case MouseButton.MouseButton5:
                return(PlayerInput.Mouse5ButtonClicked());

            case MouseButton.MouseWheelUp:
                return(PlayerInput.MouseWheelUpClicked());

            case MouseButton.MouseWheelDown:
                return(PlayerInput.MouseWheelDownClicked());
            }

            return(false);
        }
Пример #12
0
        public static bool CloseHUD(Rectangle rect)
        {
            // Always close when hitting escape
            if (PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                return(true);
            }

            //don't close when the cursor is on a UI element
            if (GUI.MouseOn != null)
            {
                return(false);
            }

            //don't close when hovering over an inventory element
            if (Inventory.IsMouseOnInventory())
            {
                return(false);
            }

            bool input = PlayerInput.PrimaryMouseButtonDown() || PlayerInput.SecondaryMouseButtonClicked();

            return(input && !rect.Contains(PlayerInput.MousePosition));
        }
        public override void Update(float deltaTime)
        {
            if (CoroutineManager.IsCoroutineRunning("LevelTransition") || CoroutineManager.IsCoroutineRunning("SubmarineTransition") || gameOver)
            {
                return;
            }

            base.Update(deltaTime);

            if (PlayerInput.SecondaryMouseButtonClicked() ||
                PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                ShowCampaignUI = false;
                if (GUIMessageBox.VisibleBox?.UserData is RoundSummary roundSummary &&
                    roundSummary.ContinueButton != null &&
                    roundSummary.ContinueButton.Visible)
                {
                    GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox);
                }
            }

#if DEBUG
            if (PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.R))
            {
                if (GUIMessageBox.MessageBoxes.Any())
                {
                    GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.MessageBoxes.Last());
                }

                GUIFrame summaryFrame = GameMain.GameSession.RoundSummary.CreateSummaryFrame(GameMain.GameSession, "", null);
                GUIMessageBox.MessageBoxes.Add(summaryFrame);
                GameMain.GameSession.RoundSummary.ContinueButton.OnClicked = (_, __) => { GUIMessageBox.MessageBoxes.Remove(summaryFrame); return(true); };
            }
#endif

            if (ShowCampaignUI || ForceMapUI)
            {
                Character.DisableControls = true;
            }

            if (!GUI.DisableHUD && !GUI.DisableUpperHUD)
            {
                endRoundButton.UpdateManually(deltaTime);
                if (CoroutineManager.IsCoroutineRunning("LevelTransition") || ForceMapUI)
                {
                    return;
                }
            }

            if (Level.Loaded.Type == LevelData.LevelType.Outpost)
            {
                KeepCharactersCloseToOutpost(deltaTime);
                if (wasDocked)
                {
                    var  connectedSubs = Submarine.MainSub.GetConnectedSubs();
                    bool isDocked      = Level.Loaded.StartOutpost != null && connectedSubs.Contains(Level.Loaded.StartOutpost);
                    if (!isDocked)
                    {
                        //undocked from outpost, need to choose a destination
                        ForceMapUI = true;
                        CampaignUI.SelectTab(InteractionType.Map);
                    }
                }
                else
                {
                    //wasn't initially docked (sub doesn't have a docking port?)
                    // -> choose a destination when the sub is far enough from the start outpost
                    if (!Submarine.MainSub.AtStartPosition)
                    {
                        ForceMapUI = true;
                        CampaignUI.SelectTab(InteractionType.Map);
                    }
                }
            }
            else
            {
                var transitionType = GetAvailableTransition(out _, out Submarine leavingSub);
                if (transitionType == TransitionType.End)
                {
                    EndCampaign();
                }
                if (transitionType == TransitionType.ProgressToNextLocation &&
                    Level.Loaded.EndOutpost != null && Level.Loaded.EndOutpost.DockedTo.Contains(leavingSub))
                {
                    LoadNewLevel();
                }
                else if (transitionType == TransitionType.ReturnToPreviousLocation &&
                         Level.Loaded.StartOutpost != null && Level.Loaded.StartOutpost.DockedTo.Contains(leavingSub))
                {
                    LoadNewLevel();
                }
                else if (transitionType == TransitionType.None && CampaignUI.SelectedTab == InteractionType.Map)
                {
                    ShowCampaignUI = false;
                }
            }

            if (!crewDead)
            {
                if (!CrewManager.GetCharacters().Any(c => !c.IsDead))
                {
                    crewDead = true;
                }
            }
            else
            {
                endTimer -= deltaTime;
                if (endTimer <= 0.0f)
                {
                    GameOver();
                }
            }
        }