Пример #1
0
        public override void Update(float deltaTime)
        {
            if (!Visible)
            {
                return;
            }

            wasOpened = false;

            base.Update(deltaTime);

            if (Dropped && PlayerInput.LeftButtonClicked())
            {
                Rectangle listBoxRect = listBox.Rect;
                listBoxRect.Width += 20;
                if (!listBoxRect.Contains(PlayerInput.MousePosition) && !button.Rect.Contains(PlayerInput.MousePosition))
                {
                    Dropped = false;
                }
            }

            button.Update(deltaTime);

            if (Dropped)
            {
                listBox.Update(deltaTime);
            }
        }
Пример #2
0
        public override void Update(float deltaTime)
        {
            if (!Visible)
            {
                return;
            }

            if (MouseOn == this && Enabled)
            {
                box.State = ComponentState.Hover;

                if (PlayerInput.LeftButtonHeld())
                {
                    box.State = ComponentState.Selected;
                }

                if (PlayerInput.LeftButtonClicked())
                {
                    Selected = !Selected;
                    if (OnSelected != null)
                    {
                        OnSelected(this);
                    }
                }
            }
            else
            {
                box.State = ComponentState.None;
            }

            if (selected)
            {
                box.State = ComponentState.Selected;
            }
        }
Пример #3
0
        public override void UpdateEditing(Camera cam)
        {
            if (editingHUD == null || editingHUD.UserData != this)
            {
                editingHUD = CreateEditingHUD();
            }

            editingHUD.Update((float)Timing.Step);

            if (PlayerInput.LeftButtonClicked())
            {
                Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);

                foreach (MapEntity e in mapEntityList)
                {
                    if (e.GetType() != typeof(WayPoint))
                    {
                        continue;
                    }
                    if (e == this)
                    {
                        continue;
                    }

                    if (!Submarine.RectContains(e.Rect, position))
                    {
                        continue;
                    }

                    linkedTo.Add(e);
                    e.linkedTo.Add(this);
                }
            }
        }
Пример #4
0
        public override void Update(float deltaTime)
        {
            if (!Visible)
            {
                return;
            }

            base.Update(deltaTime);

            if (MouseOn == frame)
            {
                if (PlayerInput.LeftButtonClicked())
                {
                    MoveButton(new Vector2(
                                   Math.Sign(PlayerInput.MousePosition.X - bar.Rect.Center.X) * bar.Rect.Width,
                                   Math.Sign(PlayerInput.MousePosition.Y - bar.Rect.Center.Y) * bar.Rect.Height));
                }
            }

            if (draggingBar == this)
            {
                if (!PlayerInput.LeftButtonHeld())
                {
                    draggingBar = null;
                }
                MoveButton(PlayerInput.MouseSpeed);
            }
        }
Пример #5
0
        public static bool DrawButton(SpriteBatch sb, Rectangle rect, string text, Color color, bool isHoldable = false)
        {
            bool clicked = false;

            if (rect.Contains(PlayerInput.MousePosition))
            {
                clicked = PlayerInput.LeftButtonHeld();

                color = clicked ?
                        new Color((int)(color.R * 0.8f), (int)(color.G * 0.8f), (int)(color.B * 0.8f), color.A) :
                        new Color((int)(color.R * 1.2f), (int)(color.G * 1.2f), (int)(color.B * 1.2f), color.A);

                if (!isHoldable)
                {
                    clicked = PlayerInput.LeftButtonClicked();
                }
            }

            DrawRectangle(sb, rect, color, true);

            Vector2 origin;

            try
            {
                origin = Font.MeasureString(text) / 2;
            }
            catch
            {
                origin = Vector2.Zero;
            }

            Font.DrawString(sb, text, new Vector2(rect.Center.X, rect.Center.Y), Color.White, 0.0f, origin, 1.0f, SpriteEffects.None, 0.0f);

            return(clicked);
        }
Пример #6
0
        public bool IsHit()
        {
            switch (MouseButton)
            {
            case null:
                return(PlayerInput.KeyHit(Key));

            case 0:
                return(PlayerInput.LeftButtonClicked());

            case 1:
                return(PlayerInput.RightButtonClicked());

            case 2:
                return(PlayerInput.MidButtonClicked());

            case 3:
                return(PlayerInput.Mouse4ButtonClicked());

            case 4:
                return(PlayerInput.Mouse5ButtonClicked());

            case 5:
                return(PlayerInput.MouseWheelUpClicked());

            case 6:
                return(PlayerInput.MouseWheelDownClicked());
            }

            return(false);
        }
Пример #7
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.LeftButtonClicked();
            bool rClick = PlayerInput.RightButtonClicked();

            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);
                    }
                }
            }
        }
Пример #8
0
 public override void Update(float deltaTime)
 {
     if (!Visible)
     {
         return;
     }
     base.Update(deltaTime);
     if (rect.Contains(PlayerInput.MousePosition) && CanBeSelected && Enabled && (MouseOn == null || MouseOn == this || IsParentOf(MouseOn)))
     {
         state = ComponentState.Hover;
         if (PlayerInput.LeftButtonHeld())
         {
             if (OnPressed != null)
             {
                 if (OnPressed())
                 {
                     state = ComponentState.Pressed;
                 }
             }
         }
         else if (PlayerInput.DoubleClicked() && CanDoubleClick)
         {
             GUI.PlayUISound(GUISoundType.Click);
             if (OnDoubleClicked != null)
             {
                 if (OnDoubleClicked(this, UserData) && CanBeSelected)
                 {
                     state = ComponentState.Selected;
                 }
             }
             else
             {
                 Selected = !Selected;
                 // state = state == ComponentState.Selected ? ComponentState.None : ComponentState.Selected;
             }
         }
         else if (PlayerInput.LeftButtonClicked())
         {
             GUI.PlayUISound(GUISoundType.Click);
             if (OnClicked != null)
             {
                 if (OnClicked(this, UserData) && CanBeSelected)
                 {
                     state = ComponentState.Selected;
                 }
             }
             else
             {
                 Selected = !Selected;
                 // state = state == ComponentState.Selected ? ComponentState.None : ComponentState.Selected;
             }
         }
     }
     else
     {
         state = Selected ? ComponentState.Selected : ComponentState.None;
     }
     //frame.State = state;
 }
Пример #9
0
        partial void UpdateProjSpecific(float deltaTime, Camera cam)
        {
            if (EditWater)
            {
                Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
                if (Submarine.RectContains(WorldRect, position))
                {
                    if (PlayerInput.LeftButtonHeld())
                    {
                        WaterVolume += 1500.0f;
                    }
                    else if (PlayerInput.RightButtonHeld())
                    {
                        WaterVolume -= 1500.0f;
                    }
                }
            }
            else if (EditFire)
            {
                Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
                if (Submarine.RectContains(WorldRect, position))
                {
                    if (PlayerInput.LeftButtonClicked())
                    {
                        new FireSource(position, this);
                    }
                }
            }

            foreach (Decal decal in decals)
            {
                decal.Update(deltaTime);
            }

            decals.RemoveAll(d => d.FadeTimer >= d.LifeTime);

            if (waterVolume < 1.0f)
            {
                return;
            }
            for (int i = 1; i < waveY.Length - 1; i++)
            {
                float maxDelta = Math.Max(Math.Abs(rightDelta[i]), Math.Abs(leftDelta[i]));
                if (maxDelta > Rand.Range(1.0f, 10.0f))
                {
                    var particlePos = new Vector2(rect.X + WaveWidth * i, surface + waveY[i]);
                    if (Submarine != null)
                    {
                        particlePos += Submarine.Position;
                    }

                    GameMain.ParticleManager.CreateParticle("mist",
                                                            particlePos,
                                                            new Vector2(0.0f, -50.0f), 0.0f, this);
                }
            }
        }
