Exemplo n.º 1
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;
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
0
        private bool SelectBar()
        {
            if (!enabled || !PlayerInput.LeftButtonDown())
            {
                return(false);
            }
            if (barSize >= 1.0f)
            {
                return(false);
            }

            draggingBar = this;

            return(true);
        }
Exemplo n.º 4
0
        partial void UpdateProjSpecific(float deltaTime)
        {
            if (GUI.DisableHUD)
            {
                return;
            }

            if (PlayerInput.KeyDown(InputType.InfoTab) &&
                (GUI.KeyboardDispatcher.Subscriber == null || GUI.KeyboardDispatcher.Subscriber is GUIListBox))
            {
                if (infoFrame == null)
                {
                    ToggleInfoFrame();
                }
            }
            else if (infoFrame != null)
            {
                ToggleInfoFrame();
            }

            if (GameMain.NetworkMember != null)
            {
                if (GameMain.NetLobbyScreen?.HeadSelectionList != null)
                {
                    if (PlayerInput.LeftButtonDown() && !GUI.IsMouseOn(GameMain.NetLobbyScreen.HeadSelectionList))
                    {
                        if (GameMain.NetLobbyScreen.HeadSelectionList != null)
                        {
                            GameMain.NetLobbyScreen.HeadSelectionList.Visible = false;
                        }
                    }
                }
                if (GameMain.NetLobbyScreen?.JobSelectionFrame != null)
                {
                    if (PlayerInput.LeftButtonDown() && !GUI.IsMouseOn(GameMain.NetLobbyScreen.JobSelectionFrame))
                    {
                        GameMain.NetLobbyScreen.JobList.Deselect();
                        if (GameMain.NetLobbyScreen.JobSelectionFrame != null)
                        {
                            GameMain.NetLobbyScreen.JobSelectionFrame.Visible = false;
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public static bool CloseHUD(Rectangle rect)
        {
            //don't close when the cursor is on a UI element
            if (GUI.MouseOn != null)
            {
                return(false);
            }

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

            bool input = PlayerInput.LeftButtonDown() || PlayerInput.RightButtonClicked();

            return(input && !rect.Contains(PlayerInput.MousePosition));
        }
Exemplo n.º 6
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);
 }
        public static bool CloseHUD(Rectangle rect)
        {
            // Always close when hitting escape
            if (PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                return(true);
            }

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

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

            bool input = PlayerInput.LeftButtonDown() || PlayerInput.RightButtonClicked();

            return(input && !rect.Contains(PlayerInput.MousePosition));
        }
Exemplo n.º 8
0
        private void DrawSplashScreen(SpriteBatch spriteBatch)
        {
            if (videoPlayer == null)
            {
                videoPlayer = new VideoPlayer();
                videoPlayer.Play(splashScreenVideo);
                videoPlayer.Volume = GameMain.Config.SoundVolume;
            }
            else
            {
                Texture2D videoTexture = null;

                if (videoPlayer.State == MediaState.Stopped)
                {
                    videoPlayer.Dispose();
                    videoPlayer = null;

                    splashScreenVideo.Dispose();
                    splashScreenVideo = null;
                }
                else
                {
                    videoTexture = videoPlayer.GetTexture();

                    spriteBatch.Begin();
                    spriteBatch.Draw(videoTexture, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
                    spriteBatch.End();

                    if (PlayerInput.KeyHit(Keys.Space) || PlayerInput.KeyHit(Keys.Enter) || PlayerInput.LeftButtonDown())
                    {
                        videoPlayer.Stop();
                    }
                }
            }
        }
Exemplo n.º 9
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;
                    }
                }
            }
        }
