Beispiel #1
0
        /// <inheritdoc />
        public bool Insert(IEntity toinsert)
        {
            DebugTools.Assert(!Deleted);

            //Verify we can insert and that the object got properly removed from its current location
            if (!CanInsert(toinsert))
            {
                return(false);
            }

            var transform = toinsert.Transform;

            if (transform.Parent == null) // Only true if Parent is the map entity
            {
                return(false);
            }

            if (ContainerHelpers.TryGetContainerMan(transform.Parent.Owner, out var containerManager) && !containerManager.Remove(toinsert))
            {
                // Can't remove from existing container, can't insert.
                return(false);
            }
            InternalInsert(toinsert);
            transform.AttachParent(Owner.Transform);

            // spatially move the object to the location of the container. If you don't want this functionality, the
            // calling code can save the local position before calling this function, and apply it afterwords.
            transform.LocalPosition = Vector2.Zero;

            return(true);
        }
        private async void MidiFileButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
        {
            var filters  = new FileDialogFilters(new FileDialogFilters.Group("mid", "midi"));
            var filename = await _fileDialogManager.OpenFile(filters);

            var instrumentEnt = _owner.Instrument.Owner;
            var instrument    = _owner.Instrument;

            ContainerHelpers.TryGetContainerMan(_owner.Instrument.Owner, out var conMan);

            var localPlayer = IoCManager.Resolve <IPlayerManager>().LocalPlayer;

            // The following checks are only in place to prevent players from playing MIDI songs locally.
            // There are equivalents for these checks on the server.

            if (string.IsNullOrEmpty(filename))
            {
                return;
            }

            // If we don't have a player or controlled entity, we return.
            if (localPlayer?.ControlledEntity == null)
            {
                return;
            }

            // If the instrument is handheld and we're not holding it, we return.
            if ((instrument.Handheld && (conMan == null ||
                                         conMan.Owner != localPlayer.ControlledEntity)))
            {
                return;
            }

            // We check that we're in range unobstructed just in case.
            if (!EntitySystem.Get <SharedInteractionSystem>()
                .InRangeUnobstructed(localPlayer.ControlledEntity.Transform.MapPosition,
                                     instrumentEnt.Transform.MapPosition, ignoredEnt: instrumentEnt))
            {
                return;
            }

            if (!_midiManager.IsMidiFile(filename))
            {
                Logger.Warning($"Not a midi file! Chosen file: {filename}");
                return;
            }

            MidiStopButtonOnPressed(null);
            await Timer.Delay(100);

            if (!_owner.Instrument.OpenMidi(filename))
            {
                return;
            }
            MidiPlaybackSetButtonsDisabled(false);
            if (midiInputButton.Pressed)
            {
                midiInputButton.Pressed = false;
            }
        }
        private bool PlayCheck()
        {
            var instrumentEnt = _owner.Instrument.Owner;
            var instrument    = _owner.Instrument;

            ContainerHelpers.TryGetContainerMan(_owner.Instrument.Owner, out var conMan);

            var localPlayer = IoCManager.Resolve <IPlayerManager>().LocalPlayer;

            // If we don't have a player or controlled entity, we return.
            if (localPlayer?.ControlledEntity == null)
            {
                return(false);
            }

            // If the instrument is handheld and we're not holding it, we return.
            if ((instrument.Handheld && (conMan == null ||
                                         conMan.Owner != localPlayer.ControlledEntity)))
            {
                return(false);
            }

            // We check that we're in range unobstructed just in case.
            return(localPlayer.InRangeUnobstructed(instrumentEnt, predicate: (e) => e == instrumentEnt || e == localPlayer.ControlledEntity));
        }