Пример #10
0
        public override void UpdateEditing(Camera cam)
        {
            if (editingHUD == null || editingHUD.UserData as Item != this)
            {
                editingHUD = CreateEditingHUD(Screen.Selected != GameMain.SubEditorScreen);
            }

            if (Screen.Selected != GameMain.SubEditorScreen)
            {
                return;
            }

            if (Character.Controlled == null)
            {
                activeHUDs.Clear();
            }

            if (!Linkable)
            {
                return;
            }

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

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

            Vector2 position    = cam.ScreenToWorld(PlayerInput.MousePosition);
            var     otherEntity = mapEntityList.FirstOrDefault(e => e != this && e.IsHighlighted && e.IsMouseOn(position));

            if (otherEntity != null)
            {
                if (linkedTo.Contains(otherEntity))
                {
                    linkedTo.Remove(otherEntity);
                    if (otherEntity.linkedTo != null && otherEntity.linkedTo.Contains(this))
                    {
                        otherEntity.linkedTo.Remove(this);
                    }
                }
                else
                {
                    linkedTo.Add(otherEntity);
                    if (otherEntity.Linkable && otherEntity.linkedTo != null)
                    {
                        otherEntity.linkedTo.Add(this);
                    }
                }
            }
        }
Пример #11
0
        protected override void Update(float deltaTime)
        {
            if (!Visible)
            {
                return;
            }
            base.Update(deltaTime);
            if (Rect.Contains(PlayerInput.MousePosition) && CanBeSelected && Enabled && GUI.IsMouseOn(this))
            {
                state = ComponentState.Hover;
                if (PlayerInput.LeftButtonDown())
                {
                    OnButtonDown?.Invoke();
                }
                if (PlayerInput.LeftButtonHeld())
                {
                    if (OnPressed != null)
                    {
                        if (OnPressed())
                        {
                            state = ComponentState.Pressed;
                        }
                    }
                    else
                    {
                        state = ComponentState.Pressed;
                    }
                }
                else if (PlayerInput.LeftButtonClicked())
                {
                    GUI.PlayUISound(GUISoundType.Click);
                    if (OnClicked != null)
                    {
                        if (OnClicked(this, UserData) && CanBeSelected)
                        {
                            state = ComponentState.Selected;
                        }
                    }
                    else
                    {
                        Selected = !Selected;
                        // state = state == ComponentState.Selected ? ComponentState.None : ComponentState.Selected;
                    }
                }
            }
            else
            {
                state = Selected ? ComponentState.Selected : ComponentState.None;
            }

            foreach (GUIComponent child in Children)
            {
                child.State = state;
            }
            //frame.State = state;
        }
Пример #12
0
        public void Update(float deltaTime, Rectangle rect, float scale = 1.0f)
        {
            Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y);
            Vector2 offset     = -currentLocation.MapPosition;

            float maxDist     = 20.0f;
            float closestDist = 0.0f;

            highlightedLocation = null;
            for (int i = 0; i < locations.Count; i++)
            {
                Location location = locations[i];
                Vector2  pos      = rectCenter + (location.MapPosition + offset) * scale;

                if (!rect.Contains(pos))
                {
                    continue;
                }

                float dist = Vector2.Distance(PlayerInput.MousePosition, pos);
                if (dist < maxDist && (highlightedLocation == null || dist < closestDist))
                {
                    closestDist         = dist;
                    highlightedLocation = location;
                }
            }

            foreach (LocationConnection connection in connections)
            {
                if (highlightedLocation != currentLocation &&
                    connection.Locations.Contains(highlightedLocation) && connection.Locations.Contains(currentLocation))
                {
                    if (PlayerInput.LeftButtonClicked() &&
                        selectedLocation != highlightedLocation && highlightedLocation != null)
                    {
                        selectedConnection = connection;
                        selectedLocation   = highlightedLocation;

                        //clients aren't allowed to select the location without a permission
                        if (GameMain.Client == null || GameMain.Client.HasPermission(Networking.ClientPermissions.ManageCampaign))
                        {
                            OnLocationSelected?.Invoke(selectedLocation, selectedConnection);
                            GameMain.Client?.SendCampaignState();
                        }
                    }
                }

#if DEBUG
                if (PlayerInput.DoubleClicked() && highlightedLocation != null)
                {
                    currentLocation = highlightedLocation;
                    OnLocationChanged?.Invoke(currentLocation);
                }
#endif
            }
        }
Пример #13
0
        private IEnumerable <object> WaitForKeyPress(GUITextBox keyBox)
        {
            yield return(CoroutineStatus.Running);

            while (PlayerInput.LeftButtonHeld() || PlayerInput.LeftButtonClicked())
            {
                //wait for the mouse to be released, so that we don't interpret clicking on the textbox as the keybinding
                yield return(CoroutineStatus.Running);
            }
            while (keyBox.Selected && PlayerInput.GetKeyboardState.GetPressedKeys().Length == 0 &&
                   !PlayerInput.LeftButtonClicked() && !PlayerInput.RightButtonClicked() && !PlayerInput.MidButtonClicked())
            {
                if (Screen.Selected != GameMain.MainMenuScreen && !GUI.SettingsMenuOpen)
                {
                    yield return(CoroutineStatus.Success);
                }

                yield return(CoroutineStatus.Running);
            }

            UnsavedSettings = true;

            int keyIndex = (int)keyBox.UserData;

            if (PlayerInput.LeftButtonClicked())
            {
                keyMapping[keyIndex] = new KeyOrMouse(0);
                keyBox.Text          = "Mouse1";
            }
            else if (PlayerInput.RightButtonClicked())
            {
                keyMapping[keyIndex] = new KeyOrMouse(1);
                keyBox.Text          = "Mouse2";
            }
            else if (PlayerInput.MidButtonClicked())
            {
                keyMapping[keyIndex] = new KeyOrMouse(2);
                keyBox.Text          = "Mouse3";
            }
            else if (PlayerInput.GetKeyboardState.GetPressedKeys().Length > 0)
            {
                Keys key = PlayerInput.GetKeyboardState.GetPressedKeys()[0];
                keyMapping[keyIndex] = new KeyOrMouse(key);
                keyBox.Text          = key.ToString("G");
            }
            else
            {
                yield return(CoroutineStatus.Success);
            }

            keyBox.Deselect();

            yield return(CoroutineStatus.Success);
        }
