Quellcode durchsuchen

Project Manager Display and Add Declared Assets

With this code a user can see a list of a folders that will be scanned for assets within each module. For non-synced modules the user can add and remove folders for declared assets as well. I also added a dedicated ReturnCommand to the GuiTextEditCtrl.
Peter Robinson vor 3 Jahren
Ursprung
Commit
225c1dc1a6

+ 2 - 1
editor/EditorCore/EditorForm.cs

@@ -50,7 +50,7 @@ function EditorForm::createTextEditItem(%this, %label)
 		Extent = (getWord(%label.extent, 0) - 24) SPC 30;
 	};
 	%textEdit.Command = %this.getID() @ ".postEvent(\"KeyPressed\", " @ %textEdit.getID() @ ");";
-	%textEdit.AltCommand = %this.getID() @ ".postEvent(\"ReturnPressed\", " @ %textEdit.getID() @ ");";
+	%textEdit.ReturnCommand = %this.getID() @ ".postEvent(\"ReturnPressed\", " @ %textEdit.getID() @ ");";
 	ThemeManager.setProfile(%textEdit, "textEditProfile");
 	%label.add(%textEdit);
 	return %textEdit;
@@ -174,6 +174,7 @@ function EditorForm::createCheckboxItem(%this, %label)
 		Extent = (getWord(%label.extent, 0) - 24) SPC 30;
 		Text = %label.text;
 	};
+	%box.textExtent = getWord(%box.Extent, 0) - getWord(%box.textOffset, 0);
 	ThemeManager.setProfile(%box, "checkboxProfile");
 	%label.add(%box);
 	%label.text = "";

+ 3 - 0
editor/ProjectManager/ProjectManager.cs

@@ -27,7 +27,10 @@ function ProjectManager::create(%this)
 	exec("./scripts/ProjectLibraryPanel.cs");
 	exec("./scripts/ProjectModuleCard.cs");
 	exec("./scripts/ProjectModuleDependList.cs");
+	exec("./scripts/ProjectModuleAssetList.cs");
 	exec("./scripts/NewDependencyDialog.cs");
+	exec("./scripts/DeclaredAssetForm.cs");
+	exec("./scripts/NewDeclaredAssetDialog.cs");
 	exec("./scripts/NewModuleDialog.cs");
 
 	%this.guiPage = EditorCore.RegisterEditor("Project Manager", %this);

+ 29 - 0
editor/ProjectManager/scripts/DeclaredAssetForm.cs

@@ -0,0 +1,29 @@
+
+function DeclaredAssetForm::getFolderPath(%this, %title, %textEdit)
+{
+	%modulePath = pathConcat(getMainDotCsDir(), ProjectManager.getProjectFolder(), %this.module.moduleID);
+	if(isDirectory(pathConcat(%modulePath, %this.module.versionID)))
+	{
+		%modulePath = pathConcat(%modulePath, %this.module.versionID);
+	}
+	%dialog = new OpenFolderDialog()
+	{
+		Filters = "All Files|*.*";
+		ChangePath = false;
+		DefaultFile = "";
+		defaultPath = %modulePath;
+		title = %title;
+	};
+	%result = %dialog.execute();
+
+	if ( %result )
+	{
+		%selectedFile = makeRelativePath(%dialog.fileName, %modulePath);
+		%textEdit.setText(%selectedFile);
+		%textEdit.setCursorPos(999999);//move it to the far right.
+	}
+	// Cleanup
+	%dialog.delete();
+
+	%this.postEvent("FolderOpened", %textEdit);
+}

+ 117 - 0
editor/ProjectManager/scripts/NewDeclaredAssetDialog.cs

