Example #1
0
        public static void AlterReference(PlayerAction_Build __instance)
        {
            if (referenceSelectionGizmo == null)
            {
                referenceSelectionGizmo                 = BoxGizmo.Create(Vector3.zero, Quaternion.identity, Vector3.zero, new Vector3(0.5f, 100f, 0.5f));
                referenceSelectionGizmo.multiplier      = 1f;
                referenceSelectionGizmo.alphaMultiplier = 0.5f;
                referenceSelectionGizmo.fadeInScale     = referenceSelectionGizmo.fadeOutScale = 1.3f;
                referenceSelectionGizmo.fadeInTime      = referenceSelectionGizmo.fadeOutTime = 0.05f;
                referenceSelectionGizmo.fadeInFalloff   = referenceSelectionGizmo.fadeOutFalloff = 0.5f;
                referenceSelectionGizmo.color           = Color.cyan;
            }

            if (areaSelectionGizmo != null)
            {
                areaSelectionGizmo.Close();
                areaSelectionGizmo = null;
            }

            bool isValidReference = false;

            if (__instance.castObjId != 0 && __instance.castObjId != referenceId && bpSelection.TryGetValue(__instance.castObjId, out BoxGizmo reference))
            {
                var       entityData = __instance.factory.entityPool[__instance.castObjId];
                ItemProto itemProto  = LDB.items.Select((int)entityData.protoId);
                if (__instance.castObjId == entityData.id &&
                    !itemProto.prefabDesc.isInserter &&
                    !itemProto.prefabDesc.isBelt &&
                    itemProto.prefabDesc.minerType == EMinerType.None)
                {
                    referenceSelectionGizmo.transform.position = reference.transform.position;
                    referenceSelectionGizmo.transform.rotation = reference.transform.rotation;
                    referenceSelectionGizmo.center             = reference.center;

                    isValidReference = true;
                }
            }


            if (isValidReference)
            {
                referenceSelectionGizmo.Open();
            }
            else
            {
                referenceSelectionGizmo.Close();
                referenceSelectionGizmo = null;
            }

            if (VFInput._buildConfirm.pressing && isValidReference)
            {
                referenceId = __instance.castObjId;

                referenceGizmo.transform.position = referenceSelectionGizmo.transform.position;
                referenceGizmo.transform.rotation = referenceSelectionGizmo.transform.rotation;
                referenceGizmo.center             = referenceSelectionGizmo.center;
            }
        }
Example #2
0
        internal void OnDestroy()
        {
            harmony.UnpatchSelf();

            if (circleGizmo != null)
            {
                circleGizmo.Close();
                circleGizmo = null;
            }
            // For ScriptEngine hot-reloading
            foreach (var tooltip in tooltips.Values)
            {
                allTips.Remove(tooltip);
            }
        }
Example #3
0
        public static void EndBpMode(bool ignoreBlueprint = false)
        {
            if (!bpMode)
            {
                return;
            }
            bpMode = false;


            BlueprintManager.CopyEntities(bpSelection.Keys.ToList());
            foreach (var selectionGizmo in bpSelection.Values)
            {
                selectionGizmo.Close();
            }


            bpSelection.Clear();
            if (circleGizmo != null)
            {
                circleGizmo.Close();
                circleGizmo = null;
            }

            if (BlueprintManager.hasData && !ignoreBlueprint)
            {
                BlueprintManager.EnterBuildModeAfterBp();
            }

            GC.Collect();
        }
Example #4
0
        public static void GameTick(PlayerAction_Build __instance)
        {
            if (VFInput.shift && __instance.controller.cmd.mode == 0)
            {
                if (circleGizmo == null)
                {
                    circleGizmo = CircleGizmo.Create(1, __instance.groundTestPos, 10);

                    circleGizmo.fadeOutScale = circleGizmo.fadeInScale = 1.8f;
                    circleGizmo.fadeOutTime  = circleGizmo.fadeInTime = 0.15f;
                    circleGizmo.color        = COPY_GIZMO_COLOR;
                    circleGizmo.autoRefresh  = true;
                    circleGizmo.Open();
                }

                circleGizmo.position = __instance.groundTestPos;
                circleGizmo.radius   = 1.2f * 10;

                if (VFInput._buildConfirm.onDown)
                {
                    copiedAssemblers.Clear();
                    copiedInserters.Clear();
                    int found = __instance.nearcdLogic.GetBuildingsInAreaNonAlloc(__instance.groundTestPos, 10, _nearObjectIds);

                    AssemblerCopy firstItem = null;
                    for (int i = 0; i < found; i++)
                    {
                        var sourceEntityId = _nearObjectIds[i];
                        var sourceEntity   = __instance.factory.entityPool[sourceEntityId];
                        var sourcePos      = sourceEntity.pos;
                        var sourceRot      = sourceEntity.rot;

                        var sourceEntityProto = LDB.items.Select(sourceEntity.protoId);

                        if (sourceEntityProto.prefabDesc.insertPoses.Length == 0)
                        {
                            continue;
                        }

                        var assemblerCopy = new AssemblerCopy()
                        {
                            itemProto      = sourceEntityProto,
                            originalEntity = sourceEntity,
                            originalPos    = sourcePos,
                            originalRot    = sourceRot
                        };

                        if (!sourceEntityProto.prefabDesc.isAssembler)
                        {
                            assemblerCopy.recipeId = __instance.factory.factorySystem.assemblerPool[sourceEntity.assemblerId].recipeId;
                        }

                        if (firstItem == null)
                        {
                            firstItem = assemblerCopy;
                        }
                        else
                        {
                            var inverseRot = Quaternion.Inverse(firstItem.originalRot);

                            assemblerCopy.cursorRelativePos = inverseRot * (assemblerCopy.originalPos - firstItem.originalPos);
                            int       path              = 0;
                            Vector3[] snaps             = new Vector3[1000];
                            var       snappedPointCount = __instance.planetAux.SnapLineNonAlloc(firstItem.originalPos, assemblerCopy.originalPos, ref path, snaps);
                            Vector3   lastSnap          = firstItem.originalPos;
                            Vector3[] snapMoves         = new Vector3[snappedPointCount];
                            for (int s = 0; s < snappedPointCount; s++)
                            {
                                // note: reverse rotation of the delta so that rotation works
                                Vector3 snapMove = inverseRot * (snaps[s] - lastSnap);
                                snapMoves[s] = snapMove;
                                lastSnap     = snaps[s];
                            }

                            assemblerCopy.snapCount = snappedPointCount;
                            assemblerCopy.snapMoves = snapMoves;
                            //assemblerCopy.cursorRelativeRot = Quaternion.Inverse(firstItem.originalRot) * assemblerCopy.originalRot;
                        }

                        copiedAssemblers.Add(sourceEntityId, assemblerCopy);
                    }

                    if (copiedAssemblers.Count > 0)
                    {
                        __instance.player.SetHandItems(firstItem.itemProto.ID, 0, 0);
                        __instance.controller.cmd.type = ECommand.Build;
                        __instance.controller.cmd.mode = 1;
                    }
                }
            }
            else
            {
                if (circleGizmo != null)
                {
                    circleGizmo.Close();
                    circleGizmo = null;
                }
            }
        }