示例#1
0
    private void OnPlaceDecalAction(PlaceDecalActionEvent args)
    {
        if (args.Handled)
        {
            return;
        }

        if (!_mapMan.TryFindGridAt(args.Target, out var grid))
        {
            return;
        }

        args.Handled = true;

        var coords = EntityCoordinates.FromMap(grid.GridEntityId, args.Target, EntityManager);

        if (args.Snap)
        {
            var newPos = new Vector2(
                (float)(MathF.Round(coords.X - 0.5f, MidpointRounding.AwayFromZero) + 0.5),
                (float)(MathF.Round(coords.Y - 0.5f, MidpointRounding.AwayFromZero) + 0.5)
                );
            coords = coords.WithPosition(newPos);
        }

        coords = coords.Offset(new Vector2(-0.5f, -0.5f));

        var decal = new Decal(coords.Position, args.DecalId, args.Color, Angle.FromDegrees(args.Rotation), args.ZIndex, args.Cleanable);

        RaiseNetworkEvent(new RequestDecalPlacementEvent(decal, coords));
    }
示例#2
0
    private void OnFillSlot(FillActionSlotEvent ev)
    {
        if (!_active || _placing)
        {
            return;
        }

        if (ev.Action != null)
        {
            return;
        }

        if (_decalId == null || !_protoMan.TryIndex <DecalPrototype>(_decalId, out var decalProto))
        {
            return;
        }

        var actionEvent = new PlaceDecalActionEvent()
        {
            DecalId   = _decalId,
            Color     = _decalColor,
            Rotation  = _decalAngle.Degrees,
            Snap      = _snap,
            ZIndex    = _zIndex,
            Cleanable = _cleanable,
        };

        ev.Action = new WorldTargetAction()
        {
            Name             = $"{_decalId} ({_decalColor.ToHex()}, {(int) _decalAngle.Degrees})", // non-unique actions may be considered duplicates when saving/loading.
            Icon             = decalProto.Sprite,
            Repeat           = true,
            CheckCanAccess   = false,
            CheckCanInteract = false,
            Range            = -1,
            Event            = actionEvent,
            IconColor        = _decalColor,
        };
    }