1 #include "ScenarioMenu.h"
5 #include "../app/Application.h"
6 #include "../app/Input.h"
7 #include "../common/GameConfig.h"
8 #include "../common/GameState.h"
9 #include "../common/Inventory.h"
10 #include "../common/Item.h"
11 #include "../graphics/Font.h"
12 #include "../graphics/Frame.h"
13 #include "../math/Vector.h"
16 using common::Inventory;
20 using graphics::Frame;
24 ScenarioMenu::ScenarioMenu(PartyMenu *parent)
26 , itemMenu(*parent->Res().scenarioMenuProperties) {
31 void ScenarioMenu::OnEnterState(SDL_Surface *) {
33 itemMenu.StartAnimation(Ctrl());
36 void ScenarioMenu::LoadItems() {
37 const Inventory &inv(parent->Game().state->inventory);
39 itemMenu.Reserve(inv.MaxScenarioItems());
41 for (; i < inv.NumScenarioItems(); ++i) {
42 const Item *item(inv.ScenarioItemAt(i));
43 itemMenu.Add(item->Name(), item, item->CanUseOnStatusScreen(), item->MenuIcon(), inv.ItemCountAt(i));
45 for (; i < inv.MaxScenarioItems(); ++i) {
46 itemMenu.AddEmptyEntry();
50 void ScenarioMenu::OnExitState(SDL_Surface *) {
54 void ScenarioMenu::OnResumeState(SDL_Surface *) {
58 void ScenarioMenu::OnPauseState(SDL_Surface *) {
63 void ScenarioMenu::OnResize(int width, int height) {
68 void ScenarioMenu::HandleEvents(const Input &input) {
69 if (input.JustPressed(Input::PAD_DOWN)) {
72 if (input.JustPressed(Input::PAD_UP)) {
73 itemMenu.PreviousRow();
75 if (input.JustPressed(Input::ACTION_B)) {
80 void ScenarioMenu::UpdateWorld(Uint32 deltaT) {
85 void ScenarioMenu::Render(SDL_Surface *screen) {
86 const Font &font(*parent->Res().normalFont);
87 Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
88 Vector<int> headlineOffset(font.CharWidth(), 13 * font.CharHeight() + font.CharHeight() / 8);
89 Vector<int> itemsOffset(font.CharWidth(), 16 * font.CharHeight() + font.CharHeight() / 8);
91 parent->RenderBackground(screen);
92 parent->RenderHeros(screen, offset);
93 RenderHeadline(screen, offset + headlineOffset);
94 RenderItems(screen, offset + itemsOffset);
97 int ScenarioMenu::Width() const {
98 return parent->Width();
101 int ScenarioMenu::Height() const {
102 return parent->Height();
105 void ScenarioMenu::RenderHeadline(SDL_Surface *screen, const math::Vector<int> &offset) const {
106 const Font &font(*parent->Res().normalFont);
107 const Frame &frame(*parent->Res().statusFrame);
108 const Vector<int> textOffset(2 * font.CharWidth(), font.CharHeight());
110 int width = font.StringWidth(parent->Res().scenarioMenuHeadline) + 4 * font.CharWidth();
111 frame.Draw(screen, offset, width, 3 * font.CharHeight());
112 font.DrawString(parent->Res().scenarioMenuHeadline, screen, offset + textOffset);
115 void ScenarioMenu::RenderItems(SDL_Surface *screen, const math::Vector<int> &offset) const {
116 const Font &font(*parent->Res().normalFont);
117 const Frame &frame(*parent->Res().statusFrame);
118 const Vector<int> menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 4);
120 frame.Draw(screen, offset, 30 * font.CharWidth(), 11 * font.CharHeight());
121 itemMenu.Draw(screen, offset + menuOffset);