Skip to content

Commit

Permalink
Merge pull request #76 from 9xbt/Development
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
Owen2k6 authored Nov 4, 2023
2 parents 46d3890 + a38c79b commit 9d702f1
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 163 deletions.
105 changes: 88 additions & 17 deletions GoOS/9xCode/Interpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Console = BetterConsole;
using ConsoleColor = PrismAPI.Graphics.Color;

// 9xCode Beta 3.0
// 9xCode Beta 3.1
// Licensed under the MIT license
// Use permitted in GoOS

Expand All @@ -36,10 +36,10 @@ private static void Interpret(string[] code)
Interpreting = true;

Console.ForegroundColor = Cyan;
Console.WriteLine("Mobren 9xCode Interpreter Version b3.0\n");
Console.WriteLine("Mobren 9xCode Interpreter Version b3.1\n");
Console.ForegroundColor = White;

bool SysLib = false, ConsoleLib = false, IOLib = false, TimeLib = false, _9xGLLib = false;
bool SysLib = false, ConsoleLib = false, IOLib = false, TimeLib = false, _9xGLLib = false, GoOSLib = false;

Dictionary<string, bool> Booleans = new Dictionary<string, bool>() { };
Dictionary<string, int> Integers = new Dictionary<string, int>() { };
Expand Down Expand Up @@ -173,6 +173,12 @@ private static void Interpret(string[] code)
continue;
}

else if (sub.StartsWith("GoOS"))
{
GoOSLib = true;
continue;
}

