public void EnvironmentVariableFalse()
        {
            PatchController.Reset();
            Environment.SetEnvironmentVariable("DPS_EnableHighDpi", "false");
            Assert.IsFalse(PatchController.EnableHighDpi);
            Environment.SetEnvironmentVariable("DPS_EnableHighDpi", null);

            Environment.SetEnvironmentVariable("DPS_EnableContentOrderFix", "false");
            Assert.IsFalse(PatchController.EnableContentOrderFix);
            Environment.SetEnvironmentVariable("DPS_EnableContentOrderFix", null);

            Environment.SetEnvironmentVariable("DPS_EnableFontInheritanceFix", "false");
            Assert.IsFalse(PatchController.EnableFontInheritanceFix);
            Environment.SetEnvironmentVariable("DPS_EnableFontInheritanceFix", null);

            Environment.SetEnvironmentVariable("DPS_EnableMainWindowFocusLostFix", "false");
            Assert.IsFalse(PatchController.EnableMainWindowFocusLostFix);
            Environment.SetEnvironmentVariable("DPS_EnableMainWindowFocusLostFix", null);

            Environment.SetEnvironmentVariable("DPS_EnableMemoryLeakFix", "false");
            Assert.IsFalse(PatchController.EnableMemoryLeakFix);
            Environment.SetEnvironmentVariable("DPS_EnableMemoryLeakFix", null);

            Environment.SetEnvironmentVariable("DPS_EnableNestedDisposalFix", "false");
            Assert.IsFalse(PatchController.EnableNestedDisposalFix);
            Environment.SetEnvironmentVariable("DPS_EnableNestedDisposalFix", null);

            Environment.SetEnvironmentVariable("DPS_EnableActiveXFix", "true");
            Assert.IsTrue(PatchController.EnableActiveXFix);
            Environment.SetEnvironmentVariable("DPS_EnableActiveXFix", null);

            Environment.SetEnvironmentVariable("DPS_EnableDisplayingPaneFix", "false");
            Assert.IsFalse(PatchController.EnableDisplayingPaneFix);
            Environment.SetEnvironmentVariable("DPS_EnableDisplayingPaneFix", null);

            Environment.SetEnvironmentVariable("DPS_EnableActiveControlFix", "false");
            Assert.IsFalse(PatchController.EnableActiveControlFix);
            Environment.SetEnvironmentVariable("DPS_EnableActiveControlFix", null);

            Environment.SetEnvironmentVariable("DPS_EnableFloatSplitterFix", "false");
            Assert.IsFalse(PatchController.EnableFloatSplitterFix);
            Environment.SetEnvironmentVariable("DPS_EnableFloatSplitterFix", null);

            Environment.SetEnvironmentVariable("DPS_EnableActivateOnDockFix", "false");
            Assert.IsFalse(PatchController.EnableActivateOnDockFix);
            Environment.SetEnvironmentVariable("DPS_EnableActivateOnDockFix", null);

            PatchController.Reset();
            Assert.IsTrue(PatchController.EnableHighDpi);
            Assert.IsTrue(PatchController.EnableContentOrderFix);
            Assert.IsTrue(PatchController.EnableFontInheritanceFix);
            Assert.IsTrue(PatchController.EnableMainWindowFocusLostFix);
            Assert.IsTrue(PatchController.EnableMemoryLeakFix);
            Assert.IsTrue(PatchController.EnableNestedDisposalFix);
            Assert.IsFalse(PatchController.EnableActiveXFix);
            Assert.IsTrue(PatchController.EnableDisplayingPaneFix);
            Assert.IsTrue(PatchController.EnableActiveControlFix);
            Assert.IsTrue(PatchController.EnableFloatSplitterFix);
            Assert.IsTrue(PatchController.EnableActivateOnDockFix);
        }
        public void RegistryValueFalse()
        {
            PatchController.Reset();
            var key = Registry.CurrentUser.CreateSubKey("Software\\DockPanelSuite");

            Assert.IsNotNull(key);
            key.SetValue("EnableHighDpi", "false", RegistryValueKind.String);
            key.SetValue("EnableContentOrderFix", "false", RegistryValueKind.String);
            key.SetValue("EnableFontInheritanceFix", "false", RegistryValueKind.String);
            key.SetValue("EnableMainWindowFocusLostFix", "false", RegistryValueKind.String);
            key.SetValue("EnableMemoryLeakFix", "false", RegistryValueKind.String);
            key.SetValue("EnableNestedDisposalFix", "false", RegistryValueKind.String);
            key.SetValue("EnableActiveXFix", "true", RegistryValueKind.String);
            key.SetValue("EnableDisplayingPaneFix", "false", RegistryValueKind.String);
            key.SetValue("EnableActiveControlFix", "false", RegistryValueKind.String);
            key.SetValue("EnableFloatSplitterFix", "false", RegistryValueKind.String);
            key.SetValue("EnableActivateOnDockFix", "false", RegistryValueKind.String);
            key.SetValue("EnableSelectClosestOnClose", "false", RegistryValueKind.String);
            key.SetValue("EnablePerScreenDpi", "true", RegistryValueKind.String);

            Assert.IsFalse(PatchController.EnableHighDpi);
            Assert.IsFalse(PatchController.EnableContentOrderFix);
            Assert.IsFalse(PatchController.EnableFontInheritanceFix);
            Assert.IsFalse(PatchController.EnableMainWindowFocusLostFix);
            Assert.IsFalse(PatchController.EnableMemoryLeakFix);
            Assert.IsFalse(PatchController.EnableNestedDisposalFix);
            Assert.IsTrue(PatchController.EnableActiveXFix);
            Assert.IsFalse(PatchController.EnableDisplayingPaneFix);
            Assert.IsFalse(PatchController.EnableActiveControlFix);
            Assert.IsFalse(PatchController.EnableFloatSplitterFix);
            Assert.IsFalse(PatchController.EnableActivateOnDockFix);
            Assert.IsFalse(PatchController.EnableSelectClosestOnClose);
            Assert.IsTrue(PatchController.EnablePerScreenDpi);
            Registry.CurrentUser.DeleteSubKeyTree("Software\\DockPanelSuite");
        }
