forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow_input_settings.cpp
106 lines (82 loc) · 2.78 KB
/
window_input_settings.cpp
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
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
// Headers
#include "window_input_settings.h"
#include "bitmap.h"
#include "input_buttons.h"
#include "window_selectable.h"
Window_InputSettings::Window_InputSettings(int ix, int iy, int iwidth, int iheight) :
Window_Selectable(ix, iy, iwidth, iheight) {
column_max = 2;
SetContents(Bitmap::Create(width - 16, height - 16));
}
Input::InputButton Window_InputSettings::GetInputButton() const {
return button;
}
void Window_InputSettings::SetInputButton(Input::InputButton button) {
this->button = button;
Refresh();
}
bool Window_InputSettings::RemoveMapping() {
int index = GetIndex();
int i = 0;
auto& mappings = Input::GetInputSource()->GetButtonMappings();
for (auto ki = mappings.LowerBound(button); ki != mappings.end() && ki->first == button; ++ki) {
if (i == index) {
auto key = static_cast<Input::Keys::InputKey>(ki->second);
mappings.Remove({button, key});
Refresh();
break;
}
++i;
}
return true;
}
void Window_InputSettings::ResetMapping() {
Input::ResetDefaultMapping(button);
Refresh();
}
void Window_InputSettings::Refresh() {
contents->Clear();
auto& mappings = Input::GetInputSource()->GetButtonMappings();
auto custom_names = Input::GetInputKeyNames();
std::vector<std::string> items;
std::stringstream ss;
for (auto ki = mappings.LowerBound(button); ki != mappings.end() && ki->first == button;++ki) {
auto key = static_cast<Input::Keys::InputKey>(ki->second);
auto custom_name = std::find_if(custom_names.begin(), custom_names.end(), [&](auto& key_pair) {
return key_pair.first == key;
});
if (custom_name != custom_names.end()) {
items.push_back(custom_name->second);
} else {
items.push_back(Input::Keys::kInputKeyNames.tag(key));
}
}
if (items.size() > mapping_limit) {
items.resize(mapping_limit);
}
item_max = static_cast<int>(items.size());
for (int i = 0; i < item_max; ++i) {
Rect rect = GetItemRect(i);
contents->ClearRect(rect);
const std::string& text = items[i];
bool enabled = true;
Font::SystemColor color = enabled ? Font::ColorDefault : Font::ColorDisabled;
contents->TextDraw(rect.x, rect.y, color, text);
}
}