Example #1
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;
            }
        }
Example #2
0
        public bool IsDown()
        {
            switch (MouseButton)
            {
            case null:
                return(PlayerInput.KeyDown(Key));

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

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

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

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

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

            case 5:     // No real way of "holding" a mouse wheel key, but then again it makes no sense to bind the key to this kind of task.
                return(PlayerInput.MouseWheelUpClicked());

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

            return(false);
        }
Example #3
0
        protected void UpdateSlot(InventorySlot slot, int slotIndex, Item item, bool isSubSlot)
        {
            bool mouseOn = slot.InteractRect.Contains(PlayerInput.MousePosition) && !Locked;

            slot.State = GUIComponent.ComponentState.None;

            if (mouseOn &&
                (draggingItem != null || selectedSlot == null || selectedSlot.Slot == slot) &&
                (highlightedSubInventory == null || highlightedSubInventory == this || highlightedSubInventorySlot?.Slot == slot || highlightedSubInventory.Owner == item))
            {
                slot.State = GUIComponent.ComponentState.Hover;

                if (selectedSlot == null || (!selectedSlot.IsSubSlot && isSubSlot))
                {
                    selectedSlot = new SlotReference(this, slot, slotIndex, isSubSlot);
                }

                if (draggingItem == null)
                {
                    if (PlayerInput.LeftButtonHeld())
                    {
                        draggingItem = Items[slotIndex];
                        draggingSlot = slot;
                    }
                }
                else if (PlayerInput.LeftButtonReleased())
                {
                    if (PlayerInput.DoubleClicked())
                    {
                        doubleClickedItem = item;
                    }
                }
            }
        }
Example #4
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);
        }
Example #5
0
        public override void DrawPlacing(SpriteBatch spriteBatch, Camera cam)
        {
            Vector2   position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
            Rectangle newRect  = new Rectangle((int)position.X, (int)position.Y, (int)ScaledSize.X, (int)ScaledSize.Y);

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

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

                newRect = Submarine.AbsRect(placePosition, placeSize);
            }

            sprite.DrawTiled(spriteBatch, new Vector2(newRect.X, -newRect.Y), new Vector2(newRect.Width, newRect.Height), textureScale: TextureScale * Scale);
            GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X - GameMain.GraphicsWidth, -newRect.Y, newRect.Width + GameMain.GraphicsWidth * 2, newRect.Height), Color.White);
            GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X, -newRect.Y - GameMain.GraphicsHeight, newRect.Width, newRect.Height + GameMain.GraphicsHeight * 2), Color.White);
        }
Example #6
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);
            }
        }
Example #7
0
        public virtual void Update(float deltaTime, bool subInventory = false)
        {
            syncItemsDelay = Math.Max(syncItemsDelay - deltaTime, 0.0f);

            if (slots == null || isSubInventory != subInventory)
            {
                CreateSlots();
                isSubInventory = subInventory;
            }

            for (int i = 0; i < capacity; i++)
            {
                if (slots[i].Disabled)
                {
                    continue;
                }
                UpdateSlot(slots[i], i, Items[i], false);
            }


            if (draggingItem != null &&
                (draggingSlot == null || (!draggingSlot.Rect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this)))
            {
                if (!PlayerInput.LeftButtonHeld())
                {
                    CreateNetworkEvent();

                    draggingItem.Drop();
                }
            }
        }
