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