aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/WinformsWindowManager.cs
diff options
context:
space:
mode:
authorwilliam341 <[email protected]>2017-05-28 12:37:00 -0700
committerGitHub <[email protected]>2017-05-28 12:37:00 -0700
commit771c20cfb3a703e0f1550fdcf9eb07b78298c944 (patch)
tree59cb532e15ebff313fdba2be264d78ec0033f407 /ShiftOS.WinForms/WinformsWindowManager.cs
parent496b0cbf8659c99203f48210fd39c572400ae623 (diff)
parentc7ba7d733c756d196f98dd4533289a1ef4db715f (diff)
downloadshiftos_thereturn-771c20cfb3a703e0f1550fdcf9eb07b78298c944.tar.gz
shiftos_thereturn-771c20cfb3a703e0f1550fdcf9eb07b78298c944.tar.bz2
shiftos_thereturn-771c20cfb3a703e0f1550fdcf9eb07b78298c944.zip
Merge pull request #1 from shiftos-game/master
welp, no longer a dev.
Diffstat (limited to 'ShiftOS.WinForms/WinformsWindowManager.cs')
-rw-r--r--ShiftOS.WinForms/WinformsWindowManager.cs152
1 files changed, 139 insertions, 13 deletions
diff --git a/ShiftOS.WinForms/WinformsWindowManager.cs b/ShiftOS.WinForms/WinformsWindowManager.cs
index b8f0cae..8bff387 100644
--- a/ShiftOS.WinForms/WinformsWindowManager.cs
+++ b/ShiftOS.WinForms/WinformsWindowManager.cs
@@ -36,6 +36,24 @@ namespace ShiftOS.WinForms
{
internal class WinformsWindowManager : WindowManager
{
+ public int DesktopHeight
+ {
+ get
+ {
+ return Desktop.Size.Height - ((Shiftorium.UpgradeInstalled("desktop") == true) ? SkinEngine.LoadedSkin.DesktopPanelHeight : 0);
+ }
+ }
+
+ public int TopLocation
+ {
+ get
+ {
+ if (!Shiftorium.UpgradeInstalled("desktop"))
+ return 0;
+ return ((SkinEngine.LoadedSkin.DesktopPanelPosition == 0) ? SkinEngine.LoadedSkin.DesktopPanelHeight : 0);
+ }
+ }
+
public override void Close(IShiftOSWindow win)
{
(win as UserControl).Close();
@@ -46,6 +64,14 @@ namespace ShiftOS.WinForms
Desktop.InvokeOnWorkerThread(act);
}
+ public WinformsWindowManager()
+ {
+ Shiftorium.Installed += () =>
+ {
+ SetupWindows();
+ };
+ }
+
public override void Maximize(IWindowBorder form)
{
try
@@ -94,19 +120,30 @@ namespace ShiftOS.WinForms
var wb = new WindowBorder(form as UserControl);
wb.IsDialog = true;
-
- wb.Show();
+ Desktop.ShowWindow(wb);
}
public override void SetupWindow(IShiftOSWindow form)
{
- if (!AppearanceManager.CanOpenWindow(form))
+ foreach(var attr in form.GetType().GetCustomAttributes(true))
{
- Infobox.Show("{MULTIPLAYER_ONLY}", "{MULTIPLAYER_ONLY_EXP}");
- return;
+ if(attr is MultiplayerOnlyAttribute)
+ {
+ if(KernelWatchdog.MudConnected == false)
+ {
+ Infobox.PromptYesNo("Disconnected from MUD", "This application requires a connection to the MUD. Would you like to reconnect?", new Action<bool>((answer) =>
+ {
+ if(answer == true)
+ {
+ KernelWatchdog.MudConnected = true;
+ SetupWindow(form);
+ }
+ }));
+ return;
+ }
+ }
}
-
if (!Shiftorium.UpgradeAttributesUnlocked(form.GetType()))
{
Console.WriteLine("{APP_NOT_FOUND}");
@@ -140,18 +177,21 @@ namespace ShiftOS.WinForms
if (maxWindows > 0)
{
- List<WindowBorder> formstoclose = new List<WindowBorder>();
-
- foreach (WindowBorder frm in AppearanceManager.OpenForms)
+ var windows = new List<WindowBorder>();
+ foreach(var WB in AppearanceManager.OpenForms)
{
- formstoclose.Add(frm);
-
+ if (WB is WindowBorder)
+ windows.Add(WB as WindowBorder);
}
+ List<WindowBorder> formstoclose = new List<WindowBorder>(windows.Where(x => x.IsDialog == false).ToArray());
+
while (formstoclose.Count > maxWindows - 1)
{
- formstoclose[0].Close();
+ this.Close(formstoclose[0].ParentWindow);
+ AppearanceManager.OpenForms.Remove(formstoclose[0]);
formstoclose.RemoveAt(0);
+
}
}
}
@@ -159,7 +199,93 @@ namespace ShiftOS.WinForms
var wb = new WindowBorder(form as UserControl);
- ControlManager.SetupWindows();
+ FormClosedEventHandler onClose = (o,a)=> { };
+ onClose = (o, a) =>
+ {
+ SetupWindows();
+ wb.FormClosed -= onClose;
+ };
+ wb.FormClosed += onClose;
+ Desktop.ShowWindow(wb);
+ SetupWindows();
+ }
+
+ public void SetupWindows()
+ {
+ var windows = new List<WindowBorder>();
+ foreach(var win in AppearanceManager.OpenForms)
+ {
+ if (win is WindowBorder)
+ if ((win as WindowBorder).IsDialog == false)
+ windows.Add(win as WindowBorder);
+ }
+
+ if (Shiftorium.UpgradeInstalled("wm_free_placement"))
+ return;
+
+ else if (windows.Count == 4)
+ {
+ var w1 = windows[0];
+ var w2 = windows[1];
+ var w3 = windows[2];
+ var w4 = windows[3];
+ w1.Location = new Point(0, TopLocation);
+ w1.Width = Desktop.Size.Width / 2;
+ w1.Height = DesktopHeight / 2;
+ w2.Left = w1.Width;
+ w2.Width = w1.Width;
+ w2.Height = w1.Height;
+ w2.Top = w1.Top;
+ w3.Top = w2.Height;
+ w3.Height = w1.Height;
+ w3.Left = 0;
+ w3.Width = w1.Width;
+ w4.Width = w3.Width;
+ w4.Top = w3.Top;
+ w4.Left = w3.Width;
+ w4.Height = w3.Height;
+ }
+ else if(windows.Count == 3)
+ {
+ var w1 = windows[0];
+ var w2 = windows[1];
+ var w3 = windows[2];
+ w1.Location = new Point(0, TopLocation);
+ w1.Width = Desktop.Size.Width / 2;
+ w1.Height = DesktopHeight / 2;
+ w2.Left = w1.Width;
+ w2.Width = w1.Width;
+ w2.Height = w1.Height;
+ w2.Top = w1.Top;
+ w3.Top = w2.Height;
+ w3.Height = w1.Height;
+ w3.Left = 0;
+ w3.Width = w1.Width + w2.Width;
+ }
+ else if (windows.Count == 2)
+ {
+ var w1 = windows[0];
+ var w2 = windows[1];
+
+ w1.Location = new Point(0, TopLocation);
+ w1.Width = Desktop.Size.Width / 2;
+ w1.Height = DesktopHeight;
+ w2.Left = w1.Width;
+ w2.Width = w1.Width;
+ w2.Height = w1.Height;
+ w2.Top = w1.Top;
+
+ }
+ else if(windows.Count == 1)
+ {
+ var win = windows.FirstOrDefault();
+ if(win != null)
+ {
+ win.Size = new Size(Desktop.Size.Width, DesktopHeight);
+ win.Location = new Point(0, this.TopLocation);
+ }
+ }
+
}
}
}