Example #8
0
        protected void UpdateSlot(InventorySlot slot, int slotIndex, Item item, bool isSubSlot)
        {
            bool mouseOn = slot.Rect.Contains(PlayerInput.MousePosition) && !Locked;

            slot.State = GUIComponent.ComponentState.None;

            if (!(this is CharacterInventory) && !mouseOn && selectedSlot == slotIndex)
            {
                selectedSlot = -1;
            }

            if (mouseOn &&
                (draggingItem != null || selectedSlot == slotIndex || selectedSlot == -1))
            {
                slot.State = GUIComponent.ComponentState.Hover;

                if (!isSubSlot && selectedSlot == -1)
                {
                    selectedSlot = slotIndex;
                }

                if (draggingItem == null)
                {
                    if (PlayerInput.LeftButtonHeld())
                    {
                        draggingItem = Items[slotIndex];
                        draggingSlot = slot;
                    }
                }
                else if (PlayerInput.LeftButtonReleased())
                {
                    if (PlayerInput.DoubleClicked())
                    {
                        doubleClickedItem = item;
                    }

                    if (draggingItem != Items[slotIndex])
                    {
                        //selectedSlot = slotIndex;
                        if (TryPutItem(draggingItem, slotIndex, true))
                        {
                            if (slots != null)
                            {
                                slots[slotIndex].ShowBorderHighlight(Color.White, 0.1f, 0.4f);
                            }
                        }
                        else
                        {
                            if (slots != null)
                            {
                                slots[slotIndex].ShowBorderHighlight(Color.Red, 0.1f, 0.9f);
                            }
                        }
                        draggingItem = null;
                        draggingSlot = null;
                    }
                }
            }
        }
Example #9
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;
 }
Example #10
0
        public override void DrawPlacing(SpriteBatch spriteBatch, Camera cam, Rectangle?placeRect = null)
        {
            Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);

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

            if (!ResizeHorizontal && !ResizeVertical)
            {
                if (placeRect.HasValue)
                {
                    sprite.Draw(spriteBatch, new Vector2(placeRect.Value.Center.X, -(placeRect.Value.Y - placeRect.Value.Height / 2)), SpriteColor);
                }
                else
                {
                    sprite.Draw(spriteBatch, new Vector2(position.X, -position.Y) + sprite.size / 2.0f * Scale, SpriteColor, scale: Scale);
                }
            }
            else if (placeRect.HasValue)
            {
                if (sprite != null)
                {
                    sprite.DrawTiled(spriteBatch, new Vector2(placeRect.Value.X, -placeRect.Value.Y), placeRect.Value.Size.ToVector2(), null, SpriteColor);
                }
            }
            else
            {
                Vector2 placeSize = size;
                if (placePosition == Vector2.Zero)
                {
                    if (PlayerInput.LeftButtonHeld())
                    {
                        placePosition = position;
                    }
                }
                else
                {
                    if (ResizeHorizontal)
                    {
                        placeSize.X = Math.Max(position.X - placePosition.X, size.X);
                    }
                    if (ResizeVertical)
                    {
                        placeSize.Y = Math.Max(placePosition.Y - position.Y, size.Y);
                    }

                    position = placePosition;
                }

                if (sprite != null)
                {
                    sprite.DrawTiled(spriteBatch, new Vector2(position.X, -position.Y), placeSize, color: SpriteColor);
                }
            }
        }
Example #11
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);
                }
            }
        }
        public override void UpdatePlacing(Camera cam)
        {
            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.LeftButtonHeld())
                {
                    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.LeftButtonReleased())
                {
                    newRect.Location -= MathUtils.ToPoint(Submarine.MainSub.Position);
                    var structure = new Structure(newRect, this, Submarine.MainSub)
                    {
                        Submarine = Submarine.MainSub
                    };

                    selected = null;
                    return;
                }
            }

            if (PlayerInput.RightButtonHeld())
            {
                selected = null;
            }
        }
Example #13
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;
        }
