Skip to content

Commit

Permalink
Show difficulty count
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico-Duduf committed Apr 12, 2024
1 parent cb660c8 commit 9cfa8bb
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/rameditwidgets/objecteditwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected slots:
void setName();
void setComment();

void objectChanged(RamObject *o);
void objectChanged(RamObject *o = nullptr);

void checkPath();

Expand Down
139 changes: 133 additions & 6 deletions src/rameditwidgets/stepeditwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ RamStep *StepEditWidget::step() const

void StepEditWidget::reInit(RamObject *obj)
{
bool same = m_step == obj;

m_step = qobject_cast<RamStep*>( obj );

if (!same)
connect(m_step->project(), &RamProject::estimationComputed,
this, [this](){ reInit(m_step); });

while(ui_statesLayout->rowCount() > 0)
ui_statesLayout->removeRow(0);
while(ui_difficultiesLayout->rowCount() > 0)
ui_difficultiesLayout->removeRow(0);


if (m_step)
{
Expand Down Expand Up @@ -62,14 +71,35 @@ void StepEditWidget::reInit(RamObject *obj)
ui_estimationMultiplierCheckBox->setChecked(true);
ui_estimationMultiplierBox->setObject( m_step->estimationMultiplyGroup() );
}
else
{
ui_estimationMultiplierBox->setEnabled(false);
ui_estimationMultiplierCheckBox->setChecked(false);
ui_estimationMultiplierBox->setCurrentIndex(-1);
}

updateEstimationSuffix();

RamStep::Type stepType = m_step->type();
if (stepType == RamStep::AssetProduction || stepType == RamStep::ShotProduction) {
ui_completionWidget->show();

int completion = m_step->completionRatio();
ui_progressWidget->setCompletionRatio(completion);
if (completion > 99)
ui_completionLabel->setText("Finished!");
else {
ui_completionLabel->setText(
QString("<i>Completion: <b>%1%</b> (%2 / %3 days)</i>")
.arg(completion)
.arg(int(m_step->daysSpent()))
.arg(int(m_step->estimation()))
);
}

const QVector<RamStep::StateCount> stateCount = m_step->stateCount();
RamState *noState = Ramses::instance()->noState();
int total = 0;
float total = 0;

for(const auto count: stateCount) {
int c = count.count;
Expand All @@ -80,24 +110,102 @@ void StepEditWidget::reInit(RamObject *obj)
if (state->is(noState))
continue;

QString cStr = "<b>"+QString::number(c)+"</b> ";
total += c;
}

if (total > 0) {

ui_statesLayout->setWidget( 0, QFormLayout::LabelRole, new QLabel("<b>"+tr("States:")+"</b>") );

for(const auto count: stateCount) {
float c = count.count;
if (c == 0)
continue;

RamState *state = count.state;
if (state->is(noState))
continue;

QString cStr = "<b>"+QString::number(c)+"</b> ";
if (stepType == RamStep::AssetProduction) cStr += "assets (";
else cStr += "shots (";
cStr += QString::number(int(c/total*100)) + "%)";

auto l = new QLabel(state->name(), this);
l->setStyleSheet("QLabel { color: "+state->color().name() + "; }");
ui_statesLayout->addRow( l, new QLabel(cStr, this) );
}

QString cStr = "<b>"+QString::number(total)+"</b> ";
if (stepType == RamStep::AssetProduction) cStr += "assets";
else cStr += "shots";

auto l = new QLabel(state->name(), this);
l->setStyleSheet("QLabel { color: "+state->color().name() + "; }");
ui_statesLayout->addRow( l, new QLabel(cStr, this) );
ui_statesLayout->addRow( "Total", new QLabel(cStr, this) );
}

const QMap<RamStatus::Difficulty, int> difficulties = m_step->difficultyCount();
total = 0;

QMapIterator<RamStatus::Difficulty, int> i(difficulties);
while(i.hasNext()) {
i.next();
float c = i.value();
if (c == 0)
continue;
total += c;
}

if (total > 0) {

ui_difficultiesLayout->setWidget( 0, QFormLayout::LabelRole, new QLabel("<b>"+tr("Difficulty:")+"</b>") );

i.toFront();
while(i.hasNext()) {
i.next();
float c = i.value();
if (c == 0)
continue;

QString cStr = "<b>"+QString::number(c)+"</b> ";
if (stepType == RamStep::AssetProduction) cStr += "assets (";
else cStr += "shots (";
cStr += QString::number(int(c/total*100)) + "%)";

QString label;

switch(i.key()) {
case RamStatus::VeryEasy:
label = tr("Very easy");
break;
case RamStatus::Easy:
label = tr("Easy");
break;
case RamStatus::Medium:
label = tr("Medium");
break;
case RamStatus::Hard:
label = tr("Hard");
break;
case RamStatus::VeryHard:
label = tr("Very hard");
break;
}

auto l = new QLabel(label, this);
ui_difficultiesLayout->addRow( l, new QLabel(cStr, this) );
}

QString cStr = "<b>"+QString::number(total)+"</b> ";
if (stepType == RamStep::AssetProduction) cStr += "assets";
else cStr += "shots";

ui_statesLayout->addRow( "Total", new QLabel(cStr, this) );
ui_difficultiesLayout->addRow( "Total", new QLabel(cStr, this) );
}
}
else
{
ui_completionWidget->hide();
}
}
else
{
Expand All @@ -118,6 +226,7 @@ void StepEditWidget::reInit(RamObject *obj)
ui_estimationMultiplierCheckBox->setChecked(false);
ui_estimationMultiplierBox->setCurrentIndex(-1);
ui_estimationMultiplierBox->setEnabled(false);
ui_completionWidget->hide();
}
}

