-void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
- monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
- heroesLayout->CalculatePositions(background->w, background->h, heroesPositions);
- for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
- heroTags.push_back(HeroTag(&heroes[i], HeroTag::Alignment((i + 1) % 2)));
+void BattleState::OnEnterState(SDL_Surface *screen) {
+ for (int i(0); i < 4; ++i) {
+ Hero &hero = HeroAt(i);
+ hero.Position() = battle.HeroesLayout().CalculatePosition(i, background->w, background->h);
+ hero.SpellMenu() = *res->spellMenuProperties;
+ hero.UpdateSpellMenu();
+ hero.IkariMenu() = *res->ikariMenuProperties;
+ hero.UpdateIkariMenu(res);
+ heroTags[i] = HeroTag(this, i);
+ smallHeroTags[i] = SmallHeroTag(this, i);
+ }
+
+ battle.GetCapsule().Position() = battle.HeroesLayout().CalculatePosition(4, background->w, background->h);
+
+ for (int i(0); i < battle.NumMonsters(); ++i) {
+ MonsterAt(i).Position() = battle.MonstersLayout().CalculatePosition(i, background->w, background->h);
+ }
+
+ int tagHeight(attackTypeMenu.Height());
+ int tagWidth(attackTypeMenu.Width() * 2 + attackTypeMenu.Width() / 2);
+ int xOffset((Width() - 2 * tagWidth) / 2);
+ heroTagPositions[0] = Vector<int>(xOffset, Height() - 2 * tagHeight);
+ heroTagPositions[1] = Vector<int>(xOffset + tagWidth, Height() - 2 * tagHeight);
+ heroTagPositions[2] = Vector<int>(xOffset, Height() - tagHeight);
+ heroTagPositions[3] = Vector<int>(xOffset + tagWidth, Height() - tagHeight);
+
+ tagHeight = res->normalFont->CharHeight() * 4 + res->smallHeroTagFrame->BorderHeight() * 2;
+ tagWidth = res->normalFont->CharWidth() * 6 + res->smallHeroTagFrame->BorderWidth() * 2;
+ xOffset = (Width() - 4 * tagWidth) / 2;
+ int yOffset(Height() - tagHeight);
+ smallHeroTagPositions[0] = Vector<int>(xOffset, yOffset);
+ smallHeroTagPositions[1] = Vector<int>(xOffset + 2 * tagWidth, yOffset);
+ smallHeroTagPositions[2] = Vector<int>(xOffset + tagWidth, yOffset);
+ smallHeroTagPositions[3] = Vector<int>(xOffset + 3 * tagWidth, yOffset);
+
+ OnResize(screen->w, screen->h);
+
+ itemMenu = *res->itemMenuProperties;
+ LoadInventory();
+ battle.ClearAllAttacks();
+}
+
+void BattleState::LoadInventory() {
+ const Inventory &inv(game->state->inventory);
+ itemMenu.Clear();
+ itemMenu.Reserve(inv.MaxItems());
+ for (int i(0); i < inv.MaxItems(); ++i) {
+ const Item *item(inv.ItemAt(i));
+ if (item) {
+ itemMenu.Add(item->Name(), item, item->CanUseInBattle(), item->MenuIcon(), inv.ItemCountAt(i));
+ } else {
+ itemMenu.AddEmptyEntry();
+ }