src/platform/qt/GamePakView.cpp (view raw)
1/* Copyright (c) 2013-2014 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include "GamePakView.h"
7
8#include "GameController.h"
9
10extern "C" {
11#include "gba-thread.h"
12}
13
14using namespace QGBA;
15
16GamePakView::GamePakView(GameController* controller, QWidget* parent)
17 : QWidget(parent)
18 , m_controller(controller)
19{
20 m_ui.setupUi(this);
21
22 connect(controller, SIGNAL(gameStarted(GBAThread*)), this, SLOT(gameStarted(GBAThread*)));
23 connect(controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped()));
24 connect(m_ui.lightSpin, SIGNAL(valueChanged(int)), this, SLOT(setLuminanceValue(int)));
25 connect(m_ui.lightSlide, SIGNAL(valueChanged(int)), this, SLOT(setLuminanceValue(int)));
26
27 connect(m_ui.timeNoOverride, SIGNAL(clicked()), controller, SLOT(setRealTime()));
28 connect(m_ui.timeFixed, &QRadioButton::clicked, [controller, this] () {
29 controller->setFixedTime(m_ui.time->dateTime());
30 });
31 connect(m_ui.timeFakeEpoch, &QRadioButton::clicked, [controller, this] () {
32 controller->setFakeEpoch(m_ui.time->dateTime());
33 });
34 connect(m_ui.time, &QDateTimeEdit::dateTimeChanged, [controller, this] (const QDateTime&) {
35 m_ui.timeButtons->checkedButton()->clicked();
36 });
37 connect(m_ui.timeNow, &QPushButton::clicked, [controller, this] () {
38 m_ui.time->setDateTime(QDateTime::currentDateTime());
39 });
40
41 if (controller->isLoaded()) {
42 gameStarted(controller->thread());
43 }
44}
45
46void GamePakView::gameStarted(GBAThread* thread) {
47 if (!thread->gba) {
48 gameStopped();
49 return;
50 }
51 SavedataType savetype = thread->gba->memory.savedata.type;
52 if (m_ui.savetype->currentIndex() > 0) {
53 if (savetype > SAVEDATA_FORCE_NONE) {
54 VFile* vf = thread->gba->memory.savedata.vf;
55 GBASavedataDeinit(&thread->gba->memory.savedata);
56 GBASavedataInit(&thread->gba->memory.savedata, vf);
57 }
58 savetype = static_cast<SavedataType>(m_ui.savetype->currentIndex() - 1);
59 GBASavedataForceType(&thread->gba->memory.savedata, savetype);
60 }
61
62 if (savetype > SAVEDATA_AUTODETECT) {
63 m_ui.savetype->setCurrentIndex(savetype + 1);
64 }
65 m_ui.savetype->setEnabled(false);
66
67 m_ui.sensorRTC->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_RTC);
68 m_ui.sensorGyro->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_GYRO);
69 m_ui.sensorLight->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_LIGHT_SENSOR);
70 m_ui.sensorTilt->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_TILT);
71}
72
73void GamePakView::gameStopped() {
74 m_ui.savetype->setCurrentIndex(0);
75 m_ui.savetype->setEnabled(true);
76
77 m_ui.sensorRTC->setChecked(false);
78 m_ui.sensorGyro->setChecked(false);
79 m_ui.sensorLight->setChecked(false);
80 m_ui.sensorTilt->setChecked(false);
81}
82
83void GamePakView::setLuminanceValue(int value) {
84 bool oldState;
85 value = std::max(0, std::min(value, 255));
86
87 oldState = m_ui.lightSpin->blockSignals(true);
88 m_ui.lightSpin->setValue(value);
89 m_ui.lightSpin->blockSignals(oldState);
90
91 oldState = m_ui.lightSlide->blockSignals(true);
92 m_ui.lightSlide->setValue(value);
93 m_ui.lightSlide->blockSignals(oldState);
94
95 m_controller->setLuminanceValue(value);
96}