@@ -0,0 +1,117 @@
+
+function NewDeclaredAssetDialog::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 = "DeclaredAssetForm";
+		superclass = "EditorForm";
+		extent = %width SPC %height;
+		cellSizeX = %width;
+		cellSizeY = 50;
+		module = %this.module;
+	};
+	%form.addListener(%this);
+
+	%item = %form.addFormItem("Asset Directory", %width SPC 30);
+	%this.folderBox = %form.createFolderOpenItem(%item, "Select Folder to Scan");
+	%this.folderBox.Command = %this.getId() @ ".Validate();";
+
+	%item = %form.addFormItem("Extension", %width SPC 30);
+	%this.extensionBox = %form.createTextEditItem(%item);
+	%this.extensionBox.text = "asset.taml";
+
+	%item = %form.addFormItem("Scan Sub Directories", %width SPC 30);
+	%this.recursiveCheckBox = %form.createCheckboxItem(%item);
+
+	%content.add(%form);
+
+	%this.cancelButton = new GuiButtonCtrl()
+	{
+		HorizSizing = "right";
+		VertSizing = "bottom";
+		Position = "278 170";
+		Extent = "100 30";
+		Text = "Cancel";
+		Command = %this.getID() @ ".onClose();";
+	};
+	ThemeManager.setProfile(%this.cancelButton, "buttonProfile");
+
+	%this.createButton = new GuiButtonCtrl()
+	{
+		HorizSizing = "right";
+		VertSizing = "bottom";
+		Position = "388 168";
+		Extent = "100 34";
+		Text = "Add";
+		Command = %this.getID() @ ".onCreate();";
+	};
+	ThemeManager.setProfile(%this.createButton, "primaryButtonProfile");
+
+	%content.add(%this.cancelButton);
+	%content.add(%this.createButton);
+
+	%this.validate();
+}
+
+function NewDeclaredAssetDialog::onFolderOpened(%this, %textBox)
+{
+	%this.Validate();
+}
+
+function NewDeclaredAssetDialog::onKeyPressed(%this, %textBox)
+{
+	%this.validate();
+}
+
+function NewDeclaredAssetDialog::onReturnPressed(%this, %textBox)
+{
+	%this.onCreate();
+}
+
+function NewDeclaredAssetDialog::Validate(%this)
+{
+	%this.createButton.active = false;
+
+	%folder = %this.folderBox.getText();
+	%ext = %this.extensionBox.getText();
+	%isRecursive = %this.recursiveCheckBox.getStateOn();
+
+	if(%ext $= "")
+	{
+		return false;
+	}
+
+	%this.createButton.active = true;
+	return true;
+}
+
+function NewDeclaredAssetDialog::onClose(%this)
+{
+	Canvas.popDialog(%this);
+	%this.postEvent("DialogClosed", %this);
+}
+
+function NewDeclaredAssetDialog::onCreate(%this)
+{
+	if(%this.validate())
+	{
+		%folder = %this.folderBox.getText();
+		%ext = %this.extensionBox.getText();
+		%isRecursive = %this.recursiveCheckBox.getStateOn();
+
+		%asset = new DeclaredAssets()
+		{
+			path = %folder;
+			extension = %ext;
+			recurse = %isRecursive;
+		};
+
+		%this.postEvent("DeclaredAssetAdded", %asset);
+		%this.onClose();
+	}
+}

+ 0 - 1
editor/ProjectManager/scripts/NewDependencyDialog.cs

@@ -48,7 +48,6 @@ function NewDependencyDialog::init(%this, %width, %height)
 	};
 	ThemeManager.setProfile(%this.createButton, "primaryButtonProfile");
 
-	%content.add(%this.feedback);
 	%content.add(%this.cancelButton);
 	%content.add(%this.createButton);
 

+ 164 - 0
editor/ProjectManager/scripts/ProjectModuleAssetList.cs

@@ -0,0 +1,164 @@
+
+function ProjectModuleAssetList::onAdd(%this)
+{
+	%this.startListening(ThemeManager);
+}
+
+function ProjectModuleAssetList::onThemeChange(%this, %theme)
+{
+	if(isObject(%this.activeModule))
+	{
+		%this.show(%this.activeModule);
+	}
+}
+
+function ProjectModuleAssetList::show(%this, %module)
+{
+	%this.activeModule = %module;
+	%this.clearItems();
+	%isSynced = %module.Synchronized;
+
+	for(%i = 0; %i < %module.getCount(); %i++)
+	{
+		%asset = %module.getObject(%i);
+		%this.addAssetItem(%asset, %isSynced);
+	}
+
+	if(!%module.Synchronized)
+	{
+		%this.addAddButton();
+	}
+}
+
+function ProjectModuleAssetList::hide(%this)
+{
+	%this.activeModule = 0;
+	%this.clearItems();
+}
+
+function ProjectModuleAssetList::clearItems(%this)
+{
+	for(%i = %this.getCount() - 1; %i >= 0; %i--)
+	{
+		%item = %this.getObject(%i);
+		%item.delete();
+	}
+}
+
+function ProjectModuleAssetList::getDeclaredAssetText(%this, %asset)
+{
+	if(%asset.recurse)
+	{
+		return pathConcat(%asset.path, "*", "*." @ %asset.extension);
+	}
+	return pathConcat(%asset.path, "*." @ %asset.extension);
+}
+
+function ProjectModuleAssetList::addAssetItem(%this, %asset, %isSynced)
+{
+	%width = getWord(%this.extent, 0) - 6;
+	%text = new GuiControl()
+	{
+		HorizSizing="width";
+		Position = "3 0";
+		Extent = %width SPC "26";
+		Text = %this.getDeclaredAssetText(%asset);
+		Align = "Left";
+		VAlign = "Middle";
+	};
+	ThemeManager.setProfile(%text, "subListProfile");
+	%this.add(%text);
+
+	if(!%isSynced)
+	{
+		%deleteButton = new GuiButtonCtrl()
+		{
+			Class="ProjectModuleAssetButton";
+			ButtonEvent = "RemoveAsset";
+			ButtonData = %asset.getID();
+			HorizSizing="left";
+			Position = (%width - 40) SPC "0";
+			Extent = "22 22";
+			MinExtent = "22 22";
+			Text = "X";
+			Align = "Center";
+			VAlign = "Middle";
+			TextExtend = 1;
+		};
+		%deleteButton.position = (%width - (getWord(%deleteButton.extent, 0) + 10)) SPC "0";
+		ThemeManager.setProfile(%deleteButton, "subListProfile");
+		%text.add(%deleteButton);
+		%this.startListening(%deleteButton);
+	}
+}
+
+function ProjectModuleAssetList::addAddButton(%this)
+{
+	%width = 140;
+	%addButton = new GuiButtonCtrl()
+	{
+		Class="ProjectModuleAssetButton";
+		ButtonEvent = "AddAsset";
+		ButtonData = "";
+		HorizSizing="right";
+		Position = "3 0";
+		Extent = %width SPC "26";
+		MinExtent = %width SPC "26";
+		Text = "+Add Declared Asset";
+		Align = "Center";
+		VAlign = "Middle";
+		TextExtend = 1;
+	};
+	ThemeManager.setProfile(%addButton, "subListProfile");
+	%this.add(%addButton);
+	%this.startListening(%addButton);
+}
+
+function ProjectModuleAssetButton::onClick(%this)
+{
+	%this.postEvent(%this.buttonEvent, %this.buttonData);
+}
+
+function ProjectModuleAssetList::onAddAsset(%this)
+{
+	%width = 500;
+	%height = 240;
+	%dialog = new GuiControl()
+	{
+		class = "NewDeclaredAssetDialog";
+		superclass = "EditorDialog";
+		dialogSize = (%width + 8) SPC (%height + 8);
+		dialogCanClose = true;
+		dialogText = "New Declared Asset";
+		module = %this.activeModule;
+	};
+	%dialog.init(%width, %height);
+	%this.startListening(%dialog);
+
+	Canvas.pushDialog(%dialog);
+}
+
+function ProjectModuleAssetList::onDeclaredAssetAdded(%this, %asset)
+{
+	%this.activeModule.add(%asset);
+	%this.activeModule.save();
+	%this.show(%this.activeModule);
+}
+
+function ProjectModuleAssetList::onRemoveAsset(%this, %asset)
+{
+	%this.activeModule.remove(%asset);
+	%this.activeModule.save();
+	%this.schedule(50, "show", %this.activeModule);
+}
+
+function ProjectModuleAssetList::onDialogClosed(%this, %dialog)
+{
+	%this.dialog = %dialog;
+	%this.schedule(100, "deleteDialog");
+}
+
+function ProjectModuleAssetList::deleteDialog(%this)
+{
+	%this.dialog.delete();
+}

