Browse Source

Project Manager New Module Dialog

This adds a very basic new module dialog to the project manager with the ability to add an empty module or copy a template from the library.
Peter Robinson 3 years ago
parent
commit
30879a9064

+ 2 - 0
editor/EditorCore/EditorForm.cs

@@ -49,6 +49,8 @@ function EditorForm::createTextEditItem(%this, %label)
 		Position = "10 16";
 		Extent = (getWord(%label.extent, 0) - 24) SPC 30;
 	};
+	%textEdit.Command = %this.getID() @ ".postEvent(\"KeyPressed\", " @ %textEdit.getID() @ ");";
+	%textEdit.AltCommand = %this.getID() @ ".postEvent(\"ReturnPressed\", " @ %textEdit.getID() @ ");";
 	ThemeManager.setProfile(%textEdit, "textEditProfile");
 	%label.add(%textEdit);
 	return %textEdit;

+ 4 - 4
editor/EditorCore/Themes/BaseTheme/BaseTheme.cs

@@ -600,7 +600,7 @@ function BaseTheme::makeIconButtonProfile(%this)
 		borderColor = "255 255 255 80";
 		borderColorHL = "255 255 255 80";
 		borderColorSL = "0 0 0 80";
-		borderColorNA = "255 255 255 80";
+		borderColorNA = "255 255 255 40";
 
 		underfill = true;
 	};
@@ -615,17 +615,17 @@ function BaseTheme::makeIconButtonProfile(%this)
 		borderColor = "0 0 0 80";
 		borderColorHL = "0 0 0 80";
 		borderColorSL = "255 255 255 80";
-		borderColorNA = "0 0 0 80";
+		borderColorNA = "0 0 0 120";
 
 		underfill = true;
 	};
 
 	%this.iconButtonProfile = new GuiControlProfile()
 	{
-		fillColor = %this.color4;
+		fillColor = %this.setAlpha(%this.color4, 100);
 		fillColorHL = %this.adjustValue(%this.color4, 10);
 		fillColorSL = %this.color5;
-		fillColorNA = %this.setAlpha(%this.color4, 80);
+		fillColorNA = %this.setAlpha(%this.color4, 20);
 
 		fontColor = %this.color1;
 		fontColorHL = %this.adjustValue(%this.color1, 10);

+ 1 - 0
editor/ProjectManager/ProjectManager.cs

@@ -28,6 +28,7 @@ function ProjectManager::create(%this)
 	exec("./scripts/ProjectModuleCard.cs");
 	exec("./scripts/ProjectModuleDependList.cs");
 	exec("./scripts/NewDependencyDialog.cs");
+	exec("./scripts/NewModuleDialog.cs");
 
 	%this.guiPage = EditorCore.RegisterEditor("Project Manager", %this);
 

+ 134 - 0
editor/ProjectManager/scripts/NewModuleDialog.cs

@@ -0,0 +1,134 @@
+
+function NewModuleDialog::init(%this, %width, %height)
+{
+	//Get the dialog contents
+	%window = %this.getObject(0);
+	%content = %window.getObject(0);
+
+	//Create the file text box
+	%form = new GuiGridCtrl()
+	{
+		class = "EditorForm";
+		extent = %width SPC %height;
+		cellSizeX = %width;
+		cellSizeY = 50;
+	};
+	%form.addListener(%this);
+
+	%item = %form.addFormItem("Module Name", %width SPC 30);
+	%this.moduleNameBox = %form.createTextEditItem(%item);
+
+	%item = %form.addFormItem("Template", %width SPC 30);
+	%this.templateDropDown = %form.createDropDownItem(%item);
+	%this.populateModuleDropDown();
+
+	%content.add(%form);
+
+	%this.cancelButton = new GuiButtonCtrl()
+	{
+		HorizSizing = "right";
+		VertSizing = "bottom";
+		Position = "278 120";
+		Extent = "100 30";
+		Text = "Cancel";
+		Command = %this.getID() @ ".onClose();";
+	};
+	ThemeManager.setProfile(%this.cancelButton, "buttonProfile");
+
+	%this.createButton = new GuiButtonCtrl()
+	{
+		HorizSizing = "right";
+		VertSizing = "bottom";
+		Position = "388 118";
+		Extent = "100 34";
+		Text = "Create";
+		Command = %this.getID() @ ".onCreate();";
+	};
+	ThemeManager.setProfile(%this.createButton, "primaryButtonProfile");
+
+	%content.add(%this.cancelButton);
+	%content.add(%this.createButton);
+
+	%this.validate();
+}
+
+function NewModuleDialog::populateModuleDropDown(%this)
+{
+	%manager = new ModuleManager();
+	%manager.EchoInfo = false;
+
+	%manager.ScanModules(pathConcat(getMainDotCsDir(), "library"));
+
+	%allModules = %manager.findModules(false);
+
+	for(%i = 0; %i < getWordCount(%allModules); %i++)
+	{
+		%mod = getWord(%allModules, %i);
+		if(%mod.type $= "template")
+		{
+			%this.templateDropDown.addItem(%mod.ModuleID);
+		}
+	}
+	%this.templateDropDown.sortByText();
+	%this.templateDropDown.insertItem(0, "none");
+	%this.templateDropDown.setSelected(0);
+}
+
+function NewModuleDialog::onDropDownClosed(%this, %dropDown)
+{
+	%this.validate();
+}
+
+function NewModuleDialog::onKeyPressed(%this, %textBox)
+{
+	%this.validate();
+}
+
+function NewModuleDialog::onReturnPressed(%this, %textBox)
+{
+	%this.onCreate();
+}
+
+function NewModuleDialog::Validate(%this)
+{
+	%this.createButton.active = false;
+
+	%module = %this.templateDropDown.getText();
+	%name = %this.moduleNameBox.getText();
+	%path = pathConcat(getMainDotCsDir(), ProjectManager.getProjectFolder(), %name);
+
+	if(%name $= "" || isDirectory(%path))
+	{
+		return false;
+	}
+
+	%this.createButton.active = true;
+	return true;
+}
+
+function NewModuleDialog::onClose(%this)
+{
+	Canvas.popDialog(%this);
+	%this.postEvent("DialogClosed", %this);
+}
+
+function NewModuleDialog::onCreate(%this)
+{
+	if(%this.validate())
+	{
+		%module = %this.templateDropDown.getText();
+		%name = %this.moduleNameBox.getText();
+		%path = pathConcat(getMainDotCsDir(), ProjectManager.getProjectFolder(), %name);
+
+		%data = new ScriptObject()
+		{
+			template = %module;
+			moduleName = %name;
+			path = %path;
+		};
+
+		%this.postEvent("ModuleCreated", %data);
+		%data.delete();
+		%this.onClose();
+	}
+}

+ 63 - 0
editor/ProjectManager/scripts/ProjectGamePanel.cs

@@ -2,6 +2,8 @@
 function ProjectGamePanel::onAdd(%this)
 {
 	%this.init("Project");
+
+	%this.buttonBar.addButton("createNewModule", 11, "Create Module", "");
 }
 
 function ProjectGamePanel::onOpen(%this, %allModules)
@@ -64,3 +66,64 @@ function ProjectGamePanel::refreshCard(%this)
 	}
 	%this.card.show(%module);
 }