Ejemplo n.º 3
0
    // Creating tree method
    public void CreateTreeAtUserPosition(bool confirmed = false)
    {
        if (DownButtonController.instance.standardMenuButtonsVisible)
        {
            DownButtonController.instance.ToggleStandardMenu();
        }

        PatchController userPatch    = PatchesController.instance.patches.Find(x => x.patchData.nick == PlayerPrefs.GetString(AppConstants.NickTag));
        List <Vector2>  patchPolygon = new List <Vector2>();

        foreach (Vector3 patchPolygonVertex in userPatch.patchData.flags)
        {
            patchPolygon.Add(new Vector2(patchPolygonVertex.x, patchPolygonVertex.z));
        }
        if (userPatch == null || !Geometry.PolygonContainsPoint(patchPolygon, new Vector2(PlayerColliderController.instance.transform.position.x, PlayerColliderController.instance.transform.position.z)))
        {
            BannerController.instance.showBannerWithText(true, "Możesz umieścić drzewo tylko w obrębie własnego rewiru", true);
            return;
        }
        if (!PlayerColliderController.instance.CanPlaceObjectHere())
        {
            BannerController.instance.showBannerWithText(true, "Zbyt blisko innego obiektu! Oddal się kilka metrów", true);
            return;
        }
        if (!confirmed)
        {
            ConfirmationPopup.instance.Open(() => { CreateTreeAtUserPosition(true); ConfirmationPopup.instance.Close(); }, () => { ConfirmationPopup.instance.Close(); }, "Czy chcesz tutaj umieścić drzewo za " + AppConstants.TreePurchaseCost + " biomasy ?");
            return;
        }
        if (PlayerPrefs.GetFloat(AppConstants.BiomassTag) < AppConstants.TreePurchaseCost)
        {
            BannerController.instance.showBannerWithText(true, "Masz zbyt mało biomasy", true);
            return;
        }
        ResourcesController.instance.AddBiomass(-AppConstants.TreePurchaseCost);

        Utils.Web.PostValues(AppConstants.AddTreeUrl, new List <KeyValuePair <string, string> >(new KeyValuePair <string, string>[] {
            new KeyValuePair <string, string>("USER_ID", AppConstants.UUID + AppConstants.PlayerDeviceIdentifierID),
            new KeyValuePair <string, string>("LAT", GoShared.Coordinates.convertVectorToCoordinates(PlayerColliderController.instance.transform.position).latitude.ToString()),
            new KeyValuePair <string, string>("LON", GoShared.Coordinates.convertVectorToCoordinates(PlayerColliderController.instance.transform.position).longitude.ToString())
        }), (code, response) =>
        {
            if (code == 200)
            {
                int ts    = (int)Utils.JSON.GetLong(Utils.JSON.GetDictionary(response), "ts");
                long id   = Utils.JSON.GetLong(Utils.JSON.GetDictionary(response), "id");
                Tree tree = new Tree(id, PlayerColliderController.instance.transform.position, PlayerPrefs.GetString(AppConstants.NickTag), ts, ts, ts);
                AddTree(tree);
            }
            else
            {
                Debug.Log(response);
                BannerController.instance.showBannerWithText(true, "Błąd serwera :(", true);
            }
        });
    }
 public void Basic()
 {
     PatchController.Reset();
     Assert.IsFalse(PatchController.EnableHighDpi);
     Assert.IsFalse(PatchController.EnableContentOrderFix);
     Assert.IsFalse(PatchController.EnableFontInheritanceFix);
     Assert.IsFalse(PatchController.EnableMainWindowFocusLostFix);
     Assert.IsFalse(PatchController.EnableMemoryLeakFix);
     Assert.IsFalse(PatchController.EnableNestedDisposalFix);
 }
 public void DisableAll()
 {
     PatchController.Reset();
     PatchController.EnableAll = false;
     Assert.IsFalse(PatchController.EnableHighDpi);
     Assert.IsFalse(PatchController.EnableContentOrderFix);
     Assert.IsFalse(PatchController.EnableFontInheritanceFix);
     Assert.IsFalse(PatchController.EnableMainWindowFocusLostFix);
     Assert.IsFalse(PatchController.EnableMemoryLeakFix);
     Assert.IsFalse(PatchController.EnableNestedDisposalFix);
     Assert.IsFalse(PatchController.EnableActiveXFix);
     Assert.IsFalse(PatchController.EnableDisplayingPaneFix);
 }
