]> git.localhorst.tv Git - l2e.git/blob - src/menu/ScenarioMenu.cpp
removed stupid file headers that eclipse put in
[l2e.git] / src / menu / ScenarioMenu.cpp
1 #include "ScenarioMenu.h"
2
3 #include "PartyMenu.h"
4 #include "Resources.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"
12
13 using app::Input;
14 using common::Inventory;
15 using common::Item;
16 using geometry::Vector;
17 using graphics::Font;
18 using graphics::Frame;
19
20 namespace menu {
21
22 ScenarioMenu::ScenarioMenu(PartyMenu *parent)
23 : parent(parent)
24 , itemMenu(*parent->Res().scenarioMenuProperties) {
25
26 }
27
28
29 void ScenarioMenu::OnEnterState(SDL_Surface *) {
30         LoadItems();
31 }
32
33 void ScenarioMenu::LoadItems() {
34         const Inventory &inv(parent->Game().state->inventory);
35         itemMenu.Clear();
36         itemMenu.Reserve(inv.MaxScenarioItems());
37         int i = 0;
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));
41         }
42         for (; i < inv.MaxScenarioItems(); ++i) {
43                 itemMenu.AddEmptyEntry();
44         }
45 }
46
47 void ScenarioMenu::OnExitState(SDL_Surface *) {
48
49 }
50
51 void ScenarioMenu::OnResumeState(SDL_Surface *) {
52
53 }
54
55 void ScenarioMenu::OnPauseState(SDL_Surface *) {
56
57 }
58
59
60 void ScenarioMenu::OnResize(int width, int height) {
61
62 }
63
64
65 void ScenarioMenu::HandleEvents(const Input &input) {
66         if (input.JustPressed(Input::PAD_DOWN)) {
67                 itemMenu.NextRow();
68         }
69         if (input.JustPressed(Input::PAD_UP)) {
70                 itemMenu.PreviousRow();
71         }
72         if (input.JustPressed(Input::ACTION_B)) {
73                 Ctrl().PopState();
74         }
75 }
76
77 void ScenarioMenu::UpdateWorld(float deltaT) {
78
79 }
80
81
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);
87
88         parent->RenderBackground(screen);
89         parent->RenderHeros(screen, offset);
90         RenderHeadline(screen, offset + headlineOffset);
91         RenderItems(screen, offset + itemsOffset);
92 }
93
94 int ScenarioMenu::Width() const {
95         return parent->Width();
96 }
97
98 int ScenarioMenu::Height() const {
99         return parent->Height();
100 }
101
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());
106
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);
110 }
111
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);
116
117         frame.Draw(screen, offset, 30 * font.CharWidth(), 11 * font.CharHeight());
118         itemMenu.Draw(screen, offset + menuOffset);
119 }
120
121 }