Skip to content

Commit 7880d05

Browse files
authored
Merge pull request #80 from mahartwig/fight_category_fix
Fight category fix
2 parents e72f35e + 910f968 commit 7880d05

File tree

10 files changed

+122
-97
lines changed

10 files changed

+122
-97
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
For most recent changes see the project on github: [https://github.com/fmuecke/Ipponboard](https://github.com/fmuecke/Ipponboard)
44

5+
- (mod): updated single tournament weight and age classes
6+
- (mod): weight classes can now be any string and have to include kg to support the use of groups instead of weights for youth tournaments
7+
- (fix): categories are now saved correctly and not duplicated when aborting the CategoryManager
58
- (new): added shortcuts to start single or team mode from splashscreen (1, 2)
69
- (fix): fixed a crash when Team Edition was started with a TournamentMode with only one round
710
- (mod): added and updated TournamentModes to current weight and age classes

base/FightCategoryManager.cpp

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <QObject>
88
#include <QMessageBox>
99
#include <QFile>
10+
#include <QDebug>
1011

1112
#include "../util/path_helpers.h"
1213
#include "FightCategoryParser.h"
@@ -24,14 +25,14 @@ FightCategoryMgr::FightCategoryMgr()
2425
: m_Categories()
2526
//---------------------------------------------------------
2627
{
27-
load_categories();
28+
LoadCategories();
2829
}
2930

3031
//---------------------------------------------------------
3132
FightCategoryMgr::~FightCategoryMgr()
3233
//---------------------------------------------------------
3334
{
34-
save_categories();
35+
SaveCategories();
3536
}
3637

3738
//---------------------------------------------------------
@@ -145,7 +146,7 @@ void FightCategoryMgr::RemoveCategory(QString const& name)
145146
}
146147

