aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn/AppearanceManager.cs
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-01-08 09:57:10 -0500
committerMichael <[email protected]>2017-01-08 09:57:10 -0500
commitf30dcf5ef41d54c588d7b42c48be8d941abba72e (patch)
tree7705f99b965673b1c034ac2b1c56e65072c827df /ShiftOS_TheReturn/AppearanceManager.cs
parent69dfad54724d4176dfce238a8d7e73970e6eef24 (diff)
downloadshiftos_thereturn-f30dcf5ef41d54c588d7b42c48be8d941abba72e.tar.gz
shiftos_thereturn-f30dcf5ef41d54c588d7b42c48be8d941abba72e.tar.bz2
shiftos_thereturn-f30dcf5ef41d54c588d7b42c48be8d941abba72e.zip
Initial upload
Diffstat (limited to 'ShiftOS_TheReturn/AppearanceManager.cs')
-rw-r--r--ShiftOS_TheReturn/AppearanceManager.cs184
1 files changed, 184 insertions, 0 deletions
diff --git a/ShiftOS_TheReturn/AppearanceManager.cs b/ShiftOS_TheReturn/AppearanceManager.cs
new file mode 100644
index 0000000..b600ad9
--- /dev/null
+++ b/ShiftOS_TheReturn/AppearanceManager.cs
@@ -0,0 +1,184 @@
+#define MUD_RAPIDDEV
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using Newtonsoft.Json;
+using static ShiftOS.Engine.SaveSystem;
+
+namespace ShiftOS.Engine
+{
+ public static class AppearanceManager
+ {
+ [Obsolete("Please use Localization.GetAllLanguages().")]
+ public static string[] GetLanguages()
+ {
+ return Localization.GetAllLanguages();
+ }
+
+ public static void AddFocusEvents(Control ctrl, Control child)
+ {
+ child.Enter += (o, a) =>
+ {
+ ctrl.BringToFront();
+ };
+ child.MouseDown += (o, a) =>
+ {
+ ctrl.BringToFront();
+ };
+
+ foreach (Control c in child.Controls)
+ {
+ c.Enter += (o, a) =>
+ {
+ ctrl.BringToFront();
+ };
+ c.MouseDown += (o, a) =>
+ {
+ ctrl.BringToFront();
+ };
+
+ try
+ {
+ AddFocusEvents(ctrl, c);
+ }
+ catch { }
+ }
+ }
+
+
+ public static string LastTerminalText { get; set; }
+ public static int CurrentPosition { get; set; }
+ public static int LastLength { get; set; }
+
+
+ public static void Minimize(IWindowBorder form)
+ {
+ winmgr.Minimize(form);
+ }
+
+ public static void Maximize(IWindowBorder form)
+ {
+ winmgr.Maximize(form);
+ }
+
+
+
+ public static List<IWindowBorder> OpenForms = new List<IWindowBorder>();
+
+ public static bool CanOpenWindow(IShiftOSWindow form)
+ {
+#if !MUD_RAPIDDEV
+ if (ServerManager.IsSingleplayer)
+ {
+ foreach (var attr in form.GetType().GetCustomAttributes(false))
+ {
+ if (attr is MultiplayerOnlyAttribute)
+ return false;
+ }
+ }
+#endif
+ return true;
+ }
+
+ public static void SetupWindow(IShiftOSWindow form)
+ {
+ winmgr.SetupWindow(form);
+ Desktop.ResetPanelButtons();
+ }
+
+ public static void Close(IShiftOSWindow win)
+ {
+ winmgr.Close(win);
+ Desktop.ResetPanelButtons();
+ }
+
+ public static void SetupDialog(IShiftOSWindow form)
+ {
+ winmgr.SetupDialog(form);
+ Desktop.ResetPanelButtons();
+ }
+
+ private static WindowManager winmgr = null;
+
+ public static double Measure(this string text, Font font)
+ {
+ return Graphics.FromImage(new Bitmap(1, 1)).MeasureString(text, font).Width;
+ }
+
+ public static void Initiate(WindowManager mgr)
+ {
+ winmgr = mgr;
+ }
+
+ [Obsolete("This is a stub.")]
+ public static void DoWinformsSkinningMagicOnWpf(this UserControl ctrl)
+ {
+ //SetupControls(ctrl);
+ }
+
+ public static event EmptyEventHandler OnExit;
+
+ internal static void Exit()
+ {
+ OnExit?.Invoke();
+ //disconnect from MUD
+ ServerManager.Disconnect();
+ }
+
+
+ internal static bool BordersHidden(Form frm)
+ {
+ string t = frm.Tag as string;
+ if (t == null)
+ return false;
+
+ return t.Contains("hidden");
+ }
+
+ public static ITerminalWidget ConsoleOut { get; set; }
+
+ public static void StartConsoleOut()
+ {
+ Console.SetOut(new TerminalTextWriter());
+ }
+
+ public static void Invoke(Action act)
+ {
+ winmgr.InvokeAction(act);
+ }
+ }
+
+ public interface ITerminalWidget
+ {
+ void Write(string text);
+ void WriteLine(string text);
+ void Clear();
+ void SelectBottom();
+ }
+
+ public abstract class WindowManager
+ {
+ public abstract void Minimize(IWindowBorder border);
+ public abstract void Maximize(IWindowBorder border);
+
+ public abstract void Close(IShiftOSWindow win);
+
+ public abstract void SetupWindow(IShiftOSWindow win);
+ public abstract void SetupDialog(IShiftOSWindow win);
+
+ public abstract void InvokeAction(Action act);
+ }
+
+ public interface IWindowBorder
+ {
+ void Close();
+ string Text { get; set; }
+ IShiftOSWindow ParentWindow { get; set; }
+ }
+}