mainwindow.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. #include "mainwindow.h"
  2. #include "filesystem.h"
  3. #include "aconfig.h"
  4. #include "anetwork.h"
  5. #include "gameres.h"
  6. #include "downloadmanager.h"
  7. #include "skin.h"
  8. #include <QBitmap>
  9. #include <QMovie>
  10. #include <QGraphicsDropShadowEffect>
  11. #include <QCloseEvent>
  12. #include <QClipboard>
  13. #include <QFileDialog>
  14. MainWindow::MainWindow( QMainWindow* parent )
  15. : QMainWindow(parent, Qt::Window | Qt::FramelessWindowHint)
  16. , ui(new Ui::MainWindow)
  17. , dx(0)
  18. , dy(0) {
  19. ui->setupUi(this);
  20. if(!FileSystem::fileExists(QApplication::applicationDirPath() + "/settings.ini"))
  21. AConfig::getInstance()->saveConfig();
  22. QString skin = Skin::getInstance()->getSkinName();
  23. setWindowIcon(QIcon(":/res/styles/" + skin + "/icon6.png"));
  24. QCoreApplication::setOrganizationName(ORGANIZATION_NAME);
  25. QCoreApplication::setOrganizationDomain(ORGANIZATION_DOMAIN);
  26. QCoreApplication::setApplicationName(APPLICATION_NAME);
  27. setWindowTitle("ВКО: Наследие");
  28. show();
  29. // Проводим подготовку к запуску
  30. loadConfig();
  31. Skin::getInstance()->loadSkin();
  32. loadNews();
  33. ANetwork::getInstance()->getFootMessage();
  34. ANetwork::getInstance()->getServers();
  35. ANetwork::getInstance()->getCoupon();
  36. loadHelp();
  37. setAbout();
  38. Skin::getInstance()->findSkins();
  39. //app->helper->setPatchsDates();
  40. qInfo("%s:%i: %s", __FILE__, __LINE__, "Оформляем главное окно.");
  41. QPixmap maskPix(":/res/styles/" + skin + "/bg.png");
  42. QPixmap maskPixLocal(QApplication::applicationDirPath() + "styles/" + skin + "/bg.png");
  43. maskPix = maskPix.isNull() ? maskPixLocal : maskPix;
  44. this->setMask(maskPix.mask());
  45. qInfo("%s:%i: %s", __FILE__, __LINE__, "Устанавливаем анимации.");
  46. QMovie * movie = new QMovie(":/res/styles/" + skin + "/loader.gif");
  47. ui->loader->setMovie(movie);
  48. movie->setScaledSize(QSize(ui->loader->width(), ui->loader->height()));
  49. movie->start();
  50. connect(ui->skinSelect, SIGNAL(currentIndexChanged(int)), this, SLOT(saveSkin()));
  51. }
  52. void MainWindow::addComboItem(QComboBox* combo, QString itemName, QIcon* icon){
  53. combo->insertItem(0, itemName);
  54. combo->setItemIcon(0, *icon);
  55. }
  56. void MainWindow::saveLocale(int locale, QPushButton * button){
  57. QString file;
  58. if(locale == 0) file = "client_local_English.dat";
  59. if(locale == 1) file = "client_local_DE.dat";
  60. if(locale == 2) file = "client_local_FR.dat";
  61. if(FileSystem::fileExists(AConfig::getInstance()->getValue("Local", "folder") + "/" + file)){
  62. ui->enButton->setEnabled(true);
  63. ui->deButton->setEnabled(true);
  64. ui->frButton->setEnabled(true);
  65. button->setEnabled(false);
  66. AConfig::getInstance()->setValue("Local", "file", file);
  67. } else {
  68. QString text = "Данная локализация отсутствует";
  69. QString info = "В настоящий момент вы не можете выбрать данную опцию, поскольку файл " + file + " отсутствует в вашем игровом клиенте. Чтобы скачать его, запустите официальный лаунчер, выберите желаемый язык в верхней правой части окна и дождитесь, когда загрузка необходимых файлов завершится.";
  70. myDialogBox(text, info, "OK", "Отмена", "gandalf.png", "", "", 400, 220, true, false);
  71. }
  72. }
  73. void MainWindow::loadConfig() {
  74. qInfo("%s:%i: %s", __FILE__, __LINE__, "Находим каталог с игрой");
  75. ui->lotropathLabel->setText(AConfig::getInstance()->getValue("Local", "folder") != "-1" ? AConfig::getInstance()->getValue("Local", "folder") : "Выберите папку с игрой");
  76. qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Шрифты\"");
  77. ui->checkFonts->setChecked(AConfig::getInstance()->getValue("Editor", "fonts") == "true" ? true : false);
  78. qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Тексты\"");
  79. ui->checkTexts->setChecked(AConfig::getInstance()->getValue("Editor", "texts")== "true" ? true : false);
  80. qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Карты\"");
  81. ui->checkMaps->setChecked(AConfig::getInstance()->getValue("Editor", "images") == "true" ? true : false);
  82. qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Звуки\"");
  83. ui->checkSounds->setChecked(AConfig::getInstance()->getValue("Editor", "sounds")== "true" ? true : false);
  84. ui->checkVideos->setChecked(AConfig::getInstance()->getValue("Editor", "videos") == "true" ? true : false);
  85. qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность патча \"Заставки\"");
  86. ui->checkScreens->setChecked(AConfig::getInstance()->getValue("Editor", "screens")== "true" ? true : false);
  87. qInfo("%s:%i: %s", __FILE__, __LINE__, "Проверяем активность микрообновлений");
  88. ui->checkMicro->setChecked(AConfig::getInstance()->getValue("Updates", "micro")== "true" ? true : false);
  89. qInfo("%s:%i: %s", __FILE__, __LINE__, "Выполнено.");
  90. }
  91. void MainWindow::loadNews(){
  92. qInfo("Загружаем скин лаунчера");
  93. qInfo("%s:%i: %s", __FILE__, __LINE__, "Загрузка новостей с сайта");
  94. QString response = ANetwork::getInstance()->query(AConfig::getInstance()->getValue("Network", "news"));
  95. if (response == "error"){
  96. qInfo("%s:%i: %s", __FILE__, __LINE__, "Отсутствует связь с сервером. Прервано.");
  97. return;
  98. }
  99. QStringList data = response.split(":::");
  100. qInfo("%s:%i: %s%s", __FILE__, __LINE__, "Получено новостей - ", QString::number(data.count()).toStdString().c_str());
  101. int counter = 1;
  102. foreach(QString news, data){
  103. qInfo("%s:%i: %s%s", __FILE__, __LINE__, "Начинаем размещение новости №", QString::number(counter).toStdString().c_str());
  104. QStringList item = news.split("|");
  105. QLabel* image = ui->newsbox->findChild<QLabel*>("news" + QString::number(counter) + "Image");
  106. QLabel* title = ui->newsbox->findChild<QLabel*>("news" + QString::number(counter) + "Title");
  107. QLabel* teaser = ui->newsbox->findChild<QLabel*>("news" + QString::number(counter) + "Teaser");
  108. qInfo("%s:%i: %s", __FILE__, __LINE__, "Устанавливаем миниатюру новости");
  109. QByteArray bytes = ANetwork::getInstance()->query_binary(item[0]);
  110. QImage img(36, 36, QImage::Format_Indexed8);
  111. img.loadFromData(bytes);
  112. QString skin = Skin::getInstance()->getSkinName();
  113. if(img.bits() == nullptr){
  114. qInfo("%s:%i: %s", __FILE__, __LINE__, "Миниатюра не найдена, устанавливаем заглушку");
  115. img.load(":/res/styles/" + skin + "/nophoto.jpg");
  116. }
  117. image->setPixmap(QPixmap::fromImage(img));
  118. qInfo("%s:%i: %s", __FILE__, __LINE__, "Применяем HTML-цвета");
  119. QString hrefcolor = htmlColors.contains("a") ? htmlColors.lowerBound("a").value() : "blue";
  120. QString html = "<a href=\"" + item[3] +"\" style=\"color:" + hrefcolor + "; text-decoration:none;\">" + item[1] + "</a>";
  121. qInfo("%s:%i: %s", __FILE__, __LINE__, "Размещаем тексты");
  122. title->setText(html);
  123. teaser->setText(item[2]);
  124. counter = counter + 1;
  125. }
  126. qInfo("%s:%i: %s", __FILE__, __LINE__, "Выполнено.");
  127. }
  128. void MainWindow::loadHelp(){
  129. qInfo("Создание справки");
  130. QFile file(QApplication::applicationDirPath() + "/readme.html");
  131. if(file.open(QFile::ReadOnly | QFile::Text)){
  132. qInfo("%s:%i: %s", __FILE__, __LINE__, "Справка загружена. Устанавливаем HTML-цвета и выводим.");
  133. ui->textBrowser->setHtml("");
  134. QString content = file.readAll();
  135. stylehtml = "<style>";
  136. for(auto e : htmlColors.keys()){
  137. stylehtml = stylehtml + e + "{color:" + htmlColors.value(e) + ";}";
  138. }
  139. QFile styleF;
  140. QString skin = Skin::getInstance()->getSkinName();
  141. styleF.setFileName(QApplication::applicationDirPath() + "styles/" + skin + "/readme.css");
  142. if(styleF.open(QFile::ReadOnly)){
  143. stylehtml = "<html><head><style type=\"text/css\">" + stylehtml + styleF.readAll();
  144. }
  145. stylehtml = stylehtml + "</style></head>";
  146. ui->textBrowser->setHtml(stylehtml + content);
  147. ui->textBrowser->document()->setDefaultStyleSheet(styleF.readAll());
  148. qInfo("%s:%i: %s", __FILE__, __LINE__, "Выполнено.");
  149. } else {
  150. qWarning("%s:%i: %s", __FILE__, __LINE__, "Не удалось получить информацию с сервера");
  151. qInfo("%s:%i: %s", __FILE__, __LINE__, "Выполнено.");
  152. }
  153. }
  154. MainWindow::~MainWindow() {
  155. delete ui;
  156. }
  157. void MainWindow::applyShadow(QWidget * obj, QString color, int blur, int offset_x, int offset_y){
  158. QGraphicsDropShadowEffect *pLabelTextShadowEffect = new QGraphicsDropShadowEffect(obj);
  159. pLabelTextShadowEffect->setColor(QColor(color));
  160. pLabelTextShadowEffect->setBlurRadius(blur);
  161. pLabelTextShadowEffect->setOffset(offset_x, offset_y);
  162. obj->setGraphicsEffect(pLabelTextShadowEffect);
  163. }
  164. void MainWindow::closeEvent(QCloseEvent *e) {
  165. if (state == "busy") e->ignore();
  166. }
  167. void MainWindow::mouseMoveEvent( QMouseEvent* e ) {
  168. if( e->buttons() | Qt::LeftButton ) {
  169. QPoint pt=mapFromGlobal(QCursor::pos());
  170. QWidget* child=childAt(pt);
  171. if (child == 0) {
  172. setGeometry(pos().x() + ( e->x() - dx ), pos().y() + ( e->y() - dy ), width(), height());
  173. return;
  174. }
  175. QString cname = child->metaObject()->className();
  176. if (cname != "QPushButton" && cname != "QComboBox"){ // отключаем перетягивание при наведение на активные элементы
  177. setGeometry(pos().x() + ( e->x() - dx ), pos().y() + ( e->y() - dy ), width(), height());
  178. } else {
  179. dx = e->x();
  180. dy = e->y();
  181. }
  182. }
  183. }
  184. void MainWindow::mousePressEvent( QMouseEvent* e ) {
  185. if( e->button() == Qt::LeftButton ) {
  186. dx = e->x();
  187. dy = e->y();
  188. setCursor( Qt::OpenHandCursor );
  189. }
  190. }
  191. void MainWindow::mouseReleaseEvent( QMouseEvent* e ) {
  192. if( e->button() == Qt::LeftButton ) {
  193. setCursor( Qt::ArrowCursor );
  194. dx = e->x();
  195. dy = e->y();
  196. }
  197. }
  198. void MainWindow::minimize() {
  199. setWindowState(Qt::WindowMinimized);
  200. }
  201. bool MainWindow::eventFilter(QObject *obj, QEvent *event){
  202. if(state == "busy") return false;
  203. if(obj->objectName() == "mainButton"){
  204. this->ui->hintLabel->setText("Применение патчей");
  205. this->ui->exthintLabel->setText("На данной странице показан список патчей и прогресс их применения");
  206. }
  207. if(obj->objectName() == "optButton"){
  208. this->ui->hintLabel->setText("Настройки лаунчера");
  209. this->ui->exthintLabel->setText("Управление параметрами применения патчей и запуском игры");
  210. }
  211. if(obj->objectName() == "newsButton"){
  212. this->ui->hintLabel->setText("Новости проекта");
  213. this->ui->exthintLabel->setText("Актуальная информация из нашего цеха русификации LotRO");
  214. }
  215. if(obj->objectName() == "helpButton"){
  216. this->ui->hintLabel->setText("Справочная информация");
  217. this->ui->exthintLabel->setText("Полезная информация о программе русификации, настройках и использовании");
  218. }
  219. if(obj->objectName() == "aboutButton"){
  220. this->ui->hintLabel->setText("О нас");
  221. this->ui->exthintLabel->setText("Информация о разработчиках, переводчиках и других хороших людях");
  222. }
  223. if(obj->objectName() == "enterButton"){
  224. this->ui->hintLabel->setText("Запуск игры");
  225. this->ui->exthintLabel->setText("Создание портала в мир Средиземья");
  226. }
  227. if(obj->objectName() == "couponButton"){
  228. this->ui->hintLabel->setText("Купон скидки");
  229. this->ui->exthintLabel->setText("Нажмите, чтобы скопировать код купона в буфер обмена");
  230. }
  231. return false;
  232. }
  233. void MainWindow::on_mainButton_clicked(){
  234. checkTab("mainbox");
  235. ui->titleLabel->setText("Патчи");
  236. if(state != "busy") ANetwork::getInstance()->getPatches();
  237. }
  238. void MainWindow::on_optButton_clicked(){
  239. checkTab("optbox");
  240. ui->titleLabel->setText("Настройки");
  241. }
  242. void MainWindow::on_newsButton_clicked(){
  243. checkTab("newsbox");
  244. ui->titleLabel->setText("Новости");
  245. }
  246. void MainWindow::on_helpButton_clicked(){
  247. checkTab("helpbox");
  248. ui->titleLabel->setText("Справка");
  249. }
  250. void MainWindow::on_aboutButton_clicked(){
  251. checkTab("aboutbox");
  252. ui->titleLabel->setText("О нас");
  253. }
  254. void MainWindow::on_enterButton_clicked(){
  255. ui->startbox->setGeometry(0, 0, width(), height());
  256. QSettings settings(Skin::getInstance()->getSkinFile(), QSettings::IniFormat);
  257. settings.beginGroup("mainWindow");
  258. int left = (settings.value("width").toInt() - ui->startframe->width())/2;
  259. int top = (settings.value("height").toInt() - ui->startframe->height())/2;
  260. ui->startframe->setGeometry(QRect(left, top, ui->startframe->width(), ui->startframe->height()));
  261. settings.endGroup();
  262. QString file = AConfig::getInstance()->getValue("Local", "file");
  263. if (file == "client_local_English.dat") file = "goenr.png";
  264. if (file == "client_local_DE.dat") file = "goderr.png";
  265. if (file == "client_local_FR.dat") file = "gofrr.png";
  266. QString skin = Skin::getInstance()->getSkinName();
  267. QString bname = ":/res/styles/" + skin + "/" + file;
  268. QPixmap isset(bname);
  269. bname = isset.isNull() ? app_folder + "styles/" + skin + "/" + file : bname;
  270. ui->goOriginal->setStyleSheet("QPushButton#goOriginal { border-image: url(" + bname + ") 0 0 0 0 stretch stretch;}");
  271. ui->startbox->show();
  272. }
  273. void MainWindow::on_goCancel_clicked(){
  274. ui->startbox->hide();
  275. }
  276. void MainWindow::on_goOriginal_clicked(){
  277. ui->goProgress->show();
  278. GameRes::getInstance()->setGameLocale("Original");
  279. //connect(GameRes::getInstance(), SIGNAL(GameRes::getInstance()->setGameLocaleFinished()), GameRes::getInstance(), SLOT(GameRes::getInstance()->startGame()));
  280. }
  281. void MainWindow::on_goLocal_clicked(){
  282. ui->goProgress->show();
  283. GameRes::getInstance()->setGameLocale("RU");
  284. //connect(GameRes::getInstance(), SIGNAL(GameRes::getInstance()->setGameLocaleFinished()), GameRes::getInstance(), SLOT(GameRes::getInstance()->startGame()));
  285. }
  286. void MainWindow::on_minimizeButton_clicked(){
  287. setWindowState(Qt::WindowMinimized);
  288. }
  289. void MainWindow::on_closeButton_clicked(){
  290. this->close();
  291. }
  292. void MainWindow::on_couponButton_clicked(){
  293. QApplication::clipboard()->setText(ui->couponButton->text());
  294. ui->exthintLabel->setText("Код скопирован.");
  295. }
  296. void MainWindow::on_enButton_clicked(){
  297. saveLocale(0, ui->enButton);
  298. AConfig::getInstance()->setValue("Local", "lang", "en");
  299. }
  300. void MainWindow::on_deButton_clicked(){
  301. saveLocale(1, this->ui->deButton);
  302. AConfig::getInstance()->setValue("Local", "lang", "de");
  303. }
  304. void MainWindow::on_frButton_clicked(){
  305. saveLocale(2, this->ui->frButton);
  306. AConfig::getInstance()->setValue("Local", "lang", "fr");
  307. }
  308. void MainWindow::saveSkin(){
  309. QString new_theme = ui->skinSelect->currentText();
  310. if(Skin::getInstance()->getSkinName() != new_theme){
  311. AConfig::getInstance()->setValue("Global", "current_theme", new_theme);
  312. Skin::getInstance()->replaceSkin(new_theme);
  313. }
  314. }
  315. void MainWindow::on_checkFonts_stateChanged(int arg1){
  316. AConfig::getInstance()->setValue("Editor", "fonts", arg1 ? "true" : "false");
  317. }
  318. void MainWindow::on_checkTexts_stateChanged(int arg1){
  319. AConfig::getInstance()->setValue("Editor", "texts", arg1 ? "true" : "false");;
  320. DownloadManager::getInstance()->abortDownload("texts");
  321. }
  322. void MainWindow::on_checkSounds_stateChanged(int arg1){
  323. AConfig::getInstance()->setValue("Editor", "sounds", arg1 ? "true" : "false");
  324. DownloadManager::getInstance()->abortDownload("sounds");
  325. }
  326. void MainWindow::on_checkMaps_stateChanged(int arg1){
  327. AConfig::getInstance()->setValue("Editor", "images", arg1 ? "true" : "false");
  328. DownloadManager::getInstance()->abortDownload("images");
  329. }
  330. void MainWindow::on_checkScreens_stateChanged(int arg1){
  331. AConfig::getInstance()->setValue("Editor", "screens", arg1 ? "true" : "false");
  332. DownloadManager::getInstance()->abortDownload("screens");
  333. }
  334. void MainWindow::on_checkVideos_stateChanged(int arg1){
  335. AConfig::getInstance()->setValue("Editor", "videos", arg1 ? "true" : "false");
  336. DownloadManager::getInstance()->abortDownload("videos");
  337. }
  338. void MainWindow::on_checkMicro_stateChanged(int arg1){
  339. AConfig::getInstance()->setValue("Updates", "micro", arg1 ? "true" : "false");
  340. }
  341. void MainWindow::on_lotropathButton_clicked(){
  342. QString path = QFileDialog::getExistingDirectory(0, "Выберите папку с игрой");
  343. if(path != "" && FileSystem::fileExists(path + "/TurbineLauncher.exe")) {
  344. ui->lotropathLabel->setText(path);
  345. AConfig::getInstance()->setValue("Local", "folder", path);
  346. } else {
  347. QString text = "Выбрана неверная папка";
  348. QString info = "<p>Убедитесь, что выбранный вами каталог является папкой игры и содержит такие файлы как TurbineLauncher.exe и client_local_English.dat.</p>";
  349. myDialogBox(text, info, "OK", "Отмена", "gandalf.png", "", "", 400, 160, true, false);
  350. }
  351. }
  352. void MainWindow::on_designButton_clicked(){
  353. Skin::getInstance()->replaceSkin(Skin::getInstance()->getSkinName());
  354. }
  355. void MainWindow::on_repairButton_clicked(){
  356. AConfig::getInstance()->deleteSection("Applied");
  357. GameRes::getInstance()->applyAll();
  358. checkTab("mainbox");
  359. }
  360. void MainWindow::on_okButton_clicked(){
  361. //QStringList commands = app->helper->dialog_ok_answer.split(" ");
  362. // foreach(QString command, commands){
  363. // if(command == "close"){
  364. // ui->dialogbox->hide();
  365. // }
  366. // if(command == "gamefind"){
  367. // QStringList folders = app->config->getLotroPath();
  368. // if(folders.count() > 1){
  369. // QString text = "Результаты поиска";
  370. // QString info = "Найдены следующие папки в которых установлена игра:<br/><br/><br/><br/><br/>Выберите нужную папку и нажмите «Далее»<br/>";
  371. // app->helper->myDialogBox(text, info, "Далее", "Отмена", "gandalf.png", "writefolder", "", 530, 200, true, false);
  372. // ui->dialogList->setGeometry(QRect(
  373. // ui->dialogImage->rect().right() + 10,
  374. // ui->dialogHeader->rect().bottom()+40, 417, 50));
  375. // foreach(QString f, folders) new QListWidgetItem(f, ui->dialogList);
  376. // ui->dialogList->show();
  377. // } else {
  378. // if(folders.count() == 1){
  379. // ui->lotropathLabel->setText(folders.first());
  380. // app->config->setValue("Local", "folder", folders.first());
  381. // this->ui->dialogbox->hide();
  382. // QString text = "Завершающий этап";
  383. // QString info = "Необходимые приготовления завершены. Сейчас вы будете перенаправлены в раздел «Настройки», где сможете выбрать патчи, которые хотите установить. После этого перейдите в раздел «Патчи» для начала их загрузки и применения.";
  384. // app->helper->myDialogBox(text, info, "OK", "Отмена", "gandalf.png", "close gotooptions", "",400, 200, true, false);
  385. // } else {
  386. // QString text = "Завершающий этап";
  387. // QString info = "Обнаружить каталог игры автоматически не удалось. Сейчас вы будете перенаправлены в раздел «Настройки», где сможете вручную выбрать каталог игры и патчи, которые хотите установить. После этого перейдите в раздел «Патчи» для начала их загрузки и применения.";
  388. // app->helper->myDialogBox(text, info, "OK", "Отмена", "gandalf.png", "close gotooptions", "",450, 200, true, false);
  389. // }
  390. // }
  391. // qDebug() << folders;
  392. // }
  393. // if(command == "writefolder"){
  394. // if(ui->dialogList->currentItem()){
  395. // QString path = ui->dialogList->currentItem()->text();qDebug() << path;
  396. // ui->lotropathLabel->setText(path);
  397. // app->config->setValue("Local", "folder", path);
  398. // ui->dialogList->clear();
  399. // ui->dialogList->hide();
  400. // this->ui->dialogbox->hide();
  401. // QString text = "Завершающий этап";
  402. // QString info = "Необходимые приготовления завершены. Сейчас вы будете перенаправлены в раздел «Настройки», где сможете выбрать патчи, которые хотите установить. После этого перейдите в раздел «Патчи» для начала их загрузки и применения.";
  403. // app->helper->myDialogBox(text, info, "OK", "Отмена", "gandalf.png", "close gotooptions", "",400, 200, true, false);
  404. // } else {
  405. // break;
  406. // }
  407. // }
  408. // if(command == "gotooptions"){
  409. // app->helper->checkTab("optbox");
  410. // app->config->setValue("Local", "runfirst", "1");
  411. // app->helper->setState("free");
  412. // }
  413. // if(command == "applypaths"){
  414. // app->ready = true;
  415. // app->config->deleteSection("Applied");
  416. // app->network->getPaths();
  417. // app->helper->checkTab("mainbox");
  418. // }
  419. // if(command == "loaddatfile"){
  420. // app->config->deleteSection("Applied");
  421. // QString filename = app->config->getDatPath(0);
  422. // qInfo("%s:%i: %s%s", __FILE__, __LINE__, "Удаляем файл: ", app->helper->stringToChar(filename));
  423. // app->helper->closeDatFile(0);
  424. // if(QFile::remove(filename)){
  425. // app->helper->startGame();
  426. // qApp->exit();
  427. // }
  428. // }
  429. // }
  430. }
  431. void MainWindow::on_cancelButton_clicked(){
  432. // QStringList commands = app->helper->dialog_cancel_answer.split(" ");
  433. // foreach(QString command, commands){
  434. // if(command == "close") this->ui->dialogbox->hide();
  435. // }
  436. }
  437. void MainWindow::checkTab(QString tabname){
  438. QList<QGroupBox *> boxes = findChildren<QGroupBox *> ();
  439. foreach (QGroupBox * box, boxes){
  440. if(box->parent()->objectName() == "centralWidget"){
  441. QLabel* boximage = findChild<QLabel*>(box->objectName() + "Image");
  442. if(box->objectName() == tabname){
  443. box->show();
  444. if(boximage != nullptr) boximage->show();
  445. } else {
  446. box->hide();
  447. if(boximage != nullptr) boximage->hide();
  448. }
  449. }
  450. }
  451. ui->serversbox->show();
  452. }
  453. void MainWindow::myDialogBox(QString text, QString info, QString okText, QString cancelText, QString image, QString okAnswer, QString cancelAnswer,
  454. int w, int h, bool textshadow = false, bool is_cancel = false){
  455. if(okAnswer == "") okAnswer = "close";
  456. //app->helper->dialog_ok_answer = okAnswer;
  457. if(cancelAnswer == "") cancelAnswer = "close";
  458. //app->helper->dialog_cancel_answer = cancelAnswer;
  459. ui->okButton->setText(okText);
  460. ui->cancelButton->setText(cancelText);
  461. ui->dialogbox->setGeometry(0, 0, width(), height());
  462. QSettings settings(Skin::getInstance()->getSkinFile(), QSettings::IniFormat );
  463. settings.beginGroup("mainWindow");
  464. int left = (settings.value("width").toInt() - w)/2;
  465. int top = (settings.value("height").toInt() - h)/2;
  466. ui->dialog->setGeometry(QRect(left, top, w, h));
  467. settings.endGroup();
  468. int image_height = ui->dialog->rect().height() - ui->dialogHeader->rect().height();
  469. ui->dialogImage->setGeometry(0,
  470. ui->dialogHeader->rect().bottom(),
  471. image_height/2 ,image_height
  472. );
  473. QString skin = Skin::getInstance()->getSkinName();
  474. QString iconpath = "";
  475. iconpath = FileSystem::fileExists("styles/" + skin + "/" + image) ? "styles/" + skin + "/" + image : ":/res/styles/" + skin + "/" + image;
  476. QPixmap icon(iconpath);
  477. ui->dialogImage->setPixmap(icon.scaled(ui->dialogImage->width(), ui->dialogImage->height()));
  478. if(icon.isNull()){
  479. ui->dialogImage->setGeometry(QRect(10, 10, 10, 10));
  480. }
  481. ui->dialogHeader->setGeometry(
  482. ui->dialogHeader->rect().left(),
  483. ui->dialogHeader->rect().top(),
  484. ui->dialog->rect().width(),
  485. ui->dialogHeader->rect().height()
  486. );
  487. ui->dialogInfo->setGeometry(ui->dialogImage->rect().right(),
  488. ui->dialogHeader->rect().bottom(),
  489. ui->dialog->rect().width() - ui->dialogImage->rect().width()-7,
  490. image_height - ui->cancelButton->height()
  491. );
  492. if(is_cancel){
  493. ui->cancelButton->setGeometry(
  494. ui->dialog->rect().left() + ui->dialog->width() - ui->cancelButton->width() - 20,
  495. ui->dialog->rect().bottom() - ui->cancelButton->height() - 10,
  496. ui->cancelButton->width(),
  497. ui->cancelButton->height()
  498. );
  499. ui->okButton->setGeometry(
  500. ui->dialog->rect().left() + ui->dialog->width() - ui->cancelButton->width() - ui->cancelButton->width() - 40,
  501. ui->dialog->rect().bottom() - ui->cancelButton->height() - 10,
  502. ui->cancelButton->width(),
  503. ui->cancelButton->height()
  504. );
  505. } else {
  506. ui->cancelButton->setGeometry(-1000,-1000, ui->cancelButton->width(), ui->cancelButton->height());
  507. ui->okButton->setGeometry(
  508. ui->dialog->rect().left() + ui->dialog->width() - ui->cancelButton->width() - 20,
  509. ui->dialog->rect().bottom() - ui->cancelButton->height() - 10,
  510. ui->cancelButton->width(),
  511. ui->cancelButton->height()
  512. );
  513. }
  514. ui->dialogHeader->setText(text);
  515. ui->dialogInfo->setText(info);
  516. ui->dialogImage->setText("");
  517. ui->dialogbox->show();
  518. }
  519. void MainWindow::setAbout(){
  520. qInfo("%s:%i: %s", __FILE__, __LINE__, "Размещаем информацию о хороших людях.");
  521. ui->programmerslist->setText("Gi1dor, coder");
  522. ui->designerslist->setText("Чирик, valyot, Quilanar, Eodoro");
  523. ui->translatorslist->setText("Arissa, unnamedartist, valyot, Чирик, Eodoro, Ferdik, Tukbard, Alcassar, Satenskyhou, Quilanar, Коралан, Invizet, taiki_exe, Rhymer, Takhizis, Lauraldo, seventhgate027, Kerita, Хилко, Leodgar, Juolukka, Auruman, Drazgar, Tondred, Foldoren, Exildil, Anormir, Василий Волков, Andoriel, Felicer, noldohini, Gi1dor, Progylkin, Arkwendir, Bara Norkins, Siltier, Maxsikr, Nahkrin, Nick_os, Razverg, ENDrain, ToX4SHOW, Jeyolin, Frenni, Коралан, Palmuch, Marty");
  524. ui->helperslist->setText("Menelhad, Мурзилка, Pastor, Alvees, Mirta, иван петров, vensys, Arkelas, Чеширская Улыбка, Shanishka70 ");
  525. }