]> git.localhorst.tv Git - l2e.git/blob - src/menu/ScenarioMenu.cpp
removed lazy fwd headers
[l2e.git] / src / menu / ScenarioMenu.cpp
1 #include "ScenarioMenu.h"
2
3 #include "PartyMenu.h"
4 #include "Resources.h"
5 #include "../app/Application.h"
6 #include "../app/Input.h"
7 #include "../common/GameConfig.h"
8 #include "../common/GameState.h"
9 #include "../common/Inventory.h"
10 #include "../common/Item.h"
11 #include "../graphics/Font.h"
12 #include "../graphics/Frame.h"
13 #include "../math/Vector.h"
14
15 using app::Input;
16 using common::Inventory;
17 using common::Item;
18 using math::Vector;
19 using graphics::Font;
20 using graphics::Frame;
21
22 namespace menu {
23
24 ScenarioMenu::ScenarioMenu(PartyMenu *parent)
25 : parent(parent)
26 , itemMenu(*parent->Res().scenarioMenuProperties) {
27
28 }
29
30
31 void ScenarioMenu::OnEnterState(SDL_Surface *) {
32         LoadItems();
33 }
34
35 void ScenarioMenu::LoadItems() {
36         const Inventory &inv(parent->Game().state->inventory);
37         itemMenu.Clear();
38         itemMenu.Reserve(inv.MaxScenarioItems());
39         int i = 0;
40         for (; i < inv.NumScenarioItems(); ++i) {
41                 const Item *item(inv.ScenarioItemAt(i));
42                 itemMenu.Add(item->Name(), item, item->CanUseOnStatusScreen(), item->MenuIcon(), inv.ItemCountAt(i));
43         }
44         for (; i < inv.MaxScenarioItems(); ++i) {
45                 itemMenu.AddEmptyEntry();
46         }
47 }
48
49 void ScenarioMenu::OnExitState(SDL_Surface *) {
50
51 }
52
53 void ScenarioMenu::OnResumeState(SDL_Surface *) {
54
55 }
56
57 void ScenarioMenu::OnPauseState(SDL_Surface *) {
58
59 }
60
61
62 void ScenarioMenu::OnResize(int width, int height) {
63
64 }
65
66
67 void ScenarioMenu::HandleEvents(const Input &input) {
68         if (input.JustPressed(Input::PAD_DOWN)) {
69                 itemMenu.NextRow();
70         }
71         if (input.JustPressed(Input::PAD_UP)) {
72                 itemMenu.PreviousRow();
73         }
74         if (input.JustPressed(Input::ACTION_B)) {
75                 Ctrl().PopState();
76         }
77 }
78
79 void ScenarioMenu::UpdateWorld(Uint32 deltaT) {
80
81 }
82
83
84 void ScenarioMenu::Render(SDL_Surface *screen) {
85         const Font &font(*parent->Res().normalFont);
86         Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
87         Vector<int> headlineOffset(font.CharWidth(), 13 * font.CharHeight() + font.CharHeight() / 8);
88         Vector<int> itemsOffset(font.CharWidth(), 16 * font.CharHeight() + font.CharHeight() / 8);
89
90         parent->RenderBackground(screen);
91         parent->RenderHeros(screen, offset);
92         RenderHeadline(screen, offset + headlineOffset);
93         RenderItems(screen, offset + itemsOffset);
94 }
95
96 int ScenarioMenu::Width() const {
97         return parent->Width();
98 }
99
100 int ScenarioMenu::Height() const {
101         return parent->Height();
102 }
103
104 void ScenarioMenu::RenderHeadline(SDL_Surface *screen, const math::Vector<int> &offset) const {
105         const Font &font(*parent->Res().normalFont);
106         const Frame &frame(*parent->Res().statusFrame);
107         const Vector<int> textOffset(2 * font.CharWidth(), font.CharHeight());
108
109         int width = font.StringWidth(parent->Res().scenarioMenuHeadline) + 4 * font.CharWidth();
110         frame.Draw(screen, offset, width, 3 * font.CharHeight());
111         font.DrawString(parent->Res().scenarioMenuHeadline, screen, offset + textOffset);
112 }
113
114 void ScenarioMenu::RenderItems(SDL_Surface *screen, const math::Vector<int> &offset) const {
115         const Font &font(*parent->Res().normalFont);
116         const Frame &frame(*parent->Res().statusFrame);
117         const Vector<int> menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 4);
118
119         frame.Draw(screen, offset, 30 * font.CharWidth(), 11 * font.CharHeight());
120         itemMenu.Draw(screen, offset + menuOffset);
121 }
122
123 }