コード例 #1
0
        public static bool CheckBpForGasGiants(PlayerController __instance, BlueprintData blueprint)
        {
            if (GameMain.history.blueprintLimit == 0)
            {
                return(false);
            }
            if (blueprint == null)
            {
                blueprint = __instance.actionBuild.blueprintClipboard;
            }
            if (BlueprintData.IsNullOrEmpty(blueprint))
            {
                return(false);
            }

            if (__instance.gameData.localPlanet?.gasItems == null || __instance.gameData.localPlanet.gasItems.Length == 0)
            {
                return(true);
            }

            foreach (BlueprintBuilding building in blueprint.buildings)
            {
                ItemProto item = LDB.items.Select(building.itemId);
                if (!item.BuildInGas)
                {
                    UIRealtimeTip.Popup("CantPasteThisInGasGiantWarn".Translate());
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        public static void OnPasteButtonClicked()
        {
            if (lastClickedFile == null)
            {
                return;
            }

            if (lastClickedFile.isDirectory)
            {
                if (!Directory.Exists(lastClickedFile.fullPath))
                {
                    return;
                }

                lastClickedFile.browser.SetCurrentDirectory(lastClickedFile.fullPath);
                return;
            }

            if (!VFInput.readyToBuild)
            {
                return;
            }
            BlueprintData blueprint = BlueprintData.CreateFromFile(lastClickedFile.fullPath);

            if (BlueprintData.IsNullOrEmpty(blueprint))
            {
                return;
            }

            GameMain.mainPlayer.controller.OpenBlueprintPasteMode(blueprint, lastClickedFile.fullPath);
            lastClickedFile.browser._Close();
        }
コード例 #3
0
        public static void Export(BlueprintData __instance, BinaryWriter w)
        {
            bool hasData = __instance.reforms != null && __instance.reforms.Length > 0;

            if (hasData)
            {
                w.Write((byte)2);
                w.Write(__instance.reforms.Length);
                foreach (ReformData data in __instance.reforms)
                {
                    data.Export(w);
                }

                bool hasColors = __instance.customColors != null && __instance.customColors.Length > 0;
                w.Write(hasColors);
                if (!hasColors)
                {
                    return;
                }

                for (int i = 0; i < 16; i++)
                {
                    w.Write(__instance.customColors[i].r);
                    w.Write(__instance.customColors[i].g);
                    w.Write(__instance.customColors[i].b);
                    w.Write(__instance.customColors[i].a);
                }

                return;
            }

            w.Write((byte)0);
        }
コード例 #4
0
        public static void InitPreviews(BlueprintData _blueprintData, int _dotsCursor)
        {
            int num  = _blueprintData.reforms.Length;
            int num2 = (_blueprintData.areas.Length > 1) ? num : (num * _dotsCursor);

            if (reformPreviews.Capacity < num2)
            {
                reformPreviews.Capacity = num2;
            }

            for (int i = 0; i < num2; i++)
            {
                if (i >= reformPreviews.Count)
                {
                    reformPreviews.Add(new ReformData());
                }

                int num4 = i % num;
                reformPreviews[i].areaIndex      = _blueprintData.reforms[num4].areaIndex;
                reformPreviews[i].localLatitude  = _blueprintData.reforms[num4].localLatitude;
                reformPreviews[i].localLongitude = _blueprintData.reforms[num4].localLongitude;
                reformPreviews[i].type           = _blueprintData.reforms[num4].type;
                reformPreviews[i].color          = _blueprintData.reforms[num4].color;
            }

            for (int i = reformPreviews.Count - 1; i >= num2; i--)
            {
                reformPreviews.RemoveAt(i);
            }
        }
コード例 #5
0
        public static void OnDismantle(BuildTool_Dismantle __instance)
        {
            if (UndoManager.IgnoreAllEvents.Value)
            {
                return;
            }
            if (NebulaModAPI.IsMultiplayerActive)
            {
                if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                {
                    return;
                }
            }

            List <int> objectIds = __instance.DetermineDismantle().ToList();

            if (objectIds.Count <= 0)
            {
                return;
            }

            BlueprintData blueprint = UndoUtils.GenerateBlueprint(objectIds, out Vector3 position);

            if (blueprint.buildings.Length > 0 && !position.Equals(Vector3.zero))
            {
                PlayerUndo data = UndoManager.GetCurrentPlayerData();
                data.AddUndoItem(new UndoDismantle(data, objectIds, blueprint, new[] { position }, 0));
            }
        }
コード例 #6
0
        public static void Import(BlueprintData __instance, BinaryReader r)
        {
            if (r.BaseStream.Position != r.BaseStream.Length)
            {
                byte version = r.ReadByte();
                if (version >= 1)
                {
                    int len = r.ReadInt32();
                    __instance.reforms = new ReformData[len];
                    for (int i = 0; i < len; i++)
                    {
                        __instance.reforms[i] = new ReformData();
                        ReformData data = __instance.reforms[i];
                        data.Import(r);
                    }
                }

                if (version >= 2 && r.ReadBoolean())
                {
                    __instance.customColors = new Color[16];
                    for (int i = 0; i < 16; i++)
                    {
                        __instance.customColors[i] = new Color(
                            r.ReadSingle(),
                            r.ReadSingle(),
                            r.ReadSingle(),
                            r.ReadSingle());
                    }
                }
            }
        }
コード例 #7
0
 public static void Repair(BlueprintData __instance)
 {
     if (__instance.reforms == null)
     {
         __instance.reforms = new ReformData[0];
     }
 }
コード例 #8
0
ファイル: BlueprintLoader.cs プロジェクト: Szejp/SurvivalGame
        /// <summary>
        /// This method allows to load a blueprint data in runtimes.
        /// </summary>
        public void LoadInRuntime(BlueprintData blueprint)
        {
            BuildManager Manager = FindObjectOfType <BuildManager>();

            if (Manager == null)
            {
                Debug.Log("<b><color=red>[Easy Build System]</color></b> : The build manager does not exists.");

                return;
            }

            List <PartModel.SerializedPart> Parts = blueprint.Model.DecodeToStr(blueprint.Data);

            GroupBehaviour Group = new GameObject("(Runtime) Blueprint").AddComponent <GroupBehaviour>();

            for (int i = 0; i < Parts.Count; i++)
            {
                PartBehaviour Part = Manager.GetPart(Parts[i].Id);

                PartBehaviour PlacedPart = Manager.PlacePrefab(Part, PartModel.ParseToVector3(Parts[i].Position),
                                                               PartModel.ParseToVector3(Parts[i].Rotation), PartModel.ParseToVector3(Parts[i].Scale), Group);

                PlacedPart.ChangeAppearance(Parts[i].AppearanceIndex);
            }
        }
コード例 #9
0
ファイル: UndoUtils.cs プロジェクト: kremnev8/DSP-Mods
        public static BlueprintData GenerateBlueprint(List <int> objectIds, out Vector3 position)
        {
            position = Vector3.zero;
            if (GameMain.mainPlayer?.controller == null)
            {
                return(BlueprintData.CreateNew());
            }
            if (GameMain.localPlanet == null)
            {
                return(BlueprintData.CreateNew());
            }

            BuildTool_BlueprintCopy copy = GameMain.mainPlayer.controller.actionBuild.blueprintCopyTool;

            using (UndoManager.IgnoreAllEvents.On())
            {
                copy.InitTool();
                copy.selectedObjIds.Clear();
                foreach (int objectId in objectIds)
                {
                    copy.selectedObjIds.Add(objectId);
                }

                copy.blueprint = BlueprintData.CreateNew();
                copy.RefreshBlueprintData();

                Vector2 minPos = GetMinLongLat(objectIds, copy);

                float radius = GameMain.localPlanet.realRadius;
                position = BlueprintUtils.GetDir(minPos.x, minPos.y) * radius;
                position = copy.actionBuild.planetAux.Snap(position, true);
            }

            return(copy.blueprint);
        }
コード例 #10
0
    public void SetUpItemData(BlueprintData bp_Data)
    {
        btn = GetComponent <Button>();
        btn.onClick.AddListener(delegate { UIManager.Instance.crafting.OnCraftBtn(bp_Data); });

        nameText.text     = bp_Data.gearData.m_name;
        previewImg.sprite = bp_Data.gearData.inventorySprite;

        for (int i = 0; i < bp_Data.resourcePrices.Length; i++)
        {
            switch (bp_Data.resourcePrices[i].resourceData.m_name)
            {
            case "Wood":
                WoodText.text = bp_Data.resourcePrices[i].price.ToString();
                break;

            case "Stone":
                StoneText.text = bp_Data.resourcePrices[i].price.ToString();
                break;

            case "Iron":
                IronText.text = bp_Data.resourcePrices[i].price.ToString();
                break;

            case "Gold":
                GoldText.text = bp_Data.resourcePrices[i].price.ToString();
                break;
            }
        }
    }
コード例 #11
0
    void Craft(BlueprintData bp_Data)
    {
        SpendResources(bp_Data.resourcePrices);
        DeleteUIItem(bp_Data);

        InventoryEventSystem.AddGearToInventory(bp_Data.gearData);
        InventoryEventSystem.ReplaceGear();
    }
コード例 #12
0
 public void OnCraftBtn(BlueprintData bp_Data)
 {
     // If enough resources => add to inventory
     if (IsEnoughResources(bp_Data.resourcePrices))
     {
         Craft(bp_Data);
     }
 }
コード例 #13
0
    void CreateUIItem(BlueprintData bp_Data)
    {
        GameObject uiItem = Instantiate(uiItemPrefab, Vector3.zero, Quaternion.identity, itemsRect.transform);

        uiItem.GetComponent <CraftingUIItem>().SetUpItemData(bp_Data);

        blueprints.Add(bp_Data, uiItem);
    }
コード例 #14
0
 public static bool CheckValid(BlueprintData __instance, ref bool __result)
 {
     if (__instance.reforms != null)
     {
         return(true);
     }
     __result = false;
     return(false);
 }
コード例 #15
0
 public CodeGeneratorData[] GetData()
 {
     return(_blueprintNames
            .Select(blueprintName => {
         var data = new BlueprintData();
         data.SetBlueprintName(blueprintName);
         return data;
     }).ToArray());
 }
コード例 #16
0
        public static IEnumerable <CodeInstruction> DontClearOpenPath(IEnumerable <CodeInstruction> instructions)
        {
            CodeMatcher matcher = new CodeMatcher(instructions)
                                  .MatchForward(false, new CodeMatch(OpCodes.Ldstr))

                                  .SetInstruction(Transpilers.EmitDelegate <Func <string> >(() =>
            {
                string currentPath = UIRoot.instance.uiGame.blueprintBrowser.openPath;

                return(BlueprintData.GenerateNewFileName(currentPath));
            }));

            return(matcher.InstructionEnumeration());
        }
コード例 #17
0
 public IActionResult CreateBlueprint([FromBody] BlueprintData bdata)
 {
     if (ModelState.IsValid)
     {
         Blueprint b = bdata.Blueprint;
         context.Add(b);
         context.SaveChanges();
         return(Ok(b.BlueprintId));
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
コード例 #18
0
 public IActionResult ReplaceBlueprint(long id, [FromBody] BlueprintData bdata)
 {
     if (ModelState.IsValid)
     {
         Blueprint b = bdata.Blueprint;
         b.BlueprintId = id;
         context.Update(b);
         context.SaveChanges();
         return(Ok());
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
コード例 #19
0
        private static void GenerateUndoData(PlanetFactory factory, List <int> targetIds)
        {
            if (NebulaModAPI.IsMultiplayerActive)
            {
                if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                {
                    return;
                }
            }

            try
            {
                List <int> filteredIds = targetIds.Where(objId =>
                {
                    if (objId < 0)
                    {
                        int modelIndex        = factory.prebuildPool[-objId].modelIndex;
                        ModelProto modelProto = LDB.models.Select(modelIndex);
                        return(modelProto != null);
                    }

                    if (objId > 0)
                    {
                        int modelIndex        = factory.entityPool[objId].modelIndex;
                        ModelProto modelProto = LDB.models.Select(modelIndex);
                        return(modelProto != null);
                    }

                    return(false);
                }).ToList();

                BlueprintData blueprint = UndoUtils.GenerateBlueprint(filteredIds, out Vector3 position);
                if (blueprint.buildings.Length > 0 && !position.Equals(Vector3.zero))
                {
                    PlayerUndo data = UndoManager.GetCurrentPlayerData();

                    data.AddUndoItem(new UndoDismantle(data, filteredIds, blueprint, new[] { position }, 0));
                }
            }
            catch (Exception e)
            {
                BlueprintTweaksPlugin.logger.LogWarning($"Failed to generate undo for drag dismantle: {e.Message}, stacktrace:\n{e.StackTrace}");
            }
        }
コード例 #20
0
        public static void RefreshReformPreviews(BlueprintData _blueprintData, PlanetData _planet, int _dotsCursor, IntVector4[] _tropicGratBoxConditionInfo,
                                                 float _yaw, int _segmentCnt, Vector4[] array)
        {
            if (!BlueprintCopyExtension.isEnabled)
            {
                return;
            }
            if (UndoManager.IgnoreAllEvents.Value)
            {
                return;
            }

            int   yawCount           = Mathf.FloorToInt(_yaw / 90f);
            float yawX               = yawCount == 1 || yawCount == 2 ? -1f : 1f;
            float yawY               = yawCount == 2 || yawCount == 3 ? -1f : 1f;
            float latitudeRadPerGrid = BlueprintUtils.GetLatitudeRadPerGrid(_segmentCnt);

            List <ReformData> reforms = BlueprintPasteExtension.reformPreviews;
            int reformsLength         = _blueprintData.reforms.Length;

            for (int i = 0; i < reformsLength; i++)
            {
                ReformData reformData = _blueprintData.reforms[i];
                for (int j = 0; j < _dotsCursor; j++)
                {
                    ReformData reformPreview = reforms[reformsLength * j + i];
                    Vector4    areaData      = array[j + reformData.areaIndex];

                    BlueprintUtilsPatch2.MirrorArea(ref areaData, yawX, yawY);

                    float   radPerGrid    = BlueprintUtils.GetLongitudeRadPerGrid(areaData.y, _segmentCnt);
                    Vector2 vector4       = BlueprintUtils.TransitionWidthAndHeight(_yaw, reformData.localLongitude - 0.5f, reformData.localLatitude - 0.5f);
                    float   longitudeRad  = areaData.x + vector4.x * radPerGrid * yawX;
                    float   finalLatitude = areaData.y + vector4.y * latitudeRadPerGrid * yawY;
                    finalLatitude = Math.Abs(finalLatitude) > 1.5707964f ? 1.5707964f * Math.Sign(finalLatitude) : finalLatitude;

                    reformPreview.latitude  = finalLatitude;
                    reformPreview.longitude = longitudeRad;
                }
            }
        }
コード例 #21
0
 public static void SetNull(BlueprintData __instance)
 {
     __instance.reforms = null;
 }
コード例 #22
0
 public static void Reset(BlueprintData __instance)
 {
     __instance.reforms = new ReformData[0];
 }
コード例 #23
0
 public static bool CheckEmpty(BlueprintData __instance, ref bool __result)
 {
     __result = (__instance.buildings == null || __instance.buildings.Length == 0) && (__instance.reforms == null || __instance.reforms.Length == 0);
     return(false);
 }
コード例 #24
0
 public static bool CheckNull(BlueprintData blueprint, ref bool __result)
 {
     __result = blueprint == null || !blueprint.isValid || blueprint.buildings.Length == 0 && blueprint.reforms.Length == 0;
     return(false);
 }
コード例 #25
0
 public UndoBlueprint(PlayerUndo undoData, IEnumerable <int> objectIds, BlueprintData blueprint, Vector3[] dotsSnapped, float yaw) : base(undoData, objectIds)
 {
     this.blueprint   = blueprint;
     this.dotsSnapped = dotsSnapped;
     this.yaw         = yaw;
 }
コード例 #26
0
 void DeleteUIItem(BlueprintData bp_Data)
 {
     Destroy(blueprints[bp_Data]);
     blueprints.Remove(bp_Data);
 }
コード例 #27
0
    private static void Hover <G, C, D>(C currentChild, C whatToBuild, InteriorFields <G, C> fields, Dictionary <C, D> buildData, Action <C> assignCurrentChild) where C : IConvertible where D : BlueprintData
    {
        //avoid filling every frame that we're hovered
        if (Convert.ToInt32(whatToBuild) != Convert.ToInt32(currentChild))
        {
            if (buildData.ContainsKey(whatToBuild))
            {
                assignCurrentChild(whatToBuild);

                BlueprintData data = buildData[whatToBuild];

                fields.DetailHeader.text      = whatToBuild.ToString();
                fields.DetailDescription.text = data.Description;
                int i = 0;
                foreach (RectTransform text in fields.DetailMaterialsParent)
                {
                    if (i == 0)
                    {
                        //noop;
                    }
                    else
                    {
                        int  actualIndex = i - 1;
                        bool active      = actualIndex < data.Requirements.Count;
                        text.gameObject.SetActive(active);
                        if (active)
                        {
                            text.GetComponent <Text>().text = data.Requirements[actualIndex].ToString();
                            text.GetChild(0).GetComponent <Image>().sprite = data.Requirements[actualIndex].Type.Sprite();
                        }
                    }

                    i++;
                }

                fields.DetailPower.transform.parent.gameObject.SetActive(data.PowerSteady.HasValue || data.PowerMin.HasValue);

                if (data.PowerSteady.HasValue)
                {
                    fields.DetailPower.text = data.PowerSteady.Value > 0 ? "+" + data.PowerSteady.Value : data.PowerSteady.Value.ToString();
                }
                else if (data.PowerMin.HasValue && data.PowerMin.Value >= 0)
                {
                    fields.DetailPower.text = String.Format("+[{0}-{1}]", data.PowerMin.Value, data.PowerMax.Value);
                }

                fields.DetailPowerStorage.transform.parent.gameObject.SetActive(data.EnergyStorage.HasValue);
                if (data.EnergyStorage.HasValue)
                {
                    fields.DetailPower.text = data.EnergyStorage.ToString();
                }

                fields.DetailTypedStorage.transform.parent.gameObject.SetActive(data.StorageType != Matter.Unspecified);
                if (data.StorageType != Matter.Unspecified)
                {
                    fields.DetailStorage.transform.parent.gameObject.SetActive(false);
                    fields.DetailTypedStorage.text = data.Storage.Value.ToString();
                    if (data.StorageType == Matter.Methane)
                    {
                        fields.DetailTypedStorageSprite.sprite = GuiBridge.Instance.Icons.MiscIcons[(int)MiscIcon.Molecule];
                    }
                    else
                    {
                        fields.DetailTypedStorageSprite.sprite = data.StorageType.Sprite();
                    }
                }
                else
                {
                    fields.DetailStorage.transform.parent.gameObject.SetActive(data.Storage.HasValue);
                    if (data.Storage.HasValue)
                    {
                        fields.DetailStorage.text = data.Storage.Value.ToString();
                    }
                }

                if (data.IO == null)
                {
                    foreach (Text io in fields.DetailIO)
                    {
                        io.transform.parent.gameObject.SetActive(false);
                    }
                }
                else
                {
                    i = 0;
                    foreach (KeyValuePair <Matter, float> entry in data.IO)
                    {
                        fields.DetailIO[i].transform.parent.gameObject.SetActive(true);
                        fields.DetailIO[i].text = entry.Value > 0 ? "+" + entry.Value : entry.Value.ToString();
                        fields.DetailIO[i].transform.parent.GetChild(0).GetComponent <Image>().sprite = entry.Key.Sprite();
                        i++;
                    }
                    for (int j = i; j < fields.DetailIO.Length; j++)
                    {
                        fields.DetailIO[i].transform.parent.gameObject.SetActive(false);
                    }
                }
            }
        }
    }
コード例 #28
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            GUILayout.Space(10);

            #region Inspector

            GUILayout.BeginVertical("Easy Build System - Group Behaviour", "window", GUILayout.Height(10));

            GUILayout.BeginVertical("box");

            GUI.color = MainEditor.GetEditorColor;

            GUILayout.BeginHorizontal();

            GUILayout.Label("Group Behaviour Settings", EditorStyles.largeLabel);

            #region Group Behaviour Settings

            GUILayout.FlexibleSpace();

            if (GUILayout.Button(DefaultInspector ? "Advanced Inspector" : "Default Inspector", GUILayout.Width(130)))
            {
                DefaultInspector = !DefaultInspector;
            }

            if (GUILayout.Button(AllIsOpen ? "Fold In" : "Fold Out", GUILayout.Width(80)))
            {
                AddonsFoldout = !AddonsFoldout;
                AllIsOpen     = !AllIsOpen;
            }

            if (GUILayout.Button(Help ? "Hide Help" : "Show Help", GUILayout.Width(100)))
            {
                Help = !Help;
            }

            GUI.color = Color.white;

            GUILayout.EndHorizontal();

            if (Help)
            {
                EditorGUILayout.HelpBox("This component allows to save and load of Group Behaviour which contains of Parts Behaviour during the edit/runtime.\n" +
                                        "The data below can be shared and loaded if the Build Manager use the same Id's in the Parts Collection.", MessageType.Info);

                GUI.color = MainEditor.GetEditorColor;

                if (GUILayout.Button("Open Documentation Link"))
                {
                    Application.OpenURL(Constants.DOCS_LINK);
                }

                GUI.color = Color.white;
            }

            if (DefaultInspector)
            {
                DrawDefaultInspector();

                GUILayout.EndVertical();

                GUILayout.EndVertical();

                serializedObject.ApplyModifiedProperties();

                GUILayout.Space(10);

                return;
            }

            GUI.enabled = false;

            EditorGUILayout.ObjectField("Script", target, typeof(AreaBehaviour), true);

            GUI.enabled = true;

            GUI.color = Color.white;

            if (Application.isPlaying)
            {
                GUILayout.BeginHorizontal();

                GUILayout.BeginVertical();

                GUI.color = MainEditor.GetEditorColor;

                if (GUILayout.Button("Save As Blueprint..."))
                {
                    BlueprintData Data = ScriptableObjectExtension.CreateAsset <BlueprintData>("New Empty Blueprint");

                    Data.name  = Target.name;
                    Data.Model = Target.GetModel();
                    Data.Data  = Target.GetModel().EncodeToStr();

                    Debug.Log("<b><color=cyan>[Easy Build System]</color></b> : The blueprint model has been saved.");
                }

                if (GUILayout.Button("Destroy Group"))
                {
                    Destroy(Target.gameObject);

                    Debug.Log("<b><color=cyan>[Easy Build System]</color></b> : The group has been destroyed.");
                }

                GUI.enabled = true;

                GUI.color = Color.white;

                GUILayout.EndVertical();

                GUILayout.EndHorizontal();
            }

            #endregion Group Behaviour Settings

            GUI.color = MainEditor.GetEditorColor;

            GUILayout.Label("Group Add-On(s) Settings", EditorStyles.largeLabel);

            #region Group Add-Ons Settings

            GUI.color = Color.white;

            GUILayout.BeginHorizontal();

            GUILayout.Space(13);

            AddonsFoldout = EditorGUILayout.Foldout(AddonsFoldout, "Add-Ons Section Settings");

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            GUILayout.Space(13);

            GUILayout.BeginVertical();

            if (AddonsFoldout)
            {
                MainEditor.DrawAddons(Target, AddOnTarget.GroupBehaviour);
            }

            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            #endregion Group Add-Ons Settings

            GUILayout.EndVertical();

            GUILayout.EndVertical();

            #endregion Inspector

            serializedObject.ApplyModifiedProperties();

            GUILayout.Space(10);
        }
コード例 #29
0
 public static string GetBlueprintName(this BlueprintData data)
 {
     return((string)data[BLUEPRINT_NAME]);
 }
コード例 #30
0
 public static void SetBlueprintName(this BlueprintData data, string blueprintName)
 {
     data[BLUEPRINT_NAME] = blueprintName;
 }