Exemplo n.º 1
0
        /// <summary>
        ///     Remove a DoAfter without showing a cancellation graphic.
        /// </summary>
        /// <param name="clientDoAfter"></param>
        public void Remove(DoAfterComponent component, ClientDoAfter clientDoAfter)
        {
            component.DoAfters.Remove(clientDoAfter.ID);

            var found = false;

            for (var i = component.CancelledDoAfters.Count - 1; i >= 0; i--)
            {
                var cancelled = component.CancelledDoAfters[i];

                if (cancelled.Message == clientDoAfter)
                {
                    component.CancelledDoAfters.RemoveAt(i);
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                component.DoAfters.Remove(clientDoAfter.ID);
            }

            component.Gui?.RemoveDoAfter(clientDoAfter.ID);
        }
Exemplo n.º 2
0
        private void OnDoAfterHandleState(EntityUid uid, DoAfterComponent component, ref ComponentHandleState args)
        {
            if (args.Current is not DoAfterComponentState state)
            {
                return;
            }

            var toRemove = new RemQueue <ClientDoAfter>();

            foreach (var(id, doAfter) in component.DoAfters)
            {
                var found = false;

                foreach (var clientdoAfter in state.DoAfters)
                {
                    if (clientdoAfter.ID == id)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    toRemove.Add(doAfter);
                }
            }

            foreach (var doAfter in toRemove)
            {
                Remove(component, doAfter);
            }

            foreach (var doAfter in state.DoAfters)
            {
                if (component.DoAfters.ContainsKey(doAfter.ID))
                {
                    continue;
                }

                component.DoAfters.Add(doAfter.ID, doAfter);
            }

            if (component.Gui == null || component.Gui.Disposed)
            {
                return;
            }

            foreach (var(_, doAfter) in component.DoAfters)
            {
                component.Gui.AddDoAfter(doAfter);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Mark a DoAfter as cancelled and show a cancellation graphic.
        /// </summary>
        ///     Actual removal is handled by DoAfterEntitySystem.
        /// <param name="id"></param>
        /// <param name="currentTime"></param>
        public void Cancel(DoAfterComponent component, byte id, TimeSpan?currentTime = null)
        {
            foreach (var(_, cancelled) in component.CancelledDoAfters)
            {
                if (cancelled.ID == id)
                {
                    return;
                }
            }

            if (!component.DoAfters.ContainsKey(id))
            {
                return;
            }

            var doAfterMessage = component.DoAfters[id];

            component.CancelledDoAfters.Add((_gameTiming.CurTime, doAfterMessage));
            component.Gui?.CancelDoAfter(id);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     For handling PVS so we dispose of controls if they go out of range
        /// </summary>
        public void Enable(DoAfterComponent component)
        {
            if (component.Gui?.Disposed == false)
            {
                return;
            }

            component.Gui = new DoAfterGui {
                AttachedEntity = component.Owner
            };

            foreach (var(_, doAfter) in component.DoAfters)
            {
                component.Gui.AddDoAfter(doAfter);
            }

            foreach (var(_, cancelled) in component.CancelledDoAfters)
            {
                component.Gui.CancelDoAfter(cancelled.ID);
            }
        }
Exemplo n.º 5
0
 public void Disable(DoAfterComponent component)
 {
     component.Gui?.Dispose();
     component.Gui = null;
 }
Exemplo n.º 6
0
 private void OnDoAfterShutdown(EntityUid uid, DoAfterComponent component, ComponentShutdown args)
 {
     Disable(component);
 }
Exemplo n.º 7
0
 private void OnDoAfterStartup(EntityUid uid, DoAfterComponent component, ComponentStartup args)
 {
     Enable(component);
 }