Пример #14
0
        protected override void Update(float deltaTime)
        {
            if (!Visible)
            {
                return;
            }

            base.Update(deltaTime);

            if (!enabled)
            {
                return;
            }

            if (IsBooleanSwitch &&
                (!PlayerInput.LeftButtonHeld() || (GUI.MouseOn != this && !IsParentOf(GUI.MouseOn))))
            {
                int dir = Math.Sign(barScroll - (minValue + maxValue) / 2.0f);
                if (dir == 0)
                {
                    dir = 1;
                }
                if ((barScroll <= maxValue && dir > 0) ||
                    (barScroll > minValue && dir < 0))
                {
                    BarScroll += dir * 0.1f;
                }
            }

            if (draggingBar == this)
            {
                if (!PlayerInput.LeftButtonHeld())
                {
                    OnReleased?.Invoke(this, BarScroll);
                    draggingBar = null;
                }
                if ((isHorizontal && PlayerInput.MousePosition.X > Rect.X && PlayerInput.MousePosition.X < Rect.Right) ||
                    (!isHorizontal && PlayerInput.MousePosition.Y > Rect.Y && PlayerInput.MousePosition.Y < Rect.Bottom))
                {
                    MoveButton(PlayerInput.MouseSpeed);
                }
            }
            else if (GUI.MouseOn == Frame)
            {
                if (PlayerInput.LeftButtonClicked())
                {
                    draggingBar?.OnReleased?.Invoke(draggingBar, draggingBar.BarScroll);
                    MoveButton(new Vector2(
                                   Math.Sign(PlayerInput.MousePosition.X - Bar.Rect.Center.X) * Bar.Rect.Width,
                                   Math.Sign(PlayerInput.MousePosition.Y - Bar.Rect.Center.Y) * Bar.Rect.Height));
                }
            }
        }
Пример #15
0
        private void HandleButtonEquipStates(Item item, InventorySlot slot, float deltaTime)
        {
            slot.EquipButtonState = slot.EquipButtonRect.Contains(PlayerInput.MousePosition) ?
                                    GUIComponent.ComponentState.Hover : GUIComponent.ComponentState.None;
            if (PlayerInput.LeftButtonHeld() && PlayerInput.RightButtonHeld())
            {
                slot.EquipButtonState = GUIComponent.ComponentState.None;
            }

            if (slot.EquipButtonState != GUIComponent.ComponentState.Hover)
            {
                slot.QuickUseTimer = Math.Max(0.0f, slot.QuickUseTimer - deltaTime * 5.0f);
                return;
            }

            var quickUseAction = GetQuickUseAction(item, allowEquip: true, allowInventorySwap: false, allowApplyTreatment: false);

            slot.QuickUseButtonToolTip = quickUseAction == QuickUseAction.None ?
                                         "" : TextManager.Get("QuickUseAction." + quickUseAction.ToString());

            //equipped item that can't be put in the inventory, use delayed dropping
            if (quickUseAction == QuickUseAction.Drop)
            {
                slot.QuickUseButtonToolTip =
                    TextManager.Get("QuickUseAction.HoldToUnequip", returnNull: true) ??
                    (GameMain.Config.Language == "English" ? "Hold to unequip" : TextManager.Get("QuickUseAction.Unequip"));

                if (PlayerInput.LeftButtonHeld())
                {
                    slot.QuickUseTimer = Math.Max(0.1f, slot.QuickUseTimer + deltaTime);
                    if (slot.QuickUseTimer >= 1.0f)
                    {
                        item.Drop(Character.Controlled);
                        GUI.PlayUISound(GUISoundType.DropItem);
                    }
                }
                else
                {
                    slot.QuickUseTimer = Math.Max(0.0f, slot.QuickUseTimer - deltaTime * 5.0f);
                }
            }
            else
            {
                if (PlayerInput.LeftButtonDown())
                {
                    slot.EquipButtonState = GUIComponent.ComponentState.Pressed;
                }
                if (PlayerInput.LeftButtonClicked())
                {
                    QuickUseItem(item, allowEquip: true, allowInventorySwap: false, allowApplyTreatment: false);
                }
            }
        }
Пример #16
0
        private void DrawLanguageSelectionPrompt(SpriteBatch spriteBatch, GraphicsDevice graphicsDevice)
        {
            if (languageSelectionFont == null)
            {
                languageSelectionFont = new ScalableFont("Content/Fonts/NotoSans/NotoSans-Bold.ttf",
                                                         (uint)(30 * (GameMain.GraphicsHeight / 1080.0f)), graphicsDevice);
            }
            if (languageSelectionFontCJK == null)
            {
                languageSelectionFontCJK = new ScalableFont("Content/Fonts/NotoSans/NotoSansCJKsc-Bold.otf",
                                                            (uint)(30 * (GameMain.GraphicsHeight / 1080.0f)), graphicsDevice, dynamicLoading: true);
            }
            if (languageSelectionCursor == null)
            {
                languageSelectionCursor = new Sprite("Content/UI/cursor.png", Vector2.Zero);
            }

            Vector2 textPos     = new Vector2(GameMain.GraphicsWidth / 2, GameMain.GraphicsHeight * 0.3f);
            Vector2 textSpacing = new Vector2(0.0f, (GameMain.GraphicsHeight * 0.5f) / TextManager.AvailableLanguages.Count());

            foreach (string language in TextManager.AvailableLanguages)
            {
                string localizedLanguageName = TextManager.GetTranslatedLanguageName(language);
                var    font = TextManager.IsCJK(localizedLanguageName) ? languageSelectionFontCJK : languageSelectionFont;

                Vector2 textSize = font.MeasureString(localizedLanguageName);
                bool    hover    =
                    Math.Abs(PlayerInput.MousePosition.X - textPos.X) < textSize.X / 2 &&
                    Math.Abs(PlayerInput.MousePosition.Y - textPos.Y) < textSpacing.Y / 2;

                font.DrawString(spriteBatch, localizedLanguageName, textPos - textSize / 2,
                                hover ? Color.White : Color.White * 0.6f);
                if (hover && PlayerInput.LeftButtonClicked())
                {
                    GameMain.Config.Language = language;
                    //reload tip in the selected language
                    selectedTip = TextManager.Get("LoadingScreenTip", true);
                    GameMain.Config.SetDefaultBindings(legacy: false);
                    GameMain.Config.CheckBindings(useDefaults: true);
                    WaitForLanguageSelection = false;
                    languageSelectionFont?.Dispose(); languageSelectionFont       = null;
                    languageSelectionFontCJK?.Dispose(); languageSelectionFontCJK = null;
                    break;
                }

                textPos += textSpacing;
            }

            languageSelectionCursor.Draw(spriteBatch, PlayerInput.LatestMousePosition, scale: 0.5f);
        }
Пример #17
0
        public override void UpdateEditing(Camera cam)
        {
            if (editingHUD == null || editingHUD.UserData as Item != this)
            {
                editingHUD = CreateEditingHUD(Screen.Selected != GameMain.EditMapScreen);
            }

            editingHUD.Update((float)Timing.Step);

            if (Screen.Selected != GameMain.EditMapScreen)
            {
                return;
            }

            if (!prefab.IsLinkable)
            {
                return;
            }

            if (!PlayerInput.LeftButtonClicked() || !PlayerInput.KeyDown(Keys.Space))
            {
                return;
            }

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

            foreach (MapEntity entity in mapEntityList)
            {
                if (entity == this || !entity.IsHighlighted)
                {
                    continue;
                }
                if (linkedTo.Contains(entity))
                {
                    continue;
                }
                if (!entity.IsMouseOn(position))
                {
                    continue;
                }

                linkedTo.Add(entity);
                if (entity.IsLinkable && entity.linkedTo != null)
                {
                    entity.linkedTo.Add(this);
                }
            }
        }
