This part of the tutorial is going to look at using UIComposer to create a simple UI, then the code to actually run the resulting GUI. This two part tutorial was originally just one part, covering how to make a UDP socket request. However, in putting together the required code, I had to build an interface, which resulted in a rather long post. Therefore I have split this into two parts. This part covers creating the UI, the next part covers wiring up the UI to actually do something and of course, the networking.
Once you are done both parts of this tutorial you will have a fully functional networked high score client with a primitive GUI.
Now, let’s create our application, fire up UIComposer.
File->Create New Project
In the Create New Project dialog, name and path it. I’m going with HighScoreApp.
File->Create New Layout
Assuming you are developing for Vita, leave it at 960x544, I named it MainWindow.
Now drag in controls from the widget panel:
Start with a Panel, the size of the entire window:
Drag and drop Label, Button and EditableText widgets to create the following result:
Now the most important part is to match my naming or your code will end up being different. The top two labels names don’t matter. On the next line, name them from left to right: textBoxName, textBoxScore, buttonAddScore and buttonGetScores.
You set the variable name by selecting the widget, then filling in the following form:
Variable Name is the field that you are most interested in.
Finally, at the bottom of the form, drag in a Label widget to fill the rest of the available space. Here are the settings I used:
Most importantly, make sure Variable Name is set to labelResults.
Now that we’ve created our screen, lets build it. Select File->Build or hit F5:
Your results should look like:
Now we are theoretically done with UIComposer, lets fire up PS Studio. Create a new solution, I called mine Networking. Add a reference to Sce.Pss.HighLevel.UI. Now we want to import our newly created UI files.
Right click your project and select Add->Add Files…
Navigate to the files you just created in UIComposer and add them. The key here is to Add them as a link. You don’t have to do this, but if you do, if you go back to the UIComposer and make a change ( and Build ), it will be automatically brought into Studio.
Add MainWindow.cs and MainWindow.composer.cs. MainWindow.composer.cs is the system generated file that wires together your windows code; you do not edit it. Instead, it makes use of partial classes and you do your editing in MainWindow.cs.
Now add the following code:
public class AppMain
public static void Main (string args)
GraphicsContext graphics = new GraphicsContext();
HighScoreApp.MainWindow window = new HighScoreApp.MainWindow();
List<TouchData> touchData = Touch.GetData(0);
graphics.SetViewport(0, 0, graphics.Screen.Width, graphics.Screen.Height);
This is about the simplest code you can create to display a UI on screen. First we create our GraphicsContext, then initialize the UISystem singleton with it. The UISystem singleton is contained in Sce.Pss.HighLevel.UI. Next we create our UIComposer generated class, HighScoreApp.MainWindow. If you are wondering where this name came from, the namespace was defined by the Project Name you specified in UIComposer, while the class name is the Class Name from the New Layout dialog. Just like when working with Director from GameEngine2D, we add the window using SetScene(). Note, these are different scenes and cannot be interchanged.
Next we loop infinitely. In our app loop, we check for new events, check what the current touch status is and pass the results to UISystem.Update(). Again, UISystem follows the same basic premise as the Director singleton, so it’s use should be familiar at this point. We then clear the screen, tell our UISystem to draw, then finally tell the graphics to SwapBuffers displaying our screen.
Here is the results of our actions:
In the next section we will actually put the GUI to use doing something. In the next part we are going to make a UDP socket connection to a high score server, to add new scores as well as retrieve the current high scores.