diff --git a/Guide.md b/Guide.md index a52373a..f231d4b 100644 --- a/Guide.md +++ b/Guide.md @@ -1,3 +1,4 @@ + # OrbisLib2 Beginners Guide Hey! This is a writeup on the OrbisLib2 API for C# to help users get started. Not everything is yet added, but will be in the coming days. @@ -16,6 +17,10 @@ Go ahead and create yourself a new .NET project. I am going to choose to create Now that we have our new project created, we need to add OrbisLib2 as a reference. If you are using Visual Studio, you do this by going to `Project > Add Project Reference > Browse` and then locating the OrbisLib2.dll file. The dll file can be found in `C:/Program Files (x86)/Orbis Suite` just like the PS4 PKG. +OrbisLib also references some SQLite libraries, so we will also need to install the required packages using NuGet or by manually adding them to our project. + + + ### Adding Our Console Now that our project is set up, we need to add a PS4 console to our target list before doing anything. There are a couple ways you can do this. - Open Orbis Neighborhood and add your console from the targets tab. @@ -32,4 +37,60 @@ As long as Orbis Suite is running on your PS4 and is on the same network as your ## Writing Our First Code -got bored at this part, will add more later :D +Now that we have everything set up properly, let's get started with our first few lines of code. Remember, this isn't a programming lesson. If you are having trouble understanding some terms and/or code, it's best to go learn the basics of C# and then come back to this later. + +### Finding and Selecting a Target +To get started, we are going to find and select our target PS4 console. There are a couple ways of doing this: +- Using the `ShowDialog()` function inside the `Dialog.SelectTarget` class. +- Iterate through the targets list and add them to a listbox. + +I am going to go with the second method as the first requires you to add SimpleUI and some WPF libraries as dependencies (since I am using WinForms and not WPF) and I want to keep the project as clean as possible. + +Anyways, let's start by placing a listbox and a button on our fresh Windows Form window. (Controls can be found in the toolbox). + + + +I have named these `targetListBox` and `refreshTargetsBtn` respectively. + +Now, we need to actually write some code to make these controls function how we want. Let's double click the refresh button to create a `Click` event. We need to iterate through the targets list and add them to our listbox. This is easily done by using a `foreach` loop, as seen below. Oh, and don't forget to clear the listbox before looping through the targets. + +```c# +private void refreshTargetsBtn_Click(object sender, EventArgs e) +{ + targetListBox.Items.Clear(); //Clears the listbox so we don't have duplicate items upon refresh. + foreach(Target target in TargetManager.Targets) //Loops through the list of targets. + { + targetListBox.Items.Add(target.Name); //For each target found in the list, add it to the listbox. + } +} +``` + +Let's run our application and test out our new code. Upon clicking the refresh button, we can see all of our targets appear in the listbox. If you don't see any targets, you either have an error in your code or you forgot to [add a target](#adding-our-console) earlier. + + + +Now that we have our refresh button working and we can see all of our targets, we need a way of selecting one. This is as simple as using the listbox's `selectedIndexChanged` event. Yet again, double click the listbox to create this event. This time we are going to select the target by it's name based on what is highlighted/selected in the listbox. This is done using the code below. + +```c# +private void targetListBox_SelectedIndexChanged(object sender, EventArgs e) +{ + //Find the target using the selected item's text and set it to the SelectedTarget property. + TargetManager.SelectedTarget = TargetManager.GetTarget(targetListBox.GetItemText(targetListBox.SelectedItem)); +} +``` +We are also going to want a way to confirm that the above code works. For testing purposes, let's create a messagebox after we set the selected target. + +```c# +private void targetListBox_SelectedIndexChanged(object sender, EventArgs e) +{ + //Find the target using the selected item's text and set it to the SelectedTarget property. + TargetManager.SelectedTarget = TargetManager.GetTarget(targetListBox.GetItemText(targetListBox.SelectedItem)); + MessageBox.Show(TargetManager.SelectedTarget.Name); //Pop a messagebox with the selected target's name. +} +``` + +When you select a target in the listbox, you should now get a message with the target's name. + + + +Congratulations! You successfully found and selected a target PS4. Let's move onto some of the more entertaining stuff, like controlling our console.