Example #14
0
        private void DrawJoints(SpriteBatch spriteBatch, Limb limb, Vector2 limbBodyPos)
        {
            foreach (var joint in editingCharacter.AnimController.LimbJoints)
            {
                Vector2 jointPos = Vector2.Zero;

                if (joint.BodyA == limb.body.FarseerBody)
                {
                    jointPos = ConvertUnits.ToDisplayUnits(joint.LocalAnchorA);
                }
                else if (joint.BodyB == limb.body.FarseerBody)
                {
                    jointPos = ConvertUnits.ToDisplayUnits(joint.LocalAnchorB);
                }
                else
                {
                    continue;
                }

                Vector2 tformedJointPos = jointPos /= limb.Scale;
                tformedJointPos.Y = -tformedJointPos.Y;
                tformedJointPos  += limbBodyPos;

                if (joint.BodyA == limb.body.FarseerBody)
                {
                    float a1 = joint.UpperLimit - MathHelper.PiOver2;
                    float a2 = joint.LowerLimit - MathHelper.PiOver2;
                    float a3 = (a1 + a2) / 2.0f;
                    GUI.DrawLine(spriteBatch, tformedJointPos, tformedJointPos + new Vector2((float)Math.Cos(a1), -(float)Math.Sin(a1)) * 30.0f, Color.Green);
                    GUI.DrawLine(spriteBatch, tformedJointPos, tformedJointPos + new Vector2((float)Math.Cos(a2), -(float)Math.Sin(a2)) * 30.0f, Color.DarkGreen);

                    GUI.DrawLine(spriteBatch, tformedJointPos, tformedJointPos + new Vector2((float)Math.Cos(a3), -(float)Math.Sin(a3)) * 30.0f, Color.LightGray);
                }

                GUI.DrawRectangle(spriteBatch, tformedJointPos, new Vector2(5.0f, 5.0f), Color.Red, true);
                if (Vector2.Distance(PlayerInput.MousePosition, tformedJointPos) < 10.0f)
                {
                    GUI.DrawString(spriteBatch, tformedJointPos + Vector2.One * 10.0f, jointPos.ToString(), Color.White, Color.Black * 0.5f);
                    GUI.DrawRectangle(spriteBatch, tformedJointPos - new Vector2(3.0f, 3.0f), new Vector2(11.0f, 11.0f), Color.Red, false);
                    if (PlayerInput.LeftButtonHeld())
                    {
                        Vector2 speed = ConvertUnits.ToSimUnits(PlayerInput.MouseSpeed);
                        speed.Y = -speed.Y;
                        if (joint.BodyA == limb.body.FarseerBody)
                        {
                            joint.LocalAnchorA += speed;
                        }
                        else
                        {
                            joint.LocalAnchorB += speed;
                        }
                    }
                }
            }
        }
Example #15
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);
        }
Example #16
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));
                }
            }
        }
        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);
                }
            }
        }
Example #18
0
        public virtual void UpdatePlacing(Camera cam)
        {
            Vector2 placeSize = Submarine.GridSize;

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

                if (PlayerInput.LeftButtonHeld())
                {
                    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.LeftButtonReleased())
                {
                    CreateInstance(newRect);
                    placePosition = Vector2.Zero;
                    selected      = null;
                }

                newRect.Y = -newRect.Y;
            }

            if (PlayerInput.RightButtonHeld())
            {
                placePosition = Vector2.Zero;
                selected      = null;
            }
        }
Example #19
0
        public override void UpdatePlacing(Camera cam)
        {
            Vector2   position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
            Rectangle newRect  = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);

            if (placePosition == Vector2.Zero)
            {
                if (PlayerInput.LeftButtonHeld())
                {
                    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;
                }

                newRect = Submarine.AbsRect(placePosition, placeSize);

                if (PlayerInput.LeftButtonReleased())
                {
                    //don't allow resizing width/height to zero
                    if ((!resizeHorizontal || placeSize.X != 0.0f) && (!resizeVertical || placeSize.Y != 0.0f))
                    {
                        newRect.Location -= Submarine.MainSub.Position.ToPoint();

                        var structure = new Structure(newRect, this, Submarine.MainSub);
                        structure.Submarine = Submarine.MainSub;
                    }

                    selected = null;
                    return;
                }
            }

            if (PlayerInput.RightButtonHeld())
            {
                selected = null;
            }
        }