else
{
HandleError("Error", "Unknown library.");
Expand Down Expand Up @@ -503,20 +509,20 @@ private static void Interpret(string[] code)
Window wnd = new Window();
ushort width, height;

if (args2[0].Contains('"'))
if (args2[0].Trim().Contains('"'))
wnd.Title = args2[0].Substring(1, args2[0].Length - 2);
else if (Strings.TryGetValue(args2[0], out string strval))
else if (Strings.TryGetValue(args2[0].Trim(), out string strval))
wnd.Title = strval;

if (Integers.TryGetValue(args2[1], out int widthval))
if (Integers.TryGetValue(args2[1].Trim(), out int widthval))
width = Convert.ToUInt16(widthval);
else
width = Convert.ToUInt16(args2[1]);
width = Convert.ToUInt16(args2[1].Trim());

if (Integers.TryGetValue(args2[2], out int heightval))
if (Integers.TryGetValue(args2[2].Trim(), out int heightval))
height = Convert.ToUInt16(heightval);
else
height = Convert.ToUInt16(args2[2]);
height = Convert.ToUInt16(args2[2].Trim());

wnd.Contents = new Canvas(width, height);
wnd.Visible = true;
Expand Down Expand Up @@ -576,7 +582,7 @@ private static void Interpret(string[] code)
else if (Strings.TryGetValue(comparation[0].Trim(), out string strval))
{
comparation[1] = comparation[1].Substring(comparation[1].IndexOf('"') + 1, comparation[1].LastIndexOf('"') - 2);
if (comparation[1] != strval)
if (comparation[1] != strval)
{
i = endif + 1;
}
Expand Down Expand Up @@ -795,12 +801,12 @@ private static void Interpret(string[] code)
{
string[] args = line.Split('>')[2].Trim().Split(',');

if (args.Length < 4)
if (args.Length < 5)
{
HandleError("Error", "Argument underflow.");
break;
}
if (args.Length > 4)
if (args.Length > 5)
{
HandleError("Error", "Argument overflow.");
break;
Expand All @@ -812,9 +818,9 @@ private static void Interpret(string[] code)
break;
}

if (!Strings.TryGetValue(args[1], out string strval))
if (!Strings.TryGetValue(args[1].Trim(), out string strval))
{
if (args[1].Contains('"'))
if (args[1].Trim().Contains('"'))
{
strval = args[1].Trim().Substring(1, args[1].Length - 3);
}
Expand All @@ -825,17 +831,29 @@ private static void Interpret(string[] code)
}
}

if (!Integers.TryGetValue(args[2], out int xval))
if (!Integers.TryGetValue(args[2].Trim(), out int xval))
{
xval = Convert.ToInt32(args[2].Trim());
}

if (!Integers.TryGetValue(args[3], out int yval))
if (!Integers.TryGetValue(args[3].Trim(), out int yval))
{
yval = Convert.ToInt32(args[3].Trim());
}

wndval.Contents.DrawString(xval, yval, strval, Fonts.Font_1x, Color.Black);
if (!Colors.TryGetValue(args[4].Trim(), out Color colval))
{
if (StringToConsoleColor.TryGetValue(args[4].Trim(), out Color colval2))
{
colval = colval2;
}
else
{
HandleError("Syntax Error", "Unknown Color.");
}
}

wndval.Contents.DrawString(xval, yval, strval, Fonts.Font_1x, colval);
}

else if (_9xGLLib && line.StartsWith("SetWindowPos") && line.Contains(">>"))
Expand Down Expand Up @@ -883,6 +901,54 @@ private static void Interpret(string[] code)

#endregion

#region GoOS Library

else if (GoOSLib && line.StartsWith("EnableKillingSystemTasks"))
{
GUI.Apps.TaskManager.pko = true;
}

else if (GoOSLib && line.StartsWith("DisableKillingSystemTasks"))
{
GUI.Apps.TaskManager.pko = false;
}

else if (GoOSLib && line.StartsWith("RegProg") && line.Contains(">>"))
{
string[] args = line.Split('>')[2].Trim().Split(',');

if (args.Length < 1)
{
HandleError("Error", "Argument underflow.");
break;
}
if (args.Length > 1)
{
HandleError("Error", "Argument overflow.");
break;
}

if (!Strings.TryGetValue(args[0].Trim(), out string strval))
{
if (args[0].Trim().Contains('"'))
{
strval = args[0].Trim().Substring(1, args[0].Length - 3);
}
else
{
HandleError("Error", "Unknown variable.");
break;
}
}

if (!Directory.Exists(@"0:\content\prf\" + strval + @"\"))
{
Directory.CreateDirectory(@"0:\content\prf\" + strval + @"\");
}
}

#endregion

else
{
HandleError("Syntax Error", "Unknown function.\nMaybe try importing a library?");
Expand All @@ -894,6 +960,11 @@ private static void Interpret(string[] code)
}
}
}

while (WindowManager.ContainsAWindow(new List<Window>(Windows.Values)))
{
WindowManager.Update();
}
}

private static void HandleError(string Title, string Message)
Expand Down
53 changes: 32 additions & 21 deletions GoOS/GUI/Apps/GoIDE/ProjectsFrame.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PrismAPI.Graphics;

namespace GoOS.GUI.Apps.GoIDE
{
public class ProjectsFrame : Window
{
Button[] RecentProjectsButtons;
Button DeleteButton;
Button ImportButton;
Button LoadExistingButton;
Button CreateNewButton;
Expand All @@ -20,10 +17,11 @@ public ProjectsFrame()
try
{
// Create the directories.
if (!Directory.Exists(@"0:\content\prf")) Directory.CreateDirectory(@"0:\content\prf");
if (!Directory.Exists(@"0:\content\prf\GoIDE")) Directory.CreateDirectory(@"0:\content\prf\GoIDE");
if (!Directory.Exists(@"0:\content\prf\GoIDE\Projects")) Directory.CreateDirectory(@"0:\content\prf\GoIDE\Projects");
if (!Directory.Exists(@"0:\content\prf\GoIDE\SaveData")) Directory.CreateDirectory(@"0:\content\prf\GoIDE\SaveData");
if (!Directory.Exists(@"0:\content\prf\GoIDE") || !Directory.Exists(@"0:\content\prf\GoIDE\Projects") || !Directory.Exists(@"0:\content\prf\GoIDE\SaveData"))
{
WindowManager.AddWindow(new WelcomeFrame());
Dispose(); return;
}

// Generate the fonts.
Fonts.Generate();
Expand Down Expand Up @@ -53,48 +51,61 @@ public ProjectsFrame()
};
}

ImportButton = new Button(this, Convert.ToUInt16(Contents.Width - 382), Convert.ToUInt16(Contents.Height - 30), 88, 20, "Import...") { Clicked = ImportButton_Click };
LoadExistingButton = new Button(this, Convert.ToUInt16(Contents.Width - 284), Convert.ToUInt16(Contents.Height - 30), 144, 20, "Load existing...") { Clicked = LoadExistingButton_Click };
CreateNewButton = new Button(this, Convert.ToUInt16(Contents.Width - 130), Convert.ToUInt16(Contents.Height - 30), 120, 20, "Create new...") { Clicked = CreateNewButton_Click };
DeleteButton = new Button(this, Convert.ToUInt16(Contents.Width - 380), Convert.ToUInt16(Contents.Height - 30), 64, 20, "Delete") { Clicked = DeleteButton_Click };
ImportButton = new Button(this, Convert.ToUInt16(Contents.Width - 306), Convert.ToUInt16(Contents.Height - 30), 64, 20, "Import") { Clicked = ImportButton_Click };
LoadExistingButton = new Button(this, Convert.ToUInt16(Contents.Width - 234), Convert.ToUInt16(Contents.Height - 30), 120, 20, "Load existing") { Clicked = LoadExistingButton_Click };
CreateNewButton = new Button(this, Convert.ToUInt16(Contents.Width - 106), Convert.ToUInt16(Contents.Height - 30), 96, 20, "Create new") { Clicked = CreateNewButton_Click };

// Paint the window.
Contents.Clear(Color.LightGray);
RenderSystemStyleBorder();
Contents.DrawFilledRectangle(2, Convert.ToUInt16(Contents.Height - 40), Convert.ToUInt16(Contents.Width - 4), 38, 0, Color.DeepGray);
Contents.DrawString(10, 10, "All projects", Fonts.Font_2x, Color.White);
foreach (Button i in RecentProjectsButtons) i.Render();
DeleteButton.Render();
ImportButton.Render();
LoadExistingButton.Render();
CreateNewButton.Render();
}
catch (Exception e)
{
Dialogue.Show("TheTunaFishSandwitch is racist!!1", e.Message, null, WindowManager.errorIcon);
}
catch { }
}