Пример #18
0
        public bool IsHit()
        {
            if (mouseButton == null)
            {
                return(PlayerInput.KeyHit(keyBinding));
            }
            else if (mouseButton == 0)
            {
                return(PlayerInput.LeftButtonClicked());
            }
            else if (mouseButton == 1)
            {
                return(PlayerInput.RightButtonClicked());
            }

            return(false);
        }
Пример #19
0
 public override void Update(double deltaTime)
 {
     base.Update(deltaTime);
     Widget.EnableMultiSelect  = PlayerInput.KeyDown(Keys.LeftControl);
     spriteList.SelectMultiple = Widget.EnableMultiSelect;
     // Select rects with the mouse
     if (Widget.selectedWidgets.None() || Widget.EnableMultiSelect)
     {
         if (selectedTexture != null)
         {
             foreach (Sprite sprite in loadedSprites)
             {
                 if (sprite.Texture != selectedTexture)
                 {
                     continue;
                 }
                 if (PlayerInput.LeftButtonClicked())
                 {
                     var scaledRect = new Rectangle(textureRect.Location + sprite.SourceRect.Location.Multiply(zoom), sprite.SourceRect.Size.Multiply(zoom));
                     if (scaledRect.Contains(PlayerInput.MousePosition))
                     {
                         spriteList.Select(sprite, autoScroll: false);
                         UpdateScrollBar(spriteList);
                         UpdateScrollBar(textureList);
                     }
                 }
             }
         }
     }
     if (GUI.MouseOn == null)
     {
         if (PlayerInput.ScrollWheelSpeed != 0)
         {
             zoom = MathHelper.Clamp(zoom + PlayerInput.ScrollWheelSpeed * (float)deltaTime * 0.05f * zoom, minZoom, maxZoom);
             zoomBar.BarScroll = GetBarScrollValue();
         }
         widgets.Values.ForEach(w => w.Update((float)deltaTime));
         if (PlayerInput.MidButtonHeld())
         {
             // "Camera" Pan
             Vector2 moveSpeed = PlayerInput.MouseSpeed * (float)deltaTime * 100.0f;
             viewAreaOffset += moveSpeed.ToPoint();
         }
     }
 }
Пример #20
0
        public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
        {
            DrawBackground(graphics, spriteBatch);

            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, GameMain.ScissorTestEnable);

            GUI.Draw(Cam, spriteBatch);

#if DEBUG
            GUI.Font.DrawString(spriteBatch, "Barotrauma v" + GameMain.Version + " (debug build)", new Vector2(10, GameMain.GraphicsHeight - 20), Color.White);
#else
            GUI.Font.DrawString(spriteBatch, "Barotrauma v" + GameMain.Version, new Vector2(10, GameMain.GraphicsHeight - 20), Color.White * 0.7f);
#endif

            if (selectedTab != Tab.Credits)
            {
                Vector2 textPos = new Vector2(GameMain.GraphicsWidth - 10, GameMain.GraphicsHeight - 10);
                for (int i = legalCrap.Length - 1; i >= 0; i--)
                {
                    Vector2 textSize = GUI.SmallFont.MeasureString(legalCrap[i]);
                    textSize = new Vector2((int)textSize.X, (int)textSize.Y);
                    bool mouseOn = i == 0 &&
                                   PlayerInput.MousePosition.X > textPos.X - textSize.X && PlayerInput.MousePosition.X <textPos.X &&
                                                                                                                        PlayerInput.MousePosition.Y> textPos.Y - textSize.Y && PlayerInput.MousePosition.Y < textPos.Y;

                    GUI.SmallFont.DrawString(spriteBatch,
                                             legalCrap[i], textPos - textSize,
                                             mouseOn ? Color.White : Color.White * 0.7f);

                    if (i == 0)
                    {
                        GUI.DrawLine(spriteBatch, textPos, textPos - Vector2.UnitX * textSize.X, mouseOn ? Color.White : Color.White * 0.7f);
                        if (mouseOn && PlayerInput.LeftButtonClicked())
                        {
                            Process.Start("http://privacypolicy.daedalic.com");
                        }
                    }
                    textPos.Y -= textSize.Y;
                }
            }

            spriteBatch.End();
        }
Пример #21
0
        public void Update(float deltaTime, Rectangle rect, float scale = 1.0f)
        {
            Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y);
            Vector2 offset     = -currentLocation.MapPosition;

            float maxDist     = 20.0f;
            float closestDist = 0.0f;

            highlightedLocation = null;
            for (int i = 0; i < locations.Count; i++)
            {
                Location location = locations[i];
                Vector2  pos      = rectCenter + (location.MapPosition + offset) * scale;

                if (!rect.Contains(pos))
                {
                    continue;
                }

                float dist = Vector2.Distance(PlayerInput.MousePosition, pos);
                if (dist < maxDist && (highlightedLocation == null || dist < closestDist))
                {
                    closestDist         = dist;
                    highlightedLocation = location;
                }
            }

            foreach (LocationConnection connection in connections)
            {
                if (highlightedLocation != currentLocation &&
                    connection.Locations.Contains(highlightedLocation) && connection.Locations.Contains(currentLocation))
                {
                    if (PlayerInput.LeftButtonClicked() &&
                        selectedLocation != highlightedLocation && highlightedLocation != null)
                    {
                        selectedConnection = connection;
                        selectedLocation   = highlightedLocation;
                        GameMain.LobbyScreen.SelectLocation(highlightedLocation, connection);
                    }
                }
            }
        }
Пример #22
0
 public virtual void Update(float deltaTime)
 {
     PreUpdate?.Invoke(deltaTime);
     if (!enabled)
     {
         return;
     }
     if (IsMouseOver || (!RequireMouseOn && selectedWidgets.Contains(this) && PlayerInput.LeftButtonHeld()))
     {
         Hovered?.Invoke();
         if (RequireMouseOn || PlayerInput.LeftButtonDown())
         {
             if ((multiselect && !selectedWidgets.Contains(this)) || selectedWidgets.None())
             {
                 selectedWidgets.Add(this);
                 Selected?.Invoke();
             }
         }
     }
     else if (selectedWidgets.Contains(this))
     {
         selectedWidgets.Remove(this);
         Deselected?.Invoke();
     }
     if (IsSelected)
     {
         if (PlayerInput.LeftButtonDown())
         {
             MouseDown?.Invoke();
         }
         if (PlayerInput.LeftButtonHeld())
         {
             MouseHeld?.Invoke(deltaTime);
         }
         if (PlayerInput.LeftButtonClicked())
         {
             MouseUp?.Invoke();
         }
     }
     PostUpdate?.Invoke(deltaTime);
 }
Пример #23
0
 protected override void Update(float deltaTime)
 {
     if (!Visible)
     {
         return;
     }
     wasOpened = false;
     base.Update(deltaTime);
     if (Dropped && PlayerInput.LeftButtonClicked())
     {
         Rectangle listBoxRect = listBox.Rect;
         if (!listBoxRect.Contains(PlayerInput.MousePosition) && !button.Rect.Contains(PlayerInput.MousePosition))
         {
             Dropped = false;
             if (GUI.KeyboardDispatcher.Subscriber == this)
             {
                 GUI.KeyboardDispatcher.Subscriber = null;
             }
         }
     }
 }
