-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsApp.cpp
More file actions
181 lines (148 loc) · 4.34 KB
/
SettingsApp.cpp
File metadata and controls
181 lines (148 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include "SettingsApp.h"
#include "HalImpl.h"
#include "src/Settings/ListSettingsItem.h"
#include "src/Framework/Game.h"
#include "src/Framework/JeopardyGame.h"
#include "src/Framework/BrainRingGame.h"
#include "src/Framework/QuestionsGame.h"
#include "EightButtonsApp.h"
using namespace vgs;
IApp* createGame(const GameConfig& config)
{
return new Game(config);
}
IApp* createJeopardyGame(const GameConfig& config)
{
return new JeopardyGame(config);
}
IApp* createBrainRingGame(const GameConfig& config, int primaryTime, int secondaryTime)
{
GameConfig newConfig = config;
newConfig.time.primary = primaryTime;
newConfig.time.secondary = secondaryTime;
return new BrainRingGame(newConfig);
}
IApp* createBrainRingGame60(const GameConfig& config)
{
return createBrainRingGame(config, 60, 20);
}
IApp* createBrainRingGame40(const GameConfig& config)
{
return createBrainRingGame(config, 40, 20);
}
IApp* createQuestionsGame(const GameConfig& config)
{
return new QuestionsGame(config);
}
IApp* createEightButtonsApp(const GameConfig& config)
{
return new EightButtonsApp();
}
typedef IApp* (*GameConstructor)(const GameConfig&);
constexpr int gameCount = 6;
constexpr GameConstructor gameConstructors[gameCount] = {createGame, createJeopardyGame, createBrainRingGame60, createBrainRingGame40, createQuestionsGame, createEightButtonsApp};
constexpr const char* gameNames[gameCount] = {"БЕЗ ОТСЧЕТА", "СВОЯ ИГРА", "БРЕЙН-РИНГ 60+20", "БРЕЙН-РИНГ 40+20", "ЧГК", "8 КНОПОК"};
constexpr const char* modeNames[3] = {"БЕЗ ФАЛЬСТАРТОВ", "С ФАЛЬСТАРТАМИ", "ХАМСА"};
constexpr const char* onOffNames[2] = {"ВКЛ", "ВЫКЛ"};
constexpr const char* linkModes[2] = {"V1 (устаревший)", "V2 (обычный)"};
SettingsApp::SettingsApp(bool launchGame) : m_launchGame(launchGame)
{
m_settings.addItem(new settings::ListSettingsItem("Тип игры", gameCount, gameNames));
m_settings.addItem(new settings::ListSettingsItem("Режим", 3, modeNames));
m_settings.addItem(new settings::ListSettingsItem("Звук", 2, onOffNames));
m_settings.addItem(new settings::ListSettingsItem("Свет", 2, onOffNames));
m_settings.addItem(new settings::ListSettingsItem("Link", 2, linkModes));
}
void SettingsApp::init(IHal& hal)
{
HalImpl* halImpl = (HalImpl*) &hal;
halImpl->loadSettings(m_settings);
if(m_launchGame)
{
m_launchGame = false;
exit(hal);
}
}
void SettingsApp::tick(IHal& hal)
{
if(m_shouldClose)
{
return;
}
process(hal);
if(m_displayDirty)
{
CustomDisplayInfo info;
info.type = DisplayInfoSettings;
info.data = (void*)&m_settings;
hal.updateDisplay(info);
m_displayDirty = false;
}
}
void SettingsApp::process(IHal& hal)
{
ButtonState buttonState = hal.getButtonState();
if(buttonState.menu)
{
exit(hal);
return;
}
if(buttonState.enter)
{
m_settings.moveNext();
m_displayDirty = true;
return;
}
if(buttonState.start)
{
m_settings.getCurrentItem().increment();
m_displayDirty = true;
m_settingsDirty = true;
return;
}
if(buttonState.stop)
{
m_settings.getCurrentItem().decrement();
m_displayDirty = true;
m_settingsDirty = true;
return;
}
}
void SettingsApp::exit(IHal& hal)
{
HalImpl* halImpl = (HalImpl*) &hal;
if(m_settingsDirty)
{
halImpl->saveSettings(m_settings);
m_settingsDirty = false;
}
int settingsState[m_settings.size()];
m_settings.dumpData(settingsState);
int soundMode = settingsState[2];
bool signalLightDisabled = settingsState[3];
int linkVersion = settingsState[4];
halImpl->setSoundMode(static_cast<HalSoundMode>(soundMode));
halImpl->setSignalLightEnabled(!signalLightDisabled);
halImpl->setLinkVersion(static_cast<vgs::link::UartLinkVersion>(linkVersion));
m_shouldClose = true;
}
AppChangeType SettingsApp::appChangeNeeded()
{
if(m_shouldClose)
{
m_displayDirty = true;
m_shouldClose = false;
return AppChangeType::Custom;
}
return AppChangeType::None;
}
IApp* SettingsApp::createCustomApp()
{
int settingsState[m_settings.size()];
m_settings.dumpData(settingsState);
int gameNumber = settingsState[0];
GameConfig config;
config.displayed_name = gameNames[gameNumber];
config.mode = static_cast<GameMode>(settingsState[1]);
return gameConstructors[gameNumber](config);
}