void RecentProjects_Click(string i)
private void RecentProjects_Click(string i)
{
WindowManager.AddWindow(new IDEFrame(i.Remove(i.LastIndexOf(".")), @"0:\content\prf\GoIDE\Projects\" + i, i.EndsWith(".9xc")));
Dispose();
if (DeleteButton.AppearPressed)
{
File.Delete(@"0:\content\prf\GoIDE\Projects\" + i);
Dispose();
WindowManager.AddWindow(new ProjectsFrame());
}
else
{
WindowManager.AddWindow(new IDEFrame(i.Remove(i.LastIndexOf(".")), @"0:\content\prf\GoIDE\Projects\" + i, i.EndsWith(".9xc")));
Dispose();
}
}

void ImportButton_Click()
private void ImportButton_Click()
{
WindowManager.AddWindow(new ImportProjectFrame());
Dispose();
}

void LoadExistingButton_Click()
private void LoadExistingButton_Click()
{
WindowManager.AddWindow(new LoadProjectFrame());
Dispose();
}

void CreateNewButton_Click()
private void CreateNewButton_Click()
{
WindowManager.AddWindow(new NewProjectFrame());
Dispose();
}

private void DeleteButton_Click()
{
DeleteButton.AppearPressed = !DeleteButton.AppearPressed;
}
}
}
52 changes: 52 additions & 0 deletions GoOS/GUI/Apps/GoIDE/WelcomeFrame.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.IO;
using PrismAPI.Graphics;

namespace GoOS.GUI.Apps.GoIDE
{
public class WelcomeFrame : Window
{
Button CancelButton;
Button NextButton;

public WelcomeFrame()
{
// Create the window.
AutoCreate(WindowDock.Center, 400, 300, "Welcome - GoIDE");

// Initialize the controls.
CancelButton = new Button(this, Convert.ToUInt16(Contents.Width - 132), Convert.ToUInt16(Contents.Height - 30), 64, 20, "Cancel") { Clicked = CancelButton_Click };
NextButton = new Button(this, Convert.ToUInt16(Contents.Width - 58), Convert.ToUInt16(Contents.Height - 30), 48, 20, "Next") { Clicked = NextButton_Click };

// Paint the window.
Contents.Clear(Color.LightGray);
RenderSystemStyleBorder();
Contents.DrawFilledRectangle(2, Convert.ToUInt16(Contents.Height - 40), Convert.ToUInt16(Contents.Width - 4), 38, 0, Color.DeepGray);
Contents.DrawString(10, 10, "Welcome", Fonts.Font_2x, Color.White);
Contents.DrawString(10, 52, "Welcome to GoIDE! This program will let you\ncreate and debug GoOS applications.\n\nGoIDE currently supports GoCode and 9xCode.\n\nPress next to install GoIDE and create a new\nproject.", Fonts.Font_1x, Color.White);
CancelButton.Render();
NextButton.Render();
}

private void NextButton_Click()
{
Dialogue msg = new Dialogue("Setup Wizard", "Installing GoIDE...", default, Dialogue.infoIcon);
WindowManager.AddWindow(msg);
WindowManager.Update();

Directory.CreateDirectory(@"0:\content\prf\GoIDE");
Directory.CreateDirectory(@"0:\content\prf\GoIDE\Projects");
Directory.CreateDirectory(@"0:\content\prf\GoIDE\SaveData");

msg.Dispose();
Dispose();
WindowManager.AddWindow(new NewProjectFrame());
}

private void CancelButton_Click()
{
Dispose();
Dialogue.Show("GoIDE", "You have canceled GoIDE setup.", default, WindowManager.errorIcon);
}
}
}
Loading

0 comments on commit 9d702f1

Please sign in to comment.