Example #20
0
        public override void DrawPlacing(SpriteBatch spriteBatch, Camera cam)
        {
            Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);

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

            if (!resizeHorizontal && !resizeVertical)
            {
                sprite.Draw(spriteBatch, new Vector2(position.X + sprite.size.X / 2.0f, -position.Y + sprite.size.Y / 2.0f), SpriteColor);
            }
            else
            {
                Vector2 placeSize = size;

                if (placePosition == Vector2.Zero)
                {
                    if (PlayerInput.LeftButtonHeld())
                    {
                        placePosition = position;
                    }
                }
                else
                {
                    if (resizeHorizontal)
                    {
                        placeSize.X = Math.Max(position.X - placePosition.X, size.X);
                    }
                    if (resizeVertical)
                    {
                        placeSize.Y = Math.Max(placePosition.Y - position.Y, size.Y);
                    }

                    position = placePosition;
                }

                if (sprite != null)
                {
                    sprite.DrawTiled(spriteBatch, new Vector2(position.X, -position.Y), placeSize, SpriteColor);
                }
            }

            //if (PlayerInput.GetMouseState.RightButton == ButtonState.Pressed) selected = null;
        }
Example #21
0
        public bool IsDown()
        {
            if (mouseButton == null)
            {
                return(PlayerInput.KeyDown(keyBinding));
            }
            else if (mouseButton == 0)
            {
                return(PlayerInput.LeftButtonHeld());
            }
            else if (mouseButton == 1)
            {
                return(PlayerInput.RightButtonHeld());
            }

            return(false);
        }
Example #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);
 }
Example #23
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;
            }
        }
Example #24
0
        public bool IsDown()
        {
            switch (MouseButton)
            {
            case MouseButton.None:
                return(PlayerInput.KeyDown(Key));

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

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

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

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

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

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

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

            case MouseButton.MouseWheelUp:     // No real way of "holding" a mouse wheel key, but then again it makes no sense to bind the key to this kind of task.
                return(PlayerInput.MouseWheelUpClicked());

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

            return(false);
        }
Example #25
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        public override void Update(double deltaTime)
        {
#if CLIENT
            if (Character.Spied != null)
            {
                if ((PlayerInput.KeyDown(InputType.Up) || PlayerInput.KeyDown(InputType.Down) || PlayerInput.KeyDown(InputType.Left) || PlayerInput.KeyDown(InputType.Right)) && !DebugConsole.IsOpen)
                {
                    if (GameMain.NetworkMember != null && !GameMain.NetworkMember.chatMsgBox.Selected)
                    {
                        if (Character.Controlled != null)
                        {
                            cam.Position = Character.Controlled.WorldPosition;
                        }
                        else
                        {
                            cam.Position = Character.Spied.WorldPosition;
                        }
                        Character.Spied = null;
                        cam.UpdateTransform(true);
                    }
                }
            }
#endif

#if DEBUG && CLIENT
            if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null &&
                !DebugConsole.IsOpen && GUIComponent.KeyboardDispatcher.Subscriber == null)
            {
                /*
                 * var closestSub = Submarine.FindClosest(cam.WorldViewCenter);
                 * if (closestSub == null) closestSub = GameMain.GameSession.Submarine;
                 *
                 * Vector2 targetMovement = Vector2.Zero;
                 * if (PlayerInput.KeyDown(Keys.I)) targetMovement.Y += 1.0f;
                 * if (PlayerInput.KeyDown(Keys.K)) targetMovement.Y -= 1.0f;
                 * if (PlayerInput.KeyDown(Keys.J)) targetMovement.X -= 1.0f;
                 * if (PlayerInput.KeyDown(Keys.L)) targetMovement.X += 1.0f;
                 *
                 * if (targetMovement != Vector2.Zero)
                 *  closestSub.ApplyForce(targetMovement * closestSub.SubBody.Body.Mass * 100.0f);
                 */
            }
#endif

#if CLIENT
            GameMain.NilModProfiler.SWMapEntityUpdate.Start();
#endif

            foreach (MapEntity e in MapEntity.mapEntityList)
            {
                e.IsHighlighted = false;
            }

#if CLIENT
            GameMain.NilModProfiler.SWMapEntityUpdate.Stop();

            if (GameMain.GameSession != null)
            {
                GameMain.NilModProfiler.SWGameSessionUpdate.Start();
                GameMain.GameSession.Update((float)deltaTime);
                GameMain.NilModProfiler.RecordGameSessionUpdate();
            }

            GameMain.NilModProfiler.SWParticleManager.Start();

            GameMain.ParticleManager.Update((float)deltaTime);

            GameMain.NilModProfiler.RecordParticleManager();
            GameMain.NilModProfiler.SWLightManager.Start();

            GameMain.LightManager.Update((float)deltaTime);

            GameMain.NilModProfiler.RecordLightManager();
#endif

            if (Level.Loaded != null)
            {
#if CLIENT
                GameMain.NilModProfiler.SWLevelUpdate.Start();
#endif
                Level.Loaded.Update((float)deltaTime, cam);
#if CLIENT
                GameMain.NilModProfiler.RecordLevelUpdate();
#endif
            }

#if CLIENT
            if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null && Character.Controlled.CanInteractWith(Character.Controlled.SelectedConstruction))
            {
                Character.Controlled.SelectedConstruction.UpdateHUD(cam, Character.Controlled);
            }
            GameMain.NilModProfiler.SWCharacterUpdate.Start();
