Week 8: Please Stop Scrolling
April 28, 2023
“Chess is, above all, a fight.” -Emanuel Lasker
Hello everyone! Welcome to Week 8 of my senior project blog. As we are nearing the end of this project, of course I start feeling the need to add a bunch of extra features. Anyways, let’s take a look at what I worked on.
- Moving The Pieces
- Implementing Variations
- Scrolling Through Catastrophe
- Plans For Next Week
Moving The Pieces
As I talked about last week, I was able to successfully read in and process the chess PGN files. However, I still needed a way to traverse through the game and display all the moves on the board. Although I previously coded an iterator for this type of traversal, this iterator only prints the move as a string. I needed to move the corresponding 3D pieces as well. Thus, I started working on an extensive system of UI buttons.
The Next Button
The next button was actually pretty easy to make. Because I already have a working Move Reader that reads in a string and makes the move on the board, my task is really simple. All I need to do is get the string move from the iterator and pass it to the Move Reader. I did need to filter out a few extra special symbols, but other than that, everything was working!!!
Annotation Text
For every move, there might be some comments associated with it. Thus, I wanted to be able to display them somewhere for the user to view. To do that, I created an annotation text box, as shown below:
The Previous Button
Now, going back is a bit harder than I expected. Knowing the string of the move is not enough because there is too much to keep track of. I need to remember which piece moved to the square (and there can be multiple valid ones) and if a piece was captured, I need to reset it. Thus, I created a MoveLog object to store all the important information and then used a moveLog stack to keep track of all the moves played. This makes everything very convenient, because for example, if I want to reset the entire board, all I have to do is keep popping from the moveLog stack until it is empty. Below is a screenshot of the type of information I stored in the MoveLog script.
The Control Panel
After creating the important buttons, I placed all of them together into a control panel that is easy for the user to access. I then wrote a quick script that rotates the panel to always face the user. The annotation text box has this script attached to it as well. Now, everything looks very neat, awesome!
Implementing Variations
When going to the next move, there may be alternative moves that the user needs to analyze as well. Thus, when such a situation occurs, I need to be able to display these alternative options and allow the user to click into them. I made use of the MRTK Tile Grid Object Collection to display all the alternative moves as buttons in a single column. When the user clicks on it, the game will branch to that particular variation. Obviously, this took a bit of debugging, but as of now, it works!
Scrolling Through Catastrophe
This does not sound good. And yes, creating a scrollable panel was one of my most catastrophic experiences. Because a database is supposed to have MANY games in it, what I needed was a scrollable panel, where the user can scroll through the supposedly thousands of games and pick the one they want to study. When I found that the MRTK has a Scrolling Object Collection [1], I was excited. I thought this would make everything much easier. However, customizing these pre-made assets took WAY too long.
MRTK’s Scrollable Objects
Shown below are the pre-made scrollable objects that came with the MRTK. I like the second type of scrolling because it is easiest to interact with.
Thus, I copied and pasted that over to my own project and started editing. First of all, I needed to create a button that can take in a string for the game information and return the index of the game when clicked. That was pretty easy to do, as it’s basically the same code I used for showing the variations. However, when I moved everything over to the pre-made scrollable object, that’s when the errors started happening.
The Errors
I’m not exactly sure how the implementation of the Scrolling Object Collection actually works, so when I keep getting a bunch of errors, I was very confused and frustrated. Turns out though, I had to change the Renderers to 0, because it was storing some obsolete information. Also, I realized that the Scrolling Object Collection was using a different type of object collection called the Grid Object Collection, not the Tile Grid Object Collection. So, I had to manually update the Collection every time I add objects to it through code.
Broken Scrolling
When I thought everything looked fine and tested it out, I ran into a major problem: the scrolling bar was not working. I spent so long trying to resolve this. I even looked into the source code to try and figure out what happened. Eventually, I came to the conclusion that because I’m adding in the objects during run time, the scrolling buttons do not properly calculate the number of items.
I was very frustrated about this and tried a lot of modifications, but to no avail. Eventually though, I came up with an idea to just pre-initialize a bunch of empty buttons and add the game text later on. This actually worked, and after so many hours, I have a working game display panel, yay!
Plans For Next Week
There are still two more things that I need to work on before I can start switching over to the Oculus platform: 1) allowing users to add variations to the game and 2) building the virtual environment. I’m not sure how long this would take, so I plan on working this weekend to get this all done. Next week, I will actually start building the Oculus version of this project and hopefully get it to work on a pair of headsets as well.
Anyways, thanks for reading my blog! Hope to see you again next week with some more success!
References
- vaoliva. “Scrolling Object Collection — MRTK2.” Scrolling Object Collection — MRTK2 | Microsoft Learn, Microsoft, 1 Aug. 2022, Https://Learn.Microsoft.Com/En-Us/Windows/Mixed-Reality/Mrtk-Unity/Mrtk2/Features/Ux-Building-Blocks/Scrolling-Object-Collection?View=Mrtkunity-2022-05.