diff options
Diffstat (limited to 'ShiftOS.WinForms')
| -rw-r--r-- | ShiftOS.WinForms/ShiftOS.WinForms.csproj | 2 | ||||
| -rw-r--r-- | ShiftOS.WinForms/VirusTestCommands.cs | 25 | ||||
| -rw-r--r-- | ShiftOS.WinForms/Viruses/WindowsEverywhere.cs | 83 | ||||
| -rw-r--r-- | ShiftOS.WinForms/WinformsDesktop.cs | 1 |
4 files changed, 111 insertions, 0 deletions
diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 901da41..f1c92da 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -463,6 +463,8 @@ <DependentUpon>UniteSignupDialog.cs</DependentUpon> </Compile> <Compile Include="VirtualEnvironments.cs" /> + <Compile Include="Viruses\WindowsEverywhere.cs" /> + <Compile Include="VirusTestCommands.cs" /> <Compile Include="VisualBasicStuff.cs" /> <Compile Include="WFLanguageProvider.cs" /> <Compile Include="WidgetManager.cs" /> diff --git a/ShiftOS.WinForms/VirusTestCommands.cs b/ShiftOS.WinForms/VirusTestCommands.cs new file mode 100644 index 0000000..09f1a36 --- /dev/null +++ b/ShiftOS.WinForms/VirusTestCommands.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms +{ +#if DEBUG + public static class VirusTestCommands + { + [Command("infect", description = "DEBUG: Infect the system with a virus.")] + [RequiresArgument("id")] + [RequiresArgument("threatlevel")] + public static void Infect(Dictionary<string, object> args) + { + var id = args["id"].ToString(); + var threatlevel = Convert.ToInt32(args["threatlevel"].ToString()); + + VirusManager.Infect(id, threatlevel); + } + } +#endif +}
\ No newline at end of file diff --git a/ShiftOS.WinForms/Viruses/WindowsEverywhere.cs b/ShiftOS.WinForms/Viruses/WindowsEverywhere.cs new file mode 100644 index 0000000..df73d58 --- /dev/null +++ b/ShiftOS.WinForms/Viruses/WindowsEverywhere.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms.Viruses +{ + [Virus("windows_everywhere", "Windows Everywhere", "Makes the windows dance around the screen if the user has the WM Free Placement upgrade. Speed depends on threatlevel.")] + [RequiresUpgrade("wm_free_placement")] + public class WindowsEverywhere : IVirus + { + private System.Windows.Forms.Timer timer = null; + private int ThreatLevel = 1; + private Dictionary<string, System.Drawing.Point> Velocities = null; + + + public void Infect(int threatlevel) + { + Velocities = new Dictionary<string, System.Drawing.Point>(); + ThreatLevel = threatlevel; + timer = new System.Windows.Forms.Timer(); + timer.Interval = 50; + timer.Tick += (o, a) => + { + foreach (var win in AppearanceManager.OpenForms) + { + var border = (win as WindowBorder); + var loc = border.Location; + var velocity = new System.Drawing.Point(1, 1); + string vKey = border.GetType().Name + "_" + border.GetHashCode(); + if (!Velocities.ContainsKey(vKey)) + { + Velocities.Add(vKey, velocity); + } + else + { + velocity = Velocities[vKey]; + } + + //Calculate proper velocity. + if (border.Top <= 0) + { + velocity.Y = 1; + } + if (border.Top + border.Height >= System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height) + { + velocity.Y = -1; + } + if (border.Left <= 0) + { + velocity.X = 1; + } + if (border.Left + border.Width >= System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width) + { + velocity.X = -1; + } + //save velocity in memory. + Velocities[vKey] = velocity; + //convert using threatlevel + + var velocityX = velocity.X * (threatlevel * 4); + var velocityY = velocity.Y * (threatlevel * 4); + + loc.X += velocityX; + loc.Y += velocityY; + + border.Location = loc; + } + }; + timer.Start(); + } + + public void Disinfect() + { + timer.Stop(); + Velocities.Clear(); + ThreatLevel = 0; + timer = null; + } + } +} diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs index 7508262..d60b6f6 100644 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ b/ShiftOS.WinForms/WinformsDesktop.cs @@ -226,6 +226,7 @@ namespace ShiftOS.WinForms SaveSystem.GameReady += () => { + VirusManager.Init(); this.Invoke(new Action(LoadIcons)); if (this.Visible == true) this.Invoke(new Action(() => SetupDesktop())); |
