forked from Icclear/OsuBot-3.0
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwindow.cpp
120 lines (93 loc) · 2.81 KB
/
mainwindow.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
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//Todo: Caption
if(program.getError() != 0)
close();
SongFolderList = program.getSongList();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
if(ui->DiffList->currentItem() == (NULL || nullptr))
return; //Nothing selected..:<
std::string DiffName = ui->DiffList->currentItem()->text().toStdString();
for(auto &i : Diffs)
{
if(i.find(DiffName) != std::string::npos)
{
DiffName = i;
break;
}
else if(DiffName.compare("[]") == 0 && i.find("[") == std::string::npos) //no diffname
{
DiffName = i;
break;
}
}
program.LoadBeatmap(program.getSongPath() +
ui->SongList->currentItem()->text().toStdString() + "\\" +
DiffName);
}
void MainWindow::on_SongSearch_textChanged()
{
ui->SongList->clear();
ui->DiffList->clear();
std::string TextBox = ui->SongSearch->toPlainText().toStdString();
std::transform(TextBox.begin(), TextBox.end(), TextBox.begin(), ::tolower);
for(auto &i : *SongFolderList)
{
std::string tmp = i;
std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
if(tmp.find(TextBox) != std::string::npos)
ui->SongList->addItem(i.c_str());
}
}
void MainWindow::on_SongList_itemSelectionChanged()
{
std::string BeatmapDir = program.getSongPath() + ui->SongList->currentItem()->text().toStdString();
ui->DiffList->clear();
Diffs.clear();
char szBuffer[MAX_PATH];
GetCurrentDirectory(MAX_PATH, szBuffer);
SetCurrentDirectory(BeatmapDir.c_str());
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile("*.osu", &fd);
// Get all sub-folders:
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
std::string pszName = fd.cFileName;
unsigned int difPos = pszName.find("[");
if(difPos == std::string::npos)
{
ui->DiffList->addItem("[]");
}
else
{
std::string temp = pszName.substr(difPos, pszName.length() - difPos - 4);
ui->DiffList->addItem(temp.c_str());
}
Diffs.push_back(pszName);
} while (FindNextFile(hFind, &fd));
FindClose(hFind);
}
// Set the current folder back to what it was:
SetCurrentDirectory(szBuffer);
}
void MainWindow::on_AutoEnabled_toggled(bool checked)
{
program.setAuto(checked);
}
void MainWindow::on_RelaxEnabled_toggled(bool checked)
{
program.setRelax(checked);
}