mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-13 17:09:05 -05:00
Added support for delta times in profile
This commit is contained in:
@@ -26,12 +26,14 @@ set(HEADER_FILES
|
||||
include/assettreeitem.h
|
||||
include/assettreemodel.h
|
||||
include/camera.h
|
||||
include/deltatimes.h
|
||||
include/filesystemaccess.h
|
||||
include/launcherwindow.h
|
||||
include/profileedit.h
|
||||
include/ui_addedscripts.h
|
||||
include/ui_assets.h
|
||||
include/ui_camera.h
|
||||
include/ui_deltatimes.h
|
||||
include/ui_editorwindow.h
|
||||
include/ui_launcherwindow.h
|
||||
)
|
||||
@@ -42,6 +44,7 @@ set(SOURCE_FILES
|
||||
src/assettreeitem.cpp
|
||||
src/assettreemodel.cpp
|
||||
src/camera.cpp
|
||||
src/deltatimes.cpp
|
||||
src/filesystemaccess.cpp
|
||||
src/launcherwindow.cpp
|
||||
src/profileedit.cpp
|
||||
|
||||
100
apps/OpenSpace/ext/launcher/include/deltatimes.h
Normal file
100
apps/OpenSpace/ext/launcher/include/deltatimes.h
Normal file
@@ -0,0 +1,100 @@
|
||||
#ifndef DELTATIMES_H
|
||||
#define DELTATIMES_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QWidget>
|
||||
#include <QListWidgetItem>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class deltaTimes;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
static const int _defaultDeltaTimes[30] = {
|
||||
1, 2, 5, 10, 30,
|
||||
60, 120, 300, 600, 1800,
|
||||
3600, 7200, 10800, 21600, 43200,
|
||||
86400, 172800, 345600, 604800, 1209600,
|
||||
2592000, 5184000, 7776000, 15552000, 31536000,
|
||||
63072000, 157680000, 315360000, 630720000, 1576800000
|
||||
};
|
||||
|
||||
struct DeltaTimes {
|
||||
std::vector<int> _times;
|
||||
DeltaTimes() {
|
||||
_times.resize(sizeof(_defaultDeltaTimes)/sizeof(int));
|
||||
};
|
||||
DeltaTimes(std::vector<int>& dt) {
|
||||
_times = dt;
|
||||
};
|
||||
void loadValues(std::vector<int>& dt) {
|
||||
for (size_t i = 0; i < dt.size(); ++i) {
|
||||
_times[i] = dt[i];
|
||||
}
|
||||
}
|
||||
size_t size() {
|
||||
auto it = find(_times.begin(), _times.end(), 0);
|
||||
return std::distance(_times.begin(), it);
|
||||
};
|
||||
size_t totalSize() {
|
||||
return sizeof(_defaultDeltaTimes) / sizeof(int);
|
||||
}
|
||||
};
|
||||
|
||||
class deltaTimes : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
void listItemSelected();
|
||||
void saveDeltaTimeValue();
|
||||
void clearDeltaTimeValue();
|
||||
void parseSelections();
|
||||
|
||||
public:
|
||||
explicit deltaTimes(DeltaTimes& _imported, QWidget *parent = nullptr);
|
||||
~deltaTimes();
|
||||
void setDeltaTimes(std::vector<int>& dt);
|
||||
QString createSummaryForDeltaTime(size_t idx, int dt, bool forListView);
|
||||
struct timeIntervals {
|
||||
int index;
|
||||
int secondsPerInterval;
|
||||
QString intervalName;
|
||||
};
|
||||
|
||||
const int secondsPerYear = 31536000;
|
||||
const int secondsPerMonth = 18144000;
|
||||
const int secondsPerWeek = 604800;
|
||||
const int secondsPerDay = 86400;
|
||||
const int secondsPerHour = 3600;
|
||||
const int secondsPerMinute = 60;
|
||||
|
||||
private:
|
||||
QString timeDescription(int value);
|
||||
bool checkForTimeDescription(QString& description, QString unit,
|
||||
int interval, int value);
|
||||
QString checkForTimeDescription(int intervalIndex, int value);
|
||||
int lastSelectableItem();
|
||||
bool isNumericalValue(QLineEdit* le);
|
||||
|
||||
Ui::deltaTimes *ui;
|
||||
QWidget* _parent;
|
||||
|
||||
DeltaTimes& _imported;
|
||||
DeltaTimes _data;
|
||||
std::vector<std::string> _deltaTimeStrings;
|
||||
std::vector<QListWidgetItem*> _deltaListItems;
|
||||
|
||||
std::vector<timeIntervals> _timeIntervals = {
|
||||
{0, 31536000, "year"},
|
||||
{1, 18144000, "month"},
|
||||
{2, 604800, "week"},
|
||||
{3, 86400, "day"},
|
||||
{4, 3600, "hour"},
|
||||
{5, 60, "minute"},
|
||||
{6, 1, "second"},
|
||||
};
|
||||
};
|
||||
|
||||
#endif // DELTATIMES_H
|
||||
95
apps/OpenSpace/ext/launcher/include/ui_deltatimes.h
Normal file
95
apps/OpenSpace/ext/launcher/include/ui_deltatimes.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/********************************************************************************
|
||||
** Form generated from reading UI file 'deltaTimes.ui'
|
||||
**
|
||||
** Created by: Qt User Interface Compiler version 5.15.0
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef UI_DELTATIMES_H
|
||||
#define UI_DELTATIMES_H
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <QtWidgets/QDialogButtonBox>
|
||||
#include <QtWidgets/QLabel>
|
||||
#include <QtWidgets/QLineEdit>
|
||||
#include <QtWidgets/QListWidget>
|
||||
#include <QtWidgets/QPushButton>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class Ui_deltaTimes
|
||||
{
|
||||
public:
|
||||
QDialogButtonBox *buttonBox;
|
||||
QLabel *label_module;
|
||||
QListWidget *listWidget;
|
||||
QLabel *label_adjust;
|
||||
QPushButton *button_save;
|
||||
QPushButton *button_remove;
|
||||
QLineEdit *line_seconds;
|
||||
|
||||
void setupUi(QDialog *deltaTimes)
|
||||
{
|
||||
if (deltaTimes->objectName().isEmpty())
|
||||
deltaTimes->setObjectName(QString::fromUtf8("deltaTimes"));
|
||||
deltaTimes->resize(531, 439);
|
||||
buttonBox = new QDialogButtonBox(deltaTimes);
|
||||
buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
|
||||
buttonBox->setGeometry(QRect(170, 390, 341, 32));
|
||||
buttonBox->setOrientation(Qt::Horizontal);
|
||||
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
|
||||
label_module = new QLabel(deltaTimes);
|
||||
label_module->setObjectName(QString::fromUtf8("label_module"));
|
||||
label_module->setGeometry(QRect(20, 20, 141, 20));
|
||||
QFont font;
|
||||
font.setFamily(QString::fromUtf8("Arial"));
|
||||
font.setPointSize(12);
|
||||
label_module->setFont(font);
|
||||
listWidget = new QListWidget(deltaTimes);
|
||||
listWidget->setObjectName(QString::fromUtf8("listWidget"));
|
||||
listWidget->setGeometry(QRect(20, 50, 381, 171));
|
||||
listWidget->setAutoScroll(true);
|
||||
listWidget->setLayoutMode(QListView::SinglePass);
|
||||
label_adjust = new QLabel(deltaTimes);
|
||||
label_adjust->setObjectName(QString::fromUtf8("label_adjust"));
|
||||
label_adjust->setGeometry(QRect(20, 284, 421, 20));
|
||||
label_adjust->setFont(font);
|
||||
button_save = new QPushButton(deltaTimes);
|
||||
button_save->setObjectName(QString::fromUtf8("button_save"));
|
||||
button_save->setGeometry(QRect(20, 354, 71, 25));
|
||||
button_remove = new QPushButton(deltaTimes);
|
||||
button_remove->setObjectName(QString::fromUtf8("button_remove"));
|
||||
button_remove->setGeometry(QRect(20, 230, 151, 25));
|
||||
line_seconds = new QLineEdit(deltaTimes);
|
||||
line_seconds->setObjectName(QString::fromUtf8("line_seconds"));
|
||||
line_seconds->setGeometry(QRect(20, 310, 191, 31));
|
||||
line_seconds->setFont(font);
|
||||
|
||||
retranslateUi(deltaTimes);
|
||||
//QObject::connect(buttonBox, SIGNAL(accepted()), deltaTimes, SLOT(accept()));
|
||||
QObject::connect(buttonBox, SIGNAL(rejected()), deltaTimes, SLOT(reject()));
|
||||
|
||||
QMetaObject::connectSlotsByName(deltaTimes);
|
||||
} // setupUi
|
||||
|
||||
void retranslateUi(QDialog *deltaTimes)
|
||||
{
|
||||
deltaTimes->setWindowTitle(QCoreApplication::translate("deltaTimes", "Delta Time Steps", nullptr));
|
||||
label_module->setText(QCoreApplication::translate("deltaTimes", "Delta Times", nullptr));
|
||||
label_adjust->setText(QCoreApplication::translate("deltaTimes", "Set Delta Time for key", nullptr));
|
||||
button_save->setText(QCoreApplication::translate("deltaTimes", "Save", nullptr));
|
||||
button_remove->setText(QCoreApplication::translate("deltaTimes", "Remove Last Entry", nullptr));
|
||||
} // retranslateUi
|
||||
|
||||
};
|
||||
|
||||
namespace Ui {
|
||||
class deltaTimes: public Ui_deltaTimes {};
|
||||
} // namespace Ui
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // UI_DELTATIMES_H
|
||||
155
apps/OpenSpace/ext/launcher/src/deltatimes.cpp
Normal file
155
apps/OpenSpace/ext/launcher/src/deltatimes.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
#include "deltatimes.h"
|
||||
#include "./ui_deltatimes.h"
|
||||
#include <qevent.h>
|
||||
|
||||
deltaTimes::deltaTimes(DeltaTimes& imported, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::deltaTimes)
|
||||
, _imported(imported)
|
||||
, _data(imported)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
for (size_t d = 0; d < _data.totalSize(); ++d) {
|
||||
QString summary = createSummaryForDeltaTime(d, _data._times.at(d), true);
|
||||
_deltaListItems.push_back(new QListWidgetItem(summary));
|
||||
ui->listWidget->addItem(_deltaListItems[d]);
|
||||
}
|
||||
connect(ui->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(listItemSelected()));
|
||||
connect(ui->button_save, SIGNAL(clicked()), this, SLOT(saveDeltaTimeValue()));
|
||||
connect(ui->button_remove, SIGNAL(clicked()), this, SLOT(clearDeltaTimeValue()));
|
||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(parseSelections()));
|
||||
}
|
||||
|
||||
QString deltaTimes::createSummaryForDeltaTime(size_t idx, int dt, bool forListView) {
|
||||
std::string s;
|
||||
int k = (idx%10 == 9) ? 0 : idx%10 + 1;
|
||||
k = (idx == 0) ? 1 : k;
|
||||
if (idx >= 20) {
|
||||
s = "shift + " + std::to_string(k);
|
||||
}
|
||||
else if (idx >= 10) {
|
||||
s = "ctrl + " + std::to_string(k);
|
||||
}
|
||||
else {
|
||||
s = std::to_string(k);
|
||||
if (forListView) {
|
||||
s += " ";
|
||||
}
|
||||
}
|
||||
|
||||
if (dt != 0) {
|
||||
s += (forListView) ? "\t" + std::to_string(dt) : "";
|
||||
}
|
||||
|
||||
if (forListView) {
|
||||
s += "\t";
|
||||
s += timeDescription(dt).toUtf8().constData();
|
||||
}
|
||||
return QString(s.c_str());
|
||||
}
|
||||
|
||||
void deltaTimes::listItemSelected() {
|
||||
QListWidgetItem *item = ui->listWidget->currentItem();
|
||||
int index = ui->listWidget->row(item);
|
||||
|
||||
if (index < (static_cast<int>(_data.totalSize()) - 1)) {
|
||||
if (index > lastSelectableItem() + 1) {
|
||||
index = lastSelectableItem() + 1;
|
||||
ui->listWidget->setCurrentRow(index);
|
||||
}
|
||||
}
|
||||
|
||||
QString labelS = "Set Delta Time for key ";
|
||||
labelS += createSummaryForDeltaTime(index, _data._times.at(index), false);
|
||||
labelS += " :\t";
|
||||
|
||||
ui->label_adjust->setText(labelS);
|
||||
ui->line_seconds->setText(QString::number(_data._times.at(index)));
|
||||
}
|
||||
|
||||
int deltaTimes::lastSelectableItem() {
|
||||
int i;
|
||||
for (i = _data.size() - 1; i >= 0; --i) {
|
||||
if (_data._times.at(i) != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i < 0) {
|
||||
return 0;
|
||||
}
|
||||
else if (i == (static_cast<int>(_data.size()) - 1)) {
|
||||
return _data.size() - 1;
|
||||
}
|
||||
else {
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
QString deltaTimes::timeDescription(int value) {
|
||||
QString description;
|
||||
|
||||
if (value == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < _timeIntervals.size(); ++i) {
|
||||
if (value >= _timeIntervals[i].secondsPerInterval) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return checkForTimeDescription(i, value);
|
||||
}
|
||||
|
||||
QString deltaTimes::checkForTimeDescription(int intervalIndex, int value) {
|
||||
float amount = static_cast<float>(value) /
|
||||
static_cast<float>(_timeIntervals[intervalIndex].secondsPerInterval);
|
||||
QString description = QString::number(amount, 'g', 2);
|
||||
return description += " " + _timeIntervals[intervalIndex].intervalName + "/sec";
|
||||
}
|
||||
|
||||
void deltaTimes::saveDeltaTimeValue() {
|
||||
QListWidgetItem *item = ui->listWidget->currentItem();
|
||||
int index = ui->listWidget->row(item);
|
||||
if (isNumericalValue(ui->line_seconds) && index <= lastSelectableItem() + 1) {
|
||||
_data._times.at(index) = ui->line_seconds->text().toInt();
|
||||
QString summary = createSummaryForDeltaTime(index, _data._times.at(index), true);
|
||||
_deltaListItems.at(index)->setText(summary);
|
||||
}
|
||||
}
|
||||
|
||||
bool deltaTimes::isNumericalValue(QLineEdit* le) {
|
||||
QString s = le->text();
|
||||
bool validConversion = false;
|
||||
s.toInt(&validConversion);
|
||||
return validConversion;
|
||||
}
|
||||
|
||||
void deltaTimes::clearDeltaTimeValue() {
|
||||
int i;
|
||||
for (i = _data.size() - 1; i >= 0; --i) {
|
||||
if (_data._times.at(i) != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= 0) {
|
||||
_data._times.at(i) = 0;
|
||||
QString summary = createSummaryForDeltaTime(i, _data._times.at(i), true);
|
||||
_deltaListItems.at(i)->setText(summary);
|
||||
ui->listWidget->setCurrentRow(i);
|
||||
}
|
||||
}
|
||||
|
||||
void deltaTimes::parseSelections() {
|
||||
_imported = _data;
|
||||
accept();
|
||||
}
|
||||
|
||||
deltaTimes::~deltaTimes() {
|
||||
for (auto d : _deltaListItems) {
|
||||
delete d;
|
||||
}
|
||||
delete ui;
|
||||
}
|
||||
167
apps/OpenSpace/ext/launcher/src/deltatimes.ui
Normal file
167
apps/OpenSpace/ext/launcher/src/deltatimes.ui
Normal file
@@ -0,0 +1,167 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>deltaTimes</class>
|
||||
<widget class="QDialog" name="deltaTimes">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>531</width>
|
||||
<height>439</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Delta Time Steps</string>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>170</x>
|
||||
<y>390</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_module">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>141</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delta Times</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QListWidget" name="listWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>50</y>
|
||||
<width>381</width>
|
||||
<height>171</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="autoScroll">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="layoutMode">
|
||||
<enum>QListView::SinglePass</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_adjust">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>284</y>
|
||||
<width>421</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Set Delta Time for key</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="button_save">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>354</y>
|
||||
<width>71</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="button_remove">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>230</y>
|
||||
<width>151</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove Last Entry</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="line_seconds">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>310</y>
|
||||
<width>191</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Enter number of simulated seconds to elapse per actual second for the particular delta time</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>deltaTimes</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>deltaTimes</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user