+
+function ProjectGamePanel::createNewModule(%this)
+{
+	%width = 500;
+	%height = 190;
+	%dialog = new GuiControl()
+	{
+		class = "NewModuleDialog";
+		superclass = "EditorDialog";
+		dialogSize = (%width + 8) SPC (%height + 8);
+		dialogCanClose = true;
+		dialogText = "Create Module";
+	};
+	%dialog.init(%width, %height);
+	%this.startListening(%dialog);
+
+	Canvas.pushDialog(%dialog);
+}
+
+function ProjectGamePanel::onDialogClosed(%this, %dialog)
+{
+	%this.dialog = %dialog;
+	%this.schedule(100, "deleteDialog");
+}
+
+function ProjectGamePanel::deleteDialog(%this)
+{
+	%this.dialog.delete();
+}
+
+function ProjectGamePanel::onModuleCreated(%this, %data)
+{
+	if(%data.template !$= "none")
+	{
+		%templatePath = pathConcat(getMainDotCsDir(), "library", %data.template);
+		if(isDirectory(%templatePath))
+		{
+			pathCopy(%templatePath, %data.path);
+			%obj = TamlRead(pathConcat(%data.path, "module.taml"));
+			%obj.ModuleID = %data.moduleName;
+			%obj.Type = "";
+			TamlWrite(%obj, pathConcat(%data.path, "module.taml"));
+		}
+	}
+	else
+	{
+		%obj = new ModuleDefinition()
+		{
+			ModuleID = %data.moduleName;
+			VersionID = "1";
+			BuildID = "1";
+			Synchronized = false;
+			Description = "";
+			Author = "";
+		};
+		createPath(%data.path);
+		TamlWrite(%obj, pathConcat(%data.path, "module.taml"));
+	}
+	ModuleDatabase.scanModules(%data.path);
+	%this.onOpen(ModuleDatabase.findModules(false));
+}

+ 23 - 3
editor/ProjectManager/scripts/ProjectModulePanel.cs

@@ -14,18 +14,38 @@ function ProjectModulePanel::init(%this, %title)
 	%this.title = new GuiControl()
 	{
 		Position = "0 4";
-		Extent = "200 40";
+		Extent = "200 34";
 		Text = %title;
 	};
 	ThemeManager.setProfile(%this.title, "titleProfile");
 	%this.leftPanel.add(%this.title);
 
+	%this.buttonBarContainer = new GuiControl()
+	{
+		Position = "0 38";
+		Extent = "200 34";
+	};
+	ThemeManager.setProfile(%this.buttonBarContainer, "panelProfile");
+	%this.leftPanel.add(%this.buttonBarContainer);
+
+	%this.buttonBar = new GuiChainCtrl()
+	{
+		Class = "EditorButtonBar";
+		Position = "0 4";
+		Extent = "0 30";
+		ChildSpacing = 4;
+		IsVertical = false;
+		Tool = %this;
+	};
+	ThemeManager.setProfile(%this.buttonBar, "emptyProfile");
+	%this.buttonBarContainer.add(%this.buttonBar);
+
 	%this.scroller = new GuiScrollCtrl()
 	{
 		HorizSizing="width";
 		VertSizing="height";
-		Position="0 40";
-		Extent="200 728";
+		Position="0 72";
+		Extent="200 696";
 		hScrollBar="alwaysOff";
 		vScrollBar="dynamic";
 		constantThumbHeight="0";