147148
//---------------------------------------------------------
148-
void FightCategoryMgr::load_categories()
149+
void FightCategoryMgr::LoadCategories()
149150
//---------------------------------------------------------
150151
{
151152
auto configFile {fm::GetSettingsFilePath(str_configFileName)};
@@ -155,22 +156,26 @@ void FightCategoryMgr::load_categories()
155156
{
156157
if (QFile::exists(configFile))
157158
{
159+
qInfo() << "Reading categories from config:" << configFile;
158160
m_Categories = FightCategoryParser::ParseIniFile(configFile);
159161
}
160162
else
161163
{
162164
if (!QFile::exists(legacyFile))
163165
{
166+
qInfo() << "Loading default categories";
164167
load_default_categories();
165168
}
166169
else
167170
{
171+
qInfo() << "Reading categories from legacy config:" << legacyFile;
168172
m_Categories = FightCategoryParser::ParseJsonFile(legacyFile);
169173
}
170174
}
171175
}
172176
catch (std::exception const& e)
173177
{
178+
qWarning() << "Error loading categories, restoring defaults";
174179
QMessageBox::critical(nullptr,
175180
QString(QObject::tr("Error")),
176181
QString(QObject::tr("Unable to load fight categories:\n%1\n\nRestoring defaults.").arg(
@@ -181,9 +186,10 @@ void FightCategoryMgr::load_categories()
181186
}
182187

183188
//---------------------------------------------------------
184-
void FightCategoryMgr::save_categories()
189+
void FightCategoryMgr::SaveCategories()
185190
//---------------------------------------------------------
186191
{
192+
qInfo() << "Saving categories to:" << str_configFileName;
187193
auto filePath {fm::GetSettingsFilePath(str_configFileName)};
188194
FightCategoryParser::ToIniFile(filePath, m_Categories);
189195
}
@@ -240,74 +246,62 @@ void FightCategoryMgr::load_default_categories()
240246
m_Categories.clear();
241247

242248
FightCategory t("M");
243-
t.SetWeights("-60;-66;-73;-81;-90;-100;+100");
249+
t.SetWeights("-60kg;-66kg;-73kg;-81kg;-90kg;-100kg;+100kg");
244250
t.SetRoundTime(4 * 60);
245-
t.SetGoldenScoreTime(3 * 60);
246-
AddCategory(t);
247-
248-
t = FightCategory("MU20");
249-
t.SetWeights("-55;-60;-66;-73;-81;-90;-100;+100");
250-
t.SetRoundTime(4 * 60);
251-
t.SetGoldenScoreTime(2 * 60);
251+
t.SetGoldenScoreTime(0);
252252
AddCategory(t);
253253

254-
t = FightCategory("MU19");
255-
t.SetWeights("-55;-60;-66;-73;-81;-90;-100;+100");
254+
t = FightCategory("MU21");
255+
t.SetWeights("-60kg;-66kg;-73kg;-81kg;-90kg;-100kg;+100kg");
256256
t.SetRoundTime(4 * 60);
257-
t.SetGoldenScoreTime(2 * 60);
257+
t.SetGoldenScoreTime(0);
258258
AddCategory(t);
259259

260-
t = FightCategory("MU17");
261-
t.SetWeights("-43;-46;-50;-55;-60;-66;-73;-81;-90;+90");
260+
t = FightCategory("MU18");
261+
t.SetWeights("-46kg;-50kg;-55kg;-60kg;-66kg;-73kg;-81kg;-90kg;+90kg");
262262
t.SetRoundTime(4 * 60);
263-
t.SetGoldenScoreTime(2 * 60);
263+
t.SetGoldenScoreTime(0);
264264
AddCategory(t);
265265

266-
t = FightCategory("MU16");
267-
t.SetWeights("-40;-43;-46;-50;-55;-60;-66;-73;-81;+81");
268-
t.SetRoundTime(4 * 60);
269-
t.SetGoldenScoreTime(2 * 60);
266+
t = FightCategory("MU15");
267+
t.SetWeights("-34kg;-37kg;-40kg;-43kg;-46kg;-50kg;-55kg;-60kg;-66kg;+66kg");
268+
t.SetRoundTime(3 * 60);
269+
t.SetGoldenScoreTime(3 * 60);
270270
AddCategory(t);
271271

272-
t = FightCategory("MU14");
273-
t.SetWeights("-31;-34;-37;-40;-43;-46;-50;-55;-60;+60");
272+
t = FightCategory("MU13");
273+
t.SetWeights("-28kg;-31kg;-34kg;-37kg;-40kg;-43kg;-46kg;-50kg;-55kg;+55kg");
274274
t.SetRoundTime(3 * 60);
275-
t.SetGoldenScoreTime(90);
275+
t.SetGoldenScoreTime(0);
276276
AddCategory(t);
277277

278278
t = FightCategory("F");
279-
t.SetWeights("-48;-52;-57;-63;-70;-78;+78");
279+
t.SetWeights("-48kg;-52kg;-57kg;-63kg;-70kg;-78kg;+78kg");
280280
t.SetRoundTime(4 * 60);
281-
t.SetGoldenScoreTime(3 * 60);
282-
AddCategory(t);
283-
284-
t = FightCategory("FU20");
285-
t.SetWeights("-44;-48;-52;-57;-63;-70;-78;+78");
286-
t.SetRoundTime(4 * 60);
287-
t.SetGoldenScoreTime(2 * 60);
281+
t.SetGoldenScoreTime(0);
288282
AddCategory(t);
289283

290-
t = FightCategory("FU19");
291-
t.SetWeights("-44;-48;-52;-57;-63;-70;-78;+78");
284+
t = FightCategory("FU21");
285+
t.SetWeights("-48kg;-52kg;-57kg;-63kg;-70kg;-78kg;+78kg");
292286
t.SetRoundTime(4 * 60);
293-
t.SetGoldenScoreTime(2 * 60);
287+
t.SetGoldenScoreTime(0);
294288
AddCategory(t);
295289

296-
t = FightCategory("FU17");
297-
t.SetWeights("-40;-44;-48;-52;-57;-63;-70;-78;+78");
290+
t = FightCategory("FU18");
291+
t.SetWeights("-40kg;-44kg;-48kg;-52kg;-57kg;-63kg;-70kg;-78kg;+78kg");
298292
t.SetRoundTime(4 * 60);
299-
t.SetGoldenScoreTime(2 * 60);
293+
t.SetGoldenScoreTime(0);
300294
AddCategory(t);
301295

302-
t = FightCategory("FU16");
303-
t.SetWeights("-40;-44;-48;-52;-57;-63;-70;+70");
304-
t.SetRoundTime(4 * 60);
305-
t.SetGoldenScoreTime(2 * 60);
296+
t = FightCategory("FU15");
297+
t.SetWeights("-33kg;-36kg;-40kg;-44kg;-48kg;-52kg;-57kg;-63kg;+63kg");
298+
t.SetRoundTime(3 * 60);
299+
t.SetGoldenScoreTime(3 * 60);
306300
AddCategory(t);
307301

308-
t = FightCategory("FU14");
309-
t.SetWeights("-30;-33;-36;-40;-44;-48;-52;-57;-63;+63");
302+
t = FightCategory("FU13");
303+
t.SetWeights("-27kg;-30kg;-33kg;-36kg;-40kg;-44kg;-48kg;-52kg;-57kg;+57kg");
310304
t.SetRoundTime(3 * 60);
311-
t.SetGoldenScoreTime(90);
305+
t.SetGoldenScoreTime(0);
312306
AddCategory(t);
313307
}

base/FightCategoryManager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class FightCategoryMgr
3131

3232
typedef std::shared_ptr<FightCategoryMgr> Ptr;
3333

34+
void LoadCategories();
35+
void SaveCategories();
36+
3437
bool GetCategory(int index, FightCategory& t) const;
3538
bool GetCategory(QString const& name, FightCategory& t) const;
3639

@@ -47,8 +50,6 @@ class FightCategoryMgr
4750
std::string ConvertCategoriesToString_WITH_GUI_ERROR();
4851

4952
private:
50-
void load_categories();
51-
void save_categories();
5253
void load_default_categories();
5354

5455
FightCategoryList m_Categories;

base/FightCategoryManagerDlg.cpp

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ FightCategoryManagerDlg::FightCategoryManagerDlg(
2929

3030
Q_ASSERT(m_pClassMgr);
3131

32-
m_originalClasses = m_pClassMgr->ConvertCategoriesToString_WITH_GUI_ERROR();
33-
3432
load_values();
3533
}
3634

@@ -87,6 +85,10 @@ void FightCategoryManagerDlg::on_pushButton_add_pressed()
8785
if (ok)
8886
{
8987
m_pClassMgr->AddCategory(name);
88+
Ipponboard::FightCategory cat;
89+
m_pClassMgr->GetCategory(name, cat);
90+
cat.SetGoldenScoreTime(0);
91+
cat.SetRoundTime(240);
9092

9193
// update combobox
9294
QStringList contents;
@@ -98,9 +100,9 @@ void FightCategoryManagerDlg::on_pushButton_add_pressed()
98100
new QTreeWidgetItem(contents, QTreeWidgetItem::UserType);
99101
pItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
100102
ui->treeWidget_classes->addTopLevelItem(pItem);
101-
pItem->setText(eColumn_Time, "...");
102-
pItem->setText(eColumn_GS, "...");
103-
pItem->setText(eColumn_Weights, "...");
103+
pItem->setText(eColumn_Time, cat.GetRoundTimeStr());
104+
pItem->setText(eColumn_GS, cat.GetGoldenScoreTimeStr());
105+
pItem->setText(eColumn_Weights, "");
104106
}
105107
}
106108

@@ -126,24 +128,6 @@ void FightCategoryManagerDlg::load_values()
126128
}
127129
}
128130

