]> git.localhorst.tv Git - l2e.git/blob - src/menu/InventoryMenu.cpp
added basic (non-functional) inventory menu
[l2e.git] / src / menu / InventoryMenu.cpp
1 /*
2  * InventoryMenu.cpp
3  *
4  *  Created on: Nov 4, 2012
5  *      Author: holy
6  */
7
8 #include "InventoryMenu.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 InventoryMenu::InventoryMenu(PartyMenu *parent)
30 : parent(parent)
31 , menu(*parent->Res().itemMenuProperties)
32 , itemMenu(*parent->Res().inventoryMenuProperties) {
33         menu.Add(parent->Res().itemMenuUseText, 0);
34         menu.Add(parent->Res().itemMenuSortText, 1);
35         menu.Add(parent->Res().itemMenuDropText, 2);
36 }
37
38
39 void InventoryMenu::OnEnterState(SDL_Surface *) {
40         const Inventory &inv(parent->Game().state->inventory);
41         itemMenu.Clear();
42         itemMenu.Reserve(inv.MaxItems());
43         for (int i(0); i < inv.MaxItems(); ++i) {
44                 const Item *item(inv.ItemAt(i));
45                 if (item) {
46                         itemMenu.Add(item->Name(), item, item->CanUseOnStatusScreen(), item->MenuIcon(), inv.ItemCountAt(i));
47                 } else {
48                         itemMenu.AddEmptyEntry();
49                 }
50         }
51 }
52
53 void InventoryMenu::OnExitState(SDL_Surface *) {
54
55 }
56
57 void InventoryMenu::OnResumeState(SDL_Surface *) {
58
59 }
60
61 void InventoryMenu::OnPauseState(SDL_Surface *) {
62
63 }
64
65
66 void InventoryMenu::OnResize(int width, int height) {
67
68 }
69
70
71 void InventoryMenu::HandleEvents(const Input &input) {
72         if (input.JustPressed(Input::PAD_LEFT)) {
73                 menu.PreviousItem();
74         }
75         if (input.JustPressed(Input::PAD_RIGHT)) {
76                 menu.NextItem();
77         }
78
79         if (input.JustPressed(Input::PAD_UP)) {
80                 itemMenu.PreviousItem();
81         }
82         if (input.JustPressed(Input::PAD_DOWN)) {
83                 itemMenu.NextItem();
84         }
85 }
86
87 void InventoryMenu::UpdateWorld(float deltaT) {
88
89 }
90
91
92 void InventoryMenu::Render(SDL_Surface *screen) {
93         const Font &font(*parent->Res().normalFont);
94         Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
95         Vector<int> menuOffset(font.CharWidth(), 13 * font.CharHeight() + font.CharHeight() / 8);
96         Vector<int> inventoryOffset(font.CharWidth(), 16 * font.CharHeight() + font.CharHeight() / 8);
97
98         parent->RenderBackground(screen);
99         parent->RenderHeros(screen, offset);
100         RenderMenu(screen, menuOffset + offset);
101         RenderInventory(screen, inventoryOffset + offset);
102 }
103
104 int InventoryMenu::Width() const {
105         return parent->Width();
106 }
107
108 int InventoryMenu::Height() const {
109         return parent->Height();
110 }
111
112 void InventoryMenu::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) const {
113         const Font &font(*parent->Res().normalFont);
114         const Frame &frame(*parent->Res().statusFrame);
115
116         const Vector<int> labelOffset(2 * font.CharWidth(), font.CharHeight());
117         const Vector<int> menuFrameOffset(offset.X() + 8 * font.CharWidth(), offset.Y());
118         const Vector<int> menuOffset(menuFrameOffset.X() + 3 * font.CharWidth(), menuFrameOffset.Y() + font.CharHeight());
119
120         frame.Draw(screen, offset, 8 * font.CharWidth(), 3 * font.CharHeight());
121         font.DrawString(parent->Res().mainMenuItemText, screen, labelOffset + offset);
122         frame.Draw(screen, menuFrameOffset, 22 * font.CharWidth(), 3 * font.CharHeight());
123         menu.Draw(screen, menuOffset);
124 }
125
126 void InventoryMenu::RenderInventory(SDL_Surface *screen, const Vector<int> &offset) const {
127         const Font &font(*parent->Res().normalFont);
128         const Frame &frame(*parent->Res().statusFrame);
129         const Vector<int> menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 4);
130
131         frame.Draw(screen, offset, 30 * font.CharWidth(), 11 * font.CharHeight());
132         itemMenu.Draw(screen, offset + menuOffset);
133 }
134
135 }