Exemplo n.º 10
0
        private void UpdateResizing(Camera cam)
        {
            isHighlighted = true;

            int startX = ResizeHorizontal ? -1 : 0;
            int StartY = ResizeVertical ? -1 : 0;

            for (int x = startX; x < 2; x += 2)
            {
                for (int y = StartY; y < 2; y += 2)
                {
                    Vector2 handlePos = cam.WorldToScreen(Position + new Vector2(x * (rect.Width * 0.5f + 5), y * (rect.Height * 0.5f + 5)));

                    bool highlighted = Vector2.Distance(PlayerInput.MousePosition, handlePos) < 5.0f;

                    if (highlighted && PlayerInput.LeftButtonDown())
                    {
                        selectionPos = Vector2.Zero;
                        resizeDirX   = x;
                        resizeDirY   = y;
                        resizing     = true;
                    }
                }
            }

            if (resizing)
            {
                if (rectMemento == null)
                {
                    rectMemento = new Memento <Rectangle>();
                    rectMemento.Store(Rect);
                }

                Vector2 placePosition = new Vector2(rect.X, rect.Y);
                Vector2 placeSize     = new Vector2(rect.Width, rect.Height);

                Vector2 mousePos = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);

                if (resizeDirX > 0)
                {
                    mousePos.X  = Math.Max(mousePos.X, rect.X + Submarine.GridSize.X);
                    placeSize.X = mousePos.X - placePosition.X;
                }
                else if (resizeDirX < 0)
                {
                    mousePos.X = Math.Min(mousePos.X, rect.Right - Submarine.GridSize.X);

                    placeSize.X     = (placePosition.X + placeSize.X) - mousePos.X;
                    placePosition.X = mousePos.X;
                }
                if (resizeDirY < 0)
                {
                    mousePos.Y  = Math.Min(mousePos.Y, rect.Y - Submarine.GridSize.Y);
                    placeSize.Y = placePosition.Y - mousePos.Y;
                }
                else if (resizeDirY > 0)
                {
                    mousePos.Y = Math.Max(mousePos.Y, rect.Y - rect.Height + Submarine.GridSize.X);

                    placeSize.Y     = mousePos.Y - (rect.Y - rect.Height);
                    placePosition.Y = mousePos.Y;
                }

                if ((int)placePosition.X != rect.X || (int)placePosition.Y != rect.Y || (int)placeSize.X != rect.Width || (int)placeSize.Y != rect.Height)
                {
                    Rect = new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y);
                }

                if (!PlayerInput.LeftButtonHeld())
                {
                    rectMemento.Store(Rect);
                    resizing = false;
                }
            }
        }
