From 505073b6938fc8be8b91807a69bd67e45ed4382f Mon Sep 17 00:00:00 2001 From: Michael VanOverbeek Date: Mon, 29 May 2017 16:41:49 +0000 Subject: Fix server-side crash when kiading revoked api keys --- ShiftOS.Objects/Save.cs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'ShiftOS.Objects/Save.cs') diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index f4e1e09..8675a35 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -47,24 +47,27 @@ namespace ShiftOS.Objects { get { - if (!string.IsNullOrWhiteSpace(UniteAuthToken)) + try { var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); return uc.GetCodepoints(); } - else + catch + { return _cp; + } } set { - if (!string.IsNullOrWhiteSpace(UniteAuthToken)) - { - var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); - uc.SetCodepoints(value); - } - else - _cp = value; - + try + { + var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); + uc.SetCodepoints(value); + } + catch + { + _cp = value; + } } } -- cgit v1.2.3 From 37ac4c684ce3904c5ec614362ed99bb9867ca0f3 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 29 May 2017 20:08:30 -0400 Subject: It's amazing what talking to Rylan can do to an integer datatype. --- ShiftOS.Objects/EngineShiftnetSubscription.cs | 2 +- ShiftOS.Objects/Save.cs | 4 ++-- ShiftOS.Objects/Shop.cs | 2 +- ShiftOS.Objects/UniteClient.cs | 12 ++++++------ ShiftOS.WinForms/Applications/Pong.cs | 20 ++++++++++---------- ShiftOS.WinForms/Applications/ShiftLetters.cs | 2 +- ShiftOS.WinForms/Applications/ShiftLotto.cs | 4 ++-- ShiftOS.WinForms/Applications/ShiftSweeper.cs | 8 ++++---- ShiftOS.WinForms/Applications/Shifter.cs | 2 +- ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs | 4 ++-- ShiftOS.WinForms/Applications/ShopItemCreator.cs | 4 ++-- ShiftOS.WinForms/HackerCommands.cs | 2 +- ShiftOS.WinForms/JobTasks.cs | 4 ++-- ShiftOS.WinForms/ShiftnetSites/AppscapeMain.cs | 4 ++-- ShiftOS.WinForms/WinformsDesktop.cs | 2 +- ShiftOS_TheReturn/Commands.cs | 4 ++-- ShiftOS_TheReturn/SaveSystem.cs | 4 ++-- ShiftOS_TheReturn/Scripting.cs | 4 ++-- ShiftOS_TheReturn/ServerManager.cs | 2 +- ShiftOS_TheReturn/Shiftorium.cs | 10 +++++----- 20 files changed, 50 insertions(+), 50 deletions(-) (limited to 'ShiftOS.Objects/Save.cs') diff --git a/ShiftOS.Objects/EngineShiftnetSubscription.cs b/ShiftOS.Objects/EngineShiftnetSubscription.cs index 1296a98..c319f18 100644 --- a/ShiftOS.Objects/EngineShiftnetSubscription.cs +++ b/ShiftOS.Objects/EngineShiftnetSubscription.cs @@ -10,7 +10,7 @@ namespace ShiftOS.Objects { public string Name { get; set; } public string Description { get; set; } - public int CostPerMonth { get; set; } + public uint CostPerMonth { get; set; } public int DownloadSpeed { get; set; } public string Company { get; set; } } diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index 8675a35..0fef7b3 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -41,9 +41,9 @@ namespace ShiftOS.Objects [Obsolete("This save variable is no longer used in Beta 2.4 and above of ShiftOS. Please use ShiftOS.Engine.SaveSystem.CurrentUser.Username to access the current user's username.")] public string Username { get; set; } - private long _cp = 0; + private ulong _cp = 0; - public long Codepoints + public ulong Codepoints { get { diff --git a/ShiftOS.Objects/Shop.cs b/ShiftOS.Objects/Shop.cs index 65f5746..c603523 100644 --- a/ShiftOS.Objects/Shop.cs +++ b/ShiftOS.Objects/Shop.cs @@ -42,7 +42,7 @@ namespace ShiftOS.Objects { public string Name { get; set; } public string Description { get; set; } - public int Cost { get; set; } + public ulong Cost { get; set; } public int FileType { get; set; } public byte[] MUDFile { get; set; } } diff --git a/ShiftOS.Objects/UniteClient.cs b/ShiftOS.Objects/UniteClient.cs index d8e34b7..ccd721b 100644 --- a/ShiftOS.Objects/UniteClient.cs +++ b/ShiftOS.Objects/UniteClient.cs @@ -83,9 +83,9 @@ namespace ShiftOS.Unite /// Get the Pong codepoint highscore for the current user. /// /// The amount of Codepoints returned by the server - public int GetPongCP() + public ulong GetPongCP() { - return Convert.ToInt32(MakeCall("/API/GetPongCP")); + return Convert.ToUInt64(MakeCall("/API/GetPongCP")); } /// @@ -110,7 +110,7 @@ namespace ShiftOS.Unite /// Set the pong Codepoints record for the user /// /// The amount of Codepoints to set the record to - public void SetPongCP(int value) + public void SetPongCP(ulong value) { MakeCall("/API/SetPongCP/" + value.ToString()); } @@ -182,16 +182,16 @@ namespace ShiftOS.Unite /// Get the user's codepoints. /// /// The amount of codepoints stored on the server for this user. - public long GetCodepoints() + public ulong GetCodepoints() { - return Convert.ToInt64(MakeCall("/API/GetCodepoints")); + return Convert.ToUInt64(MakeCall("/API/GetCodepoints")); } /// /// Set the user's codepoints. /// /// The amount of codepoints to set the user's codepoints value to. - public void SetCodepoints(long value) + public void SetCodepoints(ulong value) { MakeCall("/API/SetCodepoints/" + value.ToString()); } diff --git a/ShiftOS.WinForms/Applications/Pong.cs b/ShiftOS.WinForms/Applications/Pong.cs index 84177b7..6d81c64 100644 --- a/ShiftOS.WinForms/Applications/Pong.cs +++ b/ShiftOS.WinForms/Applications/Pong.cs @@ -58,10 +58,10 @@ namespace ShiftOS.WinForms.Applications double incrementy = 0.2; int levelxspeed = 3; int levelyspeed = 3; - int beatairewardtotal; - int beataireward = 1; - int[] levelrewards = new int[50]; - int totalreward; + ulong beatairewardtotal; + ulong beataireward = 1; + ulong[] levelrewards = new ulong[50]; + ulong totalreward; int countdown = 3; bool aiShouldIsbeEnabled = true; @@ -297,11 +297,11 @@ namespace ShiftOS.WinForms.Applications lblmissedout.Text = Localization.Parse("{YOU_MISSED_OUT_ON}:") + Environment.NewLine + lblstatscodepoints.Text.Replace(Localization.Parse("{CODEPOINTS}: "), "") + Localization.Parse(" {CODEPOINTS}"); if (ShiftoriumFrontend.UpgradeInstalled("pong_upgrade_2")) { - totalreward = levelrewards[level - 1] + beatairewardtotal; + totalreward = (ulong)(levelrewards[level - 1] + beatairewardtotal); double onePercent = (totalreward / 100); lblbutyougained.Show(); lblbutyougained.Text = Localization.Parse("{BUT_YOU_GAINED}:") + Environment.NewLine + onePercent.ToString("") + (Localization.Parse(" {CODEPOINTS}")); - SaveSystem.TransferCodepointsFrom("pong", (totalreward / 100)); + SaveSystem.TransferCodepointsFrom("pong", (ulong)(totalreward / 100)); } else { @@ -715,10 +715,10 @@ namespace ShiftOS.WinForms.Applications { if (ShiftoriumFrontend.UpgradeInstalled("pong_upgrade")) { - beataireward = level * 10; + beataireward = (ulong)(level * 10); } else { - beataireward = level * 5; + beataireward = (ulong)(level * 5); } } else @@ -726,11 +726,11 @@ namespace ShiftOS.WinForms.Applications if (ShiftoriumFrontend.UpgradeInstalled("pong_upgrade")) { double br = levelrewards[level - 1] / 10; - beataireward = (int)Math.Round(br) * 10; + beataireward = (ulong)Math.Round(br) * 10; } else { double br = levelrewards[level - 1] / 10; - beataireward = (int)Math.Round(br) * 5; + beataireward = (ulong)Math.Round(br) * 5; } } diff --git a/ShiftOS.WinForms/Applications/ShiftLetters.cs b/ShiftOS.WinForms/Applications/ShiftLetters.cs index 42e19f8..0e9f74a 100644 --- a/ShiftOS.WinForms/Applications/ShiftLetters.cs +++ b/ShiftOS.WinForms/Applications/ShiftLetters.cs @@ -217,7 +217,7 @@ namespace ShiftOS.WinForms.Applications if (!lblword.Text.Contains("_")) { int oldlives = lives; - int cp = (word.Length * oldlives) * 2; //drunky michael made this 5x... + ulong cp = (ulong)(word.Length * oldlives) * 2; //drunky michael made this 5x... SaveSystem.TransferCodepointsFrom("shiftletters", cp); StartGame(); } diff --git a/ShiftOS.WinForms/Applications/ShiftLotto.cs b/ShiftOS.WinForms/Applications/ShiftLotto.cs index 5ab8154..3f940c7 100644 --- a/ShiftOS.WinForms/Applications/ShiftLotto.cs +++ b/ShiftOS.WinForms/Applications/ShiftLotto.cs @@ -88,7 +88,7 @@ namespace ShiftOS.WinForms.Applications } else { - if (SaveSystem.CurrentSave.Codepoints - (codePoints * difficulty) <= 0) + if (SaveSystem.CurrentSave.Codepoints - (ulong)(codePoints * difficulty) <= 0) { Infobox.Show("Not enough Codepoints", "You do not have enough Codepoints to gamble this amount!"); } @@ -102,7 +102,7 @@ namespace ShiftOS.WinForms.Applications int winningNumber = rnd.Next(0, difficulty); // Multiply CodePoints * Difficulty - int jackpot = codePoints * difficulty; + ulong jackpot = (ulong)(codePoints * difficulty); // Test the random ints if (guessedNumber == winningNumber) diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index f23ed73..772ec26 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -300,12 +300,12 @@ namespace ShiftOS.WinForms.Applications { } public void winGame() { - int cp = 0; - int origminecount = gameBombCount * 10; + ulong cp = 0; + ulong origminecount = (ulong)(gameBombCount * 10); if (minetimer < 31) cp = (origminecount * 3); - else if (minetimer < 61) cp = (Int32)(origminecount * 2.5); + else if (minetimer < 61) cp = (ulong)(origminecount * 2.5); else if (minetimer < 91) cp = (origminecount * 2); - else if (minetimer < 121) cp = (Int32)(origminecount * 1.5); + else if (minetimer < 121) cp = (ulong)(origminecount * 1.5); else if (minetimer > 120) cp = (origminecount * 1); SaveSystem.TransferCodepointsFrom("shiftsweeper", cp); panelGameStatus.Image = Properties.Resources.SweeperWinFace; diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index 1a59c80..3b3a4f1 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -391,7 +391,7 @@ namespace ShiftOS.WinForms.Applications } - public int CodepointValue = 0; + public uint CodepointValue = 0; public List settings = new List(); public Skin LoadedSkin = null; diff --git a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs index 08e6c8f..d6b014d 100644 --- a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs +++ b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs @@ -213,9 +213,9 @@ namespace ShiftOS.WinForms.Applications private void btnbuy_Click(object sender, EventArgs e) { - long cpCost = 0; + ulong cpCost = 0; backend.Silent = true; - Dictionary UpgradesToBuy = new Dictionary(); + Dictionary UpgradesToBuy = new Dictionary(); foreach (var itm in lbupgrades.SelectedItems) { cpCost += upgrades[itm.ToString()].Cost; diff --git a/ShiftOS.WinForms/Applications/ShopItemCreator.cs b/ShiftOS.WinForms/Applications/ShopItemCreator.cs index 61e7491..d2836ee 100644 --- a/ShiftOS.WinForms/Applications/ShopItemCreator.cs +++ b/ShiftOS.WinForms/Applications/ShopItemCreator.cs @@ -73,7 +73,7 @@ namespace ShiftOS.WinForms.Applications Infobox.Show("No file chosen.", "Please select a file to sell."); return; } - Item.Cost = Convert.ToInt32(txtcost.Text); + Item.Cost = Convert.ToUInt64(txtcost.Text); Item.Description = txtdescription.Text; Item.Name = txtitemname.Text; Callback?.Invoke(Item); @@ -101,7 +101,7 @@ namespace ShiftOS.WinForms.Applications { try { - Item.Cost = Convert.ToInt32(txtcost.Text); + Item.Cost = Convert.ToUInt64(txtcost.Text); } catch { diff --git a/ShiftOS.WinForms/HackerCommands.cs b/ShiftOS.WinForms/HackerCommands.cs index 47b486d..f467eb2 100644 --- a/ShiftOS.WinForms/HackerCommands.cs +++ b/ShiftOS.WinForms/HackerCommands.cs @@ -504,7 +504,7 @@ namespace ShiftOS.WinForms string usr = args["user"].ToString(); string sys = args["sys"].ToString(); string pass = args["pass"].ToString(); - long amount = (long)args["amount"]; + ulong amount = (ulong)args["amount"]; if(amount < 0) { Console.WriteLine("--invalid codepoint amount - halting..."); diff --git a/ShiftOS.WinForms/JobTasks.cs b/ShiftOS.WinForms/JobTasks.cs index 622e287..d862961 100644 --- a/ShiftOS.WinForms/JobTasks.cs +++ b/ShiftOS.WinForms/JobTasks.cs @@ -35,12 +35,12 @@ namespace ShiftOS.WinForms { public class AcquireCodepointsJobTask : JobTask { - public AcquireCodepointsJobTask(int amount) + public AcquireCodepointsJobTask(uint amount) { CodepointsRequired = SaveSystem.CurrentSave.Codepoints + amount; } - public long CodepointsRequired { get; private set; } + public ulong CodepointsRequired { get; private set; } public override bool IsComplete { diff --git a/ShiftOS.WinForms/ShiftnetSites/AppscapeMain.cs b/ShiftOS.WinForms/ShiftnetSites/AppscapeMain.cs index fa575f4..c7830d0 100644 --- a/ShiftOS.WinForms/ShiftnetSites/AppscapeMain.cs +++ b/ShiftOS.WinForms/ShiftnetSites/AppscapeMain.cs @@ -372,7 +372,7 @@ namespace ShiftOS.WinForms /// public class AppscapeEntryAttribute : RequiresUpgradeAttribute { - public AppscapeEntryAttribute(string name, string description, int downloadSize, long cost, string dependencies = "", string category = "Misc") : base(name.ToLower().Replace(' ', '_')) + public AppscapeEntryAttribute(string name, string description, int downloadSize, ulong cost, string dependencies = "", string category = "Misc") : base(name.ToLower().Replace(' ', '_')) { Name = name; Description = description; @@ -385,7 +385,7 @@ namespace ShiftOS.WinForms public string Name { get; private set; } public string Description { get; private set; } public string Category { get; private set; } - public long Cost { get; private set; } + public ulong Cost { get; private set; } public string DependencyString { get; private set; } public int DownloadSize { get; private set; } } diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs index 85eab55..95e7c1a 100644 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ b/ShiftOS.WinForms/WinformsDesktop.cs @@ -192,7 +192,7 @@ namespace ShiftOS.WinForms SetupDesktop(); }; - long lastcp = 0; + ulong lastcp = 0; var storythread = new Thread(() => { diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index b97cd1d..ec89539 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -311,7 +311,7 @@ namespace ShiftOS.Engine if (args.ContainsKey("amount")) try { - long codepointsToAdd = Convert.ToInt64(args["amount"].ToString()); + ulong codepointsToAdd = Convert.ToUInt64(args["amount"].ToString()); SaveSystem.CurrentSave.Codepoints += codepointsToAdd; return true; } @@ -639,7 +639,7 @@ shiftorium.buy{{upgrade:""{upg.ID}""}}"); cat = args["cat"].ToString(); } - Dictionary upgrades = new Dictionary(); + Dictionary upgrades = new Dictionary(); int maxLength = 5; IEnumerable upglist = Shiftorium.GetAvailable(); diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index d1b92fd..395db85 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -480,7 +480,7 @@ namespace ShiftOS.Engine /// Deducts a set amount of Codepoints from the save file... and sends them to a place where they'll never be seen again. /// /// The amount of Codepoints to deduct. - public static void TransferCodepointsToVoid(long amount) + public static void TransferCodepointsToVoid(ulong amount) { if (amount < 0) throw new ArgumentOutOfRangeException("We see what you did there. Trying to pull Codepoints from the void? That won't work."); @@ -584,7 +584,7 @@ namespace ShiftOS.Engine /// /// The character name /// The amount of Codepoints. - public static void TransferCodepointsFrom(string who, long amount) + public static void TransferCodepointsFrom(string who, ulong amount) { if (amount < 0) throw new ArgumentOutOfRangeException("We see what you did there... You can't just give a fake character Codepoints like that. It's better if you transfer them to the void."); diff --git a/ShiftOS_TheReturn/Scripting.cs b/ShiftOS_TheReturn/Scripting.cs index 61c6676..5021f50 100644 --- a/ShiftOS_TheReturn/Scripting.cs +++ b/ShiftOS_TheReturn/Scripting.cs @@ -444,7 +444,7 @@ end"); /// Retrieves the user's Codepoints from the save file. /// /// The user's Codepoints. - public long getCodepoints() { return SaveSystem.CurrentSave.Codepoints; } + public ulong getCodepoints() { return SaveSystem.CurrentSave.Codepoints; } /// /// Run a command in the Terminal. @@ -462,7 +462,7 @@ end"); /// Adds the specified amount of Codepoints to the save flie. /// /// The codepoints to add. - public void addCodepoints(int cp) + public void addCodepoints(uint cp) { if (cp > 100 || cp <= 0) { diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index abb674d..1439c0d 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -246,7 +246,7 @@ Ping: {ServerManager.DigitalSocietyPing} ms var args = JsonConvert.DeserializeObject>(msg.Contents); if(args["username"] as string == SaveSystem.CurrentUser.Username) { - SaveSystem.CurrentSave.Codepoints += (long)args["amount"]; + SaveSystem.CurrentSave.Codepoints += (ulong)args["amount"]; Desktop.InvokeOnWorkerThread(new Action(() => { Infobox.Show($"MUD Control Centre", $"Someone bought an item in your shop, and they have paid {args["amount"]}, and as such, you have been granted these Codepoints."); diff --git a/ShiftOS_TheReturn/Shiftorium.cs b/ShiftOS_TheReturn/Shiftorium.cs index bd7105f..975939f 100644 --- a/ShiftOS_TheReturn/Shiftorium.cs +++ b/ShiftOS_TheReturn/Shiftorium.cs @@ -112,7 +112,7 @@ namespace ShiftOS.Engine /// The upgrade ID to buy /// The amount of Codepoints to deduct /// True if the upgrade was installed successfully, false if the user didn't have enough Codepoints or the upgrade wasn' found. - public static bool Buy(string id, long cost) + public static bool Buy(string id, ulong cost) { if (SaveSystem.CurrentSave.Codepoints >= cost) { @@ -365,7 +365,7 @@ namespace ShiftOS.Engine /// /// The upgrade ID to search /// The codepoint value. - public static long GetCPValue(string id) + public static ulong GetCPValue(string id) { foreach (var upg in GetDefaults()) { @@ -520,7 +520,7 @@ namespace ShiftOS.Engine { public string Name { get; set; } public string Description { get; set; } - public long Cost { get; set; } + public ulong Cost { get; set; } public string ID { get { return (this.Id != null ? this.Id : (Name.ToLower().Replace(" ", "_"))); } } public string Id { get; set; } public string Category { get; set; } @@ -536,7 +536,7 @@ namespace ShiftOS.Engine public class ShiftoriumUpgradeAttribute : RequiresUpgradeAttribute { - public ShiftoriumUpgradeAttribute(string name, long cost, string desc, string dependencies, string category) : base(name.ToLower().Replace(" ", "_")) + public ShiftoriumUpgradeAttribute(string name, ulong cost, string desc, string dependencies, string category) : base(name.ToLower().Replace(" ", "_")) { Name = name; Description = desc; @@ -547,7 +547,7 @@ namespace ShiftOS.Engine public string Name { get; private set; } public string Description { get; private set; } - public long Cost { get; private set; } + public ulong Cost { get; private set; } public string Dependencies { get; private set; } public string Category { get; private set; } } -- cgit v1.2.3 From 11e80a6a6134e2cbee1041d6ddc95781a265bead Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 2 Jun 2017 11:38:38 -0400 Subject: fix the audio system --- ShiftOS.Objects/Save.cs | 6 ++-- ShiftOS.WinForms/AudioManager.cs | 51 +++++++++++++++++++++++--------- ShiftOS_TheReturn/AudioManager.cs | 61 +++++++++++++++++++++++++-------------- ShiftOS_TheReturn/Commands.cs | 40 +++++++++++++++++++------ 4 files changed, 111 insertions(+), 47 deletions(-) (limited to 'ShiftOS.Objects/Save.cs') diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index 0fef7b3..cbd77e2 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -34,9 +34,9 @@ namespace ShiftOS.Objects //Better to store this stuff server-side so we can do some neat stuff with hacking... public class Save { - - public int MusicVolume { get; set; } - public int SfxVolume { get; set; } + public bool MusicEnabled = true; + public bool SoundEnabled = true; + public int MusicVolume = 100; [Obsolete("This save variable is no longer used in Beta 2.4 and above of ShiftOS. Please use ShiftOS.Engine.SaveSystem.CurrentUser.Username to access the current user's username.")] public string Username { get; set; } diff --git a/ShiftOS.WinForms/AudioManager.cs b/ShiftOS.WinForms/AudioManager.cs index ec12614..afa0d78 100644 --- a/ShiftOS.WinForms/AudioManager.cs +++ b/ShiftOS.WinForms/AudioManager.cs @@ -88,23 +88,46 @@ namespace ShiftOS.WinForms }; while (shuttingDown == false) { - str = new MemoryStream(GetRandomSong()); - mp3 = new NAudio.Wave.Mp3FileReader(str); - o = new NAudio.Wave.WaveOut(); - o.Init(mp3); - bool c = false; - o.Play(); - o.PlaybackStopped += (s, a) => + if (Engine.SaveSystem.CurrentSave != null) { - c = true; - }; - while (!c) - { - try + if (Engine.SaveSystem.CurrentSave.MusicEnabled) + { + str = new MemoryStream(GetRandomSong()); + mp3 = new NAudio.Wave.Mp3FileReader(str); + o = new NAudio.Wave.WaveOut(); + o.Init(mp3); + bool c = false; + o.Play(); + o.PlaybackStopped += (s, a) => + { + c = true; + }; + + while (!c) + { + if (Engine.SaveSystem.CurrentSave.MusicEnabled) + { + try + { + o.Volume = (float)Engine.SaveSystem.CurrentSave.MusicVolume / 100; + } + catch { } + } + else + { + o.Stop(); + c = true; + } + Thread.Sleep(10); + } + } + else { - o.Volume = (float)Engine.SaveSystem.CurrentSave.MusicVolume / 100; + Thread.Sleep(10); } - catch { } + } + else + { Thread.Sleep(10); } } diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs index 553a1d9..0a1a210 100644 --- a/ShiftOS_TheReturn/AudioManager.cs +++ b/ShiftOS_TheReturn/AudioManager.cs @@ -83,21 +83,28 @@ namespace ShiftOS.Engine /// The file to play. public static void Play(string file) { - try + bool play = true; + float volume = 1f; + if (SaveSystem.CurrentSave != null) { - _reader = new AudioFileReader(file); - _out = new WaveOut(); - _out.Init(_reader); - _out.Play(); - if (SaveSystem.CurrentSave == null) - _out.Volume = 1.0f; - else - _out.Volume = (float)SaveSystem.CurrentSave.MusicVolume / 100; - _out.PlaybackStopped += (o, a) => { PlayCompleted?.Invoke(); }; + play = (SaveSystem.CurrentSave.SoundEnabled); + volume = (float)SaveSystem.CurrentSave.MusicVolume / 100f; } - catch(Exception ex) + if (play) { - Console.WriteLine("Audio error: " + ex.Message); + try + { + _reader = new AudioFileReader(file); + _out = new WaveOut(); + _out.Init(_reader); + _out.Volume = volume; + _out.Play(); + _out.PlaybackStopped += (o, a) => { PlayCompleted?.Invoke(); }; + } + catch (Exception ex) + { + Console.WriteLine("Audio error: " + ex.Message); + } } } @@ -107,15 +114,27 @@ namespace ShiftOS.Engine /// The stream to read from. public static void PlayStream(Stream str) { - var bytes = new byte[str.Length]; - str.Read(bytes, 0, bytes.Length); - ShiftOS.Engine.AudioManager.Stop(); - if (File.Exists("snd.wav")) - File.Delete("snd.wav"); - File.WriteAllBytes("snd.wav", bytes); - - ShiftOS.Engine.AudioManager.Play("snd.wav"); - + try + { + bool play = true; + float volume = 1f; + if (SaveSystem.CurrentSave != null) + { + play = (SaveSystem.CurrentSave.SoundEnabled); + volume = (float)SaveSystem.CurrentSave.MusicVolume / 100f; + } + if (play) + { + ShiftOS.Engine.AudioManager.Stop(); + _out = new WaveOut(); + var mp3 = new WaveFileReader(str); + _out.Init(mp3); + _out.Volume = volume; + _out.Play(); + _out.PlaybackStopped += (o, a) => { PlayCompleted?.Invoke(); }; + } + } + catch { } } public static event Action PlayCompleted; diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index ec89539..e379a50 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -383,26 +383,48 @@ namespace ShiftOS.Engine [Namespace("sos")] public static class ShiftOSCommands { - [Command("setsfxvolume", description = "Set the volume of various sound effects to a value between 1 and 100.")] + + [Command("setsfxenabled", description = "Set whether or not sound effects are enabled in the system.")] [RequiresArgument("value")] - public static bool SetSfxVolume(Dictionary args) + public static bool SetSfxEnabled(Dictionary args) { - int value = int.Parse(args["value"].ToString()); - if (value >= 0 && value <= 100) + try { - SaveSystem.CurrentSave.SfxVolume = value; + bool value = Convert.ToBoolean(args["value"].ToString()); + SaveSystem.CurrentSave.SoundEnabled = value; SaveSystem.SaveGame(); } - else + catch { - Console.WriteLine("Volume must be between 0 and 100!"); + Console.WriteLine("Error: Value must be either true or false."); } return true; } - [Command("setmusicvolume", description ="Set the music volume to a value between 1 and 100.")] + + + [Command("setmusicenabled", description = "Set whether or not music is enabled in the system.")] [RequiresArgument("value")] - public static bool SetMusicVolume(Dictionary args) + public static bool SetMusicEnabled(Dictionary args) + { + try + { + bool value = Convert.ToBoolean(args["value"].ToString()); + SaveSystem.CurrentSave.MusicEnabled = value; + SaveSystem.SaveGame(); + } + catch + { + Console.WriteLine("Error: Value must be either true or false."); + } + return true; + } + + + + [Command("setsfxvolume", description ="Set the system sound volume to a value between 1 and 100.")] + [RequiresArgument("value")] + public static bool SetSfxVolume(Dictionary args) { int value = int.Parse(args["value"].ToString()); if(value >= 0 && value <= 100) -- cgit v1.2.3 From 7fe5d790dc9d73056e86af8116ba4db9674fd612 Mon Sep 17 00:00:00 2001 From: RogueAI42 Date: Sun, 4 Jun 2017 01:29:21 +1000 Subject: fixed shiftorium just in time for chrimbus --- ShiftOS.Objects/Save.cs | 75 +++++++-- .../Applications/ShiftoriumFrontend.Designer.cs | 3 - .../Applications/ShiftoriumFrontend.cs | 186 ++++++++------------- ShiftOS_TheReturn/SaveSystem.cs | 11 +- 4 files changed, 136 insertions(+), 139 deletions(-) (limited to 'ShiftOS.Objects/Save.cs') diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index cbd77e2..e0282e8 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -26,8 +26,7 @@ using System; using System.Collections.Generic; using System.Dynamic; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Threading; namespace ShiftOS.Objects { @@ -41,33 +40,77 @@ namespace ShiftOS.Objects [Obsolete("This save variable is no longer used in Beta 2.4 and above of ShiftOS. Please use ShiftOS.Engine.SaveSystem.CurrentUser.Username to access the current user's username.")] public string Username { get; set; } - private ulong _cp = 0; + private List _setCpCallbacks = new List(); // everything in this list is called by Codepoints.set() and syncCp(). + private ulong _cp = 0; // locally cached codepoints counter + private Object _cpLock = new Object(); // locked when modifying or reading the codepoints counter + private Object _webLock = new Object(); // locked when communicating with the server + private Timer _updTimer; // timer to start a new sync thread every 5 minutes + + // Sync local Codepoints count with the server. + public void syncCp() + { + new Thread(() => + { + lock (_cpLock) + { + lock (_webLock) + { + var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); + _cp = uc.GetCodepoints(); + } + } + foreach (Action a in _setCpCallbacks) + a(); + }).Start(); + } + + // we have to write these wrapper functions so we can keep _setCpCallbacks private, + // so that it doesn't get serialised + public void addSetCpCallback(Action callback) + { + _setCpCallbacks.Add(callback); + } + + public void removeSetCpCallback(Action callback) + { + _setCpCallbacks.Remove(callback); + } public ulong Codepoints { get { - try - { - var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); - return uc.GetCodepoints(); - } - catch + if (_updTimer == null) + _updTimer = new Timer((o) => syncCp(), null, 0, 300000); + lock (_cpLock) { return _cp; } } set { - try + lock (_cpLock) + { + _cp = value; + new Thread(() => { - var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); - uc.SetCodepoints(value); - } - catch + lock (_webLock) + { + try + { + var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); + uc.SetCodepoints(value); + } + catch + { } + } + }) { - _cp = value; - } + IsBackground = false + }.Start(); + } + foreach (Action a in _setCpCallbacks) + a(); } } diff --git a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.Designer.cs b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.Designer.cs index dc107c4..e4e493e 100644 --- a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.Designer.cs +++ b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.Designer.cs @@ -189,7 +189,6 @@ namespace ShiftOS.WinForms.Applications this.lblcategorytext.TabIndex = 2; this.lblcategorytext.Text = "No Upgrades"; this.lblcategorytext.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.lblcategorytext.Click += new System.EventHandler(this.lblcategorytext_Click); // // btncat_forward // @@ -226,7 +225,6 @@ namespace ShiftOS.WinForms.Applications this.lbcodepoints.Size = new System.Drawing.Size(135, 13); this.lbcodepoints.TabIndex = 3; this.lbcodepoints.Text = "You have: %cp Codepoints"; - this.lbcodepoints.Click += new System.EventHandler(this.lbcodepoints_Click); // // label1 // @@ -280,7 +278,6 @@ namespace ShiftOS.WinForms.Applications this.ForeColor = System.Drawing.Color.LightGreen; this.Name = "ShiftoriumFrontend"; this.Size = new System.Drawing.Size(782, 427); - this.Load += new System.EventHandler(this.Shiftorium_Load); this.panel1.ResumeLayout(false); this.panel2.ResumeLayout(false); this.pnlupgradeactions.ResumeLayout(false); diff --git a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs index d6b014d..0ae0803 100644 --- a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs +++ b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs @@ -47,19 +47,22 @@ namespace ShiftOS.WinForms.Applications public partial class ShiftoriumFrontend : UserControl, IShiftOSWindow { public int CategoryId = 0; - public static System.Timers.Timer timer100; + private string[] cats = backend.GetCategories(); + private ShiftoriumUpgrade[] avail; + public void updatecounter() + { + Desktop.InvokeOnWorkerThread(() => { lbcodepoints.Text = $"You have {SaveSystem.CurrentSave.Codepoints} Codepoints."; }); + } + public ShiftoriumFrontend() { - cp_update = new System.Windows.Forms.Timer(); - cp_update.Tick += (o, a) => - { - lbcodepoints.Text = $"You have {SaveSystem.CurrentSave.Codepoints} Codepoints."; - }; - cp_update.Interval = 100; InitializeComponent(); - PopulateShiftorium(); + SaveSystem.CurrentSave.addSetCpCallback(updatecounter); + updatecounter(); + Populate(); + SetList(); lbupgrades.SelectedIndexChanged += (o, a) => { try @@ -82,84 +85,57 @@ namespace ShiftOS.WinForms.Applications public void SelectUpgrade(string name) { btnbuy.Show(); - var upg = upgrades[name]; + var upg = upgrades[CategoryId][name]; lbupgradetitle.Text = Localization.Parse(upg.Name); lbupgradedesc.Text = Localization.Parse(upg.Description); } - Dictionary upgrades = new Dictionary(); - - public void PopulateShiftorium() + Dictionary[] upgrades; + + private void Populate() { - var t = new Thread(() => + upgrades = new Dictionary[cats.Length]; + int numComplete = 0; + avail = backend.GetAvailable(); + foreach (var it in cats.Select((catName, catId) => new { catName, catId })) { - try + var upl = new Dictionary(); + upgrades[it.catId] = upl; + var t = new Thread((tupobj) => { - Desktop.InvokeOnWorkerThread(() => - { - lbnoupgrades.Hide(); - lbupgrades.Items.Clear(); - upgrades.Clear(); - Timer(); - }); - - foreach (var upg in backend.GetAvailable().Where(x => x.Category == backend.GetCategories()[CategoryId])) - { - string name = Localization.Parse(upg.Name) + " - " + upg.Cost.ToString() + "CP"; - upgrades.Add(name, upg); - Desktop.InvokeOnWorkerThread(() => - { - lbupgrades.Items.Add(name); - }); - } - - if (lbupgrades.Items.Count == 0) - { - Desktop.InvokeOnWorkerThread(() => - { - lbnoupgrades.Show(); - lbnoupgrades.Location = new Point( - (lbupgrades.Width - lbnoupgrades.Width) / 2, - lbupgrades.Top + (lbupgrades.Height - lbnoupgrades.Height) / 2 - ); - }); - } - else - { - Desktop.InvokeOnWorkerThread(() => - { - lbnoupgrades.Hide(); - }); - } - - Desktop.InvokeOnWorkerThread(() => - { - try - { - lblcategorytext.Text = Shiftorium.GetCategories()[CategoryId]; - btncat_back.Visible = (CategoryId > 0); - btncat_forward.Visible = (CategoryId < backend.GetCategories().Length - 1); - } - catch - { + foreach (var upg in avail.Where(x => x.Category == it.catName)) + upl.Add(Localization.Parse(upg.Name) + " - " + upg.Cost.ToString() + "CP", upg); + numComplete++; + }); + t.Start(); + } + while (numComplete < cats.Length) { } // wait for all threads to finish their job + } - } - }); - } - catch - { - Desktop.InvokeOnWorkerThread(() => - { - lbnoupgrades.Show(); - lbnoupgrades.Location = new Point( - (lbupgrades.Width - lbnoupgrades.Width) / 2, - lbupgrades.Top + (lbupgrades.Height - lbnoupgrades.Height) / 2 - ); - }); - } - }); - t.IsBackground = true; - t.Start(); + private void SetList() + { + lbnoupgrades.Hide(); + lbupgrades.Items.Clear(); + try + { + lbupgrades.Items.AddRange(upgrades[CategoryId].Keys.ToArray()); + } + catch + { + Engine.Infobox.Show("Shiftorium Machine Broke", "Category ID " + CategoryId.ToString() + " is invalid, modulo is broken, and the world is doomed. Please tell Declan about this."); + return; + } + if (lbupgrades.Items.Count == 0) + { + lbnoupgrades.Show(); + lbnoupgrades.Location = new Point( + (lbupgrades.Width - lbnoupgrades.Width) / 2, + lbupgrades.Top + (lbupgrades.Height - lbnoupgrades.Height) / 2 + ); + } + else + lbnoupgrades.Hide(); + lblcategorytext.Text = cats[CategoryId]; } public static bool UpgradeInstalled(string upg) @@ -218,8 +194,9 @@ namespace ShiftOS.WinForms.Applications Dictionary UpgradesToBuy = new Dictionary(); foreach (var itm in lbupgrades.SelectedItems) { - cpCost += upgrades[itm.ToString()].Cost; - UpgradesToBuy.Add(upgrades[itm.ToString()].ID, upgrades[itm.ToString()].Cost); + var upg = upgrades[CategoryId][itm.ToString()]; + cpCost += upg.Cost; + UpgradesToBuy.Add(upg.ID, upg.Cost); } if (SaveSystem.CurrentSave.Codepoints < cpCost) { @@ -230,7 +207,6 @@ namespace ShiftOS.WinForms.Applications { foreach(var upg in UpgradesToBuy) { - SaveSystem.CurrentSave.Codepoints -= upg.Value; if (SaveSystem.CurrentSave.Upgrades.ContainsKey(upg.Key)) { SaveSystem.CurrentSave.Upgrades[upg.Key] = true; @@ -242,20 +218,15 @@ namespace ShiftOS.WinForms.Applications SaveSystem.SaveGame(); backend.InvokeUpgradeInstalled(); } + SaveSystem.CurrentSave.Codepoints -= cpCost; } backend.Silent = false; - PopulateShiftorium(); btnbuy.Hide(); } - private void Shiftorium_Load(object sender, EventArgs e) { - - } - public void OnLoad() { - cp_update.Start(); lbnoupgrades.Hide(); } @@ -264,12 +235,9 @@ namespace ShiftOS.WinForms.Applications } - System.Windows.Forms.Timer cp_update = new System.Windows.Forms.Timer(); - public bool OnUnload() { - cp_update.Stop(); - cp_update = null; + SaveSystem.CurrentSave.removeSetCpCallback(updatecounter); return true; } @@ -277,44 +245,26 @@ namespace ShiftOS.WinForms.Applications { lbupgrades.SelectionMode = (UpgradeInstalled("shiftorium_gui_bulk_buy") == true) ? SelectionMode.MultiExtended : SelectionMode.One; lbcodepoints.Visible = Shiftorium.UpgradeInstalled("shiftorium_gui_codepoints_display"); + Populate(); + SetList(); } - private void lbcodepoints_Click(object sender, EventArgs e) + private void moveCat(short direction) // direction is -1 to move backwards or 1 to move forwards { - - } - - void Timer() - { - timer100 = new System.Timers.Timer(); - timer100.Interval = 2000; - //CLARIFICATION: What is this supposed to do? - Michael - //timer100.Elapsed += ???; - timer100.AutoReset = true; - timer100.Enabled = true; + CategoryId += direction; + CategoryId %= cats.Length; + if (CategoryId < 0) CategoryId += cats.Length; // fix modulo on negatives + SetList(); } private void btncat_back_Click(object sender, EventArgs e) { - if(CategoryId > 0) - { - CategoryId--; - PopulateShiftorium(); - } + moveCat(-1); } private void btncat_forward_Click(object sender, EventArgs e) { - if(CategoryId < backend.GetCategories().Length - 1) - { - CategoryId++; - PopulateShiftorium(); - } - } - - private void lblcategorytext_Click(object sender, EventArgs e) - { - + moveCat(1); } } } diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index 395db85..155f002 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -570,8 +570,15 @@ namespace ShiftOS.Engine Console.Write("{SE_SAVING}... "); if (SaveSystem.CurrentSave != null) { - Utils.WriteAllText(Paths.GetPath("user.dat"), CurrentSave.UniteAuthToken); - ServerManager.SendMessage("mud_save", JsonConvert.SerializeObject(CurrentSave, Formatting.Indented)); + Utils.WriteAllText(Paths.GetPath("user.dat"), CurrentSave.UniteAuthToken); + var serialisedSaveFile = JsonConvert.SerializeObject(CurrentSave, Formatting.Indented); + new Thread(() => + { + // please don't do networking on the main thread if you're just going to + // discard the response, it's extremely slow + ServerManager.SendMessage("mud_save", serialisedSaveFile); + }) + { IsBackground = false }.Start(); } if (!Shiftorium.Silent) Console.WriteLine(" ...{DONE}."); -- cgit v1.2.3 From 69aba3b373f9c9c70ec4ef2250e71465d3327299 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 4 Jun 2017 15:18:53 -0400 Subject: A fuckton of storyline features. --- ShiftOS.Objects/Save.cs | 5 ++ ShiftOS.WinForms/Applications/Terminal.cs | 82 ++++++++++++++++- ShiftOS.WinForms/Commands.cs | 1 - ShiftOS.WinForms/Oobe.cs | 6 +- ShiftOS.WinForms/Stories/LegionStory.cs | 144 +++++++++++++++++++++--------- ShiftOS.WinForms/Tools/ControlManager.cs | 12 ++- ShiftOS_TheReturn/Commands.cs | 27 ++++-- ShiftOS_TheReturn/SaveSystem.cs | 10 +++ ShiftOS_TheReturn/Story.cs | 25 ++---- 9 files changed, 239 insertions(+), 73 deletions(-) (limited to 'ShiftOS.Objects/Save.cs') diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index e0282e8..7891a22 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -173,6 +173,11 @@ namespace ShiftOS.Objects } public List Users { get; set; } + + /// + /// DO NOT MODIFY THIS. EVER. YOU WILL BREAK THE STORYLINE. Let the engine do it's job. + /// + public string PickupPoint { get; set; } } public class SettingsObject : DynamicObject diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index a4b77ae..687b2b9 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -410,8 +410,6 @@ namespace ShiftOS.WinForms.Applications public static void FirstSteps() { TerminalBackend.PrefixEnabled = false; - new Thread(() => - { TerminalBackend.InStory = true; Console.WriteLine("Hey there, and welcome to ShiftOS."); Thread.Sleep(2000); @@ -521,8 +519,86 @@ namespace ShiftOS.WinForms.Applications TerminalBackend.InStory = false; SaveSystem.SaveGame(); Thread.Sleep(1000); + + Story.Context.AutoComplete = false; + + Console.WriteLine(@"Welcome to the ShiftOS Newbie's Guide. + +This tutorial will guide you through the more intermediate features of ShiftOS, +such as earning Codepoints, buying Shiftoorium Upgrades, and using the objectives system. + +Every now and then, you'll get a notification in your terminal of a ""NEW OBJECTIVE"". +This means that someone has instructed you to do something inside ShiftOS. At any moment +you may type ""sos.status"" in your Terminal to see your current objectives. + +This command is very useful as not only does it allow you to see your current objectives +but you can also see the amount of Codepoints you have as well as the upgrades you've +installed and how many upgrades are available. + +Now, onto your first objective! All you need to do is earn 200 Codepoints using any +program on your system."); + + Story.PushObjective("First Steps: Your First Codepoints", "Play a few rounds of Pong, or use another program to earn 200 Codepoints.", () => + { + return SaveSystem.CurrentSave.Codepoints >= 200; + }, () => + { + Desktop.InvokeOnWorkerThread(() => + { + AppearanceManager.SetupWindow(new Terminal()); + }); + Console.WriteLine("Good job! You've earned " + SaveSystem.CurrentSave.Codepoints + @" Codepoints! You can use these inside the +Shiftorium to buy new upgrades inside ShiftOS. + +These upgrades can give ShiftOS more features, fixes and programs, +which can make the operating system easier to use and navigate around +and also make it easier for you to earn more Codepoints and thus upgrade +te system further. + +Be cautious though! Only certain upgrades offer the ability to earn more +Codepoints. These upgrades are typically in the form of new programs. + +So, try to get as many new programs as possible for your computer, and save +the system feature upgrades for later unless you absolutely need them. + +The worst thing that could happen is you end up stuck with very little Codepoints +and only a few small programs to use to earn very little amounts of Codepoints. + +Now, let's get you your first Shiftorium upgrade!"); + + Story.PushObjective("First Steps: The Shiftorium", "Buy your first Shiftorium upgrade with your new Codepoints using shiftorium.list, shiftorium.info and shiftorium.buy.", + () => + { + return SaveSystem.CurrentSave.CountUpgrades() > 0; + }, () => + { + Console.WriteLine("This concludes the ShiftOS Newbie's Guide! Now, go, and shift it your way!"); + Console.WriteLine(@" +Your goal: Earn 1,000 Codepoints."); + Story.Context.MarkComplete(); + Story.Start("first_steps_transition"); + }); TerminalBackend.PrintPrompt(); - }).Start(); + }); + + TerminalBackend.PrintPrompt(); + } + + + [Story("first_steps_transition")] + public static void FirstStepsTransition() + { + Story.PushObjective("Earn 1000 Codepoints", "You now know the basics of ShiftOS. Let's get your system up and running with a few upgrades, and get a decent amount of Codepoints.", () => + { + return SaveSystem.CurrentSave.Codepoints >= 1000; + }, + () => + { + Story.Context.MarkComplete(); + Story.Start("victortran_shiftnet"); + }); + + Story.Context.AutoComplete = false; } public void OnSkinLoad() diff --git a/ShiftOS.WinForms/Commands.cs b/ShiftOS.WinForms/Commands.cs index 2d297f5..b04ffe7 100644 --- a/ShiftOS.WinForms/Commands.cs +++ b/ShiftOS.WinForms/Commands.cs @@ -80,7 +80,6 @@ namespace ShiftOS.WinForms } } - [Namespace("coherence")] [RequiresUpgrade("kernel_coherence")] public static class CoherenceCommands diff --git a/ShiftOS.WinForms/Oobe.cs b/ShiftOS.WinForms/Oobe.cs index 96c2bf5..271e1fd 100644 --- a/ShiftOS.WinForms/Oobe.cs +++ b/ShiftOS.WinForms/Oobe.cs @@ -91,6 +91,7 @@ namespace ShiftOS.WinForms slashcount++; if (slashcount == 5) slashcount = 1; + Engine.AudioManager.PlayStream(Properties.Resources.writesound); Thread.Sleep(50); } rtext += Environment.NewLine; @@ -138,7 +139,10 @@ namespace ShiftOS.WinForms TextType("Your computer has been taken over by ShiftOS, and is currently being wiped clean of all existing files and programs."); Thread.Sleep(2000); Clear(); - TextType("I will not share my identity or my intentions at this moment.I will just proceed with the installation.There’s nothing you can do to stop it."); + TextType("I will not share my identity or my intentions at this moment."); + Thread.Sleep(2000); + Clear(); + TextType("I will just proceed with the installation.There’s nothing you can do to stop it."); Thread.Sleep(2000); Clear(); TextType("All I will say, is I need your help.Once ShiftOS is installed, I will explain."); diff --git a/ShiftOS.WinForms/Stories/LegionStory.cs b/ShiftOS.WinForms/Stories/LegionStory.cs index a0fc9bf..8c79f0e 100644 --- a/ShiftOS.WinForms/Stories/LegionStory.cs +++ b/ShiftOS.WinForms/Stories/LegionStory.cs @@ -16,8 +16,8 @@ namespace ShiftOS.WinForms.Stories [Story("victortran_shiftnet")] public static void ShiftnetStoryFeaturingTheBlueSmileyFaceHolyFuckThisFunctionNameIsLong() { - CharacterName = "victor_tran"; - SysName = "theos"; + CharacterName = "aiden"; + SysName = "appscape_main"; bool waiting = false; var installer = new Applications.Installer(); installer.InstallCompleted += () => @@ -35,53 +35,107 @@ namespace ShiftOS.WinForms.Stories AppearanceManager.SetupWindow(term); } - var t = new Thread(() => + WriteLine("aiden@appscape_main - user connecting to your system.", false); + Thread.Sleep(2000); + WriteLine("Hello there! My name's Aiden Nirh."); + WriteLine("I run a small Shiftnet website known simply as \"Appscape\"."); + WriteLine("Oh - wait... you don't know what the Shiftnet is..."); + WriteLine("Well, the Shiftnet is like... a private Internet, only accessible through ShiftOS."); + WriteLine("It has many sites and companies on it - banks, software centres, service providers, you name it."); + WriteLine("Appscape is one of them. I host many applications on Appscape, from games to utilities to productivity programs, and anything in between. If it exists as a ShiftOS program, it's either on the Shiftorium or Appscape."); + WriteLine("I'm going to assume you're interested... and I'll install the Shiftnet just in case."); + WriteLine("Beginning installation of Shiftnet..."); + //Set up an Installer. + waiting = true; + Desktop.InvokeOnWorkerThread(() => { - WriteLine("victortran@theos - user connecting to your system.", false); - Thread.Sleep(2000); - WriteLine("Hey there - yes, I am not just a sentient being. I am indeed Victor Tran."); - WriteLine("I am the creator of a Linux desktop environment called theShell."); - WriteLine("I'm in the middle of working on a ShiftOS version of it."); - WriteLine("However, before I start, I feel I need to show you something."); - WriteLine("You have a lot of ShiftOS applications, and you can earn lots of Codepoints - and you already have lots."); - WriteLine("Well, you'd be a perfect candidate for me to install the Shiftnet Client on your system."); - WriteLine("I'll begin the installation right now."); - //Set up an Installer. - waiting = true; - Desktop.InvokeOnWorkerThread(() => - { - Story.Start("installer"); - while (!Shiftorium.UpgradeInstalled("installer")) - Thread.Sleep(20); - AppearanceManager.SetupWindow(installer); - installer.InitiateInstall(new ShiftnetInstallation()); - }); - while (waiting == true) - Thread.Sleep(25); + SaveSystem.CurrentSave.StoriesExperienced.Add("installer"); + SaveSystem.CurrentSave.StoriesExperienced.Add("downloader"); - WriteLine("All installed! Once I disconnect, type win.open to see a list of your new apps."); - WriteLine("The Shiftnet is a vast network of websites only accessible through ShiftOS."); - WriteLine("Think of it as the DarkNet, but much darker, and much more secretive."); - WriteLine("There are lots of apps, games, skins and utilities on the Shiftnet."); - WriteLine("There are also lots of companies offering many services."); - WriteLine("I'd stay on the shiftnet/ cluster though, others may be dangerous."); - WriteLine("I'd also stick to the sites listed on shiftnet/shiftsoft/ping - that site is regularly updated with the most safe Shiftnet sites."); - WriteLine("Oh, that reminds me. I have set you up with ShiftSoft's service provider, Freebie Solutions."); - WriteLine("It's a free provider, but it offers only 256 bytes per second download and upload speeds."); - WriteLine("You may want to go look for another provider when you can afford it."); - WriteLine("Trust me - with this provider, things get slow."); - WriteLine("Anyways, it was nice meeting you, hopefully someday you'll give theShell a try."); + while (!Shiftorium.UpgradeInstalled("installer")) + Thread.Sleep(20); + AppearanceManager.SetupWindow(installer); + installer.InitiateInstall(new ShiftnetInstallation()); + }); + while (waiting == true) + Thread.Sleep(25); - TerminalBackend.PrefixEnabled = true; + WriteLine("All good to go! Once I disconnect, type win.open to see a list of your new apps."); + WriteLine("I've installed everything you need, for free."); + WriteLine("You've got the Downloader, a simple application to help you track Shiftnet file downloads..."); + WriteLine("...the Installer which will help you unpack programs from .stp files and install them to your system..."); + WriteLine("...and lastly, the Shiftnet browser itself. This program lets you browse the Shiftnet, much like you would the real Internet."); + WriteLine("I'd stay on the shiftnet/ cluster though, because although there are many services on the Shiftnet, some of them may try to scam you into losing loads of Codepoints, or worse, wrecking your system with viruses."); + WriteLine("If you want a nice list of safe Shiftnet services, head to ShiftSoft's \"Ping\" site, at shiftnet/shiftsoft/ping."); + WriteLine("Oh, also, the Shiftnet, much like the real internet, is not free."); + WriteLine("It requires a service provider. Service providers cost a fair amount of Codepoints, but if you want to get faster speeds and more reliable connections on the Shiftnet, finding a good service provider is a necessity."); + WriteLine("Right now, you are on ShiftSoft's free trial plan, Freebie Solutions, which gives you access to the Shiftnet however you are locked at 256 bytes per second file downloads and can't leave the shiftnet/ cluster."); + WriteLine("It's enough to get you started - you'll want to find a faster provider though.."); + WriteLine("Anyways, that's all I'll say for now. Have fun on the Shiftnet. I have to go work on something."); + WriteLine("One of my friends'll contact you once you've gotten a new service provider."); + + Story.PushObjective("Register with a new Shiftnet service provider.", "You've just unlocked the Shiftnet, which has opened up a whole new world of applications and features for ShiftOS. Before you go nuts with it, you may want to register with a better service provider than Freebie Solutions.", () => + { + return SaveSystem.CurrentSave.ShiftnetSubscription != 0; + }, + () => + { + Story.Context.MarkComplete(); + SaveSystem.SaveGame(); TerminalBackend.PrintPrompt(); + Story.Start("hacker101_breakingbonds_1"); }); - t.IsBackground = true; - t.Start(); - TerminalBackend.PrefixEnabled = false; + TerminalBackend.PrefixEnabled = true; + TerminalBackend.PrintPrompt(); + Story.Context.AutoComplete = false; } + [Story("hacker101_breakingbonds_1")] + public static void BreakingTheBondsIntro() + { + CharacterName = "hacker101"; + SysName = "pebcak"; + + if (!terminalOpen()) + { + var term = new Applications.Terminal(); + AppearanceManager.SetupWindow(term); + } + + WriteLine("hacker101@pebcak - user connecting to your system.", false); + Thread.Sleep(2000); + WriteLine("Greetings, user."); + WriteLine("My name is hacker101. I have a few things to show you."); + WriteLine("Before I can do that, however, I need you to do a few things."); + WriteLine("I'll assign what I need you to do as an objective. When you're done, I'll tell you what you need to know."); + + Story.PushObjective("Breaking the Bonds: Errand Boy", @"hacker101 has something he needs to show you, however before he can, you need to do the following: + + - Buy ""TriWrite"" from Appscape + - Buy ""Address Book"" from Appscape + - Buy ""SimpleSRC"" from Appscape", () => + { + bool flag1 = Shiftorium.UpgradeInstalled("address_book"); + bool flag2 = Shiftorium.UpgradeInstalled("triwrite"); + bool flag3 = Shiftorium.UpgradeInstalled("simplesrc"); + return flag1 && flag2 && flag3; + }, () => + { + Story.Context.MarkComplete(); + SaveSystem.SaveGame(); + Story.Start("hacker101_breakingbonds_2"); + }); + + TerminalBackend.PrefixEnabled = true; + TerminalBackend.PrintPrompt(); + + Story.Context.AutoComplete = false; + + } + + private static void WriteLine(string text, bool showCharacterName=true) { Console.WriteLine(); @@ -90,15 +144,23 @@ namespace ShiftOS.WinForms.Stories ConsoleEx.Bold = true; ConsoleEx.ForegroundColor = ConsoleColor.DarkMagenta; Console.Write(CharacterName); + ConsoleEx.OnFlush?.Invoke(); Console.ForegroundColor = ConsoleColor.White; Console.Write("@"); + ConsoleEx.OnFlush?.Invoke(); ConsoleEx.ForegroundColor = ConsoleColor.Yellow; Console.Write(SysName + ": "); + ConsoleEx.OnFlush?.Invoke(); } ConsoleEx.ForegroundColor = ConsoleColor.Gray; ConsoleEx.Bold = false; - Console.WriteLine(text); + foreach(var c in text) + { + Console.Write(c); + ConsoleEx.OnFlush?.Invoke(); + Thread.Sleep(45); + } Thread.Sleep(1000); } diff --git a/ShiftOS.WinForms/Tools/ControlManager.cs b/ShiftOS.WinForms/Tools/ControlManager.cs index 548a62a..7fbfd1b 100644 --- a/ShiftOS.WinForms/Tools/ControlManager.cs +++ b/ShiftOS.WinForms/Tools/ControlManager.cs @@ -137,10 +137,14 @@ namespace ShiftOS.WinForms.Tools /// The control to center (this is an extension method - you can call it on a control as though it was a method in that control) public static void CenterParent(this Control ctrl) { - ctrl.Location = new Point( - (ctrl.Parent.Width - ctrl.Width) / 2, - (ctrl.Parent.Height - ctrl.Height) / 2 - ); + try + { + ctrl.Location = new Point( + (ctrl.Parent.Width - ctrl.Width) / 2, + (ctrl.Parent.Height - ctrl.Height) / 2 + ); + } + catch { } } public static void SetupControl(Control ctrl) diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index 72bccb1..f37bcb3 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -538,15 +538,28 @@ Upgrades: {SaveSystem.CurrentSave.CountUpgrades()} installed, "; Console.WriteLine(status); - - if(Story.CurrentObjective != null) + Console.WriteLine("Objectives:"); + try + { + if (Story.CurrentObjectives.Count > 0) + { + foreach (var obj in Story.CurrentObjectives) + { + Console.WriteLine(obj.Name); + Console.WriteLine("-------------------------------"); + Console.WriteLine(); + Console.WriteLine(obj.Description); + } + } + else + { + Console.WriteLine(" - No objectives are running. Check back later!"); + } + } + catch { - Console.WriteLine("CURRENT OBJECTIVE: " + Story.CurrentObjective.Name); - Console.WriteLine("-------------------------------"); - Console.WriteLine(); - Console.WriteLine(Story.CurrentObjective.Description); + Console.WriteLine(" - No objectives are running. Check back later!"); } - return true; } } diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index 155f002..e98a51e 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -453,6 +453,16 @@ namespace ShiftOS.Engine Desktop.InvokeOnWorkerThread(new Action(() => Desktop.PopulateAppLauncher())); GameReady?.Invoke(); + + if (!string.IsNullOrWhiteSpace(CurrentSave.PickupPoint)) + { + try + { + Story.Start(CurrentSave.PickupPoint); + TerminalBackend.PrintPrompt(); + } + catch { } + } } /// diff --git a/ShiftOS_TheReturn/Story.cs b/ShiftOS_TheReturn/Story.cs index 848c757..4d1d5cc 100644 --- a/ShiftOS_TheReturn/Story.cs +++ b/ShiftOS_TheReturn/Story.cs @@ -93,33 +93,24 @@ namespace ShiftOS.Engine { public static StoryContext Context { get; private set; } public static event Action StoryComplete; - public static Objective CurrentObjective { get; private set; } + public static List CurrentObjectives { get; private set; } public static void PushObjective(string name, string desc, Func completeFunc, Action onComplete) { - if (CurrentObjective != null) - { - if (CurrentObjective.IsComplete == false) - { - throw new Exception("Cannot start objective - an objective is already running."); - } - else - { - CurrentObjective = null; - } - } - - CurrentObjective = new Objective(name, desc, completeFunc, onComplete); + if (CurrentObjectives == null) + CurrentObjectives = new List(); + var currentObjective = new Objective(name, desc, completeFunc, onComplete); + CurrentObjectives.Add(currentObjective); var t = new Thread(() => { - var obj = CurrentObjective; + var obj = currentObjective; while (!obj.IsComplete) { Thread.Sleep(5000); } + CurrentObjectives.Remove(obj); obj.Complete(); - CurrentObjective = null; }); t.IsBackground = true; t.Start(); @@ -163,9 +154,11 @@ namespace ShiftOS.Engine Method = mth, AutoComplete = true, }; + SaveSystem.CurrentSave.Password = Context.Id; Context.OnComplete += () => { StoryComplete?.Invoke(stid); + SaveSystem.CurrentSave.PickupPoint = null; }; mth.Invoke(null, null); if (Context.AutoComplete) -- cgit v1.2.3 From c40d071d58859e25b3781299b949b91caa0548fe Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 10 Jun 2017 10:17:10 -0400 Subject: main menu system + sandbox mode --- ShiftOS.Objects/Save.cs | 6 + ShiftOS.WinForms/MainMenu/MainMenu.Designer.cs | 147 ++++++++++++++++ ShiftOS.WinForms/MainMenu/MainMenu.cs | 100 +++++++++++ ShiftOS.WinForms/MainMenu/MainMenu.resx | 120 +++++++++++++ ShiftOS.WinForms/Program.cs | 35 ++-- ShiftOS.WinForms/ShiftOS.WinForms.csproj | 9 + .../ShiftnetSites/ShiftSoft.Designer.cs | 188 ++++++++++++++++++++- ShiftOS.WinForms/ShiftnetSites/ShiftSoft.cs | 56 ++++++ ShiftOS.WinForms/ShiftnetSites/ShiftSoft.resx | 10 ++ ShiftOS.WinForms/Stories/LegionStory.cs | 42 ++--- ShiftOS.WinForms/WinformsDesktop.cs | 32 +++- ShiftOS_TheReturn/AppearanceManager.cs | 1 + ShiftOS_TheReturn/SaveSystem.cs | 152 ++++++++++++----- ShiftOS_TheReturn/ServerManager.cs | 18 +- ShiftOS_TheReturn/Shiftorium.cs | 3 + ShiftOS_TheReturn/Story.cs | 8 + 16 files changed, 825 insertions(+), 102 deletions(-) create mode 100644 ShiftOS.WinForms/MainMenu/MainMenu.Designer.cs create mode 100644 ShiftOS.WinForms/MainMenu/MainMenu.cs create mode 100644 ShiftOS.WinForms/MainMenu/MainMenu.resx (limited to 'ShiftOS.Objects/Save.cs') diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index 7891a22..6e7f167 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -76,10 +76,14 @@ namespace ShiftOS.Objects _setCpCallbacks.Remove(callback); } + public bool IsSandbox = false; + public ulong Codepoints { get { + if (IsSandbox == true) + return 0; if (_updTimer == null) _updTimer = new Timer((o) => syncCp(), null, 0, 300000); lock (_cpLock) @@ -89,6 +93,8 @@ namespace ShiftOS.Objects } set { + if (IsSandbox == true) + return; lock (_cpLock) { _cp = value; diff --git a/ShiftOS.WinForms/MainMenu/MainMenu.Designer.cs b/ShiftOS.WinForms/MainMenu/MainMenu.Designer.cs new file mode 100644 index 0000000..62db46d --- /dev/null +++ b/ShiftOS.WinForms/MainMenu/MainMenu.Designer.cs @@ -0,0 +1,147 @@ +namespace ShiftOS.WinForms.MainMenu +{ + partial class MainMenu + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.flmenu = new System.Windows.Forms.FlowLayoutPanel(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); + this.lbticker = new System.Windows.Forms.Label(); + this.flmenu.SuspendLayout(); + this.SuspendLayout(); + // + // flmenu + // + this.flmenu.AutoSize = true; + this.flmenu.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.flmenu.Controls.Add(this.button1); + this.flmenu.Controls.Add(this.button2); + this.flmenu.Controls.Add(this.button3); + this.flmenu.Controls.Add(this.button4); + this.flmenu.Controls.Add(this.button5); + this.flmenu.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; + this.flmenu.Location = new System.Drawing.Point(46, 218); + this.flmenu.Name = "flmenu"; + this.flmenu.Size = new System.Drawing.Size(187, 145); + this.flmenu.TabIndex = 0; + // + // button1 + // + this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.button1.Location = new System.Drawing.Point(3, 3); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(181, 23); + this.button1.TabIndex = 0; + this.button1.Text = "Campaign"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button2 + // + this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.button2.Location = new System.Drawing.Point(3, 32); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(181, 23); + this.button2.TabIndex = 1; + this.button2.Text = "Sandbox"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button3 + // + this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.button3.Location = new System.Drawing.Point(3, 61); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(181, 23); + this.button3.TabIndex = 2; + this.button3.Text = "Settings"; + this.button3.UseVisualStyleBackColor = true; + // + // button4 + // + this.button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.button4.Location = new System.Drawing.Point(3, 90); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(181, 23); + this.button4.TabIndex = 3; + this.button4.Text = "About"; + this.button4.UseVisualStyleBackColor = true; + // + // button5 + // + this.button5.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.button5.Location = new System.Drawing.Point(3, 119); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(181, 23); + this.button5.TabIndex = 4; + this.button5.Text = "Exit"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.button5_Click); + // + // lbticker + // + this.lbticker.AutoSize = true; + this.lbticker.Location = new System.Drawing.Point(29, 515); + this.lbticker.Name = "lbticker"; + this.lbticker.Size = new System.Drawing.Size(93, 13); + this.lbticker.TabIndex = 1; + this.lbticker.Tag = "header3"; + this.lbticker.Text = "This is a tickerbar."; + // + // MainMenu + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.Black; + this.ClientSize = new System.Drawing.Size(1161, 566); + this.Controls.Add(this.lbticker); + this.Controls.Add(this.flmenu); + this.ForeColor = System.Drawing.Color.White; + this.Name = "MainMenu"; + this.Text = "MainMenu"; + this.Load += new System.EventHandler(this.MainMenu_Load); + this.flmenu.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.FlowLayoutPanel flmenu; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.Label lbticker; + } +} \ No newline at end of file diff --git a/ShiftOS.WinForms/MainMenu/MainMenu.cs b/ShiftOS.WinForms/MainMenu/MainMenu.cs new file mode 100644 index 0000000..20cd4ec --- /dev/null +++ b/ShiftOS.WinForms/MainMenu/MainMenu.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; +using ShiftOS.WinForms.Tools; + +namespace ShiftOS.WinForms.MainMenu +{ + public partial class MainMenu : Form + { + public MainMenu(IDesktop desk) + { + InitializeComponent(); + (desk as WinformsDesktop).ParentMenu = this; + + var tickermove = new Timer(); + var tickerreset = new Timer(); + tickermove.Tick += (o, a) => + { + if(lbticker.Left <= (0 - lbticker.Width)) + { + tickermove.Stop(); + tickerreset.Start(); + } + else + { + lbticker.Top = (this.ClientSize.Height - (lbticker.Height * 2)); + lbticker.Left -= 2; + } + }; + tickerreset.Tick += (o, a) => + { + lbticker.Visible = false; + lbticker.Text = GetTickerMessage(); + lbticker.Left = this.Width; + lbticker.Visible = true; + tickerreset.Stop(); + tickermove.Start(); + }; + + tickermove.Interval = 1; + tickerreset.Interval = 1000; + + flmenu.CenterParent(); + + tickerreset.Start(); + } + + private void MainMenu_Load(object sender, EventArgs e) + { + Tools.ControlManager.SetupControls(this); + + } + + private Random rnd = new Random(); + + private string GetTickerMessage() + { + switch (rnd.Next(0, 10)) + { + case 0: + return "Did you know that you can skin this very menu? Just goes to show how much you can shift it your way."; + case 1: + return "Want to pick up a few skins or mods from the community? Head on over to http://getshiftos.ml/Skins!"; + case 2: + return "Sandbox mode is a special version of ShiftOS that allows you to use the operating system without having to deal with Codepoints, the Shiftorium or having to play through the storyline. Handy..."; + case 3: + return "ArtPad not good enough? You can use an external image editor to create ShiftOS skin textures. Just save your files to the Shared Directory and they'll be imported into ShiftOS on the 1:/ drive."; + case 4: + return "Terminal too weird for ya? You can use the Format Editor to generate your own Terminal command parser. No coding knowledge needed!"; + case 5: + return "Contests are a good way to earn heaps of Codepoints. Head on over to http://getshiftos.ml/Contests for info on current community contests."; + default: + return "Good God. We don't know what to put here."; + } + } + + private void button1_Click(object sender, EventArgs e) + { + Desktop.CurrentDesktop.Show(); + } + + private void button5_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void button2_Click(object sender, EventArgs e) + { + (Desktop.CurrentDesktop as WinformsDesktop).IsSandbox = true; + Desktop.CurrentDesktop.Show(); + } + } +} diff --git a/ShiftOS.WinForms/MainMenu/MainMenu.resx b/ShiftOS.WinForms/MainMenu/MainMenu.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/MainMenu/MainMenu.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShiftOS.WinForms/Program.cs b/ShiftOS.WinForms/Program.cs index 8f65265..b07d97a 100644 --- a/ShiftOS.WinForms/Program.cs +++ b/ShiftOS.WinForms/Program.cs @@ -50,6 +50,21 @@ namespace ShiftOS.WinForms Application.SetCompatibleTextRenderingDefault(false); //if ANYONE puts code before those two winforms config lines they will be declared a drunky. - Michael SkinEngine.SetPostProcessor(new DitheringSkinPostProcessor()); + LoginManager.Init(new GUILoginFrontend()); + CrashHandler.SetGameMetadata(Assembly.GetExecutingAssembly()); + SkinEngine.SetIconProber(new ShiftOSIconProvider()); + TerminalBackend.TerminalRequested += () => + { + AppearanceManager.SetupWindow(new Applications.Terminal()); + }; + Localization.RegisterProvider(new WFLanguageProvider()); + Infobox.Init(new Dialog()); + FileSkimmerBackend.Init(new WinformsFSFrontend()); + var desk = new WinformsDesktop(); + Desktop.Init(desk); + OutOfBoxExperience.Init(new Oobe()); + AppearanceManager.Initiate(new WinformsWindowManager()); +#if OLD SaveSystem.PreDigitalSocietyConnection += () => { Action completed = null; @@ -63,25 +78,11 @@ namespace ShiftOS.WinForms Engine.AudioManager.PlayStream(Properties.Resources.dial_up_modem_02); }; - LoginManager.Init(new GUILoginFrontend()); - CrashHandler.SetGameMetadata(Assembly.GetExecutingAssembly()); - SkinEngine.SetIconProber(new ShiftOSIconProvider()); - ShiftOS.Engine.AudioManager.Init(new ShiftOSAudioProvider()); - Localization.RegisterProvider(new WFLanguageProvider()); - TutorialManager.RegisterTutorial(new Oobe()); - - TerminalBackend.TerminalRequested += () => - { - AppearanceManager.SetupWindow(new Applications.Terminal()); - }; - Infobox.Init(new Dialog()); - FileSkimmerBackend.Init(new WinformsFSFrontend()); - var desk = new WinformsDesktop(); - Desktop.Init(desk); - OutOfBoxExperience.Init(new Oobe()); - AppearanceManager.Initiate(new WinformsWindowManager()); Application.Run(desk); +#else + Application.Run(new MainMenu.MainMenu(desk)); +#endif } } diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index e1afa84..d589ed4 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -356,6 +356,12 @@ + + Form + + + MainMenu.cs + Form @@ -603,6 +609,9 @@ GUILogin.cs + + MainMenu.cs + Oobe.cs diff --git a/ShiftOS.WinForms/ShiftnetSites/ShiftSoft.Designer.cs b/ShiftOS.WinForms/ShiftnetSites/ShiftSoft.Designer.cs index a62b5a8..b3e408f 100644 --- a/ShiftOS.WinForms/ShiftnetSites/ShiftSoft.Designer.cs +++ b/ShiftOS.WinForms/ShiftnetSites/ShiftSoft.Designer.cs @@ -28,27 +28,198 @@ /// private void InitializeComponent() { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ShiftSoft)); this.label1 = new System.Windows.Forms.Label(); + this.pnldivider = new System.Windows.Forms.Panel(); + this.label2 = new System.Windows.Forms.Label(); + this.flbuttons = new System.Windows.Forms.FlowLayoutPanel(); + this.btnhome = new System.Windows.Forms.Button(); + this.btnservices = new System.Windows.Forms.Button(); + this.btnping = new System.Windows.Forms.Button(); + this.pnlhome = new System.Windows.Forms.Panel(); + this.lbwhere = new System.Windows.Forms.Label(); + this.lbdesc = new System.Windows.Forms.Label(); + this.pnlservices = new System.Windows.Forms.Panel(); + this.lbfreebiedesc = new System.Windows.Forms.Label(); + this.lbfreebie = new System.Windows.Forms.Label(); + this.btnjoinfreebie = new System.Windows.Forms.Button(); + this.flbuttons.SuspendLayout(); + this.pnlhome.SuspendLayout(); + this.pnlservices.SuspendLayout(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("Franklin Gothic Heavy", 24.75F, System.Drawing.FontStyle.Italic); - this.label1.Location = new System.Drawing.Point(13, 17); + this.label1.Location = new System.Drawing.Point(13, 8); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(152, 38); this.label1.TabIndex = 0; this.label1.Tag = "keepfont"; this.label1.Text = "Shiftsoft"; // + // pnldivider + // + this.pnldivider.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.pnldivider.Location = new System.Drawing.Point(20, 71); + this.pnldivider.Name = "pnldivider"; + this.pnldivider.Size = new System.Drawing.Size(654, 2); + this.pnldivider.TabIndex = 1; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(17, 46); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(163, 13); + this.label2.TabIndex = 2; + this.label2.Text = "What do you want to shift today?"; + // + // flbuttons + // + this.flbuttons.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.flbuttons.AutoSize = true; + this.flbuttons.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.flbuttons.Controls.Add(this.btnhome); + this.flbuttons.Controls.Add(this.btnservices); + this.flbuttons.Controls.Add(this.btnping); + this.flbuttons.Location = new System.Drawing.Point(515, 17); + this.flbuttons.Name = "flbuttons"; + this.flbuttons.Size = new System.Drawing.Size(159, 29); + this.flbuttons.TabIndex = 3; + // + // btnhome + // + this.btnhome.AutoSize = true; + this.btnhome.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnhome.Location = new System.Drawing.Point(3, 3); + this.btnhome.Name = "btnhome"; + this.btnhome.Size = new System.Drawing.Size(45, 23); + this.btnhome.TabIndex = 0; + this.btnhome.Tag = "header3"; + this.btnhome.Text = "Home"; + this.btnhome.UseVisualStyleBackColor = true; + this.btnhome.Click += new System.EventHandler(this.btnhome_Click); + // + // btnservices + // + this.btnservices.AutoSize = true; + this.btnservices.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnservices.Location = new System.Drawing.Point(54, 3); + this.btnservices.Name = "btnservices"; + this.btnservices.Size = new System.Drawing.Size(58, 23); + this.btnservices.TabIndex = 1; + this.btnservices.Tag = "header3"; + this.btnservices.Text = "Services"; + this.btnservices.UseVisualStyleBackColor = true; + this.btnservices.Click += new System.EventHandler(this.btnservices_Click); + // + // btnping + // + this.btnping.AutoSize = true; + this.btnping.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnping.Location = new System.Drawing.Point(118, 3); + this.btnping.Name = "btnping"; + this.btnping.Size = new System.Drawing.Size(38, 23); + this.btnping.TabIndex = 2; + this.btnping.Tag = "header3"; + this.btnping.Text = "Ping"; + this.btnping.UseVisualStyleBackColor = true; + this.btnping.Click += new System.EventHandler(this.btnping_Click); + // + // pnlhome + // + this.pnlhome.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.pnlhome.Controls.Add(this.lbdesc); + this.pnlhome.Controls.Add(this.lbwhere); + this.pnlhome.Location = new System.Drawing.Point(20, 92); + this.pnlhome.Name = "pnlhome"; + this.pnlhome.Size = new System.Drawing.Size(654, 271); + this.pnlhome.TabIndex = 4; + // + // lbwhere + // + this.lbwhere.AutoSize = true; + this.lbwhere.Location = new System.Drawing.Point(4, 4); + this.lbwhere.Name = "lbwhere"; + this.lbwhere.Size = new System.Drawing.Size(169, 13); + this.lbwhere.TabIndex = 0; + this.lbwhere.Tag = "header2"; + this.lbwhere.Text = "Where do you want to shift today?"; + // + // lbdesc + // + this.lbdesc.Location = new System.Drawing.Point(4, 17); + this.lbdesc.Name = "lbdesc"; + this.lbdesc.Size = new System.Drawing.Size(361, 160); + this.lbdesc.TabIndex = 1; + this.lbdesc.Text = resources.GetString("lbdesc.Text"); + // + // pnlservices + // + this.pnlservices.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.pnlservices.Controls.Add(this.btnjoinfreebie); + this.pnlservices.Controls.Add(this.lbfreebiedesc); + this.pnlservices.Controls.Add(this.lbfreebie); + this.pnlservices.Location = new System.Drawing.Point(20, 92); + this.pnlservices.Name = "pnlservices"; + this.pnlservices.Size = new System.Drawing.Size(654, 271); + this.pnlservices.TabIndex = 5; + // + // lbfreebiedesc + // + this.lbfreebiedesc.Location = new System.Drawing.Point(4, 17); + this.lbfreebiedesc.Name = "lbfreebiedesc"; + this.lbfreebiedesc.Size = new System.Drawing.Size(361, 105); + this.lbfreebiedesc.TabIndex = 1; + this.lbfreebiedesc.Text = resources.GetString("lbfreebiedesc.Text"); + // + // lbfreebie + // + this.lbfreebie.AutoSize = true; + this.lbfreebie.Location = new System.Drawing.Point(4, 4); + this.lbfreebie.Name = "lbfreebie"; + this.lbfreebie.Size = new System.Drawing.Size(88, 13); + this.lbfreebie.TabIndex = 0; + this.lbfreebie.Tag = "header2"; + this.lbfreebie.Text = "Freebie Solutions"; + // + // btnjoinfreebie + // + this.btnjoinfreebie.AutoSize = true; + this.btnjoinfreebie.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnjoinfreebie.Location = new System.Drawing.Point(245, 125); + this.btnjoinfreebie.Name = "btnjoinfreebie"; + this.btnjoinfreebie.Size = new System.Drawing.Size(120, 23); + this.btnjoinfreebie.TabIndex = 2; + this.btnjoinfreebie.Text = "Join Freebie Solutions"; + this.btnjoinfreebie.UseVisualStyleBackColor = true; + this.btnjoinfreebie.Click += new System.EventHandler(this.btnjoinfreebie_Click); + // // ShiftSoft // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.pnlservices); + this.Controls.Add(this.pnlhome); + this.Controls.Add(this.flbuttons); + this.Controls.Add(this.label2); + this.Controls.Add(this.pnldivider); this.Controls.Add(this.label1); this.Name = "ShiftSoft"; - this.Size = new System.Drawing.Size(523, 384); + this.Size = new System.Drawing.Size(694, 384); + this.flbuttons.ResumeLayout(false); + this.flbuttons.PerformLayout(); + this.pnlhome.ResumeLayout(false); + this.pnlhome.PerformLayout(); + this.pnlservices.ResumeLayout(false); + this.pnlservices.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -57,5 +228,18 @@ #endregion private System.Windows.Forms.Label label1; + private System.Windows.Forms.Panel pnldivider; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.FlowLayoutPanel flbuttons; + private System.Windows.Forms.Button btnhome; + private System.Windows.Forms.Button btnservices; + private System.Windows.Forms.Button btnping; + private System.Windows.Forms.Panel pnlhome; + private System.Windows.Forms.Label lbdesc; + private System.Windows.Forms.Label lbwhere; + private System.Windows.Forms.Panel pnlservices; + private System.Windows.Forms.Label lbfreebiedesc; + private System.Windows.Forms.Label lbfreebie; + private System.Windows.Forms.Button btnjoinfreebie; } } diff --git a/ShiftOS.WinForms/ShiftnetSites/ShiftSoft.cs b/ShiftOS.WinForms/ShiftnetSites/ShiftSoft.cs index 18968cd..0d84ecc 100644 --- a/ShiftOS.WinForms/ShiftnetSites/ShiftSoft.cs +++ b/ShiftOS.WinForms/ShiftnetSites/ShiftSoft.cs @@ -25,6 +25,18 @@ namespace ShiftOS.WinForms.ShiftnetSites public void OnSkinLoad() { + pnldivider.Tag = "keepbg"; + pnldivider.BackColor = SkinEngine.LoadedSkin.ControlTextColor; + Tools.ControlManager.SetupControls(flbuttons); + Tools.ControlManager.SetupControls(pnlhome); + Tools.ControlManager.SetupControls(pnlservices); + + lbfreebiedesc.Top = lbfreebie.Top + lbfreebie.Height + 5; + btnjoinfreebie.Top = lbfreebiedesc.Top + lbfreebiedesc.Height + 5; + + SetupFreebieUI(); + + lbdesc.Top = lbwhere.Top + lbwhere.Height + 5; } public void OnUpgrade() @@ -33,6 +45,50 @@ namespace ShiftOS.WinForms.ShiftnetSites public void Setup() { + pnlhome.BringToFront(); + } + + private void btnping_Click(object sender, EventArgs e) + { + GoToUrl?.Invoke("shiftnet/shiftsoft/ping"); + } + + private void btnhome_Click(object sender, EventArgs e) + { + pnlhome.BringToFront(); + } + + private void btnservices_Click(object sender, EventArgs e) + { + pnlservices.BringToFront(); + SetupFreebieUI(); + } + + public void SetupFreebieUI() + { + if(SaveSystem.CurrentSave.ShiftnetSubscription == 0) + { + btnjoinfreebie.Enabled = false; + btnjoinfreebie.Text = "You are already subscribed to Freebie Solutions."; + } + else + { + btnjoinfreebie.Enabled = true; + btnjoinfreebie.Text = "Join Freebie Solutions"; + } + btnjoinfreebie.Left = (lbfreebiedesc.Left + lbfreebiedesc.Width) - btnjoinfreebie.Width; + } + + private void btnjoinfreebie_Click(object sender, EventArgs e) + { + Infobox.PromptYesNo("Switch providers", "Would you like to switch from your current Shiftnet provider, " + Applications.DownloadManager.GetAllSubscriptions()[SaveSystem.CurrentSave.ShiftnetSubscription].Name + ", to Freebie Solutions by ShiftSoft?", (res) => + { + if(res == true) + { + SaveSystem.CurrentSave.ShiftnetSubscription = 0; + Infobox.Show("Switch providers", "The operation has completed successfully."); + } + }); } } } diff --git a/ShiftOS.WinForms/ShiftnetSites/ShiftSoft.resx b/ShiftOS.WinForms/ShiftnetSites/ShiftSoft.resx index 1af7de1..cd314f0 100644 --- a/ShiftOS.WinForms/ShiftnetSites/ShiftSoft.resx +++ b/ShiftOS.WinForms/ShiftnetSites/ShiftSoft.resx @@ -117,4 +117,14 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Welcome to ShiftSoft. We understand the troubles of being locked within a digital society. For some, it's a prison. For others, it's all they know. It's what life means for them. + +But for us, it's a safe-haven. We may all be locked within an evolving operating system with no possibility of escaping, but we can at least develop ways of improving life within this binary world, and that's what we at ShiftSoft are doing. + + + The Shiftnet is a wonderful place full of apps, utilities, enhancements and much more for ShiftOS, but it comes at a cost. + +Freebie Solutions takes that cost away. You get free Shiftnet usage, but are locked to sites listed on Ping and you are limited to 256 byte-per-second downloads. Perfect for those situations where Codepoints and shiftnet connectivity are a needed resource. + \ No newline at end of file diff --git a/ShiftOS.WinForms/Stories/LegionStory.cs b/ShiftOS.WinForms/Stories/LegionStory.cs index 056fe85..c52732e 100644 --- a/ShiftOS.WinForms/Stories/LegionStory.cs +++ b/ShiftOS.WinForms/Stories/LegionStory.cs @@ -74,22 +74,10 @@ namespace ShiftOS.WinForms.Stories WriteLine("Anyways, that's all I'll say for now. Have fun on the Shiftnet. I have to go work on something."); WriteLine("One of my friends'll contact you once you've gotten a new service provider."); - Story.PushObjective("Register with a new Shiftnet service provider.", "You've just unlocked the Shiftnet, which has opened up a whole new world of applications and features for ShiftOS. Before you go nuts with it, you may want to register with a better service provider than Freebie Solutions.", () => - { - return SaveSystem.CurrentSave.ShiftnetSubscription != 0; - }, - () => - { - Story.Context.MarkComplete(); - SaveSystem.SaveGame(); - TerminalBackend.PrintPrompt(); - Story.Start("hacker101_breakingbonds_1"); - }); - TerminalBackend.PrefixEnabled = true; - TerminalBackend.PrintPrompt(); - Story.Context.AutoComplete = false; + Story.Context.MarkComplete(); + Story.Start("aiden_shiftnet2"); } [Story("hacker101_breakingbonds_1")] @@ -111,6 +99,9 @@ namespace ShiftOS.WinForms.Stories WriteLine("Before I can do that, however, I need you to do a few things."); WriteLine("I'll assign what I need you to do as an objective. When you're done, I'll tell you what you need to know."); + Story.Context.MarkComplete(); + TerminalBackend.PrefixEnabled = true; + Story.PushObjective("Breaking the Bonds: Errand Boy", @"hacker101 has something he needs to show you, however before he can, you need to do the following: - Buy ""TriWrite"" from Appscape @@ -127,14 +118,25 @@ namespace ShiftOS.WinForms.Stories SaveSystem.SaveGame(); Story.Start("hacker101_breakingbonds_2"); }); - - TerminalBackend.PrefixEnabled = true; - TerminalBackend.PrintPrompt(); - Story.Context.AutoComplete = false; - } + [Story("aiden_shiftnet2")] + public static void AidenShiftnet2() + { + Story.PushObjective("Register with a new Shiftnet service provider.", "You've just unlocked the Shiftnet, which has opened up a whole new world of applications and features for ShiftOS. Before you go nuts with it, you may want to register with a better service provider than Freebie Solutions.", () => + { + return SaveSystem.CurrentSave.ShiftnetSubscription != 0; + }, + () => + { + Story.Context.MarkComplete(); + SaveSystem.SaveGame(); + TerminalBackend.PrintPrompt(); + Story.Start("hacker101_breakingbonds_1"); + }); + Story.Context.AutoComplete = false; + } private static void WriteLine(string text, bool showCharacterName=true) { @@ -159,7 +161,7 @@ namespace ShiftOS.WinForms.Stories { Console.Write(c); ConsoleEx.OnFlush?.Invoke(); - Thread.Sleep(45); + Thread.Sleep(5); } Thread.Sleep(1000); } diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs index 4614842..f6c4383 100644 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ b/ShiftOS.WinForms/WinformsDesktop.cs @@ -50,6 +50,8 @@ namespace ShiftOS.WinForms [Namespace("desktop")] public partial class WinformsDesktop : Form, IDesktop { + public MainMenu.MainMenu ParentMenu = null; + [Command("pushnote")] [RequiresArgument("target")] [RequiresArgument("title")] @@ -921,7 +923,7 @@ namespace ShiftOS.WinForms /// E. private void Desktop_Load(object sender, EventArgs e) { - + SaveSystem.IsSandbox = this.IsSandbox; SaveSystem.Begin(); SetupDesktop(); @@ -964,6 +966,7 @@ namespace ShiftOS.WinForms } private IWindowBorder focused = null; + internal bool IsSandbox = false; public string DesktopName { @@ -1033,10 +1036,17 @@ namespace ShiftOS.WinForms { try { - this.Invoke(new Action(() => + if (this.Visible == true) { - act?.Invoke(); - })); + this.Invoke(new Action(() => + { + act?.Invoke(); + })); + } + else + { + ParentMenu?.Invoke(act); + } } catch { @@ -1105,12 +1115,16 @@ namespace ShiftOS.WinForms public void HideAppLauncher() { - this.Invoke(new Action(() => + try { - currentSettingsPane?.Hide(); - currentSettingsPane = null; - pnladvancedal.Hide(); - })); + this.Invoke(new Action(() => + { + currentSettingsPane?.Hide(); + currentSettingsPane = null; + pnladvancedal.Hide(); + })); + } + catch { } } } diff --git a/ShiftOS_TheReturn/AppearanceManager.cs b/ShiftOS_TheReturn/AppearanceManager.cs index 7cf06c9..e244b77 100644 --- a/ShiftOS_TheReturn/AppearanceManager.cs +++ b/ShiftOS_TheReturn/AppearanceManager.cs @@ -126,6 +126,7 @@ namespace ShiftOS.Engine } + // Provides a list of all open ShiftOS windows. public static List OpenForms = new List(); diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index e98a51e..e36fee6 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -67,6 +67,7 @@ namespace ShiftOS.Engine /// Boolean representing whether the save system is ready to be used. /// public static bool Ready = false; + public static bool IsSandbox = false; /// /// Occurs before the save system connects to the ShiftOS Digital Society. @@ -140,63 +141,126 @@ namespace ShiftOS.Engine Console.WriteLine("[simpl-conf] Reading configuration files (global-3.conf)"); Console.WriteLine("[termdb] Building command database from filesystem..."); TerminalBackend.PopulateTerminalCommands(); - Console.WriteLine("[inetd] Connecting to network..."); - Ready = false; - - if (PreDigitalSocietyConnection != null) + if (IsSandbox == false) { - PreDigitalSocietyConnection?.Invoke(); + Console.WriteLine("[inetd] Connecting to network..."); + + Ready = false; - while (!Ready) + if (PreDigitalSocietyConnection != null) { - Thread.Sleep(10); + PreDigitalSocietyConnection?.Invoke(); + + while (!Ready) + { + Thread.Sleep(10); + } } - } - - bool guidReceived = false; - ServerManager.GUIDReceived += (str) => - { - //Connection successful! Stop waiting! - guidReceived = true; - Console.WriteLine("[inetd] Connection successful."); - }; - try - { + bool guidReceived = false; + ServerManager.GUIDReceived += (str) => + { + //Connection successful! Stop waiting! + guidReceived = true; + Console.WriteLine("[inetd] Connection successful."); + }; - ServerManager.Initiate(UserConfig.Get().DigitalSocietyAddress, UserConfig.Get().DigitalSocietyPort); - //This haults the client until the connection is successful. - while (ServerManager.thisGuid == new Guid()) + try { - Thread.Sleep(10); + + ServerManager.Initiate(UserConfig.Get().DigitalSocietyAddress, UserConfig.Get().DigitalSocietyPort); + //This haults the client until the connection is successful. + while (ServerManager.thisGuid == new Guid()) + { + Thread.Sleep(10); + } + Console.WriteLine("[inetd] DHCP GUID recieved, finished setup"); + FinishBootstrap(); } - Console.WriteLine("[inetd] DHCP GUID recieved, finished setup"); - FinishBootstrap(); + catch (Exception ex) + { + //No errors, this never gets called. + Console.WriteLine("[inetd] SEVERE: " + ex.Message); + Thread.Sleep(3000); + Console.WriteLine("[sys] SEVERE: Cannot connect to server. Shutting down in 5..."); + Thread.Sleep(1000); + Console.WriteLine("[sys] 4..."); + Thread.Sleep(1000); + Console.WriteLine("[sys] 3..."); + Thread.Sleep(1000); + Console.WriteLine("[sys] 2..."); + Thread.Sleep(1000); + Console.WriteLine("[sys] 1..."); + Thread.Sleep(1000); + Console.WriteLine("[sys] Bye bye."); + System.Diagnostics.Process.GetCurrentProcess().Kill(); + } + + //Nothing happens past this point - but the client IS connected! It shouldn't be stuck in that while loop above. } - catch (Exception ex) + else { - //No errors, this never gets called. - Console.WriteLine("[inetd] SEVERE: " + ex.Message); - Thread.Sleep(3000); - Console.WriteLine("[sys] SEVERE: Cannot connect to server. Shutting down in 5..."); - Thread.Sleep(1000); - Console.WriteLine("[sys] 4..."); - Thread.Sleep(1000); - Console.WriteLine("[sys] 3..."); - Thread.Sleep(1000); - Console.WriteLine("[sys] 2..."); - Thread.Sleep(1000); - Console.WriteLine("[sys] 1..."); - Thread.Sleep(1000); - Console.WriteLine("[sys] Bye bye."); - System.Diagnostics.Process.GetCurrentProcess().Kill(); - } + Console.WriteLine("[inetd] Sandbox mode initiating..."); + CurrentSave = new Save + { + IsSandbox = true, + Username = "sandbox", + Password = "sandbox", + SystemName = "shiftos", + Users = new List + { + new ClientSave + { + Username = "user", + Password = "", + Permissions = 0 + } + }, + Class = 0, + ID = new Guid(), + Upgrades = new Dictionary(), + CurrentLegions = null, + IsMUDAdmin = false, + IsPatreon = false, + Language = "english", + LastMonthPaid = 0, + MajorVersion = 1, + MinorVersion = 0, + MusicEnabled = false, + MusicVolume = 100, + MyShop = "", + PasswordHashed = false, + PickupPoint = "", + RawReputation = 0.0f, + Revision = 0, + ShiftnetSubscription = 0, + SoundEnabled = true, + StoriesExperienced = null, + StoryPosition = 0, + UniteAuthToken = "", + }; + + CurrentUser = CurrentSave.Users.First(); + + Localization.SetupTHETRUEDefaultLocals(); + + Shiftorium.Init(); + + TerminalBackend.InStory = false; + TerminalBackend.PrefixEnabled = true; + + Desktop.InvokeOnWorkerThread(new Action(() => + { + ShiftOS.Engine.Scripting.LuaInterpreter.RunSft(Paths.GetPath("kernel.sft")); + })); - //Nothing happens past this point - but the client IS connected! It shouldn't be stuck in that while loop above. + Desktop.InvokeOnWorkerThread(new Action(() => Desktop.PopulateAppLauncher())); + GameReady?.Invoke(); + } })); thread.IsBackground = true; @@ -243,10 +307,6 @@ namespace ShiftOS.Engine Thread.Sleep(10); } - Localization.SetupTHETRUEDefaultLocals(); - - Shiftorium.Init(); - while (CurrentSave.StoryPosition < 1) { Thread.Sleep(10); diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index 1439c0d..be4f086 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -302,15 +302,17 @@ Ping: {ServerManager.DigitalSocietyPing} ms /// The message body public static void SendMessage(string name, string contents) { - var sMsg = new ServerMessage + if (!SaveSystem.IsSandbox) { - Name = name, - Contents = contents, - GUID = thisGuid.ToString(), - }; - PingTimer.Start(); - client.Send(new NetObject("msg", sMsg)); - + var sMsg = new ServerMessage + { + Name = name, + Contents = contents, + GUID = thisGuid.ToString(), + }; + PingTimer.Start(); + client.Send(new NetObject("msg", sMsg)); + } } private static bool singleplayer = false; diff --git a/ShiftOS_TheReturn/Shiftorium.cs b/ShiftOS_TheReturn/Shiftorium.cs index 975939f..7faf336 100644 --- a/ShiftOS_TheReturn/Shiftorium.cs +++ b/ShiftOS_TheReturn/Shiftorium.cs @@ -429,6 +429,9 @@ namespace ShiftOS.Engine /// Whether the upgrade is installed. public static bool UpgradeInstalled(string id) { + if (SaveSystem.IsSandbox == true) + return true; + if (string.IsNullOrWhiteSpace(id)) return true; if (SaveSystem.CurrentSave != null) diff --git a/ShiftOS_TheReturn/Story.cs b/ShiftOS_TheReturn/Story.cs index f473f89..e44d2be 100644 --- a/ShiftOS_TheReturn/Story.cs +++ b/ShiftOS_TheReturn/Story.cs @@ -115,8 +115,16 @@ namespace ShiftOS.Engine t.IsBackground = true; t.Start(); + Console.WriteLine(); + ConsoleEx.ForegroundColor = ConsoleColor.Red; + ConsoleEx.Bold = true; Console.WriteLine("NEW OBJECTIVE:"); + Console.WriteLine(); + + ConsoleEx.ForegroundColor = ConsoleColor.White; + ConsoleEx.Bold = false; Console.WriteLine("A new objective has been added to your system. Run sos.status to find out what you need to do."); + TerminalBackend.PrintPrompt(); } -- cgit v1.2.3 From c3deaa23fffb7011efb2b5b0f7fc3e754d21f600 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 10 Jun 2017 22:02:10 -0400 Subject: Even more menu work. --- ShiftOS.Objects/Save.cs | 78 +-------- .../Applications/ShiftoriumFrontend.cs | 2 - ShiftOS.WinForms/MainMenu/MainMenu.Designer.cs | 188 ++++++++++++++++++++- ShiftOS.WinForms/MainMenu/MainMenu.cs | 120 ++++++++++++- ShiftOS_TheReturn/AudioManager.cs | 4 + ShiftOS_TheReturn/Paths.cs | 9 + ShiftOS_TheReturn/SaveSystem.cs | 41 ++--- 7 files changed, 342 insertions(+), 100 deletions(-) (limited to 'ShiftOS.Objects/Save.cs') diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index 6e7f167..7323028 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -40,85 +40,9 @@ namespace ShiftOS.Objects [Obsolete("This save variable is no longer used in Beta 2.4 and above of ShiftOS. Please use ShiftOS.Engine.SaveSystem.CurrentUser.Username to access the current user's username.")] public string Username { get; set; } - private List _setCpCallbacks = new List(); // everything in this list is called by Codepoints.set() and syncCp(). - private ulong _cp = 0; // locally cached codepoints counter - private Object _cpLock = new Object(); // locked when modifying or reading the codepoints counter - private Object _webLock = new Object(); // locked when communicating with the server - private Timer _updTimer; // timer to start a new sync thread every 5 minutes - - // Sync local Codepoints count with the server. - public void syncCp() - { - new Thread(() => - { - lock (_cpLock) - { - lock (_webLock) - { - var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); - _cp = uc.GetCodepoints(); - } - } - foreach (Action a in _setCpCallbacks) - a(); - }).Start(); - } - - // we have to write these wrapper functions so we can keep _setCpCallbacks private, - // so that it doesn't get serialised - public void addSetCpCallback(Action callback) - { - _setCpCallbacks.Add(callback); - } - - public void removeSetCpCallback(Action callback) - { - _setCpCallbacks.Remove(callback); - } - public bool IsSandbox = false; - public ulong Codepoints - { - get - { - if (IsSandbox == true) - return 0; - if (_updTimer == null) - _updTimer = new Timer((o) => syncCp(), null, 0, 300000); - lock (_cpLock) - { - return _cp; - } - } - set - { - if (IsSandbox == true) - return; - lock (_cpLock) - { - _cp = value; - new Thread(() => - { - lock (_webLock) - { - try - { - var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); - uc.SetCodepoints(value); - } - catch - { } - } - }) - { - IsBackground = false - }.Start(); - } - foreach (Action a in _setCpCallbacks) - a(); - } - } + public ulong Codepoints { get; set; } public Dictionary Upgrades { get; set; } public int StoryPosition { get; set; } diff --git a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs index 5dfb98e..eebd897 100644 --- a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs +++ b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs @@ -59,7 +59,6 @@ namespace ShiftOS.WinForms.Applications public ShiftoriumFrontend() { InitializeComponent(); - SaveSystem.CurrentSave.addSetCpCallback(updatecounter); updatecounter(); Populate(); SetList(); @@ -238,7 +237,6 @@ namespace ShiftOS.WinForms.Applications public bool OnUnload() { - SaveSystem.CurrentSave.removeSetCpCallback(updatecounter); return true; } diff --git a/ShiftOS.WinForms/MainMenu/MainMenu.Designer.cs b/ShiftOS.WinForms/MainMenu/MainMenu.Designer.cs index 62db46d..a056866 100644 --- a/ShiftOS.WinForms/MainMenu/MainMenu.Designer.cs +++ b/ShiftOS.WinForms/MainMenu/MainMenu.Designer.cs @@ -35,7 +35,24 @@ this.button4 = new System.Windows.Forms.Button(); this.button5 = new System.Windows.Forms.Button(); this.lbticker = new System.Windows.Forms.Label(); + this.pnloptions = new System.Windows.Forms.Panel(); + this.txtubase = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtdsport = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.txtdsaddress = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); + this.opt_btncancel = new System.Windows.Forms.Button(); + this.btnsave = new System.Windows.Forms.Button(); + this.flcampaign = new System.Windows.Forms.FlowLayoutPanel(); + this.btnnewgame = new System.Windows.Forms.Button(); + this.btncontinue = new System.Windows.Forms.Button(); + this.button10 = new System.Windows.Forms.Button(); this.flmenu.SuspendLayout(); + this.pnloptions.SuspendLayout(); + this.flowLayoutPanel1.SuspendLayout(); + this.flcampaign.SuspendLayout(); this.SuspendLayout(); // // flmenu @@ -48,7 +65,7 @@ this.flmenu.Controls.Add(this.button4); this.flmenu.Controls.Add(this.button5); this.flmenu.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; - this.flmenu.Location = new System.Drawing.Point(46, 218); + this.flmenu.Location = new System.Drawing.Point(49, 367); this.flmenu.Name = "flmenu"; this.flmenu.Size = new System.Drawing.Size(187, 145); this.flmenu.TabIndex = 0; @@ -84,6 +101,7 @@ this.button3.TabIndex = 2; this.button3.Text = "Settings"; this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); // // button4 // @@ -116,12 +134,161 @@ this.lbticker.Tag = "header3"; this.lbticker.Text = "This is a tickerbar."; // + // pnloptions + // + this.pnloptions.Controls.Add(this.txtubase); + this.pnloptions.Controls.Add(this.label3); + this.pnloptions.Controls.Add(this.txtdsport); + this.pnloptions.Controls.Add(this.label2); + this.pnloptions.Controls.Add(this.txtdsaddress); + this.pnloptions.Controls.Add(this.label1); + this.pnloptions.Controls.Add(this.flowLayoutPanel1); + this.pnloptions.Location = new System.Drawing.Point(49, 26); + this.pnloptions.Name = "pnloptions"; + this.pnloptions.Size = new System.Drawing.Size(432, 290); + this.pnloptions.TabIndex = 2; + // + // txtubase + // + this.txtubase.Location = new System.Drawing.Point(146, 133); + this.txtubase.Name = "txtubase"; + this.txtubase.Size = new System.Drawing.Size(225, 20); + this.txtubase.TabIndex = 6; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(22, 136); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(106, 13); + this.label3.TabIndex = 5; + this.label3.Text = "Unite API base URL:"; + // + // txtdsport + // + this.txtdsport.Location = new System.Drawing.Point(146, 85); + this.txtdsport.Name = "txtdsport"; + this.txtdsport.Size = new System.Drawing.Size(225, 20); + this.txtdsport.TabIndex = 4; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(22, 88); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(99, 13); + this.label2.TabIndex = 3; + this.label2.Text = "Digital Society Port:"; + // + // txtdsaddress + // + this.txtdsaddress.Location = new System.Drawing.Point(146, 54); + this.txtdsaddress.Name = "txtdsaddress"; + this.txtdsaddress.Size = new System.Drawing.Size(225, 20); + this.txtdsaddress.TabIndex = 2; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(22, 57); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(118, 13); + this.label1.TabIndex = 1; + this.label1.Text = "Digital Society Address:"; + // + // flowLayoutPanel1 + // + this.flowLayoutPanel1.AutoSize = true; + this.flowLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.flowLayoutPanel1.Controls.Add(this.opt_btncancel); + this.flowLayoutPanel1.Controls.Add(this.btnsave); + this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft; + this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 259); + this.flowLayoutPanel1.Name = "flowLayoutPanel1"; + this.flowLayoutPanel1.Size = new System.Drawing.Size(432, 31); + this.flowLayoutPanel1.TabIndex = 0; + // + // opt_btncancel + // + this.opt_btncancel.AutoSize = true; + this.opt_btncancel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.opt_btncancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.opt_btncancel.Location = new System.Drawing.Point(377, 3); + this.opt_btncancel.Name = "opt_btncancel"; + this.opt_btncancel.Size = new System.Drawing.Size(52, 25); + this.opt_btncancel.TabIndex = 0; + this.opt_btncancel.Text = "Cancel"; + this.opt_btncancel.UseVisualStyleBackColor = true; + this.opt_btncancel.Click += new System.EventHandler(this.opt_btncancel_Click); + // + // btnsave + // + this.btnsave.AutoSize = true; + this.btnsave.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnsave.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btnsave.Location = new System.Drawing.Point(327, 3); + this.btnsave.Name = "btnsave"; + this.btnsave.Size = new System.Drawing.Size(44, 25); + this.btnsave.TabIndex = 1; + this.btnsave.Text = "Save"; + this.btnsave.UseVisualStyleBackColor = true; + this.btnsave.Click += new System.EventHandler(this.btnsave_Click); + // + // flcampaign + // + this.flcampaign.AutoSize = true; + this.flcampaign.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.flcampaign.Controls.Add(this.btnnewgame); + this.flcampaign.Controls.Add(this.btncontinue); + this.flcampaign.Controls.Add(this.button10); + this.flcampaign.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; + this.flcampaign.Location = new System.Drawing.Point(242, 364); + this.flcampaign.Name = "flcampaign"; + this.flcampaign.Size = new System.Drawing.Size(187, 87); + this.flcampaign.TabIndex = 3; + // + // btnnewgame + // + this.btnnewgame.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btnnewgame.Location = new System.Drawing.Point(3, 3); + this.btnnewgame.Name = "btnnewgame"; + this.btnnewgame.Size = new System.Drawing.Size(181, 23); + this.btnnewgame.TabIndex = 0; + this.btnnewgame.Text = "New Game"; + this.btnnewgame.UseVisualStyleBackColor = true; + this.btnnewgame.Click += new System.EventHandler(this.btnnewgame_Click); + // + // btncontinue + // + this.btncontinue.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btncontinue.Location = new System.Drawing.Point(3, 32); + this.btncontinue.Name = "btncontinue"; + this.btncontinue.Size = new System.Drawing.Size(181, 23); + this.btncontinue.TabIndex = 1; + this.btncontinue.Text = "Continue"; + this.btncontinue.UseVisualStyleBackColor = true; + this.btncontinue.Click += new System.EventHandler(this.btncontinue_Click); + // + // button10 + // + this.button10.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.button10.Location = new System.Drawing.Point(3, 61); + this.button10.Name = "button10"; + this.button10.Size = new System.Drawing.Size(181, 23); + this.button10.TabIndex = 4; + this.button10.Text = "Back"; + this.button10.UseVisualStyleBackColor = true; + this.button10.Click += new System.EventHandler(this.button10_Click); + // // MainMenu // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Black; this.ClientSize = new System.Drawing.Size(1161, 566); + this.Controls.Add(this.flcampaign); + this.Controls.Add(this.pnloptions); this.Controls.Add(this.lbticker); this.Controls.Add(this.flmenu); this.ForeColor = System.Drawing.Color.White; @@ -129,6 +296,11 @@ this.Text = "MainMenu"; this.Load += new System.EventHandler(this.MainMenu_Load); this.flmenu.ResumeLayout(false); + this.pnloptions.ResumeLayout(false); + this.pnloptions.PerformLayout(); + this.flowLayoutPanel1.ResumeLayout(false); + this.flowLayoutPanel1.PerformLayout(); + this.flcampaign.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -143,5 +315,19 @@ private System.Windows.Forms.Button button4; private System.Windows.Forms.Button button5; private System.Windows.Forms.Label lbticker; + private System.Windows.Forms.Panel pnloptions; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; + private System.Windows.Forms.Button opt_btncancel; + private System.Windows.Forms.Button btnsave; + private System.Windows.Forms.TextBox txtubase; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtdsport; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtdsaddress; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.FlowLayoutPanel flcampaign; + private System.Windows.Forms.Button btnnewgame; + private System.Windows.Forms.Button btncontinue; + private System.Windows.Forms.Button button10; } } \ No newline at end of file diff --git a/ShiftOS.WinForms/MainMenu/MainMenu.cs b/ShiftOS.WinForms/MainMenu/MainMenu.cs index 20cd4ec..4b510e2 100644 --- a/ShiftOS.WinForms/MainMenu/MainMenu.cs +++ b/ShiftOS.WinForms/MainMenu/MainMenu.cs @@ -47,11 +47,20 @@ namespace ShiftOS.WinForms.MainMenu tickermove.Interval = 1; tickerreset.Interval = 1000; + pnloptions.Hide(); + flcampaign.Hide(); flmenu.CenterParent(); tickerreset.Start(); } + public void HideOptions() + { + pnloptions.Hide(); + flmenu.BringToFront(); + flmenu.CenterParent(); + } + private void MainMenu_Load(object sender, EventArgs e) { Tools.ControlManager.SetupControls(this); @@ -76,6 +85,12 @@ namespace ShiftOS.WinForms.MainMenu return "Terminal too weird for ya? You can use the Format Editor to generate your own Terminal command parser. No coding knowledge needed!"; case 5: return "Contests are a good way to earn heaps of Codepoints. Head on over to http://getshiftos.ml/Contests for info on current community contests."; + case 6: + return "There's no bugs in this game... But if you find some, please submit them to http://getshiftos.ml/Bugs."; + case 7: + return "SHIFTOS - PROPERTY OF MICHAEL VANOVERBEEK. FOR INTERNAL USE ONLY. Build number = sos_tr_133764 [Just kidding. ShiftOS is open-source. Find the code at http://github.com/shiftos-game/ShiftOS!]"; + case 8: + return "Hold your Codepoints against the wall... when they take everything away. Hold your Codepoints against the wall..."; default: return "Good God. We don't know what to put here."; } @@ -83,7 +98,18 @@ namespace ShiftOS.WinForms.MainMenu private void button1_Click(object sender, EventArgs e) { - Desktop.CurrentDesktop.Show(); + if(System.IO.File.Exists(System.IO.Path.Combine(Paths.SaveDirectory, "autosave.save"))) + { + btncontinue.Show(); + } + else + { + btncontinue.Hide(); + } + flmenu.Hide(); + flcampaign.Show(); + flcampaign.BringToFront(); + flcampaign.CenterParent(); } private void button5_Click(object sender, EventArgs e) @@ -96,5 +122,97 @@ namespace ShiftOS.WinForms.MainMenu (Desktop.CurrentDesktop as WinformsDesktop).IsSandbox = true; Desktop.CurrentDesktop.Show(); } + + private void button3_Click(object sender, EventArgs e) + { + var conf = ShiftOS.Objects.UserConfig.Get(); + + txtubase.Text = conf.UniteUrl; + txtdsaddress.Text = conf.DigitalSocietyAddress; + txtdsport.Text = conf.DigitalSocietyPort.ToString(); + + + pnloptions.Show(); + pnloptions.BringToFront(); + pnloptions.CenterParent(); + } + + private void opt_btncancel_Click(object sender, EventArgs e) + { + HideOptions(); + } + + private void btnsave_Click(object sender, EventArgs e) + { + var conf = ShiftOS.Objects.UserConfig.Get(); + + conf.DigitalSocietyAddress = txtdsaddress.Text; + + int p = 0; + + if(int.TryParse(txtdsport.Text, out p) == false) + { + Infobox.Show("Invalid port number", "The Digital Society Port must be a valid whole number between 0 and 65535."); + return; + } + else + { + if(p < 0 || p > 65535) + { + Infobox.Show("Invalid port number", "The Digital Society Port must be a valid whole number between 0 and 65535."); + return; + } + } + + conf.DigitalSocietyPort = p; + + string unite = txtubase.Text; + if (unite.EndsWith("/")) + { + int len = unite.Length; + int index = len - 1; + int end = 1; + unite = unite.Remove(index, end); + } + conf.UniteUrl = unite; + + System.IO.File.WriteAllText("servers.json", Newtonsoft.Json.JsonConvert.SerializeObject(conf, Newtonsoft.Json.Formatting.Indented)); + + HideOptions(); + } + + private void button10_Click(object sender, EventArgs e) + { + flcampaign.Hide(); + flmenu.Show(); + flmenu.BringToFront(); + flmenu.CenterParent(); + } + + private void btncontinue_Click(object sender, EventArgs e) + { + Desktop.CurrentDesktop.Show(); + + } + + private void btnnewgame_Click(object sender, EventArgs e) + { + string path = System.IO.Path.Combine(Paths.SaveDirectory, "autosave.save"); + if (System.IO.File.Exists(path)) + { + Infobox.PromptYesNo("Campaign", "You are about to start a new game, which will erase any previous progress. Are you sure you want to do this?", (result) => + { + if (result == true) + { + System.IO.File.Delete(path); + Desktop.CurrentDesktop.Show(); + } + }); + } + else + { + Desktop.CurrentDesktop.Show(); + } + } } } diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs index 0a1a210..0950b55 100644 --- a/ShiftOS_TheReturn/AudioManager.cs +++ b/ShiftOS_TheReturn/AudioManager.cs @@ -125,6 +125,10 @@ namespace ShiftOS.Engine } if (play) { + while(_out.PlaybackState == PlaybackState.Playing) + { + Thread.Sleep(10); + } ShiftOS.Engine.AudioManager.Stop(); _out = new WaveOut(); var mp3 = new WaveFileReader(str); diff --git a/ShiftOS_TheReturn/Paths.cs b/ShiftOS_TheReturn/Paths.cs index 5b75ae6..332cdd3 100644 --- a/ShiftOS_TheReturn/Paths.cs +++ b/ShiftOS_TheReturn/Paths.cs @@ -94,6 +94,15 @@ namespace ShiftOS.Engine } + public static string SaveDirectory + { + get + { + string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + return System.IO.Path.Combine(appdata, "ShiftOS", "saves"); + } + } + /// /// Gets all full paths without their keynames. /// diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index c5a6a51..18f8f78 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -575,14 +575,14 @@ namespace ShiftOS.Engine public static void ReadSave() { //Migrate old saves. - if(System.IO.Directory.Exists("C:\\ShiftOS2")) + if (System.IO.Directory.Exists("C:\\ShiftOS2")) { Console.WriteLine("Old save detected. Migrating filesystem to MFS..."); foreach (string file in System.IO.Directory.EnumerateDirectories("C:\\ShiftOS2") .Select(d => new DirectoryInfo(d).FullName)) { - if(!Utils.DirectoryExists(file.Replace("C:\\ShiftOS2\\", "0:/").Replace("\\", "/"))) - Utils.CreateDirectory(file.Replace("C:\\ShiftOS2\\", "0:/").Replace("\\", "/")); + if (!Utils.DirectoryExists(file.Replace("C:\\ShiftOS2\\", "0:/").Replace("\\", "/"))) + Utils.CreateDirectory(file.Replace("C:\\ShiftOS2\\", "0:/").Replace("\\", "/")); } foreach (string file in System.IO.Directory.EnumerateFiles("C:\\ShiftOS2")) { @@ -594,25 +594,18 @@ namespace ShiftOS.Engine } + string path = Path.Combine(Paths.SaveDirectory, "autosave.save"); - if (Utils.FileExists(Paths.SaveFileInner)) + if (System.IO.File.Exists(Path.Combine(Paths.SaveDirectory, "autosave.save"))) { - oobe.ShowSaveTransfer(JsonConvert.DeserializeObject(Utils.ReadAllText(Paths.SaveFileInner))); + CurrentSave = JsonConvert.DeserializeObject(System.IO.File.ReadAllText(path)); } else { - if (Utils.FileExists(Paths.GetPath("user.dat"))) - { - string token = Utils.ReadAllText(Paths.GetPath("user.dat")); - - ServerManager.SendMessage("mud_token_login", token); - } - else - { - NewSave(); - } + NewSave(); } + } /// @@ -644,15 +637,25 @@ namespace ShiftOS.Engine Console.Write("{SE_SAVING}... "); if (SaveSystem.CurrentSave != null) { - Utils.WriteAllText(Paths.GetPath("user.dat"), CurrentSave.UniteAuthToken); var serialisedSaveFile = JsonConvert.SerializeObject(CurrentSave, Formatting.Indented); new Thread(() => { - // please don't do networking on the main thread if you're just going to - // discard the response, it's extremely slow - ServerManager.SendMessage("mud_save", serialisedSaveFile); + try + { + // please don't do networking on the main thread if you're just going to + // discard the response, it's extremely slow + ServerManager.SendMessage("mud_save", serialisedSaveFile); + } + catch { } }) { IsBackground = false }.Start(); + if (!System.IO.Directory.Exists(Paths.SaveDirectory)) + { + System.IO.Directory.CreateDirectory(Paths.SaveDirectory); + + } + + System.IO.File.WriteAllText(Path.Combine(Paths.SaveDirectory, "autosave.save"), serialisedSaveFile); } if (!Shiftorium.Silent) Console.WriteLine(" ...{DONE}."); -- cgit v1.2.3