-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsettings.cpp
176 lines (150 loc) · 4 KB
/
settings.cpp
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
#ifndef _MDLP_SETTING
#define _MDLP_SETTING
#include "include/header.h"
using namespace std;
/**
* @details KeyChecker Class
*/
class Setting{
private:
vector<pair<char,int> > keys;
string path;
void write()
{
FILE* fw = fopen(path.data(),"w");
for(auto key : keys)
fprintf(fw, "%c %d\n", key.first, key.second);
fclose(fw);
}
void read()
{
FILE* fr = fopen(path.data(),"r");
keys.clear();
char c; int x;
while(fscanf(fr, "%c %d\n", &c, &x) != EOF)
keys.emplace_back(c, x);
fclose(fr);
}
public:
void Prework(int typ){
path=typ==0?"data/md_settings.laf":"data/fourkey_settings.laf";
load();
}
void load()
{
ClearScreen();
Print("Loading...\n", 20);
if(access(path.data(),0) == -1)
{
if(path=="data/md_settings.laf")
keys = {{'d',1}, {'f',1}, {'j',2}, {'k',2}};
else keys = {{'d',1}, {'f',2}, {'j',3}, {'k',4}};
write();
}
read();
puts("Completed!");
Sleep(OneSecond/20);
}
int checkKey(char c)
{
for(auto key : keys)
if(c == key.first or c == key.first-32)
return key.second;
return -1;
}
void printKey()
{
ClearScreen();
puts("Your key is:");
for(auto key : keys)
printf("%c %d\n", key.first, key.second);
WaitForInput();
}
void set(vector<pair<char,int>> newkeys)
{
keys = newkeys;
write();
}
};
Setting setting[2];
void ResetKey(int);
void SettingsMain()
{
begin:
ClearScreen();
puts("1. Muse Dash Setting.");
puts("2. 4Key Setting.");
puts("3. Back.");
int type;
while(1)
{
if(!_kbhit()) continue;
char c = _getch();
if(c=='1')
{type = 1; break;}
else if(c=='2')
{type = 2; break;}
else if(c=='3')
{goto end; break;}
}
ClearScreen();
Print(type==1?"Muse Dash ":"4Key ", 20);
Print("Settings:\n",20);
cout << "1. Reset the keys." << endl;
cout << "2. Print the keys." << endl;
cout << "3. Back.\n" << endl;
type--;
while(true)
{
if(!_kbhit()) continue;
char c = _getch();
switch(c)
{
case '1': ResetKey(type+1); goto end;
case '2': setting[type].printKey(); goto end;
case '3': goto begin; break;
default: break;
}
}
end:;
}
void ResetKey(int type)
{
type--;
vector<pair<char,int>> keys;
set<char> st;
begin:
system("cls");
puts(type?"4Key Settings:":"Muse Dash Settings:");
puts("Input a char and a number on a line, you can input many until \"0\" \n");
keys.clear();
st.clear();
while(true)
{
char c; int x;
scanf("%c", &c);
if(c == '0') break;
scanf("%d\n", &x);
c = lower(c);
if(st.count(c))
{
puts("Error: The key cannot be the same!");
continue;
}
keys.emplace_back(c, x);
}
puts("Sure to Save?(y/n)");
while(true)
{
if(!_kbhit()) continue;
char c = _getch();
if(c == 'n' or c == 'N') goto begin;
else if(c == 'y' or c == 'Y') break;
}
puts("Saving...");
Sleep(OneSecond);
setting[type].set(keys);
puts("The settings has saved!");
Sleep(OneSecond);
}
#endif // _MDLP_SETTING