From 9cfa8bb4ec6bbf4e725ba220afcb46d0464d000a Mon Sep 17 00:00:00 2001 From: Duduf Date: Fri, 12 Apr 2024 14:23:10 +0200 Subject: [PATCH] Show difficulty count --- src/rameditwidgets/objecteditwidget.h | 2 +- src/rameditwidgets/stepeditwidget.cpp | 139 ++++++++++++++++++++++++-- src/rameditwidgets/stepeditwidget.h | 6 ++ src/ramobjects/ramstatus.h | 4 +- src/ramobjects/ramstep.cpp | 22 ++++ src/ramobjects/ramstep.h | 2 + 6 files changed, 166 insertions(+), 9 deletions(-) diff --git a/src/rameditwidgets/objecteditwidget.h b/src/rameditwidgets/objecteditwidget.h index ec3be33f..479908cf 100644 --- a/src/rameditwidgets/objecteditwidget.h +++ b/src/rameditwidgets/objecteditwidget.h @@ -37,7 +37,7 @@ protected slots: void setName(); void setComment(); - void objectChanged(RamObject *o); + void objectChanged(RamObject *o = nullptr); void checkPath(); diff --git a/src/rameditwidgets/stepeditwidget.cpp b/src/rameditwidgets/stepeditwidget.cpp index 2b1f50c4..a9402451 100644 --- a/src/rameditwidgets/stepeditwidget.cpp +++ b/src/rameditwidgets/stepeditwidget.cpp @@ -27,10 +27,19 @@ RamStep *StepEditWidget::step() const void StepEditWidget::reInit(RamObject *obj) { + bool same = m_step == obj; + m_step = qobject_cast( 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) { @@ -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("Completion: %1% (%2 / %3 days)") + .arg(completion) + .arg(int(m_step->daysSpent())) + .arg(int(m_step->estimation())) + ); + } + const QVector stateCount = m_step->stateCount(); RamState *noState = Ramses::instance()->noState(); - int total = 0; + float total = 0; for(const auto count: stateCount) { int c = count.count; @@ -80,24 +110,102 @@ void StepEditWidget::reInit(RamObject *obj) if (state->is(noState)) continue; - QString cStr = ""+QString::number(c)+" "; + total += c; + } + + if (total > 0) { + + ui_statesLayout->setWidget( 0, QFormLayout::LabelRole, new QLabel(""+tr("States:")+"") ); + + for(const auto count: stateCount) { + float c = count.count; + if (c == 0) + continue; + + RamState *state = count.state; + if (state->is(noState)) + continue; + + QString cStr = ""+QString::number(c)+" "; + 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 = ""+QString::number(total)+" "; 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 difficulties = m_step->difficultyCount(); + total = 0; + + QMapIterator 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(""+tr("Difficulty:")+"") ); + + i.toFront(); + while(i.hasNext()) { + i.next(); + float c = i.value(); + if (c == 0) + continue; + + QString cStr = ""+QString::number(c)+" "; + 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 = ""+QString::number(total)+" "; 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 { @@ -118,6 +226,7 @@ void StepEditWidget::reInit(RamObject *obj) ui_estimationMultiplierCheckBox->setChecked(false); ui_estimationMultiplierBox->setCurrentIndex(-1); ui_estimationMultiplierBox->setEnabled(false); + ui_completionWidget->hide(); } } @@ -296,10 +405,28 @@ void StepEditWidget::setupUi() ""+tr("Status")+"" )); + 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); diff --git a/src/rameditwidgets/stepeditwidget.h b/src/rameditwidgets/stepeditwidget.h index eadb549a..70522f72 100644 --- a/src/rameditwidgets/stepeditwidget.h +++ b/src/rameditwidgets/stepeditwidget.h @@ -13,6 +13,7 @@ #include "duqf-widgets/duqffolderdisplaywidget.h" #include "duqf-widgets/duqfcolorselector.h" #include "objectlistwidget.h" +#include "progresswidget.h" class StepEditWidget : public ObjectEditWidget { @@ -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; diff --git a/src/ramobjects/ramstatus.h b/src/ramobjects/ramstatus.h index d66721ad..20b15df9 100644 --- a/src/ramobjects/ramstatus.h +++ b/src/ramobjects/ramstatus.h @@ -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; diff --git a/src/ramobjects/ramstep.cpp b/src/ramobjects/ramstep.cpp index 2bdb06b9..b0cf8b2e 100644 --- a/src/ramobjects/ramstep.cpp +++ b/src/ramobjects/ramstep.cpp @@ -10,6 +10,7 @@ #include "ramworkingfolder.h" #include "stepeditwidget.h" #include "ramshot.h" +#include "ramses.h" // STATIC // @@ -206,6 +207,27 @@ QVector RamStep::stateCount() return count; } +QMap RamStep::difficultyCount() +{ + QMap difficulty; + + RamProject *proj = project(); + if (!proj) return difficulty; + + RamState *noState = Ramses::instance()->noState(); + + const QSet 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 RamStep::stats(RamUser *user) { float estim = estimation(); diff --git a/src/ramobjects/ramstep.h b/src/ramobjects/ramstep.h index 674db3fb..52bd3f59 100644 --- a/src/ramobjects/ramstep.h +++ b/src/ramobjects/ramstep.h @@ -4,6 +4,7 @@ #include #include "ramtemplatestep.h" +#include "ramstatus.h" class RamAssetGroup; class RamProject; @@ -48,6 +49,7 @@ class RamStep : public RamTemplateStep float neededDays() ; QVector stateCount(); + QMap difficultyCount(); /** * @brief stats