Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make adding InputSchemes more User friendly #549

Merged
merged 7 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 232 additions & 0 deletions rootex/core/input/input_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,236 @@ Vector2 InputManager::getMousePosition()
return { getMouse()->GetFloat(MouseButton::MouseAxisX), getMouse()->GetFloat(MouseButton::MouseAxisY) };
}

Array<String, 23> InputManager::getMouseButtonNames()
{
static Array<String, 23> mouseKeys = {
"mouse_left",
"mouse_middle",
"mouse_right",
"mouse_3",
"mouse_4",
"mouse_5",
"mouse_6",
"mouse_7",
"mouse_8",
"mouse_9",
"mouse_10",
"mouse_11",
"mouse_12",
"mouse_13",
"mouse_14",
"mouse_15",
"mouse_16",
"mouse_17",
"mouse_18",
"mouse_19",
"mouse_20",
"mouse_x",
"mouse_y"
};
return mouseKeys;
}

Array<String, 166> InputManager::getKeyboardButtonNames()
{
static Array<String, 166> keyboardKeys = {
"escape",
"f1",
"f2",
"f3",
"f4",
"f5",
"f6",
"f7",
"f8",
"f9",
"f10",
"f11",
"f12",
"print",
"scroll_lock",
"break",
"space",
"apostrophe",
"comma",
"minus",
"period",
"slash",
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"semicolon",
"less",
"equal",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
"bracket_left",
"backslash",
"bracket_right",
"grave",
"left",
"right",
"up",
"down",
"insert",
"home",
"delete",
"end",
"page_up",
"page_down",
"num_lock",
"kp_divide",
"kp_multiply",
"kp_subtract",
"kp_add",
"kp_enter",
"kp_insert",
"kp_end",
"kp_down",
"kp_page_down",
"kp_left",
"kp_begin",
"kp_right",
"kp_home",
"kp_up",
"kp_page_up",
"kp_delete",
"back_space",
"tab",
"return",
"caps_lock",
"shift_l",
"ctrl_l",
"super_l",
"alt_l",
"alt_r",
"super_r",
"menu",
"ctrl_r",
"shift_r",
"back",
"soft_left",
"soft_right",
"call",
"endcall",
"star",
"pound",
"dpad_center",
"volume_up",
"volume_down",
"power",
"camera",
"clear",
"symbol",
"explorer",
"envelope",
"equals",
"at",
"headsethook",
"focus",
"plus",
"notification",
"search",
"media_play_pause",
"media_stop",
"media_next",
"media_previous",
"media_rewind",
"media_fast_forward",
"mute",
"pictsymbols",
"switch_charset",
"forward",
"extra_1",
"extra_2",
"extra_3",
"extra_4",
"extra_5",
"extra_6",
"fn",
"circumflex",
"ssharp",
"acute",
"alt_gr",
"numbersign",
"udiaeresis",
"adiaeresis",
"odiaeresis",
"section",
"aring",
"diaeresis",
"twosuperior",
"right_parenthesis",
"dollar",
"ugrave",
"asterisk",
"colon",
"exclam",
"brace_left",
"brace_right",
"sys_rq"
};
return keyboardKeys;
}

Array<String, 20> InputManager::getPadButtonNames()
{
static Array<String, 20> padKeys = {
"pad_left_stick_x",
"pad_left_stick_y",
"pad_right_stick_x",
"pad_right_stick_y",
"pad_button_start",
"pad_button_select",
"pad_button_left",
"pad_button_right",
"pad_button_up",
"pad_button_down",
"pad_button_a",
"pad_button_b",
"pad_button_x",
"pad_button_y",
"pad_button_l1",
"pad_button_r1",
"pad_button_l2",
"pad_button_r2",
"pad_button_l3",
"pad_button_r3"
};
return padKeys;
}

void InputManager::update()
{
m_GainputManager.Update();
Expand Down Expand Up @@ -261,6 +491,7 @@ void to_json(JSON::json& j, const InputScheme& s)
{
j["bools"] = s.bools;
j["floats"] = s.floats;
j["active"] = s.isActive;
}

void from_json(const JSON::json& j, InputScheme& s)
Expand All @@ -275,4 +506,5 @@ void from_json(const JSON::json& j, InputScheme& s)
InputDescription id = floatInput;
s.floats.push_back(id);
}
s.isActive = j.value("active", false);
}
9 changes: 9 additions & 0 deletions rootex/core/input/input_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct InputScheme
{
Vector<InputDescription> bools;
Vector<InputDescription> floats;
bool isActive;
};

void to_json(JSON::json& j, const InputScheme& s);
Expand Down Expand Up @@ -122,6 +123,14 @@ class InputManager
void update();
void setDisplaySize(const Vector2& newSize);

Array<String, 23> getMouseButtonNames();
Array<String, 166> getKeyboardButtonNames();
Array<String, 20> getPadButtonNames();

static Array<String, 23> GetMouseButtonNames() { return GetSingleton()->getMouseButtonNames(); }
static Array<String, 166> GetKeyboardButtonNames() { return GetSingleton()->getKeyboardButtonNames(); }
static Array<String, 20> GetPadButtonNames() { return GetSingleton()->getPadButtonNames(); }

const gainput::InputMap& getMap() const { return m_GainputMap; }
gainput::InputDeviceMouse* getMouse() { return static_cast<gainput::InputDeviceMouse*>(m_GainputManager.GetDevice(DeviceIDs[Device::Mouse])); }
gainput::InputDeviceKeyboard* getKeyboard() { return static_cast<gainput::InputDeviceKeyboard*>(m_GainputManager.GetDevice(DeviceIDs[Device::Keyboard])); }
Expand Down
Loading