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
38 if (controller->isLoaded()) {
39 gameStarted(controller->thread());
40 }
41}
42
43void GamePakView::gameStarted(GBAThread* thread) {
44 if (!thread->gba) {
45 gameStopped();
46 return;
47 }
48 SavedataType savetype = thread->gba->memory.savedata.type;
49 if (m_ui.savetype->currentIndex() > 0) {
50 if (savetype > SAVEDATA_NONE) {
51 VFile* vf = thread->gba->memory.savedata.vf;
52 GBASavedataDeinit(&thread->gba->memory.savedata);
53 GBASavedataInit(&thread->gba->memory.savedata, vf);
54 }
55 savetype = static_cast<SavedataType>(m_ui.savetype->currentIndex() - 1);
56 GBASavedataForceType(&thread->gba->memory.savedata, savetype);
57 }
58
59 if (savetype > SAVEDATA_NONE) {
60 m_ui.savetype->setCurrentIndex(savetype + 1);
61 }
62 m_ui.savetype->setEnabled(false);
63
64 m_ui.sensorRTC->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_RTC);
65 m_ui.sensorGyro->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_GYRO);
66 m_ui.sensorLight->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_LIGHT_SENSOR);
67 m_ui.sensorTilt->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_TILT);
68}
69
70void GamePakView::gameStopped() {
71 m_ui.savetype->setCurrentIndex(0);
72 m_ui.savetype->setEnabled(true);
73
74 m_ui.sensorRTC->setChecked(false);
75 m_ui.sensorGyro->setChecked(false);
76 m_ui.sensorLight->setChecked(false);
77 m_ui.sensorTilt->setChecked(false);
78}
79
80void GamePakView::setLuminanceValue(int value) {
81 bool oldState;
82 value = std::max(0, std::min(value, 255));
83
84 oldState = m_ui.lightSpin->blockSignals(true);
85 m_ui.lightSpin->setValue(value);
86 m_ui.lightSpin->blockSignals(oldState);
87
88 oldState = m_ui.lightSlide->blockSignals(true);
89 m_ui.lightSlide->setValue(value);
90 m_ui.lightSlide->blockSignals(oldState);
91
92 m_controller->setLuminanceValue(value);
93}