NOISSUE Add Konami Code

Fun little thing for hiding extra debug options in the future.
This commit is contained in:
Petr Mrázek 2018-03-15 09:27:45 +01:00
parent ea151ca9d4
commit 303842a19e
5 changed files with 80 additions and 0 deletions

View File

@ -31,6 +31,10 @@ SET(MULTIMC_SOURCES
ColorCache.cpp ColorCache.cpp
HoeDown.h HoeDown.h
# Super secret!
KonamiCode.h
KonamiCode.cpp
# GUI - windows # GUI - windows
MainWindow.h MainWindow.h
MainWindow.cpp MainWindow.cpp

View File

@ -0,0 +1,42 @@
#include "KonamiCode.h"
#include <array>
#include <QDebug>
namespace {
const std::array<Qt::Key, 10> konamiCode =
{
Qt::Key_Up, Qt::Key_Up,
Qt::Key_Down, Qt::Key_Down,
Qt::Key_Left, Qt::Key_Right,
Qt::Key_Left, Qt::Key_Right,
Qt::Key_B, Qt::Key_A
};
}
KonamiCode::KonamiCode(QObject* parent) : QObject(parent)
{
}
void KonamiCode::input(QEvent* event)
{
if( event->type() == QEvent::KeyPress )
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>( event );
auto key = Qt::Key(keyEvent->key());
if(key == konamiCode[m_progress])
{
m_progress ++;
}
else
{
m_progress = 0;
}
if(m_progress == konamiCode.size())
{
m_progress = 0;
emit triggered();
}
}
}

17
application/KonamiCode.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <QKeyEvent>
class KonamiCode : public QObject
{
Q_OBJECT
public:
KonamiCode(QObject *parent = 0);
void input(QEvent *event);
signals:
void triggered();
private:
int m_progress = 0;
};

View File

@ -89,6 +89,7 @@
#include <FolderInstanceProvider.h> #include <FolderInstanceProvider.h>
#include <InstanceImportTask.h> #include <InstanceImportTask.h>
#include "UpdateController.h" #include "UpdateController.h"
#include "KonamiCode.h"
// WHY: to hold the pre-translation strings together with the T pointer, so it can be retranslated without a lot of ugly code // WHY: to hold the pre-translation strings together with the T pointer, so it can be retranslated without a lot of ugly code
template <typename T> template <typename T>
@ -631,6 +632,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
connect(q, SIGNAL(activated()), qApp, SLOT(quit())); connect(q, SIGNAL(activated()), qApp, SLOT(quit()));
} }
// Konami Code
{
secretEventFilter = new KonamiCode(this);
connect(secretEventFilter, &KonamiCode::triggered, this, &MainWindow::konamiTriggered);
}
// Add the news label to the news toolbar. // Add the news label to the news toolbar.
{ {
m_newsChecker.reset(new NewsChecker(BuildConfig.NEWS_RSS_URL)); m_newsChecker.reset(new NewsChecker(BuildConfig.NEWS_RSS_URL));
@ -806,6 +813,11 @@ MainWindow::~MainWindow()
{ {
} }
void MainWindow::konamiTriggered()
{
qDebug() << "Super Secret Mode ACTIVATED!";
}
void MainWindow::skinJobFinished() void MainWindow::skinJobFinished()
{ {
activeAccountChanged(); activeAccountChanged();
@ -1064,6 +1076,7 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *ev)
{ {
if (ev->type() == QEvent::KeyPress) if (ev->type() == QEvent::KeyPress)
{ {
secretEventFilter->input(ev);
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev); QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
switch (keyEvent->key()) switch (keyEvent->key())
{ {

View File

@ -38,6 +38,7 @@ class MinecraftLauncher;
class BaseProfilerFactory; class BaseProfilerFactory;
class GroupView; class GroupView;
class ServerStatus; class ServerStatus;
class KonamiCode;
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
@ -176,6 +177,8 @@ private slots:
void droppedURLs(QList<QUrl> urls); void droppedURLs(QList<QUrl> urls);
void konamiTriggered();
private: private:
void addInstance(QString url = QString()); void addInstance(QString url = QString());
void activateInstance(InstancePtr instance); void activateInstance(InstancePtr instance);
@ -200,6 +203,7 @@ private:
ServerStatus *m_statusRight = nullptr; ServerStatus *m_statusRight = nullptr;
QMenu *accountMenu = nullptr; QMenu *accountMenu = nullptr;
QToolButton *accountMenuButton = nullptr; QToolButton *accountMenuButton = nullptr;
KonamiCode * secretEventFilter = nullptr;
unique_qobject_ptr<NetJob> skin_download_job; unique_qobject_ptr<NetJob> skin_download_job;
unique_qobject_ptr<NewsChecker> m_newsChecker; unique_qobject_ptr<NewsChecker> m_newsChecker;