Browse Source

Project Manager Module Data Edit

This allows a user to edit basic information about a non-synced module.
Peter Robinson 3 years ago
parent
commit
f0875bbd78

BIN
editor/EditorCore/images/editorIcons16.png


+ 1 - 0
editor/ProjectManager/ProjectManager.cs

@@ -32,6 +32,7 @@ function ProjectManager::create(%this)
 	exec("./scripts/DeclaredAssetForm.cs");
 	exec("./scripts/NewDeclaredAssetDialog.cs");
 	exec("./scripts/NewModuleDialog.cs");
+	exec("./scripts/EditModuleDialog.cs");
 
 	%this.guiPage = EditorCore.RegisterEditor("Project Manager", %this);
 

+ 149 - 0
editor/ProjectManager/scripts/EditModuleDialog.cs

@@ -0,0 +1,149 @@
+
+function EditModuleDialog::init(%this, %width, %height)
+{
+	//Get the dialog contents
+	%window = %this.getObject(0);
+	%content = %window.getObject(0);
+
+	%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);
+	%this.moduleNameBox.text = %this.module.moduleID;
+
+	%item = %form.addFormItem("Description", %width SPC 30);
+	%this.descriptionBox = %form.createTextEditItem(%item);
+	%this.descriptionBox.text = %this.module.description;
+
+	%item = %form.addFormItem("Version", %width SPC 30);
+	%this.versionBox = %form.createTextEditItem(%item);
+	%this.versionBox.inputMode = "number";
+	%this.versionBox.text = %this.module.versionID;
+
+	%item = %form.addFormItem("Build", %width SPC 30);
+	%this.buildBox = %form.createTextEditItem(%item);
+	%this.buildBox.inputMode = "number";
+	%this.buildBox.text = %this.module.buildID;
+
+	%item = %form.addFormItem("Type", %width SPC 30);
+	%this.typeBox = %form.createTextEditItem(%item);
+	%this.typeBox.text = %this.module.type;
+
+	%item = %form.addFormItem("Author", %width SPC 30);
+	%this.authorBox = %form.createTextEditItem(%item);
+	%this.authorBox.text = %this.module.author;
+
+	%content.add(%form);
+
+	%this.feedback = new GuiControl()
+	{
+		HorizSizing = "right";
+		VertSizing = "bottom";
+		Position = "12 320";
+		Extent = (%width - 24) SPC 80;
+		text = "Saving changes to a module will require the module to be unloaded. Changes will not apply until after a restart. Also, changing the name or version of a module may break dependencies. You will need to find and fix these.";
+		textWrap = true;
+		textExtend = true;
+	};
+	ThemeManager.setProfile(%this.feedback, "infoProfile");
+
+	%this.cancelButton = new GuiButtonCtrl()
+	{
+		HorizSizing = "right";
+		VertSizing = "bottom";
+		Position = "278 450";
+		Extent = "100 30";
+		Text = "Cancel";
+		Command = %this.getID() @ ".onClose();";
+	};
+	ThemeManager.setProfile(%this.cancelButton, "buttonProfile");
+
+	%this.saveButton = new GuiButtonCtrl()
+	{
+		HorizSizing = "right";
+		VertSizing = "bottom";
+		Position = "388 448";
+		Extent = "100 34";
+		Text = "Save";
+		Command = %this.getID() @ ".onSave();";
+	};
+	ThemeManager.setProfile(%this.saveButton, "primaryButtonProfile");
+
+	%content.add(%this.feedback);
+	%content.add(%this.cancelButton);
+	%content.add(%this.saveButton);
+
+	%this.validate();
+}
+
+function EditModuleDialog::onKeyPressed(%this, %textBox)
+{
+	%this.validate();
+}
+
+function EditModuleDialog::onReturnPressed(%this, %textBox)
+{
+	%this.onSave();
+}
+
+function EditModuleDialog::Validate(%this)
+{
+	%this.createButton.active = false;
+
+	%name = %this.moduleNameBox.getText();
+	%desc = %this.descriptionBox.getText();
+	%version = %this.versionBox.getText();
+	%build = %this.buildBox.getText();
+	%type = %this.typeBox.getText();
+	%author = %this.authorBox.getText();
+
+	if(%name $= "" || %version $= "" || %build $= "")
+	{
+		return false;
+	}
+
+	%this.moduleNameBox.text = stripChars(%name, " ");
+
+	%this.saveButton.active = true;
+	return true;
+}
+
+function EditModuleDialog::onClose(%this)
+{
+	Canvas.popDialog(%this);
+	%this.postEvent("DialogClosed", %this);
+}
+
+function EditModuleDialog::onSave(%this)
+{
+	if(%this.validate())
+	{
+		%name = %this.moduleNameBox.getText();
+		%desc = %this.descriptionBox.getText();
+		%version = %this.versionBox.getText();
+		%build = %this.buildBox.getText();
+		%type = %this.typeBox.getText();
+		%author = %this.authorBox.getText();
+
+		%data = new ScriptObject()
+		{
+			moduleID = %name;
+			description = %desc;
+			versionID = %version;
+			buildID = %build;
+			type = %type;
+			author = %author;
+		};
+
+		%this.postEvent("ModuleEdited", %data);
+		%data.delete();
+		%this.onClose();
+	}
+}

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

