Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/UI/ControlMappingScreen.h
5654 views
1
// Copyright (c) 2013- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <functional>
21
#include <memory>
22
#include <set>
23
#include <mutex>
24
#include <vector>
25
#include <string>
26
27
#include "Common/UI/View.h"
28
#include "Common/UI/UIScreen.h"
29
#include "Common/UI/PopupScreens.h"
30
#include "Common/Data/Text/I18n.h"
31
32
#include "Core/ControlMapper.h"
33
34
#include "UI/BaseScreens.h"
35
#include "UI/TabbedDialogScreen.h"
36
#include "UI/SimpleDialogScreen.h"
37
38
class SingleControlMapper;
39
40
class ControlMappingScreen : public UITwoPaneBaseDialogScreen {
41
public:
42
ControlMappingScreen(const Path &gamePath) : UITwoPaneBaseDialogScreen(gamePath, TwoPaneFlags::SettingsInContextMenu | TwoPaneFlags::ContentsCanScroll | TwoPaneFlags::NoTopbarInLandscape) {
43
categoryToggles_[0] = true;
44
categoryToggles_[1] = true;
45
categoryToggles_[2] = true;
46
categoryToggles_[3] = false;
47
}
48
const char *tag() const override { return "ControlMapping"; }
49
50
protected:
51
void CreateSettingsViews(UI::ViewGroup *parent) override;
52
void CreateContentViews(UI::ViewGroup *parent) override;
53
void update() override;
54
55
std::string_view GetTitle() const override;
56
57
private:
58
void OnAutoConfigure(UI::EventParams &params);
59
60
void dialogFinished(const Screen *dialog, DialogResult result) override;
61
62
std::vector<SingleControlMapper *> mappers_;
63
int keyMapGeneration_ = -1;
64
65
bool categoryToggles_[10]{};
66
};
67
68
class KeyMappingNewKeyDialog : public UI::PopupScreen {
69
public:
70
explicit KeyMappingNewKeyDialog(int btn, bool replace, std::function<void(KeyMap::MultiInputMapping)> callback, I18NCat i18n)
71
: PopupScreen(T(i18n, "Map Key"), "Cancel", ""), pspBtn_(btn), callback_(callback) {}
72
73
const char *tag() const override { return "KeyMappingNewKey"; }
74
75
bool key(const KeyInput &key) override;
76
void axis(const AxisInput &axis) override;
77
78
void SetDelay(float t);
79
80
protected:
81
void CreatePopupContents(UI::ViewGroup *parent) override;
82
83
bool FillVertical() const override { return false; }
84
bool ShowButtons() const override { return true; }
85
void OnCompleted(DialogResult result) override {}
86
87
private:
88
int pspBtn_;
89
std::function<void(KeyMap::MultiInputMapping)> callback_;
90
91
KeyMap::MultiInputMapping mapping_;
92
93
UI::View *comboMappingsNotEnabled_ = nullptr;
94
95
// We need to do our own detection for axis "keyup" here.
96
std::set<InputMapping> triggeredAxes_;
97
98
double delayUntil_ = 0.0f;
99
};
100
101
class KeyMappingNewMouseKeyDialog : public UI::PopupScreen {
102
public:
103
KeyMappingNewMouseKeyDialog(int btn, bool replace, std::function<void(KeyMap::MultiInputMapping)> callback, I18NCat i18n)
104
: PopupScreen(T(i18n, "Map Mouse"), "", ""), callback_(callback) {}
105
~KeyMappingNewMouseKeyDialog() {
106
g_IsMappingMouseInput = false;
107
}
108
109
const char *tag() const override { return "KeyMappingNewMouseKey"; }
110
111
bool key(const KeyInput &key) override;
112
void axis(const AxisInput &axis) override;
113
114
protected:
115
void CreatePopupContents(UI::ViewGroup *parent) override;
116
117
bool FillVertical() const override { return false; }
118
bool ShowButtons() const override { return true; }
119
void OnCompleted(DialogResult result) override {}
120
121
private:
122
std::function<void(KeyMap::MultiInputMapping)> callback_;
123
bool mapped_ = false; // Prevent double registrations
124
};
125
126
class JoystickHistoryView;
127
128
class AnalogCalibrationScreen : public UITwoPaneBaseDialogScreen {
129
public:
130
AnalogCalibrationScreen(const Path &gamePath);
131
132
bool key(const KeyInput &key) override;
133
void axis(const AxisInput &axis) override;
134
135
void update() override;
136
137
const char *tag() const override { return "AnalogSetup"; }
138
139
protected:
140
void CreateSettingsViews(UI::ViewGroup *parent) override;
141
void CreateContentViews(UI::ViewGroup *parent) override;
142
143
std::string_view GetTitle() const override;
144
private:
145
void OnResetToDefaults(UI::EventParams &e);
146
147
ControlMapper mapper_;
148
149
float analogX_[2]{};
150
float analogY_[2]{};
151
float rawX_[2]{};
152
float rawY_[2]{};
153
154
JoystickHistoryView *stickView_[2]{};
155
};
156
157
class MockPSP;
158
159
class VisualMappingScreen : public UIBaseDialogScreen {
160
public:
161
VisualMappingScreen(const Path &gamePath) : UIBaseDialogScreen(gamePath) {}
162
163
const char *tag() const override { return "VisualMapping"; }
164
165
bool key(const KeyInput &key) override;
166
void axis(const AxisInput &axis) override;
167
168
protected:
169
void CreateViews() override;
170
171
void dialogFinished(const Screen *dialog, DialogResult result) override;
172
void resized() override;
173
174
private:
175
void OnMapButton(UI::EventParams &e);
176
void OnBindAll(UI::EventParams &e);
177
void HandleKeyMapping(const KeyMap::MultiInputMapping &key);
178
void MapNext(bool successive);
179
180
MockPSP *psp_ = nullptr;
181
int nextKey_ = 0;
182
int bindAll_ = -1;
183
bool replace_ = false;
184
};
185
186