aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Wpf/Applications/MainWindow.xaml.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.Wpf/Applications/MainWindow.xaml.cs
parent69dfad54724d4176dfce238a8d7e73970e6eef24 (diff)
downloadshiftos_thereturn-f30dcf5ef41d54c588d7b42c48be8d941abba72e.tar.gz
shiftos_thereturn-f30dcf5ef41d54c588d7b42c48be8d941abba72e.tar.bz2
shiftos_thereturn-f30dcf5ef41d54c588d7b42c48be8d941abba72e.zip
Initial upload
Diffstat (limited to 'ShiftOS.Wpf/Applications/MainWindow.xaml.cs')
-rw-r--r--ShiftOS.Wpf/Applications/MainWindow.xaml.cs179
1 files changed, 179 insertions, 0 deletions
diff --git a/ShiftOS.Wpf/Applications/MainWindow.xaml.cs b/ShiftOS.Wpf/Applications/MainWindow.xaml.cs
new file mode 100644
index 0000000..478c652
--- /dev/null
+++ b/ShiftOS.Wpf/Applications/MainWindow.xaml.cs
@@ -0,0 +1,179 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using ShiftOS.Engine;
+using backend = ShiftOS.Engine.TerminalBackend;
+
+namespace ShiftOS.Wpf
+{
+ /// <summary>
+ /// Interaction logic for MainWindow.xaml
+ /// </summary>
+ [Launcher("Terminal", false)]
+ public partial class Terminal : UserControl, IShiftOSWindow
+ {
+ public Terminal()
+ {
+ InitializeComponent();
+ Startup.ConsoleOut = this.txtterm;
+
+ if (SaveSystem.CurrentSave == null)
+ {
+ Startup.InitiateEngine(new WpfTerminalTextWriter());
+ SaveSystem.GameReady += () =>
+ {
+ try
+ {
+ Dispatcher.Invoke(new Action(() =>
+ {
+ txtterm.Text = "";
+ backend.PrefixEnabled = true;
+ backend.InStory = false;
+ if (SaveSystem.CurrentSave.StoryPosition != 8)
+ {
+ Story.RunFromInternalResource("sys_shiftoriumstory");
+ SaveSystem.CurrentSave.StoryPosition = 8;
+ }
+ Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
+ txtterm.Background = SkinEngine.LoadedSkin.TerminalBackColor.CreateBrush();
+ txtterm.Foreground = SkinEngine.LoadedSkin.TerminalForeColor.CreateBrush();
+ txtterm.SetFont(SkinEngine.LoadedSkin.TerminalFont);
+ }));
+ }
+ catch { }
+ };
+ }
+ else
+ {
+ Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
+ }
+ txtterm.Background = SkinEngine.LoadedSkin.TerminalBackColor.CreateBrush();
+ txtterm.Foreground = SkinEngine.LoadedSkin.TerminalForeColor.CreateBrush();
+
+ txtterm.GotFocus += (o, a) =>
+ {
+ Startup.ConsoleOut = txtterm;
+ };
+
+ txtterm.Focus();
+
+ }
+
+ public void OnLoad()
+ {
+ this.SetTitle("Terminal");
+ }
+
+ public void OnSkinLoad()
+ {
+ txtterm.SetFont(SkinEngine.LoadedSkin.TerminalFont);
+ }
+
+ public bool OnUnload()
+ {
+ return true;
+ }
+
+ public void OnUpgrade()
+ {
+ }
+
+ public void txtterm_KeyDown(object o, KeyEventArgs a) {
+ if (a.Key == Key.Enter)
+ {
+ try
+ {
+ a.Handled = true;
+ var text2 = txtterm.GetLineText(txtterm.LineCount - 1);
+ Console.WriteLine("");
+ var text3 = "";
+ var text4 = Regex.Replace(text2, @"\t|\n|\r", "");
+
+ if (backend.PrefixEnabled)
+ {
+ text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length);
+ }
+ backend.LastCommand = text3;
+ if (backend.InStory == false)
+ {
+ backend.InvokeCommand(text3);
+ }
+ if (backend.PrefixEnabled)
+ {
+ Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex);
+ }
+ }
+ else if (a.Key == Key.Back)
+ {
+ var tostring3 = txtterm.GetLineText(txtterm.LineCount - 1);
+ var tostringlen = tostring3.Length + 1;
+ var workaround = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
+ var derp = workaround.Length + 1;
+ if (tostringlen != derp)
+ {
+ AppearanceManager.CurrentPosition--;
+ }
+ else
+ {
+ a.Handled = true;
+ }
+ }
+ else if (a.Key == Key.Left)
+ {
+ var getstring = txtterm.GetLineText(txtterm.LineCount - 1);
+ var stringlen = getstring.Length + 1;
+ var header = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
+ var headerlen = header.Length + 1;
+ var selstart = txtterm.SelectionStart;
+ var remstrlen = txtterm.Text.Length - stringlen;
+ var finalnum = selstart - remstrlen;
+
+ if (finalnum != headerlen)
+ {
+ AppearanceManager.CurrentPosition--;
+ }
+ else
+ {
+ a.Handled = true;
+ }
+ }
+ //( ͡° ͜ʖ ͡° ) You found the lennyface without looking at the commit message. Message Michael in the #shiftos channel on Discord saying "ladouceur" somewhere in your message if you see this.
+ else if (a.Key == Key.Up)
+ {
+ var tostring3 = txtterm.GetLineText(txtterm.LineCount - 1);
+ if (tostring3 == $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ")
+ Console.Write(backend.LastCommand);
+ a.Handled = true;
+
+ }
+ else
+ {
+
+ AppearanceManager.CurrentPosition++;
+ }
+
+ }
+
+ private void txtterm_GotFocus(object sender, RoutedEventArgs e)
+ {
+ Startup.ConsoleOut = txtterm;
+ }
+ }
+}