From 3009356c8aec713c46bb34039d6f3311e38abef1 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 1 Oct 2022 20:11:07 +0200 Subject: [PATCH] feat: add Cat support Signed-off-by: Sefa Eyeoglu --- launcher/ui/MainWindow.cpp | 48 +---------------------- launcher/ui/MainWindow.h | 1 - launcher/ui/instanceview/InstanceView.cpp | 32 +++++++++++++++ launcher/ui/instanceview/InstanceView.h | 2 + 4 files changed, 36 insertions(+), 47 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 229ca470a..4fea1529c 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -882,7 +882,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow ui->actionCAT->setChecked(cat_enable); // NOTE: calling the operator like that is an ugly hack to appease ancient gcc... connect(ui->actionCAT.operator->(), SIGNAL(toggled(bool)), SLOT(onCatToggled(bool))); - setCatBackground(cat_enable); + view->setCatDisplayed(cat_enable); } // start instance when double-clicked connect(view, &InstanceView::instanceActivated, this, &MainWindow::instanceActivated); @@ -1469,54 +1469,10 @@ void MainWindow::downloadUpdates(GoUpdate::Status status) void MainWindow::onCatToggled(bool state) { - setCatBackground(state); + view->setCatDisplayed(state); APPLICATION->settings()->set("TheCat", state); } -namespace { -template -T non_stupid_abs(T in) -{ - if (in < 0) - return -in; - return in; -} -} - -void MainWindow::setCatBackground(bool enabled) -{ - if (enabled) - { - QDateTime now = QDateTime::currentDateTime(); - QDateTime birthday(QDate(now.date().year(), 11, 30), QTime(0, 0)); - QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0)); - QString cat; - if(non_stupid_abs(now.daysTo(xmas)) <= 4) { - cat = "catmas"; - } - else if (non_stupid_abs(now.daysTo(birthday)) <= 12) { - cat = "cattiversary"; - } - else { - cat = "kitteh"; - } - view->setStyleSheet(QString(R"( -InstanceView -{ - background-image: url(:/backgrounds/%1); - background-attachment: fixed; - background-clip: padding; - background-position: top right; - background-repeat: none; - background-color:palette(base); -})").arg(cat)); - } - else - { - view->setStyleSheet(QString()); - } -} - void MainWindow::runModalTask(Task *task) { connect(task, &Task::failed, [this](QString reason) diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h index e438f8fe1..511967105 100644 --- a/launcher/ui/MainWindow.h +++ b/launcher/ui/MainWindow.h @@ -212,7 +212,6 @@ private: void addInstance(QString url = QString()); void activateInstance(InstancePtr instance); - void setCatBackground(bool enabled); void updateInstanceToolIcon(QString new_icon); void setSelectedInstanceById(const QString &id); void updateStatusCenter(); diff --git a/launcher/ui/instanceview/InstanceView.cpp b/launcher/ui/instanceview/InstanceView.cpp index 093ed5a78..1e06a124b 100644 --- a/launcher/ui/instanceview/InstanceView.cpp +++ b/launcher/ui/instanceview/InstanceView.cpp @@ -161,3 +161,35 @@ QModelIndex InstanceView::mappedIndex(const QModelIndex& index) const { return m_proxy->mapToSource(index); } + +void InstanceView::setCatDisplayed(bool enabled) +{ + if (enabled) { + QDateTime now = QDateTime::currentDateTime(); + QDateTime birthday(QDate(now.date().year(), 11, 30), QTime(0, 0)); + QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0)); + QString cat; + if (std::abs(now.daysTo(xmas)) <= 4) { + cat = "catmas"; + } else if (std::abs(now.daysTo(birthday)) <= 12) { + cat = "cattiversary"; + } else { + cat = "kitteh"; + } + setStyleSheet(QString(R"( +* +{ + background-image: url(:/backgrounds/%1); + background-attachment: fixed; + background-clip: padding; + background-position: bottom right; + background-repeat: none; + background-color:palette(base); +})") + .arg(cat)); + m_table->setAlternatingRowColors(false); + } else { + setStyleSheet(QString()); + m_table->setAlternatingRowColors(true); + } +} diff --git a/launcher/ui/instanceview/InstanceView.h b/launcher/ui/instanceview/InstanceView.h index 7eb1871ac..0822e5542 100644 --- a/launcher/ui/instanceview/InstanceView.h +++ b/launcher/ui/instanceview/InstanceView.h @@ -39,6 +39,8 @@ class InstanceView : public QStackedWidget { // save state of current view void storeState(); + void setCatDisplayed(bool enabled); + signals: void instanceActivated(InstancePtr inst); void currentInstanceChanged(InstancePtr current, InstancePtr previous);