Esempio n. 1
0
 private void OnCrayonDropped(EntityUid uid, CrayonComponent component, DroppedEvent args)
 {
     if (TryComp <ActorComponent>(args.User, out var actor))
     {
         component.UserInterface?.Close(actor.PlayerSession);
     }
 }
    private void OnCrayonInit(EntityUid uid, CrayonComponent component, ComponentInit args)
    {
        component.Charges = component.Capacity;

        // Get the first one from the catalog and set it as default
        var decal = _prototypeManager.EnumeratePrototypes<DecalPrototype>().FirstOrDefault(x => x.Tags.Contains("crayon"));
        component.SelectedState = decal?.ID ?? string.Empty;
        Dirty(component);
    }
    private void OnCrayonBoundUI(EntityUid uid, CrayonComponent component, CrayonSelectMessage args)
    {
        // Check if the selected state is valid
        if (!_prototypeManager.TryIndex<DecalPrototype>(args.State, out var prototype) || !prototype.Tags.Contains("crayon")) return;

        component.SelectedState = args.State;

        Dirty(component);
    }
Esempio n. 4
0
        public StatusControl(CrayonComponent parent)
        {
            _parent = parent;
            _label  = new RichTextLabel {
                StyleClasses = { StyleNano.StyleClassItemStatus }
            };
            AddChild(_label);

            parent.UIUpdateNeeded = true;
        }
    private void OnCrayonBoundUIColor(EntityUid uid, CrayonComponent component, CrayonColorMessage args)
    {
        // you still need to ensure that the given color is a valid color
        if (component.SelectableColor && args.Color != component.Color)
        {
            component.Color = args.Color;

            Dirty(component);
        }

    }
Esempio n. 6
0
    private static void OnCrayonHandleState(EntityUid uid, CrayonComponent component, ref ComponentHandleState args)
    {
        if (args.Current is not CrayonComponentState state)
        {
            return;
        }

        component._color        = state.Color;
        component.SelectedState = state.State;
        component.Charges       = state.Charges;
        component.Capacity      = state.Capacity;

        component.UIUpdateNeeded = true;
    }
Esempio n. 7
0
    private void OnCrayonAfterInteract(EntityUid uid, CrayonComponent component, AfterInteractEvent args)
    {
        if (args.Handled || !args.CanReach)
        {
            return;
        }

        if (component.Charges <= 0)
        {
            if (component.DeleteEmpty)
            {
                UseUpCrayon(uid, args.User);
            }
            else
            {
                _popup.PopupEntity(Loc.GetString("crayon-interact-not-enough-left-text"), uid, Filter.Entities(args.User));
            }

            args.Handled = true;
            return;
        }

        if (!args.ClickLocation.IsValid(EntityManager))
        {
            _popup.PopupEntity(Loc.GetString("crayon-interact-invalid-location"), uid, Filter.Entities(args.User));
            args.Handled = true;
            return;
        }

        if (!_decals.TryAddDecal(component.SelectedState, args.ClickLocation.Offset(new Vector2(-0.5f, -0.5f)), out _, Color.FromName(component._color), cleanable: true))
        {
            return;
        }

        if (component.UseSound != null)
        {
            SoundSystem.Play(Filter.Pvs(uid), component.UseSound.GetSound(), uid, AudioHelpers.WithVariation(0.125f));
        }

        // Decrease "Ammo"
        component.Charges--;
        Dirty(component);
        _logs.Add(LogType.CrayonDraw, LogImpact.Low, $"{EntityManager.ToPrettyString(args.User):user} drew a {component._color:color} {component.SelectedState}");
        args.Handled = true;

        if (component.DeleteEmpty && component.Charges <= 0)
        {
            UseUpCrayon(uid, args.User);
        }
    }
    private void OnCrayonUse(EntityUid uid, CrayonComponent component, UseInHandEvent args)
    {
        // Open crayon window if neccessary.
        if (args.Handled)
            return;

        if (!TryComp<ActorComponent>(args.User, out var actor)) return;

        component.UserInterface?.Toggle(actor.PlayerSession);

        if (component.UserInterface?.SessionHasOpen(actor.PlayerSession) == true)
        {
            // Tell the user interface the selected stuff
            component.UserInterface.SetState(new CrayonBoundUserInterfaceState(component.SelectedState, component.SelectableColor, component.Color));
        }

        args.Handled = true;
    }
Esempio n. 9
0
 private static void OnCrayonItemStatus(EntityUid uid, CrayonComponent component, ItemStatusCollectMessage args)
 {
     args.Controls.Add(new StatusControl(component));
 }
Esempio n. 10
0
 private static void OnCrayonGetState(EntityUid uid, CrayonComponent component, ref ComponentGetState args)
 {
     args.State = new CrayonComponentState(component._color, component.SelectedState, component.Charges, component.Capacity);
 }