Qt: Add menu items for adjusting in-game solar levels
Jeffrey Pfau jeffrey@endrift.com
Wed, 21 Jan 2015 01:13:28 -0800
3 files changed,
49 insertions(+),
1 deletions(-)
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -24,6 +24,8 @@
using namespace QGBA; using namespace std; +const int GameController::LUX_LEVELS[10] = { 5, 11, 18, 27, 42, 62, 84, 109, 139, 183 }; + GameController::GameController(QObject* parent) : QObject(parent) , m_drawContext(new uint32_t[256 * 256])@@ -62,6 +64,7 @@ m_lux.readLuminance = [] (GBALuminanceSource* context) {
GameControllerLux* lux = static_cast<GameControllerLux*>(context); return lux->value; }; + setLuminanceLevel(0); m_rtc.p = this; m_rtc.override = GameControllerRTC::NO_OVERRIDE;@@ -417,6 +420,27 @@ void GameController::clearAVStream() {
threadInterrupt(); m_threadContext.stream = nullptr; threadContinue(); +} + +void GameController::setLuminanceValue(uint8_t value) { + m_luxValue = value; + value = std::max<int>(value - 0x16, 0); + m_luxLevel = 10; + for (int i = 0; i < 10; ++i) { + if (value < LUX_LEVELS[i]) { + m_luxLevel = i; + break; + } + } +} + +void GameController::setLuminanceLevel(int level) { + int value = 0x16; + level = std::max(0, std::min(10, level)); + if (level > 0) { + value += LUX_LEVELS[level - 1]; + } + setLuminanceValue(value); } void GameController::setRealTime() {
M
src/platform/qt/GameController.h
→
src/platform/qt/GameController.h
@@ -98,7 +98,11 @@ void setFrameskip(int);
void setTurbo(bool, bool forced = true); void setAVStream(GBAAVStream*); void clearAVStream(); - void setLuminanceValue(uint8_t value) { m_luxValue = value; } + + void setLuminanceValue(uint8_t value); + void setLuminanceLevel(int level); + void increaseLuminanceLevel() { setLuminanceLevel(m_luxLevel + 1); } + void decreaseLuminanceLevel() { setLuminanceLevel(m_luxLevel - 1); } void setRealTime(); void setFixedTime(const QDateTime& time);@@ -154,6 +158,9 @@ GameController* p;
uint8_t value; } m_lux; uint8_t m_luxValue; + int m_luxLevel; + + static const int LUX_LEVELS[10]; struct GameControllerRTC : GBARTCSource { GameController* p;
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -659,6 +659,23 @@ addControlledAction(toolsMenu, gdbWindow, "gdbWindow");
#endif toolsMenu->addSeparator(); + QAction* solarIncrease = new QAction(tr("Increase solar level"), toolsMenu); + connect(solarIncrease, SIGNAL(triggered()), m_controller, SLOT(increaseLuminanceLevel())); + addControlledAction(toolsMenu, solarIncrease, "increaseLuminanceLevel"); + + QAction* solarDecrease = new QAction(tr("Decrease solar level"), toolsMenu); + connect(solarDecrease, SIGNAL(triggered()), m_controller, SLOT(decreaseLuminanceLevel())); + addControlledAction(toolsMenu, solarDecrease, "decreaseLuminanceLevel"); + + QAction* maxSolar = new QAction(tr("Brightest solar level"), toolsMenu); + connect(maxSolar, &QAction::triggered, [this]() { m_controller->setLuminanceLevel(10); }); + addControlledAction(toolsMenu, maxSolar, "maxLuminanceLevel"); + + QAction* minSolar = new QAction(tr("Darkest solar level"), toolsMenu); + connect(minSolar, &QAction::triggered, [this]() { m_controller->setLuminanceLevel(0); }); + addControlledAction(toolsMenu, minSolar, "minLuminanceLevel"); + + toolsMenu->addSeparator(); addControlledAction(toolsMenu, toolsMenu->addAction(tr("Settings..."), this, SLOT(openSettingsWindow())), "settings"); addControlledAction(toolsMenu, toolsMenu->addAction(tr("Edit shortcuts..."), this, SLOT(openShortcutWindow())), "shortcuts");