Пример #24
0
        protected override void Update(float deltaTime)
        {
            if (!Visible)
            {
                return;
            }

            if (GUI.MouseOn == this && Enabled)
            {
                box.State = ComponentState.Hover;

                if (PlayerInput.LeftButtonHeld())
                {
                    box.State = ComponentState.Selected;
                }

                if (PlayerInput.LeftButtonClicked())
                {
                    if (radioButtonGroup == null)
                    {
                        Selected = !Selected;
                    }
                    else if (!selected)
                    {
                        Selected = true;
                    }
                }
            }
            else
            {
                box.State = ComponentState.None;
            }

            if (selected)
            {
                box.State = ComponentState.Selected;
            }
        }
Пример #25
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);
        }
Пример #26
0
        private void UpdateChildrenRect()
        {
            for (int i = 0; i < Content.CountChildren; i++)
            {
                var child = Content.RectTransform.GetChild(i)?.GUIComponent;
                if (child == null)
                {
                    continue;
                }

                // selecting
                if (Enabled && child.CanBeFocused && (GUI.IsMouseOn(child)) && child.Rect.Contains(PlayerInput.MousePosition))
                {
                    child.State = ComponentState.Hover;
                    if (PlayerInput.LeftButtonClicked())
                    {
                        Select(i, autoScroll: false);
                    }
                }
                else if (selected.Contains(child))
                {
                    child.State = ComponentState.Selected;

                    if (CheckSelected != null)
                    {
                        if (CheckSelected() != child.UserData)
                        {
                            selected.Remove(child);
                        }
                    }
                }
                else
                {
                    child.State = ComponentState.None;
                }
            }
        }
Пример #27
0
        public override void UpdateEditing(Camera cam)
        {
            if (editingHUD == null || editingHUD.UserData as LinkedSubmarine != this)
            {
                editingHUD = CreateEditingHUD();
            }

            editingHUD.UpdateManually((float)Timing.Step);

            if (!PlayerInput.LeftButtonClicked() || !PlayerInput.KeyDown(Keys.Space))
            {
                return;
            }

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

            foreach (MapEntity entity in mapEntityList)
            {
                if (entity == this || !entity.IsHighlighted || !(entity is Item) || !entity.IsMouseOn(position))
                {
                    continue;
                }
                if (((Item)entity).GetComponent <DockingPort>() == null)
                {
                    continue;
                }
                if (linkedTo.Contains(entity))
                {
                    linkedTo.Remove(entity);
                }
                else
                {
                    linkedTo.Add(entity);
                }
            }
        }
Пример #28
0
        protected override void Update(float deltaTime)
        {
            if (!Visible)
            {
                return;
            }

            if (flashTimer > 0.0f)
            {
                flashTimer -= deltaTime;
            }
            if (!Enabled)
            {
                return;
            }

            if (skipUpdate)
            {
                skipUpdate = false;
                return;
            }

            if (MouseRect.Contains(PlayerInput.MousePosition) && (GUI.MouseOn == null || (!(GUI.MouseOn is GUIButton) && GUI.IsMouseOn(this))))
            {
                State = ComponentState.Hover;
                if (PlayerInput.PrimaryMouseButtonDown())
                {
                    mouseHeldInside = true;
                    Select();
                }
                else
                {
                    isSelecting = PlayerInput.PrimaryMouseButtonHeld();
                }
                if (PlayerInput.DoubleClicked())
                {
                    SelectAll();
                }
                if (isSelecting)
                {
                    if (!MathUtils.NearlyEqual(PlayerInput.MouseSpeed.X, 0))
                    {
                        CaretIndex = textBlock.GetCaretIndexFromScreenPos(PlayerInput.MousePosition);
                        CalculateCaretPos();
                        CalculateSelection();
                    }
                }
            }
            else
            {
                if ((PlayerInput.LeftButtonClicked() || PlayerInput.RightButtonClicked()) && selected)
                {
                    if (!mouseHeldInside)
                    {
                        Deselect();
                    }
                    mouseHeldInside = false;
                }
                isSelecting = false;
                State       = ComponentState.None;
            }
            if (!isSelecting)
            {
                isSelecting = PlayerInput.KeyDown(Keys.LeftShift) || PlayerInput.KeyDown(Keys.RightShift);
            }

            if (CaretEnabled)
            {
                if (textBlock.OverflowClipActive)
                {
                    if (CaretScreenPos.X < textBlock.Rect.X + textBlock.Padding.X)
                    {
                        textBlock.TextPos = new Vector2(textBlock.TextPos.X + ((textBlock.Rect.X + textBlock.Padding.X) - CaretScreenPos.X), textBlock.TextPos.Y);
                        CalculateCaretPos();
                    }
                    else if (CaretScreenPos.X > textBlock.Rect.Right - textBlock.Padding.Z)
                    {
                        textBlock.TextPos = new Vector2(textBlock.TextPos.X - (CaretScreenPos.X - (textBlock.Rect.Right - textBlock.Padding.Z)), textBlock.TextPos.Y);
                        CalculateCaretPos();
                    }
                }
                caretTimer  += deltaTime;
                caretVisible = ((caretTimer * 1000.0f) % 1000) < 500;
                if (caretVisible && caretPosDirty)
                {
                    CalculateCaretPos();
                }
            }

            if (GUI.KeyboardDispatcher.Subscriber == this)
            {
                State = ComponentState.Selected;
                Character.DisableControls = true;
                if (OnEnterPressed != null && PlayerInput.KeyHit(Keys.Enter))
                {
                    OnEnterPressed(this, Text);
                }
            }
            else if (Selected)
            {
                Deselect();
            }

            textBlock.State = State;
        }
