diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index 2a02bbc..cc19c79 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -35,6 +35,9 @@ namespace ShiftOS.Objects public class Save { + public int MusicVolume { get; set; } + public int SfxVolume { get; set; } + [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/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index a14cc58..02c4cc0 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -491,9 +491,9 @@ namespace ShiftOS.WinForms.Applications TerminalBackend.InStory = false; TerminalBackend.PrintPrompt(); bool help_entered = false; - TerminalBackend.TextSent += (text) => + TerminalBackend.CommandProcessed += (text, args) => { - if (text == "sos.help" && help_entered == false) + if (text.EndsWith("sos.help") && help_entered == false) help_entered = true; }; while (help_entered == false) @@ -523,10 +523,10 @@ namespace ShiftOS.WinForms.Applications TerminalBackend.InStory = false; bool winopenEntered = false; TerminalBackend.PrintPrompt(); - TerminalBackend.TextSent += (text) => + TerminalBackend.CommandProcessed += (text, args) => { if (help_entered == true) - if (text == "win.open" && winopenEntered == false) + if (text.EndsWith("win.open") && winopenEntered == false) winopenEntered = true; }; while (winopenEntered == false) diff --git a/ShiftOS.WinForms/AudioManager.cs b/ShiftOS.WinForms/AudioManager.cs index eb0e798..ec12614 100644 --- a/ShiftOS.WinForms/AudioManager.cs +++ b/ShiftOS.WinForms/AudioManager.cs @@ -74,7 +74,19 @@ namespace ShiftOS.WinForms MemoryStream str = null; NAudio.Wave.Mp3FileReader mp3 = null; NAudio.Wave.WaveOut o = null; - while (!Engine.SaveSystem.ShuttingDown) + bool shuttingDown = false; + + Engine.AppearanceManager.OnExit += () => + { + shuttingDown = true; + o?.Stop(); + o?.Dispose(); + mp3?.Close(); + mp3?.Dispose(); + str?.Close(); + str?.Dispose(); + }; + while (shuttingDown == false) { str = new MemoryStream(GetRandomSong()); mp3 = new NAudio.Wave.Mp3FileReader(str); @@ -87,14 +99,15 @@ namespace ShiftOS.WinForms c = true; }; while (!c) + { + try + { + o.Volume = (float)Engine.SaveSystem.CurrentSave.MusicVolume / 100; + } + catch { } Thread.Sleep(10); - str.Dispose(); - o.Dispose(); - mp3.Dispose(); + } } - str?.Dispose(); - o?.Dispose(); - mp3?.Dispose(); }); athread.IsBackground = true; athread.Start(); diff --git a/ShiftOS.WinForms/Program.cs b/ShiftOS.WinForms/Program.cs index 73215d4..8f65265 100644 --- a/ShiftOS.WinForms/Program.cs +++ b/ShiftOS.WinForms/Program.cs @@ -68,11 +68,7 @@ namespace ShiftOS.WinForms SkinEngine.SetIconProber(new ShiftOSIconProvider()); ShiftOS.Engine.AudioManager.Init(new ShiftOSAudioProvider()); Localization.RegisterProvider(new WFLanguageProvider()); - AppearanceManager.OnExit += () => - { - Environment.Exit(0); - }; - + TutorialManager.RegisterTutorial(new Oobe()); TerminalBackend.TerminalRequested += () => diff --git a/ShiftOS.WinForms/Tools/DitheringEngine.cs b/ShiftOS.WinForms/Tools/DitheringEngine.cs index f96a45a..d042a40 100644 --- a/ShiftOS.WinForms/Tools/DitheringEngine.cs +++ b/ShiftOS.WinForms/Tools/DitheringEngine.cs @@ -226,6 +226,53 @@ namespace ShiftOS.WinForms.Tools } #endif + public static int GetClosestColor(int gray, bool eightBits, bool sixBits, bool fourBits, bool twoBits) + { + int newgray = gray; + if (!eightBits) + { + if (sixBits) + { + newgray = gray >> 2; + } + else + { + if (fourBits) + { + newgray = (int)linear(gray, 0, 255, 0, 15) * 4; + } + else + { + if (twoBits) + { + if (gray > 127 + 63) + { + newgray = 255; + } + else if (gray > 127) + newgray = 127 + 63; + else if (gray > 63) + { + newgray = 127; + } + else if (gray > 0) + newgray = 63; + else + newgray = 0; + } + else + { + if (gray > 127) + newgray = 255; + else + newgray = 0; + } + } + } + } + return newgray; + } + #if FLOYDSTEINBERG public static Image DitherImage(Image source) { @@ -260,75 +307,78 @@ namespace ShiftOS.WinForms.Tools bool eightBits = Shiftorium.UpgradeInstalled("color_depth_8_bits"); bool color_depth_floydsteinberg = Shiftorium.UpgradeInstalled("color_depth_floyd-steinberg_dithering"); bool dithering = Shiftorium.UpgradeInstalled("color_depth_dithering"); - - if (!sixteenBits) + bool twentyfourbits = Shiftorium.UpgradeInstalled("color_depth_24_bits"); + if (twentyfourbits) + { + sourceArr.CopyTo(destArr, 0); + } + else { - if (dithering == true) - { - if (false == true) - { + if (!sixteenBits) + { + if (dithering == true) + { + if (false == true) + { + + } + else + { + int error = 0; + for (int i = 0; i < destArr.Length; i += 3) + { + byte r = sourceArr[i]; + byte g = sourceArr[i + 1]; + byte b = sourceArr[i + 2]; + + if (SkinEngine.LoadedSkin.SystemKey == Color.FromArgb(r, g, b)) + { + destArr[i] = r; + destArr[i + 1] = g; + destArr[i + 2] = b; + continue; + } + + + int gray = (((r + g + b) / 3) + error); + int newgray = gray; + newgray = GetClosestColor(gray, eightBits, sixBits, fourBits, twoBits); + if (newgray > 255) + newgray = 255; + if (newgray < 0) + newgray = 0; + error = gray - newgray; + destArr[i] = (byte)newgray; + destArr[i + 1] = (byte)newgray; + destArr[i + 2] = (byte)newgray; + + } + } } + else { - int error = 0; - for (int i = 0; i < destArr.Length; i += 3) + for (int i = 0; i < sourceArr.Length; i += 3) { byte r = sourceArr[i]; byte g = sourceArr[i + 1]; byte b = sourceArr[i + 2]; - - int gray = (((r + g + b) / 3) + error); - int newgray = gray; - if (!eightBits) + if (SkinEngine.LoadedSkin.SystemKey == Color.FromArgb(r, g, b)) { - if (sixBits) - { - newgray = gray >> 2; - } - else - { - if (fourBits) - { - newgray = (int)linear(gray, 0, 255, 0, 63) * 4; - } - else - { - if (twoBits) - { - if (gray > 127 + 63) - { - newgray = 255; - } - else if (gray > 127) - newgray = 127 + 63; - else if (gray > 63) - { - newgray = 127; - } - else if (gray > 0) - newgray = 63; - else - newgray = 0; - } - else - { - if (gray > 127) - newgray = 255; - else - newgray = 0; - } - } - } + destArr[i] = r; + destArr[i + 1] = g; + destArr[i + 2] = b; + continue; } - if (newgray > 255) - newgray = 255; - if (newgray < 0) - newgray = 0; - error = gray - newgray; + + int gray = (r + g + b) / 3; + int newgray = GetClosestColor(gray, eightBits, sixBits, fourBits, twoBits); destArr[i] = (byte)newgray; - destArr[i+1] = (byte)newgray; - destArr[i+2] = (byte)newgray; + destArr[i + 1] = (byte)newgray; + destArr[i + 2] = (byte)newgray; + + } } diff --git a/ShiftOS_TheReturn/AppearanceManager.cs b/ShiftOS_TheReturn/AppearanceManager.cs index 42642f8..d8004bc 100644 --- a/ShiftOS_TheReturn/AppearanceManager.cs +++ b/ShiftOS_TheReturn/AppearanceManager.cs @@ -223,6 +223,7 @@ namespace ShiftOS.Engine /// internal static void Exit() { + OnExit?.Invoke(); //disconnect from MUD ServerManager.Disconnect(); Environment.Exit(0); diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs index c50bd24..fff3369 100644 --- a/ShiftOS_TheReturn/AudioManager.cs +++ b/ShiftOS_TheReturn/AudioManager.cs @@ -88,7 +88,13 @@ namespace ShiftOS.Engine _reader = new AudioFileReader(file); _out = new WaveOut(); _out.Init(_reader); - _out.Volume = _provider.Volume; + try + { + _out.Volume = (float)SaveSystem.CurrentSave.SfxVolume / 100; + } + catch + { + } _out.Play(); _out.PlaybackStopped += (o, a) => { PlayCompleted?.Invoke(); }; } diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index 5b7674a..6e59311 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -378,6 +378,40 @@ 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.")] + [RequiresArgument("value")] + public static bool SetSfxVolume(Dictionary args) + { + int value = int.Parse(args["value"].ToString()); + if (value >= 0 && value <= 100) + { + SaveSystem.CurrentSave.SfxVolume = value; + SaveSystem.SaveGame(); + } + else + { + Console.WriteLine("Volume must be between 0 and 100!"); + } + return true; + } + + [Command("setmusicvolume", description ="Set the music volume to a value between 1 and 100.")] + [RequiresArgument("value")] + public static bool SetMusicVolume(Dictionary args) + { + int value = int.Parse(args["value"].ToString()); + if(value >= 0 && value <= 100) + { + SaveSystem.CurrentSave.MusicVolume = value; + SaveSystem.SaveGame(); + } + else + { + Console.WriteLine("Volume must be between 0 and 100!"); + } + return true; + } + [RemoteLock] [Command("shutdown")] public static bool Shutdown()