]> git.localhorst.tv Git - l2e.git/blobdiff - src/menu/ScenarioMenu.cpp
added scenario menu
[l2e.git] / src / menu / ScenarioMenu.cpp
diff --git a/src/menu/ScenarioMenu.cpp b/src/menu/ScenarioMenu.cpp
new file mode 100644 (file)
index 0000000..a2aca87
--- /dev/null
@@ -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<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);
+}
+
+}