X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmenu%2FScenarioMenu.cpp;fp=src%2Fmenu%2FScenarioMenu.cpp;h=a2aca87875b899aa1333062d612c8b67026ad06d;hb=37f46a0eb5ddbf9e3de672cf6da97605e41bd1f4;hp=0000000000000000000000000000000000000000;hpb=ee953c3847abc32c3e369672b7c35424f061765c;p=l2e.git diff --git a/src/menu/ScenarioMenu.cpp b/src/menu/ScenarioMenu.cpp new file mode 100644 index 0000000..a2aca87 --- /dev/null +++ b/src/menu/ScenarioMenu.cpp @@ -0,0 +1,128 @@ +/* + * ScenarioMenu.cpp + * + * Created on: Nov 30, 2012 + * Author: holy + */ + +#include "ScenarioMenu.h" + +#include "PartyMenu.h" +#include "Resources.h" +#include "../app/Input.h" +#include "../common/GameConfig.h" +#include "../common/GameState.h" +#include "../common/Inventory.h" +#include "../common/Item.h" +#include "../graphics/Font.h" +#include "../graphics/Frame.h" + +using app::Input; +using common::Inventory; +using common::Item; +using geometry::Vector; +using graphics::Font; +using graphics::Frame; + +namespace menu { + +ScenarioMenu::ScenarioMenu(PartyMenu *parent) +: parent(parent) +, itemMenu(*parent->Res().scenarioMenuProperties) { + +} + + +void ScenarioMenu::OnEnterState(SDL_Surface *) { + LoadItems(); +} + +void ScenarioMenu::LoadItems() { + const Inventory &inv(parent->Game().state->inventory); + itemMenu.Clear(); + itemMenu.Reserve(inv.MaxScenarioItems()); + int i = 0; + for (; i < inv.NumScenarioItems(); ++i) { + const Item *item(inv.ScenarioItemAt(i)); + itemMenu.Add(item->Name(), item, item->CanUseOnStatusScreen(), item->MenuIcon(), inv.ItemCountAt(i)); + } + for (; i < inv.MaxScenarioItems(); ++i) { + itemMenu.AddEmptyEntry(); + } +} + +void ScenarioMenu::OnExitState(SDL_Surface *) { + +} + +void ScenarioMenu::OnResumeState(SDL_Surface *) { + +} + +void ScenarioMenu::OnPauseState(SDL_Surface *) { + +} + + +void ScenarioMenu::OnResize(int width, int height) { + +} + + +void ScenarioMenu::HandleEvents(const Input &input) { + if (input.JustPressed(Input::PAD_DOWN)) { + itemMenu.NextRow(); + } + if (input.JustPressed(Input::PAD_UP)) { + itemMenu.PreviousRow(); + } + if (input.JustPressed(Input::ACTION_B)) { + Ctrl().PopState(); + } +} + +void ScenarioMenu::UpdateWorld(float deltaT) { + +} + + +void ScenarioMenu::Render(SDL_Surface *screen) { + const Font &font(*parent->Res().normalFont); + Vector offset((screen->w - Width()) / 2, (screen->h - Height()) / 2); + Vector headlineOffset(font.CharWidth(), 13 * font.CharHeight() + font.CharHeight() / 8); + Vector itemsOffset(font.CharWidth(), 16 * font.CharHeight() + font.CharHeight() / 8); + + parent->RenderBackground(screen); + parent->RenderHeros(screen, offset); + RenderHeadline(screen, offset + headlineOffset); + RenderItems(screen, offset + itemsOffset); +} + +int ScenarioMenu::Width() const { + return parent->Width(); +} + +int ScenarioMenu::Height() const { + return parent->Height(); +} + +void ScenarioMenu::RenderHeadline(SDL_Surface *screen, const geometry::Vector &offset) const { + const Font &font(*parent->Res().normalFont); + const Frame &frame(*parent->Res().statusFrame); + const Vector textOffset(2 * font.CharWidth(), font.CharHeight()); + + int width = font.StringWidth(parent->Res().scenarioMenuHeadline) + 4 * font.CharWidth(); + frame.Draw(screen, offset, width, 3 * font.CharHeight()); + font.DrawString(parent->Res().scenarioMenuHeadline, screen, offset + textOffset); +} + +void ScenarioMenu::RenderItems(SDL_Surface *screen, const geometry::Vector &offset) const { + const Font &font(*parent->Res().normalFont); + const Frame &frame(*parent->Res().statusFrame); + const Vector menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 4); + + frame.Draw(screen, offset, 30 * font.CharWidth(), 11 * font.CharHeight()); + itemMenu.Draw(screen, offset + menuOffset); +} + +}