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"
15 using common::Inventory;
17 using geometry::Vector;
19 using graphics::Frame;
23 ScenarioMenu::ScenarioMenu(PartyMenu *parent)
25 , itemMenu(*parent->Res().scenarioMenuProperties) {
30 void ScenarioMenu::OnEnterState(SDL_Surface *) {
34 void ScenarioMenu::LoadItems() {
35 const Inventory &inv(parent->Game().state->inventory);
37 itemMenu.Reserve(inv.MaxScenarioItems());
39 for (; i < inv.NumScenarioItems(); ++i) {
40 const Item *item(inv.ScenarioItemAt(i));
41 itemMenu.Add(item->Name(), item, item->CanUseOnStatusScreen(), item->MenuIcon(), inv.ItemCountAt(i));
43 for (; i < inv.MaxScenarioItems(); ++i) {
44 itemMenu.AddEmptyEntry();
48 void ScenarioMenu::OnExitState(SDL_Surface *) {
52 void ScenarioMenu::OnResumeState(SDL_Surface *) {
56 void ScenarioMenu::OnPauseState(SDL_Surface *) {
61 void ScenarioMenu::OnResize(int width, int height) {
66 void ScenarioMenu::HandleEvents(const Input &input) {
67 if (input.JustPressed(Input::PAD_DOWN)) {
70 if (input.JustPressed(Input::PAD_UP)) {
71 itemMenu.PreviousRow();
73 if (input.JustPressed(Input::ACTION_B)) {
78 void ScenarioMenu::UpdateWorld(float deltaT) {
83 void ScenarioMenu::Render(SDL_Surface *screen) {
84 const Font &font(*parent->Res().normalFont);
85 Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
86 Vector<int> headlineOffset(font.CharWidth(), 13 * font.CharHeight() + font.CharHeight() / 8);
87 Vector<int> itemsOffset(font.CharWidth(), 16 * font.CharHeight() + font.CharHeight() / 8);
89 parent->RenderBackground(screen);
90 parent->RenderHeros(screen, offset);
91 RenderHeadline(screen, offset + headlineOffset);
92 RenderItems(screen, offset + itemsOffset);
95 int ScenarioMenu::Width() const {
96 return parent->Width();
99 int ScenarioMenu::Height() const {
100 return parent->Height();
103 void ScenarioMenu::RenderHeadline(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
104 const Font &font(*parent->Res().normalFont);
105 const Frame &frame(*parent->Res().statusFrame);
106 const Vector<int> textOffset(2 * font.CharWidth(), font.CharHeight());
108 int width = font.StringWidth(parent->Res().scenarioMenuHeadline) + 4 * font.CharWidth();
109 frame.Draw(screen, offset, width, 3 * font.CharHeight());
110 font.DrawString(parent->Res().scenarioMenuHeadline, screen, offset + textOffset);
113 void ScenarioMenu::RenderItems(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
114 const Font &font(*parent->Res().normalFont);
115 const Frame &frame(*parent->Res().statusFrame);
116 const Vector<int> menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 4);
118 frame.Draw(screen, offset, 30 * font.CharWidth(), 11 * font.CharHeight());
119 itemMenu.Draw(screen, offset + menuOffset);