Expand Down Expand Up @@ -296,10 +405,28 @@ void StepEditWidget::setupUi()
"<b>"+tr("Status")+"</b>"
));

ui_completionWidget = new QWidget(this);
estimLayout->addWidget(ui_completionWidget);

auto completionLayout = new QVBoxLayout(ui_completionWidget);
completionLayout->setContentsMargins(0,0,0,0);
completionLayout->setSpacing(1);

ui_progressWidget = new ProgressWidget(this);
completionLayout->addWidget(ui_progressWidget);

ui_completionLabel = new QLabel(this);
completionLayout->addWidget(ui_completionLabel);
completionLayout->setAlignment(ui_completionLabel, Qt::AlignCenter);

ui_statesWidget = new QWidget(ui_tabWidget);
ui_statesLayout = new QFormLayout(ui_statesWidget);
estimLayout->addWidget(ui_statesWidget);

ui_difficultiesWidget = new QWidget(ui_tabWidget);
ui_difficultiesLayout = new QFormLayout(ui_difficultiesWidget);
estimLayout->addWidget(ui_difficultiesWidget);

estimLayout->addStretch(1);

QFormLayout *estimationLayout = new QFormLayout(ui_estimationWidget);
Expand Down
6 changes: 6 additions & 0 deletions src/rameditwidgets/stepeditwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "duqf-widgets/duqffolderdisplaywidget.h"
#include "duqf-widgets/duqfcolorselector.h"
#include "objectlistwidget.h"
#include "progresswidget.h"

class StepEditWidget : public ObjectEditWidget
{
Expand Down Expand Up @@ -52,7 +53,12 @@ private slots:
DuComboBox *ui_typeBox;
QWidget *ui_estimationWidget;
QWidget *ui_statesWidget;
QWidget *ui_completionWidget;
ProgressWidget *ui_progressWidget;
QLabel *ui_completionLabel;
QWidget *ui_difficultiesWidget;
QFormLayout *ui_statesLayout;
QFormLayout *ui_difficultiesLayout;
DuComboBox *ui_estimationTypeBox;
QLabel *ui_estimationTypeLabel;
DuQFTextEdit *ui_publishSettingsEdit;
Expand Down
4 changes: 2 additions & 2 deletions src/ramobjects/ramstatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class RamStatus : public RamObject

QString restoreVersionFile(QString fileName) const;

virtual QString name() const;
virtual QString shortName() const;
virtual QString name() const override;
virtual QString shortName() const override;

virtual QString previewImagePath() const override;

Expand Down
22 changes: 22 additions & 0 deletions src/ramobjects/ramstep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ramworkingfolder.h"
#include "stepeditwidget.h"
#include "ramshot.h"
#include "ramses.h"

// STATIC //

Expand Down Expand Up @@ -206,6 +207,27 @@ QVector<RamStep::StateCount> RamStep::stateCount()
return count;
}

QMap<RamStatus::Difficulty, int> RamStep::difficultyCount()
{
QMap<RamStatus::Difficulty, int> difficulty;

RamProject *proj = project();
if (!proj) return difficulty;

RamState *noState = Ramses::instance()->noState();

const QSet<RamStatus*> status = proj->stepStatus(this);
for(auto st: status) {
if (noState->is(st->state()))
continue;
RamStatus::Difficulty d = st->difficulty();
int c = difficulty.value(d, 0);
difficulty.insert(d, c+1);
}

return difficulty;
}

QVector<float> RamStep::stats(RamUser *user)
{
float estim = estimation();
Expand Down
2 changes: 2 additions & 0 deletions src/ramobjects/ramstep.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QDesktopServices>

#include "ramtemplatestep.h"
#include "ramstatus.h"

class RamAssetGroup;
class RamProject;
Expand Down Expand Up @@ -48,6 +49,7 @@ class RamStep : public RamTemplateStep
float neededDays() ;

QVector<StateCount> stateCount();
QMap<RamStatus::Difficulty,int> difficultyCount();

/**
* @brief stats
Expand Down

0 comments on commit 9cfa8bb

Please sign in to comment.