Exemplo n.º 11
0
        private void DrawSplashScreen(SpriteBatch spriteBatch)
        {
            if (SplashScreen != null)
            {
                if (SplashScreen.IsPlaying)
                {
                    spriteBatch.Begin();
                    spriteBatch.Draw(SplashScreen.GetTexture(), new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
                    spriteBatch.End();

                    if (PlayerInput.KeyHit(Keys.Space) || PlayerInput.KeyHit(Keys.Enter) || PlayerInput.LeftButtonDown())
                    {
                        SplashScreen.Dispose(); SplashScreen = null;
                    }
                }
                else
                {
                    SplashScreen.Dispose(); SplashScreen = null;
                }
            }
        }
Exemplo n.º 12
0
        private void UpdateChildrenRect()
        {
            //dragging
            if (CanDragElements && draggedElement != null)
            {
                if (!PlayerInput.LeftButtonHeld())
                {
                    OnRearranged?.Invoke(this, draggedElement.UserData);
                    draggedElement = null;
                    RepositionChildren();
                }
                else
                {
                    draggedElement.RectTransform.AbsoluteOffset = draggedReferenceOffset + new Point(0, (int)PlayerInput.MousePosition.Y - draggedReferenceRectangle.Center.Y);

                    int index     = Content.RectTransform.GetChildIndex(draggedElement.RectTransform);
                    int currIndex = index;

                    while (currIndex > 0 && PlayerInput.MousePosition.Y < draggedReferenceRectangle.Top)
                    {
                        currIndex--;
                        draggedReferenceRectangle.Y -= draggedReferenceRectangle.Height;
                        draggedReferenceOffset.Y    -= draggedReferenceRectangle.Height;
                    }
                    while (currIndex < Content.CountChildren - 1 && PlayerInput.MousePosition.Y > draggedReferenceRectangle.Bottom)
                    {
                        currIndex++;
                        draggedReferenceRectangle.Y += draggedReferenceRectangle.Height;
                        draggedReferenceOffset.Y    += draggedReferenceRectangle.Height;
                    }

                    if (currIndex != index)
                    {
                        draggedElement.RectTransform.RepositionChildInHierarchy(currIndex);
                    }

                    return;
                }
            }

            for (int i = 0; i < Content.CountChildren; i++)
            {
                var child = Content.RectTransform.GetChild(i)?.GUIComponent;
                if (child == null)
                {
                    continue;
                }

                // selecting
                if (Enabled && CanBeFocused && child.CanBeFocused && (GUI.IsMouseOn(child)) && child.Rect.Contains(PlayerInput.MousePosition))
                {
                    child.State = ComponentState.Hover;

                    var mouseDown = useMouseDownToSelect ? PlayerInput.PrimaryMouseButtonDown() : PlayerInput.PrimaryMouseButtonClicked();

                    if (mouseDown)
                    {
                        Select(i, autoScroll: false);
                    }

                    if (CanDragElements && PlayerInput.LeftButtonDown() && GUI.MouseOn == child)
                    {
                        draggedElement            = child;
                        draggedReferenceRectangle = child.Rect;
                        draggedReferenceOffset    = child.RectTransform.AbsoluteOffset;
                    }
                }
                else if (selected.Contains(child))
                {
                    child.State = ComponentState.Selected;

                    if (CheckSelected != null)
                    {
                        if (CheckSelected() != child.UserData)
                        {
                            selected.Remove(child);
                        }
                    }
                }
                else
                {
                    child.State = !child.ExternalHighlight ? ComponentState.None : ComponentState.Hover;
                }
            }
        }
Exemplo n.º 13
0
        private void DrawSplashScreen(SpriteBatch spriteBatch, GraphicsDevice graphics)
        {
            if (currSplashScreen == null && PendingSplashScreens.Count == 0)
            {
                return;
            }

            if (currSplashScreen == null)
            {
                var    newSplashScreen = PendingSplashScreens.Dequeue();
                string fileName        = newSplashScreen.First;
                Point  resolution      = newSplashScreen.Second;
                try
                {
                    currSplashScreen = new Video(graphics, GameMain.SoundManager, fileName, (uint)resolution.X, (uint)resolution.Y);
                    videoStartTime   = DateTime.Now;
                }
                catch (Exception e)
                {
                    GameMain.Config.EnableSplashScreen = false;
                    DebugConsole.ThrowError("Playing the splash screen \"" + fileName + "\" failed.", e);
                    PendingSplashScreens.Clear();
                    currSplashScreen = null;
                }
            }

            if (currSplashScreen.IsPlaying)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(currSplashScreen.GetTexture(), new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
                spriteBatch.End();

                if (GameMain.WindowActive && (PlayerInput.KeyHit(Keys.Space) || PlayerInput.KeyHit(Keys.Enter) || PlayerInput.LeftButtonDown()))
                {
                    currSplashScreen.Dispose(); currSplashScreen = null;
                }
            }
            else if (DateTime.Now > videoStartTime + new TimeSpan(0, 0, 0, 0, milliseconds: 500))
            {
                currSplashScreen.Dispose(); currSplashScreen = null;
            }
        }
Exemplo n.º 14
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 (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);
                }
            }

            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 (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 = "Hold to unequip";
                        if (PlayerInput.LeftButtonHeld())
                        {
                            slots[i].QuickUseTimer = Math.Max(0.1f, slots[i].QuickUseTimer + deltaTime);
                            if (slots[i].QuickUseTimer >= 1.0f)
                            {
                                CreateNetworkEvent();
                                Items[i].Drop(Character.Controlled);
                            }
                        }
                        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)
                {
                    draggingItem = null;
                }
            }

            doubleClickedItem = null;
        }
Exemplo n.º 15
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;
        }
Exemplo n.º 16
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;
        }
Exemplo n.º 17
0
        private void DrawSplashScreen(SpriteBatch spriteBatch)
        {
            bool vsync = GameMain.Config.VSyncEnabled;

            if (videoPlayer == null)
            {
                // Enforce the vsync so that the video player doesn't eat all the vram
                if (!GameMain.Config.VSyncEnabled)
                {
                    GameMain.Config.VSyncEnabled = true;
                    GameMain.Instance.ApplyGraphicsSettings();
                }
                videoPlayer = new VideoPlayer();
                videoPlayer.Play(splashScreenVideo);
                videoPlayer.Volume = GameMain.Config.SoundVolume;
            }
            else
            {
                Texture2D videoTexture = null;

                if (videoPlayer.State == MediaState.Stopped)
                {
                    videoPlayer.Dispose();
                    videoPlayer = null;

                    splashScreenVideo.Dispose();
                    splashScreenVideo = null;
                    // If the vsync was enforced, restore the user preference
                    if (GameMain.Config.VSyncEnabled != vsync)
                    {
                        GameMain.Config.VSyncEnabled = vsync;
                        GameMain.Instance.ApplyGraphicsSettings();
                    }
                }
                else
                {
                    videoTexture = videoPlayer.GetTexture();

                    spriteBatch.Begin();
                    spriteBatch.Draw(videoTexture, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
                    spriteBatch.End();

                    if (PlayerInput.KeyHit(Keys.Space) || PlayerInput.KeyHit(Keys.Enter) || PlayerInput.LeftButtonDown())
                    {
                        videoPlayer.Stop();
                    }
                }
            }
        }