Ejemplo n.º 6
0
    // Draw patch method
    public void AddPatch(Patch patch, float overrideY = 0, bool nullParent = false)
    {
        PatchController foundPatch = patches.Find(x => x.patchData.nick.Equals(patch.nick));

        if (foundPatch != null)
        {
            foundPatch.patchData = patch;
            return;
        }

        GameObject patchObject = new GameObject(patch.nick + "_" + patch.fraction);

        if (nullParent)
        {
            patchObject.transform.parent = null;
        }
        else
        {
            patchObject.transform.parent = this.transform;
            PatchController patchController = patchObject.AddComponent <PatchController>();
            patchController.patchData = patch;
            patches.Add(patchController);
        }

        for (int i = 1; i <= patch.flags.Count; i++)
        {
            int     vertex1          = (i - 1) % patch.flags.Count;
            int     vertex2          = i % patch.flags.Count;
            Vector3 particlePosition = new Vector3((patch.flags[vertex1].x + patch.flags[vertex2].x) / 2, overrideY, (patch.flags[vertex1].z + patch.flags[vertex2].z) / 2);
            float   particleRadius   = Vector3.Distance(patch.flags[vertex1], patch.flags[vertex2]) / 2;

            bool    condition        = patch.flags[vertex1].x < patch.flags[vertex2].x;
            Vector3 particleRotation = new Vector3(
                0,
                Vector3.Angle(
                    condition ? Vector3.forward : Vector3.back,
                    patch.flags[vertex2] - patch.flags[vertex1]
                    ) + 90,
                0
                );

            GameObject patchWall = Instantiate(PatchBorder, patchObject.transform);
            patchWall.transform.position               = new Vector3(particlePosition.x, 0, particlePosition.z);
            patchWall.transform.eulerAngles            = particleRotation;
            patchWall.transform.GetChild(0).localScale = new Vector3(particleRadius * 2f, patch.borders[i - 1] ? 10f : 3f, 0.5f);
            Material material = patch.fraction == (int)AppConstants.Fraction.NATURE ? natureWallMaterial : patch.fraction == (int)AppConstants.Fraction.COMMERCY ? commercyWallMaterial : industryWallMaterial;
            patchWall.transform.GetChild(0).GetComponent <MeshRenderer>().material = material;
            patchWall.transform.GetChild(0).GetComponent <MeshRenderer>().material = patch.nick.Equals(PlayerPrefs.GetString(AppConstants.NickTag)) ? ownWallMaterial : material;
        }
    }
 public void Basic()
 {
     PatchController.Reset();
     Assert.IsTrue(PatchController.EnableHighDpi);
     Assert.IsTrue(PatchController.EnableContentOrderFix);
     Assert.IsTrue(PatchController.EnableFontInheritanceFix);
     Assert.IsTrue(PatchController.EnableMainWindowFocusLostFix);
     Assert.IsTrue(PatchController.EnableMemoryLeakFix);
     Assert.IsTrue(PatchController.EnableNestedDisposalFix);
     Assert.IsFalse(PatchController.EnableActiveXFix);
     Assert.IsTrue(PatchController.EnableDisplayingPaneFix);
     Assert.IsTrue(PatchController.EnableActiveControlFix);
     Assert.IsTrue(PatchController.EnableFloatSplitterFix);
     Assert.IsTrue(PatchController.EnableActivateOnDockFix);
 }
 public void DisableAll()
 {
     PatchController.Reset();
     PatchController.EnableAll = false;
     Assert.IsFalse(PatchController.EnableHighDpi);
     Assert.IsFalse(PatchController.EnableContentOrderFix);
     Assert.IsFalse(PatchController.EnableFontInheritanceFix);
     Assert.IsFalse(PatchController.EnableMainWindowFocusLostFix);
     Assert.IsFalse(PatchController.EnableMemoryLeakFix);
     Assert.IsFalse(PatchController.EnableNestedDisposalFix);
     Assert.IsFalse(PatchController.EnableActiveXFix);
     Assert.IsFalse(PatchController.EnableDisplayingPaneFix);
     Assert.IsFalse(PatchController.EnableActiveControlFix);
     Assert.IsFalse(PatchController.EnableFloatSplitterFix);
     Assert.IsFalse(PatchController.EnableActivateOnDockFix);
     Assert.IsFalse(PatchController.EnableSelectClosestOnClose);
     Assert.IsFalse(PatchController.EnablePerScreenDpi);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Assembles the 6502 asm provided into raw bytes.
        /// </summary>
        /// <param name="origin">The address this code will run at. e.g. 0x8000. Must be between 0 and 0xFFFF.</param>
        /// <param name="name">A human-readable reference, e.g. a subroutine name.</param>
        /// <param name="asm">the 6502 asm source, including newline characters.</param>
        /// <example>
        /// var newBytes = InlineAssembler.assemble(0x8000, "FixTheThing", @"
        ///   LDA $30
        ///   JMP $8044
        ///  ");
        /// </example>
        /// <exception cref="AssemblyError">if something goes wrong.</exception>
        public byte[] Assemble(int origin, string name, string asm, Dictionary <string, int> variables = null, Dictionary <string, int> labels = null)
        {
            if (origin < 0 || origin > 0xFFFF)
            {
                throw new ArgumentOutOfRangeException(nameof(origin));
            }

            // it is very important for caseSensitive to be false here. it interprets even instructions as case-sensitive with it on.
            var options = new AssemblyOptions();

            var controller = new PatchController(this, options);

            controller.AddAssembler(new Asm6502(controller));

            // have to do this every pass because each one clears everything out every time...
            controller.OnBeginningOfPass += delegate(object sender, EventArgs e)
            {
                // load up the symbol table
                variables?.ToList().ForEach(pair => controller.Symbols.Variables.SetSymbol(pair.Key, pair.Value, isStrict: false));
                labels?.ToList().ForEach(pair => controller.Symbols.Labels.SetSymbol(pair.Key, pair.Value, isStrict: false));

                // set PC
                controller.Output.SetPC(origin);
            };

            var result = controller.Assemble(name, asm);

            if (ShowWarningsInConsole)
            {
                controller.Log.DumpAll();
            }
            else if (controller.Log.HasErrors)
            {
                controller.Log.DumpErrors();
            }

            if (result is null)
            {
                throw new AssemblyError($"Unable to assemble {name} at {origin}; see console output for details");
            }

            return(result);
        }
Ejemplo n.º 10
0
    public void ChoosePatchEdgeModeToggle()
    {
        if (DownButtonController.instance.standardMenuButtonsVisible)
        {
            DownButtonController.instance.ToggleStandardMenu();
        }

        PatchController userPatch    = PatchesController.instance.patches.Find(x => x.patchData.nick == PlayerPrefs.GetString(AppConstants.NickTag));
        List <Vector2>  patchPolygon = new List <Vector2>();

        foreach (Vector3 patchPolygonVertex in userPatch.patchData.flags)
        {
            patchPolygon.Add(new Vector2(patchPolygonVertex.x, patchPolygonVertex.z));
        }
        if (userPatch == null || !Geometry.PolygonContainsPoint(patchPolygon, new Vector2(PlayerColliderController.instance.transform.position.x, PlayerColliderController.instance.transform.position.z)))
        {
            BannerController.instance.showBannerWithText(true, "Możesz postawić granicę będąc w obrębie własnego rewiru", true);
            return;
        }
        if (userPatch.patchData.borders.FindIndex(x => !x) == -1)
        {
            BannerController.instance.showBannerWithText(true, "Nie możesz postawić już więcej granic", true);
            return;
        }

        Patch   patch             = userPatch.patchData;
        Vector3 centroid          = Geometry.CalculateCentroid(patch.flags);
        float   maxDiagonalLength = float.MinValue;

        foreach (Vector3 flagPosition1 in patch.flags)
        {
            foreach (Vector3 flagPosition2 in patch.flags)
            {
                if (Vector3.Distance(flagPosition1, flagPosition2) > maxDiagonalLength)
                {
                    maxDiagonalLength = Vector3.Distance(flagPosition1, flagPosition2);
                }
            }
        }
        StartCoroutine(SmoothPatchViewController(centroid, maxDiagonalLength));
    }
        public void RegistryValueFalse()
        {
            PatchController.Reset();
            var key = Registry.CurrentUser.CreateSubKey("Software\\DockPanelSuite");

            Assert.IsNotNull(key);
            key.SetValue("EnableHighDpi", "false", RegistryValueKind.String);
            key.SetValue("EnableContentOrderFix", "false", RegistryValueKind.String);
            key.SetValue("EnableFontInheritanceFix", "false", RegistryValueKind.String);
            key.SetValue("EnableMainWindowFocusLostFix", "false", RegistryValueKind.String);
            key.SetValue("EnableMemoryLeakFix", "false", RegistryValueKind.String);
            key.SetValue("EnableNestedDisposalFix", "false", RegistryValueKind.String);

            Assert.IsFalse(PatchController.EnableHighDpi);
            Assert.IsFalse(PatchController.EnableContentOrderFix);
            Assert.IsFalse(PatchController.EnableFontInheritanceFix);
            Assert.IsFalse(PatchController.EnableMainWindowFocusLostFix);
            Assert.IsFalse(PatchController.EnableMemoryLeakFix);
            Assert.IsFalse(PatchController.EnableNestedDisposalFix);
            Registry.CurrentUser.DeleteSubKeyTree("Software\\DockPanelSuite");
        }
Ejemplo n.º 12
0
    // Accepting border purchase
    public void AddBorder(bool confirmed = false)
    {
        if (!confirmed)
        {
            ConfirmationPopup.instance.Open(() => { AddBorder(true); ConfirmationPopup.instance.Close(); }, () => { ConfirmationPopup.instance.Close(); }, "Czy chcesz postawić granicę na tej krawędzi za " + AppConstants.BorderPurchaseCost + " jednostek wszystkich zasobów?");
            return;
        }
        if (PlayerPrefs.GetFloat(AppConstants.EnergyTag) < AppConstants.BorderPurchaseCost || PlayerPrefs.GetFloat(AppConstants.BiomassTag) < AppConstants.BorderPurchaseCost || PlayerPrefs.GetFloat(AppConstants.GadgetsTag) < AppConstants.BorderPurchaseCost || PlayerPrefs.GetFloat(AppConstants.FuelTag) < AppConstants.BorderPurchaseCost)
        {
            BannerController.instance.showBannerWithText(true, "Masz zbyt mało zasobów", true);
            return;
        }

        PatchController userPatch   = PatchesController.instance.patches.Find(x => x.patchData.nick == PlayerPrefs.GetString(AppConstants.NickTag));
        int             vertexIndex = userPatch.GetHighlightedEdgeIndex();

        Utils.Web.PostValues(AppConstants.AddBorderUrl, new List <KeyValuePair <string, string> >(new KeyValuePair <string, string>[] {
            new KeyValuePair <string, string>("USER_ID", AppConstants.UUID + AppConstants.PlayerDeviceIdentifierID),
            new KeyValuePair <string, string>("VERTEX_INDEX", (vertexIndex + 1).ToString())
        }), (code, response) =>
        {
            if (code == 200)
            {
                userPatch.patchData.borders[vertexIndex] = true;
                choosePatchModeEnded = true;

                ResourcesController.instance.AddEnergy(-AppConstants.BorderPurchaseCost);
                ResourcesController.instance.AddBiomass(-AppConstants.BorderPurchaseCost);
                ResourcesController.instance.AddGadgets(-AppConstants.BorderPurchaseCost);
                ResourcesController.instance.AddFuel(-AppConstants.BorderPurchaseCost);
            }
            else
            {
                Debug.Log(response);
                BannerController.instance.showBannerWithText(true, "Błąd serwera :(", true);
            }
        });
    }
Ejemplo n.º 13
0
        public static void DownloadAndInstall(Mod m, bool isUpdatingMod = false)
        {
            // validate mod is not already downloading/updating
            ModStatus status = Sys.GetStatus(m.ID);

            if (status == ModStatus.Downloading)
            {
                Sys.Message(new WMessage($"{m.Name} is already downloading!", true));
                return;
            }

            if (status == ModStatus.Updating)
            {
                Sys.Message(new WMessage($"{m.Name} is already updating!", true));
                return;
            }

            if (status == ModStatus.Installed && !isUpdatingMod)
            {
                Sys.Message(new WMessage($"{m.Name} is already downloaded and installed!", true));
                return;
            }

            Action             onCancel = () => Sys.RevertStatus(m.ID);
            Action <Exception> onError  = ex =>
            {
                Sys.Message(new WMessage($"Error occurred downloading/installing {m.Name} - {ex.Message}", WMessageLogLevel.Error, ex));
                Sys.RevertStatus(m.ID);
            };

            string file     = String.Format("{0}_{1}_{2}.iro", m.ID, SafeStr(m.Name), m.LatestVersion.Version);
            string temppath = System.IO.Path.Combine(Sys.Settings.LibraryLocation, "temp");

            System.IO.Directory.CreateDirectory(temppath);

            var install = Sys.Library.GetItem(m.ID);

            if (install != null)
            {
                // mod is installed so download update files for updating mod
                Sys.SetStatus(m.ID, ModStatus.Updating);

                List <ModPatch> patches = m.GetPatchesFromTo(install.LatestInstalled.VersionDetails.Version, m.LatestVersion.Version);
                if (patches.Any())
                {
                    // download patches to update the mod
                    string       pfile    = String.Format("{0}_{1}_{2}.irop", m.ID, SafeStr(m.Name), m.LatestVersion.Version);
                    DownloadItem download = new DownloadItem()
                    {
                        Links        = patches.Select(p => p.Link).ToList(),
                        SaveFilePath = System.IO.Path.Combine(temppath, pfile),
                        Category     = DownloadCategory.Mod,
                        ItemName     = "Downloading " + m.Name,
                        OnCancel     = onCancel
                    };

                    download.IProc = new PatchModProcedure()
                    {
                        File    = pfile,
                        Install = install,
                        Mod     = m,
                        Error   = onError
                    };

                    Sys.Downloads.AddToDownloadQueue(download);
                    return;
                }
                else
                {
                    // no patches available to update so download entire new mod version .iro
                    DownloadItem installDownload = new DownloadItem()
                    {
                        Links        = m.LatestVersion.Links,
                        SaveFilePath = System.IO.Path.Combine(temppath, file),
                        Category     = DownloadCategory.Mod,
                        ItemName     = "Downloading " + m.Name,
                        OnCancel     = onCancel
                    };

                    installDownload.IProc = new InstallModProcedure()
                    {
                        File             = file,
                        Mod              = m,
                        ExtractSubFolder = m.LatestVersion.ExtractSubFolder,
                        ExtractInto      = m.LatestVersion.ExtractInto,
                        Error            = onError
                    };

                    Sys.Downloads.AddToDownloadQueue(installDownload);
                    return;
                }
            }



            Sys.SetStatus(m.ID, ModStatus.Downloading);

            if (m.LatestVersion.PatchLinks.Any())
            {
                // mod is not installed and the latest version has patches available
                // so first download and install mod then download all patches for mod
                PatchController pc = new PatchController(m.LatestVersion.PatchLinks.Count);

                DownloadItem download = new DownloadItem()
                {
                    Links        = m.LatestVersion.Links,
                    SaveFilePath = System.IO.Path.Combine(temppath, file),
                    ItemName     = "Downloading " + m.Name,
                    Category     = DownloadCategory.Mod,
                    OnCancel     = onCancel
                };

                download.IProc = new DownloadThenPatchProcedure()
                {
                    File       = file,
                    Mod        = m,
                    Controller = pc,
                    Error      = onError
                };

                Sys.Downloads.AddToDownloadQueue(download);

                int pCount = 0;
                foreach (string p in m.LatestVersion.PatchLinks)
                {
                    string pfile = String.Format("{0}_{1}_{2}_patch{3}.iro", m.ID, SafeStr(m.Name), m.LatestVersion.Version, pCount);
                    pc.PatchFiles.Add(pfile);

                    DownloadItem patchDownload = new DownloadItem()
                    {
                        Links = new List <string>()
                        {
                            p
                        },
                        SaveFilePath = System.IO.Path.Combine(temppath, pfile),
                        ItemName     = "Downloading " + m.Name + " patch " + pCount,
                        Category     = DownloadCategory.Mod,
                        OnCancel     = () =>
                        {
                            pc.PatchFailed();
                            Sys.RevertStatus(m.ID);
                        }
                    };

                    patchDownload.IProc = new DownloadPatchProcedure()
                    {
                        File       = pfile,
                        Controller = pc,
                        Error      = ex =>
                        {
                            pc.PatchFailed();
                            Sys.RevertStatus(m.ID);
                        }
                    };

                    Sys.Downloads.AddToDownloadQueue(patchDownload);
                    pCount++;
                }
            }
            else
            {
                // mod is not installed in library so just download using the links of latest version
                DownloadItem installDownload = new DownloadItem()
                {
                    Links        = m.LatestVersion.Links,
                    SaveFilePath = System.IO.Path.Combine(temppath, file),
                    Category     = DownloadCategory.Mod,
                    ItemName     = "Downloading " + m.Name,
                    OnCancel     = onCancel
                };

                installDownload.IProc = new InstallModProcedure()
                {
                    File             = file,
                    Mod              = m,
                    ExtractSubFolder = m.LatestVersion.ExtractSubFolder,
                    ExtractInto      = m.LatestVersion.ExtractInto,
                    Error            = onError
                };

                Sys.Downloads.AddToDownloadQueue(installDownload);
            }
        }
Ejemplo n.º 14
0
    // Remove own patch method
    public void RemoveOwnPatch(bool confirmed = false)
    {
        if (DownButtonController.instance.standardMenuButtonsVisible)
        {
            DownButtonController.instance.ToggleStandardMenu();
        }

        PatchController userPatch    = PatchesController.instance.patches.Find(x => x.patchData.nick.Equals(PlayerPrefs.GetString(AppConstants.NickTag)));
        List <Vector2>  patchPolygon = new List <Vector2>();

        foreach (Vector3 patchPolygonVertex in userPatch.patchData.flags)
        {
            patchPolygon.Add(new Vector2(patchPolygonVertex.x, patchPolygonVertex.z));
        }
        if (!confirmed)
        {
            ConfirmationPopup.instance.Open(() => { RemoveOwnPatch(true); ConfirmationPopup.instance.Close(); }, () => { ConfirmationPopup.instance.Close(); }, "Czy chcesz usunąć swój rewir?");
            return;
        }

        Utils.Web.PostValues(AppConstants.RemovePatchUrl, new List <KeyValuePair <string, string> >(new KeyValuePair <string, string>[] {
            new KeyValuePair <string, string>("USER_ID", AppConstants.UUID + AppConstants.PlayerDeviceIdentifierID)
        }), (code, response) =>
        {
            if (code == 200)
            {
                PlayerPrefs.DeleteKey("PatchCreatedTag");
                PlayerPrefs.DeleteKey("GeneratorCreatedTag");
                PlayerPrefs.DeleteKey("GeneratorVisitTimestampTag");
                PlayerPrefs.DeleteKey("ConverterCreatedTag");
                PlayerPrefs.DeleteKey("BatteryCreatedTag");
                PlayerPrefs.DeleteKey("ProjectObjectsCountTag");
                PlayerPrefs.Save();

                List <GeneratorController> generators         = GeneratorsController.instance.generators.FindAll(x => x.generatorData.nick.Equals(PlayerPrefs.GetString(AppConstants.NickTag)));
                List <ProjectObjectController> projectObjects = ProjectObjectsController.instance.projectObjects.FindAll(x => x.projectObjectData.nick.Equals(PlayerPrefs.GetString(AppConstants.NickTag)));
                List <AutomationController> automations       = AutomationsController.instance.automations.FindAll(x => x.automationData.nick.Equals(PlayerPrefs.GetString(AppConstants.NickTag)));
                List <TreeController> trees = TreesController.instance.trees.FindAll(x => x.treeData.nick.Equals(PlayerPrefs.GetString(AppConstants.NickTag)));
                List <WellController> wells = WellsController.instance.wells.FindAll(x => x.wellData.nick.Equals(PlayerPrefs.GetString(AppConstants.NickTag)));

                int energySpent  = 0;
                int biomassSpent = 0;
                int gadgetsSpent = 0;
                int fuelSpent    = 0;

                foreach (GeneratorController generator in generators)
                {
                    if (PlayerPrefs.GetInt(AppConstants.GeneratorCreatedTag) == 1)
                    {
                        for (int i = 1; i < generator.generatorData.level; i++)
                        {
                            energySpent += (i * AppConstants.GeneratorUpgradeConstant);
                        }
                    }
                    if (PlayerPrefs.GetInt(AppConstants.BatteryCreatedTag) == 1)
                    {
                        energySpent += AppConstants.GeneratorBatteryPurchaseCost;
                        for (int i = 1; i < generator.generatorData.batteryLevel; i++)
                        {
                            energySpent += (i * AppConstants.GeneratorBatteryUpgradeConstant);
                        }
                    }
                    if (PlayerPrefs.GetInt(AppConstants.ConverterCreatedTag) == 1)
                    {
                        energySpent += AppConstants.GeneratorConverterPurchaseCost;
                        for (int i = 1; i < generator.generatorData.converterLevel; i++)
                        {
                            energySpent += (i * AppConstants.GeneratorConverterUpgradeConstant);
                        }
                    }
                }

                gadgetsSpent += (automations.Count * AppConstants.AutomationPurchaseCost);

                biomassSpent += (trees.Count * AppConstants.TreePurchaseCost);

                fuelSpent += (wells.Count * AppConstants.WellPurchaseCost);
                foreach (WellController well in wells)
                {
                    for (int i = 1; i < well.wellData.level; i++)
                    {
                        fuelSpent += (i * AppConstants.WellUpgradeCostConstant);
                    }
                }

                int projectObjectsTotalCostSingleResource = 0;
                for (int i = 0; i < projectObjects.Count; i++)
                {
                    projectObjectsTotalCostSingleResource += ((i + 1) * AppConstants.ProjectObjectPurchaseCost);
                }
                if (PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.NATURE)
                {
                    biomassSpent += projectObjectsTotalCostSingleResource;
                    gadgetsSpent += projectObjectsTotalCostSingleResource;
                }
                else if (PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.COMMERCY)
                {
                    gadgetsSpent += projectObjectsTotalCostSingleResource;
                    fuelSpent    += projectObjectsTotalCostSingleResource;
                }
                else
                {
                    fuelSpent    += projectObjectsTotalCostSingleResource;
                    biomassSpent += projectObjectsTotalCostSingleResource;
                }

                int energyAdded = Mathf.RoundToInt((float)energySpent / AppConstants.PatchRemoveReturnedResourcesCoeff);
                ResourcesController.instance.AddEnergy(energyAdded);
                int biomassAdded = Mathf.RoundToInt((float)biomassSpent / AppConstants.PatchRemoveReturnedResourcesCoeff);
                ResourcesController.instance.AddBiomass(biomassAdded);
                int gadgetsAdded = Mathf.RoundToInt((float)gadgetsSpent / AppConstants.PatchRemoveReturnedResourcesCoeff);
                ResourcesController.instance.AddGadgets(gadgetsAdded);
                int fuelAdded = Mathf.RoundToInt((float)fuelSpent / AppConstants.PatchRemoveReturnedResourcesCoeff);
                ResourcesController.instance.AddFuel(fuelAdded);

                InfoPopup.instance.Open(() => { StartCoroutine(RestartSceneCoroutine()); InfoPopup.instance.Close(); }, "Usunięto wszystkie Twoje obiekty. Dodano " + energyAdded + " energii, " + biomassAdded + " biomasy, " + gadgetsAdded + " gadżetów i " + fuelAdded + " paliwa");
            }
            else
            {
                Debug.Log(response);
                BannerController.instance.showBannerWithText(true, "Błąd serwera :(", true);
            }
        });
    }
Ejemplo n.º 15
0
    // Highlighting next patch edge (border purchasing)
    public void SwitchToNextEdge()
    {
        PatchController userPatch = PatchesController.instance.patches.Find(x => x.patchData.nick == PlayerPrefs.GetString(AppConstants.NickTag));

        userPatch.HighlightNextEdge();
    }
    // Creating project object method
    public void CreateProjectObjectAtUserPosition(bool confirmed = false)
    {
        if (DownButtonController.instance.standardMenuButtonsVisible)
        {
            DownButtonController.instance.ToggleStandardMenu();
        }

        PatchController userPatch    = PatchesController.instance.patches.Find(x => x.patchData.nick == PlayerPrefs.GetString(AppConstants.NickTag));
        List <Vector2>  patchPolygon = new List <Vector2>();

        foreach (Vector3 patchPolygonVertex in userPatch.patchData.flags)
        {
            patchPolygon.Add(new Vector2(patchPolygonVertex.x, patchPolygonVertex.z));
        }
        if (userPatch == null || !Geometry.PolygonContainsPoint(patchPolygon, new Vector2(PlayerColliderController.instance.transform.position.x, PlayerColliderController.instance.transform.position.z)))
        {
            string objectName = PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.NATURE ? "regulator klimatu" : PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.COMMERCY ? "sztuczną inteligencję" : "rafinerię";
            BannerController.instance.showBannerWithText(true, "Możesz umieścić " + objectName + " tylko w obrębie własnego rewiru", true);
            return;
        }
        if (!PlayerColliderController.instance.CanPlaceObjectHere())
        {
            BannerController.instance.showBannerWithText(true, "Zbyt blisko innego obiektu! Oddal się kilka metrów", true);
            return;
        }

        int    projectObjectCost = (PlayerPrefs.GetInt(AppConstants.ProjectObjectsCountTag) + 1) * AppConstants.ProjectObjectPurchaseCost;
        string costResource1     = PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.NATURE ? "biomasy" : PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.COMMERCY ? "gadżetów" : "paliwa";
        string costResource2     = PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.NATURE ? "gadżetów" : PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.COMMERCY ? "paliwa" : "biomasy";

        if (!confirmed)
        {
            string objectName = PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.NATURE ? "regulator klimatu" : PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.COMMERCY ? "sztuczną inteligencję" : "rafinerię";
            ConfirmationPopup.instance.Open(() => { CreateProjectObjectAtUserPosition(true); ConfirmationPopup.instance.Close(); }, () => { ConfirmationPopup.instance.Close(); }, "Czy chcesz tutaj umieścić  " + objectName + " za " + projectObjectCost + " " + costResource1 + " oraz " + projectObjectCost + " " + costResource2 + " ?");
            return;
        }
        if (PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.NATURE && (PlayerPrefs.GetFloat(AppConstants.BiomassTag) < projectObjectCost || PlayerPrefs.GetFloat(AppConstants.GadgetsTag) < projectObjectCost))
        {
            BannerController.instance.showBannerWithText(true, "Masz zbyt mało zasobów", true);
            return;
        }
        if (PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.COMMERCY && (PlayerPrefs.GetFloat(AppConstants.GadgetsTag) < projectObjectCost || PlayerPrefs.GetFloat(AppConstants.FuelTag) < projectObjectCost))
        {
            BannerController.instance.showBannerWithText(true, "Masz zbyt mało zasobów", true);
            return;
        }
        if (PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.INDUSTRY && (PlayerPrefs.GetFloat(AppConstants.FuelTag) < projectObjectCost || PlayerPrefs.GetFloat(AppConstants.BiomassTag) < projectObjectCost))
        {
            BannerController.instance.showBannerWithText(true, "Masz zbyt mało zasobów", true);
            return;
        }
        if (PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.NATURE)
        {
            ResourcesController.instance.AddBiomass(-projectObjectCost);
            ResourcesController.instance.AddGadgets(-projectObjectCost);
        }
        if (PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.COMMERCY)
        {
            ResourcesController.instance.AddGadgets(-projectObjectCost);
            ResourcesController.instance.AddFuel(-projectObjectCost);
        }
        if (PlayerPrefs.GetInt(AppConstants.FractionTag) == (int)AppConstants.Fraction.INDUSTRY)
        {
            ResourcesController.instance.AddFuel(-projectObjectCost);
            ResourcesController.instance.AddBiomass(-projectObjectCost);
        }

        Utils.Web.PostValues(AppConstants.AddProjectObjectUrl, new List <KeyValuePair <string, string> >(new KeyValuePair <string, string>[] {
            new KeyValuePair <string, string>("USER_ID", AppConstants.UUID + AppConstants.PlayerDeviceIdentifierID),
            new KeyValuePair <string, string>("LAT", GoShared.Coordinates.convertVectorToCoordinates(PlayerColliderController.instance.transform.position).latitude.ToString()),
            new KeyValuePair <string, string>("LON", GoShared.Coordinates.convertVectorToCoordinates(PlayerColliderController.instance.transform.position).longitude.ToString())
        }), (code, response) =>
        {
            if (code == 200)
            {
                long id = Utils.JSON.GetLong(Utils.JSON.GetDictionary(response), "id");
                ProjectObject projectObject = new ProjectObject(id, PlayerColliderController.instance.transform.position, PlayerPrefs.GetString(AppConstants.NickTag), PlayerPrefs.GetInt(AppConstants.FractionTag));
                AddProjectObject(projectObject);
                PlayerPrefs.SetInt(AppConstants.ProjectObjectsCountTag, (PlayerPrefs.GetInt(AppConstants.ProjectObjectsCountTag) + 1));
                PlayerPrefs.Save();
            }
            else
            {
                Debug.Log(response);
                BannerController.instance.showBannerWithText(true, "Błąd serwera :(", true);
            }
        });
    }
Ejemplo n.º 17
0
    // Destroying patch edge highlight
    public void DestroyPatchHighlight()
    {
        PatchController userPatch = PatchesController.instance.patches.Find(x => x.patchData.nick == PlayerPrefs.GetString(AppConstants.NickTag));

        userPatch.RemoveHighlight();
    }
Ejemplo n.º 18
0
        public static void DownloadAndInstall(Mod m)
        {
            string temppath = System.IO.Path.Combine(Sys.Settings.LibraryLocation, "temp");

            System.IO.Directory.CreateDirectory(temppath);

            var install = Sys.Library.GetItem(m.ID);

            if (install != null)
            {
                var patches = m.GetPatchesFromTo(install.LatestInstalled.VersionDetails.Version, m.LatestVersion.Version);
                if (patches.Any())
                {
                    string pfile = String.Format("{0}_{1}_{2}.irop", m.ID, SafeStr(m.Name), m.LatestVersion.Version);
                    Sys.SetStatus(m.ID, ModStatus.Downloading);
                    Sys.Downloads.Download(patches.Select(p => p.Link),
                                           System.IO.Path.Combine(temppath, pfile),
                                           "Downloading " + m.Name,
                                           new PatchModProcedure()
                    {
                        File = pfile, Install = install, Mod = m
                    },
                                           () => Sys.RevertStatus(m.ID)
                                           );
                    return;
                }
            }

            string file = String.Format("{0}_{1}_{2}.iro", m.ID, SafeStr(m.Name), m.LatestVersion.Version);

            Sys.SetStatus(m.ID, ModStatus.Downloading);

            if (m.LatestVersion.PatchLinks.Any())
            {
                PatchController pc = new PatchController(m.LatestVersion.PatchLinks.Count);

                Sys.Downloads.Download(m.LatestVersion.Links,
                                       System.IO.Path.Combine(temppath, file),
                                       "Downloading " + m.Name,
                                       new DownloadThenPatchProcedure()
                {
                    File = file, Mod = m, Controller = pc
                },
                                       () => Sys.RevertStatus(m.ID)
                                       );
                int pCount = 0;
                foreach (string p in m.LatestVersion.PatchLinks)
                {
                    string pfile = String.Format("{0}_{1}_{2}_patch{3}.iro", m.ID, SafeStr(m.Name), m.LatestVersion.Version, pCount);
                    pc.PatchFiles.Add(pfile);
                    Sys.Downloads.Download(p,
                                           System.IO.Path.Combine(temppath, pfile),
                                           "Downloading " + m.Name + " patch " + pCount,
                                           new DownloadPatchProcedure()
                    {
                        File = pfile, Controller = pc
                    },
                                           () => {
                        pc.PatchFailed();
                        Sys.RevertStatus(m.ID);
                    }
                                           );

                    pCount++;
                }
            }
            else
            {
                Sys.Downloads.Download(m.LatestVersion.Links,
                                       System.IO.Path.Combine(temppath, file),
                                       "Downloading " + m.Name,
                                       new InstallModProcedure()
                {
                    File = file, Mod = m, ExtractSubFolder = m.LatestVersion.ExtractSubFolder, ExtractInto = m.LatestVersion.ExtractInto
                },
                                       () => Sys.RevertStatus(m.ID)
                                       );
            }
        }