#endif

            Character.UpdateAll((float)deltaTime, cam);

#if CLIENT
            //NilMod spy Code
            if (Character.Spied != null)
            {
                Character.ViewSpied((float)deltaTime, Cam, true);
                Lights.LightManager.ViewTarget = Character.Spied;
                CharacterHUD.Update((float)deltaTime, Character.Spied);

                foreach (HUDProgressBar progressBar in Character.Spied.HUDProgressBars.Values)
                {
                    progressBar.Update((float)deltaTime);
                }

                foreach (var pb in Character.Spied.HUDProgressBars)
                {
                    if (pb.Value.FadeTimer <= 0.0f)
                    {
                        Character.Spied.HUDProgressBars.Remove(pb.Key);
                    }
                }
            }

            GameMain.NilModProfiler.SWCharacterUpdate.Stop();
            GameMain.NilModProfiler.RecordCharacterUpdate();
            GameMain.NilModProfiler.SWStatusEffect.Start();
#endif
            StatusEffect.UpdateAll((float)deltaTime);

#if CLIENT
            GameMain.NilModProfiler.RecordStatusEffect();
            if ((Character.Controlled != null && Lights.LightManager.ViewTarget != null) || (Character.Spied != null && Lights.LightManager.ViewTarget != null))
            {
                cam.TargetPos = Lights.LightManager.ViewTarget.WorldPosition;
            }
#endif

            cam.MoveCamera((float)deltaTime);
#if CLIENT
            GameMain.NilModProfiler.SWSetTransforms.Start();
#endif
            foreach (Submarine sub in Submarine.Loaded)
            {
                sub.SetPrevTransform(sub.Position);
            }

            foreach (PhysicsBody pb in PhysicsBody.List)
            {
                pb.SetPrevTransform(pb.SimPosition, pb.Rotation);
            }
#if CLIENT
            GameMain.NilModProfiler.RecordSetTransforms();
            GameMain.NilModProfiler.SWMapEntityUpdate.Start();
#endif
            MapEntity.UpdateAll((float)deltaTime, cam);
#if CLIENT
            GameMain.NilModProfiler.RecordMapEntityUpdate();
            GameMain.NilModProfiler.SWCharacterAnimUpdate.Start();
#endif
            Character.UpdateAnimAll((float)deltaTime);
#if CLIENT
            GameMain.NilModProfiler.RecordCharacterAnimUpdate();
            GameMain.NilModProfiler.SWRagdollUpdate.Start();
#endif
            Ragdoll.UpdateAll((float)deltaTime, cam);
#if CLIENT
            GameMain.NilModProfiler.RecordRagdollUpdate();
            GameMain.NilModProfiler.SWSubmarineUpdate.Start();
#endif
            foreach (Submarine sub in Submarine.Loaded)
            {
                sub.Update((float)deltaTime);
            }

