Plowing Through UI
I got quite a bit done today, working on the UI. Some parts were more straightforward than others, but I finished the day with a fully-functional main UI in all four resolutions.
Status Bars and Buttons
The main player status bars and buttons were probably the easiest to do. They don't need very much special handling, and were mainly a matter of setting the right coordinates for each of the modes.
As part of the restructuring, I finally did away with the "No Worky" button. There was quite a lot of speculation as to that button's purpose. Demo players assumed it was a disabled save button, while beta players assumed it was a disabled vehicle button.
In fact, it was just decoration. As I worked on the UI style, I was aiming for a set of buttons that looked like things scavenged from junkyards, like the buttons on an old vehicle or machine. As I did so, I decided part of the motif was broken stuff, so I added a button that had a helpful "No Worky" taped across it, to remind the user not to press it.
Unfortunately (or fortunately), room is getting sparse in the new layouts, so I removed it. Probably for the best, given the confusion it caused!
This one was a bit trickier to setup, namely because it involves different component sizes in each resolution. I ended up drawing two versions of the background, to fit flush against the differing message window in each screen size. Plus, I used different fonts and scaling on the buttons/weapon.
I actually found a bug in the font-switching code while I was doing so, which caused extra line breaks when switching fonts in some text. So that was a bonus.
Speaking of bonuses, the message window came back for revenge, which led to discovering (and fixing) some nasty bugs.
When I left off yesterday, the message window was behaving in 800x450 and 1360x768 modes. However, I forgot to test it in 1600x900 and 2400x1350.
Because those latter two modes are actually zoomed/scaled versions of the 800x450 mode, the message window's camera became misaligned, and started acting all wonky. As it turned out, there were a few things that needed fixing.
The position was probably the easiest to fix, as the message window camera just needed to account for the zoom amount when repositioning during a resolution change. It had some resizing issues, too, but that only took a few tries to get right.
The expand/collapse function of that window also needed some rewriting. It used some hard-coded screen sizes to adjust itself when expanding and collapsing, and that needed to account for the different screen layouts.
However, while testing it in one of the larger screen sizes, a curious thing happened: Flash crashed. The error report just said I was trying to create an invalid bitmap. However, there didn't seem to be anything unusual about it (no huge size nor negative dimensions, for example).
So I tried to reproduce the issue, and discovered that it only happened after running for 30 seconds or so in the larger resolution. Hm, that sounds a bit suspicious. I popped open my task manager, and sure enough, Flash was chewing through something like 1.4GB of memory. Normally, the debug version of the game uses 300-350MB, so something was up.
As it turned out, it was the code I wrote for resizing the camera yesterday. In the resize function, I was creating a new bitmap for the camera to draw to, using FlxSprite.makeGraphic(). What I didn't realize is that flixel does all kinds of stuff under the hood each time makeGraphic() is called, including checking for cached copies.
To make matters worse, a bug in the way I was checking the user's mouse position meant that this code was being called once per frame. (as many as 60 times per second). Needless to say, this wreaked havoc on RAM. I'm not sure if the garbage collector just couldn't keep up, or if there's a memory leak in flixel's makeGraphic(), but I decided to avoid the issue by using some cheaper code that directly creates BitmapData.
Fortunately, memory was stabilized after the fix, which was a relief!
So the day had a few obstacles and bumps, but the UI is shaping up. Monday, I should be able to start on the minimap, and eventually, the monster that is inventory/conditions/encounter/combat/skills/vehicle/camp. The inventory suite will be a ton of work, I expect, but hopefully my experiences this week will prep me for it.
That's it for this week. Have a good weekend, all!