Skip to content

Commit

Permalink
New release
Browse files Browse the repository at this point in the history
  • Loading branch information
raik199x committed Jan 3, 2023
1 parent 9fdc805 commit b169f35
Show file tree
Hide file tree
Showing 15 changed files with 920 additions and 472 deletions.
8 changes: 5 additions & 3 deletions Butcher_Circus_Randomizer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 += \
Expand Down
198 changes: 16 additions & 182 deletions Butcher_Circus_Randomizer.pro.user

Large diffs are not rendered by default.

429 changes: 429 additions & 0 deletions Butcher_Circus_Randomizer.pro.user.2430ef6

Large diffs are not rendered by default.

20 changes: 0 additions & 20 deletions description.cpp

This file was deleted.

25 changes: 0 additions & 25 deletions description.h

This file was deleted.

68 changes: 0 additions & 68 deletions description.ui

This file was deleted.

56 changes: 56 additions & 0 deletions filemanip.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
9 changes: 9 additions & 0 deletions filemanip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef FILEMANIP_H
#define FILEMANIP_H
#include <iostream>
#include <fstream>

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
55 changes: 55 additions & 0 deletions filemanip_windows.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
128 changes: 128 additions & 0 deletions heroselection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#include "heroselection.h"
#include "qboxlayout.h"
#include "ui_heroselection.h"
#include "filemanip.h"
#include <filesystem>
#include <QMessageBox>

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;
}
Loading

0 comments on commit b169f35

Please sign in to comment.