Пример #29
0
        public override void Update(float deltaTime, Camera cam, bool isSubInventory = false)
        {
            if (!AccessibleWhenAlive && !character.IsDead)
            {
                syncItemsDelay = Math.Max(syncItemsDelay - deltaTime, 0.0f);
                return;
            }

            base.Update(deltaTime, cam);

            bool hoverOnInventory = GUI.MouseOn == null &&
                                    ((selectedSlot != null && selectedSlot.IsSubSlot) || (draggingItem != null && (draggingSlot == null || !draggingSlot.MouseOn())));

            if (CharacterHealth.OpenHealthWindow != null)
            {
                hoverOnInventory = true;
            }

            if (layout == Layout.Default && hideButton.Visible)
            {
                hideButton.AddToGUIUpdateList();
                hideButton.UpdateManually(deltaTime, alsoChildren: true);

                hidePersonalSlotsState = hidePersonalSlots ?
                                         Math.Min(hidePersonalSlotsState + deltaTime * 5.0f, 1.0f) :
                                         Math.Max(hidePersonalSlotsState - deltaTime * 5.0f, 0.0f);

                for (int i = 0; i < slots.Length; i++)
                {
                    if (!PersonalSlots.HasFlag(SlotTypes[i]))
                    {
                        continue;
                    }
                    if (HidePersonalSlots)
                    {
                        if (selectedSlot?.Slot == slots[i])
                        {
                            selectedSlot = null;
                        }
                        highlightedSubInventorySlots.RemoveWhere(s => s.Slot == slots[i]);
                    }
                    slots[i].DrawOffset = Vector2.Lerp(Vector2.Zero, new Vector2(personalSlotArea.Width, 0.0f), hidePersonalSlotsState);
                }
            }

            if (hoverOnInventory)
            {
                HideTimer = 0.5f;
            }
            if (HideTimer > 0.0f)
            {
                HideTimer -= deltaTime;
            }

            for (int i = 0; i < capacity; i++)
            {
                if (Items[i] != null && Items[i] != draggingItem && Character.Controlled?.Inventory == this &&
                    GUI.KeyboardDispatcher.Subscriber == null &&
                    slots[i].QuickUseKey != Keys.None && PlayerInput.KeyHit(slots[i].QuickUseKey))
                {
                    QuickUseItem(Items[i], true, false, true);
                }
            }

            //force personal slots open if an item is running out of battery/fuel/oxygen/etc
            if (hidePersonalSlots)
            {
                for (int i = 0; i < slots.Length; i++)
                {
                    if (Items[i]?.OwnInventory != null && Items[i].OwnInventory.Capacity == 1 && PersonalSlots.HasFlag(SlotTypes[i]))
                    {
                        if (Items[i].OwnInventory.Items[0] != null &&
                            Items[i].OwnInventory.Items[0].Condition > 0.0f &&
                            Items[i].OwnInventory.Items[0].Condition / Items[i].OwnInventory.Items[0].MaxCondition < 0.15f)
                        {
                            hidePersonalSlots = false;
                        }
                    }
                }
            }

            List <SlotReference> hideSubInventories = new List <SlotReference>();

            foreach (var highlightedSubInventorySlot in highlightedSubInventorySlots)
            {
                if (highlightedSubInventorySlot.ParentInventory == this)
                {
                    UpdateSubInventory(deltaTime, highlightedSubInventorySlot.SlotIndex, cam);
                }

                Rectangle hoverArea = GetSubInventoryHoverArea(highlightedSubInventorySlot);
                if (highlightedSubInventorySlot.Inventory?.slots == null || (!hoverArea.Contains(PlayerInput.MousePosition)))
                {
                    hideSubInventories.Add(highlightedSubInventorySlot);
                }
                else
                {
                    highlightedSubInventorySlot.Inventory.HideTimer = 1.0f;
                }
            }

            if (doubleClickedItem != null)
            {
                QuickUseItem(doubleClickedItem, true, true, true);
            }

            //activate the subinventory of the currently selected slot
            if (selectedSlot?.ParentInventory == this)
            {
                var subInventory = GetSubInventory(selectedSlot.SlotIndex);
                if (subInventory != null)
                {
                    selectedSlot.Inventory = subInventory;
                    if (!highlightedSubInventorySlots.Any(s => s.Inventory == subInventory))
                    {
                        var slot = selectedSlot;
                        highlightedSubInventorySlots.Add(selectedSlot);
                        UpdateSubInventory(deltaTime, selectedSlot.SlotIndex, cam);

                        //hide previously opened subinventories if this one overlaps with them
                        Rectangle hoverArea = GetSubInventoryHoverArea(slot);
                        foreach (SlotReference highlightedSubInventorySlot in highlightedSubInventorySlots)
                        {
                            if (highlightedSubInventorySlot == slot)
                            {
                                continue;
                            }
                            if (hoverArea.Intersects(GetSubInventoryHoverArea(highlightedSubInventorySlot)))
                            {
                                hideSubInventories.Add(highlightedSubInventorySlot);
                                highlightedSubInventorySlot.Inventory.HideTimer = 0.0f;
                            }
                        }
                    }
                }
            }

            foreach (var subInventorySlot in hideSubInventories)
            {
                if (subInventorySlot.Inventory == null)
                {
                    continue;
                }
                subInventorySlot.Inventory.HideTimer -= deltaTime;
                if (subInventorySlot.Inventory.HideTimer <= 0.0f)
                {
                    highlightedSubInventorySlots.Remove(subInventorySlot);
                }
            }

            for (int i = 0; i < capacity; i++)
            {
                if (Items[i] != null && Items[i].AllowedSlots.Any(a => a != InvSlotType.Any))
                {
                    slots[i].EquipButtonState = slots[i].EquipButtonRect.Contains(PlayerInput.MousePosition) ?
                                                GUIComponent.ComponentState.Hover : GUIComponent.ComponentState.None;
                    if (PlayerInput.LeftButtonHeld() && PlayerInput.RightButtonHeld())
                    {
                        slots[i].EquipButtonState = GUIComponent.ComponentState.None;
                    }

                    if (slots[i].EquipButtonState != GUIComponent.ComponentState.Hover)
                    {
                        slots[i].QuickUseTimer = Math.Max(0.0f, slots[i].QuickUseTimer - deltaTime * 5.0f);
                        continue;
                    }

                    var quickUseAction = GetQuickUseAction(Items[i], allowEquip: true, allowInventorySwap: false, allowApplyTreatment: false);
                    slots[i].QuickUseButtonToolTip = quickUseAction == QuickUseAction.None ?
                                                     "" : TextManager.Get("QuickUseAction." + quickUseAction.ToString());

                    //equipped item that can't be put in the inventory, use delayed dropping
                    if (quickUseAction == QuickUseAction.Drop)
                    {
                        slots[i].QuickUseButtonToolTip =
                            TextManager.Get("QuickUseAction.HoldToUnequip", returnNull: true) ??
                            (GameMain.Config.Language == "English" ?  "Hold to unequip" : TextManager.Get("QuickUseAction.Unequip"));

                        if (PlayerInput.LeftButtonHeld())
                        {
                            slots[i].QuickUseTimer = Math.Max(0.1f, slots[i].QuickUseTimer + deltaTime);
                            if (slots[i].QuickUseTimer >= 1.0f)
                            {
                                Items[i].Drop(Character.Controlled);
                                GUI.PlayUISound(GUISoundType.DropItem);
                            }
                        }
                        else
                        {
                            slots[i].QuickUseTimer = Math.Max(0.0f, slots[i].QuickUseTimer - deltaTime * 5.0f);
                        }
                    }
                    else
                    {
                        if (PlayerInput.LeftButtonDown())
                        {
                            slots[i].EquipButtonState = GUIComponent.ComponentState.Pressed;
                        }
                        if (PlayerInput.LeftButtonClicked())
                        {
                            QuickUseItem(Items[i], allowEquip: true, allowInventorySwap: false, allowApplyTreatment: false);
                        }
                    }
                }
            }


            //cancel dragging if too far away from the container of the dragged item
            if (draggingItem != null)
            {
                var rootContainer = draggingItem.GetRootContainer();
                var rootInventory = draggingItem.ParentInventory;

                if (rootContainer != null)
                {
                    rootInventory = rootContainer.ParentInventory ?? rootContainer.GetComponent <ItemContainer>().Inventory;
                }

                if (rootInventory != null &&
                    rootInventory.Owner != Character.Controlled &&
                    rootInventory.Owner != Character.Controlled.SelectedConstruction &&
                    rootInventory.Owner != Character.Controlled.SelectedCharacter)
                {
                    //allow interacting if the container is linked to the item the character is interacting with
                    if (!(rootContainer != null &&
                          rootContainer.DisplaySideBySideWhenLinked &&
                          Character.Controlled.SelectedConstruction != null &&
                          rootContainer.linkedTo.Contains(Character.Controlled.SelectedConstruction)))
                    {
                        draggingItem = null;
                    }
                }
            }

            doubleClickedItem = null;
        }