#if CLIENT
            GameMain.NilModProfiler.RecordSubmarineUpdate();
            GameMain.NilModProfiler.SWCharacterUpdate.Start();
#endif

#if CLIENT
            GameMain.NilModProfiler.RecordCharacterUpdate();
            GameMain.NilModProfiler.SWPhysicsWorldStep.Start();
#endif
            GameMain.World.Step((float)deltaTime);
#if CLIENT
            GameMain.NilModProfiler.RecordPhysicsWorldStep();

            if (!PlayerInput.LeftButtonHeld())
            {
                Inventory.draggingSlot = null;
                Inventory.draggingItem = null;
            }
#endif
        }
Example #26
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;
        }
Example #27
0
        public void Update(float deltaTime, GUICustomComponent mapContainer)
        {
            Rectangle rect = mapContainer.Rect;

            subReticlePosition  = Vector2.Lerp(subReticlePosition, CurrentLocation.MapPosition, deltaTime);
            subReticleAnimState = 0.8f - Vector2.Distance(subReticlePosition, CurrentLocation.MapPosition) / 50.0f;
            subReticleAnimState = MathHelper.Clamp(subReticleAnimState + (float)Math.Sin(Timing.TotalTime * 3.5f) * 0.2f, 0.0f, 1.0f);

            targetReticleAnimState = SelectedLocation == null?
                                     Math.Max(targetReticleAnimState - deltaTime, 0.0f) :
                                         Math.Min(targetReticleAnimState + deltaTime, 0.6f + (float)Math.Sin(Timing.TotalTime * 2.5f) * 0.4f);

#if DEBUG
            if (GameMain.DebugDraw)
            {
                if (editor == null)
                {
                    CreateEditor();
                }
                editor.AddToGUIUpdateList(order: 1);
            }
#endif

            if (mapAnimQueue.Count > 0)
            {
                hudOpenState = Math.Max(hudOpenState - deltaTime, 0.0f);
                UpdateMapAnim(mapAnimQueue.Peek(), deltaTime);
                if (mapAnimQueue.Peek().Finished)
                {
                    mapAnimQueue.Dequeue();
                }
                return;
            }

            hudOpenState = Math.Min(hudOpenState + deltaTime, 0.75f + (float)Math.Sin(Timing.TotalTime * 3.0f) * 0.25f);

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

            float closestDist = 0.0f;
            highlightedLocation = null;
            if (GUI.MouseOn == null || GUI.MouseOn == mapContainer)
            {
                for (int i = 0; i < Locations.Count; i++)
                {
                    Location location = Locations[i];
                    Vector2  pos      = rectCenter + (location.MapPosition + drawOffset) * zoom;

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

                    float iconScale = MapGenerationParams.Instance.LocationIconSize / location.Type.Sprite.size.X;

                    Rectangle drawRect = location.Type.Sprite.SourceRect;
                    drawRect.Width  = (int)(drawRect.Width * iconScale * zoom * 1.4f);
                    drawRect.Height = (int)(drawRect.Height * iconScale * zoom * 1.4f);
                    drawRect.X      = (int)pos.X - drawRect.Width / 2;
                    drawRect.Y      = (int)pos.Y - drawRect.Width / 2;

                    if (!drawRect.Contains(PlayerInput.MousePosition))
                    {
                        continue;
                    }

                    float dist = Vector2.Distance(PlayerInput.MousePosition, pos);
                    if (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)
                    {
                        //clients aren't allowed to select the location without a permission
                        if (GameMain.Client == null || GameMain.Client.HasPermission(Networking.ClientPermissions.ManageCampaign))
                        {
                            SelectedConnection     = connection;
                            SelectedLocation       = highlightedLocation;
                            targetReticleAnimState = 0.0f;

                            OnLocationSelected?.Invoke(SelectedLocation, SelectedConnection);
                            GameMain.Client?.SendCampaignState();
                        }
                    }
                }
            }

            if (GUI.KeyboardDispatcher.Subscriber == null)
            {
                float   moveSpeed  = 1000.0f;
                Vector2 moveAmount = Vector2.Zero;
                if (PlayerInput.KeyDown(InputType.Left))
                {
                    moveAmount += Vector2.UnitX;
                }
                if (PlayerInput.KeyDown(InputType.Right))
                {
                    moveAmount -= Vector2.UnitX;
                }
                if (PlayerInput.KeyDown(InputType.Up))
                {
                    moveAmount += Vector2.UnitY;
                }
                if (PlayerInput.KeyDown(InputType.Down))
                {
                    moveAmount -= Vector2.UnitY;
                }
                drawOffset += moveAmount * moveSpeed / zoom * deltaTime;
            }

            if (GUI.MouseOn == mapContainer)
            {
                zoom += PlayerInput.ScrollWheelSpeed / 1000.0f;
                zoom  = MathHelper.Clamp(zoom, 1.0f, 4.0f);

                if (PlayerInput.MidButtonHeld() || (highlightedLocation == null && PlayerInput.LeftButtonHeld()))
                {
                    drawOffset += PlayerInput.MouseSpeed / zoom;
                }
#if DEBUG
                if (PlayerInput.DoubleClicked() && highlightedLocation != null)
                {
                    var passedConnection = CurrentLocation.Connections.Find(c => c.OtherLocation(CurrentLocation) == highlightedLocation);
                    if (passedConnection != null)
                    {
                        passedConnection.Passed = true;
                    }

                    Location prevLocation = CurrentLocation;
                    CurrentLocation            = highlightedLocation;
                    CurrentLocation.Discovered = true;
                    OnLocationChanged?.Invoke(prevLocation, CurrentLocation);
                    SelectLocation(-1);
                    ProgressWorld();
                }
#endif
            }
        }
