Beispiel #1
0
 public static void UIBuildingGrid_Update_Postfix(ref UIBuildingGrid __instance)
 {
     if (bpMode)
     {
         __instance.material.SetColor("_TintColor", BP_GRID_COLOR);
     }
 }
Beispiel #2
0
 public static void UIBuildingGrid_Update_Postfix(ref UIBuildingGrid __instance, ref Material ___material)
 {
     if (TrarckPlugin.Instance.isBPCreate)
     {
         PlanetData    planetData    = GameMain.localPlanet;
         Player        mainPlayer    = GameMain.mainPlayer;
         PlanetFactory planetFactory = planetData?.factory;
         if (planetFactory == null || !planetData.factoryLoaded)
         {
             planetData = null;
         }
         PlanetGrid planetGrid = null;
         if (mainPlayer != null && planetData != null && planetData.aux != null && (uint)planetData.aux.activeGridIndex < (uint)planetData.aux.customGrids.Count)
         {
             planetGrid = planetData.aux.customGrids[planetData.aux.activeGridIndex];
         }
         if (planetGrid != null)
         {
             Vector4 value = Vector4.zero;
             if (TrarckPlugin.Instance.isBPCreate && TrarckPlugin.Instance.bluePrintCreateTool.cursorType > 0 && TrarckPlugin.Instance.bluePrintCreateTool.castGround)
             {
                 value = planetGrid.GratboxByCenterSize(TrarckPlugin.Instance.bluePrintCreateTool.castGroundPos, TrarckPlugin.Instance.bluePrintCreateTool.cursorSize);
             }
             ___material.SetVector("_CursorGratBox", value);
         }
     }
 }
        public static void UpdateGrid(UIBuildingGrid __instance)
        {
            Player mainPlayer = GameMain.mainPlayer;

            PlanetFactory planetFactory = GameMain.localPlanet?.factory;

            if (planetFactory == null)
            {
                return;
            }

            if (GameMain.localPlanet.type == EPlanetType.Gas)
            {
                return;
            }

            PlayerAction_Build actionBuild = mainPlayer?.controller.actionBuild;

            if (actionBuild == null)
            {
                return;
            }

            if (actionBuild.blueprintMode != EBlueprintMode.None)
            {
                return;
            }

            if (!BlueprintTweaksPlugin.tool.active)
            {
                return;
            }
            if (BlueprintTweaksPlugin.tool.isSelecting)
            {
                __instance.blueprintMaterial.SetColor(tintColor, Color.clear);
                __instance.blueprintMaterial.SetVector(cursorGratBox, (Vector4)BlueprintTweaksPlugin.tool.preSelectGratBox);
                __instance.blueprintMaterial.SetVector(selectColor, __instance.dismantleColor);
                __instance.blueprintMaterial.SetFloat(showDivideLine, 0f);
                __instance.blueprintGridRnd.enabled = true;
            }
            else
            {
                __instance.blueprintMaterial.SetColor(tintColor, __instance.blueprintColor);
                __instance.blueprintMaterial.SetVector(cursorGratBox, Vector4.zero);
                __instance.blueprintMaterial.SetVector(selectColor, Vector4.one);
                __instance.blueprintMaterial.SetFloat(showDivideLine, 0f);
                __instance.blueprintGridRnd.enabled = false;
            }

            for (int l = 0; l < 64; l++)
            {
                __instance.blueprintMaterial.SetVector($"_CursorGratBox{l}", Vector4.zero);
                __instance.blueprintMaterial.SetFloat($"_CursorGratBoxInfo{l}", 0f);
            }
        }
