1 #include "ScenarioMenu.h"
5 #include "../app/Input.h"
6 #include "../common/GameConfig.h"
7 #include "../common/GameState.h"
8 #include "../common/Inventory.h"
9 #include "../common/Item.h"
10 #include "../graphics/Font.h"
11 #include "../graphics/Frame.h"
14 using common::Inventory;
16 using geometry::Vector;
18 using graphics::Frame;
22 ScenarioMenu::ScenarioMenu(PartyMenu *parent)
24 , itemMenu(*parent->Res().scenarioMenuProperties) {
29 void ScenarioMenu::OnEnterState(SDL_Surface *) {
33 void ScenarioMenu::LoadItems() {
34 const Inventory &inv(parent->Game().state->inventory);
36 itemMenu.Reserve(inv.MaxScenarioItems());
38 for (; i < inv.NumScenarioItems(); ++i) {
39 const Item *item(inv.ScenarioItemAt(i));
40 itemMenu.Add(item->Name(), item, item->CanUseOnStatusScreen(), item->MenuIcon(), inv.ItemCountAt(i));
42 for (; i < inv.MaxScenarioItems(); ++i) {
43 itemMenu.AddEmptyEntry();
47 void ScenarioMenu::OnExitState(SDL_Surface *) {
51 void ScenarioMenu::OnResumeState(SDL_Surface *) {
55 void ScenarioMenu::OnPauseState(SDL_Surface *) {
60 void ScenarioMenu::OnResize(int width, int height) {
65 void ScenarioMenu::HandleEvents(const Input &input) {
66 if (input.JustPressed(Input::PAD_DOWN)) {
69 if (input.JustPressed(Input::PAD_UP)) {
70 itemMenu.PreviousRow();
72 if (input.JustPressed(Input::ACTION_B)) {
77 void ScenarioMenu::UpdateWorld(float deltaT) {
82 void ScenarioMenu::Render(SDL_Surface *screen) {
83 const Font &font(*parent->Res().normalFont);
84 Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
85 Vector<int> headlineOffset(font.CharWidth(), 13 * font.CharHeight() + font.CharHeight() / 8);
86 Vector<int> itemsOffset(font.CharWidth(), 16 * font.CharHeight() + font.CharHeight() / 8);
88 parent->RenderBackground(screen);
89 parent->RenderHeros(screen, offset);
90 RenderHeadline(screen, offset + headlineOffset);
91 RenderItems(screen, offset + itemsOffset);
94 int ScenarioMenu::Width() const {
95 return parent->Width();
98 int ScenarioMenu::Height() const {
99 return parent->Height();
102 void ScenarioMenu::RenderHeadline(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
103 const Font &font(*parent->Res().normalFont);
104 const Frame &frame(*parent->Res().statusFrame);
105 const Vector<int> textOffset(2 * font.CharWidth(), font.CharHeight());
107 int width = font.StringWidth(parent->Res().scenarioMenuHeadline) + 4 * font.CharWidth();
108 frame.Draw(screen, offset, width, 3 * font.CharHeight());
109 font.DrawString(parent->Res().scenarioMenuHeadline, screen, offset + textOffset);
112 void ScenarioMenu::RenderItems(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
113 const Font &font(*parent->Res().normalFont);
114 const Frame &frame(*parent->Res().statusFrame);
115 const Vector<int> menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 4);
117 frame.Draw(screen, offset, 30 * font.CharWidth(), 11 * font.CharHeight());
118 itemMenu.Draw(screen, offset + menuOffset);