Пример #30
0
        public void Draw(SpriteBatch spriteBatch, GUICustomComponent mapContainer)
        {
            Rectangle rect = mapContainer.Rect;

            Vector2 viewSize   = new Vector2(rect.Width / zoom, rect.Height / zoom);
            float   edgeBuffer = size * (BackgroundScale - 1.0f) / 2;

            drawOffset.X = MathHelper.Clamp(drawOffset.X, -size - edgeBuffer + viewSize.X / 2.0f, edgeBuffer - viewSize.X / 2.0f);
            drawOffset.Y = MathHelper.Clamp(drawOffset.Y, -size - edgeBuffer + viewSize.Y / 2.0f, edgeBuffer - viewSize.Y / 2.0f);

            drawOffsetNoise = new Vector2(
                (float)PerlinNoise.CalculatePerlin(Timing.TotalTime * 0.1f % 255, Timing.TotalTime * 0.1f % 255, 0) - 0.5f,
                (float)PerlinNoise.CalculatePerlin(Timing.TotalTime * 0.2f % 255, Timing.TotalTime * 0.2f % 255, 0.5f) - 0.5f) * 10.0f;

            Vector2 viewOffset = drawOffset + drawOffsetNoise;

            Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y);

            Rectangle prevScissorRect = GameMain.Instance.GraphicsDevice.ScissorRectangle;

            spriteBatch.End();
            spriteBatch.GraphicsDevice.ScissorRectangle = Rectangle.Intersect(prevScissorRect, rect);
            spriteBatch.Begin(SpriteSortMode.Deferred, rasterizerState: GameMain.ScissorTestEnable);

            for (int x = 0; x < mapTiles.GetLength(0); x++)
            {
                for (int y = 0; y < mapTiles.GetLength(1); y++)
                {
                    Vector2 mapPos = new Vector2(
                        x * generationParams.TileSpriteSpacing.X + ((y % 2 == 0) ? 0.0f : generationParams.TileSpriteSpacing.X * 0.5f),
                        y * generationParams.TileSpriteSpacing.Y);

                    mapPos.X -= size / 2 * (BackgroundScale - 1.0f);
                    mapPos.Y -= size / 2 * (BackgroundScale - 1.0f);

                    Vector2 scale = new Vector2(
                        generationParams.TileSpriteSize.X / mapTiles[x, y].Sprite.size.X,
                        generationParams.TileSpriteSize.Y / mapTiles[x, y].Sprite.size.Y);
                    mapTiles[x, y].Sprite.Draw(spriteBatch, rectCenter + (mapPos + viewOffset) * zoom, Color.White,
                                               origin: new Vector2(256.0f, 256.0f), rotate: 0, scale: scale * zoom, spriteEffect: mapTiles[x, y].SpriteEffect);
                }
            }
#if DEBUG
            if (generationParams.ShowNoiseMap)
            {
                GUI.DrawRectangle(spriteBatch, rectCenter + (borders.Location.ToVector2() + viewOffset) * zoom, borders.Size.ToVector2() * zoom, Color.White, true);
            }
