07 October 2010

The Caravan Dialog

Windows/Mac
The dialog which lets you send a trading mission was another complex one that I was putting off. First, it took a lot of space. Second, it has a lot of messy validation, to make sure the Send button is only available when you’ve put together a meaningful caravan. For simplicity, you can’t do both a treasure trade and a trade of other stuff. (Treasures have an interactive scene, so you can decide whether an offer is worth it. Regular trade is simply summarized by news.) So when you clicked the Sell Treasure or Buy Treasure checkbox, the others become disabled. And you need to specify both what you’re selling and what you want to get (e.g. buy Food with Goods).

iOS
The dialog layout itself worked out, in part because clan and treasure information no longer needs space on the screen. Instead, it’s a popup, as seen here. (Lists no longer need to devote space to a scroll bar gadget, which is also nice.)

Validation was a lot easier with a functional specification (pun intended). Though I think there was actually a minor bug in the original (which we deemed harmless, if memory serves). This time it was a bit easier to factor the code and make it correct.

If you can read Objective-C, here’s what some of the validation code looks like. (Variables with an ‘f’ prefix are the UI elements — fClans is the list of known clans.)

- (void) validateSendButton
{
SInt16 total = fFootmen.value + fWeaponthanes.value; // Can't go with nobody!

BOOL selling = fSellCattle.selected || fSellFood.selected || fSellGoods.selected || fSellHorses.selected;
BOOL buying = fBuyCattle.selected || fBuyFood.selected || fBuyGoods.selected || fBuyHorses.selected;
BOOL treasure = (fSellTreasure.selected && fTreasures.value != kNoSelectedItem) || fBuyTreasure.selected;

  fActionButton.enabled = total > 0 && fClans.value != kNoSelectedItem && ((selling && buying) || treasure || fEstablishRoute.selected);
}

So now all the dialogs are functional. Sacrifice still has some edge cases (divination and healing), but you can now perform all the actions of play.

No comments:

Post a Comment