diff --git a/Butcher_Circus_Randomizer.pro b/Butcher_Circus_Randomizer.pro index dac310f..48e16b9 100644 --- a/Butcher_Circus_Randomizer.pro +++ b/Butcher_Circus_Randomizer.pro @@ -9,17 +9,19 @@ CONFIG += c++17 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ - description.cpp \ + filemanip.cpp \ + heroselection.cpp \ main.cpp \ mainwindow.cpp HEADERS += \ Random.h \ - description.h \ + filemanip.h \ + heroselection.h \ mainwindow.h FORMS += \ - description.ui \ + heroselection.ui \ mainwindow.ui TRANSLATIONS += \ diff --git a/Butcher_Circus_Randomizer.pro.user b/Butcher_Circus_Randomizer.pro.user index b29e631..a6d5a77 100644 --- a/Butcher_Circus_Randomizer.pro.user +++ b/Butcher_Circus_Randomizer.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {2430ef67-c089-495b-a5d8-5aeaa48b8b8b} + {de97db6a-fc80-4a40-9dac-34782ce41e16} ProjectExplorer.Project.ActiveTarget @@ -54,6 +54,7 @@ *.md, *.MD, Makefile false true + true @@ -70,9 +71,6 @@ 0 true - - true - Builtin.BuildSystem true true @@ -89,16 +87,16 @@ ProjectExplorer.Project.Target.0 Desktop - Desktop Qt 6.3.0 GCC 64bit - Desktop Qt 6.3.0 GCC 64bit - qt.qt6.630.gcc_64_kit + Desktop Qt 6.4.0 GCC 64bit + Desktop Qt 6.4.0 GCC 64bit + qt.qt6.640.gcc_64_kit 1 0 0 0 - /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Debug - /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Debug + /home/raik199x/qtProjects/Butcher-circus-randomizer/../build-Butcher_Circus_Randomizer-Desktop_Qt_6_4_0_GCC_64bit-Debug + /home/raik199x/qtProjects/build-Butcher_Circus_Randomizer-Desktop_Qt_6_4_0_GCC_64bit-Debug true @@ -136,8 +134,8 @@ 2 - /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Release - /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Release + /home/raik199x/qtProjects/Butcher-circus-randomizer/../build-Butcher_Circus_Randomizer-Desktop_Qt_6_4_0_GCC_64bit-Release + /home/raik199x/qtProjects/build-Butcher_Circus_Randomizer-Desktop_Qt_6_4_0_GCC_64bit-Release true @@ -177,8 +175,8 @@ 0 - /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Profile - /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Profile + /home/raik199x/qtProjects/Butcher-circus-randomizer/../build-Butcher_Circus_Randomizer-Desktop_Qt_6_4_0_GCC_64bit-Profile + /home/raik199x/qtProjects/build-Butcher_Circus_Randomizer-Desktop_Qt_6_4_0_GCC_64bit-Profile true @@ -238,185 +236,21 @@ 2 - Qt4ProjectManager.Qt4RunConfiguration:/home/alexander/Desktop/Butcher-circus-randomizer/Butcher_Circus_Randomizer.pro - /home/alexander/Desktop/Butcher-circus-randomizer/Butcher_Circus_Randomizer.pro - false - true - true - false - true - /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Release - - 1 - - - - ProjectExplorer.Project.Target.1 - - Desktop - Replacement for "Desktop Qt 5.15.2 GCC 64bit" - Replacement for "Desktop Qt 5.15.2 GCC 64bit" - qt.qt5.5152.gcc_64_kit - 1 - 0 - 0 - - 0 - /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_5_15_2_GCC_64bit-Debug - /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_5_15_2_GCC_64bit-Debug - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_5_15_2_GCC_64bit-Release - /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_5_15_2_GCC_64bit-Release - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_5_15_2_GCC_64bit-Profile - /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_5_15_2_GCC_64bit-Profile - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:/home/alexander/Desktop/Butcher-circus-randomizer/Butcher_Circus_Randomizer.pro - /home/alexander/Desktop/Butcher-circus-randomizer/Butcher_Circus_Randomizer.pro + Qt4ProjectManager.Qt4RunConfiguration:/home/raik199x/qtProjects/Butcher-circus-randomizer/Butcher_Circus_Randomizer.pro + /home/raik199x/qtProjects/Butcher-circus-randomizer/Butcher_Circus_Randomizer.pro false true true false true + /home/raik199x/qtProjects/build-Butcher_Circus_Randomizer-Desktop_Qt_6_4_0_GCC_64bit-Release 1 ProjectExplorer.Project.TargetCount - 2 + 1 ProjectExplorer.Project.Updater.FileVersion diff --git a/Butcher_Circus_Randomizer.pro.user.2430ef6 b/Butcher_Circus_Randomizer.pro.user.2430ef6 new file mode 100644 index 0000000..b29e631 --- /dev/null +++ b/Butcher_Circus_Randomizer.pro.user.2430ef6 @@ -0,0 +1,429 @@ + + + + + + EnvironmentId + {2430ef67-c089-495b-a5d8-5aeaa48b8b8b} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + true + Builtin.BuildSystem + + true + true + Builtin.DefaultTidyAndClazy + 6 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.3.0 GCC 64bit + Desktop Qt 6.3.0 GCC 64bit + qt.qt6.630.gcc_64_kit + 1 + 0 + 0 + + 0 + /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Debug + /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Release + /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Profile + /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:/home/alexander/Desktop/Butcher-circus-randomizer/Butcher_Circus_Randomizer.pro + /home/alexander/Desktop/Butcher-circus-randomizer/Butcher_Circus_Randomizer.pro + false + true + true + false + true + /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_6_3_0_GCC_64bit-Release + + 1 + + + + ProjectExplorer.Project.Target.1 + + Desktop + Replacement for "Desktop Qt 5.15.2 GCC 64bit" + Replacement for "Desktop Qt 5.15.2 GCC 64bit" + qt.qt5.5152.gcc_64_kit + 1 + 0 + 0 + + 0 + /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_5_15_2_GCC_64bit-Debug + /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_5_15_2_GCC_64bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_5_15_2_GCC_64bit-Release + /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_5_15_2_GCC_64bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_5_15_2_GCC_64bit-Profile + /home/alexander/Desktop/build-Butcher_Circus_Randomizer-Desktop_Qt_5_15_2_GCC_64bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:/home/alexander/Desktop/Butcher-circus-randomizer/Butcher_Circus_Randomizer.pro + /home/alexander/Desktop/Butcher-circus-randomizer/Butcher_Circus_Randomizer.pro + false + true + true + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 2 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/description.cpp b/description.cpp deleted file mode 100644 index ede64d1..0000000 --- a/description.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "description.h" -#include "ui_description.h" - -Description::Description(QWidget *parent) : - QDialog(parent), - ui(new Ui::Description) -{ - ui->setupUi(this); -} - -Description::~Description() -{ - delete ui; -} - -void Description::on_buttonClose_clicked() -{ - close(); -} - diff --git a/description.h b/description.h deleted file mode 100644 index ab9e692..0000000 --- a/description.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef DESCRIPTION_H -#define DESCRIPTION_H - -#include - -namespace Ui { -class Description; -} - -class Description : public QDialog -{ - Q_OBJECT - -public: - explicit Description(QWidget *parent = nullptr); - ~Description(); - -private slots: - void on_buttonClose_clicked(); - -private: - Ui::Description *ui; -}; - -#endif // DESCRIPTION_H diff --git a/description.ui b/description.ui deleted file mode 100644 index 5c926a5..0000000 --- a/description.ui +++ /dev/null @@ -1,68 +0,0 @@ - - - Description - - - - 0 - 0 - 419 - 509 - - - - Dialog - - - - - 20 - 40 - 61 - 61 - - - - - - - - - - 10 - 120 - 41 - 16 - - - - Name - - - - - - 140 - 40 - 256 - 401 - - - - - - - 170 - 470 - 80 - 22 - - - - OK - - - - - - diff --git a/filemanip.cpp b/filemanip.cpp new file mode 100644 index 0000000..0e4859d --- /dev/null +++ b/filemanip.cpp @@ -0,0 +1,56 @@ +#include "filemanip.h" + +bool recreate(std::string fileName, std::string *fighters){ + std::ofstream file(fileName); + if(!file) + return true; + for(int i = 0; i < 18; i++){ + std::string line = fighters[i] + ":" + std::string(8,'1') + '\n'; + file << line; + } + file.close(); + return false; +} + +int changeLine(std::string fileName, std::string heroName, int what, int AccessableHeroes){ + int returnCode; + if(heroName == "abomination" && what != 0) + return -4; + std::fstream file(fileName); + if(!file) + return -1; + + while(1){ + std::string line; + file >> line; + if(file.eof()) + return false; + if(line.find(heroName) != std::string::npos){ + file.seekp(-line.size(), std::ios::cur); // moving back in file + // finding pos of first + size_t posStart = 0; + while(line[posStart] != ':') + posStart++; + posStart++; + if(what == 0 && AccessableHeroes == 4 && line[posStart+what] == '1') + return -2; + else if(what == 0 && line[posStart+what] == '1') + returnCode = 0; + else if(what == 0 && line[posStart+what] == '0') + returnCode = 1; + else + returnCode = 3; + int checkSpells = 0; + for(unsigned int i = posStart+1; i < line.length(); i++) + if(line[i] == '1') checkSpells++; + if(checkSpells == 4 && line[posStart+what] == '1' && what != 0) + return -3; + line[posStart+what] == '0' ? line[posStart+what] = '1' : line[posStart+what] = '0'; + line += '\n'; + file << line; + break; + } + } + + return returnCode; +} diff --git a/filemanip.h b/filemanip.h new file mode 100644 index 0000000..d69d53d --- /dev/null +++ b/filemanip.h @@ -0,0 +1,9 @@ +#ifndef FILEMANIP_H +#define FILEMANIP_H +#include +#include + +bool recreate(std::string fileName, std::string *fighters); // recreates file with default settings +int changeLine(std::string fileName, std::string heroName, int what, int AccesableHeroes); // forbids/allows randoming hero/spell + +#endif // FILEMANIP_H diff --git a/filemanip_windows.cpp b/filemanip_windows.cpp new file mode 100644 index 0000000..5418884 --- /dev/null +++ b/filemanip_windows.cpp @@ -0,0 +1,55 @@ +#include "filemanip.h" + +bool recreate(std::string fileName, std::string *fighters){ + std::ofstream file(fileName); + if(!file) + return true; + for(int i = 0; i < 18; i++){ + std::string line = fighters[i] + ":" + std::string(8,'1') + '\n'; + file << line; + } + file.close(); + return false; +} + +int changeLine(std::string fileName, std::string heroName, int what, int AccessableHeroes){ + int returnCode; + if(heroName == "abomination" && what != 0) + return -4; + std::fstream file(fileName); + if(!file) + return -1; + + std::string content[18]; unsigned int i = 0, pos; + // obtaining list of heroes + while(i < 18){ + getline(file,content[i++]); + if(content[i-1].find(heroName) != std::string::npos) + pos = i - 1; + } + unsigned int separator_pos = content[pos].find(":")+1; // needs for future + if(what == 0 && AccessableHeroes == 4 && content[pos][separator_pos+what] == '1') // need to be at least 4 heroes + return -2; + else if(what == 0 && content[pos][separator_pos+what] == '1') // setted 0 (need to lower counter) + returnCode = 0; + else if(what == 0 && content[pos][separator_pos+what] == '0') // setted 1 (need to up counter) + returnCode = 1; + else + returnCode = 3; // spell changed (but still need to check) + + // changing number + checking + unsigned int checkSpells = 0; + for(i = separator_pos; i < content[pos].length(); i++) + if(content[pos][i] == '1') checkSpells++; + if(checkSpells == 4 && content[pos][separator_pos+what] == '1' && what != 0) + return -3; + content[pos][separator_pos+what] == '0' ? content[pos][separator_pos+what] = '1' : content[pos][separator_pos+what] = '0'; + + // writting changes to a file + file.close(); + file.open(fileName); + for(i = 0; i < 18; i++) + file << content[i] << "\n"; + file.close(); + return returnCode; +} diff --git a/heroselection.cpp b/heroselection.cpp new file mode 100644 index 0000000..a6df5a5 --- /dev/null +++ b/heroselection.cpp @@ -0,0 +1,128 @@ +#include "heroselection.h" +#include "qboxlayout.h" +#include "ui_heroselection.h" +#include "filemanip.h" +#include +#include + +HeroSelection::HeroSelection(QWidget *parent, std::string *fighters, int numTeam) : + QDialog(parent), + ui(new Ui::HeroSelection) +{ + ui->setupUi(this); + + this->setFixedSize(1065,342); + this->setWindowTitle("Random settings"); + this->setStyleSheet("background-color: #323232"); + + for(int i = 0; i < 18; i++) + this->fighters[i] = fighters[i]; + + numTeam == 0 ? this->fileName = "BCR_T1.txt" : this->fileName = "BCR_T2.txt"; + // we should analyze how many heros accesable for random + if(!std::filesystem::exists(this->fileName)){ + if(!recreate(this->fileName, fighters)) // if file does not exist and cannot be created + std::terminate(); + this->AccessableHeroes = 18; + } else{ // checking how many heroes enabled + this->AccessableHeroes = 0; + std::ifstream file(this->fileName); + if(!file){ + QMessageBox::critical(this, "Cannot open file", "For some reason BCR cannot open file BCR_T(1,2)"); + std::terminate(); + } + for(int i = 0; i < 18; i++){ + std::string line; + file >> line; + if(line[line.find(":")+1] == '1') + this->AccessableHeroes++; + int spellsAvailable = 0; // also checking that hero can random 4 spells + for(unsigned int j = line.find(":")+2; j < line.size(); j++) + if(line[j] == '1') spellsAvailable++; + if(spellsAvailable < 4){ + this->AccessableHeroes = 18; + QMessageBox::warning(this, "Random settings analyze", "One of heroes had less than 4 skills for randoming, file will be recreated"); + recreate(this->fileName,this->fighters); + break; + } + } + if(this->AccessableHeroes < 4){ + QMessageBox::warning(this, "Random settings analyze", "Less than 4 heroes where set for randoming, file will be recreated"); + recreate(this->fileName,this->fighters); + this->AccessableHeroes = 18; + } + } + + this->buttons = new QPushButton**[18]; + for(int i = 0; i < 18; i++) + this->buttons[i] = new QPushButton*[8]; + + // initialazing + QWidget *wgtMain = new QWidget(); + QVBoxLayout *vboxMain = new QVBoxLayout(wgtMain); + for(int i = 0; i < 18;i++){ + QWidget *wgtSub = new QWidget(); + QHBoxLayout *hboxSub = new QHBoxLayout(wgtSub); + for(int j = 0; j < 8;j++){ + this->buttons[i][j] = new QPushButton(); + buttons[i][j]->setFixedSize(QSize(75,80)); + hboxSub->addWidget(buttons[i][j]); + connect(this->buttons[i][j], SIGNAL(clicked()),this,SLOT(ButtonClicked())); + } + vboxMain->addWidget(wgtSub); + } + // updating ui + for(int i = 0; i < 18; i++) + updateUiLine(i+1); + this->ui->heroes->setWidget(wgtMain); +} + +bool HeroSelection::updateUiLine(int line){ + std::ifstream file(this->fileName); + if(!file) + return false; + // getting statistic line + std::string lines; + for(int i = 0; i < line; i++) + getline(file,lines); + file.close(); + + // analyzing and changing + size_t pos = lines.find(":"); pos++; + std::string color; + lines[pos] == '0' ? color = "Red;" : color = "Green;"; + std::string style = "background-color: " + color + " background-image: url(:/heroes/heroes+spells/" + this->fighters[line-1] + "/hero_"+ this->fighters[line-1] +")"; // changing hero frame + buttons[line-1][0]->setStyleSheet(QString::fromStdString(style)); + pos++; + for(unsigned int i = pos; i < pos+7; i++){ // 7 since hero was checked before + lines[i] == '0' ? color = "Red;" : color = "Green;"; + style = "background-color: " + color + " background-image: url(:/heroes/heroes+spells/" + this->fighters[line-1] + "/" + std::to_string(i-pos+1) +".png)"; + buttons[line-1][i-pos+1]->setStyleSheet(QString::fromStdString(style)); + } + return true; +} + +void HeroSelection::ButtonClicked(){ + QPushButton *button = (QPushButton*) sender(); + for(int x = 0; x < 18; x++) + for(int c = 0; c < 8; c++) + if(this->buttons[x][c] == button){ + switch(changeLine(this->fileName,this->fighters[x],c,this->AccessableHeroes)){ + case 0: this->AccessableHeroes--; break; + case 1: this->AccessableHeroes++; break; + case 3: break; + case -1: QMessageBox::critical(this, "File open error", "Could not open file BCR_T(1,2)"); std::terminate(); break; + case -2: QMessageBox::warning(this, "Random settings analyze", "You are trying to set less than 4 heroes for randoming"); break; + case -3: QMessageBox::warning(this, "Random settings analyze", "You are trying to set less than 4 spells for hero"); break; + case -4: QMessageBox::warning(this, "Random settings analyze", "Bruh"); break; + default: break; + } + updateUiLine(x+1); + return; + } + +} + +HeroSelection::~HeroSelection(){ + delete ui; +} diff --git a/heroselection.h b/heroselection.h new file mode 100644 index 0000000..2b52906 --- /dev/null +++ b/heroselection.h @@ -0,0 +1,31 @@ +#ifndef HEROSELECTION_H +#define HEROSELECTION_H + +#include "qpushbutton.h" +#include + +namespace Ui { +class HeroSelection; +} + +class HeroSelection : public QDialog +{ + Q_OBJECT + +public: + explicit HeroSelection(QWidget *parent = nullptr, std::string *fighters = nullptr, int numTeam = 0); + ~HeroSelection(); + +private: + QPushButton ***buttons; + Ui::HeroSelection *ui; + std::string fighters[18]; + std::string fileName; + int AccessableHeroes; + + bool updateUiLine(int line); +private slots: + void ButtonClicked(); +}; + +#endif // HEROSELECTION_H diff --git a/heroselection.ui b/heroselection.ui new file mode 100644 index 0000000..cf98988 --- /dev/null +++ b/heroselection.ui @@ -0,0 +1,42 @@ + + + HeroSelection + + + + 0 + 0 + 1065 + 343 + + + + Dialog + + + + + 0 + 0 + 1061 + 341 + + + + true + + + + + 0 + 0 + 1059 + 339 + + + + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index e053f44..52b47e7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,9 +1,11 @@ #include "mainwindow.h" -#include "description.h" +#include "heroselection.h" #include "ui_mainwindow.h" #include "Random.h" +#include "filemanip.h" #include +#include #include #include #include @@ -39,7 +41,14 @@ MainWindow::MainWindow(QWidget *parent) this->ui->statusbar->hide(); this->setFixedSize(QSize(1192, 665)); + // setting colors this->setStyleSheet("color: #FFFFFF"); + this->ui->RandomSettings1->setStyleSheet("background-color: #3F3F3F"); + this->ui->RandomSettings2->setStyleSheet("background-color: #3F3F3F"); + this->ui->doRandom->setStyleSheet("background-color: #3F3F3F"); + this->ui->level1->setStyleSheet("background-color: #242424"); + this->ui->level2->setStyleSheet("background-color: #242424"); + this->ui->level1->setMaximum(75); this->ui->level2->setMaximum(75); @@ -80,9 +89,7 @@ string ParsingTrinket(string line, int mode){ QString* GetTrinkets(int lvl, string usedFighters[4]){ vector possibleTrinkets; QFile trinketList(":/trinkets/trinkets/list.txt"); - //std::ifstream trinketList(file.toStdString()); if (!trinketList.open(QIODevice::ReadOnly)){ - qDebug() << "ERROR"; std::terminate(); } QTextStream in(&trinketList); @@ -92,7 +99,7 @@ QString* GetTrinkets(int lvl, string usedFighters[4]){ stopLine = "-----"; else{ stopLine = "--" + to_string(lvl+1); - lvl < 10 ? stopLine+="--" : stopLine+="-"; + lvl + 1 < 10 ? stopLine+="--" : stopLine+="-"; } // obtaining possible trinkets for team while(true){ @@ -146,68 +153,55 @@ QString* GetTrinkets(int lvl, string usedFighters[4]){ void MainWindow::Randoming(int numCommand){ string usedFighters[4]; int usedSpells[4][4]; // 0 for NA - bool flagellantEnterned = false, shieldbreakerEnterned = false, musketeerEnterned = false; + vector possibleHeroes; + vector possibleSkills; + // opening file + string fileName; + numCommand == 0 ? fileName = "BCR_T1.txt" : fileName = "BCR_T2.txt"; + if(!filesystem::exists(fileName) && recreate(fileName,this->fighters)){ + QMessageBox::critical(this, "Cannot create file", "For some reason BCR cannot create file for team random settings"); + return; + } + ifstream file(fileName); + if(!file){ + QMessageBox::critical(this, "Cannot open file", "For some reason BCR cannot open file for reading"); + return; + } + // analyzing which heroes and skills we can use for random + for(int i = 0; i < 18; i++){ + string line; + file >> line; + if(line[line.find(":")+1] == '1'){ + possibleHeroes.push_back(this->fighters[i]); // saving hero + string skills; + for(unsigned int i = line.find(":")+2; i < line.size();i++) + skills += line[i]; + possibleSkills.push_back(skills); // saving his skills + } + } //randoming first team //randoming heroes for(int i = 0; i < 4; i++){ - usedFighters[i] = this->fighters[Random::get(0,17)]; - //setting flag for future check - if(usedFighters[i] == "shieldbreaker") - shieldbreakerEnterned = true; - else if(usedFighters[i] == "flagellant") - flagellantEnterned = true; - else if(usedFighters[i] == "musketeer") - musketeerEnterned = true; - + int index = possibleHeroes.size(); // variable for storing index that has hero skills + int numHero = Random::get(0,index-1); // variable for storing hero index + index = numHero; // now we know where heroes spells located + usedFighters[i] = possibleHeroes[numHero]; //randoming spells if(usedFighters[i] == "abomination"){ for(int j = 0; j < 4; j++) usedSpells[i][j] = 0; } else for(int j = 0; j < 4; j++){ - usedSpells[i][j] = Random::get(1,7); - //also checking if such spells already taken - for(int z = 0; z < j; z++) - if(usedSpells[i][z] == usedSpells[i][j]){ - j--; - break; - } - } - //checking if we can paste randomed hero - if(numCommand == 0){ //checking for first team - if(this->ui->t1Shieldbreaker->isChecked() == false && shieldbreakerEnterned == true){ - shieldbreakerEnterned = false; - i--; - continue; - } else if(this->ui->t1Musketeer->isChecked() == false && musketeerEnterned == true){ - musketeerEnterned = false; - i--; - continue; - } else if(this->ui->t1Flagellant->isChecked() == false && flagellantEnterned == true){ - flagellantEnterned = false; - i--; - continue; - } - } else{ //checking for second team - if(this->ui->t2Shieldbreaker->isChecked() == false && shieldbreakerEnterned == true){ - shieldbreakerEnterned = false; - i--; - continue; - } else if(this->ui->t2Musketeer->isChecked() == false && musketeerEnterned == true){ - musketeerEnterned = false; - i--; - continue; - } else if(this->ui->t2Flagellant->isChecked() == false && flagellantEnterned == true){ - flagellantEnterned = false; - i--; - continue; - } - } - for(int j = 0; j < i; j++) - if(usedFighters[j] == usedFighters[i]){ - i--; - break; + int result = Random::get(1,7); + if(possibleSkills[index][result-1] == '0'){ + j--; + continue; + } + possibleSkills[index][result-1] = '0'; + usedSpells[i][j] = result; } + possibleSkills.erase(possibleSkills.cbegin()+index); + possibleHeroes.erase(possibleHeroes.cbegin()+numHero); } for(int i = 0; i < 4; i++){ //heroes @@ -220,7 +214,6 @@ void MainWindow::Randoming(int numCommand){ hero[i+(numCommand*4)] = QString::fromStdString(usedFighters[i]); //abilities for(int j = 0; j < 4;j++){ - buttonName = "s" + QString::number(i+(numCommand*4)+1) + "_" + QString::number(j+1); buttons = this->findChildren(buttonName); temp = "background-image: url(:/heroes/heroes+spells/" + usedFighters[i] + "/"+ to_string(usedSpells[i][j]) +".png)"; @@ -257,15 +250,6 @@ void MainWindow::on_doRandom_clicked() Randoming(1); } - -void MainWindow::on_hero1_clicked() -{ - Description *window = new Description; - window->setModal(true); - window->exec(); -} - - void MainWindow::on_level1_valueChanged(int arg1) { if(this->ui->sameTeamLevel->isChecked()) @@ -286,3 +270,21 @@ void MainWindow::on_sameTeamLevel_clicked() this->ui->level2->setValue(this->ui->level1->value()); } + +void MainWindow::on_RandomSettings1_clicked() +{ + HeroSelection *win = new HeroSelection(this,fighters,0); + win->setModal(true); + win->exec(); + delete win; +} + + +void MainWindow::on_RandomSettings2_clicked() +{ + HeroSelection *win = new HeroSelection(this,fighters,1); + win->setModal(true); + win->exec(); + delete win; +} + diff --git a/mainwindow.h b/mainwindow.h index 5013639..1922245 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -17,7 +17,6 @@ class MainWindow : public QMainWindow private slots: void on_doRandom_clicked(); - void on_hero1_clicked(); void on_level1_valueChanged(int arg1); @@ -25,6 +24,10 @@ private slots: void on_sameTeamLevel_clicked(); + void on_RandomSettings1_clicked(); + + void on_RandomSettings2_clicked(); + private: Ui::MainWindow *ui; std::string fighters[18]; diff --git a/mainwindow.ui b/mainwindow.ui index f7142fe..32d819d 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -272,7 +272,7 @@ 550 80 - 111 + 121 16 @@ -848,114 +848,12 @@ - - - - 10 - 0 - 441 - 76 - - - - - - - - - Musketeer - - - - - - - Shieldbreaker - - - - - - - Flagellant - - - - - - - - - - - level - - - - - - - - - - - - - - 750 - 0 - 441 - 76 - - - - - - - - - Musketeer - - - - - - - Shieldbreaker - - - - - - - Flagellant - - - - - - - - - - - level - - - - - - - - - - 540 110 - 131 + 141 20 @@ -966,9 +864,9 @@ - 748 + 728 500 - 441 + 461 101 @@ -1279,6 +1177,78 @@ + + + + 10 + 20 + 121 + 51 + + + + Random Settings + + + + + + 380 + 40 + 61 + 24 + + + + + + + 380 + 10 + 61 + 21 + + + + level + + + + + + 750 + 40 + 61 + 21 + + + + + + + 750 + 10 + 41 + 21 + + + + level + + + + + + 1070 + 20 + 121 + 51 + + + + Random Settings + + @@ -1286,7 +1256,7 @@ 0 0 1202 - 19 + 21