--- /dev/null
+/*
+ * 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<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
+ Vector<int> headlineOffset(font.CharWidth(), 13 * font.CharHeight() + font.CharHeight() / 8);
+ Vector<int> 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<int> &offset) const {
+ const Font &font(*parent->Res().normalFont);
+ const Frame &frame(*parent->Res().statusFrame);
+ const Vector<int> 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<int> &offset) const {
+ const Font &font(*parent->Res().normalFont);
+ const Frame &frame(*parent->Res().statusFrame);
+ const Vector<int> menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 4);
+
+ frame.Draw(screen, offset, 30 * font.CharWidth(), 11 * font.CharHeight());
+ itemMenu.Draw(screen, offset + menuOffset);
+}
+
+}
--- /dev/null
+/*
+ * ScenarioMenu.h
+ *
+ * Created on: Nov 30, 2012
+ * Author: holy
+ */
+
+#ifndef MENU_SCENARIOMENU_H_
+#define MENU_SCENARIOMENU_H_
+
+#include "fwd.h"
+#include "../app/State.h"
+#include "../common/fwd.h"
+#include "../geometry/Vector.h"
+#include "../graphics/Menu.h"
+
+namespace menu {
+
+class ScenarioMenu
+: public app::State {
+
+public:
+ explicit ScenarioMenu(PartyMenu *parent);
+
+public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+ int Width() const;
+ int Height() const;
+
+private:
+ virtual void OnEnterState(SDL_Surface *screen);
+ virtual void OnExitState(SDL_Surface *screen);
+ virtual void OnResumeState(SDL_Surface *screen);
+ virtual void OnPauseState(SDL_Surface *screen);
+
+ virtual void OnResize(int width, int height);
+
+ void LoadItems();
+
+ void RenderHeadline(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderItems(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+
+private:
+ PartyMenu *parent;
+ graphics::Menu<const common::Item *> itemMenu;
+
+};
+
+}
+
+#endif /* MENU_SCENARIOMENU_H_ */