I've worked keybinding functionality into Python, but there are some workarounds and notes (See the Jankfile)

This commit is contained in:
John McCardle 2023-07-16 23:30:00 -04:00
commit e85861cbb2
7 changed files with 40 additions and 9 deletions

View file

@ -32,7 +32,7 @@ GameEngine::GameEngine()
}
Scene* GameEngine::currentScene() { return scenes[scene]; }
void GameEngine::changeScene(std::string s) { scene = s; }
void GameEngine::changeScene(std::string s) { std::cout << "Current scene is now '" << s << "'\n"; scene = s; }
void GameEngine::quit() { running = false; }
void GameEngine::setPause(bool p) { paused = p; }
sf::Font & GameEngine::getFont() { return font; }

View file

@ -558,8 +558,10 @@ PyObject* McRFPy_API::_registerInputAction(PyObject *self, PyObject *args)
bool success;
if (actionstr == NULL) { // Action provided is None, i.e. unregister
std::cout << "Unregistering\n";
success = game->currentScene()->unregisterActionInjected(action_code, std::string(actionstr) + "_py");
} else {
std::cout << "Registering" << actionstr << "_py to " << action_code << "\n";
success = game->currentScene()->registerActionInjected(action_code, std::string(actionstr) + "_py");
}

View file

@ -187,7 +187,7 @@ void PythonScene::doAction(std::string name, std::string type) {
auto mousepos = sf::Mouse::getPosition(game->getWindow());
//std::cout << "name: " << name << ", type: " << type << std::endl;
if (ACTIONPY) {
McRFPy_API::doAction(name);
McRFPy_API::doAction(name.substr(0, name.size() - 3));
}
else if (ACTIONONCE("click")) {
// left click start
@ -241,8 +241,10 @@ void PythonScene::doAction(std::string name, std::string type) {
}
bool PythonScene::registerActionInjected(int code, std::string name) {
return false;
std::cout << "Registering injected action (PythonScene): " << code << " (" << ActionCode::KEY + code << ")\n";
registerAction(ActionCode::KEY + code, name);
//return false;
return true;
}
bool PythonScene::unregisterActionInjected(int code, std::string name) {

View file

@ -24,6 +24,6 @@ public:
void update() override final;
void doAction(std::string, std::string) override final;
void sRender() override final;
bool registerActionInjected(int, std::string) override final;
bool unregisterActionInjected(int, std::string) override final;
bool registerActionInjected(int, std::string) override;
bool unregisterActionInjected(int, std::string) override;
};

View file

@ -26,6 +26,7 @@ std::string Scene::action(int code)
bool Scene::registerActionInjected(int code, std::string name)
{
std::cout << "Inject registered action - default implementation\n";
return false;
}

View file

@ -257,6 +257,10 @@ class TestScene:
mcrfpy.createMenu("o", 540 + (80 * 4), 540, 80, 80) #10
mcrfpy.createSprite("o", 4, 4, 10, 10, 1.0)
mcrfpy.createMenu("p", 20, 20, 40, 40) #11
mcrfpy.createButton("p", 0, 0, 130, 40, DARKGREEN, (0, 0, 0), "Register", "keyregistration")
mcrfpy.registerPyAction("keyregistration", keyregistration)
#print("Make UIs visible")
self.menus = mcrfpy.listMenus()
self.menus[0].visible = True
@ -273,6 +277,9 @@ class TestScene:
self.menus[mn].bgcolor = BLACK
self.menus[mn].visible = False
mcrfpy.modMenu(self.menus[mn])
self.menus[11].visible=True
mcrfpy.modMenu(self.menus[11])
#self.menus[2].bgcolor = BLACK
#self.menus[3].visible = True
@ -536,10 +543,21 @@ class TestScene:
False,
[0, 1, 2, 1, 2, 0]
)
def keytest():
print("Key tested.")
def keyregistration():
print("Registering 'keytest'")
mcrfpy.registerPyAction("keytest", keytest)
print("Registering input")
print(mcrfpy.registerInputAction(15, "keytest"))
def start():
global scene
#print("TestScene.start called")
scene = TestScene()
mcrfpy.refreshFov()
scene.updatehints()