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); }
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; } }
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); } } }
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; } }
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; } }
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); }
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); }
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; }
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); } } }
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; } } } }
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 (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 = "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) { //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; }
public override void Update(Camera cam, float deltaTime) { Oxygen -= OxygenDetoriationSpeed * deltaTime; if (EditWater) { Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition); if (Submarine.RectContains(WorldRect, position)) { if (PlayerInput.LeftButtonHeld()) { //waveY[GetWaveIndex(position.X - rect.X - Submarine.Position.X) / WaveWidth] = 100.0f; Volume = Volume + 1500.0f; } else if (PlayerInput.RightButtonHeld()) { Volume = Volume - 1500.0f; } } } else if (EditFire) { Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition); if (Submarine.RectContains(WorldRect, position)) { if (PlayerInput.LeftButtonClicked()) { new FireSource(position, this); } } } FireSource.UpdateAll(fireSources, deltaTime); aiTarget.SightRange = Submarine == null ? 0.0f : Math.Max(Submarine.Velocity.Length() * 500.0f, 500.0f); aiTarget.SoundRange -= deltaTime * 1000.0f; 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(strongestFlow / 100.0f); index = Math.Min(index, 2); 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; } } //update client hulls if the amount of water has changed by >10% //or if oxygen percentage has changed by 5% if (Math.Abs(lastSentVolume - volume) > FullVolume * 0.1f || Math.Abs(lastSentOxygen - OxygenPercentage) > 5f) { if (GameMain.Server != null) { sendUpdateTimer -= deltaTime; if (sendUpdateTimer < 0.0f) { GameMain.Server.CreateEntityEvent(this); lastSentVolume = volume; lastSentOxygen = OxygenPercentage; sendUpdateTimer = NetworkUpdateInterval; } } } if (!update) { lethalPressure = 0.0f; return; } float surfaceY = rect.Y - rect.Height + Volume / rect.Width; for (int i = 0; i < waveY.Length; 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); } waveY[i] = waveY[i] + waveVel[i]; if (surfaceY + waveY[i] > rect.Y) { waveY[i] -= (surfaceY + waveY[i]) - rect.Y; waveVel[i] = waveVel[i] * -0.5f; } else if (surfaceY + waveY[i] < rect.Y - rect.Height) { waveY[i] -= (surfaceY + waveY[i]) - (rect.Y - rect.Height); waveVel[i] = waveVel[i] * -0.5f; } //acceleration float a = -WaveStiffness * waveY[i] - waveVel[i] * WaveDampening; waveVel[i] = waveVel[i] + a; } for (int j = 0; j < 2; j++) { for (int i = 1; i < waveY.Length - 1; i++) { leftDelta[i] = WaveSpread * (waveY[i] - waveY[i - 1]); waveVel[i - 1] = waveVel[i - 1] + leftDelta[i]; rightDelta[i] = WaveSpread * (waveY[i] - waveY[i + 1]); waveVel[i + 1] = waveVel[i + 1] + rightDelta[i]; } for (int i = 1; i < waveY.Length - 1; i++) { waveY[i - 1] = waveY[i - 1] + leftDelta[i]; waveY[i + 1] = waveY[i + 1] + rightDelta[i]; } } //interpolate the position of the rendered surface towards the "target surface" surface = Math.Max(MathHelper.Lerp(surface, surfaceY, deltaTime * 10.0f), rect.Y - rect.Height); if (volume < FullVolume) { LethalPressure -= 10.0f * deltaTime; if (Volume == 0.0f) { //wait for the surface to be lerped back to bottom and the waves to settle until disabling update if (surface > rect.Y - rect.Height + 1) { return; } for (int i = 1; i < waveY.Length - 1; i++) { if (waveY[i] > 0.1f) { return; } } update = false; } } }