mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-05-23 16:13:52 +00:00
Implement user control loading from controls.txt
Added user control loading functionality from a configuration file.
This commit is contained in:
parent
891bfb00da
commit
46b6e6260c
1 changed files with 73 additions and 0 deletions
|
|
@ -4,6 +4,39 @@
|
|||
|
||||
#include "KeyboardMouseInput.h"
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <cctype>
|
||||
|
||||
// Default keyboard and mouse bindings
|
||||
#define INPUT_BINDING_TABLE \
|
||||
X(KEY_FORWARD, 'W') \
|
||||
X(KEY_BACKWARD, 'S') \
|
||||
X(KEY_LEFT, 'A') \
|
||||
X(KEY_RIGHT, 'D') \
|
||||
X(KEY_JUMP, VK_SPACE) \
|
||||
X(KEY_SNEAK, VK_LSHIFT) \
|
||||
X(KEY_SPRINT, VK_CONTROL) \
|
||||
X(KEY_INVENTORY, 'E') \
|
||||
X(KEY_DROP, 'Q') \
|
||||
X(KEY_CRAFTING, 'C') \
|
||||
X(KEY_CRAFTING_ALT, 'R') \
|
||||
X(KEY_CHAT, 'T') \
|
||||
X(KEY_CONFIRM, VK_RETURN) \
|
||||
X(KEY_CANCEL, VK_ESCAPE) \
|
||||
X(KEY_PAUSE, VK_ESCAPE) \
|
||||
X(KEY_TOGGLE_HUD, VK_F1) \
|
||||
X(KEY_DEBUG_INFO, VK_F3) \
|
||||
X(KEY_DEBUG_MENU, VK_F4) \
|
||||
X(KEY_THIRD_PERSON, VK_F5) \
|
||||
X(KEY_DEBUG_CONSOLE, VK_F6) \
|
||||
X(KEY_HOST_SETTINGS, VK_TAB) \
|
||||
X(KEY_SCREENSHOT, VK_F2)
|
||||
|
||||
#define X(name, default_val) int KeyboardMouseInput::name = default_val;
|
||||
INPUT_BINDING_TABLE
|
||||
#undef X
|
||||
|
||||
KeyboardMouseInput g_KBMInput;
|
||||
|
||||
|
|
@ -27,6 +60,46 @@ static bool IsModifierKeyDown(const bool* keyState, int vkCode)
|
|||
}
|
||||
}
|
||||
|
||||
static void LoadUserControls()
|
||||
{
|
||||
std::map<std::string, int*> controlMap;
|
||||
|
||||
#define X(name, default_val) controlMap[#name] = &KeyboardMouseInput::name;
|
||||
INPUT_BINDING_TABLE
|
||||
#undef X
|
||||
|
||||
std::ifstream controlsFile("controls.txt");
|
||||
if (controlsFile.is_open())
|
||||
{
|
||||
std::string line;
|
||||
while (std::getline(controlsFile, line))
|
||||
{
|
||||
if (!line.empty() && line.back() == '\r') line.pop_back();
|
||||
if (line.length() < 1) continue;
|
||||
|
||||
size_t sep = line.find('=');
|
||||
if (sep != std::string::npos && line.length() > sep + 1)
|
||||
{
|
||||
std::string keyName = line.substr(0, sep);
|
||||
std::string valueStr = line.substr(sep + 1);
|
||||
|
||||
if (controlMap.count(keyName))
|
||||
{
|
||||
if (isdigit(valueStr[0]))
|
||||
{
|
||||
*controlMap[keyName] = std::stoi(valueStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
*controlMap[keyName] = (int)valueStr[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
controlsFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardMouseInput::Init()
|
||||
{
|
||||
memset(m_keyDown, 0, sizeof(m_keyDown));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue