123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- function NewParticleAssetDialog::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("Image Asset", %width SPC 30);
- %this.imageDropDown = %form.createDropDownItem(%item);
- %this.populateImageDropDown();
- %item = %form.addFormItem("Animation Asset", %width SPC 30);
- %this.animationDropDown = %form.createDropDownItem(%item);
- %this.populateAnimationDropDown();
- %item = %form.addFormItem("Target Folder", %width SPC 30);
- %this.folderBox = %form.createFolderOpenItem(%item, "Select Target Folder");
- %this.folderBox.Command = %this.getId() @ ".Validate();";
- %item = %form.addFormItem("Asset Name", %width SPC 30);
- %this.assetNameBox = %form.createTextEditItem(%item);
- %this.assetNameBox.Command = %this.getId() @ ".Validate();";
- %item = %form.addFormItem("Target Module", %width SPC 30);
- %this.moduleNameBox = %form.createTextEditItem(%item);
- %this.moduleNameBox.setActive(false);
- %content.add(%form);
- %this.feedback = new GuiControl()
- {
- HorizSizing = "right";
- VertSizing = "bottom";
- Position = "12 270";
- Extent = (%width - 24) SPC 80;
- text = "Select an Image Asset or Animation Assset to get started!";
- textWrap = true;
- textExtend = true;
- };
- ThemeManager.setProfile(%this.feedback, "infoProfile");
- %this.cancelButton = new GuiButtonCtrl()
- {
- HorizSizing = "right";
- VertSizing = "bottom";
- Position = "478 370";
- Extent = "100 30";
- Text = "Cancel";
- Command = %this.getID() @ ".onClose();";
- };
- ThemeManager.setProfile(%this.cancelButton, "buttonProfile");
- %this.createButton = new GuiButtonCtrl()
- {
- HorizSizing = "right";
- VertSizing = "bottom";
- Position = "588 368";
- Extent = "100 34";
- Text = "Create";
- Command = %this.getID() @ ".onCreate();";
- };
- ThemeManager.setProfile(%this.createButton, "primaryButtonProfile");
- %content.add(%this.feedback);
- %content.add(%this.cancelButton);
- %content.add(%this.createButton);
- %this.prevFolder = "";
- }
- function NewParticleAssetDialog::Validate(%this)
- {
- %this.createButton.active = false;
- %imageAssetID = %this.imageDropDown.getText();
- %animationAssetID = %this.animationDropDown.getText();
- if(%imageAssetID $= "" && %animationAssetID $= "")
- {
- %this.feedback.setText("Select an Image Asset or Animation Assset to get started!");
- return false;
- }
- %assetID = %imageAssetID;
- if(%imageAssetID $= "")
- {
- %assetID = %animationAssetID;
- }
- %assetFilePath = AssetDatabase.getAssetFilePath(%assetID);
- if(%this.folderBox.getText() $= "")
- {
- %this.folderBox.setText(makeRelativePath(filePath(%assetFilePath), getMainDotCsDir()));
- }
- if(%this.assetNameBox.getText() $= "")
- {
- %this.assetNameBox.setText(getUnit(%assetID, 1, ":") @ "_PT");
- }
- %folderPath = %this.getFolderPath();
- %assetName = %this.assetNameBox.getText();
- if(%folderPath !$= %this.prevFolder)
- {
- %modSig = EditorCore.findModuleOfPath(%folderPath @ "a.txt");
- %this.moduleNameBox.setText(%modSig);
- %this.prevFolder = %folderPath;
- }
- %assetPath = pathConcat(%folderPath, %assetName @ ".particle.taml");
- %moduleName = getUnit(%this.moduleNameBox.getText(), 0, "_");
- %moduleVersion = getUnit(%this.moduleNameBox.getText(), 1, "_");
- %assetID = %moduleName @ ":" @ %assetName;
- if(%folderPath $= "")
- {
- %this.feedback.setText("Please select a target folder.");
- return false;
- }
- if(%assetName $= "")
- {
- %this.feedback.setText("A particle asset must have an Asset Name.");
- return false;
- }
- if(%moduleName $= "")
- {
- %this.feedback.setText("You can only create a particle asset inside of a module.");
- return false;
- }
- else
- {
- %module = ModuleDatabase.findModule(%moduleName, %moduleVersion);
- if(!isObject(%module))
- {
- %this.feedback.setText("There was a problem finding the module for this asset.");
- return false;
- }
- else if(%module.Synchronized)
- {
- %this.feedback.setText("You cannot add assets to a library module. Updates to the module would remove your assets. Instead, create your own module and add assets to it. Remember to have your module scan for assets.");
- return false;
- }
- }
- %button = AssetAdmin.Dictionary["ParticleAsset"].getButton(%assetID);
- if(isObject(%button))
- {
- %this.feedback.setText("An asset by this name already exists in this module. Try choosing a different name.");
- return false;
- }
- %this.createButton.active = true;
- %this.feedback.setText("Press the Create button to open the new asset for editing. Your new asset will have the extension particle.taml. You must have your module scan the asset's folder for this extension.");
- return true;
- }
- function NewParticleAssetDialog::onCreate(%this)
- {
- if(%this.validate())
- {
- %folderPath = %this.getFolderPath();
- %assetName = %this.assetNameBox.getText();
- %assetPath = pathConcat(%folderPath, %assetName @ ".particle.taml");
- %moduleName = getUnit(%this.moduleNameBox.getText(), 0, "_");
- %moduleVersion = getUnit(%this.moduleNameBox.getText(), 1, "_");
- %assetID = %moduleName @ ":" @ %assetName;
- //Time to create a new file
- %newAsset = new ParticleAsset()
- {
- assetName = %assetName;
- };
- %newEmitter = %newAsset.createEmitter();
- %newEmitter.setEmitterName("DefaultEmitter");
- if(%this.imageDropDown.getText() !$= "")
- {
- %newEmitter.setImage(%this.imageDropDown.getText());
- }
- else
- {
- %newEmitter.setAnimation(%this.animationDropDown.getText());
- }
- %assetImportSuccessful = TAMLWrite(%newAsset, %assetPath);
- %moduleDef = ModuleDatabase.findModule(%moduleName, %moduleVersion);
- AssetDatabase.addDeclaredAsset(%moduleDef, %assetPath);
- //Do we already have this button?
- %button = AssetAdmin.Dictionary["ParticleAsset"].getButton(%assetID);
- if(!isObject(%button))
- {
- //Load it into the image dictionary
- %button = AssetAdmin.Dictionary["ParticleAsset"].addButton(%assetID);
- }
- %button.onClick();
- %this.onClose();
- }
- }
- function NewParticleAssetDialog::onFolderOpened(%this, %textBox)
- {
- %this.Validate();
- }
- function NewParticleAssetDialog::getFolderPath(%this)
- {
- %folderPath = stripTrailingSpaces(makeFullPath(%this.folderBox.getText()));
- %length = strlen(%folderPath);
- %lastChar = getSubStr(%folderPath, %length - 1, 1);
- if(%lastChar $= "/")
- {
- return %folderPath;
- }
- return %folderPath @ "/";
- }
- function NewParticleAssetDialog::onDropDownClosed(%this, %dropDown)
- {
- if(%dropDown == %this.imageDropDown && %dropDown.getText() !$= "")
- {
- %this.animationDropDown.setSelected(0);
- }
- else if(%dropDown == %this.animationDropDown && %dropDown.getText() !$= "")
- {
- %this.imageDropDown.setSelected(0);
- }
- %this.validate();
- }
- function NewParticleAssetDialog::populateImageDropDown(%this)
- {
- %this.imageDropDown.clearItems();
- %query = new AssetQuery();
- AssetDatabase.findAllAssets(%query);
- AssetDatabase.findAssetType(%query, "ImageAsset", true);
- for(%i = 0; %i < %query.getCount(); %i++)
- {
- %assetID = %query.getAsset(%i);
- if(!AssetDatabase.isAssetInternal(%assetID))
- {
- %this.imageDropDown.addItem(%assetID);
- }
- }
- %query.delete();
- %this.imageDropDown.sortByText();
- %this.imageDropDown.insertItem(0, "");
- %this.imageDropDown.setSelected(0);
- }
- function NewParticleAssetDialog::populateAnimationDropDown(%this)
- {
- %this.animationDropDown.clearItems();
- %query = new AssetQuery();
- AssetDatabase.findAllAssets(%query);
- AssetDatabase.findAssetType(%query, "AnimationAsset", true);
- for(%i = 0; %i < %query.getCount(); %i++)
- {
- %assetID = %query.getAsset(%i);
- if(!AssetDatabase.isAssetInternal(%assetID))
- {
- %this.animationDropDown.addItem(%assetID);
- }
- }
- %query.delete();
- %this.animationDropDown.sortByText();
- %this.animationDropDown.insertItem(0, "");
- %this.animationDropDown.setSelected(0);
- }
|