#endif
            Vector2 topLeft = rectCenter + viewOffset * zoom;
            topLeft.X = (int)topLeft.X;
            topLeft.Y = (int)topLeft.Y;

            Vector2 bottomRight = rectCenter + (viewOffset + new Vector2(size, size)) * zoom;
            bottomRight.X = (int)bottomRight.X;
            bottomRight.Y = (int)bottomRight.Y;

            spriteBatch.Draw(noiseTexture,
                             destinationRectangle: new Rectangle((int)topLeft.X, (int)topLeft.Y, (int)(bottomRight.X - topLeft.X), (int)(bottomRight.Y - topLeft.Y)),
                             sourceRectangle: null,
                             color: Color.White);

            if (topLeft.X > rect.X)
            {
                GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Y, (int)(topLeft.X - rect.X), rect.Height), Color.Black * 0.8f, true);
            }
            if (topLeft.Y > rect.Y)
            {
                GUI.DrawRectangle(spriteBatch, new Rectangle((int)topLeft.X, rect.Y, (int)(bottomRight.X - topLeft.X), (int)(topLeft.Y - rect.Y)), Color.Black * 0.8f, true);
            }
            if (bottomRight.X < rect.Right)
            {
                GUI.DrawRectangle(spriteBatch, new Rectangle((int)bottomRight.X, rect.Y, (int)(rect.Right - bottomRight.X), rect.Height), Color.Black * 0.8f, true);
            }
            if (bottomRight.Y < rect.Bottom)
            {
                GUI.DrawRectangle(spriteBatch, new Rectangle((int)topLeft.X, (int)bottomRight.Y, (int)(bottomRight.X - topLeft.X), (int)(rect.Bottom - bottomRight.Y)), Color.Black * 0.8f, true);
            }

            var   sourceRect    = rect;
            float rawNoiseScale = 1.0f + Noise[(int)(Timing.TotalTime * 100 % Noise.GetLength(0) - 1), (int)(Timing.TotalTime * 100 % Noise.GetLength(1) - 1)];
            cameraNoiseStrength = Noise[(int)(Timing.TotalTime * 10 % Noise.GetLength(0) - 1), (int)(Timing.TotalTime * 10 % Noise.GetLength(1) - 1)];

            rawNoiseSprite.DrawTiled(spriteBatch, rect.Location.ToVector2(), rect.Size.ToVector2(),
                                     startOffset: new Point(Rand.Range(0, rawNoiseSprite.SourceRect.Width), Rand.Range(0, rawNoiseSprite.SourceRect.Height)),
                                     color: Color.White * cameraNoiseStrength * 0.5f,
                                     textureScale: Vector2.One * rawNoiseScale);

            rawNoiseSprite.DrawTiled(spriteBatch, rect.Location.ToVector2(), rect.Size.ToVector2(),
                                     startOffset: new Point(Rand.Range(0, rawNoiseSprite.SourceRect.Width), Rand.Range(0, rawNoiseSprite.SourceRect.Height)),
                                     color: new Color(20, 20, 20, 100),
                                     textureScale: Vector2.One * rawNoiseScale * 2);

            if (generationParams.ShowLocations)
            {
                foreach (LocationConnection connection in connections)
                {
                    Color connectionColor;
                    if (GameMain.DebugDraw)
                    {
                        float sizeFactor = MathUtils.InverseLerp(
                            MapGenerationParams.Instance.SmallLevelConnectionLength,
                            MapGenerationParams.Instance.LargeLevelConnectionLength,
                            connection.Length);

                        connectionColor = ToolBox.GradientLerp(sizeFactor, Color.LightGreen, Color.Orange, Color.Red);
                    }
                    else
                    {
                        connectionColor = ToolBox.GradientLerp(connection.Difficulty / 100.0f,
                                                               MapGenerationParams.Instance.LowDifficultyColor,
                                                               MapGenerationParams.Instance.MediumDifficultyColor,
                                                               MapGenerationParams.Instance.HighDifficultyColor);
                    }

                    int width = (int)(3 * zoom);

                    if (SelectedLocation != CurrentLocation &&
                        (connection.Locations.Contains(SelectedLocation) && connection.Locations.Contains(CurrentLocation)))
                    {
                        connectionColor = Color.Gold;
                        width          *= 2;
                    }
                    else if (highlightedLocation != CurrentLocation &&
                             (connection.Locations.Contains(highlightedLocation) && connection.Locations.Contains(CurrentLocation)))
                    {
                        connectionColor = Color.Lerp(connectionColor, Color.White, 0.5f);
                        width          *= 2;
                    }
                    else if (!connection.Passed)
                    {
                        //crackColor *= 0.5f;
                    }

                    for (int i = 0; i < connection.CrackSegments.Count; i++)
                    {
                        var segment = connection.CrackSegments[i];

                        Vector2 start = rectCenter + (segment[0] + viewOffset) * zoom;
                        Vector2 end   = rectCenter + (segment[1] + viewOffset) * zoom;

                        if (!rect.Contains(start) && !rect.Contains(end))
                        {
                            continue;
                        }
                        else
                        {
                            if (MathUtils.GetLineRectangleIntersection(start, end, new Rectangle(rect.X, rect.Y + rect.Height, rect.Width, rect.Height), out Vector2 intersection))
                            {
                                if (!rect.Contains(start))
                                {
                                    start = intersection;
                                }
                                else
                                {
                                    end = intersection;
                                }
                            }
                        }

                        float distFromPlayer = Vector2.Distance(CurrentLocation.MapPosition, (segment[0] + segment[1]) / 2.0f);
                        float dist           = Vector2.Distance(start, end);

                        float a = GameMain.DebugDraw ? 1.0f : (200.0f - distFromPlayer) / 200.0f;
                        spriteBatch.Draw(generationParams.ConnectionSprite.Texture,
                                         new Rectangle((int)start.X, (int)start.Y, (int)(dist - 1 * zoom), width),
                                         null, connectionColor * MathHelper.Clamp(a, 0.1f, 0.5f), MathUtils.VectorToAngle(end - start),
                                         new Vector2(0, 16), SpriteEffects.None, 0.01f);
                    }

                    if (GameMain.DebugDraw && zoom > 1.0f && generationParams.ShowLevelTypeNames)
                    {
                        Vector2 center = rectCenter + (connection.CenterPos + viewOffset) * zoom;
                        if (rect.Contains(center))
                        {
                            GUI.DrawString(spriteBatch, center, connection.Biome.Name + " (" + connection.Difficulty + ")", Color.White);
                        }
                    }
                }

                rect.Inflate(8, 8);
                GUI.DrawRectangle(spriteBatch, rect, Color.Black, false, 0.0f, 8);
                GUI.DrawRectangle(spriteBatch, rect, Color.LightGray);

                for (int i = 0; i < Locations.Count; i++)
                {
                    Location location = Locations[i];
                    Vector2  pos      = rectCenter + (location.MapPosition + viewOffset) * zoom;

                    Rectangle drawRect = location.Type.Sprite.SourceRect;
                    drawRect.X = (int)pos.X - drawRect.Width / 2;
                    drawRect.Y = (int)pos.Y - drawRect.Width / 2;

                    if (!rect.Intersects(drawRect))
                    {
                        continue;
                    }

                    Color color = location.Type.SpriteColor;
                    if (location.Connections.Find(c => c.Locations.Contains(CurrentLocation)) == null)
                    {
                        color *= 0.5f;
                    }

                    float iconScale = location == CurrentLocation ? 1.2f : 1.0f;
                    if (location == highlightedLocation)
                    {
                        iconScale *= 1.1f;
                        color      = Color.Lerp(color, Color.White, 0.5f);
                    }

                    float distFromPlayer = Vector2.Distance(CurrentLocation.MapPosition, location.MapPosition);
                    color *= MathHelper.Clamp((1000.0f - distFromPlayer) / 500.0f, 0.1f, 1.0f);

                    location.Type.Sprite.Draw(spriteBatch, pos, color,
                                              scale: MapGenerationParams.Instance.LocationIconSize / location.Type.Sprite.size.X * iconScale * zoom);
                    MapGenerationParams.Instance.LocationIndicator.Draw(spriteBatch, pos, color,
                                                                        scale: MapGenerationParams.Instance.LocationIconSize / MapGenerationParams.Instance.LocationIndicator.size.X * iconScale * zoom * 1.4f);
                }

                //PLACEHOLDER until the stuff at the center of the map is implemented
                float   centerIconSize = 50.0f;
                Vector2 centerPos      = rectCenter + (new Vector2(size / 2) + viewOffset) * zoom;
                bool    mouseOn        = Vector2.Distance(PlayerInput.MousePosition, centerPos) < centerIconSize * zoom;

                var   centerLocationType = LocationType.List.Last();
                Color centerColor        = centerLocationType.SpriteColor * (mouseOn ? 1.0f : 0.6f);
                centerLocationType.Sprite.Draw(spriteBatch, centerPos, centerColor,
                                               scale: centerIconSize / centerLocationType.Sprite.size.X * zoom);
                MapGenerationParams.Instance.LocationIndicator.Draw(spriteBatch, centerPos, centerColor,
                                                                    scale: centerIconSize / MapGenerationParams.Instance.LocationIndicator.size.X * zoom * 1.2f);

                if (mouseOn && PlayerInput.LeftButtonClicked() && !messageBoxOpen)
                {
                    if (TextManager.ContainsTag("centerarealockedheader") && TextManager.ContainsTag("centerarealockedtext"))
                    {
                        var messageBox = new GUIMessageBox(
                            TextManager.Get("centerarealockedheader"),
                            TextManager.Get("centerarealockedtext"));
                        messageBoxOpen = true;
                        CoroutineManager.StartCoroutine(WaitForMessageBoxClosed(messageBox));
                    }
                    else
                    {
                        //if the message cannot be shown in the selected language,
                        //show the campaign roadmap (which mentions the center location not being reachable)
                        var messageBox = new GUIMessageBox(TextManager.Get("CampaignRoadMapTitle"), TextManager.Get("CampaignRoadMapText"));
                        messageBoxOpen = true;
                        CoroutineManager.StartCoroutine(WaitForMessageBoxClosed(messageBox));
                    }
                }
            }

            DrawDecorativeHUD(spriteBatch, rect);

            for (int i = 0; i < 2; i++)
            {
                Location location = (i == 0) ? highlightedLocation : CurrentLocation;
                if (location == null)
                {
                    continue;
                }

                Vector2 pos = rectCenter + (location.MapPosition + viewOffset) * zoom;
                pos.X += 25 * zoom;
                pos.Y -= 5 * zoom;
                Vector2 size = GUI.LargeFont.MeasureString(location.Name);
                GUI.Style.GetComponentStyle("OuterGlow").Sprites[GUIComponent.ComponentState.None][0].Draw(
                    spriteBatch, new Rectangle((int)pos.X - 30, (int)pos.Y, (int)size.X + 60, (int)(size.Y + 25 * GUI.Scale)), Color.Black * hudOpenState * 0.7f);
                GUI.DrawString(spriteBatch, pos,
                               location.Name, Color.White * hudOpenState * 1.5f, font: GUI.LargeFont);
                GUI.DrawString(spriteBatch, pos + Vector2.UnitY * 25 * GUI.Scale,
                               location.Type.Name, Color.White * hudOpenState * 1.5f);
            }

            GameMain.Instance.GraphicsDevice.ScissorRectangle = prevScissorRect;
            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Deferred);
        }