@@ -102,6 +102,8 @@ function NewModuleDialog::Validate(%this)
 		return false;
 	}
 
+	%this.moduleNameBox.text = stripChars(%name, " ");
+
 	%this.createButton.active = true;
 	return true;
 }

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

@@ -4,6 +4,7 @@ function ProjectGamePanel::onAdd(%this)
 	%this.init("Project");
 
 	%this.buttonBar.addButton("createNewModule", 11, "Create Module", "");
+	%this.buttonBar.addButton("editModule", 49, "Edit Module", "editModuleAvailable");
 }
 
 function ProjectGamePanel::onOpen(%this, %allModules)
@@ -28,6 +29,10 @@ function ProjectGamePanel::onOpen(%this, %allModules)
 	{
 		%this.refreshCard();
 	}
+	else
+	{
+		%this.buttonBar.refreshEnabled();
+	}
 }
 
 function ProjectGamePanel::addModule(%this, %module, %loadedModules)
@@ -127,3 +132,76 @@ function ProjectGamePanel::onModuleCreated(%this, %data)
 	ModuleDatabase.scanModules(%data.path);
 	%this.onOpen(ModuleDatabase.findModules(false));
 }
+
+function ProjectGamePanel::editModule(%this)
+{
+	%width = 500;
+	%height = 520;
+	%dialog = new GuiControl()
+	{
+		class = "EditModuleDialog";
+		superclass = "EditorDialog";
+		dialogSize = (%width + 8) SPC (%height + 8);
+		dialogCanClose = true;
+		dialogText = "Edit Module";
+		module = %this.card.activeModule;
+	};
+	%dialog.init(%width, %height);
+	%this.startListening(%dialog);
+
+	Canvas.pushDialog(%dialog);
+}
+
+function ProjectGamePanel::editModuleAvailable(%this)
+{
+	if(isObject(%this.card.activeModule) && !%this.card.activeModule.Synchronized)
+	{
+		return true;
+	}
+	return false;
+}
+
+function ProjectGamePanel::onModuleEdited(%this, %data)
+{
+	if(%this.moduleHasChanged(%data))
+	{
+		%module = %this.card.activeModule;
+		%moduleID = %this.card.activeModule.moduleID;
+		%projectPath = ProjectManager.getProjectFolder();
+		%modulePath = pathConcat(%projectPath, %module.moduleID);
+		ModuleDatabase.unregisterModule(%module.moduleID, %module.versionID);
+		%newModulePath = pathConcat(%projectPath, %data.moduleID);
+		if(%moduleID !$= %data.moduleID && !isDirectory(%newModulePath))
+		{
+			if(pathCopy(%modulePath, %newModulePath))
+			{
+				directoryDelete(%modulePath);
+				%modulePath = %newModulePath;
+			}
+		}
+		%file = TamlRead(pathConcat(%modulePath, "module.taml"));
+		%file.moduleID = %data.moduleID;
+		%file.versionID = %data.versionID;
+		%file.buildID = %data.buildID;
+		%file.description = %data.description;
+		%file.type = %data.type;
+		%file.author = %data.author;
+		TamlWrite(%file, pathConcat(%modulePath, "module.taml"));
+		ModuleDatabase.scanModules(%modulePath, true);
+		%this.card.moduleID = %data.moduleID;
+		%this.card.versionID = %data.versionID;
+		%allModules = ModuleDatabase.findModules(false);
+		%this.onOpen(%allModules);
+	}
+}
+
+function ProjectGamePanel::moduleHasChanged(%this, %data)
+{
+	%module = %this.card.activeModule;
+	return %module.moduleID !$= %data.moduleID ||
+		%module.versionID !$= %data.versionID ||
+		%module.buildID !$= %data.buildID ||
+		%module.description !$= %data.description ||
+		%module.type !$= %data.type ||
+		%module.author !$= %data.author;
+}

+ 3 - 2
editor/ProjectManager/scripts/ProjectModuleCard.cs

@@ -59,8 +59,8 @@
 	{
 		HorizSizing="width";
 		Position = "0 10";
-		Extent = "286 150";
-		MinExtent = "250 150";
+		Extent = "286 80";
+		MinExtent = "250 80";
 		Text = "";
 		TextWrap = 1;
 		TextExtend = 1;
@@ -254,6 +254,7 @@ function ProjectModuleCard::show(%this, %module)
 		%this.visible = true;
 		%this.dependList.show(%module);
 		%this.assetList.show(%module);
+		%this.postEvent("ModuleShown", %module);
 	}
 }
 

+ 5 - 0
editor/ProjectManager/scripts/ProjectModulePanel.cs

@@ -146,3 +146,8 @@ function ProjectModulePanel::sortModules(%this)
 {
 	%this.list.sortByText();
 }
+
+function ProjectModulePanel::onModuleShown(%this, %module)
+{
+	%this.buttonBar.refreshEnabled();
+}