Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/UI/ControlMappingScreen.h
3185 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/Data/Text/I18n.h"
30
31
#include "Core/ControlMapper.h"
32
33
#include "UI/MiscScreens.h"
34
35
class SingleControlMapper;
36
37
class ControlMappingScreen : public UIDialogScreenWithGameBackground {
38
public:
39
explicit ControlMappingScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {
40
categoryToggles_[0] = true;
41
categoryToggles_[1] = true;
42
categoryToggles_[2] = true;
43
categoryToggles_[3] = false;
44
}
45
const char *tag() const override { return "ControlMapping"; }
46
47
protected:
48
void CreateViews() override;
49
void update() override;
50
51
private:
52
UI::EventReturn OnAutoConfigure(UI::EventParams &params);
53
54
void dialogFinished(const Screen *dialog, DialogResult result) override;
55
56
UI::ScrollView *rightScroll_ = nullptr;
57
std::vector<SingleControlMapper *> mappers_;
58
int keyMapGeneration_ = -1;
59
60
bool categoryToggles_[10]{};
61
};
62
63
class KeyMappingNewKeyDialog : public PopupScreen {
64
public:
65
explicit KeyMappingNewKeyDialog(int btn, bool replace, std::function<void(KeyMap::MultiInputMapping)> callback, I18NCat i18n)
66
: PopupScreen(T(i18n, "Map Key"), "Cancel", ""), pspBtn_(btn), callback_(callback) {}
67
68
const char *tag() const override { return "KeyMappingNewKey"; }
69
70
bool key(const KeyInput &key) override;
71
void axis(const AxisInput &axis) override;
72
73
void SetDelay(float t);
74
75
protected:
76
void CreatePopupContents(UI::ViewGroup *parent) override;
77
78
bool FillVertical() const override { return false; }
79
bool ShowButtons() const override { return true; }
80
void OnCompleted(DialogResult result) override {}
81
82
private:
83
int pspBtn_;
84
std::function<void(KeyMap::MultiInputMapping)> callback_;
85
86
KeyMap::MultiInputMapping mapping_;
87
88
UI::View *comboMappingsNotEnabled_ = nullptr;
89
90
// We need to do our own detection for axis "keyup" here.
91
std::set<InputMapping> triggeredAxes_;
92
93
double delayUntil_ = 0.0f;
94
};
95
96
class KeyMappingNewMouseKeyDialog : public PopupScreen {
97
public:
98
KeyMappingNewMouseKeyDialog(int btn, bool replace, std::function<void(KeyMap::MultiInputMapping)> callback, I18NCat i18n)
99
: PopupScreen(T(i18n, "Map Mouse"), "", ""), callback_(callback) {}
100
~KeyMappingNewMouseKeyDialog() {
101
g_IsMappingMouseInput = false;
102
}
103
104
const char *tag() const override { return "KeyMappingNewMouseKey"; }
105
106
bool key(const KeyInput &key) override;
107
void axis(const AxisInput &axis) override;
108
109
protected:
110
void CreatePopupContents(UI::ViewGroup *parent) override;
111
112
bool FillVertical() const override { return false; }
113
bool ShowButtons() const override { return true; }
114
void OnCompleted(DialogResult result) override {}
115
116
private:
117
std::function<void(KeyMap::MultiInputMapping)> callback_;
118
bool mapped_ = false; // Prevent double registrations
119
};
120
121
class JoystickHistoryView;
122
123
class AnalogSetupScreen : public UIDialogScreenWithGameBackground {
124
public:
125
AnalogSetupScreen(const Path &gamePath);
126
127
bool key(const KeyInput &key) override;
128
void axis(const AxisInput &axis) override;
129
130
void update() override;
131
132
const char *tag() const override { return "AnalogSetup"; }
133
134
protected:
135
void CreateViews() override;
136
137
private:
138
UI::EventReturn OnResetToDefaults(UI::EventParams &e);
139
140
ControlMapper mapper_;
141
142
float analogX_[2]{};
143
float analogY_[2]{};
144
float rawX_[2]{};
145
float rawY_[2]{};
146
147
JoystickHistoryView *stickView_[2]{};
148
};
149
150
class MockPSP;
151
152
class VisualMappingScreen : public UIDialogScreenWithGameBackground {
153
public:
154
VisualMappingScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {}
155
156
const char *tag() const override { return "VisualMapping"; }
157
158
bool key(const KeyInput &key) override;
159
void axis(const AxisInput &axis) override;
160
161
protected:
162
void CreateViews() override;
163
164
void dialogFinished(const Screen *dialog, DialogResult result) override;
165
void resized() override;
166
167
private:
168
UI::EventReturn OnMapButton(UI::EventParams &e);
169
UI::EventReturn OnBindAll(UI::EventParams &e);
170
void HandleKeyMapping(const KeyMap::MultiInputMapping &key);
171
void MapNext(bool successive);
172
173
MockPSP *psp_ = nullptr;
174
int nextKey_ = 0;
175
int bindAll_ = -1;
176
bool replace_ = false;
177
};
178
179