129-
//---------------------------------------------------------
130-
void FightCategoryManagerDlg::on_buttonBox_accepted()
131-
//---------------------------------------------------------
132-
{
133-
// do not restore old values
134-
//TODO: ? accept();
135-
}
136-
137-
//---------------------------------------------------------
138-
void FightCategoryManagerDlg::on_buttonBox_rejected()
139-
//---------------------------------------------------------
140-
{
141-
// restore old values
142-
//TODO: ? reject();
143-
144-
m_pClassMgr->CategoriesFromString(m_originalClasses);
145-
}
146-
147131
//---------------------------------------------------------
148132
void FightCategoryManagerDlg::on_pushButton_remove_pressed()
149133
//---------------------------------------------------------
@@ -167,7 +151,7 @@ void FightCategoryManagerDlg::on_treeWidget_classes_itemChanged(
167151
//---------------------------------------------------------
168152
{
169153
bool matches(false);
170-
154+
171155
FightCategory cat(pItem->text(eColumn_Name));
172156
cat.SetRoundTime(pItem->text(eColumn_Time));
173157
cat.SetGoldenScoreTime(pItem->text(eColumn_GS));
@@ -232,8 +216,8 @@ void FightCategoryManagerDlg::on_treeWidget_classes_itemChanged(
232216
}
233217
else if (column == eColumn_Weights)
234218
{
235-
QRegExp regex("([-+]{0,1}[0-9]{1,3}[;])*[-+]{0,1}[0-9]{1,3}");
236-
matches = regex.exactMatch(pItem->text(eColumn_Weights));
219+
//no regex check to enable creating custom groups instead of weight classes
220+
matches = true;
237221
}
238222

239223
QBrush brush(pItem->foreground(column));

base/FightCategoryManagerDlg.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,10 @@ class FightCategoryManagerDlg : public QDialog
3535

3636
Ui::FightCategoryManagerDlg* ui;
3737
Ipponboard::FightCategoryMgr::Ptr m_pClassMgr;
38-
std::string m_originalClasses;
3938
//Ipponboard::WeightClass m_currentClass;
4039

4140
private slots:
4241
void on_treeWidget_classes_itemChanged(QTreeWidgetItem* item, int column);
43-
void on_buttonBox_rejected();
44-
void on_buttonBox_accepted();
4542
void on_pushButton_remove_pressed();
4643
void on_pushButton_add_pressed();
4744
};

base/FightCategoryManagerDlg.ui

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>587</width>
10-
<height>405</height>
10+
<height>420</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -20,7 +20,7 @@
2020
<property name="modal">
2121
<bool>true</bool>
2222
</property>
23-
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
23+
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0">
2424
<item>
2525
<widget class="QTreeWidget" name="treeWidget_classes">
2626
<property name="mouseTracking">
@@ -90,6 +90,32 @@
9090
</column>
9191
</widget>
9292
</item>
93+
<item>
94+
<widget class="QLabel" name="label">
95+
<property name="font">
96+
<font>
97+
<family>Segoe UI</family>
98+
<pointsize>9</pointsize>
99+
</font>
100+
</property>
101+
<property name="text">
102+
<string>0:00 Golden Score Time means Golden Score has no end (or there is no Golden Score at all)</string>
103+
</property>
104+
</widget>
105+
</item>
106+
<item>
107+
<widget class="QLabel" name="label_2">
108+
<property name="font">
109+
<font>
110+
<family>Segoe UI</family>
111+
<pointsize>9</pointsize>
112+
</font>
113+
</property>
114+
<property name="text">
115+
<string>Input weight classes/groups seperated by &quot;;&quot;</string>
116+
</property>
117+
</widget>
118+
</item>
93119
<item>
94120
<layout class="QHBoxLayout" name="horizontalLayout">
95121
<property name="spacing">

base/MainWindow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,15 @@ void MainWindow::Init()
7070

7171
void MainWindow::on_actionManageCategories_triggered()
7272
{
73+
//save categories before editing
74+
m_pCategoryManager->SaveCategories();
75+
7376
FightCategoryManagerDlg dlg(m_pCategoryManager, this);
7477

7578
if (QDialog::Accepted == dlg.exec())
7679
{
80+
m_pCategoryManager->SaveCategories();
81+
7782
QString currentClass =
7883
m_pUi->comboBox_weight_class->currentText();
7984

@@ -97,6 +102,11 @@ void MainWindow::on_actionManageCategories_triggered()
97102
m_pUi->comboBox_weight_class->setCurrentIndex(index);
98103
on_comboBox_weight_class_currentIndexChanged(currentClass);
99104
}
105+
else
106+
{
107+
//load old categories to discard changes
108+
m_pCategoryManager->LoadCategories();
109+
}
100110
}
101111

102112
void MainWindow::on_actionManageFighters_triggered()

0 commit comments

Comments
 (0)