Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
AddReferencedFileToGlobalContent adds the argument file to the Global Content Files tree node. The second parameter determines whether the folders relative to GlobalContent are prefixed on the name, which may be necessary if a project has multiple files with the same name in different folders.
IGluxCommands is an interface containing methods for performing common tasks to the Glue project (specifically which saves to the .glux file as opposed to the .csproj project).
The MakeAbsolute method takes a relative file name and makes it absolute. If the file is a content file, then the relative path is considered relative to the content project. If the file is a code file, then the relative path is considered relative to the code project.
The following will obtain the absolute folder for the currently-selected element (Screen or Entity):
The ITreeItemSelect interface is an interface which defines a method which gets raised whenever the user selects a tree item in Glue.
The selectedTreeNode's tag can be used to identify the type of tree node selected.
IProjectCommands provides methods that apply to the entire project. IProjectCommands can be accessed through the IGlueCommands interface.
The GetFilesReferencedBy delegate is a delegate which can be used to provide custom file reference logic. Custom file reference logic is useful if you are working with files which are not natively supported by Glue. Glue natively supports a number of files like .scnx, .achx, and .emix. If you are working with a file format which references other files, you can create a plugin which handles the GetFilesReferencedBy delegate.
The delegate is defined as:
Lets look at the three parameters:
string (first parameter) - this is the absolute file name which the plugin should handle. Usually plugins handle only a specific file format, so you may need to first look at the extension of the first argument to see if you should even handle it.
EditorObjects.Parsing.TopLevelOrRecursive - Whether the search should be top-level or recursive. If your file format references files which may reference other files, and if a recursive check is called for, you should perform deep reference gathering.
List<string> - The list to fill. If your plugin does not handle the file which has been passed in, then you do not need to make any changes to this list. You should not clear the list as multiple plugins may handle a single file.
The ICodeGeneratorPlugin interface allows you to create plugins that generate code. Not only can these plugins create new code files, but you can also insert your own code into the .Generated.cs file that is created by Glue normally. Injecting custom code into the .Generated.cs file is done through the use of .
This tutorial will show you how to create a custom class in your code. The ICodeGeneratorPlugin is written to react to when an IElement (Screen or Entity) is regenerated. If you are looking to make a plugin that generates code unrelated to any IElement, the code here can be used as an example; however, the ICodeGeneratorPlugin interface may not be very useful. First you will need to create a .cs file for your plugin. To do this:
Add a new .cs file to your plugin template named MyCodeGenerator
Add the following using statements:
Add the following code above your class declaration:
Add the following code after the class declaration:
Click on the "ICodeGeneratorPlugin" then press CTRL + . (that's the period key) and select "Implement interface 'ICodeGeneratorPlugin'". You should have stubs for all of the methods and properties for this plugin now.
Next we'll clean up the stubs:
Delete the contents of the CodeGenerationStart method. We'll fill this in after cleaning everything else up
Replace the exception in the getters for CodeGeneratorList and CodeGenerator with
Replace the exception in the FriendlyName getter with
Replace the exception in Version with
Delete the exception in StartUp
Replace the exception in ShutDown with
Now let's modify the CodeGenerationStart method. First, we'll add an if-statement to return (do nothing) if the IElement is a Screen. The code we're about to write will only work on Entities. To do this, add this in your CodeGenerationStart method:
Next we'll create a ICodeBlock and use that to generate our code. ICodeBlock is an interface that Glue uses to simplify code generation.
Now that we have this code written, let's add the file to the project and save it to disk. To do this, append the following code after the code that fills the StringBuilder:
The CreateAndAddPartialFile will add the .cs file that we pass to the project. This code can be called over and over - the file will only be added to the Project if it isn't already there. This code will be called for every Entity in your project. The result is that every Entity will have a .Generated.MyCode.cs file which will contain a method called MoveRight. Of course, this method doesn't do anything very useful; however, this shows how you can create your own code files with methods that can do virtually anything.
Add a new file to plugin template and call it CodeGenerationComponent
Add the following using statements:
Add the following code after the class name to make it implement ElementComponentCodeGenerator:
Add the stub for the GenerateActivity method:
Add the following code inside GenerateActivity to create logic to move the Entity to the right when the space bar is pressed:
Next we'll return to the ICodeGeneratorPlugin-implementing class (which was MyCodeGenerator).
Add the following field to MyCodeGenerator:
Add the following code to the contents of the CodeGenerator property:
Now the class will generate the code that is in the AppendLine methods inside every Entity.
The example above shows how to create a brand new file and generate code. You may want to add code directly in the .Generated.cs file (the one that Glue creates for every Screen and Entity). This section will show you how to do this. For the sake of keeping the tutorial shorter, we'll assume that you already have a class that implements and exports the ICodeGeneratorPlugin interface as shown above. The first step is to create a class that inherits from the class:
The PluginBase class acts as a base class for all plugins. It simplifies the process of creating plugins as you simply need to inherit from this class and then add events for whatever your plugin needs to handle.
An IMenuStripPlugin is a plugin that adds a menu strip item. IMenuStripPlugins can create new top-level menus (such as a new menu to the right of "Glue View" in the image above) or can add items under existing menu items (such as under the "Project" menu item).
The following code example adds an option under the "Plugins" menu option which shows a simple message box when clicked.
The IGlueState interface provides a centralized way to get information about the current state of Glue. IGlueState is very similar to IGlueCommands in that an instance of IGlueState can be provided to your plugin automatically through the plugin system (see below for more details).
Any plugin can get access to an instance of IGlueState . To do so, add the following to your plugin class:
That's all you have to do. The plugin system that Glue uses will automatically assign an instance to this interface. That means that your class can immediately start using the GlueState instance in its code with no additional hookup.
The AddContentFileToProject method can be called to add an existing file to the project. The file must already be located relative to the main project's content folder. For XNA applications this means relative to the folder that contains the .contentproj file. Non-XNA projects usually have a Content folder relative to the .csproj (or .vcproj) file. If so, the file should be located in this location. This simply adds a code file to the Visual Studio project - it does not add it to Glue, nor does it perform any code generation. The absolute file name must be passed to the method.
The IErrorReporter interface is used to report errors to the user. Implementations of this interface can be registered to Glue through a Plugin's AddErrorReporter method. An IErrorReporter is responsible for returning an array of ErrorViewModels. Typically a plugin will create an IErrorReporter for errors that pertain to the particular plugin. For example, the Gum plugin has an ErrorReporter which reports errors specific to Gum files. The only responsibility for an IErrorReporter is to return an array of ErrorViewModels. Each ErrorViewModel manages itself once it is created. Specifically, ErrorViewModels can respond to events such as a file changed, and can return whether they are fixed. Therefore, it is common for the same logic to be used in creating ErrorViewModel instances as well as checking if an existing ErrorViewModel is fixed.
The CodeBuildItemAdder provides methods for adding entire .cs files into game projects. Entire files may be needed in projects for a number of reasons:
As a cross-platform way to embed classes which are needed by a plugin, such as a runtime type for a file
To create singletons which are used to simplify code generation in each screen or entity
To provide utility methods to be used in custom code
The steps for adding code to a project using the CodeBuildItemAdder are:
Add a .cs file to your project as an embedded resource:
(Optional) Set the namespace to use the $PROJECT_NAMESPACE$ keyword to indicate that it should match the game project's namespace:
Add the code to embed the class. Embedded resources use the '.' character to separate folders, so if your file in the project is located at MyPlugin/EmbeddedCodeFiles/CodeFile.cs, then your code to add the file would be as shown in the following snippet: