Skip to content

Commit

Permalink
Add refresh button for techleak
Browse files Browse the repository at this point in the history
  • Loading branch information
jwrober committed Feb 24, 2024
1 parent 9e16bd9 commit 24dd0e4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
37 changes: 35 additions & 2 deletions client/views/view_research.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QGridLayout>
#include <QMouseEvent>
#include <QPainter>
#include <QPushButton>
#include <QScrollArea>
#include <QTimer>
#include <QToolTip>
Expand All @@ -26,6 +27,7 @@
#include "game.h"
#include "government.h"
#include "research.h"

// client
#include "citydlg.h"
#include "client_main.h"
Expand All @@ -40,6 +42,9 @@
#include "views/view_research.h"
#include "views/view_research_reqtree.h"

// server
#include "../server/techtools.h"

extern QString split_text(const QString &text, bool cut);
extern QString cut_helptext(const QString &text);
extern QString get_tooltip_improvement(impr_type *building,
Expand Down Expand Up @@ -273,15 +278,22 @@ science_report::science_report() : QWidget()
auto sci_layout = new QGridLayout();
res_diag = new research_diagram();
auto scroll = new QScrollArea();
refresh_but = new QPushButton();
refresh_but->setText(_("Refresh"));
refresh_but->setToolTip(_("Press to refresh currently researched "
"technology calculation again."));
refresh_but->setVisible(false);

progress->setTextVisible(true);
progress_label->setSizePolicy(size_fixed_policy);
sci_layout->addWidget(progress_label, 0, 0, 1, 8);
sci_layout->addWidget(researching_combo, 1, 0, 1, 4);
sci_layout->addWidget(researching_combo, 1, 0, 1, 3);
sci_layout->addWidget(refresh_but, 1, 3, 1, 1);
researching_combo->setSizePolicy(size_fixed_policy);
refresh_but->setSizePolicy(size_fixed_policy);
sci_layout->addWidget(progress, 1, 5, 1, 4);
progress->setSizePolicy(size_fixed_policy);
sci_layout->addWidget(goal_combo, 2, 0, 1, 4);
sci_layout->addWidget(goal_combo, 2, 0, 1, 3);
goal_combo->setSizePolicy(size_fixed_policy);
sci_layout->addWidget(info_label, 2, 5, 1, 4);
info_label->setSizePolicy(size_fixed_policy);
Expand All @@ -298,6 +310,9 @@ science_report::science_report() : QWidget()
QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&science_report::current_tech_changed);

QObject::connect(refresh_but, &QAbstractButton::pressed, this,
&science_report::push_research);

QObject::connect(goal_combo,
QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&science_report::goal_tech_changed);
Expand Down Expand Up @@ -500,6 +515,12 @@ void science_report::update_report()
researching_combo->setDisabled(false);
goal_combo->setDisabled(false);
}

// If tech leak happens we enable a button to force/push a refresh.
if (done >= total) {
refresh_but->setVisible(true);
}

update_reqtree();
}

Expand Down Expand Up @@ -540,6 +561,18 @@ void science_report::goal_tech_changed(int changed_index)
}
}

/**
* Push (redo) research when qty bulbs researched is
* greater than the number needed
*/
void science_report::push_research()
{
if (can_client_issue_orders()) {
auto research = research_get(client_player());
dsend_packet_player_research(&client.conn, research->researching);
}
}

/**
Update the science report.
*/
Expand Down
3 changes: 3 additions & 0 deletions client/views/view_research.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class QObject;
class QPaintEvent;
class QScrollArea;
class progress_bar;
class QPushButton;

/****************************************************************************
Custom widget representing research diagram in science_report
Expand Down Expand Up @@ -72,6 +73,7 @@ class science_report : public QWidget {

QComboBox *goal_combo;
QComboBox *researching_combo;
QPushButton *refresh_but;
progress_bar *progress;
QLabel *info_label;
QLabel *progress_label;
Expand All @@ -94,6 +96,7 @@ class science_report : public QWidget {
private slots:
void current_tech_changed(int index);
void goal_tech_changed(int index);
void push_research();
};

void popdown_science_report();
Expand Down

0 comments on commit 24dd0e4

Please sign in to comment.