示例#1
0
 public bool buy(ShiftoriumUpgrade upgrade)
 {
     foreach (var upg in getAvailable())
     {
         if (upg.ID == upgrade && SaveSystem.CurrentSave.Codepoints >= upg.Cost)
         {
             return(true);
         }
     }
     return(false);
 }
示例#2
0
 public bool DependenciesInstalled(ShiftoriumUpgrade upg)
 {
     string[] split = upg.Dependencies.Split(';');
     foreach (var u in split)
     {
         if (!u.StartsWith("appscape_handled"))
         {
             if (!Shiftorium.UpgradeInstalled(u))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
示例#3
0
        public List <ShiftoriumUpgrade> GetDefaults()
        {
            var defaultList = JsonConvert.DeserializeObject <List <ShiftoriumUpgrade> >(Properties.Resources.Shiftorium);

            foreach (var type in ReflectMan.Types)
            {
                var attribs = type.GetCustomAttributes(false);
                var attrib  = attribs.FirstOrDefault(x => x is AppscapeEntryAttribute) as AppscapeEntryAttribute;
                if (attrib != null)
                {
                    var upgrade = new ShiftoriumUpgrade
                    {
                        Id           = attrib.Upgrade,
                        Name         = attrib.Name,
                        Description  = attrib.Description,
                        Cost         = attrib.Cost,
                        Category     = attrib.Category,
                        Dependencies = (string.IsNullOrWhiteSpace(attrib.DependencyString)) ? "appscape_handled_nodisplay" : "appscape_handled_nodisplay;" + attrib.DependencyString
                    };
                    defaultList.Add(upgrade);
                }

                var sattrib = attribs.FirstOrDefault(x => x is StpContents) as StpContents;
                if (sattrib != null)
                {
                    var upgrade = new ShiftoriumUpgrade
                    {
                        Id           = sattrib.Upgrade,
                        Name         = sattrib.Name,
                        Description  = "This is a hidden dummy upgrade for the .stp file installation attribute \"" + sattrib.Name + "\".",
                        Cost         = 0,
                        Category     = "If this is shown, there's a bug in the Shiftorium Provider or the user is a supreme Shifter.",
                        Dependencies = "dummy_nodisplay"
                    };
                    defaultList.Add(upgrade);
                }
            }
            return(defaultList);
        }
示例#4
0
        public void ViewMoreInfo(ShiftoriumUpgrade upg)
        {
            lbtitle.Text = upg.Name;
            pnlappslist.Controls.Clear();

            var cp_display = new Panel();

            cp_display.Height = 30;
            cp_display.Dock   = DockStyle.Bottom;
            pnlappslist.Controls.Add(cp_display);
            cp_display.Show();

            var cp_value = new Label();

            if (Shiftorium.UpgradeInstalled(upg.ID))
            {
                cp_value.Text = "Already Purchased.";
            }
            else
            {
                cp_value.Text = $"{upg.Cost} CP";
            }
            cp_value.AutoSize = true;
            cp_value.Top      = (cp_display.Height - cp_value.Height) / 2;
            cp_value.Left     = 5;
            cp_display.Controls.Add(cp_value);
            cp_value.Show();


            if (cp_value.Text != "Already Purchased.")
            {
                var more_info = new Button();
                more_info.Text   = "Buy";
                more_info.Click += (o, a) =>
                {
                    //Detect if dependencies are installed.
                    if (DependenciesInstalled(upg))
                    {
                        //Detect sufficient codepoints
                        if (SaveSystem.CurrentSave.Codepoints >= upg.Cost)
                        {
                            Infobox.PromptYesNo("Confirm Purchase", "Do you want to purchase " + upg.Name + " from Appscape for " + upg.Cost.ToString() + " Codepoints?", (result) =>
                            {
                                if (result == true)
                                {
                                    SaveSystem.CurrentSave.Codepoints -= upg.Cost;
                                    foreach (var type in ReflectMan.Types)
                                    {
                                        var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is AppscapeEntryAttribute) as AppscapeEntryAttribute;
                                        if (attrib != null)
                                        {
                                            if (attrib.Name == upg.Name)
                                            {
                                                var installer    = new Applications.Installer();
                                                var installation = new AppscapeInstallation(upg.Name, attrib.DownloadSize, upg.ID);
                                                AppearanceManager.SetupWindow(installer);
                                                installer.InitiateInstall(installation);
                                                return;
                                            }
                                        }
                                    }
                                }
                            });
                        }
                        else
                        {
                            Infobox.Show("Not enough Codepoints", "You do not have enough Codepoints to buy this package.");
                        }
                    }
                    else
                    {
                        Infobox.Show("Missing dependencies", "You are missing some Shiftorium upgrades that this package requires. Please upgrade your system and try again!");
                    }
                };
                more_info.AutoSize     = false;
                more_info.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                more_info.Top          = (cp_display.Height - more_info.Height) / 2;
                more_info.Left         = cp_display.Width - more_info.Width - 5;
                cp_display.Controls.Add(more_info);
                more_info.Show();
                ControlManager.SetupControls(pnlappslist);
            }

            var desc = new Label();

            desc.Text     = upg.Description;
            desc.AutoSize = false;
            desc.Dock     = DockStyle.Fill;
            pnlappslist.Controls.Add(desc);
            desc.Show();
            desc.BringToFront();

            desc.Text += Environment.NewLine + Environment.NewLine + "Dependencies:" + Environment.NewLine;
            string[] deplist = upg.Dependencies.Split(';');
            if (deplist.Length > 1)
            {
                for (int i = 1; i < deplist.Length; i++)
                {
                    ShiftoriumUpgrade dep = Shiftorium.GetDefaults().FirstOrDefault(x => x.ID == deplist[i]);
                    if (dep != null)
                    {
                        desc.Text += $" - {dep.Name}{Environment.NewLine}";
                    }
                }
            }
            else
            {
                desc.Text += " - No dependencies.";
            }
        }