コード例 #1
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,
        };
    }
コード例 #2
0
    /// <summary>
    ///     This checks if the placement manager is currently active, and attempts to copy the placement information for
    ///     some entity or tile into an action. This is somewhat janky, but it seem to work well enough. Though I'd
    ///     prefer if it were to function more like DecalPlacementSystem.
    /// </summary>
    private void OnFillActionSlot(FillActionSlotEvent ev)
    {
        if (!_placementMan.IsActive)
        {
            return;
        }

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

        var             actionEvent = new StartPlacementActionEvent();
        ITileDefinition?tileDef     = null;

        if (_placementMan.CurrentPermission != null)
        {
            actionEvent.EntityType      = _placementMan.CurrentPermission.EntityType;
            actionEvent.PlacementOption = _placementMan.CurrentPermission.PlacementOption;

            if (_placementMan.CurrentPermission.IsTile)
            {
                tileDef            = _tileMan[_placementMan.CurrentPermission.TileType];
                actionEvent.TileId = tileDef.ID;
            }
        }
        else if (_placementMan.Eraser)
        {
            actionEvent.Eraser = true;
        }
        else
        {
            return;
        }

        if (tileDef != null)
        {
            if (tileDef is not ContentTileDefinition contentTileDef)
            {
                return;
            }

            var tileIcon = contentTileDef.IsSpace
                ? _spaceIcon
                : new SpriteSpecifier.Texture(new ResourcePath(tileDef.Path) / $"{tileDef.SpriteName}.png");

            ev.Action = new InstantAction()
            {
                CheckCanInteract = false,
                Event            = actionEvent,
                Name             = tileDef.Name,
                Icon             = tileIcon
            };

            return;
        }

        if (actionEvent.Eraser)
        {
            ev.Action = new InstantAction()
            {
                CheckCanInteract = false,
                Event            = actionEvent,
                Name             = "action-name-mapping-erase",
                Icon             = _deleteIcon,
            };

            return;
        }

        if (string.IsNullOrWhiteSpace(actionEvent.EntityType))
        {
            return;
        }

        ev.Action = new InstantAction()
        {
            CheckCanInteract = false,
            Event            = actionEvent,
            Name             = actionEvent.EntityType,
            Icon             = new SpriteSpecifier.EntityPrototype(actionEvent.EntityType),
        };
    }