Example #28
0
        protected override void Update(float deltaTime)
        {
            if (!Visible)
            {
                return;
            }

            if (flashTimer > 0.0f)
            {
                flashTimer -= deltaTime;
            }
            if (!Enabled)
            {
                return;
            }
            if (MouseRect.Contains(PlayerInput.MousePosition) && (GUI.MouseOn == null || GUI.IsMouseOn(this)))
            {
                state = ComponentState.Hover;
                if (PlayerInput.LeftButtonDown())
                {
                    Select();
                }
                else
                {
                    isSelecting = PlayerInput.LeftButtonHeld();
                }
                if (PlayerInput.DoubleClicked())
                {
                    SelectAll();
                }
                if (isSelecting)
                {
                    if (!MathUtils.NearlyEqual(PlayerInput.MouseSpeed.X, 0))
                    {
                        CaretIndex = GetCaretIndexFromScreenPos(PlayerInput.MousePosition);
                        CalculateCaretPos();
                        CalculateSelection();
                    }
                }
            }
            else
            {
                if (PlayerInput.LeftButtonClicked() && selected)
                {
                    Deselect();
                }
                isSelecting = false;
                state       = ComponentState.None;
            }
            if (!isSelecting)
            {
                isSelecting = PlayerInput.KeyDown(Keys.LeftShift) || PlayerInput.KeyDown(Keys.RightShift);
            }

            if (CaretEnabled)
            {
                if (textBlock.OverflowClipActive)
                {
                    if (CaretScreenPos.X < Rect.X + textBlock.Padding.X)
                    {
                        textBlock.TextPos = new Vector2(textBlock.TextPos.X + ((Rect.X + textBlock.Padding.X) - CaretScreenPos.X), textBlock.TextPos.Y);
                        CalculateCaretPos();
                    }
                    else if (CaretScreenPos.X > Rect.Right - textBlock.Padding.Z)
                    {
                        textBlock.TextPos = new Vector2(textBlock.TextPos.X - (CaretScreenPos.X - (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;
        }
Example #29
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);

            float strongestFlow = 0.0f;

            foreach (Gap gap in ConnectedGaps)
            {
                if (gap.IsRoomToRoom)
                {
                    //only the first linked hull plays the flow sound
                    if (gap.linkedTo[1] == this)
                    {
                        continue;
                    }
                }

                float gapFlow = gap.LerpedFlowForce.Length();

                if (gapFlow > strongestFlow)
                {
                    strongestFlow = gapFlow;
                }
            }

            if (strongestFlow > 1.0f)
            {
                soundVolume = soundVolume + ((strongestFlow < 100.0f) ? -deltaTime * 0.5f : deltaTime * 0.5f);
                soundVolume = MathHelper.Clamp(soundVolume, 0.0f, 1.0f);

                int index = (int)Math.Floor(MathHelper.Lerp(0, SoundPlayer.FlowSounds.Count - 1, strongestFlow / 600.0f));
                index = Math.Min(index, SoundPlayer.FlowSounds.Count - 1);

                var flowSound = SoundPlayer.FlowSounds[index];
                if (flowSound != currentFlowSound && soundIndex > -1)
                {
                    Sounds.SoundManager.Stop(soundIndex);
                    currentFlowSound = null;
                    soundIndex       = -1;
                }

                currentFlowSound = flowSound;
                soundIndex       = currentFlowSound.Loop(soundIndex, soundVolume, WorldPosition, Math.Min(strongestFlow * 5.0f, 2000.0f));
            }
            else
            {
                if (soundIndex > -1)
                {
                    Sounds.SoundManager.Stop(soundIndex);
                    currentFlowSound = null;
                    soundIndex       = -1;
                }
            }

            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);
                }
            }
        }
Example #30
0
        protected void UpdateSlot(InventorySlot slot, int slotIndex, Item item, bool isSubSlot)
        {
            Rectangle interactRect = slot.InteractRect;

            interactRect.Location += slot.DrawOffset.ToPoint();

            bool mouseOnGUI = false;

            /*if (GUI.MouseOn != null)
             * {
             *  //block usage if the mouse is on a GUIComponent that's not related to this inventory
             *  if (RectTransform == null || (RectTransform != GUI.MouseOn.RectTransform && !GUI.MouseOn.IsParentOf(RectTransform.GUIComponent)))
             *  {
             *      mouseOnGUI = true;
             *  }
             * }*/

            bool mouseOn = interactRect.Contains(PlayerInput.MousePosition) && !Locked && !mouseOnGUI;

            if (PlayerInput.LeftButtonHeld() && PlayerInput.RightButtonHeld())
            {
                mouseOn = false;
            }

            if (selectedSlot != null && selectedSlot.Slot != slot)
            {
                //subinventory slot highlighted -> don't allow highlighting this one
                if (selectedSlot.IsSubSlot && !isSubSlot)
                {
                    mouseOn = false;
                }
                else if (!selectedSlot.IsSubSlot && isSubSlot && mouseOn)
                {
                    selectedSlot = null;
                }
            }


            slot.State = GUIComponent.ComponentState.None;

            if (mouseOn && (draggingItem != null || selectedSlot == null || selectedSlot.Slot == slot))
            // &&
            //(highlightedSubInventories.Count == 0 || highlightedSubInventories.Contains(this) || highlightedSubInventorySlot?.Slot == slot || highlightedSubInventory.Owner == item))
            {
                slot.State = GUIComponent.ComponentState.Hover;

                if (selectedSlot == null || (!selectedSlot.IsSubSlot && isSubSlot))
                {
                    selectedSlot = new SlotReference(this, slot, slotIndex, isSubSlot, Items[slotIndex]?.GetComponent <ItemContainer>()?.Inventory);
                }

                if (draggingItem == null)
                {
                    if (PlayerInput.LeftButtonDown())
                    {
                        draggingItem = Items[slotIndex];
                        draggingSlot = slot;
                    }
                }
                else if (PlayerInput.LeftButtonReleased())
                {
                    if (PlayerInput.DoubleClicked())
                    {
                        doubleClickedItem = item;
                    }
                }
            }
        }