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 *) {
35 void ScenarioMenu::LoadItems() {
36 const Inventory &inv(parent->Game().state->inventory);
38 itemMenu.Reserve(inv.MaxScenarioItems());
40 for (; i < inv.NumScenarioItems(); ++i) {
41 const Item *item(inv.ScenarioItemAt(i));
42 itemMenu.Add(item->Name(), item, item->CanUseOnStatusScreen(), item->MenuIcon(), inv.ItemCountAt(i));
44 for (; i < inv.MaxScenarioItems(); ++i) {
45 itemMenu.AddEmptyEntry();
49 void ScenarioMenu::OnExitState(SDL_Surface *) {
53 void ScenarioMenu::OnResumeState(SDL_Surface *) {
57 void ScenarioMenu::OnPauseState(SDL_Surface *) {
62 void ScenarioMenu::OnResize(int width, int height) {
67 void ScenarioMenu::HandleEvents(const Input &input) {
68 if (input.JustPressed(Input::PAD_DOWN)) {
71 if (input.JustPressed(Input::PAD_UP)) {
72 itemMenu.PreviousRow();
74 if (input.JustPressed(Input::ACTION_B)) {
79 void ScenarioMenu::UpdateWorld(Uint32 deltaT) {
84 void ScenarioMenu::Render(SDL_Surface *screen) {
85 const Font &font(*parent->Res().normalFont);
86 Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
87 Vector<int> headlineOffset(font.CharWidth(), 13 * font.CharHeight() + font.CharHeight() / 8);
88 Vector<int> itemsOffset(font.CharWidth(), 16 * font.CharHeight() + font.CharHeight() / 8);
90 parent->RenderBackground(screen);
91 parent->RenderHeros(screen, offset);
92 RenderHeadline(screen, offset + headlineOffset);
93 RenderItems(screen, offset + itemsOffset);
96 int ScenarioMenu::Width() const {
97 return parent->Width();
100 int ScenarioMenu::Height() const {
101 return parent->Height();
104 void ScenarioMenu::RenderHeadline(SDL_Surface *screen, const math::Vector<int> &offset) const {
105 const Font &font(*parent->Res().normalFont);
106 const Frame &frame(*parent->Res().statusFrame);
107 const Vector<int> textOffset(2 * font.CharWidth(), font.CharHeight());
109 int width = font.StringWidth(parent->Res().scenarioMenuHeadline) + 4 * font.CharWidth();
110 frame.Draw(screen, offset, width, 3 * font.CharHeight());
111 font.DrawString(parent->Res().scenarioMenuHeadline, screen, offset + textOffset);
114 void ScenarioMenu::RenderItems(SDL_Surface *screen, const math::Vector<int> &offset) const {
115 const Font &font(*parent->Res().normalFont);
116 const Frame &frame(*parent->Res().statusFrame);
117 const Vector<int> menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 4);
119 frame.Draw(screen, offset, 30 * font.CharWidth(), 11 * font.CharHeight());
120 itemMenu.Draw(screen, offset + menuOffset);