+ 29 - 11
editor/ProjectManager/scripts/ProjectModuleCard.cs

@@ -105,19 +105,36 @@
    ThemeManager.setProfile(%this.dependList, "emptyProfile");
    %this.chain.add(%this.dependList);
 
-	%this.button = new GuiButtonCtrl()
+   %this.addEmptySpace(30, %this.chain);
+
+	%this.addSubSection("Declared Assets");
+
+	%this.assetList = new GuiChainCtrl()
 	{
-		Class="ProjectModuleCardButton";
-		HorizSizing="left";
-		VertSizing="bottom";
-		Position = "184 40";
-		Extent = "100 30";
-		MinExtent = "100 30";
-		Text = "";
+		Class = ProjectModuleAssetList;
+		HorizSizing="width";
+		VertSizing="height";
+		Position = "0 0";
+		Extent = "286 100";
+		IsVertical = "1";
+		ChildSpacing = 2;
 	};
-	ThemeManager.setProfile(%this.button, "primaryButtonProfile");
-	%this.add(%this.button);
-	%this.startListening(%this.button);
+   ThemeManager.setProfile(%this.assetList, "emptyProfile");
+   %this.chain.add(%this.assetList);
+
+   %this.button = new GuiButtonCtrl()
+   {
+	   Class="ProjectModuleCardButton";
+	   HorizSizing="left";
+	   VertSizing="bottom";
+	   Position = "184 40";
+	   Extent = "100 30";
+	   MinExtent = "100 30";
+	   Text = "";
+   };
+   ThemeManager.setProfile(%this.button, "primaryButtonProfile");
+   %this.add(%this.button);
+   %this.startListening(%this.button);
 
 	%this.startListening(ThemeManager);
  }
@@ -236,6 +253,7 @@ function ProjectModuleCard::show(%this, %module)
 
 		%this.visible = true;
 		%this.dependList.show(%module);
+		%this.assetList.show(%module);
 	}
 }
 

+ 8 - 3
engine/source/gui/guiTextEditCtrl.cc

@@ -382,6 +382,7 @@ GuiTextEditCtrl::GuiTextEditCtrl()
 
    mTextOffsetY = 0;
 
+   mReturnCommand = StringTable->EmptyString;
    mEscapeCommand = StringTable->EmptyString;
    mPasswordMask = StringTable->insert( "*" );
 
@@ -415,7 +416,8 @@ void GuiTextEditCtrl::initPersistFields()
    addDepricatedField("tabComplete");
 
    addGroup("Text Edit");
-   addField("escapeCommand",     TypeString,    Offset(mEscapeCommand,     GuiTextEditCtrl));
+   addField("returnCommand", TypeString, Offset(mReturnCommand, GuiTextEditCtrl));
+   addField("escapeCommand", TypeString, Offset(mEscapeCommand, GuiTextEditCtrl));
    addField("sinkAllKeyEvents",  TypeBool,      Offset(mSinkAllKeyEvents,  GuiTextEditCtrl));
    addField("password", TypeBool, Offset(mPasswordText, GuiTextEditCtrl));
    addField("returnCausesTab", TypeBool, Offset(mReturnCausesTab, GuiTextEditCtrl));
@@ -1565,8 +1567,6 @@ bool GuiTextEditCtrl::handleDelete()
 
 bool GuiTextEditCtrl::handleEnterKey()
 {
-    execAltConsoleCallback();
-
     if (isMethod("onReturn"))
         Con::executef(this, 1, "onReturn");
 
@@ -1574,6 +1574,11 @@ bool GuiTextEditCtrl::handleEnterKey()
     {
         tabNext();
     }
+
+    if (isMethod(mReturnCommand))
+    {
+        Con::evaluate(mReturnCommand);
+    }
     return true;
 }
 

+ 1 - 0
engine/source/gui/guiTextEditCtrl.h

@@ -109,6 +109,7 @@ protected:
    string mTextBuffer;
    TextBlockList mTextBlockList;
 
+   StringTableEntry mReturnCommand;
    StringTableEntry mEscapeCommand;
 
 public: