-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtab.cpp
More file actions
60 lines (54 loc) · 1.44 KB
/
tab.cpp
File metadata and controls
60 lines (54 loc) · 1.44 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
#include "tab.hpp"
void Tab::display() {
printf("<<< %s >>>\n", m_sName.c_str());
for (int i = 1; i <= m_iItems.size(); i++) {
m_iItems.at(i - 1)->setItemNum(i);
(m_iSelectedItem == i - 1) ? m_iItems.at(i - 1)->display("<--") : m_iItems.at(i - 1)->display("");
}
}
void Tab::think() {
bool up = (GetAsyncKeyState(VK_UP) & 0x8000) != 0;
bool down = (GetAsyncKeyState(VK_DOWN) & 0x8000) != 0;
if (up != down && (up || down)) {
Sleep(85);
down ? m_iSelectedItem++ : m_iSelectedItem--;
m_iSelectedItem = down ? Math::menu_wrap(m_iSelectedItem, 0, m_iItems.size() - 1) : Math::menu_wrap(m_iSelectedItem, m_iItems.size() - 1, 0);
system("cls");
display();
}
else if (GetAsyncKeyState(VK_RETURN)) {
Sleep(100);
m_iItems.at(m_iSelectedItem)->execute();
system("cls");
display();
}
}
void Tab::setKeyValue(int val) {
m_iKeyValue = val;
}
string Tab::createConfig() {
string fig = "";
for (int i = 0; i < m_iItems.size(); i++) {
fig += m_iItems.at(i)->createConfig();
}
fig += m_sName + "\n";
return fig;
}
void Tab::loadConfig(ifstream& file) {
string lines;
string line;
while (getline(file, line))
{
if (line == this->getName())
break;
lines += line + "\n";
}
for (int i = 0; i < m_iItems.size(); i++) {
m_iItems.at(i)->loadConfig(lines);
}
}
Tab::Tab(string name, vector<unique_ptr<Item>>&& items) {
m_sName = name;
m_iItems = move(items);
m_iSelectedItem = 0;
}