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