-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMenu.h
More file actions
200 lines (158 loc) · 5.84 KB
/
Menu.h
File metadata and controls
200 lines (158 loc) · 5.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#pragma once
#include "Includes.h"
#include "D2DOverlay.h"
class MenuItem {
public:
std::wstring name;
int minimum = 0;
int maximum = 1;
int* setting = nullptr;
int increment = 1;
MenuItem(std::wstring _name) {
this->name = _name;
}
MenuItem(std::wstring _name, int* _setting) {
this->name = _name;
this->setting = _setting;
}
MenuItem(std::wstring _name, int* _setting, int _minimum, int _maximum) {
this->name = _name;
this->setting = _setting;
this->minimum = _minimum;
this->maximum = _maximum;
}
MenuItem(std::wstring _name, int* _setting, int _minimum, int _maximum, int _inc) {
this->name = _name;
this->setting = _setting;
this->minimum = _minimum;
this->maximum = _maximum;
this->increment = _inc;
}
};
class MenuTab {
public:
std::wstring label;
MenuTab();
MenuTab(std::wstring _label) {
label = _label;
}
std::vector<MenuItem> Items = std::vector<MenuItem>();
void AddItem(MenuItem item) {
this->Items.push_back(item);
}
};
class Menu {
private:
Direct2DOverlay* ov;
public:
bool show = true;
int positionx = 20;
int positiony = 20;
int maxwidth = 375;
int maxheight = 500;
D3DXCOLOR Background = D3DXCOLOR(0, .5, .1, .5);
D3DXCOLOR Borders = D3DXCOLOR(0, .8, .7, 1);
D3DXCOLOR Text_Titles = D3DXCOLOR(1, 1, 1, 1);
D3DXCOLOR Text_Items = D3DXCOLOR(.9, .8, .9, 1);
int SelectedMenu = 0;
int SelectedItem = 0;
int spacing = 20;
std::wstring title;
std::vector<MenuTab> Tabs = std::vector<MenuTab>();
Menu() {}
void Initialize(Direct2DOverlay* _ov, std::wstring _title) {
this->ov = _ov;
this->title = _title;
}
void AddTab(MenuTab tab) {
Tabs.push_back(tab);
}
void Render() {
int heightm = (this->Tabs[this->SelectedMenu].Items.size()+ 8)* spacing;
if (!this->show) heightm = this->spacing * 4;
this->ov->DrawBox(this->positionx, this->positiony, this->maxwidth, heightm, 1, Background.r, Background.g, Background.b, Background.a, true); //background
this->ov->DrawString(this->title, 20, this->positionx + 10, this->positiony + spacing - 10, this->Text_Titles.r, this->Text_Titles.g, this->Text_Titles.b);
if (!this->show) {
this->ov->DrawString(L"[Del]: Show/Hide Menu", 20, this->positionx + 10, this->positiony + spacing*2 - 10, this->Text_Items.r, this->Text_Items.g, this->Text_Items.b);
}
else {
for (int tabindex = 0; tabindex < Tabs.size(); tabindex++) {
int widthx = ((this->maxwidth - this->positionx) / Tabs.size());
float thicc = 2;
if (this->SelectedMenu == tabindex) {
thicc = 5;
}
int y1 = this->positiony + this->spacing * 2;
int y2 = this->positiony + this->spacing * 3;
int x1 = (this->positionx + widthx*tabindex) + thicc;
int x2 = (this->positionx + widthx*(tabindex + 1)) - thicc;
this->ov->DrawLine(x1, y1, x2, y1, thicc, Borders.r, Borders.g, Borders.g);
this->ov->DrawLine(x2, y1, x2, y2, thicc, Borders.r, Borders.g, Borders.g);
this->ov->DrawLine(x2, y2, x1, y2, thicc, Borders.r, Borders.g, Borders.g);
this->ov->DrawLine(x1, y2, x1, y1, thicc, Borders.r, Borders.g, Borders.g);
this->ov->DrawString(Tabs[tabindex].label, 15, x1 + 5, y1, this->Text_Titles.r, this->Text_Titles.g, this->Text_Titles.b);
}
for (int itemindex = 0; itemindex < this->Tabs[this->SelectedMenu].Items.size(); itemindex++) {
this->ov->DrawString(this->Tabs[this->SelectedMenu].Items[itemindex].name,
20, this->positionx + 30,
this->positiony + (this->spacing*(4 + itemindex)),
this->Text_Items.r, this->Text_Items.g, this->Text_Items.b);
if (this->Tabs[this->SelectedMenu].Items[itemindex].setting != nullptr) {
this->ov->DrawString(std::to_wstring(*this->Tabs[this->SelectedMenu].Items[itemindex].setting),
20, (this->positionx + this->maxwidth ) - 100,
this->positiony + (this->spacing*(4 + itemindex)),
this->Text_Items.r, this->Text_Items.g, this->Text_Items.b);
}
}
this->ov->DrawString(L"->", 20, this->positionx + 5, this->positiony + (this->SelectedItem*(spacing)+(this->spacing * 4)), 1, 1, 0);
if (GetAsyncKeyState(VK_TAB)) {
this->SelectedMenu += 1;
this->SelectedItem = 0;
if (this->SelectedMenu > this->Tabs.size() - 1) {
this->SelectedMenu = 0;
}
Sleep(150);
}
if (GetAsyncKeyState(VK_DOWN)) {
this->SelectedItem += 1;
if (this->SelectedItem > this->Tabs[this->SelectedMenu].Items.size() - 1) {
this->SelectedItem = 0;
}
Sleep(150);
}
if (GetAsyncKeyState(VK_UP)) {
this->SelectedItem -= 1;
if (this->SelectedItem < 0) {
this->SelectedItem = this->Tabs[this->SelectedMenu].Items.size() - 1;
}
Sleep(150);
}
if (GetAsyncKeyState(VK_RIGHT)) {
if (this->Tabs[this->SelectedMenu].Items[this->SelectedItem].setting != nullptr) {
*this->Tabs[this->SelectedMenu].Items[this->SelectedItem].setting += this->Tabs[this->SelectedMenu].Items[this->SelectedItem].increment;
if (*this->Tabs[this->SelectedMenu].Items[this->SelectedItem].setting >
this->Tabs[this->SelectedMenu].Items[this->SelectedItem].maximum) {
*this->Tabs[this->SelectedMenu].Items[this->SelectedItem].setting =
this->Tabs[this->SelectedMenu].Items[this->SelectedItem].maximum;
}
}
Sleep(150);
}
if (GetAsyncKeyState(VK_LEFT)) {
if (this->Tabs[this->SelectedMenu].Items[this->SelectedItem].setting != nullptr) {
*this->Tabs[this->SelectedMenu].Items[this->SelectedItem].setting -= this->Tabs[this->SelectedMenu].Items[this->SelectedItem].increment;
if (*this->Tabs[this->SelectedMenu].Items[this->SelectedItem].setting <
this->Tabs[this->SelectedMenu].Items[this->SelectedItem].minimum) {
*this->Tabs[this->SelectedMenu].Items[this->SelectedItem].setting =
this->Tabs[this->SelectedMenu].Items[this->SelectedItem].minimum;
}
}
Sleep(150);
}
}
if (GetAsyncKeyState(VK_DELETE)) {
this->show = !this->show;
Sleep(150);
}
}
};