Even though I knew exactly what I wanted to work on today, the morning started out very slow. I was attempting to do some work in the bedroom while my daughter watched some cartoons, but that didn’t work, as she was more impressed with sitting next to me and pressing every single button on the laptop. Then, she laid on me, I decided to “rest my eyes”, and a couple of hours later, I woke up, feeling like shit.

I ran off to the gym, got a smoothie afterwards, some tennis balls at Kmart after that, and made my way home. It would still be a few hours until I got into my groove. But damn, once I did, I was very happy with the results!

Today’s plan was pretty simple. Take the existing backend structure I implemented for turn orders, and make a GUI representation of it. At first, a lot of the time was taken up by me trying to implement the math involved to position each unit in the proper place, and then I decided to take a step back, and see what Unity had to offer out of the box. As it turns out, there was a lot.

I quickly stumbled across the GUI Auto Layout components of the new UI system, and was good to go from there. Now, all I have to do is add the unit to the panel that has the auto layout on it, and they’re automatically added to the right spot. If they’re removed, the next one moves up, and if they’re added again, they’ll be at he back of the line. And of course, I need to make sure to call back to the data class to make sure all the non-GUI stuff is updated as well. Pretty straightforward stuff. Here’s some sample code:

    public void AddUnit(Player unit) {
        Image unitImage = Instantiate (imagePrefab);
        unitImage.sprite = unit.portrait;
        unitImage.transform.SetParent (_panel.transform, false);

        _images.Add (unit, unitImage);
        _turnOrder.AddCombatant (unit);

    public void RemoveUnit(Player unit) {
        Image unitImage = _images [unit];
        unitImage.transform.SetParent (null);        
        Destroy (_images [unit]);

        _images.Remove (unit);
        _turnOrder.RemoveCombatant (unit);

Next up is for me is to go back to the data side of things, and actually implement the priority queue, based off of the speed of the unit. Also, I’ll need to add more units to the map itself so that turn order GUI can fill up a bit, just to get a better idea of how it’ll function.

With regards to adding more units, I think I’ll be needed a larger map soon, and with that, I’ll need map scrolling 🙂

Ah, the honeymoon phase of things continues!

Till tomorrow…