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