Beispiel #4
0
        public static void Update(UIBuildingGrid __instance)
        {
            if (!BlueprintCopyExtension.isEnabled)
            {
                return;
            }

            Player mainPlayer = GameMain.mainPlayer;

            PlanetFactory planetFactory = GameMain.localPlanet?.factory;

            if (planetFactory == null)
            {
                return;
            }

            if (GameMain.localPlanet.type == EPlanetType.Gas)
            {
                return;
            }

            PlayerAction_Build actionBuild = mainPlayer?.controller.actionBuild;

            if (actionBuild == null)
            {
                return;
            }

            if (__instance.reformCursorMap == null)
            {
                return;
            }

            int            maxLen = __instance.reformCursorMap.Length;
            PlatformSystem system = planetFactory.platformSystem;

            if (system == null)
            {
                return;
            }
            system.EnsureReformData();

            if (actionBuild.blueprintMode == EBlueprintMode.None)
            {
                __instance.material.SetColor(cursorColor, Color.white);
                return;
            }

            float realRadius = GameMain.localPlanet.realRadius;

            __instance.displayScale = (realRadius + 0.2f) * 2f;

            if (currentFactory == null || currentFactory.index != planetFactory.index)
            {
                currentFactory = planetFactory;

                fakeReformData = new byte[system.maxReformCount];
                Array.Copy(system.reformData, fakeReformData, system.maxReformCount);
            }

            if (actionBuild.blueprintMode == EBlueprintMode.Copy)
            {
                bool any = false;
                if (BlueprintCopyExtension.reformSelection.Count > 0)
                {
                    __instance.material.SetColor(cursorColor, displayColor);
                    foreach (var kv in BlueprintCopyExtension.reformSelection)
                    {
                        int index = kv.Key;
                        if (index >= 0 && index < maxLen)
                        {
                            if (BlueprintCopyExtension.reformPreSelection.Count == 0)
                            {
                                fakeReformData[index] = 0;
                            }

                            __instance.reformCursorMap[index] = 1;
                        }
                    }
                    any = true;
                }

                if (BlueprintCopyExtension.reformPreSelection.Count > 0)
                {
                    __instance.material.SetColor(cursorColor, selectColor);

                    foreach (var kv in BlueprintCopyExtension.reformPreSelection)
                    {
                        int index = kv.Key;
                        if (index >= 0 && index < maxLen)
                        {
                            fakeReformData[index]             = 0;
                            __instance.reformCursorMap[index] = 1;
                        }
                    }
                    any = true;
                }

                if (any)
                {
                    __instance.material.SetColor(tintColor, Color.clear);
                    __instance.gridRnd.enabled = true;
                    __instance.material.SetFloat(reformMode, 1f);
                    __instance.material.SetFloat(zMin, -1.5f);
                    __instance.reformCursorBuffer.SetData(__instance.reformCursorMap);
                    __instance.material.SetBuffer(cursorBuffer, __instance.reformCursorBuffer);

                    ComputeBuffer reformDataBuffer = system.reformDataBuffer;
                    reformDataBuffer.SetData(fakeReformData);
                    __instance.material.SetBuffer(dataBuffer, reformDataBuffer);

                    foreach (var kv in BlueprintCopyExtension.reformSelection)
                    {
                        int index = kv.Key;
                        if (index >= 0 && index < maxLen)
                        {
                            if (BlueprintCopyExtension.reformPreSelection.Count == 0)
                            {
                                fakeReformData[index] = system.reformData[index];
                            }

                            __instance.reformCursorMap[index] = 0;
                        }
                    }

                    foreach (var kv in BlueprintCopyExtension.reformPreSelection)
                    {
                        int index = kv.Key;
                        if (index >= 0 && index < maxLen)
                        {
                            fakeReformData[index]             = system.reformData[index];
                            __instance.reformCursorMap[index] = 0;
                        }
                    }
                }
            }

            if (actionBuild.blueprintMode == EBlueprintMode.Paste)
            {
                ReformBPUtils.currentGrid = GameMain.localPlanet.aux.mainGrid;

                __instance.material.SetColor(cursorColor, displayColor);
                __instance.gridRnd.enabled = true;
                PlatformSystem platformSystem = __instance.reformMapPlanet.factory.platformSystem;
                if (BlueprintPasteExtension.reformPreviews.Count > 0)
                {
                    foreach (ReformData reformPreview in BlueprintPasteExtension.reformPreviews)
                    {
                        ReformBPUtils.GetSegmentCount(reformPreview.latitude, reformPreview.longitude, out float latCount, out float longCount, out int segmentCount);
                        longCount = Mathf.Repeat(longCount, segmentCount);

                        int index = platformSystem.GetReformIndexForSegment(latCount, longCount);
                        if (index >= 0 && index < maxLen)
                        {
                            __instance.reformCursorMap[index] = 1;
                        }
                    }

                    __instance.material.SetColor(tintColor, Color.clear);
                    __instance.material.SetFloat(reformMode, 1f);
                    __instance.material.SetFloat(zMin, -1.5f);
                    __instance.reformCursorBuffer.SetData(__instance.reformCursorMap);
                    __instance.material.SetBuffer(cursorBuffer, __instance.reformCursorBuffer);

                    foreach (ReformData reformPreview in BlueprintPasteExtension.reformPreviews)
                    {
                        ReformBPUtils.GetSegmentCount(reformPreview.latitude, reformPreview.longitude, out float latCount, out float longCount, out int segmentCount);
                        longCount = Mathf.Repeat(longCount, segmentCount);

                        int index = platformSystem.GetReformIndexForSegment(latCount, longCount);
                        if (index >= 0 && index < maxLen)
                        {
                            __instance.reformCursorMap[index] = 0;
                        }
                    }
                }
            }
        }